import Mathlibnamespace PermutohedronMatchingopen scoped BigOperatorssectionvariable {Row Col : Type*} [Fintype Row] [Fintype Col]def corrected (base : Row → Col → ℝ) (potential : Col → ℝ) (average : Row → ℝ)(r : Row) (c : Col) : ℝ :=base r c * (1 + potential c - average r)/-- A row-preserving, column-equalizing transport, including its support and positivity. -/theorem correct_flow (base : Row → Col → ℝ) (potential : Col → ℝ)(average : Row → ℝ) (goal : Col → ℝ)(hbase : ∀ r c, 0 ≤ base r c)(hrow : ∀ r, ∑ c, base r c * (potential c - average r) = 0)(hcol : ∀ c, ∑ r, base r c * (potential c - average r) =goal c - ∑ r, base r c)(hbound : ∀ r c, base r c ≠ 0 → average r - potential c ≤ 1) :(∀ r c, 0 ≤ corrected base potential average r c) ∧(∀ r c, base r c = 0 → corrected base potential average r c = 0) ∧(∀ r, ∑ c, corrected base potential average r c = ∑ c, base r c) ∧(∀ c, ∑ r, corrected base potential average r c = goal c) := byhave he (r : Row) (c : Col) : corrected base potential average r c =base r c + base r c * (potential c - average r) := byunfold correctedringrefine ⟨?_, ?_, ?_, ?_⟩· intro r cby_cases h : base r c = 0· simp [corrected, h]· apply mul_nonneg (hbase r c)linarith [hbound r c h]· intro r c hsimp [corrected, h]· intro rsimp only [he, Finset.sum_add_distrib, hrow, add_zero]· intro csimp only [he, Finset.sum_add_distrib, hcol]ringendend PermutohedronMatching