Lean / Reader
Lean reader

WeightedFlow.lean

47 lines2 declarationsno sorryimports Mathlib
  1. import Mathlib
  2. namespace PermutohedronMatching
  3. open scoped BigOperators
  4. section
  5. variable {Row Col : Type*} [Fintype Row] [Fintype Col]
  6. def corrected (base : Row → Col → ℝ) (potential : Col → ℝ) (average : Row → ℝ)
  7. (r : Row) (c : Col) : ℝ :=
  8. base r c * (1 + potential c - average r)
  9. /-- A row-preserving, column-equalizing transport, including its support and positivity. -/
  10. theorem correct_flow (base : Row → Col → ℝ) (potential : Col → ℝ)
  11. (average : Row → ℝ) (goal : Col → ℝ)
  12. (hbase : ∀ r c, 0 ≤ base r c)
  13. (hrow : ∀ r, ∑ c, base r c * (potential c - average r) = 0)
  14. (hcol : ∀ c, ∑ r, base r c * (potential c - average r) =
  15. goal c - ∑ r, base r c)
  16. (hbound : ∀ r c, base r c ≠ 0 → average r - potential c ≤ 1) :
  17. (∀ r c, 0 ≤ corrected base potential average r c) ∧
  18. (∀ r c, base r c = 0 → corrected base potential average r c = 0) ∧
  19. (∀ r, ∑ c, corrected base potential average r c = ∑ c, base r c) ∧
  20. (∀ c, ∑ r, corrected base potential average r c = goal c) := by
  21. have he (r : Row) (c : Col) : corrected base potential average r c =
  22. base r c + base r c * (potential c - average r) := by
  23. unfold corrected
  24. ring
  25. refine ⟨?_, ?_, ?_, ?_⟩
  26. · intro r c
  27. by_cases h : base r c = 0
  28. · simp [corrected, h]
  29. · apply mul_nonneg (hbase r c)
  30. linarith [hbound r c h]
  31. · intro r c h
  32. simp [corrected, h]
  33. · intro r
  34. simp only [he, Finset.sum_add_distrib, hrow, add_zero]
  35. · intro c
  36. simp only [he, Finset.sum_add_distrib, hcol]
  37. ring
  38. end
  39. end PermutohedronMatching