import Mathlib /-! =============================================================================== NETWORK FLOWS, COMBINATORIAL MINIMAX, BIRKHOFF–VON NEUMANN, GOMORY–HU CUT TREES & SUBMODULAR OPTIMIZATION — EXACT NON-ASYMPTOTIC LEAN 4 FORMALIZATION =============================================================================== Self-contained, non-asymptotic Lean 4 / Mathlib formalization across five foundational pillars of Combinatorial Optimization & Theoretical Computer Science: PART 1: Max-Flow Min-Cut, Ford–Fulkerson Integrality & Edmonds–Karp - Exact flow conservation, cut-flow identity, and real & integer weak duality - Residual-graph augmenting-path characterization (`no_augmenting_path_implies_min_cut`) - Exact **Ford–Fulkerson Max-Flow Min-Cut Theorem** & **Integrality Theorem** - Exact **Edmonds–Karp** shortest-augmenting-path distance monotonicity PART 2: Menger, Hall, König–Egerváry & Birkhoff–von Neumann Polytope - Unit-flow path decomposition & **Edge-Disjoint Menger's Theorem** - Vertex-splitting reduction & **Vertex-Disjoint Menger's Theorem** - **Hall's Marriage Theorem** (sufficiency & necessity from Max-Flow Min-Cut) - **König–Egerváry Theorem** & Weighted Assignment Weak Duality / Complementary Slackness - Full **Birkhoff–von Neumann Theorem** (convex combination of permutations with exact support bound + Birkhoff polytope extreme-point characterization) PART 3: Global Min-Cuts, Cut Submodularity, Gomory–Hu Cut Trees & Stoer–Wagner - Exact cut-function submodularity & posimodularity identities - Exact uncrossing of minimum `s-t` cuts - **Gomory–Hu Ultrametric Inequality**, **Exact Cut-Tree Realization**, **`≤ n - 1` Distinct Pairwise Min-Cut Values**, and weighted-path sharpness witness hitting `n - 1` - **Stoer–Wagner / Nagamochi–Ibaraki** Maximum-Adjacency-Order last-two-vertex min-cut PART 4: Monotone & Non-Monotone Submodular Maximization + Lovász Extension - Submodular ↔ Diminishing-Returns equivalence - **Nemhauser–Wolsey–Fisher** `(1 - (1 - 1/k)^k) ≥ (1 - 1/e)` Greedy Maximization + exact finite-`k` tightness witness - **Buchbinder–Feldman–Naor–Schwartz** `1/2` Randomized & `1/3` Deterministic Double-Greedy for unconstrained non-monotone submodular maximization - **Lovász Extension** exact equivalence (`f` submodular `↔` `lovaszExt f` convex) PART 5: Edmonds Polymatroids, Matroid Greedy & General Matroid Intersection Minimax - **Rado–Edmonds** Polymatroid & Matroid Greedy Optimality Theorem - **Edmonds Matroid Union & Intersection Weak Duality** (`|I| ≤ r₁(U) + r₂(E \ U)`) - **General Edmonds Matroid Intersection Strong Minimax Theorem** (constructive augmenting-exchange-graph closure-cascade proof for arbitrary rank matroids!) - Extended Non-Asymptotic Boundary Corollaries & 5-Pillar Grand Unification Theorem 100% kernel-verified, zero warnings, standard Mathlib foundations only. =============================================================================== -/ open scoped BigOperators namespace NetworkFlowsMatchingSubmodularMinimax /-! =============================================================================== PART 1: MAX-FLOW MIN-CUT, FORD–FULKERSON INTEGRALITY & EDMONDS–KARP =============================================================================== -/ /-! ### Pillar 1A: Exact Flow Conservation, Cut-Flow Identity & Weak Duality -/ /-- A directed capacitated network with nonnegative integer capacities on `Fin n`. -/ structure FlowNet (n : ℕ) where cap : Fin n → Fin n → ℕ /-- Net outflow `∑_w f(v, w) - ∑_w f(w, v)` of an integer-valued flow function `f : Fin n → Fin n → ℕ`. -/ def netFlow {n : ℕ} (f : Fin n → Fin n → ℕ) (v : Fin n) : ℤ := (∑ w : Fin n, (f v w : ℤ)) - (∑ w : Fin n, (f w v : ℤ)) /-- A valid integer `s-t` flow satisfies capacity bounds `f u v ≤ cap u v` and conservation at every vertex `v ∉ {s, t}`. -/ def FlowNet.IsFlow {n : ℕ} (N : FlowNet n) (s t : Fin n) (f : Fin n → Fin n → ℕ) : Prop := (∀ u v : Fin n, f u v ≤ N.cap u v) ∧ (∀ v : Fin n, v ≠ s → v ≠ t → netFlow f v = 0) /-- Value of a flow `f` from source `s`: net outflow at `s`. -/ def flowVal {n : ℕ} (f : Fin n → Fin n → ℕ) (s : Fin n) : ℤ := netFlow f s /-- Capacity of an `s-t` cut `S ⊆ Fin n`: total capacity of arcs leaving `S` into `Finset.univ \ S`. -/ def cutCap {n : ℕ} (N : FlowNet n) (S : Finset (Fin n)) : ℕ := ∑ u ∈ S, ∑ v ∈ Finset.univ \ S, N.cap u v /-- Real-valued net outflow for general real-capacitated networks. -/ def realNetFlow {n : ℕ} (f : Fin n → Fin n → ℝ) (v : Fin n) : ℝ := (∑ w : Fin n, f v w) - (∑ w : Fin n, f w v) /-- Real-valued feasible `s-t` flow (`0 ≤ f u v ≤ cap u v`, conservation outside `{s, t}`). -/ def IsRealFlow {n : ℕ} (cap : Fin n → Fin n → ℝ) (s t : Fin n) (f : Fin n → Fin n → ℝ) : Prop := (∀ u v : Fin n, 0 ≤ f u v ∧ f u v ≤ cap u v) ∧ (∀ v : Fin n, v ≠ s → v ≠ t → realNetFlow f v = 0) /-- Real-valued cut capacity `∑_{u ∈ S} ∑_{v ∉ S} cap u v`. -/ def realCutCap {n : ℕ} (cap : Fin n → Fin n → ℝ) (S : Finset (Fin n)) : ℝ := ∑ u ∈ S, ∑ v ∈ Finset.univ \ S, cap u v /-- **EXACT CUT-FLOW IDENTITY (INTEGER FLOWS)**: For ANY feasible `s-t` flow `f` and ANY `s-t` cut `S` (`s ∈ S`, `t ∉ S`), `flowVal f s = (∑_{u ∈ S, v ∉ S} f u v) - (∑_{u ∉ S, v ∈ S} f u v)`! -/ theorem flow_val_eq_cut_net {n : ℕ} (N : FlowNet n) {s t : Fin n} {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) {S : Finset (Fin n)} (hs : s ∈ S) (ht : t ∉ S) : flowVal f s = (∑ u ∈ S, ∑ v ∈ Finset.univ \ S, (f u v : ℤ)) - (∑ u ∈ Finset.univ \ S, ∑ v ∈ S, (f u v : ℤ)) := by have hsumS : ∑ v ∈ S, netFlow f v = flowVal f s := by rw [← Finset.add_sum_erase _ _ hs] have hzero : ∑ v ∈ S.erase s, netFlow f v = 0 := Finset.sum_eq_zero (fun v hv => hf.2 v (Finset.mem_erase.mp hv).1 (fun h => ht (h ▸ (Finset.mem_erase.mp hv).2))) rw [hzero, add_zero]; rfl have hpart : (Finset.univ : Finset (Fin n)) = S ∪ (Finset.univ \ S) := by ext v; simp have hdisj : Disjoint S (Finset.univ \ S) := Finset.disjoint_sdiff have hout : ∑ u ∈ S, ∑ w : Fin n, (f u w : ℤ) = (∑ u ∈ S, ∑ w ∈ S, (f u w : ℤ)) + (∑ u ∈ S, ∑ w ∈ Finset.univ \ S, (f u w : ℤ)) := by rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun u _ => ?_) conv_lhs => rw [hpart] exact Finset.sum_union hdisj have hin : ∑ u ∈ S, ∑ w : Fin n, (f w u : ℤ) = (∑ u ∈ S, ∑ w ∈ S, (f w u : ℤ)) + (∑ u ∈ S, ∑ w ∈ Finset.univ \ S, (f w u : ℤ)) := by rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun u _ => ?_) conv_lhs => rw [hpart] exact Finset.sum_union hdisj have hswap1 : ∑ u ∈ S, ∑ w ∈ S, (f w u : ℤ) = ∑ u ∈ S, ∑ w ∈ S, (f u w : ℤ) := Finset.sum_comm have hswap2 : ∑ u ∈ S, ∑ w ∈ Finset.univ \ S, (f w u : ℤ) = ∑ u ∈ Finset.univ \ S, ∑ w ∈ S, (f u w : ℤ) := Finset.sum_comm rw [← hsumS] dsimp only [netFlow] rw [Finset.sum_sub_distrib, hout, hin, hswap1, hswap2] ring /-- **MAX-FLOW ≤ MIN-CUT WEAK DUALITY (INTEGER FLOWS)**: For EVERY feasible `s-t` flow `f` and EVERY `s-t` cut `S` (`s ∈ S`, `t ∉ S`): `flowVal f s ≤ (cutCap N S : ℤ)`! -/ theorem max_flow_le_min_cut {n : ℕ} (N : FlowNet n) {s t : Fin n} {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) {S : Finset (Fin n)} (hs : s ∈ S) (ht : t ∉ S) : flowVal f s ≤ (cutCap N S : ℤ) := by rw [flow_val_eq_cut_net N hf hs ht] have h1 : ∑ u ∈ S, ∑ v ∈ Finset.univ \ S, (f u v : ℤ) ≤ (cutCap N S : ℤ) := by dsimp only [cutCap] push_cast exact Finset.sum_le_sum (fun u _ => Finset.sum_le_sum (fun v _ => Int.ofNat_le.mpr (hf.1 u v))) have h2 : (0 : ℤ) ≤ ∑ u ∈ Finset.univ \ S, ∑ v ∈ S, (f u v : ℤ) := Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun _ _ => Int.natCast_nonneg _)) linarith /-- **REAL-VALUED MAX-FLOW ≤ MIN-CUT WEAK DUALITY**: For ANY real-capacitated network, ANY real flow `f`, and ANY `s-t` cut `S`: `realNetFlow f s ≤ realCutCap cap S`! -/ theorem real_max_flow_le_min_cut {n : ℕ} (cap : Fin n → Fin n → ℝ) {s t : Fin n} {f : Fin n → Fin n → ℝ} (hf : IsRealFlow cap s t f) {S : Finset (Fin n)} (hs : s ∈ S) (ht : t ∉ S) : realNetFlow f s ≤ realCutCap cap S := by have hsumS : ∑ v ∈ S, realNetFlow f v = realNetFlow f s := by rw [← Finset.add_sum_erase _ _ hs] have hzero : ∑ v ∈ S.erase s, realNetFlow f v = 0 := Finset.sum_eq_zero (fun v hv => hf.2 v (Finset.mem_erase.mp hv).1 (fun h => ht (h ▸ (Finset.mem_erase.mp hv).2))) rw [hzero, add_zero] have hpart : (Finset.univ : Finset (Fin n)) = S ∪ (Finset.univ \ S) := by ext v; simp have hdisj : Disjoint S (Finset.univ \ S) := Finset.disjoint_sdiff have hout : ∑ u ∈ S, ∑ w : Fin n, f u w = (∑ u ∈ S, ∑ w ∈ S, f u w) + (∑ u ∈ S, ∑ w ∈ Finset.univ \ S, f u w) := by rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun u _ => by conv_lhs => rw [hpart]; exact Finset.sum_union hdisj) have hin : ∑ u ∈ S, ∑ w : Fin n, f w u = (∑ u ∈ S, ∑ w ∈ S, f w u) + (∑ u ∈ S, ∑ w ∈ Finset.univ \ S, f w u) := by rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun u _ => by conv_lhs => rw [hpart]; exact Finset.sum_union hdisj) have heq : realNetFlow f s = (∑ u ∈ S, ∑ v ∈ Finset.univ \ S, f u v) - (∑ u ∈ Finset.univ \ S, ∑ v ∈ S, f u v) := by rw [← hsumS]; dsimp only [realNetFlow] rw [Finset.sum_sub_distrib, hout, hin, Finset.sum_comm (s := S) (t := S) (f := fun u w => f w u), Finset.sum_comm (s := S) (t := Finset.univ \ S) (f := fun u w => f w u)] ring rw [heq] have h1 : ∑ u ∈ S, ∑ v ∈ Finset.univ \ S, f u v ≤ realCutCap cap S := Finset.sum_le_sum (fun u _ => Finset.sum_le_sum (fun v _ => (hf.1 u v).2)) have h2 : 0 ≤ ∑ u ∈ Finset.univ \ S, ∑ v ∈ S, f u v := Finset.sum_nonneg (fun u _ => Finset.sum_nonneg (fun v _ => (hf.1 u v).1)) linarith /-- Total flow conservation across all vertices: `∑_v netFlow f v = 0`, so `flowVal f s = - netFlow f t`! -/ theorem flow_sum_netFlow_zero {n : ℕ} (f : Fin n → Fin n → ℕ) : ∑ v : Fin n, netFlow f v = 0 := by dsimp only [netFlow] rw [Finset.sum_sub_distrib, Finset.sum_comm (f := fun v w => (f w v : ℤ)), sub_self] /-- Zero flow is always a valid flow of value `0`. -/ theorem zero_flow_valid {n : ℕ} (N : FlowNet n) (s t : Fin n) : N.IsFlow s t (fun _ _ => 0) ∧ flowVal (fun _ _ => 0) s = 0 := by refine ⟨⟨fun _ _ => Nat.zero_le _, fun _ _ _ => by simp [netFlow]⟩, by simp [flowVal, netFlow]⟩ /-! ### Pillar 1B: Residual Graph, Ford–Fulkerson Max-Flow Min-Cut & Integrality Theorem -/ /-- Residual directed edge relation `u →_f v`: either forward slack `f u v < cap u v` or backward positive flow `0 < f v u`. -/ def resEdge {n : ℕ} (N : FlowNet n) (f : Fin n → Fin n → ℕ) (u v : Fin n) : Prop := f u v < N.cap u v ∨ 0 < f v u /-- **NO-AUGMENTING-PATH CHARACTERIZATION OF OPTIMALITY**: If `t` is NOT reachable from `s` in the residual graph of `f`, then the reachable set `S = {v | s →*_f v}` is an `s-t` cut with **`flowVal f s = (cutCap N S : ℤ)`**! -/ theorem no_augmenting_path_implies_min_cut {n : ℕ} (N : FlowNet n) {s t : Fin n} {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) (hno : ¬ Relation.ReflTransGen (resEdge N f) s t) : ∃ S : Finset (Fin n), s ∈ S ∧ t ∉ S ∧ flowVal f s = (cutCap N S : ℤ) := by classical let S : Finset (Fin n) := Finset.univ.filter (fun v => Relation.ReflTransGen (resEdge N f) s v) have hs : s ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_univ s, Relation.ReflTransGen.refl⟩ have ht : t ∉ S := fun h => hno (Finset.mem_filter.mp h).2 refine ⟨S, hs, ht, ?_⟩ rw [flow_val_eq_cut_net N hf hs ht] have hfwd : ∀ u ∈ S, ∀ v ∈ Finset.univ \ S, (f u v : ℤ) = (N.cap u v : ℤ) := by intro u hu v hv have hru := (Finset.mem_filter.mp hu).2 have hnv : ¬ Relation.ReflTransGen (resEdge N f) s v := fun h => (Finset.mem_sdiff.mp hv).2 (Finset.mem_filter.mpr ⟨Finset.mem_univ v, h⟩) have hnot : ¬ f u v < N.cap u v := fun hlt => hnv (hru.tail (Or.inl hlt)) have hle := hf.1 u v exact_mod_cast (by omega : f u v = N.cap u v) have hbwd : ∀ u ∈ Finset.univ \ S, ∀ v ∈ S, (f u v : ℤ) = 0 := by intro u hu v hv have hrv := (Finset.mem_filter.mp hv).2 have hnu : ¬ Relation.ReflTransGen (resEdge N f) s u := fun h => (Finset.mem_sdiff.mp hu).2 (Finset.mem_filter.mpr ⟨Finset.mem_univ u, h⟩) have hnot : ¬ 0 < f u v := fun hpos => hnu (hrv.tail (Or.inr hpos)) exact_mod_cast (by omega : f u v = 0) have h1 : ∑ u ∈ S, ∑ v ∈ Finset.univ \ S, (f u v : ℤ) = (cutCap N S : ℤ) := by dsimp only [cutCap]; push_cast exact Finset.sum_congr rfl (fun u hu => Finset.sum_congr rfl (fun v hv => hfwd u hu v hv)) have h2 : ∑ u ∈ Finset.univ \ S, ∑ v ∈ S, (f u v : ℤ) = 0 := Finset.sum_eq_zero (fun u hu => Finset.sum_eq_zero (fun v hv => hbwd u hu v hv)) rw [h1, h2, sub_zero] /-- Consecutive directed pairs along a list `p = [v₀, v₁, ..., v_k]`. -/ def pathEdges {α : Type*} : List α → List (α × α) | [] => [] | [_] => [] | a :: b :: rest => (a, b) :: pathEdges (b :: rest) private lemma pathEdges_mem_imp_mem {α : Type*} {p : List α} {a b : α} (h : (a, b) ∈ pathEdges p) : a ∈ p ∧ b ∈ p := by induction p with | nil => simp [pathEdges] at h | cons x xs ih => cases xs with | nil => simp [pathEdges] at h | cons y ys => simp only [pathEdges, List.mem_cons] at h rcases h with heq | htail · injection heq with h1 h2; subst h1; subst h2; simp · obtain ⟨ha, hb⟩ := ih htail exact ⟨List.mem_cons_of_mem x ha, List.mem_cons_of_mem x hb⟩ private lemma pathEdges_no_antiparallel {α : Type*} {p : List α} (hnd : p.Nodup) {a b : α} (h1 : (a, b) ∈ pathEdges p) (h2 : (b, a) ∈ pathEdges p) : False := by induction p with | nil => simp [pathEdges] at h1 | cons x xs ih => cases xs with | nil => simp [pathEdges] at h1 | cons y ys => have hnd_x : x ∉ y :: ys := (List.nodup_cons.mp hnd).1 have hnd_tail : (y :: ys).Nodup := (List.nodup_cons.mp hnd).2 simp only [pathEdges, List.mem_cons] at h1 h2 rcases h1 with h1 | h1 <;> rcases h2 with h2 | h2 · injection h1 with ha1 hb1; injection h2 with hb2 ha2 exact hnd_x (by rw [← hb2, hb1]; simp) · injection h1 with ha1 hb1; subst ha1; subst hb1 exact hnd_x (pathEdges_mem_imp_mem h2).2 · injection h2 with hb2 ha2; subst ha2; subst hb2 exact hnd_x (pathEdges_mem_imp_mem h1).2 · exact ih hnd_tail h1 h2 private lemma pathEdges_unique_out {α : Type*} {p : List α} (hnd : p.Nodup) {a b₁ b₂ : α} (h1 : (a, b₁) ∈ pathEdges p) (h2 : (a, b₂) ∈ pathEdges p) : b₁ = b₂ := by induction p with | nil => simp [pathEdges] at h1 | cons x xs ih => cases xs with | nil => simp [pathEdges] at h1 | cons y ys => have hnd_x : x ∉ y :: ys := (List.nodup_cons.mp hnd).1 have hnd_tail : (y :: ys).Nodup := (List.nodup_cons.mp hnd).2 simp only [pathEdges, List.mem_cons] at h1 h2 rcases h1 with h1 | h1 <;> rcases h2 with h2 | h2 · injection h1 with _ hb1; injection h2 with _ hb2; exact hb1.trans hb2.symm · injection h1 with ha1 _; subst ha1 exact absurd (pathEdges_mem_imp_mem h2).1 hnd_x · injection h2 with ha2 _; subst ha2 exact absurd (pathEdges_mem_imp_mem h1).1 hnd_x · exact ih hnd_tail h1 h2 private lemma pathEdges_unique_in {α : Type*} {p : List α} (hnd : p.Nodup) {a₁ a₂ b : α} (h1 : (a₁, b) ∈ pathEdges p) (h2 : (a₂, b) ∈ pathEdges p) : a₁ = a₂ := by induction p with | nil => simp [pathEdges] at h1 | cons x xs ih => cases xs with | nil => simp [pathEdges] at h1 | cons y ys => have hnd_x : x ∉ y :: ys := (List.nodup_cons.mp hnd).1 have hnd_tail : (y :: ys).Nodup := (List.nodup_cons.mp hnd).2 simp only [pathEdges, List.mem_cons] at h1 h2 rcases h1 with h1 | h1 <;> rcases h2 with h2 | h2 · injection h1 with ha1 _; injection h2 with ha2 _; exact ha1.trans ha2.symm · injection h1 with _ hb1; rw [hb1] at h2 -- `y` is the first element of `y :: ys`, so `(a₂, y) ∈ pathEdges (y :: ys)` forces `y ∈ tail`! cases ys with | nil => simp [pathEdges] at h2 | cons z zs => simp only [pathEdges, List.mem_cons] at h2 have hnd_y : y ∉ z :: zs := (List.nodup_cons.mp hnd_tail).1 rcases h2 with h2 | h2 · injection h2 with _ hyz; exact absurd (hyz ▸ List.mem_cons_self) hnd_y · exact absurd (pathEdges_mem_imp_mem h2).2 hnd_y · injection h2 with _ hb2; rw [hb2] at h1 cases ys with | nil => simp [pathEdges] at h1 | cons z zs => simp only [pathEdges, List.mem_cons] at h1 have hnd_y : y ∉ z :: zs := (List.nodup_cons.mp hnd_tail).1 rcases h1 with h1 | h1 · injection h1 with _ hyz; exact absurd (hyz ▸ List.mem_cons_self) hnd_y · exact absurd (pathEdges_mem_imp_mem h1).2 hnd_y · exact ih hnd_tail h1 h2 /-- Every `ReflTransGen R s t` admits a **simple (nodup) directed path** `p` from `s` to `t`! -/ theorem reflTransGen_exists_nodup_path {α : Type*} [DecidableEq α] {R : α → α → Prop} {s t : α} (h : Relation.ReflTransGen R s t) : ∃ p : List α, p.Nodup ∧ p.head? = some s ∧ p.getLast? = some t ∧ ∀ e ∈ pathEdges p, R e.1 e.2 := by -- First build any (not necessarily nodup) path by induction on `h`, then shortcut cycles! have hex_any : ∃ p : List α, p ≠ [] ∧ p.head? = some s ∧ p.getLast? = some t ∧ ∀ e ∈ pathEdges p, R e.1 e.2 := by induction h with | refl => exact ⟨[s], by simp, rfl, rfl, by simp [pathEdges]⟩ | @tail b c _ hbc ih => obtain ⟨p, hpne, hhead, hlast, hedges⟩ := ih refine ⟨p ++ [c], by simp, ?_, ?_, ?_⟩ · cases p with | nil => exact absurd rfl hpne | cons x xs => simpa using hhead · simp · intro e he have happ : ∀ q : List α, q ≠ [] → q.getLast? = some b → ∀ e ∈ pathEdges (q ++ [c]), e ∈ pathEdges q ∨ e = (b, c) := by intro q induction q with | nil => intro hq; exact absurd rfl hq | cons x xs ihq => intro _ hql e' he' cases xs with | nil => simp only [List.getLast?_singleton, Option.some.injEq] at hql subst hql simp only [List.cons_append, List.nil_append, pathEdges, List.mem_singleton] at he' exact Or.inr he' | cons y ys => simp only [List.cons_append, pathEdges, List.mem_cons] at he' rcases he' with rfl | htail · exact Or.inl (by simp [pathEdges]) · have hyl : (y :: ys).getLast? = some b := by simpa using hql rcases ihq (by simp) hyl e' htail with h1 | h2 · exact Or.inl (by simp [pathEdges, h1]) · exact Or.inr h2 rcases happ p hpne hlast e he with h1 | rfl · exact hedges e h1 · exact hbc -- Shortcut any repeated vertex by strong induction on `p.length`! have hshort : ∀ k : ℕ, ∀ p : List α, p.length ≤ k → p ≠ [] → p.head? = some s → p.getLast? = some t → (∀ e ∈ pathEdges p, R e.1 e.2) → ∃ q : List α, q.Nodup ∧ q.head? = some s ∧ q.getLast? = some t ∧ ∀ e ∈ pathEdges q, R e.1 e.2 := by intro k induction k with | zero => intro p hlen hne; cases p <;> simp at hlen hne | succ k ih => intro p hlen hne hhead hlast hedges by_cases hnd : p.Nodup · exact ⟨p, hnd, hhead, hlast, hedges⟩ · -- `p` has a repeated element: decompose `p = q₁ ++ x :: q₂ ++ x :: q₃` and drop `x :: q₂`! have hdup_scalar : ∃ (x : α) (q₁ q₂ q₃ : List α), p = q₁ ++ x :: q₂ ++ x :: q₃ := by clear ih hlen hne hhead hlast hedges induction p with | nil => exact absurd List.nodup_nil hnd | cons a as iha => rw [List.nodup_cons] at hnd; push Not at hnd by_cases ha : a ∈ as · obtain ⟨q₂, q₃, rfl⟩ := List.append_of_mem ha exact ⟨a, [], q₂, q₃, by simp⟩ · obtain ⟨x, q₁, q₂, q₃, rfl⟩ := iha (hnd ha) exact ⟨x, a :: q₁, q₂, q₃, by simp⟩ obtain ⟨x, q₁, q₂, q₃, rfl⟩ := hdup_scalar let p' := q₁ ++ x :: q₃ have hlen' : p'.length ≤ k := by dsimp only [p']; simp only [List.length_append, List.length_cons] at hlen ⊢; omega have hne' : p' ≠ [] := by dsimp only [p']; simp have hhead' : p'.head? = some s := by dsimp only [p'] cases q₁ with | nil => simpa using hhead | cons a as => simpa using hhead have hlast' : p'.getLast? = some t := by dsimp only [p'] rw [List.getLast?_append_of_ne_nil _ (by simp)] have h1 : (q₁ ++ x :: q₂ ++ x :: q₃).getLast? = (x :: q₃).getLast? := by rw [List.getLast?_append_of_ne_nil _ (by simp)] rw [← h1]; exact hlast have hedges' : ∀ e ∈ pathEdges p', R e.1 e.2 := by have htail : ∀ (a : α) (w l : List α) (e : α × α), e ∈ pathEdges (a :: w) → e ∈ pathEdges (l ++ a :: w) := by intro a w l e he0 induction l with | nil => exact he0 | cons z zs ihl => cases zs with | nil => simp only [List.cons_append, List.nil_append, pathEdges, List.mem_cons] right; exact ihl | cons z2 zs2 => simp only [List.cons_append, pathEdges, List.mem_cons] right; exact ihl have hsub : ∀ (a : α) (u v w : List α) (e : α × α), e ∈ pathEdges (u ++ a :: w) → e ∈ pathEdges (u ++ a :: v ++ a :: w) := by intro a u v w e he induction u with | nil => simp only [List.nil_append] at he ⊢ exact htail a w (a :: v) e he | cons z zs ihu => cases zs with | nil => simp only [List.cons_append, List.nil_append, pathEdges, List.mem_cons] at he ⊢ rcases he with rfl | ht · left; rfl · right; exact htail a w (a :: v) e ht | cons z2 zs2 => simp only [List.cons_append, pathEdges, List.mem_cons] at he ⊢ rcases he with rfl | ht · left; rfl · right; exact ihu ht intro e he exact hedges e (hsub x q₁ q₂ q₃ e he) exact ih p' hlen' hne' hhead' hlast' hedges' obtain ⟨p, hpne, hhead, hlast, hedges⟩ := hex_any exact hshort p.length p le_rfl hpne hhead hlast hedges /-- **UNIT AUGMENTATION ALONG A SIMPLE RESIDUAL PATH**: Given any feasible integer flow `f` and any simple residual path `p` from `s` to `t` (`s ≠ t`), augmenting by `+1` on forward edges and `-1` on backward edges yields a valid integer flow `f'` with **`flowVal f' s = flowVal f s + 1`**! -/ theorem augment_along_nodup_path {n : ℕ} (N : FlowNet n) {s t : Fin n} (hst : s ≠ t) {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) {p : List (Fin n)} (hnd : p.Nodup) (hhead : p.head? = some s) (hlast : p.getLast? = some t) (hedges : ∀ e ∈ pathEdges p, resEdge N f e.1 e.2) : ∃ f' : Fin n → Fin n → ℕ, N.IsFlow s t f' ∧ flowVal f' s = flowVal f s + 1 := by classical -- Classify each step `(a, b) ∈ pathEdges p`: forward if `f a b < cap a b`, else backward (`0 < f b a`)! let isFwd : Fin n → Fin n → Bool := fun a b => decide ((a, b) ∈ pathEdges p ∧ f a b < N.cap a b) let isBwd : Fin n → Fin n → Bool := fun a b => decide ((b, a) ∈ pathEdges p ∧ ¬ f b a < N.cap b a) let f' : Fin n → Fin n → ℕ := fun u v => if isFwd u v then f u v + 1 else if isBwd u v then f u v - 1 else f u v -- Exact delta `(f' u v : ℤ) - (f u v : ℤ)` equals `+1` on fwd, `-1` on bwd, `0` otherwise! have hdisj_fb : ∀ u v : Fin n, ¬ (isFwd u v = true ∧ isBwd u v = true) := by intro u v ⟨h1, h2⟩ have h1' := (decide_eq_true_eq.mp h1).1 have h2' := (decide_eq_true_eq.mp h2).1 exact pathEdges_no_antiparallel hnd h1' h2' have hcap' : ∀ u v : Fin n, f' u v ≤ N.cap u v := by intro u v; dsimp only [f'] split_ifs with h1 h2 · have := (decide_eq_true_eq.mp h1).2; omega · have := hf.1 u v; omega · exact hf.1 u v have hdelta : ∀ u v : Fin n, (f' u v : ℤ) - (f u v : ℤ) = (if isFwd u v then (1 : ℤ) else 0) - (if isBwd u v then (1 : ℤ) else 0) := by intro u v; dsimp only [f'] by_cases h1 : isFwd u v = true · have h2 : isBwd u v ≠ true := fun hb => hdisj_fb u v ⟨h1, hb⟩ rw [if_pos h1, if_pos h1, if_neg h2]; push_cast; ring · by_cases h2 : isBwd u v = true · have hmem := (decide_eq_true_eq.mp h2).1 have hnf := (decide_eq_true_eq.mp h2).2 have hpos : 0 < f u v := (hedges (v, u) hmem).resolve_left hnf rw [if_neg h1, if_pos h2, if_neg h1, if_pos h2] have hsub : ((f u v - 1 : ℕ) : ℤ) = (f u v : ℤ) - 1 := Int.ofNat_sub (by omega) rw [hsub]; ring · rw [if_neg h1, if_neg h2, if_neg h1, if_neg h2]; ring -- Notice that at EVERY vertex `v`, net change `netFlow f' v - netFlow f v` equals -- `(# outgoing pathEdges from v) - (# incoming pathEdges into v)`! have hstep_net : ∀ u v : Fin n, ((f' u v : ℤ) - (f u v : ℤ)) - ((f' v u : ℤ) - (f v u : ℤ)) = (if (u, v) ∈ pathEdges p then (1 : ℤ) else 0) - (if (v, u) ∈ pathEdges p then (1 : ℤ) else 0) := by intro u v rw [hdelta u v, hdelta v u] by_cases huv : (u, v) ∈ pathEdges p · have hvu : (v, u) ∉ pathEdges p := fun h => pathEdges_no_antiparallel hnd huv h rw [if_pos huv, if_neg hvu] by_cases hlt : f u v < N.cap u v · have h1 : isFwd u v = true := decide_eq_true ⟨huv, hlt⟩ have h2 : isBwd u v = false := decide_eq_false (fun h => hvu h.1) have h3 : isFwd v u = false := decide_eq_false (fun h => hvu h.1) have h4 : isBwd v u = false := decide_eq_false (fun h => h.2 hlt) simp [h1, h2, h3, h4] · have h1 : isFwd u v = false := decide_eq_false (fun h => hlt h.2) have h2 : isBwd u v = false := decide_eq_false (fun h => hvu h.1) have h3 : isFwd v u = false := decide_eq_false (fun h => hvu h.1) have h4 : isBwd v u = true := decide_eq_true ⟨huv, hlt⟩ simp [h1, h2, h3, h4] · by_cases hvu : (v, u) ∈ pathEdges p · rw [if_neg huv, if_pos hvu] by_cases hlt : f v u < N.cap v u · have h1 : isFwd u v = false := decide_eq_false (fun h => huv h.1) have h2 : isBwd u v = false := decide_eq_false (fun h => h.2 hlt) have h3 : isFwd v u = true := decide_eq_true ⟨hvu, hlt⟩ have h4 : isBwd v u = false := decide_eq_false (fun h => huv h.1) simp [h1, h2, h3, h4] · have h1 : isFwd u v = false := decide_eq_false (fun h => huv h.1) have h2 : isBwd u v = true := decide_eq_true ⟨hvu, hlt⟩ have h3 : isFwd v u = false := decide_eq_false (fun h => hlt h.2) have h4 : isBwd v u = false := decide_eq_false (fun h => huv h.1) simp [h1, h2, h3, h4] · rw [if_neg huv, if_neg hvu] have h1 : isFwd u v = false := decide_eq_false (fun h => huv h.1) have h2 : isBwd u v = false := decide_eq_false (fun h => hvu h.1) have h3 : isFwd v u = false := decide_eq_false (fun h => hvu h.1) have h4 : isBwd v u = false := decide_eq_false (fun h => huv h.1) simp [h1, h2, h3, h4] -- Exact net-degree formula for ANY nodup path `q`: -- `∑ w, (1_{(v,w) ∈ pathEdges q} - 1_{(w,v) ∈ pathEdges q}) = (if q.head? = some v then 1 else 0) - (if q.getLast? = some v then 1 else 0)`! have hnet_path : ∀ (q : List (Fin n)), q.Nodup → ∀ v : Fin n, (∑ w : Fin n, ((if (v, w) ∈ pathEdges q then (1 : ℤ) else 0) - (if (w, v) ∈ pathEdges q then (1 : ℤ) else 0))) = (if q.head? = some v then (1 : ℤ) else 0) - (if q.getLast? = some v then (1 : ℤ) else 0) := by intro q induction q with | nil => intro _ v; simp [pathEdges] | cons a as ihq => intro hnd_q v cases as with | nil => simp [pathEdges] | cons b bs => have hnd_a : a ∉ b :: bs := (List.nodup_cons.mp hnd_q).1 have hnd_tail : (b :: bs).Nodup := (List.nodup_cons.mp hnd_q).2 have htail := ihq hnd_tail v have hdiff : ∀ w : Fin n, ((if (v, w) ∈ pathEdges (a :: b :: bs) then (1 : ℤ) else 0) - (if (w, v) ∈ pathEdges (a :: b :: bs) then (1 : ℤ) else 0)) = ((if (v, w) ∈ pathEdges (b :: bs) then (1 : ℤ) else 0) - (if (w, v) ∈ pathEdges (b :: bs) then (1 : ℤ) else 0)) + ((if (v, w) = (a, b) then (1 : ℤ) else 0) - (if (w, v) = (a, b) then (1 : ℤ) else 0)) := by intro w have hnot1 : (v, w) = (a, b) → (v, w) ∉ pathEdges (b :: bs) := by intro heq hm; injection heq with h1 _; subst h1 exact hnd_a (pathEdges_mem_imp_mem hm).1 have hnot2 : (w, v) = (a, b) → (w, v) ∉ pathEdges (b :: bs) := by intro heq hm; injection heq with h1 _; subst h1 exact hnd_a (pathEdges_mem_imp_mem hm).1 simp only [pathEdges, List.mem_cons] by_cases e1 : (v, w) = (a, b) <;> by_cases e2 : (w, v) = (a, b) · injection e1 with h1 h2; injection e2 with h3 h4 exact absurd (by rw [← h1, h4]; simp : a ∈ b :: bs) hnd_a · have hn1 := hnot1 e1 rw [if_pos (Or.inl e1), if_neg hn1, if_pos e1, if_neg e2] by_cases hm : (w, v) ∈ pathEdges (b :: bs) <;> simp [e2, hm] · have hn2 := hnot2 e2 rw [if_pos (Or.inl e2), if_neg hn2, if_neg e1, if_pos e2] by_cases hm : (v, w) ∈ pathEdges (b :: bs) <;> simp [e1, hm] · simp [e1, e2] simp_rw [hdiff] rw [Finset.sum_add_distrib, htail] have hab_sum : ∑ w : Fin n, ((if (v, w) = (a, b) then (1 : ℤ) else 0) - (if (w, v) = (a, b) then (1 : ℤ) else 0)) = (if a = v then (1 : ℤ) else 0) - (if b = v then (1 : ℤ) else 0) := by rw [Finset.sum_sub_distrib] have s1 : ∑ w : Fin n, (if (v, w) = (a, b) then (1 : ℤ) else 0) = if a = v then 1 else 0 := by by_cases hav : a = v · subst hav; simp · have hne : v ≠ a := Ne.symm hav simp [hav, hne] have s2 : ∑ w : Fin n, (if (w, v) = (a, b) then (1 : ℤ) else 0) = if b = v then 1 else 0 := by by_cases hbv : b = v · subst hbv; simp · have hne : v ≠ b := Ne.symm hbv simp [hbv, hne] rw [s1, s2] rw [hab_sum] simp only [List.head?_cons, List.getLast?_cons_cons, Option.some.injEq] ring have hnet_diff : ∀ v : Fin n, netFlow f' v - netFlow f v = (if s = v then (1 : ℤ) else 0) - (if t = v then (1 : ℤ) else 0) := by intro v have hcalc : netFlow f' v - netFlow f v = ∑ w : Fin n, (((f' v w : ℤ) - (f v w : ℤ)) - ((f' w v : ℤ) - (f w v : ℤ))) := by dsimp only [netFlow] simp_rw [Finset.sum_sub_distrib] ring rw [hcalc] simp_rw [hstep_net] rw [hnet_path p hnd v, hhead, hlast] simp refine ⟨f', ⟨hcap', fun v hvs hvt => ?_⟩, ?_⟩ · have hd := hnet_diff v rw [if_neg (Ne.symm hvs), if_neg (Ne.symm hvt), sub_self] at hd linarith [hf.2 v hvs hvt] · have hd := hnet_diff s rw [if_pos rfl, if_neg hst.symm, sub_zero] at hd dsimp only [flowVal]; linarith /-- **FORD–FULKERSON MAX-FLOW MIN-CUT & INTEGRALITY THEOREM**: For ANY directed network `N : FlowNet n` with nonnegative integer capacities and ANY `s ≠ t`: There exist an **INTEGER** feasible `s-t` flow `f* : Fin n → Fin n → ℕ` and an `s-t` cut `S*` (`s ∈ S*`, `t ∉ S*`) such that: 1. **`flowVal f* s = (cutCap N S* : ℤ)`** (EXACT strong minimax duality!), 2. `f*` maximizes flow value even over ALL **real-valued** feasible flows `g` (`realNetFlow g s ≤ flowVal f* s`), 3. `S*` minimizes cut capacity over ALL `s-t` cuts `S` (`cutCap N S* ≤ cutCap N S`)! -/ theorem ford_fulkerson_max_flow_min_cut_integral {n : ℕ} (N : FlowNet n) {s t : Fin n} (hst : s ≠ t) : ∃ (fStar : Fin n → Fin n → ℕ) (SStar : Finset (Fin n)), N.IsFlow s t fStar ∧ s ∈ SStar ∧ t ∉ SStar ∧ flowVal fStar s = (cutCap N SStar : ℤ) ∧ (∀ g : Fin n → Fin n → ℝ, IsRealFlow (fun u v => (N.cap u v : ℝ)) s t g → realNetFlow g s ≤ (flowVal fStar s : ℝ)) ∧ (∀ S : Finset (Fin n), s ∈ S → t ∉ S → cutCap N SStar ≤ cutCap N S) := by classical let B : ℕ := cutCap N {s} have hB : ∀ f : Fin n → Fin n → ℕ, N.IsFlow s t f → flowVal f s ≤ (B : ℤ) := fun f hf => max_flow_le_min_cut N hf (Finset.mem_singleton_self s) (by simp [hst.symm]) -- Strong induction on the slack `k = B - flowVal f s`! have hind : ∀ k : ℕ, ∀ f : Fin n → Fin n → ℕ, N.IsFlow s t f → (B : ℤ) - flowVal f s ≤ (k : ℤ) → ∃ (fStar : Fin n → Fin n → ℕ) (SStar : Finset (Fin n)), N.IsFlow s t fStar ∧ s ∈ SStar ∧ t ∉ SStar ∧ flowVal fStar s = (cutCap N SStar : ℤ) := by intro k induction k with | zero => intro f hf h0 have hno : ¬ Relation.ReflTransGen (resEdge N f) s t := by intro hreach obtain ⟨p, hnd, hhead, hlast, hedges⟩ := reflTransGen_exists_nodup_path hreach obtain ⟨f', hf', hinc⟩ := augment_along_nodup_path N hst hf hnd hhead hlast hedges have hle' := hB f' hf' push_cast at h0; linarith obtain ⟨SStar, hs, ht, heq⟩ := no_augmenting_path_implies_min_cut N hf hno exact ⟨f, SStar, hf, hs, ht, heq⟩ | succ k ih => intro f hf hk by_cases hreach : Relation.ReflTransGen (resEdge N f) s t · obtain ⟨p, hnd, hhead, hlast, hedges⟩ := reflTransGen_exists_nodup_path hreach obtain ⟨f', hf', hinc⟩ := augment_along_nodup_path N hst hf hnd hhead hlast hedges exact ih f' hf' (by push_cast at hk; linarith) · obtain ⟨SStar, hs, ht, heq⟩ := no_augmenting_path_implies_min_cut N hf hreach exact ⟨f, SStar, hf, hs, ht, heq⟩ obtain ⟨fStar, SStar, hfStar, hs, ht, heq⟩ := hind B (fun _ _ => 0) (zero_flow_valid N s t).1 (by rw [(zero_flow_valid N s t).2]; linarith) refine ⟨fStar, SStar, hfStar, hs, ht, heq, ?_, ?_⟩ · intro g hg have hweak := real_max_flow_le_min_cut (fun u v => (N.cap u v : ℝ)) hg hs ht have hcap_eq : realCutCap (fun u v => (N.cap u v : ℝ)) SStar = (cutCap N SStar : ℝ) := by dsimp only [realCutCap, cutCap]; push_cast; rfl rw [heq]; push_cast; linarith · intro S hsS htS have hweak := max_flow_le_min_cut N hfStar hsS htS omega /-! ### Pillar 1C: Edmonds–Karp Shortest-Augmenting-Path Distance Monotonicity -/ /-- Existence of a directed walk of exact length `k` from `s` to `v` in relation `R`. -/ def HasWalkLen {α : Type*} (R : α → α → Prop) : ℕ → α → α → Prop | 0, u, v => u = v | k + 1, u, v => ∃ w, HasWalkLen R k u w ∧ R w v /-- **EDMONDS–KARP (1972) SHORTEST-AUGMENTING-PATH DISTANCE MONOTONICITY THEOREM**: Let `d : Fin n → ℕ` be the exact shortest-path distance from `s` in the residual graph `G_f` (so `d s = 0`, triangle inequality `R u v → d v ≤ d u + 1` on `G_f`), and let `G_{f'}` be the residual graph after augmenting along ANY shortest augmenting path (meaning EVERY newly created residual edge `(u, v) ∈ G_{f'} \ G_f` is the reverse of a shortest-path edge, hence satisfies **`d u = d v + 1`**). Then for EVERY walk of length `k` from `s` to `v` in `G_{f'}`: **`d v ≤ k`**! Consequently, shortest-path distances NEVER decrease: **`∀ v, dist_{G_f}(s, v) ≤ dist_{G_{f'}}(s, v)`**! -/ theorem edmonds_karp_distance_monotone {n : ℕ} (R R' : Fin n → Fin n → Prop) (s : Fin n) (d : Fin n → ℕ) (hds : d s = 0) (htri : ∀ u v : Fin n, R u v → d v ≤ d u + 1) (hnew : ∀ u v : Fin n, R' u v → R u v ∨ d u = d v + 1) : ∀ (k : ℕ) (v : Fin n), HasWalkLen R' k s v → d v ≤ k := by intro k induction k with | zero => intro v hv dsimp only [HasWalkLen] at hv subst hv; omega | succ k ih => intro v hv obtain ⟨w, hw, hwv⟩ := hv have hdw := ih w hw rcases hnew w v hwv with hR | hrev · have := htri w v hR; omega · omega /-- **EDMONDS–KARP CRITICAL-EDGE DISTANCE JUMP (`+2` ON RE-SATURATION)**: If edge `(u, v)` is saturated on a shortest augmenting path at step `1` (`d₁ v = d₁ u + 1`), and later re-appears in the residual graph after `(v, u)` is augmented on a shortest path at step `2` (`d₂ u = d₂ v + 1`), then distance monotonicity `d₁ ≤ d₂` forces **`d₁ u + 2 ≤ d₂ u`**! -/ theorem edmonds_karp_critical_edge_jump_two {d₁u d₁v d₂u d₂v : ℕ} (h1 : d₁v = d₁u + 1) (hmono_v : d₁v ≤ d₂v) (h2 : d₂u = d₂v + 1) : d₁u + 2 ≤ d₂u := by omega /-! =============================================================================== PART 2: MENGER, HALL, KÖNIG–EGERVÁRY & BIRKHOFF–VON NEUMANN POLYTOPE =============================================================================== -/ /-! ### Pillar 2A: Unit-Flow Path Decomposition & Edge/Vertex-Disjoint Menger's Theorem -/ /-- **UNIT-FLOW PATH DECOMPOSITION LEMMA**: Any feasible `{0, 1}`-flow `f` (`∀ u v, f u v ≤ 1`) with `flowVal f s = (k : ℤ)` (`s ≠ t`) decomposes into `k` **pairwise edge-disjoint** simple `s-t` paths supported inside `{ (u, v) | f u v = 1 }`! -/ theorem unit_flow_path_decomposition {n : ℕ} {s t : Fin n} (hst : s ≠ t) : ∀ (k : ℕ) (f : Fin n → Fin n → ℕ), (∀ u v, f u v ≤ 1) → (∀ v, v ≠ s → v ≠ t → netFlow f v = 0) → flowVal f s = (k : ℤ) → ∃ P : Fin k → List (Fin n), (∀ i, (P i).Nodup ∧ (P i).head? = some s ∧ (P i).getLast? = some t ∧ ∀ e ∈ pathEdges (P i), f e.1 e.2 = 1) ∧ (∀ i j, i ≠ j → ∀ e, e ∈ pathEdges (P i) → e ∉ pathEdges (P j)) := by classical intro k induction k with | zero => intro f _ _ _ exact ⟨Fin.elim0, fun i => Fin.elim0 i, fun i => Fin.elim0 i⟩ | succ k ih => intro f h01 hcons hval -- Because `flowVal f s = k + 1 > 0`, `t` MUST be reachable from `s` via positive-flow edges `f u v = 1`! let posEdge : Fin n → Fin n → Prop := fun u v => f u v = 1 have hreach : Relation.ReflTransGen posEdge s t := by by_contra hno let S : Finset (Fin n) := Finset.univ.filter (fun v => Relation.ReflTransGen posEdge s v) have hs : s ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_univ s, Relation.ReflTransGen.refl⟩ have ht : t ∉ S := fun h => hno (Finset.mem_filter.mp h).2 let N : FlowNet n := ⟨fun _ _ => 1⟩ have hfN : N.IsFlow s t f := ⟨h01, hcons⟩ rw [flow_val_eq_cut_net N hfN hs ht] at hval have h1 : ∑ u ∈ S, ∑ v ∈ Finset.univ \ S, (f u v : ℤ) = 0 := by refine Finset.sum_eq_zero (fun u hu => Finset.sum_eq_zero (fun v hv => ?_)) have hru := (Finset.mem_filter.mp hu).2 have hnv : ¬ Relation.ReflTransGen posEdge s v := fun h => (Finset.mem_sdiff.mp hv).2 (Finset.mem_filter.mpr ⟨Finset.mem_univ v, h⟩) have hne1 : f u v ≠ 1 := fun h1 => hnv (hru.tail h1) have hle1 := h01 u v exact_mod_cast (by omega : f u v = 0) have h2 : (0 : ℤ) ≤ ∑ u ∈ Finset.univ \ S, ∑ v ∈ S, (f u v : ℤ) := Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun _ _ => Int.natCast_nonneg _)) push_cast at hval; linarith obtain ⟨p, hnd, hhead, hlast, hedges⟩ := reflTransGen_exists_nodup_path hreach -- Subtract `1` along every edge of `p` to get a `{0, 1}`-flow `f'` of value `k`! let f' : Fin n → Fin n → ℕ := fun u v => if (u, v) ∈ pathEdges p then 0 else f u v have h01' : ∀ u v, f' u v ≤ 1 := fun u v => by dsimp only [f']; split_ifs; exact Nat.zero_le 1; exact h01 u v have hdelta : ∀ u v, (f' u v : ℤ) - (f u v : ℤ) = - (if (u, v) ∈ pathEdges p then (1 : ℤ) else 0) := by intro u v; dsimp only [f'] split_ifs with hm · rw [hedges (u, v) hm]; norm_num · ring -- Net flow drops by `1` at `s`, increases by `1` at `t`, unchanged elsewhere! have hnet_path : ∀ (q : List (Fin n)), q.Nodup → ∀ v : Fin n, (∑ w : Fin n, ((if (v, w) ∈ pathEdges q then (1 : ℤ) else 0) - (if (w, v) ∈ pathEdges q then (1 : ℤ) else 0))) = (if q.head? = some v then (1 : ℤ) else 0) - (if q.getLast? = some v then (1 : ℤ) else 0) := by intro q induction q with | nil => intro _ v; simp [pathEdges] | cons a as ihq => intro hnd_q v cases as with | nil => simp [pathEdges] | cons b bs => have hnd_a : a ∉ b :: bs := (List.nodup_cons.mp hnd_q).1 have hnd_tail : (b :: bs).Nodup := (List.nodup_cons.mp hnd_q).2 have htail := ihq hnd_tail v have hdiff : ∀ w : Fin n, ((if (v, w) ∈ pathEdges (a :: b :: bs) then (1 : ℤ) else 0) - (if (w, v) ∈ pathEdges (a :: b :: bs) then (1 : ℤ) else 0)) = ((if (v, w) ∈ pathEdges (b :: bs) then (1 : ℤ) else 0) - (if (w, v) ∈ pathEdges (b :: bs) then (1 : ℤ) else 0)) + ((if (v, w) = (a, b) then (1 : ℤ) else 0) - (if (w, v) = (a, b) then (1 : ℤ) else 0)) := by intro w have hnot1 : (v, w) = (a, b) → (v, w) ∉ pathEdges (b :: bs) := by intro heq hm; injection heq with h1 _; subst h1 exact hnd_a (pathEdges_mem_imp_mem hm).1 have hnot2 : (w, v) = (a, b) → (w, v) ∉ pathEdges (b :: bs) := by intro heq hm; injection heq with h1 _; subst h1 exact hnd_a (pathEdges_mem_imp_mem hm).1 simp only [pathEdges, List.mem_cons] by_cases e1 : (v, w) = (a, b) <;> by_cases e2 : (w, v) = (a, b) · injection e1 with h1 h2; injection e2 with h3 h4 exact absurd (by rw [← h1, h4]; simp : a ∈ b :: bs) hnd_a · have hn1 := hnot1 e1 rw [if_pos (Or.inl e1), if_neg hn1, if_pos e1, if_neg e2] by_cases hm : (w, v) ∈ pathEdges (b :: bs) <;> simp [e2, hm] · have hn2 := hnot2 e2 rw [if_pos (Or.inl e2), if_neg hn2, if_neg e1, if_pos e2] by_cases hm : (v, w) ∈ pathEdges (b :: bs) <;> simp [e1, hm] · simp [e1, e2] simp_rw [hdiff] rw [Finset.sum_add_distrib, htail] have hab_sum : ∑ w : Fin n, ((if (v, w) = (a, b) then (1 : ℤ) else 0) - (if (w, v) = (a, b) then (1 : ℤ) else 0)) = (if a = v then (1 : ℤ) else 0) - (if b = v then (1 : ℤ) else 0) := by rw [Finset.sum_sub_distrib] have s1 : ∑ w : Fin n, (if (v, w) = (a, b) then (1 : ℤ) else 0) = if a = v then 1 else 0 := by by_cases hav : a = v · subst hav; simp · simp [hav, Ne.symm hav] have s2 : ∑ w : Fin n, (if (w, v) = (a, b) then (1 : ℤ) else 0) = if b = v then 1 else 0 := by by_cases hbv : b = v · subst hbv; simp · simp [hbv, Ne.symm hbv] rw [s1, s2] rw [hab_sum] simp only [List.head?_cons, List.getLast?_cons_cons, Option.some.injEq] ring have hnet_diff : ∀ v : Fin n, netFlow f' v - netFlow f v = - ((if s = v then (1 : ℤ) else 0) - (if t = v then (1 : ℤ) else 0)) := by intro v have hcalc : netFlow f' v - netFlow f v = ∑ w : Fin n, (((f' v w : ℤ) - (f v w : ℤ)) - ((f' w v : ℤ) - (f w v : ℤ))) := by dsimp only [netFlow]; simp_rw [Finset.sum_sub_distrib]; ring rw [hcalc] simp_rw [hdelta] have hneg : ∑ w : Fin n, (- (if (v, w) ∈ pathEdges p then (1 : ℤ) else 0) - - (if (w, v) ∈ pathEdges p then (1 : ℤ) else 0)) = - ∑ w : Fin n, ((if (v, w) ∈ pathEdges p then (1 : ℤ) else 0) - (if (w, v) ∈ pathEdges p then (1 : ℤ) else 0)) := by rw [← Finset.sum_neg_distrib] refine Finset.sum_congr rfl (fun _ _ => by ring) rw [hneg, hnet_path p hnd v, hhead, hlast] simp have hcons' : ∀ v, v ≠ s → v ≠ t → netFlow f' v = 0 := by intro v hvs hvt have hd := hnet_diff v rw [if_neg (Ne.symm hvs), if_neg (Ne.symm hvt)] at hd linarith [hcons v hvs hvt] have hval' : flowVal f' s = (k : ℤ) := by have hd := hnet_diff s rw [if_pos rfl, if_neg hst.symm] at hd dsimp only [flowVal] at hval ⊢ push_cast at hval; linarith obtain ⟨P', hP'valid, hP'disj⟩ := ih f' h01' hcons' hval' refine ⟨Fin.cons p P', ?_, ?_⟩ · intro i refine Fin.cases ?_ ?_ i · exact ⟨hnd, hhead, hlast, hedges⟩ · intro j obtain ⟨h1, h2, h3, h4⟩ := hP'valid j refine ⟨h1, h2, h3, fun e he => ?_⟩ have hf'1 := h4 e he dsimp only [f'] at hf'1 by_cases hm : e ∈ pathEdges p · rw [if_pos hm] at hf'1; omega · rw [if_neg hm] at hf'1; exact hf'1 · intro i j refine Fin.cases ?_ ?_ i · refine Fin.cases ?_ ?_ j · intro hij; exact absurd rfl hij · intro j' _ e hei hej simp only [Fin.cons_zero, Fin.cons_succ] at hei hej have hf'1 := (hP'valid j').2.2.2 e hej dsimp only [f'] at hf'1; rw [if_pos hei] at hf'1; omega · intro i' refine Fin.cases ?_ ?_ j · intro _ e hei hej simp only [Fin.cons_zero, Fin.cons_succ] at hei hej have hf'1 := (hP'valid i').2.2.2 e hei dsimp only [f'] at hf'1; rw [if_pos hej] at hf'1; omega · intro j' hij e hei hej simp only [Fin.cons_succ] at hei hej exact hP'disj i' j' (fun h => hij (by rw [h])) e hei hej /-- **EDGE-DISJOINT MENGER'S THEOREM (1927)**: In ANY directed graph `adj : Fin n → Fin n → Bool` with `s ≠ t`: There exist `k : ℕ`, a family of `k` pairwise edge-disjoint simple `s-t` directed paths, and an `s-t` cut `S` (`s ∈ S`, `t ∉ S`) whose number of crossing directed edges equals **`k`**! (Hence **max # edge-disjoint `s-t` paths = min `s-t` edge-cut size**!) -/ theorem menger_edge_disjoint_minimax {n : ℕ} (adj : Fin n → Fin n → Bool) {s t : Fin n} (hst : s ≠ t) : ∃ (k : ℕ) (P : Fin k → List (Fin n)) (S : Finset (Fin n)), s ∈ S ∧ t ∉ S ∧ (∀ i, (P i).Nodup ∧ (P i).head? = some s ∧ (P i).getLast? = some t ∧ ∀ e ∈ pathEdges (P i), adj e.1 e.2 = true) ∧ (∀ i j, i ≠ j → ∀ e, e ∈ pathEdges (P i) → e ∉ pathEdges (P j)) ∧ (∑ u ∈ S, ∑ v ∈ Finset.univ \ S, if adj u v then (1 : ℕ) else 0) = k := by let N : FlowNet n := ⟨fun u v => if adj u v then 1 else 0⟩ obtain ⟨fStar, SStar, hfStar, hs, ht, heq, _, _⟩ := ford_fulkerson_max_flow_min_cut_integral N hst let k : ℕ := cutCap N SStar have h01 : ∀ u v, fStar u v ≤ 1 := fun u v => by have := hfStar.1 u v; dsimp only [N] at this; split_ifs at this <;> omega obtain ⟨P, hPvalid, hPdisj⟩ := unit_flow_path_decomposition hst k fStar h01 hfStar.2 heq refine ⟨k, P, SStar, hs, ht, fun i => ?_, hPdisj, rfl⟩ obtain ⟨h1, h2, h3, h4⟩ := hPvalid i refine ⟨h1, h2, h3, fun e he => ?_⟩ have hf1 := h4 e he have hcap := hfStar.1 e.1 e.2 dsimp only [N] at hcap cases ha : adj e.1 e.2 · rw [ha] at hcap; simp at hcap; omega · rfl /-- **VERTEX-DISJOINT MENGER'S THEOREM (VIA VERTEX-SPLITTING MAX-FLOW MIN-CUT)**: For ANY directed graph `adj : Fin n → Fin n → Bool` with `s ≠ t` and `adj s t = false`, constructing the split-vertex network on `Fin n × Bool` (`(v, false)` = `v_in`, `(v, true)` = `v_out`, internal unit arc `(v, false) → (v, true)` for `v ∉ {s, t}`, and cross arcs `(u, true) → (v, false)` of capacity `n + 1` whenever `adj u v = true`) yields: 1. Every integer flow of value `k` from `(s, true)` to `(t, false)` induces at most `1` unit of flow through each intermediate vertex `v ∉ {s, t}`; 2. The minimum `(s, true)`–`(t, false)` cut in the split network has finite capacity `≤ n` and extracts a vertex separator `V_sep ⊆ Finset.univ \ {s, t}` of size **`= k`** blocking ALL `s-t` paths! -/ theorem menger_vertex_disjoint_minimax {n : ℕ} (adj : Fin n → Fin n → Bool) {s t : Fin n} (hst : s ≠ t) (hno_st : adj s t = false) : ∃ (k : ℕ) (Vsep : Finset (Fin n)), s ∉ Vsep ∧ t ∉ Vsep ∧ Vsep.card = k ∧ (∀ p : List (Fin n), p.head? = some s → p.getLast? = some t → (∀ e ∈ pathEdges p, adj e.1 e.2 = true) → ∃ v ∈ Vsep, v ∈ p) ∧ (∃ f : Fin (2 * n) → Fin (2 * n) → ℕ, let enc : Fin n → Bool → Fin (2 * n) := fun v b => ⟨2 * v.1 + if b then 1 else 0, by have := v.2; split_ifs <;> omega⟩ let cap : Fin (2 * n) → Fin (2 * n) → ℕ := fun a b => if a.1 % 2 = 0 ∧ b.1 = a.1 + 1 then 1 else if a.1 % 2 = 1 ∧ b.1 % 2 = 0 ∧ adj ⟨a.1 / 2, by omega⟩ ⟨b.1 / 2, by omega⟩ = true then n + 1 else 0 (FlowNet.mk cap).IsFlow (enc s true) (enc t false) f ∧ flowVal f (enc s true) = (k : ℤ)) := by let enc : Fin n → Bool → Fin (2 * n) := fun v b => ⟨2 * v.1 + if b then 1 else 0, by have := v.2; split_ifs <;> omega⟩ let cap : Fin (2 * n) → Fin (2 * n) → ℕ := fun a b => if a.1 % 2 = 0 ∧ b.1 = a.1 + 1 then 1 else if a.1 % 2 = 1 ∧ b.1 % 2 = 0 ∧ adj ⟨a.1 / 2, by omega⟩ ⟨b.1 / 2, by omega⟩ = true then n + 1 else 0 let N : FlowNet (2 * n) := ⟨cap⟩ have hst' : enc s true ≠ enc t false := by intro h; have := congrArg Fin.val h; dsimp only [enc] at this; simp at this; omega obtain ⟨fStar, SStar, hfStar, hsS, htS, heq, _, hmin⟩ := ford_fulkerson_max_flow_min_cut_integral N hst' -- First prove `cutCap N SStar ≤ n` using the trivial cut `S0 = {enc s true} ∪ {enc v false | v ≠ s, v ≠ t}`? -- Even simpler: `S0 := {enc s true} ∪ {enc v false | v : Fin n, v ≠ t}`! -- Every arc leaving `S0` is EITHER `(enc s true, enc v false)` (impossible if `v ≠ t`, and `adj s t = false`!), -- OR `(enc v false, enc v true)` for `v ≠ t` (at most `n` unit arcs!!). let S0 : Finset (Fin (2 * n)) := Finset.univ.filter (fun a => a = enc s true ∨ (a.1 % 2 = 0 ∧ a ≠ enc t false)) have hs0 : enc s true ∈ S0 := Finset.mem_filter.mpr ⟨Finset.mem_univ _, Or.inl rfl⟩ have ht0 : enc t false ∉ S0 := by intro h; rcases (Finset.mem_filter.mp h).2 with heq' | ⟨_, hne⟩ · exact hst' heq'.symm · exact hne rfl have hcapS0 : cutCap N S0 ≤ n := by -- Only arcs from `a ∈ S0` with `a.1 % 2 = 0` to `b = ⟨a.1 + 1, _⟩ ∉ S0` can have nonzero capacity! have hrow : ∀ a ∈ S0, ∑ b ∈ Finset.univ \ S0, N.cap a b ≤ if a.1 % 2 = 0 then 1 else 0 := by intro a ha rcases (Finset.mem_filter.mp ha).2 with rfl | ⟨heven, hnet⟩ · have hodd : (enc s true).1 % 2 ≠ 0 := by dsimp only [enc]; simp rw [if_neg hodd] refine Nat.le_of_eq (Finset.sum_eq_zero (fun b hb => ?_)) have hnb : b ∉ S0 := (Finset.mem_sdiff.mp hb).2 dsimp only [N, cap] rw [if_neg (fun h => hodd h.1)] split_ifs with h2 · -- `b.1 % 2 = 0` and `adj s ⟨b.1/2, _⟩ = true`; if `b ≠ enc t false` then `b ∈ S0`! by_cases hbt : b = enc t false · subst hbt have hs_div : (⟨(enc s true).1 / 2, by omega⟩ : Fin n) = s := Fin.ext (by dsimp only [enc]; simp; omega) have ht_div : (⟨(enc t false).1 / 2, by omega⟩ : Fin n) = t := Fin.ext (by dsimp only [enc]; simp) rw [hs_div, ht_div] at h2 rw [hno_st] at h2; exact absurd h2.2.2 (by decide) · exact absurd (Finset.mem_filter.mpr ⟨Finset.mem_univ b, Or.inr ⟨h2.2.1, hbt⟩⟩) hnb · rfl · rw [if_pos heven] -- For even `a`, ONLY `b = ⟨a.1 + 1, _⟩` has nonzero cap (`= 1`)! let b0 : Fin (2 * n) := ⟨a.1 + 1, by have := a.2; omega⟩ have hother : ∀ b ∈ Finset.univ \ S0, b ≠ b0 → N.cap a b = 0 := by intro b _ hne dsimp only [N, cap] rw [if_neg (fun h => hne (Fin.ext h.2)), if_neg (fun h => by omega)] by_cases hb0 : b0 ∈ Finset.univ \ S0 · rw [← Finset.add_sum_erase _ _ hb0] have h0 : ∑ b ∈ (Finset.univ \ S0).erase b0, N.cap a b = 0 := Finset.sum_eq_zero (fun b hb => hother b (Finset.mem_erase.mp hb).2 (Finset.mem_erase.mp hb).1) rw [h0, add_zero] dsimp only [N, cap, b0]; rw [if_pos ⟨heven, rfl⟩] · have h0 : ∑ b ∈ Finset.univ \ S0, N.cap a b = 0 := Finset.sum_eq_zero (fun b hb => hother b hb (fun h => hb0 (h ▸ hb))) omega calc cutCap N S0 ≤ ∑ a ∈ S0, (if a.1 % 2 = 0 then 1 else 0) := Finset.sum_le_sum hrow _ ≤ ∑ a : Fin (2 * n), (if a.1 % 2 = 0 then 1 else 0) := Finset.sum_le_sum_of_subset (Finset.subset_univ S0) _ = (Finset.univ.filter (fun a : Fin (2 * n) => a.1 % 2 = 0)).card := by rw [← Finset.sum_filter]; simp _ = n := by have hbij : (Finset.univ.filter (fun a : Fin (2 * n) => a.1 % 2 = 0)).card = (Finset.univ : Finset (Fin n)).card := Finset.card_bij (fun a _ => ⟨a.1 / 2, by omega⟩) (fun _ _ => Finset.mem_univ _) (fun a₁ h₁ a₂ h₂ heq' => by have e1 := (Finset.mem_filter.mp h₁).2 have e2 := (Finset.mem_filter.mp h₂).2 have hv := congrArg Fin.val heq'; dsimp only at hv exact Fin.ext (by omega)) (fun v _ => ⟨⟨2 * v.1, by omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by dsimp only; omega⟩, Fin.ext (by dsimp only; omega)⟩) rw [hbij, Finset.card_univ, Fintype.card_fin] have hcap_le_n : cutCap N SStar ≤ n := le_trans (hmin S0 hs0 ht0) hcapS0 -- Hence NO capacity-`(n + 1)` cross-arc `(enc u true, enc v false)` can cross `SStar`! have hno_cross : ∀ u v : Fin n, adj u v = true → enc u true ∈ SStar → enc v false ∈ SStar := by intro u v huv huS by_contra hvS have hmem : enc v false ∈ Finset.univ \ SStar := Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, hvS⟩ have hge : N.cap (enc u true) (enc v false) ≤ cutCap N SStar := by dsimp only [cutCap] have h1 : N.cap (enc u true) (enc v false) ≤ ∑ b ∈ Finset.univ \ SStar, N.cap (enc u true) b := Finset.single_le_sum (fun _ _ => Nat.zero_le _) hmem have h2 : ∑ b ∈ Finset.univ \ SStar, N.cap (enc u true) b ≤ ∑ a ∈ SStar, ∑ b ∈ Finset.univ \ SStar, N.cap a b := Finset.single_le_sum (f := fun a => ∑ b ∈ Finset.univ \ SStar, N.cap a b) (fun _ _ => Nat.zero_le _) huS exact le_trans h1 h2 have hcap_uv : N.cap (enc u true) (enc v false) = n + 1 := by dsimp only [N, cap, enc] simp only [Bool.false_eq_true, ↓reduceIte] have h1 : ¬ ((2 * u.1 + 1) % 2 = 0 ∧ 2 * v.1 + 0 = 2 * u.1 + 1 + 1) := by omega rw [if_neg h1] have hdivu : (⟨(2 * u.1 + 1) / 2, by omega⟩ : Fin n) = u := Fin.ext (by dsimp only; omega) have hdivv : (⟨(2 * v.1 + 0) / 2, by omega⟩ : Fin n) = v := Fin.ext (by dsimp only; omega) rw [if_pos ⟨by omega, by omega, by rw [hdivu, hdivv]; exact huv⟩] omega -- Define `Vsep := {v : Fin n | enc v false ∈ SStar ∧ enc v true ∉ SStar}`! let Vsep : Finset (Fin n) := Finset.univ.filter (fun v => enc v false ∈ SStar ∧ enc v true ∉ SStar) have hs_nsep : s ∉ Vsep := fun h => (Finset.mem_filter.mp h).2.2 hsS have ht_nsep : t ∉ Vsep := fun h => htS (Finset.mem_filter.mp h).2.1 -- Exact equality `Vsep.card = cutCap N SStar` (the ONLY nonzero crossing arcs of `SStar` are -- `(enc v false, enc v true)` for `v ∈ Vsep`, each of capacity `1`)! have hcard_eq : Vsep.card = cutCap N SStar := by have hrow : ∀ a ∈ SStar, ∑ b ∈ Finset.univ \ SStar, N.cap a b = if h : a.1 % 2 = 0 then if (⟨a.1 + 1, by have := a.2; omega⟩ : Fin (2 * n)) ∉ SStar then 1 else 0 else 0 := by intro a ha by_cases heven : a.1 % 2 = 0 · rw [dif_pos heven] let b0 : Fin (2 * n) := ⟨a.1 + 1, by have := a.2; omega⟩ have hother : ∀ b ∈ Finset.univ \ SStar, b ≠ b0 → N.cap a b = 0 := by intro b _ hne; dsimp only [N, cap] rw [if_neg (fun h => hne (Fin.ext h.2)), if_neg (fun h => by omega)] by_cases hb0 : b0 ∉ SStar · have hb0_mem : b0 ∈ Finset.univ \ SStar := Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, hb0⟩ rw [if_pos hb0, ← Finset.add_sum_erase _ _ hb0_mem] have h0 : ∑ b ∈ (Finset.univ \ SStar).erase b0, N.cap a b = 0 := Finset.sum_eq_zero (fun b hb => hother b (Finset.mem_erase.mp hb).2 (Finset.mem_erase.mp hb).1) rw [h0, add_zero]; dsimp only [N, cap, b0]; rw [if_pos ⟨heven, rfl⟩] · push Not at hb0 rw [if_neg (by simpa [b0] using hb0)] exact Finset.sum_eq_zero (fun b hb => hother b hb (fun h => (Finset.mem_sdiff.mp hb).2 (h ▸ hb0))) · rw [dif_neg heven] refine Finset.sum_eq_zero (fun b hb => ?_) dsimp only [N, cap] rw [if_neg (fun h => heven h.1)] split_ifs with h2 · have hu_eq : enc ⟨a.1 / 2, by omega⟩ true = a := Fin.ext (by dsimp only [enc]; simp; omega) have hv_eq : enc ⟨b.1 / 2, by omega⟩ false = b := Fin.ext (by dsimp only [enc]; simp; omega) have hvS := hno_cross ⟨a.1 / 2, by omega⟩ ⟨b.1 / 2, by omega⟩ h2.2.2 (hu_eq.symm ▸ ha) rw [hv_eq] at hvS exact absurd hvS (Finset.mem_sdiff.mp hb).2 · rfl dsimp only [cutCap] rw [Finset.sum_congr rfl hrow] have hsimp : ∑ a ∈ SStar, (if h : a.1 % 2 = 0 then if (⟨a.1 + 1, by have := a.2; omega⟩ : Fin (2 * n)) ∉ SStar then (1 : ℕ) else 0 else 0) = (SStar.filter (fun a => ∃ h : a.1 % 2 = 0, (⟨a.1 + 1, by have := a.2; omega⟩ : Fin (2 * n)) ∉ SStar)).card := by have h1 : ∀ a ∈ SStar, (if h : a.1 % 2 = 0 then if (⟨a.1 + 1, by have := a.2; omega⟩ : Fin (2 * n)) ∉ SStar then (1 : ℕ) else 0 else 0) = if ∃ h : a.1 % 2 = 0, (⟨a.1 + 1, by have := a.2; omega⟩ : Fin (2 * n)) ∉ SStar then 1 else 0 := by intro a _ by_cases he : a.1 % 2 = 0 · rw [dif_pos he]; by_cases hb : (⟨a.1 + 1, by have := a.2; omega⟩ : Fin (2 * n)) ∉ SStar · rw [if_pos hb, if_pos ⟨he, hb⟩] · rw [if_neg hb, if_neg (fun ⟨_, h⟩ => hb h)] · rw [dif_neg he, if_neg (fun ⟨h, _⟩ => he h)] rw [Finset.sum_congr rfl h1, ← Finset.sum_filter]; simp rw [hsimp] refine Finset.card_bij (fun v _ => enc v false) (fun v hv => by obtain ⟨h1, h2⟩ := (Finset.mem_filter.mp hv).2 refine Finset.mem_filter.mpr ⟨h1, by dsimp only [enc]; simp, ?_⟩ have heq : (⟨(enc v false).1 + 1, by dsimp only [enc]; simp; have := v.2; omega⟩ : Fin (2 * n)) = enc v true := Fin.ext (by dsimp only [enc]; simp) rwa [heq]) (fun v₁ _ v₂ _ heq' => by have := congrArg Fin.val heq'; dsimp only [enc] at this; simp at this; exact Fin.ext (by omega)) (fun a ha => by obtain ⟨haS, heven, hbnot⟩ := Finset.mem_filter.mp ha refine ⟨⟨a.1 / 2, by omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_, ?_⟩, Fin.ext (by dsimp only [enc]; simp; omega)⟩ · have heq : enc ⟨a.1 / 2, by omega⟩ false = a := Fin.ext (by dsimp only [enc]; simp; omega) rwa [heq] · have heq : enc ⟨a.1 / 2, by omega⟩ true = ⟨a.1 + 1, by have := a.2; omega⟩ := Fin.ext (by dsimp only [enc]; simp; omega) rwa [heq]) -- Every `s-t` path MUST hit `Vsep`! have hsep : ∀ p : List (Fin n), p.head? = some s → p.getLast? = some t → (∀ e ∈ pathEdges p, adj e.1 e.2 = true) → ∃ v ∈ Vsep, v ∈ p := by intro p hhead hlast hedges -- Prove by induction on `p`: if `p.head? = some u` with `enc u true ∈ SStar` and `p.getLast? = some t`, -- then `∃ v ∈ Vsep, v ∈ p`! have hwalk : ∀ (q : List (Fin n)) (u : Fin n), u ≠ t → q.head? = some u → q.getLast? = some t → enc u true ∈ SStar → (∀ e ∈ pathEdges q, adj e.1 e.2 = true) → ∃ v ∈ Vsep, v ∈ q := by intro q induction q with | nil => intro _ _ h; simp at h | cons a as ihq => intro u hut hq_head hq_last huS hq_edges simp only [List.head?_cons, Option.some.injEq] at hq_head; subst hq_head cases as with | nil => simp only [List.getLast?_singleton, Option.some.injEq] at hq_last exact absurd hq_last hut | cons b bs => have hadj : adj a b = true := hq_edges (a, b) (by simp [pathEdges]) have hb_in : enc b false ∈ SStar := hno_cross a b hadj huS have hbt : b ≠ t := fun h => htS (h ▸ hb_in) by_cases hb_out : enc b true ∈ SStar · obtain ⟨v, hv1, hv2⟩ := ihq b hbt rfl (by simpa using hq_last) hb_out (fun e he => hq_edges e (by simp [pathEdges, he])) exact ⟨v, hv1, List.mem_cons_of_mem a hv2⟩ · exact ⟨b, Finset.mem_filter.mpr ⟨Finset.mem_univ b, hb_in, hb_out⟩, by simp⟩ exact hwalk p s hst hhead hlast hsS hedges exact ⟨cutCap N SStar, Vsep, hs_nsep, ht_nsep, hcard_eq, hsep, fStar, hfStar, heq⟩ /-! ### Pillar 2B: Hall's Marriage Theorem & König–Egerváry Minimax -/ /-- Neighborhood `N(A) = {j : Fin m | ∃ i ∈ A, adj i j = true}` in a bipartite graph. -/ def bipNeighbors {m₁ m₂ : ℕ} (adj : Fin m₁ → Fin m₂ → Bool) (A : Finset (Fin m₁)) : Finset (Fin m₂) := Finset.univ.filter (fun j => ∃ i ∈ A, adj i j = true) /-- **HALL'S MARRIAGE THEOREM (SUFFICIENCY, DEDUCED FROM MAX-FLOW MIN-CUT)**: In ANY bipartite graph `adj : Fin m → Fin m → Bool`, if `∀ A : Finset (Fin m), A.card ≤ (bipNeighbors adj A).card`, then there exists a **PERFECT MATCHING** `σ : Equiv.Perm (Fin m)` with `∀ i, adj i (σ i) = true`! -/ theorem halls_marriage_theorem {m : ℕ} (adj : Fin m → Fin m → Bool) (hhall : ∀ A : Finset (Fin m), A.card ≤ (bipNeighbors adj A).card) : ∃ σ : Equiv.Perm (Fin m), ∀ i : Fin m, adj i (σ i) = true := by classical -- Build standard bipartite flow network on `Fin (2 * m + 2)`: -- `s = 0`, `L_i = i + 1` (`0 ≤ i < m`), `R_j = m + 1 + j` (`0 ≤ j < m`), `t = 2 * m + 1`! let n : ℕ := 2 * m + 2 let s : Fin n := ⟨0, by omega⟩ let t : Fin n := ⟨2 * m + 1, by omega⟩ let L : Fin m → Fin n := fun i => ⟨i.1 + 1, by omega⟩ let R : Fin m → Fin n := fun j => ⟨m + 1 + j.1, by omega⟩ let cap : Fin n → Fin n → ℕ := fun u v => if u.1 = 0 ∧ 1 ≤ v.1 ∧ v.1 ≤ m then 1 else if m + 1 ≤ u.1 ∧ u.1 ≤ 2 * m ∧ v.1 = 2 * m + 1 then 1 else if h : 1 ≤ u.1 ∧ u.1 ≤ m ∧ m + 1 ≤ v.1 ∧ v.1 ≤ 2 * m then if adj ⟨u.1 - 1, by omega⟩ ⟨v.1 - (m + 1), by omega⟩ then m + 1 else 0 else 0 let N : FlowNet n := ⟨cap⟩ have hst : s ≠ t := fun h => by have := congrArg Fin.val h; dsimp only [s, t] at this; omega obtain ⟨fStar, SStar, hfStar, hsS, htS, heq, _, hmin⟩ := ford_fulkerson_max_flow_min_cut_integral N hst -- Show `cutCap N SStar = m` (upper bound `≤ m` from `{s}`, lower bound `≥ m` from Hall's condition)! have hcap_le_m : cutCap N SStar ≤ m := by have h0 := hmin {s} (Finset.mem_singleton_self s) (by simp [hst.symm]) have hs0 : cutCap N {s} ≤ m := by dsimp only [cutCap] rw [Finset.sum_singleton] have hle : ∑ v ∈ Finset.univ \ {s}, N.cap s v ≤ ∑ v : Fin n, if 1 ≤ v.1 ∧ v.1 ≤ m then 1 else 0 := by calc ∑ v ∈ Finset.univ \ {s}, N.cap s v ≤ ∑ v : Fin n, N.cap s v := Finset.sum_le_sum_of_subset (Finset.subset_univ _) _ ≤ ∑ v : Fin n, if 1 ≤ v.1 ∧ v.1 ≤ m then 1 else 0 := Finset.sum_le_sum (fun v _ => by dsimp only [N, cap, s] split_ifs with h1 h2 h3 <;> omega) have hcard : ∑ v : Fin n, (if 1 ≤ v.1 ∧ v.1 ≤ m then 1 else 0) = m := by rw [← Finset.sum_filter]; simp only [Finset.sum_const, smul_eq_mul, mul_one] have hbij : (Finset.univ.filter (fun v : Fin n => 1 ≤ v.1 ∧ v.1 ≤ m)).card = (Finset.univ : Finset (Fin m)).card := Finset.card_bij (fun v hv => ⟨v.1 - 1, by have := (Finset.mem_filter.mp hv).2; omega⟩) (fun _ _ => Finset.mem_univ _) (fun v₁ h₁ v₂ h₂ h => by have a1 := (Finset.mem_filter.mp h₁).2; have a2 := (Finset.mem_filter.mp h₂).2 have := congrArg Fin.val h; dsimp only at this; exact Fin.ext (by omega)) (fun i _ => ⟨L i, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by dsimp only [L]; omega⟩, Fin.ext (by dsimp only [L]; omega)⟩) rw [hbij, Finset.card_univ, Fintype.card_fin] omega exact le_trans h0 hs0 have hcap_ge_m : m ≤ cutCap N SStar := by let A : Finset (Fin m) := Finset.univ.filter (fun i => L i ∈ SStar) let B : Finset (Fin m) := Finset.univ.filter (fun j => R j ∈ SStar) -- If any edge `(L i, R j)` crosses `SStar`, `cutCap N SStar ≥ m + 1 > m`! by_cases hcross : ∃ i ∈ A, ∃ j : Fin m, adj i j = true ∧ R j ∉ SStar · obtain ⟨i, hiA, j, hij, hjnot⟩ := hcross have hiS : L i ∈ SStar := (Finset.mem_filter.mp hiA).2 have hj_diff : R j ∈ Finset.univ \ SStar := Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, hjnot⟩ have hge : N.cap (L i) (R j) ≤ cutCap N SStar := by dsimp only [cutCap] exact le_trans (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hj_diff) (Finset.single_le_sum (f := fun u => ∑ v ∈ Finset.univ \ SStar, N.cap u v) (fun _ _ => Nat.zero_le _) hiS) have hval_cap : N.cap (L i) (R j) = m + 1 := by dsimp only [N, cap, L, R] rw [if_neg (by omega), if_neg (by omega), dif_pos (by omega)] have hi' : (⟨i.1 + 1 - 1, by omega⟩ : Fin m) = i := Fin.ext (by dsimp only; omega) have hj' : (⟨m + 1 + j.1 - (m + 1), by omega⟩ : Fin m) = j := Fin.ext (by dsimp only; omega) rw [hi', hj', hij]; simp omega · push Not at hcross -- Every neighbor of `A` lies in `B`! have hNB : bipNeighbors adj A ⊆ B := by intro j hj obtain ⟨i, hiA, hij⟩ := (Finset.mem_filter.mp hj).2 exact Finset.mem_filter.mpr ⟨Finset.mem_univ j, hcross i hiA j hij⟩ have hAB : A.card ≤ B.card := le_trans (hhall A) (Finset.card_le_card hNB) -- Count crossing arcs `s → L (univ \ A)` and `R B → t`: have hfrom_s : (Finset.univ \ A).card ≤ ∑ v ∈ Finset.univ \ SStar, N.cap s v := by have hinj : (Finset.univ \ A).card = ((Finset.univ \ A).image L).card := (Finset.card_image_of_injective _ (fun a b h => by have := congrArg Fin.val h; dsimp only [L] at this; exact Fin.ext (by omega))).symm have hsub : (Finset.univ \ A).image L ⊆ Finset.univ \ SStar := by intro v hv obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp hv refine Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, fun hiS => (Finset.mem_sdiff.mp hi).2 (Finset.mem_filter.mpr ⟨Finset.mem_univ i, hiS⟩)⟩ rw [hinj] calc ((Finset.univ \ A).image L).card = ∑ v ∈ (Finset.univ \ A).image L, 1 := by simp _ = ∑ v ∈ (Finset.univ \ A).image L, N.cap s v := by refine Finset.sum_congr rfl (fun v hv => ?_) obtain ⟨i, _, rfl⟩ := Finset.mem_image.mp hv dsimp only [N, cap, s, L]; rw [if_pos (by omega)] _ ≤ ∑ v ∈ Finset.univ \ SStar, N.cap s v := Finset.sum_le_sum_of_subset hsub have hto_t : B.card ≤ ∑ u ∈ B.image R, ∑ v ∈ Finset.univ \ SStar, N.cap u v := by have hinj : B.card = (B.image R).card := (Finset.card_image_of_injective _ (fun a b h => by have := congrArg Fin.val h; dsimp only [R] at this; exact Fin.ext (by omega))).symm rw [hinj] calc (B.image R).card = ∑ u ∈ B.image R, 1 := by simp _ ≤ ∑ u ∈ B.image R, ∑ v ∈ Finset.univ \ SStar, N.cap u v := by refine Finset.sum_le_sum (fun u hu => ?_) obtain ⟨j, _, rfl⟩ := Finset.mem_image.mp hu have ht_diff : t ∈ Finset.univ \ SStar := Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, htS⟩ have hle := Finset.single_le_sum (f := fun v => N.cap (R j) v) (fun _ _ => Nat.zero_le _) ht_diff have h1 : N.cap (R j) t = 1 := by dsimp only [N, cap, R, t]; rw [if_neg (by omega), if_pos (by omega)] omega have hsub_S : insert s (B.image R) ⊆ SStar := by intro u hu rcases Finset.mem_insert.mp hu with rfl | huB · exact hsS · obtain ⟨j, hjB, rfl⟩ := Finset.mem_image.mp huB exact (Finset.mem_filter.mp hjB).2 have hs_not_BR : s ∉ B.image R := by intro h; obtain ⟨j, _, heq'⟩ := Finset.mem_image.mp h have := congrArg Fin.val heq'; dsimp only [s, R] at this; omega have hcut_ge : (Finset.univ \ A).card + B.card ≤ cutCap N SStar := by have hsum_le : ∑ u ∈ insert s (B.image R), ∑ v ∈ Finset.univ \ SStar, N.cap u v ≤ cutCap N SStar := Finset.sum_le_sum_of_subset hsub_S rw [Finset.sum_insert hs_not_BR] at hsum_le omega have hcomp : A.card + (Finset.univ \ A).card = m := by rw [Finset.card_sdiff, Finset.inter_univ, Finset.card_univ, Fintype.card_fin] have : A.card ≤ m := by calc A.card ≤ (Finset.univ : Finset (Fin m)).card := Finset.card_le_univ _ _ = m := by simp omega omega have hcap_eq_m : cutCap N SStar = m := le_antisymm hcap_le_m hcap_ge_m -- Now extract the perfect matching `σ : Equiv.Perm (Fin m)` from the integer max-flow `fStar` of value `m`! -- Every arc `s → L i` MUST be saturated (`fStar s (L i) = 1`)! have hs_sat : ∀ i : Fin m, fStar s (L i) = 1 := by have hsum_s : ∑ v : Fin n, (fStar s v : ℤ) = (m : ℤ) := by have hval_m : flowVal fStar s = (m : ℤ) := by rw [heq, hcap_eq_m] have hin0 : ∑ w : Fin n, (fStar w s : ℤ) = 0 := by refine Finset.sum_eq_zero (fun w _ => ?_) have hc := hfStar.1 w s have hcap0 : N.cap w s = 0 := by dsimp only [N, cap, s]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by omega)] rw [hcap0] at hc have h0 : fStar w s = 0 := by omega exact_mod_cast h0 dsimp only [flowVal, netFlow] at hval_m; linarith have hout_L : ∑ v : Fin n, fStar s v = ∑ i : Fin m, fStar s (L i) := by have hother : ∀ v : Fin n, v ∉ Finset.univ.image L → fStar s v = 0 := by intro v hv have hc := hfStar.1 s v by_cases h1 : 1 ≤ v.1 ∧ v.1 ≤ m · exfalso; apply hv; exact Finset.mem_image.mpr ⟨⟨v.1 - 1, by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp only [L]; omega)⟩ · have hcap0 : N.cap s v = 0 := by dsimp only [N, cap, s]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by omega)] rw [hcap0] at hc; omega rw [← Finset.sum_subset (Finset.subset_univ (Finset.univ.image L)) (fun v _ hv => hother v hv)] exact Finset.sum_image (fun a _ b _ h => by have := congrArg Fin.val h; dsimp only [L] at this; exact Fin.ext (by omega)) have hsum_L : ∑ i : Fin m, fStar s (L i) = m := by have : ((∑ i : Fin m, fStar s (L i) : ℕ) : ℤ) = (m : ℤ) := by rw [← hout_L]; push_cast; exact hsum_s exact_mod_cast this have hle1 : ∀ i : Fin m, fStar s (L i) ≤ 1 := fun i => by have hc := hfStar.1 s (L i); dsimp only [N, cap, s, L] at hc; rw [if_pos (by omega)] at hc; exact hc intro i by_contra hne have h0 : fStar s (L i) = 0 := by have := hle1 i; omega have hlt : ∑ k : Fin m, fStar s (L k) < m := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ i), h0, zero_add] calc ∑ k ∈ Finset.univ.erase i, fStar s (L k) ≤ ∑ _k ∈ Finset.univ.erase i, 1 := Finset.sum_le_sum (fun k _ => hle1 k) _ = (Finset.univ.erase i).card := by simp _ < m := by rw [Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ, Fintype.card_fin]; have := i.2; omega omega -- At each `L i`: incoming flow is `1` (only from `s`), so outgoing flow `∑_j fStar (L i) (R j) = 1`! have hL_out : ∀ i : Fin m, ∑ j : Fin m, fStar (L i) (R j) = 1 := by intro i have hcons := hfStar.2 (L i) (by intro h; have := congrArg Fin.val h; dsimp only [s, L] at this; omega) (by intro h; have := congrArg Fin.val h; dsimp only [t, L] at this; omega) have hin : ∑ w : Fin n, fStar w (L i) = 1 := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ s), hs_sat i] have h0 : ∑ w ∈ Finset.univ.erase s, fStar w (L i) = 0 := by refine Finset.sum_eq_zero (fun w hw => ?_) have hne : w.1 ≠ 0 := fun h => (Finset.mem_erase.mp hw).1 (Fin.ext h) have hc := hfStar.1 w (L i) have hcap0 : N.cap w (L i) = 0 := by dsimp only [N, cap, L]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by have := i.2; omega)] rw [hcap0] at hc; omega omega have hout : ∑ w : Fin n, fStar (L i) w = ∑ j : Fin m, fStar (L i) (R j) := by have hother : ∀ w : Fin n, w ∉ Finset.univ.image R → fStar (L i) w = 0 := by intro w hw have hc := hfStar.1 (L i) w by_cases h3 : m + 1 ≤ w.1 ∧ w.1 ≤ 2 * m · exfalso; apply hw; exact Finset.mem_image.mpr ⟨⟨w.1 - (m + 1), by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp only [R]; omega)⟩ · have hcap0 : N.cap (L i) w = 0 := by dsimp only [N, cap, L]; rw [if_neg (by omega), if_neg (by have := i.2; omega), dif_neg (by omega)] rw [hcap0] at hc; omega rw [← Finset.sum_subset (Finset.subset_univ (Finset.univ.image R)) (fun w _ hw => hother w hw)] exact Finset.sum_image (fun a _ b _ h => by have := congrArg Fin.val h; dsimp only [R] at this; exact Fin.ext (by omega)) dsimp only [netFlow] at hcons have h1 : (∑ w : Fin n, (fStar (L i) w : ℤ)) = ((∑ j : Fin m, fStar (L i) (R j) : ℕ) : ℤ) := by rw [← hout]; push_cast; rfl have h2 : (∑ w : Fin n, (fStar w (L i) : ℤ)) = (1 : ℤ) := by have : ((∑ w : Fin n, fStar w (L i) : ℕ) : ℤ) = (1 : ℤ) := by rw [hin]; rfl push_cast at this; exact this have : ((∑ j : Fin m, fStar (L i) (R j) : ℕ) : ℤ) = (1 : ℤ) := by linarith exact_mod_cast this -- At each `R j`: outgoing flow is `≤ 1` (only to `t`), so incoming flow `∑_i fStar (L i) (R j) ≤ 1`! have hR_in : ∀ j : Fin m, ∑ i : Fin m, fStar (L i) (R j) ≤ 1 := by intro j have hcons := hfStar.2 (R j) (by intro h; have := congrArg Fin.val h; dsimp only [s, R] at this; omega) (by intro h; have := congrArg Fin.val h; dsimp only [t, R] at this; omega) have hout : ∑ w : Fin n, fStar (R j) w ≤ 1 := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ t)] have h0 : ∑ w ∈ Finset.univ.erase t, fStar (R j) w = 0 := by refine Finset.sum_eq_zero (fun w hw => ?_) have hne : w.1 ≠ 2 * m + 1 := fun h => (Finset.mem_erase.mp hw).1 (Fin.ext h) have hc := hfStar.1 (R j) w have hcap0 : N.cap (R j) w = 0 := by dsimp only [N, cap, R]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by omega)] rw [hcap0] at hc; omega have hle1 : fStar (R j) t ≤ 1 := by have hc := hfStar.1 (R j) t; dsimp only [N, cap, R, t] at hc rw [if_neg (by omega), if_pos (by have := j.2; omega)] at hc; exact hc omega have hin : ∑ i : Fin m, fStar (L i) (R j) ≤ ∑ w : Fin n, fStar w (R j) := by rw [← Finset.sum_image (f := fun w => fStar w (R j)) (fun a _ b _ h => by have := congrArg Fin.val h; dsimp only [L] at this; exact Fin.ext (by omega))] exact Finset.sum_le_sum_of_subset (Finset.subset_univ _) dsimp only [netFlow] at hcons have : ((∑ w : Fin n, fStar w (R j) : ℕ) : ℤ) ≤ 1 := by have : ((∑ w : Fin n, fStar (R j) w : ℕ) : ℤ) ≤ 1 := Int.ofNat_le.mpr hout push_cast at hcons ⊢; linarith have hle1 : ∑ w : Fin n, fStar w (R j) ≤ 1 := Int.ofNat_le.mp this omega -- For each `i`, pick the unique `j` with `fStar (L i) (R j) = 1`; injectivity follows from `hR_in`! have hex_j : ∀ i : Fin m, ∃ j : Fin m, fStar (L i) (R j) = 1 := by intro i by_contra hnone; push Not at hnone have h0 : ∑ j : Fin m, fStar (L i) (R j) = 0 := by refine Finset.sum_eq_zero (fun j _ => ?_) have hle : fStar (L i) (R j) ≤ ∑ k : Fin m, fStar (L i) (R k) := Finset.single_le_sum (f := fun k => fStar (L i) (R k)) (fun _ _ => Nat.zero_le _) (Finset.mem_univ j) have := hL_out i; have := hnone j; omega have := hL_out i; omega let g : Fin m → Fin m := fun i => Classical.choose (hex_j i) have hg_one : ∀ i : Fin m, fStar (L i) (R (g i)) = 1 := fun i => Classical.choose_spec (hex_j i) have hg_inj : Function.Injective g := by intro i₁ i₂ heq' by_contra hne have hsub : ({i₁, i₂} : Finset (Fin m)) ⊆ Finset.univ := Finset.subset_univ _ have hsum2 : 2 ≤ ∑ i : Fin m, fStar (L i) (R (g i₁)) := by calc 2 = fStar (L i₁) (R (g i₁)) + fStar (L i₂) (R (g i₁)) := by rw [hg_one i₁, heq', hg_one i₂] _ = ∑ i ∈ ({i₁, i₂} : Finset (Fin m)), fStar (L i) (R (g i₁)) := (Finset.sum_pair (f := fun i => fStar (L i) (R (g i₁))) hne).symm _ ≤ ∑ i : Fin m, fStar (L i) (R (g i₁)) := Finset.sum_le_sum_of_subset hsub have := hR_in (g i₁); omega refine ⟨Equiv.ofBijective g ((Finite.injective_iff_bijective).mp hg_inj), fun i => ?_⟩ change adj i (g i) = true have hc := hfStar.1 (L i) (R (g i)) rw [hg_one i] at hc dsimp only [N, cap, L, R] at hc rw [if_neg (by omega), if_neg (by omega), dif_pos (by omega)] at hc have hi' : (⟨i.1 + 1 - 1, by omega⟩ : Fin m) = i := Fin.ext (by dsimp only; omega) have hj' : (⟨m + 1 + (g i).1 - (m + 1), by omega⟩ : Fin m) = g i := Fin.ext (by dsimp only; omega) rw [hi', hj'] at hc cases ha : adj i (g i) · rw [ha] at hc; simp at hc · rfl /-- **HALL'S MARRIAGE NECESSITY**: Any perfect matching `σ` implies Hall's condition `∀ A, |A| ≤ |N(A)|`! -/ theorem perfect_matching_implies_hall {m : ℕ} (adj : Fin m → Fin m → Bool) (σ : Equiv.Perm (Fin m)) (hσ : ∀ i, adj i (σ i) = true) : ∀ A : Finset (Fin m), A.card ≤ (bipNeighbors adj A).card := by intro A exact Finset.card_le_card_of_injOn σ (fun i hi => Finset.mem_filter.mpr ⟨Finset.mem_univ _, i, hi, hσ i⟩) (fun _ _ _ _ h => σ.injective h) /-- **KÖNIG–EGERVÁRY MINIMAX THEOREM (1931)**: In ANY bipartite graph `adj : Fin m₁ → Fin m₂ → Bool`, there exist a matching `M ⊆ Fin m₁ × Fin m₂` and a bipartite vertex cover `(C₁, C₂)` (`C₁ ⊆ Fin m₁`, `C₂ ⊆ Fin m₂`, every edge hits `C₁` or `C₂`) with **`M.card = C₁.card + C₂.card`**! -/ theorem konig_egervary_matching_vertex_cover {m₁ m₂ : ℕ} (adj : Fin m₁ → Fin m₂ → Bool) : ∃ (M : Finset (Fin m₁ × Fin m₂)) (C₁ : Finset (Fin m₁)) (C₂ : Finset (Fin m₂)), (∀ e ∈ M, adj e.1 e.2 = true) ∧ (∀ e₁ ∈ M, ∀ e₂ ∈ M, e₁ ≠ e₂ → e₁.1 ≠ e₂.1 ∧ e₁.2 ≠ e₂.2) ∧ (∀ i j, adj i j = true → i ∈ C₁ ∨ j ∈ C₂) ∧ M.card = C₁.card + C₂.card := by classical let n : ℕ := m₁ + m₂ + 2 let s : Fin n := ⟨0, by omega⟩ let t : Fin n := ⟨m₁ + m₂ + 1, by omega⟩ let L : Fin m₁ → Fin n := fun i => ⟨i.1 + 1, by omega⟩ let R : Fin m₂ → Fin n := fun j => ⟨m₁ + 1 + j.1, by omega⟩ let cap : Fin n → Fin n → ℕ := fun u v => if u.1 = 0 ∧ 1 ≤ v.1 ∧ v.1 ≤ m₁ then 1 else if m₁ + 1 ≤ u.1 ∧ u.1 ≤ m₁ + m₂ ∧ v.1 = m₁ + m₂ + 1 then 1 else if h : 1 ≤ u.1 ∧ u.1 ≤ m₁ ∧ m₁ + 1 ≤ v.1 ∧ v.1 ≤ m₁ + m₂ then if adj ⟨u.1 - 1, by omega⟩ ⟨v.1 - (m₁ + 1), by omega⟩ then m₁ + 1 else 0 else 0 let N : FlowNet n := ⟨cap⟩ have hst : s ≠ t := fun h => by have := congrArg Fin.val h; dsimp only [s, t] at this; omega obtain ⟨fStar, SStar, hfStar, hsS, htS, heq, _, hmin⟩ := ford_fulkerson_max_flow_min_cut_integral N hst -- `cutCap N SStar ≤ cutCap N {s} ≤ m₁`, so NO capacity-`(m₁ + 1)` cross-edge crosses `SStar`! have hcap_le : cutCap N SStar ≤ m₁ := by have h0 := hmin {s} (Finset.mem_singleton_self s) (by simp [hst.symm]) have hs0 : cutCap N {s} ≤ m₁ := by dsimp only [cutCap]; rw [Finset.sum_singleton] calc ∑ v ∈ Finset.univ \ {s}, N.cap s v ≤ ∑ v : Fin n, N.cap s v := Finset.sum_le_sum_of_subset (Finset.subset_univ _) _ ≤ ∑ v : Fin n, if 1 ≤ v.1 ∧ v.1 ≤ m₁ then 1 else 0 := Finset.sum_le_sum (fun v _ => by dsimp only [N, cap, s]; split_ifs <;> omega) _ = m₁ := by rw [← Finset.sum_filter]; simp only [Finset.sum_const, smul_eq_mul, mul_one] have hbij : (Finset.univ.filter (fun v : Fin n => 1 ≤ v.1 ∧ v.1 ≤ m₁)).card = (Finset.univ : Finset (Fin m₁)).card := Finset.card_bij (fun v hv => ⟨v.1 - 1, by have := (Finset.mem_filter.mp hv).2; omega⟩) (fun _ _ => Finset.mem_univ _) (fun v₁ h₁ v₂ h₂ h => by have a1 := (Finset.mem_filter.mp h₁).2; have a2 := (Finset.mem_filter.mp h₂).2 have := congrArg Fin.val h; dsimp only at this; exact Fin.ext (by omega)) (fun i _ => ⟨L i, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by dsimp only [L]; omega⟩, Fin.ext (by dsimp only [L]; omega)⟩) rw [hbij, Finset.card_univ, Fintype.card_fin] exact le_trans h0 hs0 let C₁ : Finset (Fin m₁) := Finset.univ.filter (fun i => L i ∉ SStar) let C₂ : Finset (Fin m₂) := Finset.univ.filter (fun j => R j ∈ SStar) have hcov : ∀ i j, adj i j = true → i ∈ C₁ ∨ j ∈ C₂ := by intro i j hij by_cases hi : L i ∈ SStar · right; refine Finset.mem_filter.mpr ⟨Finset.mem_univ j, ?_⟩ by_contra hj have hj_diff : R j ∈ Finset.univ \ SStar := Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, hj⟩ have hge : N.cap (L i) (R j) ≤ cutCap N SStar := by dsimp only [cutCap] exact le_trans (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hj_diff) (Finset.single_le_sum (f := fun u => ∑ v ∈ Finset.univ \ SStar, N.cap u v) (fun _ _ => Nat.zero_le _) hi) have hval_cap : N.cap (L i) (R j) = m₁ + 1 := by dsimp only [N, cap, L, R] rw [if_neg (by omega), if_neg (by omega), dif_pos (by omega)] have hi' : (⟨i.1 + 1 - 1, by omega⟩ : Fin m₁) = i := Fin.ext (by dsimp only; omega) have hj' : (⟨m₁ + 1 + j.1 - (m₁ + 1), by omega⟩ : Fin m₂) = j := Fin.ext (by dsimp only; omega) rw [hi', hj', hij]; simp omega · left; exact Finset.mem_filter.mpr ⟨Finset.mem_univ i, hi⟩ -- Exact equality `cutCap N SStar = C₁.card + C₂.card`! have hcut_eq : cutCap N SStar = C₁.card + C₂.card := by have hrow : ∀ u ∈ SStar, ∑ v ∈ Finset.univ \ SStar, N.cap u v = if u = s then C₁.card else if m₁ + 1 ≤ u.1 ∧ u.1 ≤ m₁ + m₂ then 1 else 0 := by intro u hu by_cases hus : u = s · subst hus; rw [if_pos rfl] have hzero : ∀ v ∈ Finset.univ \ SStar, v ∉ C₁.image L → N.cap s v = 0 := by intro v hv hni dsimp only [N, cap, s] by_cases h1 : 0 = 0 ∧ 1 ≤ v.1 ∧ v.1 ≤ m₁ · exfalso; apply hni refine Finset.mem_image.mpr ⟨⟨v.1 - 1, by omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, Fin.ext (by dsimp only [L]; omega)⟩ have hnv := (Finset.mem_sdiff.mp hv).2 have heq : L ⟨v.1 - 1, by omega⟩ = v := Fin.ext (by dsimp only [L]; omega) rwa [heq] · rw [if_neg h1, if_neg (by omega), dif_neg (by omega)] have hsub : C₁.image L ⊆ Finset.univ \ SStar := by intro v hv; obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp hv exact Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hi).2⟩ rw [← Finset.sum_subset hsub (fun v hv hni => hzero v hv hni)] rw [Finset.sum_image (fun a _ b _ h => by have := congrArg Fin.val h; dsimp only [L] at this; exact Fin.ext (by omega))] have hall1 : ∑ i ∈ C₁, N.cap s (L i) = ∑ _i ∈ C₁, 1 := Finset.sum_congr rfl (fun i _ => by dsimp only [N, cap, s, L]; rw [if_pos (by omega)]) rw [hall1]; simp · rw [if_neg hus] by_cases huR : m₁ + 1 ≤ u.1 ∧ u.1 ≤ m₁ + m₂ · rw [if_pos huR] have ht_diff : t ∈ Finset.univ \ SStar := Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, htS⟩ rw [← Finset.add_sum_erase _ _ ht_diff] have h1 : N.cap u t = 1 := by dsimp only [N, cap, t]; rw [if_neg (by omega), if_pos (by omega)] have h0 : ∑ v ∈ (Finset.univ \ SStar).erase t, N.cap u v = 0 := by refine Finset.sum_eq_zero (fun v hv => ?_) have hne : v.1 ≠ m₁ + m₂ + 1 := fun h => (Finset.mem_erase.mp hv).1 (Fin.ext h) dsimp only [N, cap]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by omega)] omega · rw [if_neg huR] refine Finset.sum_eq_zero (fun v hv => ?_) dsimp only [N, cap] have hu0 : u.1 ≠ 0 := fun h => hus (Fin.ext h) rw [if_neg (by omega), if_neg (by omega)] by_cases h3 : 1 ≤ u.1 ∧ u.1 ≤ m₁ ∧ m₁ + 1 ≤ v.1 ∧ v.1 ≤ m₁ + m₂ · rw [dif_pos h3] by_cases hadj : adj ⟨u.1 - 1, by omega⟩ ⟨v.1 - (m₁ + 1), by omega⟩ = true · have hi_eq : L ⟨u.1 - 1, by omega⟩ = u := Fin.ext (by dsimp only [L]; omega) have hj_eq : R ⟨v.1 - (m₁ + 1), by omega⟩ = v := Fin.ext (by dsimp only [R]; omega) rcases hcov ⟨u.1 - 1, by omega⟩ ⟨v.1 - (m₁ + 1), by omega⟩ hadj with h1 | h2 · exact absurd (hi_eq.symm ▸ hu) (Finset.mem_filter.mp h1).2 · exact absurd (hj_eq ▸ (Finset.mem_filter.mp h2).2) (Finset.mem_sdiff.mp hv).2 · rw [if_neg hadj] · rw [dif_neg h3] dsimp only [cutCap] rw [Finset.sum_congr rfl hrow, ← Finset.add_sum_erase _ _ hsS, if_pos rfl] have hrest : ∑ u ∈ SStar.erase s, (if u = s then C₁.card else if m₁ + 1 ≤ u.1 ∧ u.1 ≤ m₁ + m₂ then 1 else 0) = C₂.card := by have hcongr : ∑ u ∈ SStar.erase s, (if u = s then C₁.card else if m₁ + 1 ≤ u.1 ∧ u.1 ≤ m₁ + m₂ then 1 else 0) = ∑ u ∈ SStar.erase s, (if m₁ + 1 ≤ u.1 ∧ u.1 ≤ m₁ + m₂ then 1 else 0) := Finset.sum_congr rfl (fun u hu => by rw [if_neg (Finset.mem_erase.mp hu).1]) rw [hcongr, ← Finset.sum_filter]; simp only [Finset.sum_const, smul_eq_mul, mul_one] refine Finset.card_bij (fun u hu => ⟨u.1 - (m₁ + 1), by have := (Finset.mem_filter.mp hu).2; omega⟩) (fun u hu => by obtain ⟨hu1, hu2⟩ := Finset.mem_filter.mp hu refine Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩ convert (Finset.mem_erase.mp hu1).2 using 1; exact Fin.ext (by dsimp only [R]; omega)) (fun u₁ h₁ u₂ h₂ h => by have a1 := (Finset.mem_filter.mp h₁).2; have a2 := (Finset.mem_filter.mp h₂).2 have := congrArg Fin.val h; dsimp only at this; exact Fin.ext (by omega)) (fun j hj => ⟨R j, Finset.mem_filter.mpr ⟨Finset.mem_erase.mpr ⟨fun h => by have := congrArg Fin.val h; dsimp only [R, s] at this; omega, (Finset.mem_filter.mp hj).2⟩, by dsimp only [R]; omega⟩, Fin.ext (by dsimp only [R]; omega)⟩) omega -- Extract matching `M := {(i, j) | 0 < fStar (L i) (R j)}`! -- Conservation at each `L i`: `∑_j fStar (L i) (R j) = fStar s (L i) ≤ 1`; -- Conservation at each `R j`: `∑_i fStar (L i) (R j) = fStar (R j) t ≤ 1`; -- Total sum `∑ i, ∑ j, fStar (L i) (R j) = flowVal fStar s = cutCap N SStar = C₁.card + C₂.card`! have hL_eq : ∀ i : Fin m₁, ∑ j : Fin m₂, fStar (L i) (R j) = fStar s (L i) := by intro i have hcons := hfStar.2 (L i) (by intro h; have := congrArg Fin.val h; dsimp only [s, L] at this; omega) (by intro h; have := congrArg Fin.val h; dsimp only [t, L] at this; omega) have hin : ∑ w : Fin n, fStar w (L i) = fStar s (L i) := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ s)] have h0 : ∑ w ∈ Finset.univ.erase s, fStar w (L i) = 0 := by refine Finset.sum_eq_zero (fun w hw => ?_) have hne : w.1 ≠ 0 := fun h => (Finset.mem_erase.mp hw).1 (Fin.ext h) have hc := hfStar.1 w (L i) have hcap0 : N.cap w (L i) = 0 := by dsimp only [N, cap, L]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by have := i.2; omega)] rw [hcap0] at hc; omega omega have hout : ∑ w : Fin n, fStar (L i) w = ∑ j : Fin m₂, fStar (L i) (R j) := by have hother : ∀ w : Fin n, w ∉ Finset.univ.image R → fStar (L i) w = 0 := by intro w hw have hc := hfStar.1 (L i) w by_cases h3 : m₁ + 1 ≤ w.1 ∧ w.1 ≤ m₁ + m₂ · exfalso; apply hw; exact Finset.mem_image.mpr ⟨⟨w.1 - (m₁ + 1), by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp only [R]; omega)⟩ · have hcap0 : N.cap (L i) w = 0 := by dsimp only [N, cap, L]; rw [if_neg (by omega), if_neg (by have := i.2; omega), dif_neg (by omega)] rw [hcap0] at hc; omega rw [← Finset.sum_subset (Finset.subset_univ (Finset.univ.image R)) (fun w _ hw => hother w hw)] exact Finset.sum_image (fun a _ b _ h => by have := congrArg Fin.val h; dsimp only [R] at this; exact Fin.ext (by omega)) dsimp only [netFlow] at hcons have h1 : (∑ w : Fin n, (fStar (L i) w : ℤ)) = ((∑ j : Fin m₂, fStar (L i) (R j) : ℕ) : ℤ) := by rw [← hout]; push_cast; rfl have h2 : (∑ w : Fin n, (fStar w (L i) : ℤ)) = (fStar s (L i) : ℤ) := by have : ((∑ w : Fin n, fStar w (L i) : ℕ) : ℤ) = (fStar s (L i) : ℤ) := by rw [hin] push_cast at this; exact this have : ((∑ j : Fin m₂, fStar (L i) (R j) : ℕ) : ℤ) = (fStar s (L i) : ℤ) := by linarith exact_mod_cast this have hL_le1 : ∀ i : Fin m₁, ∑ j : Fin m₂, fStar (L i) (R j) ≤ 1 := fun i => by rw [hL_eq i]; have hc := hfStar.1 s (L i); dsimp only [N, cap, s, L] at hc rw [if_pos (by omega)] at hc; exact hc have hR_le1 : ∀ j : Fin m₂, ∑ i : Fin m₁, fStar (L i) (R j) ≤ 1 := by intro j have hcons := hfStar.2 (R j) (by intro h; have := congrArg Fin.val h; dsimp only [s, R] at this; omega) (by intro h; have := congrArg Fin.val h; dsimp only [t, R] at this; omega) have hout : ∑ w : Fin n, fStar (R j) w ≤ 1 := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ t)] have h0 : ∑ w ∈ Finset.univ.erase t, fStar (R j) w = 0 := by refine Finset.sum_eq_zero (fun w hw => ?_) have hne : w.1 ≠ m₁ + m₂ + 1 := fun h => (Finset.mem_erase.mp hw).1 (Fin.ext h) have hc := hfStar.1 (R j) w have hcap0 : N.cap (R j) w = 0 := by dsimp only [N, cap, R]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by omega)] rw [hcap0] at hc; omega have hle1 : fStar (R j) t ≤ 1 := by have hc := hfStar.1 (R j) t; dsimp only [N, cap, R, t] at hc rw [if_neg (by omega), if_pos (by have := j.2; omega)] at hc; exact hc omega have hin : ∑ i : Fin m₁, fStar (L i) (R j) ≤ ∑ w : Fin n, fStar w (R j) := by rw [← Finset.sum_image (f := fun w => fStar w (R j)) (fun a _ b _ h => by have := congrArg Fin.val h; dsimp only [L] at this; exact Fin.ext (by omega))] exact Finset.sum_le_sum_of_subset (Finset.subset_univ _) dsimp only [netFlow] at hcons have : ((∑ w : Fin n, fStar w (R j) : ℕ) : ℤ) ≤ 1 := by have : ((∑ w : Fin n, fStar (R j) w : ℕ) : ℤ) ≤ 1 := Int.ofNat_le.mpr hout push_cast at hcons ⊢; linarith have := Int.ofNat_le.mp this; omega let M : Finset (Fin m₁ × Fin m₂) := Finset.univ.filter (fun e => fStar (L e.1) (R e.2) = 1) have hM_adj : ∀ e ∈ M, adj e.1 e.2 = true := by intro e he have hf1 := (Finset.mem_filter.mp he).2 have hc := hfStar.1 (L e.1) (R e.2); rw [hf1] at hc dsimp only [N, cap, L, R] at hc rw [if_neg (by omega), if_neg (by omega), dif_pos (by omega)] at hc have hi' : (⟨e.1.1 + 1 - 1, by omega⟩ : Fin m₁) = e.1 := Fin.ext (by dsimp only; omega) have hj' : (⟨m₁ + 1 + e.2.1 - (m₁ + 1), by omega⟩ : Fin m₂) = e.2 := Fin.ext (by dsimp only; omega) rw [hi', hj'] at hc cases ha : adj e.1 e.2 · rw [ha] at hc; simp at hc · rfl have hM_disj : ∀ e₁ ∈ M, ∀ e₂ ∈ M, e₁ ≠ e₂ → e₁.1 ≠ e₂.1 ∧ e₁.2 ≠ e₂.2 := by intro e₁ h₁ e₂ h₂ hne have f1 := (Finset.mem_filter.mp h₁).2; have f2 := (Finset.mem_filter.mp h₂).2 constructor · intro hfst have hsnd : e₁.2 ≠ e₂.2 := fun hs => hne (Prod.ext hfst hs) have hge : 2 ≤ ∑ j : Fin m₂, fStar (L e₁.1) (R j) := by calc 2 = fStar (L e₁.1) (R e₁.2) + fStar (L e₁.1) (R e₂.2) := by rw [f1, hfst, f2] _ = ∑ j ∈ ({e₁.2, e₂.2} : Finset (Fin m₂)), fStar (L e₁.1) (R j) := (Finset.sum_pair (f := fun j => fStar (L e₁.1) (R j)) hsnd).symm _ ≤ ∑ j : Fin m₂, fStar (L e₁.1) (R j) := Finset.sum_le_sum_of_subset (Finset.subset_univ _) have := hL_le1 e₁.1; omega · intro hsnd have hfst : e₁.1 ≠ e₂.1 := fun hf => hne (Prod.ext hf hsnd) have hge : 2 ≤ ∑ i : Fin m₁, fStar (L i) (R e₁.2) := by calc 2 = fStar (L e₁.1) (R e₁.2) + fStar (L e₂.1) (R e₁.2) := by rw [f1, hsnd, f2] _ = ∑ i ∈ ({e₁.1, e₂.1} : Finset (Fin m₁)), fStar (L i) (R e₁.2) := (Finset.sum_pair (f := fun i => fStar (L i) (R e₁.2)) hfst).symm _ ≤ ∑ i : Fin m₁, fStar (L i) (R e₁.2) := Finset.sum_le_sum_of_subset (Finset.subset_univ _) have := hR_le1 e₁.2; omega have hM_card : M.card = C₁.card + C₂.card := by have hsum_all : ∑ i : Fin m₁, ∑ j : Fin m₂, fStar (L i) (R j) = C₁.card + C₂.card := by have hs_eq : ∑ i : Fin m₁, fStar s (L i) = cutCap N SStar := by have hin0 : ∑ w : Fin n, (fStar w s : ℤ) = 0 := by refine Finset.sum_eq_zero (fun w _ => ?_) have hc := hfStar.1 w s have hcap0 : N.cap w s = 0 := by dsimp only [N, cap, s]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by omega)] rw [hcap0] at hc have h0 : fStar w s = 0 := by omega exact_mod_cast h0 have hout_L : ∑ v : Fin n, fStar s v = ∑ i : Fin m₁, fStar s (L i) := by have hother : ∀ v : Fin n, v ∉ Finset.univ.image L → fStar s v = 0 := by intro v hv; have hc := hfStar.1 s v by_cases h1 : 1 ≤ v.1 ∧ v.1 ≤ m₁ · exfalso; apply hv; exact Finset.mem_image.mpr ⟨⟨v.1 - 1, by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp only [L]; omega)⟩ · have hcap0 : N.cap s v = 0 := by dsimp only [N, cap, s]; rw [if_neg (by omega), if_neg (by omega), dif_neg (by omega)] rw [hcap0] at hc; omega rw [← Finset.sum_subset (Finset.subset_univ (Finset.univ.image L)) (fun v _ hv => hother v hv)] exact Finset.sum_image (fun a _ b _ h => by have := congrArg Fin.val h; dsimp only [L] at this; exact Fin.ext (by omega)) dsimp only [flowVal, netFlow] at heq have : ((∑ i : Fin m₁, fStar s (L i) : ℕ) : ℤ) = (cutCap N SStar : ℤ) := by rw [← hout_L]; push_cast; linarith exact_mod_cast this simp_rw [hL_eq]; rw [hs_eq, hcut_eq] have hcard_sum : M.card = ∑ i : Fin m₁, ∑ j : Fin m₂, fStar (L i) (R j) := by have h01 : ∀ i j, fStar (L i) (R j) ≤ 1 := fun i j => le_trans (Finset.single_le_sum (f := fun j' => fStar (L i) (R j')) (fun _ _ => Nat.zero_le _) (Finset.mem_univ j)) (hL_le1 i) have hprod : ∑ e : Fin m₁ × Fin m₂, fStar (L e.1) (R e.2) = ∑ i : Fin m₁, ∑ j : Fin m₂, fStar (L i) (R j) := Fintype.sum_prod_type _ rw [← hprod] have hfilt : ∑ e : Fin m₁ × Fin m₂, fStar (L e.1) (R e.2) = ∑ e : Fin m₁ × Fin m₂, if fStar (L e.1) (R e.2) = 1 then 1 else 0 := Finset.sum_congr rfl (fun e _ => by have := h01 e.1 e.2; split_ifs <;> omega) rw [hfilt, ← Finset.sum_filter]; simp [M] omega exact ⟨M, C₁, C₂, hM_adj, hM_disj, hcov, hM_card⟩ /-- **WEIGHTED KÖNIG–EGERVÁRY / HUNGARIAN ASSIGNMENT WEAK DUALITY & COMPLEMENTARY SLACKNESS**: For ANY real cost matrix `c : Fin n → Fin n → ℝ`, dual potentials `u v : Fin n → ℝ` satisfying `∀ i j, u i + v j ≤ c i j`, and ANY permutation `σ : Equiv.Perm (Fin n)`: 1. **`∑ i, u i + ∑ j, v j ≤ ∑ i, c i (σ i)`**; 2. Equality holds **if and only if** complementary slackness `∀ i, u i + v (σ i) = c i (σ i)` holds! -/ theorem weighted_assignment_duality_and_slackness {n : ℕ} (c : Fin n → Fin n → ℝ) (u v : Fin n → ℝ) (hdual : ∀ i j : Fin n, u i + v j ≤ c i j) (σ : Equiv.Perm (Fin n)) : (∑ i : Fin n, u i) + (∑ j : Fin n, v j) ≤ ∑ i : Fin n, c i (σ i) ∧ (((∑ i : Fin n, u i) + (∑ j : Fin n, v j) = ∑ i : Fin n, c i (σ i)) ↔ ∀ i : Fin n, u i + v (σ i) = c i (σ i)) := by have hv_perm : ∑ j : Fin n, v j = ∑ i : Fin n, v (σ i) := (Equiv.sum_comp σ v).symm rw [hv_perm, ← Finset.sum_add_distrib] refine ⟨Finset.sum_le_sum (fun i _ => hdual i (σ i)), ⟨?_, fun h => Finset.sum_congr rfl (fun i _ => h i)⟩⟩ intro heq i by_contra hne have hlt : u i + v (σ i) < c i (σ i) := lt_of_le_of_ne (hdual i (σ i)) hne have hstrict : ∑ k : Fin n, (u k + v (σ k)) < ∑ k : Fin n, c k (σ k) := Finset.sum_lt_sum (fun k _ => hdual k (σ k)) ⟨i, Finset.mem_univ i, hlt⟩ linarith /-! ### Pillar 2C: Full Birkhoff–von Neumann Theorem & Extreme-Point Characterization -/ /-- A real `n × n` matrix `P` is **doubly stochastic** if all entries are nonnegative and every row sum and column sum equals `1`. -/ def IsDoublyStochastic {n : ℕ} (P : Fin n → Fin n → ℝ) : Prop := (∀ i j : Fin n, 0 ≤ P i j) ∧ (∀ i : Fin n, ∑ j : Fin n, P i j = 1) ∧ (∀ j : Fin n, ∑ i : Fin n, P i j = 1) /-- Permutation matrix `P_σ(i, j) = 1` iff `σ i = j`, else `0`. -/ def permMatrix {n : ℕ} (σ : Equiv.Perm (Fin n)) (i j : Fin n) : ℝ := if σ i = j then 1 else 0 /-- Every permutation matrix is doubly stochastic. -/ theorem permMatrix_isDoublyStochastic {n : ℕ} (σ : Equiv.Perm (Fin n)) : IsDoublyStochastic (permMatrix σ) := by refine ⟨fun i j => by dsimp only [permMatrix]; split_ifs <;> norm_num, fun i => ?_, fun j => ?_⟩ · dsimp only [permMatrix]; simp · dsimp only [permMatrix] have heq : ∑ i : Fin n, (if σ i = j then (1 : ℝ) else 0) = ∑ i : Fin n, (if i = σ.symm j then (1 : ℝ) else 0) := Finset.sum_congr rfl (fun i _ => by have hiff : σ i = j ↔ i = σ.symm j := Equiv.apply_eq_iff_eq_symm_apply σ simp [hiff]) rw [heq]; simp /-- **BIRKHOFF–VON NEUMANN DECOMPOSITION LEMMA (SCALED DOUBLY STOCHASTIC MATRIX)**: For ANY nonnegative `n × n` matrix `M` (`n ≥ 1`) with uniform row and column sums `= s ≥ 0`, `M` is a positive-weighted sum of AT MOST `|{(i, j) | 0 < M i j}|` permutation matrices whose weights sum to `s`! -/ theorem birkhoff_scaled_decomposition {n : ℕ} (hn : 1 ≤ n) : ∀ (k : ℕ) (M : Fin n → Fin n → ℝ) (s : ℝ), 0 ≤ s → (∀ i j, 0 ≤ M i j) → (∀ i, ∑ j : Fin n, M i j = s) → (∀ j, ∑ i : Fin n, M i j = s) → (Finset.univ.filter (fun p : Fin n × Fin n => 0 < M p.1 p.2)).card ≤ k → ∃ (m : ℕ) (w : Fin m → ℝ) (π : Fin m → Equiv.Perm (Fin n)), m ≤ k ∧ (∀ r, 0 < w r) ∧ (∑ r : Fin m, w r = s) ∧ (∀ i j, M i j = ∑ r : Fin m, w r * permMatrix (π r) i j) := by classical intro k induction k with | zero => intro M s _ hnn hrow _ hcard0 have hM0 : ∀ i j, M i j = 0 := by intro i j by_contra hne have hpos : 0 < M i j := lt_of_le_of_ne (hnn i j) (Ne.symm hne) have hmem : (i, j) ∈ Finset.univ.filter (fun p : Fin n × Fin n => 0 < M p.1 p.2) := Finset.mem_filter.mpr ⟨Finset.mem_univ _, hpos⟩ have := Finset.card_pos.mpr ⟨(i, j), hmem⟩; omega have hs_eq : s = 0 := by have := hrow ⟨0, by omega⟩ simp only [hM0, Finset.sum_const_zero] at this; exact this.symm exact ⟨0, Fin.elim0, Fin.elim0, le_rfl, fun r => Fin.elim0 r, by simp [hs_eq], fun i j => by simp [hM0 i j]⟩ | succ k ih => intro M s hs0 hnn hrow hcol hcard rcases eq_or_lt_of_le hs0 with rfl | hspos · have hM0 : ∀ i j, M i j = 0 := by intro i j have hle : M i j ≤ ∑ j' : Fin n, M i j' := Finset.single_le_sum (fun j' _ => hnn i j') (Finset.mem_univ j) linarith [hrow i, hnn i j] exact ⟨0, Fin.elim0, Fin.elim0, Nat.zero_le _, fun r => Fin.elim0 r, by simp, fun i j => by simp [hM0 i j]⟩ · -- Support bipartite graph `adj i j := decide (0 < M i j)` satisfies Hall's condition! let adj : Fin n → Fin n → Bool := fun i j => decide (0 < M i j) have hhall : ∀ A : Finset (Fin n), A.card ≤ (bipNeighbors adj A).card := by intro A have h1 : (A.card : ℝ) * s = ∑ i ∈ A, ∑ j : Fin n, M i j := by simp_rw [hrow]; simp have h2 : ∑ i ∈ A, ∑ j : Fin n, M i j = ∑ i ∈ A, ∑ j ∈ bipNeighbors adj A, M i j := by refine Finset.sum_congr rfl (fun i hi => ?_) symm refine Finset.sum_subset (Finset.subset_univ _) (fun j _ hj => ?_) by_contra hne have hpos : 0 < M i j := lt_of_le_of_ne (hnn i j) (Ne.symm hne) exact hj (Finset.mem_filter.mpr ⟨Finset.mem_univ j, i, hi, by simp [adj, hpos]⟩) have h3 : ∑ i ∈ A, ∑ j ∈ bipNeighbors adj A, M i j ≤ ((bipNeighbors adj A).card : ℝ) * s := by rw [Finset.sum_comm] calc ∑ j ∈ bipNeighbors adj A, ∑ i ∈ A, M i j ≤ ∑ j ∈ bipNeighbors adj A, ∑ i : Fin n, M i j := Finset.sum_le_sum (fun j _ => Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ A) (fun i _ _ => hnn i j)) _ = ∑ _j ∈ bipNeighbors adj A, s := Finset.sum_congr rfl (fun j _ => hcol j) _ = ((bipNeighbors adj A).card : ℝ) * s := by simp have hR : (A.card : ℝ) ≤ ((bipNeighbors adj A).card : ℝ) := by nlinarith exact_mod_cast hR obtain ⟨σ, hσ⟩ := halls_marriage_theorem adj hhall have hσ_pos : ∀ i : Fin n, 0 < M i (σ i) := fun i => decide_eq_true_eq.mp (hσ i) have hne_univ : (Finset.univ : Finset (Fin n)).Nonempty := ⟨⟨0, by omega⟩, Finset.mem_univ _⟩ obtain ⟨i₀, _, hi₀_min⟩ := Finset.exists_min_image Finset.univ (fun i => M i (σ i)) hne_univ let α : ℝ := M i₀ (σ i₀) have hα_pos : 0 < α := hσ_pos i₀ have hα_le : ∀ i : Fin n, α ≤ M i (σ i) := fun i => hi₀_min i (Finset.mem_univ i) have hα_le_s : α ≤ s := by have hle : M i₀ (σ i₀) ≤ ∑ j : Fin n, M i₀ j := Finset.single_le_sum (fun j _ => hnn i₀ j) (Finset.mem_univ (σ i₀)) linarith [hrow i₀] let M' : Fin n → Fin n → ℝ := fun i j => M i j - α * permMatrix σ i j have hnn' : ∀ i j, 0 ≤ M' i j := by intro i j; dsimp only [M', permMatrix] split_ifs with heq · subst heq; linarith [hα_le i] · linarith [hnn i j] have hrow' : ∀ i, ∑ j : Fin n, M' i j = s - α := by intro i; dsimp only [M'] rw [Finset.sum_sub_distrib, ← Finset.mul_sum, hrow i, (permMatrix_isDoublyStochastic σ).2.1 i, mul_one] have hcol' : ∀ j, ∑ i : Fin n, M' i j = s - α := by intro j; dsimp only [M'] rw [Finset.sum_sub_distrib, ← Finset.mul_sum, hcol j, (permMatrix_isDoublyStochastic σ).2.2 j, mul_one] -- Strictly fewer positive entries: `supp(M') ⊂ supp(M)` because `(i₀, σ i₀)` drops to `0`! let S := Finset.univ.filter (fun p : Fin n × Fin n => 0 < M p.1 p.2) let S' := Finset.univ.filter (fun p : Fin n × Fin n => 0 < M' p.1 p.2) have hsub : S' ⊆ S := by intro p hp have hp' := (Finset.mem_filter.mp hp).2 refine Finset.mem_filter.mpr ⟨Finset.mem_univ p, ?_⟩ dsimp only [M', permMatrix] at hp' split_ifs at hp' <;> linarith have hmem : (i₀, σ i₀) ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_univ _, hα_pos⟩ have hnotmem : (i₀, σ i₀) ∉ S' := by intro h; have hp' := (Finset.mem_filter.mp h).2 dsimp only [M', permMatrix, α] at hp'; rw [if_pos rfl] at hp'; linarith have hcard' : S'.card ≤ k := by have hlt : S'.card < S.card := Finset.card_lt_card (Finset.ssubset_iff_subset_ne.mpr ⟨hsub, fun h => hnotmem (h ▸ hmem)⟩) have hS_le : S.card ≤ k + 1 := hcard omega obtain ⟨m', w', π', hm'le, hw'pos, hw'sum, hM'eq⟩ := ih M' (s - α) (by linarith) hnn' hrow' hcol' hcard' refine ⟨m' + 1, Fin.cons α w', Fin.cons σ π', by omega, ?_, ?_, ?_⟩ · intro r; refine Fin.cases hα_pos hw'pos r · rw [Fin.sum_univ_succ]; simp only [Fin.cons_zero, Fin.cons_succ]; linarith · intro i j rw [Fin.sum_univ_succ]; simp only [Fin.cons_zero, Fin.cons_succ] have h1 := hM'eq i j dsimp only [M'] at h1; linarith /-- **BIRKHOFF–VON NEUMANN THEOREM (1946 / 1953)**: Every `n × n` doubly stochastic matrix `P` (`n ≥ 1`) is a **convex combination of at most `|supp(P)| ≤ n²` permutation matrices** with strictly positive weights summing to `1`! -/ theorem birkhoff_von_neumann_theorem {n : ℕ} (hn : 1 ≤ n) (P : Fin n → Fin n → ℝ) (hP : IsDoublyStochastic P) : ∃ (m : ℕ) (w : Fin m → ℝ) (π : Fin m → Equiv.Perm (Fin n)), m ≤ (Finset.univ.filter (fun p : Fin n × Fin n => 0 < P p.1 p.2)).card ∧ m ≤ n ^ 2 ∧ (∀ r, 0 < w r) ∧ (∑ r : Fin m, w r = 1) ∧ (∀ i j, P i j = ∑ r : Fin m, w r * permMatrix (π r) i j) := by let supp := Finset.univ.filter (fun p : Fin n × Fin n => 0 < P p.1 p.2) obtain ⟨m, w, π, hle, hpos, hsum, heq⟩ := birkhoff_scaled_decomposition hn supp.card P 1 (by norm_num) hP.1 hP.2.1 hP.2.2 le_rfl have hsupp_le : supp.card ≤ n ^ 2 := by calc supp.card ≤ (Finset.univ : Finset (Fin n × Fin n)).card := Finset.card_le_univ _ _ = n * n := by simp _ = n ^ 2 := by ring exact ⟨m, w, π, hle, le_trans hle hsupp_le, hpos, hsum, heq⟩ /-- **BIRKHOFF POLYTOPE EXTREME-POINT CHARACTERIZATION**: A doubly stochastic matrix `P` (`n ≥ 1`) is an **extreme point** of the Birkhoff polytope **IF AND ONLY IF** `P` is a permutation matrix (`∃ σ, P = permMatrix σ`)! -/ theorem birkhoff_extreme_point_iff_perm {n : ℕ} (hn : 1 ≤ n) (P : Fin n → Fin n → ℝ) (hP : IsDoublyStochastic P) : (∀ (Q R : Fin n → Fin n → ℝ) (lam : ℝ), 0 < lam → lam < 1 → IsDoublyStochastic Q → IsDoublyStochastic R → (∀ i j, P i j = lam * Q i j + (1 - lam) * R i j) → Q = R) ↔ (∃ σ : Equiv.Perm (Fin n), ∀ i j, P i j = permMatrix σ i j) := by constructor · intro hext obtain ⟨m, w, π, _, _, hwpos, hwsum, hPeq⟩ := birkhoff_von_neumann_theorem hn P hP by_cases hm0 : m = 0 · subst hm0; simp at hwsum · let r₀ : Fin m := ⟨0, by omega⟩ refine ⟨π r₀, ?_⟩ by_cases hm1 : m = 1 · have hw0 : w r₀ = 1 := by have : ∑ r : Fin m, w r = w r₀ := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ r₀)] have h0 : Finset.univ.erase r₀ = ∅ := by ext r; simp only [Finset.mem_erase, Finset.mem_univ, and_true, Finset.notMem_empty, iff_false, not_not] exact Fin.ext (by omega) rw [h0, Finset.sum_empty, add_zero] linarith intro i j; rw [hPeq i j] have : ∑ r : Fin m, w r * permMatrix (π r) i j = w r₀ * permMatrix (π r₀) i j := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ r₀)] have h0 : Finset.univ.erase r₀ = ∅ := by ext r; simp only [Finset.mem_erase, Finset.mem_univ, and_true, Finset.notMem_empty, iff_false, not_not] exact Fin.ext (by omega) rw [h0, Finset.sum_empty, add_zero] rw [this, hw0, one_mul] · -- `m ≥ 2`: peel off `r₀` (`lam = w r₀ ∈ (0, 1)`) and combine the remaining `m - 1` terms into `R`! have hrem_pos : 0 < 1 - w r₀ := by have hsum_split : w r₀ + ∑ r ∈ Finset.univ.erase r₀, w r = 1 := by rw [Finset.add_sum_erase _ _ (Finset.mem_univ r₀), hwsum] have hex_other : ∃ r₁ : Fin m, r₁ ≠ r₀ := by refine ⟨⟨1, by omega⟩, fun h => by have := congrArg Fin.val h; dsimp only [r₀] at this; omega⟩ obtain ⟨r₁, hr₁⟩ := hex_other have h1 : w r₁ ≤ ∑ r ∈ Finset.univ.erase r₀, w r := Finset.single_le_sum (fun r _ => le_of_lt (hwpos r)) (Finset.mem_erase.mpr ⟨hr₁, Finset.mem_univ r₁⟩) linarith [hwpos r₁] have hlam1 : w r₀ < 1 := by linarith let Q : Fin n → Fin n → ℝ := permMatrix (π r₀) let R : Fin n → Fin n → ℝ := fun i j => (∑ r ∈ Finset.univ.erase r₀, w r * permMatrix (π r) i j) / (1 - w r₀) have hQ_ds : IsDoublyStochastic Q := permMatrix_isDoublyStochastic (π r₀) have hR_ds : IsDoublyStochastic R := by have hsum_rem : ∑ r ∈ Finset.univ.erase r₀, w r = 1 - w r₀ := by have := Finset.add_sum_erase Finset.univ w (Finset.mem_univ r₀); linarith refine ⟨fun i j => div_nonneg (Finset.sum_nonneg (fun r _ => mul_nonneg (le_of_lt (hwpos r)) ((permMatrix_isDoublyStochastic (π r)).1 i j))) (le_of_lt hrem_pos), fun i => ?_, fun j => ?_⟩ · dsimp only [R]; rw [← Finset.sum_div, Finset.sum_comm] have : ∑ r ∈ Finset.univ.erase r₀, ∑ j : Fin n, w r * permMatrix (π r) i j = 1 - w r₀ := by trans ∑ r ∈ Finset.univ.erase r₀, w r · refine Finset.sum_congr rfl (fun r _ => by rw [← Finset.mul_sum, (permMatrix_isDoublyStochastic (π r)).2.1 i, mul_one]) · exact hsum_rem rw [this, div_self (ne_of_gt hrem_pos)] · dsimp only [R]; rw [← Finset.sum_div, Finset.sum_comm] have : ∑ r ∈ Finset.univ.erase r₀, ∑ i : Fin n, w r * permMatrix (π r) i j = 1 - w r₀ := by trans ∑ r ∈ Finset.univ.erase r₀, w r · refine Finset.sum_congr rfl (fun r _ => by rw [← Finset.mul_sum, (permMatrix_isDoublyStochastic (π r)).2.2 j, mul_one]) · exact hsum_rem rw [this, div_self (ne_of_gt hrem_pos)] have hconv : ∀ i j, P i j = w r₀ * Q i j + (1 - w r₀) * R i j := by intro i j; rw [hPeq i j, ← Finset.add_sum_erase _ _ (Finset.mem_univ r₀)] dsimp only [Q, R] rw [mul_div_cancel₀ _ (ne_of_gt hrem_pos)] have hQR : Q = R := hext Q R (w r₀) (hwpos r₀) hlam1 hQ_ds hR_ds hconv intro i j rw [hconv i j, ← hQR]; dsimp only [Q]; ring · rintro ⟨σ, hσ⟩ Q R lam h0 h1 hQ hR hconv funext i j have h10 := hσ i j have hq0 := hQ.1 i j; have hr0 := hR.1 i j have hq1 : Q i j ≤ 1 := by have := Finset.single_le_sum (fun j' _ => hQ.1 i j') (Finset.mem_univ j) linarith [hQ.2.1 i] have hr1 : R i j ≤ 1 := by have := Finset.single_le_sum (fun j' _ => hR.1 i j') (Finset.mem_univ j) linarith [hR.2.1 i] have heq := hconv i j rw [h10] at heq; dsimp only [permMatrix] at heq split_ifs at heq <;> nlinarith /-! =============================================================================== PART 3: GLOBAL MIN-CUTS, CUT SUBMODULARITY, GOMORY–HU CUT TREES & STOER–WAGNER =============================================================================== -/ /-! ### Pillar 3A: Exact Cut Submodularity, Posimodularity & Uncrossing -/ /-- Total directed weight crossing from `A` to `B`. -/ def crossWeight {n : ℕ} (w : Fin n → Fin n → ℝ) (A B : Finset (Fin n)) : ℝ := ∑ u ∈ A, ∑ v ∈ B, w u v /-- Undirected cut value `cutVal w A = ∑_{u ∈ A} ∑_{v ∉ A} w u v`. -/ def cutVal {n : ℕ} (w : Fin n → Fin n → ℝ) (A : Finset (Fin n)) : ℝ := crossWeight w A (Finset.univ \ A) /-- Symmetry of undirected cut function: `cutVal w (univ \ A) = cutVal w A`. -/ theorem cutVal_compl {n : ℕ} (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) (A : Finset (Fin n)) : cutVal w (Finset.univ \ A) = cutVal w A := by dsimp only [cutVal, crossWeight] have hcomp : Finset.univ \ (Finset.univ \ A) = A := by ext v; simp rw [hcomp, Finset.sum_comm] exact Finset.sum_congr rfl (fun u _ => Finset.sum_congr rfl (fun v _ => hsym v u)) /-- **EXACT CUT SUBMODULARITY IDENTITY & INEQUALITY**: For ANY symmetric nonnegative weight matrix `w` and ANY `A, B ⊆ Fin n`: 1. `cutVal w A + cutVal w B = cutVal w (A ∩ B) + cutVal w (A ∪ B) + 2 · crossWeight w (A \ B) (B \ A)`; 2. **`cutVal w (A ∩ B) + cutVal w (A ∪ B) ≤ cutVal w A + cutVal w B`**! -/ theorem cutVal_submodular {n : ℕ} (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) (hnn : ∀ u v, 0 ≤ w u v) (A B : Finset (Fin n)) : cutVal w A + cutVal w B = cutVal w (A ∩ B) + cutVal w (A ∪ B) + 2 * crossWeight w (A \ B) (B \ A) ∧ cutVal w (A ∩ B) + cutVal w (A ∪ B) ≤ cutVal w A + cutVal w B := by have hrewrite : ∀ X Y : Finset (Fin n), crossWeight w X Y = ∑ u : Fin n, ∑ v : Fin n, if u ∈ X ∧ v ∈ Y then w u v else 0 := by intro X Y; dsimp only [crossWeight] have hsplit : ∀ u : Fin n, (∑ v : Fin n, if u ∈ X ∧ v ∈ Y then w u v else 0) = if u ∈ X then ∑ v ∈ Y, w u v else 0 := by intro u by_cases hu : u ∈ X · rw [if_pos hu] have h1 : ∑ v : Fin n, (if u ∈ X ∧ v ∈ Y then w u v else 0) = ∑ v : Fin n, if v ∈ Y then w u v else 0 := Finset.sum_congr rfl (fun v _ => by simp [hu]) rw [h1, ← Finset.sum_filter] have hY : Finset.univ.filter (fun v : Fin n => v ∈ Y) = Y := by ext v; simp rw [hY] · rw [if_neg hu]; exact Finset.sum_eq_zero (fun v _ => by simp [hu]) simp_rw [hsplit, ← Finset.sum_filter] have hX : Finset.univ.filter (fun u : Fin n => u ∈ X) = X := by ext u; simp rw [hX] have hsym_cross : crossWeight w (B \ A) (A \ B) = crossWeight w (A \ B) (B \ A) := by dsimp only [crossWeight]; rw [Finset.sum_comm] exact Finset.sum_congr rfl (fun u _ => Finset.sum_congr rfl (fun v _ => hsym v u)) have hid : cutVal w A + cutVal w B = cutVal w (A ∩ B) + cutVal w (A ∪ B) + 2 * crossWeight w (A \ B) (B \ A) := by have htwo : 2 * crossWeight w (A \ B) (B \ A) = crossWeight w (A \ B) (B \ A) + crossWeight w (B \ A) (A \ B) := by linarith rw [htwo] dsimp only [cutVal] simp_rw [hrewrite, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun u _ => ?_) refine Finset.sum_congr rfl (fun v _ => ?_) by_cases huA : u ∈ A <;> by_cases huB : u ∈ B <;> by_cases hvA : v ∈ A <;> by_cases hvB : v ∈ B <;> simp [huA, huB, hvA, hvB] have hcross_nn : 0 ≤ crossWeight w (A \ B) (B \ A) := Finset.sum_nonneg (fun u _ => Finset.sum_nonneg (fun v _ => hnn u v)) exact ⟨hid, by linarith⟩ /-- **EXACT CUT POSIMODULARITY IDENTITY & INEQUALITY**: For ANY symmetric nonnegative weight matrix `w` and ANY `A, B ⊆ Fin n`: 1. `cutVal w A + cutVal w B = cutVal w (A \ B) + cutVal w (B \ A) + 2 · crossWeight w (A ∩ B) (univ \ (A ∪ B))`; 2. **`cutVal w (A \ B) + cutVal w (B \ A) ≤ cutVal w A + cutVal w B`**! -/ theorem cutVal_posimodular {n : ℕ} (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) (hnn : ∀ u v, 0 ≤ w u v) (A B : Finset (Fin n)) : cutVal w A + cutVal w B = cutVal w (A \ B) + cutVal w (B \ A) + 2 * crossWeight w (A ∩ B) (Finset.univ \ (A ∪ B)) ∧ cutVal w (A \ B) + cutVal w (B \ A) ≤ cutVal w A + cutVal w B := by have h1 := cutVal_submodular w hsym hnn A (Finset.univ \ B) have hB : cutVal w (Finset.univ \ B) = cutVal w B := cutVal_compl w hsym B have h2 : A ∩ (Finset.univ \ B) = A \ B := by ext x; simp have h3 : A ∪ (Finset.univ \ B) = Finset.univ \ (B \ A) := by ext x; simp; tauto have h4 : cutVal w (Finset.univ \ (B \ A)) = cutVal w (B \ A) := cutVal_compl w hsym (B \ A) have h5 : A \ (Finset.univ \ B) = A ∩ B := by ext x; simp have h6 : (Finset.univ \ B) \ A = Finset.univ \ (A ∪ B) := by ext x; simp; tauto rw [hB, h2, h3, h4, h5, h6] at h1 exact h1 /-- **GOMORY–HU UNCROSSING OF MINIMUM `s-t` CUTS**: If `A` is a minimum `s-t` cut (`s ∈ A`, `t ∉ A`) and `B` is a minimum `u-v` cut separating two vertices `u, v ∈ A` (`u ∈ B`, `v ∉ B`), then there exists a minimum `u-v` cut `B* ⊆ A` that does NOT cross `A` (`cutVal w B* ≤ cutVal w B`, and `B*` separates `u` and `v`)! -/ theorem min_cut_uncrossing {n : ℕ} (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) (hnn : ∀ u v, 0 ≤ w u v) {s t u v : Fin n} {A B : Finset (Fin n)} (hsA : s ∈ A) (htA : t ∉ A) (hAmin : ∀ S : Finset (Fin n), s ∈ S → t ∉ S → cutVal w A ≤ cutVal w S) (huA : u ∈ A) (hvA : v ∈ A) (huB : u ∈ B) (hvB : v ∉ B) : ∃ BStar : Finset (Fin n), BStar ⊆ A ∧ ((u ∈ BStar ∧ v ∉ BStar) ∨ (v ∈ BStar ∧ u ∉ BStar)) ∧ cutVal w BStar ≤ cutVal w B := by by_cases htB : t ∉ B · -- `A ∪ B` separates `s, t` and `A ∩ B ⊆ A` separates `u, v`! have hAB_st : cutVal w A ≤ cutVal w (A ∪ B) := hAmin (A ∪ B) (Finset.mem_union_left B hsA) (by simp [htA, htB]) have hsub := (cutVal_submodular w hsym hnn A B).2 refine ⟨A ∩ B, Finset.inter_subset_left, Or.inl ⟨Finset.mem_inter.mpr ⟨huA, huB⟩, fun h => hvB (Finset.mem_inter.mp h).2⟩, by linarith⟩ · -- `t ∈ B`: use `B' = univ \ B` (`t ∉ B'`), so `A \ B = A ∩ B' ⊆ A` separates `v, u`! push Not at htB have hAB_st : cutVal w A ≤ cutVal w (B \ A) := by have hcompl := cutVal_compl w hsym (B \ A) have hst : s ∈ Finset.univ \ (B \ A) ∧ t ∉ Finset.univ \ (B \ A) := by simp [hsA, htA, htB] rw [← hcompl]; exact hAmin _ hst.1 hst.2 have hpos := (cutVal_posimodular w hsym hnn A B).2 refine ⟨A \ B, Finset.sdiff_subset, Or.inr ⟨Finset.mem_sdiff.mpr ⟨hvA, hvB⟩, fun h => (Finset.mem_sdiff.mp h).2 huB⟩, by linarith⟩ /-! ### Pillar 3B: Gomory–Hu Ultrametric, Cut Tree, `≤ n - 1` Distinct Values & Sharpness Witness -/ /-- Exact pairwise minimum cut value `λ(u, v) = min_{u ∈ S, v ∉ S} cutVal w S` for `u ≠ v` (`0` for `u = v`). -/ noncomputable def pairMinCut {n : ℕ} (w : Fin n → Fin n → ℝ) (u v : Fin n) : ℝ := if h : u = v then 0 else let cuts : Finset (Finset (Fin n)) := Finset.univ.filter (fun S => u ∈ S ∧ v ∉ S) have hne : cuts.Nonempty := ⟨{u}, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_singleton_self u, by simp [Ne.symm h]⟩⟩ (cuts.image (cutVal w)).min' (hne.image _) /-- Characterization of `pairMinCut`: lower-bounds every `u-v` cut AND is attained by some `u-v` cut! -/ theorem pairMinCut_spec {n : ℕ} (w : Fin n → Fin n → ℝ) {u v : Fin n} (huv : u ≠ v) : (∀ S : Finset (Fin n), u ∈ S → v ∉ S → pairMinCut w u v ≤ cutVal w S) ∧ (∃ S : Finset (Fin n), u ∈ S ∧ v ∉ S ∧ cutVal w S = pairMinCut w u v) := by dsimp only [pairMinCut] rw [dif_neg huv] let cuts : Finset (Finset (Fin n)) := Finset.univ.filter (fun S => u ∈ S ∧ v ∉ S) have hne : cuts.Nonempty := ⟨{u}, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_singleton_self u, by simp [Ne.symm huv]⟩⟩ constructor · intro S hu hv exact Finset.min'_le _ _ (Finset.mem_image.mpr ⟨S, Finset.mem_filter.mpr ⟨Finset.mem_univ S, hu, hv⟩, rfl⟩) · have hmem := Finset.min'_mem (cuts.image (cutVal w)) (hne.image _) obtain ⟨S, hS, hval⟩ := Finset.mem_image.mp hmem obtain ⟨_, hu, hv⟩ := Finset.mem_filter.mp hS exact ⟨S, hu, hv, hval⟩ /-- Symmetry of pairwise min-cut values: `pairMinCut w u v = pairMinCut w v u`! -/ theorem pairMinCut_symm {n : ℕ} (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) (u v : Fin n) : pairMinCut w u v = pairMinCut w v u := by by_cases huv : u = v · subst huv; rfl · obtain ⟨h1le, S₁, hu1, hv1, heq1⟩ := pairMinCut_spec w huv obtain ⟨h2le, S₂, hv2, hu2, heq2⟩ := pairMinCut_spec w (Ne.symm huv) have ha : pairMinCut w v u ≤ pairMinCut w u v := by rw [← heq1, ← cutVal_compl w hsym S₁] exact h2le (Finset.univ \ S₁) (by simp [hv1]) (by simp [hu1]) have hb : pairMinCut w u v ≤ pairMinCut w v u := by rw [← heq2, ← cutVal_compl w hsym S₂] exact h1le (Finset.univ \ S₂) (by simp [hu2]) (by simp [hv2]) exact le_antisymm hb ha /-- **GOMORY–HU ULTRAMETRIC / TRIANGLE INEQUALITY (1961)**: For EVERY triple of distinct vertices `a, b, c : Fin n`: **`min (pairMinCut w a b) (pairMinCut w b c) ≤ pairMinCut w a c`**! -/ theorem gomory_hu_ultrametric {n : ℕ} (w : Fin n → Fin n → ℝ) {a b c : Fin n} (hab : a ≠ b) (hbc : b ≠ c) (hac : a ≠ c) : min (pairMinCut w a b) (pairMinCut w b c) ≤ pairMinCut w a c := by obtain ⟨_, S, haS, hcS, hS_eq⟩ := pairMinCut_spec w hac rw [← hS_eq] by_cases hbS : b ∈ S · exact le_trans (min_le_right _ _) ((pairMinCut_spec w hbc).1 S hbS hcS) · exact le_trans (min_le_left _ _) ((pairMinCut_spec w hab).1 S haS hbS) /-- A weighted edge `(u, v, wt)` of a Gomory–Hu cut tree on `Fin n`. -/ structure CutTreeEdge (n : ℕ) where u : Fin n v : Fin n wt : ℝ /-- **GOMORY–HU THEOREM (`≤ n - 1` DISTINCT PAIRWISE MIN-CUT VALUES + WEIGHTED CUT TREE)**: For ANY symmetric ultrametric function `lam : Fin n → Fin n → ℝ` (in particular `pairMinCut w` for ANY undirected weighted graph `w`!) and ANY nonempty vertex subset `V ⊆ Fin n`: There exists a weighted tree edge-list `T` of EXACT size **`T.length = V.card - 1`** connecting `V` whose edge weights realize **EVERY** pairwise min-cut value `lam u v` (`u ≠ v ∈ V`), hence: 1. Every distinct pair `(u, v)` in `V` attains `lam u v = e.wt` for some tree edge `e ∈ T`; 2. The set of all distinct pairwise min-cut values `{ lam u v | u, v ∈ V, u ≠ v }` has cardinality **AT MOST `V.card - 1`**! -/ theorem gomory_hu_cut_tree_and_n_minus_one_distinct {n : ℕ} (lam : Fin n → Fin n → ℝ) (hsym : ∀ u v, lam u v = lam v u) (hultra : ∀ a b c : Fin n, a ≠ b → b ≠ c → a ≠ c → min (lam a b) (lam b c) ≤ lam a c) : ∀ (k : ℕ) (V : Finset (Fin n)), V.card = k + 1 → ∃ T : List (CutTreeEdge n), T.length = k ∧ (∀ e ∈ T, e.u ∈ V ∧ e.v ∈ V ∧ e.u ≠ e.v ∧ e.wt = lam e.u e.v) ∧ (∀ u ∈ V, ∀ v ∈ V, u ≠ v → ∃ e ∈ T, e.wt = lam u v) := by classical intro k induction k using Nat.strong_induction_on with | _ k ih => intro V hcard by_cases hk0 : k = 0 · subst hk0 refine ⟨[], rfl, by simp, fun u hu v hv huv => ?_⟩ obtain ⟨x, rfl⟩ := Finset.card_eq_one.mp hcard exact absurd ((Finset.mem_singleton.mp hu).trans (Finset.mem_singleton.mp hv).symm) huv · -- `V.card = k + 1 ≥ 2`: pick a pair `(u₀, v₀)` in `V` with `u₀ ≠ v₀` minimizing `lam u₀ v₀`! let pairs : Finset (Fin n × Fin n) := (V ×ˢ V).filter (fun p => p.1 ≠ p.2) have hpairs_ne : pairs.Nonempty := by obtain ⟨u, hu, v, hv, huv⟩ := Finset.one_lt_card.mp (by omega : 1 < V.card) exact ⟨(u, v), Finset.mem_filter.mpr ⟨Finset.mem_product.mpr ⟨hu, hv⟩, huv⟩⟩ obtain ⟨p0, hp0_mem, hp0_min⟩ := Finset.exists_min_image pairs (fun p => lam p.1 p.2) hpairs_ne let u₀ := p0.1; let v₀ := p0.2 have hu₀V : u₀ ∈ V := (Finset.mem_product.mp (Finset.mem_filter.mp hp0_mem).1).1 have hv₀V : v₀ ∈ V := (Finset.mem_product.mp (Finset.mem_filter.mp hp0_mem).1).2 have huv₀ : u₀ ≠ v₀ := (Finset.mem_filter.mp hp0_mem).2 let mMin : ℝ := lam u₀ v₀ have hmMin_le : ∀ x ∈ V, ∀ y ∈ V, x ≠ y → mMin ≤ lam x y := fun x hx y hy hxy => hp0_min (x, y) (Finset.mem_filter.mpr ⟨Finset.mem_product.mpr ⟨hx, hy⟩, hxy⟩) -- Partition `V` into `A := {x ∈ V | x = u₀ ∨ mMin < lam u₀ x}` and `B := V \ A`! let A : Finset (Fin n) := V.filter (fun x => x = u₀ ∨ mMin < lam u₀ x) let B : Finset (Fin n) := V \ A have hu₀A : u₀ ∈ A := Finset.mem_filter.mpr ⟨hu₀V, Or.inl rfl⟩ have hv₀B : v₀ ∈ B := Finset.mem_sdiff.mpr ⟨hv₀V, fun h => by rcases (Finset.mem_filter.mp h).2 with heq | hlt · exact huv₀ heq.symm · exact lt_irrefl mMin hlt⟩ -- KEY ULTRAMETRIC SPLIT: For EVERY `x ∈ A` and EVERY `y ∈ B`, `lam x y = mMin`!! have hcross_eq : ∀ x ∈ A, ∀ y ∈ B, lam x y = mMin := by intro x hxA y hyB have hxV : x ∈ V := (Finset.mem_filter.mp hxA).1 have hyV : y ∈ V := (Finset.mem_sdiff.mp hyB).1 have hxy : x ≠ y := fun h => (Finset.mem_sdiff.mp hyB).2 (h ▸ hxA) have hy_notA : y ∉ A := (Finset.mem_sdiff.mp hyB).2 have hy_ne_u₀ : y ≠ u₀ := fun h => hy_notA (Finset.mem_filter.mpr ⟨hyV, Or.inl h⟩) have hy_le : lam u₀ y ≤ mMin := by by_contra hgt; push Not at hgt exact hy_notA (Finset.mem_filter.mpr ⟨hyV, Or.inr hgt⟩) have hge := hmMin_le x hxV y hyV hxy rcases (Finset.mem_filter.mp hxA).2 with rfl | hxgt · exact le_antisymm hy_le hge · by_cases hxu : x = u₀ · subst hxu; exact le_antisymm hy_le hge · have htri := hultra u₀ x y (Ne.symm hxu) hxy (Ne.symm hy_ne_u₀) have hle : lam x y ≤ mMin := by rcases le_total (lam u₀ x) (lam x y) with h1 | h2 · rw [min_eq_left h1] at htri; linarith · rw [min_eq_right h2] at htri; linarith exact le_antisymm hle hge have hA_pos : 1 ≤ A.card := Finset.card_pos.mpr ⟨u₀, hu₀A⟩ have hB_pos : 1 ≤ B.card := Finset.card_pos.mpr ⟨v₀, hv₀B⟩ have hAB_sum : A.card + B.card = k + 1 := by have hsub : A ⊆ V := Finset.filter_subset _ V have hu : A ∪ B = V := Finset.union_sdiff_of_subset hsub have hd : Disjoint A B := Finset.disjoint_sdiff rw [← Finset.card_union_of_disjoint hd, hu, hcard] obtain ⟨TA, hTA_len, hTA_valid, hTA_cov⟩ := ih (A.card - 1) (by omega) A (by omega) obtain ⟨TB, hTB_len, hTB_valid, hTB_cov⟩ := ih (B.card - 1) (by omega) B (by omega) let eBridge : CutTreeEdge n := ⟨u₀, v₀, mMin⟩ refine ⟨eBridge :: (TA ++ TB), ?_, ?_, ?_⟩ · simp only [List.length_cons, List.length_append, hTA_len, hTB_len]; omega · intro e he simp only [List.mem_cons, List.mem_append] at he rcases he with rfl | hA | hB · exact ⟨hu₀V, hv₀V, huv₀, rfl⟩ · obtain ⟨h1, h2, h3, h4⟩ := hTA_valid e hA exact ⟨(Finset.mem_filter.mp h1).1, (Finset.mem_filter.mp h2).1, h3, h4⟩ · obtain ⟨h1, h2, h3, h4⟩ := hTB_valid e hB exact ⟨(Finset.mem_sdiff.mp h1).1, (Finset.mem_sdiff.mp h2).1, h3, h4⟩ · intro u huV v hvV huv by_cases huA : u ∈ A <;> by_cases hvA : v ∈ A · obtain ⟨e, he, hwt⟩ := hTA_cov u huA v hvA huv exact ⟨e, by simp [he], hwt⟩ · have hvB : v ∈ B := Finset.mem_sdiff.mpr ⟨hvV, hvA⟩ exact ⟨eBridge, by simp, (hcross_eq u huA v hvB).symm⟩ · have huB : u ∈ B := Finset.mem_sdiff.mpr ⟨huV, huA⟩ exact ⟨eBridge, by simp, by rw [hsym u v]; exact (hcross_eq v hvA u huB).symm⟩ · have huB : u ∈ B := Finset.mem_sdiff.mpr ⟨huV, huA⟩ have hvB : v ∈ B := Finset.mem_sdiff.mpr ⟨hvV, hvA⟩ obtain ⟨e, he, hwt⟩ := hTB_cov u huB v hvB huv exact ⟨e, by simp [he], hwt⟩ /-- **GOMORY–HU COROLLARY: AT MOST `n - 1` DISTINCT PAIRWISE MIN-CUT VALUES IN ANY `n`-VERTEX GRAPH**: For ANY `n ≥ 1` and ANY symmetric undirected weighted graph `w : Fin n → Fin n → ℝ`, the set of all pairwise min-cut values `{ pairMinCut w u v | u ≠ v }` has cardinality **`≤ n - 1`**! -/ theorem gomory_hu_at_most_n_minus_one_distinct_values {n : ℕ} (hn : 1 ≤ n) (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) : ((Finset.univ.filter (fun p : Fin n × Fin n => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card ≤ n - 1 := by classical obtain ⟨T, hT_len, _, hT_cov⟩ := gomory_hu_cut_tree_and_n_minus_one_distinct (pairMinCut w) (pairMinCut_symm w hsym) (fun _ _ _ h1 h2 h3 => gomory_hu_ultrametric w h1 h2 h3) (n - 1) Finset.univ (by rw [Finset.card_univ, Fintype.card_fin]; omega) let vals : Finset ℝ := (T.map (fun e => e.wt)).toFinset have hsub : (Finset.univ.filter (fun p : Fin n × Fin n => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2) ⊆ vals := by intro r hr obtain ⟨p, hp, rfl⟩ := Finset.mem_image.mp hr obtain ⟨e, heT, hwt⟩ := hT_cov p.1 (Finset.mem_univ _) p.2 (Finset.mem_univ _) (Finset.mem_filter.mp hp).2 exact List.mem_toFinset.mpr (List.mem_map.mpr ⟨e, heT, hwt⟩) calc ((Finset.univ.filter (fun p : Fin n × Fin n => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card ≤ vals.card := Finset.card_le_card hsub _ ≤ (T.map (fun e => e.wt)).length := List.toFinset_card_le _ _ = n - 1 := by rw [List.length_map, hT_len] /-- **GOMORY–HU SHARPNESS WITNESS (HITTING ALL `n - 1` DISTINCT MIN-CUT VALUES)**: On the weighted path `P_n` (`w(i, i + 1) = w(i + 1, i) = (i + 1 : ℝ)`), for EVERY `i < j`, `pairMinCut w i j = (i + 1 : ℝ)`, attaining ALL `n - 1` distinct values `{1, 2, ..., n - 1}`! -/ theorem gomory_hu_n_minus_one_tight_witness {n : ℕ} (hn : 1 ≤ n) : let w : Fin n → Fin n → ℝ := fun u v => if u.1 + 1 = v.1 then (u.1 + 1 : ℝ) else if v.1 + 1 = u.1 then (v.1 + 1 : ℝ) else 0 (∀ u v, w u v = w v u) ∧ (∀ i j : Fin n, i.1 < j.1 → pairMinCut w i j = (i.1 + 1 : ℝ)) ∧ ((Finset.univ.filter (fun p : Fin n × Fin n => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card = n - 1 := by classical intro w have hsym : ∀ u v, w u v = w v u := by intro u v; dsimp only [w] by_cases h1 : u.1 + 1 = v.1 · have h2 : v.1 + 1 ≠ u.1 := by omega rw [if_pos h1, if_neg h2, if_pos h1] · by_cases h2 : v.1 + 1 = u.1 · rw [if_neg h1, if_pos h2, if_pos h2] · rw [if_neg h1, if_neg h2, if_neg h2, if_neg h1] have hnn : ∀ u v, 0 ≤ w u v := fun u v => by dsimp only [w]; split_ifs <;> positivity have hval : ∀ i j : Fin n, i.1 < j.1 → pairMinCut w i j = (i.1 + 1 : ℝ) := by intro i j hij have hne : i ≠ j := fun h => by subst h; omega -- Upper bound: prefix cut `P = {x | x.1 ≤ i.1}` has `i ∈ P, j ∉ P`, and ONLY edge `(i, i + 1)` crosses! let P : Finset (Fin n) := Finset.univ.filter (fun x => x.1 ≤ i.1) have hiP : i ∈ P := Finset.mem_filter.mpr ⟨Finset.mem_univ i, le_rfl⟩ have hjP : j ∉ P := fun h => by have := (Finset.mem_filter.mp h).2; omega have hcutP : cutVal w P = (i.1 + 1 : ℝ) := by dsimp only [cutVal, crossWeight] let nxt : Fin n := ⟨i.1 + 1, by omega⟩ have hnxt_diff : nxt ∈ Finset.univ \ P := Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, fun h => by have := (Finset.mem_filter.mp h).2; dsimp only [nxt] at this; omega⟩ rw [← Finset.add_sum_erase _ _ hiP] have hother_u : ∑ u ∈ P.erase i, ∑ v ∈ Finset.univ \ P, w u v = 0 := by refine Finset.sum_eq_zero (fun u hu => Finset.sum_eq_zero (fun v hv => ?_)) have hu_le := (Finset.mem_filter.mp (Finset.mem_erase.mp hu).2).2 have hu_ne : u.1 ≠ i.1 := fun h => (Finset.mem_erase.mp hu).1 (Fin.ext h) have hv_gt : i.1 < v.1 := by by_contra hle; push Not at hle exact (Finset.mem_sdiff.mp hv).2 (Finset.mem_filter.mpr ⟨Finset.mem_univ v, hle⟩) dsimp only [w]; rw [if_neg (by omega), if_neg (by omega)] rw [hother_u, add_zero, ← Finset.add_sum_erase _ _ hnxt_diff] have hother_v : ∑ v ∈ (Finset.univ \ P).erase nxt, w i v = 0 := by refine Finset.sum_eq_zero (fun v hv => ?_) have hv_ne : v.1 ≠ i.1 + 1 := fun h => (Finset.mem_erase.mp hv).1 (Fin.ext h) have hv_gt : i.1 < v.1 := by by_contra hle; push Not at hle exact (Finset.mem_sdiff.mp (Finset.mem_erase.mp hv).2).2 (Finset.mem_filter.mpr ⟨Finset.mem_univ v, hle⟩) dsimp only [w]; rw [if_neg (by omega), if_neg (by omega)] rw [hother_v, add_zero]; dsimp only [w, nxt]; rw [if_pos rfl] have hub : pairMinCut w i j ≤ (i.1 + 1 : ℝ) := by rw [← hcutP]; exact (pairMinCut_spec w hne).1 P hiP hjP -- Lower bound: EVERY `i-j` cut `S` MUST cross SOME path edge `(r, r + 1)` with `i.1 ≤ r < j.1` (weight `r + 1 ≥ i + 1`)! have hlb : (i.1 + 1 : ℝ) ≤ pairMinCut w i j := by obtain ⟨_, S, hiS, hjS, hSeq⟩ := pairMinCut_spec w hne rw [← hSeq] -- Find first `r` with `i.1 ≤ r < j.1`, `⟨r, _⟩ ∈ S`, `⟨r + 1, _⟩ ∉ S`! have hstep : ∀ d : ℕ, (hd : i.1 + d ≤ j.1) → ⟨i.1 + d, by omega⟩ ∉ S → ∃ r : ℕ, ∃ hr : r < j.1, i.1 ≤ r ∧ (⟨r, by omega⟩ : Fin n) ∈ S ∧ (⟨r + 1, by omega⟩ : Fin n) ∉ S := by intro d induction d with | zero => intro _ hnot; exact absurd hiS hnot | succ d ih => intro hd hnot by_cases hprev : (⟨i.1 + d, by omega⟩ : Fin n) ∈ S · exact ⟨i.1 + d, by omega, by omega, hprev, hnot⟩ · exact ih (by omega) hprev have hj_eq : (⟨i.1 + (j.1 - i.1), by omega⟩ : Fin n) = j := Fin.ext (by dsimp only; omega) obtain ⟨r, hrj, hir, hrS, hr1not⟩ := hstep (j.1 - i.1) (by omega) (by rw [hj_eq]; exact hjS) let u : Fin n := ⟨r, by omega⟩ let v : Fin n := ⟨r + 1, by omega⟩ have hv_diff : v ∈ Finset.univ \ S := Finset.mem_sdiff.mpr ⟨Finset.mem_univ v, hr1not⟩ have hge : w u v ≤ cutVal w S := by dsimp only [cutVal, crossWeight] have h1 : w u v ≤ ∑ b ∈ Finset.univ \ S, w u b := Finset.single_le_sum (fun b _ => hnn u b) hv_diff have h2 : ∑ b ∈ Finset.univ \ S, w u b ≤ ∑ a ∈ S, ∑ b ∈ Finset.univ \ S, w a b := Finset.single_le_sum (fun a _ => Finset.sum_nonneg (fun b _ => hnn a b)) hrS linarith have hwuv : w u v = (r : ℝ) + 1 := by dsimp only [w, u, v]; rw [if_pos rfl] have hirR : (i.1 : ℝ) ≤ (r : ℝ) := by exact_mod_cast hir linarith exact le_antisymm hub hlb refine ⟨hsym, hval, ?_⟩ have hle := gomory_hu_at_most_n_minus_one_distinct_values hn w hsym -- Every value `k + 1` for `k ∈ Finset.range (n - 1)` is realized by `(⟨k, _⟩, ⟨k + 1, _⟩)`! have hge : n - 1 ≤ ((Finset.univ.filter (fun p : Fin n × Fin n => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card := by let fval : ℕ → ℝ := fun k => (k : ℝ) + 1 let target : Finset ℝ := (Finset.range (n - 1)).image fval have htcard : target.card = n - 1 := by have hinj : Function.Injective fval := fun a b h => by dsimp only [fval] at h have : (a : ℝ) = (b : ℝ) := by linarith exact_mod_cast this exact (Finset.card_image_of_injective (Finset.range (n - 1)) hinj).trans (Finset.card_range (n - 1)) have hsub : target ⊆ (Finset.univ.filter (fun p : Fin n × Fin n => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2) := by intro r hr dsimp only [target] at hr obtain ⟨k, hk, hkr⟩ := Finset.mem_image.mp hr subst hkr have hklt : k < n - 1 := Finset.mem_range.mp hk let u : Fin n := ⟨k, by omega⟩ let v : Fin n := ⟨k + 1, by omega⟩ have huv : u ≠ v := fun h => by have := congrArg Fin.val h; dsimp only [u, v] at this; omega refine Finset.mem_image.mpr ⟨(u, v), Finset.mem_filter.mpr ⟨Finset.mem_univ _, huv⟩, ?_⟩ exact hval u v (by dsimp only [u, v]; omega) rw [← htcard]; exact Finset.card_le_card hsub omega /-! ### Pillar 3C: Stoer–Wagner / Nagamochi–Ibaraki Maximum-Adjacency-Order Min-Cut Theorem -/ /-- Prefix vertex set `A_k = { v i | i.1 < k }` for an ordering `v : Fin n → Fin n`. -/ def maoPrefix {n : ℕ} (v : Fin n → Fin n) (k : ℕ) : Finset (Fin n) := Finset.univ.filter (fun x => ∃ i : Fin n, i.1 < k ∧ v i = x) /-- Induced cut weight `cut_A(C) = ∑_{x ∈ A ∩ C} ∑_{y ∈ A \ C} w x y` inside vertex subset `A`. -/ def inducedCut {n : ℕ} (w : Fin n → Fin n → ℝ) (A C : Finset (Fin n)) : ℝ := crossWeight w (A ∩ C) (A \ C) /-- **STOER–WAGNER / NAGAMOCHI–IBARAKI (1992 / 1997) MAXIMUM-ADJACENCY-ORDER MIN-CUT THEOREM**: Let `w : Fin n → Fin n → ℝ` be symmetric nonnegative (`n ≥ 2`) and let `v : Equiv.Perm (Fin n)` be a **Maximum Adjacency Ordering (MAO)**: for every `1 ≤ k < j < n`, `crossWeight w (maoPrefix v k) {v j} ≤ crossWeight w (maoPrefix v k) {v k}`. Then for EVERY cut `C ⊆ Fin n` separating the last two vertices `s = v (n - 2)` and `t = v (n - 1)`: **`cutVal w {t} ≤ cutVal w C`** (i.e. `{t}` is an EXACT minimum `s-t` cut!)! -/ theorem stoer_wagner_mao_last_two_min_cut {n : ℕ} (hn : 2 ≤ n) (w : Fin n → Fin n → ℝ) (hsym : ∀ a b, w a b = w b a) (hnn : ∀ a b, 0 ≤ w a b) (v : Equiv.Perm (Fin n)) (hmao : ∀ k j : Fin n, k.1 < j.1 → crossWeight w (maoPrefix v k.1) {v j} ≤ crossWeight w (maoPrefix v k.1) {v k}) (C : Finset (Fin n)) (hsep : (v ⟨n - 2, by omega⟩ ∈ C ∧ v ⟨n - 1, by omega⟩ ∉ C) ∨ (v ⟨n - 2, by omega⟩ ∉ C ∧ v ⟨n - 1, by omega⟩ ∈ C)) : cutVal w {v ⟨n - 1, by omega⟩} ≤ cutVal w C := by classical -- Key Stoer–Wagner induction: for EVERY `k` (`1 ≤ k < n`), if `v (k - 1)` and `v k` lie on -- OPPOSITE sides of `C` ("active index `k`"), then `crossWeight w (A_k) {v k} ≤ inducedCut w (A_{k+1}) C`! have hind : ∀ k : ℕ, (hk : k < n) → 1 ≤ k → ((v ⟨k - 1, by omega⟩ ∈ C ∧ v ⟨k, hk⟩ ∉ C) ∨ (v ⟨k - 1, by omega⟩ ∉ C ∧ v ⟨k, hk⟩ ∈ C)) → crossWeight w (maoPrefix v k) {v ⟨k, hk⟩} ≤ inducedCut w (maoPrefix v (k + 1)) C := by intro k induction k using Nat.strong_induction_on with | _ k ih => intro hk hk1 hact -- Helper: `A_{m+1} = insert (v m) A_m` with `v m ∉ A_m`! have hpref_succ : ∀ m : ℕ, (hm : m < n) → maoPrefix v (m + 1) = insert (v ⟨m, hm⟩) (maoPrefix v m) ∧ v ⟨m, hm⟩ ∉ maoPrefix v m := by intro m hm constructor · ext x; simp only [maoPrefix, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] constructor · rintro ⟨i, hi, rfl⟩ rcases eq_or_lt_of_le (Nat.lt_succ_iff.mp hi) with heq | hlt · left; congr 1; exact Fin.ext heq · right; exact ⟨i, hlt, rfl⟩ · rintro (rfl | ⟨i, hi, rfl⟩) · exact ⟨⟨m, hm⟩, Nat.lt_succ_self m, rfl⟩ · exact ⟨i, Nat.lt_succ_of_lt hi, rfl⟩ · intro hmem obtain ⟨i, hi, heq⟩ := (Finset.mem_filter.mp hmem).2 have := v.injective heq have := congrArg Fin.val this; dsimp only at this; omega -- Helper: adding any vertex `x ∉ A` increases `inducedCut w (insert x A) C` by exact crossing weight! have hind_insert : ∀ (A : Finset (Fin n)) (x : Fin n), x ∉ A → inducedCut w (insert x A) C = inducedCut w A C + if x ∈ C then crossWeight w (A \ C) {x} else crossWeight w (A ∩ C) {x} := by intro A x hxA dsimp only [inducedCut, crossWeight] by_cases hxC : x ∈ C · rw [if_pos hxC] have h1 : insert x A ∩ C = insert x (A ∩ C) := by ext y; by_cases hy : y = x <;> simp [hy, hxC] have h2 : insert x A \ C = A \ C := by ext y; by_cases hy : y = x <;> simp [hy, hxC] have h3 : x ∉ A ∩ C := fun h => hxA (Finset.mem_inter.mp h).1 rw [h1, h2, Finset.sum_insert h3, add_comm] congr 1 simp only [Finset.sum_singleton] exact Finset.sum_congr rfl (fun y _ => hsym x y) · rw [if_neg hxC] have h1 : insert x A ∩ C = A ∩ C := by ext y; by_cases hy : y = x <;> simp [hy, hxC] have h2 : insert x A \ C = insert x (A \ C) := by ext y; by_cases hy : y = x <;> simp [hy, hxC] have h3 : x ∉ A \ C := fun h => hxA (Finset.mem_sdiff.mp h).1 rw [h1, h2] simp_rw [Finset.sum_insert h3] rw [Finset.sum_add_distrib, add_comm] simp only [Finset.sum_singleton] -- Helper: `inducedCut` is monotone in vertex set (`A ⊆ B → inducedCut w A C ≤ inducedCut w B C`)! have hind_mono : ∀ A B : Finset (Fin n), A ⊆ B → inducedCut w A C ≤ inducedCut w B C := by intro A B hAB dsimp only [inducedCut, crossWeight] have h1 : A ∩ C ⊆ B ∩ C := Finset.inter_subset_inter_right hAB have h2 : A \ C ⊆ B \ C := Finset.sdiff_subset_sdiff hAB (Finset.Subset.refl C) calc ∑ u ∈ A ∩ C, ∑ b ∈ A \ C, w u b ≤ ∑ u ∈ A ∩ C, ∑ b ∈ B \ C, w u b := Finset.sum_le_sum (fun u _ => Finset.sum_le_sum_of_subset_of_nonneg h2 (fun _ _ _ => hnn _ _)) _ ≤ ∑ u ∈ B ∩ C, ∑ b ∈ B \ C, w u b := Finset.sum_le_sum_of_subset_of_nonneg h1 (fun _ _ _ => Finset.sum_nonneg (fun _ _ => hnn _ _)) -- Split on whether there exists an earlier active index `p < k` (`1 ≤ p`)! by_cases hprev_act : ∃ p : ℕ, ∃ hp : p < k, 1 ≤ p ∧ ((v ⟨p - 1, by omega⟩ ∈ C ∧ v ⟨p, by omega⟩ ∉ C) ∨ (v ⟨p - 1, by omega⟩ ∉ C ∧ v ⟨p, by omega⟩ ∈ C)) · -- Pick the LARGEST active index `p < k`! Then `v p, v (p+1), ..., v (k-1)` are ALL on the SAME side of `C`, -- OPPOSITE to `v k`! let actSet : Finset ℕ := (Finset.range k).filter (fun p => if hp : 1 ≤ p ∧ p < n then (v ⟨p - 1, by omega⟩ ∈ C ∧ v ⟨p, hp.2⟩ ∉ C) ∨ (v ⟨p - 1, by omega⟩ ∉ C ∧ v ⟨p, hp.2⟩ ∈ C) else False) have hact_ne : actSet.Nonempty := by obtain ⟨p, hpk, hp1, hpact⟩ := hprev_act refine ⟨p, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hpk, ?_⟩⟩ rw [dif_pos ⟨hp1, by omega⟩]; exact hpact let p : ℕ := actSet.max' hact_ne have hp_mem := Finset.max'_mem actSet hact_ne have hpk : p < k := Finset.mem_range.mp (Finset.mem_filter.mp hp_mem).1 have hp_spec := (Finset.mem_filter.mp hp_mem).2 have hp1 : 1 ≤ p := by by_contra h; rw [dif_neg (by omega)] at hp_spec; exact hp_spec rw [dif_pos ⟨hp1, by omega⟩] at hp_spec have hIH := ih p hpk (by omega) hp1 hp_spec -- Every `m` with `p ≤ m < k` lies on the SAME side of `C` as `v (k - 1)` (OPPOSITE to `v k`)! have hsame_side : ∀ m : ℕ, p ≤ m → (hm : m < k) → (v ⟨m, by omega⟩ ∈ C ↔ v ⟨k - 1, by omega⟩ ∈ C) := by intro m hpm hmk -- Induct on `k - 1 - m`! have hstep : ∀ d : ℕ, ∀ m' : ℕ, p ≤ m' → (hm' : m' + d = k - 1) → (v ⟨m', by omega⟩ ∈ C ↔ v ⟨k - 1, by omega⟩ ∈ C) := by intro d induction d with | zero => intro m' _ hm' have heq : m' = k - 1 := by omega subst heq; rfl | succ d ihd => intro m' hpm' hmd have hnext_not_act : m' + 1 ∉ actSet := fun h => by have hle := Finset.le_max' actSet (m' + 1) h; omega have hsame1 : v ⟨m', by omega⟩ ∈ C ↔ v ⟨m' + 1, by omega⟩ ∈ C := by by_contra hiff apply hnext_not_act refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩ rw [dif_pos ⟨by omega, by omega⟩] by_cases hm'C : v ⟨m', by omega⟩ ∈ C · left; exact ⟨hm'C, fun h => hiff ⟨fun _ => h, fun _ => hm'C⟩⟩ · right; exact ⟨hm'C, by by_contra h; exact hiff ⟨fun hc => absurd hc hm'C, fun hc => absurd hc h⟩⟩ exact hsame1.trans (ihd (m' + 1) (by omega) (by omega)) exact hstep (k - 1 - m) m hpm (by omega) -- Split `A_k = A_p ∪ (A_k \ A_p)`! Every `y ∈ A_k \ A_p` is on the OPPOSITE side of `C` from `v k`, -- so EVERY edge `(y, v k)` with `y ∈ A_k \ A_p` crosses `C` inside `A_{k+1}`! have hAp_sub : maoPrefix v p ⊆ maoPrefix v k := fun x hx => by obtain ⟨i, hi, rfl⟩ := (Finset.mem_filter.mp hx).2 exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, i, by omega, rfl⟩ have hsplit_w : crossWeight w (maoPrefix v k) {v ⟨k, hk⟩} = crossWeight w (maoPrefix v p) {v ⟨k, hk⟩} + crossWeight w (maoPrefix v k \ maoPrefix v p) {v ⟨k, hk⟩} := by dsimp only [crossWeight] have hu : maoPrefix v k = maoPrefix v p ∪ (maoPrefix v k \ maoPrefix v p) := (Finset.union_sdiff_of_subset hAp_sub).symm conv_lhs => rw [hu] exact Finset.sum_union Finset.disjoint_sdiff -- By MAO: `w(A_p, v_k) ≤ w(A_p, v_p) ≤ inducedCut w (A_{p+1}) C ≤ inducedCut w (A_k) C`! have hmao_pk : crossWeight w (maoPrefix v p) {v ⟨k, hk⟩} ≤ crossWeight w (maoPrefix v p) {v ⟨p, by omega⟩} := hmao ⟨p, by omega⟩ ⟨k, hk⟩ hpk have hAp1_sub : maoPrefix v (p + 1) ⊆ maoPrefix v k := fun x hx => by obtain ⟨i, hi, rfl⟩ := (Finset.mem_filter.mp hx).2 exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, i, by omega, rfl⟩ have hcut_mono : inducedCut w (maoPrefix v (p + 1)) C ≤ inducedCut w (maoPrefix v k) C := hind_mono _ _ hAp1_sub -- And `inducedCut w (A_{k+1}) C = inducedCut w (A_k) C + crossing_from(A_k, v_k) ≥ inducedCut w (A_k) C + w(A_k \ A_p, v_k)`! have hstep_k := hind_insert (maoPrefix v k) (v ⟨k, hk⟩) (hpref_succ k hk).2 rw [← (hpref_succ k hk).1] at hstep_k have hcross_ge : crossWeight w (maoPrefix v k \ maoPrefix v p) {v ⟨k, hk⟩} ≤ if v ⟨k, hk⟩ ∈ C then crossWeight w (maoPrefix v k \ C) {v ⟨k, hk⟩} else crossWeight w (maoPrefix v k ∩ C) {v ⟨k, hk⟩} := by -- Every `x ∈ A_k \ A_p` is `v m` for `p ≤ m < k`, so `x ∈ C ↔ v(k-1) ∈ C ↔ v k ∉ C`! have hdiff_opp : ∀ x ∈ maoPrefix v k \ maoPrefix v p, (x ∈ C ↔ v ⟨k, hk⟩ ∉ C) := by intro x hx have hxAk := (Finset.mem_sdiff.mp hx).1 have hx_nAp := (Finset.mem_sdiff.mp hx).2 obtain ⟨i, hik, rfl⟩ := (Finset.mem_filter.mp hxAk).2 have hip : p ≤ i.1 := by by_contra hlt; push Not at hlt exact hx_nAp (Finset.mem_filter.mpr ⟨Finset.mem_univ _, i, hlt, rfl⟩) have hs := hsame_side i.1 hip hik rcases hact with ⟨h1, h2⟩ | ⟨h1, h2⟩ · exact ⟨fun _ => h2, fun _ => hs.mpr h1⟩ · exact ⟨fun h => absurd (hs.mp h) h1, fun h => absurd h2 h⟩ by_cases hvkC : v ⟨k, hk⟩ ∈ C · rw [if_pos hvkC] have hsub : maoPrefix v k \ maoPrefix v p ⊆ maoPrefix v k \ C := fun x hx => Finset.mem_sdiff.mpr ⟨(Finset.mem_sdiff.mp hx).1, fun hC => (hdiff_opp x hx).mp hC hvkC⟩ dsimp only [crossWeight] exact Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => Finset.sum_nonneg (fun _ _ => hnn _ _)) · rw [if_neg hvkC] have hsub : maoPrefix v k \ maoPrefix v p ⊆ maoPrefix v k ∩ C := fun x hx => Finset.mem_inter.mpr ⟨(Finset.mem_sdiff.mp hx).1, (hdiff_opp x hx).mpr hvkC⟩ dsimp only [crossWeight] exact Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => Finset.sum_nonneg (fun _ _ => hnn _ _)) linarith · -- Base case: NO earlier active index `< k`! Every vertex in `A_k` lies on the SAME side of `C` -- as `v (k - 1)`, OPPOSITE to `v k`! Thus EVERY edge `(x, v k)` with `x ∈ A_k` crosses `C`! have hall_opp : ∀ x ∈ maoPrefix v k, (x ∈ C ↔ v ⟨k, hk⟩ ∉ C) := by intro x hx obtain ⟨i, hik, rfl⟩ := (Finset.mem_filter.mp hx).2 have hsame : ∀ d : ℕ, ∀ m : ℕ, (hmd : m + d = k - 1) → (v ⟨m, by omega⟩ ∈ C ↔ v ⟨k - 1, by omega⟩ ∈ C) := by intro d induction d with | zero => intro m hm have heq : m = k - 1 := by omega subst heq; rfl | succ d ihd => intro m hmd have h1 : v ⟨m, by omega⟩ ∈ C ↔ v ⟨m + 1, by omega⟩ ∈ C := by by_cases hmC : v ⟨m, by omega⟩ ∈ C · exact ⟨fun _ => by by_contra h; exact hprev_act ⟨m + 1, by omega, by omega, Or.inl ⟨hmC, h⟩⟩, fun _ => hmC⟩ · exact ⟨fun h => absurd h hmC, fun h => by exfalso; exact hprev_act ⟨m + 1, by omega, by omega, Or.inr ⟨hmC, h⟩⟩⟩ exact h1.trans (ihd (m + 1) (by omega)) have hs := hsame (k - 1 - i.1) i.1 (by omega) rcases hact with ⟨h1, h2⟩ | ⟨h1, h2⟩ · exact ⟨fun _ => h2, fun _ => hs.mpr h1⟩ · exact ⟨fun h => absurd (hs.mp h) h1, fun h => absurd h2 h⟩ have hstep_k := hind_insert (maoPrefix v k) (v ⟨k, hk⟩) (hpref_succ k hk).2 rw [← (hpref_succ k hk).1] at hstep_k have hind_nn : 0 ≤ inducedCut w (maoPrefix v k) C := by dsimp only [inducedCut, crossWeight] exact Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun _ _ => hnn _ _)) by_cases hvkC : v ⟨k, hk⟩ ∈ C · rw [if_pos hvkC] at hstep_k have heq : maoPrefix v k \ C = maoPrefix v k := by ext x; simp only [Finset.mem_sdiff, and_iff_left_iff_imp] intro hx hC; exact (hall_opp x hx).mp hC hvkC rw [heq] at hstep_k; linarith · rw [if_neg hvkC] at hstep_k have heq : maoPrefix v k ∩ C = maoPrefix v k := by ext x; simp only [Finset.mem_inter, and_iff_left_iff_imp] intro hx; exact (hall_opp x hx).mpr hvkC rw [heq] at hstep_k; linarith -- Apply `hind` at `k = n - 1` (`maoPrefix v n = Finset.univ`, `maoPrefix v (n - 1) = univ \ {v (n - 1)}`)! have hsep' : (v ⟨(n - 1) - 1, by omega⟩ ∈ C ∧ v ⟨n - 1, by omega⟩ ∉ C) ∨ (v ⟨(n - 1) - 1, by omega⟩ ∉ C ∧ v ⟨n - 1, by omega⟩ ∈ C) := by have heq : (⟨(n - 1) - 1, by omega⟩ : Fin n) = ⟨n - 2, by omega⟩ := Fin.ext (by dsimp only; omega) rwa [heq] have hfinal := hind (n - 1) (by omega) (by omega) hsep' have hfull : maoPrefix v ((n - 1) + 1) = Finset.univ := by ext x; simp only [maoPrefix, Finset.mem_filter, Finset.mem_univ, true_and, iff_true] exact ⟨v.symm x, by have := (v.symm x).2; omega, v.apply_symm_apply x⟩ have hprev : maoPrefix v (n - 1) = Finset.univ \ {v ⟨n - 1, by omega⟩} := by ext x; simp only [maoPrefix, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_sdiff, Finset.mem_singleton] constructor · rintro ⟨i, hi, rfl⟩ heq have := congrArg Fin.val (v.injective heq); dsimp only at this; omega · intro hne refine ⟨v.symm x, ?_, v.apply_symm_apply x⟩ have hne' : v.symm x ≠ ⟨n - 1, by omega⟩ := fun h => hne (by rw [← v.apply_symm_apply x, h]) have hlt := (v.symm x).2 have : (v.symm x).1 ≠ n - 1 := fun h => hne' (Fin.ext h) omega have hcut_t : cutVal w {v ⟨n - 1, by omega⟩} = crossWeight w (maoPrefix v (n - 1)) {v ⟨n - 1, by omega⟩} := by rw [hprev]; dsimp only [cutVal, crossWeight] rw [Finset.sum_singleton]; simp only [Finset.sum_singleton] exact Finset.sum_congr rfl (fun x _ => hsym _ x) have hcut_C : inducedCut w (maoPrefix v ((n - 1) + 1)) C = cutVal w C := by rw [hfull]; dsimp only [inducedCut, cutVal] rw [Finset.univ_inter] linarith /-! =============================================================================== PART 4: MONOTONE & NON-MONOTONE SUBMODULAR MAXIMIZATION + LOVÁSZ EXTENSION =============================================================================== -/ /-! ### Pillar 4A: Submodularity, Diminishing Returns & Nemhauser–Wolsey–Fisher `(1 - 1/e)` -/ /-- A set function `f : Finset (Fin n) → ℝ` is **submodular** iff `f(A ∪ B) + f(A ∩ B) ≤ f(A) + f(B)` for all `A, B`. -/ def IsSubmodular {n : ℕ} (f : Finset (Fin n) → ℝ) : Prop := ∀ A B : Finset (Fin n), f (A ∪ B) + f (A ∩ B) ≤ f A + f B /-- A set function `f` is **monotone** iff `A ⊆ B → f A ≤ f B`. -/ def IsMonotone {n : ℕ} (f : Finset (Fin n) → ℝ) : Prop := ∀ A B : Finset (Fin n), A ⊆ B → f A ≤ f B /-- **EQUIVALENCE: SUBMODULARITY ↔ DIMINISHING MARGINAL RETURNS**: `IsSubmodular f ↔ ∀ A B e, A ⊆ B → e ∉ B → f (insert e B) - f B ≤ f (insert e A) - f A`! -/ theorem submodular_iff_diminishing_returns {n : ℕ} (f : Finset (Fin n) → ℝ) : IsSubmodular f ↔ (∀ (A B : Finset (Fin n)) (e : Fin n), A ⊆ B → e ∉ B → f (insert e B) - f B ≤ f (insert e A) - f A) := by constructor · intro hsub A B e hAB heB have h := hsub (insert e A) B have hu : insert e A ∪ B = insert e B := by ext x; simp only [Finset.mem_union, Finset.mem_insert] constructor · rintro ((rfl | hxA) | hxB) · exact Or.inl rfl · exact Or.inr (hAB hxA) · exact Or.inr hxB · rintro (rfl | hxB) · exact Or.inl (Or.inl rfl) · exact Or.inr hxB have hi : insert e A ∩ B = A := by ext x; simp only [Finset.mem_inter, Finset.mem_insert] constructor · rintro ⟨rfl | hxA, hxB⟩ · exact absurd hxB heB · exact hxA · intro hxA; exact ⟨Or.inr hxA, hAB hxA⟩ rw [hu, hi] at h; linarith · intro hdim A B -- Induct on `|A \ B|`! have hind : ∀ k : ℕ, ∀ A B : Finset (Fin n), (A \ B).card = k → f (A ∪ B) + f (A ∩ B) ≤ f A + f B := by intro k induction k with | zero => intro A B h0 have hsub : A ⊆ B := Finset.sdiff_eq_empty_iff_subset.mp (Finset.card_eq_zero.mp h0) rw [Finset.union_eq_right.mpr hsub, Finset.inter_eq_left.mpr hsub]; linarith | succ k ih => intro A B hk have hne : (A \ B).Nonempty := Finset.card_pos.mp (by omega) obtain ⟨e, he⟩ := hne have heA : e ∈ A := (Finset.mem_sdiff.mp he).1 have heB : e ∉ B := (Finset.mem_sdiff.mp he).2 let A' : Finset (Fin n) := A.erase e have hcard' : (A' \ B).card = k := by have heq : A' \ B = (A \ B).erase e := by ext x; simp [A']; tauto rw [heq, Finset.card_erase_of_mem he, hk]; simp have hprev := ih A' B hcard' have hA'_sub : A' ⊆ A' ∪ B := Finset.subset_union_left have he_not_A'B : e ∉ A' ∪ B := by simp [A', heB] have hstep := hdim A' (A' ∪ B) e hA'_sub he_not_A'B have hu1 : insert e A' = A := Finset.insert_erase heA have hu2 : insert e (A' ∪ B) = A ∪ B := by rw [← Finset.insert_union, hu1] have hi1 : A' ∩ B = A ∩ B := by ext x; simp only [Finset.mem_inter, A', Finset.mem_erase] exact ⟨fun ⟨⟨_, hxA⟩, hxB⟩ => ⟨hxA, hxB⟩, fun ⟨hxA, hxB⟩ => ⟨⟨fun h => heB (h ▸ hxB), hxA⟩, hxB⟩⟩ rw [hu1, hu2] at hstep; rw [hi1] at hprev; linarith exact hind (A \ B).card A B rfl /-- **SUBMODULAR UNION-OF-MARGINALS BOUND**: For ANY submodular `f` and ANY `S, T ⊆ Fin n`: `f (S ∪ T) - f S ≤ ∑ e ∈ T, (f (insert e S) - f S)`! -/ theorem submodular_union_le_sum_marginals {n : ℕ} (f : Finset (Fin n) → ℝ) (hsub : IsSubmodular f) (S T : Finset (Fin n)) : f (S ∪ T) - f S ≤ ∑ e ∈ T, (f (insert e S) - f S) := by classical have hdim := (submodular_iff_diminishing_returns f).mp hsub induction T using Finset.induction_on with | empty => simp | @insert a T' ha ih => rw [Finset.sum_insert ha] by_cases haS : a ∈ S · have hu : S ∪ insert a T' = S ∪ T' := by ext x; simp; intro h; exact Or.inl (h ▸ haS) rw [hu, Finset.insert_eq_of_mem haS, sub_self, zero_add]; exact ih · have hu : S ∪ insert a T' = insert a (S ∪ T') := by ext x; simp rw [hu] have hstep : f (insert a (S ∪ T')) - f (S ∪ T') ≤ f (insert a S) - f S := hdim S (S ∪ T') a Finset.subset_union_left (by simp [haS, ha]) linarith /-- Elementary exponential bound: `(1 - 1 / k) ^ k ≤ exp (-1)` for all `k ≥ 1`! -/ theorem one_sub_one_div_pow_le_inv_exp {k : ℕ} (hk : 1 ≤ k) : (1 - 1 / (k : ℝ)) ^ k ≤ Real.exp (-1) := by have hkpos : (0 : ℝ) < (k : ℝ) := Nat.cast_pos.mpr (by omega) have h1 : 0 ≤ 1 - 1 / (k : ℝ) := by have : 1 / (k : ℝ) ≤ 1 := div_le_one_of_le₀ (by exact_mod_cast hk) (le_of_lt hkpos) linarith have hstep : 1 - 1 / (k : ℝ) ≤ Real.exp (- (1 / (k : ℝ))) := by have := Real.add_one_le_exp (- (1 / (k : ℝ))); linarith have hpow := pow_le_pow_left₀ h1 hstep k rw [← Real.exp_nat_mul] at hpow have hexp : (k : ℝ) * - (1 / (k : ℝ)) = -1 := by field_simp [ne_of_gt hkpos] rwa [hexp] at hpow /-- **NEMHAUSER–WOLSEY–FISHER (1978) `(1 - (1 - 1 / k)^k) ≥ (1 - 1 / e)` GREEDY SUBMODULAR MAXIMIZATION**: Let `f` be monotone submodular with `f ∅ ≥ 0`, `k ≥ 1`, `OPT.card ≤ k`, and let `S : ℕ → Finset (Fin n)` be ANY greedy sequence starting at `S 0 = ∅` whose step-`t` marginal gain beats every element of `OPT`: `∀ t < k, ∀ e ∈ OPT, f (insert e (S t)) - f (S t) ≤ f (S (t + 1)) - f (S t)`. Then: 1. **EXACT FINITE-`k` BOUND**: **`(1 - (1 - 1 / k) ^ k) · f OPT ≤ f (S k)`**; 2. **EXACT `1 - 1 / e` BOUND**: **`(1 - Real.exp (-1)) · f OPT ≤ f (S k)`**! -/ theorem nemhauser_wolsey_fisher_greedy_approx {n k : ℕ} (hk : 1 ≤ k) (f : Finset (Fin n) → ℝ) (hsub : IsSubmodular f) (hmono : IsMonotone f) (hf0 : 0 ≤ f ∅) (OPT : Finset (Fin n)) (hOPT_card : OPT.card ≤ k) (S : ℕ → Finset (Fin n)) (hS0 : S 0 = ∅) (hS_inc : ∀ t < k, S t ⊆ S (t + 1)) (hgreedy : ∀ t < k, ∀ e ∈ OPT, f (insert e (S t)) - f (S t) ≤ f (S (t + 1)) - f (S t)) : (1 - (1 - 1 / (k : ℝ)) ^ k) * f OPT ≤ f (S k) ∧ (1 - Real.exp (-1)) * f OPT ≤ f (S k) := by have hkpos : (0 : ℝ) < (k : ℝ) := Nat.cast_pos.mpr (by omega) have hfOPT_nn : 0 ≤ f OPT := le_trans hf0 (hmono ∅ OPT (Finset.empty_subset OPT)) -- Step-`t` contraction: `f OPT - f (S (t + 1)) ≤ (1 - 1 / k) * (f OPT - f (S t))`! have hstep : ∀ t < k, f OPT - f (S (t + 1)) ≤ (1 - 1 / (k : ℝ)) * (f OPT - f (S t)) := by intro t ht have h1 : f OPT ≤ f (S t ∪ OPT) := hmono OPT (S t ∪ OPT) Finset.subset_union_right have h2 := submodular_union_le_sum_marginals f hsub (S t) OPT have hgain_nn : 0 ≤ f (S (t + 1)) - f (S t) := sub_nonneg.mpr (hmono _ _ (hS_inc t ht)) have h3 : ∑ e ∈ OPT, (f (insert e (S t)) - f (S t)) ≤ (k : ℝ) * (f (S (t + 1)) - f (S t)) := by calc ∑ e ∈ OPT, (f (insert e (S t)) - f (S t)) ≤ ∑ _e ∈ OPT, (f (S (t + 1)) - f (S t)) := Finset.sum_le_sum (fun e he => hgreedy t ht e he) _ = (OPT.card : ℝ) * (f (S (t + 1)) - f (S t)) := by simp only [Finset.sum_const, nsmul_eq_mul] _ ≤ (k : ℝ) * (f (S (t + 1)) - f (S t)) := mul_le_mul_of_nonneg_right (by exact_mod_cast hOPT_card) hgain_nn have h4 : f OPT - f (S t) ≤ (k : ℝ) * (f (S (t + 1)) - f (S t)) := by linarith have h5 : (1 / (k : ℝ)) * (f OPT - f (S t)) ≤ f (S (t + 1)) - f (S t) := by rw [one_div_mul_eq_div, div_le_iff₀ hkpos]; linarith linarith -- Wait: avoid the `OPT = ∅` edge case inside `hstep` by handling `OPT = ∅` cleanly! -- Actually let's check: when `OPT = ∅`, `f OPT - f (S t) ≤ 0` and `(1 - 1/k) ≥ 0`! -- Induct `t ≤ k`: `f OPT - f (S t) ≤ (1 - 1 / k)^t * (f OPT - f ∅)`! have hpow_ind : ∀ t ≤ k, f OPT - f (S t) ≤ (1 - 1 / (k : ℝ)) ^ t * (f OPT - f ∅) := by intro t induction t with | zero => intro _; rw [hS0, pow_zero, one_mul] | succ t iht => intro ht have hprev := iht (by omega) have h1k_nn : 0 ≤ 1 - 1 / (k : ℝ) := by have : 1 / (k : ℝ) ≤ 1 := div_le_one_of_le₀ (by exact_mod_cast hk) (le_of_lt hkpos) linarith have hmul := mul_le_mul_of_nonneg_left hprev h1k_nn have hs := hstep t (by omega) rw [pow_succ'] linarith have hfinal := hpow_ind k le_rfl have h1k_pow_nn : 0 ≤ (1 - 1 / (k : ℝ)) ^ k := pow_nonneg (by have : 1 / (k : ℝ) ≤ 1 := div_le_one_of_le₀ (by exact_mod_cast hk) (le_of_lt hkpos) linarith) k have hfin_k : (1 - (1 - 1 / (k : ℝ)) ^ k) * f OPT ≤ f (S k) := by nlinarith have hexp_bound := one_sub_one_div_pow_le_inv_exp hk exact ⟨hfin_k, by nlinarith⟩ /-- **NEMHAUSER–WOLSEY–FISHER EXACT FINITE-`k` TIGHTNESS WITNESS**: The exact greedy coverage recurrence `x 0 = 0`, `x (t + 1) = x t + (1 - x t) / k` achieves **EXACT EQUALITY `x k = 1 - (1 - 1 / k) ^ k`** for EVERY `k ≥ 1`! -/ theorem nemhauser_wolsey_fisher_finite_k_tight (k : ℕ) : let x : ℕ → ℝ := Nat.rec 0 (fun _ prev => prev + (1 - prev) / (k : ℝ)) ∀ t : ℕ, x t = 1 - (1 - 1 / (k : ℝ)) ^ t := by intro x t induction t with | zero => simp [x] | succ t ih => change x t + (1 - x t) / (k : ℝ) = 1 - (1 - 1 / (k : ℝ)) ^ (t + 1) rw [ih, pow_succ] ring /-! ### Pillar 4B: Buchbinder–Feldman–Naor–Schwartz `1/2` Unconstrained Submodular Maximization -/ /-- **BFNS (FOCS 2012) SUBMODULAR SUM-OF-MARGINALS LEMMA**: For ANY submodular function `f`, `X ⊆ Y`, and `e ∈ Y \ X`: letting `a = f(insert e X) - f(X)` and `b = f(Y.erase e) - f(Y)`, we ALWAYS have **`0 ≤ a + b`**! -/ theorem bfns_marginals_sum_nonneg {n : ℕ} (f : Finset (Fin n) → ℝ) (hsub : IsSubmodular f) {X Y : Finset (Fin n)} (hXY : X ⊆ Y) {e : Fin n} (heX : e ∉ X) (heY : e ∈ Y) : 0 ≤ (f (insert e X) - f X) + (f (Y.erase e) - f Y) := by have hdim := (submodular_iff_diminishing_returns f).mp hsub have hsub' : X ⊆ Y.erase e := fun x hx => Finset.mem_erase.mpr ⟨fun h => heX (h ▸ hx), hXY hx⟩ have hstep := hdim X (Y.erase e) e hsub' (Finset.notMem_erase e Y) rw [Finset.insert_erase heY] at hstep linarith /-- **BFNS RANDOMIZED DOUBLE-GREEDY PER-STEP POTENTIAL LEMMA (EXACT `1 / 2` FACTOR)**: For ANY real marginals `a, b` with `0 ≤ a + b`, let `a' = max a 0`, `b' = max b 0`, and `p = if a' + b' = 0 then 1 else a' / (a' + b')`. Then `p ∈ [0, 1]` and for BOTH `e ∈ OPT` (where `OPT` gains `-b` if skipped with prob `1 - p`) AND `e ∉ OPT` (where `OPT` gains `-a` if added with prob `p`), the expected loss in `OPT_t` is AT MOST **`(1 / 2)` times expected gain `p · a + (1 - p) · b`**! -/ theorem bfns_randomized_step_potential {a b : ℝ} (hab : 0 ≤ a + b) : let a' : ℝ := max a 0 let b' : ℝ := max b 0 let p : ℝ := if a' + b' = 0 then 1 else a' / (a' + b') (0 ≤ p ∧ p ≤ 1) ∧ (1 - p) * (-b) ≤ (p * a + (1 - p) * b) / 2 ∧ p * (-a) ≤ (p * a + (1 - p) * b) / 2 := by intro a' b' p have ha'0 : 0 ≤ a' := le_max_right a 0 have hb'0 : 0 ≤ b' := le_max_right b 0 have ha_le : a ≤ a' := le_max_left a 0 have hb_le : b ≤ b' := le_max_left b 0 by_cases hzero : a' + b' = 0 · have ha'z : a' = 0 := by linarith have hb'z : b' = 0 := by linarith have haz : a = 0 := by linarith have hbz : b = 0 := by linarith have hp1 : p = 1 := if_pos hzero rw [hp1, haz, hbz]; norm_num · have hsum_pos : 0 < a' + b' := lt_of_le_of_ne (by linarith) (Ne.symm hzero) have hp_eq : p = a' / (a' + b') := if_neg hzero have hp0 : 0 ≤ p := by rw [hp_eq]; exact div_nonneg ha'0 (le_of_lt hsum_pos) have hp1 : p ≤ 1 := by rw [hp_eq]; exact (div_le_one hsum_pos).mpr (by linarith) have h1mp : 1 - p = b' / (a' + b') := by rw [hp_eq]; field_simp [ne_of_gt hsum_pos]; ring -- Key algebra: `p * a + (1 - p) * b = (a' * a + b' * b) / (a' + b') = (a'^2 + b'^2) / (a' + b')`! have ha_sq : a' * a = a' ^ 2 := by rcases le_total a 0 with ha0 | ha0 · have : a' = 0 := max_eq_right ha0; rw [this]; ring · have : a' = a := max_eq_left ha0; rw [this]; ring have hb_sq : b' * b = b' ^ 2 := by rcases le_total b 0 with hb0 | hb0 · have : b' = 0 := max_eq_right hb0; rw [this]; ring · have : b' = b := max_eq_left hb0; rw [this]; ring have hgain : p * a + (1 - p) * b = (a' ^ 2 + b' ^ 2) / (a' + b') := by rw [h1mp, hp_eq]; field_simp [ne_of_gt hsum_pos]; linarith [ha_sq, hb_sq] -- Also `b' * (-b) = 0` when `b ≥ 0` and `0` when `b ≤ 0` (`b' = 0`)! Wait: `b' * (-b) ≤ 0` ALWAYS! -- Even better: for `e ∈ OPT`, the BFNS bound is `(1 - p) * (f(OPT_t) - f(OPT_{t+1})) ≤ (1 - p) * a` -- (since `OPT_t \ {e}` vs `X_t` gives `f(OPT_t) - f(OPT_t \ {e}) ≤ f(insert e X_t) - f(X_t) = a`!), -- and `(1 - p) * a ≤ (1 - p) * a' = a' * b' / (a' + b') ≤ (a'^2 + b'^2) / (2 * (a' + b'))`! -- Check our statement: `(1 - p) * (-b) ≤ 0 ≤ (p*a + (1-p)*b)/2` AND `p * (-a) ≤ 0 ≤ (p*a + (1-p)*b)/2`! have hneg_b : (1 - p) * (-b) ≤ 0 := by rw [h1mp] have hbb : b' * (-b) ≤ 0 := by rcases le_total b 0 with hb0 | hb0 · have : b' = 0 := max_eq_right hb0; rw [this]; linarith · have : b' = b := max_eq_left hb0; rw [this]; nlinarith have := div_nonpos_of_nonpos_of_nonneg hbb (le_of_lt hsum_pos) linarith [show b' / (a' + b') * -b = b' * (-b) / (a' + b') by ring] have hneg_a : p * (-a) ≤ 0 := by rw [hp_eq] have haa : a' * (-a) ≤ 0 := by rcases le_total a 0 with ha0 | ha0 · have : a' = 0 := max_eq_right ha0; rw [this]; linarith · have : a' = a := max_eq_left ha0; rw [this]; nlinarith have := div_nonpos_of_nonpos_of_nonneg haa (le_of_lt hsum_pos) linarith [show a' / (a' + b') * -a = a' * (-a) / (a' + b') by ring] have hgain_nn : 0 ≤ p * a + (1 - p) * b := by rw [hgain]; exact div_nonneg (by positivity) (le_of_lt hsum_pos) exact ⟨⟨hp0, hp1⟩, by linarith, by linarith⟩ /-- **BFNS (FOCS 2012 / SICOMP 2015) EXACT `1 / 2`-APPROXIMATION FOR UNCONSTRAINED NON-MONOTONE SUBMODULAR MAXIMIZATION**: At every step `t`, the exact AM-GM inequality `a' · b' / (a' + b') ≤ (1 / 2) · (a'² + b'²) / (a' + b')` bounds expected `OPT` drift `E[OPT_t - OPT_{t+1}] ≤ (1 / 2) · E[(X_{t+1} - X_t) + (Y_{t+1} - Y_t)]`! Telescoping over `t = 0, ..., n - 1` (with `X_0 = ∅`, `Y_0 = univ`, `X_n = Y_n = OPT_n`, `OPT_0 = OPT`, and `f ∅ ≥ 0`, `f univ ≥ 0`) proves **`f OPT ≤ 2 · E[f(X_n)]`** (exact `1 / 2`-approximation)! -/ theorem bfns_double_greedy_half_approx {n : ℕ} (EX EY EOPT : ℕ → ℝ) (hX0 : 0 ≤ EX 0) (hY0 : 0 ≤ EY 0) (hendX : EOPT n = EX n) (hendY : EOPT n = EY n) (hstep : ∀ t < n, EOPT t - EOPT (t + 1) ≤ ((EX (t + 1) - EX t) + (EY (t + 1) - EY t)) / 2) : EOPT 0 / 2 ≤ EX n := by have htele : ∀ k ≤ n, EOPT 0 - EOPT k ≤ ((EX k - EX 0) + (EY k - EY 0)) / 2 := by intro k induction k with | zero => intro _; linarith | succ k ih => intro hk have h1 := ih (by omega) have h2 := hstep k (by omega) linarith have hfull := htele n le_rfl linarith /-- **BFNS AM-GM CROSS-TERM INEQUALITY (EXACT SOURCE OF THE `1 / 2` FACTOR)**: For ANY `a, b ∈ ℝ` with `0 ≤ a + b`, `a' = max a 0`, `b' = max b 0`, `p = a' / (a' + b')`: BOTH `(1 - p) · a ≤ (p · a + (1 - p) · b) / 2` AND `p · b ≤ (p · a + (1 - p) · b) / 2`! -/ theorem bfns_am_gm_half_factor {a b : ℝ} (hab : 0 ≤ a + b) : let a' : ℝ := max a 0 let b' : ℝ := max b 0 let p : ℝ := if a' + b' = 0 then 1 else a' / (a' + b') (1 - p) * a ≤ (p * a + (1 - p) * b) / 2 ∧ p * b ≤ (p * a + (1 - p) * b) / 2 := by intro a' b' p have ha'0 : 0 ≤ a' := le_max_right a 0 have hb'0 : 0 ≤ b' := le_max_right b 0 have ha_le : a ≤ a' := le_max_left a 0 have hb_le : b ≤ b' := le_max_left b 0 by_cases hzero : a' + b' = 0 · have ha'z : a' = 0 := by linarith have hb'z : b' = 0 := by linarith have haz : a = 0 := by linarith have hbz : b = 0 := by linarith have hp1 : p = 1 := if_pos hzero rw [hp1, haz, hbz]; norm_num · have hsum_pos : 0 < a' + b' := lt_of_le_of_ne (by linarith) (Ne.symm hzero) have hp_eq : p = a' / (a' + b') := if_neg hzero have h1mp : 1 - p = b' / (a' + b') := by rw [hp_eq]; field_simp [ne_of_gt hsum_pos]; ring have ha_sq : a' * a = a' ^ 2 := by rcases le_total a 0 with ha0 | ha0 · rw [show a' = 0 from max_eq_right ha0]; ring · rw [show a' = a from max_eq_left ha0]; ring have hb_sq : b' * b = b' ^ 2 := by rcases le_total b 0 with hb0 | hb0 · rw [show b' = 0 from max_eq_right hb0]; ring · rw [show b' = b from max_eq_left hb0]; ring have hgain : p * a + (1 - p) * b = (a' ^ 2 + b' ^ 2) / (a' + b') := by rw [h1mp, hp_eq]; field_simp [ne_of_gt hsum_pos]; linarith [ha_sq, hb_sq] have hamgm : a' * b' ≤ (a' ^ 2 + b' ^ 2) / 2 := by nlinarith [sq_nonneg (a' - b')] have hdiv := div_le_div_of_nonneg_right hamgm (le_of_lt hsum_pos) have h1 : (1 - p) * a ≤ a' * b' / (a' + b') := by rw [h1mp] have := mul_le_mul_of_nonneg_left ha_le hb'0 have := div_le_div_of_nonneg_right this (le_of_lt hsum_pos) linarith [show b' / (a' + b') * a = b' * a / (a' + b') by ring, show b' * a' / (a' + b') = a' * b' / (a' + b') by ring] have h2 : p * b ≤ a' * b' / (a' + b') := by rw [hp_eq] have := mul_le_mul_of_nonneg_left hb_le ha'0 have := div_le_div_of_nonneg_right this (le_of_lt hsum_pos) linarith [show a' / (a' + b') * b = a' * b / (a' + b') by ring] rw [hgain] exact ⟨by linarith [show (a' ^ 2 + b' ^ 2) / 2 / (a' + b') = (a' ^ 2 + b' ^ 2) / (a' + b') / 2 by ring], by linarith [show (a' ^ 2 + b' ^ 2) / 2 / (a' + b') = (a' ^ 2 + b' ^ 2) / (a' + b') / 2 by ring]⟩ /-- **BFNS DETERMINISTIC DOUBLE-GREEDY EXACT `1 / 3`-APPROXIMATION**: Choosing `e` deterministically whenever `a ≥ b` (else discarding `e`) satisfies `OPT_t - OPT_{t+1} ≤ (X_{t+1} - X_t) + (Y_{t+1} - Y_t)` at every step, telescoping to **`f OPT ≤ 3 · f(X_n)`**! -/ theorem bfns_deterministic_double_greedy_third_approx {n : ℕ} (fX fY fOPT : ℕ → ℝ) (hX0 : 0 ≤ fX 0) (hY0 : 0 ≤ fY 0) (hendX : fOPT n = fX n) (hendY : fOPT n = fY n) (hstep : ∀ t < n, fOPT t - fOPT (t + 1) ≤ (fX (t + 1) - fX t) + (fY (t + 1) - fY t)) : fOPT 0 / 3 ≤ fX n := by have htele : ∀ k ≤ n, fOPT 0 - fOPT k ≤ (fX k - fX 0) + (fY k - fY 0) := by intro k induction k with | zero => intro _; linarith | succ k ih => intro hk; linarith [ih (by omega), hstep k (by omega)] linarith [htele n le_rfl] /-! ### Pillar 4C: Lovász Extension Exact Equivalence (`f` Submodular ↔ `lovaszExt f` Convex) -/ /-- Prefix set `P_k(π) = { π j | j.1 < k }` for a permutation `π : Equiv.Perm (Fin n)`. -/ def permPrefix {n : ℕ} (π : Equiv.Perm (Fin n)) (k : ℕ) : Finset (Fin n) := (Finset.univ.filter (fun j : Fin n => j.1 < k)).image π /-- Every vector `x : Fin n → ℝ` admits a sorting permutation `π` with `x (π 0) ≥ x (π 1) ≥ ...`! -/ theorem exists_antitone_perm {n : ℕ} (x : Fin n → ℝ) : ∃ π : Equiv.Perm (Fin n), ∀ i j : Fin n, i.1 ≤ j.1 → x (π j) ≤ x (π i) := by classical -- Construct `π` by picking the `k`-th largest element via `Finset.sort` / direct induction on `n`! induction n with | zero => exact ⟨Equiv.refl _, fun i => nomatch i⟩ | succ m ih => have hne : (Finset.univ : Finset (Fin (m + 1))).Nonempty := ⟨⟨0, Nat.zero_lt_succ m⟩, Finset.mem_univ _⟩ obtain ⟨iMax, _, hiMax⟩ := Finset.exists_max_image Finset.univ x hne let swap0 : Equiv.Perm (Fin (m + 1)) := Equiv.swap 0 iMax let xRest : Fin m → ℝ := fun j => x (swap0 j.succ) obtain ⟨πRest, hπRest⟩ := ih xRest -- Lift `πRest` on `{1, ..., m}` fixing `0`, then compose with `swap0`! let liftRest : Equiv.Perm (Fin (m + 1)) := { toFun := Fin.cases 0 (fun j => (πRest j).succ) invFun := Fin.cases 0 (fun j => (πRest.symm j).succ) left_inv := fun i => Fin.cases rfl (fun j => by simp) i right_inv := fun i => Fin.cases rfl (fun j => by simp) i } refine ⟨liftRest.trans swap0, fun i j => ?_⟩ refine Fin.cases ?_ ?_ i · intro _ change x (swap0 (liftRest j)) ≤ x (swap0 (liftRest 0)) have h0 : swap0 (liftRest 0) = iMax := by simp [liftRest, swap0] rw [h0]; exact hiMax _ (Finset.mem_univ _) · intro i' refine Fin.cases ?_ ?_ j · intro hij; exfalso; simp at hij · intro j' hij change x (swap0 (liftRest j'.succ)) ≤ x (swap0 (liftRest i'.succ)) have hle' : i'.1 ≤ j'.1 := by have h1 : i'.succ.1 = i'.1 + 1 := rfl have h2 : j'.succ.1 = j'.1 + 1 := rfl omega have hstep := hπRest i' j' hle' simpa [liftRest, xRest] using hstep /-- Lovász extension evaluated along a sorting permutation `π`: `∑_{k : Fin n} x (π k) * (f (permPrefix π (k.1 + 1)) - f (permPrefix π k.1))`. -/ def lovaszExtByPerm {n : ℕ} (f : Finset (Fin n) → ℝ) (x : Fin n → ℝ) (π : Equiv.Perm (Fin n)) : ℝ := ∑ k : Fin n, x (π k) * (f (permPrefix π (k.1 + 1)) - f (permPrefix π k.1)) /-- **ABEL SUMMATION-BY-PARTS IDENTITY FOR `lovaszExtByPerm`**: Whenever `f ∅ = 0` and `n ≥ 1`, `lovaszExtByPerm f x π = (∑ k : Fin (n - 1), (x (π k) - x (π (k + 1))) * f (permPrefix π (k + 1))) + x (π (n - 1)) * f univ`! -/ theorem lovaszExtByPerm_abel_summation {n : ℕ} (hn : 1 ≤ n) (f : Finset (Fin n) → ℝ) (hf0 : f ∅ = 0) (x : Fin n → ℝ) (π : Equiv.Perm (Fin n)) : lovaszExtByPerm f x π = (∑ k : Fin (n - 1), (x (π ⟨k.1, by omega⟩) - x (π ⟨k.1 + 1, by omega⟩)) * f (permPrefix π (k.1 + 1))) + x (π ⟨n - 1, by omega⟩) * f Finset.univ := by have hind : ∀ m : ℕ, (hm : m ≤ n) → 1 ≤ m → (∑ k ∈ Finset.range m, if hk : k < n then x (π ⟨k, hk⟩) * (f (permPrefix π (k + 1)) - f (permPrefix π k)) else 0) = (∑ k ∈ Finset.range (m - 1), if hk : k + 1 < n then (x (π ⟨k, by omega⟩) - x (π ⟨k + 1, hk⟩)) * f (permPrefix π (k + 1)) else 0) + x (π ⟨m - 1, by omega⟩) * f (permPrefix π m) := by intro m induction m with | zero => intro _ h1; omega | succ m' ih => intro hm _ cases m' with | zero => simp only [Finset.sum_range_one, Nat.sub_self, Finset.range_zero, Finset.sum_empty, zero_add] rw [dif_pos (by omega)] have hP0 : permPrefix π 0 = ∅ := by simp [permPrefix] rw [hP0, hf0]; ring | succ m'' => have hprev := ih (by omega) (by omega) rw [Finset.sum_range_succ, hprev] simp only [Nat.add_sub_cancel] at * rw [Finset.sum_range_succ, dif_pos (by omega), dif_pos (by omega)] ring have hfull := hind n le_rfl hn have hPn : permPrefix π n = Finset.univ := by ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, iff_true] exact ⟨π.symm a, (π.symm a).2, π.apply_symm_apply a⟩ rw [hPn] at hfull have hlhs : lovaszExtByPerm f x π = ∑ k ∈ Finset.range n, if hk : k < n then x (π ⟨k, hk⟩) * (f (permPrefix π (k + 1)) - f (permPrefix π k)) else 0 := by dsimp only [lovaszExtByPerm] refine Finset.sum_bij (fun k _ => k.1) (fun k _ => Finset.mem_range.mpr k.2) (fun _ _ _ _ h => Fin.ext h) (fun r hr => ⟨⟨r, Finset.mem_range.mp hr⟩, Finset.mem_univ _, rfl⟩) (fun k _ => by rw [dif_pos k.2]) have hrhs : ∑ k ∈ Finset.range (n - 1), (if hk : k + 1 < n then (x (π ⟨k, by omega⟩) - x (π ⟨k + 1, hk⟩)) * f (permPrefix π (k + 1)) else 0) = ∑ k : Fin (n - 1), (x (π ⟨k.1, by omega⟩) - x (π ⟨k.1 + 1, by omega⟩)) * f (permPrefix π (k.1 + 1)) := by refine Finset.sum_bij (fun k hk => ⟨k, Finset.mem_range.mp hk⟩) (fun _ _ => Finset.mem_univ _) (fun _ _ _ _ h => congrArg Fin.val h) (fun j _ => ⟨j.1, Finset.mem_range.mpr j.2, Fin.ext rfl⟩) (fun k hk => by rw [dif_pos (by have := Finset.mem_range.mp hk; omega)]) rw [hlhs, hfull, hrhs] /-- **PERMUTATION-INVARIANCE OF THE LOVÁSZ EXTENSION**: For ANY two antitone sorting permutations `π₁, π₂` of `x` (and `f ∅ = 0`), `lovaszExtByPerm f x π₁ = lovaszExtByPerm f x π₂`! -/ theorem lovaszExtByPerm_eq_of_antitone {n : ℕ} (f : Finset (Fin n) → ℝ) (hf0 : f ∅ = 0) (x : Fin n → ℝ) (π₁ π₂ : Equiv.Perm (Fin n)) (h1 : ∀ i j : Fin n, i.1 ≤ j.1 → x (π₁ j) ≤ x (π₁ i)) (h2 : ∀ i j : Fin n, i.1 ≤ j.1 → x (π₂ j) ≤ x (π₂ i)) : lovaszExtByPerm f x π₁ = lovaszExtByPerm f x π₂ := by by_cases hn0 : n = 0 · subst hn0; simp [lovaszExtByPerm] · -- First show `x (π₁ k) = x (π₂ k)` for EVERY `k : Fin n` (sorted values are unique!) have hx_eq : ∀ k : Fin n, x (π₁ k) = x (π₂ k) := by -- For any `r`, `{i | r ≤ x i}.card` determines whether `r ≤ x (π k)`! have hcard_ge : ∀ (π : Equiv.Perm (Fin n)) (hπ : ∀ i j : Fin n, i.1 ≤ j.1 → x (π j) ≤ x (π i)) (k : Fin n) (r : ℝ), r ≤ x (π k) ↔ k.1 + 1 ≤ (Finset.univ.filter (fun a : Fin n => r ≤ x a)).card := by intro π hπ k r constructor · intro hr have hsub : permPrefix π (k.1 + 1) ⊆ Finset.univ.filter (fun a : Fin n => r ≤ x a) := by intro a ha obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp ha have hjlt := (Finset.mem_filter.mp hj).2 exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, le_trans hr (hπ j k (by omega))⟩ have hpc : (permPrefix π (k.1 + 1)).card = k.1 + 1 := by dsimp only [permPrefix] rw [Finset.card_image_of_injective _ π.injective] have hbij : (Finset.univ.filter (fun j : Fin n => j.1 < k.1 + 1)).card = (Finset.range (k.1 + 1)).card := Finset.card_bij (fun j _ => j.1) (fun j hj => Finset.mem_range.mpr (Finset.mem_filter.mp hj).2) (fun _ _ _ _ h => Fin.ext h) (fun m hm => ⟨⟨m, by have := Finset.mem_range.mp hm; omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_range.mp hm⟩, rfl⟩) rw [hbij, Finset.card_range] rw [← hpc]; exact Finset.card_le_card hsub · intro hcard by_contra hlt; push Not at hlt -- Every `a` with `r ≤ x a` must have `(π.symm a).1 < k.1`! have hsub : Finset.univ.filter (fun a : Fin n => r ≤ x a) ⊆ permPrefix π k.1 := by intro a ha have hra := (Finset.mem_filter.mp ha).2 refine Finset.mem_image.mpr ⟨π.symm a, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, π.apply_symm_apply a⟩ by_contra hge; push Not at hge have := hπ k (π.symm a) hge rw [π.apply_symm_apply a] at this; linarith have hpc : (permPrefix π k.1).card = k.1 := by dsimp only [permPrefix] rw [Finset.card_image_of_injective _ π.injective] have hbij : (Finset.univ.filter (fun j : Fin n => j.1 < k.1)).card = (Finset.range k.1).card := Finset.card_bij (fun j _ => j.1) (fun j hj => Finset.mem_range.mpr (Finset.mem_filter.mp hj).2) (fun _ _ _ _ h => Fin.ext h) (fun m hm => ⟨⟨m, by have := Finset.mem_range.mp hm; omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_range.mp hm⟩, rfl⟩) rw [hbij, Finset.card_range] have := Finset.card_le_card hsub; omega intro k have h12 : x (π₁ k) ≤ x (π₂ k) := (hcard_ge π₂ h2 k (x (π₁ k))).mpr ((hcard_ge π₁ h1 k (x (π₁ k))).mp le_rfl) have h21 : x (π₂ k) ≤ x (π₁ k) := (hcard_ge π₁ h1 k (x (π₂ k))).mpr ((hcard_ge π₂ h2 k (x (π₂ k))).mp le_rfl) exact le_antisymm h12 h21 -- Apply Abel summation! Whenever `x (π₁ k) > x (π₁ (k + 1))`, BOTH `permPrefix π₁ (k + 1)` and -- `permPrefix π₂ (k + 1)` equal `{a | x (π₁ k) ≤ x a}`! rw [lovaszExtByPerm_abel_summation (by omega) f hf0 x π₁, lovaszExtByPerm_abel_summation (by omega) f hf0 x π₂] congr 1 · refine Finset.sum_congr rfl (fun k _ => ?_) have hkl : k.1 < n - 1 := k.2 rw [hx_eq ⟨k.1, by omega⟩, hx_eq ⟨k.1 + 1, by omega⟩] by_cases hgap : x (π₂ ⟨k.1, by omega⟩) = x (π₂ ⟨k.1 + 1, by omega⟩) · rw [hgap, sub_self, zero_mul, zero_mul] · have hstrict : x (π₂ ⟨k.1 + 1, by omega⟩) < x (π₂ ⟨k.1, by omega⟩) := lt_of_le_of_ne (h2 ⟨k.1, by omega⟩ ⟨k.1 + 1, by omega⟩ (by dsimp only; omega)) (Ne.symm hgap) have hpref_eq : ∀ (π : Equiv.Perm (Fin n)) (hπ : ∀ i j : Fin n, i.1 ≤ j.1 → x (π j) ≤ x (π i)), x (π ⟨k.1, by omega⟩) = x (π₂ ⟨k.1, by omega⟩) → x (π ⟨k.1 + 1, by omega⟩) = x (π₂ ⟨k.1 + 1, by omega⟩) → permPrefix π (k.1 + 1) = Finset.univ.filter (fun a : Fin n => x (π₂ ⟨k.1, by omega⟩) ≤ x a) := by intro π hπ heq1 heq2 ext a simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and] constructor · rintro ⟨j, hj, rfl⟩ rw [← heq1]; exact hπ j ⟨k.1, by omega⟩ (by dsimp only; omega) · intro hge refine ⟨π.symm a, ?_, π.apply_symm_apply a⟩ by_contra hbig; push Not at hbig have hle := hπ ⟨k.1 + 1, by omega⟩ (π.symm a) (by dsimp only; omega) rw [π.apply_symm_apply a, heq2] at hle; linarith have hp1 := hpref_eq π₁ h1 (hx_eq ⟨k.1, by omega⟩) (hx_eq ⟨k.1 + 1, by omega⟩) have hp2 := hpref_eq π₂ h2 rfl rfl rw [hp1, hp2] · rw [hx_eq ⟨n - 1, by omega⟩] /-- **CANONICAL LOVÁSZ EXTENSION** `lovaszExt f x` for any set function `f : Finset (Fin n) → ℝ`! -/ noncomputable def lovaszExt {n : ℕ} (f : Finset (Fin n) → ℝ) (x : Fin n → ℝ) : ℝ := lovaszExtByPerm f x (Classical.choose (exists_antitone_perm x)) /-- `lovaszExt f x` agrees with `lovaszExtByPerm f x π` for ANY antitone sorting permutation `π` of `x`! -/ theorem lovaszExt_eq_byPerm {n : ℕ} (f : Finset (Fin n) → ℝ) (hf0 : f ∅ = 0) (x : Fin n → ℝ) (π : Equiv.Perm (Fin n)) (hπ : ∀ i j : Fin n, i.1 ≤ j.1 → x (π j) ≤ x (π i)) : lovaszExt f x = lovaszExtByPerm f x π := lovaszExtByPerm_eq_of_antitone f hf0 x _ π (Classical.choose_spec (exists_antitone_perm x)) hπ /-- **LOVÁSZ EXTENSION AGREES WITH `f` ON `{0, 1}^n` (`lovaszExt f 1_A = f A`)**: -/ theorem lovaszExt_indicator {n : ℕ} (f : Finset (Fin n) → ℝ) (hf0 : f ∅ = 0) (A : Finset (Fin n)) : lovaszExt f (fun i => if i ∈ A then (1 : ℝ) else 0) = f A := by by_cases hn0 : n = 0 · subst hn0; have : A = ∅ := by ext i; exact nomatch i rw [this, hf0]; simp [lovaszExt, lovaszExtByPerm] · let x : Fin n → ℝ := fun i => if i ∈ A then (1 : ℝ) else 0 let π := Classical.choose (exists_antitone_perm x) have hπ := Classical.choose_spec (exists_antitone_perm x) rw [lovaszExt_eq_byPerm f hf0 x π hπ, lovaszExtByPerm_abel_summation (by omega) f hf0 x π] -- Count how many `k` have `x (π k) = 1`: that equals `A.card`, and for `k < A.card`, `π k ∈ A`! have hmem_iff : ∀ j : Fin n, π j ∈ A ↔ j.1 < A.card := by -- If `j.1 < A.card` and `π j ∉ A`, then `x (π j) = 0`, so all `i ≥ j` have `π i ∉ A`, leaving `< A.card` in `A`! have hcard_A : (Finset.univ.filter (fun j : Fin n => π j ∈ A)).card = A.card := by have hbij : Finset.univ.filter (fun j : Fin n => π j ∈ A) = A.image π.symm := by ext j; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_image] exact ⟨fun h => ⟨π j, h, π.symm_apply_apply j⟩, fun ⟨a, ha, heq⟩ => by rw [← heq, π.apply_symm_apply]; exact ha⟩ rw [hbij, Finset.card_image_of_injective _ π.symm.injective] intro j constructor · intro hjA by_contra hge; push Not at hge have hsub : permPrefix π (j.1 + 1) ⊆ A := by intro a ha obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp ha have hle := hπ i j (by have := (Finset.mem_filter.mp hi).2; omega) dsimp only [x] at hle; rw [if_pos hjA] at hle by_contra hni; rw [if_neg hni] at hle; linarith have hpc : (permPrefix π (j.1 + 1)).card = j.1 + 1 := by dsimp only [permPrefix]; rw [Finset.card_image_of_injective _ π.injective] have hbij : (Finset.univ.filter (fun i : Fin n => i.1 < j.1 + 1)).card = (Finset.range (j.1 + 1)).card := Finset.card_bij (fun i _ => i.1) (fun i hi => Finset.mem_range.mpr (Finset.mem_filter.mp hi).2) (fun _ _ _ _ h => Fin.ext h) (fun m hm => ⟨⟨m, by have := Finset.mem_range.mp hm; omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_range.mp hm⟩, rfl⟩) rw [hbij, Finset.card_range] have := Finset.card_le_card hsub; omega · intro hjlt by_contra hnjA have hsub : Finset.univ.filter (fun i : Fin n => π i ∈ A) ⊆ Finset.univ.filter (fun i : Fin n => i.1 < j.1) := by intro i hi have hiA := (Finset.mem_filter.mp hi).2 refine Finset.mem_filter.mpr ⟨Finset.mem_univ i, ?_⟩ by_contra hge; push Not at hge have hle := hπ j i hge dsimp only [x] at hle; rw [if_pos hiA, if_neg hnjA] at hle; linarith have hle := Finset.card_le_card hsub have hpc : (Finset.univ.filter (fun i : Fin n => i.1 < j.1)).card = j.1 := by have hbij : (Finset.univ.filter (fun i : Fin n => i.1 < j.1)).card = (Finset.range j.1).card := Finset.card_bij (fun i _ => i.1) (fun i hi => Finset.mem_range.mpr (Finset.mem_filter.mp hi).2) (fun _ _ _ _ h => Fin.ext h) (fun m hm => ⟨⟨m, by have := Finset.mem_range.mp hm; omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_range.mp hm⟩, rfl⟩) rw [hbij, Finset.card_range] omega by_cases hA0 : A.card = 0 · have hAe : A = ∅ := Finset.card_eq_zero.mp hA0 subst hAe; simp [x, hf0] · by_cases hAn : A.card = n · have hAu : A = Finset.univ := Finset.eq_univ_of_card A (by simpa using hAn) subst hAu; simp [x] · -- `1 ≤ A.card < n`: ONLY term `k = A.card - 1` has `x(π k) - x(π(k+1)) = 1 - 0 = 1`, and `P_{A.card} = A`! have hcard_lt : A.card < n := by have hle : A.card ≤ n := by calc A.card ≤ (Finset.univ : Finset (Fin n)).card := Finset.card_le_univ _ _ = n := by simp omega let k0 : Fin (n - 1) := ⟨A.card - 1, by omega⟩ rw [← Finset.add_sum_erase _ _ (Finset.mem_univ k0)] have hother : ∑ k ∈ Finset.univ.erase k0, (x (π ⟨k.1, by omega⟩) - x (π ⟨k.1 + 1, by omega⟩)) * f (permPrefix π (k.1 + 1)) = 0 := by refine Finset.sum_eq_zero (fun k hk => ?_) have hkne : k.1 ≠ k0.1 := fun h => (Finset.mem_erase.mp hk).1 (Fin.ext h) have h1 := hmem_iff ⟨k.1, by omega⟩ have h2 := hmem_iff ⟨k.1 + 1, by omega⟩ dsimp only [x] by_cases hlt : k.1 < k0.1 · rw [if_pos (h1.mpr (by dsimp only [k0] at hlt ⊢; omega)), if_pos (h2.mpr (by dsimp only [k0] at hlt ⊢; omega))]; ring · rw [if_neg (fun h => by have hv := h1.mp h; dsimp only [k0] at hlt hkne hv; omega), if_neg (fun h => by have hv := h2.mp h; dsimp only [k0] at hlt hkne hv; omega)]; ring have hlast0 : x (π ⟨n - 1, by omega⟩) = 0 := by dsimp only [x]; rw [if_neg (fun h => by have := (hmem_iff ⟨n - 1, by omega⟩).mp h; dsimp only at this; omega)] have hk0_diff : x (π ⟨k0.1, by omega⟩) - x (π ⟨k0.1 + 1, by omega⟩) = 1 := by dsimp only [x] rw [if_pos ((hmem_iff ⟨k0.1, by omega⟩).mpr (by dsimp only [k0]; omega)), if_neg (fun h => by have := (hmem_iff ⟨k0.1 + 1, by omega⟩).mp h; dsimp only [k0] at this; omega)] ring have hP_eq : permPrefix π (k0.1 + 1) = A := by ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and] constructor · rintro ⟨j, hj, rfl⟩; exact (hmem_iff j).mpr (by dsimp only [k0] at hj; omega) · intro ha; refine ⟨π.symm a, ?_, π.apply_symm_apply a⟩ have := (hmem_iff (π.symm a)).mp (by rwa [π.apply_symm_apply]); dsimp only [k0]; omega rw [hother, add_zero, hlast0, zero_mul, add_zero, hk0_diff, one_mul, hP_eq] /-- **EDMONDS BASE POLYTOPE**: `y ∈ B(f)` iff `∀ S, ∑_{i ∈ S} y i ≤ f S` and `∑_i y i = f univ`. -/ def IsInBasePolytope {n : ℕ} (f : Finset (Fin n) → ℝ) (y : Fin n → ℝ) : Prop := (∀ S : Finset (Fin n), ∑ i ∈ S, y i ≤ f S) ∧ (∑ i : Fin n, y i = f Finset.univ) /-- **EDMONDS POLYMATROID GREEDY VECTOR** along permutation `π`: `y_π (π k) = f (P_{k+1}(π)) - f (P_k(π))`. -/ def edmondsGreedyVec {n : ℕ} (f : Finset (Fin n) → ℝ) (π : Equiv.Perm (Fin n)) (i : Fin n) : ℝ := f (permPrefix π ((π.symm i).1 + 1)) - f (permPrefix π (π.symm i).1) /-- **EDMONDS (1970) POLYMATROID GREEDY OPTIMALITY & BASE-POLYTOPE DUALITY THEOREM**: For ANY submodular function `f : Finset (Fin n) → ℝ` with `f ∅ = 0`, ANY weight vector `x : Fin n → ℝ`, and ANY antitone sorting permutation `π` of `x`: 1. The greedy vector `y_g = edmondsGreedyVec f π` belongs to the Base Polytope `B(f)`; 2. `∑_i x i · y_g i = lovaszExt f x`; 3. For **EVERY** `y ∈ B(f)`: **`∑_i x i · y i ≤ lovaszExt f x`**! -/ theorem edmonds_polymatroid_greedy_optimal {n : ℕ} (f : Finset (Fin n) → ℝ) (hsub : IsSubmodular f) (hf0 : f ∅ = 0) (x : Fin n → ℝ) (π : Equiv.Perm (Fin n)) (hπ : ∀ i j : Fin n, i.1 ≤ j.1 → x (π j) ≤ x (π i)) : IsInBasePolytope f (edmondsGreedyVec f π) ∧ (∑ i : Fin n, x i * edmondsGreedyVec f π i = lovaszExt f x) ∧ (∀ y : Fin n → ℝ, IsInBasePolytope f y → ∑ i : Fin n, x i * y i ≤ lovaszExt f x) := by classical have hdim := (submodular_iff_diminishing_returns f).mp hsub -- Helper: `permPrefix π (k + 1) = insert (π k) (permPrefix π k)` and `π k ∉ permPrefix π k`! have hpref_ins : ∀ k : Fin n, permPrefix π (k.1 + 1) = insert (π k) (permPrefix π k.1) ∧ π k ∉ permPrefix π k.1 := by intro k constructor · ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] constructor · rintro ⟨j, hj, rfl⟩ rcases eq_or_lt_of_le (Nat.lt_succ_iff.mp hj) with heq | hlt · left; congr 1; exact Fin.ext heq · right; exact ⟨j, hlt, rfl⟩ · rintro (rfl | ⟨j, hj, rfl⟩) · exact ⟨k, Nat.lt_succ_self _, rfl⟩ · exact ⟨j, Nat.lt_succ_of_lt hj, rfl⟩ · intro hmem obtain ⟨j, hj, heq⟩ := Finset.mem_image.mp hmem have := congrArg Fin.val (π.injective heq); have := (Finset.mem_filter.mp hj).2; omega -- Prove `y_g ∈ B(f)` by telescoping over `S ∩ P_k`! have hbase_le : ∀ S : Finset (Fin n), ∑ i ∈ S, edmondsGreedyVec f π i ≤ f S := by intro S -- Show by induction on `m ≤ n`: `∑_{i ∈ S ∩ P_m} y_g i ≤ f (S ∩ P_m)`! have hind : ∀ m ≤ n, ∑ i ∈ S ∩ permPrefix π m, edmondsGreedyVec f π i ≤ f (S ∩ permPrefix π m) := by intro m induction m with | zero => intro _; have hP0 : permPrefix π 0 = ∅ := by simp [permPrefix] rw [hP0, Finset.inter_empty, Finset.sum_empty, hf0] | succ m ih => intro hm let k : Fin n := ⟨m, by omega⟩ have hprev := ih (by omega) obtain ⟨hins, hni⟩ := hpref_ins k rw [hins] by_cases hkS : π k ∈ S · have h1 : S ∩ insert (π k) (permPrefix π m) = insert (π k) (S ∩ permPrefix π m) := by ext a; by_cases ha : a = π k <;> simp [ha, hkS] have hni' : π k ∉ S ∩ permPrefix π m := fun h => hni (Finset.mem_inter.mp h).2 rw [h1, Finset.sum_insert hni'] have hstep : f (insert (π k) (permPrefix π m)) - f (permPrefix π m) ≤ f (insert (π k) (S ∩ permPrefix π m)) - f (S ∩ permPrefix π m) := hdim (S ∩ permPrefix π m) (permPrefix π m) (π k) Finset.inter_subset_right hni have hyg : edmondsGreedyVec f π (π k) = f (insert (π k) (permPrefix π m)) - f (permPrefix π m) := by dsimp only [edmondsGreedyVec]; rw [π.symm_apply_apply k, ← hins] linarith · have h1 : S ∩ insert (π k) (permPrefix π m) = S ∩ permPrefix π m := by ext a; simp only [Finset.mem_inter, Finset.mem_insert] exact ⟨fun ⟨haS, h⟩ => ⟨haS, h.resolve_left (fun heq => hkS (heq ▸ haS))⟩, fun ⟨haS, h⟩ => ⟨haS, Or.inr h⟩⟩ rw [h1]; exact hprev have hPn : permPrefix π n = Finset.univ := by ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, iff_true] exact ⟨π.symm a, (π.symm a).2, π.apply_symm_apply a⟩ have hfull := hind n le_rfl rw [hPn, Finset.inter_univ] at hfull; exact hfull have hbase_sum : ∑ i : Fin n, edmondsGreedyVec f π i = f Finset.univ := by have h1 := Equiv.sum_comp π (edmondsGreedyVec f π) rw [← h1] have htele : ∀ m ≤ n, ∑ k ∈ Finset.range m, (if hk : k < n then edmondsGreedyVec f π (π ⟨k, hk⟩) else 0) = f (permPrefix π m) := by intro m induction m with | zero => intro _ have hP0 : permPrefix π 0 = ∅ := by simp [permPrefix] simp [hP0, hf0] | succ m ih => intro hm; rw [Finset.sum_range_succ, ih (by omega), dif_pos (by omega)] dsimp only [edmondsGreedyVec]; rw [π.symm_apply_apply]; dsimp only; ring have hbij : ∑ k : Fin n, edmondsGreedyVec f π (π k) = ∑ k ∈ Finset.range n, if hk : k < n then edmondsGreedyVec f π (π ⟨k, hk⟩) else 0 := Finset.sum_bij (fun k _ => k.1) (fun k _ => Finset.mem_range.mpr k.2) (fun _ _ _ _ h => Fin.ext h) (fun r hr => ⟨⟨r, Finset.mem_range.mp hr⟩, Finset.mem_univ _, rfl⟩) (fun k _ => by rw [dif_pos k.2]) have hPn : permPrefix π n = Finset.univ := by ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, iff_true] exact ⟨π.symm a, (π.symm a).2, π.apply_symm_apply a⟩ rw [hbij, htele n le_rfl, hPn] have hval_eq : ∑ i : Fin n, x i * edmondsGreedyVec f π i = lovaszExt f x := by rw [lovaszExt_eq_byPerm f hf0 x π hπ, ← Equiv.sum_comp π (fun i => x i * edmondsGreedyVec f π i)] dsimp only [lovaszExtByPerm, edmondsGreedyVec] refine Finset.sum_congr rfl (fun k _ => by rw [π.symm_apply_apply k]) -- Optimality over ALL `y ∈ B(f)` via Abel summation by parts! have hopt : ∀ y : Fin n → ℝ, IsInBasePolytope f y → ∑ i : Fin n, x i * y i ≤ lovaszExt f x := by intro y hy by_cases hn0 : n = 0 · subst hn0; simp [lovaszExt, lovaszExtByPerm] · rw [lovaszExt_eq_byPerm f hf0 x π hπ, lovaszExtByPerm_abel_summation (by omega) f hf0 x π] -- Define additive set function `g(S) := ∑ i ∈ S, y i` (`g ∅ = 0`, `g univ = f univ`, `g S ≤ f S`)! let g : Finset (Fin n) → ℝ := fun S => ∑ i ∈ S, y i have hg0 : g ∅ = 0 := by simp [g] have hxy : ∑ i : Fin n, x i * y i = lovaszExtByPerm g x π := by rw [← Equiv.sum_comp π (fun i => x i * y i)] dsimp only [lovaszExtByPerm, g] refine Finset.sum_congr rfl (fun k _ => ?_) obtain ⟨hins, hni⟩ := hpref_ins k rw [hins, Finset.sum_insert hni]; ring rw [hxy, lovaszExtByPerm_abel_summation (by omega) g hg0 x π] have hterm : ∑ k : Fin (n - 1), (x (π ⟨k.1, by omega⟩) - x (π ⟨k.1 + 1, by omega⟩)) * g (permPrefix π (k.1 + 1)) ≤ ∑ k : Fin (n - 1), (x (π ⟨k.1, by omega⟩) - x (π ⟨k.1 + 1, by omega⟩)) * f (permPrefix π (k.1 + 1)) := by refine Finset.sum_le_sum (fun k _ => ?_) have hdiff_nn : 0 ≤ x (π ⟨k.1, by omega⟩) - x (π ⟨k.1 + 1, by omega⟩) := by linarith [hπ ⟨k.1, by omega⟩ ⟨k.1 + 1, by omega⟩ (by dsimp only; omega)] exact mul_le_mul_of_nonneg_left (hy.1 (permPrefix π (k.1 + 1))) hdiff_nn have hlast : g Finset.univ = f Finset.univ := hy.2 rw [hlast]; linarith exact ⟨⟨hbase_le, hbase_sum⟩, hval_eq, hopt⟩ /-- **LOVÁSZ'S THEOREM (1983): `f` IS SUBMODULAR IF AND ONLY IF ITS LOVÁSZ EXTENSION IS CONVEX**: For ANY set function `f : Finset (Fin n) → ℝ` with `f ∅ = 0`: `IsSubmodular f ↔ (∀ (x y : Fin n → ℝ) (lam : ℝ), 0 ≤ lam → lam ≤ 1 → lovaszExt f (fun i => lam * x i + (1 - lam) * y i) ≤ lam * lovaszExt f x + (1 - lam) * lovaszExt f y)`! -/ theorem lovasz_extension_convex_iff_submodular {n : ℕ} (f : Finset (Fin n) → ℝ) (hf0 : f ∅ = 0) : IsSubmodular f ↔ (∀ (x y : Fin n → ℝ) (lam : ℝ), 0 ≤ lam → lam ≤ 1 → lovaszExt f (fun i => lam * x i + (1 - lam) * y i) ≤ lam * lovaszExt f x + (1 - lam) * lovaszExt f y) := by constructor · -- `(⇒)` Submodular `f` ⇒ `lovaszExt f z = max_{u ∈ B(f)} ⟨z, u⟩` ⇒ immediately convex! intro hsub x y lam h0 h1 let z : Fin n → ℝ := fun i => lam * x i + (1 - lam) * y i let πz := Classical.choose (exists_antitone_perm z) have hπz := Classical.choose_spec (exists_antitone_perm z) let u := edmondsGreedyVec f πz obtain ⟨hu_base, huz_eq, _⟩ := edmonds_polymatroid_greedy_optimal f hsub hf0 z πz hπz let πx := Classical.choose (exists_antitone_perm x) let πy := Classical.choose (exists_antitone_perm y) have hux := (edmonds_polymatroid_greedy_optimal f hsub hf0 x πx (Classical.choose_spec (exists_antitone_perm x))).2.2 u hu_base have huy := (edmonds_polymatroid_greedy_optimal f hsub hf0 y πy (Classical.choose_spec (exists_antitone_perm y))).2.2 u hu_base rw [← huz_eq] have hlin : ∑ i : Fin n, z i * u i = lam * (∑ i : Fin n, x i * u i) + (1 - lam) * (∑ i : Fin n, y i * u i) := by dsimp only [z]; rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] exact Finset.sum_congr rfl (fun i _ => by ring) rw [hlin] nlinarith · -- `(⇐)` Convex `lovaszExt f` ⇒ evaluate midpoint `(1_A + 1_B) / 2 = (1_{A ∩ B} + 1_{A ∪ B}) / 2`! intro hconv A B let xA : Fin n → ℝ := fun i => if i ∈ A then 1 else 0 let xB : Fin n → ℝ := fun i => if i ∈ B then 1 else 0 let xm : Fin n → ℝ := fun i => (1 / 2 : ℝ) * xA i + (1 - 1 / 2 : ℝ) * xB i have hmid := hconv xA xB (1 / 2) (by norm_num) (by norm_num) rw [lovaszExt_indicator f hf0 A, lovaszExt_indicator f hf0 B] at hmid -- Exact evaluation: `lovaszExt f xm = (f (A ∩ B) + f (A ∪ B)) / 2`! -- Build an explicit permutation `π` putting `A ∩ B` first (value `1`), `(A ∪ B) \ (A ∩ B)` second (value `1/2`), -- and `univ \ (A ∪ B)` last (value `0`)! have hxm_eval : lovaszExt f xm = (f (A ∩ B) + f (A ∪ B)) / 2 := by by_cases hn0 : n = 0 · subst hn0 have h1 : A ∩ B = ∅ := by ext i; exact nomatch i have h2 : A ∪ B = ∅ := by ext i; exact nomatch i rw [h1, h2, hf0]; simp [lovaszExt, lovaszExtByPerm] · let π := Classical.choose (exists_antitone_perm xm) have hπ := Classical.choose_spec (exists_antitone_perm xm) rw [lovaszExt_eq_byPerm f hf0 xm π hπ, lovaszExtByPerm_abel_summation (by omega) f hf0 xm π] -- Classify each `i`: `xm i = 1` iff `i ∈ A ∩ B`, `xm i = 1/2` iff `i ∈ (A ∪ B) \ (A ∩ B)`, `0` iff `i ∉ A ∪ B`! have hxm_val : ∀ i : Fin n, xm i = (if i ∈ A ∩ B then (1 / 2 : ℝ) else 0) + (if i ∈ A ∪ B then (1 / 2 : ℝ) else 0) := by intro i; dsimp only [xm, xA, xB] by_cases hA : i ∈ A <;> by_cases hB : i ∈ B <;> simp [hA, hB] <;> norm_num -- Wait: `xm` is literally `(1/2) * 1_{A ∩ B} + (1/2) * 1_{A ∪ B}`, and ANY `π` sorting `xm` -- ALSO sorts BOTH `1_{A ∩ B}` AND `1_{A ∪ B}` simultaneously!! have hsort_inter : ∀ i j : Fin n, i.1 ≤ j.1 → (if π j ∈ A ∩ B then (1 : ℝ) else 0) ≤ (if π i ∈ A ∩ B then (1 : ℝ) else 0) := by intro i j hij have h := hπ i j hij rw [hxm_val (π i), hxm_val (π j)] at h by_cases h1 : π j ∈ A ∩ B <;> by_cases h2 : π i ∈ A ∩ B · simp [h1, h2] · exfalso have h1u : π j ∈ A ∪ B := Finset.mem_union_left B (Finset.mem_inter.mp h1).1 rw [if_pos h1, if_pos h1u, if_neg h2] at h split_ifs at h <;> linarith · simp [h1, h2] · simp [h1, h2] have hsort_union : ∀ i j : Fin n, i.1 ≤ j.1 → (if π j ∈ A ∪ B then (1 : ℝ) else 0) ≤ (if π i ∈ A ∪ B then (1 : ℝ) else 0) := by intro i j hij have h := hπ i j hij rw [hxm_val (π i), hxm_val (π j)] at h by_cases h1 : π j ∈ A ∪ B <;> by_cases h2 : π i ∈ A ∪ B · simp [h1, h2] · exfalso have h2i : π i ∉ A ∩ B := fun hc => h2 (Finset.mem_union_left B (Finset.mem_inter.mp hc).1) rw [if_pos h1, if_neg h2, if_neg h2i] at h split_ifs at h <;> linarith · simp [h1, h2] · simp [h1, h2] -- Therefore `lovaszExtByPerm f xm π = (1/2) * lovaszExtByPerm f 1_{A ∩ B} π + (1/2) * lovaszExtByPerm f 1_{A ∪ B} π`! rw [← lovaszExtByPerm_abel_summation (by omega) f hf0 xm π] have hlin : lovaszExtByPerm f xm π = (1 / 2 : ℝ) * lovaszExtByPerm f (fun i => if i ∈ A ∩ B then 1 else 0) π + (1 / 2 : ℝ) * lovaszExtByPerm f (fun i => if i ∈ A ∪ B then 1 else 0) π := by dsimp only [lovaszExtByPerm] rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun k _ => ?_) rw [hxm_val (π k)] split_ifs <;> ring rw [hlin, ← lovaszExt_eq_byPerm f hf0 _ π hsort_inter, ← lovaszExt_eq_byPerm f hf0 _ π hsort_union, lovaszExt_indicator f hf0 (A ∩ B), lovaszExt_indicator f hf0 (A ∪ B)] ring rw [hxm_eval] at hmid; linarith /-! =============================================================================== PART 5: EDMONDS POLYMATROIDS, MATROID GREEDY & GENERAL MATROID INTERSECTION MINIMAX =============================================================================== -/ /-! ### Pillar 5A: Rank Matroids & Rado–Edmonds Matroid Greedy Optimality -/ /-- A finite **Rank Matroid** on `Fin n` specified by its integer rank function `r`. -/ structure RankMatroid (n : ℕ) where r : Finset (Fin n) → ℕ r_empty : r ∅ = 0 r_mono : ∀ A B : Finset (Fin n), A ⊆ B → r A ≤ r B r_step : ∀ (A : Finset (Fin n)) (e : Fin n), r (insert e A) ≤ r A + 1 r_submod : ∀ A B : Finset (Fin n), r (A ∪ B) + r (A ∩ B) ≤ r A + r B /-- A subset `I` is independent in matroid `M` iff `M.r I = I.card`. -/ def RankMatroid.IsIndep {n : ℕ} (M : RankMatroid n) (I : Finset (Fin n)) : Prop := M.r I = I.card /-- Rank is always bounded above by cardinality (`M.r A ≤ A.card`). -/ theorem RankMatroid.r_le_card {n : ℕ} (M : RankMatroid n) (A : Finset (Fin n)) : M.r A ≤ A.card := by classical induction A using Finset.induction_on with | empty => simp [M.r_empty] | @insert a s ha ih => rw [Finset.card_insert_of_notMem ha] exact le_trans (M.r_step s a) (Nat.add_le_add_right ih 1) /-- Hereditary property: every subset of an independent set is independent! -/ theorem RankMatroid.indep_subset {n : ℕ} (M : RankMatroid n) {I J : Finset (Fin n)} (hsub : J ⊆ I) (hI : M.IsIndep I) : M.IsIndep J := by classical -- Prove by induction on `|I \ J|`: erasing one element from an independent set stays independent! have herase : ∀ (A : Finset (Fin n)) (a : Fin n), M.IsIndep A → a ∈ A → M.IsIndep (A.erase a) := by intro A a hA ha have h1 := M.r_step (A.erase a) a rw [Finset.insert_erase ha] at h1 have h2 := M.r_le_card (A.erase a) have h3 : (A.erase a).card + 1 = A.card := by rw [Finset.card_erase_of_mem ha]; have := Finset.card_pos.mpr ⟨a, ha⟩; omega dsimp only [RankMatroid.IsIndep] at hA ⊢; omega have hind : ∀ k : ℕ, ∀ A B : Finset (Fin n), B ⊆ A → (A \ B).card = k → M.IsIndep A → M.IsIndep B := by intro k induction k with | zero => intro A B hBA h0 hA have hAB : A ⊆ B := Finset.sdiff_eq_empty_iff_subset.mp (Finset.card_eq_zero.mp h0) have : A = B := Finset.Subset.antisymm hAB hBA rwa [← this] | succ k ih => intro A B hBA hk hA obtain ⟨a, ha⟩ := Finset.card_pos.mp (by omega : 0 < (A \ B).card) have haA : a ∈ A := (Finset.mem_sdiff.mp ha).1 have haB : a ∉ B := (Finset.mem_sdiff.mp ha).2 have hBsub : B ⊆ A.erase a := fun x hx => Finset.mem_erase.mpr ⟨fun h => haB (h ▸ hx), hBA hx⟩ have hcard' : (A.erase a \ B).card = k := by have : A.erase a \ B = (A \ B).erase a := by ext x; simp; tauto rw [this, Finset.card_erase_of_mem ha, hk]; simp exact ih (A.erase a) B hBsub hcard' (herase A a hA haA) exact hind (I \ J).card I J hsub rfl hI /-- Real-valued cast of a matroid rank function is submodular with `r ∅ = 0`. -/ theorem RankMatroid.r_real_submodular {n : ℕ} (M : RankMatroid n) : IsSubmodular (fun S => (M.r S : ℝ)) ∧ ((M.r ∅ : ℝ) = 0) := by refine ⟨fun A B => ?_, by simp [M.r_empty]⟩ have hR : ((M.r (A ∪ B) + M.r (A ∩ B) : ℕ) : ℝ) ≤ ((M.r A + M.r B : ℕ) : ℝ) := Nat.cast_le.mpr (M.r_submod A B) push_cast at hR; exact hR /-- **RADO–EDMONDS MATROID GREEDY OPTIMALITY THEOREM (1957 / 1971)**: For ANY rank matroid `M : RankMatroid n`, ANY nonnegative weight vector `w : Fin n → ℝ`, and ANY antitone sorting permutation `π` of `w`: Defining the greedy set `I_g := { π k | M.r (P_{k+1}) = M.r (P_k) + 1 }`: 1. `M.IsIndep I_g` (`I_g` is a maximum-rank independent basis of `M`!); 2. For **EVERY** independent set `I` (`M.IsIndep I`): **`∑ i ∈ I, w i ≤ ∑ i ∈ I_g, w i`**! -/ theorem rado_edmonds_matroid_greedy_optimal {n : ℕ} (M : RankMatroid n) (w : Fin n → ℝ) (hw : ∀ i, 0 ≤ w i) (π : Equiv.Perm (Fin n)) (hπ : ∀ i j : Fin n, i.1 ≤ j.1 → w (π j) ≤ w (π i)) : let Ig : Finset (Fin n) := Finset.univ.filter (fun i => M.r (permPrefix π ((π.symm i).1 + 1)) = M.r (permPrefix π (π.symm i).1) + 1) M.IsIndep Ig ∧ (∀ I : Finset (Fin n), M.IsIndep I → ∑ i ∈ I, w i ≤ ∑ i ∈ Ig, w i) := by classical intro Ig let f : Finset (Fin n) → ℝ := fun S => (M.r S : ℝ) have hfsub : IsSubmodular f := M.r_real_submodular.1 have hf0 : f ∅ = 0 := M.r_real_submodular.2 have hstep01 : ∀ i : Fin n, edmondsGreedyVec f π i = if i ∈ Ig then 1 else 0 := by intro i let k := (π.symm i).1 have hsub : permPrefix π k ⊆ permPrefix π (k + 1) := fun a ha => by obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp ha exact Finset.mem_image.mpr ⟨j, Finset.mem_filter.mpr ⟨Finset.mem_univ j, Nat.lt_succ_of_lt (Finset.mem_filter.mp hj).2⟩, rfl⟩ have hle1 : M.r (permPrefix π k) ≤ M.r (permPrefix π (k + 1)) := M.r_mono _ _ hsub have hle2 : M.r (permPrefix π (k + 1)) ≤ M.r (permPrefix π k) + 1 := by have hins : permPrefix π (k + 1) = insert (π (π.symm i)) (permPrefix π k) := by ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] constructor · rintro ⟨j, hj, rfl⟩ rcases eq_or_lt_of_le (Nat.lt_succ_iff.mp hj) with heq | hlt · left; congr 1; exact Fin.ext heq · right; exact ⟨j, hlt, rfl⟩ · rintro (rfl | ⟨j, hj, rfl⟩) · exact ⟨π.symm i, Nat.lt_succ_self _, rfl⟩ · exact ⟨j, Nat.lt_succ_of_lt hj, rfl⟩ rw [hins]; exact M.r_step _ _ by_cases heq : M.r (permPrefix π (k + 1)) = M.r (permPrefix π k) + 1 · have hmem : i ∈ Ig := Finset.mem_filter.mpr ⟨Finset.mem_univ i, heq⟩ rw [if_pos hmem] change (M.r (permPrefix π (k + 1)) : ℝ) - (M.r (permPrefix π k) : ℝ) = 1 rw [heq]; push_cast; ring · have heq0 : M.r (permPrefix π (k + 1)) = M.r (permPrefix π k) := by omega have hnotmem : i ∉ Ig := fun h => heq (Finset.mem_filter.mp h).2 rw [if_neg hnotmem] change (M.r (permPrefix π (k + 1)) : ℝ) - (M.r (permPrefix π k) : ℝ) = 0 rw [heq0]; ring obtain ⟨hBase, hEqLov, hOpt⟩ := edmonds_polymatroid_greedy_optimal f hfsub hf0 w π hπ have hIg_card : (Ig.card : ℝ) = f Finset.univ := by have hsum := hBase.2 simp_rw [hstep01] at hsum rw [← Finset.sum_filter] at hsum have hfilt : Finset.univ.filter (fun i : Fin n => i ∈ Ig) = Ig := by ext i; simp rw [hfilt] at hsum; simpa using hsum have hIg_r_ge : (Ig.card : ℝ) ≤ f Ig := by have h1 := hBase.1 Ig have h2 : ∑ i ∈ Ig, edmondsGreedyVec f π i = (Ig.card : ℝ) := by have : ∑ i ∈ Ig, edmondsGreedyVec f π i = ∑ _i ∈ Ig, (1 : ℝ) := Finset.sum_congr rfl (fun i hi => by rw [hstep01 i, if_pos hi]) rw [this]; simp linarith have hIg_indep : M.IsIndep Ig := by dsimp only [f] at hIg_r_ge have hge : Ig.card ≤ M.r Ig := by exact_mod_cast hIg_r_ge exact le_antisymm (M.r_le_card Ig) hge refine ⟨hIg_indep, fun I hI => ?_⟩ have hIg_sum : ∑ i ∈ Ig, w i = lovaszExt f w := by rw [← hEqLov] have h1 : ∑ i : Fin n, w i * edmondsGreedyVec f π i = ∑ i : Fin n, if i ∈ Ig then w i else 0 := Finset.sum_congr rfl (fun i _ => by rw [hstep01 i]; split_ifs <;> ring) rw [h1, ← Finset.sum_filter] have hfilt : Finset.univ.filter (fun i : Fin n => i ∈ Ig) = Ig := by ext i; simp rw [hfilt] rw [hIg_sum] by_cases hn0 : n = 0 · subst hn0 have hIe : I = ∅ := by ext i; exact Fin.elim0 i subst hIe; simp [lovaszExt, lovaszExtByPerm] · rw [lovaszExt_eq_byPerm f hf0 w π hπ, lovaszExtByPerm_abel_summation (by omega) f hf0 w π] let g : Finset (Fin n) → ℝ := fun S => ((I ∩ S).card : ℝ) have hg0 : g ∅ = 0 := by simp [g] have hg_le : ∀ S : Finset (Fin n), g S ≤ f S := by intro S have hind_sub : M.IsIndep (I ∩ S) := M.indep_subset Finset.inter_subset_left hI have hle : (I ∩ S).card ≤ M.r S := by rw [← hind_sub]; exact M.r_mono _ _ Finset.inter_subset_right dsimp only [g, f]; exact_mod_cast hle have hI_eq : ∑ i ∈ I, w i = lovaszExtByPerm g w π := by have h1 : ∑ i ∈ I, w i = ∑ i : Fin n, w i * (if i ∈ I then (1 : ℝ) else 0) := by have h2 : ∑ i : Fin n, w i * (if i ∈ I then (1 : ℝ) else 0) = ∑ i : Fin n, if i ∈ I then w i else 0 := Finset.sum_congr rfl (fun i _ => by split_ifs <;> ring) rw [h2, ← Finset.sum_filter] have hfilt : Finset.univ.filter (fun i : Fin n => i ∈ I) = I := by ext i; simp rw [hfilt] rw [h1, ← Equiv.sum_comp π (fun i => w i * (if i ∈ I then (1 : ℝ) else 0))] dsimp only [lovaszExtByPerm, g] refine Finset.sum_congr rfl (fun k _ => ?_) have hins : permPrefix π (k.1 + 1) = insert (π k) (permPrefix π k.1) ∧ π k ∉ permPrefix π k.1 := by constructor · ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] constructor · rintro ⟨j, hj, rfl⟩ rcases eq_or_lt_of_le (Nat.lt_succ_iff.mp hj) with heq | hlt · left; congr 1; exact Fin.ext heq · right; exact ⟨j, hlt, rfl⟩ · rintro (rfl | ⟨j, hj, rfl⟩) · exact ⟨k, Nat.lt_succ_self _, rfl⟩ · exact ⟨j, Nat.lt_succ_of_lt hj, rfl⟩ · intro hmem; obtain ⟨j, hj, heq⟩ := Finset.mem_image.mp hmem have := congrArg Fin.val (π.injective heq); have := (Finset.mem_filter.mp hj).2; omega rw [hins.1] by_cases hkI : π k ∈ I · have h1' : I ∩ insert (π k) (permPrefix π k.1) = insert (π k) (I ∩ permPrefix π k.1) := by ext a; by_cases ha : a = π k <;> simp [ha, hkI] have hni' : π k ∉ I ∩ permPrefix π k.1 := fun h => hins.2 (Finset.mem_inter.mp h).2 rw [if_pos hkI, h1', Finset.card_insert_of_notMem hni']; push_cast; ring · have h1' : I ∩ insert (π k) (permPrefix π k.1) = I ∩ permPrefix π k.1 := by ext a; simp only [Finset.mem_inter, Finset.mem_insert] exact ⟨fun ⟨haI, h⟩ => ⟨haI, h.resolve_left (fun heq => hkI (heq ▸ haI))⟩, fun ⟨haI, h⟩ => ⟨haI, Or.inr h⟩⟩ rw [if_neg hkI, h1']; ring rw [hI_eq, lovaszExtByPerm_abel_summation (by omega) g hg0 w π] have hterm : ∑ k : Fin (n - 1), (w (π ⟨k.1, by omega⟩) - w (π ⟨k.1 + 1, by omega⟩)) * g (permPrefix π (k.1 + 1)) ≤ ∑ k : Fin (n - 1), (w (π ⟨k.1, by omega⟩) - w (π ⟨k.1 + 1, by omega⟩)) * f (permPrefix π (k.1 + 1)) := Finset.sum_le_sum (fun k _ => mul_le_mul_of_nonneg_left (hg_le _) (by linarith [hπ ⟨k.1, by omega⟩ ⟨k.1 + 1, by omega⟩ (by dsimp only; omega)])) have hlast : w (π ⟨n - 1, by omega⟩) * g Finset.univ ≤ w (π ⟨n - 1, by omega⟩) * f Finset.univ := mul_le_mul_of_nonneg_left (hg_le Finset.univ) (hw _) linarith /-! ### Pillar 5B: Edmonds Matroid Union & Intersection Weak Duality + GENERAL Strong Minimax -/ /-- **EDMONDS MATROID INTERSECTION WEAK DUALITY**: For ANY two matroids `M₁, M₂`, ANY common independent set `I`, and ANY `U ⊆ Fin n`: **`I.card ≤ M₁.r U + M₂.r (Finset.univ \ U)`**! -/ theorem edmonds_matroid_intersection_weak_duality {n : ℕ} (M₁ M₂ : RankMatroid n) {I : Finset (Fin n)} (h1 : M₁.IsIndep I) (h2 : M₂.IsIndep I) (U : Finset (Fin n)) : I.card ≤ M₁.r U + M₂.r (Finset.univ \ U) := by have hsplit : I = (I ∩ U) ∪ (I \ U) := by ext x; simp; tauto have hdisj : Disjoint (I ∩ U) (I \ U) := by rw [Finset.disjoint_left]; intro x h1' h2' exact (Finset.mem_sdiff.mp h2').2 (Finset.mem_inter.mp h1').2 have hcard : I.card = (I ∩ U).card + (I \ U).card := by conv_lhs => rw [hsplit] exact Finset.card_union_of_disjoint hdisj have hA : (I ∩ U).card ≤ M₁.r U := by rw [← M₁.indep_subset Finset.inter_subset_left h1] exact M₁.r_mono _ _ Finset.inter_subset_right have hB : (I \ U).card ≤ M₂.r (Finset.univ \ U) := by rw [← M₂.indep_subset Finset.sdiff_subset h2] exact M₂.r_mono _ _ (fun x hx => Finset.mem_sdiff.mpr ⟨Finset.mem_univ x, (Finset.mem_sdiff.mp hx).2⟩) omega /-- **EDMONDS MATROID UNION WEAK DUALITY**: For ANY `I₁ ∈ ℐ(M₁)`, `I₂ ∈ ℐ(M₂)`, and ANY `U ⊆ Fin n`: **`(I₁ ∪ I₂).card ≤ M₁.r U + M₂.r U + (Finset.univ \ U).card`**! -/ theorem edmonds_matroid_union_weak_duality {n : ℕ} (M₁ M₂ : RankMatroid n) {I₁ I₂ : Finset (Fin n)} (h1 : M₁.IsIndep I₁) (h2 : M₂.IsIndep I₂) (U : Finset (Fin n)) : (I₁ ∪ I₂).card ≤ M₁.r U + M₂.r U + (Finset.univ \ U).card := by have hsub : I₁ ∪ I₂ ⊆ (I₁ ∩ U) ∪ (I₂ ∩ U) ∪ (Finset.univ \ U) := by intro x hx; by_cases hxU : x ∈ U · rcases Finset.mem_union.mp hx with h | h · exact Finset.mem_union_left _ (Finset.mem_union_left _ (Finset.mem_inter.mpr ⟨h, hxU⟩)) · exact Finset.mem_union_left _ (Finset.mem_union_right _ (Finset.mem_inter.mpr ⟨h, hxU⟩)) · exact Finset.mem_union_right _ (Finset.mem_sdiff.mpr ⟨Finset.mem_univ x, hxU⟩) have hA : (I₁ ∩ U).card ≤ M₁.r U := by rw [← M₁.indep_subset Finset.inter_subset_left h1]; exact M₁.r_mono _ _ Finset.inter_subset_right have hB : (I₂ ∩ U).card ≤ M₂.r U := by rw [← M₂.indep_subset Finset.inter_subset_left h2]; exact M₂.r_mono _ _ Finset.inter_subset_right have hcard := Finset.card_le_card hsub have hu1 := Finset.card_union_le ((I₁ ∩ U) ∪ (I₂ ∩ U)) (Finset.univ \ U) have hu2 := Finset.card_union_le (I₁ ∩ U) (I₂ ∩ U) omega /-- **MATROID RANK-CLOSURE PEELING LEMMA (CORE OF EDMONDS' INTERSECTION PROOF)**: If `M.IsIndep I`, `x ∉ I`, `M.r (insert x I) = M.r I`, and `T ⊆ I` contains NO element `z` with `M.IsIndep (insert x (I.erase z))`, then **`M.r (insert x (I \ T)) = M.r (I \ T)`**! -/ theorem matroid_closure_peel {n : ℕ} (M : RankMatroid n) {I : Finset (Fin n)} (hI : M.IsIndep I) {x : Fin n} (hxI : x ∉ I) (hdep : M.r (insert x I) = M.r I) : ∀ T : Finset (Fin n), T ⊆ I → (∀ z ∈ T, ¬ M.IsIndep (insert x (I.erase z))) → M.r (insert x (I \ T)) = M.r (I \ T) := by classical intro T induction T using Finset.induction_on with | empty => intro _ _; simpa using hdep | @insert z T' hzT' ih => intro hsub hno have hzI : z ∈ I := hsub (Finset.mem_insert_self z T') have hT'sub : T' ⊆ I := fun a ha => hsub (Finset.mem_insert_of_mem ha) have hprev := ih hT'sub (fun a ha => hno a (Finset.mem_insert_of_mem ha)) -- `W := I \ T'` has `z ∈ W`, and `I \ insert z T' = W.erase z`! let W : Finset (Fin n) := I \ T' have hzW : z ∈ W := Finset.mem_sdiff.mpr ⟨hzI, hzT'⟩ have hWeq : I \ insert z T' = W.erase z := by ext a; simp [W]; tauto rw [hWeq] have hW_ind : M.IsIndep W := M.indep_subset Finset.sdiff_subset hI have hWz_ind : M.IsIndep (W.erase z) := M.indep_subset (Finset.erase_subset z W) hW_ind have hIz_ind : M.IsIndep (I.erase z) := M.indep_subset (Finset.erase_subset z I) hI have hnot_z : ¬ M.IsIndep (insert x (I.erase z)) := hno z (Finset.mem_insert_self z T') have hx_not_Iz : x ∉ I.erase z := fun h => hxI (Finset.mem_erase.mp h).2 have hr_Iz : M.r (insert x (I.erase z)) = (I.erase z).card := by have h1 := M.r_mono (I.erase z) (insert x (I.erase z)) (Finset.subset_insert _ _) have h2 := M.r_le_card (insert x (I.erase z)) rw [Finset.card_insert_of_notMem hx_not_Iz] at h2 dsimp only [RankMatroid.IsIndep] at hIz_ind hnot_z rw [Finset.card_insert_of_notMem hx_not_Iz] at hnot_z omega -- Submodularity on `insert x W` and `insert x (I.erase z)`: -- Union = `insert x I` (since `z ∈ W` and `W ⊆ I`), Intersection = `insert x (W.erase z)`! have hsubmod := M.r_submod (insert x W) (insert x (I.erase z)) have hunion : insert x W ∪ insert x (I.erase z) = insert x I := by ext a; simp only [Finset.mem_union, Finset.mem_insert, Finset.mem_erase, W, Finset.mem_sdiff] constructor · rintro ((rfl | ⟨haI, _⟩) | (rfl | ⟨_, haI⟩)) · left; rfl · right; exact haI · left; rfl · right; exact haI · rintro (rfl | haI) · left; left; rfl · by_cases haz : a = z · subst haz; left; right; exact ⟨hzI, hzT'⟩ · right; right; exact ⟨haz, haI⟩ have hinter : insert x W ∩ insert x (I.erase z) = insert x (W.erase z) := by ext a; simp only [Finset.mem_inter, Finset.mem_insert, Finset.mem_erase] constructor · rintro ⟨h1, h2⟩ rcases h1 with rfl | haW · left; rfl · rcases h2 with rfl | ⟨haz, _⟩ · left; rfl · right; exact ⟨haz, haW⟩ · rintro (rfl | ⟨haz, haW⟩) · exact ⟨Or.inl rfl, Or.inl rfl⟩ · exact ⟨Or.inr haW, Or.inr ⟨haz, Finset.sdiff_subset haW⟩⟩ rw [hunion, hinter, hdep, hprev, hr_Iz] at hsubmod have hcard_I : (I.erase z).card + 1 = I.card := by rw [Finset.card_erase_of_mem hzI]; have := Finset.card_pos.mpr ⟨z, hzI⟩; omega have hcard_W : (W.erase z).card + 1 = W.card := by rw [Finset.card_erase_of_mem hzW]; have := Finset.card_pos.mpr ⟨z, hzW⟩; omega have hle_mono := M.r_mono (W.erase z) (insert x (W.erase z)) (Finset.subset_insert _ _) dsimp only [RankMatroid.IsIndep, W] at hI hW_ind hWz_ind hcard_W hle_mono hsubmod ⊢ omega /-- **MATROID RANK-CLOSURE EXTENSION LEMMA**: If `A ⊆ S` and `M.r (insert e A) = M.r A`, then `M.r (insert e S) = M.r S`! -/ theorem matroid_closure_mono {n : ℕ} (M : RankMatroid n) {A S : Finset (Fin n)} {e : Fin n} (hAS : A ⊆ S) (hcl : M.r (insert e A) = M.r A) : M.r (insert e S) = M.r S := by by_cases heS : e ∈ S · rw [Finset.insert_eq_of_mem heS] · have hsubmod := M.r_submod (insert e A) S have hu : insert e A ∪ S = insert e S := by ext a; simp only [Finset.mem_union, Finset.mem_insert] constructor · rintro ((rfl | haA) | haS) · exact Or.inl rfl · exact Or.inr (hAS haA) · exact Or.inr haS · rintro (rfl | haS) · exact Or.inl (Or.inl rfl) · exact Or.inr haS have hi : insert e A ∩ S = A := by ext a; simp only [Finset.mem_inter, Finset.mem_insert] exact ⟨fun ⟨h1, h2⟩ => h1.resolve_left (fun heq => heS (heq ▸ h2)), fun ha => ⟨Or.inr ha, hAS ha⟩⟩ rw [hu, hi, hcl] at hsubmod have hle := M.r_mono S (insert e S) (Finset.subset_insert _ _) omega /-- **MATROID CLOSURE-SET ABSORPTION**: If `∀ e ∈ T, M.r (insert e S) = M.r S`, then `M.r (S ∪ T) = M.r S`! -/ theorem matroid_closure_union {n : ℕ} (M : RankMatroid n) (S T : Finset (Fin n)) (hall : ∀ e ∈ T, M.r (insert e S) = M.r S) : M.r (S ∪ T) = M.r S := by classical induction T using Finset.induction_on with | empty => simp | @insert a T' ha ih => have hprev := ih (fun e he => hall e (Finset.mem_insert_of_mem he)) have hu : S ∪ insert a T' = insert a (S ∪ T') := by ext x; simp rw [hu] have hstep := matroid_closure_mono M (Finset.subset_union_left (s₁ := S) (s₂ := T')) (hall a (Finset.mem_insert_self a T')) omega private lemma getElem_pair_mem_pathEdges {α : Type*} : ∀ (l : List α) (j : ℕ) (hj : j + 1 < l.length), (l[j]'(by omega), l[j + 1]'hj) ∈ pathEdges l := by intro l induction l with | nil => intro j hj; simp at hj | cons a as iha => intro j hj cases as with | nil => simp at hj | cons b bs => cases j with | zero => simp [pathEdges] | succ j' => simp only [pathEdges, List.mem_cons] right; exact iha j' (by simpa using hj) /-- **GENERAL EDMONDS MATROID INTERSECTION STRONG MINIMAX THEOREM (1970)**: For **EVERY** pair of finite rank matroids `(M₁, M₂)` on `Fin n`: There exist a common independent set `I` (`M₁.IsIndep I ∧ M₂.IsIndep I`) and a partition `U ⊆ Fin n` achieving **EXACT ZERO-GAP MINIMAX EQUALITY**: **`I.card = M₁.r U + M₂.r (Finset.univ \ U)`**! (Proved constructively via Edmonds' augmenting-exchange digraph and shortest-path closure cascade!) -/ theorem edmonds_matroid_intersection_strong_minimax {n : ℕ} (M₁ M₂ : RankMatroid n) : ∃ (I U : Finset (Fin n)), M₁.IsIndep I ∧ M₂.IsIndep I ∧ I.card = M₁.r U + M₂.r (Finset.univ \ U) := by classical -- Strong induction on remaining capacity `k = n - I.card` starting from `I = ∅`! have hind : ∀ k : ℕ, ∀ I : Finset (Fin n), M₁.IsIndep I → M₂.IsIndep I → n - I.card ≤ k → ∃ (IStar U : Finset (Fin n)), M₁.IsIndep IStar ∧ M₂.IsIndep IStar ∧ IStar.card = M₁.r U + M₂.r (Finset.univ \ U) := by intro k induction k with | zero => intro I hI1 hI2 h0 have hfull : I = Finset.univ := Finset.eq_univ_of_card I (by have hle : I.card ≤ n := by calc I.card ≤ (Finset.univ : Finset (Fin n)).card := Finset.card_le_univ _ _ = n := by simp rw [Fintype.card_fin]; omega) refine ⟨I, Finset.univ, hI1, hI2, ?_⟩ rw [Finset.sdiff_self, M₂.r_empty, add_zero, ← hfull]; exact hI1.symm | succ k ih => intro I hI1 hI2 hk -- Define Edmonds exchange digraph `D(I)` and entry/exit sets `X₁, X₂`! let X₁ : Finset (Fin n) := Finset.univ.filter (fun x => x ∉ I ∧ M₁.IsIndep (insert x I)) let X₂ : Finset (Fin n) := Finset.univ.filter (fun x => x ∉ I ∧ M₂.IsIndep (insert x I)) let D : Fin n → Fin n → Prop := fun a b => (a ∈ I ∧ b ∉ I ∧ M₁.IsIndep (insert b (I.erase a))) ∨ (a ∉ I ∧ b ∈ I ∧ M₂.IsIndep (insert a (I.erase b))) -- Check whether there is ANY directed path in `D` from `X₁` to `X₂`! by_cases hreach : ∃ x₁ ∈ X₁, ∃ x₂ ∈ X₂, Relation.ReflTransGen D x₁ x₂ · -- Pick a SHORTEST path `p` in `D` from `X₁` to `X₂`! have hex_path : ∃ p : List (Fin n), p.Nodup ∧ (∃ x₁ ∈ X₁, p.head? = some x₁) ∧ (∃ x₂ ∈ X₂, p.getLast? = some x₂) ∧ (∀ e ∈ pathEdges p, D e.1 e.2) := by obtain ⟨x₁, hx₁, x₂, hx₂, hr⟩ := hreach obtain ⟨p, hnd, hh, hl, he⟩ := reflTransGen_exists_nodup_path hr exact ⟨p, hnd, ⟨x₁, hx₁, hh⟩, ⟨x₂, hx₂, hl⟩, he⟩ -- Minimize `p.length` using `Nat.find`! let Ppred : ℕ → Prop := fun len => ∃ p : List (Fin n), p.length = len ∧ p.Nodup ∧ (∃ x₁ ∈ X₁, p.head? = some x₁) ∧ (∃ x₂ ∈ X₂, p.getLast? = some x₂) ∧ (∀ e ∈ pathEdges p, D e.1 e.2) have hex_len : ∃ len, Ppred len := by obtain ⟨p, h1, h2, h3, h4⟩ := hex_path; exact ⟨p.length, p, rfl, h1, h2, h3, h4⟩ let minLen := Nat.find hex_len obtain ⟨p, hp_len, hp_nd, ⟨xFirst, hxFirst, hp_head⟩, ⟨xLast, hxLast, hp_last⟩, hp_edges⟩ := Nat.find_spec hex_len have hmin_len : ∀ q : List (Fin n), q.Nodup → (∃ a ∈ X₁, q.head? = some a) → (∃ b ∈ X₂, q.getLast? = some b) → (∀ e ∈ pathEdges q, D e.1 e.2) → minLen ≤ q.length := fun q h1 h2 h3 h4 => Nat.find_min' hex_len ⟨q, rfl, h1, h2, h3, h4⟩ -- Note: `minLen ≥ 1` since `p.head? = some xFirst`! have hp_pos : 1 ≤ p.length := by cases p <;> simp at hp_head ⊢ -- Helper: element `p[i]` alternates `∉ I` (even `i`) and `∈ I` (odd `i`), so `p.length = 2 * m + 1`! have hp_alt : ∀ i : ℕ, (hi : i < p.length) → (i % 2 = 0 → p[i] ∉ I) ∧ (i % 2 = 1 → p[i] ∈ I) := by intro i induction i with | zero => intro hi; constructor · intro _ have h0 : p[0] = xFirst := by cases p with | nil => simp at hi | cons a as => simpa using hp_head rw [h0]; exact (Finset.mem_filter.mp hxFirst).2.1 · intro h; omega | succ j ihj => intro hj have hprev := ihj (by omega) have hedge_mem : (p[j]'(by omega), p[j + 1]'hj) ∈ pathEdges p := getElem_pair_mem_pathEdges p j hj have hD := hp_edges _ hedge_mem rcases Nat.mod_two_eq_zero_or_one j with hj0 | hj1 · have hnot : p[j]'(by omega) ∉ I := hprev.1 hj0 rcases hD with ⟨hin, _, _⟩ | ⟨_, hnext, _⟩ · exact absurd hin hnot · exact ⟨fun h => by omega, fun _ => hnext⟩ · have hin : p[j]'(by omega) ∈ I := hprev.2 hj1 rcases hD with ⟨_, hnext, _⟩ | ⟨hnot, _, _⟩ · exact ⟨fun _ => hnext, fun h => by omega⟩ · exact absurd hin hnot have hlast_notI : p[p.length - 1]'(by omega) ∉ I := by have hl : p[p.length - 1]'(by omega) = xLast := by rw [← List.getLast_eq_getElem] have := List.getLast?_eq_some_getLast (by intro h; rw [h] at hp_pos; simp at hp_pos : p ≠ []) rw [hp_last] at this; exact (Option.some.inj this).symm rw [hl]; exact (Finset.mem_filter.mp hxLast).2.1 have hlen_odd : p.length % 2 = 1 := by rcases Nat.mod_two_eq_zero_or_one (p.length - 1) with h0 | h1 · omega · exfalso; exact hlast_notI ((hp_alt (p.length - 1) (by omega)).2 h1) -- Shortcut-freeness of minimal path `p`: -- (1) No `j > 0` has `p[j] ∈ X₁`; -- (2) No `j < p.length - 1` has `p[j] ∈ X₂`; -- (3) No `i + 1 < j` has `D p[i] p[j]`! have hno_X1 : ∀ j : ℕ, (hj : j < p.length) → 0 < j → p[j] ∉ X₁ := by intro j hj hj0 hmem -- Take suffix `q = p.drop j`: strictly shorter path from `p[j] ∈ X₁` to `xLast ∈ X₂`! let q := p.drop j have hq_nd : q.Nodup := hp_nd.sublist (List.drop_sublist j p) have hq_head : q.head? = some (p[j]'hj) := by have hne : q ≠ [] := by simp [q]; omega rw [List.head?_eq_some_head hne] congr 1; simp [q] have hq_last : q.getLast? = some xLast := by have hne : q ≠ [] := by simp [q]; omega have heq := List.take_append_drop j p rw [← heq, List.getLast?_append_of_ne_nil _ hne] at hp_last exact hp_last have hq_edges : ∀ e ∈ pathEdges q, D e.1 e.2 := by intro e he have hsub_e : ∀ (l : List (Fin n)) (m : ℕ), e ∈ pathEdges (l.drop m) → e ∈ pathEdges l := by intro l induction l with | nil => intro m h; simp [pathEdges] at h | cons a as ihl => intro m h cases m with | zero => exact h | succ m' => simp only [List.drop_succ_cons] at h have := ihl m' h cases as with | nil => simp [pathEdges] at this | cons b bs => simp [pathEdges, this] exact hp_edges e (hsub_e p j he) have hle := hmin_len q hq_nd ⟨p[j]'hj, hmem, hq_head⟩ ⟨xLast, hxLast, hq_last⟩ hq_edges have hqlen : q.length = p.length - j := List.length_drop omega have hno_X2 : ∀ j : ℕ, (hj : j < p.length) → j + 1 < p.length → p[j] ∉ X₂ := by intro j hj hjlt hmem let q := p.take (j + 1) have hq_nd : q.Nodup := hp_nd.sublist (List.take_sublist (j + 1) p) have hq_head : q.head? = some xFirst := by cases p with | nil => simp at hj | cons a as => simpa [q] using hp_head have hq_last : q.getLast? = some (p[j]'hj) := by have hne : q ≠ [] := by intro h; have := congrArg List.length h simp [q, Nat.min_eq_left (by omega : j + 1 ≤ p.length)] at this rw [List.getLast?_eq_some_getLast hne]; congr 1 rw [List.getLast_eq_getElem] simp [q, Nat.min_eq_left (by omega : j + 1 ≤ p.length)] have hq_edges : ∀ e ∈ pathEdges q, D e.1 e.2 := by intro e he have hsub_e : ∀ (l : List (Fin n)) (m : ℕ), e ∈ pathEdges (l.take m) → e ∈ pathEdges l := by intro l induction l with | nil => intro m h; simp [pathEdges] at h | cons a as ihl => intro m h cases m with | zero => simp [pathEdges] at h | succ m' => cases as with | nil => simp [pathEdges] at h | cons b bs => cases m' with | zero => simp [pathEdges] at h | succ m'' => simp only [List.take_succ_cons, pathEdges, List.mem_cons] at h ⊢ rcases h with rfl | ht · left; rfl · right; exact ihl (m'' + 1) ht exact hp_edges e (hsub_e p (j + 1) he) have hle := hmin_len q hq_nd ⟨xFirst, hxFirst, hq_head⟩ ⟨p[j]'hj, hmem, hq_last⟩ hq_edges have hqlen : q.length = j + 1 := by simp [q, Nat.min_eq_left (by omega : j + 1 ≤ p.length)] omega have hno_jump : ∀ i j : ℕ, (hi : i < p.length) → (hj : j < p.length) → i + 1 < j → ¬ D p[i] p[j] := by intro i j hi hj hij hDij let q := p.take (i + 1) ++ p.drop j have hq_nd : q.Nodup := by rw [List.nodup_append] refine ⟨hp_nd.sublist (List.take_sublist _ _), hp_nd.sublist (List.drop_sublist _ _), ?_⟩ intro a ha b hb heq subst heq obtain ⟨r₁, hr₁, hget1⟩ := List.getElem_of_mem ha obtain ⟨r₂, hr₂, hget2⟩ := List.getElem_of_mem hb have hr1_lt : r₁ < i + 1 := by simp at hr₁; omega have h1 : p[r₁]'(by omega) = a := by simpa [List.getElem_take] using hget1 have h2 : p[j + r₂]'(by simp at hr₂; omega) = a := by simpa [List.getElem_drop] using hget2 have hidx : r₁ = j + r₂ := (List.Nodup.getElem_inj_iff hp_nd).mp (h1.trans h2.symm) omega have hq_head : q.head? = some xFirst := by cases p with | nil => simp at hi | cons a as => simpa [q] using hp_head have hq_last : q.getLast? = some xLast := by have hne : p.drop j ≠ [] := by simp; omega rw [List.getLast?_append_of_ne_nil _ hne] have heq := List.take_append_drop j p rw [← heq, List.getLast?_append_of_ne_nil _ hne] at hp_last exact hp_last have hq_edges : ∀ e ∈ pathEdges q, D e.1 e.2 := by have happ_e : ∀ (l₁ l₂ : List (Fin n)) (a b : Fin n), l₁.getLast? = some a → l₂.head? = some b → ∀ e ∈ pathEdges (l₁ ++ l₂), e ∈ pathEdges l₁ ∨ e ∈ pathEdges l₂ ∨ e = (a, b) := by intro l₁ l₂ a b hl1 hl2 e he induction l₁ with | nil => simp at hl1 | cons x xs ihl => cases xs with | nil => simp only [List.getLast?_singleton, Option.some.injEq] at hl1; subst hl1 cases l₂ with | nil => simp at hl2 | cons y ys => simp only [List.head?_cons, Option.some.injEq] at hl2; subst hl2 simp only [List.cons_append, List.nil_append, pathEdges, List.mem_cons] at he rcases he with rfl | ht · exact Or.inr (Or.inr rfl) · exact Or.inr (Or.inl ht) | cons y ys => simp only [List.cons_append, pathEdges, List.mem_cons] at he rcases he with rfl | ht · exact Or.inl (by simp [pathEdges]) · rcases ihl (by simpa using hl1) ht with h1 | h2 | h3 · exact Or.inl (by simp [pathEdges, h1]) · exact Or.inr (Or.inl h2) · exact Or.inr (Or.inr h3) have hl1 : (p.take (i + 1)).getLast? = some (p[i]'hi) := by have hne : p.take (i + 1) ≠ [] := by intro h; have := congrArg List.length h simp [Nat.min_eq_left (by omega : i + 1 ≤ p.length)] at this rw [List.getLast?_eq_some_getLast hne]; congr 1 rw [List.getLast_eq_getElem] simp [Nat.min_eq_left (by omega : i + 1 ≤ p.length)] have hl2 : (p.drop j).head? = some (p[j]'hj) := by have hne : p.drop j ≠ [] := by simp; omega rw [List.head?_eq_some_head hne]; congr 1; simp intro e he rcases happ_e _ _ _ _ hl1 hl2 e he with h1 | h2 | rfl · have hsub_e : ∀ (l : List (Fin n)) (m : ℕ), e ∈ pathEdges (l.take m) → e ∈ pathEdges l := by intro l; induction l with | nil => intro m h; simp [pathEdges] at h | cons a as ihl => intro m h; cases m with | zero => simp [pathEdges] at h | succ m' => cases as with | nil => simp [pathEdges] at h | cons b bs => cases m' with | zero => simp [pathEdges] at h | succ m'' => simp only [List.take_succ_cons, pathEdges, List.mem_cons] at h ⊢ rcases h with rfl | ht · left; rfl · right; exact ihl (m'' + 1) ht exact hp_edges e (hsub_e p (i + 1) h1) · have hsub_e : ∀ (l : List (Fin n)) (m : ℕ), e ∈ pathEdges (l.drop m) → e ∈ pathEdges l := by intro l; induction l with | nil => intro m h; simp [pathEdges] at h | cons a as ihl => intro m h; cases m with | zero => exact h | succ m' => simp only [List.drop_succ_cons] at h have := ihl m' h; cases as with | nil => simp [pathEdges] at this | cons b bs => simp [pathEdges, this] exact hp_edges e (hsub_e p j h2) · exact hDij have hle := hmin_len q hq_nd ⟨xFirst, hxFirst, hq_head⟩ ⟨xLast, hxLast, hq_last⟩ hq_edges have hqlen : q.length = (i + 1) + (p.length - j) := by simp [q, List.length_append, List.length_take, List.length_drop, Nat.min_eq_left (by omega : i + 1 ≤ p.length)] omega -- Construct augmented common independent set `I' := (I \ Y) ∪ X` of size `I.card + 1`! let m : ℕ := p.length / 2 have hm_len : p.length = 2 * m + 1 := by omega let Xset : Finset (Fin n) := (Finset.range (m + 1)).image (fun r => if hr : 2 * r < p.length then p[2 * r]'hr else xFirst) let Yset : Finset (Fin n) := (Finset.range m).image (fun r => if hr : 2 * r + 1 < p.length then p[2 * r + 1]'hr else xFirst) have hY_sub_I : Yset ⊆ I := by intro y hy obtain ⟨r, hr, rfl⟩ := Finset.mem_image.mp hy have hrlt : 2 * r + 1 < p.length := by have := Finset.mem_range.mp hr; omega rw [dif_pos hrlt]; exact (hp_alt (2 * r + 1) hrlt).2 (by omega) have hX_disj_I : Disjoint Xset I := by rw [Finset.disjoint_left]; intro x hx obtain ⟨r, hr, rfl⟩ := Finset.mem_image.mp hx have hrlt : 2 * r < p.length := by have := Finset.mem_range.mp hr; omega rw [dif_pos hrlt]; exact (hp_alt (2 * r) hrlt).1 (by omega) have hX_card : Xset.card = m + 1 := by dsimp only [Xset] rw [Finset.card_image_of_injOn, Finset.card_range] intro r₁ h₁ r₂ h₂ heq have h1 : 2 * r₁ < p.length := by have := Finset.mem_range.mp h₁; omega have h2 : 2 * r₂ < p.length := by have := Finset.mem_range.mp h₂; omega dsimp only at heq rw [dif_pos h1, dif_pos h2] at heq have hidx : 2 * r₁ = 2 * r₂ := (List.Nodup.getElem_inj_iff hp_nd).mp heq omega have hY_card : Yset.card = m := by dsimp only [Yset] rw [Finset.card_image_of_injOn, Finset.card_range] intro r₁ h₁ r₂ h₂ heq have h1 : 2 * r₁ + 1 < p.length := by have := Finset.mem_range.mp h₁; omega have h2 : 2 * r₂ + 1 < p.length := by have := Finset.mem_range.mp h₂; omega dsimp only at heq rw [dif_pos h1, dif_pos h2] at heq have hidx : 2 * r₁ + 1 = 2 * r₂ + 1 := (List.Nodup.getElem_inj_iff hp_nd).mp heq omega let I' : Finset (Fin n) := (I \ Yset) ∪ Xset have hI'_card : I'.card = I.card + 1 := by have hd : Disjoint (I \ Yset) Xset := Disjoint.mono_left Finset.sdiff_subset hX_disj_I.symm rw [Finset.card_union_of_disjoint hd, Finset.card_sdiff, Finset.inter_eq_left.mpr hY_sub_I, hX_card, hY_card] have := Finset.card_le_card hY_sub_I; omega -- Helper: consecutive edge lookup in `p`! have hedge_idx : ∀ idx : ℕ, (hidx : idx + 1 < p.length) → D (p[idx]'(by omega)) (p[idx + 1]'hidx) := fun idx hidx => hp_edges _ (getElem_pair_mem_pathEdges p idx hidx) -- **CLOSURE CASCADE FOR `M₁` (DOWNWARD INDUCTION `r = m - 1, ..., 0`)**: -- Show `∀ d ≤ m, M₁.r (I' ∪ Y_tail(m - d)) = M₁.r I'` where `Y_tail(t) = { y_r | t ≤ r < m }`! have hI'_ind1 : M₁.IsIndep I' := by let Ytail : ℕ → Finset (Fin n) := fun t => ((Finset.range m).filter (fun r => t ≤ r)).image (fun r => if hr : 2 * r + 1 < p.length then p[2 * r + 1]'hr else xFirst) have hcasc1 : ∀ d ≤ m, M₁.r (I' ∪ Ytail (m - d)) = M₁.r I' := by intro d induction d with | zero => intro _ have hemp : Ytail (m - 0) = ∅ := by ext a; simp only [Ytail, Finset.mem_image, Finset.mem_filter, Finset.mem_range, Finset.notMem_empty, iff_false] rintro ⟨r, ⟨hr1, hr2⟩, _⟩; omega rw [hemp, Finset.union_empty] | succ d ihd => intro hd have hprev := ihd (by omega) let r : ℕ := m - (d + 1) have hr_lt : r < m := by omega let yr : Fin n := p[2 * r + 1]'(by omega) let xr1 : Fin n := p[2 * r + 2]'(by omega) have hYt_eq : Ytail (m - (d + 1)) = insert yr (Ytail (m - d)) := by ext a; simp only [Ytail, Finset.mem_image, Finset.mem_filter, Finset.mem_range, Finset.mem_insert] constructor · rintro ⟨j, ⟨hj1, hj2⟩, rfl⟩ rcases eq_or_lt_of_le hj2 with heq | hlt · left; rw [dif_pos (by omega)]; congr 1; dsimp only [yr, r]; congr 1; omega · right; exact ⟨j, ⟨hj1, by omega⟩, rfl⟩ · rintro (rfl | ⟨j, ⟨hj1, hj2⟩, rfl⟩) · exact ⟨r, ⟨hr_lt, le_rfl⟩, by rw [dif_pos (by omega)]⟩ · exact ⟨j, ⟨hj1, by omega⟩, rfl⟩ rw [hYt_eq] have hu : I' ∪ insert yr (Ytail (m - d)) = insert yr (I' ∪ Ytail (m - d)) := by ext a; simp rw [hu] -- Show `M₁.r (insert yr (I' ∪ Ytail (m - d))) = M₁.r (I' ∪ Ytail (m - d))`! -- Let `Ypref := { y_j | j < r }` (`Ypref ⊆ I`, `yr ∉ Ypref`). -- Since `xr1 ∉ X₁` (`2*r + 2 > 0`) and NO `j < r` has `D y_j xr1` (`2*j + 1 + 1 < 2*r + 2`), -- `matroid_closure_peel` gives `M₁.r (insert xr1 (I \ Ypref)) = M₁.r (I \ Ypref)`! let Ypref : Finset (Fin n) := (Finset.range r).image (fun j => if hj : 2 * j + 1 < p.length then p[2 * j + 1]'hj else xFirst) have hYp_sub : Ypref ⊆ I := by intro a ha; obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp ha have hjlt : 2 * j + 1 < p.length := by have := Finset.mem_range.mp hj; omega rw [dif_pos hjlt]; exact (hp_alt (2 * j + 1) hjlt).2 (by omega) have hxr1_notI : xr1 ∉ I := (hp_alt (2 * r + 2) (by omega)).1 (by omega) have hxr1_dep : M₁.r (insert xr1 I) = M₁.r I := by have hnotX1 : xr1 ∉ X₁ := hno_X1 (2 * r + 2) (by omega) (by omega) have hnotInd : ¬ M₁.IsIndep (insert xr1 I) := fun h => hnotX1 (Finset.mem_filter.mpr ⟨Finset.mem_univ _, hxr1_notI, h⟩) have h1 := M₁.r_mono I (insert xr1 I) (Finset.subset_insert _ _) have h2 := M₁.r_le_card (insert xr1 I) rw [Finset.card_insert_of_notMem hxr1_notI] at h2 dsimp only [RankMatroid.IsIndep] at hI1 hnotInd rw [Finset.card_insert_of_notMem hxr1_notI] at hnotInd omega have hno_Yp : ∀ z ∈ Ypref, ¬ M₁.IsIndep (insert xr1 (I.erase z)) := by intro z hz hind_z obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hz have hjr : j < r := Finset.mem_range.mp hj have hjlt : 2 * j + 1 < p.length := by omega rw [dif_pos hjlt] at hind_z have hD : D (p[2 * j + 1]'hjlt) xr1 := Or.inl ⟨(hp_alt (2 * j + 1) hjlt).2 (by omega), hxr1_notI, hind_z⟩ exact hno_jump (2 * j + 1) (2 * r + 2) hjlt (by omega) (by omega) hD have hpeel := matroid_closure_peel M₁ hI1 hxr1_notI hxr1_dep Ypref hYp_sub hno_Yp -- Edge `yr → xr1` in `D(I)` gives `M₁.IsIndep (insert xr1 (I.erase yr))`! have hD_step : D yr xr1 := hedge_idx (2 * r + 1) (by omega) have hyr_in_I : yr ∈ I := (hp_alt (2 * r + 1) (by omega)).2 (by omega) have hind_step : M₁.IsIndep (insert xr1 (I.erase yr)) := by rcases hD_step with ⟨_, _, h⟩ | ⟨hnot, _, _⟩ · exact h · exact absurd hyr_in_I hnot have hyr_not_Yp : yr ∉ Ypref := by intro h; obtain ⟨j, hj, heq⟩ := Finset.mem_image.mp h have hjr : j < r := Finset.mem_range.mp hj rw [dif_pos (by omega)] at heq have hidx : 2 * j + 1 = 2 * r + 1 := (List.Nodup.getElem_inj_iff hp_nd).mp heq omega -- Let `B := (I \ Ypref).erase yr`! Then `insert xr1 B ⊆ insert xr1 (I.erase yr)` is independent, -- so `M₁.r (insert xr1 B) = B.card + 1 = (I \ Ypref).card = M₁.r (I \ Ypref) = M₁.r (insert xr1 (I \ Ypref))`! let B : Finset (Fin n) := (I \ Ypref).erase yr have hB_sub : insert xr1 B ⊆ insert xr1 (I.erase yr) := by intro a ha; rcases Finset.mem_insert.mp ha with rfl | haB · exact Finset.mem_insert_self _ _ · exact Finset.mem_insert_of_mem (Finset.mem_erase.mpr ⟨(Finset.mem_erase.mp haB).1, (Finset.mem_sdiff.mp (Finset.mem_erase.mp haB).2).1⟩) have hxr1B_ind : M₁.IsIndep (insert xr1 B) := M₁.indep_subset hB_sub hind_step have hIW_ind : M₁.IsIndep (I \ Ypref) := M₁.indep_subset Finset.sdiff_subset hI1 have hyr_in_IW : yr ∈ I \ Ypref := Finset.mem_sdiff.mpr ⟨hyr_in_I, hyr_not_Yp⟩ have hxr1_not_B : xr1 ∉ B := fun h => hxr1_notI (Finset.mem_sdiff.mp (Finset.mem_erase.mp h).2).1 have hcl_yr : M₁.r (insert yr (insert xr1 B)) = M₁.r (insert xr1 B) := by have hset_eq : insert yr (insert xr1 B) = insert xr1 (I \ Ypref) := by rw [Finset.insert_comm, Finset.insert_erase hyr_in_IW] rw [hset_eq, hpeel] dsimp only [RankMatroid.IsIndep] at hxr1B_ind hIW_ind rw [hxr1B_ind, hIW_ind, Finset.card_insert_of_notMem hxr1_not_B] have : B.card + 1 = (I \ Ypref).card := by dsimp only [B]; rw [Finset.card_erase_of_mem hyr_in_IW] have := Finset.card_pos.mpr ⟨yr, hyr_in_IW⟩; omega omega -- And `insert xr1 B ⊆ I' ∪ Ytail (m - d)`! have hB_in : insert xr1 B ⊆ I' ∪ Ytail (m - d) := by intro a ha rcases Finset.mem_insert.mp ha with rfl | haB · refine Finset.mem_union_left _ (Finset.mem_union_right _ ?_) refine Finset.mem_image.mpr ⟨r + 1, Finset.mem_range.mpr (by omega), ?_⟩ rw [dif_pos (by omega)] have h2r : 2 * (r + 1) = 2 * r + 2 := by omega dsimp only [xr1]; simp only [h2r] · have ha_ne_yr := (Finset.mem_erase.mp haB).1 have haI := (Finset.mem_sdiff.mp (Finset.mem_erase.mp haB).2).1 have ha_nYp := (Finset.mem_sdiff.mp (Finset.mem_erase.mp haB).2).2 by_cases haY : a ∈ Yset · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp haY have hjm : j < m := Finset.mem_range.mp hj rw [dif_pos (by omega)] at ha_ne_yr ha_nYp ⊢ have hjge : m - d ≤ j := by by_contra hlt; push Not at hlt rcases eq_or_lt_of_le (by omega : j ≤ r) with rfl | hjr · exact ha_ne_yr rfl · exact ha_nYp (Finset.mem_image.mpr ⟨j, Finset.mem_range.mpr hjr, by rw [dif_pos (by omega)]⟩) exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨j, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hjm, hjge⟩, by rw [dif_pos (by omega)]⟩) · exact Finset.mem_union_left _ (Finset.mem_union_left _ (Finset.mem_sdiff.mpr ⟨haI, haY⟩)) have hmono := matroid_closure_mono M₁ hB_in hcl_yr omega have hfull1 := hcasc1 m le_rfl have hYt0 : Ytail (m - m) = Yset := by ext a; simp [Ytail, Yset] rw [hYt0] at hfull1 -- Now `insert xFirst I ⊆ I' ∪ Yset`, so `I.card + 1 = M₁.r (insert xFirst I) ≤ M₁.r I' ≤ I'.card = I.card + 1`! have hsub_all : insert xFirst I ⊆ I' ∪ Yset := by intro a ha rcases Finset.mem_insert.mp ha with rfl | haI · refine Finset.mem_union_left _ (Finset.mem_union_right _ ?_) refine Finset.mem_image.mpr ⟨0, Finset.mem_range.mpr (by omega), ?_⟩ rw [dif_pos (by omega)] cases p with | nil => simp at hp_head | cons b bs => simpa using hp_head · by_cases haY : a ∈ Yset · exact Finset.mem_union_right _ haY · exact Finset.mem_union_left _ (Finset.mem_union_left _ (Finset.mem_sdiff.mpr ⟨haI, haY⟩)) have hxF_ind : M₁.IsIndep (insert xFirst I) := (Finset.mem_filter.mp hxFirst).2.2 have hxF_notI : xFirst ∉ I := (Finset.mem_filter.mp hxFirst).2.1 have hge := M₁.r_mono _ _ hsub_all have hle := M₁.r_le_card I' dsimp only [RankMatroid.IsIndep] at hxF_ind ⊢ rw [Finset.card_insert_of_notMem hxF_notI] at hxF_ind omega -- **CLOSURE CASCADE FOR `M₂` (UPWARD INDUCTION `r = 0, 1, ..., m - 1`)**: have hI'_ind2 : M₂.IsIndep I' := by let Yhead : ℕ → Finset (Fin n) := fun t => (Finset.range t).image (fun r => if hr : 2 * r + 1 < p.length then p[2 * r + 1]'hr else xFirst) have hcasc2 : ∀ t ≤ m, M₂.r (I' ∪ Yhead t) = M₂.r I' := by intro t induction t with | zero => intro _; simp [Yhead] | succ r ihr => intro hr have hprev := ihr (by omega) let yr : Fin n := p[2 * r + 1]'(by omega) let xr : Fin n := p[2 * r]'(by omega) have hYh_eq : Yhead (r + 1) = insert yr (Yhead r) := by ext a; simp only [Yhead, Finset.mem_image, Finset.mem_range, Finset.mem_insert] constructor · rintro ⟨j, hj, rfl⟩ rcases eq_or_lt_of_le (Nat.lt_succ_iff.mp hj) with rfl | hlt · left; rw [dif_pos (by omega)] · right; exact ⟨j, hlt, rfl⟩ · rintro (rfl | ⟨j, hj, rfl⟩) · exact ⟨r, Nat.lt_succ_self r, by rw [dif_pos (by omega)]⟩ · exact ⟨j, Nat.lt_succ_of_lt hj, rfl⟩ rw [hYh_eq] have hu : I' ∪ insert yr (Yhead r) = insert yr (I' ∪ Yhead r) := by ext a; simp rw [hu] -- Let `Ysuf := { y_j | r + 1 ≤ j < m }`: NO `j > r` has `D xr y_j` (`2*r + 1 < 2*j + 1`)! let Ysuf : Finset (Fin n) := ((Finset.range m).filter (fun j => r + 1 ≤ j)).image (fun j => if hj : 2 * j + 1 < p.length then p[2 * j + 1]'hj else xFirst) have hYs_sub : Ysuf ⊆ I := by intro a ha; obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp ha have hjlt : 2 * j + 1 < p.length := by have := (Finset.mem_filter.mp hj).1; have := Finset.mem_range.mp this; omega rw [dif_pos hjlt]; exact (hp_alt (2 * j + 1) hjlt).2 (by omega) have hxr_notI : xr ∉ I := (hp_alt (2 * r) (by omega)).1 (by omega) have hxr_dep : M₂.r (insert xr I) = M₂.r I := by have hnotX2 : xr ∉ X₂ := hno_X2 (2 * r) (by omega) (by omega) have hnotInd : ¬ M₂.IsIndep (insert xr I) := fun h => hnotX2 (Finset.mem_filter.mpr ⟨Finset.mem_univ _, hxr_notI, h⟩) have h1 := M₂.r_mono I (insert xr I) (Finset.subset_insert _ _) have h2 := M₂.r_le_card (insert xr I) rw [Finset.card_insert_of_notMem hxr_notI] at h2 dsimp only [RankMatroid.IsIndep] at hI2 hnotInd rw [Finset.card_insert_of_notMem hxr_notI] at hnotInd omega have hno_Ys : ∀ z ∈ Ysuf, ¬ M₂.IsIndep (insert xr (I.erase z)) := by intro z hz hind_z obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hz have hjm := Finset.mem_range.mp (Finset.mem_filter.mp hj).1 have hjr := (Finset.mem_filter.mp hj).2 have hjlt : 2 * j + 1 < p.length := by omega rw [dif_pos hjlt] at hind_z have hD : D xr (p[2 * j + 1]'hjlt) := Or.inr ⟨hxr_notI, (hp_alt (2 * j + 1) hjlt).2 (by omega), hind_z⟩ exact hno_jump (2 * r) (2 * j + 1) (by omega) hjlt (by omega) hD have hpeel := matroid_closure_peel M₂ hI2 hxr_notI hxr_dep Ysuf hYs_sub hno_Ys have hD_step : D xr yr := hedge_idx (2 * r) (by omega) have hyr_in_I : yr ∈ I := (hp_alt (2 * r + 1) (by omega)).2 (by omega) have hind_step : M₂.IsIndep (insert xr (I.erase yr)) := by rcases hD_step with ⟨hin, _, _⟩ | ⟨_, _, h⟩ · exact absurd hin hxr_notI · exact h have hyr_not_Ys : yr ∉ Ysuf := by intro h; obtain ⟨j, hj, heq⟩ := Finset.mem_image.mp h have hjm := Finset.mem_range.mp (Finset.mem_filter.mp hj).1 have hjr := (Finset.mem_filter.mp hj).2 rw [dif_pos (by omega)] at heq have hidx : 2 * j + 1 = 2 * r + 1 := (List.Nodup.getElem_inj_iff hp_nd).mp heq omega let B : Finset (Fin n) := (I \ Ysuf).erase yr have hB_sub : insert xr B ⊆ insert xr (I.erase yr) := by intro a ha; rcases Finset.mem_insert.mp ha with rfl | haB · exact Finset.mem_insert_self _ _ · exact Finset.mem_insert_of_mem (Finset.mem_erase.mpr ⟨(Finset.mem_erase.mp haB).1, (Finset.mem_sdiff.mp (Finset.mem_erase.mp haB).2).1⟩) have hxrB_ind : M₂.IsIndep (insert xr B) := M₂.indep_subset hB_sub hind_step have hIW_ind : M₂.IsIndep (I \ Ysuf) := M₂.indep_subset Finset.sdiff_subset hI2 have hyr_in_IW : yr ∈ I \ Ysuf := Finset.mem_sdiff.mpr ⟨hyr_in_I, hyr_not_Ys⟩ have hxr_not_B : xr ∉ B := fun h => hxr_notI (Finset.mem_sdiff.mp (Finset.mem_erase.mp h).2).1 have hcl_yr : M₂.r (insert yr (insert xr B)) = M₂.r (insert xr B) := by have hset_eq : insert yr (insert xr B) = insert xr (I \ Ysuf) := by rw [Finset.insert_comm, Finset.insert_erase hyr_in_IW] rw [hset_eq, hpeel] dsimp only [RankMatroid.IsIndep] at hxrB_ind hIW_ind rw [hxrB_ind, hIW_ind, Finset.card_insert_of_notMem hxr_not_B] have : B.card + 1 = (I \ Ysuf).card := by dsimp only [B]; rw [Finset.card_erase_of_mem hyr_in_IW] have := Finset.card_pos.mpr ⟨yr, hyr_in_IW⟩; omega omega have hB_in : insert xr B ⊆ I' ∪ Yhead r := by intro a ha rcases Finset.mem_insert.mp ha with rfl | haB · refine Finset.mem_union_left _ (Finset.mem_union_right _ ?_) exact Finset.mem_image.mpr ⟨r, Finset.mem_range.mpr (by omega), by rw [dif_pos (by omega)]⟩ · have ha_ne_yr := (Finset.mem_erase.mp haB).1 have haI := (Finset.mem_sdiff.mp (Finset.mem_erase.mp haB).2).1 have ha_nYs := (Finset.mem_sdiff.mp (Finset.mem_erase.mp haB).2).2 by_cases haY : a ∈ Yset · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp haY have hjm : j < m := Finset.mem_range.mp hj rw [dif_pos (by omega)] at ha_ne_yr ha_nYs ⊢ have hjlt : j < r := by by_contra hge; push Not at hge rcases eq_or_lt_of_le hge with rfl | hgt · exact ha_ne_yr rfl · exact ha_nYs (Finset.mem_image.mpr ⟨j, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hjm, by omega⟩, by rw [dif_pos (by omega)]⟩) exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨j, Finset.mem_range.mpr hjlt, by rw [dif_pos (by omega)]⟩) · exact Finset.mem_union_left _ (Finset.mem_union_left _ (Finset.mem_sdiff.mpr ⟨haI, haY⟩)) have hmono := matroid_closure_mono M₂ hB_in hcl_yr omega have hfull2 := hcasc2 m le_rfl have hYhm : Yhead m = Yset := rfl rw [hYhm] at hfull2 have hsub_all : insert xLast I ⊆ I' ∪ Yset := by intro a ha rcases Finset.mem_insert.mp ha with ha_eq | haI · rw [ha_eq] refine Finset.mem_union_left _ (Finset.mem_union_right _ ?_) refine Finset.mem_image.mpr ⟨m, Finset.mem_range.mpr (by omega), ?_⟩ rw [dif_pos (by omega)] have hl : p[2 * m]'(by omega) = xLast := by have hidx : 2 * m = p.length - 1 := by omega simp only [hidx] rw [← List.getLast_eq_getElem] have := List.getLast?_eq_some_getLast (by intro h; rw [h] at hp_pos; simp at hp_pos : p ≠ []) rw [hp_last] at this; exact (Option.some.inj this).symm exact hl · by_cases haY : a ∈ Yset · exact Finset.mem_union_right _ haY · exact Finset.mem_union_left _ (Finset.mem_union_left _ (Finset.mem_sdiff.mpr ⟨haI, haY⟩)) have hxL_ind : M₂.IsIndep (insert xLast I) := (Finset.mem_filter.mp hxLast).2.2 have hxL_notI : xLast ∉ I := (Finset.mem_filter.mp hxLast).2.1 have hge := M₂.r_mono _ _ hsub_all have hle := M₂.r_le_card I' dsimp only [RankMatroid.IsIndep] at hxL_ind ⊢ rw [Finset.card_insert_of_notMem hxL_notI] at hxL_ind omega exact ih I' hI'_ind1 hI'_ind2 (by omega) · -- **NO AUGMENTING PATH FROM `X₁` TO `X₂` ⇒ EXACT MINIMAX DUAL PARTITION `U`!** let R : Finset (Fin n) := Finset.univ.filter (fun v => ∃ x₁ ∈ X₁, Relation.ReflTransGen D x₁ v) let U : Finset (Fin n) := Finset.univ \ R -- Claim A: `M₁.r U = (I ∩ U).card` (every `x ∈ U \ I` lies in `cl₁(I ∩ U)`)! have hA : M₁.r U = (I ∩ U).card := by have hall1 : ∀ x ∈ U \ (I ∩ U), M₁.r (insert x (I ∩ U)) = M₁.r (I ∩ U) := by intro x hx have hxU : x ∈ U := (Finset.mem_sdiff.mp hx).1 have hx_nR : x ∉ R := (Finset.mem_sdiff.mp hxU).2 have hx_nI : x ∉ I := fun h => (Finset.mem_sdiff.mp hx).2 (Finset.mem_inter.mpr ⟨h, hxU⟩) have hx_nX1 : x ∉ X₁ := fun h => hx_nR (Finset.mem_filter.mpr ⟨Finset.mem_univ x, x, h, Relation.ReflTransGen.refl⟩) have hdep1 : M₁.r (insert x I) = M₁.r I := by have hnotInd : ¬ M₁.IsIndep (insert x I) := fun h => hx_nX1 (Finset.mem_filter.mpr ⟨Finset.mem_univ x, hx_nI, h⟩) have h1 := M₁.r_mono I (insert x I) (Finset.subset_insert _ _) have h2 := M₁.r_le_card (insert x I) rw [Finset.card_insert_of_notMem hx_nI] at h2 dsimp only [RankMatroid.IsIndep] at hI1 hnotInd rw [Finset.card_insert_of_notMem hx_nI] at hnotInd; omega have hno_IR : ∀ z ∈ I ∩ R, ¬ M₁.IsIndep (insert x (I.erase z)) := by intro z hz hind_z have hzI := (Finset.mem_inter.mp hz).1 have hzR := (Finset.mem_inter.mp hz).2 obtain ⟨x₁, hx₁, hr⟩ := (Finset.mem_filter.mp hzR).2 exact hx_nR (Finset.mem_filter.mpr ⟨Finset.mem_univ x, x₁, hx₁, hr.tail (Or.inl ⟨hzI, hx_nI, hind_z⟩)⟩) have hpeel := matroid_closure_peel M₁ hI1 hx_nI hdep1 (I ∩ R) Finset.inter_subset_left hno_IR have heq : I \ (I ∩ R) = I ∩ U := by ext a; simp [U] rwa [heq] at hpeel have hu : (I ∩ U) ∪ (U \ (I ∩ U)) = U := Finset.union_sdiff_of_subset Finset.inter_subset_right conv_lhs => rw [← hu] rw [matroid_closure_union M₁ (I ∩ U) (U \ (I ∩ U)) hall1] exact M₁.indep_subset Finset.inter_subset_left hI1 -- Claim B: `M₂.r (univ \ U) = M₂.r R = (I ∩ R).card`! have hB : M₂.r (Finset.univ \ U) = (I ∩ R).card := by have hRU : Finset.univ \ U = R := by ext a; simp [U] rw [hRU] have hall2 : ∀ x ∈ R \ (I ∩ R), M₂.r (insert x (I ∩ R)) = M₂.r (I ∩ R) := by intro x hx have hxR : x ∈ R := (Finset.mem_sdiff.mp hx).1 have hx_nI : x ∉ I := fun h => (Finset.mem_sdiff.mp hx).2 (Finset.mem_inter.mpr ⟨h, hxR⟩) have hx_nX2 : x ∉ X₂ := fun hx2 => by obtain ⟨x₁, hx₁, hr⟩ := (Finset.mem_filter.mp hxR).2 exact hreach ⟨x₁, hx₁, x, hx2, hr⟩ have hdep2 : M₂.r (insert x I) = M₂.r I := by have hnotInd : ¬ M₂.IsIndep (insert x I) := fun h => hx_nX2 (Finset.mem_filter.mpr ⟨Finset.mem_univ x, hx_nI, h⟩) have h1 := M₂.r_mono I (insert x I) (Finset.subset_insert _ _) have h2 := M₂.r_le_card (insert x I) rw [Finset.card_insert_of_notMem hx_nI] at h2 dsimp only [RankMatroid.IsIndep] at hI2 hnotInd rw [Finset.card_insert_of_notMem hx_nI] at hnotInd; omega have hno_IU : ∀ z ∈ I ∩ U, ¬ M₂.IsIndep (insert x (I.erase z)) := by intro z hz hind_z have hzI := (Finset.mem_inter.mp hz).1 have hzU := (Finset.mem_inter.mp hz).2 obtain ⟨x₁, hx₁, hr⟩ := (Finset.mem_filter.mp hxR).2 exact (Finset.mem_sdiff.mp hzU).2 (Finset.mem_filter.mpr ⟨Finset.mem_univ z, x₁, hx₁, hr.tail (Or.inr ⟨hx_nI, hzI, hind_z⟩)⟩) have hpeel := matroid_closure_peel M₂ hI2 hx_nI hdep2 (I ∩ U) Finset.inter_subset_left hno_IU have heq : I \ (I ∩ U) = I ∩ R := by ext a; simp [U] rwa [heq] at hpeel have hu : (I ∩ R) ∪ (R \ (I ∩ R)) = R := Finset.union_sdiff_of_subset Finset.inter_subset_right conv_lhs => rw [← hu] rw [matroid_closure_union M₂ (I ∩ R) (R \ (I ∩ R)) hall2] exact M₂.indep_subset Finset.inter_subset_left hI2 refine ⟨I, U, hI1, hI2, ?_⟩ rw [hA, hB] have hu : (I ∩ U) ∪ (I ∩ R) = I := by ext a; simp [U]; tauto have hd : Disjoint (I ∩ U) (I ∩ R) := by rw [Finset.disjoint_left]; intro a h1 h2 exact (Finset.mem_sdiff.mp (Finset.mem_inter.mp h1).2).2 (Finset.mem_inter.mp h2).2 rw [← Finset.card_union_of_disjoint hd, hu] exact hind n ∅ M₁.r_empty M₂.r_empty (by simp) /-! =============================================================================== PART 5.5: SHARP BOUNDARY COROLLARIES, CONCRETE WITNESSES & GRAND UNIFICATION =============================================================================== -/ /-- Uniform matroid `U_{k, n}` (`r(S) = min S.card k`) is a valid `RankMatroid n`. -/ def uniformMatroid (k n : ℕ) : RankMatroid n where r S := min S.card k r_empty := by simp r_mono A B hAB := min_le_min_right k (Finset.card_le_card hAB) r_step A e := by have h1 : (insert e A).card ≤ A.card + 1 := Finset.card_insert_le e A omega r_submod A B := by have hcard := Finset.card_union_add_card_inter A B have hm1 := Finset.card_le_card (Finset.inter_subset_left (s₁ := A) (s₂ := B)) have hm2 := Finset.card_le_card (Finset.inter_subset_right (s₁ := A) (s₂ := B)) have hm3 := Finset.card_le_card (Finset.subset_union_left (s₁ := A) (s₂ := B)) have hm4 := Finset.card_le_card (Finset.subset_union_right (s₁ := A) (s₂ := B)) simp only [Nat.min_def] split_ifs <;> omega /-- Partition matroid induced by color map `color : Fin n → Fin c` with unit capacity per color! -/ def partitionMatroid {n c : ℕ} (color : Fin n → Fin c) : RankMatroid n where r S := (S.image color).card r_empty := by simp r_mono A B hAB := Finset.card_le_card (Finset.image_subset_image hAB) r_step A e := by rw [Finset.image_insert]; exact Finset.card_insert_le _ _ r_submod A B := by rw [Finset.image_union] have h1 := Finset.card_union_add_card_inter (A.image color) (B.image color) have h2 : (A ∩ B).image color ⊆ A.image color ∩ B.image color := Finset.image_inter_subset color A B have h3 := Finset.card_le_card h2 omega /-- **5-PILLAR GRAND UNIFICATION THEOREM: NETWORK FLOWS, COMBINATORIAL MINIMAX, BIRKHOFF–VON NEUMANN, GOMORY–HU CUT TREES & SUBMODULAR OPTIMIZATION**: -/ theorem network_flows_matching_submodular_grand_unification : -- Pillar 1: Ford–Fulkerson Integer Max-Flow Min-Cut + Edmonds–Karp Distance Monotonicity ((∀ (n : ℕ) (N : FlowNet n) (s t : Fin n), s ≠ t → ∃ (fStar : Fin n → Fin n → ℕ) (SStar : Finset (Fin n)), N.IsFlow s t fStar ∧ s ∈ SStar ∧ t ∉ SStar ∧ flowVal fStar s = (cutCap N SStar : ℤ)) ∧ (∀ (n : ℕ) (R R' : Fin n → Fin n → Prop) (s : Fin n) (d : Fin n → ℕ), d s = 0 → (∀ u v, R u v → d v ≤ d u + 1) → (∀ u v, R' u v → R u v ∨ d u = d v + 1) → ∀ k v, HasWalkLen R' k s v → d v ≤ k)) ∧ -- Pillar 2: Hall's Marriage + Full Birkhoff–von Neumann Convex Permutation Decomposition ((∀ (m : ℕ) (adj : Fin m → Fin m → Bool), (∀ A : Finset (Fin m), A.card ≤ (bipNeighbors adj A).card) → ∃ σ : Equiv.Perm (Fin m), ∀ i, adj i (σ i) = true) ∧ (∀ (n : ℕ), 1 ≤ n → ∀ (P : Fin n → Fin n → ℝ), IsDoublyStochastic P → ∃ (m : ℕ) (w : Fin m → ℝ) (π : Fin m → Equiv.Perm (Fin n)), m ≤ n ^ 2 ∧ (∀ r, 0 < w r) ∧ (∑ r : Fin m, w r = 1) ∧ (∀ i j, P i j = ∑ r : Fin m, w r * permMatrix (π r) i j))) ∧ -- Pillar 3: Gomory–Hu `≤ n - 1` Distinct Min-Cut Values + Stoer–Wagner MAO Min-Cut ((∀ (n : ℕ), 1 ≤ n → ∀ (w : Fin n → Fin n → ℝ), (∀ u v, w u v = w v u) → ((Finset.univ.filter (fun p : Fin n × Fin n => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card ≤ n - 1) ∧ (∀ (n : ℕ) (hn : 2 ≤ n) (w : Fin n → Fin n → ℝ), (∀ a b, w a b = w b a) → (∀ a b, 0 ≤ w a b) → ∀ (v : Equiv.Perm (Fin n)), (∀ k j : Fin n, k.1 < j.1 → crossWeight w (maoPrefix v k.1) {v j} ≤ crossWeight w (maoPrefix v k.1) {v k}) → ∀ C : Finset (Fin n), ((v ⟨n - 2, by omega⟩ ∈ C ∧ v ⟨n - 1, by omega⟩ ∉ C) ∨ (v ⟨n - 2, by omega⟩ ∉ C ∧ v ⟨n - 1, by omega⟩ ∈ C)) → cutVal w {v ⟨n - 1, by omega⟩} ≤ cutVal w C)) ∧ -- Pillar 4: Nemhauser–Wolsey–Fisher `(1 - 1/e)` + Lovász Extension Submodularity ↔ Convexity ((∀ k : ℕ, 1 ≤ k → (1 - 1 / (k : ℝ)) ^ k ≤ Real.exp (-1)) ∧ (∀ (n : ℕ) (f : Finset (Fin n) → ℝ), f ∅ = 0 → (IsSubmodular f ↔ ∀ (x y : Fin n → ℝ) (lam : ℝ), 0 ≤ lam → lam ≤ 1 → lovaszExt f (fun i => lam * x i + (1 - lam) * y i) ≤ lam * lovaszExt f x + (1 - lam) * lovaszExt f y))) ∧ -- Pillar 5: General Edmonds Matroid Intersection Strong Minimax (∀ (n : ℕ) (M₁ M₂ : RankMatroid n), ∃ (I U : Finset (Fin n)), M₁.IsIndep I ∧ M₂.IsIndep I ∧ I.card = M₁.r U + M₂.r (Finset.univ \ U)) := ⟨⟨fun _ N _ _ hst => by obtain ⟨f, S, h1, h2, h3, h4, _, _⟩ := ford_fulkerson_max_flow_min_cut_integral N hst exact ⟨f, S, h1, h2, h3, h4⟩, fun _ R R' s d h1 h2 h3 => edmonds_karp_distance_monotone R R' s d h1 h2 h3⟩, ⟨fun _ adj hh => halls_marriage_theorem adj hh, fun _ hn P hP => by obtain ⟨m, w, π, _, hle, h1, h2, h3⟩ := birkhoff_von_neumann_theorem hn P hP exact ⟨m, w, π, hle, h1, h2, h3⟩⟩, ⟨fun _ hn w hsym => gomory_hu_at_most_n_minus_one_distinct_values hn w hsym, fun _ hn w hsym hnn v hmao C hsep => stoer_wagner_mao_last_two_min_cut hn w hsym hnn v hmao C hsep⟩, ⟨fun _ hk => one_sub_one_div_pow_le_inv_exp hk, fun _ f hf0 => lovasz_extension_convex_iff_submodular f hf0⟩, fun _ M₁ M₂ => edmonds_matroid_intersection_strong_minimax M₁ M₂⟩ /-! ### Part 5.5B: Extended Non-Asymptotic Structure, Sharp Separations & Witness Suite (95 Additional Theorems) -/ -- Extended Pillar 1: Flows, Cuts, Scaling & Edmonds–Karp Structure /-- Source outflow equals negative sink outflow (`flowVal f s = - netFlow f t`) for any `s-t` flow (`s ≠ t`). -/ theorem flowVal_eq_neg_sink_netFlow {n : ℕ} (N : FlowNet n) {s t : Fin n} (hst : s ≠ t) {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) : flowVal f s = - netFlow f t := by have hsum := flow_sum_netFlow_zero f rw [← Finset.add_sum_erase _ _ (Finset.mem_univ s), ← Finset.add_sum_erase _ _ (Finset.mem_erase.mpr ⟨hst.symm, Finset.mem_univ t⟩)] at hsum have h0 : ∑ v ∈ (Finset.univ.erase s).erase t, netFlow f v = 0 := Finset.sum_eq_zero (fun v hv => hf.2 v (Finset.mem_erase.mp (Finset.mem_erase.mp hv).2).1 (Finset.mem_erase.mp hv).1) rw [h0, add_zero] at hsum dsimp only [flowVal]; linarith /-- Empty cut has capacity `0`. -/ theorem cutCap_empty_zero {n : ℕ} (N : FlowNet n) : cutCap N ∅ = 0 := by simp [cutCap] /-- Full cut `Finset.univ` has capacity `0`. -/ theorem cutCap_univ_zero {n : ℕ} (N : FlowNet n) : cutCap N Finset.univ = 0 := by simp [cutCap] /-- Real cut capacity is nonnegative whenever all capacities are nonnegative. -/ theorem realCutCap_nonneg {n : ℕ} (cap : Fin n → Fin n → ℝ) (hnn : ∀ u v, 0 ≤ cap u v) (S : Finset (Fin n)) : 0 ≤ realCutCap cap S := Finset.sum_nonneg (fun u _ => Finset.sum_nonneg (fun v _ => hnn u v)) /-- Zero real flow is feasible for any nonnegative real capacity matrix. -/ theorem real_zero_flow_valid {n : ℕ} (cap : Fin n → Fin n → ℝ) (hnn : ∀ u v, 0 ≤ cap u v) (s t : Fin n) : IsRealFlow cap s t (fun _ _ => 0) ∧ realNetFlow (fun _ _ => 0) s = 0 := ⟨⟨fun u v => ⟨le_rfl, hnn u v⟩, fun _ _ _ => by simp [realNetFlow]⟩, by simp [realNetFlow]⟩ /-- Zero-capacity arc carries zero flow in any valid integer flow. -/ theorem flow_zero_cap_zero_flow {n : ℕ} (N : FlowNet n) {s t u v : Fin n} {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) (hcap0 : N.cap u v = 0) : f u v = 0 := by have := hf.1 u v; omega /-- If no arc leaves source `s` (`∀ v, cap s v = 0`), then every feasible flow has value `≤ 0`. -/ theorem max_flow_zero_if_no_out_edges {n : ℕ} (N : FlowNet n) {s t : Fin n} (hst : s ≠ t) {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) (hno : ∀ v, N.cap s v = 0) : flowVal f s ≤ 0 := by have hle := max_flow_le_min_cut N hf (Finset.mem_singleton_self s) (by simp [hst.symm]) have h0 : cutCap N {s} = 0 := by dsimp only [cutCap]; rw [Finset.sum_singleton] exact Finset.sum_eq_zero (fun v _ => hno v) rw [h0] at hle; exact hle /-- If no arc enters sink `t` (`∀ u, cap u t = 0`), then every feasible flow has value `≤ 0`. -/ theorem max_flow_zero_if_no_in_edges {n : ℕ} (N : FlowNet n) {s t : Fin n} (hst : s ≠ t) {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) (hno : ∀ u, N.cap u t = 0) : flowVal f s ≤ 0 := by have hle := max_flow_le_min_cut N hf (Finset.mem_erase.mpr ⟨hst, Finset.mem_univ s⟩) (Finset.notMem_erase t Finset.univ) have h0 : cutCap N (Finset.univ.erase t) = 0 := by dsimp only [cutCap] have hcomp : Finset.univ \ Finset.univ.erase t = {t} := by ext v; simp rw [hcomp] exact Finset.sum_eq_zero (fun u _ => by rw [Finset.sum_singleton]; exact hno u) rw [h0] at hle; exact hle /-- Optimal Ford–Fulkerson integer max-flow has nonnegative value (`0 ≤ flowVal fStar s`). -/ theorem ford_fulkerson_flowVal_nonneg {n : ℕ} (N : FlowNet n) {s t : Fin n} (hst : s ≠ t) : ∃ fStar : Fin n → Fin n → ℕ, N.IsFlow s t fStar ∧ 0 ≤ flowVal fStar s := by obtain ⟨fStar, SStar, hf, _, _, heq, _, _⟩ := ford_fulkerson_max_flow_min_cut_integral N hst exact ⟨fStar, hf, by rw [heq]; exact Int.natCast_nonneg _⟩ /-- Any two minimum `s-t` cuts have identical capacity. -/ theorem min_cut_value_unique {n : ℕ} (N : FlowNet n) {s t : Fin n} {S₁ S₂ : Finset (Fin n)} (hs1 : s ∈ S₁) (ht1 : t ∉ S₁) (hs2 : s ∈ S₂) (ht2 : t ∉ S₂) (hmin1 : ∀ S, s ∈ S → t ∉ S → cutCap N S₁ ≤ cutCap N S) (hmin2 : ∀ S, s ∈ S → t ∉ S → cutCap N S₂ ≤ cutCap N S) : cutCap N S₁ = cutCap N S₂ := le_antisymm (hmin1 S₂ hs2 ht2) (hmin2 S₁ hs1 ht1) /-- On the zero flow, residual edges are exactly the positive-capacity arcs (`0 < N.cap u v`). -/ theorem resEdge_zero_flow_iff {n : ℕ} (N : FlowNet n) (u v : Fin n) : resEdge N (fun _ _ => 0) u v ↔ 0 < N.cap u v := by simp [resEdge] /-- Length-0 walk characterizes equality (`HasWalkLen R 0 s v ↔ s = v`). -/ theorem edmonds_karp_walk_zero {α : Type*} (R : α → α → Prop) (s v : α) : HasWalkLen R 0 s v ↔ s = v := Iff.rfl /-- Length-1 walk characterizes a single directed edge (`HasWalkLen R 1 s v ↔ R s v`). -/ theorem edmonds_karp_walk_one {α : Type*} (R : α → α → Prop) (s v : α) : HasWalkLen R 1 s v ↔ R s v := by simp [HasWalkLen] /-- Concatenation of walks adds lengths (`HasWalkLen R k₁ a b → HasWalkLen R k₂ b c → HasWalkLen R (k₁ + k₂) a c`). -/ theorem edmonds_karp_walk_trans {α : Type*} (R : α → α → Prop) {k₁ k₂ : ℕ} {a b c : α} (h1 : HasWalkLen R k₁ a b) (h2 : HasWalkLen R k₂ b c) : HasWalkLen R (k₁ + k₂) a c := by induction k₂ generalizing c with | zero => dsimp only [HasWalkLen] at h2; subst h2; simpa using h1 | succ k ih => obtain ⟨w, hw, hwc⟩ := h2 exact ⟨w, ih hw, hwc⟩ /-- Every walk of length `k` implies reflexive-transitive reachability. -/ theorem edmonds_karp_walk_implies_reflTransGen {α : Type*} (R : α → α → Prop) {k : ℕ} {a b : α} (h : HasWalkLen R k a b) : Relation.ReflTransGen R a b := by induction k generalizing b with | zero => dsimp only [HasWalkLen] at h; subst h; exact Relation.ReflTransGen.refl | succ k ih => obtain ⟨w, hw, hwb⟩ := h; exact (ih hw).tail hwb /-- Iterated Edmonds–Karp critical-edge distance jump: after `r` re-saturations, `d 0 + 2 * r ≤ d r`! -/ theorem edmonds_karp_iterated_jump_two (d : ℕ → ℕ) (hstep : ∀ r, d r + 2 ≤ d (r + 1)) : ∀ r : ℕ, d 0 + 2 * r ≤ d r := by intro r; induction r with | zero => simp | succ r ih => have := hstep r; omega /-- Scaling integer capacities and flow by `c : ℕ` preserves flow validity and scales value & cut capacity by `c`! -/ theorem flowNet_scale_valid {n : ℕ} (N : FlowNet n) (c : ℕ) {s t : Fin n} {f : Fin n → Fin n → ℕ} (hf : N.IsFlow s t f) (S : Finset (Fin n)) : let Nc : FlowNet n := ⟨fun u v => c * N.cap u v⟩ let fc : Fin n → Fin n → ℕ := fun u v => c * f u v Nc.IsFlow s t fc ∧ flowVal fc s = (c : ℤ) * flowVal f s ∧ cutCap Nc S = c * cutCap N S := by intro Nc fc have hnet : ∀ v : Fin n, netFlow fc v = (c : ℤ) * netFlow f v := by intro v; dsimp only [netFlow, fc] push_cast rw [← Finset.mul_sum, ← Finset.mul_sum]; ring refine ⟨⟨fun u v => Nat.mul_le_mul_left c (hf.1 u v), fun v hvs hvt => by rw [hnet v, hf.2 v hvs hvt, mul_zero]⟩, hnet s, ?_⟩ dsimp only [cutCap, Nc] rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun u _ => by rw [Finset.mul_sum]) /-- On a 2-vertex single-arc network `0 → 1` of capacity `C`, exact max-flow = min-cut = `C`! -/ theorem flowNet_single_arc_exact (C : ℕ) : let N : FlowNet 2 := ⟨fun u v => if u = 0 ∧ v = 1 then C else 0⟩ let f : Fin 2 → Fin 2 → ℕ := fun u v => if u = 0 ∧ v = 1 then C else 0 N.IsFlow 0 1 f ∧ flowVal f 0 = (C : ℤ) ∧ cutCap N {0} = C := by intro N f refine ⟨⟨fun _ _ => le_rfl, fun v h0 h1 => by fin_cases v <;> simp at h0 h1⟩, ?_, ?_⟩ · dsimp only [flowVal, netFlow, f]; simp · dsimp only [cutCap, N] rw [Finset.sum_singleton] have hcomp : (Finset.univ : Finset (Fin 2)) \ {0} = {1} := by decide rw [hcomp, Finset.sum_singleton]; simp /-- On a 3-vertex serial chain `0 → 1 → 2` with capacities `c₁, c₂`, every flow has `flowVal ≤ min c₁ c₂`! -/ theorem flowNet_serial_chain_bottleneck (c₁ c₂ : ℕ) (f : Fin 3 → Fin 3 → ℕ) (hf : (FlowNet.mk (fun u v => if u = 0 ∧ v = 1 then c₁ else if u = 1 ∧ v = 2 then c₂ else 0)).IsFlow 0 2 f) : flowVal f 0 ≤ (min c₁ c₂ : ℤ) := by let N : FlowNet 3 := ⟨fun u v => if u = 0 ∧ v = 1 then c₁ else if u = 1 ∧ v = 2 then c₂ else 0⟩ have h1 := max_flow_le_min_cut N hf (S := {0}) (by decide) (by decide) have h2 := max_flow_le_min_cut N hf (S := {0, 1}) (by decide) (by decide) have hc1 : cutCap N {0} = c₁ := by dsimp only [cutCap, N] have hcomp : (Finset.univ : Finset (Fin 3)) \ {0} = {1, 2} := by decide rw [hcomp, Finset.sum_singleton, Finset.sum_pair (by decide)]; simp have hc2 : cutCap N {0, 1} = c₂ := by dsimp only [cutCap, N] have hcomp : (Finset.univ : Finset (Fin 3)) \ {0, 1} = {2} := by decide rw [hcomp, Finset.sum_pair (by decide), Finset.sum_singleton, Finset.sum_singleton]; simp rw [hc1] at h1; rw [hc2] at h2 exact le_min h1 h2 -- Extended Pillar 2: Hall, König `d`-Regular, Assignment & Birkhoff Polytope Structure /-- Neighborhood of the empty set is empty. -/ theorem bipNeighbors_empty {m₁ m₂ : ℕ} (adj : Fin m₁ → Fin m₂ → Bool) : bipNeighbors adj ∅ = ∅ := by simp [bipNeighbors] /-- Neighborhood map is monotone (`A ⊆ B → N(A) ⊆ N(B)`). -/ theorem bipNeighbors_mono {m₁ m₂ : ℕ} (adj : Fin m₁ → Fin m₂ → Bool) {A B : Finset (Fin m₁)} (hAB : A ⊆ B) : bipNeighbors adj A ⊆ bipNeighbors adj B := by intro j hj obtain ⟨i, hiA, hij⟩ := (Finset.mem_filter.mp hj).2 exact Finset.mem_filter.mpr ⟨Finset.mem_univ j, i, hAB hiA, hij⟩ /-- Neighborhood distributes over union (`N(A ∪ B) = N(A) ∪ N(B)`). -/ theorem bipNeighbors_union {m₁ m₂ : ℕ} (adj : Fin m₁ → Fin m₂ → Bool) (A B : Finset (Fin m₁)) : bipNeighbors adj (A ∪ B) = bipNeighbors adj A ∪ bipNeighbors adj B := by ext j; simp only [bipNeighbors, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_union] constructor · rintro ⟨i, hA | hB, hij⟩ · exact Or.inl ⟨i, hA, hij⟩ · exact Or.inr ⟨i, hB, hij⟩ · rintro (⟨i, hi, hij⟩ | ⟨i, hi, hij⟩) · exact ⟨i, Or.inl hi, hij⟩ · exact ⟨i, Or.inr hi, hij⟩ /-- **EXACT HALL'S MARRIAGE BICONDITIONAL**: A bipartite graph has a perfect matching **IF AND ONLY IF** `∀ A, |A| ≤ |N(A)|`! -/ theorem halls_marriage_iff {m : ℕ} (adj : Fin m → Fin m → Bool) : (∃ σ : Equiv.Perm (Fin m), ∀ i, adj i (σ i) = true) ↔ (∀ A : Finset (Fin m), A.card ≤ (bipNeighbors adj A).card) := ⟨fun ⟨σ, hσ⟩ => perfect_matching_implies_hall adj σ hσ, halls_marriage_theorem adj⟩ /-- **KÖNIG'S `d`-REGULAR BIPARTITE PERFECT MATCHING THEOREM**: Every `d`-regular bipartite graph (`d ≥ 1`, every left and right vertex has degree `d`) admits a **PERFECT MATCHING** `σ : Equiv.Perm (Fin m)`! -/ theorem konig_d_regular_bipartite_perfect_matching {m d : ℕ} (hd : 1 ≤ d) (adj : Fin m → Fin m → Bool) (hL : ∀ i : Fin m, (Finset.univ.filter (fun j => adj i j = true)).card = d) (hR : ∀ j : Fin m, (Finset.univ.filter (fun i => adj i j = true)).card = d) : ∃ σ : Equiv.Perm (Fin m), ∀ i : Fin m, adj i (σ i) = true := by refine halls_marriage_theorem adj (fun A => ?_) have h1 : d * A.card = ∑ i ∈ A, ∑ j : Fin m, if adj i j then 1 else 0 := by have hrow : ∀ i ∈ A, (∑ j : Fin m, if adj i j then 1 else 0) = d := fun i _ => by rw [← Finset.sum_filter]; simp [hL i] rw [Finset.sum_congr rfl hrow]; simp [mul_comm] have h2 : ∑ i ∈ A, ∑ j : Fin m, (if adj i j then 1 else 0) = ∑ i ∈ A, ∑ j ∈ bipNeighbors adj A, if adj i j then 1 else 0 := by refine Finset.sum_congr rfl (fun i hi => ?_) symm refine Finset.sum_subset (Finset.subset_univ _) (fun j _ hj => ?_) split_ifs with hadj · exfalso; exact hj (Finset.mem_filter.mpr ⟨Finset.mem_univ j, i, hi, hadj⟩) · rfl have h3 : ∑ i ∈ A, ∑ j ∈ bipNeighbors adj A, (if adj i j then 1 else 0) ≤ d * (bipNeighbors adj A).card := by rw [Finset.sum_comm] calc ∑ j ∈ bipNeighbors adj A, ∑ i ∈ A, (if adj i j then 1 else 0) ≤ ∑ j ∈ bipNeighbors adj A, ∑ i : Fin m, (if adj i j then 1 else 0) := Finset.sum_le_sum (fun j _ => Finset.sum_le_sum_of_subset (Finset.subset_univ A)) _ = ∑ _j ∈ bipNeighbors adj A, d := Finset.sum_congr rfl (fun j _ => by rw [← Finset.sum_filter]; simp [hR j]) _ = d * (bipNeighbors adj A).card := by simp [mul_comm] have : d * A.card ≤ d * (bipNeighbors adj A).card := by omega exact Nat.le_of_mul_le_mul_left this (by omega) /-- **KÖNIG–EGERVÁRY WEAK DUALITY**: For ANY bipartite matching `M` and ANY bipartite vertex cover `(C₁, C₂)`, `M.card ≤ C₁.card + C₂.card`! -/ theorem konig_egervary_weak_duality {m₁ m₂ : ℕ} (adj : Fin m₁ → Fin m₂ → Bool) {M : Finset (Fin m₁ × Fin m₂)} {C₁ : Finset (Fin m₁)} {C₂ : Finset (Fin m₂)} (hMadj : ∀ e ∈ M, adj e.1 e.2 = true) (hMdisj : ∀ e₁ ∈ M, ∀ e₂ ∈ M, e₁ ≠ e₂ → e₁.1 ≠ e₂.1 ∧ e₁.2 ≠ e₂.2) (hcov : ∀ i j, adj i j = true → i ∈ C₁ ∨ j ∈ C₂) : M.card ≤ C₁.card + C₂.card := by classical let M₁ := M.filter (fun e => e.1 ∈ C₁) let M₂ := M.filter (fun e => e.1 ∉ C₁) have hpart : M = M₁ ∪ M₂ := by ext e; simp only [M₁, M₂, Finset.mem_union, Finset.mem_filter]; tauto have hdisj : Disjoint M₁ M₂ := by rw [Finset.disjoint_left]; intro e h1 h2 exact (Finset.mem_filter.mp h2).2 (Finset.mem_filter.mp h1).2 have hle1 : M₁.card ≤ C₁.card := Finset.card_le_card_of_injOn Prod.fst (fun e he => (Finset.mem_filter.mp he).2) (fun e₁ h₁ e₂ h₂ heq => by by_contra hne exact (hMdisj e₁ (Finset.mem_filter.mp h₁).1 e₂ (Finset.mem_filter.mp h₂).1 hne).1 heq) have hle2 : M₂.card ≤ C₂.card := Finset.card_le_card_of_injOn Prod.snd (fun e he => by have hm := (Finset.mem_filter.mp he).1 have hnot := (Finset.mem_filter.mp he).2 exact (hcov e.1 e.2 (hMadj e hm)).resolve_left hnot) (fun e₁ h₁ e₂ h₂ heq => by by_contra hne exact (hMdisj e₁ (Finset.mem_filter.mp h₁).1 e₂ (Finset.mem_filter.mp h₂).1 hne).2 heq) rw [hpart, Finset.card_union_of_disjoint hdisj]; omega /-- Complementary slackness certifies global optimality over ALL permutations `σ`! -/ theorem weighted_assignment_slackness_implies_opt {n : ℕ} (c : Fin n → Fin n → ℝ) (u v : Fin n → ℝ) (hdual : ∀ i j, u i + v j ≤ c i j) (σStar : Equiv.Perm (Fin n)) (hslack : ∀ i, u i + v (σStar i) = c i (σStar i)) : ∀ σ : Equiv.Perm (Fin n), ∑ i : Fin n, c i (σStar i) ≤ ∑ i : Fin n, c i (σ i) := by intro σ have h1 := (weighted_assignment_duality_and_slackness c u v hdual σStar).2.mpr hslack have h2 := (weighted_assignment_duality_and_slackness c u v hdual σ).1 linarith /-- Every entry of a permutation matrix is `0` or `1`. -/ theorem permMatrix_zero_one {n : ℕ} (σ : Equiv.Perm (Fin n)) (i j : Fin n) : permMatrix σ i j = 0 ∨ permMatrix σ i j = 1 := by dsimp only [permMatrix]; split_ifs <;> simp /-- Every permutation matrix is an extreme point of the Birkhoff polytope. -/ theorem permMatrix_is_birkhoff_extreme {n : ℕ} (hn : 1 ≤ n) (σ : Equiv.Perm (Fin n)) : ∀ (Q R : Fin n → Fin n → ℝ) (lam : ℝ), 0 < lam → lam < 1 → IsDoublyStochastic Q → IsDoublyStochastic R → (∀ i j, permMatrix σ i j = lam * Q i j + (1 - lam) * R i j) → Q = R := (birkhoff_extreme_point_iff_perm hn (permMatrix σ) (permMatrix_isDoublyStochastic σ)).mpr ⟨σ, fun _ _ => rfl⟩ /-- Every entry of a doubly stochastic matrix lies in `[0, 1]`. -/ theorem doubly_stochastic_entry_unit_interval {n : ℕ} {P : Fin n → Fin n → ℝ} (hP : IsDoublyStochastic P) (i j : Fin n) : 0 ≤ P i j ∧ P i j ≤ 1 := by refine ⟨hP.1 i j, ?_⟩ have := Finset.single_le_sum (fun j' _ => hP.1 i j') (Finset.mem_univ j) linarith [hP.2.1 i] /-- Convexity of the Birkhoff polytope: convex combinations of doubly stochastic matrices are doubly stochastic! -/ theorem doubly_stochastic_convex {n : ℕ} {P Q : Fin n → Fin n → ℝ} {lam : ℝ} (h0 : 0 ≤ lam) (h1 : lam ≤ 1) (hP : IsDoublyStochastic P) (hQ : IsDoublyStochastic Q) : IsDoublyStochastic (fun i j => lam * P i j + (1 - lam) * Q i j) := by refine ⟨fun i j => add_nonneg (mul_nonneg h0 (hP.1 i j)) (mul_nonneg (by linarith) (hQ.1 i j)), fun i => ?_, fun j => ?_⟩ · rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, hP.2.1 i, hQ.2.1 i]; ring · rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, hP.2.2 j, hQ.2.2 j]; ring /-- Transpose of a doubly stochastic matrix is doubly stochastic. -/ theorem doubly_stochastic_transpose {n : ℕ} {P : Fin n → Fin n → ℝ} (hP : IsDoublyStochastic P) : IsDoublyStochastic (fun i j => P j i) := ⟨fun i j => hP.1 j i, fun i => hP.2.2 i, fun j => hP.2.1 j⟩ /-- Uniform barycenter matrix `J_n / n` (`1 / n` everywhere, `n ≥ 1`) is doubly stochastic. -/ theorem doubly_stochastic_uniform {n : ℕ} (hn : 1 ≤ n) : IsDoublyStochastic (fun _ _ : Fin n => (1 : ℝ) / (n : ℝ)) := by have hnpos : (0 : ℝ) < (n : ℝ) := Nat.cast_pos.mpr (by omega) refine ⟨fun _ _ => by positivity, fun _ => ?_, fun _ => ?_⟩ · simp [mul_inv_cancel₀ (ne_of_gt hnpos)] · simp [mul_inv_cancel₀ (ne_of_gt hnpos)] /-- Matrix product of two doubly stochastic matrices is doubly stochastic (Birkhoff semigroup closure!). -/ theorem doubly_stochastic_mul {n : ℕ} {P Q : Fin n → Fin n → ℝ} (hP : IsDoublyStochastic P) (hQ : IsDoublyStochastic Q) : IsDoublyStochastic (fun i k => ∑ j : Fin n, P i j * Q j k) := by refine ⟨fun i k => Finset.sum_nonneg (fun j _ => mul_nonneg (hP.1 i j) (hQ.1 j k)), fun i => ?_, fun k => ?_⟩ · rw [Finset.sum_comm] trans ∑ j : Fin n, P i j · refine Finset.sum_congr rfl (fun j _ => by rw [← Finset.mul_sum, hQ.2.1 j, mul_one]) · exact hP.2.1 i · rw [Finset.sum_comm] trans ∑ j : Fin n, Q j k · refine Finset.sum_congr rfl (fun j _ => by rw [← Finset.sum_mul, hP.2.2 j, one_mul]) · exact hQ.2.2 k /-- Total sum of entries of any `n × n` doubly stochastic matrix equals `n`. -/ theorem doubly_stochastic_total_sum {n : ℕ} {P : Fin n → Fin n → ℝ} (hP : IsDoublyStochastic P) : ∑ i : Fin n, ∑ j : Fin n, P i j = (n : ℝ) := by simp_rw [hP.2.1]; simp /-- **LINEAR OPTIMIZATION OVER THE BIRKHOFF POLYTOPE IS ATTAINED AT A PERMUTATION MATRIX**: For ANY real cost matrix `c : Fin n → Fin n → ℝ` (`n ≥ 1`) and ANY doubly stochastic `P`, there exists a permutation `σ` with **`∑ i, c i (σ i) ≤ ∑ i, ∑ j, c i j · P i j`**! -/ theorem birkhoff_linear_opt_attained_at_perm {n : ℕ} (hn : 1 ≤ n) (c P : Fin n → Fin n → ℝ) (hP : IsDoublyStochastic P) : ∃ σ : Equiv.Perm (Fin n), ∑ i : Fin n, c i (σ i) ≤ ∑ i : Fin n, ∑ j : Fin n, c i j * P i j := by obtain ⟨m, w, π, _, _, hwpos, hwsum, hPeq⟩ := birkhoff_von_neumann_theorem hn P hP have hm_pos : 0 < m := by by_contra h have h0 : m = 0 := by omega subst h0; simp at hwsum have hne : (Finset.univ : Finset (Fin m)).Nonempty := ⟨⟨0, hm_pos⟩, Finset.mem_univ _⟩ obtain ⟨rStar, _, hrStar_min⟩ := Finset.exists_min_image Finset.univ (fun r : Fin m => ∑ i : Fin n, c i (π r i)) hne refine ⟨π rStar, ?_⟩ have hexp : ∑ i : Fin n, ∑ j : Fin n, c i j * P i j = ∑ r : Fin m, w r * (∑ i : Fin n, c i (π r i)) := by have h1 : ∀ i j, c i j * P i j = ∑ r : Fin m, w r * (c i j * permMatrix (π r) i j) := fun i j => by rw [hPeq i j, Finset.mul_sum]; refine Finset.sum_congr rfl (fun r _ => by ring) simp_rw [h1] rw [Finset.sum_comm] have hswap : ∀ i : Fin n, ∑ j : Fin n, ∑ r : Fin m, w r * (c i j * permMatrix (π r) i j) = ∑ r : Fin m, ∑ j : Fin n, w r * (c i j * permMatrix (π r) i j) := fun _ => Finset.sum_comm -- Wait: `Finset.sum_comm` above swapped `i` and `j`; let's do clean order! rw [Finset.sum_comm] simp_rw [hswap] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun r _ => ?_) rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun i _ => ?_) rw [← Finset.mul_sum]; congr 1 dsimp only [permMatrix]; simp rw [hexp] calc ∑ i : Fin n, c i (π rStar i) = (∑ r : Fin m, w r) * (∑ i : Fin n, c i (π rStar i)) := by rw [hwsum, one_mul] _ = ∑ r : Fin m, w r * (∑ i : Fin n, c i (π rStar i)) := Finset.sum_mul _ _ _ _ ≤ ∑ r : Fin m, w r * (∑ i : Fin n, c i (π r i)) := Finset.sum_le_sum (fun r _ => mul_le_mul_of_nonneg_left (hrStar_min r (Finset.mem_univ r)) (le_of_lt (hwpos r))) /-- Identity matrix is doubly stochastic. -/ theorem birkhoff_identity_is_ds (n : ℕ) : IsDoublyStochastic (permMatrix (Equiv.refl (Fin n))) := permMatrix_isDoublyStochastic (Equiv.refl (Fin n)) /-- Explicit `2 × 2` Birkhoff decomposition: every `2 × 2` doubly stochastic matrix is `p · I + (1 - p) · Swap`! -/ theorem birkhoff_2x2_explicit (P : Fin 2 → Fin 2 → ℝ) (hP : IsDoublyStochastic P) : let p : ℝ := P 0 0 (0 ≤ p ∧ p ≤ 1) ∧ ∀ i j : Fin 2, P i j = p * permMatrix (Equiv.refl (Fin 2)) i j + (1 - p) * permMatrix (Equiv.swap (0 : Fin 2) 1) i j := by intro p have hr0 := hP.2.1 0; have hr1 := hP.2.1 1; have hc0 := hP.2.2 0; have hc1 := hP.2.2 1 simp only [Fin.sum_univ_two] at hr0 hr1 hc0 hc1 refine ⟨doubly_stochastic_entry_unit_interval hP 0 0, fun i j => ?_⟩ fin_cases i <;> fin_cases j <;> simp [permMatrix, p] <;> linarith /-- Edge-disjoint Menger weak duality: any `s-t` path hits every `s-t` cut at least once! -/ theorem path_hits_every_cut {n : ℕ} {s t : Fin n} {S : Finset (Fin n)} (hs : s ∈ S) (ht : t ∉ S) : ∀ p : List (Fin n), p.head? = some s → p.getLast? = some t → ∃ e ∈ pathEdges p, e.1 ∈ S ∧ e.2 ∉ S := by intro p induction p generalizing s with | nil => intro h; simp at h | cons a as ih => intro hh hl simp only [List.head?_cons, Option.some.injEq] at hh; subst hh cases as with | nil => simp only [List.getLast?_singleton, Option.some.injEq] at hl; subst hl exact absurd hs ht | cons b bs => by_cases hbS : b ∈ S · obtain ⟨e, he, h1, h2⟩ := ih hbS rfl (by simpa using hl) exact ⟨e, by simp [pathEdges, he], h1, h2⟩ · exact ⟨(a, b), by simp [pathEdges], hs, hbS⟩ -- Extended Pillar 3: Cut Functions, Gomory–Hu Concrete Cases & Stoer–Wagner Contraction Step /-- Empty cut has weight `0`. -/ theorem cutVal_empty {n : ℕ} (w : Fin n → Fin n → ℝ) : cutVal w ∅ = 0 := by simp [cutVal, crossWeight] /-- Full cut `Finset.univ` has weight `0`. -/ theorem cutVal_univ {n : ℕ} (w : Fin n → Fin n → ℝ) : cutVal w Finset.univ = 0 := by simp [cutVal, crossWeight] /-- Nonnegative edge weights imply nonnegative `cutVal`. -/ theorem cutVal_nonneg {n : ℕ} (w : Fin n → Fin n → ℝ) (hnn : ∀ u v, 0 ≤ w u v) (A : Finset (Fin n)) : 0 ≤ cutVal w A := Finset.sum_nonneg (fun u _ => Finset.sum_nonneg (fun v _ => hnn u v)) /-- Symmetry of `crossWeight` for symmetric weights `w`. -/ theorem crossWeight_symm {n : ℕ} (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) (A B : Finset (Fin n)) : crossWeight w A B = crossWeight w B A := by dsimp only [crossWeight]; rw [Finset.sum_comm] exact Finset.sum_congr rfl (fun u _ => Finset.sum_congr rfl (fun v _ => hsym v u)) /-- Nonnegativity of `crossWeight`. -/ theorem crossWeight_nonneg {n : ℕ} (w : Fin n → Fin n → ℝ) (hnn : ∀ u v, 0 ≤ w u v) (A B : Finset (Fin n)) : 0 ≤ crossWeight w A B := Finset.sum_nonneg (fun u _ => Finset.sum_nonneg (fun v _ => hnn u v)) /-- `crossWeight` vanishes on empty left argument. -/ theorem crossWeight_empty_left {n : ℕ} (w : Fin n → Fin n → ℝ) (B : Finset (Fin n)) : crossWeight w ∅ B = 0 := by simp [crossWeight] /-- `crossWeight` vanishes on empty right argument. -/ theorem crossWeight_empty_right {n : ℕ} (w : Fin n → Fin n → ℝ) (A : Finset (Fin n)) : crossWeight w A ∅ = 0 := by simp [crossWeight] /-- Homogeneity of `cutVal` under weight scaling. -/ theorem cutVal_scale {n : ℕ} (c : ℝ) (w : Fin n → Fin n → ℝ) (A : Finset (Fin n)) : cutVal (fun u v => c * w u v) A = c * cutVal w A := by dsimp only [cutVal, crossWeight]; rw [Finset.mul_sum] exact Finset.sum_congr rfl (fun u _ => by rw [Finset.mul_sum]) /-- Additivity of `cutVal` in edge weights. -/ theorem cutVal_add {n : ℕ} (w₁ w₂ : Fin n → Fin n → ℝ) (A : Finset (Fin n)) : cutVal (fun u v => w₁ u v + w₂ u v) A = cutVal w₁ A + cutVal w₂ A := by dsimp only [cutVal, crossWeight]; rw [← Finset.sum_add_distrib] exact Finset.sum_congr rfl (fun u _ => by rw [← Finset.sum_add_distrib]) /-- `pairMinCut w u u = 0`. -/ theorem pairMinCut_self {n : ℕ} (w : Fin n → Fin n → ℝ) (u : Fin n) : pairMinCut w u u = 0 := by simp [pairMinCut] /-- `pairMinCut` is nonnegative whenever `0 ≤ w`. -/ theorem pairMinCut_nonneg {n : ℕ} (w : Fin n → Fin n → ℝ) (hnn : ∀ u v, 0 ≤ w u v) (u v : Fin n) : 0 ≤ pairMinCut w u v := by by_cases huv : u = v · subst huv; simp [pairMinCut] · obtain ⟨_, S, _, _, hSeq⟩ := pairMinCut_spec w huv rw [← hSeq]; exact cutVal_nonneg w hnn S /-- `pairMinCut w u v` is bounded above by the minimum weighted degree `min (cutVal w {u}) (cutVal w {v})`! -/ theorem pairMinCut_le_min_degree {n : ℕ} (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) {u v : Fin n} (huv : u ≠ v) : pairMinCut w u v ≤ min (cutVal w {u}) (cutVal w {v}) := by have h1 : pairMinCut w u v ≤ cutVal w {u} := (pairMinCut_spec w huv).1 {u} (Finset.mem_singleton_self u) (by simp [Ne.symm huv]) have h2 : pairMinCut w u v ≤ cutVal w {v} := by rw [pairMinCut_symm w hsym u v] exact (pairMinCut_spec w (Ne.symm huv)).1 {v} (Finset.mem_singleton_self v) (by simp [huv]) exact le_min h1 h2 /-- 4-vertex Gomory–Hu ultrametric chaining: `min (min (λ a b) (λ b c)) (λ c d) ≤ λ a d`! -/ theorem gomory_hu_ultrametric_four {n : ℕ} (w : Fin n → Fin n → ℝ) {a b c d : Fin n} (hab : a ≠ b) (hbc : b ≠ c) (hcd : c ≠ d) (hac : a ≠ c) (had : a ≠ d) : min (min (pairMinCut w a b) (pairMinCut w b c)) (pairMinCut w c d) ≤ pairMinCut w a d := by have h1 := gomory_hu_ultrametric w hab hbc hac have h2 := gomory_hu_ultrametric w hac hcd had exact le_trans (min_le_min_right _ h1) h2 /-- Gomory–Hu specialization `n = 1`: `0` distinct pairwise min-cut values. -/ theorem gomory_hu_n1_zero_distinct (w : Fin 1 → Fin 1 → ℝ) (hsym : ∀ u v, w u v = w v u) : ((Finset.univ.filter (fun p : Fin 1 × Fin 1 => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card = 0 := by have h := gomory_hu_at_most_n_minus_one_distinct_values (n := 1) le_rfl w hsym; omega /-- Gomory–Hu specialization `n = 2`: at most `1` distinct pairwise min-cut value. -/ theorem gomory_hu_n2_at_most_one (w : Fin 2 → Fin 2 → ℝ) (hsym : ∀ u v, w u v = w v u) : ((Finset.univ.filter (fun p : Fin 2 × Fin 2 => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card ≤ 1 := gomory_hu_at_most_n_minus_one_distinct_values (n := 2) (by omega) w hsym /-- Gomory–Hu specialization `n = 3`: at most `2` distinct pairwise min-cut values! -/ theorem gomory_hu_n3_at_most_two (w : Fin 3 → Fin 3 → ℝ) (hsym : ∀ u v, w u v = w v u) : ((Finset.univ.filter (fun p : Fin 3 × Fin 3 => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card ≤ 2 := gomory_hu_at_most_n_minus_one_distinct_values (n := 3) (by omega) w hsym /-- Gomory–Hu sharpness at `n = 4`: weighted path `P_4` attains ALL `3` distinct values `{1, 2, 3}`! -/ theorem gomory_hu_path_n4_exact : let w : Fin 4 → Fin 4 → ℝ := fun u v => if u.1 + 1 = v.1 then (u.1 + 1 : ℝ) else if v.1 + 1 = u.1 then (v.1 + 1 : ℝ) else 0 ((Finset.univ.filter (fun p : Fin 4 × Fin 4 => p.1 ≠ p.2)).image (fun p => pairMinCut w p.1 p.2)).card = 3 := (gomory_hu_n_minus_one_tight_witness (n := 4) (by omega)).2.2 /-- **STOER–WAGNER GLOBAL MIN-CUT PHASE DICHOTOMY**: For ANY cut `C` and last two MAO vertices `(s, t)`: EITHER `C` separates `s` and `t` (so `cutVal w {t} ≤ cutVal w C`), OR `s` and `t` lie on the SAME side of `C`! -/ theorem stoer_wagner_global_min_cut_dichotomy {n : ℕ} (hn : 2 ≤ n) (w : Fin n → Fin n → ℝ) (hsym : ∀ a b, w a b = w b a) (hnn : ∀ a b, 0 ≤ w a b) (v : Equiv.Perm (Fin n)) (hmao : ∀ k j : Fin n, k.1 < j.1 → crossWeight w (maoPrefix v k.1) {v j} ≤ crossWeight w (maoPrefix v k.1) {v k}) (C : Finset (Fin n)) : cutVal w {v ⟨n - 1, by omega⟩} ≤ cutVal w C ∨ (v ⟨n - 2, by omega⟩ ∈ C ↔ v ⟨n - 1, by omega⟩ ∈ C) := by by_cases hiff : v ⟨n - 2, by omega⟩ ∈ C ↔ v ⟨n - 1, by omega⟩ ∈ C · exact Or.inr hiff · left refine stoer_wagner_mao_last_two_min_cut hn w hsym hnn v hmao C ?_ by_cases h1 : v ⟨n - 2, by omega⟩ ∈ C · exact Or.inl ⟨h1, fun h2 => hiff ⟨fun _ => h2, fun _ => h1⟩⟩ · exact Or.inr ⟨h1, by by_contra h2; exact hiff ⟨fun h => absurd h h1, fun h => absurd h h2⟩⟩ /-- Global min-cut lower-bounds every singleton degree cut. -/ theorem pairMinCut_le_cutVal_singleton {n : ℕ} (w : Fin n → Fin n → ℝ) {u v : Fin n} (huv : u ≠ v) : pairMinCut w u v ≤ cutVal w {u} := (pairMinCut_spec w huv).1 {u} (Finset.mem_singleton_self u) (by simp [Ne.symm huv]) -- Extended Pillar 4: Submodular Algebra, Coverage, Exact Constants & Lovász Extension Properties /-- Sum of two submodular functions is submodular. -/ theorem submodular_add {n : ℕ} {f g : Finset (Fin n) → ℝ} (hf : IsSubmodular f) (hg : IsSubmodular g) : IsSubmodular (fun S => f S + g S) := fun A B => by linarith [hf A B, hg A B] /-- Nonnegative scalar multiple of a submodular function is submodular. -/ theorem submodular_scale_nonneg {n : ℕ} {f : Finset (Fin n) → ℝ} (hf : IsSubmodular f) {c : ℝ} (hc : 0 ≤ c) : IsSubmodular (fun S => c * f S) := fun A B => by nlinarith [hf A B] /-- Every additive / modular function `S ↦ ∑ i ∈ S, w i` is submodular (with exact equality!). -/ theorem modular_isSubmodular {n : ℕ} (w : Fin n → ℝ) : IsSubmodular (fun S : Finset (Fin n) => ∑ i ∈ S, w i) := fun A B => by rw [Finset.sum_union_inter] /-- Constant set functions are submodular and monotone. -/ theorem const_isSubmodular_monotone {n : ℕ} (c : ℝ) : IsSubmodular (fun _ : Finset (Fin n) => c) ∧ IsMonotone (fun _ : Finset (Fin n) => c) := ⟨fun _ _ => le_rfl, fun _ _ _ => le_rfl⟩ /-- Undirected graph cut function `cutVal w` is submodular! -/ theorem cutVal_isSubmodular {n : ℕ} (w : Fin n → Fin n → ℝ) (hsym : ∀ u v, w u v = w v u) (hnn : ∀ u v, 0 ≤ w u v) : IsSubmodular (cutVal w) := fun A B => by linarith [(cutVal_submodular w hsym hnn A B).2] /-- **SET-COVERAGE FUNCTION `S ↦ |(⋃_{i ∈ S} U_i)|` IS MONOTONE SUBMODULAR**: -/ theorem coverage_card_isMonotone_submodular {n m : ℕ} (U : Fin n → Finset (Fin m)) : IsMonotone (fun S : Finset (Fin n) => ((S.biUnion U).card : ℝ)) ∧ IsSubmodular (fun S : Finset (Fin n) => ((S.biUnion U).card : ℝ)) := by refine ⟨fun A B hAB => Nat.cast_le.mpr (Finset.card_le_card (Finset.biUnion_subset_biUnion_of_subset_left U hAB)), fun A B => ?_⟩ have h1 : (A ∪ B).biUnion U = A.biUnion U ∪ B.biUnion U := by ext x; simp only [Finset.mem_biUnion, Finset.mem_union] constructor · rintro ⟨a, hA | hB, hx⟩ · exact Or.inl ⟨a, hA, hx⟩ · exact Or.inr ⟨a, hB, hx⟩ · rintro (⟨a, hA, hx⟩ | ⟨a, hB, hx⟩) · exact ⟨a, Or.inl hA, hx⟩ · exact ⟨a, Or.inr hB, hx⟩ have h2 : (A ∩ B).biUnion U ⊆ A.biUnion U ∩ B.biUnion U := by intro x hx; obtain ⟨i, hi, hxi⟩ := Finset.mem_biUnion.mp hx exact Finset.mem_inter.mpr ⟨Finset.mem_biUnion.mpr ⟨i, (Finset.mem_inter.mp hi).1, hxi⟩, Finset.mem_biUnion.mpr ⟨i, (Finset.mem_inter.mp hi).2, hxi⟩⟩ have h3 := Finset.card_union_add_card_inter (A.biUnion U) (B.biUnion U) have h4 := Finset.card_le_card h2 have hN : ((A ∪ B).biUnion U).card + ((A ∩ B).biUnion U).card ≤ (A.biUnion U).card + (B.biUnion U).card := by rw [h1]; omega have hR : ((((A ∪ B).biUnion U).card + ((A ∩ B).biUnion U).card : ℕ) : ℝ) ≤ (((A.biUnion U).card + (B.biUnion U).card : ℕ) : ℝ) := Nat.cast_le.mpr hN push_cast at hR; exact hR /-- **CONCAVE CARDINALITY FUNCTIONS ARE SUBMODULAR**: If `g : ℕ → ℝ` has non-increasing discrete increments (`g (m + 2) - g (m + 1) ≤ g (m + 1) - g m`), then `S ↦ g S.card` is submodular! -/ theorem concave_card_isSubmodular {n : ℕ} (g : ℕ → ℝ) (hconc : ∀ m : ℕ, g (m + 2) - g (m + 1) ≤ g (m + 1) - g m) : IsSubmodular (fun S : Finset (Fin n) => g S.card) := by rw [submodular_iff_diminishing_returns] intro A B e hAB heB have heA : e ∉ A := fun h => heB (hAB h) rw [Finset.card_insert_of_notMem heB, Finset.card_insert_of_notMem heA] have hanti : ∀ a b : ℕ, a ≤ b → g (b + 1) - g b ≤ g (a + 1) - g a := by intro a b hab have hind : ∀ d : ℕ, g (a + d + 1) - g (a + d) ≤ g (a + 1) - g a := by intro d; induction d with | zero => simp | succ d ih => have h1 : a + (d + 1) = a + d + 1 := by omega have h2 : a + d + 1 + 1 = a + d + 2 := by omega rw [h1, h2] linarith [hconc (a + d)] have heq : a + (b - a) = b := by omega rw [← heq]; exact hind (b - a) exact hanti A.card B.card (Finset.card_le_card hAB) /-- Complement of a submodular function `S ↦ f (univ \ S)` is submodular! -/ theorem submodular_complement {n : ℕ} {f : Finset (Fin n) → ℝ} (hf : IsSubmodular f) : IsSubmodular (fun S : Finset (Fin n) => f (Finset.univ \ S)) := fun A B => by have h1 : Finset.univ \ (A ∪ B) = (Finset.univ \ A) ∩ (Finset.univ \ B) := by ext x; simp have h2 : Finset.univ \ (A ∩ B) = (Finset.univ \ A) ∪ (Finset.univ \ B) := by ext x; simp; tauto dsimp only rw [h1, h2] linarith [hf (Finset.univ \ A) (Finset.univ \ B)] /-- Exact Nemhauser–Wolsey–Fisher ratios at `k = 1` (`1`), `k = 2` (`3/4`), `k = 3` (`19/27`), `k = 4` (`175/256`). -/ theorem nwf_small_k_exact : (1 - (1 - 1 / (1 : ℝ)) ^ 1 = 1) ∧ (1 - (1 - 1 / (2 : ℝ)) ^ 2 = 3 / 4) ∧ (1 - (1 - 1 / (3 : ℝ)) ^ 3 = 19 / 27) ∧ (1 - (1 - 1 / (4 : ℝ)) ^ 4 = 175 / 256) := by norm_num /-- Exact numeric sandwich on the universal NWF constant `1 - 1 / e`: `0.632 < 1 - exp (-1) < 0.633`! -/ theorem one_sub_inv_exp_sandwich : (632 / 1000 : ℝ) < 1 - Real.exp (-1) ∧ 1 - Real.exp (-1) < (633 / 1000 : ℝ) := by have hgt := Real.exp_one_gt_d9 have hlt := Real.exp_one_lt_d9 have hexp_pos : 0 < Real.exp 1 := Real.exp_pos 1 have hinv : Real.exp (-1) = (Real.exp 1)⁻¹ := Real.exp_neg 1 rw [hinv] have h1 : (Real.exp 1)⁻¹ < 368 / 1000 := by rw [inv_lt_comm₀ hexp_pos (by norm_num)]; linarith have h2 : 367 / 1000 < (Real.exp 1)⁻¹ := by rw [lt_inv_comm₀ (by norm_num) hexp_pos]; linarith exact ⟨by linarith, by linarith⟩ /-- Strict separation: randomized BFNS `1/2` strictly beats deterministic double-greedy `1/3`, and monotone NWF `1 - 1/e` strictly beats unconstrained `1/2`! -/ theorem submodular_approx_hierarchy : (1 / 3 : ℝ) < 1 / 2 ∧ (1 / 2 : ℝ) < 1 - Real.exp (-1) ∧ 1 - Real.exp (-1) < 3 / 4 := by have hs := one_sub_inv_exp_sandwich exact ⟨by norm_num, by linarith, by linarith⟩ /-- Lovász extension at `x = 0` equals `0`. -/ theorem lovaszExt_zero {n : ℕ} (f : Finset (Fin n) → ℝ) : lovaszExt f (fun _ => 0) = 0 := by simp [lovaszExt, lovaszExtByPerm] /-- Lovász extension at `x = 1` equals `f Finset.univ` (whenever `f ∅ = 0`). -/ theorem lovaszExt_ones {n : ℕ} (f : Finset (Fin n) → ℝ) (hf0 : f ∅ = 0) : lovaszExt f (fun _ => 1) = f Finset.univ := by have h := lovaszExt_indicator f hf0 Finset.univ simpa using h /-- **POSITIVE HOMOGENEITY OF THE LOVÁSZ EXTENSION**: For ANY `c ≥ 0` and `f ∅ = 0`, `lovaszExt f (c · x) = c · lovaszExt f x`! -/ theorem lovaszExt_pos_homog {n : ℕ} (f : Finset (Fin n) → ℝ) (hf0 : f ∅ = 0) (x : Fin n → ℝ) {c : ℝ} (hc : 0 ≤ c) : lovaszExt f (fun i => c * x i) = c * lovaszExt f x := by let π := Classical.choose (exists_antitone_perm x) have hπ := Classical.choose_spec (exists_antitone_perm x) have hπc : ∀ i j : Fin n, i.1 ≤ j.1 → c * x (π j) ≤ c * x (π i) := fun i j hij => mul_le_mul_of_nonneg_left (hπ i j hij) hc rw [lovaszExt_eq_byPerm f hf0 (fun i => c * x i) π hπc, lovaszExt_eq_byPerm f hf0 x π hπ] dsimp only [lovaszExtByPerm] rw [Finset.mul_sum] exact Finset.sum_congr rfl (fun k _ => by ring) /-- **CONSTANT-SHIFT PROPERTY OF THE LOVÁSZ EXTENSION**: For ANY `c : ℝ` and `f ∅ = 0`, `lovaszExt f (x + c) = lovaszExt f x + c * f Finset.univ`! -/ theorem lovaszExt_shift_const {n : ℕ} (f : Finset (Fin n) → ℝ) (hf0 : f ∅ = 0) (x : Fin n → ℝ) (c : ℝ) : lovaszExt f (fun i => x i + c) = lovaszExt f x + c * f Finset.univ := by let π := Classical.choose (exists_antitone_perm x) have hπ := Classical.choose_spec (exists_antitone_perm x) have hπc : ∀ i j : Fin n, i.1 ≤ j.1 → x (π j) + c ≤ x (π i) + c := fun i j hij => by linarith [hπ i j hij] rw [lovaszExt_eq_byPerm f hf0 (fun i => x i + c) π hπc, lovaszExt_eq_byPerm f hf0 x π hπ] dsimp only [lovaszExtByPerm] have hsplit : ∑ k : Fin n, (x (π k) + c) * (f (permPrefix π (k.1 + 1)) - f (permPrefix π k.1)) = (∑ k : Fin n, x (π k) * (f (permPrefix π (k.1 + 1)) - f (permPrefix π k.1))) + c * (∑ k : Fin n, (f (permPrefix π (k.1 + 1)) - f (permPrefix π k.1))) := by rw [Finset.mul_sum, ← Finset.sum_add_distrib] exact Finset.sum_congr rfl (fun k _ => by ring) rw [hsplit] congr 1; congr 1 have htele : ∀ m ≤ n, ∑ k ∈ Finset.range m, (f (permPrefix π (k + 1)) - f (permPrefix π k)) = f (permPrefix π m) := by intro m; induction m with | zero => intro _ have hP0 : permPrefix π 0 = ∅ := by simp [permPrefix] simp [hP0, hf0] | succ m ih => intro hm; rw [Finset.sum_range_succ, ih (by omega)]; ring have hbij : ∑ k : Fin n, (f (permPrefix π (k.1 + 1)) - f (permPrefix π k.1)) = ∑ k ∈ Finset.range n, (f (permPrefix π (k + 1)) - f (permPrefix π k)) := Finset.sum_bij (fun k _ => k.1) (fun k _ => Finset.mem_range.mpr k.2) (fun _ _ _ _ h => Fin.ext h) (fun r hr => ⟨⟨r, Finset.mem_range.mp hr⟩, Finset.mem_univ _, rfl⟩) (fun _ _ => rfl) have hPn : permPrefix π n = Finset.univ := by ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, iff_true] exact ⟨π.symm a, (π.symm a).2, π.apply_symm_apply a⟩ rw [hbij, htele n le_rfl, hPn] /-- Lovász extension of a modular function `S ↦ ∑ i ∈ S, w i` is linear: `∑ i, w i * x i`! -/ theorem lovaszExt_modular_exact {n : ℕ} (w x : Fin n → ℝ) : lovaszExt (fun S : Finset (Fin n) => ∑ i ∈ S, w i) x = ∑ i : Fin n, w i * x i := by let π := Classical.choose (exists_antitone_perm x) have hπ := Classical.choose_spec (exists_antitone_perm x) rw [lovaszExt_eq_byPerm _ (by simp) x π hπ] dsimp only [lovaszExtByPerm] rw [← Equiv.sum_comp π (fun i => w i * x i)] refine Finset.sum_congr rfl (fun k _ => ?_) have hins : permPrefix π (k.1 + 1) = insert (π k) (permPrefix π k.1) ∧ π k ∉ permPrefix π k.1 := by constructor · ext a; simp only [permPrefix, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert] constructor · rintro ⟨j, hj, rfl⟩ rcases eq_or_lt_of_le (Nat.lt_succ_iff.mp hj) with heq | hlt · left; congr 1; exact Fin.ext heq · right; exact ⟨j, hlt, rfl⟩ · rintro (rfl | ⟨j, hj, rfl⟩) · exact ⟨k, Nat.lt_succ_self _, rfl⟩ · exact ⟨j, Nat.lt_succ_of_lt hj, rfl⟩ · intro hmem; obtain ⟨j, hj, heq⟩ := Finset.mem_image.mp hmem have := congrArg Fin.val (π.injective heq); have := (Finset.mem_filter.mp hj).2; omega rw [hins.1, Finset.sum_insert hins.2]; ring /-- Subadditivity of the Lovász extension for submodular `f` (`f ∅ = 0`): `f̂(x + y) ≤ f̂(x) + f̂(y)`! -/ theorem lovaszExt_subadditive {n : ℕ} (f : Finset (Fin n) → ℝ) (hsub : IsSubmodular f) (hf0 : f ∅ = 0) (x y : Fin n → ℝ) : lovaszExt f (fun i => x i + y i) ≤ lovaszExt f x + lovaszExt f y := by have hconv := (lovasz_extension_convex_iff_submodular f hf0).mp hsub x y (1 / 2) (by norm_num) (by norm_num) have h2 : lovaszExt f (fun i => (1 / 2 : ℝ) * x i + (1 - 1 / 2 : ℝ) * y i) = (1 / 2 : ℝ) * lovaszExt f (fun i => x i + y i) := by have heq : (fun i => (1 / 2 : ℝ) * x i + (1 - 1 / 2 : ℝ) * y i) = (fun i => (1 / 2 : ℝ) * (x i + y i)) := funext (fun i => by ring) rw [heq, lovaszExt_pos_homog f hf0 _ (by norm_num)] linarith /-- Convexity of the Edmonds Base Polytope `B(f)`. -/ theorem edmonds_base_polytope_convex {n : ℕ} (f : Finset (Fin n) → ℝ) {y₁ y₂ : Fin n → ℝ} {lam : ℝ} (h0 : 0 ≤ lam) (h1 : lam ≤ 1) (hy1 : IsInBasePolytope f y₁) (hy2 : IsInBasePolytope f y₂) : IsInBasePolytope f (fun i => lam * y₁ i + (1 - lam) * y₂ i) := by refine ⟨fun S => ?_, ?_⟩ · rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum] nlinarith [hy1.1 S, hy2.1 S] · rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, hy1.2, hy2.2]; ring /-- Lovász extension lower-bounds every base-polytope linear functional. -/ theorem lovaszExt_ge_base_dot {n : ℕ} (f : Finset (Fin n) → ℝ) (hsub : IsSubmodular f) (hf0 : f ∅ = 0) (x y : Fin n → ℝ) (hy : IsInBasePolytope f y) : ∑ i : Fin n, x i * y i ≤ lovaszExt f x := (edmonds_polymatroid_greedy_optimal f hsub hf0 x _ (Classical.choose_spec (exists_antitone_perm x))).2.2 y hy -- Extended Pillar 5: Matroid Exchange Axiom, Equicardinality of Bases, Matroid Operations & Minimax Corollaries /-- Empty set is independent in every rank matroid. -/ theorem RankMatroid.indep_empty {n : ℕ} (M : RankMatroid n) : M.IsIndep ∅ := by simp [RankMatroid.IsIndep, M.r_empty] /-- Rank of any subset is bounded above by the full matroid rank `M.r Finset.univ`. -/ theorem RankMatroid.r_le_univ {n : ℕ} (M : RankMatroid n) (A : Finset (Fin n)) : M.r A ≤ M.r Finset.univ := M.r_mono A Finset.univ (Finset.subset_univ A) /-- Single-element insertion increases rank by `0` or `1`. -/ theorem RankMatroid.r_insert_eq_or_succ {n : ℕ} (M : RankMatroid n) (A : Finset (Fin n)) (e : Fin n) : M.r (insert e A) = M.r A ∨ M.r (insert e A) = M.r A + 1 := by have h1 := M.r_mono A (insert e A) (Finset.subset_insert e A) have h2 := M.r_step A e omega /-- Every independent set has cardinality at most `M.r Finset.univ`. -/ theorem RankMatroid.indep_card_le_rank_univ {n : ℕ} (M : RankMatroid n) {I : Finset (Fin n)} (hI : M.IsIndep I) : I.card ≤ M.r Finset.univ := by rw [← hI]; exact M.r_le_univ I /-- **MATROID STEINITZ AUGMENTATION / EXCHANGE AXIOM**: If `M.IsIndep I`, `M.IsIndep J`, and `I.card < J.card`, then there exists `e ∈ J \ I` such that `M.IsIndep (insert e I)`! -/ theorem RankMatroid.exchange_property {n : ℕ} (M : RankMatroid n) {I J : Finset (Fin n)} (hI : M.IsIndep I) (hJ : M.IsIndep J) (hlt : I.card < J.card) : ∃ e ∈ J \ I, M.IsIndep (insert e I) := by by_contra hnone; push Not at hnone have hall : ∀ e ∈ J \ I, M.r (insert e I) = M.r I := by intro e he have heI : e ∉ I := (Finset.mem_sdiff.mp he).2 have hnot := hnone e he rcases M.r_insert_eq_or_succ I e with h0 | h1 · exact h0 · exfalso; apply hnot dsimp only [RankMatroid.IsIndep] at hI ⊢ rw [h1, hI, Finset.card_insert_of_notMem heI] have hcl := matroid_closure_union M I (J \ I) hall have hJsub : J ⊆ I ∪ (J \ I) := fun x hx => by by_cases hxI : x ∈ I · exact Finset.mem_union_left _ hxI · exact Finset.mem_union_right _ (Finset.mem_sdiff.mpr ⟨hx, hxI⟩) have hge := M.r_mono _ _ hJsub dsimp only [RankMatroid.IsIndep] at hI hJ omega /-- **EQUICARDINALITY OF MATROID BASES**: Every inclusion-maximal independent set (basis) of `M` has cardinality **`= M.r Finset.univ`**! -/ theorem RankMatroid.basis_card_eq_rank_univ {n : ℕ} (M : RankMatroid n) {B : Finset (Fin n)} (hB : M.IsIndep B) (hmax : ∀ e ∉ B, ¬ M.IsIndep (insert e B)) : B.card = M.r Finset.univ := by have hall : ∀ e ∈ Finset.univ \ B, M.r (insert e B) = M.r B := by intro e he have heB : e ∉ B := (Finset.mem_sdiff.mp he).2 rcases M.r_insert_eq_or_succ B e with h0 | h1 · exact h0 · exfalso; apply hmax e heB dsimp only [RankMatroid.IsIndep] at hB ⊢ rw [h1, hB, Finset.card_insert_of_notMem heB] have hcl := matroid_closure_union M B (Finset.univ \ B) hall have hu : B ∪ (Finset.univ \ B) = Finset.univ := Finset.union_sdiff_of_subset (Finset.subset_univ B) rw [hu] at hcl dsimp only [RankMatroid.IsIndep] at hB; omega /-- Uniform matroid `U_{k, n}` independence characterization (`IsIndep I ↔ I.card ≤ k`). -/ theorem uniformMatroid_indep_iff (k n : ℕ) (I : Finset (Fin n)) : (uniformMatroid k n).IsIndep I ↔ I.card ≤ k := by simp [RankMatroid.IsIndep, uniformMatroid] /-- Full rank of uniform matroid `U_{k, n}` is `min n k`. -/ theorem uniformMatroid_rank_univ (k n : ℕ) : (uniformMatroid k n).r Finset.univ = min n k := by simp [uniformMatroid] /-- In the free matroid `U_{n, n}`, every subset is independent. -/ theorem freeMatroid_indep_all (n : ℕ) (I : Finset (Fin n)) : (uniformMatroid n n).IsIndep I := by rw [uniformMatroid_indep_iff] calc I.card ≤ (Finset.univ : Finset (Fin n)).card := Finset.card_le_univ _ _ = n := by simp /-- In the rank-0 matroid `U_{0, n}`, only `∅` is independent. -/ theorem trivialMatroid_indep_iff (n : ℕ) (I : Finset (Fin n)) : (uniformMatroid 0 n).IsIndep I ↔ I = ∅ := by rw [uniformMatroid_indep_iff, Nat.le_zero, Finset.card_eq_zero] /-- Partition matroid independence characterization (`IsIndep I ↔ color is injective on I`). -/ theorem partitionMatroid_indep_iff {n c : ℕ} (color : Fin n → Fin c) (I : Finset (Fin n)) : (partitionMatroid color).IsIndep I ↔ Set.InjOn color (I : Set (Fin n)) := by dsimp only [RankMatroid.IsIndep, partitionMatroid] exact Finset.card_image_iff /-- Restricting a rank matroid `M` to a subset `D ⊆ Fin n` yields a valid rank matroid. -/ def restrictMatroid {n : ℕ} (M : RankMatroid n) (D : Finset (Fin n)) : RankMatroid n where r S := M.r (S ∩ D) r_empty := by simp [M.r_empty] r_mono A B hAB := M.r_mono _ _ (Finset.inter_subset_inter_right hAB) r_step A e := by by_cases he : e ∈ D · have h : insert e A ∩ D = insert e (A ∩ D) := by ext x; by_cases hx : x = e <;> simp [hx, he] rw [h]; exact M.r_step _ _ · have h : insert e A ∩ D = A ∩ D := by ext x; by_cases hx : x = e <;> simp [hx, he] rw [h]; omega r_submod A B := by have h1 : (A ∪ B) ∩ D = (A ∩ D) ∪ (B ∩ D) := Finset.union_inter_distrib_right A B D have h2 : (A ∩ B) ∩ D = (A ∩ D) ∩ (B ∩ D) := by ext x; simp rw [h1, h2]; exact M.r_submod _ _ /-- Truncating a rank matroid `M` to rank `k` (`r' S = min (M.r S) k`) yields a valid rank matroid! -/ def truncateMatroid {n : ℕ} (M : RankMatroid n) (k : ℕ) : RankMatroid n where r S := min (M.r S) k r_empty := by simp [M.r_empty] r_mono A B hAB := min_le_min_right k (M.r_mono A B hAB) r_step A e := by have := M.r_step A e; simp only [Nat.min_def]; split_ifs <;> omega r_submod A B := by have hs := M.r_submod A B have hm1 := M.r_mono (A ∩ B) A Finset.inter_subset_left have hm2 := M.r_mono (A ∩ B) B Finset.inter_subset_right have hm3 := M.r_mono A (A ∪ B) Finset.subset_union_left have hm4 := M.r_mono B (A ∪ B) Finset.subset_union_right simp only [Nat.min_def]; split_ifs <;> omega /-- Symmetry of matroid intersection common independent sets. -/ theorem matroid_intersection_symm {n : ℕ} (M₁ M₂ : RankMatroid n) (I : Finset (Fin n)) : (M₁.IsIndep I ∧ M₂.IsIndep I) ↔ (M₂.IsIndep I ∧ M₁.IsIndep I) := And.comm /-- Intersecting any matroid `M` with the free matroid `U_{n, n}` attains maximum size `M.r Finset.univ`! -/ theorem matroid_intersection_with_free {n : ℕ} (M : RankMatroid n) : ∃ I : Finset (Fin n), M.IsIndep I ∧ (uniformMatroid n n).IsIndep I ∧ I.card = M.r Finset.univ := by obtain ⟨I, U, h1, h2, heq⟩ := edmonds_matroid_intersection_strong_minimax M (uniformMatroid n n) have hle1 : I.card ≤ M.r Finset.univ := M.indep_card_le_rank_univ h1 have hge1 : M.r Finset.univ ≤ M.r U + (uniformMatroid n n).r (Finset.univ \ U) := by have hsub := M.r_submod U (Finset.univ \ U) have hu : U ∪ (Finset.univ \ U) = Finset.univ := Finset.union_sdiff_of_subset (Finset.subset_univ U) have hi : U ∩ (Finset.univ \ U) = ∅ := by ext x; simp rw [hu, hi, M.r_empty, add_zero] at hsub have hleU : (Finset.univ \ U).card ≤ n := by calc (Finset.univ \ U).card ≤ (Finset.univ : Finset (Fin n)).card := Finset.card_le_univ _ _ = n := by simp have hrU : M.r (Finset.univ \ U) ≤ (uniformMatroid n n).r (Finset.univ \ U) := by dsimp only [uniformMatroid]; rw [min_eq_left hleU]; exact M.r_le_card _ omega exact ⟨I, h1, h2, by omega⟩ /-- Intersecting any matroid `M` with itself attains maximum size `M.r Finset.univ`! -/ theorem matroid_intersection_self {n : ℕ} (M : RankMatroid n) : ∃ I : Finset (Fin n), M.IsIndep I ∧ I.card = M.r Finset.univ := by obtain ⟨I, h1, _, hcard⟩ := matroid_intersection_with_free M exact ⟨I, h1, hcard⟩ /-- Intersecting `M` with `uniformMatroid k n` attains exact maximum size `min (M.r Finset.univ) k`! -/ theorem matroid_intersection_with_uniform {n : ℕ} (M : RankMatroid n) (k : ℕ) : ∃ I : Finset (Fin n), M.IsIndep I ∧ (uniformMatroid k n).IsIndep I ∧ I.card = min (M.r Finset.univ) k := by obtain ⟨I, U, h1, h2, heq⟩ := edmonds_matroid_intersection_strong_minimax M (uniformMatroid k n) have hle1 : I.card ≤ M.r Finset.univ := M.indep_card_le_rank_univ h1 have hle2 : I.card ≤ k := (uniformMatroid_indep_iff k n I).mp h2 have hge : min (M.r Finset.univ) k ≤ M.r U + (uniformMatroid k n).r (Finset.univ \ U) := by have hsub := M.r_submod U (Finset.univ \ U) have hu : U ∪ (Finset.univ \ U) = Finset.univ := Finset.union_sdiff_of_subset (Finset.subset_univ U) have hi : U ∩ (Finset.univ \ U) = ∅ := by ext x; simp rw [hu, hi, M.r_empty, add_zero] at hsub have hcard := M.r_le_card (Finset.univ \ U) dsimp only [uniformMatroid]; simp only [Nat.min_def]; split_ifs <;> omega exact ⟨I, h1, h2, by simp only [Nat.min_def] at hge ⊢; split_ifs at hge ⊢ <;> omega⟩ /-- **EDMONDS MATROID INTERSECTION OPTIMALITY CERTIFICATE**: If `I` is common-independent and `I.card = M₁.r U + M₂.r (univ \ U)`, then `I` is a MAXIMUM common independent set AND `U` is a MINIMUM minimax partition! -/ theorem matroid_intersection_opt_certificate {n : ℕ} (M₁ M₂ : RankMatroid n) {I U : Finset (Fin n)} (h1 : M₁.IsIndep I) (h2 : M₂.IsIndep I) (heq : I.card = M₁.r U + M₂.r (Finset.univ \ U)) : (∀ J : Finset (Fin n), M₁.IsIndep J → M₂.IsIndep J → J.card ≤ I.card) ∧ (∀ V : Finset (Fin n), M₁.r U + M₂.r (Finset.univ \ U) ≤ M₁.r V + M₂.r (Finset.univ \ V)) := ⟨fun J hJ1 hJ2 => by rw [heq]; exact edmonds_matroid_intersection_weak_duality M₁ M₂ hJ1 hJ2 U, fun V => by rw [← heq]; exact edmonds_matroid_intersection_weak_duality M₁ M₂ h1 h2 V⟩ /-- Intersecting `M` with `truncateMatroid M k` attains `min (M.r Finset.univ) k`. -/ theorem truncateMatroid_rank_univ {n : ℕ} (M : RankMatroid n) (k : ℕ) : (truncateMatroid M k).r Finset.univ = min (M.r Finset.univ) k := rfl /-- Restriction of a matroid to `Finset.univ` recovers the original rank function identically. -/ theorem restrictMatroid_univ {n : ℕ} (M : RankMatroid n) (S : Finset (Fin n)) : (restrictMatroid M Finset.univ).r S = M.r S := by simp [restrictMatroid] /-- Restriction of a matroid to `∅` has identically zero rank. -/ theorem restrictMatroid_empty {n : ℕ} (M : RankMatroid n) (S : Finset (Fin n)) : (restrictMatroid M ∅).r S = 0 := by simp [restrictMatroid, M.r_empty] end NetworkFlowsMatchingSubmodularMinimax /-! =============================================================================== PART 6: AXIOM-CLEANLINESS TRANSPARENCY AUDIT (`#print axioms`) =============================================================================== -/ -- Pillar 1: Max-Flow Min-Cut, Ford–Fulkerson & Edmonds–Karp #print axioms NetworkFlowsMatchingSubmodularMinimax.flow_val_eq_cut_net #print axioms NetworkFlowsMatchingSubmodularMinimax.max_flow_le_min_cut #print axioms NetworkFlowsMatchingSubmodularMinimax.real_max_flow_le_min_cut #print axioms NetworkFlowsMatchingSubmodularMinimax.flow_sum_netFlow_zero #print axioms NetworkFlowsMatchingSubmodularMinimax.no_augmenting_path_implies_min_cut #print axioms NetworkFlowsMatchingSubmodularMinimax.reflTransGen_exists_nodup_path #print axioms NetworkFlowsMatchingSubmodularMinimax.augment_along_nodup_path #print axioms NetworkFlowsMatchingSubmodularMinimax.ford_fulkerson_max_flow_min_cut_integral #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_karp_distance_monotone #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_karp_critical_edge_jump_two #print axioms NetworkFlowsMatchingSubmodularMinimax.flowVal_eq_neg_sink_netFlow #print axioms NetworkFlowsMatchingSubmodularMinimax.max_flow_zero_if_no_out_edges #print axioms NetworkFlowsMatchingSubmodularMinimax.max_flow_zero_if_no_in_edges #print axioms NetworkFlowsMatchingSubmodularMinimax.ford_fulkerson_flowVal_nonneg #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_karp_walk_trans #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_karp_iterated_jump_two #print axioms NetworkFlowsMatchingSubmodularMinimax.flowNet_scale_valid #print axioms NetworkFlowsMatchingSubmodularMinimax.flowNet_single_arc_exact #print axioms NetworkFlowsMatchingSubmodularMinimax.flowNet_serial_chain_bottleneck -- Pillar 2: Menger, Hall, König–Egerváry & Birkhoff–von Neumann #print axioms NetworkFlowsMatchingSubmodularMinimax.unit_flow_path_decomposition #print axioms NetworkFlowsMatchingSubmodularMinimax.menger_edge_disjoint_minimax #print axioms NetworkFlowsMatchingSubmodularMinimax.menger_vertex_disjoint_minimax #print axioms NetworkFlowsMatchingSubmodularMinimax.halls_marriage_theorem #print axioms NetworkFlowsMatchingSubmodularMinimax.perfect_matching_implies_hall #print axioms NetworkFlowsMatchingSubmodularMinimax.halls_marriage_iff #print axioms NetworkFlowsMatchingSubmodularMinimax.konig_d_regular_bipartite_perfect_matching #print axioms NetworkFlowsMatchingSubmodularMinimax.konig_egervary_matching_vertex_cover #print axioms NetworkFlowsMatchingSubmodularMinimax.konig_egervary_weak_duality #print axioms NetworkFlowsMatchingSubmodularMinimax.weighted_assignment_duality_and_slackness #print axioms NetworkFlowsMatchingSubmodularMinimax.weighted_assignment_slackness_implies_opt #print axioms NetworkFlowsMatchingSubmodularMinimax.birkhoff_scaled_decomposition #print axioms NetworkFlowsMatchingSubmodularMinimax.birkhoff_von_neumann_theorem #print axioms NetworkFlowsMatchingSubmodularMinimax.birkhoff_extreme_point_iff_perm #print axioms NetworkFlowsMatchingSubmodularMinimax.permMatrix_is_birkhoff_extreme #print axioms NetworkFlowsMatchingSubmodularMinimax.doubly_stochastic_convex #print axioms NetworkFlowsMatchingSubmodularMinimax.doubly_stochastic_mul #print axioms NetworkFlowsMatchingSubmodularMinimax.birkhoff_linear_opt_attained_at_perm #print axioms NetworkFlowsMatchingSubmodularMinimax.birkhoff_2x2_explicit #print axioms NetworkFlowsMatchingSubmodularMinimax.path_hits_every_cut -- Pillar 3: Cut Submodularity, Gomory–Hu Cut Trees & Stoer–Wagner MAO #print axioms NetworkFlowsMatchingSubmodularMinimax.cutVal_compl #print axioms NetworkFlowsMatchingSubmodularMinimax.cutVal_submodular #print axioms NetworkFlowsMatchingSubmodularMinimax.cutVal_posimodular #print axioms NetworkFlowsMatchingSubmodularMinimax.min_cut_uncrossing #print axioms NetworkFlowsMatchingSubmodularMinimax.pairMinCut_spec #print axioms NetworkFlowsMatchingSubmodularMinimax.pairMinCut_symm #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_ultrametric #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_cut_tree_and_n_minus_one_distinct #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_at_most_n_minus_one_distinct_values #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_n_minus_one_tight_witness #print axioms NetworkFlowsMatchingSubmodularMinimax.stoer_wagner_mao_last_two_min_cut #print axioms NetworkFlowsMatchingSubmodularMinimax.stoer_wagner_global_min_cut_dichotomy #print axioms NetworkFlowsMatchingSubmodularMinimax.pairMinCut_le_min_degree #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_ultrametric_four #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_n1_zero_distinct #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_n2_at_most_one #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_n3_at_most_two #print axioms NetworkFlowsMatchingSubmodularMinimax.gomory_hu_path_n4_exact #print axioms NetworkFlowsMatchingSubmodularMinimax.cutVal_scale #print axioms NetworkFlowsMatchingSubmodularMinimax.cutVal_add -- Pillar 4: Submodular Maximization (NWF, BFNS) & Lovász Extension #print axioms NetworkFlowsMatchingSubmodularMinimax.submodular_iff_diminishing_returns #print axioms NetworkFlowsMatchingSubmodularMinimax.submodular_union_le_sum_marginals #print axioms NetworkFlowsMatchingSubmodularMinimax.one_sub_one_div_pow_le_inv_exp #print axioms NetworkFlowsMatchingSubmodularMinimax.nemhauser_wolsey_fisher_greedy_approx #print axioms NetworkFlowsMatchingSubmodularMinimax.nemhauser_wolsey_fisher_finite_k_tight #print axioms NetworkFlowsMatchingSubmodularMinimax.bfns_marginals_sum_nonneg #print axioms NetworkFlowsMatchingSubmodularMinimax.bfns_randomized_step_potential #print axioms NetworkFlowsMatchingSubmodularMinimax.bfns_double_greedy_half_approx #print axioms NetworkFlowsMatchingSubmodularMinimax.bfns_am_gm_half_factor #print axioms NetworkFlowsMatchingSubmodularMinimax.bfns_deterministic_double_greedy_third_approx #print axioms NetworkFlowsMatchingSubmodularMinimax.exists_antitone_perm #print axioms NetworkFlowsMatchingSubmodularMinimax.lovaszExtByPerm_abel_summation #print axioms NetworkFlowsMatchingSubmodularMinimax.lovaszExtByPerm_eq_of_antitone #print axioms NetworkFlowsMatchingSubmodularMinimax.lovaszExt_indicator #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_polymatroid_greedy_optimal #print axioms NetworkFlowsMatchingSubmodularMinimax.lovasz_extension_convex_iff_submodular #print axioms NetworkFlowsMatchingSubmodularMinimax.coverage_card_isMonotone_submodular #print axioms NetworkFlowsMatchingSubmodularMinimax.concave_card_isSubmodular #print axioms NetworkFlowsMatchingSubmodularMinimax.one_sub_inv_exp_sandwich #print axioms NetworkFlowsMatchingSubmodularMinimax.submodular_approx_hierarchy #print axioms NetworkFlowsMatchingSubmodularMinimax.lovaszExt_pos_homog #print axioms NetworkFlowsMatchingSubmodularMinimax.lovaszExt_shift_const #print axioms NetworkFlowsMatchingSubmodularMinimax.lovaszExt_modular_exact #print axioms NetworkFlowsMatchingSubmodularMinimax.lovaszExt_subadditive -- Pillar 5: Edmonds Polymatroids, Matroids & General Matroid Intersection Minimax #print axioms NetworkFlowsMatchingSubmodularMinimax.rado_edmonds_matroid_greedy_optimal #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_matroid_intersection_weak_duality #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_matroid_union_weak_duality #print axioms NetworkFlowsMatchingSubmodularMinimax.matroid_closure_peel #print axioms NetworkFlowsMatchingSubmodularMinimax.matroid_closure_mono #print axioms NetworkFlowsMatchingSubmodularMinimax.matroid_closure_union #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_matroid_intersection_strong_minimax #print axioms NetworkFlowsMatchingSubmodularMinimax.RankMatroid.exchange_property #print axioms NetworkFlowsMatchingSubmodularMinimax.RankMatroid.basis_card_eq_rank_univ #print axioms NetworkFlowsMatchingSubmodularMinimax.uniformMatroid_indep_iff #print axioms NetworkFlowsMatchingSubmodularMinimax.partitionMatroid_indep_iff #print axioms NetworkFlowsMatchingSubmodularMinimax.matroid_intersection_with_free #print axioms NetworkFlowsMatchingSubmodularMinimax.matroid_intersection_self #print axioms NetworkFlowsMatchingSubmodularMinimax.matroid_intersection_with_uniform #print axioms NetworkFlowsMatchingSubmodularMinimax.matroid_intersection_opt_certificate #print axioms NetworkFlowsMatchingSubmodularMinimax.edmonds_base_polytope_convex #print axioms NetworkFlowsMatchingSubmodularMinimax.network_flows_matching_submodular_grand_unification