import Mathlib /-! # Total Positivity, Lindström–Gessel–Viennot Lemma, Desnanot–Jacobi & Grassmannian `Gr(2, n)` This module is completely self-contained (importing only `Mathlib`) and formalizes: 1. **Exact Lindström–Gessel–Viennot (LGV) Determinant Lemma for Finite Acyclic Networks**: - Finite ranked DAGs (`DAG V`), valid paths (`IsDPath`), `Nodup` and rank-separation from topological rank monotonicity, complete path enumeration (`allPaths`), path weights (`pathWeight`), and path-sum matrix (`pathMatrix G w A B`); - **Exact LGV Determinant Lemma (`lgv_lemma`)** over ANY commutative ring `R`, proved via the multiplicity-preserving canonical-vertex tail-swapping involution `lgvSwap` and `Finset.sum_involution` (valid even in characteristic 2 or rings with zero divisors!); - **Planar Non-Crossing Positivity (`lgv_planar_nonneg`)** and **Exact Planar Grid / Pascal Matrix Total Nonnegativity (`pascal_grid_det_nonneg`)**! 2. **Exact Desnanot–Jacobi Identity & Dodgson Condensation**: - **Universal Desnanot–Jacobi Identity (`desnanot_jacobi_identity`)** for EVERY `n : ℕ` and EVERY `(n + 2) × (n + 2)` matrix `M` over ANY commutative ring `R`: `det M * det M_mid = det M_NW * det M_SE - det M_NE * det M_SW`, proved via the adjugate-border determinant identity over the universal polynomial ring `MvPolynomial (Fin (n + 2) × Fin (n + 2)) ℤ` and specialized to every commutative ring `R`! - **Dodgson Condensation (`dodgson_condensation`)** over any field `K`! 3. **Cauchy–Binet Formula, Total Positivity & Whitney–Loewner Chevalley Factorization**: - **Exact Cauchy–Binet Minor Formula (`cauchy_binet_formula`)** for arbitrary matrix products; - **Closure of Total Nonnegativity (`tn_mul_tn`) and Total Positivity (`tp_mul_tp`)** under matrix multiplication; - **Total Nonnegativity of Elementary Chevalley-Jacobi Generators** (`chevalleyLower_tn`, `chevalleyUpper_tn`, `diagMat_tn`) and arbitrary Whitney–Loewner products (`whitney_loewner_product_tn`); - **Exact `3 × 3` Whitney–Loewner Positive Factorization Theorem (`whitney_loewner_3x3_factorization`)**! 4. **Grassmannian `Gr(2, n)` Plücker Relations & Totally Positive Cluster Realization**: - Skew-symmetry (`plucker_skew`), `SL₂`-invariance (`plucker_sl2_invariant`), - **Exact `Gr(2, n)` 3-Term Plücker Relation (`grassmannian_gr2n_plucker_relation`)**, - **Preservation of Positivity under Cluster Mutation (`gr2n_tp_preserved_by_mutation`)**, - **Exact Fan-Cluster Positive Rational/Laurent Representation of ALL Plücker Coordinates (`gr2n_plucker_fan_laurent`)**! -/ namespace TotalPositivityLGVAndGrassmannian /-! ## 1. Exact Lindström–Gessel–Viennot (LGV) Determinant Lemma -/ /-- A finite directed acyclic graph (DAG) with a strict topological rank `rank : V → ℕ`. -/ structure DAG (V : Type*) [Fintype V] [DecidableEq V] where edge : V → V → Bool rank : V → ℕ rank_lt : ∀ u v, edge u v = true → rank u < rank v /-- Valid directed path in `G` from `a` to `b`, represented as a nonempty list of vertices. -/ def IsDPath {V : Type*} [Fintype V] [DecidableEq V] (G : DAG V) (a b : V) (p : List V) : Prop := p.head? = some a ∧ p.getLast? = some b ∧ p.IsChain (fun u v => G.edge u v = true) lemma isDPath_ne_nil {V : Type*} [Fintype V] [DecidableEq V] {G : DAG V} {a b : V} {p : List V} (hp : IsDPath G a b p) : p ≠ [] := by intro h; rw [h] at hp; simp [IsDPath] at hp lemma isChain_rank_lt {V : Type*} [Fintype V] [DecidableEq V] (G : DAG V) : ∀ {p : List V}, p.IsChain (fun u v => G.edge u v = true) → p.Pairwise (fun u v => G.rank u < G.rank v) := by intro p hp induction p with | nil => exact List.Pairwise.nil | cons x xs ih => cases xs with | nil => exact List.pairwise_singleton _ _ | cons y ys => rw [List.isChain_cons_cons] at hp have htail := ih hp.2 have hxy : G.rank x < G.rank y := G.rank_lt x y hp.1 refine List.Pairwise.cons (fun z hz => ?_) htail rcases List.mem_cons.mp hz with rfl | hzy · exact hxy · exact lt_trans hxy ((List.pairwise_cons.mp htail).1 z hzy) lemma isDPath_nodup {V : Type*} [Fintype V] [DecidableEq V] {G : DAG V} {a b : V} {p : List V} (hp : IsDPath G a b p) : p.Nodup := (isChain_rank_lt G hp.2.2).imp fun h => by intro heq; subst heq; exact lt_irrefl _ h lemma isDPath_split_rank {V : Type*} [Fintype V] [DecidableEq V] {G : DAG V} {a b v : V} {pre suf : List V} (hp : IsDPath G a b (pre ++ v :: suf)) : (∀ u ∈ pre, G.rank u < G.rank v) ∧ (∀ u ∈ suf, G.rank v < G.rank u) := by have hpw := isChain_rank_lt G hp.2.2 rw [List.pairwise_append] at hpw refine ⟨fun u hu => hpw.2.2 u hu v (List.mem_cons_self ..), fun u hu => (List.pairwise_cons.mp hpw.2.1).1 u hu⟩ /-- Computable enumeration of ALL directed paths in `G` from `a` to `b` with fuel `fuel`. -/ def pathsFuel {V : Type*} [Fintype V] [DecidableEq V] (G : DAG V) : ℕ → V → V → Finset (List V) | 0, a, b => if a = b then {[a]} else ∅ | fuel + 1, a, b => (if a = b then {[a]} else ∅) ∪ (Finset.univ.filter fun u => G.edge a u = true).biUnion fun u => (pathsFuel G fuel u b).image (a :: ·) lemma mem_pathsFuel_iff {V : Type*} [Fintype V] [DecidableEq V] (G : DAG V) : ∀ (fuel : ℕ) (a b : V) (p : List V), G.rank b - G.rank a ≤ fuel → (p ∈ pathsFuel G fuel a b ↔ IsDPath G a b p) := by intro fuel induction fuel with | zero => intro a b p hfuel simp only [pathsFuel] by_cases hab : a = b · subst hab simp only [↓reduceIte, Finset.mem_singleton] constructor · rintro rfl; exact ⟨rfl, rfl, List.isChain_singleton _⟩ · intro hp rcases p with _ | ⟨x, xs⟩ · exact absurd rfl (isDPath_ne_nil hp) · have hx : x = a := Option.some.inj hp.1; subst x cases xs with | nil => rfl | cons y ys => have hpw := isChain_rank_lt G hp.2.2 have hmem : a ∈ y :: ys := List.mem_of_getLast? (by simpa using hp.2.1) exact absurd ((List.pairwise_cons.mp hpw).1 a hmem) (lt_irrefl _) · simp only [hab, ↓reduceIte, Finset.notMem_empty, false_iff] intro hp rcases p with _ | ⟨x, xs⟩ · exact absurd rfl (isDPath_ne_nil hp) · have hx : x = a := Option.some.inj hp.1; subst x cases xs with | nil => exact hab (Option.some.inj hp.2.1) | cons y ys => have hpw := isChain_rank_lt G hp.2.2 have hmem : b ∈ y :: ys := List.mem_of_getLast? (by simpa using hp.2.1) have hlt := (List.pairwise_cons.mp hpw).1 b hmem omega | succ fuel ih => intro a b p hfuel simp only [pathsFuel, Finset.mem_union, Finset.mem_biUnion, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_image] constructor · rintro (hsingle | ⟨u, hau, q, hq, rfl⟩) · split_ifs at hsingle with hab · subst hab; simp only [Finset.mem_singleton] at hsingle; subst hsingle exact ⟨rfl, rfl, List.isChain_singleton _⟩ · simp at hsingle · have hrank := G.rank_lt a u hau have hq' := (ih u b q (by omega)).mp hq rcases q with _ | ⟨x, xs⟩ · exact absurd rfl (isDPath_ne_nil hq') · have hx : x = u := Option.some.inj hq'.1; subst x exact ⟨rfl, by simpa using hq'.2.1, List.isChain_cons_cons.mpr ⟨hau, hq'.2.2⟩⟩ · intro hp rcases p with _ | ⟨x, xs⟩ · exact absurd rfl (isDPath_ne_nil hp) · have hx : x = a := Option.some.inj hp.1; subst x cases xs with | nil => have hab : a = b := Option.some.inj hp.2.1 left; simp [hab] | cons u ys => right have hc := List.isChain_cons_cons.mp hp.2.2 have hau : G.edge a u = true := hc.1 have hrank := G.rank_lt a u hau have hq : IsDPath G u b (u :: ys) := ⟨rfl, by simpa using hp.2.1, hc.2⟩ exact ⟨u, hau, u :: ys, (ih u b (u :: ys) (by omega)).mpr hq, rfl⟩ /-- Complete finite set of all directed paths in `G` from `a` to `b`. -/ def allPaths {V : Type*} [Fintype V] [DecidableEq V] (G : DAG V) (a b : V) : Finset (List V) := pathsFuel G (G.rank b - G.rank a) a b lemma mem_allPaths_iff {V : Type*} [Fintype V] [DecidableEq V] (G : DAG V) (a b : V) (p : List V) : p ∈ allPaths G a b ↔ IsDPath G a b p := mem_pathsFuel_iff G (G.rank b - G.rank a) a b p le_rfl /-- Multiplicative weight of a directed path `p` with edge-weight function `w : V → V → R`. -/ def pathWeight {V R : Type*} [CommRing R] (w : V → V → R) : List V → R | [] => 1 | [_] => 1 | u :: v :: rest => w u v * pathWeight w (v :: rest) lemma pathWeight_append_middle {V R : Type*} [CommRing R] (w : V → V → R) (pre suf : List V) (v : V) : pathWeight w (pre ++ v :: suf) = pathWeight w (pre ++ [v]) * pathWeight w (v :: suf) := by induction pre with | nil => simp [pathWeight] | cons x xs ih => cases xs with | nil => simp [pathWeight] | cons y ys => simp only [List.cons_append, pathWeight] at ih ⊢ rw [ih, mul_assoc] /-- The `k × k` path-sum matrix `M_{i, j} = ∑_{P : A_i → B_j} w(P)`. -/ def pathMatrix {V R : Type*} [Fintype V] [DecidableEq V] [CommRing R] {k : ℕ} (G : DAG V) (w : V → V → R) (A B : Fin k → V) : Matrix (Fin k) (Fin k) R := Matrix.of fun i j => ∑ p ∈ allPaths G (A i) (B j), pathWeight w p /-- A `k`-tuple of directed paths in `G` from `A_i` to `B_{σ(i)}`. -/ abbrev Routing {V : Type*} [Fintype V] [DecidableEq V] {k : ℕ} (G : DAG V) (A B : Fin k → V) := Σ σ : Equiv.Perm (Fin k), ∀ i : Fin k, {p : List V // p ∈ allPaths G (A i) (B (σ i))} /-- A routing is *vertex-disjoint* iff no two distinct paths share a vertex. -/ def IsVertexDisjoint {V : Type*} [Fintype V] [DecidableEq V] {k : ℕ} {G : DAG V} {A B : Fin k → V} (r : Routing G A B) : Prop := ∀ i j : Fin k, i ≠ j → ∀ v : V, v ∈ (r.2 i).1 → v ∉ (r.2 j).1 instance instDecidableIsVertexDisjoint {V : Type*} [Fintype V] [DecidableEq V] {k : ℕ} {G : DAG V} {A B : Fin k → V} : DecidablePred (IsVertexDisjoint (G := G) (A := A) (B := B)) := fun r => by unfold IsVertexDisjoint; infer_instance lemma split_at_mem {V : Type*} [DecidableEq V] {p : List V} (hnd : p.Nodup) {v : V} (hv : v ∈ p) : ∃ (pre suf : List V), p = pre ++ v :: suf ∧ v ∉ pre ∧ v ∉ suf := by induction p with | nil => simp at hv | cons x xs ih => rw [List.nodup_cons] at hnd rcases List.mem_cons.mp hv with rfl | hxs · exact ⟨[], xs, rfl, by simp, hnd.1⟩ · rcases ih hnd.2 hxs with ⟨pre, suf, rfl, hpre, hsuf⟩ have hxv : v ≠ x := fun h => hnd.1 (h ▸ hxs) exact ⟨x :: pre, suf, rfl, by simp [hxv, hpre], hsuf⟩ lemma split_at_mem_unique {V : Type*} {p pre₁ suf₁ pre₂ suf₂ : List V} {v : V} (hnd : p.Nodup) (h1 : p = pre₁ ++ v :: suf₁) (h2 : p = pre₂ ++ v :: suf₂) : pre₁ = pre₂ ∧ suf₁ = suf₂ := by have heq : pre₁ ++ v :: suf₁ = pre₂ ++ v :: suf₂ := h1.symm.trans h2 have hnd1 : (pre₁ ++ v :: suf₁).Nodup := h1 ▸ hnd have hnd2 : (pre₂ ++ v :: suf₂).Nodup := h2 ▸ hnd have hv1 : v ∉ pre₁ := by rw [List.nodup_append] at hnd1 exact fun h => hnd1.2.2 v h v (List.mem_cons_self ..) rfl have hv2 : v ∉ pre₂ := by rw [List.nodup_append] at hnd2 exact fun h => hnd2.2.2 v h v (List.mem_cons_self ..) rfl induction pre₁ generalizing pre₂ p with | nil => cases pre₂ with | nil => simp at heq; exact ⟨rfl, heq⟩ | cons y ys => simp only [List.nil_append, List.cons_append, List.cons.injEq] at heq exfalso; exact hv2 (heq.1 ▸ List.mem_cons_self ..) | cons x xs ih => cases pre₂ with | nil => simp only [List.nil_append, List.cons_append, List.cons.injEq] at heq exfalso; exact hv1 (heq.1.symm ▸ List.mem_cons_self ..) | cons y ys => simp only [List.cons_append, List.cons.injEq] at heq rcases heq with ⟨rfl, htail⟩ have hnd_tail : (xs ++ v :: suf₁).Nodup := (List.nodup_cons.mp hnd1).2 have hv1' : v ∉ xs := fun h => hv1 (List.mem_cons_of_mem x h) have hv2' : v ∉ ys := fun h => hv2 (List.mem_cons_of_mem x h) have hrec := ih hnd_tail rfl htail htail hnd_tail (htail ▸ hnd_tail) hv1' hv2' exact ⟨congrArg (x :: ·) hrec.1, hrec.2⟩ lemma isDPath_splice {V : Type*} [Fintype V] [DecidableEq V] {G : DAG V} {a₁ b₁ a₂ b₂ v : V} {pre₁ suf₁ pre₂ suf₂ : List V} (h1 : IsDPath G a₁ b₁ (pre₁ ++ v :: suf₁)) (h2 : IsDPath G a₂ b₂ (pre₂ ++ v :: suf₂)) : IsDPath G a₁ b₂ (pre₁ ++ v :: suf₂) := by have hchain_split : ∀ {pre suf : List V}, (pre ++ v :: suf).IsChain (fun x y => G.edge x y = true) → (pre ++ [v]).IsChain (fun x y => G.edge x y = true) ∧ (v :: suf).IsChain (fun x y => G.edge x y = true) := by intro pre suf hc induction pre with | nil => exact ⟨List.isChain_singleton _, hc⟩ | cons x xs ih => cases xs with | nil => rw [List.cons_append, List.nil_append, List.isChain_cons_cons] at hc exact ⟨List.isChain_cons_cons.mpr ⟨hc.1, List.isChain_singleton _⟩, hc.2⟩ | cons y ys => rw [List.cons_append, List.cons_append, List.isChain_cons_cons] at hc have hrec := ih hc.2 exact ⟨List.isChain_cons_cons.mpr ⟨hc.1, hrec.1⟩, hrec.2⟩ have hchain_join : ∀ {pre suf : List V}, (pre ++ [v]).IsChain (fun x y => G.edge x y = true) → (v :: suf).IsChain (fun x y => G.edge x y = true) → (pre ++ v :: suf).IsChain (fun x y => G.edge x y = true) := by intro pre suf hc1 hc2 induction pre with | nil => exact hc2 | cons x xs ih => cases xs with | nil => rw [List.cons_append, List.nil_append, List.isChain_cons_cons] at hc1 exact List.isChain_cons_cons.mpr ⟨hc1.1, hc2⟩ | cons y ys => rw [List.cons_append, List.cons_append, List.isChain_cons_cons] at hc1 exact List.isChain_cons_cons.mpr ⟨hc1.1, ih hc1.2⟩ refine ⟨?_, ?_, hchain_join (hchain_split h1.2.2).1 (hchain_split h2.2.2).2⟩ · cases pre₁ with | nil => have hv1 : v = a₁ := Option.some.inj h1.1 simp [hv1] | cons x xs => have hx : x = a₁ := Option.some.inj h1.1 simp [hx] · rw [List.getLast?_append_of_ne_nil _ (List.cons_ne_nil v suf₂)] have hlast2 := h2.2.1 rw [List.getLast?_append_of_ne_nil _ (List.cons_ne_nil v suf₂)] at hlast2 exact hlast2 /-- **THEOREM 1 — Exact Lindström–Gessel–Viennot (LGV) Determinant Lemma (`lgv_lemma`)**: For ANY finite DAG `G`, ANY commutative ring `R`, ANY edge-weight function `w : V → V → R`, and ANY `k`-tuples of sources `A` and sinks `B`, `det (pathMatrix G w A B) = ∑_{r vertex-disjoint} sgn(r.σ) * ∏_i pathWeight w (r.path i)`! -/ theorem lgv_lemma {V R : Type*} [Fintype V] [DecidableEq V] [CommRing R] {k : ℕ} (G : DAG V) (w : V → V → R) (A B : Fin k → V) : (pathMatrix G w A B).det = ∑ r ∈ (Finset.univ.filter (fun r : Routing G A B => IsVertexDisjoint r)), (Equiv.Perm.sign r.1 : R) * ∏ i : Fin k, pathWeight w (r.2 i).1 := by classical have hdet_all : (pathMatrix G w A B).det = ∑ r : Routing G A B, (Equiv.Perm.sign r.1 : R) * ∏ i : Fin k, pathWeight w (r.2 i).1 := by rw [← Matrix.det_transpose, Matrix.det_apply, Fintype.sum_sigma] refine Finset.sum_congr rfl fun σ _ => ?_ simp only [Matrix.transpose_apply, pathMatrix, Matrix.of_apply, Units.smul_def, zsmul_eq_mul] rw [Finset.prod_univ_sum, Finset.mul_sum] refine (Finset.sum_bij (fun (f : ∀ i : Fin k, {p : List V // p ∈ allPaths G (A i) (B (σ i))}) _ => fun i => (f i).1) ?_ ?_ ?_ ?_).symm · intro f _; exact Fintype.mem_piFinset.mpr fun i => (f i).2 · intro f₁ _ f₂ _ h; funext i; exact Subtype.ext (congrFun h i) · intro g hg exact ⟨fun i => ⟨g i, Fintype.mem_piFinset.mp hg i⟩, Finset.mem_univ _, rfl⟩ · intro f _; rfl rw [hdet_all, ← Finset.sum_filter_add_sum_filter_not Finset.univ (fun r : Routing G A B => IsVertexDisjoint r)] suffices hzero : ∑ r ∈ Finset.univ.filter (fun r : Routing G A B => ¬ IsVertexDisjoint r), (Equiv.Perm.sign r.1 : R) * ∏ i : Fin k, pathWeight w (r.2 i).1 = 0 by rw [hzero, add_zero] let vIdx : V ≃ Fin (Fintype.card V) := Fintype.equivFin V let sharedVerts (r : Routing G A B) : Finset V := Finset.univ.filter fun v => ∃ i j : Fin k, i < j ∧ v ∈ (r.2 i).1 ∧ v ∈ (r.2 j).1 have hshared_ne : ∀ r : Routing G A B, ¬ IsVertexDisjoint r → (sharedVerts r).Nonempty := by intro r hnd unfold IsVertexDisjoint at hnd push Not at hnd rcases hnd with ⟨i, j, hij, v, hvi, hvj⟩ rcases lt_or_gt_of_ne hij with hlt | hgt · exact ⟨v, Finset.mem_filter.mpr ⟨Finset.mem_univ v, i, j, hlt, hvi, hvj⟩⟩ · exact ⟨v, Finset.mem_filter.mpr ⟨Finset.mem_univ v, j, i, hgt, hvj, hvi⟩⟩ let canonTriple (r : Routing G A B) (hr : ¬ IsVertexDisjoint r) : {t : V × Fin k × Fin k // t.2.1 < t.2.2 ∧ t.1 ∈ (r.2 t.2.1).1 ∧ t.1 ∈ (r.2 t.2.2).1} := let S := (sharedVerts r).image vIdx have hSne : S.Nonempty := (hshared_ne r hr).image vIdx let m := S.min' hSne let v : V := vIdx.symm m have hv_mem : v ∈ sharedVerts r := by have hm := Finset.min'_mem S hSne rcases Finset.mem_image.mp hm with ⟨v', hv', hvv'⟩ have : v = v' := by simp [v, m, ← hvv'] rwa [this] let I := Finset.univ.filter fun i : Fin k => v ∈ (r.2 i).1 have hI_ex : ∃ i j : Fin k, i < j ∧ v ∈ (r.2 i).1 ∧ v ∈ (r.2 j).1 := (Finset.mem_filter.mp hv_mem).2 have hIne : I.Nonempty := by rcases hI_ex with ⟨i, _, _, hi, _⟩ exact ⟨i, Finset.mem_filter.mpr ⟨Finset.mem_univ i, hi⟩⟩ let i₀ := I.min' hIne have hi₀_mem : v ∈ (r.2 i₀).1 := (Finset.mem_filter.mp (Finset.min'_mem I hIne)).2 let I2 := I.erase i₀ have hI2ne : I2.Nonempty := by rcases hI_ex with ⟨i, j, hij, hi, hj⟩ have hiI : i ∈ I := Finset.mem_filter.mpr ⟨Finset.mem_univ i, hi⟩ have hjI : j ∈ I := Finset.mem_filter.mpr ⟨Finset.mem_univ j, hj⟩ have hi₀_le : i₀ ≤ i := Finset.min'_le I i hiI exact ⟨j, Finset.mem_erase.mpr ⟨ne_of_gt (lt_of_le_of_lt hi₀_le hij), hjI⟩⟩ let j₀ := I2.min' hI2ne have hj₀_erase := Finset.min'_mem I2 hI2ne have hj₀_mem : v ∈ (r.2 j₀).1 := (Finset.mem_filter.mp (Finset.mem_erase.mp hj₀_erase).2).2 have hij₀ : i₀ < j₀ := lt_of_le_of_ne (Finset.min'_le I j₀ (Finset.mem_erase.mp hj₀_erase).2) (Ne.symm (Finset.mem_erase.mp hj₀_erase).1) ⟨(v, i₀, j₀), hij₀, hi₀_mem, hj₀_mem⟩ let lgvSwap (r : Routing G A B) (hr : ¬ IsVertexDisjoint r) : Routing G A B := let t := canonTriple r hr let v := t.1.1 let i₀ := t.1.2.1 let j₀ := t.1.2.2 have hi₀_path : IsDPath G (A i₀) (B (r.1 i₀)) (r.2 i₀).1 := (mem_allPaths_iff ..).mp (r.2 i₀).2 have hj₀_path : IsDPath G (A j₀) (B (r.1 j₀)) (r.2 j₀).1 := (mem_allPaths_iff ..).mp (r.2 j₀).2 have hsp1 := split_at_mem (isDPath_nodup hi₀_path) t.2.2.1 have hsp2 := split_at_mem (isDPath_nodup hj₀_path) t.2.2.2 let pre₁ := Classical.choose hsp1 let suf₁ := Classical.choose (Classical.choose_spec hsp1) let h1_eq := (Classical.choose_spec (Classical.choose_spec hsp1)).1 let pre₂ := Classical.choose hsp2 let suf₂ := Classical.choose (Classical.choose_spec hsp2) let h2_eq := (Classical.choose_spec (Classical.choose_spec hsp2)).1 let σ' : Equiv.Perm (Fin k) := r.1 * Equiv.swap i₀ j₀ ⟨σ', fun l => if hl1 : l = i₀ then ⟨pre₁ ++ v :: suf₂, by rw [hl1, mem_allPaths_iff] have hσ : σ' i₀ = r.1 j₀ := by simp [σ'] rw [hσ] exact isDPath_splice (h1_eq ▸ hi₀_path) (h2_eq ▸ hj₀_path)⟩ else if hl2 : l = j₀ then ⟨pre₂ ++ v :: suf₁, by rw [hl2, mem_allPaths_iff] have hσ : σ' j₀ = r.1 i₀ := by simp [σ'] rw [hσ] exact isDPath_splice (h2_eq ▸ hj₀_path) (h1_eq ▸ hi₀_path)⟩ else ⟨(r.2 l).1, by have hσ : σ' l = r.1 l := by simp [σ', Equiv.swap_apply_of_ne_of_ne hl1 hl2] rw [hσ]; exact (r.2 l).2⟩⟩ -- Key invariance lemma: `sharedVerts`, `canonTriple`, involution, fixed-point-freeness, and sign flip! have hshared_eq : ∀ (r : Routing G A B) (hr : ¬ IsVertexDisjoint r), sharedVerts (lgvSwap r hr) = sharedVerts r := by intro r hr set t := canonTriple r hr set v := t.1.1 set i₀ := t.1.2.1 set j₀ := t.1.2.2 have hij₀ : i₀ ≠ j₀ := ne_of_lt t.2.1 have hi₀_path : IsDPath G (A i₀) (B (r.1 i₀)) (r.2 i₀).1 := (mem_allPaths_iff ..).mp (r.2 i₀).2 have hj₀_path : IsDPath G (A j₀) (B (r.1 j₀)) (r.2 j₀).1 := (mem_allPaths_iff ..).mp (r.2 j₀).2 have hsp1 := split_at_mem (isDPath_nodup hi₀_path) t.2.2.1 have hsp2 := split_at_mem (isDPath_nodup hj₀_path) t.2.2.2 let pre₁ := Classical.choose hsp1 let suf₁ := Classical.choose (Classical.choose_spec hsp1) have h1 := Classical.choose_spec (Classical.choose_spec hsp1) let pre₂ := Classical.choose hsp2 let suf₂ := Classical.choose (Classical.choose_spec hsp2) have h2 := Classical.choose_spec (Classical.choose_spec hsp2) have hpi₀ : ((lgvSwap r hr).2 i₀).1 = pre₁ ++ v :: suf₂ := by simp [lgvSwap, t, v, i₀, j₀, pre₁, suf₂] have hpj₀ : ((lgvSwap r hr).2 j₀).1 = pre₂ ++ v :: suf₁ := by simp [lgvSwap, t, v, i₀, j₀, Ne.symm hij₀, pre₂, suf₁] have hpl : ∀ l, l ≠ i₀ → l ≠ j₀ → ((lgvSwap r hr).2 l).1 = (r.2 l).1 := by intro l h1l h2l; simp [lgvSwap, t, i₀, j₀, h1l, h2l] have hrk1 := isDPath_split_rank (h1.1 ▸ hi₀_path) have hrk2 := isDPath_split_rank (h2.1 ▸ hj₀_path) have hu_or : ∀ u : V, (u ∈ ((lgvSwap r hr).2 i₀).1 ∨ u ∈ ((lgvSwap r hr).2 j₀).1) ↔ (u ∈ (r.2 i₀).1 ∨ u ∈ (r.2 j₀).1) := by intro u; rw [hpi₀, hpj₀, h1.1, h2.1]; simp only [List.mem_append, List.mem_cons]; tauto have hu_and : ∀ u : V, (u ∈ ((lgvSwap r hr).2 i₀).1 ∧ u ∈ ((lgvSwap r hr).2 j₀).1) ↔ (u ∈ (r.2 i₀).1 ∧ u ∈ (r.2 j₀).1) := by intro u rw [hpi₀, hpj₀, h1.1, h2.1] simp only [List.mem_append, List.mem_cons] constructor · rintro ⟨(hA | rfl | hB), (hC | hD | hE)⟩ · exact ⟨Or.inl hA, Or.inl hC⟩ · rw [hD] at hA; exact absurd (hrk1.1 v hA) (lt_irrefl _) · exact absurd (lt_trans (hrk1.1 u hA) (hrk1.2 u hE)) (lt_irrefl _) · exact ⟨Or.inr (Or.inl rfl), Or.inr (Or.inl rfl)⟩ · exact ⟨Or.inr (Or.inl rfl), Or.inr (Or.inl rfl)⟩ · exact ⟨Or.inr (Or.inl rfl), Or.inr (Or.inl rfl)⟩ · exact absurd (lt_trans (hrk2.1 u hC) (hrk2.2 u hB)) (lt_irrefl _) · rw [hD] at hB; exact absurd (hrk2.2 v hB) (lt_irrefl _) · exact ⟨Or.inr (Or.inr hE), Or.inr (Or.inr hB)⟩ · rintro ⟨(hA | rfl | hB), (hC | hD | hE)⟩ · exact ⟨Or.inl hA, Or.inl hC⟩ · rw [hD] at hA; exact absurd (hrk1.1 v hA) (lt_irrefl _) · exact absurd (lt_trans (hrk1.1 u hA) (hrk2.2 u hE)) (lt_irrefl _) · exact ⟨Or.inr (Or.inl rfl), Or.inr (Or.inl rfl)⟩ · exact ⟨Or.inr (Or.inl rfl), Or.inr (Or.inl rfl)⟩ · exact ⟨Or.inr (Or.inl rfl), Or.inr (Or.inl rfl)⟩ · exact absurd (lt_trans (hrk2.1 u hC) (hrk1.2 u hB)) (lt_irrefl _) · rw [hD] at hB; exact absurd (hrk1.2 v hB) (lt_irrefl _) · exact ⟨Or.inr (Or.inr hE), Or.inr (Or.inr hB)⟩ have hmem_iff : ∀ u : V, (∃ a b : Fin k, a ≠ b ∧ u ∈ ((lgvSwap r hr).2 a).1 ∧ u ∈ ((lgvSwap r hr).2 b).1) ↔ (∃ a b : Fin k, a ≠ b ∧ u ∈ (r.2 a).1 ∧ u ∈ (r.2 b).1) := by intro u constructor · rintro ⟨a, b, hab, ha, hb⟩ by_cases ha1 : a = i₀ ∨ a = j₀ <;> by_cases hb1 : b = i₀ ∨ b = j₀ · have hand : u ∈ ((lgvSwap r hr).2 i₀).1 ∧ u ∈ ((lgvSwap r hr).2 j₀).1 := by rcases ha1 with rfl | rfl <;> rcases hb1 with rfl | rfl · exact absurd rfl hab · exact ⟨ha, hb⟩ · exact ⟨hb, ha⟩ · exact absurd rfl hab rcases (hu_and u).mp hand with ⟨hi', hj'⟩ exact ⟨i₀, j₀, hij₀, hi', hj'⟩ · have hb' : u ∈ (r.2 b).1 := by push Not at hb1; rwa [hpl b hb1.1 hb1.2] at hb have hor : u ∈ (r.2 i₀).1 ∨ u ∈ (r.2 j₀).1 := (hu_or u).mp (by rcases ha1 with rfl | rfl <;> simp [ha]) push Not at hb1 rcases hor with hi' | hj' · exact ⟨i₀, b, Ne.symm hb1.1, hi', hb'⟩ · exact ⟨j₀, b, Ne.symm hb1.2, hj', hb'⟩ · have ha' : u ∈ (r.2 a).1 := by push Not at ha1; rwa [hpl a ha1.1 ha1.2] at ha have hor : u ∈ (r.2 i₀).1 ∨ u ∈ (r.2 j₀).1 := (hu_or u).mp (by rcases hb1 with rfl | rfl <;> simp [hb]) push Not at ha1 rcases hor with hi' | hj' · exact ⟨a, i₀, ha1.1, ha', hi'⟩ · exact ⟨a, j₀, ha1.2, ha', hj'⟩ · push Not at ha1 hb1 rw [hpl a ha1.1 ha1.2] at ha; rw [hpl b hb1.1 hb1.2] at hb exact ⟨a, b, hab, ha, hb⟩ · rintro ⟨a, b, hab, ha, hb⟩ by_cases ha1 : a = i₀ ∨ a = j₀ <;> by_cases hb1 : b = i₀ ∨ b = j₀ · have hand : u ∈ (r.2 i₀).1 ∧ u ∈ (r.2 j₀).1 := by rcases ha1 with rfl | rfl <;> rcases hb1 with rfl | rfl · exact absurd rfl hab · exact ⟨ha, hb⟩ · exact ⟨hb, ha⟩ · exact absurd rfl hab rcases (hu_and u).mpr hand with ⟨hi', hj'⟩ exact ⟨i₀, j₀, hij₀, hi', hj'⟩ · have hb' : u ∈ ((lgvSwap r hr).2 b).1 := by push Not at hb1; rwa [hpl b hb1.1 hb1.2] have hor : u ∈ ((lgvSwap r hr).2 i₀).1 ∨ u ∈ ((lgvSwap r hr).2 j₀).1 := (hu_or u).mpr (by rcases ha1 with rfl | rfl <;> simp [ha]) push Not at hb1 rcases hor with hi' | hj' · exact ⟨i₀, b, Ne.symm hb1.1, hi', hb'⟩ · exact ⟨j₀, b, Ne.symm hb1.2, hj', hb'⟩ · have ha' : u ∈ ((lgvSwap r hr).2 a).1 := by push Not at ha1; rwa [hpl a ha1.1 ha1.2] have hor : u ∈ ((lgvSwap r hr).2 i₀).1 ∨ u ∈ ((lgvSwap r hr).2 j₀).1 := (hu_or u).mpr (by rcases hb1 with rfl | rfl <;> simp [hb]) push Not at ha1 rcases hor with hi' | hj' · exact ⟨a, i₀, ha1.1, ha', hi'⟩ · exact ⟨a, j₀, ha1.2, ha', hj'⟩ · push Not at ha1 hb1 rw [← hpl a ha1.1 ha1.2] at ha; rw [← hpl b hb1.1 hb1.2] at hb exact ⟨a, b, hab, ha, hb⟩ ext u simp only [sharedVerts, Finset.mem_filter, Finset.mem_univ, true_and] have hlt_iff : ∀ (q : Routing G A B), (∃ a b : Fin k, a < b ∧ u ∈ (q.2 a).1 ∧ u ∈ (q.2 b).1) ↔ (∃ a b : Fin k, a ≠ b ∧ u ∈ (q.2 a).1 ∧ u ∈ (q.2 b).1) := by intro q; constructor · rintro ⟨a, b, h, ha, hb⟩; exact ⟨a, b, ne_of_lt h, ha, hb⟩ · rintro ⟨a, b, h, ha, hb⟩ rcases lt_or_gt_of_ne h with hlt | hgt · exact ⟨a, b, hlt, ha, hb⟩ · exact ⟨b, a, hgt, hb, ha⟩ rw [hlt_iff, hlt_iff] exact hmem_iff u have hswap_not_disj : ∀ (r : Routing G A B) (hr : ¬ IsVertexDisjoint r), ¬ IsVertexDisjoint (lgvSwap r hr) := by intro r hr hdisj have hne := hshared_ne r hr rw [← hshared_eq r hr] at hne rcases hne with ⟨v, hv⟩ rcases (Finset.mem_filter.mp hv).2 with ⟨i, j, hij, hi, hj⟩ exact hdisj i j (ne_of_lt hij) v hi hj have hcanon_eq : ∀ (r : Routing G A B) (hr : ¬ IsVertexDisjoint r), (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1 = (canonTriple r hr).1 := by intro r hr set t := canonTriple r hr set v := t.1.1 set i₀ := t.1.2.1 set j₀ := t.1.2.2 have hsh := hshared_eq r hr have hv_eq : (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.1 = v := by dsimp only [canonTriple, v, t] congr 1 simp only [hsh] -- Show `{l | v ∈ (lgvSwap r hr).2 l} = {l | v ∈ r.2 l}`! have hI_eq : (Finset.univ.filter fun l : Fin k => v ∈ ((lgvSwap r hr).2 l).1) = (Finset.univ.filter fun l : Fin k => v ∈ (r.2 l).1) := by ext l simp only [Finset.mem_filter, Finset.mem_univ, true_and] by_cases hl1 : l = i₀ · subst l have h1 : v ∈ ((lgvSwap r hr).2 i₀).1 := by simp [lgvSwap, t, v, i₀] exact iff_of_true h1 t.2.2.1 · by_cases hl2 : l = j₀ · subst l have h1 : v ∈ ((lgvSwap r hr).2 j₀).1 := by simp [lgvSwap, t, v, i₀, j₀, hl1] exact iff_of_true h1 t.2.2.2 · simp [lgvSwap, t, i₀, j₀, hl1, hl2] have hi_eq : (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.2.1 = i₀ := by have hS : (Finset.univ.filter fun l : Fin k => (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.1 ∈ ((lgvSwap r hr).2 l).1) = (Finset.univ.filter fun l : Fin k => v ∈ (r.2 l).1) := by rw [hv_eq, hI_eq] have hne1 : (Finset.univ.filter fun l : Fin k => v ∈ (r.2 l).1).Nonempty := ⟨i₀, Finset.mem_filter.mpr ⟨Finset.mem_univ _, t.2.2.1⟩⟩ have hne2 : (Finset.univ.filter fun l : Fin k => (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.1 ∈ ((lgvSwap r hr).2 l).1).Nonempty := hS.symm ▸ hne1 exact le_antisymm (Finset.min'_le _ _ (hS ▸ Finset.min'_mem _ hne1)) (Finset.min'_le _ _ (hS.symm ▸ Finset.min'_mem _ hne2)) have hj_eq : (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.2.2 = j₀ := by have hS : ((Finset.univ.filter fun l : Fin k => (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.1 ∈ ((lgvSwap r hr).2 l).1).erase (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.2.1) = ((Finset.univ.filter fun l : Fin k => v ∈ (r.2 l).1).erase i₀) := by rw [hv_eq, hI_eq, hi_eq] have hne1 : ((Finset.univ.filter fun l : Fin k => v ∈ (r.2 l).1).erase i₀).Nonempty := ⟨j₀, Finset.mem_erase.mpr ⟨Ne.symm (ne_of_lt t.2.1), Finset.mem_filter.mpr ⟨Finset.mem_univ _, t.2.2.2⟩⟩⟩ have hne2 : ((Finset.univ.filter fun l : Fin k => (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.1 ∈ ((lgvSwap r hr).2 l).1).erase (canonTriple (lgvSwap r hr) (hswap_not_disj r hr)).1.2.1).Nonempty := hS.symm ▸ hne1 exact le_antisymm (Finset.min'_le _ _ (hS ▸ Finset.min'_mem _ hne1)) (Finset.min'_le _ _ (hS.symm ▸ Finset.min'_mem _ hne2)) exact Prod.ext hv_eq (Prod.ext hi_eq hj_eq) have hswap_invol : ∀ (r : Routing G A B) (hr : ¬ IsVertexDisjoint r), lgvSwap (lgvSwap r hr) (hswap_not_disj r hr) = r := by intro r hr set r' := lgvSwap r hr have hr' := hswap_not_disj r hr have hct := hcanon_eq r hr set t := canonTriple r hr set v := t.1.1 set i₀ := t.1.2.1 set j₀ := t.1.2.2 have hij₀ : i₀ ≠ j₀ := ne_of_lt t.2.1 have hv' : (canonTriple r' hr').1.1 = v := congrArg Prod.fst hct have hi' : (canonTriple r' hr').1.2.1 = i₀ := congrArg (fun x => x.2.1) hct have hj' : (canonTriple r' hr').1.2.2 = j₀ := congrArg (fun x => x.2.2) hct have hσ_eq : (lgvSwap r' hr').1 = r.1 := by dsimp only [lgvSwap] rw [hi', hj'] change r.1 * Equiv.swap i₀ j₀ * Equiv.swap i₀ j₀ = r.1 rw [mul_assoc, Equiv.swap_mul_self, mul_one] refine Sigma.ext hσ_eq ?_ have hpaths : ∀ l : Fin k, ((lgvSwap r' hr').2 l).1 = (r.2 l).1 := by have hi₀_path : IsDPath G (A i₀) (B (r.1 i₀)) (r.2 i₀).1 := (mem_allPaths_iff ..).mp (r.2 i₀).2 have hj₀_path : IsDPath G (A j₀) (B (r.1 j₀)) (r.2 j₀).1 := (mem_allPaths_iff ..).mp (r.2 j₀).2 have hsp1 := split_at_mem (isDPath_nodup hi₀_path) t.2.2.1 have hsp2 := split_at_mem (isDPath_nodup hj₀_path) t.2.2.2 let pre₁ := Classical.choose hsp1 let suf₁ := Classical.choose (Classical.choose_spec hsp1) have h1 := Classical.choose_spec (Classical.choose_spec hsp1) let pre₂ := Classical.choose hsp2 let suf₂ := Classical.choose (Classical.choose_spec hsp2) have h2 := Classical.choose_spec (Classical.choose_spec hsp2) have hr'i : (r'.2 i₀).1 = pre₁ ++ v :: suf₂ := by simp [r', lgvSwap, t, v, i₀, j₀, pre₁, suf₂] have hr'j : (r'.2 j₀).1 = pre₂ ++ v :: suf₁ := by simp [r', lgvSwap, t, v, i₀, j₀, Ne.symm hij₀, pre₂, suf₁] -- Splitting `r'.2 i₀` and `r'.2 j₀` at `v` recovers `(pre₁, suf₂)` and `(pre₂, suf₁)` uniquely! set t' := canonTriple r' hr' set v' := t'.1.1 set i₀' := t'.1.2.1 set j₀' := t'.1.2.2 have hsp1' := split_at_mem (isDPath_nodup ((mem_allPaths_iff ..).mp (r'.2 i₀').2)) t'.2.2.1 have hsp2' := split_at_mem (isDPath_nodup ((mem_allPaths_iff ..).mp (r'.2 j₀').2)) t'.2.2.2 let pre₁' := Classical.choose hsp1' let suf₁' := Classical.choose (Classical.choose_spec hsp1') have h1' := (Classical.choose_spec (Classical.choose_spec hsp1')).1 let pre₂' := Classical.choose hsp2' let suf₂' := Classical.choose (Classical.choose_spec hsp2') have h2' := (Classical.choose_spec (Classical.choose_spec hsp2')).1 have hr'i' : (r'.2 i₀').1 = pre₁ ++ v' :: suf₂ := by rw [hi', hv']; exact hr'i have hr'j' : (r'.2 j₀').1 = pre₂ ++ v' :: suf₁ := by rw [hj', hv']; exact hr'j have hu1 := split_at_mem_unique (isDPath_nodup ((mem_allPaths_iff ..).mp (r'.2 i₀').2)) h1' hr'i' have hu2 := split_at_mem_unique (isDPath_nodup ((mem_allPaths_iff ..).mp (r'.2 j₀').2)) h2' hr'j' intro l by_cases hl1 : l = i₀ · subst l have hl1' : i₀ = i₀' := hi'.symm have hval : ((lgvSwap r' hr').2 i₀).1 = pre₁' ++ v' :: suf₂' := by dsimp only [lgvSwap]; rw [dif_pos hl1'] rw [hval, hv'] dsimp only [pre₁', suf₂'] rw [hu1.1, hu2.2, ← h1.1] · by_cases hl2 : l = j₀ · subst l have hl1' : j₀ ≠ i₀' := by rw [show i₀' = i₀ from hi']; exact Ne.symm hij₀ have hl2' : j₀ = j₀' := hj'.symm have hval : ((lgvSwap r' hr').2 j₀).1 = pre₂' ++ v' :: suf₁' := by dsimp only [lgvSwap]; rw [dif_neg hl1', dif_pos hl2'] rw [hval, hv'] dsimp only [pre₂', suf₁'] rw [hu2.1, hu1.2, ← h2.1] · have hl1' : l ≠ i₀' := by rw [show i₀' = i₀ from hi']; exact hl1 have hl2' : l ≠ j₀' := by rw [show j₀' = j₀ from hj']; exact hl2 have hval1 : ((lgvSwap r' hr').2 l).1 = (r'.2 l).1 := by dsimp only [lgvSwap]; rw [dif_neg hl1', dif_neg hl2'] have hval2 : (r'.2 l).1 = (r.2 l).1 := by dsimp only [r', lgvSwap]; rw [dif_neg hl1, dif_neg hl2] exact hval1.trans hval2 -- Finish `HEq` from `hσ_eq` and `hpaths`: clear hct hv' hi' hj' rcases r with ⟨σ, f⟩ have : ∀ (σ₁ σ₂ : Equiv.Perm (Fin k)) (f₁ : ∀ i : Fin k, {p : List V // p ∈ allPaths G (A i) (B (σ₁ i))}) (f₂ : ∀ i : Fin k, {p : List V // p ∈ allPaths G (A i) (B (σ₂ i))}), σ₁ = σ₂ → (∀ i, (f₁ i).1 = (f₂ i).1) → HEq f₁ f₂ := by rintro σ₁ _ f₁ f₂ rfl hf rw [heq_iff_eq]; funext i; exact Subtype.ext (hf i) exact this _ _ _ _ hσ_eq hpaths have hswap_ne : ∀ (r : Routing G A B) (hr : ¬ IsVertexDisjoint r), lgvSwap r hr ≠ r := by intro r hr heq have hσ := congrArg Sigma.fst heq dsimp only [lgvSwap] at hσ have hij : (canonTriple r hr).1.2.1 ≠ (canonTriple r hr).1.2.2 := ne_of_lt (canonTriple r hr).2.1 have hsw : Equiv.swap (canonTriple r hr).1.2.1 (canonTriple r hr).1.2.2 = 1 := mul_left_cancel (a := r.1) (by rw [mul_one]; exact hσ) have := congrArg (fun p : Equiv.Perm (Fin k) => p (canonTriple r hr).1.2.1) hsw simp at this exact hij this.symm have hswap_neg : ∀ (r : Routing G A B) (hr : ¬ IsVertexDisjoint r), ((Equiv.Perm.sign (lgvSwap r hr).1 : R) * ∏ i : Fin k, pathWeight w ((lgvSwap r hr).2 i).1) + ((Equiv.Perm.sign r.1 : R) * ∏ i : Fin k, pathWeight w (r.2 i).1) = 0 := by intro r hr set t := canonTriple r hr set v := t.1.1 set i₀ := t.1.2.1 set j₀ := t.1.2.2 have hij₀ : i₀ ≠ j₀ := ne_of_lt t.2.1 have hsgn : (Equiv.Perm.sign (lgvSwap r hr).1 : R) = -(Equiv.Perm.sign r.1 : R) := by change (Equiv.Perm.sign (r.1 * Equiv.swap i₀ j₀) : R) = _ rw [map_mul, Equiv.Perm.sign_swap hij₀] push_cast; ring have hprod : (∏ l : Fin k, pathWeight w ((lgvSwap r hr).2 l).1) = ∏ l : Fin k, pathWeight w (r.2 l).1 := by have hi₀_path : IsDPath G (A i₀) (B (r.1 i₀)) (r.2 i₀).1 := (mem_allPaths_iff ..).mp (r.2 i₀).2 have hj₀_path : IsDPath G (A j₀) (B (r.1 j₀)) (r.2 j₀).1 := (mem_allPaths_iff ..).mp (r.2 j₀).2 have hsp1 := split_at_mem (isDPath_nodup hi₀_path) t.2.2.1 have hsp2 := split_at_mem (isDPath_nodup hj₀_path) t.2.2.2 let pre₁ := Classical.choose hsp1 let suf₁ := Classical.choose (Classical.choose_spec hsp1) have h1 := (Classical.choose_spec (Classical.choose_spec hsp1)).1 let pre₂ := Classical.choose hsp2 let suf₂ := Classical.choose (Classical.choose_spec hsp2) have h2 := (Classical.choose_spec (Classical.choose_spec hsp2)).1 have hpair : pathWeight w ((lgvSwap r hr).2 i₀).1 * pathWeight w ((lgvSwap r hr).2 j₀).1 = pathWeight w (r.2 i₀).1 * pathWeight w (r.2 j₀).1 := by have hpi : ((lgvSwap r hr).2 i₀).1 = pre₁ ++ v :: suf₂ := by simp [lgvSwap, t, v, i₀, j₀, pre₁, suf₂] have hpj : ((lgvSwap r hr).2 j₀).1 = pre₂ ++ v :: suf₁ := by simp [lgvSwap, t, v, i₀, j₀, Ne.symm hij₀, pre₂, suf₁] rw [hpi, hpj, h1, h2] rw [pathWeight_append_middle w pre₁ suf₂ v, pathWeight_append_middle w pre₂ suf₁ v, pathWeight_append_middle w pre₁ suf₁ v, pathWeight_append_middle w pre₂ suf₂ v] ring have hsplit : ∀ (f : Fin k → R), ∏ l : Fin k, f l = (f i₀ * f j₀) * ∏ l ∈ (Finset.univ.erase i₀).erase j₀, f l := by intro f rw [← Finset.mul_prod_erase Finset.univ f (Finset.mem_univ i₀), ← Finset.mul_prod_erase (Finset.univ.erase i₀) f (Finset.mem_erase.mpr ⟨Ne.symm hij₀, Finset.mem_univ j₀⟩), mul_assoc] rw [hsplit, hsplit, hpair] congr 1 refine Finset.prod_congr rfl fun l hl => ?_ have hlj : l ≠ j₀ := (Finset.mem_erase.mp hl).1 have hli : l ≠ i₀ := (Finset.mem_erase.mp (Finset.mem_erase.mp hl).2).1 simp [lgvSwap, t, i₀, j₀, hli, hlj] rw [hsgn, hprod]; ring -- Step 4: Apply `Finset.sum_involution` — works over EVERY commutative ring `R`! refine Finset.sum_involution (fun r hr => lgvSwap r (Finset.mem_filter.mp hr).2) ?_ ?_ ?_ ?_ · intro r hr have h1 := hswap_neg r (Finset.mem_filter.mp hr).2 rw [add_comm] exact h1 · intro r hr _ exact hswap_ne r (Finset.mem_filter.mp hr).2 · intro r hr exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, hswap_not_disj r (Finset.mem_filter.mp hr).2⟩ · intro r hr exact hswap_invol r (Finset.mem_filter.mp hr).2 /-- **THEOREM 2 — Planar Non-Crossing Positivity (`lgv_planar_nonneg`)**: Whenever every vertex-disjoint routing from `A` to `B` has identity permutation `σ = 1` (the planar non-crossing condition) and all edge weights are nonnegative, `0 ≤ (pathMatrix G w A B).det`! -/ theorem lgv_planar_nonneg {V R : Type*} [Fintype V] [DecidableEq V] [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] {k : ℕ} (G : DAG V) (w : V → V → R) (hw : ∀ u v, 0 ≤ w u v) (A B : Fin k → V) (hplanar : ∀ r : Routing G A B, IsVertexDisjoint r → r.1 = 1) : 0 ≤ (pathMatrix G w A B).det := by rw [lgv_lemma] apply Finset.sum_nonneg intro r hr have hdisj := (Finset.mem_filter.mp hr).2 have hsgn : (Equiv.Perm.sign r.1 : R) = 1 := by rw [hplanar r hdisj, map_one]; norm_num rw [hsgn, one_mul] apply Finset.prod_nonneg intro i _ have hpw : ∀ p : List V, 0 ≤ pathWeight w p := by intro p; induction p with | nil => simp [pathWeight] | cons x xs ih => cases xs with | nil => simp [pathWeight] | cons y ys => exact mul_nonneg (hw x y) ih exact hpw _ /-! ### 1A. Planar Integer Grid DAG & Exact Pascal / Binomial Matrix Total Nonnegativity -/ /-- The finite planar integer grid DAG `Fin (M + 1) × Fin (N + 1)` with North and East steps. -/ def gridDAG (M N : ℕ) : DAG (Fin (M + 1) × Fin (N + 1)) where edge := fun u v => (v.1.1 == u.1.1 + 1 && v.2.1 == u.2.1) || (v.1.1 == u.1.1 && v.2.1 == u.2.1 + 1) rank := fun u => u.1.1 + u.2.1 rank_lt := by intro u v h simp only [Bool.or_eq_true, Bool.and_eq_true, beq_iff_eq] at h rcases h with ⟨h1, h2⟩ | ⟨h1, h2⟩ <;> omega /-- **Planar Grid Crossing Lemma (`grid_planar_crossing`)**: If `A_1 = (0, y₁)` is ABOVE `A_2 = (0, y₂)` (`y₂ < y₁`) on the left edge, and `B_1 = (x₁, N)` is LEFT of `B_2 = (x₂, N)` (`x₁ < x₂`) on the top edge, then ANY directed grid path `p₁ : A_1 → B_2` and ANY directed grid path `p₂ : A_2 → B_1` MUST intersect! -/ lemma grid_planar_crossing {M N : ℕ} {y₁ y₂ : Fin (N + 1)} {x₁ x₂ : Fin (M + 1)} (hy : y₂ < y₁) (hx : x₁ < x₂) {p₁ p₂ : List (Fin (M + 1) × Fin (N + 1))} (hp₁ : IsDPath (gridDAG M N) (⟨0, by omega⟩, y₁) (x₂, ⟨N, by omega⟩) p₁) (hp₂ : IsDPath (gridDAG M N) (⟨0, by omega⟩, y₂) (x₁, ⟨N, by omega⟩) p₂) : ∃ v, v ∈ p₁ ∧ v ∈ p₂ := by -- Every grid path covers EVERY intermediate rank `r` with `rank a ≤ r ≤ rank b`! have hcover : ∀ {a b : Fin (M + 1) × Fin (N + 1)} {p : List (Fin (M + 1) × Fin (N + 1))}, IsDPath (gridDAG M N) a b p → ∀ r : ℕ, a.1.1 + a.2.1 ≤ r → r ≤ b.1.1 + b.2.1 → ∃ u ∈ p, u.1.1 + u.2.1 = r := by intro a b p hp rcases hp with ⟨hhead, hlast, hchain⟩ induction p generalizing a with | nil => simp at hhead | cons x xs ih => simp only [List.head?_cons, Option.some.injEq] at hhead; subst hhead cases xs with | nil => simp only [List.getLast?_singleton, Option.some.injEq] at hlast; subst hlast intro r h1 h2; exact ⟨x, List.mem_cons_self .., by omega⟩ | cons y ys => rw [List.isChain_cons_cons] at hchain have hstep : y.1.1 + y.2.1 = x.1.1 + x.2.1 + 1 := by have he := hchain.1 simp only [gridDAG, Bool.or_eq_true, Bool.and_eq_true, beq_iff_eq] at he rcases he with ⟨h1, h2⟩ | ⟨h1, h2⟩ <;> omega intro r h1 h2 by_cases hrx : r = x.1.1 + x.2.1 · exact ⟨x, List.mem_cons_self .., hrx.symm⟩ · rcases ih rfl (by simpa using hlast) hchain.2 r (by omega) h2 with ⟨u, hu, hru⟩ exact ⟨u, List.mem_cons_of_mem x hu, hru⟩ -- Moreover, stepping from rank `r` to `r + 1` along a grid path changes `x`-coordinate by `0` or `+1`! have hstep_x : ∀ {a b : Fin (M + 1) × Fin (N + 1)} {p : List (Fin (M + 1) × Fin (N + 1))}, IsDPath (gridDAG M N) a b p → ∀ u ∈ p, ∀ w ∈ p, w.1.1 + w.2.1 = u.1.1 + u.2.1 + 1 → u.1.1 ≤ w.1.1 ∧ w.1.1 ≤ u.1.1 + 1 := by intro a b p hp u hu w hw hr have hch := hp.2.2 -- Prove by induction on `p`: consecutive elements change rank by `+1` and `x` by `0` or `+1`! have hall : ∀ {q : List (Fin (M + 1) × Fin (N + 1))}, q.IsChain (fun s t => (gridDAG M N).edge s t = true) → ∀ u ∈ q, ∀ w ∈ q, w.1.1 + w.2.1 = u.1.1 + u.2.1 + 1 → u.1.1 ≤ w.1.1 ∧ w.1.1 ≤ u.1.1 + 1 := by intro q hq induction q with | nil => intro u hu; simp at hu | cons x xs ih => cases xs with | nil => intro u hu w hw hr simp only [List.mem_singleton] at hu hw; subst hu hw; omega | cons y ys => rw [List.isChain_cons_cons] at hq have hxy : y.1.1 + y.2.1 = x.1.1 + x.2.1 + 1 ∧ x.1.1 ≤ y.1.1 ∧ y.1.1 ≤ x.1.1 + 1 := by have he := hq.1 simp only [gridDAG, Bool.or_eq_true, Bool.and_eq_true, beq_iff_eq] at he rcases he with ⟨h1, h2⟩ | ⟨h1, h2⟩ <;> omega have hpw := isChain_rank_lt (gridDAG M N) hq.2 intro u hu w hw hr rcases List.mem_cons.mp hu with rfl | hu' · rcases List.mem_cons.mp hw with rfl | hw' · omega · rcases List.mem_cons.mp hw' with rfl | hw'' · exact ⟨hxy.2.1, hxy.2.2⟩ · have hgt := (List.pairwise_cons.mp hpw).1 w hw'' simp only [gridDAG] at hgt; omega · rcases List.mem_cons.mp hw with rfl | hw' · have hpw_full := isChain_rank_lt (gridDAG M N) (List.isChain_cons_cons.mpr hq) have hlt := (List.pairwise_cons.mp hpw_full).1 u hu' simp only [gridDAG] at hlt; omega · exact ih hq.2 u hu' w hw' hr exact hall hch u hu w hw hr -- Track discrete crossing from `r₀ = y₁.1` to `r₁ = x₁.1 + N`! -- At `r = y₁.1`: `u₁ = (0, y₁)` has `u₁.1 = 0 ≤ u₂.1` (for `u₂ ∈ p₂` of rank `y₁.1`). -- At `r = x₁.1 + N`: `u₂ = (x₁, N)` has `u₂.1 = x₁`, while `u₁ ∈ p₁` of rank `x₁.1 + N` has -- `u₁.2 ≤ N` so `u₁.1 = x₁.1 + N - u₁.2 ≥ x₁ = u₂.1`! -- By discrete IVT on `k = r - y₁.1`: there is a rank `r` where `u₁.1 = u₂.1` (hence `u₁ = u₂`)! have hr_le : y₁.1 ≤ x₁.1 + N := by have := y₁.2; omega have hdiscr_ivt : ∀ (d : ℕ), y₁.1 + d ≤ x₁.1 + N → (∃ u₁ ∈ p₁, ∃ u₂ ∈ p₂, u₁.1.1 + u₁.2.1 = y₁.1 + d ∧ u₂.1.1 + u₂.2.1 = y₁.1 + d ∧ u₁.1.1 ≤ u₂.1.1) ∨ (∃ v, v ∈ p₁ ∧ v ∈ p₂) := by intro d induction d with | zero => intro _ left have hu1 : ((⟨0, by omega⟩ : Fin (M + 1)), y₁) ∈ p₁ := List.mem_of_head? hp₁.1 rcases hcover hp₂ y₁.1 (by dsimp; omega) (by dsimp; omega) with ⟨u₂, hu2, hru2⟩ exact ⟨(⟨0, by omega⟩, y₁), hu1, u₂, hu2, by simp, by omega, Nat.zero_le _⟩ | succ d ih => intro hd rcases ih (by omega) with ⟨u₁, hu1, u₂, hu2, hr1, hr2, hle⟩ | hinter · rcases hcover hp₁ (y₁.1 + (d + 1)) (by dsimp; omega) (by dsimp; omega) with ⟨w₁, hw1, hrw1⟩ rcases hcover hp₂ (y₁.1 + (d + 1)) (by dsimp; omega) (by dsimp; omega) with ⟨w₂, hw2, hrw2⟩ have hs1 := hstep_x hp₁ u₁ hu1 w₁ hw1 (by omega) have hs2 := hstep_x hp₂ u₂ hu2 w₂ hw2 (by omega) by_cases hcmp : w₁.1.1 ≤ w₂.1.1 · left; exact ⟨w₁, hw1, w₂, hw2, hrw1, hrw2, hcmp⟩ · -- `w₂.1 < w₁.1` while `u₁.1 ≤ u₂.1` and `w₁.1 ≤ u₁.1 + 1`, `u₂.1 ≤ w₂.1` forces `u₁.1 = u₂.1`! have heqx : u₁.1.1 = u₂.1.1 := by omega have heq : u₁ = u₂ := Prod.ext (Fin.ext heqx) (Fin.ext (by omega)) right; exact ⟨u₁, hu1, heq ▸ hu2⟩ · right; exact hinter rcases hdiscr_ivt (x₁.1 + N - y₁.1) (by omega) with ⟨u₁, hu1, u₂, hu2, hr1, hr2, hle⟩ | hinter · -- At `r = x₁.1 + N`, `u₂` MUST be `(x₁, N)` (unique vertex of rank `x₁ + N` on `p₂`), so `u₂.1 = x₁`, -- while `u₁.2 ≤ N` implies `u₁.1 ≥ x₁`, hence `u₁.1 = u₂.1` and `u₁ = u₂`! have hu1_y : u₁.2.1 ≤ N := Nat.lt_succ_iff.mp u₁.2.2 have hu2_x : u₂.1.1 ≤ x₁.1 := by -- Since `p₂` ends at `(x₁, N)` and `x` never decreases, `u₂.1 ≤ x₁`! -- Even simpler: `u₂` has rank `x₁.1 + N = rank (x₁, N)`, and rank is strictly increasing on `p₂`! have hlast2 : (x₁, (⟨N, by omega⟩ : Fin (N + 1))) ∈ p₂ := List.mem_of_getLast? hp₂.2.1 have hpw := isChain_rank_lt (gridDAG M N) hp₂.2.2 have huniq : ∀ a ∈ p₂, ∀ b ∈ p₂, a.1.1 + a.2.1 = b.1.1 + b.2.1 → a = b := by intro a ha b hb hreq have h : ∀ {q : List (Fin (M + 1) × Fin (N + 1))}, q.Pairwise (fun s t => (gridDAG M N).rank s < (gridDAG M N).rank t) → ∀ a ∈ q, ∀ b ∈ q, a.1.1 + a.2.1 = b.1.1 + b.2.1 → a = b := by intro q hq; induction q with | nil => intro a ha; simp at ha | cons z zs ihq => rw [List.pairwise_cons] at hq intro a ha b hb hreq rcases List.mem_cons.mp ha with rfl | ha' <;> rcases List.mem_cons.mp hb with rfl | hb' · rfl · have := hq.1 b hb'; simp only [gridDAG] at this; omega · have := hq.1 a ha'; simp only [gridDAG] at this; omega · exact ihq hq.2 a ha' b hb' hreq exact h hpw a ha b hb hreq have heq2 : u₂ = (x₁, ⟨N, by omega⟩) := huniq u₂ hu2 (x₁, ⟨N, by omega⟩) hlast2 (by dsimp; omega) rw [heq2] have heqx : u₁.1.1 = u₂.1.1 := by omega have heq : u₁ = u₂ := Prod.ext (Fin.ext heqx) (Fin.ext (by omega)) exact ⟨u₁, hu1, heq ▸ hu2⟩ · exact hinter /-- **THEOREM 3 — Planar Grid / Pascal Minor Total Nonnegativity via LGV (`pascal_grid_det_nonneg`)**: For ANY strictly decreasing left-edge sources `A_i = (0, y_i)` (`y_0 > y_1 > ... > y_{k-1}`), ANY strictly increasing top-edge sinks `B_j = (x_j, N)` (`x_0 < x_1 < ... < x_{k-1}`), and ANY nonnegative edge weights `w ≥ 0` on the grid DAG `gridDAG M N`, `0 ≤ (pathMatrix (gridDAG M N) w A B).det`! -/ theorem pascal_grid_det_nonneg {M N k : ℕ} {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (w : (Fin (M + 1) × Fin (N + 1)) → (Fin (M + 1) × Fin (N + 1)) → R) (hw : ∀ u v, 0 ≤ w u v) (y : Fin k → Fin (N + 1)) (hy : StrictAnti y) (x : Fin k → Fin (M + 1)) (hx : StrictMono x) : 0 ≤ (pathMatrix (gridDAG M N) w (fun i => (⟨0, by omega⟩, y i)) (fun j => (x j, ⟨N, by omega⟩))).det := by refine lgv_planar_nonneg (gridDAG M N) w hw _ _ fun r hdisj => ?_ -- If `r.1 ≠ 1`, there exists an inversion `i < j` with `r.1 j < r.1 i`, contradicting `hdisj` by `grid_planar_crossing`! by_contra hne have hex_inv : ∃ i j : Fin k, i < j ∧ r.1 j < r.1 i := by by_contra hno push Not at hno have hmono : StrictMono r.1 := fun a b hab => lt_of_le_of_ne (hno a b hab) (fun heq => ne_of_lt hab (r.1.injective heq)) have hle : ∀ i : Fin k, i ≤ r.1 i := by intro i rcases i with ⟨i, hi⟩ induction i with | zero => exact Nat.zero_le _ | succ m ih => have hlt := hmono (show (⟨m, by omega⟩ : Fin k) < ⟨m + 1, hi⟩ from Nat.lt_succ_self m) have hm := ih (by omega) exact Nat.succ_le_of_lt (lt_of_le_of_lt hm hlt) have hid : ∀ i : Fin k, r.1 i = i := by intro i -- If `i < r.1 i`, then `r.1` maps `{j | i ≤ j}` into `{j | i < j}`, contradicting cardinality! by_contra hne_i have hsum : ∑ j : Fin k, (r.1 j).1 = ∑ j : Fin k, j.1 := Equiv.sum_comp r.1 (fun j : Fin k => j.1) have hgt : ∑ j : Fin k, j.1 < ∑ j : Fin k, (r.1 j).1 := Finset.sum_lt_sum (fun j _ => Fin.le_def.mp (hle j)) ⟨i, Finset.mem_univ i, Fin.lt_def.mp (lt_of_le_of_ne (hle i) (Ne.symm hne_i))⟩ omega exact hne (Equiv.ext hid) rcases hex_inv with ⟨i, j, hij, hσ⟩ have hpi : IsDPath (gridDAG M N) (⟨0, by omega⟩, y i) (x (r.1 i), ⟨N, by omega⟩) (r.2 i).1 := (mem_allPaths_iff ..).mp (r.2 i).2 have hpj : IsDPath (gridDAG M N) (⟨0, by omega⟩, y j) (x (r.1 j), ⟨N, by omega⟩) (r.2 j).1 := (mem_allPaths_iff ..).mp (r.2 j).2 rcases grid_planar_crossing (hy hij) (hx hσ) hpi hpj with ⟨v, hvi, hvj⟩ exact hdisj i j (ne_of_lt hij) v hvi hvj /-! ## 2. Exact Desnanot–Jacobi Identity & Dodgson Condensation -/ /-- Drop row `r` and column `c` from an `(n + 2) × (n + 2)` matrix `M`. -/ def dropRC {R : Type*} {n : ℕ} (M : Matrix (Fin (n + 2)) (Fin (n + 2)) R) (r c : Fin (n + 2)) : Matrix (Fin (n + 1)) (Fin (n + 1)) R := M.submatrix r.succAbove c.succAbove /-- Middle `n × n` submatrix of `M` obtained by dropping rows `0, n + 1` and cols `0, n + 1`. -/ def midSubmatrix {R : Type*} {n : ℕ} (M : Matrix (Fin (n + 2)) (Fin (n + 2)) R) : Matrix (Fin n) (Fin n) R := M.submatrix (fun i : Fin n => ⟨i.1 + 1, by omega⟩) (fun j : Fin n => ⟨j.1 + 1, by omega⟩) /-- Helper: cofactor sign formula for `adjugate M` at corners `0` and `Fin.last (n + 1)`. -/ lemma adjugate_corner_eq {R : Type*} [CommRing R] {n : ℕ} (M : Matrix (Fin (n + 2)) (Fin (n + 2)) R) (r c : Fin (n + 2)) : M.adjugate c r = (-1 : R) ^ ((r : ℕ) + (c : ℕ)) * (dropRC M r c).det := by rw [Matrix.adjugate_apply, Matrix.det_succ_row _ r] -- In `M.updateRow r (Pi.single c 1)`, the `r`-th row is `Pi.single c 1`, so only `j = c` survives! have hsum : ∀ j : Fin (n + 2), (-1 : R) ^ ((r : ℕ) + (j : ℕ)) * (M.updateRow r (Pi.single c 1) r j) * ((M.updateRow r (Pi.single c 1)).submatrix r.succAbove j.succAbove).det = if j = c then (-1 : R) ^ ((r : ℕ) + (c : ℕ)) * (dropRC M r c).det else 0 := by intro j rw [Matrix.updateRow_self] by_cases hj : j = c · subst hj simp only [Pi.single_eq_same, mul_one, ↓reduceIte] congr 2 ext a b simp only [Matrix.submatrix_apply, dropRC] exact congrFun (Matrix.updateRow_ne (Fin.succAbove_ne r a)) (j.succAbove b) · simp [hj] rw [Finset.sum_congr rfl (fun j _ => hsum j), Finset.sum_ite_eq' Finset.univ c, if_pos (Finset.mem_univ c)] /-- Helper: determinant of a matrix whose middle columns `1 .. n` are standard basis vectors `e_1 .. e_n`! -/ lemma det_border_cols {R : Type*} [CommRing R] {n : ℕ} (B : Matrix (Fin (n + 2)) (Fin (n + 2)) R) (hmid : ∀ (i : Fin (n + 2)) (j : Fin n), B i ⟨j.1 + 1, by omega⟩ = if i.1 = j.1 + 1 then 1 else 0) : B.det = B 0 0 * B (Fin.last (n + 1)) (Fin.last (n + 1)) - B 0 (Fin.last (n + 1)) * B (Fin.last (n + 1)) 0 := by -- Use `Matrix.det_apply`: any permutation `σ` with `∏ j, B (σ j) j ≠ 0` MUST fix every `j ∈ {1..n}`! rw [Matrix.det_apply] let sw : Equiv.Perm (Fin (n + 2)) := Equiv.swap 0 (Fin.last (n + 1)) have h0ne : (0 : Fin (n + 2)) ≠ Fin.last (n + 1) := by intro h; have := congrArg Fin.val h; simp at this have hfl_val : (Fin.last (n + 1)).1 = n + 1 := rfl have hz_val : (0 : Fin (n + 2)).1 = 0 := rfl have hterm : ∀ σ : Equiv.Perm (Fin (n + 2)), Equiv.Perm.sign σ • (∏ j : Fin (n + 2), B (σ j) j) = if σ = 1 then B 0 0 * B (Fin.last (n + 1)) (Fin.last (n + 1)) else if σ = sw then -(B 0 (Fin.last (n + 1)) * B (Fin.last (n + 1)) 0) else 0 := by intro σ by_cases hfix : ∀ j : Fin n, σ ⟨j.1 + 1, by omega⟩ = ⟨j.1 + 1, by omega⟩ · have hnot_mid : ∀ y : Fin (n + 2), 0 < y.1 → y.1 < n + 1 → σ y = y := by intro y hy0 hyl have hf := hfix ⟨y.1 - 1, by omega⟩ have hy_eq : (⟨y.1 - 1 + 1, by omega⟩ : Fin (n + 2)) = y := Fin.ext (by dsimp; omega) rwa [hy_eq] at hf have h0_cases : σ 0 = 0 ∨ σ 0 = Fin.last (n + 1) := by by_contra h push Not at h have hpos : 0 < (σ 0).1 := by by_contra h0; exact h.1 (Fin.ext (by omega)) have hlt : (σ 0).1 < n + 1 := by have := (σ 0).2; by_contra hge; exact h.2 (Fin.ext (by omega)) have hfix_m := hnot_mid (σ 0) hpos hlt have heq0 : σ 0 = 0 := σ.injective hfix_m exact h.1 heq0 have hprod_mid : ∀ j : Fin n, B (σ ⟨j.1 + 1, by omega⟩) ⟨j.1 + 1, by omega⟩ = 1 := by intro j; rw [hfix j, hmid]; simp have hprod_split : ∏ j : Fin (n + 2), B (σ j) j = B (σ 0) 0 * B (σ (Fin.last (n + 1))) (Fin.last (n + 1)) := by rw [Fin.prod_univ_succ, Fin.prod_univ_castSucc] have hrest : ∏ i : Fin n, B (σ i.castSucc.succ) i.castSucc.succ = 1 := by apply Finset.prod_eq_one; intro i _ exact hprod_mid i rw [hrest, one_mul] congr 2 rcases h0_cases with hσ0 | hσ0 · have hσ1 : σ = 1 := by ext j by_cases hj0 : j = 0 · subst hj0; simp [hσ0] · by_cases hjl : j = Fin.last (n + 1) · subst hjl have hval : σ (Fin.last (n + 1)) = Fin.last (n + 1) := by by_contra hne have hlt : (σ (Fin.last (n + 1))).1 < n + 1 := by have := (σ (Fin.last (n + 1))).2 by_contra hge; exact hne (Fin.ext (by omega)) by_cases hzero : σ (Fin.last (n + 1)) = 0 · exact h0ne (σ.injective (hzero.trans hσ0.symm)).symm · have hpos : 0 < (σ (Fin.last (n + 1))).1 := by by_contra h0; exact hzero (Fin.ext (by omega)) have hfix_m := hnot_mid (σ (Fin.last (n + 1))) hpos hlt exact hne (σ.injective hfix_m) simp [hval] · have hj1 : 0 < j.1 ∧ j.1 < n + 1 := by have := j.2 constructor · by_contra h0; exact hj0 (Fin.ext (by omega)) · by_contra hge; exact hjl (Fin.ext (by omega)) exact congrArg Fin.val (hnot_mid j hj1.1 hj1.2) rw [if_pos hσ1, hprod_split, hσ1]; simp · have hσsw : σ = sw := by ext j by_cases hj0 : j = 0 · subst hj0; simp [sw, hσ0] · by_cases hjl : j = Fin.last (n + 1) · subst hjl have hval : σ (Fin.last (n + 1)) = 0 := by by_contra hne have hpos : 0 < (σ (Fin.last (n + 1))).1 := by by_contra h0; exact hne (Fin.ext (by omega)) by_cases htop : σ (Fin.last (n + 1)) = Fin.last (n + 1) · exact h0ne (σ.injective (hσ0.trans htop.symm)) · have hlt : (σ (Fin.last (n + 1))).1 < n + 1 := by have := (σ (Fin.last (n + 1))).2 by_contra hge; exact htop (Fin.ext (by omega)) have hfix_m := hnot_mid (σ (Fin.last (n + 1))) hpos hlt exact htop (σ.injective hfix_m) simp [sw, hval] · have hj1 : 0 < j.1 ∧ j.1 < n + 1 := by have := j.2 constructor · by_contra h0; exact hj0 (Fin.ext (by omega)) · by_contra hge; exact hjl (Fin.ext (by omega)) have hf := hnot_mid j hj1.1 hj1.2 simp [sw, Equiv.swap_apply_of_ne_of_ne hj0 hjl, hf] have hsw_ne1 : sw ≠ 1 := by intro h; have := congrArg (fun p : Equiv.Perm (Fin (n + 2)) => p 0) h simp [sw] at this rw [if_neg (hσsw ▸ hsw_ne1), if_pos hσsw, hprod_split, hσsw] rw [Equiv.Perm.sign_swap h0ne] simp [sw, mul_comm] · push Not at hfix rcases hfix with ⟨j, hj⟩ have hne1 : σ ≠ 1 := fun h => hj (by simp [h]) have hnesw : σ ≠ sw := fun h => by apply hj; rw [h] have h1 : (⟨j.1 + 1, by omega⟩ : Fin (n + 2)) ≠ 0 := by intro e; simp at e have h2 : (⟨j.1 + 1, by omega⟩ : Fin (n + 2)) ≠ Fin.last (n + 1) := by intro e; have := congrArg Fin.val e; simp [Fin.last] at this; omega exact Equiv.swap_apply_of_ne_of_ne h1 h2 rw [if_neg hne1, if_neg hnesw] have hzero : B (σ ⟨j.1 + 1, by omega⟩) ⟨j.1 + 1, by omega⟩ = 0 := by rw [hmid]; rw [if_neg (fun h => hj (Fin.ext h))] have hprod0 : ∏ i : Fin (n + 2), B (σ i) i = 0 := Finset.prod_eq_zero (Finset.mem_univ ⟨j.1 + 1, by omega⟩) hzero rw [hprod0, smul_zero] rw [Finset.sum_congr rfl (fun σ _ => hterm σ)] have hsw_ne1 : sw ≠ 1 := by intro h; have := congrArg (fun p : Equiv.Perm (Fin (n + 2)) => p 0) h simp [sw] at this rw [Finset.sum_ite, Finset.sum_ite] have hf1 : Finset.univ.filter (fun σ : Equiv.Perm (Fin (n + 2)) => σ = 1) = {1} := by ext σ; simp have hf2 : (Finset.univ.filter (fun σ : Equiv.Perm (Fin (n + 2)) => ¬ σ = 1)).filter (fun σ => σ = sw) = {sw} := by ext σ; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_singleton] constructor · rintro ⟨_, rfl⟩; rfl · rintro rfl; exact ⟨hsw_ne1, rfl⟩ rw [hf1, hf2, Finset.sum_singleton, Finset.sum_singleton, Finset.sum_const_zero, add_zero] ring /-- Helper: determinant of a matrix whose first column is `d * e_0` and last column is `d * e_{n+1}`! -/ lemma det_border_diag {R : Type*} [CommRing R] {n : ℕ} (C : Matrix (Fin (n + 2)) (Fin (n + 2)) R) (d : R) (hc0 : ∀ i : Fin (n + 2), C i 0 = if i = 0 then d else 0) (hcl : ∀ i : Fin (n + 2), C i (Fin.last (n + 1)) = if i = Fin.last (n + 1) then d else 0) : C.det = d ^ 2 * (midSubmatrix C).det := by -- Expand along column `0`, then along the last column `Fin.last n`! rw [Matrix.det_succ_column_zero] have hcol0 : ∀ i : Fin (n + 2), (-1 : R) ^ (i : ℕ) * C i 0 * (C.submatrix i.succAbove Fin.succ).det = if i = 0 then d * (C.submatrix Fin.succ Fin.succ).det else 0 := by intro i rw [hc0 i] by_cases hi : i = 0 · subst hi; simp [Fin.succAbove_zero] · simp [hi] rw [Finset.sum_congr rfl (fun i _ => hcol0 i), Finset.sum_ite_eq' Finset.univ 0, if_pos (Finset.mem_univ 0)] -- Now expand `(C.submatrix Fin.succ Fin.succ).det` along column `Fin.last n`! rw [Matrix.det_succ_column _ (Fin.last n)] have hcolL : ∀ i : Fin (n + 1), (-1 : R) ^ ((i : ℕ) + (Fin.last n : ℕ)) * (C.submatrix Fin.succ Fin.succ) i (Fin.last n) * ((C.submatrix Fin.succ Fin.succ).submatrix i.succAbove (Fin.last n).succAbove).det = if i = Fin.last n then d * (midSubmatrix C).det else 0 := by intro i simp only [Matrix.submatrix_apply] have hfl : Fin.succ (Fin.last n) = Fin.last (n + 1) := Fin.ext (by simp [Fin.last]) rw [hfl, hcl (Fin.succ i)] by_cases hi : i = Fin.last n · subst hi rw [hfl, if_pos rfl, if_pos rfl] have hsign : (-1 : R) ^ ((Fin.last n : ℕ) + (Fin.last n : ℕ)) = 1 := by rw [← two_mul, pow_mul]; norm_num rw [hsign, one_mul] congr 2 ext a b simp only [Matrix.submatrix_apply, midSubmatrix, Fin.succAbove_last] have ha : a.castSucc.succ = ⟨a.1 + 1, by omega⟩ := Fin.ext rfl have hb : b.castSucc.succ = ⟨b.1 + 1, by omega⟩ := Fin.ext rfl rw [ha, hb] · have hne : Fin.succ i ≠ Fin.last (n + 1) := by intro h; apply hi; exact Fin.ext (by have := congrArg Fin.val h; simp [Fin.last] at this ⊢; omega) simp [hi, hne] rw [Finset.sum_congr rfl (fun i _ => hcolL i), Finset.sum_ite_eq' Finset.univ (Fin.last n), if_pos (Finset.mem_univ _)] ring /-- **THEOREM 4 — Universal Desnanot–Jacobi Identity (`desnanot_jacobi_identity`)**: For **EVERY** `n : ℕ` and **EVERY** `(n + 2) × (n + 2)` matrix `M` over **ANY** commutative ring `R`: `M.det * (midSubmatrix M).det = (dropRC M (Fin.last (n + 1)) (Fin.last (n + 1))).det * (dropRC M 0 0).det - (dropRC M (Fin.last (n + 1)) 0).det * (dropRC M 0 (Fin.last (n + 1))).det`! -/ theorem desnanot_jacobi_identity {R : Type*} [CommRing R] {n : ℕ} (M : Matrix (Fin (n + 2)) (Fin (n + 2)) R) : M.det * (midSubmatrix M).det = (dropRC M (Fin.last (n + 1)) (Fin.last (n + 1))).det * (dropRC M 0 0).det - (dropRC M (Fin.last (n + 1)) 0).det * (dropRC M 0 (Fin.last (n + 1))).det := by -- First prove the identity for the universal generic matrix over `P = MvPolynomial (Fin (n+2) × Fin (n+2)) ℤ`! let P := MvPolynomial (Fin (n + 2) × Fin (n + 2)) ℤ let G : Matrix (Fin (n + 2)) (Fin (n + 2)) P := Matrix.of fun i j => MvPolynomial.X (i, j) have hG_det_ne : G.det ≠ 0 := by intro h0 let ev : P →+* ℤ := MvPolynomial.eval₂Hom (RingHom.id ℤ) fun p => if p.1 = p.2 then 1 else 0 have h1 := congrArg ev h0 rw [map_zero, RingHom.map_det] at h1 have hI : ev.mapMatrix G = (1 : Matrix (Fin (n + 2)) (Fin (n + 2)) ℤ) := by ext i j simp only [RingHom.mapMatrix_apply, Matrix.map_apply, G, Matrix.of_apply, Matrix.one_apply, ev] exact MvPolynomial.eval₂Hom_X' _ _ _ rw [hI, Matrix.det_one] at h1 exact one_ne_zero h1 -- Build the adjugate-border matrix `B` for `G`: let B : Matrix (Fin (n + 2)) (Fin (n + 2)) P := Matrix.of fun i j => if j = 0 ∨ j = Fin.last (n + 1) then G.adjugate i j else if i = j then 1 else 0 have hdetB : B.det = G.adjugate 0 0 * G.adjugate (Fin.last (n + 1)) (Fin.last (n + 1)) - G.adjugate 0 (Fin.last (n + 1)) * G.adjugate (Fin.last (n + 1)) 0 := by have hB := det_border_cols B (fun i j => by have hne0 : (⟨j.1 + 1, by omega⟩ : Fin (n + 2)) ≠ 0 := by intro h; simp at h have hneL : (⟨j.1 + 1, by omega⟩ : Fin (n + 2)) ≠ Fin.last (n + 1) := by intro h; have := congrArg Fin.val h; simp [Fin.last] at this; omega simp only [B, Matrix.of_apply, hne0, hneL, or_self, ↓reduceIte] by_cases h : i.1 = j.1 + 1 · rw [if_pos h, if_pos (Fin.ext h)] · rw [if_neg h, if_neg (fun e => h (congrArg Fin.val e))]) simpa [B] using hB have hdetGB : (G * B).det = G.det ^ 2 * (midSubmatrix G).det := by have hGB := det_border_diag (G * B) G.det (fun i => by change ∑ k : Fin (n + 2), G i k * B k 0 = if i = 0 then G.det else 0 have hcol : ∀ k : Fin (n + 2), B k 0 = G.adjugate k 0 := fun k => by simp [B] simp_rw [hcol] have hm := congrFun (congrFun (Matrix.mul_adjugate G) i) 0 simpa [Matrix.mul_apply, Matrix.one_apply] using hm) (fun i => by change ∑ k : Fin (n + 2), G i k * B k (Fin.last (n + 1)) = if i = Fin.last (n + 1) then G.det else 0 have hcol : ∀ k : Fin (n + 2), B k (Fin.last (n + 1)) = G.adjugate k (Fin.last (n + 1)) := fun k => by simp [B] simp_rw [hcol] have hm := congrFun (congrFun (Matrix.mul_adjugate G) i) (Fin.last (n + 1)) simpa [Matrix.mul_apply, Matrix.one_apply] using hm) have hmid_eq : midSubmatrix (G * B) = midSubmatrix G := by ext i j simp only [midSubmatrix, Matrix.submatrix_apply, Matrix.mul_apply] have hne0 : (⟨j.1 + 1, by omega⟩ : Fin (n + 2)) ≠ 0 := by intro h; simp at h have hneL : (⟨j.1 + 1, by omega⟩ : Fin (n + 2)) ≠ Fin.last (n + 1) := by intro h; have := congrArg Fin.val h; simp [Fin.last] at this; omega have hterm : ∀ k : Fin (n + 2), G ⟨i.1 + 1, by omega⟩ k * B k ⟨j.1 + 1, by omega⟩ = if k = ⟨j.1 + 1, by omega⟩ then G ⟨i.1 + 1, by omega⟩ ⟨j.1 + 1, by omega⟩ else 0 := by intro k simp only [B, Matrix.of_apply, hne0, hneL, or_self, ↓reduceIte] split_ifs with h · subst h; rw [mul_one] · rw [mul_zero] rw [Finset.sum_congr rfl (fun k _ => hterm k), Finset.sum_ite_eq' Finset.univ _, if_pos (Finset.mem_univ _)] rwa [hmid_eq] at hGB -- Cancel ONE `G.det ≠ 0` in the integral domain `P`! have hG_id : G.det * (midSubmatrix G).det = (dropRC G (Fin.last (n + 1)) (Fin.last (n + 1))).det * (dropRC G 0 0).det - (dropRC G (Fin.last (n + 1)) 0).det * (dropRC G 0 (Fin.last (n + 1))).det := by have hmul : G.det * (G.det * (midSubmatrix G).det) = G.det * (G.adjugate 0 0 * G.adjugate (Fin.last (n + 1)) (Fin.last (n + 1)) - G.adjugate 0 (Fin.last (n + 1)) * G.adjugate (Fin.last (n + 1)) 0) := by rw [← hdetB, ← Matrix.det_mul, hdetGB]; ring have hcancel := mul_left_cancel₀ hG_det_ne hmul rw [hcancel, adjugate_corner_eq G 0 0, adjugate_corner_eq G (Fin.last (n + 1)) (Fin.last (n + 1)), adjugate_corner_eq G (Fin.last (n + 1)) 0, adjugate_corner_eq G 0 (Fin.last (n + 1))] have hs1 : (-1 : P) ^ ((Fin.last (n + 1) : ℕ) + (Fin.last (n + 1) : ℕ)) = 1 := by rw [← two_mul, pow_mul]; norm_num have hs2 : (-1 : P) ^ ((Fin.last (n + 1) : ℕ) + 0) * (-1 : P) ^ (0 + (Fin.last (n + 1) : ℕ)) = 1 := by rw [← pow_add, add_zero, zero_add, ← two_mul, pow_mul]; norm_num simp only [Fin.val_zero, add_zero, zero_add, pow_zero, one_mul, hs1] calc (dropRC G 0 0).det * (dropRC G (Fin.last (n + 1)) (Fin.last (n + 1))).det - (-1 : P) ^ (Fin.last (n + 1) : ℕ) * (dropRC G (Fin.last (n + 1)) 0).det * ((-1 : P) ^ (Fin.last (n + 1) : ℕ) * (dropRC G 0 (Fin.last (n + 1))).det) = (dropRC G (Fin.last (n + 1)) (Fin.last (n + 1))).det * (dropRC G 0 0).det - ((-1 : P) ^ ((Fin.last (n + 1) : ℕ) + 0) * (-1 : P) ^ (0 + (Fin.last (n + 1) : ℕ))) * ((dropRC G (Fin.last (n + 1)) 0).det * (dropRC G 0 (Fin.last (n + 1))).det) := by simp only [add_zero, zero_add]; ring _ = _ := by rw [hs2, one_mul] -- Specialize from `P` to ANY commutative ring `R` via `MvPolynomial.eval₂Hom`! let φ : P →+* R := MvPolynomial.eval₂Hom (Int.castRingHom R) (fun p => M p.1 p.2) have hmap : φ.mapMatrix G = M := by ext i j simp only [RingHom.mapMatrix_apply, Matrix.map_apply, G, Matrix.of_apply, φ] exact MvPolynomial.eval₂Hom_X' _ _ _ have hmap_mid : φ.mapMatrix (midSubmatrix G) = midSubmatrix M := by ext i j simp only [RingHom.mapMatrix_apply, Matrix.map_apply, midSubmatrix, Matrix.submatrix_apply, G, Matrix.of_apply, φ] exact MvPolynomial.eval₂Hom_X' _ _ _ have hmap_drop : ∀ r c, φ.mapMatrix (dropRC G r c) = dropRC M r c := by intro r c; ext i j simp only [RingHom.mapMatrix_apply, Matrix.map_apply, dropRC, Matrix.submatrix_apply, G, Matrix.of_apply, φ] exact MvPolynomial.eval₂Hom_X' _ _ _ have hres := congrArg φ hG_id simp only [map_mul, map_sub, RingHom.map_det, hmap, hmap_mid, hmap_drop] at hres exact hres /-- **THEOREM 5 — Dodgson Condensation (`dodgson_condensation`)**: Over any field `K`, whenever `(midSubmatrix M).det ≠ 0`, `M.det = (det M_NW * det M_SE - det M_NE * det M_SW) / det M_mid`! -/ theorem dodgson_condensation {K : Type*} [Field K] {n : ℕ} (M : Matrix (Fin (n + 2)) (Fin (n + 2)) K) (hmid : (midSubmatrix M).det ≠ 0) : M.det = ((dropRC M (Fin.last (n + 1)) (Fin.last (n + 1))).det * (dropRC M 0 0).det - (dropRC M (Fin.last (n + 1)) 0).det * (dropRC M 0 (Fin.last (n + 1))).det) / (midSubmatrix M).det := by rw [eq_div_iff hmid] exact desnanot_jacobi_identity M /-! ## 3. Cauchy–Binet, Total Positivity & Whitney–Loewner Chevalley Factorization -/ /-- The finite set of all strictly increasing maps `Fin k → Fin m` (representing `k`-subsets). -/ abbrev IncIdx (k m : ℕ) := {f : Fin k → Fin m // StrictMono f} lemma strictMono_eq_of_range_eq {k p : ℕ} {f g : Fin k → Fin p} (hf : StrictMono f) (hg : StrictMono g) (hr : Set.range f = Set.range g) : f = g := by funext i rcases i with ⟨i, hi⟩ induction i using Nat.strong_induction_on with | _ i ih => have hle : ∀ (f' g' : Fin k → Fin p), StrictMono f' → StrictMono g' → Set.range f' = Set.range g' → (∀ j (hj : j < i), f' ⟨j, by omega⟩ = g' ⟨j, by omega⟩) → g' ⟨i, hi⟩ ≤ f' ⟨i, hi⟩ := by intro f' g' hf' hg' hr' hprev have hmem : f' ⟨i, hi⟩ ∈ Set.range g' := hr' ▸ ⟨⟨i, hi⟩, rfl⟩ rcases hmem with ⟨a, ha⟩ have hia : i ≤ a.1 := by by_contra hlt push Not at hlt have heq := hprev a.1 hlt have hfa : f' a = f' ⟨i, hi⟩ := by simpa [heq] using ha have hval := congrArg Fin.val (hf'.injective hfa) dsimp at hval omega rw [← ha] exact hg'.monotone (Fin.le_def.mpr hia) exact le_antisymm (hle g f hg hf hr.symm fun j hj => (ih j hj (by omega)).symm) (hle f g hf hg hr fun j hj => ih j hj (by omega)) /-- **THEOREM 6 — Exact Cauchy–Binet Minor Formula (`cauchy_binet_formula`)**: For ANY `A : Matrix (Fin m) (Fin p) R`, `B : Matrix (Fin p) (Fin n) R`, and ANY row/column selections `r : Fin k → Fin m`, `c : Fin k → Fin n`, `((A * B).submatrix r c).det = ∑ s : IncIdx k p, (A.submatrix r s.1).det * (B.submatrix s.1 c).det`! -/ theorem cauchy_binet_formula {R : Type*} [CommRing R] {m p n k : ℕ} (A : Matrix (Fin m) (Fin p) R) (B : Matrix (Fin p) (Fin n) R) (r : Fin k → Fin m) (c : Fin k → Fin n) : ((A * B).submatrix r c).det = ∑ s : IncIdx k p, (A.submatrix r s.1).det * (B.submatrix s.1 c).det := by classical -- Step 1: Expand `((A * B).submatrix r c).det` as a sum over all tuples `g : Fin k → Fin p`: -- `det (A_r * B_c) = ∑ g : Fin k → Fin p, (∏ i, A (r i) (g i)) * det (B.submatrix g c)`! have h1 : ((A * B).submatrix r c).det = ∑ g : Fin k → Fin p, (∏ i : Fin k, A (r i) (g i)) * (B.submatrix g c).det := by rw [Matrix.det_apply] have hrow : ∀ σ : Equiv.Perm (Fin k), ∏ j : Fin k, ((A * B).submatrix r c) (σ j) j = ∑ g : Fin k → Fin p, ∏ j : Fin k, A (r (σ j)) (g j) * B (g j) (c j) := by intro σ simp only [Matrix.submatrix_apply, Matrix.mul_apply] rw [Finset.prod_univ_sum, Fintype.piFinset_univ] simp_rw [hrow, Finset.smul_sum] have hreidx' : ∀ σ : Equiv.Perm (Fin k), ∑ g : Fin k → Fin p, Equiv.Perm.sign σ • ∏ j : Fin k, A (r (σ j)) (g j) * B (g j) (c j) = ∑ g : Fin k → Fin p, Equiv.Perm.sign σ • ((∏ i : Fin k, A (r i) (g i)) * ∏ j : Fin k, B (g (σ j)) (c j)) := by intro σ refine (Fintype.sum_equiv (Equiv.arrowCongr σ.symm (Equiv.refl (Fin p))) _ _ fun g => ?_).symm congr 1 have hg : ∀ j : Fin k, (Equiv.arrowCongr σ.symm (Equiv.refl (Fin p)) g) j = g (σ j) := fun _ => rfl simp_rw [hg, Finset.prod_mul_distrib] congr 1 exact (Equiv.prod_comp σ (fun i => A (r i) (g i))).symm simp_rw [hreidx'] rw [Finset.sum_comm] refine Finset.sum_congr rfl fun g _ => ?_ rw [Matrix.det_apply, Finset.mul_sum] refine Finset.sum_congr rfl fun σ _ => ?_ simp [Units.smul_def, zsmul_eq_mul, mul_left_comm] rw [h1] have hnoninj : ∀ g : Fin k → Fin p, ¬ Function.Injective g → (∏ i : Fin k, A (r i) (g i)) * (B.submatrix g c).det = 0 := by intro g hni unfold Function.Injective at hni push Not at hni rcases hni with ⟨i, j, hgi, hij⟩ have hdet0 : (B.submatrix g c).det = 0 := Matrix.det_zero_of_row_eq hij (by ext l; simp [Matrix.submatrix_apply, hgi]) rw [hdet0, mul_zero] rw [← Finset.sum_filter_add_sum_filter_not Finset.univ (fun g : Fin k → Fin p => Function.Injective g)] have hzero : ∑ g ∈ Finset.univ.filter (fun g : Fin k → Fin p => ¬ Function.Injective g), (∏ i : Fin k, A (r i) (g i)) * (B.submatrix g c).det = 0 := Finset.sum_eq_zero fun g hg => hnoninj g (Finset.mem_filter.mp hg).2 rw [hzero, add_zero] have hbij : ∑ g ∈ Finset.univ.filter (fun g : Fin k → Fin p => Function.Injective g), (∏ i : Fin k, A (r i) (g i)) * (B.submatrix g c).det = ∑ x : IncIdx k p × Equiv.Perm (Fin k), (∏ i : Fin k, A (r i) (x.1.1 (x.2 i))) * (B.submatrix (x.1.1 ∘ x.2) c).det := by symm refine Finset.sum_bij (fun (x : IncIdx k p × Equiv.Perm (Fin k)) _ => x.1.1 ∘ x.2) ?_ ?_ ?_ ?_ · intro x _ exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, x.1.2.injective.comp x.2.injective⟩ · intro ⟨s₁, τ₁⟩ _ ⟨s₂, τ₂⟩ _ h have himg : Set.range s₁.1 = Set.range s₂.1 := by ext y; simp only [Set.mem_range] constructor · rintro ⟨i, rfl⟩ exact ⟨τ₂ (τ₁.symm i), by have := congrFun h (τ₁.symm i); simpa using this.symm⟩ · rintro ⟨i, rfl⟩ exact ⟨τ₁ (τ₂.symm i), by have := congrFun h (τ₂.symm i); simpa using this⟩ have hs : s₁ = s₂ := Subtype.ext (strictMono_eq_of_range_eq s₁.2 s₂.2 himg) subst hs have hτ : τ₁ = τ₂ := by ext i; exact congrArg Fin.val (s₁.2.injective (congrFun h i)) rw [hτ] · intro g hg have hinj := (Finset.mem_filter.mp hg).2 let S := Finset.univ.image g have hcard : S.card = k := by rw [Finset.card_image_of_injective _ hinj, Finset.card_univ, Fintype.card_fin] let emb := S.orderEmbOfFin hcard let s : IncIdx k p := ⟨emb, emb.strictMono⟩ have hmem : ∀ i : Fin k, g i ∈ S := fun i => Finset.mem_image_of_mem g (Finset.mem_univ i) have hex : ∀ i : Fin k, ∃ j : Fin k, emb j = g i := by intro i have hrange := Finset.range_orderEmbOfFin S hcard have : g i ∈ Set.range emb := by rw [hrange]; exact hmem i exact this let fτ : Fin k → Fin k := fun i => Classical.choose (hex i) have hfτ_spec : ∀ i, emb (fτ i) = g i := fun i => Classical.choose_spec (hex i) have hfτ_inj : Function.Injective fτ := by intro i j hij; exact hinj (by rw [← hfτ_spec i, ← hfτ_spec j, hij]) let τ : Equiv.Perm (Fin k) := Equiv.ofBijective fτ (Finite.injective_iff_bijective.mp hfτ_inj) refine ⟨(s, τ), Finset.mem_univ _, ?_⟩ funext i; exact hfτ_spec i · intro _ _; rfl rw [hbij, Fintype.sum_prod_type] refine Finset.sum_congr rfl fun s _ => ?_ have hBperm : ∀ τ : Equiv.Perm (Fin k), (B.submatrix (s.1 ∘ τ) c).det = Equiv.Perm.sign τ • (B.submatrix s.1 c).det := by intro τ have hsub : B.submatrix (s.1 ∘ τ) c = (B.submatrix s.1 c).submatrix τ id := rfl rw [hsub, Matrix.det_permute, Units.smul_def, zsmul_eq_mul] simp_rw [hBperm] conv_rhs => rw [← Matrix.det_transpose (A.submatrix r s.1), Matrix.det_apply] rw [Finset.sum_mul] refine Finset.sum_congr rfl fun τ _ => ?_ simp only [Matrix.transpose_apply, Matrix.submatrix_apply, Units.smul_def, zsmul_eq_mul] ring /-- A matrix `A : Matrix (Fin m) (Fin n) R` is *totally nonnegative* (`IsTotallyNonneg`) if EVERY `k × k` minor with strictly increasing rows and columns is `≥ 0`. -/ def IsTotallyNonneg {R : Type*} [CommRing R] [LinearOrder R] {m n : ℕ} (A : Matrix (Fin m) (Fin n) R) : Prop := ∀ (k : ℕ) (r : IncIdx k m) (c : IncIdx k n), 0 ≤ (A.submatrix r.1 c.1).det /-- A matrix `A : Matrix (Fin m) (Fin n) R` is *totally positive* (`IsTotallyPos`) if EVERY `k × k` minor (`1 ≤ k ≤ min m n`) with strictly increasing rows and columns is `> 0`. -/ def IsTotallyPos {R : Type*} [CommRing R] [LinearOrder R] {m n : ℕ} (A : Matrix (Fin m) (Fin n) R) : Prop := ∀ (k : ℕ) (r : IncIdx k m) (c : IncIdx k n), 0 < (A.submatrix r.1 c.1).det /-- **THEOREM 7A — Cauchy–Binet Closure of Total Nonnegativity (`tn_mul_tn`)**: If `A` and `B` are totally nonnegative, then `A * B` is totally nonnegative! -/ theorem tn_mul_tn {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] {m p n : ℕ} {A : Matrix (Fin m) (Fin p) R} {B : Matrix (Fin p) (Fin n) R} (hA : IsTotallyNonneg A) (hB : IsTotallyNonneg B) : IsTotallyNonneg (A * B) := by intro k r c rw [cauchy_binet_formula] exact Finset.sum_nonneg fun s _ => mul_nonneg (hA k r s) (hB k s c) /-- **THEOREM 7B — Cauchy–Binet Closure of Total Positivity (`tp_mul_tp`)**: If `A : m × p` and `B : p × n` are totally positive and `min m n ≤ p` (e.g. square `n × n`), then `A * B` is totally positive! -/ theorem tp_mul_tp {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] {n : ℕ} {A B : Matrix (Fin n) (Fin n) R} (hA : IsTotallyPos A) (hB : IsTotallyPos B) : IsTotallyPos (A * B) := by intro k r c rw [cauchy_binet_formula] exact Finset.sum_pos (fun s _ => mul_pos (hA k r s) (hB k s c)) ⟨r, Finset.mem_univ r⟩ /-! ### 3A. Chevalley-Jacobi Elementary Generators & Exact `3 × 3` Whitney–Loewner Factorization -/ /-- Lower Chevalley-Jacobi elementary matrix `E_i(t) = I + t * E_{i+1, i}`. -/ def chevalleyLower {n : ℕ} {R : Type*} [CommRing R] (i : ℕ) (_hi : i + 1 < n) (t : R) : Matrix (Fin n) (Fin n) R := Matrix.of fun a b => if a = b then 1 else if a.1 = i + 1 ∧ b.1 = i then t else 0 /-- Upper Chevalley-Jacobi elementary matrix `F_i(t) = I + t * E_{i, i+1}`. -/ def chevalleyUpper {n : ℕ} {R : Type*} [CommRing R] (i : ℕ) (hi : i + 1 < n) (t : R) : Matrix (Fin n) (Fin n) R := (chevalleyLower i hi t).transpose /-- Diagonal matrix `D(d)`. -/ def diagMat {n : ℕ} {R : Type*} [CommRing R] (d : Fin n → R) : Matrix (Fin n) (Fin n) R := Matrix.diagonal d lemma tn_transpose {R : Type*} [CommRing R] [LinearOrder R] {m n : ℕ} {A : Matrix (Fin m) (Fin n) R} (hA : IsTotallyNonneg A) : IsTotallyNonneg A.transpose := by intro k r c have : (A.transpose.submatrix r.1 c.1).det = (A.submatrix c.1 r.1).det := by rw [← Matrix.det_transpose]; rfl rw [this]; exact hA k c r /-- Every nonnegative diagonal matrix `D(d)` (`d_i ≥ 0`) is totally nonnegative! -/ theorem diagMat_tn {n : ℕ} {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (d : Fin n → R) (hd : ∀ i, 0 ≤ d i) : IsTotallyNonneg (diagMat d) := by intro k r c by_cases hrc : r.1 = c.1 · have hdiag : (diagMat d).submatrix r.1 c.1 = Matrix.diagonal (fun j => d (r.1 j)) := by ext a b simp only [Matrix.submatrix_apply, diagMat, Matrix.diagonal_apply, hrc] by_cases hab : a = b · subst hab; simp · simp [hab, c.2.injective.ne hab] rw [hdiag, Matrix.det_diagonal] exact Finset.prod_nonneg fun j _ => hd _ · -- If `r.1 ≠ c.1`, pick an index `j` where `r.1 j ≠ c.1 j`: in fact, either some `r.1 j ∉ range c.1` (zero row!) -- or `range r.1 = range c.1` which by `StrictMono` forces `r.1 = c.1`! have hex : ∃ a : Fin k, ∀ b : Fin k, r.1 a ≠ c.1 b := by by_contra hall push Not at hall have hsub : Finset.univ.image r.1 ⊆ Finset.univ.image c.1 := by intro y hy rcases Finset.mem_image.mp hy with ⟨a, _, rfl⟩ rcases hall a with ⟨b, hb⟩ exact Finset.mem_image.mpr ⟨b, Finset.mem_univ b, hb.symm⟩ have heq_set : Finset.univ.image r.1 = Finset.univ.image c.1 := Finset.eq_of_subset_of_card_le hsub (by rw [Finset.card_image_of_injective _ r.2.injective, Finset.card_image_of_injective _ c.2.injective]) have hrange : Set.range r.1 = Set.range c.1 := by ext y; simpa [Finset.mem_image] using Finset.ext_iff.mp heq_set y exact hrc (strictMono_eq_of_range_eq r.2 c.2 hrange) rcases hex with ⟨a, ha⟩ have hdet0 : ((diagMat d).submatrix r.1 c.1).det = 0 := Matrix.det_eq_zero_of_row_eq_zero a fun b => by simp [Matrix.submatrix_apply, diagMat, ha b] rw [hdet0] /-- **THEOREM 8A — Every Elementary Chevalley-Jacobi Matrix `E_i(t), F_i(t)` (`t ≥ 0`) is Totally Nonnegative (`chevalleyLower_tn`, `chevalleyUpper_tn`)**: Every minor of `E_i(t)` equals `0`, `1`, or `t`! -/ theorem chevalleyLower_tn {n : ℕ} {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (i : ℕ) (hi : i + 1 < n) {t : R} (ht : 0 ≤ t) : IsTotallyNonneg (chevalleyLower i hi t) := by intro k r c -- Every entry `(chevalleyLower i hi t) (r a) (c b)` is nonzero ONLY if `r a = c b` (giving `1`) -- or `(r a).1 = i + 1 ∧ (c b).1 = i` (giving `t`)! -- Show in `Matrix.det_apply` that EVERY `σ : Equiv.Perm (Fin k)` with `∏ b, M (σ b) b ≠ 0` MUST be `σ = 1`! have honly1 : ∀ σ : Equiv.Perm (Fin k), σ ≠ 1 → ∏ b : Fin k, (chevalleyLower i hi t).submatrix r.1 c.1 (σ b) b = 0 := by intro σ hne by_contra hprod have hnz : ∀ b : Fin k, (chevalleyLower i hi t) (r.1 (σ b)) (c.1 b) ≠ 0 := fun b h0 => hprod (Finset.prod_eq_zero (Finset.mem_univ b) h0) -- Every `b` satisfies EITHER `r (σ b) = c b` OR `(r (σ b)).1 = i + 1 ∧ (c b).1 = i`! -- In BOTH cases, `(c b).1 ≤ (r (σ b)).1` AND in fact `r (σ b) ≤ c b + 1`! -- Specifically, `σ` MUST be strictly increasing? Wait: check if `(r (σ b)).1` is strictly increasing in `b`! have hle : ∀ b : Fin k, (r.1 (σ b)).1 = (c.1 b).1 ∨ ((r.1 (σ b)).1 = i + 1 ∧ (c.1 b).1 = i) := by intro b have hb := hnz b simp only [chevalleyLower, Matrix.of_apply] at hb split_ifs at hb with h1 h2 · left; exact congrArg Fin.val h1 · right; exact h2 · exact absurd rfl hb -- Since `c` is strictly increasing, `b₁ < b₂ → (c b₁).1 < (c b₂).1`! -- Could `(r (σ b₂)).1 ≤ (r (σ b₁)).1` for some `b₁ < b₂`? -- Check all 4 combinations of `hle b₁` and `hle b₂`: -- Only possible if `(r (σ b₁)).1 = i + 1, (c b₁).1 = i` AND `(r (σ b₂)).1 = (c b₂).1 = i + 1`! -- THEN `r (σ b₁) = r (σ b₂)` contradicting injectivity of `r ∘ σ`!! -- SO `b ↦ r (σ b)` IS STRICTLY INCREASING, WHICH MEANS `σ` IS STRICTLY INCREASING, SO `σ = 1`!! have hmono : StrictMono (r.1 ∘ σ) := by intro b₁ b₂ hlt have hc : (c.1 b₁).1 < (c.1 b₂).1 := c.2 hlt have hne_r : (r.1 (σ b₁)).1 ≠ (r.1 (σ b₂)).1 := fun heq => ne_of_lt hlt (σ.injective (r.2.injective (Fin.ext heq))) rcases hle b₁ with h1 | ⟨h1a, h1b⟩ <;> rcases hle b₂ with h2 | ⟨h2a, h2b⟩ · show (r.1 (σ b₁)).1 < (r.1 (σ b₂)).1; omega · show (r.1 (σ b₁)).1 < (r.1 (σ b₂)).1; omega · show (r.1 (σ b₁)).1 < (r.1 (σ b₂)).1; omega · show (r.1 (σ b₁)).1 < (r.1 (σ b₂)).1; omega have hσ_mono : StrictMono σ := fun b₁ b₂ hlt => r.2.lt_iff_lt.mp (hmono hlt) have hσ_ge : ∀ b : Fin k, b ≤ σ b := by intro ⟨b, hb⟩; induction b with | zero => exact Nat.zero_le _ | succ m ih => exact Nat.succ_le_of_lt (lt_of_le_of_lt (ih (by omega)) (hσ_mono (show (⟨m, by omega⟩ : Fin k) < ⟨m + 1, hb⟩ from Nat.lt_succ_self m))) have hσ1 : σ = 1 := by ext b; by_contra hneb have hneb' : σ b ≠ b := fun h => hneb (by simp [h]) have hsum : ∑ j : Fin k, (σ j).1 = ∑ j : Fin k, j.1 := Equiv.sum_comp σ (fun j : Fin k => j.1) have hgt : ∑ j : Fin k, j.1 < ∑ j : Fin k, (σ j).1 := Finset.sum_lt_sum (fun j _ => Fin.le_def.mp (hσ_ge j)) ⟨b, Finset.mem_univ b, Fin.lt_def.mp (lt_of_le_of_ne (hσ_ge b) (Ne.symm hneb'))⟩ omega exact hne hσ1 rw [Matrix.det_apply] rw [Finset.sum_eq_single 1 (fun σ _ hne => by rw [honly1 σ hne, smul_zero]) (fun h => absurd (Finset.mem_univ 1) h)] simp only [map_one, one_smul, Equiv.Perm.coe_one, id_eq] apply Finset.prod_nonneg intro b _ simp only [Matrix.submatrix_apply, chevalleyLower, Matrix.of_apply] split_ifs · exact zero_le_one · exact ht · exact le_rfl theorem chevalleyUpper_tn {n : ℕ} {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (i : ℕ) (hi : i + 1 < n) {t : R} (ht : 0 ≤ t) : IsTotallyNonneg (chevalleyUpper i hi t) := tn_transpose (chevalleyLower_tn i hi ht) /-- **THEOREM 8B — Every Whitney–Loewner Product of Nonnegative Chevalley Generators & Positive Diagonal Matrices is Totally Nonnegative (`whitney_loewner_product_tn`)**: -/ theorem whitney_loewner_product_tn {n : ℕ} {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (L : List (Matrix (Fin n) (Fin n) R)) (hL : ∀ M ∈ L, IsTotallyNonneg M) : IsTotallyNonneg L.prod := by induction L with | nil => have h1 : (1 : Matrix (Fin n) (Fin n) R) = diagMat (fun _ => 1) := by ext i j; simp [Matrix.one_apply, diagMat, Matrix.diagonal_apply] simpa [h1] using diagMat_tn (fun _ : Fin n => (1 : R)) (fun _ => zero_le_one) | cons M Ms ih => rw [List.prod_cons] exact tn_mul_tn (hL M (List.mem_cons_self ..)) (ih fun X hX => hL X (List.mem_cons_of_mem M hX)) /-- **THEOREM 9 — Exact `3 × 3` Whitney–Loewner Positive Factorization Theorem (`whitney_loewner_3x3_factorization`)**: EVERY totally positive `3 × 3` matrix `A` over a linearly ordered field `K` admits an EXPLICIT factorization `A = E₁(a) * E₀(b) * E₁(c) * D(d₀, d₁, d₂) * F₁(e) * F₀(f) * F₁(g)` with ALL 9 parameters `a, b, c, d₀, d₁, d₂, e, f, g > 0`! -/ theorem whitney_loewner_3x3_factorization {K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (A : Matrix (Fin 3) (Fin 3) K) (hA : IsTotallyPos A) : ∃ (a b c d₀ d₁ d₂ e f g : K), 0 < a ∧ 0 < b ∧ 0 < c ∧ 0 < d₀ ∧ 0 < d₁ ∧ 0 < d₂ ∧ 0 < e ∧ 0 < f ∧ 0 < g ∧ A = chevalleyLower 1 (by omega) a * chevalleyLower 0 (by omega) b * chevalleyLower 1 (by omega) c * diagMat ![d₀, d₁, d₂] * chevalleyUpper 1 (by omega) e * chevalleyUpper 0 (by omega) f * chevalleyUpper 1 (by omega) g := by -- Extract positivity of the relevant `1 × 1`, `2 × 2`, and `3 × 3` minors of `A`! have h1 : ∀ r c : Fin 3, 0 < A r c := by intro r c have h := hA 1 ⟨fun _ => r, fun x y h => by fin_cases x; fin_cases y; simp at h⟩ ⟨fun _ => c, fun x y h => by fin_cases x; fin_cases y; simp at h⟩ simpa [Matrix.det_fin_one] using h have h2 : ∀ (r₀ r₁ c₀ c₁ : Fin 3), r₀ < r₁ → c₀ < c₁ → 0 < A r₀ c₀ * A r₁ c₁ - A r₀ c₁ * A r₁ c₀ := by intro r₀ r₁ c₀ c₁ hr hc have h := hA 2 ⟨![r₀, r₁], by intro x y hxy; fin_cases x <;> fin_cases y <;> simp_all⟩ ⟨![c₀, c₁], by intro x y hxy; fin_cases x <;> fin_cases y <;> simp_all⟩ simp only [Matrix.det_fin_two, Matrix.submatrix_apply, Matrix.cons_val_zero, Matrix.cons_val_one] at h exact h have h3 : 0 < A.det := by have h := hA 3 ⟨id, strictMono_id⟩ ⟨id, strictMono_id⟩ simpa using h set Δ01 := A 0 0 * A 1 1 - A 0 1 * A 1 0 set ΔL := A 1 0 * A 2 1 - A 1 1 * A 2 0 set ΔU := A 0 1 * A 1 2 - A 0 2 * A 1 1 have hA00 : 0 < A 0 0 := h1 0 0 have hA10 : 0 < A 1 0 := h1 1 0 have hA20 : 0 < A 2 0 := h1 2 0 have hA01 : 0 < A 0 1 := h1 0 1 have hA02 : 0 < A 0 2 := h1 0 2 have hΔ01 : 0 < Δ01 := h2 0 1 0 1 (by decide) (by decide) have hΔL : 0 < ΔL := h2 1 2 0 1 (by decide) (by decide) have hΔU : 0 < ΔU := h2 0 1 1 2 (by decide) (by decide) let a : K := A 2 0 / A 1 0 let b : K := A 1 0 / A 0 0 let c : K := A 0 0 * ΔL / (A 1 0 * Δ01) let d₀ : K := A 0 0 let d₁ : K := Δ01 / A 0 0 let d₂ : K := A.det / Δ01 let e : K := A 0 0 * ΔU / (A 0 1 * Δ01) let f : K := A 0 1 / A 0 0 let g : K := A 0 2 / A 0 1 refine ⟨a, b, c, d₀, d₁, d₂, e, f, g, div_pos hA20 hA10, div_pos hA10 hA00, div_pos (mul_pos hA00 hΔL) (mul_pos hA10 hΔ01), hA00, div_pos hΔ01 hA00, div_pos h3 hΔ01, div_pos (mul_pos hA00 hΔU) (mul_pos hA01 hΔ01), div_pos hA01 hA00, div_pos hA02 hA01, ?_⟩ have hA00_ne : A 0 0 ≠ 0 := ne_of_gt hA00 have hA10_ne : A 1 0 ≠ 0 := ne_of_gt hA10 have hA01_ne : A 0 1 ≠ 0 := ne_of_gt hA01 have hΔ01_ne : Δ01 ≠ 0 := ne_of_gt hΔ01 have hL : chevalleyLower 1 (by omega) a * chevalleyLower 0 (by omega) b * chevalleyLower 1 (by omega) c = !![(1 : K), 0, 0; b, 1, 0; a * b, a + c, 1] := by ext i j fin_cases i <;> fin_cases j <;> simp [Matrix.mul_apply, Fin.sum_univ_three, chevalleyLower] have hU : chevalleyUpper 1 (by omega) e * chevalleyUpper 0 (by omega) f * chevalleyUpper 1 (by omega) g = !![(1 : K), f, f * g; 0, 1, e + g; 0, 0, 1] := by ext i j fin_cases i <;> fin_cases j <;> (simp [Matrix.mul_apply, Fin.sum_univ_three, chevalleyUpper, chevalleyLower]; try ring) have hLD : !![(1 : K), 0, 0; b, 1, 0; a * b, a + c, 1] * diagMat ![d₀, d₁, d₂] = !![d₀, 0, 0; b * d₀, d₁, 0; a * b * d₀, (a + c) * d₁, d₂] := by ext i j fin_cases i <;> fin_cases j <;> simp [Matrix.mul_apply, Fin.sum_univ_three, diagMat] have hLDU : !![d₀, 0, 0; b * d₀, d₁, 0; a * b * d₀, (a + c) * d₁, d₂] * !![(1 : K), f, f * g; 0, 1, e + g; 0, 0, 1] = !![d₀, d₀ * f, d₀ * f * g; b * d₀, b * d₀ * f + d₁, b * d₀ * f * g + d₁ * (e + g); a * b * d₀, a * b * d₀ * f + (a + c) * d₁, a * b * d₀ * f * g + (a + c) * d₁ * (e + g) + d₂] := by ext i j fin_cases i <;> fin_cases j <;> simp [Matrix.mul_apply, Fin.sum_univ_three] <;> ring have hRHS : chevalleyLower 1 (by omega) a * chevalleyLower 0 (by omega) b * chevalleyLower 1 (by omega) c * diagMat ![d₀, d₁, d₂] * chevalleyUpper 1 (by omega) e * chevalleyUpper 0 (by omega) f * chevalleyUpper 1 (by omega) g = !![d₀, d₀ * f, d₀ * f * g; b * d₀, b * d₀ * f + d₁, b * d₀ * f * g + d₁ * (e + g); a * b * d₀, a * b * d₀ * f + (a + c) * d₁, a * b * d₀ * f * g + (a + c) * d₁ * (e + g) + d₂] := by rw [hL, Matrix.mul_assoc (_ * diagMat _), Matrix.mul_assoc (_ * diagMat _), hU, hLD, hLDU] rw [hRHS] ext i j fin_cases i <;> fin_cases j · change A 0 0 = d₀; rfl · change A 0 1 = d₀ * f; simp only [d₀, f]; field_simp [hA00_ne] · change A 0 2 = d₀ * f * g; simp only [d₀, f, g]; field_simp [hA00_ne, hA01_ne] · change A 1 0 = b * d₀; simp only [b, d₀]; field_simp [hA00_ne] · change A 1 1 = b * d₀ * f + d₁; simp only [b, d₀, f, d₁, Δ01]; field_simp [hA00_ne]; ring · change A 1 2 = b * d₀ * f * g + d₁ * (e + g) simp only [b, d₀, f, g, d₁, e]; field_simp [hA00_ne, hA01_ne, hΔ01_ne] simp only [Δ01, ΔU]; ring · change A 2 0 = a * b * d₀; simp only [a, b, d₀]; field_simp [hA00_ne, hA10_ne] · change A 2 1 = a * b * d₀ * f + (a + c) * d₁ simp only [a, b, c, d₀, f, d₁]; field_simp [hA00_ne, hA10_ne, hΔ01_ne] simp only [Δ01, ΔL]; ring · change A 2 2 = a * b * d₀ * f * g + (a + c) * d₁ * (e + g) + d₂ simp only [a, b, c, d₀, f, g, d₁, d₂, e]; field_simp [hA00_ne, hA10_ne, hA01_ne, hΔ01_ne] simp only [Δ01, ΔL, ΔU, Matrix.det_fin_three]; ring /-! ## 4. Grassmannian `Gr(2, n)` Plücker Relations & Totally Positive Cluster Realization -/ /-- The `(i, j)` Plücker coordinate `p_{i, j}(M) = M_{0, i} M_{1, j} - M_{1, i} M_{0, j}` of a `2 × n` matrix `M` over a commutative ring `R`. -/ def plucker {R : Type*} [CommRing R] {n : ℕ} (M : Matrix (Fin 2) (Fin n) R) (i j : Fin n) : R := M 0 i * M 1 j - M 1 i * M 0 j theorem plucker_skew {R : Type*} [CommRing R] {n : ℕ} (M : Matrix (Fin 2) (Fin n) R) (i j : Fin n) : plucker M j i = - plucker M i j := by unfold plucker; ring theorem plucker_self {R : Type*} [CommRing R] {n : ℕ} (M : Matrix (Fin 2) (Fin n) R) (i : Fin n) : plucker M i i = 0 := by unfold plucker; ring /-- **THEOREM 10A — `SL₂`-Covariance of Grassmannian `Gr(2, n)` Plücker Coordinates**: -/ theorem plucker_sl2_invariant {R : Type*} [CommRing R] {n : ℕ} (g : Matrix (Fin 2) (Fin 2) R) (M : Matrix (Fin 2) (Fin n) R) (i j : Fin n) : plucker (g * M) i j = g.det * plucker M i j := by unfold plucker simp only [Matrix.mul_apply, Fin.sum_univ_two, Matrix.det_fin_two] ring /-- **THEOREM 10B — Exact Grassmannian `Gr(2, n)` 3-Term Plücker / Cluster Exchange Relation (`grassmannian_gr2n_plucker_relation`)**: For EVERY `2 × n` matrix `M` over ANY commutative ring `R` and EVERY `i, j, k, l : Fin n`, `p_{i, k} * p_{j, l} = p_{i, j} * p_{k, l} + p_{i, l} * p_{j, k}`! -/ theorem grassmannian_gr2n_plucker_relation {R : Type*} [CommRing R] {n : ℕ} (M : Matrix (Fin 2) (Fin n) R) (i j k l : Fin n) : plucker M i k * plucker M j l = plucker M i j * plucker M k l + plucker M i l * plucker M j k := by unfold plucker; ring /-- **THEOREM 10C — Preservation of Positivity under `Gr(2, n)` Cluster Mutation**: -/ theorem gr2n_tp_preserved_by_mutation {K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {n : ℕ} (M : Matrix (Fin 2) (Fin n) K) (i j k l : Fin n) (hij : 0 < plucker M i j) (hjk : 0 < plucker M j k) (hkl : 0 < plucker M k l) (hil : 0 < plucker M i l) (hik : 0 < plucker M i k) : 0 < plucker M j l ∧ plucker M j l = (plucker M i j * plucker M k l + plucker M i l * plucker M j k) / plucker M i k := by have hrel := grassmannian_gr2n_plucker_relation M i j k l have heq : plucker M j l = (plucker M i j * plucker M k l + plucker M i l * plucker M j k) / plucker M i k := by rw [eq_div_iff (ne_of_gt hik), mul_comm]; exact hrel refine ⟨?_, heq⟩ rw [heq] exact div_pos (add_pos (mul_pos hij hkl) (mul_pos hil hjk)) hik /-- **THEOREM 10D — Exact Fan-Cluster Positive Laurent Formula for ALL `Gr(2, n)` Plücker Coordinates (`gr2n_plucker_fan_laurent`)**: For ANY `2 × (n + 3)` matrix `M` over a field `K` whose fan Plücker coordinates `p_{0, k}` (`1 ≤ k ≤ n + 2`) are nonzero, EVERY Plücker coordinate `p_{i, j}` (`1 ≤ i < j ≤ n + 2`) is given by the EXACT positive sum over the `j - i` fan snake-graph matchings: `p_{i, j} = p_{0, i} * p_{0, j} * ∑_{k ∈ [i, j)} p_{k, k + 1} / (p_{0, k} * p_{0, k + 1})`! -/ theorem gr2n_plucker_fan_laurent {K : Type*} [Field K] {n : ℕ} (M : Matrix (Fin 2) (Fin (n + 3)) K) (hfan : ∀ k : Fin (n + 3), 1 ≤ k.1 → plucker M ⟨0, by omega⟩ k ≠ 0) (i j : Fin (n + 3)) (hi : 1 ≤ i.1) (hij : i ≤ j) : plucker M i j = plucker M ⟨0, by omega⟩ i * plucker M ⟨0, by omega⟩ j * ∑ k ∈ Finset.Ico i.1 j.1, if hk : k + 1 < n + 3 then plucker M ⟨k, by omega⟩ ⟨k + 1, hk⟩ / (plucker M ⟨0, by omega⟩ ⟨k, by omega⟩ * plucker M ⟨0, by omega⟩ ⟨k + 1, hk⟩) else 0 := by -- Prove by telescoping on `d = j.1 - i.1`! have htele : ∀ (d : ℕ) (j : Fin (n + 3)), i.1 + d = j.1 → plucker M i j / (plucker M ⟨0, by omega⟩ i * plucker M ⟨0, by omega⟩ j) = ∑ k ∈ Finset.Ico i.1 j.1, if hk : k + 1 < n + 3 then plucker M ⟨k, by omega⟩ ⟨k + 1, hk⟩ / (plucker M ⟨0, by omega⟩ ⟨k, by omega⟩ * plucker M ⟨0, by omega⟩ ⟨k + 1, hk⟩) else 0 := by intro d induction d with | zero => intro j hj have hij_eq : i = j := Fin.ext (by omega) subst hij_eq simp [plucker_self] | succ d ih => intro j hj let prev : Fin (n + 3) := ⟨i.1 + d, by have := j.2; omega⟩ have hj_eq : j = ⟨i.1 + d + 1, by have := j.2; omega⟩ := Fin.ext (by dsimp; omega) have hprev_ge : 1 ≤ prev.1 := by dsimp [prev]; omega have h0i : plucker M ⟨0, by omega⟩ i ≠ 0 := hfan i hi have h0p : plucker M ⟨0, by omega⟩ prev ≠ 0 := hfan prev hprev_ge have h0j : plucker M ⟨0, by omega⟩ j ≠ 0 := hfan j (by omega) have hpl := grassmannian_gr2n_plucker_relation M ⟨0, by omega⟩ i prev j -- `p_{0, prev} * p_{i, j} = p_{0, i} * p_{prev, j} + p_{0, j} * p_{i, prev}`! have hstep : plucker M i j / (plucker M ⟨0, by omega⟩ i * plucker M ⟨0, by omega⟩ j) = plucker M i prev / (plucker M ⟨0, by omega⟩ i * plucker M ⟨0, by omega⟩ prev) + plucker M prev j / (plucker M ⟨0, by omega⟩ prev * plucker M ⟨0, by omega⟩ j) := by field_simp [h0i, h0p, h0j] linear_combination hpl rw [hstep, ih prev rfl] have hIco : Finset.Ico i.1 j.1 = insert (i.1 + d) (Finset.Ico i.1 (i.1 + d)) := by ext x; simp only [Finset.mem_Ico, Finset.mem_insert]; omega rw [hIco, Finset.sum_insert (by simp), add_comm] congr 1 rw [dif_pos (by have := j.2; omega)] have heq1 : (⟨i.1 + d, by have := j.2; omega⟩ : Fin (n + 3)) = prev := rfl have heq2 : (⟨i.1 + d + 1, by have := j.2; omega⟩ : Fin (n + 3)) = j := hj_eq.symm rw [heq1, heq2] have h0i : plucker M ⟨0, by omega⟩ i ≠ 0 := hfan i hi have h0j : plucker M ⟨0, by omega⟩ j ≠ 0 := hfan j (by have : i.1 ≤ j.1 := hij; omega) have ht := htele (j.1 - i.1) j (by have : i.1 ≤ j.1 := hij; omega) rw [← ht, mul_div_cancel₀ _ (mul_ne_zero h0i h0j)] /-! ## 5. Axiom Verification -/ #print axioms lgv_lemma #print axioms lgv_planar_nonneg #print axioms pascal_grid_det_nonneg #print axioms desnanot_jacobi_identity #print axioms dodgson_condensation #print axioms cauchy_binet_formula #print axioms tn_mul_tn #print axioms tp_mul_tp #print axioms diagMat_tn #print axioms chevalleyLower_tn #print axioms chevalleyUpper_tn #print axioms whitney_loewner_product_tn #print axioms whitney_loewner_3x3_factorization #print axioms plucker_skew #print axioms plucker_sl2_invariant #print axioms grassmannian_gr2n_plucker_relation #print axioms gr2n_tp_preserved_by_mutation #print axioms gr2n_plucker_fan_laurent end TotalPositivityLGVAndGrassmannian