import Mathlib /-! # Constructive Robinson–Schensted Bijection, Schensted's LIS Theorem & Erdős–Szekeres Self-contained Lean 4 formalization (Mathlib only): 1. Integer partitions `IntPart n`, list-of-rows tableaux, `IsSSYT`, `IsStrictTab`, and standard Young tableaux `SYT λ` (entries exactly `0, …, n-1`). 2. Constructive Schensted row insertion (`rowInsert`, `tabInsert`) and exact reverse bumping (`rowRevBump`, `tabRevBump`), proved mutually inverse at every outer corner (`tabRevBump_tabInsert`, `tabInsert_tabRevBump`), preserving semistandardness. 3. **Robinson–Schensted bijection** `rsBijection n : Equiv.Perm (Fin n) ≃ Σ λ, SYT λ × SYT λ` (forward map = insertion, inverse map = reverse bumping) and the **Frobenius–Schur identity** `∑_{λ ⊢ n} (f^λ)² = n!`. 4. **Schensted's theorem (first row)**: `λ₁(P(w))` = length of the longest (weakly) increasing subsequence of any word `w` (strictly increasing for permutations), via the patience-sorting invariant of the first row. 5. **Erdős–Szekeres theorem** `|w| ≤ LIS(w) · LDS(w)` derived from the RS first row together with its patience piles (strictly decreasing subsequences), plus an explicit **sharp rectangular witness** in `S_{rs}` with `LIS = r`, `LDS = s` for all `r, s ≥ 1`. 6. **Schützenberger symmetry** `P(w⁻¹) = Q(w)`, `Q(w⁻¹) = P(w)` proved for **all `n : ℕ`** and **all `w ∈ S_n`** via Fomin's local growth-diagram rules (`fominStep`, `fominGrid`), yielding the universal **involution bijection** `{w ∈ S_n // w² = 1} ≃ Σ λ, SYT λ` and the **involution identity** `∑_{λ ⊢ n} f^λ = #{w ∈ S_n : w² = 1}` for every `n : ℕ`. Not formalized here (verified numerically in `verify_schur_rsk.py`): the column/LDS half of Schensted's theorem and Greene's theorem for `k ≥ 2`. -/ namespace CombinatorialHopfRSK open Finset /-! ## Section 1: Integer Partitions and Conjugate Partitions -/ /-- An integer partition of `n` represented as a weakly decreasing list of positive integers. -/ @[ext] structure IntPart (n : ℕ) where parts : List ℕ pos : ∀ p ∈ parts, 0 < p anti : parts.Pairwise (· ≥ ·) sum_eq : parts.sum = n deriving DecidableEq /-- `r`-th part of a list of row lengths (0 beyond the end). -/ def partAt (l : List ℕ) (r : ℕ) : ℕ := l.getD r 0 lemma length_le_sum_of_pos : ∀ {l : List ℕ}, (∀ p ∈ l, 0 < p) → l.length ≤ l.sum | [], _ => le_rfl | a :: rest, h => by have ha : 1 ≤ a := h a (by simp) have hr := length_le_sum_of_pos (l := rest) (fun p hp => h p (List.mem_cons_of_mem a hp)) simp only [List.length_cons, List.sum_cons] omega lemma mem_le_sum : ∀ {l : List ℕ} {x : ℕ}, x ∈ l → x ≤ l.sum | [], _, h => by simp at h | a :: rest, x, h => by simp only [List.mem_cons] at h rcases h with rfl | h · simp · exact le_trans (mem_le_sum h) (by simp) lemma partAt_le_sum (l : List ℕ) (r : ℕ) : partAt l r ≤ l.sum := by unfold partAt by_cases h : r < l.length · rw [List.getD_eq_getElem _ _ h] exact mem_le_sum (List.getElem_mem h) · rw [List.getD_eq_default _ _ (Nat.le_of_not_lt h)] exact Nat.zero_le _ lemma partAt_eq_zero_of_ge {l : List ℕ} {r : ℕ} (h : l.length ≤ r) : partAt l r = 0 := List.getD_eq_default _ _ h lemma list_eq_of_partAt_eq : ∀ {l₁ l₂ : List ℕ}, (∀ p ∈ l₁, 0 < p) → (∀ p ∈ l₂, 0 < p) → (∀ r, partAt l₁ r = partAt l₂ r) → l₁ = l₂ | [], [], _, _, _ => rfl | [], b :: bs, _, h₂, heq => by have h0 := heq 0 simp [partAt] at h0 have hb := h₂ b (by simp) omega | a :: as, [], h₁, _, heq => by have h0 := heq 0 simp [partAt] at h0 have ha := h₁ a (by simp) omega | a :: as, b :: bs, h₁, h₂, heq => by have h0 := heq 0 simp [partAt] at h0 subst h0 congr 1 apply list_eq_of_partAt_eq (fun p hp => h₁ p (by simp [hp])) (fun p hp => h₂ p (by simp [hp])) intro r simpa [partAt] using heq (r + 1) noncomputable instance instFintypeIntPart (n : ℕ) : Fintype (IntPart n) := by refine Fintype.ofInjective (fun (p : IntPart n) (i : Fin n) => (⟨partAt p.parts i.1, by have h1 := partAt_le_sum p.parts i.1 have h2 := p.sum_eq omega⟩ : Fin (n + 1))) ?_ intro p₁ p₂ h ext1 apply list_eq_of_partAt_eq p₁.pos p₂.pos intro r by_cases hr : r < n · exact congrArg (fun f => (f ⟨r, hr⟩).1) h · have h1 : p₁.parts.length ≤ r := by have := length_le_sum_of_pos p₁.pos; have hs := p₁.sum_eq; omega have h2 : p₂.parts.length ≤ r := by have := length_le_sum_of_pos p₂.pos; have hs := p₂.sum_eq; omega rw [partAt_eq_zero_of_ge h1, partAt_eq_zero_of_ge h2] /-! ## Section 2: Tableaux, Semistandard & Standard Young Tableaux -/ /-- Column-strictness and weakly decreasing row lengths for a list of rows. -/ def IsColChain : List (List ℕ) → Prop | [] => True | [_] => True | r₁ :: r₂ :: rest => r₂.length ≤ r₁.length ∧ (∀ j (h₂ : j < r₂.length) (h₁ : j < r₁.length), r₁[j] < r₂[j]) ∧ IsColChain (r₂ :: rest) /-- A Semistandard Young Tableau represented as a list of nonempty rows. -/ def IsSSYT (T : List (List ℕ)) : Prop := (∀ r ∈ T, r ≠ []) ∧ (∀ r ∈ T, r.Pairwise (· ≤ ·)) ∧ IsColChain T /-- A Strict Tableau (both rows and columns strictly increasing). -/ def IsStrictTab (T : List (List ℕ)) : Prop := (∀ r ∈ T, r ≠ []) ∧ (∀ r ∈ T, r.Pairwise (· < ·)) ∧ IsColChain T lemma IsStrictTab.isSSYT {T : List (List ℕ)} (h : IsStrictTab T) : IsSSYT T := ⟨h.1, fun r hr => (h.2.1 r hr).imp (fun hab => Nat.le_of_lt hab), h.2.2⟩ lemma isColChain_lengths_pairwise : ∀ {T : List (List ℕ)}, IsColChain T → (T.map List.length).Pairwise (· ≥ ·) | [], _ => List.Pairwise.nil | [_], _ => List.Pairwise.cons (by simp) List.Pairwise.nil | r₁ :: r₂ :: rest, ⟨hlen, _, hrest⟩ => by have htail := isColChain_lengths_pairwise hrest simp only [List.map_cons, List.pairwise_cons] at htail ⊢ refine ⟨?_, htail⟩ intro x hx simp only [List.mem_cons] at hx rcases hx with rfl | hx · exact hlen · exact le_trans (htail.1 x hx) hlen lemma pairwise_lt_of_pairwise_le_nodup : ∀ {r : List ℕ}, r.Pairwise (· ≤ ·) → r.Nodup → r.Pairwise (· < ·) | [], _, _ => List.Pairwise.nil | a :: rest, hle, hnd => by simp only [List.pairwise_cons, List.nodup_cons] at hle hnd ⊢ refine ⟨?_, pairwise_lt_of_pairwise_le_nodup hle.2 hnd.2⟩ intro b hb have h1 := hle.1 b hb have hne : a ≠ b := fun h => hnd.1 (h ▸ hb) omega lemma isStrictTab_of_isSSYT_nodup {T : List (List ℕ)} (h : IsSSYT T) (hnd : T.flatten.Nodup) : IsStrictTab T := by refine ⟨h.1, ?_, h.2.2⟩ intro r hr have hr_nd : r.Nodup := by induction T with | nil => simp at hr | cons a rest ih => simp only [List.flatten_cons, List.nodup_append] at hnd simp only [List.mem_cons] at hr rcases hr with rfl | hr · exact hnd.1 · exact ih ⟨fun s hs => h.1 s (List.mem_cons_of_mem a hs), fun s hs => h.2.1 s (List.mem_cons_of_mem a hs), by cases rest with | nil => trivial | cons b rest' => exact h.2.2.2.2⟩ hnd.2.1 hr exact pairwise_lt_of_pairwise_le_nodup (h.2.1 r hr) hr_nd /-- Standard Young Tableau of shape `lam : IntPart n` with entries `0, 1, ..., n - 1`. -/ @[ext] structure SYT {n : ℕ} (lam : IntPart n) where rows : List (List ℕ) shape_eq : rows.map List.length = lam.parts strict : IsStrictTab rows perm_range : rows.flatten.Perm (List.range n) deriving DecidableEq lemma syt_entry_lt {n : ℕ} {lam : IntPart n} (T : SYT lam) {r : List ℕ} (hr : r ∈ T.rows) {x : ℕ} (hx : x ∈ r) : x < n := by have hmem : x ∈ T.rows.flatten := List.mem_flatten.mpr ⟨r, hr, hx⟩ exact List.mem_range.mp (T.perm_range.subset hmem) lemma list_eq_of_getD_eq {n : ℕ} : ∀ {l₁ l₂ : List ℕ}, (∀ x ∈ l₁, x < n) → (∀ x ∈ l₂, x < n) → (∀ j, l₁.getD j n = l₂.getD j n) → l₁ = l₂ | [], [], _, _, _ => rfl | [], b :: bs, _, h₂, heq => by have h0 := heq 0; simp at h0 have hb := h₂ b (by simp); omega | a :: as, [], h₁, _, heq => by have h0 := heq 0; simp at h0 have ha := h₁ a (by simp); omega | a :: as, b :: bs, h₁, h₂, heq => by have h0 := heq 0; simp at h0 subst h0 congr 1 apply list_eq_of_getD_eq (fun x hx => h₁ x (by simp [hx])) (fun x hx => h₂ x (by simp [hx])) intro j simpa using heq (j + 1) noncomputable instance instFintypeSYT {n : ℕ} (lam : IntPart n) : Fintype (SYT lam) := by refine Fintype.ofInjective (fun (T : SYT lam) (ij : Fin n × Fin n) => (⟨(T.rows.getD ij.1.1 []).getD ij.2.1 n, by by_cases hi : ij.1.1 < T.rows.length · rw [List.getD_eq_getElem _ _ hi] by_cases hj : ij.2.1 < T.rows[ij.1.1].length · rw [List.getD_eq_getElem _ _ hj] exact Nat.lt_succ_of_lt (syt_entry_lt T (List.getElem_mem hi) (List.getElem_mem hj)) · rw [List.getD_eq_default _ _ (Nat.le_of_not_lt hj)] exact Nat.lt_succ_self n · rw [List.getD_eq_default _ _ (Nat.le_of_not_lt hi)] simp⟩ : Fin (n + 1))) ?_ intro T₁ T₂ h ext1 have hlen1 : T₁.rows.length = lam.parts.length := by have := congrArg List.length T₁.shape_eq; simpa using this have hlen2 : T₂.rows.length = lam.parts.length := by have := congrArg List.length T₂.shape_eq; simpa using this have hlen_le : lam.parts.length ≤ n := by have := length_le_sum_of_pos lam.pos; have hs := lam.sum_eq; omega apply List.ext_getElem (hlen1.trans hlen2.symm) intro i hi₁ hi₂ have hi_n : i < n := lt_of_lt_of_le (hlen1 ▸ hi₁) hlen_le apply list_eq_of_getD_eq (n := n) (fun x hx => syt_entry_lt T₁ (List.getElem_mem hi₁) hx) (fun x hx => syt_entry_lt T₂ (List.getElem_mem hi₂) hx) intro j by_cases hj : j < n · have hval := congrArg (fun f => (f (⟨i, hi_n⟩, ⟨j, hj⟩)).1) h dsimp only at hval rwa [List.getD_eq_getElem _ _ hi₁, List.getD_eq_getElem _ _ hi₂] at hval · have hrl1 : T₁.rows[i].length ≤ n := by have hmem : T₁.rows[i].length ∈ lam.parts := by rw [← T₁.shape_eq]; exact List.mem_map.mpr ⟨T₁.rows[i], List.getElem_mem hi₁, rfl⟩ have := mem_le_sum hmem; have hs := lam.sum_eq; omega have hrl2 : T₂.rows[i].length ≤ n := by have hmem : T₂.rows[i].length ∈ lam.parts := by rw [← T₂.shape_eq]; exact List.mem_map.mpr ⟨T₂.rows[i], List.getElem_mem hi₂, rfl⟩ have := mem_le_sum hmem; have hs := lam.sum_eq; omega rw [List.getD_eq_default _ _ (by omega), List.getD_eq_default _ _ (by omega)] /-! ## Section 3: Constructive Schensted Row-Insertion & Reverse Bumping -/ /-- Schensted row-insertion: replace the first element `a > x` with `x` and bump `a`, or append `x` to the end if all elements are `≤ x`. -/ def rowInsert (x : ℕ) : List ℕ → List ℕ × Option ℕ | [] => ([x], none) | a :: rest => if x < a then (x :: rest, some a) else let (r', b) := rowInsert x rest (a :: r', b) /-- Reverse bumping `y` into a nonempty row `r` with `r[0] < y`: replace the last element `< y` with `y` and return the replaced element. -/ def rowRevBump (y : ℕ) : List ℕ → List ℕ × ℕ | [] => ([], y) | [a] => ([y], a) | a :: b :: rest => if b < y then let (r', popped) := rowRevBump y (b :: rest) (a :: r', popped) else (y :: b :: rest, a) /-- Schensted tableau insertion: returns `(newTab, addedRowIdx)`. -/ def tabInsert (x : ℕ) : List (List ℕ) → List (List ℕ) × ℕ | [] => ([[x]], 0) | r :: rest => match rowInsert x r with | (r', none) => (r' :: rest, 0) | (r', some y) => let (rest', k) := tabInsert y rest (r' :: rest', k + 1) /-- Reverse bumping from row `k`: pops the last element of row `k` (deleting row `k` if singleton), then reverse-bumps upward through rows `k-1, ..., 0`. -/ def tabRevBump : ℕ → List (List ℕ) → List (List ℕ) × ℕ | _, [] => ([], 0) | 0, r :: rest => match r.reverse with | [] => (rest, 0) | [a] => (rest, a) | a :: revInit => (revInit.reverse :: rest, a) | k + 1, r :: rest => let (rest', y) := tabRevBump k rest let (r', popped) := rowRevBump y r (r' :: rest', popped) /-- Append `t` to the end of row `k` (creating a new row `[t]` if `k = Q.length`). -/ def tabAppendRow : ℕ → ℕ → List (List ℕ) → List (List ℕ) | 0, t, [] => [[t]] | 0, t, r :: rest => (r ++ [t]) :: rest | _ + 1, t, [] => [[t]] | k + 1, t, r :: rest => r :: tabAppendRow k t rest /-- Delete the last element of row `k` (deleting the row if singleton). -/ def tabPopRow : ℕ → List (List ℕ) → List (List ℕ) | _, [] => [] | 0, r :: rest => match r.reverse with | [] => rest | [_] => rest | _ :: revInit => revInit.reverse :: rest | k + 1, r :: rest => r :: tabPopRow k rest /-! ### Row-insertion invariants -/ lemma rowInsert_none_eq : ∀ {x : ℕ} {r r' : List ℕ}, rowInsert x r = (r', none) → r' = r ++ [x] ∧ ∀ a ∈ r, a ≤ x | x, [], r', h => by simp [rowInsert] at h; subst h; simp | x, a :: rest, r', h => by simp only [rowInsert] at h split_ifs at h with hlt · simp at h · rcases hrec : rowInsert x rest with ⟨r₁, b⟩ rw [hrec] at h simp only [Prod.mk.injEq] at h rcases h with ⟨rfl, rfl⟩ rcases rowInsert_none_eq hrec with ⟨rfl, hall⟩ refine ⟨rfl, ?_⟩ intro z hz simp only [List.mem_cons] at hz rcases hz with rfl | hz · omega · exact hall z hz lemma rowInsert_none_of_all_le : ∀ {x : ℕ} {r : List ℕ}, (∀ a ∈ r, a ≤ x) → rowInsert x r = (r ++ [x], none) | _, [], _ => rfl | x, a :: rest, hall => by have ha : a ≤ x := hall a (by simp) have hnot : ¬ (x < a) := by omega simp only [rowInsert, hnot, ↓reduceIte] rw [rowInsert_none_of_all_le (fun z hz => hall z (List.mem_cons_of_mem a hz))] simp lemma rowInsert_some_spec : ∀ {x y : ℕ} {r r' : List ℕ}, rowInsert x r = (r', some y) → r'.length = r.length ∧ x < y ∧ (r'.Perm (x :: r.erase y) ∧ y ∈ r) ∧ (∃ k, ∃ (hk : k < r.length), ∃ (hk' : k < r'.length), r[k] = y ∧ r'[k] = x ∧ (∀ j (hj : j < k), r[j]'(lt_trans hj hk) ≤ x) ∧ (∀ j (hj : j < r.length) (hj' : j < r'.length), j ≠ k → r'[j] = r[j])) | x, y, [], r', h => by simp [rowInsert] at h | x, y, a :: rest, r', h => by simp only [rowInsert] at h split_ifs at h with hlt · simp only [Prod.mk.injEq, Option.some.injEq] at h rcases h with ⟨rfl, rfl⟩ refine ⟨rfl, hlt, ⟨by simp, by simp⟩, 0, by simp, by simp, rfl, rfl, ?_, ?_⟩ · intro j hj; omega · intro j hj hj' hne cases j with | zero => exact absurd rfl hne | succ j => rfl · rcases hrec : rowInsert x rest with ⟨rest', b⟩ rw [hrec] at h simp only [Prod.mk.injEq] at h rcases h with ⟨rfl, rfl⟩ rcases rowInsert_some_spec hrec with ⟨hlen, hxy, ⟨hperm, hy_mem⟩, k, hk, hk', hgetk, hgetk', hlt_k, hother⟩ refine ⟨by simp [hlen], hxy, ?_, k + 1, by simp [hk], by simp [hk'], ?_, ?_, ?_, ?_⟩ · refine ⟨?_, List.mem_cons_of_mem a hy_mem⟩ have hne : a ≠ y := by omega rw [List.erase_cons_tail (by simp [hne])] exact (hperm.cons a).trans (List.Perm.swap x a _) · simpa using hgetk · simpa using hgetk' · intro j hj cases j with | zero => simp; omega | succ j => exact hlt_k j (Nat.lt_of_succ_lt_succ hj) · intro j hj hj' hne cases j with | zero => rfl | succ j => exact hother j (Nat.lt_of_succ_lt_succ hj) (Nat.lt_of_succ_lt_succ hj') (by omega) lemma rowInsert_perm_none {x : ℕ} {r r' : List ℕ} (h : rowInsert x r = (r', none)) : r'.Perm (x :: r) := by rcases rowInsert_none_eq h with ⟨rfl, _⟩ exact List.perm_append_singleton x r lemma rowInsert_perm_some {x y : ℕ} {r r' : List ℕ} (h : rowInsert x r = (r', some y)) : (y :: r').Perm (x :: r) := by rcases rowInsert_some_spec h with ⟨_, _, ⟨hperm, hy⟩, _⟩ have h1 : (y :: r').Perm (y :: x :: r.erase y) := hperm.cons y have h2 : (y :: x :: r.erase y).Perm (x :: y :: r.erase y) := List.Perm.swap x y _ have h3 : (x :: y :: r.erase y).Perm (x :: r) := (List.perm_cons_erase hy).symm.cons x exact h1.trans (h2.trans h3) lemma rowInsert_preserves_pairwise_le {x : ℕ} {r r' : List ℕ} {b : Option ℕ} (hr : r.Pairwise (· ≤ ·)) (h : rowInsert x r = (r', b)) : r'.Pairwise (· ≤ ·) := by induction r generalizing r' b with | nil => simp [rowInsert] at h rcases h with ⟨rfl, rfl⟩ simp | cons a rest ih => simp only [rowInsert] at h simp only [List.pairwise_cons] at hr split_ifs at h with hlt · simp only [Prod.mk.injEq] at h rcases h with ⟨rfl, rfl⟩ exact List.pairwise_cons.mpr ⟨fun z hz => le_trans (Nat.le_of_lt hlt) (hr.1 z hz), hr.2⟩ · rcases hrec : rowInsert x rest with ⟨rest', b'⟩ rw [hrec] at h simp only [Prod.mk.injEq] at h rcases h with ⟨rfl, rfl⟩ refine List.pairwise_cons.mpr ⟨?_, ih hr.2 hrec⟩ intro z hz cases b' with | none => have hmem := (rowInsert_perm_none hrec).subset hz simp only [List.mem_cons] at hmem rcases hmem with rfl | hmem · omega · exact hr.1 z hmem | some y => have hmem := (rowInsert_perm_some hrec).subset (List.mem_cons_of_mem y hz) simp only [List.mem_cons] at hmem rcases hmem with rfl | hmem · omega · exact hr.1 z hmem lemma rowInsert_nonempty {x : ℕ} {r r' : List ℕ} {b : Option ℕ} (h : rowInsert x r = (r', b)) : r' ≠ [] := by cases r with | nil => simp [rowInsert] at h; rcases h with ⟨rfl, _⟩; simp | cons a rest => simp only [rowInsert] at h split_ifs at h · rcases h with ⟨rfl, _⟩; simp · rcases hrec : rowInsert x rest with ⟨rest', b'⟩ rw [hrec] at h; rcases h with ⟨rfl, _⟩; simp lemma pairwise_getElem_le {r : List ℕ} (hr : r.Pairwise (· ≤ ·)) {i j : ℕ} (hij : i ≤ j) (hj : j < r.length) : r[i]'(Nat.lt_of_le_of_lt hij hj) ≤ r[j] := by rcases eq_or_lt_of_le hij with rfl | hlt · exact le_rfl · exact List.pairwise_iff_getElem.mp hr i j (Nat.lt_of_lt_of_le hlt (le_of_lt hj)) hj hlt lemma rowInsert_getElem_le {x y : ℕ} {r r' : List ℕ} (h : rowInsert x r = (r', some y)) {j : ℕ} (hj : j < r.length) (hj' : j < r'.length) : r'[j] ≤ r[j] := by rcases rowInsert_some_spec h with ⟨_, hxy, _, k, hk, hk', hgetk, hgetk', _, hother⟩ by_cases hjk : j = k · subst hjk; rw [hgetk, hgetk']; exact Nat.le_of_lt hxy · rw [hother j hj hj' hjk] /-- Core column-preservation theorem for Schensted insertion. -/ lemma tabInsert_preserves_isSSYT : ∀ {T : List (List ℕ)} (x : ℕ), IsSSYT T → IsSSYT (tabInsert x T).1 | [], x, _ => by refine ⟨?_, ?_, ?_⟩ · simp [tabInsert] · simp [tabInsert] · simp [tabInsert, IsColChain] | [r], x, ⟨hne, hrow, _⟩ => by simp only [tabInsert] cases hri : rowInsert x r with | mk r' b => cases b with | none => refine ⟨?_, ?_, trivial⟩ · intro s hs; simp only [List.mem_singleton] at hs; subst hs; exact rowInsert_nonempty hri · intro s hs; simp only [List.mem_singleton] at hs; subst hs exact rowInsert_preserves_pairwise_le (hrow r (by simp)) hri | some y => rcases rowInsert_some_spec hri with ⟨hlen, hxy, _, k, hk, hk', hgetk, hgetk', _, _⟩ have hr'_pw := rowInsert_preserves_pairwise_le (hrow r (by simp)) hri refine ⟨?_, ?_, ?_⟩ · intro s hs; simp only [List.mem_cons, List.not_mem_nil, or_false] at hs rcases hs with rfl | rfl · exact rowInsert_nonempty hri · simp · intro s hs; simp only [List.mem_cons, List.not_mem_nil, or_false] at hs rcases hs with rfl | rfl · exact hr'_pw · simp · simp only [IsColChain, List.length_singleton] refine ⟨by omega, ?_, trivial⟩ intro j hj₂ hj₁ have hj0 : j = 0 := by simp at hj₂; omega subst hj0 have h0k : r'[0] ≤ r'[k] := pairwise_getElem_le hr'_pw (Nat.zero_le k) hk' rw [hgetk'] at h0k simpa using lt_of_le_of_lt h0k hxy | r₁ :: r₂ :: rest, x, ⟨hne, hrow, ⟨hlen12, hcol12, hchain2⟩⟩ => by simp only [tabInsert] cases hri1 : rowInsert x r₁ with | mk r₁' b₁ => have hr₁'_pw := rowInsert_preserves_pairwise_le (hrow r₁ (by simp)) hri1 cases b₁ with | none => rcases rowInsert_none_eq hri1 with ⟨rfl, _⟩ refine ⟨?_, ?_, ?_⟩ · intro s hs rcases List.mem_cons.mp hs with rfl | hs · simp · exact hne s (List.mem_cons_of_mem r₁ hs) · intro s hs rcases List.mem_cons.mp hs with rfl | hs · exact hr₁'_pw · exact hrow s (List.mem_cons_of_mem r₁ hs) · refine ⟨by simp; omega, ?_, hchain2⟩ intro j hj₂ hj₁ have hj₁_orig : j < r₁.length := lt_of_lt_of_le hj₂ hlen12 simpa [List.getElem_append_left hj₁_orig] using hcol12 j hj₂ hj₁_orig | some y => rcases rowInsert_some_spec hri1 with ⟨hlen1, hxy, _, k₁, hk₁, hk₁', hgetk₁, hgetk₁', _, _⟩ have hssyt_tail : IsSSYT (r₂ :: rest) := ⟨fun s hs => hne s (List.mem_cons_of_mem r₁ hs), fun s hs => hrow s (List.mem_cons_of_mem r₁ hs), hchain2⟩ have hih := tabInsert_preserves_isSSYT y hssyt_tail simp only [tabInsert] at hih ⊢ cases hri2 : rowInsert y r₂ with | mk r₂' b₂ => rw [hri2] at hih cases b₂ with | none => rcases rowInsert_none_eq hri2 with ⟨rfl, hall2⟩ have hk₁_ge : r₂.length ≤ k₁ := by by_contra hlt push Not at hlt have h1 := hcol12 k₁ hlt hk₁ have h2 := hall2 r₂[k₁] (List.getElem_mem hlt) omega refine ⟨?_, ?_, ?_⟩ · intro s hs rcases List.mem_cons.mp hs with rfl | hs · exact rowInsert_nonempty hri1 · exact hih.1 s hs · intro s hs rcases List.mem_cons.mp hs with rfl | hs · exact hr₁'_pw · exact hih.2.1 s hs · refine ⟨by simp; omega, ?_, hih.2.2⟩ intro j hj₂ hj₁ simp only [List.length_append, List.length_singleton] at hj₂ by_cases hj_old : j < r₂.length · rw [List.getElem_append_left hj_old] have hle := rowInsert_getElem_le hri1 (lt_of_lt_of_le hj_old hlen12) hj₁ exact lt_of_le_of_lt hle (hcol12 j hj_old (lt_of_lt_of_le hj_old hlen12)) · have hjeq : j = r₂.length := by omega subst hjeq simp only [List.getElem_append_right (le_refl _), Nat.sub_self, List.getElem_singleton] have hle := pairwise_getElem_le hr₁'_pw hk₁_ge hk₁' rw [hgetk₁'] at hle exact lt_of_le_of_lt hle hxy | some z => rcases rowInsert_some_spec hri2 with ⟨hlen2, _, _, k₂, hk₂, hk₂', _, hgetk₂', hlt_k₂, hother2⟩ have hk₂_le : k₂ ≤ k₁ := by by_contra hlt push Not at hlt have hk₁_lt2 : k₁ < r₂.length := lt_trans hlt hk₂ have h1 := hcol12 k₁ hk₁_lt2 hk₁ have h2 := hlt_k₂ k₁ hlt omega refine ⟨?_, ?_, ?_⟩ · intro s hs rcases List.mem_cons.mp hs with rfl | hs · exact rowInsert_nonempty hri1 · exact hih.1 s hs · intro s hs rcases List.mem_cons.mp hs with rfl | hs · exact hr₁'_pw · exact hih.2.1 s hs · refine ⟨by omega, ?_, hih.2.2⟩ intro j hj₂ hj₁ by_cases hjk₂ : j = k₂ · subst hjk₂ rw [hgetk₂'] have hle := pairwise_getElem_le hr₁'_pw hk₂_le hk₁' rw [hgetk₁'] at hle exact lt_of_le_of_lt hle hxy · have hj₂_orig : j < r₂.length := hlen2 ▸ hj₂ rw [hother2 j hj₂_orig hj₂ hjk₂] have hj₁_orig : j < r₁.length := hlen1 ▸ hj₁ have hle := rowInsert_getElem_le hri1 hj₁_orig hj₁ exact lt_of_le_of_lt hle (hcol12 j hj₂_orig hj₁_orig) lemma tabInsert_flatten_perm : ∀ (x : ℕ) (T : List (List ℕ)), (tabInsert x T).1.flatten.Perm (x :: T.flatten) | x, [] => by simp [tabInsert] | x, r :: rest => by simp only [tabInsert] cases hri : rowInsert x r with | mk r' b => cases b with | none => simp only [List.flatten_cons] exact (rowInsert_perm_none hri).append_right rest.flatten | some y => simp only [List.flatten_cons] have h1 : (r' ++ (tabInsert y rest).1.flatten).Perm (r' ++ (y :: rest.flatten)) := (tabInsert_flatten_perm y rest).append_left r' have h2 : (r' ++ (y :: rest.flatten)).Perm ((y :: r') ++ rest.flatten) := List.perm_middle have h3 : ((y :: r') ++ rest.flatten).Perm ((x :: r) ++ rest.flatten) := (rowInsert_perm_some hri).append_right rest.flatten exact h1.trans (h2.trans h3) lemma tabInsert_preserves_isStrictTab {T : List (List ℕ)} {x : ℕ} (hT : IsStrictTab T) (hnd : T.flatten.Nodup) (hnotmem : x ∉ T.flatten) : IsStrictTab (tabInsert x T).1 := by have hssyt := tabInsert_preserves_isSSYT x hT.isSSYT have hnd' : (tabInsert x T).1.flatten.Nodup := (tabInsert_flatten_perm x T).nodup_iff.mpr (List.nodup_cons.mpr ⟨hnotmem, hnd⟩) exact isStrictTab_of_isSSYT_nodup hssyt hnd' lemma tabInsert_shape_spec : ∀ (x : ℕ) (T : List (List ℕ)), (tabInsert x T).2 ≤ T.length ∧ ∀ r, ((tabInsert x T).1.getD r []).length = (T.getD r []).length + (if r = (tabInsert x T).2 then 1 else 0) | x, [] => by refine ⟨le_rfl, ?_⟩ intro r; cases r <;> simp [tabInsert] | x, row :: rest => by have hri : ∃ row' b, rowInsert x row = (row', b) := ⟨(rowInsert x row).1, (rowInsert x row).2, rfl⟩ rcases hri with ⟨row', b, hri⟩ simp only [tabInsert, hri] cases b with | none => rcases rowInsert_none_eq hri with ⟨rfl, _⟩ refine ⟨Nat.zero_le _, ?_⟩ intro r; cases r <;> simp | some y => have hlen := (rowInsert_some_spec hri).1 rcases tabInsert_shape_spec y rest with ⟨hk_le, hshape⟩ refine ⟨Nat.succ_le_succ hk_le, ?_⟩ intro r cases r with | zero => simp [hlen] | succ r' => simpa using hshape r' lemma tabAppendRow_getD_length : ∀ (k t : ℕ) (Q : List (List ℕ)), k ≤ Q.length → ∀ r, ((tabAppendRow k t Q).getD r []).length = (Q.getD r []).length + (if r = k then 1 else 0) | 0, t, [], _ => by intro r; cases r <;> simp [tabAppendRow] | 0, t, row :: rest, _ => by intro r; cases r <;> simp [tabAppendRow] | k + 1, t, [], hk => by simp at hk | k + 1, t, row :: rest, hk => by intro r cases r with | zero => simp [tabAppendRow] | succ r' => simpa [tabAppendRow] using tabAppendRow_getD_length k t rest (Nat.le_of_succ_le_succ hk) r' lemma tabAppendRow_nonempty : ∀ (k t : ℕ) (Q : List (List ℕ)), (∀ r ∈ Q, r ≠ []) → ∀ r ∈ tabAppendRow k t Q, r ≠ [] | 0, t, [], _, r, hr => by simp [tabAppendRow] at hr; subst hr; simp | 0, t, row :: rest, hne, r, hr => by simp [tabAppendRow] at hr rcases hr with rfl | hr · simp · exact hne r (List.mem_cons_of_mem row hr) | _ + 1, t, [], _, r, hr => by simp [tabAppendRow] at hr; subst hr; simp | k + 1, t, row :: rest, hne, r, hr => by simp only [tabAppendRow, List.mem_cons] at hr rcases hr with rfl | hr · exact hne r (by simp) · exact tabAppendRow_nonempty k t rest (fun s hs => hne s (List.mem_cons_of_mem row hs)) r hr lemma partAt_map_length (T : List (List ℕ)) (r : ℕ) : partAt (T.map List.length) r = (T.getD r []).length := by unfold partAt by_cases h : r < T.length · rw [List.getD_eq_getElem _ _ (by simpa using h), List.getD_eq_getElem _ _ h] simp · rw [List.getD_eq_default _ _ (by simpa using Nat.le_of_not_lt h), List.getD_eq_default _ _ (Nat.le_of_not_lt h)] simp lemma tabAppendRow_shape_eq {k t : ℕ} {P Q P' : List (List ℕ)} (hk : k ≤ P.length) (hQ_ne : ∀ r ∈ Q, r ≠ []) (hP'_ne : ∀ r ∈ P', r ≠ []) (hPQ : Q.map List.length = P.map List.length) (hshape : ∀ r, (P'.getD r []).length = (P.getD r []).length + (if r = k then 1 else 0)) : (tabAppendRow k t Q).map List.length = P'.map List.length := by have hkQ : k ≤ Q.length := by have := congrArg List.length hPQ; simp at this; omega apply list_eq_of_partAt_eq · intro p hp rcases List.mem_map.mp hp with ⟨r, hr, rfl⟩ exact List.length_pos_iff.mpr (tabAppendRow_nonempty k t Q hQ_ne r hr) · intro p hp rcases List.mem_map.mp hp with ⟨r, hr, rfl⟩ exact List.length_pos_iff.mpr (hP'_ne r hr) · intro r rw [partAt_map_length, partAt_map_length, tabAppendRow_getD_length k t Q hkQ r, hshape r] have hPQr : (Q.getD r []).length = (P.getD r []).length := by rw [← partAt_map_length, ← partAt_map_length, hPQ] rw [hPQr] /-! ### Exact Mutual Inverse: `rowInsert` ↔ `rowRevBump` and `tabInsert` ↔ `tabRevBump` -/ lemma rowRevBump_rowInsert : ∀ {x y : ℕ} {r r' : List ℕ}, r.Pairwise (· ≤ ·) → rowInsert x r = (r', some y) → rowRevBump y r' = (r, x) | x, y, [], r', _, h => by simp [rowInsert] at h | x, y, a :: rest, r', hpw, h => by simp only [List.pairwise_cons] at hpw simp only [rowInsert] at h split_ifs at h with hlt · simp only [Prod.mk.injEq, Option.some.injEq] at h rcases h with ⟨rfl, rfl⟩ cases rest with | nil => simp [rowRevBump] | cons b rest' => have hab : a ≤ b := hpw.1 b (by simp) have hnot : ¬ (b < a) := by omega simp [rowRevBump, hnot] · rcases hrec : rowInsert x rest with ⟨rest', b⟩ rw [hrec] at h simp only [Prod.mk.injEq] at h rcases h with ⟨rfl, rfl⟩ have hih := rowRevBump_rowInsert hpw.2 hrec rcases rowInsert_some_spec hrec with ⟨hlen, hxy, _, k, hk, hk', hgetk, hgetk', _, _⟩ cases rest' with | nil => simp at hk' | cons c cs => have hc_lt_y : c < y := by have hr'_pw := rowInsert_preserves_pairwise_le hpw.2 hrec have h0k : (c :: cs)[0] ≤ (c :: cs)[k] := pairwise_getElem_le hr'_pw (Nat.zero_le k) hk' simp only [List.getElem_cons_zero] at h0k omega simp [rowRevBump, hc_lt_y, hih] lemma rowRevBump_spec : ∀ {y x : ℕ} {r' r : List ℕ}, r'.Pairwise (· ≤ ·) → r' ≠ [] → (∀ h0 : 0 < r'.length, r'[0] < y) → rowRevBump y r' = (r, x) → r.length = r'.length ∧ x < y ∧ r.Pairwise (· ≤ ·) ∧ (y :: r').Perm (x :: r) ∧ rowInsert x r = (r', some y) ∧ (∃ m, ∃ (hm : m < r'.length), ∃ (hm' : m < r.length), r'[m] = x ∧ r[m] = y ∧ (∀ j (_hj : m < j) (hj' : j < r'.length), y ≤ r'[j]) ∧ (∀ j (hj : j < r'.length) (hj' : j < r.length), j ≠ m → r[j] = r'[j])) | y, x, [], r, _, hne, _, _ => absurd rfl hne | y, x, [a], r, _, _, h0, h => by simp [rowRevBump] at h rcases h with ⟨rfl, rfl⟩ have hay : a < y := h0 (by simp) refine ⟨rfl, hay, by simp, List.Perm.swap a y [], by simp [rowInsert, hay], 0, by simp, by simp, rfl, rfl, ?_, ?_⟩ · intro j hj hj'; simp at hj'; omega · intro j hj _ hne; simp at hj; omega | y, x, a :: b :: rest, r, hpw, _, h0, h => by have hpw_cons := List.pairwise_cons.mp hpw have hay : a < y := h0 (by simp) simp only [rowRevBump] at h split_ifs at h with hby · rcases hrec : rowRevBump y (b :: rest) with ⟨r₁, x₁⟩ rw [hrec] at h simp only [Prod.mk.injEq] at h rcases h with ⟨rfl, rfl⟩ rcases rowRevBump_spec hpw_cons.2 (by simp) (fun _ => by simpa using hby) hrec with ⟨hlen, hxy, hr₁_pw, hperm, hri, m, hm, hm', hgetm, hgetm', hge_m, hother⟩ have hax : a ≤ x₁ := by have hmem : x₁ ∈ b :: rest := hgetm ▸ List.getElem_mem hm exact hpw_cons.1 x₁ hmem have hnot_xa : ¬ (x₁ < a) := by omega refine ⟨by simp [hlen], hxy, ?_, ?_, ?_, m + 1, Nat.succ_lt_succ hm, Nat.succ_lt_succ hm', ?_, ?_, ?_, ?_⟩ · refine List.pairwise_cons.mpr ⟨?_, hr₁_pw⟩ intro z hz have hz_mem : z ∈ y :: b :: rest := hperm.symm.subset (List.mem_cons_of_mem x₁ hz) rcases List.mem_cons.mp hz_mem with rfl | hz_mem · exact Nat.le_of_lt hay · exact hpw_cons.1 z hz_mem · exact (List.Perm.swap a y (b :: rest)).trans ((hperm.cons a).trans (List.Perm.swap x₁ a r₁)) · simp [rowInsert, hnot_xa, hri] · simpa using hgetm · simpa using hgetm' · intro j hj hj' cases j with | zero => omega | succ j' => exact hge_m j' (Nat.lt_of_succ_lt_succ hj) (Nat.lt_of_succ_lt_succ hj') · intro j hj hj' hne cases j with | zero => rfl | succ j' => exact hother j' (Nat.lt_of_succ_lt_succ hj) (Nat.lt_of_succ_lt_succ hj') (by omega) · simp only [Prod.mk.injEq] at h rcases h with ⟨rfl, rfl⟩ have hyb : y ≤ b := by omega have hpw_tail := List.pairwise_cons.mp hpw_cons.2 refine ⟨rfl, hay, ?_, List.Perm.swap a y (b :: rest), by simp [rowInsert, hay], 0, by simp, by simp, rfl, rfl, ?_, ?_⟩ · refine List.pairwise_cons.mpr ⟨?_, hpw_cons.2⟩ intro z hz rcases List.mem_cons.mp hz with rfl | hz · exact hyb · exact le_trans hyb (hpw_tail.1 z hz) · intro j hj hj' cases j with | zero => omega | succ j' => cases j' with | zero => simpa using hyb | succ j'' => have hmem : rest[j'']'(by simp at hj'; omega) ∈ rest := List.getElem_mem _ exact le_trans hyb (hpw_tail.1 _ hmem) · intro j hj hj' hne cases j with | zero => exact absurd rfl hne | succ j' => rfl lemma tabRevBump_zero_append (r : List ℕ) (x : ℕ) (rest : List (List ℕ)) : tabRevBump 0 ((r ++ [x]) :: rest) = (if r = [] then rest else r :: rest, x) := by simp only [tabRevBump, List.reverse_append, List.reverse_singleton, List.singleton_append] cases hr : r.reverse with | nil => have : r = [] := List.reverse_eq_nil_iff.mp hr simp [this] | cons a as => have hne : r ≠ [] := by intro h; subst h; simp at hr have hrev : (a :: as).reverse = r := by rw [← hr, List.reverse_reverse] simp [hne, hrev] /-- Left inverse: reverse bumping from the newly created row recovers `(T, x)`. -/ theorem tabRevBump_tabInsert : ∀ {T : List (List ℕ)} {x : ℕ}, IsSSYT T → tabRevBump (tabInsert x T).2 (tabInsert x T).1 = (T, x) | [], x, _ => by simp [tabInsert, tabRevBump] | r :: rest, x, ⟨hne, hrow, hchain⟩ => by simp only [tabInsert] cases hri : rowInsert x r with | mk r' b => cases b with | none => rcases rowInsert_none_eq hri with ⟨rfl, _⟩ have hr_ne : r ≠ [] := hne r (by simp) simp [tabRevBump_zero_append, hr_ne] | some y => have hssyt_rest : IsSSYT rest := by refine ⟨fun s hs => hne s (List.mem_cons_of_mem r hs), fun s hs => hrow s (List.mem_cons_of_mem r hs), ?_⟩ cases rest with | nil => trivial | cons r₂ rest' => exact hchain.2.2 have hih := tabRevBump_tabInsert (x := y) hssyt_rest simp only [tabRevBump, hih, rowRevBump_rowInsert (hrow r (by simp)) hri] /-! ## Section 4: Right Inverse Reverse Bumping, Full RS Bijection & Frobenius–Schur Identity -/ /-- Whether row `k` is an outer corner of tableau `T`: `k < T.length` and either `k + 1 = T.length` or row `k + 1` is strictly shorter than row `k`. -/ def IsTabCorner (T : List (List ℕ)) (k : ℕ) : Prop := k < T.length ∧ (T.getD (k + 1) []).length < (T.getD k []).length /-- In any `IsSSYT (r :: rest)`, every element of `rest.flatten` is strictly greater than `r[0]`. -/ lemma isSSYT_head_lt_tail_flatten : ∀ {r : List ℕ} {rest : List (List ℕ)}, IsSSYT (r :: rest) → ∀ (h0 : 0 < r.length) {y : ℕ}, y ∈ rest.flatten → r[0] < y | r, [], _, _, _, hy => by simp at hy | r, r₂ :: rest', ⟨hne, hrow, ⟨hlen, hcol, hchain⟩⟩, h0, y, hy => by have hr₂_ne : r₂ ≠ [] := hne r₂ (by simp) have hr₂_pos : 0 < r₂.length := List.length_pos_iff.mpr hr₂_ne have h0_lt : r[0] < r₂[0] := hcol 0 hr₂_pos h0 simp only [List.flatten_cons, List.mem_append] at hy rcases hy with hy₂ | hy_rest · rcases List.getElem_of_mem hy₂ with ⟨j, hj, rfl⟩ have hle : r₂[0] ≤ r₂[j] := pairwise_getElem_le (hrow r₂ (by simp)) (Nat.zero_le j) hj exact lt_of_lt_of_le h0_lt hle · have hssyt2 : IsSSYT (r₂ :: rest') := ⟨fun s hs => hne s (List.mem_cons_of_mem r hs), fun s hs => hrow s (List.mem_cons_of_mem r hs), hchain⟩ exact lt_trans h0_lt (isSSYT_head_lt_tail_flatten hssyt2 hr₂_pos hy_rest) lemma dropLast_append_last {r : List ℕ} (hr : r ≠ []) : r.dropLast ++ [r.getLast hr] = r := List.dropLast_append_getLast hr lemma tabRevBump_zero_of_nonempty {r : List ℕ} (hr : r ≠ []) (rest : List (List ℕ)) : tabRevBump 0 (r :: rest) = (if r.dropLast = [] then rest else r.dropLast :: rest, r.getLast hr) := by have h := tabRevBump_zero_append r.dropLast (r.getLast hr) rest rwa [List.dropLast_append_getLast hr] at h /-- Right inverse & invariant preservation for `tabRevBump` at any outer corner `k`. -/ theorem tabInsert_tabRevBump : ∀ {k : ℕ} {T' : List (List ℕ)}, IsSSYT T' → IsTabCorner T' k → let (T, x) := tabRevBump k T' IsSSYT T ∧ tabInsert x T = (T', k) ∧ (x :: T.flatten).Perm T'.flatten | 0, [], _, hcr => by simp [IsTabCorner] at hcr | 0, r :: rest, ⟨hne, hrow, hchain⟩, ⟨_, hlen_lt⟩ => by have hr_ne : r ≠ [] := hne r (by simp) have hrb := tabRevBump_zero_of_nonempty hr_ne rest rw [hrb] dsimp only have hr_eq : r.dropLast ++ [r.getLast hr_ne] = r := List.dropLast_append_getLast hr_ne have hpw_r : r.Pairwise (· ≤ ·) := hrow r (by simp) have hpw_split : (r.dropLast ++ [r.getLast hr_ne]).Pairwise (· ≤ ·) := by rw [hr_eq]; exact hpw_r have hall_le : ∀ a ∈ r.dropLast, a ≤ r.getLast hr_ne := by intro a ha exact (List.pairwise_append.mp hpw_split).2.2 a ha (r.getLast hr_ne) (by simp) have hpw_dl : r.dropLast.Pairwise (· ≤ ·) := (List.pairwise_append.mp hpw_split).1 have hri_dl : rowInsert (r.getLast hr_ne) r.dropLast = (r, none) := by rw [rowInsert_none_of_all_le hall_le, hr_eq] by_cases hdl : r.dropLast = [] · -- r is a singleton [a], so rest must be [] since rest[0].length < 1! have hr_len1 : r.length = 1 := by have := congrArg List.length hr_eq; simp [hdl] at this; omega have hrest_nil : rest = [] := by cases rest with | nil => rfl | cons r₂ rest' => have hr₂_ne : r₂ ≠ [] := hne r₂ (by simp) have hr₂_pos : 0 < r₂.length := List.length_pos_iff.mpr hr₂_ne simp at hlen_lt; omega subst hrest_nil simp only [hdl, ↓reduceIte] have hr_sing : r = [r.getLast hr_ne] := by simpa [hdl] using hr_eq.symm refine ⟨⟨by simp, by simp, trivial⟩, ?_, ?_⟩ · simp [tabInsert, ← hr_sing] · simp [← hr_sing] · simp only [hdl, ↓reduceIte] have hssyt_T : IsSSYT (r.dropLast :: rest) := by refine ⟨?_, ?_, ?_⟩ · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hdl · exact hne s (List.mem_cons_of_mem r hs) · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hpw_dl · exact hrow s (List.mem_cons_of_mem r hs) · cases rest with | nil => trivial | cons r₂ rest' => simp only [List.getD_cons_succ, List.getD_cons_zero] at hlen_lt have hdl_len : r.dropLast.length + 1 = r.length := by have h1 := List.length_dropLast (xs := r) have h2 := List.length_pos_iff.mpr hr_ne omega refine ⟨by omega, ?_, hchain.2.2⟩ intro j hj₂ hj₁ rw [List.getElem_dropLast] exact hchain.2.1 j hj₂ (by omega) refine ⟨hssyt_T, ?_, ?_⟩ · simp [tabInsert, hri_dl] · simp only [List.flatten_cons] have hperm := (List.perm_append_singleton (r.getLast hr_ne) r.dropLast).symm rw [hr_eq] at hperm exact hperm.append_right rest.flatten | k + 1, [], _, hcr => by simp [IsTabCorner] at hcr | k + 1, r :: rest, ⟨hne, hrow, hchain⟩, ⟨hk_lt, hlen_lt⟩ => by have hssyt_rest : IsSSYT rest := by refine ⟨fun s hs => hne s (List.mem_cons_of_mem r hs), fun s hs => hrow s (List.mem_cons_of_mem r hs), ?_⟩ cases rest with | nil => trivial | cons r₂ rest' => exact hchain.2.2 have hcr_rest : IsTabCorner rest k := by refine ⟨by simp at hk_lt; omega, ?_⟩ simpa using hlen_lt have hih := tabInsert_tabRevBump hssyt_rest hcr_rest rcases hrec : tabRevBump k rest with ⟨rest₀, y⟩ rw [hrec] at hih rcases hih with ⟨hssyt_rest₀, hti_rest₀, hperm_rest⟩ have hy_mem : y ∈ rest.flatten := hperm_rest.subset (by simp) have hr_ne : r ≠ [] := hne r (by simp) have h0_lt : ∀ h0 : 0 < r.length, r[0] < y := fun h0 => isSSYT_head_lt_tail_flatten ⟨hne, hrow, hchain⟩ h0 hy_mem rcases hrb : rowRevBump y r with ⟨r₀, x⟩ rcases rowRevBump_spec (hrow r (by simp)) hr_ne h0_lt hrb with ⟨hlen0, hxy, hr₀_pw, hperm_r, hri_r, m, hm, hm', hgetm, hgetm', hge_m, hother⟩ have hr₀_ne : r₀ ≠ [] := by intro h; rw [h] at hlen0; exact hr_ne (List.eq_nil_of_length_eq_zero hlen0.symm) -- Prove IsSSYT (r₀ :: rest₀)! have hssyt_new : IsSSYT (r₀ :: rest₀) := by refine ⟨?_, ?_, ?_⟩ · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hr₀_ne · exact hssyt_rest₀.1 s hs · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hr₀_pw · exact hssyt_rest₀.2.1 s hs · cases hrest₀ : rest₀ with | nil => trivial | cons r₂₀ rest₀' => rw [hrest₀] at hssyt_rest₀ hti_rest₀ -- Inspect head of rest = (tabInsert y (r₂₀ :: rest₀')).1 = (rowInsert y r₂₀).1 :: ... simp only [tabInsert] at hti_rest₀ cases hri2 : rowInsert y r₂₀ with | mk r₂ b₂ => rw [hri2] at hti_rest₀ cases b₂ with | none => simp only [Prod.mk.injEq] at hti_rest₀ rcases hti_rest₀ with ⟨hrest_eq, _⟩ rw [← hrest_eq] at hchain rcases rowInsert_none_eq hri2 with ⟨rfl, _⟩ -- r₂₀ ++ [y] has length ≤ r.length = r₀.length! -- Crucial: m ≥ r₂₀.length because r[r₂₀.length] < (r₂₀ ++ [y])[r₂₀.length] = y! have hlen_le : r₂₀.length < r.length := by have := hchain.1; simp at this; omega have hm_ge : r₂₀.length ≤ m := by by_contra hlt; push Not at hlt have hge := hge_m r₂₀.length hlt hlen_le have hcol := hchain.2.1 r₂₀.length (by simp) hlen_le simp only [List.getElem_append_right (le_refl _), Nat.sub_self, List.getElem_singleton] at hcol omega refine ⟨by have := hchain.1; omega, ?_, hssyt_rest₀.2.2⟩ intro j hj₂ hj₁ have hjm : j ≠ m := by omega have hj_r : j < r.length := hlen0 ▸ hj₁ rw [hother j hj_r hj₁ hjm] have hcol := hchain.2.1 j (by simp; omega) hj_r simpa [List.getElem_append_left hj₂] using hcol | some z => simp only [Prod.mk.injEq] at hti_rest₀ rcases hti_rest₀ with ⟨hrest_eq, _⟩ rw [← hrest_eq] at hchain rcases rowInsert_some_spec hri2 with ⟨hlen2, hyz, _, k₂, hk₂, hk₂', hgetk₂, hgetk₂', _, _⟩ -- Crucial: k₂ ≤ m because r[k₂] < r₂[k₂] = y! have hk₂_lt_r : k₂ < r.length := lt_of_lt_of_le hk₂' hchain.1 have hk₂_le : k₂ ≤ m := by by_contra hlt; push Not at hlt have hge := hge_m k₂ hlt hk₂_lt_r have hcol := hchain.2.1 k₂ hk₂' hk₂_lt_r omega refine ⟨by have := hchain.1; omega, ?_, hssyt_rest₀.2.2⟩ intro j hj₂ hj₁ by_cases hjm : j = m · subst hjm rw [hgetm'] have hle := pairwise_getElem_le (hssyt_rest₀.2.1 r₂₀ (by simp)) hk₂_le hj₂ rw [hgetk₂] at hle exact lt_of_lt_of_le hyz hle · have hj_r : j < r.length := hlen0 ▸ hj₁ rw [hother j hj_r hj₁ hjm] have hj₂' : j < r₂.length := hlen2.symm ▸ hj₂ have hcol := hchain.2.1 j hj₂' hj_r have hle := rowInsert_getElem_le hri2 hj₂ hj₂' exact lt_of_lt_of_le hcol hle simp only [tabRevBump, hrec, hrb] refine ⟨hssyt_new, ?_, ?_⟩ · simp only [tabInsert, hri_r, hti_rest₀] · simp only [List.flatten_cons] have h1 : (x :: (r₀ ++ rest₀.flatten)).Perm ((x :: r₀) ++ rest₀.flatten) := List.Perm.refl _ have h2 : ((x :: r₀) ++ rest₀.flatten).Perm ((y :: r) ++ rest₀.flatten) := hperm_r.symm.append_right rest₀.flatten have h3 : ((y :: r) ++ rest₀.flatten).Perm (r ++ (y :: rest₀.flatten)) := List.perm_middle.symm have h4 : (r ++ (y :: rest₀.flatten)).Perm (r ++ rest.flatten) := hperm_rest.append_left r exact h1.trans (h2.trans (h3.trans h4)) /-! ### Full Robinson–Schensted Correspondence `rsEncode` / `rsDecode` -/ /-- Insert a list of values `w` sequentially starting from `(P, Q)` at step counter `t`. -/ def rsStep (t : ℕ) (P Q : List (List ℕ)) : List ℕ → List (List ℕ) × List (List ℕ) | [] => (P, Q) | x :: xs => let (P', k) := tabInsert x P let Q' := tabAppendRow k t Q rsStep (t + 1) P' Q' xs /-- Forward Robinson–Schensted map on any word `w : List ℕ`. -/ def rsWord (w : List ℕ) : List (List ℕ) × List (List ℕ) := rsStep 0 [] [] w /-- Insertion tableau `P(w)` of a word `w`. -/ def rsP (w : List ℕ) : List (List ℕ) := (rsWord w).1 /-- Recording tableau `Q(w)` of a word `w`. -/ def rsQ (w : List ℕ) : List (List ℕ) := (rsWord w).2 /-- Find the row index whose last element equals `target` (0 if not found). -/ def findRowLast (target : ℕ) : List (List ℕ) → ℕ | [] => 0 | r :: rest => match r.getLast? with | some a => if a = target then 0 else findRowLast target rest + 1 | none => findRowLast target rest + 1 /-- Decode `m` steps of RS backwards from `(P, Q)` with maximum Q-entry `m - 1`, prepending to `acc`. -/ def rsDecodeAux : ℕ → List (List ℕ) → List (List ℕ) → List ℕ → List ℕ | 0, _, _, acc => acc | m + 1, P, Q, acc => let k := findRowLast m Q let (P', x) := tabRevBump k P let Q' := tabPopRow k Q rsDecodeAux m P' Q' (x :: acc) /-- Exact inverse Robinson–Schensted map recovering a word of length `n` from `(P, Q)`. -/ def rsDecode (n : ℕ) (P Q : List (List ℕ)) : List ℕ := rsDecodeAux n P Q [] /-! ### Invariants of `tabAppendRow` / `tabPopRow` / `findRowLast` -/ lemma tabAppendRow_flatten_perm : ∀ (k t : ℕ) (Q : List (List ℕ)), (tabAppendRow k t Q).flatten.Perm (t :: Q.flatten) | 0, t, [] => by simp [tabAppendRow] | 0, t, r :: rest => by simp only [tabAppendRow, List.flatten_cons] exact (List.perm_append_singleton t r).append_right rest.flatten | _ + 1, t, [] => by simp [tabAppendRow] | k + 1, t, r :: rest => by simp only [tabAppendRow, List.flatten_cons] have h1 := (tabAppendRow_flatten_perm k t rest).append_left r exact h1.trans List.perm_middle lemma tabPopRow_tabAppendRow : ∀ {k t : ℕ} {Q : List (List ℕ)}, (∀ r ∈ Q, r ≠ []) → k ≤ Q.length → tabPopRow k (tabAppendRow k t Q) = Q | 0, t, [], _, _ => by simp [tabAppendRow, tabPopRow] | 0, t, r :: rest, hne, _ => by have hr_ne : r ≠ [] := hne r (by simp) simp only [tabAppendRow, tabPopRow, List.reverse_append, List.reverse_singleton, List.singleton_append] cases hrev : r.reverse with | nil => exact absurd (List.reverse_eq_nil_iff.mp hrev) hr_ne | cons a as => have : (a :: as).reverse = r := by rw [← hrev, List.reverse_reverse] simp [this] | k + 1, t, [], _, hk => by simp at hk | k + 1, t, r :: rest, hne, hk => by simp only [tabAppendRow, tabPopRow] congr 1 exact tabPopRow_tabAppendRow (fun s hs => hne s (List.mem_cons_of_mem r hs)) (Nat.le_of_succ_le_succ hk) lemma findRowLast_tabAppendRow : ∀ {k t : ℕ} {Q : List (List ℕ)}, k ≤ Q.length → (∀ x ∈ Q.flatten, x < t) → findRowLast t (tabAppendRow k t Q) = k | 0, t, [], _, _ => by simp [tabAppendRow, findRowLast] | 0, t, r :: rest, _, _ => by simp [tabAppendRow, findRowLast] | k + 1, t, [], hk, _ => by simp at hk | k + 1, t, r :: rest, hk, hlt => by simp only [tabAppendRow, findRowLast] have hlt_r : ∀ x ∈ r, x < t := fun x hx => hlt x (by simp [hx]) have hlt_rest : ∀ x ∈ rest.flatten, x < t := fun x hx => hlt x (by simp [hx]) have hih := findRowLast_tabAppendRow (Nat.le_of_succ_le_succ hk) hlt_rest cases hgl : r.getLast? with | none => simp [hih] | some a => have ha_mem : a ∈ r := List.mem_of_getLast? hgl have hne : a ≠ t := ne_of_lt (hlt_r a ha_mem) simp [hne, hih] lemma tabAppendRow_isStrictTab : ∀ {k t : ℕ} {Q : List (List ℕ)}, IsStrictTab Q → (∀ x ∈ Q.flatten, x < t) → k ≤ Q.length → ((tabAppendRow k t Q).map List.length).Pairwise (· ≥ ·) → IsStrictTab (tabAppendRow k t Q) | 0, t, [], _, _, _, _ => ⟨by simp [tabAppendRow], by simp [tabAppendRow], trivial⟩ | 0, t, r :: rest, ⟨hne, hrow, hchain⟩, hlt, _, _ => by simp only [tabAppendRow] refine ⟨?_, ?_, ?_⟩ · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · simp · exact hne s (List.mem_cons_of_mem r hs) · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact List.pairwise_append.mpr ⟨hrow r (by simp), by simp, fun a ha b hb => by simp at hb; subst hb; exact hlt a (by simp [ha])⟩ · exact hrow s (List.mem_cons_of_mem r hs) · cases rest with | nil => trivial | cons r₂ rest' => refine ⟨by simp; have := hchain.1; omega, ?_, hchain.2.2⟩ intro j hj₂ hj₁ have hj₁_orig : j < r.length := lt_of_lt_of_le hj₂ hchain.1 simpa [List.getElem_append_left hj₁_orig] using hchain.2.1 j hj₂ hj₁_orig | k + 1, t, [], _, _, hk, _ => by simp at hk | k + 1, t, r :: rest, ⟨hne, hrow, hchain⟩, hlt, hk, hanti => by have hstrict_rest : IsStrictTab rest := by refine ⟨fun s hs => hne s (List.mem_cons_of_mem r hs), fun s hs => hrow s (List.mem_cons_of_mem r hs), ?_⟩ cases rest with | nil => trivial | cons r₂ rest' => exact hchain.2.2 have hlt_rest : ∀ x ∈ rest.flatten, x < t := fun x hx => hlt x (by simp [hx]) have hanti_rest : ((tabAppendRow k t rest).map List.length).Pairwise (· ≥ ·) := (List.pairwise_cons.mp hanti).2 have hih := tabAppendRow_isStrictTab hstrict_rest hlt_rest (Nat.le_of_succ_le_succ hk) hanti_rest simp only [tabAppendRow] refine ⟨?_, ?_, ?_⟩ · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hne _ (by simp) · exact hih.1 s hs · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hrow _ (by simp) · exact hih.2.1 s hs · cases hrest : rest with | nil => have hk0 : k = 0 := by rw [hrest] at hk; simp at hk; omega subst hk0 simp only [tabAppendRow] have hr_ne : r ≠ [] := hne r (by simp) have hr_pos : 0 < r.length := List.length_pos_iff.mpr hr_ne refine ⟨by simp; omega, ?_, trivial⟩ intro j hj₂ hj₁ have hj0 : j = 0 := by simp at hj₂; omega subst hj0 simpa using hlt r[0] (by simp [List.getElem_mem hr_pos]) | cons r₂ rest' => rw [hrest] at hchain hanti hih cases k with | zero => simp only [tabAppendRow] at hanti hih ⊢ have hlen_le : (r₂ ++ [t]).length ≤ r.length := (List.pairwise_cons.mp hanti).1 (r₂ ++ [t]).length (by simp) refine ⟨hlen_le, ?_, hih.2.2⟩ intro j hj₂ hj₁ by_cases hj_old : j < r₂.length · rw [List.getElem_append_left hj_old] exact hchain.2.1 j hj_old hj₁ · have hjeq : j = r₂.length := by simp at hj₂; omega subst hjeq simp only [List.getElem_append_right (le_refl _), Nat.sub_self, List.getElem_singleton] exact hlt r[r₂.length] (by simp [List.getElem_mem hj₁]) | succ k' => simp only [tabAppendRow] at hih ⊢ exact ⟨hchain.1, hchain.2.1, hih.2.2⟩ lemma rsStep_invariants : ∀ (w : List ℕ) (t : ℕ) (P Q : List (List ℕ)), IsStrictTab P → P.flatten.Nodup → IsStrictTab Q → Q.flatten.Perm (List.range t) → Q.map List.length = P.map List.length → w.Nodup → (∀ x ∈ w, x ∉ P.flatten) → IsStrictTab (rsStep t P Q w).1 ∧ (rsStep t P Q w).1.flatten.Perm (w ++ P.flatten) ∧ IsStrictTab (rsStep t P Q w).2 ∧ (rsStep t P Q w).2.flatten.Perm (List.range (t + w.length)) ∧ (rsStep t P Q w).2.map List.length = (rsStep t P Q w).1.map List.length | [], t, P, Q, hP, _, hQ, hQperm, hshape, _, _ => by simp [rsStep, hP, hQ, hQperm, hshape] | x :: xs, t, P, Q, hP, hPnd, hQ, hQperm, hshape, hwand, hdisj => by simp only [rsStep] have hx_not : x ∉ P.flatten := hdisj x (by simp) have hP'_strict : IsStrictTab (tabInsert x P).1 := tabInsert_preserves_isStrictTab hP hPnd hx_not have hP'_perm : (tabInsert x P).1.flatten.Perm (x :: P.flatten) := tabInsert_flatten_perm x P have hP'_nd : (tabInsert x P).1.flatten.Nodup := hP'_perm.nodup_iff.mpr (List.nodup_cons.mpr ⟨hx_not, hPnd⟩) rcases tabInsert_shape_spec x P with ⟨hk_le, hk_shape⟩ have hshape' : (tabAppendRow (tabInsert x P).2 t Q).map List.length = (tabInsert x P).1.map List.length := tabAppendRow_shape_eq hk_le hQ.1 hP'_strict.1 hshape hk_shape have hQ_lt : ∀ a ∈ Q.flatten, a < t := fun a ha => List.mem_range.mp (hQperm.subset ha) have hk_le_Q : (tabInsert x P).2 ≤ Q.length := by have := congrArg List.length hshape; simp at this; omega have hanti' : ((tabAppendRow (tabInsert x P).2 t Q).map List.length).Pairwise (· ≥ ·) := by rw [hshape']; exact isColChain_lengths_pairwise hP'_strict.2.2 have hQ'_strict : IsStrictTab (tabAppendRow (tabInsert x P).2 t Q) := tabAppendRow_isStrictTab hQ hQ_lt hk_le_Q hanti' have hQ'_perm : (tabAppendRow (tabInsert x P).2 t Q).flatten.Perm (List.range (t + 1)) := by have h1 := tabAppendRow_flatten_perm (tabInsert x P).2 t Q have h2 : (t :: Q.flatten).Perm (t :: List.range t) := hQperm.cons t have h3 : (t :: List.range t).Perm (List.range (t + 1)) := by rw [List.range_succ]; exact List.perm_append_singleton t (List.range t) |>.symm exact h1.trans (h2.trans h3) have hxs_nd : xs.Nodup := (List.nodup_cons.mp hwand).2 have hxs_disj : ∀ z ∈ xs, z ∉ (tabInsert x P).1.flatten := by intro z hz hmem have hmem' := hP'_perm.subset hmem rcases List.mem_cons.mp hmem' with rfl | hmem' · exact (List.nodup_cons.mp hwand).1 hz · exact hdisj z (List.mem_cons_of_mem x hz) hmem' have hih := rsStep_invariants xs (t + 1) (tabInsert x P).1 (tabAppendRow (tabInsert x P).2 t Q) hP'_strict hP'_nd hQ'_strict hQ'_perm hshape' hxs_nd hxs_disj rcases hih with ⟨hPf_s, hPf_p, hQf_s, hQf_p, hsh_f⟩ refine ⟨hPf_s, ?_, hQf_s, ?_, hsh_f⟩ · exact (hPf_p.trans (hP'_perm.append_left xs)).trans List.perm_middle · convert hQf_p using 2 simp only [List.length_cons]; omega /-- Left inverse: `rsDecodeAux` recovers `w` after `rsStep`! -/ lemma rsDecodeAux_rsStep : ∀ (w : List ℕ) (t : ℕ) (P Q : List (List ℕ)) (acc : List ℕ), IsSSYT P → (∀ r ∈ Q, r ≠ []) → Q.map List.length = P.map List.length → (∀ a ∈ Q.flatten, a < t) → rsDecodeAux (t + w.length) (rsStep t P Q w).1 (rsStep t P Q w).2 acc = rsDecodeAux t P Q (w ++ acc) | [], t, P, Q, acc, _, _, _, _ => by simp [rsStep] | x :: xs, t, P, Q, acc, hP, hQne, hshape, hQlt => by simp only [rsStep, List.length_cons] have hP'_ssyt := tabInsert_preserves_isSSYT x hP rcases tabInsert_shape_spec x P with ⟨hk_le, hk_shape⟩ have hshape' := tabAppendRow_shape_eq (t := t) hk_le hQne hP'_ssyt.1 hshape hk_shape have hQ'_ne := tabAppendRow_nonempty (tabInsert x P).2 t Q hQne have hQ'_lt : ∀ a ∈ (tabAppendRow (tabInsert x P).2 t Q).flatten, a < t + 1 := by intro a ha have hmem := (tabAppendRow_flatten_perm (tabInsert x P).2 t Q).subset ha rcases List.mem_cons.mp hmem with rfl | hmem · omega · exact Nat.lt_succ_of_lt (hQlt a hmem) have hih := rsDecodeAux_rsStep xs (t + 1) (tabInsert x P).1 (tabAppendRow (tabInsert x P).2 t Q) acc hP'_ssyt hQ'_ne hshape' hQ'_lt have hlen_eq : t + (xs.length + 1) = (t + 1) + xs.length := by omega rw [hlen_eq, hih] -- Now one step of rsDecodeAux (t + 1) on (tabInsert x P).1, tabAppendRow k t Q! have hk_le_Q : (tabInsert x P).2 ≤ Q.length := by have := congrArg List.length hshape; simp at this; omega simp only [rsDecodeAux, findRowLast_tabAppendRow hk_le_Q hQlt, tabRevBump_tabInsert hP, tabPopRow_tabAppendRow hQne hk_le_Q, List.cons_append] /-- **Left Inverse of RS on Words**: `rsDecode w.length (rsP w) (rsQ w) = w` for every word `w`. -/ theorem rsDecode_rsWord (w : List ℕ) : rsDecode w.length (rsP w) (rsQ w) = w := by have h := rsDecodeAux_rsStep w 0 [] [] [] ⟨by simp, by simp, trivial⟩ (by simp) rfl (by simp) simpa [rsDecode, rsP, rsQ, rsWord, rsDecodeAux] using h /-- Properties of `findRowLast` and `tabPopRow` on an `SYT` of size `m + 1`. -/ lemma findRowLast_spec {m : ℕ} {Q : List (List ℕ)} (hQ : IsStrictTab Q) (hperm : Q.flatten.Perm (List.range (m + 1))) : let k := findRowLast m Q IsTabCorner Q k ∧ IsStrictTab (tabPopRow k Q) ∧ (tabPopRow k Q).flatten.Perm (List.range m) ∧ tabAppendRow k m (tabPopRow k Q) = Q ∧ k ≤ (tabPopRow k Q).length := by have hmax : ∀ x ∈ Q.flatten, x ≤ m := fun x hx => Nat.le_of_lt_succ (List.mem_range.mp (hperm.subset hx)) have hm_mem : m ∈ Q.flatten := hperm.symm.subset (List.mem_range.mpr (Nat.lt_succ_self m)) have hnd : Q.flatten.Nodup := hperm.nodup_iff.mpr List.nodup_range -- Prove by induction on Q that findRowLast locates the unique row containing `m`, which is an outer corner! have hfind : ∀ (T : List (List ℕ)), IsStrictTab T → T.flatten.Nodup → (∀ x ∈ T.flatten, x ≤ m) → m ∈ T.flatten → let k := findRowLast m T IsTabCorner T k ∧ IsStrictTab (tabPopRow k T) ∧ (m :: (tabPopRow k T).flatten).Perm T.flatten ∧ tabAppendRow k m (tabPopRow k T) = T ∧ k ≤ (tabPopRow k T).length := by intro T induction T with | nil => intro _ _ _ hm; simp at hm | cons r rest ih => intro hT hTnd hTmax hTm have hr_ne : r ≠ [] := hT.1 r (by simp) have hgl_r : r.getLast? = some (r.getLast hr_ne) := List.getLast?_eq_some_getLast hr_ne simp only [findRowLast, hgl_r] by_cases hlast_eq : r.getLast hr_ne = m · -- Row 0 contains m at the very end! simp only [hlast_eq, ↓reduceIte] have hr_eq : r.dropLast ++ [m] = r := by rw [← hlast_eq]; exact List.dropLast_append_getLast hr_ne -- Check row 0 is a corner (rest[0].length < r.length)! have hcr : IsTabCorner (r :: rest) 0 := by refine ⟨by simp, ?_⟩ cases rest with | nil => simp [List.length_pos_iff.mpr hr_ne] | cons r₂ rest' => simp only [List.getD_cons_succ, List.getD_cons_zero] have hle := hT.2.2.1 by_contra hnot; push Not at hnot have hlen_eq : r₂.length = r.length := by omega have hj_lt : r.length - 1 < r₂.length := by have := List.length_pos_iff.mpr hr_ne; omega have hcol := hT.2.2.2.1 (r.length - 1) hj_lt (by omega) rw [← List.getLast_eq_getElem hr_ne, hlast_eq] at hcol have hle_m := hTmax r₂[r.length - 1] (List.mem_flatten.mpr ⟨r₂, by simp, List.getElem_mem hj_lt⟩) omega -- Compute tabPopRow 0 (r :: rest) have hpop : tabPopRow 0 (r :: rest) = if r.dropLast = [] then rest else r.dropLast :: rest := by have hrev_eq : r.reverse = m :: r.dropLast.reverse := by conv_lhs => rw [← hr_eq] simp simp only [tabPopRow, hrev_eq] cases hd : r.dropLast.reverse with | nil => have : r.dropLast = [] := List.reverse_eq_nil_iff.mp hd simp [this] | cons a as => have hne_dl : r.dropLast ≠ [] := by intro h; rw [h] at hd; simp at hd have : (a :: as).reverse = r.dropLast := by rw [← hd, List.reverse_reverse] simp [hne_dl, this] rw [hpop] by_cases hdl : r.dropLast = [] · have hr_sing : r = [m] := by simpa [hdl] using hr_eq.symm have hrest_nil : rest = [] := by cases rest with | nil => rfl | cons r₂ rest' => have h1 := hcr.2 simp only [List.getD_cons_succ, List.getD_cons_zero, hr_sing, List.length_singleton] at h1 have := List.length_pos_iff.mpr (hT.1 r₂ (by simp)); omega subst hrest_nil simp only [hdl, ↓reduceIte] refine ⟨hcr, ⟨by simp, by simp, trivial⟩, by simp [hr_sing], by simp [tabAppendRow, hr_sing], le_rfl⟩ · simp only [hdl, ↓reduceIte] have hstrict_new : IsStrictTab (r.dropLast :: rest) := by refine ⟨?_, ?_, ?_⟩ · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hdl · exact hT.1 s (List.mem_cons_of_mem r hs) · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · have h := hT.2.1 r (by simp) rw [← hr_eq] at h exact (List.pairwise_append.mp h).1 · exact hT.2.1 s (List.mem_cons_of_mem r hs) · cases rest with | nil => trivial | cons r₂ rest' => have hcr2 := hcr.2; simp only [List.getD_cons_succ, List.getD_cons_zero] at hcr2 have hdl_len : r.dropLast.length + 1 = r.length := by have h1 := List.length_dropLast (xs := r) have h2 := List.length_pos_iff.mpr hr_ne omega refine ⟨by omega, ?_, hT.2.2.2.2⟩ intro j hj₂ hj₁ rw [List.getElem_dropLast]; exact hT.2.2.2.1 j hj₂ (by omega) refine ⟨hcr, hstrict_new, ?_, ?_, Nat.zero_le _⟩ · simp only [List.flatten_cons] have hp : (m :: r.dropLast).Perm r := by have := (List.perm_append_singleton m r.dropLast).symm rwa [hr_eq] at this exact hp.append_right rest.flatten · simp [tabAppendRow, hr_eq] · -- m is NOT the last element of r, so m ∉ r, hence m ∈ rest.flatten! simp only [hlast_eq, ↓reduceIte] have hm_not_r : m ∉ r := by intro hm_r have hpw := hT.2.1 r (by simp) have hle1 : r.getLast hr_ne ≤ m := hTmax _ (by simp [List.getLast_mem hr_ne]) rcases List.getElem_of_mem hm_r with ⟨j, hj, hgetj⟩ by_cases hlast : j + 1 = r.length · apply hlast_eq rw [List.getLast_eq_getElem] have : r.length - 1 = j := by omega simp only [this, hgetj] · have hlt := List.pairwise_iff_getElem.mp hpw j (r.length - 1) hj (by omega) (by omega) rw [← List.getLast_eq_getElem hr_ne, hgetj] at hlt; omega have hm_rest : m ∈ rest.flatten := by simp only [List.flatten_cons, List.mem_append] at hTm exact hTm.resolve_left hm_not_r have hT_rest : IsStrictTab rest := by refine ⟨fun s hs => hT.1 s (List.mem_cons_of_mem r hs), fun s hs => hT.2.1 s (List.mem_cons_of_mem r hs), ?_⟩ cases rest with | nil => trivial | cons r₂ rest' => exact hT.2.2.2.2 have hnd_rest : rest.flatten.Nodup := (List.nodup_append.mp (by simpa using hTnd)).2.1 have hmax_rest : ∀ x ∈ rest.flatten, x ≤ m := fun x hx => hTmax x (by simp [hx]) rcases ih hT_rest hnd_rest hmax_rest hm_rest with ⟨hcr_rest, hst_rest, hperm_rest, happ_rest, hkle_rest⟩ refine ⟨⟨Nat.succ_lt_succ hcr_rest.1, by simpa using hcr_rest.2⟩, ?_, ?_, ?_, Nat.succ_le_succ hkle_rest⟩ · simp only [tabPopRow] refine ⟨?_, ?_, ?_⟩ · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hr_ne · exact hst_rest.1 s hs · intro s hs; rcases List.mem_cons.mp hs with rfl | hs · exact hT.2.1 _ (by simp) · exact hst_rest.2.1 s hs · cases hpop_r : tabPopRow (findRowLast m rest) rest with | nil => trivial | cons r₂' rest'' => rw [hpop_r] at hst_rest happ_rest -- Compare r₂' with head of rest! cases hrest_eq : rest with | nil => simp [hrest_eq] at hm_rest | cons r₂ rest' => rw [hrest_eq] at hT happ_rest cases hk : findRowLast m (r₂ :: rest') with | zero => rw [hk] at happ_rest simp only [tabAppendRow, List.cons.injEq] at happ_rest rcases happ_rest with ⟨hr₂_eq, _⟩ refine ⟨by have := hT.2.2.1; rw [← hr₂_eq] at this; simp at this; omega, ?_, hst_rest.2.2⟩ intro j hj₂ hj₁ have hcol := hT.2.2.2.1 j (by rw [← hr₂_eq]; simp; omega) hj₁ have hget : r₂[j]'(by rw [← hr₂_eq]; simp; omega) = r₂'[j] := by subst hr₂_eq; exact List.getElem_append_left hj₂ rwa [hget] at hcol | succ k' => rw [hk] at happ_rest simp only [tabAppendRow, List.cons.injEq] at happ_rest rcases happ_rest with ⟨rfl, _⟩ exact ⟨hT.2.2.1, hT.2.2.2.1, hst_rest.2.2⟩ · simp only [tabPopRow, List.flatten_cons] exact List.perm_middle.symm.trans (hperm_rest.append_left r) · simp only [tabPopRow, tabAppendRow, happ_rest] rcases hfind Q hQ hnd hmax hm_mem with ⟨hcr, hst, hperm_m, happ, hkle⟩ refine ⟨hcr, hst, ?_, happ, hkle⟩ have hrange : (m :: List.range m).Perm (List.range (m + 1)) := by rw [List.range_succ]; exact (List.perm_append_singleton m (List.range m)).symm exact (List.perm_cons m).mp (hperm_m.trans (hperm.trans hrange.symm)) /-- Right inverse: `rsStep` on `rsDecodeAux n P Q []` recovers `(P, Q)`! -/ lemma rsWord_rsDecode : ∀ (n : ℕ) (P Q : List (List ℕ)), IsStrictTab P → P.flatten.Perm (List.range n) → IsStrictTab Q → Q.flatten.Perm (List.range n) → Q.map List.length = P.map List.length → rsWord (rsDecode n P Q) = (P, Q) ∧ (rsDecode n P Q).Perm (List.range n) := by -- Prove general version with accumulator `acc` via induction on `n`! have hgen : ∀ (n : ℕ) (P Q : List (List ℕ)) (acc : List ℕ), IsStrictTab P → P.flatten.Nodup → IsStrictTab Q → Q.flatten.Perm (List.range n) → Q.map List.length = P.map List.length → rsWord (rsDecodeAux n P Q acc) = rsStep n P Q acc ∧ (rsDecodeAux n P Q acc).Perm (P.flatten ++ acc) := by intro n induction n with | zero => intro P Q acc hP _ hQ hQperm hshape have hQnil : Q = [] := by cases Q with | nil => rfl | cons r rest => have h0 := List.length_pos_iff.mpr (hQ.1 r (by simp)) have hlen := hQperm.length_eq simp only [List.flatten_cons, List.length_append, List.length_range] at hlen; omega have hPnil : P = [] := by cases P with | nil => rfl | cons r rest => simp [hQnil] at hshape subst hQnil hPnil simp [rsDecodeAux, rsWord] | succ m ih => intro P Q acc hP hPnd hQ hQperm hshape rcases findRowLast_spec hQ hQperm with ⟨hcrQ, hstQ', hpermQ', happQ', hkleQ'⟩ set k := findRowLast m Q with hk have hcrP : IsTabCorner P k := by have hlen_eq : Q.length = P.length := by have := congrArg List.length hshape; simpa using this have hget_eq : ∀ r, (Q.getD r []).length = (P.getD r []).length := fun r => by rw [← partAt_map_length, ← partAt_map_length, hshape] exact ⟨hlen_eq ▸ hcrQ.1, by rw [← hget_eq, ← hget_eq]; exact hcrQ.2⟩ have hrb := tabInsert_tabRevBump hP.isSSYT hcrP rcases hrb_eq : tabRevBump k P with ⟨P', x⟩ rw [hrb_eq] at hrb rcases hrb with ⟨hssytP', htiP', hpermP'⟩ have hndP' : P'.flatten.Nodup := (List.nodup_cons.mp (hpermP'.nodup_iff.mpr hPnd)).2 have hstP' : IsStrictTab P' := isStrictTab_of_isSSYT_nodup hssytP' hndP' -- Show shape of tabPopRow k Q equals shape of P' have hshape' : (tabPopRow k Q).map List.length = P'.map List.length := by apply list_eq_of_partAt_eq · intro p hp; rcases List.mem_map.mp hp with ⟨r, hr, rfl⟩ exact List.length_pos_iff.mpr (hstQ'.1 r hr) · intro p hp; rcases List.mem_map.mp hp with ⟨r, hr, rfl⟩ exact List.length_pos_iff.mpr (hstP'.1 r hr) · intro r have h1 := tabAppendRow_getD_length k m (tabPopRow k Q) hkleQ' r rw [happQ'] at h1 have h2 := (tabInsert_shape_spec x P').2 r rw [htiP'] at h2 dsimp only at h2 have h3 : (Q.getD r []).length = (P.getD r []).length := by rw [← partAt_map_length, ← partAt_map_length, hshape] rw [partAt_map_length, partAt_map_length] omega rcases ih P' (tabPopRow k Q) (x :: acc) hstP' hndP' hstQ' hpermQ' hshape' with ⟨hrs_ih, hperm_ih⟩ simp only [rsDecodeAux] rw [← hk, hrb_eq] refine ⟨?_, ?_⟩ · rw [hrs_ih] simp only [rsStep, htiP', happQ'] · have h1 : (P'.flatten ++ (x :: acc)).Perm ((x :: P'.flatten) ++ acc) := List.perm_middle exact hperm_ih.trans (h1.trans (hpermP'.append_right acc)) intro n P Q hP hPperm hQ hQperm hshape have hPnd : P.flatten.Nodup := hPperm.nodup_iff.mpr List.nodup_range rcases hgen n P Q [] hP hPnd hQ hQperm hshape with ⟨hrs, hperm⟩ refine ⟨by simpa [rsStep, rsDecode] using hrs, ?_⟩ rw [List.append_nil] at hperm exact hperm.trans hPperm /-- RS invariants for every duplicate-free word `w`. -/ theorem rsWord_invariants (w : List ℕ) (hw : w.Nodup) : IsStrictTab (rsP w) ∧ (rsP w).flatten.Perm w ∧ IsStrictTab (rsQ w) ∧ (rsQ w).flatten.Perm (List.range w.length) ∧ (rsQ w).map List.length = (rsP w).map List.length := by have h := rsStep_invariants w 0 [] [] ⟨by simp, by simp, trivial⟩ List.nodup_nil ⟨by simp, by simp, trivial⟩ List.Perm.nil rfl hw (by simp) simpa [rsP, rsQ, rsWord] using h /-- Convert a permutation `w : Equiv.Perm (Fin n)` to its one-line word `[w 0, ..., w (n-1)]`. -/ def permToWord {n : ℕ} (w : Equiv.Perm (Fin n)) : List ℕ := (List.finRange n).map (fun i => (w i).1) lemma permToWord_length {n : ℕ} (w : Equiv.Perm (Fin n)) : (permToWord w).length = n := by simp [permToWord] lemma permToWord_nodup {n : ℕ} (w : Equiv.Perm (Fin n)) : (permToWord w).Nodup := by unfold permToWord refine (List.nodup_finRange n).map ?_ intro i j h exact w.injective (Fin.ext h) lemma permToWord_perm_range {n : ℕ} (w : Equiv.Perm (Fin n)) : (permToWord w).Perm (List.range n) := by rw [List.perm_ext_iff_of_nodup (permToWord_nodup w) List.nodup_range] intro x simp only [permToWord, List.mem_map, List.mem_finRange, true_and, List.mem_range] constructor · rintro ⟨i, rfl⟩; exact (w i).2 · intro hx; exact ⟨w⁻¹ ⟨x, hx⟩, by simp⟩ lemma permToWord_injective {n : ℕ} : Function.Injective (permToWord (n := n)) := by intro w₁ w₂ h ext i have hi : i.1 < (permToWord w₁).length := by rw [permToWord_length]; exact i.2 have hget := List.getElem_of_eq h hi simpa [permToWord] using hget lemma perm_range_length {n : ℕ} {l : List ℕ} (h : l.Perm (List.range n)) : l.length = n := by simpa using h.length_eq /-- One-line function of a word that is a permutation of `[0, n)`. -/ def wordToFun {n : ℕ} (l : List ℕ) (hperm : l.Perm (List.range n)) (i : Fin n) : Fin n := ⟨l[i.1]'(by rw [perm_range_length hperm]; exact i.2), List.mem_range.mp (hperm.subset (List.getElem_mem _))⟩ lemma wordToFun_injective {n : ℕ} (l : List ℕ) (hperm : l.Perm (List.range n)) : Function.Injective (wordToFun l hperm) := by intro i j h have hnd : l.Nodup := hperm.nodup_iff.mpr List.nodup_range have hval := congrArg Fin.val h simp only [wordToFun] at hval exact Fin.ext ((List.Nodup.getElem_inj_iff hnd).mp hval) /-- Construct `Equiv.Perm (Fin n)` from a list that is a permutation of `List.range n`. -/ noncomputable def wordToPerm {n : ℕ} (l : List ℕ) (hperm : l.Perm (List.range n)) : Equiv.Perm (Fin n) := Equiv.ofBijective (wordToFun l hperm) (Finite.injective_iff_bijective.mp (wordToFun_injective l hperm)) lemma permToWord_wordToPerm {n : ℕ} (l : List ℕ) (hperm : l.Perm (List.range n)) : permToWord (wordToPerm l hperm) = l := by apply List.ext_getElem (by rw [permToWord_length, perm_range_length hperm]) intro i hi₁ hi₂ simp [permToWord, wordToPerm, wordToFun] /-- Forward RS map on permutations: `w ↦ (shape, P(w), Q(w))`. -/ noncomputable def rsToSigma {n : ℕ} (w : Equiv.Perm (Fin n)) : Σ lam : IntPart n, SYT lam × SYT lam := let h := rsWord_invariants (permToWord w) (permToWord_nodup w) ⟨⟨(rsP (permToWord w)).map List.length, fun p hp => by rcases List.mem_map.mp hp with ⟨r, hr, rfl⟩ exact List.length_pos_iff.mpr (h.1.1 r hr), isColChain_lengths_pairwise h.1.2.2, by have := (h.2.1.trans (permToWord_perm_range w)).length_eq simpa [List.length_flatten] using this⟩, ⟨rsP (permToWord w), rfl, h.1, h.2.1.trans (permToWord_perm_range w)⟩, ⟨rsQ (permToWord w), h.2.2.2.2, h.2.2.1, by have := h.2.2.2.1 rwa [permToWord_length] at this⟩⟩ /-- Inverse RS map: reverse bumping recovers the permutation from `(P, Q)`. -/ noncomputable def rsFromSigma {n : ℕ} (x : Σ lam : IntPart n, SYT lam × SYT lam) : Equiv.Perm (Fin n) := wordToPerm (rsDecode n x.2.1.rows x.2.2.rows) (rsWord_rsDecode n x.2.1.rows x.2.2.rows x.2.1.strict x.2.1.perm_range x.2.2.strict x.2.2.perm_range (x.2.2.shape_eq.trans x.2.1.shape_eq.symm)).2 lemma sigma_syt_ext {n : ℕ} {a b : Σ lam : IntPart n, SYT lam × SYT lam} (h1 : a.2.1.rows = b.2.1.rows) (h2 : a.2.2.rows = b.2.2.rows) : a = b := by rcases a with ⟨la, Pa, Qa⟩ rcases b with ⟨lb, Pb, Qb⟩ simp only at h1 h2 have hl : la = lb := by ext1; rw [← Pa.shape_eq, ← Pb.shape_eq, h1] subst hl rw [show Pa = Pb from SYT.ext h1, show Qa = Qb from SYT.ext h2] /-- **Constructive Robinson–Schensted Bijection Theorem**: `Equiv.Perm (Fin n) ≃ Σ λ : IntPart n, SYT λ × SYT λ`, explicitly given by row insertion (`rsToSigma`) and reverse bumping (`rsFromSigma`). -/ noncomputable def rsBijection (n : ℕ) : Equiv.Perm (Fin n) ≃ Σ lam : IntPart n, SYT lam × SYT lam where toFun := rsToSigma invFun := rsFromSigma left_inv w := by apply permToWord_injective rw [rsFromSigma, permToWord_wordToPerm] have hdec := rsDecode_rsWord (permToWord w) rw [permToWord_length] at hdec exact hdec right_inv x := by have hrs := (rsWord_rsDecode n x.2.1.rows x.2.2.rows x.2.1.strict x.2.1.perm_range x.2.2.strict x.2.2.perm_range (x.2.2.shape_eq.trans x.2.1.shape_eq.symm)).1 have hpw : permToWord (rsFromSigma x) = rsDecode n x.2.1.rows x.2.2.rows := permToWord_wordToPerm _ _ apply sigma_syt_ext · change rsP (permToWord (rsFromSigma x)) = x.2.1.rows rw [hpw]; unfold rsP; rw [hrs] · change rsQ (permToWord (rsFromSigma x)) = x.2.2.rows rw [hpw]; unfold rsQ; rw [hrs] /-- **Frobenius–Schur Identity** `∑_{λ ⊢ n} (f^λ)² = n!`, derived from the RS bijection. -/ theorem frobenius_schur_identity (n : ℕ) : ∑ lam : IntPart n, (Fintype.card (SYT lam)) ^ 2 = n.factorial := by have hcard := Fintype.card_congr (rsBijection n) rw [Fintype.card_perm, Fintype.card_fin, Fintype.card_sigma] at hcard rw [hcard] apply Finset.sum_congr rfl intro lam _ rw [Fintype.card_prod, sq] /-! ## Section 5: Schensted's LIS Theorem, Patience Piles & the Erdős–Szekeres Theorem -/ /-- First row of the insertion tableau, computed by patience sorting. -/ def firstRow (w : List ℕ) : List ℕ := w.foldl (fun r x => (rowInsert x r).1) [] lemma tabInsert_headD (x : ℕ) (P : List (List ℕ)) : (tabInsert x P).1.headD [] = (rowInsert x (P.headD [])).1 := by cases P with | nil => simp [tabInsert, rowInsert] | cons r rest => obtain ⟨⟨r', b⟩, hri⟩ : ∃ p, rowInsert x r = p := ⟨_, rfl⟩ cases b <;> simp [tabInsert, hri] lemma rsStep_headD (w : List ℕ) : ∀ (t : ℕ) (P Q : List (List ℕ)), (rsStep t P Q w).1.headD [] = w.foldl (fun r x => (rowInsert x r).1) (P.headD []) := by induction w with | nil => intro t P Q; simp [rsStep] | cons x xs ih => intro t P Q simp only [rsStep, List.foldl_cons] rw [ih, tabInsert_headD] /-- The first row of `P(w)` is the patience-sorting row `firstRow w`. -/ theorem rsP_headD (w : List ℕ) : (rsP w).headD [] = firstRow w := by have h := rsStep_headD w 0 [] [] simpa [rsP, rsWord, firstRow] using h lemma firstRow_append (u : List ℕ) (x : ℕ) : firstRow (u ++ [x]) = (rowInsert x (firstRow u)).1 := by simp [firstRow, List.foldl_append] /-- `u` has a weakly increasing subsequence of length `j + 1` ending in the value `v`. -/ def IncEnd (u : List ℕ) (j v : ℕ) : Prop := ∃ s : List ℕ, (s ++ [v]).Sublist u ∧ (s ++ [v]).Pairwise (· ≤ ·) ∧ s.length = j lemma IncEnd.mono {u : List ℕ} {j v : ℕ} (h : IncEnd u j v) (x : ℕ) : IncEnd (u ++ [x]) j v := by obtain ⟨s, hs, hp, hl⟩ := h exact ⟨s, hs.trans (List.sublist_append_left u [x]), hp, hl⟩ lemma IncEnd.single (u : List ℕ) (x : ℕ) : IncEnd (u ++ [x]) 0 x := ⟨[], by simp, by simp, rfl⟩ lemma IncEnd.extend {u : List ℕ} {j a x : ℕ} (h : IncEnd u j a) (hax : a ≤ x) : IncEnd (u ++ [x]) (j + 1) x := by obtain ⟨s, hs, hp, hl⟩ := h refine ⟨s ++ [a], hs.append_right [x], ?_, by simp [hl]⟩ rw [List.pairwise_append] refine ⟨hp, by simp, ?_⟩ intro b hb c hc simp only [List.mem_singleton] at hc subst hc rcases List.mem_append.mp hb with hb | hb · exact le_trans ((List.pairwise_append.mp hp).2.2 b hb a (by simp)) hax · simp only [List.mem_singleton] at hb; subst hb; exact hax lemma sublist_append_singleton_cases {s u : List ℕ} {v x : ℕ} (h : (s ++ [v]).Sublist (u ++ [x])) : (s ++ [v]).Sublist u ∨ (v = x ∧ s.Sublist u) := by rcases List.sublist_append_iff.mp h with ⟨l₁, l₂, heq, h₁, h₂⟩ rcases l₂ with _ | ⟨a, _ | ⟨b, t⟩⟩ · left; rw [List.append_nil] at heq; rw [heq]; exact h₁ · right have ha : a = x := by simpa using h₂.subset (List.mem_cons_self (a := a) (l := [])) subst ha obtain ⟨hs, hv⟩ := List.append_inj' heq rfl simp only [List.cons.injEq, and_true] at hv subst hs; exact ⟨hv, h₁⟩ · exfalso; have := h₂.length_le; simp at this lemma eq_nil_or_append_singleton (s : List ℕ) : s = [] ∨ ∃ s' v, s = s' ++ [v] := by rcases List.eq_nil_or_concat s with h | ⟨s', v, h⟩ · exact Or.inl h · exact Or.inr ⟨s', v, by rw [h, List.concat_eq_append]⟩ /-- **Patience-sorting invariant** for the first row `R` of `P(u)`: `R` is weakly increasing, `R[j]` is the end of a weakly increasing subsequence of length `j + 1`, and every weakly increasing subsequence of length `L + 1` ending in `v` satisfies `L < |R|` and `R[L] ≤ v`. -/ theorem patience_lis_invariant (u : List ℕ) : (firstRow u).Pairwise (· ≤ ·) ∧ (∀ j (hj : j < (firstRow u).length), IncEnd u j (firstRow u)[j]) ∧ (∀ s v, (s ++ [v]).Sublist u → (s ++ [v]).Pairwise (· ≤ ·) → ∃ h : s.length < (firstRow u).length, (firstRow u)[s.length] ≤ v) := by induction u using List.reverseRecOn with | nil => refine ⟨by simp [firstRow], fun j hj => by simp [firstRow] at hj, ?_⟩ intro s v hs _ have := hs.length_le; simp at this | append_singleton u x ih => obtain ⟨hpw, hex, hbd⟩ := ih rw [firstRow_append] obtain ⟨⟨R', b⟩, hri⟩ : ∃ p, rowInsert x (firstRow u) = p := ⟨_, rfl⟩ rw [hri] dsimp only have hpw' : R'.Pairwise (· ≤ ·) := rowInsert_preserves_pairwise_le hpw hri cases b with | none => obtain ⟨rfl, hall⟩ := rowInsert_none_eq hri refine ⟨hpw', ?_, ?_⟩ · intro j hj rw [List.length_append, List.length_singleton] at hj by_cases hjR : j < (firstRow u).length · rw [List.getElem_append_left hjR]; exact (hex j hjR).mono x · have hjeq : j = (firstRow u).length := by omega subst hjeq simp only [List.getElem_append_right (le_refl _), Nat.sub_self, List.getElem_singleton] rcases Nat.eq_zero_or_pos (firstRow u).length with h0 | hpos · rw [h0]; exact IncEnd.single u x · have h := (hex ((firstRow u).length - 1) (by omega)).extend (hall _ (List.getElem_mem _)) rwa [Nat.sub_add_cancel hpos] at h · intro s v hs hp rcases sublist_append_singleton_cases hs with hsu | ⟨hvx, hsu⟩ · obtain ⟨hlt, hle⟩ := hbd s v hsu hp refine ⟨by simp only [List.length_append, List.length_singleton]; omega, ?_⟩ rw [List.getElem_append_left hlt]; exact hle · rw [hvx] rcases eq_nil_or_append_singleton s with rfl | ⟨s', v', rfl⟩ · refine ⟨by simp, ?_⟩ rcases Nat.eq_zero_or_pos (firstRow u).length with h0 | hpos · have hR : firstRow u = [] := List.eq_nil_of_length_eq_zero h0 simp [hR] · simp only [List.length_nil] rw [List.getElem_append_left hpos]; exact hall _ (List.getElem_mem _) · have hp' : (s' ++ [v']).Pairwise (· ≤ ·) := (List.pairwise_append.mp hp).1 obtain ⟨hlt, _⟩ := hbd s' v' hsu hp' have hL : (s' ++ [v']).length = s'.length + 1 := by simp refine ⟨by rw [hL]; simp only [List.length_append, List.length_singleton]; omega, ?_⟩ by_cases hLR : s'.length + 1 < (firstRow u).length · simp only [hL]; rw [List.getElem_append_left hLR]; exact hall _ (List.getElem_mem _) · have hL' : s'.length + 1 = (firstRow u).length := by omega simp only [hL, hL']; simp | some y => obtain ⟨hlen', hxy, _, k, hk, hk', hgetk, hgetk', hbefore, hother⟩ := rowInsert_some_spec hri refine ⟨hpw', ?_, ?_⟩ · intro j hj by_cases hjk : j = k · subst hjk rw [hgetk'] rcases Nat.eq_zero_or_pos j with h0 | hpos · subst h0; exact IncEnd.single u x · have h := (hex (j - 1) (by omega)).extend (hbefore (j - 1) (by omega)) rwa [Nat.sub_add_cancel hpos] at h · have hjR : j < (firstRow u).length := hlen' ▸ hj rw [hother j hjR hj hjk]; exact (hex j hjR).mono x · intro s v hs hp rcases sublist_append_singleton_cases hs with hsu | ⟨hvx, hsu⟩ · obtain ⟨hlt, hle⟩ := hbd s v hsu hp exact ⟨hlen' ▸ hlt, le_trans (rowInsert_getElem_le hri hlt _) hle⟩ · rcases eq_nil_or_append_singleton s with rfl | ⟨s', v', rfl⟩ · refine ⟨by simp only [List.length_nil]; omega, ?_⟩ rw [hvx] by_cases hk0 : k = 0 · subst hk0; simpa using hgetk'.le · simp only [List.length_nil] rw [hother 0 (by omega) (by omega) (Ne.symm hk0)] exact hbefore 0 (by omega) · have hp' : (s' ++ [v']).Pairwise (· ≤ ·) := (List.pairwise_append.mp hp).1 have hv'v : v' ≤ v := (List.pairwise_append.mp hp).2.2 v' (by simp) v (by simp) obtain ⟨hlt, hle⟩ := hbd s' v' hsu hp' have hsk : s'.length < k := by by_contra hge push Not at hge have h1 : (firstRow u)[k] ≤ (firstRow u)[s'.length] := pairwise_getElem_le hpw hge hlt rw [hgetk] at h1 omega have hL : (s' ++ [v']).length = s'.length + 1 := by simp refine ⟨by rw [hL]; omega, ?_⟩ rw [hvx] by_cases hLk : s'.length + 1 = k · simp only [hL, hLk]; rw [hgetk'] · have hLlt : s'.length + 1 < (firstRow u).length := by omega simp only [hL] rw [hother (s'.length + 1) hLlt (by omega) hLk] exact hbefore _ (by omega) /-- **Schensted's Theorem (first row)**: `λ₁(P(w))` equals the maximum length of a weakly increasing subsequence of the word `w`. -/ theorem schensted_lis (w : List ℕ) : (∃ s : List ℕ, s.Sublist w ∧ s.Pairwise (· ≤ ·) ∧ s.length = ((rsP w).headD []).length) ∧ (∀ s : List ℕ, s.Sublist w → s.Pairwise (· ≤ ·) → s.length ≤ ((rsP w).headD []).length) := by rw [rsP_headD] obtain ⟨_, hex, hbd⟩ := patience_lis_invariant w refine ⟨?_, ?_⟩ · rcases Nat.eq_zero_or_pos (firstRow w).length with h0 | hpos · exact ⟨[], List.nil_sublist _, List.Pairwise.nil, by simp [h0]⟩ · obtain ⟨s, hs, hp, hl⟩ := hex _ (Nat.sub_lt hpos Nat.one_pos) exact ⟨_, hs, hp, by simp only [List.length_append, List.length_singleton, hl]; omega⟩ · intro s hs hp rcases eq_nil_or_append_singleton s with rfl | ⟨s', v, rfl⟩ · simp · obtain ⟨hlt, _⟩ := hbd s' v hs hp simp only [List.length_append, List.length_singleton]; omega /-- Schensted's theorem for duplicate-free words: `λ₁(P(w)) = LIS(w)` (strictly increasing). -/ theorem schensted_lis_nodup (w : List ℕ) (hw : w.Nodup) : (∃ s : List ℕ, s.Sublist w ∧ s.Pairwise (· < ·) ∧ s.length = ((rsP w).headD []).length) ∧ (∀ s : List ℕ, s.Sublist w → s.Pairwise (· < ·) → s.length ≤ ((rsP w).headD []).length) := by obtain ⟨⟨s, hs, hp, hl⟩, hbd⟩ := schensted_lis w exact ⟨⟨s, hs, pairwise_lt_of_pairwise_le_nodup hp (hs.nodup hw), hl⟩, fun t ht htp => hbd t ht (htp.imp Nat.le_of_lt)⟩ lemma headD_eq_getD_zero (L : List (List ℕ)) : L.headD [] = L.getD 0 [] := by cases L <;> rfl /-- **Schensted's LIS Theorem for permutations**: for every `w ∈ S_n`, the first part `λ₁` of the RS shape of `w` equals the length of the longest increasing subsequence of `w`. -/ theorem schensted_lis_perm {n : ℕ} (w : Equiv.Perm (Fin n)) : (∃ s : List ℕ, s.Sublist (permToWord w) ∧ s.Pairwise (· < ·) ∧ s.length = partAt (rsBijection n w).1.parts 0) ∧ (∀ s : List ℕ, s.Sublist (permToWord w) → s.Pairwise (· < ·) → s.length ≤ partAt (rsBijection n w).1.parts 0) := by have hlam : partAt (rsBijection n w).1.parts 0 = ((rsP (permToWord w)).headD []).length := by change partAt ((rsP (permToWord w)).map List.length) 0 = _ rw [partAt_map_length, headD_eq_getD_zero] rw [hlam] exact schensted_lis_nodup _ (permToWord_nodup w) /-- `u` has a strictly decreasing subsequence of length `len` ending in the value `v`. -/ def DecEnd (u : List ℕ) (len v : ℕ) : Prop := ∃ s : List ℕ, (s ++ [v]).Sublist u ∧ (s ++ [v]).Pairwise (· > ·) ∧ s.length + 1 = len /-- **Patience piles**: each first-row position `k` carries a pile of size `c k` that is a strictly decreasing subsequence ending in `R[k]`, and the pile sizes sum to `|u|`. -/ theorem patience_piles (u : List ℕ) : ∃ c : ℕ → ℕ, (∑ k ∈ Finset.range (firstRow u).length, c k) = u.length ∧ ∀ k (hk : k < (firstRow u).length), DecEnd u (c k) (firstRow u)[k] := by induction u using List.reverseRecOn with | nil => exact ⟨fun _ => 0, by simp [firstRow], fun k hk => by simp [firstRow] at hk⟩ | append_singleton u x ih => obtain ⟨c, hsum, hdec⟩ := ih rw [firstRow_append] obtain ⟨⟨R', b⟩, hri⟩ : ∃ p, rowInsert x (firstRow u) = p := ⟨_, rfl⟩ rw [hri] dsimp only have hmono : ∀ {len v}, DecEnd u len v → DecEnd (u ++ [x]) len v := by rintro len v ⟨s, hs, hp, hl⟩ exact ⟨s, hs.trans (List.sublist_append_left u [x]), hp, hl⟩ cases b with | none => obtain ⟨rfl, _⟩ := rowInsert_none_eq hri refine ⟨Function.update c (firstRow u).length 1, ?_, ?_⟩ · rw [List.length_append, List.length_singleton, Finset.sum_range_succ, Function.update_self] have hcong : ∑ k ∈ Finset.range (firstRow u).length, Function.update c (firstRow u).length 1 k = ∑ k ∈ Finset.range (firstRow u).length, c k := Finset.sum_congr rfl fun k hk => Function.update_of_ne (Finset.mem_range.mp hk).ne _ _ rw [hcong, hsum, List.length_append, List.length_singleton] · intro k hk rw [List.length_append, List.length_singleton] at hk by_cases hkR : k < (firstRow u).length · rw [Function.update_of_ne hkR.ne, List.getElem_append_left hkR]; exact hmono (hdec k hkR) · have hkeq : k = (firstRow u).length := by omega subst hkeq rw [Function.update_self] simp only [List.getElem_append_right (le_refl _), Nat.sub_self, List.getElem_singleton] exact ⟨[], by simp, by simp, rfl⟩ | some y => obtain ⟨hlen', hxy, _, k₀, hk₀, hk₀', hgetk, hgetk', _, hother⟩ := rowInsert_some_spec hri refine ⟨Function.update c k₀ (c k₀ + 1), ?_, ?_⟩ · rw [hlen', List.length_append, List.length_singleton, ← hsum, Finset.sum_update_of_mem (Finset.mem_range.mpr hk₀), ← Finset.add_sum_erase _ _ (Finset.mem_range.mpr hk₀), Finset.sdiff_singleton_eq_erase] ring · intro k hk by_cases hkk : k = k₀ · subst hkk rw [Function.update_self, hgetk'] obtain ⟨s, hs, hp, hl⟩ := hdec k hk₀ rw [hgetk] at hs hp refine ⟨s ++ [y], hs.append_right [x], ?_, by simp [hl]⟩ rw [List.pairwise_append] refine ⟨hp, by simp, ?_⟩ intro b hb c' hc' simp only [List.mem_singleton] at hc' subst hc' rcases List.mem_append.mp hb with hb | hb · exact lt_trans hxy ((List.pairwise_append.mp hp).2.2 b hb y (by simp)) · simp only [List.mem_singleton] at hb; subst hb; exact hxy · have hkR : k < (firstRow u).length := hlen' ▸ hk rw [Function.update_of_ne hkk, hother k hkR hk hkk]; exact hmono (hdec k hkR) /-- **Erdős–Szekeres Theorem (via RS / patience sorting)**: every word `w` has a weakly increasing subsequence `a` of length exactly `λ₁(P(w))` and a strictly decreasing subsequence `b` with `|w| ≤ |a| · |b|`. -/ theorem erdos_szekeres (w : List ℕ) : ∃ a b : List ℕ, a.Sublist w ∧ a.Pairwise (· ≤ ·) ∧ a.length = ((rsP w).headD []).length ∧ b.Sublist w ∧ b.Pairwise (· > ·) ∧ w.length ≤ a.length * b.length := by rw [rsP_headD] obtain ⟨_, hex, _⟩ := patience_lis_invariant w obtain ⟨c, hsum, hdec⟩ := patience_piles w rcases Nat.eq_zero_or_pos (firstRow w).length with h0 | hpos · refine ⟨[], [], List.nil_sublist _, List.Pairwise.nil, by simp [h0], List.nil_sublist _, List.Pairwise.nil, ?_⟩ rw [h0, Finset.sum_range_zero] at hsum simp [← hsum] · obtain ⟨s, hs, hp, hl⟩ := hex ((firstRow w).length - 1) (by omega) obtain ⟨k, hk, hmax⟩ := Finset.exists_max_image (Finset.range (firstRow w).length) c ⟨0, Finset.mem_range.mpr hpos⟩ obtain ⟨t, ht, htp, htl⟩ := hdec k (Finset.mem_range.mp hk) refine ⟨_, _, hs, hp, by simp only [List.length_append, List.length_singleton, hl]; omega, ht, htp, ?_⟩ have hbound : (∑ i ∈ Finset.range (firstRow w).length, c i) ≤ ∑ _i ∈ Finset.range (firstRow w).length, c k := Finset.sum_le_sum fun i hi => hmax i hi rw [Finset.sum_const, Finset.card_range, smul_eq_mul, hsum] at hbound simp only [List.length_append, List.length_singleton] rw [htl, hl, Nat.sub_add_cancel hpos] exact hbound /-- **Erdős–Szekeres for permutations / duplicate-free words**: `|w| ≤ LIS(w) · LDS(w)`. -/ theorem erdos_szekeres_nodup (w : List ℕ) (hw : w.Nodup) : ∃ a b : List ℕ, a.Sublist w ∧ a.Pairwise (· < ·) ∧ b.Sublist w ∧ b.Pairwise (· > ·) ∧ w.length ≤ a.length * b.length := by obtain ⟨a, b, ha, hap, _, hb, hbp, hlen⟩ := erdos_szekeres w exact ⟨a, b, ha, pairwise_lt_of_pairwise_le_nodup hap (ha.nodup hw), hb, hbp, hlen⟩ /-- Rectangular Erdős–Szekeres witness: `s` blocks of `r` increasing values, blocks decreasing. -/ def esWitness (r : ℕ) : ℕ → List ℕ | 0 => [] | s + 1 => (List.range r).map (· + s * r) ++ esWitness r s lemma mem_esWitness_iff (r : ℕ) : ∀ (s x : ℕ), x ∈ esWitness r s ↔ x < s * r | 0, x => by simp [esWitness] | s + 1, x => by have hm : (s + 1) * r = s * r + r := by ring simp only [esWitness, List.mem_append, List.mem_map, List.mem_range, mem_esWitness_iff r s x] constructor · rintro (⟨a, ha, rfl⟩ | hx) <;> omega · intro hx by_cases h : s * r ≤ x · exact Or.inl ⟨x - s * r, by omega, by omega⟩ · exact Or.inr (by omega) lemma esWitness_nodup (r : ℕ) : ∀ s, (esWitness r s).Nodup | 0 => by simp [esWitness] | s + 1 => by rw [esWitness, List.nodup_append] refine ⟨List.nodup_range.map (fun a b h => by simpa using h), esWitness_nodup r s, ?_⟩ intro a ha b hb hab simp only [List.mem_map, List.mem_range] at ha obtain ⟨a', _, rfl⟩ := ha have := (mem_esWitness_iff r s b).mp hb omega lemma esWitness_inc_bound (r : ℕ) : ∀ (s : ℕ) (a : List ℕ), a.Sublist (esWitness r s) → a.Pairwise (· ≤ ·) → a.length ≤ r | 0, a, ha, _ => by simp [esWitness] at ha; simp [ha] | s + 1, a, ha, hp => by rw [esWitness] at ha obtain ⟨a₁, a₂, rfl, h₁, h₂⟩ := List.sublist_append_iff.mp ha by_cases ha₂ : a₂ = [] · subst ha₂; simpa using h₁.length_le · by_cases ha₁ : a₁ = [] · subst ha₁; simpa using esWitness_inc_bound r s a₂ h₂ (by simpa using hp) · exfalso obtain ⟨p, hp₁⟩ := List.exists_mem_of_ne_nil a₁ ha₁ obtain ⟨q, hq₂⟩ := List.exists_mem_of_ne_nil a₂ ha₂ have hpq : p ≤ q := (List.pairwise_append.mp hp).2.2 p hp₁ q hq₂ have hp' := h₁.subset hp₁ simp only [List.mem_map, List.mem_range] at hp' obtain ⟨p', _, rfl⟩ := hp' have := (mem_esWitness_iff r s q).mp (h₂.subset hq₂) omega lemma esWitness_dec_bound (r : ℕ) : ∀ (s : ℕ) (b : List ℕ), b.Sublist (esWitness r s) → b.Pairwise (· > ·) → b.length ≤ s | 0, b, hb, _ => by simp [esWitness] at hb; simp [hb] | s + 1, b, hb, hp => by rw [esWitness] at hb obtain ⟨b₁, b₂, rfl, h₁, h₂⟩ := List.sublist_append_iff.mp hb have hp₁ : b₁.Pairwise (· > ·) := (List.pairwise_append.mp hp).1 have hp₂ : b₂.Pairwise (· > ·) := (List.pairwise_append.mp hp).2.1 have hinc : b₁.Pairwise (· < ·) := by have hB : ((List.range r).map (· + s * r)).Pairwise (· < ·) := by rw [List.pairwise_map]; exact List.pairwise_lt_range.imp (fun h => by omega) exact hB.sublist h₁ have hb₁ : b₁.length ≤ 1 := by rcases b₁ with _ | ⟨p, _ | ⟨q, rest⟩⟩ · simp · simp · exfalso have h1 := List.rel_of_pairwise_cons hp₁ (List.mem_cons_self (a := q) (l := rest)) have h2 := List.rel_of_pairwise_cons hinc (List.mem_cons_self (a := q) (l := rest)) omega have := esWitness_dec_bound r s b₂ h₂ hp₂ simp only [List.length_append]; omega /-- Decreasing transversal `[(s-1)·r, …, r, 0]` of `esWitness r s` (first entry of each block). -/ def esDiag (r : ℕ) : ℕ → List ℕ | 0 => [] | s + 1 => (s * r) :: esDiag r s lemma esDiag_spec (r : ℕ) (hr : 0 < r) : ∀ s, (esDiag r s).Sublist (esWitness r s) ∧ (esDiag r s).Pairwise (· > ·) ∧ (esDiag r s).length = s | 0 => by simp [esDiag, esWitness] | s + 1 => by obtain ⟨h1, h2, h3⟩ := esDiag_spec r hr s refine ⟨?_, ?_, by simp [esDiag, h3]⟩ · obtain ⟨r', hr'⟩ : ∃ r', r = r' + 1 := ⟨r - 1, by omega⟩ have hblock : (List.range r).map (· + s * r) = (s * r) :: ((List.range r').map Nat.succ).map (· + s * r) := by rw [hr', List.range_succ_eq_map, List.map_cons, Nat.zero_add] rw [esDiag, esWitness, hblock, List.cons_append] exact (h1.trans (List.sublist_append_right _ _)).cons_cons _ · rw [esDiag, List.pairwise_cons] exact ⟨fun y hy => (mem_esWitness_iff r s y).mp (h1.subset hy), h2⟩ /-- **Sharpness of Erdős–Szekeres**: for all `r, s ≥ 1` the explicit permutation `esWitness r s` of `[0, rs)` has longest increasing subsequence exactly `r` and longest decreasing subsequence exactly `s`, so `|w| = LIS(w) · LDS(w)` is attained. -/ theorem erdos_szekeres_sharp (r s : ℕ) (hr : 0 < r) (hs : 0 < s) : (esWitness r s).Perm (List.range (r * s)) ∧ (∃ a : List ℕ, a.Sublist (esWitness r s) ∧ a.Pairwise (· < ·) ∧ a.length = r) ∧ (∀ a : List ℕ, a.Sublist (esWitness r s) → a.Pairwise (· < ·) → a.length ≤ r) ∧ (∃ b : List ℕ, b.Sublist (esWitness r s) ∧ b.Pairwise (· > ·) ∧ b.length = s) ∧ (∀ b : List ℕ, b.Sublist (esWitness r s) → b.Pairwise (· > ·) → b.length ≤ s) := by refine ⟨?_, ?_, fun a ha hp => esWitness_inc_bound r s a ha (hp.imp Nat.le_of_lt), ⟨esDiag r s, esDiag_spec r hr s⟩, esWitness_dec_bound r s⟩ · rw [List.perm_ext_iff_of_nodup (esWitness_nodup r s) List.nodup_range] intro x rw [mem_esWitness_iff, List.mem_range, Nat.mul_comm] · obtain ⟨s', rfl⟩ : ∃ s', s = s' + 1 := ⟨s - 1, by omega⟩ refine ⟨(List.range r).map (· + s' * r), List.sublist_append_left _ _, ?_, by simp⟩ rw [List.pairwise_map]; exact List.pairwise_lt_range.imp (fun h => by omega) /-! ## Section 6: Fomin Growth Diagrams, Universal Schützenberger Symmetry & the Involution Identity -/ /-- Row-length profile of a tableau as a function `ℕ → ℕ` (0 past the end). -/ def tabShape (T : List (List ℕ)) (k : ℕ) : ℕ := (T.getD k []).length lemma tabShape_nil (k : ℕ) : tabShape [] k = 0 := rfl lemma tabShape_cons_zero (r : List ℕ) (rest : List (List ℕ)) : tabShape (r :: rest) 0 = r.length := rfl lemma tabShape_cons_succ (r : List ℕ) (rest : List (List ℕ)) (k : ℕ) : tabShape (r :: rest) (k + 1) = tabShape rest k := rfl lemma tabShape_eq_of_map_length_eq {T₁ T₂ : List (List ℕ)} (h : T₁.map List.length = T₂.map List.length) : tabShape T₁ = tabShape T₂ := by funext k unfold tabShape by_cases hk : k < T₁.length · have hk₂ : k < T₂.length := by have := congrArg List.length h; simp at this; omega rw [List.getD_eq_getElem _ _ hk, List.getD_eq_getElem _ _ hk₂] have hm := List.getElem_of_eq h (i := k) (by simp [hk]) simpa using hm · have hk₂ : ¬ k < T₂.length := by have := congrArg List.length h; simp at this; omega rw [List.getD_eq_default _ _ (Nat.le_of_not_lt hk), List.getD_eq_default _ _ (Nat.le_of_not_lt hk₂)] /-- **Fomin's symmetric local growth-diagram rule** on row-length profiles: given SW = `μ`, NW = `ν`, SE = `ρ`, and cell bit `b`, returns NE = `λ`. -/ def fominStep (μ ν ρ : ℕ → ℕ) (b : Bool) : ℕ → ℕ | 0 => if b then μ 0 + 1 else max (ν 0) (ρ 0) | k + 1 => if μ k < ν k ∧ μ k < ρ k then μ (k + 1) + 1 else max (ν (k + 1)) (ρ (k + 1)) lemma fominStep_comm (μ ν ρ : ℕ → ℕ) (b : Bool) : fominStep μ ν ρ b = fominStep μ ρ ν b := by funext k cases k with | zero => simp [fominStep, max_comm] | succ k => simp [fominStep, and_comm, max_comm] /-- Fomin growth diagram for a permutation `w ∈ S_n`: `fominGrid w r c` is the partition shape at grid vertex `(r, c)`. -/ def fominGrid {n : ℕ} (w : Equiv.Perm (Fin n)) : ℕ → ℕ → (ℕ → ℕ) | 0, _ => fun _ => 0 | _ + 1, 0 => fun _ => 0 | r + 1, c + 1 => fominStep (fominGrid w r c) (fominGrid w (r + 1) c) (fominGrid w r (c + 1)) (if hr : r < n then decide ((w ⟨r, hr⟩).1 = c) else false) lemma fominGrid_zero_left {n : ℕ} (w : Equiv.Perm (Fin n)) (c : ℕ) : fominGrid w 0 c = fun _ => 0 := by simp [fominGrid] lemma fominGrid_zero_right {n : ℕ} (w : Equiv.Perm (Fin n)) (r : ℕ) : fominGrid w r 0 = fun _ => 0 := by cases r <;> simp [fominGrid] /-- **Transpose symmetry of Fomin's growth diagram**: `fominGrid w⁻¹ r c = fominGrid w c r` for all `r ≤ n`, `c ≤ n`. -/ lemma fominGrid_inv {n : ℕ} (w : Equiv.Perm (Fin n)) : ∀ r c, r ≤ n → c ≤ n → fominGrid w⁻¹ r c = fominGrid w c r | 0, c, _, _ => by rw [fominGrid_zero_left, fominGrid_zero_right] | r + 1, 0, _, _ => by rw [fominGrid_zero_right, fominGrid_zero_left] | r + 1, c + 1, hr, hc => by have hrn : r < n := Nat.lt_of_succ_le hr have hcn : c < n := Nat.lt_of_succ_le hc have hbit : decide ((w⁻¹ ⟨r, hrn⟩).1 = c) = decide ((w ⟨c, hcn⟩).1 = r) := by apply decide_eq_decide.mpr constructor · intro h have hfin : w⁻¹ ⟨r, hrn⟩ = ⟨c, hcn⟩ := Fin.ext h exact congrArg Fin.val ((Equiv.symm_apply_eq w).mp hfin).symm · intro h have hfin : w ⟨c, hcn⟩ = ⟨r, hrn⟩ := Fin.ext h exact congrArg Fin.val ((Equiv.symm_apply_eq w).mpr hfin.symm) simp only [fominGrid, dif_pos hrn, dif_pos hcn, hbit] rw [fominGrid_inv w r c (Nat.le_of_lt hrn) (Nat.le_of_lt hcn), fominGrid_inv w (r + 1) c hr (Nat.le_of_lt hcn), fominGrid_inv w r (c + 1) (Nat.le_of_lt hrn) hc, fominStep_comm] /-- Restrict a tableau to entries strictly less than `c`, stopping at the first empty filtered row. -/ def tabRestrict (c : ℕ) : List (List ℕ) → List (List ℕ) | [] => [] | r :: rest => let r' := r.filter (· < c) if r'.isEmpty then [] else r' :: tabRestrict c rest lemma tabRestrict_zero (T : List (List ℕ)) : tabRestrict 0 T = [] := by cases T with | nil => rfl | cons r rest => simp [tabRestrict] lemma tabRestrict_eq_self {c : ℕ} : ∀ {T : List (List ℕ)}, (∀ r ∈ T, r ≠ []) → (∀ a ∈ T.flatten, a < c) → tabRestrict c T = T | [], _, _ => rfl | r :: rest, hne, hlt => by have hflt : r.filter (· < c) = r := List.filter_eq_self.mpr fun a ha => decide_eq_true (hlt a (by simp [ha])) have hne_r : r ≠ [] := hne r (by simp) have his : r.isEmpty = false := by cases r with | nil => exact absurd rfl hne_r | cons _ _ => rfl simp only [tabRestrict, hflt, his, Bool.false_eq_true, ↓reduceIte] congr 1 exact tabRestrict_eq_self (fun s hs => hne s (List.mem_cons_of_mem r hs)) (fun a ha => hlt a (by simp [ha])) lemma tabRestrict_nil_of_all_ge {c : ℕ} {T : List (List ℕ)} (h : ∀ a ∈ T.flatten, c ≤ a) : tabRestrict c T = [] := by cases T with | nil => rfl | cons r rest => have hflt : r.filter (· < c) = [] := List.filter_eq_nil_iff.mpr fun a ha => by have := h a (by simp [ha]); simp; omega simp [tabRestrict, hflt] lemma tabRestrict_tail_nil_of_head_filter_nil {c : ℕ} {r : List ℕ} {rest : List (List ℕ)} (hssyt : IsSSYT (r :: rest)) (hflt : r.filter (· < c) = []) : tabRestrict c rest = [] := by have hr_ne : r ≠ [] := hssyt.1 r (by simp) have hr_pos : 0 < r.length := List.length_pos_iff.mpr hr_ne have hr0_ge : c ≤ r[0] := by by_contra hlt push Not at hlt have : r[0] ∈ r.filter (· < c) := List.mem_filter.mpr ⟨List.getElem_mem hr_pos, by simpa⟩ rw [hflt] at this; simp at this apply tabRestrict_nil_of_all_ge intro y hy exact Nat.le_of_lt (lt_of_le_of_lt hr0_ge (isSSYT_head_lt_tail_flatten hssyt hr_pos hy)) lemma tabShape_tabRestrict_le (c : ℕ) : ∀ (T : List (List ℕ)) (k : ℕ), tabShape (tabRestrict c T) k ≤ tabShape T k | [], _ => le_rfl | r :: rest, k => by simp only [tabRestrict] split_ifs with hemp · exact Nat.zero_le _ · cases k with | zero => exact List.length_filter_le _ _ | succ k => exact tabShape_tabRestrict_le c rest k lemma tabShape_tabInsert_ge : ∀ (x : ℕ) (T : List (List ℕ)) (k : ℕ), tabShape T k ≤ tabShape (tabInsert x T).1 k | x, [], k => by cases k <;> simp [tabInsert, tabShape] | x, r :: rest, k => by simp only [tabInsert] cases hri : rowInsert x r with | mk r' b => cases b with | none => rcases rowInsert_none_eq hri with ⟨rfl, _⟩ cases k with | zero => simp [tabShape] | succ k => exact le_rfl | some y => rcases rowInsert_some_spec hri with ⟨hlen, _⟩ cases k with | zero => simp [tabShape, hlen] | succ k => exact tabShape_tabInsert_ge y rest k lemma rowInsert_filter_lt_of_ge {c x : ℕ} (hcx : c ≤ x) : ∀ {r r' : List ℕ} {b : Option ℕ}, rowInsert x r = (r', b) → r'.filter (· < c) = r.filter (· < c) | [], r', b, h => by simp [rowInsert] at h; rcases h with ⟨rfl, rfl⟩ simp; omega | a :: rest, r', b, h => by simp only [rowInsert] at h split_ifs at h with hlt · simp only [Prod.mk.injEq] at h; rcases h with ⟨rfl, rfl⟩ have h1 : ¬ (x < c) := by omega have h2 : ¬ (a < c) := by omega simp [h1, h2] · cases hrec : rowInsert x rest with | mk rest' b' => rw [hrec] at h; simp only [Prod.mk.injEq] at h; rcases h with ⟨rfl, rfl⟩ simp only [List.filter_cons] rw [rowInsert_filter_lt_of_ge hcx hrec] /-- Inserting a value `x ≥ c` does not change the `< c` restriction of an SSYT. -/ lemma tabRestrict_tabInsert_ge {c x : ℕ} (hcx : c ≤ x) : ∀ {T : List (List ℕ)}, IsSSYT T → tabRestrict c (tabInsert x T).1 = tabRestrict c T | [], _ => by simp only [tabInsert, tabRestrict, List.filter_cons, List.filter_nil] have hnot : ¬ (x < c) := by omega simp [hnot] | r :: rest, hssyt => by simp only [tabInsert] cases hri : rowInsert x r with | mk r' b => have hflt : r'.filter (· < c) = r.filter (· < c) := rowInsert_filter_lt_of_ge hcx hri cases b with | none => simp only [tabRestrict, hflt] | some y => rcases rowInsert_some_spec hri with ⟨_, hxy, _⟩ have hssyt_rest : IsSSYT rest := ⟨fun s hs => hssyt.1 s (List.mem_cons_of_mem r hs), fun s hs => hssyt.2.1 s (List.mem_cons_of_mem r hs), by cases rest with | nil => trivial | cons _ _ => exact hssyt.2.2.2.2⟩ simp only [tabRestrict, hflt] split_ifs · rfl · congr 1 exact tabRestrict_tabInsert_ge (le_trans hcx (Nat.le_of_lt hxy)) hssyt_rest lemma pairwise_split_lt_ge (c : ℕ) : ∀ {r : List ℕ}, r.Pairwise (· ≤ ·) → ∃ rge : List ℕ, r = r.filter (· < c) ++ rge ∧ ∀ a ∈ rge, c ≤ a | [], _ => ⟨[], rfl, fun _ h => by simp at h⟩ | a :: rest, hpw => by obtain ⟨ha_le, hrest_pw⟩ := List.pairwise_cons.mp hpw by_cases hac : a < c · obtain ⟨rge, heq, hge⟩ := pairwise_split_lt_ge c hrest_pw refine ⟨rge, ?_, hge⟩ simp only [List.filter_cons, decide_eq_true hac, ↓reduceIte, List.cons_append] exact congrArg (a :: ·) heq · have hflt_nil : rest.filter (· < c) = [] := List.filter_eq_nil_iff.mpr fun z hz => by have := ha_le z hz; simp; omega refine ⟨a :: rest, ?_, ?_⟩ · simp [hac, hflt_nil] · intro z hz rcases List.mem_cons.mp hz with rfl | hz · omega · have := ha_le z hz; omega lemma rowInsert_append_of_some {x y : ℕ} : ∀ {l₁ l₂ l₁' : List ℕ}, rowInsert x l₁ = (l₁', some y) → rowInsert x (l₁ ++ l₂) = (l₁' ++ l₂, some y) | [], _, _, h => by simp [rowInsert] at h | a :: rest, l₂, l₁', h => by simp only [rowInsert] at h simp only [List.cons_append, rowInsert] split_ifs at h with hlt · simp only [Prod.mk.injEq, Option.some.injEq] at h rcases h with ⟨rfl, rfl⟩ simp [hlt] · simp only [hlt, ↓reduceIte] cases hrec : rowInsert x rest with | mk rest' b => rw [hrec] at h; simp only [Prod.mk.injEq] at h; rcases h with ⟨rfl, rfl⟩ rw [rowInsert_append_of_some hrec]; rfl lemma rowInsert_append_of_none {x : ℕ} : ∀ {l₁ l₂ : List ℕ}, (∀ a ∈ l₁, a ≤ x) → rowInsert x (l₁ ++ l₂) = (l₁ ++ (rowInsert x l₂).1, (rowInsert x l₂).2) | [], l₂, _ => by simp | a :: rest, l₂, hall => by have ha : a ≤ x := hall a (by simp) have hnot : ¬ (x < a) := by omega simp only [List.cons_append, rowInsert, hnot, ↓reduceIte] rw [rowInsert_append_of_none (fun z hz => hall z (List.mem_cons_of_mem a hz))] /-- Inserting a value `x < c` commutes with `< c` restriction on any SSYT. -/ lemma tabRestrict_tabInsert_lt {c x : ℕ} (hxc : x < c) : ∀ {T : List (List ℕ)}, IsSSYT T → tabRestrict c (tabInsert x T).1 = (tabInsert x (tabRestrict c T)).1 | [], _ => by simp [tabInsert, tabRestrict, hxc] | r :: rest, hssyt => by have hssyt_rest : IsSSYT rest := ⟨fun s hs => hssyt.1 s (List.mem_cons_of_mem r hs), fun s hs => hssyt.2.1 s (List.mem_cons_of_mem r hs), by cases rest with | nil => trivial | cons _ _ => exact hssyt.2.2.2.2⟩ obtain ⟨rge, hr_eq, hrge⟩ := pairwise_split_lt_ge c (hssyt.2.1 r (by simp)) set rlt := r.filter (· < c) with hrlt_def have hrlt_lt : ∀ a ∈ rlt, a < c := fun a ha => of_decide_eq_true (List.mem_filter.mp ha).2 have hrge_flt : rge.filter (· < c) = [] := List.filter_eq_nil_iff.mpr fun a ha => by have := hrge a ha; simp; omega cases hri_lt : rowInsert x rlt with | mk rlt' b => cases b with | some y => rcases rowInsert_some_spec hri_lt with ⟨_, _, ⟨hperm, hy_mem⟩, _⟩ have hy_lt : y < c := hrlt_lt y hy_mem have hrlt'_lt : ∀ a ∈ rlt', a < c := by intro a ha have := hperm.subset ha rcases List.mem_cons.mp this with rfl | ha' · exact hxc · exact hrlt_lt a (List.mem_of_mem_erase ha') have hrlt'_ne : rlt' ≠ [] := rowInsert_nonempty hri_lt have hrlt_ne : rlt ≠ [] := fun h => by rw [h] at hy_mem; simp at hy_mem have hri_r : rowInsert x r = (rlt' ++ rge, some y) := by rw [hr_eq]; exact rowInsert_append_of_some hri_lt have hflt_new : (rlt' ++ rge).filter (· < c) = rlt' := by rw [List.filter_append, hrge_flt, List.append_nil] exact List.filter_eq_self.mpr fun a ha => decide_eq_true (hrlt'_lt a ha) have his_rlt : rlt.isEmpty = false := by cases h : rlt with | nil => exact absurd h hrlt_ne | cons _ _ => rfl have his_rlt' : rlt'.isEmpty = false := by cases h : rlt' with | nil => exact absurd h hrlt'_ne | cons _ _ => rfl simp only [tabInsert, hri_r, tabRestrict, hflt_new, his_rlt', ← hrlt_def, his_rlt, Bool.false_eq_true, ↓reduceIte, hri_lt] congr 1 exact tabRestrict_tabInsert_lt hy_lt hssyt_rest | none => rcases rowInsert_none_eq hri_lt with ⟨rfl, hall_le⟩ have hrlt_append_flt : (rlt ++ [x]).filter (· < c) = rlt ++ [x] := List.filter_eq_self.mpr fun a ha => by rcases List.mem_append.mp ha with ha | ha · exact decide_eq_true (hrlt_lt a ha) · simp only [List.mem_singleton] at ha; subst ha; exact decide_eq_true hxc have his_app : (rlt ++ [x]).isEmpty = false := by cases rlt <;> rfl cases rge with | nil => have hri_r : rowInsert x r = (rlt ++ [x], none) := by rw [hr_eq, List.append_nil]; exact hri_lt simp only [tabInsert, hri_r, tabRestrict, hrlt_append_flt, his_app, Bool.false_eq_true, ↓reduceIte, ← hrlt_def] by_cases hemp : rlt.isEmpty · have hnil : rlt = [] := List.isEmpty_iff.mp hemp rw [tabRestrict_tail_nil_of_head_filter_nil hssyt hnil] simp [hnil, tabInsert] · simp only [hemp, Bool.false_eq_true, ↓reduceIte, tabInsert, hri_lt] | cons a rge' => have ha_ge : c ≤ a := hrge a (by simp) have hxa : x < a := lt_of_lt_of_le hxc ha_ge have hri_r : rowInsert x r = (rlt ++ x :: rge', some a) := by rw [hr_eq, rowInsert_append_of_none hall_le] simp [rowInsert, hxa] have hrge'_flt : rge'.filter (· < c) = [] := List.filter_eq_nil_iff.mpr fun z hz => by have := hrge z (List.mem_cons_of_mem a hz); simp; omega have hflt_new : (rlt ++ x :: rge').filter (· < c) = rlt ++ [x] := by rw [List.filter_append, List.filter_cons, decide_eq_true hxc, if_pos rfl, hrge'_flt] rw [List.filter_eq_self.mpr fun z hz => decide_eq_true (hrlt_lt z hz)] simp only [tabInsert, hri_r, tabRestrict, hflt_new, his_app, Bool.false_eq_true, ↓reduceIte, ← hrlt_def] rw [tabRestrict_tabInsert_ge ha_ge hssyt_rest] by_cases hemp : rlt.isEmpty · have hnil : rlt = [] := List.isEmpty_iff.mp hemp rw [tabRestrict_tail_nil_of_head_filter_nil hssyt hnil] simp [hnil, tabInsert] · simp only [hemp, Bool.false_eq_true, ↓reduceIte, tabInsert, hri_lt] /-- Row-insertion of `c` into a tableau whose entries are all `< c` simply appends `c` to row 0. -/ lemma tabShape_tabInsert_max {c : ℕ} {T : List (List ℕ)} (hlt : ∀ a ∈ T.flatten, a < c) (k : ℕ) : tabShape (tabInsert c T).1 k = tabShape T k + if k = 0 then 1 else 0 := by cases T with | nil => cases k <;> simp [tabInsert, tabShape] | cons r rest => have hall : ∀ a ∈ r, a ≤ c := fun a ha => Nat.le_of_lt (hlt a (by simp [ha])) have hri : rowInsert c r = (r ++ [c], none) := rowInsert_none_of_all_le hall simp only [tabInsert, hri] cases k <;> simp [tabShape] /-- Core case of Fomin's local rule: inserting `x < c` into `T'` vs `T = tabRestrict c T'` when `T'` has all entries `≤ c` and `c` appears at most once in `T'`. -/ lemma fomin_local_insert_lt {c : ℕ} : ∀ {T' : List (List ℕ)} {x : ℕ}, x < c → IsSSYT T' → (∀ a ∈ T'.flatten, a ≤ c) → T'.flatten.count c ≤ 1 → tabShape (tabInsert x T').1 = fominStep (tabShape (tabRestrict c T')) (tabShape (tabInsert x (tabRestrict c T')).1) (tabShape T') false | [], x, _, _, _, _ => by funext k; cases k <;> simp [tabRestrict, tabInsert, tabShape, fominStep] | r :: rest, x, hxc, hssyt, hle, hcnt => by have hssyt_rest : IsSSYT rest := ⟨fun s hs => hssyt.1 s (List.mem_cons_of_mem r hs), fun s hs => hssyt.2.1 s (List.mem_cons_of_mem r hs), by cases rest with | nil => trivial | cons _ _ => exact hssyt.2.2.2.2⟩ have hle_rest : ∀ a ∈ rest.flatten, a ≤ c := fun a ha => hle a (by simp [ha]) have hcnt_split : r.count c + rest.flatten.count c ≤ 1 := by simpa [List.flatten_cons, List.count_append] using hcnt by_cases hcr : c ∈ r · -- `c` occurs in the top row `r` (exactly once, at the end), and not in `rest` have hcr_pos : 1 ≤ r.count c := List.count_pos_iff.mpr hcr have hrest_cnt0 : rest.flatten.count c = 0 := by omega have hc_not_rest : c ∉ rest.flatten := List.count_eq_zero.mp hrest_cnt0 have hrest_lt : ∀ a ∈ rest.flatten, a < c := fun a ha => lt_of_le_of_ne (hle_rest a ha) (fun h => hc_not_rest (h ▸ ha)) have hrest_res : tabRestrict c rest = rest := tabRestrict_eq_self hssyt_rest.1 hrest_lt obtain ⟨rge, hr_eq, hrge⟩ := pairwise_split_lt_ge c (hssyt.2.1 r (by simp)) set rlt := r.filter (· < c) with hrlt_def have hrge_all_c : ∀ a ∈ rge, a = c := fun a ha => by have h1 := hrge a ha have h2 : a ≤ c := hle a (by rw [List.flatten_cons, List.mem_append, hr_eq]; exact Or.inl (List.mem_append_right _ ha)) omega have hrge_cnt : rge.count c = r.count c := by have hrlt_not : c ∉ rlt := fun h => by have := (List.mem_filter.mp h).2; simp at this have := congrArg (List.count c) hr_eq rw [List.count_append, List.count_eq_zero.mpr hrlt_not, Nat.zero_add] at this exact this.symm have hrge_eq : rge = [c] := by cases rge with | nil => have : r.count c = 0 := by rw [← hrge_cnt]; simp omega | cons a t => have ha : a = c := hrge_all_c a (by simp) subst a cases t with | nil => rfl | cons b t' => have hb : b = c := hrge_all_c b (by simp) subst b have : (c :: c :: t').count c ≥ 2 := by simp omega rw [hrge_eq] at hr_eq have hr_len : r.length = rlt.length + 1 := by rw [hr_eq]; simp cases hrlte : rlt with | nil => -- `r = [c]`, so `rest = []` by column-strictness and `≤ c` have hr_c : r = [c] := by rw [hr_eq, hrlte]; rfl have hrest_nil : rest = [] := by cases rest with | nil => rfl | cons r₂ rest' => exfalso have hr₂_ne : r₂ ≠ [] := hssyt.1 r₂ (by simp) have hr₂_pos : 0 < r₂.length := List.length_pos_iff.mpr hr₂_ne have hlt0 : r[0] < r₂[0] := by have h0 : 0 < r.length := by rw [hr_c]; simp exact hssyt.2.2.2.1 0 hr₂_pos h0 have hr0 : r[0]'(by rw [hr_c]; simp) = c := by simp [hr_c] have hr₂_le : r₂[0] ≤ c := hle_rest r₂[0] (by simp [List.getElem_mem hr₂_pos]) omega subst hr_c; subst hrest_nil funext k cases k with | zero => simp [tabInsert, rowInsert, hxc, tabRestrict, tabShape, fominStep] | succ k => cases k with | zero => simp [tabInsert, rowInsert, hxc, tabRestrict, tabShape, fominStep] | succ k => simp [tabInsert, rowInsert, hxc, tabRestrict, tabShape, fominStep] | cons a0 rlt_t => have hrlt_ne : rlt ≠ [] := by rw [hrlte]; simp have his_rlt : rlt.isEmpty = false := by rw [hrlte]; rfl have hres_T' : tabRestrict c (r :: rest) = rlt :: rest := by simp only [tabRestrict, ← hrlt_def, his_rlt, Bool.false_eq_true, ↓reduceIte, hrest_res] cases hri_lt : rowInsert x rlt with | mk rlt' b => cases b with | some y => rcases rowInsert_some_spec hri_lt with ⟨hrlt'_len, _⟩ have hri_r : rowInsert x r = (rlt' ++ [c], some y) := by rw [hr_eq]; exact rowInsert_append_of_some hri_lt funext k rw [hres_T'] simp only [tabInsert, hri_r, hri_lt] cases k with | zero => simp only [fominStep, tabShape_cons_zero, hr_len, hrlt'_len, List.length_append, List.length_singleton, Bool.false_eq_true, ↓reduceIte] omega | succ k => cases k with | zero => have hge := tabShape_tabInsert_ge y rest 0 simp only [fominStep, tabShape_cons_zero, tabShape_cons_succ, hrlt'_len, hr_len] have hnot : ¬ (rlt.length < rlt.length ∧ rlt.length < rlt.length + 1) := by omega rw [if_neg hnot, max_eq_left hge] | succ k => have hge := tabShape_tabInsert_ge y rest (k + 1) simp only [fominStep] split_ifs with hcond · exfalso; simp only [tabShape_cons_succ] at hcond; omega · simp only [tabShape_cons_succ]; exact (max_eq_left hge).symm | none => rcases rowInsert_none_eq hri_lt with ⟨rfl, hall_le⟩ have hri_r : rowInsert x r = (rlt ++ [x], some c) := by rw [hr_eq, rowInsert_append_of_none hall_le] simp [rowInsert, hxc] funext k rw [hres_T'] simp only [tabInsert, hri_r, hri_lt] cases k with | zero => simp only [fominStep, tabShape_cons_zero, hr_len, List.length_append, List.length_singleton, Bool.false_eq_true, ↓reduceIte] omega | succ k => cases k with | zero => simp only [fominStep, tabShape_cons_zero, tabShape_cons_succ, hr_len, List.length_append, List.length_singleton] have hboth : rlt.length < rlt.length + 1 ∧ rlt.length < rlt.length + 1 := by omega rw [if_pos hboth, tabShape_tabInsert_max hrest_lt 0] simp | succ k => simp only [fominStep, tabShape_cons_succ] split_ifs with hcond · omega · rw [max_self, tabShape_tabInsert_max hrest_lt (k + 1)]; simp · -- `c ∉ r`, so every entry of `r` is `< c` have hr_lt : ∀ a ∈ r, a < c := fun a ha => lt_of_le_of_ne (hle a (by simp [ha])) (fun h => hcr (h ▸ ha)) have hr_flt : r.filter (· < c) = r := List.filter_eq_self.mpr fun a ha => decide_eq_true (hr_lt a ha) have hr_ne : r ≠ [] := hssyt.1 r (by simp) have his_r : r.isEmpty = false := by cases r with | nil => exact absurd rfl hr_ne | cons _ _ => rfl have hres_T' : tabRestrict c (r :: rest) = r :: tabRestrict c rest := by simp only [tabRestrict, hr_flt, his_r, Bool.false_eq_true, ↓reduceIte] cases hri : rowInsert x r with | mk r' b => cases b with | none => rcases rowInsert_none_eq hri with ⟨rfl, _⟩ funext k rw [hres_T'] simp only [tabInsert, hri] cases k with | zero => simp only [fominStep, tabShape_cons_zero, List.length_append, List.length_singleton, Bool.false_eq_true, ↓reduceIte] omega | succ k => cases k with | zero => have hle0 := tabShape_tabRestrict_le c rest 0 simp only [fominStep, tabShape_cons_zero, tabShape_cons_succ, List.length_append, List.length_singleton] have hnot : ¬ (r.length < r.length + 1 ∧ r.length < r.length) := by omega rw [if_neg hnot, max_eq_right hle0] | succ k => have hlek := tabShape_tabRestrict_le c rest (k + 1) simp only [fominStep] split_ifs with hcond · exfalso; simp only [tabShape_cons_succ] at hcond; omega · simp only [tabShape_cons_succ]; exact (max_eq_right hlek).symm | some y => rcases rowInsert_some_spec hri with ⟨hr'_len, _, ⟨_, hy_mem⟩, _⟩ have hy_lt : y < c := hr_lt y hy_mem have hih := fomin_local_insert_lt (T' := rest) hy_lt hssyt_rest hle_rest (by omega) funext k rw [hres_T'] simp only [tabInsert, hri] cases k with | zero => simp only [fominStep, tabShape_cons_zero, hr'_len, Bool.false_eq_true, ↓reduceIte] omega | succ k => have hih_k := congrFun hih k cases k with | zero => simp only [tabShape_cons_succ] at hih_k ⊢ rw [hih_k] simp only [fominStep, tabShape_cons_zero, tabShape_cons_succ, hr'_len, Bool.false_eq_true, ↓reduceIte] have hnot : ¬ (r.length < r.length ∧ r.length < r.length) := by omega rw [if_neg hnot] | succ k => simp only [tabShape_cons_succ] at hih_k ⊢ rw [hih_k] rfl /-- Full local growth-diagram step for any value `x` inserted into `T'` vs `T = tabRestrict c T'`. -/ lemma fomin_local_square {c x : ℕ} {T' : List (List ℕ)} (hssyt : IsSSYT T') (hle : ∀ a ∈ T'.flatten, a ≤ c) (hcnt : T'.flatten.count c ≤ 1) (hxc_not : x = c → c ∉ T'.flatten) : tabShape (if x ≤ c then (tabInsert x T').1 else T') = fominStep (tabShape (tabRestrict c T')) (tabShape (if x < c then (tabInsert x (tabRestrict c T')).1 else tabRestrict c T')) (tabShape T') (decide (x = c)) := by rcases lt_trichotomy x c with hlt | heq | hgt · have hle_x : x ≤ c := Nat.le_of_lt hlt have hne : x ≠ c := Nat.ne_of_lt hlt simp only [hle_x, ↓reduceIte, hlt, decide_eq_false hne] exact fomin_local_insert_lt hlt hssyt hle hcnt · subst x have hnot_in : c ∉ T'.flatten := hxc_not rfl have hlt_all : ∀ a ∈ T'.flatten, a < c := fun a ha => lt_of_le_of_ne (hle a ha) (fun h => hnot_in (h ▸ ha)) have hres : tabRestrict c T' = T' := tabRestrict_eq_self hssyt.1 hlt_all simp only [le_refl, ↓reduceIte, lt_irrefl, decide_true, hres] funext k rw [tabShape_tabInsert_max hlt_all k] cases k with | zero => simp [fominStep] | succ k => simp [fominStep] · have hnot_le : ¬ (x ≤ c) := by omega have hnot_lt : ¬ (x < c) := by omega have hne : x ≠ c := by omega simp only [hnot_le, ↓reduceIte, hnot_lt, decide_eq_false hne] funext k have hle_k := tabShape_tabRestrict_le c T' k cases k with | zero => simp only [fominStep, Bool.false_eq_true, ↓reduceIte]; exact (max_eq_right hle_k).symm | succ k => simp only [fominStep] have hnot : ¬ (tabShape (tabRestrict c T') k < tabShape (tabRestrict c T') k ∧ tabShape (tabRestrict c T') k < tabShape T' k) := by omega rw [if_neg hnot, max_eq_right hle_k] /-- Helper: `rsStep` over a concatenated word splits cleanly. -/ lemma rsStep_append (u v : List ℕ) : ∀ (t : ℕ) (P Q : List (List ℕ)), rsStep t P Q (u ++ v) = rsStep (t + u.length) (rsStep t P Q u).1 (rsStep t P Q u).2 v := by induction u with | nil => intro t P Q; simp [rsStep] | cons x xs ih => intro t P Q simp only [List.cons_append, rsStep, List.length_cons] have h := ih (t + 1) (tabInsert x P).1 (tabAppendRow (tabInsert x P).2 t Q) have hlen : t + (xs.length + 1) = (t + 1) + xs.length := by omega rw [hlen]; exact h lemma rsP_append_singleton (u : List ℕ) (x : ℕ) : rsP (u ++ [x]) = (tabInsert x (rsP u)).1 := by unfold rsP rsWord rw [rsStep_append] simp [rsStep] /-- For a prefix of `permToWord w`, filtering to `< c` commutes with `rsP`. -/ lemma tabRestrict_rsP (c : ℕ) : ∀ (u : List ℕ), tabRestrict c (rsP u) = rsP (u.filter (· < c)) := by intro u induction u using List.reverseRecOn with | nil => simp [rsP, rsWord, rsStep, tabRestrict] | append_singleton u x ih => rw [rsP_append_singleton, List.filter_append] have hssyt : IsSSYT (rsP u) := by have : ∀ (v : List ℕ) (t : ℕ) (P Q : List (List ℕ)), IsSSYT P → IsSSYT (rsStep t P Q v).1 := by intro v; induction v with | nil => intro t P Q hP; exact hP | cons y ys ihy => intro t P Q hP; exact ihy _ _ _ (tabInsert_preserves_isSSYT y hP) exact this u 0 [] [] ⟨by simp, by simp, trivial⟩ by_cases hxc : x < c · rw [tabRestrict_tabInsert_lt hxc hssyt, ih] simp [hxc, rsP_append_singleton] · rw [tabRestrict_tabInsert_ge (Nat.le_of_not_lt hxc) hssyt, ih] simp [hxc] lemma rsP_flatten_perm (u : List ℕ) : (rsP u).flatten.Perm u := by induction u using List.reverseRecOn with | nil => simp [rsP, rsWord, rsStep] | append_singleton u x ih => rw [rsP_append_singleton] exact (tabInsert_flatten_perm x (rsP u)).trans ((ih.cons x).trans (List.perm_append_singleton x u).symm) lemma rsP_isSSYT (u : List ℕ) : IsSSYT (rsP u) := by have : ∀ (v : List ℕ) (t : ℕ) (P Q : List (List ℕ)), IsSSYT P → IsSSYT (rsStep t P Q v).1 := by intro v; induction v with | nil => intro t P Q hP; exact hP | cons y ys ihy => intro t P Q hP; exact ihy _ _ _ (tabInsert_preserves_isSSYT y hP) exact this u 0 [] [] ⟨by simp, by simp, trivial⟩ lemma take_succ_permToWord {n : ℕ} (w : Equiv.Perm (Fin n)) {r : ℕ} (hr : r < n) : (permToWord w).take (r + 1) = (permToWord w).take r ++ [(w ⟨r, hr⟩).1] := by have hlen : r < (permToWord w).length := by rw [permToWord_length]; exact hr rw [List.take_succ_eq_append_getElem hlen] congr 2 simp [permToWord] /-- **Fomin growth-diagram identification**: for every `w ∈ S_n` and `r ≤ n, c ≤ n`, `fominGrid w r c = tabShape (rsP (((permToWord w).take r).filter (· < c)))`. -/ lemma fominGrid_eq_rsP_shape {n : ℕ} (w : Equiv.Perm (Fin n)) : ∀ r c, r ≤ n → c ≤ n → fominGrid w r c = tabShape (rsP (((permToWord w).take r).filter (· < c))) | 0, c, _, _ => by funext k; simp [fominGrid_zero_left, rsP, rsWord, rsStep, tabShape] | r + 1, 0, _, _ => by funext k; simp [fominGrid_zero_right, rsP, rsWord, rsStep, tabShape] | r + 1, c + 1, hr, hc => by have hrn : r < n := Nat.lt_of_succ_le hr have hcn : c < n := Nat.lt_of_succ_le hc set u := (permToWord w).take r with hu_def set x := (w ⟨r, hrn⟩).1 with hx_def set T' := rsP (u.filter (· < c + 1)) with hT'_def have hT'_ssyt : IsSSYT T' := rsP_isSSYT _ have hT'_perm : T'.flatten.Perm (u.filter (· < c + 1)) := rsP_flatten_perm _ have hT'_le : ∀ a ∈ T'.flatten, a ≤ c := fun a ha => by have := (List.mem_filter.mp (hT'_perm.subset ha)).2 exact Nat.lt_succ_iff.mp (of_decide_eq_true this) have hu_nd : u.Nodup := (permToWord_nodup w).take have hT'_nd : T'.flatten.Nodup := hT'_perm.nodup_iff.mpr (hu_nd.filter _) have hT'_cnt : T'.flatten.count c ≤ 1 := by rw [List.nodup_iff_count_le_one] at hT'_nd; exact hT'_nd c have hxc_not : x = c → c ∉ T'.flatten := by intro hxc hmem have hmem_u : c ∈ u := (List.mem_filter.mp (hT'_perm.subset hmem)).1 have htake_nd : ((permToWord w).take (r + 1)).Nodup := (permToWord_nodup w).take rw [take_succ_permToWord w hrn] at htake_nd have hdisj := (List.nodup_append.mp htake_nd).2.2 c hmem_u x (by simp [hx_def]) exact hdisj hxc.symm have hres_T' : tabRestrict c T' = rsP (u.filter (· < c)) := by rw [hT'_def, tabRestrict_rsP] congr 1 rw [List.filter_filter] apply List.filter_congr intro a _ by_cases hac : a < c · have hac1 : a < c + 1 := by omega simp [hac, hac1] · simp [hac] have hnext_c1 : rsP (((permToWord w).take (r + 1)).filter (· < c + 1)) = if x ≤ c then (tabInsert x T').1 else T' := by rw [take_succ_permToWord w hrn, List.filter_append, ← hu_def, ← hx_def] by_cases hle_xc : x ≤ c · have hflt_x : [x].filter (· < c + 1) = [x] := by simp [hle_xc] rw [if_pos hle_xc, hflt_x, rsP_append_singleton, hT'_def] · have hflt_x : [x].filter (· < c + 1) = [] := by have hgt : c < x := by omega simp [hgt] rw [if_neg hle_xc, hflt_x, List.append_nil, hT'_def] have hnext_c : rsP (((permToWord w).take (r + 1)).filter (· < c)) = if x < c then (tabInsert x (tabRestrict c T')).1 else tabRestrict c T' := by rw [take_succ_permToWord w hrn, List.filter_append, ← hu_def, ← hx_def, hres_T'] by_cases hlt_xc : x < c · have hflt_x : [x].filter (· < c) = [x] := by simp [hlt_xc] rw [if_pos hlt_xc, hflt_x, rsP_append_singleton] · have hflt_x : [x].filter (· < c) = [] := by simp [hlt_xc] rw [if_neg hlt_xc, hflt_x, List.append_nil] have hloc := fomin_local_square hT'_ssyt hT'_le hT'_cnt hxc_not rw [← hnext_c1, ← hnext_c, hres_T'] at hloc simp only [fominGrid, dif_pos hrn] rw [fominGrid_eq_rsP_shape w r c (Nat.le_of_lt hrn) (Nat.le_of_lt hcn), fominGrid_eq_rsP_shape w (r + 1) c hr (Nat.le_of_lt hcn), fominGrid_eq_rsP_shape w r (c + 1) (Nat.le_of_lt hrn) hc] exact hloc.symm /-- Appending an element `t' ≥ t` to `Q` does not change `tabRestrict t Q`. -/ lemma tabRestrict_tabAppendRow_ge {t t' : ℕ} (htt' : t ≤ t') : ∀ (k : ℕ) (Q : List (List ℕ)), tabRestrict t (tabAppendRow k t' Q) = tabRestrict t Q | 0, [] => by have hnot : ¬ (t' < t) := by omega simp [tabAppendRow, tabRestrict, hnot] | k + 1, [] => by have hnot : ¬ (t' < t) := by omega simp [tabAppendRow, tabRestrict, hnot] | 0, r :: rest => by have hnot : ¬ (t' < t) := by omega simp [tabAppendRow, tabRestrict, List.filter_append, hnot] | k + 1, r :: rest => by simp only [tabAppendRow, tabRestrict] split_ifs · rfl · congr 1; exact tabRestrict_tabAppendRow_ge htt' k rest lemma tabRestrict_rsStep_Q {t : ℕ} : ∀ (v : List ℕ) (t' : ℕ) (P Q : List (List ℕ)), t ≤ t' → tabRestrict t (rsStep t' P Q v).2 = tabRestrict t Q | [], _, _, _, _ => rfl | x :: xs, t', P, Q, htt' => by simp only [rsStep] rw [tabRestrict_rsStep_Q xs (t' + 1) _ _ (by omega), tabRestrict_tabAppendRow_ge htt'] /-- Right boundary of Fomin's grid equals the `< r` restricted shape of `Q(w)`. -/ lemma fominGrid_right_eq_rsQ {n : ℕ} (w : Equiv.Perm (Fin n)) {r : ℕ} (hr : r ≤ n) : fominGrid w r n = tabShape (tabRestrict r (rsQ (permToWord w))) := by have h1 := fominGrid_eq_rsP_shape w r n hr le_rfl have hflt : ((permToWord w).take r).filter (· < n) = (permToWord w).take r := List.filter_eq_self.mpr fun a ha => by have ha' := List.mem_of_mem_take ha exact decide_eq_true (List.mem_range.mp ((permToWord_perm_range w).subset ha')) rw [hflt] at h1 rw [h1] have hsplit : permToWord w = (permToWord w).take r ++ (permToWord w).drop r := (List.take_append_drop r (permToWord w)).symm have hlen_take : ((permToWord w).take r).length = r := by rw [List.length_take, permToWord_length]; exact Nat.min_eq_left hr have hQ_res : tabRestrict r (rsQ (permToWord w)) = (rsWord ((permToWord w).take r)).2 := by unfold rsQ rsWord conv_lhs => rw [hsplit] rw [rsStep_append, Nat.zero_add, hlen_take, tabRestrict_rsStep_Q _ r _ _ le_rfl] have hinv := rsWord_invariants ((permToWord w).take r) (permToWord_nodup w).take exact tabRestrict_eq_self hinv.2.2.1.1 fun a ha => by have := List.mem_range.mp (hinv.2.2.2.1.subset ha) rwa [hlen_take] at this rw [hQ_res] have hinv := rsWord_invariants ((permToWord w).take r) (permToWord_nodup w).take exact (tabShape_eq_of_map_length_eq hinv.2.2.2.2).symm /-- Top boundary of Fomin's grid equals the `< c` restricted shape of `P(w)`. -/ lemma fominGrid_top_eq_rsP {n : ℕ} (w : Equiv.Perm (Fin n)) {c : ℕ} (hc : c ≤ n) : fominGrid w n c = tabShape (tabRestrict c (rsP (permToWord w))) := by have h1 := fominGrid_eq_rsP_shape w n c le_rfl hc have htake : (permToWord w).take n = permToWord w := by rw [List.take_of_length_le]; rw [permToWord_length] rw [htake, ← tabRestrict_rsP] at h1 exact h1 /-- Restricting an SYT to `< c + 1` adds `c` at the end of a unique row `i` of `tabRestrict c T`. -/ lemma tabRestrict_succ_eq_append {c : ℕ} : ∀ {T : List (List ℕ)}, IsSSYT T → T.flatten.count c = 1 → ∃ i, tabRestrict (c + 1) T = tabAppendRow i c (tabRestrict c T) ∧ ∀ k, tabShape (tabRestrict (c + 1) T) k = tabShape (tabRestrict c T) k + if k = i then 1 else 0 | [], _, hcnt => by simp at hcnt | r :: rest, hssyt, hcnt => by have hssyt_rest : IsSSYT rest := ⟨fun s hs => hssyt.1 s (List.mem_cons_of_mem r hs), fun s hs => hssyt.2.1 s (List.mem_cons_of_mem r hs), by cases rest with | nil => trivial | cons _ _ => exact hssyt.2.2.2.2⟩ have hcnt_split : r.count c + rest.flatten.count c = 1 := by simpa [List.flatten_cons, List.count_append] using hcnt by_cases hcr : c ∈ r · have hcr_pos : 1 ≤ r.count c := List.count_pos_iff.mpr hcr have hrest_cnt0 : rest.flatten.count c = 0 := by omega have hc_not_rest : c ∉ rest.flatten := List.count_eq_zero.mp hrest_cnt0 have hrest_eq : tabRestrict (c + 1) rest = tabRestrict c rest := by have hgo : ∀ {U : List (List ℕ)}, c ∉ U.flatten → tabRestrict (c + 1) U = tabRestrict c U := by intro U induction U with | nil => intro _; rfl | cons s us ihu => intro hcU have hcs : c ∉ s := fun h => hcU (by simp [h]) have hcus : c ∉ us.flatten := fun h => hcU (by simp [h]) have hflt : s.filter (· < c + 1) = s.filter (· < c) := by apply List.filter_congr intro a ha have hne : a ≠ c := fun h => hcs (h ▸ ha) simp only [decide_eq_decide]; omega simp only [tabRestrict, hflt, ihu hcus] exact hgo hc_not_rest -- Split `r.filter (· < c + 1) = r.filter (· < c) ++ [c]` have hr_split : r.filter (· < c + 1) = r.filter (· < c) ++ [c] := by obtain ⟨rge, hr_eq, hrge⟩ := pairwise_split_lt_ge c (hssyt.2.1 r (by simp)) have hflt_lt : (r.filter (· < c)).filter (· < c + 1) = r.filter (· < c) := List.filter_eq_self.mpr fun a ha => by have := of_decide_eq_true (List.mem_filter.mp ha).2; exact decide_eq_true (by omega) have hrge_flt : rge.filter (· < c + 1) = [c] := by have hrge_cnt : rge.count c = 1 := by have hrlt_not : c ∉ r.filter (· < c) := fun h => by have := (List.mem_filter.mp h).2; simp at this have := congrArg (List.count c) hr_eq rw [List.count_append, List.count_eq_zero.mpr hrlt_not, Nat.zero_add] at this omega have hall_eq : ∀ a ∈ rge.filter (· < c + 1), a = c := fun a ha => by have h1 := hrge a (List.mem_filter.mp ha).1 have h2 := of_decide_eq_true (List.mem_filter.mp ha).2 omega have hcnt_flt : (rge.filter (· < c + 1)).count c = 1 := by rw [List.count_filter] · exact hrge_cnt · exact decide_eq_true (Nat.lt_succ_self c) cases hf : rge.filter (· < c + 1) with | nil => rw [hf] at hcnt_flt; simp at hcnt_flt | cons a t => have ha : a = c := hall_eq a (by rw [hf]; simp) subst a cases t with | nil => rfl | cons b t' => have hb : b = c := hall_eq b (by rw [hf]; simp) subst b rw [hf] at hcnt_flt; simp at hcnt_flt conv_lhs => rw [hr_eq] rw [List.filter_append, hflt_lt, hrge_flt] refine ⟨0, ?_, ?_⟩ · have his_app : (r.filter (· < c) ++ [c]).isEmpty = false := by cases r.filter (· < c) <;> rfl simp only [tabRestrict, hr_split, his_app, Bool.false_eq_true, ↓reduceIte, hrest_eq] by_cases hemp : (r.filter (· < c)).isEmpty · have hnil : r.filter (· < c) = [] := List.isEmpty_iff.mp hemp rw [tabRestrict_tail_nil_of_head_filter_nil hssyt hnil] simp [hnil, tabAppendRow] · simp [hemp, tabAppendRow] · intro k have his_app : (r.filter (· < c) ++ [c]).isEmpty = false := by cases r.filter (· < c) <;> rfl simp only [tabRestrict, hr_split, his_app, Bool.false_eq_true, ↓reduceIte, hrest_eq] by_cases hemp : (r.filter (· < c)).isEmpty · have hnil : r.filter (· < c) = [] := List.isEmpty_iff.mp hemp rw [tabRestrict_tail_nil_of_head_filter_nil hssyt hnil] cases k <;> simp [hnil, tabShape] · cases k <;> simp [hemp, tabShape] · -- `c ∉ r`, so `c ∈ rest.flatten` have hcr0 : r.count c = 0 := List.count_eq_zero.mpr hcr have hrest_cnt1 : rest.flatten.count c = 1 := by omega have hflt_eq : r.filter (· < c + 1) = r.filter (· < c) := by apply List.filter_congr intro a ha have hne : a ≠ c := fun h => hcr (h ▸ ha) simp only [decide_eq_decide]; omega -- Moreover `r.filter (· < c)` MUST be nonempty, since `rest` contains `c` and `r[0] < c`! have hc_rest : c ∈ rest.flatten := List.count_pos_iff.mp (by omega) have hr_ne : r ≠ [] := hssyt.1 r (by simp) have hr_pos : 0 < r.length := List.length_pos_iff.mpr hr_ne have hr0_lt : r[0] < c := isSSYT_head_lt_tail_flatten hssyt hr_pos hc_rest have hr_flt_ne : r.filter (· < c) ≠ [] := by intro hnil have : r[0] ∈ r.filter (· < c) := List.mem_filter.mpr ⟨List.getElem_mem hr_pos, decide_eq_true hr0_lt⟩ rw [hnil] at this; simp at this have his_r : (r.filter (· < c)).isEmpty = false := by cases h : r.filter (· < c) with | nil => exact absurd h hr_flt_ne | cons _ _ => rfl obtain ⟨i, hih_eq, hih_sh⟩ := tabRestrict_succ_eq_append hssyt_rest hrest_cnt1 refine ⟨i + 1, ?_, ?_⟩ · simp only [tabRestrict, hflt_eq, his_r, Bool.false_eq_true, ↓reduceIte, hih_eq, tabAppendRow] · intro k simp only [tabRestrict, hflt_eq, his_r, Bool.false_eq_true, ↓reduceIte] cases k with | zero => simp [tabShape] | succ k => simpa [tabShape] using hih_sh k /-- Two SYTs on `[0, n)` whose `< c`-restricted shapes agree for all `c ≤ n` are equal. -/ lemma syt_eq_of_restrict_shape_eq {T₁ T₂ : List (List ℕ)} {n : ℕ} (h₁ : IsStrictTab T₁) (hp₁ : T₁.flatten.Perm (List.range n)) (h₂ : IsStrictTab T₂) (hp₂ : T₂.flatten.Perm (List.range n)) (hsh : ∀ c ≤ n, tabShape (tabRestrict c T₁) = tabShape (tabRestrict c T₂)) : T₁ = T₂ := by have hres : ∀ c ≤ n, tabRestrict c T₁ = tabRestrict c T₂ := by intro c induction c with | zero => intro _; rw [tabRestrict_zero, tabRestrict_zero] | succ c ih => intro hcn have hcn' : c < n := Nat.lt_of_succ_le hcn have hcnt₁ : T₁.flatten.count c = 1 := by rw [hp₁.count_eq, List.count_eq_one_of_mem List.nodup_range (List.mem_range.mpr hcn')] have hcnt₂ : T₂.flatten.count c = 1 := by rw [hp₂.count_eq, List.count_eq_one_of_mem List.nodup_range (List.mem_range.mpr hcn')] obtain ⟨i₁, heq₁, hsh₁⟩ := tabRestrict_succ_eq_append h₁.isSSYT hcnt₁ obtain ⟨i₂, heq₂, hsh₂⟩ := tabRestrict_succ_eq_append h₂.isSSYT hcnt₂ have hi : i₁ = i₂ := by by_contra hne have h1 := congrFun (hsh (c + 1) hcn) i₁ have h0 := congrFun (hsh c (Nat.le_of_lt hcn')) i₁ rw [hsh₁ i₁, hsh₂ i₁, h0] at h1 simp [hne] at h1 rw [heq₁, heq₂, hi, ih (Nat.le_of_lt hcn')] have h1_all : tabRestrict n T₁ = T₁ := tabRestrict_eq_self h₁.1 (fun a ha => List.mem_range.mp (hp₁.subset ha)) have h2_all : tabRestrict n T₂ = T₂ := tabRestrict_eq_self h₂.1 (fun a ha => List.mem_range.mp (hp₂.subset ha)) rw [← h1_all, ← h2_all] exact hres n le_rfl /-- **Schützenberger Symmetry Theorem (universal, all `n : ℕ`)**: for every permutation `w ∈ S_n`, `P(w⁻¹) = Q(w)` and `Q(w⁻¹) = P(w)`, proved constructively via Fomin's local growth diagrams. -/ theorem schutzenberger_symmetry (n : ℕ) (w : Equiv.Perm (Fin n)) : rsP (permToWord w⁻¹) = rsQ (permToWord w) ∧ rsQ (permToWord w⁻¹) = rsP (permToWord w) := by have hPQ : ∀ v : Equiv.Perm (Fin n), rsP (permToWord v⁻¹) = rsQ (permToWord v) := by intro v have hinv₁ := rsWord_invariants (permToWord v⁻¹) (permToWord_nodup v⁻¹) have hinv₂ := rsWord_invariants (permToWord v) (permToWord_nodup v) apply syt_eq_of_restrict_shape_eq (n := n) hinv₁.1 (hinv₁.2.1.trans (permToWord_perm_range v⁻¹)) hinv₂.2.2.1 (by have := hinv₂.2.2.2.1; rwa [permToWord_length] at this) intro c hc rw [← fominGrid_top_eq_rsP v⁻¹ hc, fominGrid_inv v n c le_rfl hc, fominGrid_right_eq_rsQ v hc] refine ⟨hPQ w, ?_⟩ have := hPQ w⁻¹ simpa using this.symm /-- Constructive bijection between involutions in `S_n` and single standard Young tableaux of size `n`, induced by RS and Schützenberger symmetry. -/ noncomputable def involutionEquiv (n : ℕ) : {w : Equiv.Perm (Fin n) // w * w = 1} ≃ Σ lam : IntPart n, SYT lam where toFun w := ⟨(rsBijection n w.1).1, (rsBijection n w.1).2.1⟩ invFun x := ⟨(rsBijection n).symm ⟨x.1, x.2, x.2⟩, by set v := (rsBijection n).symm ⟨x.1, x.2, x.2⟩ with hv_def have hv : rsBijection n v = ⟨x.1, x.2, x.2⟩ := Equiv.apply_symm_apply _ _ have hP : rsP (permToWord v) = x.2.rows := by change (rsBijection n v).2.1.rows = _; rw [hv] have hQ : rsQ (permToWord v) = x.2.rows := by change (rsBijection n v).2.2.rows = _; rw [hv] have hinv : rsBijection n v⁻¹ = rsBijection n v := by apply sigma_syt_ext · change rsP (permToWord v⁻¹) = rsP (permToWord v) rw [(schutzenberger_symmetry n v).1, hQ, hP] · change rsQ (permToWord v⁻¹) = rsQ (permToWord v) rw [(schutzenberger_symmetry n v).2, hP, hQ] have hvv : v⁻¹ = v := (rsBijection n).injective hinv calc v * v = v * v⁻¹ := by rw [hvv] _ = 1 := mul_inv_cancel v⟩ left_inv w := by apply Subtype.ext have hww : w.1⁻¹ = w.1 := inv_eq_of_mul_eq_one_right w.2 have hPQ : rsQ (permToWord w.1) = rsP (permToWord w.1) := by rw [← (schutzenberger_symmetry n w.1).1, hww] have hsig : (⟨(rsBijection n w.1).1, (rsBijection n w.1).2.1, (rsBijection n w.1).2.1⟩ : Σ lam : IntPart n, SYT lam × SYT lam) = rsBijection n w.1 := sigma_syt_ext rfl (by change rsP (permToWord w.1) = rsQ (permToWord w.1); exact hPQ.symm) change (rsBijection n).symm ⟨(rsBijection n w.1).1, (rsBijection n w.1).2.1, (rsBijection n w.1).2.1⟩ = w.1 rw [hsig, Equiv.symm_apply_apply] right_inv x := by rcases x with ⟨lam, T⟩ have h := Equiv.apply_symm_apply (rsBijection n) ⟨lam, T, T⟩ change (⟨(rsBijection n ((rsBijection n).symm ⟨lam, T, T⟩)).1, (rsBijection n ((rsBijection n).symm ⟨lam, T, T⟩)).2.1⟩ : Σ lam : IntPart n, SYT lam) = ⟨lam, T⟩ rw [h] /-- **Universal Involution Identity**: for every `n : ℕ`, `∑_{λ ⊢ n} f^λ = #{w ∈ S_n : w² = 1}`. -/ theorem involution_identity (n : ℕ) : ∑ lam : IntPart n, Fintype.card (SYT lam) = Fintype.card {w : Equiv.Perm (Fin n) // w * w = 1} := by rw [← Fintype.card_sigma] exact (Fintype.card_congr (involutionEquiv n)).symm #print axioms tabRevBump_tabInsert #print axioms tabInsert_tabRevBump #print axioms rsDecode_rsWord #print axioms rsWord_rsDecode #print axioms rsWord_invariants #print axioms rsBijection #print axioms frobenius_schur_identity #print axioms rsP_headD #print axioms patience_lis_invariant #print axioms schensted_lis #print axioms schensted_lis_nodup #print axioms schensted_lis_perm #print axioms patience_piles #print axioms erdos_szekeres #print axioms erdos_szekeres_nodup #print axioms erdos_szekeres_sharp #print axioms schutzenberger_symmetry #print axioms involutionEquiv #print axioms involution_identity end CombinatorialHopfRSK