diff --git a/LeanPool/PatternPosetNotSperner.lean b/LeanPool/PatternPosetNotSperner.lean new file mode 100644 index 0000000000..681aa4a7a6 --- /dev/null +++ b/LeanPool/PatternPosetNotSperner.lean @@ -0,0 +1,27 @@ +/- +Copyright (c) 2026 Tyler B. Hughes. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Tyler B. Hughes +-/ + +module + +public import LeanPool.PatternPosetNotSperner.Defs +public import LeanPool.PatternPosetNotSperner.BoxChains +public import LeanPool.PatternPosetNotSperner.SevenPoint +public import LeanPool.PatternPosetNotSperner.Family + +/-! +# Non-Sperner Intervals and Exact Deficiency Family in the Permutation Pattern Poset + +Source: arxiv:1305.5569, doi:10.1016/j.jcta.2015.02.009, url:https://mathdiscoveries.org/results/pattern-poset-not-sperner/ +Authors: Tyler B. Hughes +Status: verified +Main declarations: `PatternPoset.mcnamara_steingrimsson_Q9_5_false`, + `PatternPoset.not_sperner_interval7`, `PatternPoset.interval7_card`, + `PatternPoset.interval7_largestRank`, `PatternPoset.interval7_width`, + `PatternPoset.family_exact_deficiency`, `PatternPoset.family_not_sperner`, + `PatternPoset.family_largestRank`, `PatternPoset.family_width` +Tags: combinatorics, permutation-patterns, posets, sperner-property, symmetric-chain-decomposition +MSC: 05A05, 06A07 +-/ diff --git a/LeanPool/PatternPosetNotSperner/BoxChains.lean b/LeanPool/PatternPosetNotSperner/BoxChains.lean new file mode 100644 index 0000000000..16cf3443b5 --- /dev/null +++ b/LeanPool/PatternPosetNotSperner/BoxChains.lean @@ -0,0 +1,430 @@ +/- +Copyright (c) 2026 Tyler B. Hughes. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Tyler B. Hughes +-/ + +-- Modified for Lean Pool: Lean 4.36 module and import port with style and linter fixes. + +module + +public import Mathlib.Algebra.BigOperators.Group.Finset.Basic +public import Mathlib.Data.Finset.Card +public import Mathlib.Data.Finset.Image +public import Mathlib.Data.Finset.Prod + +import Mathlib.Algebra.BigOperators.Group.Finset.Sigma +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.Ring +import Mathlib.Tactic.Tauto +import Mathlib.Tactic.Zify + +/-! +# Symmetric Chain Decomposition and Exact Slice Counts of the 3D Box + +Formalizes the 3D integer box +`Box(k) = { (x, y, z) : 0 ≤ x ≤ 2k + 1, 0 ≤ y ≤ 2k + 1, 0 ≤ z ≤ 2k }`, +its exact slice cardinality formula +`B(3k + 1 + t) = 3k^2 + 5k + 2 - t^2` (`0 ≤ t ≤ k`), +and an explicit closed-form symmetric chain decomposition (`boxId` / `boxRecon`) +yielding both: +1. Exactly `3k^2 + 5k + 2` chains partitioning `Box(k)` in the coordinatewise order; +2. Unimodality of the slice sizes `B(s)`. +-/ + +@[expose] public section + +namespace PatternPoset + +/-! ### 2D Rectangle Symmetric Chain (Hook) Decomposition -/ + +/-- Hook index of `(i, j)` in `[0, A] × [0, B]`. -/ +def rectId (A i j : ℕ) : ℕ := min (A - i) j + +/-- Position along the hook `rectId A i j`. -/ +def rectPos (A i j : ℕ) : ℕ := i + j - rectId A i j + +/-- Reconstruct `(i, j)` in `[0, A] × [0, B]` from hook index `d` and hook position `u`. -/ +def rectRecon (A d u : ℕ) : ℕ × ℕ := + if u ≤ A - d then (u, d) else (A - d, u + 2 * d - A) + +theorem rectId_bounds {A B i j : ℕ} (hi : i ≤ A) (hj : j ≤ B) : + rectId A i j ≤ A ∧ rectId A i j ≤ B ∧ + rectId A i j ≤ i + j ∧ + rectPos A i j ≤ A + B - 2 * rectId A i j := by + simp only [rectPos, rectId] + omega + +theorem rectRecon_mem {A B d u : ℕ} (hdA : d ≤ A) (hdB : d ≤ B) (hu : u ≤ A + B - 2 * d) : + (rectRecon A d u).1 ≤ A ∧ (rectRecon A d u).2 ≤ B := by + unfold rectRecon + split_ifs <;> omega + +theorem rectId_rectRecon {A B d u : ℕ} (hdA : d ≤ A) (_hdB : d ≤ B) + (_hu : u ≤ A + B - 2 * d) : + rectId A (rectRecon A d u).1 (rectRecon A d u).2 = d ∧ + rectPos A (rectRecon A d u).1 (rectRecon A d u).2 = u ∧ + (rectRecon A d u).1 + (rectRecon A d u).2 = u + d := by + simp only [rectPos, rectId, rectRecon] + split_ifs <;> dsimp <;> omega + +theorem rectRecon_rectId_rectPos {A B i j : ℕ} (hi : i ≤ A) (_hj : j ≤ B) : + rectRecon A (rectId A i j) (rectPos A i j) = (i, j) := by + simp only [rectRecon, rectPos, rectId] + by_cases h : i + j - min (A - i) j ≤ A - min (A - i) j + · simp only [h, ↓reduceIte] + apply Prod.ext <;> dsimp <;> omega + · simp only [h, ↓reduceIte] + apply Prod.ext <;> dsimp <;> omega + +theorem rectRecon_mono {A d u₁ u₂ : ℕ} (hdA : d ≤ A) (h : u₁ ≤ u₂) : + (rectRecon A d u₁).1 ≤ (rectRecon A d u₂).1 ∧ + (rectRecon A d u₁).2 ≤ (rectRecon A d u₂).2 := by + unfold rectRecon + split_ifs <;> dsimp <;> omega + +/-! ### 3D Box `Box(k)` and Iterated Symmetric Chain Decomposition -/ + +/-- The 3D box `[0, 2k+1] × [0, 2k+1] × [0, 2k]` as a `Finset`. -/ +def boxFinset (k : ℕ) : Finset (ℕ × ℕ × ℕ) := + (Finset.range (2 * k + 2)) ×ˢ ((Finset.range (2 * k + 2)) ×ˢ (Finset.range (2 * k + 1))) + +theorem mem_boxFinset {k : ℕ} {t : ℕ × ℕ × ℕ} : + t ∈ boxFinset k ↔ t.1 ≤ 2 * k + 1 ∧ t.2.1 ≤ 2 * k + 1 ∧ t.2.2 ≤ 2 * k := by + simp only [boxFinset, Finset.mem_product, Finset.mem_range] + omega + +/-- The slice of `Box(k)` of triples with coordinate sum `s`. -/ +def boxSlice (k s : ℕ) : Finset (ℕ × ℕ × ℕ) := + (boxFinset k).filter (fun t => t.1 + t.2.1 + t.2.2 = s) + +theorem mem_boxSlice {k s : ℕ} {t : ℕ × ℕ × ℕ} : + t ∈ boxSlice k s ↔ + t.1 ≤ 2 * k + 1 ∧ t.2.1 ≤ 2 * k + 1 ∧ t.2.2 ≤ 2 * k ∧ + t.1 + t.2.1 + t.2.2 = s := by + rw [boxSlice, Finset.mem_filter, mem_boxFinset] + tauto + +/-- Symmetric chain identifier `(d₁, d₂)` for a triple `(x, y, z) ∈ Box(k)`. -/ +def boxId (k : ℕ) (t : ℕ × ℕ × ℕ) : ℕ × ℕ := + let M := 2 * k + 1 + let d₁ := rectId M t.1 t.2.1 + let u := rectPos M t.1 t.2.1 + (d₁, rectId (2 * M - 2 * d₁) u t.2.2) + +/-- Reconstruct the unique triple on chain `(d₁, d₂)` in `Box(k)` with sum `s`. -/ +def boxRecon (k d₁ d₂ s : ℕ) : ℕ × ℕ × ℕ := + let M := 2 * k + 1 + let uz := rectRecon (2 * M - 2 * d₁) d₂ (s - d₁ - d₂) + let xy := rectRecon M d₁ uz.1 + (xy.1, xy.2, uz.2) + +theorem boxId_bounds {k : ℕ} {t : ℕ × ℕ × ℕ} (ht : t ∈ boxFinset k) : + let id := boxId k t + id.1 ≤ 2 * k + 1 ∧ + id.2 ≤ 4 * k + 2 - 2 * id.1 ∧ + id.2 ≤ 2 * k ∧ + id.1 + id.2 ≤ 3 * k + 1 ∧ + id.1 + id.2 ≤ t.1 + t.2.1 + t.2.2 ∧ + t.1 + t.2.1 + t.2.2 ≤ 6 * k + 2 - (id.1 + id.2) := by + rw [mem_boxFinset] at ht + rcases ht with ⟨hx, hy, hz⟩ + have h1 := rectId_bounds (A := 2 * k + 1) (B := 2 * k + 1) hx hy + have h2 := rectId_bounds (A := 2 * (2 * k + 1) - 2 * rectId (2 * k + 1) t.1 t.2.1) + (B := 2 * k) (by omega : rectPos (2 * k + 1) t.1 t.2.1 ≤ _) hz + dsimp only [boxId] + have hpos1 : rectPos (2 * k + 1) t.1 t.2.1 = t.1 + t.2.1 - rectId (2 * k + 1) t.1 t.2.1 := rfl + have hpos2 : rectPos (2 * (2 * k + 1) - 2 * rectId (2 * k + 1) t.1 t.2.1) + (rectPos (2 * k + 1) t.1 t.2.1) t.2.2 = + rectPos (2 * k + 1) t.1 t.2.1 + t.2.2 - + rectId (2 * (2 * k + 1) - 2 * rectId (2 * k + 1) t.1 t.2.1) + (rectPos (2 * k + 1) t.1 t.2.1) t.2.2 := rfl + omega + +theorem boxRecon_mem_slice {k d₁ d₂ s : ℕ} + (hd1 : d₁ ≤ 2 * k + 1) + (hd2a : d₂ ≤ 4 * k + 2 - 2 * d₁) + (hd2b : d₂ ≤ 2 * k) + (hs1 : d₁ + d₂ ≤ s) + (hs2 : s ≤ 6 * k + 2 - (d₁ + d₂)) : + boxRecon k d₁ d₂ s ∈ boxSlice k s ∧ + boxId k (boxRecon k d₁ d₂ s) = (d₁, d₂) := by + set M := 2 * k + 1 + have hA : 2 * M - 2 * d₁ = 4 * k + 2 - 2 * d₁ := by omega + have hv : s - d₁ - d₂ ≤ (2 * M - 2 * d₁) + 2 * k - 2 * d₂ := by omega + have huz_mem := rectRecon_mem (A := 2 * M - 2 * d₁) (B := 2 * k) (by omega) hd2b hv + have huz_id := rectId_rectRecon (A := 2 * M - 2 * d₁) (B := 2 * k) (by omega) hd2b hv + set uz := rectRecon (2 * M - 2 * d₁) d₂ (s - d₁ - d₂) + have hu : uz.1 ≤ M + M - 2 * d₁ := by omega + have hxy_mem := rectRecon_mem (A := M) (B := M) hd1 hd1 hu + have hxy_id := rectId_rectRecon (A := M) (B := M) hd1 hd1 hu + set xy := rectRecon M d₁ uz.1 + constructor + · rw [mem_boxSlice] + refine ⟨hxy_mem.1, hxy_mem.2, huz_mem.2, ?_⟩ + change xy.1 + xy.2 + uz.2 = s + omega + · change (rectId M xy.1 xy.2, + rectId (2 * M - 2 * rectId M xy.1 xy.2) (rectPos M xy.1 xy.2) uz.2) = (d₁, d₂) + rw [hxy_id.1, hxy_id.2.1, huz_id.1] + +theorem boxRecon_boxId {k : ℕ} {t : ℕ × ℕ × ℕ} (ht : t ∈ boxFinset k) : + boxRecon k (boxId k t).1 (boxId k t).2 (t.1 + t.2.1 + t.2.2) = t := by + have hb := boxId_bounds ht + rw [mem_boxFinset] at ht + rcases ht with ⟨hx, hy, hz⟩ + set M := 2 * k + 1 + set d₁ := rectId M t.1 t.2.1 + set u := rectPos M t.1 t.2.1 + set d₂ := rectId (2 * M - 2 * d₁) u t.2.2 + have h1 := rectId_bounds (A := M) (B := M) hx hy + have hu_le : u ≤ 2 * M - 2 * d₁ := by omega + have hsum_eq : t.1 + t.2.1 + t.2.2 - d₁ - d₂ = rectPos (2 * M - 2 * d₁) u t.2.2 := by + change t.1 + t.2.1 + t.2.2 - d₁ - d₂ = (t.1 + t.2.1 - d₁) + t.2.2 - d₂ + omega + have huz : + rectRecon (2 * M - 2 * d₁) d₂ (t.1 + t.2.1 + t.2.2 - d₁ - d₂) = (u, t.2.2) := by + rw [hsum_eq] + exact rectRecon_rectId_rectPos hu_le hz + have hxy : rectRecon M d₁ u = (t.1, t.2.1) := rectRecon_rectId_rectPos hx hy + change (let uz := rectRecon (2 * M - 2 * d₁) d₂ (t.1 + t.2.1 + t.2.2 - d₁ - d₂) + let xy := rectRecon M d₁ uz.1 + (xy.1, xy.2, uz.2)) = t + rw [huz] + dsimp only + rw [hxy] + +/-- Any two triples in `Box(k)` with the same `boxId` are coordinatewise comparable. -/ +theorem box_chain_comparable {k : ℕ} {t₁ t₂ : ℕ × ℕ × ℕ} + (h1 : t₁ ∈ boxFinset k) (h2 : t₂ ∈ boxFinset k) (hid : boxId k t₁ = boxId k t₂) : + (t₁.1 ≤ t₂.1 ∧ t₁.2.1 ≤ t₂.2.1 ∧ t₁.2.2 ≤ t₂.2.2) ∨ + (t₂.1 ≤ t₁.1 ∧ t₂.2.1 ≤ t₁.2.1 ∧ t₂.2.2 ≤ t₁.2.2) := by + have mono_step : ∀ {a b : ℕ × ℕ × ℕ}, a ∈ boxFinset k → b ∈ boxFinset k → + boxId k a = boxId k b → a.1 + a.2.1 + a.2.2 ≤ b.1 + b.2.1 + b.2.2 → + a.1 ≤ b.1 ∧ a.2.1 ≤ b.2.1 ∧ a.2.2 ≤ b.2.2 := by + intro a b ha hb hab hle + have hba := boxId_bounds ha + set M := 2 * k + 1 + set d₁ := (boxId k a).1 + set d₂ := (boxId k a).2 + have ha_eq := (boxRecon_boxId ha).symm + have hb_eq := (boxRecon_boxId hb).symm + rw [← hab] at hb_eq + have hv : a.1 + a.2.1 + a.2.2 - d₁ - d₂ ≤ b.1 + b.2.1 + b.2.2 - d₁ - d₂ := by omega + have huz := rectRecon_mono (A := 2 * M - 2 * d₁) (d := d₂) (by omega) hv + have hxy := rectRecon_mono (A := M) (d := d₁) (by omega) huz.1 + rw [ha_eq, hb_eq] + exact ⟨hxy.1, hxy.2, huz.2⟩ + rcases le_total (t₁.1 + t₁.2.1 + t₁.2.2) (t₂.1 + t₂.2.1 + t₂.2.2) with hle | hle + · exact Or.inl (mono_step h1 h2 hid hle) + · exact Or.inr (mono_step h2 h1 hid.symm hle) + +/-- `boxId k` is injective on every fixed slice `boxSlice k s`. -/ +theorem boxId_injOn_slice (k s : ℕ) : + Set.InjOn (boxId k) (boxSlice k s : Set (ℕ × ℕ × ℕ)) := by + intro t₁ h1 t₂ h2 heq + rw [Finset.mem_coe, boxSlice, Finset.mem_filter] at h1 h2 + have hr1 := boxRecon_boxId h1.1 + have hr2 := boxRecon_boxId h2.1 + rw [h1.2] at hr1 + rw [h2.2, ← heq] at hr2 + exact hr1.symm.trans hr2 + +/-- Every chain in `Box(k)` crosses the middle slice `s = 3k + 1`. -/ +theorem boxId_image_eq_mid (k : ℕ) : + (boxFinset k).image (boxId k) = (boxSlice k (3 * k + 1)).image (boxId k) := by + ext id + simp only [Finset.mem_image] + constructor + · rintro ⟨t, ht, rfl⟩ + have hb := boxId_bounds ht + have hrec := boxRecon_mem_slice (s := 3 * k + 1) hb.1 hb.2.1 hb.2.2.1 + hb.2.2.2.1 (by omega) + exact ⟨boxRecon k (boxId k t).1 (boxId k t).2 (3 * k + 1), hrec.1, hrec.2⟩ + · rintro ⟨t, ht, rfl⟩ + exact ⟨t, (Finset.mem_filter.mp ht).1, rfl⟩ + +/-- The number of chains in the symmetric chain decomposition of `Box(k)` equals `B(3k + 1)`. -/ +theorem boxId_image_card (k : ℕ) : + ((boxFinset k).image (boxId k)).card = (boxSlice k (3 * k + 1)).card := by + rw [boxId_image_eq_mid] + exact Finset.card_image_of_injOn (boxId_injOn_slice k (3 * k + 1)) + +/-- Every slice has cardinality at most the middle slice `B(3k + 1)`. -/ +theorem boxSlice_card_le_mid (k s : ℕ) : + (boxSlice k s).card ≤ (boxSlice k (3 * k + 1)).card := by + rw [← boxId_image_card] + calc + (boxSlice k s).card = ((boxSlice k s).image (boxId k)).card := + (Finset.card_image_of_injOn (boxId_injOn_slice k s)).symm + _ ≤ ((boxFinset k).image (boxId k)).card := + Finset.card_le_card (Finset.image_subset_image (Finset.filter_subset _ _)) + +/-- Unimodality on the upper half: for `3k + 1 ≤ s₁ ≤ s₂`, `B(s₂) ≤ B(s₁)`. -/ +theorem boxSlice_card_antitone {k s₁ s₂ : ℕ} (h1 : 3 * k + 1 ≤ s₁) (h2 : s₁ ≤ s₂) : + (boxSlice k s₂).card ≤ (boxSlice k s₁).card := by + have hsub : (boxSlice k s₂).image (boxId k) ⊆ (boxSlice k s₁).image (boxId k) := by + intro id hid + rcases Finset.mem_image.mp hid with ⟨t, ht, rfl⟩ + rw [boxSlice, Finset.mem_filter] at ht + have hb := boxId_bounds ht.1 + have hrec := boxRecon_mem_slice (s := s₁) hb.1 hb.2.1 hb.2.2.1 + (by omega) (by omega) + exact Finset.mem_image.mpr ⟨boxRecon k (boxId k t).1 (boxId k t).2 s₁, hrec.1, hrec.2⟩ + rw [← Finset.card_image_of_injOn (boxId_injOn_slice k s₂), + ← Finset.card_image_of_injOn (boxId_injOn_slice k s₁)] + exact Finset.card_le_card hsub + +/-! ### Exact Slice Cardinality Formula `B(3k + 1 + t) = 3k^2 + 5k + 2 - t^2` -/ + +private theorem two_mul_sum_range_add (a n : ℕ) : + 2 * ∑ i ∈ Finset.range n, (a + i) = n * (2 * a + n - 1) := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ, mul_add, ih] + cases n with + | zero => simp + | succ m => + have h1 : 2 * a + (m + 1) - 1 = 2 * a + m := by omega + have h2 : 2 * a + (m + 1 + 1) - 1 = 2 * a + m + 1 := by omega + rw [h1, h2] + ring + +private theorem two_mul_sum_range_sub (b n : ℕ) (h : n ≤ b + 1) : + 2 * ∑ i ∈ Finset.range n, (b - i) = n * (2 * b + 1 - n) := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ, mul_add, ih (by omega)] + have h1 : n ≤ b := by omega + have h2 : n ≤ 2 * b + 1 := by omega + have h3 : n + 1 ≤ 2 * b + 1 := by omega + zify [h1, h2, h3] + ring + +/-- Number of pairs `(x, y) ∈ [0, M]^2` with `x + y = m`. -/ +private theorem card_pair_sum (M m : ℕ) (hm : m ≤ 2 * M) : + (((Finset.range (M + 1)) ×ˢ (Finset.range (M + 1))).filter + (fun p => p.1 + p.2 = m)).card = + if m ≤ M then m + 1 else 2 * M + 1 - m := by + split_ifs with hle + · have hbij : + (((Finset.range (M + 1)) ×ˢ (Finset.range (M + 1))).filter + (fun p => p.1 + p.2 = m)).card = (Finset.range (m + 1)).card := by + refine Finset.card_bij (fun p _ => p.1) ?_ ?_ ?_ + · intro p hp + simp only [Finset.mem_filter, Finset.mem_product, Finset.mem_range] at hp ⊢ + omega + · intro p₁ hp₁ p₂ hp₂ heq + simp only [Finset.mem_filter, Finset.mem_product, Finset.mem_range] at hp₁ hp₂ + ext + · exact heq + · omega + · intro x hx + rw [Finset.mem_range] at hx + refine ⟨(x, m - x), ?_, rfl⟩ + simp only [Finset.mem_filter, Finset.mem_product, Finset.mem_range] + omega + rw [hbij, Finset.card_range] + · have hbij : + (((Finset.range (M + 1)) ×ˢ (Finset.range (M + 1))).filter + (fun p => p.1 + p.2 = m)).card = (Finset.range (2 * M + 1 - m)).card := by + refine Finset.card_bij (fun p _ => p.1 - (m - M)) ?_ ?_ ?_ + · intro p hp + simp only [Finset.mem_filter, Finset.mem_product, Finset.mem_range] at hp ⊢ + omega + · intro p₁ hp₁ p₂ hp₂ heq + simp only [Finset.mem_filter, Finset.mem_product, Finset.mem_range] at hp₁ hp₂ + ext <;> omega + · intro u hu + rw [Finset.mem_range] at hu + refine ⟨(m - M + u, M - u), ?_, by dsimp; omega⟩ + simp only [Finset.mem_filter, Finset.mem_product, Finset.mem_range] + omega + rw [hbij, Finset.card_range] + +/-- Exact slice cardinality formula: for `0 ≤ t ≤ k`, +`B(3k + 1 + t) = 3k^2 + 5k + 2 - t^2`. -/ +theorem boxSlice_card (k t : ℕ) (ht : t ≤ k) : + (boxSlice k (3 * k + 1 + t)).card = 3 * k ^ 2 + 5 * k + 2 - t ^ 2 := by + have hfiber : + (boxSlice k (3 * k + 1 + t)).card = + ∑ z ∈ Finset.range (2 * k + 1), + (((Finset.range (2 * k + 2)) ×ˢ (Finset.range (2 * k + 2))).filter + (fun p => p.1 + p.2 = 3 * k + 1 + t - z)).card := by + rw [← Finset.card_sigma] + refine Finset.card_bij (fun tr _ => ⟨tr.2.2, (tr.1, tr.2.1)⟩) ?_ ?_ ?_ + · intro tr htr + rw [mem_boxSlice] at htr + simp only [Finset.mem_sigma, Finset.mem_filter, Finset.mem_product, Finset.mem_range] + omega + · intro tr₁ _ tr₂ _ heq + rcases tr₁ with ⟨x₁, y₁, z₁⟩ + rcases tr₂ with ⟨x₂, y₂, z₂⟩ + simp only [Sigma.mk.inj_iff, heq_eq_eq, Prod.mk.injEq] at heq + rcases heq with ⟨hz, hx, hy⟩ + subst hx; subst hy; subst hz; rfl + · rintro ⟨z, x, y⟩ h + simp only [Finset.mem_sigma, Finset.mem_filter, Finset.mem_product, Finset.mem_range] at h + refine ⟨(x, y, z), ?_, rfl⟩ + rw [mem_boxSlice] + dsimp + omega + rw [hfiber] + have hrew : ∀ z ∈ Finset.range (2 * k + 1), + (((Finset.range (2 * k + 2)) ×ˢ (Finset.range (2 * k + 2))).filter + (fun p => p.1 + p.2 = 3 * k + 1 + t - z)).card = + if z < k + t then k + 2 - t + z else 3 * k + 2 + t - z := by + intro z hz + rw [Finset.mem_range] at hz + rw [card_pair_sum (2 * k + 1) (3 * k + 1 + t - z) (by omega)] + split_ifs <;> omega + rw [Finset.sum_congr rfl hrew] + -- Split `range (2*k + 1)` at `k + t` + have hsplit : + ∑ z ∈ Finset.range (2 * k + 1), + (if z < k + t then k + 2 - t + z else 3 * k + 2 + t - z) = + (∑ z ∈ Finset.range (k + t), (k + 2 - t + z)) + + (∑ u ∈ Finset.range (k + 1 - t), (2 * k + 2 - u)) := by + have hdecomp : 2 * k + 1 = (k + t) + (k + 1 - t) := by omega + conv_lhs => rw [hdecomp, Finset.sum_range_add] + congr 1 + · apply Finset.sum_congr rfl + intro z hz + rw [Finset.mem_range] at hz + simp [hz] + · apply Finset.sum_congr rfl + intro u hu + rw [Finset.mem_range] at hu + have hnot : ¬ (k + t + u < k + t) := by omega + simp only [hnot, ↓reduceIte] + omega + rw [hsplit] + have hs1 := two_mul_sum_range_add (k + 2 - t) (k + t) + have hs2 := two_mul_sum_range_sub (2 * k + 2) (k + 1 - t) (by omega) + have hsq : t ^ 2 ≤ 3 * k ^ 2 + 5 * k + 2 := by nlinarith + have h2eq : + 2 * ((∑ z ∈ Finset.range (k + t), (k + 2 - t + z)) + + (∑ u ∈ Finset.range (k + 1 - t), (2 * k + 2 - u))) = + 2 * (3 * k ^ 2 + 5 * k + 2 - t ^ 2) := by + rw [mul_add, hs1, hs2] + have h1 : t ≤ k + 2 := by omega + have h2 : 1 ≤ 2 * (k + 2 - t) + (k + t) := by omega + have h3 : t ≤ k + 1 := by omega + have h4 : k + 1 - t ≤ 2 * (2 * k + 2) + 1 := by omega + zify [h1, h2, h3, h4, hsq] + ring + omega + +/-- Middle slice cardinality: `B(3k + 1) = 3k^2 + 5k + 2`. -/ +theorem boxSlice_mid_card (k : ℕ) : + (boxSlice k (3 * k + 1)).card = 3 * k ^ 2 + 5 * k + 2 := by + simpa using boxSlice_card k 0 (Nat.zero_le k) + +/-- Exact number of symmetric chains covering `Box(k)`: `3k^2 + 5k + 2`. -/ +theorem boxId_image_card_eq (k : ℕ) : + ((boxFinset k).image (boxId k)).card = 3 * k ^ 2 + 5 * k + 2 := by + rw [boxId_image_card, boxSlice_mid_card] + +end PatternPoset diff --git a/LeanPool/PatternPosetNotSperner/Defs.lean b/LeanPool/PatternPosetNotSperner/Defs.lean new file mode 100644 index 0000000000..ec0753a17d --- /dev/null +++ b/LeanPool/PatternPosetNotSperner/Defs.lean @@ -0,0 +1,528 @@ +/- +Copyright (c) 2026 Tyler B. Hughes. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Tyler B. Hughes +-/ + +-- Modified for Lean Pool: Lean 4.36 module and import port with style and linter fixes. + +module + +public import Mathlib.Data.Finset.Card +public import Mathlib.Data.Finset.Image +public import Mathlib.Data.Finset.Lattice.Fold +public import Mathlib.Data.Finset.Powerset +public import Mathlib.Data.Finset.Sort +public import Mathlib.Data.Fintype.Perm +public import Mathlib.Order.Hom.Basic + +import Mathlib.Tactic.Choose + +/-! +# Core Definitions for the Classical Permutation Pattern Poset + +Faithful Lean 4 formalization of: +- `Perm`: finite permutations `(len : ℕ, perm : Equiv.Perm (Fin len))`. +- `Contains` (`≤`): classical permutation pattern containment via order-preserving + embeddings `Fin σ.len ↪o Fin τ.len` preserving pairwise value comparisons. +- `PartialOrder Perm`: reflexivity, transitivity, antisymmetry. +- `IsAntichain`, `IsChain`, `RankLevel`, `largestRank`, `width`, `IsSperner`. +- Fundamental chain-cover upper bound (`antichain_card_le_of_indexed_chain_cover`, + `width_le_of_chain_cover`, `width_le_of_indexed_chain_cover`). +- `HasValley` and upward monotonicity (`hasValley_mono`). +- Genuine principal downset `Downset τ` (`π ∈ Downset τ ↔ π ≤ τ`) and + interval `Interval σ τ` (`π ∈ Interval σ τ ↔ σ ≤ π ∧ π ≤ τ`). +- Faithful list representation `toList` and list standardization `standardizeList`. +-/ + +@[expose] public section + +namespace PatternPoset + +/-- A finite permutation of `{0, …, len - 1}` (0-indexed representation of `S_len`). -/ +structure Perm where + /-- Length of the permutation. -/ + len : ℕ + /-- Underlying bijection on `Fin len`. -/ + perm : Equiv.Perm (Fin len) + +instance : DecidableEq Perm := fun σ τ => by + cases σ with + | mk n p => + cases τ with + | mk m q => + by_cases h : n = m + · subst h + by_cases hp : p = q + · exact isTrue (by subst hp; rfl) + · exact isFalse (fun heq => hp (by cases heq; rfl)) + · exact isFalse (fun heq => h (by cases heq; rfl)) + +/-- Extensionality for `Perm` via length equality and entry values. -/ +theorem Perm.ext_val {σ τ : Perm} (hlen : σ.len = τ.len) + (hval : ∀ i : Fin σ.len, (σ.perm i).val = (τ.perm (Fin.cast hlen i)).val) : + σ = τ := by + cases σ with + | mk n p => + cases τ with + | mk m q => + dsimp at hlen + subst hlen + congr 1 + ext i + exact hval i + +/-- Any strictly monotone function `Fin n → Fin n` is the identity. -/ +theorem strictMono_fin_eq_id {n : ℕ} {f : Fin n → Fin n} (hf : StrictMono f) : + ∀ i : Fin n, f i = i := by + have hge : ∀ (k : ℕ) (hk : k < n), k ≤ (f ⟨k, hk⟩).val := by + intro k + induction k with + | zero => intro _; exact Nat.zero_le _ + | succ k ih => + intro hk + have hk' : k < n := Nat.lt_of_succ_lt hk + have h1 : k ≤ (f ⟨k, hk'⟩).val := ih hk' + have h2 : (f ⟨k, hk'⟩).val < (f ⟨k + 1, hk⟩).val := + hf (show (⟨k, hk'⟩ : Fin n) < ⟨k + 1, hk⟩ by exact Nat.lt_succ_self k) + omega + have hle : ∀ (d : ℕ) (i : Fin n), n - 1 - i.val = d → (f i).val ≤ i.val := by + intro d + induction d with + | zero => + intro i hi + have h1 : (f i).val < n := (f i).isLt + omega + | succ d ih => + intro i hi + have hi1 : i.val + 1 < n := by omega + have hnext : (f ⟨i.val + 1, hi1⟩).val ≤ i.val + 1 := + ih ⟨i.val + 1, hi1⟩ (by dsimp; omega) + have hlt : (f i).val < (f ⟨i.val + 1, hi1⟩).val := + hf (show i < ⟨i.val + 1, hi1⟩ by exact Nat.lt_succ_self i.val) + omega + intro i + ext + have h1 : i.val ≤ (f i).val := hge i.val i.isLt + have h2 : (f i).val ≤ i.val := hle (n - 1 - i.val) i rfl + omega + +/-- Classical permutation pattern containment: `σ` occurs as a pattern in `τ` if there is +a strictly increasing map `f : Fin σ.len ↪o Fin τ.len` such that the values `τ.perm (f i)` +have the same relative order as `σ.perm i`. -/ +def Contains (σ τ : Perm) : Prop := + ∃ f : Fin σ.len ↪o Fin τ.len, + ∀ i j : Fin σ.len, σ.perm i < σ.perm j ↔ τ.perm (f i) < τ.perm (f j) + +/-- Containment implies length inequality. -/ +theorem contains_len_le {σ τ : Perm} (h : Contains σ τ) : σ.len ≤ τ.len := by + rcases h with ⟨f, _⟩ + simpa using Fintype.card_le_of_injective f f.injective + +/-- Two permutations of equal length with `Contains σ τ` are equal. -/ +theorem contains_eq_of_len_eq {σ τ : Perm} (h : Contains σ τ) (hlen : σ.len = τ.len) : + σ = τ := by + rcases h with ⟨f, hf⟩ + cases σ with + | mk n p => + cases τ with + | mk m q => + dsimp at hlen + subst hlen + have hf_id : ∀ i : Fin n, f i = i := strictMono_fin_eq_id f.strictMono + have hqp : StrictMono (fun a : Fin n => q (p.symm a)) := by + intro a b hab + have h1 : p (p.symm a) < p (p.symm b) := by simpa using hab + have h2 : q (f (p.symm a)) < q (f (p.symm b)) := (hf _ _).mp h1 + simpa [hf_id] using h2 + have hqp_id : ∀ a : Fin n, q (p.symm a) = a := strictMono_fin_eq_id hqp + congr 1 + refine Equiv.ext fun i => ?_ + have := hqp_id (p i) + simpa using this.symm + +/-- Uniqueness from relative order: if `σ` and `τ` have the same length and the same +pairwise value comparisons, then `σ = τ`. -/ +theorem Perm.eq_of_lt_iff {σ τ : Perm} (hlen : σ.len = τ.len) + (hlt : ∀ i j : Fin σ.len, + σ.perm i < σ.perm j ↔ τ.perm (Fin.cast hlen i) < τ.perm (Fin.cast hlen j)) : + σ = τ := by + apply contains_eq_of_len_eq _ hlen + refine ⟨⟨⟨Fin.cast hlen, (Fin.castOrderIso hlen).injective⟩, ?_⟩, hlt⟩ + intro a b + exact (Fin.castOrderIso hlen).le_iff_le + +instance : PartialOrder Perm where + le := Contains + le_refl σ := ⟨OrderEmbedding.ofStrictMono id strictMono_id, fun _ _ => Iff.rfl⟩ + le_trans _ _ _ h₁ h₂ := by + rcases h₁ with ⟨f, hf⟩ + rcases h₂ with ⟨g, hg⟩ + exact ⟨f.trans g, fun i j => (hf i j).trans (hg (f i) (f j))⟩ + le_antisymm _ _ h₁ h₂ := + contains_eq_of_len_eq h₁ (le_antisymm (contains_len_le h₁) (contains_len_le h₂)) + +/-- Definitional bridge between `≤` on `Perm` and `Contains`. -/ +theorem le_iff_contains {σ τ : Perm} : σ ≤ τ ↔ Contains σ τ := Iff.rfl + +/-- Helper: `σ ≤ τ` implies `σ.len ≤ τ.len`. -/ +theorem le_len_le {σ τ : Perm} (h : σ ≤ τ) : σ.len ≤ τ.len := + contains_len_le h + +/-- Helper: `σ ≤ τ` with `σ.len = τ.len` implies `σ = τ`. -/ +theorem eq_of_le_of_len_eq {σ τ : Perm} (h : σ ≤ τ) (hlen : σ.len = τ.len) : σ = τ := + contains_eq_of_len_eq h hlen + +/-- An antichain in `Perm`: no two distinct elements are comparable. -/ +def IsAntichain (A : Finset Perm) : Prop := + ∀ x ∈ A, ∀ y ∈ A, x ≤ y → x = y + +/-- A chain in `Perm`: every pair of elements is comparable. -/ +def IsChain (C : Finset Perm) : Prop := + ∀ x ∈ C, ∀ y ∈ C, x ≤ y ∨ y ≤ x + +/-- The rank-`r` level of a finite set `S` of permutations: all elements of length `r`. -/ +def RankLevel (S : Finset Perm) (r : ℕ) : Finset Perm := + S.filter (fun π => π.len = r) + +/-- Every rank level is an antichain. -/ +theorem rankLevel_isAntichain (S : Finset Perm) (r : ℕ) : IsAntichain (RankLevel S r) := by + intro x hx y hy hxy + rw [RankLevel, Finset.mem_filter] at hx hy + exact eq_of_le_of_len_eq hxy (hx.2.trans hy.2.symm) + +/-- The largest rank size (maximum cardinality of any rank level) of `S`. -/ +def largestRank (S : Finset Perm) : ℕ := + (S.image Perm.len).sup (fun r => (RankLevel S r).card) + +theorem rankLevel_card_le_largestRank (S : Finset Perm) (r : ℕ) : + (RankLevel S r).card ≤ largestRank S := by + by_cases hne : (RankLevel S r).Nonempty + · rcases hne with ⟨π, hπ⟩ + rw [RankLevel, Finset.mem_filter] at hπ + have hr : r ∈ S.image Perm.len := Finset.mem_image.mpr ⟨π, hπ.1, hπ.2⟩ + exact Finset.le_sup (f := fun r => (RankLevel S r).card) hr + · rw [Finset.not_nonempty_iff_eq_empty.mp hne, Finset.card_empty] + exact Nat.zero_le _ + +theorem largestRank_le_iff {S : Finset Perm} {m : ℕ} : + largestRank S ≤ m ↔ ∀ r : ℕ, (RankLevel S r).card ≤ m := by + constructor + · intro h r + exact (rankLevel_card_le_largestRank S r).trans h + · intro h + unfold largestRank + exact Finset.sup_le fun r _ => h r + +theorem largestRank_eq_of_bounds {S : Finset Perm} {m r : ℕ} + (hupper : ∀ r' : ℕ, (RankLevel S r').card ≤ m) + (hlower : m ≤ (RankLevel S r).card) : + largestRank S = m := + le_antisymm (largestRank_le_iff.mpr hupper) (hlower.trans (rankLevel_card_le_largestRank S r)) + +/-- The width of a finite set `S` of permutations: maximum cardinality of an antichain `A ⊆ S`. -/ +noncomputable def width (S : Finset Perm) : ℕ := + letI := Classical.decPred IsAntichain + (S.powerset.filter IsAntichain).sup Finset.card + +theorem card_le_width_of_antichain {S A : Finset Perm} + (hsub : A ⊆ S) (hanti : IsAntichain A) : A.card ≤ width S := by + unfold width + let _ := Classical.decPred IsAntichain + have hmem : A ∈ S.powerset.filter IsAntichain := by + rw [Finset.mem_filter, Finset.mem_powerset] + exact ⟨hsub, hanti⟩ + exact Finset.le_sup (f := Finset.card) hmem + +theorem width_le_of_forall_antichain {S : Finset Perm} {m : ℕ} + (h : ∀ A : Finset Perm, A ⊆ S → IsAntichain A → A.card ≤ m) : + width S ≤ m := by + unfold width + let _ := Classical.decPred IsAntichain + apply Finset.sup_le + intro A hA + rw [Finset.mem_filter, Finset.mem_powerset] at hA + exact h A hA.1 hA.2 + +/-- Every finite poset `S` satisfies `largestRank S ≤ width S`. -/ +theorem largestRank_le_width (S : Finset Perm) : largestRank S ≤ width S := by + rw [largestRank_le_iff] + intro r + exact card_le_width_of_antichain (Finset.filter_subset _ _) (rankLevel_isAntichain S r) + +/-- A finite subset `S` of the permutation pattern poset is **Sperner** if its width equals +its largest rank size. -/ +def IsSperner (S : Finset Perm) : Prop := + width S = largestRank S + +/-- Fundamental chain-cover upper bound (indexed form): if a finite family of chains +`{C i | i ∈ I}` covers `S`, then every antichain `A ⊆ S` has `A.card ≤ I.card`. -/ +theorem antichain_card_le_of_indexed_chain_cover {ι : Type*} + {S A : Finset Perm} {I : Finset ι} {C : ι → Finset Perm} + (hsub : A ⊆ S) (hanti : IsAntichain A) + (hchains : ∀ i ∈ I, IsChain (C i)) + (hcover : ∀ x ∈ S, ∃ i ∈ I, x ∈ C i) : + A.card ≤ I.card := by + have hex : ∀ x : Perm, x ∈ A → ∃ i ∈ I, x ∈ C i := fun x hx => hcover x (hsub hx) + classical + choose f hfI hfC using fun (x : { x // x ∈ A }) => hex x.1 x.2 + by_cases hA : A.Nonempty + · have hI_ne : Nonempty ι := by + rcases hA with ⟨a, ha⟩ + exact ⟨f ⟨a, ha⟩⟩ + let g' : Perm → ι := fun x => if hx : x ∈ A then f ⟨x, hx⟩ else Classical.choice hI_ne + refine Finset.card_le_card_of_injOn g' ?_ ?_ + · intro x hx + have hx' : x ∈ A := Finset.mem_coe.mp hx + change g' x ∈ (I : Set ι) + simp only [g', hx', dite_true] + exact hfI ⟨x, hx'⟩ + · intro x hx y hy hxy + have hx' : x ∈ A := Finset.mem_coe.mp hx + have hy' : y ∈ A := Finset.mem_coe.mp hy + have hxy' : f ⟨x, hx'⟩ = f ⟨y, hy'⟩ := by + simpa only [g', hx', hy', dite_true] using hxy + have hxC : x ∈ C (f ⟨x, hx'⟩) := hfC ⟨x, hx'⟩ + have hyC : y ∈ C (f ⟨x, hx'⟩) := hxy' ▸ hfC ⟨y, hy'⟩ + rcases hchains (f ⟨x, hx'⟩) (hfI ⟨x, hx'⟩) x hxC y hyC with hle | hle + · exact hanti x hx' y hy' hle + · exact (hanti y hy' x hx' hle).symm + · rw [Finset.not_nonempty_iff_eq_empty.mp hA, Finset.card_empty] + exact Nat.zero_le _ + +/-- Indexed chain-cover upper bound on `width S`. -/ +theorem width_le_of_indexed_chain_cover {ι : Type*} + {S : Finset Perm} {I : Finset ι} {C : ι → Finset Perm} + (hchains : ∀ i ∈ I, IsChain (C i)) + (hcover : ∀ x ∈ S, ∃ i ∈ I, x ∈ C i) : + width S ≤ I.card := + width_le_of_forall_antichain fun _ hsub hanti => + antichain_card_le_of_indexed_chain_cover hsub hanti hchains hcover + +/-- Unindexed chain-cover upper bound on `width S`. -/ +theorem width_le_of_chain_cover {S : Finset Perm} {𝒞 : Finset (Finset Perm)} + (hchains : ∀ C ∈ 𝒞, IsChain C) + (hcover : ∀ x ∈ S, ∃ C ∈ 𝒞, x ∈ C) : + width S ≤ 𝒞.card := + width_le_of_indexed_chain_cover (I := 𝒞) (C := id) hchains hcover + +/-- A permutation has a **valley** if some entry is strictly smaller than an earlier entry +and a later entry (i.e., contains `213` or `312`). -/ +def HasValley (π : Perm) : Prop := + ∃ i j k : Fin π.len, i < j ∧ j < k ∧ π.perm j < π.perm i ∧ π.perm j < π.perm k + +/-- Having a valley is inherited upward under pattern containment. -/ +theorem hasValley_mono {σ τ : Perm} (hv : HasValley σ) (hle : σ ≤ τ) : HasValley τ := by + rcases hv with ⟨i, j, k, hij, hjk, hji, hjk'⟩ + rcases le_iff_contains.mp hle with ⟨f, hf⟩ + exact ⟨f i, f j, f k, f.strictMono hij, f.strictMono hjk, (hf j i).mp hji, (hf j k).mp hjk'⟩ + +/-! ### Principal Downsets and Intervals -/ + +/-- The standardized pattern of `τ` obtained by restricting to the positions in +`S : Finset (Fin τ.len)`. -/ +def subseqPerm (τ : Perm) (S : Finset (Fin τ.len)) : Perm where + len := S.card + perm := + let ePos : Fin S.card ≃o S := S.orderIsoOfFin rfl + let V : Finset (Fin τ.len) := S.image τ.perm + have hV : V.card = S.card := Finset.card_image_of_injective S τ.perm.injective + let eVal : Fin S.card ≃o V := V.orderIsoOfFin hV + let eRestrict : S ≃ V := + { toFun := fun x => ⟨τ.perm x.1, Finset.mem_image_of_mem τ.perm x.2⟩ + invFun := fun y => + ⟨τ.perm.symm y.1, by + rcases Finset.mem_image.mp y.2 with ⟨x, hx, hxy⟩ + have : τ.perm.symm y.1 = x := by rw [← hxy]; exact τ.perm.symm_apply_apply x + exact this ▸ hx⟩ + left_inv := fun x => Subtype.ext (τ.perm.symm_apply_apply x.1) + right_inv := fun y => Subtype.ext (τ.perm.apply_symm_apply y.1) } + (ePos.toEquiv.trans eRestrict).trans eVal.toEquiv.symm + +/-- Every subsequence pattern `subseqPerm τ S` is contained in `τ`. -/ +theorem subseqPerm_le (τ : Perm) (S : Finset (Fin τ.len)) : subseqPerm τ S ≤ τ := by + rw [le_iff_contains] + let ePos : Fin S.card ≃o S := S.orderIsoOfFin rfl + let V : Finset (Fin τ.len) := S.image τ.perm + have hV : V.card = S.card := Finset.card_image_of_injective S τ.perm.injective + let eVal : Fin S.card ≃o V := V.orderIsoOfFin hV + refine ⟨ePos.toOrderEmbedding.trans (OrderEmbedding.subtype _), ?_⟩ + intro i j + change (eVal.symm ⟨τ.perm (ePos i).1, _⟩) < (eVal.symm ⟨τ.perm (ePos j).1, _⟩) ↔ + τ.perm (ePos i).1 < τ.perm (ePos j).1 + exact eVal.symm.lt_iff_lt + +/-- If `σ ≤ τ` via `f`, then `σ = subseqPerm τ (Finset.univ.image f)`. -/ +theorem eq_subseqPerm_of_le {σ τ : Perm} (f : Fin σ.len ↪o Fin τ.len) + (hf : ∀ i j : Fin σ.len, σ.perm i < σ.perm j ↔ τ.perm (f i) < τ.perm (f j)) : + σ = subseqPerm τ (Finset.univ.image f) := by + set S : Finset (Fin τ.len) := Finset.univ.image f + have hcard : σ.len = (subseqPerm τ S).len := by + change σ.len = S.card + rw [Finset.card_image_of_injective _ f.injective, Finset.card_univ, Fintype.card_fin] + let ePos : Fin S.card ≃o S := S.orderIsoOfFin rfl + let V : Finset (Fin τ.len) := S.image τ.perm + have hV : V.card = S.card := Finset.card_image_of_injective S τ.perm.injective + let eVal : Fin S.card ≃o V := V.orderIsoOfFin hV + have hpos_eq : ∀ i : Fin σ.len, (ePos (Fin.cast hcard i)).1 = f i := by + have hsm : StrictMono (fun i : Fin σ.len => + Fin.cast hcard.symm + (ePos.symm ⟨f i, Finset.mem_image_of_mem f (Finset.mem_univ i)⟩)) := by + intro a b hab + change (ePos.symm ⟨f a, _⟩).val < (ePos.symm ⟨f b, _⟩).val + exact ePos.symm.lt_iff_lt.mpr (f.strictMono hab) + have hid := strictMono_fin_eq_id hsm + intro i + have hi := hid i + have h1 : + ePos.symm ⟨f i, Finset.mem_image_of_mem f (Finset.mem_univ i)⟩ = Fin.cast hcard i := by + apply Fin.ext + have hval : + (ePos.symm ⟨f i, Finset.mem_image_of_mem f (Finset.mem_univ i)⟩).val = i.val := + congrArg Fin.val hi + exact hval + have h2 := congrArg ePos h1 + simp only [OrderIso.apply_symm_apply] at h2 + exact congrArg Subtype.val h2.symm + apply Perm.eq_of_lt_iff hcard + intro i j + rw [hf i j] + change τ.perm (f i) < τ.perm (f j) ↔ + eVal.symm ⟨τ.perm (ePos (Fin.cast hcard i)).1, _⟩ < + eVal.symm ⟨τ.perm (ePos (Fin.cast hcard j)).1, _⟩ + rw [eVal.symm.lt_iff_lt] + change τ.perm (f i) < τ.perm (f j) ↔ + τ.perm (ePos (Fin.cast hcard i)).1 < τ.perm (ePos (Fin.cast hcard j)).1 + rw [hpos_eq i, hpos_eq j] + +/-- The principal downset `[∅, τ]` of `τ` in the permutation pattern poset: +the genuine `Finset` of all patterns contained in `τ`. -/ +def Downset (τ : Perm) : Finset Perm := + ((Finset.univ : Finset (Fin τ.len)).powerset).image (subseqPerm τ) + +/-- Exact characterization of `Downset τ`: `π ∈ Downset τ ↔ π ≤ τ`. -/ +theorem mem_downset_iff {π τ : Perm} : π ∈ Downset τ ↔ π ≤ τ := by + unfold Downset + rw [Finset.mem_image] + constructor + · rintro ⟨S, _, rfl⟩ + exact subseqPerm_le τ S + · intro hle + rcases le_iff_contains.mp hle with ⟨f, hf⟩ + exact ⟨Finset.univ.image f, Finset.mem_powerset.mpr (Finset.subset_univ _), + (eq_subseqPerm_of_le f hf).symm⟩ + +instance decidableContains : DecidableRel Contains := + fun σ τ => decidable_of_iff (σ ∈ Downset τ) (mem_downset_iff.trans le_iff_contains) + +instance decidableLEPerm : DecidableRel (· ≤ · : Perm → Perm → Prop) := + fun σ τ => decidable_of_iff (σ ∈ Downset τ) mem_downset_iff + +/-- The closed interval `[σ, τ]` in the permutation pattern poset: +all permutations `π` with `σ ≤ π` and `π ≤ τ`. -/ +def Interval (σ τ : Perm) : Finset Perm := + (Downset τ).filter (fun π => σ ≤ π) + +/-- Exact characterization of `Interval σ τ`: +`π ∈ Interval σ τ ↔ σ ≤ π ∧ π ≤ τ`. -/ +theorem mem_interval_iff {σ τ π : Perm} : π ∈ Interval σ τ ↔ σ ≤ π ∧ π ≤ τ := by + unfold Interval + rw [Finset.mem_filter, mem_downset_iff] + exact and_comm + +/-! ### List Representation and Standardization -/ + +/-- List of 0-indexed values of a permutation `π`. -/ +def Perm.toList (π : Perm) : List ℕ := + List.ofFn (fun i : Fin π.len => (π.perm i).val) + +theorem Perm.toList_length (π : Perm) : π.toList.length = π.len := by + simp [Perm.toList] + +/-- `Perm.toList` is injective. -/ +theorem Perm.toList_injective : Function.Injective Perm.toList := by + intro σ τ h + have hlen : σ.len = τ.len := by + have := congrArg List.length h + simpa [Perm.toList_length] using this + apply Perm.ext_val hlen + intro i + have hget := congrArg (fun l => l[i.val]?) h + simp only [Perm.toList, List.getElem?_ofFn, i.isLt, dite_true, + show i.val < τ.len from hlen ▸ i.isLt] at hget + exact Option.some.inj hget + +/-- Standardize a list of distinct natural numbers to `{0, …, l.length - 1}` by +replacing each entry `v` with the count of entries strictly smaller than `v`. -/ +def standardizeList (l : List ℕ) : List ℕ := + l.map (fun v => (l.filter (· < v)).length) + +/-- Count of indices `j : Fin n` with `p j < p i` equals `(p i).val`. -/ +theorem card_lt_perm_val {n : ℕ} (p : Equiv.Perm (Fin n)) (i : Fin n) : + (Finset.univ.filter (fun j : Fin n => p j < p i)).card = (p i).val := by + have hbij : + (Finset.univ.filter (fun j : Fin n => p j < p i)).card = + (Finset.univ.filter (fun v : Fin n => v < p i)).card := by + refine Finset.card_bij (fun j _ => p j) ?_ ?_ ?_ + · intro j hj + rw [Finset.mem_filter] at hj ⊢ + exact ⟨Finset.mem_univ _, hj.2⟩ + · intro j₁ _ j₂ _ h + exact p.injective h + · intro v hv + rw [Finset.mem_filter] at hv + refine ⟨p.symm v, ?_, p.apply_symm_apply v⟩ + rw [Finset.mem_filter] + exact ⟨Finset.mem_univ _, by simpa using hv.2⟩ + rw [hbij] + have hbij2 : + (Finset.univ.filter (fun v : Fin n => v < p i)).card = + (Finset.range (p i).val).card := by + refine Finset.card_bij (fun v _ => v.val) ?_ ?_ ?_ + · intro v hv + rw [Finset.mem_filter] at hv + exact Finset.mem_range.mpr hv.2 + · intro v₁ _ v₂ _ h + exact Fin.ext h + · intro k hk + rw [Finset.mem_range] at hk + refine ⟨⟨k, lt_trans hk (p i).isLt⟩, ?_, rfl⟩ + rw [Finset.mem_filter] + exact ⟨Finset.mem_univ _, hk⟩ + rw [hbij2, Finset.card_range] + +/-- If `σ ≤ τ` via `f`, then `σ.toList` equals `standardizeList` of the selected +values of `τ`. -/ +theorem toList_eq_standardizeList_of_le {σ τ : Perm} (f : Fin σ.len ↪o Fin τ.len) + (hf : ∀ i j : Fin σ.len, σ.perm i < σ.perm j ↔ τ.perm (f i) < τ.perm (f j)) : + σ.toList = standardizeList (List.ofFn (fun i : Fin σ.len => (τ.perm (f i)).val)) := by + set L := List.ofFn (fun i : Fin σ.len => (τ.perm (f i)).val) + apply List.ext_getElem + · simp [Perm.toList, standardizeList, L] + · intro idx h1 h2 + simp only [Perm.toList, standardizeList, L, List.getElem_map, List.getElem_ofFn] + have hfilt : + ((List.ofFn (fun j : Fin σ.len => (τ.perm (f j)).val)).filter + (· < (τ.perm (f ⟨idx, by simpa [Perm.toList] using h1⟩)).val)).length = + (Finset.univ.filter (fun j : Fin σ.len => + σ.perm j < σ.perm ⟨idx, by simpa [Perm.toList] using h1⟩)).card := by + have hlist : + (List.ofFn (fun j : Fin σ.len => (τ.perm (f j)).val)).filter + (· < (τ.perm (f ⟨idx, by simpa [Perm.toList] using h1⟩)).val) = + ((List.finRange σ.len).filter (fun j : Fin σ.len => + decide (σ.perm j < σ.perm ⟨idx, by simpa [Perm.toList] using h1⟩))).map + (fun j => (τ.perm (f j)).val) := by + rw [List.ofFn_eq_map, List.filter_map] + congr 1 + apply List.filter_congr + intro j _ + simp only [Function.comp_apply, decide_eq_decide] + exact (hf j ⟨idx, by simpa [Perm.toList] using h1⟩).symm + rw [hlist, List.length_map] + rw [← List.toFinset_card_of_nodup ((List.nodup_finRange σ.len).filter _)] + congr 1 + ext j + simp + rw [hfilt, card_lt_perm_val] + +end PatternPoset diff --git a/LeanPool/PatternPosetNotSperner/Family.lean b/LeanPool/PatternPosetNotSperner/Family.lean new file mode 100644 index 0000000000..93146a8aaa --- /dev/null +++ b/LeanPool/PatternPosetNotSperner/Family.lean @@ -0,0 +1,1218 @@ +/- +Copyright (c) 2026 Tyler B. Hughes. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Tyler B. Hughes +-/ + +-- Modified for Lean Pool: Lean 4.36 module and import port with style and linter fixes. + +module + +public import Mathlib.Order.Interval.Finset.Nat +public import LeanPool.PatternPosetNotSperner.Defs +public import LeanPool.PatternPosetNotSperner.BoxChains + +import Mathlib.Tactic.Linarith + +/-! +# Infinite Family `τ_k` with Exact Sperner Deficiency `k` + +Formalizes the two-leader infinite family `τ_k` (`k ≥ 1`) of length `6k + 4`: +- `tau k`: first entry `4k + 2` (`4k + 3` 1-indexed), second entry `2k` (`2k + 1` 1-indexed), + followed by all remaining entries in strictly decreasing order. +- Complete disjoint classification of `Downset (tau k)` into: + 1. Valley patterns `patP x y z` (`0 ≤ x, y ≤ 2k + 1`, `0 ≤ z ≤ 2k`, `x + y ≥ 1`); + 2. One-leader valley-free patterns `patQ p q` (`p ≥ 1`, either `p ≤ 2k + 1 ∧ q ≤ 4k + 1` + or `p ≤ 4k + 2 ∧ q ≤ 2k`); + 3. Decreasing patterns `patD l` (`l ≤ 6k + 2`). +- Explicit antichain of size `3k^2 + 9k + 5` inside `Downset (tau k)`. +- Explicit matching cover by `3k^2 + 9k + 5` chains (`3k^2 + 5k + 2` symmetric box chains + plus `4k + 3` valley-free chains), proving `width (Downset (tau k)) = 3k^2 + 9k + 5`. +- Exact largest rank proof `largestRank (Downset (tau k)) = 3k^2 + 8k + 5`. +- Exact Sperner deficiency `width (Downset (tau k)) = largestRank (Downset (tau k)) + k` + and `¬ IsSperner (Downset (tau k))` for all `k ≥ 1`. +-/ + +@[expose] public section + +namespace PatternPoset + +/-! ### Canonical Pattern Families `P(x, y, z)`, `Q(p, q)`, `D(l)`, and `τ_k` -/ + +/-- Plain `ℕ` value formula for `patP x y z` at position `i` (0-indexed). -/ +def patPVal (x y z i : ℕ) : ℕ := + if i = 0 then y + z + 1 + else if i = 1 then z + else if i < x + 2 then x + y + z + 3 - i + else if i < x + y + 2 then x + y + z + 2 - i + else x + y + z + 1 - i + +/-- Plain `ℕ` inverse formula for `patP x y z` at value `v` (0-indexed). -/ +def patPInvVal (x y z v : ℕ) : ℕ := + if v = y + z + 1 then 0 + else if v = z then 1 + else if y + z + 2 ≤ v then x + y + z + 3 - v + else if z + 1 ≤ v then x + y + z + 2 - v + else x + y + z + 1 - v + +/-- Forward entry map of `patP x y z` on `Fin (x + y + z + 2)` (0-indexed). -/ +def patPFun (x y z : ℕ) (i : Fin (x + y + z + 2)) : Fin (x + y + z + 2) := + ⟨patPVal x y z i.val, by unfold patPVal; split_ifs <;> omega⟩ + +/-- Inverse entry map of `patP x y z` on `Fin (x + y + z + 2)` (0-indexed). -/ +def patPInv (x y z : ℕ) (v : Fin (x + y + z + 2)) : Fin (x + y + z + 2) := + ⟨patPInvVal x y z v.val, by unfold patPInvVal; split_ifs <;> omega⟩ + +/-- Two-leader pattern `P(x, y, z)` of length `x + y + z + 2` keeping both leaders, +`x` tail entries above the first leader, `y` between the leaders, and `z` below the second. -/ +def patP (x y z : ℕ) : Perm where + len := x + y + z + 2 + perm := + { toFun := patPFun x y z + invFun := patPInv x y z + left_inv := fun i => Fin.ext (by + change patPInvVal x y z (patPVal x y z i.val) = i.val + have hi : i.val < x + y + z + 2 := i.isLt + unfold patPVal + split_ifs <;> (unfold patPInvVal; split_ifs <;> omega)) + right_inv := fun v => Fin.ext (by + change patPVal x y z (patPInvVal x y z v.val) = v.val + have hv : v.val < x + y + z + 2 := v.isLt + unfold patPInvVal + split_ifs <;> + (simp only [patPVal, ↓reduceIte, Nat.one_ne_zero]; try split_ifs) <;> omega) } + +/-- The infinite family `τ_k` of length `6k + 4`: first entry `4k + 2` (`4k + 3` in 1-indexing), +second entry `2k` (`2k + 1` in 1-indexing), followed by the remaining values decreasing. -/ +def tau (k : ℕ) : Perm := patP (2 * k + 1) (2 * k + 1) (2 * k) + +theorem tau_len (k : ℕ) : (tau k).len = 6 * k + 4 := by + change (2 * k + 1) + (2 * k + 1) + 2 * k + 2 = 6 * k + 4 + omega + +/-- First entry of `tau k` is `4k + 2` (i.e., `4k + 3` in 1-indexed notation). -/ +theorem tau_entry_zero (k : ℕ) : + ((tau k).perm ⟨0, by rw [tau_len]; omega⟩).val = 4 * k + 2 := by + change patPVal (2 * k + 1) (2 * k + 1) (2 * k) 0 = 4 * k + 2 + simp only [patPVal, ↓reduceIte] + omega + +/-- Second entry of `tau k` is `2k` (i.e., `2k + 1` in 1-indexed notation). -/ +theorem tau_entry_one (k : ℕ) : + ((tau k).perm ⟨1, by rw [tau_len]; omega⟩).val = 2 * k := by + change patPVal (2 * k + 1) (2 * k + 1) (2 * k) 1 = 2 * k + simp only [patPVal, ↓reduceIte, Nat.one_ne_zero] + +/-- All entries of `tau k` from index `2` onward are strictly decreasing. -/ +theorem tau_tail_strictAnti (k : ℕ) (i j : Fin (tau k).len) + (hi : 2 ≤ i.val) (hij : i < j) : (tau k).perm j < (tau k).perm i := by + change patPVal (2 * k + 1) (2 * k + 1) (2 * k) j.val < + patPVal (2 * k + 1) (2 * k + 1) (2 * k) i.val + have hi_lt : i.val < (2 * k + 1) + (2 * k + 1) + 2 * k + 2 := i.isLt + have hj_lt : j.val < (2 * k + 1) + (2 * k + 1) + 2 * k + 2 := j.isLt + have hlt : i.val < j.val := hij + unfold patPVal + split_ifs <;> omega + +/-- Plain `ℕ` value formula for `patQ p q` at position `i` (0-indexed). -/ +def patQVal (p q i : ℕ) : ℕ := + if i = 0 then q + else if i < p + 1 then p + q + 1 - i + else p + q - i + +/-- Plain `ℕ` inverse formula for `patQ p q` at value `v` (0-indexed). -/ +def patQInvVal (p q v : ℕ) : ℕ := + if v = q then 0 + else if q + 1 ≤ v then p + q + 1 - v + else p + q - v + +/-- Forward entry map of `patQ p q` on `Fin (p + q + 1)` (0-indexed). -/ +def patQFun (p q : ℕ) (i : Fin (p + q + 1)) : Fin (p + q + 1) := + ⟨patQVal p q i.val, by unfold patQVal; split_ifs <;> omega⟩ + +/-- Inverse entry map of `patQ p q` on `Fin (p + q + 1)` (0-indexed). -/ +def patQInv (p q : ℕ) (v : Fin (p + q + 1)) : Fin (p + q + 1) := + ⟨patQInvVal p q v.val, by unfold patQInvVal; split_ifs <;> omega⟩ + +/-- One-leader valley-free pattern `Q(p, q)` of length `p + q + 1`: +first entry `q` (`q + 1` in 1-indexing), followed by `p` entries above it and `q` below it +in strictly decreasing order. -/ +def patQ (p q : ℕ) : Perm where + len := p + q + 1 + perm := + { toFun := patQFun p q + invFun := patQInv p q + left_inv := fun i => Fin.ext (by + change patQInvVal p q (patQVal p q i.val) = i.val + have hi : i.val < p + q + 1 := i.isLt + unfold patQInvVal patQVal + split_ifs <;> omega) + right_inv := fun v => Fin.ext (by + change patQVal p q (patQInvVal p q v.val) = v.val + have hv : v.val < p + q + 1 := v.isLt + unfold patQVal patQInvVal + split_ifs <;> omega) } + +/-- Strictly decreasing permutation `D(l) = (l, l-1, …, 1)` of length `l`. -/ +def patD (l : ℕ) : Perm where + len := l + perm := + { toFun := fun i => ⟨l - 1 - i.val, by omega⟩ + invFun := fun i => ⟨l - 1 - i.val, by omega⟩ + left_inv := fun i => Fin.ext (by dsimp; omega) + right_inv := fun i => Fin.ext (by dsimp; omega) } + +/-! ### Special Cases, Valleys, Injectivity, and Disjointness -/ + +theorem patP_zero_zero (z : ℕ) : patP 0 0 z = patD (z + 2) := by + apply Perm.ext_val (by dsimp [patP, patD]; omega) + intro i + change patPVal 0 0 z i.val = z + 2 - 1 - i.val + have hi : i.val < 0 + 0 + z + 2 := i.isLt + unfold patPVal + split_ifs <;> omega + +theorem patQ_zero (q : ℕ) : patQ 0 q = patD (q + 1) := by + apply Perm.ext_val (by dsimp [patQ, patD]; omega) + intro i + change patQVal 0 q i.val = q + 1 - 1 - i.val + have hi : i.val < 0 + q + 1 := i.isLt + unfold patQVal + split_ifs <;> omega + +private theorem perm_val_eq_of_eq {σ τ : Perm} (h : σ = τ) {k : ℕ} + (h1 : k < σ.len) (h2 : k < τ.len) : + (σ.perm ⟨k, h1⟩).val = (τ.perm ⟨k, h2⟩).val := by + subst h; rfl + +/-- `P(x, y, z)` has a valley whenever `x + y ≥ 1`. -/ +theorem patP_hasValley {x y z : ℕ} (h : 1 ≤ x + y) : HasValley (patP x y z) := by + refine ⟨⟨0, by dsimp [patP]; omega⟩, ⟨1, by dsimp [patP]; omega⟩, + ⟨2, by dsimp [patP]; omega⟩, ?_, ?_, ?_, ?_⟩ + · exact Nat.zero_lt_one + · exact Nat.one_lt_two + · change patPVal x y z 1 < patPVal x y z 0 + simp only [patPVal, ↓reduceIte, Nat.one_ne_zero] + omega + · change patPVal x y z 1 < patPVal x y z 2 + simp only [patPVal, ↓reduceIte, Nat.one_ne_zero, show (2 : ℕ) ≠ 0 by decide, + show (2 : ℕ) ≠ 1 by decide] + split_ifs <;> omega + +/-- `Q(p, q)` is valley-free. -/ +theorem patQ_not_hasValley (p q : ℕ) : ¬ HasValley (patQ p q) := by + rintro ⟨i, j, k, hij, hjk, _, hjk'⟩ + have hj1 : 1 ≤ j.val := by omega + have hlt : j.val < k.val := hjk + have hk : k.val < p + q + 1 := k.isLt + change patQVal p q j.val < patQVal p q k.val at hjk' + unfold patQVal at hjk' + split_ifs at hjk' <;> omega + +/-- `D(l)` is valley-free. -/ +theorem patD_not_hasValley (l : ℕ) : ¬ HasValley (patD l) := by + rintro ⟨_, j, k, _, hjk, _, hjk'⟩ + change l - 1 - j.val < l - 1 - k.val at hjk' + have hlt : j.val < k.val := hjk + have hk : k.val < l := k.isLt + omega + +/-- `patP` is injective in `(x, y, z)`. -/ +theorem patP_injective {x₁ y₁ z₁ x₂ y₂ z₂ : ℕ} + (h : patP x₁ y₁ z₁ = patP x₂ y₂ z₂) : + x₁ = x₂ ∧ y₁ = y₂ ∧ z₁ = z₂ := by + have hlen : x₁ + y₁ + z₁ + 2 = x₂ + y₂ + z₂ + 2 := congrArg Perm.len h + have h0 := perm_val_eq_of_eq h (k := 0) (by dsimp [patP]; omega) (by dsimp [patP]; omega) + have h1 := perm_val_eq_of_eq h (k := 1) (by dsimp [patP]; omega) (by dsimp [patP]; omega) + change patPVal x₁ y₁ z₁ 0 = patPVal x₂ y₂ z₂ 0 at h0 + change patPVal x₁ y₁ z₁ 1 = patPVal x₂ y₂ z₂ 1 at h1 + simp only [patPVal, ↓reduceIte, Nat.one_ne_zero] at h0 h1 + omega + +/-- `patQ` is injective in `(p, q)`. -/ +theorem patQ_injective {p₁ q₁ p₂ q₂ : ℕ} + (h : patQ p₁ q₁ = patQ p₂ q₂) : p₁ = p₂ ∧ q₁ = q₂ := by + have hlen : p₁ + q₁ + 1 = p₂ + q₂ + 1 := congrArg Perm.len h + have h0 := perm_val_eq_of_eq h (k := 0) (by dsimp [patQ]; omega) (by dsimp [patQ]; omega) + change patQVal p₁ q₁ 0 = patQVal p₂ q₂ 0 at h0 + simp only [patQVal, ↓reduceIte] at h0 + omega + +/-- `patD` is injective in `l`. -/ +theorem patD_injective {l₁ l₂ : ℕ} (h : patD l₁ = patD l₂) : l₁ = l₂ := + congrArg Perm.len h + +theorem patP_ne_patQ {x y z p q : ℕ} (hxy : 1 ≤ x + y) : patP x y z ≠ patQ p q := by + intro h + exact patQ_not_hasValley p q (h ▸ patP_hasValley hxy) + +theorem patP_ne_patD {x y z l : ℕ} (hxy : 1 ≤ x + y) : patP x y z ≠ patD l := by + intro h + exact patD_not_hasValley l (h ▸ patP_hasValley hxy) + +theorem patQ_ne_patD {p q l : ℕ} (hp : 1 ≤ p) : patQ p q ≠ patD l := by + intro h + have hlen : p + q + 1 = l := congrArg Perm.len h + have h0 := perm_val_eq_of_eq h (k := 0) (by dsimp [patQ]; omega) (by dsimp [patD]; omega) + change patQVal p q 0 = l - 1 - 0 at h0 + simp only [patQVal, ↓reduceIte] at h0 + omega + +/-! ### Value-Order Band Lemmas and Monotonicity -/ + +private def patPBand (x y i : ℕ) : ℕ := + if i = 0 then 3 + else if i = 1 then 1 + else if i < x + 2 then 4 + else if i < x + y + 2 then 2 + else 0 + +private def patQBand (p i : ℕ) : ℕ := + if i = 0 then 1 + else if i < p + 1 then 2 + else 0 + +private theorem patPVal_lt_iff {x y z a b : ℕ} + (ha : a < x + y + z + 2) (hb : b < x + y + z + 2) : + patPVal x y z a < patPVal x y z b ↔ + patPBand x y a < patPBand x y b ∨ (patPBand x y a = patPBand x y b ∧ b < a) := by + unfold patPVal patPBand + split_ifs <;> omega + +private theorem patQVal_lt_iff {p q a b : ℕ} + (ha : a < p + q + 1) (hb : b < p + q + 1) : + patQVal p q a < patQVal p q b ↔ + patQBand p a < patQBand p b ∨ (patQBand p a = patQBand p b ∧ b < a) := by + unfold patQVal patQBand + split_ifs <;> omega + +private def patPNo1Band (x i : ℕ) : ℕ := + if i = 0 then 1 + else if i < x + 2 then 2 + else 0 + +private theorem patPVal_lt_iff_no1 {x y z a b : ℕ} + (ha : a < x + y + z + 2) (hb : b < x + y + z + 2) (ha1 : a ≠ 1) (hb1 : b ≠ 1) : + patPVal x y z a < patPVal x y z b ↔ + patPNo1Band x a < patPNo1Band x b ∨ (patPNo1Band x a = patPNo1Band x b ∧ b < a) := by + unfold patPVal patPNo1Band + split_ifs <;> omega + +private def patPNo0Band (x y i : ℕ) : ℕ := + if i = 1 then 1 + else if i < x + y + 2 then 2 + else 0 + +private theorem patPVal_lt_iff_no0 {x y z a b : ℕ} + (ha : a < x + y + z + 2) (hb : b < x + y + z + 2) (ha0 : a ≠ 0) (hb0 : b ≠ 0) : + patPVal x y z a < patPVal x y z b ↔ + patPNo0Band x y a < patPNo0Band x y b ∨ + (patPNo0Band x y a = patPNo0Band x y b ∧ b < a) := by + unfold patPVal patPNo0Band + split_ifs <;> omega + +private theorem patPVal_lt_iff_tail {x y z a b : ℕ} + (ha : a < x + y + z + 2) (hb : b < x + y + z + 2) (ha2 : 2 ≤ a) (hb2 : 2 ≤ b) : + patPVal x y z a < patPVal x y z b ↔ b < a := by + unfold patPVal + split_ifs <;> omega + +theorem patP_le_patP {x₁ y₁ z₁ x₂ y₂ z₂ : ℕ} + (hx : x₁ ≤ x₂) (hy : y₁ ≤ y₂) (hz : z₁ ≤ z₂) : + patP x₁ y₁ z₁ ≤ patP x₂ y₂ z₂ := by + rw [le_iff_contains] + let fVal : ℕ → ℕ := fun i => + if i < x₁ + 2 then i + else if i < x₁ + y₁ + 2 then i + (x₂ - x₁) + else i + (x₂ - x₁) + (y₂ - y₁) + let f : Fin (x₁ + y₁ + z₁ + 2) → Fin (x₂ + y₂ + z₂ + 2) := + fun i => ⟨fVal i.val, by have := i.isLt; dsimp only [fVal]; split_ifs <;> omega⟩ + have hf_sm : StrictMono f := by + intro a b hab + change fVal a.val < fVal b.val + have : a.val < b.val := hab + dsimp only [fVal] + split_ifs <;> omega + have hband : ∀ i : Fin (x₁ + y₁ + z₁ + 2), + patPBand x₂ y₂ (fVal i.val) = patPBand x₁ y₁ i.val := by + intro i + dsimp only [patPBand, fVal] + split_ifs <;> omega + refine ⟨OrderEmbedding.ofStrictMono f hf_sm, ?_⟩ + intro i j + change patPVal x₁ y₁ z₁ i.val < patPVal x₁ y₁ z₁ j.val ↔ + patPVal x₂ y₂ z₂ (fVal i.val) < patPVal x₂ y₂ z₂ (fVal j.val) + have hi : i.val < x₁ + y₁ + z₁ + 2 := i.isLt + have hj : j.val < x₁ + y₁ + z₁ + 2 := j.isLt + have hfi : fVal i.val < x₂ + y₂ + z₂ + 2 := (f i).isLt + have hfj : fVal j.val < x₂ + y₂ + z₂ + 2 := (f j).isLt + rw [patPVal_lt_iff hi hj, patPVal_lt_iff hfi hfj, hband i, hband j] + have hgt : j.val < i.val ↔ fVal j.val < fVal i.val := by + constructor + · intro h; exact hf_sm h + · intro h; exact hf_sm.lt_iff_lt.mp h + rw [hgt] + +theorem patQ_le_patQ {p₁ q₁ p₂ q₂ : ℕ} (hp : p₁ ≤ p₂) (hq : q₁ ≤ q₂) : + patQ p₁ q₁ ≤ patQ p₂ q₂ := by + rw [le_iff_contains] + let fVal : ℕ → ℕ := fun i => if i < p₁ + 1 then i else i + (p₂ - p₁) + let f : Fin (p₁ + q₁ + 1) → Fin (p₂ + q₂ + 1) := + fun i => ⟨fVal i.val, by have := i.isLt; dsimp only [fVal]; split_ifs <;> omega⟩ + have hf_sm : StrictMono f := by + intro a b hab + change fVal a.val < fVal b.val + have : a.val < b.val := hab + dsimp only [fVal] + split_ifs <;> omega + have hband : ∀ i : Fin (p₁ + q₁ + 1), patQBand p₂ (fVal i.val) = patQBand p₁ i.val := by + intro i + dsimp only [patQBand, fVal] + split_ifs <;> omega + refine ⟨OrderEmbedding.ofStrictMono f hf_sm, ?_⟩ + intro i j + change patQVal p₁ q₁ i.val < patQVal p₁ q₁ j.val ↔ + patQVal p₂ q₂ (fVal i.val) < patQVal p₂ q₂ (fVal j.val) + have hi : i.val < p₁ + q₁ + 1 := i.isLt + have hj : j.val < p₁ + q₁ + 1 := j.isLt + have hfi : fVal i.val < p₂ + q₂ + 1 := (f i).isLt + have hfj : fVal j.val < p₂ + q₂ + 1 := (f j).isLt + rw [patQVal_lt_iff hi hj, patQVal_lt_iff hfi hfj, hband i, hband j] + have hgt : j.val < i.val ↔ fVal j.val < fVal i.val := hf_sm.lt_iff_lt.symm + rw [hgt] + +theorem patD_le_patD {l₁ l₂ : ℕ} (hl : l₁ ≤ l₂) : patD l₁ ≤ patD l₂ := by + rw [le_iff_contains] + let f : Fin l₁ → Fin l₂ := fun i => ⟨i.val, by omega⟩ + have hf_sm : StrictMono f := fun _ _ hab => hab + refine ⟨OrderEmbedding.ofStrictMono f hf_sm, ?_⟩ + intro i j + change l₁ - 1 - i.val < l₁ - 1 - j.val ↔ l₂ - 1 - i.val < l₂ - 1 - j.val + have hi : i.val < l₁ := i.isLt + have hj : j.val < l₁ := j.isLt + omega + +theorem patP_le_tau {k x y z : ℕ} + (hx : x ≤ 2 * k + 1) (hy : y ≤ 2 * k + 1) (hz : z ≤ 2 * k) : + patP x y z ≤ tau k := + patP_le_patP hx hy hz + +theorem patQ_le_tau_leaderA (k : ℕ) : patQ (2 * k + 1) (4 * k + 1) ≤ tau k := by + rw [le_iff_contains] + let fVal : ℕ → ℕ := fun i => if i = 0 then 0 else i + 1 + let f : Fin ((2 * k + 1) + (4 * k + 1) + 1) → + Fin ((2 * k + 1) + (2 * k + 1) + 2 * k + 2) := + fun i => ⟨fVal i.val, by have := i.isLt; dsimp only [fVal]; split_ifs <;> omega⟩ + have hf_sm : StrictMono f := by + intro a b hab + change fVal a.val < fVal b.val + have : a.val < b.val := hab + dsimp only [fVal] + split_ifs <;> omega + have hband : ∀ i : Fin ((2 * k + 1) + (4 * k + 1) + 1), + patPNo1Band (2 * k + 1) (fVal i.val) = patQBand (2 * k + 1) i.val := by + intro i + by_cases h0 : i.val = 0 + · simp [patPNo1Band, patQBand, fVal, h0] + · have hfval : fVal i.val = i.val + 1 := by simp [fVal, h0] + rw [hfval] + unfold patPNo1Band patQBand + by_cases hlt : i.val < (2 * k + 1) + 1 + · have hlt2 : i.val + 1 < (2 * k + 1) + 2 := by omega + simp [h0, hlt, hlt2] + · have hlt2 : ¬ i.val + 1 < (2 * k + 1) + 2 := by omega + simp [h0, hlt, hlt2] + refine ⟨OrderEmbedding.ofStrictMono f hf_sm, ?_⟩ + intro i j + change patQVal (2 * k + 1) (4 * k + 1) i.val < patQVal (2 * k + 1) (4 * k + 1) j.val ↔ + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (fVal i.val) < + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (fVal j.val) + have hi : i.val < (2 * k + 1) + (4 * k + 1) + 1 := i.isLt + have hj : j.val < (2 * k + 1) + (4 * k + 1) + 1 := j.isLt + have hfi : fVal i.val < (2 * k + 1) + (2 * k + 1) + 2 * k + 2 := (f i).isLt + have hfj : fVal j.val < (2 * k + 1) + (2 * k + 1) + 2 * k + 2 := (f j).isLt + have hfi1 : fVal i.val ≠ 1 := by dsimp only [fVal]; split_ifs <;> omega + have hfj1 : fVal j.val ≠ 1 := by dsimp only [fVal]; split_ifs <;> omega + rw [patQVal_lt_iff hi hj, patPVal_lt_iff_no1 hfi hfj hfi1 hfj1, hband i, hband j] + have hgt : j.val < i.val ↔ fVal j.val < fVal i.val := hf_sm.lt_iff_lt.symm + rw [hgt] + +theorem patQ_le_tau_leaderB (k : ℕ) : patQ (4 * k + 2) (2 * k) ≤ tau k := by + rw [le_iff_contains] + let f : Fin ((4 * k + 2) + (2 * k) + 1) → + Fin ((2 * k + 1) + (2 * k + 1) + 2 * k + 2) := fun i => ⟨i.val + 1, by omega⟩ + have hf_sm : StrictMono f := fun _ _ hab => Nat.add_lt_add_right hab 1 + have hband : ∀ i : Fin ((4 * k + 2) + (2 * k) + 1), + patPNo0Band (2 * k + 1) (2 * k + 1) (i.val + 1) = patQBand (4 * k + 2) i.val := by + intro i + dsimp only [patPNo0Band, patQBand] + split_ifs <;> omega + refine ⟨OrderEmbedding.ofStrictMono f hf_sm, ?_⟩ + intro i j + change patQVal (4 * k + 2) (2 * k) i.val < patQVal (4 * k + 2) (2 * k) j.val ↔ + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (i.val + 1) < + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (j.val + 1) + have hi : i.val < (4 * k + 2) + (2 * k) + 1 := i.isLt + have hj : j.val < (4 * k + 2) + (2 * k) + 1 := j.isLt + rw [patQVal_lt_iff hi hj, patPVal_lt_iff_no0 (by omega) (by omega) (by omega) (by omega), + hband i, hband j] + have hgt : j.val < i.val ↔ j.val + 1 < i.val + 1 := by omega + rw [hgt] + +theorem patQ_le_tau {k p q : ℕ} + (h : (p ≤ 2 * k + 1 ∧ q ≤ 4 * k + 1) ∨ (p ≤ 4 * k + 2 ∧ q ≤ 2 * k)) : + patQ p q ≤ tau k := by + rcases h with ⟨hp, hq⟩ | ⟨hp, hq⟩ + · exact (patQ_le_patQ hp hq).trans (patQ_le_tau_leaderA k) + · exact (patQ_le_patQ hp hq).trans (patQ_le_tau_leaderB k) + +theorem patD_le_tau {k l : ℕ} (hl : l ≤ 6 * k + 2) : patD l ≤ tau k := by + refine (patD_le_patD hl).trans ?_ + rw [le_iff_contains] + let f : Fin (6 * k + 2) → Fin ((2 * k + 1) + (2 * k + 1) + 2 * k + 2) := + fun i => ⟨i.val + 2, by omega⟩ + have hf_sm : StrictMono f := fun _ _ hab => Nat.add_lt_add_right hab 2 + refine ⟨OrderEmbedding.ofStrictMono f hf_sm, ?_⟩ + intro i j + change 6 * k + 2 - 1 - i.val < 6 * k + 2 - 1 - j.val ↔ + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (i.val + 2) < + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (j.val + 2) + have hi : i.val < 6 * k + 2 := i.isLt + have hj : j.val < 6 * k + 2 := j.isLt + rw [patPVal_lt_iff_tail (by omega) (by omega) (by omega) (by omega)] + omega + +/-! ### Complete Classification of `Downset (tau k)` -/ + +/-- Downward-closed subsets of `Fin m` are initial segments `{i | i.val < S.card}`. -/ +private theorem downward_closed_fin_iff {m : ℕ} (S : Finset (Fin m)) + (hdown : ∀ i j : Fin m, j < i → i ∈ S → j ∈ S) : + ∀ i : Fin m, i ∈ S ↔ i.val < S.card := by + intro i + constructor + · intro hi + have hsub : Finset.univ.filter (fun j : Fin m => j.val ≤ i.val) ⊆ S := by + intro j hj + rw [Finset.mem_filter] at hj + rcases eq_or_lt_of_le hj.2 with heq | hlt + · exact (Fin.ext heq) ▸ hi + · exact hdown i j hlt hi + have hcard : (Finset.univ.filter (fun j : Fin m => j.val ≤ i.val)).card = i.val + 1 := by + have hbij : (Finset.univ.filter (fun j : Fin m => j.val ≤ i.val)).card = + (Finset.range (i.val + 1)).card := by + refine Finset.card_bij (fun j _ => j.val) ?_ ?_ ?_ + · intro j hj; rw [Finset.mem_filter] at hj; rw [Finset.mem_range]; omega + · intro a _ b _ h; exact Fin.ext h + · intro r hr; rw [Finset.mem_range] at hr + refine ⟨⟨r, by omega⟩, ?_, rfl⟩ + rw [Finset.mem_filter]; exact ⟨Finset.mem_univ _, by dsimp; omega⟩ + rw [hbij, Finset.card_range] + have := Finset.card_le_card hsub + omega + · intro hlt + by_contra hni + have hsub : S ⊆ Finset.univ.filter (fun j : Fin m => j.val < i.val) := by + intro j hj + rw [Finset.mem_filter] + refine ⟨Finset.mem_univ _, ?_⟩ + by_contra hge + rcases eq_or_lt_of_le (Nat.le_of_not_lt hge) with heq | hgt + · exact hni ((Fin.ext heq) ▸ hj) + · exact hni (hdown j i hgt hj) + have hcard : (Finset.univ.filter (fun j : Fin m => j.val < i.val)).card = i.val := by + have hbij : (Finset.univ.filter (fun j : Fin m => j.val < i.val)).card = + (Finset.range i.val).card := by + refine Finset.card_bij (fun j _ => j.val) ?_ ?_ ?_ + · intro j hj; rw [Finset.mem_filter] at hj; rw [Finset.mem_range]; exact hj.2 + · intro a _ b _ h; exact Fin.ext h + · intro r hr; rw [Finset.mem_range] at hr + refine ⟨⟨r, lt_trans hr i.isLt⟩, ?_, rfl⟩ + rw [Finset.mem_filter]; exact ⟨Finset.mem_univ _, hr⟩ + rw [hbij, Finset.card_range] + have := Finset.card_le_card hsub + omega + +/-- Counting preimages of a half-open interval `[a, b)` under a strictly monotone map +`Fin m ↪o Fin n`. -/ +private theorem card_filter_lt_le {m n : ℕ} (f : Fin m ↪o Fin n) (a b : ℕ) (hab : a ≤ b) : + (Finset.univ.filter (fun i : Fin m => (f i).val < b)).card - + (Finset.univ.filter (fun i : Fin m => (f i).val < a)).card ≤ b - a := by + have hsub : Finset.univ.filter (fun i : Fin m => (f i).val < a) ⊆ + Finset.univ.filter (fun i : Fin m => (f i).val < b) := by + intro i hi + rw [Finset.mem_filter] at hi ⊢ + exact ⟨Finset.mem_univ _, lt_of_lt_of_le hi.2 hab⟩ + have hadd := Finset.card_sdiff_add_card_eq_card hsub + have hle : ((Finset.univ.filter (fun i : Fin m => (f i).val < b)) \ + (Finset.univ.filter (fun i : Fin m => (f i).val < a))).card ≤ + (Finset.Ico a b).card := by + refine Finset.card_le_card_of_injOn (fun i => (f i).val) ?_ ?_ + · intro i hi + simp only [Finset.mem_coe, Finset.mem_sdiff, Finset.mem_filter, Finset.mem_univ, + true_and, Finset.mem_Ico] at hi ⊢ + omega + · intro i _ j _ heq + exact f.injective (Fin.ext heq) + rw [Nat.card_Ico] at hle + omega + +/-- Complete classification of every pattern `π ≤ tau k` into valley patterns `P(x,y,z)`, +one-leader valley-free patterns `Q(p,q)`, and decreasing patterns `D(l)`. -/ +theorem downset_tau_classify {k : ℕ} {π : Perm} (h : π ≤ tau k) : + (∃ x y z : ℕ, x ≤ 2 * k + 1 ∧ y ≤ 2 * k + 1 ∧ z ≤ 2 * k ∧ + 1 ≤ x + y ∧ π = patP x y z) ∨ + (∃ p q : ℕ, 1 ≤ p ∧ + ((p ≤ 2 * k + 1 ∧ q ≤ 4 * k + 1) ∨ (p ≤ 4 * k + 2 ∧ q ≤ 2 * k)) ∧ + π = patQ p q) ∨ + (∃ l : ℕ, l ≤ 6 * k + 2 ∧ π = patD l) := by + rcases le_iff_contains.mp h with ⟨f, hf⟩ + have hthresh : ∀ (t : ℕ) (i : Fin π.len), + (f i).val < t ↔ + i.val < (Finset.univ.filter (fun j : Fin π.len => (f j).val < t)).card := by + intro t i + have hdown : ∀ a b : Fin π.len, b < a → + a ∈ Finset.univ.filter (fun j : Fin π.len => (f j).val < t) → + b ∈ Finset.univ.filter (fun j : Fin π.len => (f j).val < t) := by + intro a b hba ha + rw [Finset.mem_filter] at ha ⊢ + exact ⟨Finset.mem_univ _, Nat.lt_trans (f.strictMono hba) ha.2⟩ + simpa [Finset.mem_filter] using downward_closed_fin_iff _ hdown i + set c₁ := (Finset.univ.filter (fun i : Fin π.len => (f i).val < 2)).card + set c₂ := (Finset.univ.filter (fun i : Fin π.len => (f i).val < 2 * k + 3)).card + set c₃ := (Finset.univ.filter (fun i : Fin π.len => (f i).val < 4 * k + 4)).card + set c₄ := (Finset.univ.filter (fun i : Fin π.len => (f i).val < 6 * k + 4)).card + have hc₁_iff := hthresh 2 + have hc₂_iff := hthresh (2 * k + 3) + have hc₃_iff := hthresh (4 * k + 4) + have hc₄_eq : c₄ = π.len := by + have hall : Finset.univ.filter (fun i : Fin π.len => (f i).val < 6 * k + 4) = Finset.univ := by + ext i + simp only [Finset.mem_filter, Finset.mem_univ, true_and, iff_true] + have := (f i).isLt + change (f i).val < (2 * k + 1) + (2 * k + 1) + 2 * k + 2 at this + omega + simp [c₄, hall] + have hc1_le2 : c₁ ≤ 2 := by + have := card_filter_lt_le f 0 2 (by omega) + have h0 : (Finset.univ.filter (fun i : Fin π.len => (f i).val < 0)).card = 0 := by simp + omega + have hc1_le_c2 : c₁ ≤ c₂ := Finset.card_le_card (by + intro i hi; rw [Finset.mem_filter] at hi ⊢; exact ⟨Finset.mem_univ _, by omega⟩) + have hc2_le_c3 : c₂ ≤ c₃ := Finset.card_le_card (by + intro i hi; rw [Finset.mem_filter] at hi ⊢; exact ⟨Finset.mem_univ _, by omega⟩) + have hc3_le_len : c₃ ≤ π.len := by + rw [← hc₄_eq] + exact Finset.card_le_card (by + intro i hi; rw [Finset.mem_filter] at hi ⊢; exact ⟨Finset.mem_univ _, by omega⟩) + have hbandX : c₂ - c₁ ≤ 2 * k + 1 := by + have := card_filter_lt_le f 2 (2 * k + 3) (by omega); omega + have hbandY : c₃ - c₂ ≤ 2 * k + 1 := by + have := card_filter_lt_le f (2 * k + 3) (4 * k + 4) (by omega); omega + have hbandZ : π.len - c₃ ≤ 2 * k := by + have := card_filter_lt_le f (4 * k + 4) (6 * k + 4) (by omega); omega + have hf_lt : ∀ i : Fin π.len, (f i).val < (2 * k + 1) + (2 * k + 1) + 2 * k + 2 := + fun i => (f i).isLt + -- Case split on `c₁ ∈ {0, 1, 2}` + have hc1_cases : c₁ = 0 ∨ c₁ = 1 ∨ c₁ = 2 := by omega + rcases hc1_cases with hc1 | hc1 | hc1 + · -- Case `c₁ = 0`: neither leader kept → strictly decreasing `patD π.len` + right; right + refine ⟨π.len, by omega, ?_⟩ + apply Perm.eq_of_lt_iff (σ := π) (τ := patD π.len) rfl + intro i j + rw [hf i j] + have hfi : 2 ≤ (f i).val := by have := hc₁_iff i; omega + have hfj : 2 ≤ (f j).val := by have := hc₁_iff j; omega + change patPVal (2 * k + 1) (2 * k + 1) (2 * k) (f i).val < + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (f j).val ↔ + π.len - 1 - i.val < π.len - 1 - j.val + rw [patPVal_lt_iff_tail (hf_lt i) (hf_lt j) hfi hfj] + have hgt : j.val < i.val ↔ (f j).val < (f i).val := f.lt_iff_lt.symm + have hi_lt : i.val < π.len := i.isLt + have hj_lt : j.val < π.len := j.isLt + omega + · -- Case `c₁ = 1`: exactly one leader kept (`(f 0).val = 0` or `(f 0).val = 1`) + have hlen_pos : 0 < π.len := by omega + have hf0_lt2 : (f ⟨0, hlen_pos⟩).val < 2 := + (hc₁_iff ⟨0, hlen_pos⟩).mpr (by dsimp; omega) + have hf0_cases : (f ⟨0, hlen_pos⟩).val = 0 ∨ (f ⟨0, hlen_pos⟩).val = 1 := by omega + rcases hf0_cases with hf0 | hf0 + · -- Leader `a` kept (`f 0 = 0`, `1` not in range) + set p := c₂ - 1 + set q := π.len - c₂ + have hlen_eq : π.len = (patQ p q).len := by dsimp [patQ]; omega + have hno1 : ∀ i : Fin π.len, (f i).val ≠ 1 := by + intro i + by_cases hi0 : i.val = 0 + · have : i = ⟨0, hlen_pos⟩ := Fin.ext hi0; rw [this, hf0]; omega + · have := hc₁_iff i; omega + have hband : ∀ i : Fin π.len, + patPNo1Band (2 * k + 1) (f i).val = patQBand p i.val := by + intro i + have hi0 : i.val = 0 → (f i).val = 0 := fun hi => by + have : i = ⟨0, hlen_pos⟩ := Fin.ext hi; rw [this, hf0] + have hi_lt2 := hc₁_iff i + have hi_X := hc₂_iff i + unfold patPNo1Band patQBand + split_ifs <;> omega + have hpi : π = patQ p q := by + apply Perm.eq_of_lt_iff hlen_eq + intro i j + rw [hf i j] + change patPVal (2 * k + 1) (2 * k + 1) (2 * k) (f i).val < + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (f j).val ↔ + patQVal p q i.val < patQVal p q j.val + have hi_lt : i.val < p + q + 1 := by have := i.isLt; omega + have hj_lt : j.val < p + q + 1 := by have := j.isLt; omega + rw [patPVal_lt_iff_no1 (hf_lt i) (hf_lt j) (hno1 i) (hno1 j), + patQVal_lt_iff hi_lt hj_lt, hband i, hband j] + have hgt : (f j).val < (f i).val ↔ j.val < i.val := f.lt_iff_lt + rw [hgt] + by_cases hp0 : p = 0 + · right; right + refine ⟨q + 1, by omega, ?_⟩ + rw [hpi, hp0, patQ_zero] + · right; left + exact ⟨p, q, by omega, Or.inl ⟨by omega, by omega⟩, hpi⟩ + · -- Leader `b` kept (`f 0 = 1`, `0` not in range) + set p := c₃ - 1 + set q := π.len - c₃ + have hlen_eq : π.len = (patQ p q).len := by dsimp [patQ]; omega + have hno0 : ∀ i : Fin π.len, (f i).val ≠ 0 := by + intro i + by_cases hi0 : i.val = 0 + · have : i = ⟨0, hlen_pos⟩ := Fin.ext hi0; rw [this, hf0]; omega + · have := hc₁_iff i; omega + have hband : ∀ i : Fin π.len, + patPNo0Band (2 * k + 1) (2 * k + 1) (f i).val = patQBand p i.val := by + intro i + have hi0 : i.val = 0 → (f i).val = 1 := fun hi => by + have : i = ⟨0, hlen_pos⟩ := Fin.ext hi; rw [this, hf0] + have hi_lt2 := hc₁_iff i + have hi_Y := hc₃_iff i + unfold patPNo0Band patQBand + split_ifs <;> omega + have hpi : π = patQ p q := by + apply Perm.eq_of_lt_iff hlen_eq + intro i j + rw [hf i j] + change patPVal (2 * k + 1) (2 * k + 1) (2 * k) (f i).val < + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (f j).val ↔ + patQVal p q i.val < patQVal p q j.val + have hi_lt : i.val < p + q + 1 := by have := i.isLt; omega + have hj_lt : j.val < p + q + 1 := by have := j.isLt; omega + rw [patPVal_lt_iff_no0 (hf_lt i) (hf_lt j) (hno0 i) (hno0 j), + patQVal_lt_iff hi_lt hj_lt, hband i, hband j] + have hgt : (f j).val < (f i).val ↔ j.val < i.val := f.lt_iff_lt + rw [hgt] + by_cases hp0 : p = 0 + · right; right + refine ⟨q + 1, by omega, ?_⟩ + rw [hpi, hp0, patQ_zero] + · right; left + exact ⟨p, q, by omega, Or.inr ⟨by omega, by omega⟩, hpi⟩ + · -- Case `c₁ = 2`: both leaders kept (`f 0 = 0`, `f 1 = 1`) + have hlen_ge2 : 2 ≤ π.len := by omega + have hf0_lt2 : (f ⟨0, by omega⟩).val < 2 := + (hc₁_iff ⟨0, by omega⟩).mpr (by dsimp; omega) + have hf1_lt2 : (f ⟨1, by omega⟩).val < 2 := + (hc₁_iff ⟨1, by omega⟩).mpr (by dsimp; omega) + have hf01 : (f ⟨0, by omega⟩).val < (f ⟨1, by omega⟩).val := + f.strictMono (show (⟨0, by omega⟩ : Fin π.len) < ⟨1, by omega⟩ from Nat.zero_lt_one) + have hf0 : (f ⟨0, by omega⟩).val = 0 := by omega + have hf1 : (f ⟨1, by omega⟩).val = 1 := by omega + set x := c₂ - 2 + set y := c₃ - c₂ + set z := π.len - c₃ + have hlen_eq : π.len = (patP x y z).len := by dsimp [patP]; omega + have hband : ∀ i : Fin π.len, + patPBand (2 * k + 1) (2 * k + 1) (f i).val = patPBand x y i.val := by + intro i + have hi0 : i.val = 0 → (f i).val = 0 := fun hi => by + have : i = ⟨0, by omega⟩ := Fin.ext hi; rw [this, hf0] + have hi1 : i.val = 1 → (f i).val = 1 := fun hi => by + have : i = ⟨1, by omega⟩ := Fin.ext hi; rw [this, hf1] + have hi_lt2 := hc₁_iff i + have hi_X := hc₂_iff i + have hi_Y := hc₃_iff i + unfold patPBand + split_ifs <;> omega + have hpi : π = patP x y z := by + apply Perm.eq_of_lt_iff hlen_eq + intro i j + rw [hf i j] + change patPVal (2 * k + 1) (2 * k + 1) (2 * k) (f i).val < + patPVal (2 * k + 1) (2 * k + 1) (2 * k) (f j).val ↔ + patPVal x y z i.val < patPVal x y z j.val + have hi_lt : i.val < x + y + z + 2 := by have := i.isLt; omega + have hj_lt : j.val < x + y + z + 2 := by have := j.isLt; omega + rw [patPVal_lt_iff (hf_lt i) (hf_lt j), patPVal_lt_iff hi_lt hj_lt, hband i, hband j] + have hgt : (f j).val < (f i).val ↔ j.val < i.val := f.lt_iff_lt + rw [hgt] + by_cases hxy : 1 ≤ x + y + · left + exact ⟨x, y, z, by omega, by omega, by omega, hxy, hpi⟩ + · right; right + have hx0 : x = 0 := by omega + have hy0 : y = 0 := by omega + refine ⟨z + 2, by omega, ?_⟩ + rw [hpi, hx0, hy0, patP_zero_zero] + +/-! ### Exact Width of `Downset (tau k)`: Antichain + Matching Chain Cover -/ + +/-- The explicit antichain of size `3k^2 + 9k + 5` inside `Downset (tau k)`: +the `3k^2 + 5k + 2` middle-slice valley patterns of length `3k + 3`, together with +all `4k + 3` valley-free patterns of length `4k + 3`. -/ +def familyAntichain (k : ℕ) : Finset Perm := + (boxSlice k (3 * k + 1)).image (fun t => patP t.1 t.2.1 t.2.2) ∪ + (insert (patD (4 * k + 3)) + ((Finset.Icc 1 (4 * k + 2)).image (fun p => patQ p (4 * k + 2 - p)))) + +theorem familyAntichain_subset (k : ℕ) (hk : 1 ≤ k) : + familyAntichain k ⊆ Downset (tau k) := by + intro π hπ + rw [mem_downset_iff] + unfold familyAntichain at hπ + rcases Finset.mem_union.mp hπ with hval | hvf + · rcases Finset.mem_image.mp hval with ⟨t, ht, rfl⟩ + rw [mem_boxSlice] at ht + exact patP_le_tau ht.1 ht.2.1 ht.2.2.1 + · rcases Finset.mem_insert.mp hvf with rfl | hq + · exact patD_le_tau (by omega) + · rcases Finset.mem_image.mp hq with ⟨p, hp, rfl⟩ + rw [Finset.mem_Icc] at hp + by_cases hple : p ≤ 2 * k + 1 + · exact patQ_le_tau (Or.inl ⟨hple, by omega⟩) + · exact patQ_le_tau (Or.inr ⟨hp.2, by omega⟩) + +theorem familyAntichain_isAntichain (k : ℕ) (hk : 1 ≤ k) : + IsAntichain (familyAntichain k) := by + intro x hx y hy hxy + unfold familyAntichain at hx hy + rcases Finset.mem_union.mp hx with hxV | hxVF <;> + rcases Finset.mem_union.mp hy with hyV | hyVF + · -- both valley patterns of length `3k + 3` + rcases Finset.mem_image.mp hxV with ⟨tx, htx, rfl⟩ + rcases Finset.mem_image.mp hyV with ⟨ty, hty, rfl⟩ + rw [mem_boxSlice] at htx hty + exact eq_of_le_of_len_eq hxy (by dsimp [patP]; omega) + · -- valley pattern ≤ valley-free pattern: impossible by `hasValley_mono` + exfalso + rcases Finset.mem_image.mp hxV with ⟨tx, htx, rfl⟩ + rw [mem_boxSlice] at htx + have hval : HasValley (patP tx.1 tx.2.1 tx.2.2) := patP_hasValley (by omega) + have hval_y : HasValley y := hasValley_mono hval hxy + rcases Finset.mem_insert.mp hyVF with rfl | hq + · exact patD_not_hasValley _ hval_y + · rcases Finset.mem_image.mp hq with ⟨p, _, rfl⟩ + exact patQ_not_hasValley _ _ hval_y + · -- valley-free of length `4k + 3` ≤ valley of length `3k + 3`: impossible by length + exfalso + rcases Finset.mem_image.mp hyV with ⟨ty, hty, rfl⟩ + rw [mem_boxSlice] at hty + have hlen_le := le_len_le hxy + have hlen_x : x.len = 4 * k + 3 := by + rcases Finset.mem_insert.mp hxVF with rfl | hq + · rfl + · rcases Finset.mem_image.mp hq with ⟨p, hp, rfl⟩ + rw [Finset.mem_Icc] at hp + dsimp [patQ]; omega + have hlen_y : (patP ty.1 ty.2.1 ty.2.2).len = 3 * k + 3 := by dsimp [patP]; omega + omega + · -- both valley-free of length `4k + 3` + have hlen_x : x.len = 4 * k + 3 := by + rcases Finset.mem_insert.mp hxVF with rfl | hq + · rfl + · rcases Finset.mem_image.mp hq with ⟨p, hp, rfl⟩ + rw [Finset.mem_Icc] at hp + dsimp [patQ]; omega + have hlen_y : y.len = 4 * k + 3 := by + rcases Finset.mem_insert.mp hyVF with rfl | hq + · rfl + · rcases Finset.mem_image.mp hq with ⟨p, hp, rfl⟩ + rw [Finset.mem_Icc] at hp + dsimp [patQ]; omega + exact eq_of_le_of_len_eq hxy (hlen_x.trans hlen_y.symm) + +theorem familyAntichain_card (k : ℕ) (_hk : 1 ≤ k) : + (familyAntichain k).card = 3 * k ^ 2 + 9 * k + 5 := by + unfold familyAntichain + have hdisj : Disjoint + ((boxSlice k (3 * k + 1)).image (fun t => patP t.1 t.2.1 t.2.2)) + (insert (patD (4 * k + 3)) + ((Finset.Icc 1 (4 * k + 2)).image (fun p => patQ p (4 * k + 2 - p)))) := by + rw [Finset.disjoint_left] + intro x hxV hxVF + rcases Finset.mem_image.mp hxV with ⟨t, ht, rfl⟩ + rw [mem_boxSlice] at ht + rcases Finset.mem_insert.mp hxVF with heq | hq + · exact patP_ne_patD (by omega) heq + · rcases Finset.mem_image.mp hq with ⟨p, _, heq⟩ + exact patP_ne_patQ (by omega) heq.symm + rw [Finset.card_union_of_disjoint hdisj] + have hcard1 : ((boxSlice k (3 * k + 1)).image (fun t => patP t.1 t.2.1 t.2.2)).card = + 3 * k ^ 2 + 5 * k + 2 := by + rw [Finset.card_image_of_injective _ (fun a b h => by + have := patP_injective h + rcases a with ⟨x₁, y₁, z₁⟩; rcases b with ⟨x₂, y₂, z₂⟩ + simp only at this + exact Prod.ext this.1 (Prod.ext this.2.1 this.2.2)), boxSlice_mid_card] + have hnotmem : patD (4 * k + 3) ∉ + (Finset.Icc 1 (4 * k + 2)).image (fun p => patQ p (4 * k + 2 - p)) := by + intro hm + rcases Finset.mem_image.mp hm with ⟨p, hp, heq⟩ + rw [Finset.mem_Icc] at hp + exact patQ_ne_patD hp.1 heq + rw [Finset.card_insert_of_notMem hnotmem] + have hcard2 : ((Finset.Icc 1 (4 * k + 2)).image (fun p => patQ p (4 * k + 2 - p))).card = + 4 * k + 2 := by + rw [Finset.card_image_of_injOn (fun p₁ _ p₂ _ h => (patQ_injective h).1)] + simp [Nat.card_Icc] + rw [hcard1, hcard2] + omega + +/-- Index type for the matching cover of `Downset (tau k)` by `3k^2 + 9k + 5` chains. -/ +inductive ChainIdx where + /-- Symmetric chain in `Box(k)` identified by `(d₁, d₂)`. -/ + | box (id : ℕ × ℕ) + /-- Chain of strictly decreasing patterns `D(l)`. -/ + | dec + /-- Chain of one-leader patterns `Q(p, q)` with fixed `p`. -/ + | qFixedP (p : ℕ) + /-- Chain of one-leader patterns `Q(p, q)` with fixed `q`. -/ + | qFixedQ (q : ℕ) + deriving DecidableEq + +/-- The `3k^2 + 9k + 5` chain indices covering `Downset (tau k)`. -/ +def familyChainIndices (k : ℕ) : Finset ChainIdx := + ((boxFinset k).image (boxId k)).image ChainIdx.box ∪ + (insert ChainIdx.dec + (((Finset.Icc 1 (2 * k + 1)).image ChainIdx.qFixedP) ∪ + ((Finset.range (2 * k + 1)).image ChainIdx.qFixedQ))) + +/-- The chain of permutations corresponding to each `ChainIdx`. -/ +def familyChain (k : ℕ) : ChainIdx → Finset Perm + | ChainIdx.box id => + ((boxFinset k).filter (fun t => boxId k t = id)).image (fun t => patP t.1 t.2.1 t.2.2) + | ChainIdx.dec => + (Finset.range (6 * k + 3)).image patD + | ChainIdx.qFixedP p => + (Finset.range (4 * k + 2)).image (fun q => patQ p q) + | ChainIdx.qFixedQ q => + (Finset.Icc (2 * k + 2) (4 * k + 2)).image (fun p => patQ p q) + +theorem familyChain_isChain (k : ℕ) (idx : ChainIdx) : IsChain (familyChain k idx) := by + cases idx with + | box id => + intro x hx y hy + rcases Finset.mem_image.mp hx with ⟨tx, htx, rfl⟩ + rcases Finset.mem_image.mp hy with ⟨ty, hty, rfl⟩ + rw [Finset.mem_filter] at htx hty + rcases box_chain_comparable htx.1 hty.1 (htx.2.trans hty.2.symm) with hle | hle + · exact Or.inl (patP_le_patP hle.1 hle.2.1 hle.2.2) + · exact Or.inr (patP_le_patP hle.1 hle.2.1 hle.2.2) + | dec => + intro x hx y hy + rcases Finset.mem_image.mp hx with ⟨lx, _, rfl⟩ + rcases Finset.mem_image.mp hy with ⟨ly, _, rfl⟩ + rcases le_total lx ly with hle | hle + · exact Or.inl (patD_le_patD hle) + · exact Or.inr (patD_le_patD hle) + | qFixedP p => + intro x hx y hy + rcases Finset.mem_image.mp hx with ⟨qx, _, rfl⟩ + rcases Finset.mem_image.mp hy with ⟨qy, _, rfl⟩ + rcases le_total qx qy with hle | hle + · exact Or.inl (patQ_le_patQ (le_refl p) hle) + · exact Or.inr (patQ_le_patQ (le_refl p) hle) + | qFixedQ q => + intro x hx y hy + rcases Finset.mem_image.mp hx with ⟨px, _, rfl⟩ + rcases Finset.mem_image.mp hy with ⟨py, _, rfl⟩ + rcases le_total px py with hle | hle + · exact Or.inl (patQ_le_patQ hle (le_refl q)) + · exact Or.inr (patQ_le_patQ hle (le_refl q)) + +theorem familyChain_covers (k : ℕ) : + ∀ π ∈ Downset (tau k), ∃ idx ∈ familyChainIndices k, π ∈ familyChain k idx := by + intro π hπ + rw [mem_downset_iff] at hπ + rcases downset_tau_classify hπ with + ⟨x, y, z, hx, hy, hz, _, rfl⟩ | ⟨p, q, hp1, hbounds, rfl⟩ | ⟨l, hl, rfl⟩ + · have ht : (x, y, z) ∈ boxFinset k := mem_boxFinset.mpr ⟨hx, hy, hz⟩ + refine ⟨ChainIdx.box (boxId k (x, y, z)), ?_, ?_⟩ + · unfold familyChainIndices + exact Finset.mem_union_left _ (Finset.mem_image_of_mem _ (Finset.mem_image_of_mem _ ht)) + · exact Finset.mem_image.mpr ⟨(x, y, z), Finset.mem_filter.mpr ⟨ht, rfl⟩, rfl⟩ + · by_cases hple : p ≤ 2 * k + 1 + · have hq : q ≤ 4 * k + 1 := by rcases hbounds with ⟨_, hq⟩ | ⟨_, hq⟩ <;> omega + refine ⟨ChainIdx.qFixedP p, ?_, ?_⟩ + · unfold familyChainIndices + refine Finset.mem_union_right _ (Finset.mem_insert_of_mem (Finset.mem_union_left _ ?_)) + exact Finset.mem_image_of_mem _ (Finset.mem_Icc.mpr ⟨hp1, hple⟩) + · exact Finset.mem_image.mpr ⟨q, Finset.mem_range.mpr (by omega), rfl⟩ + · have hpq : p ≤ 4 * k + 2 ∧ q ≤ 2 * k := by + rcases hbounds with ⟨hp, _⟩ | h2 + · omega + · exact h2 + refine ⟨ChainIdx.qFixedQ q, ?_, ?_⟩ + · unfold familyChainIndices + refine Finset.mem_union_right _ (Finset.mem_insert_of_mem (Finset.mem_union_right _ ?_)) + exact Finset.mem_image_of_mem _ (Finset.mem_range.mpr (by omega)) + · exact Finset.mem_image.mpr ⟨p, Finset.mem_Icc.mpr ⟨by omega, hpq.1⟩, rfl⟩ + · refine ⟨ChainIdx.dec, ?_, ?_⟩ + · unfold familyChainIndices + exact Finset.mem_union_right _ (Finset.mem_insert_self _ _) + · exact Finset.mem_image.mpr ⟨l, Finset.mem_range.mpr (by omega), rfl⟩ + +theorem familyChainIndices_card (k : ℕ) : + (familyChainIndices k).card = 3 * k ^ 2 + 9 * k + 5 := by + unfold familyChainIndices + have hd1 : Disjoint + (((boxFinset k).image (boxId k)).image ChainIdx.box) + (insert ChainIdx.dec + (((Finset.Icc 1 (2 * k + 1)).image ChainIdx.qFixedP) ∪ + ((Finset.range (2 * k + 1)).image ChainIdx.qFixedQ))) := by + rw [Finset.disjoint_left] + intro x hx1 hx2 + rcases Finset.mem_image.mp hx1 with ⟨_, _, rfl⟩ + rcases Finset.mem_insert.mp hx2 with h | hx3 + · exact ChainIdx.noConfusion h + · rcases Finset.mem_union.mp hx3 with hp | hq + · rcases Finset.mem_image.mp hp with ⟨_, _, h⟩; exact ChainIdx.noConfusion h + · rcases Finset.mem_image.mp hq with ⟨_, _, h⟩; exact ChainIdx.noConfusion h + have hndec : ChainIdx.dec ∉ + (((Finset.Icc 1 (2 * k + 1)).image ChainIdx.qFixedP) ∪ + ((Finset.range (2 * k + 1)).image ChainIdx.qFixedQ)) := by + intro hm + rcases Finset.mem_union.mp hm with hp | hq + · rcases Finset.mem_image.mp hp with ⟨_, _, h⟩; exact ChainIdx.noConfusion h + · rcases Finset.mem_image.mp hq with ⟨_, _, h⟩; exact ChainIdx.noConfusion h + have hd2 : Disjoint + ((Finset.Icc 1 (2 * k + 1)).image ChainIdx.qFixedP) + ((Finset.range (2 * k + 1)).image ChainIdx.qFixedQ) := by + rw [Finset.disjoint_left] + intro x hp hq + rcases Finset.mem_image.mp hp with ⟨_, _, rfl⟩ + rcases Finset.mem_image.mp hq with ⟨_, _, h⟩ + exact ChainIdx.noConfusion h + rw [Finset.card_union_of_disjoint hd1, Finset.card_insert_of_notMem hndec, + Finset.card_union_of_disjoint hd2] + rw [Finset.card_image_of_injective _ (fun _ _ h => ChainIdx.box.inj h), boxId_image_card_eq] + rw [Finset.card_image_of_injective _ (fun _ _ h => ChainIdx.qFixedP.inj h)] + rw [Finset.card_image_of_injective _ (fun _ _ h => ChainIdx.qFixedQ.inj h)] + simp [Nat.card_Icc] + omega + +/-- Exact width of `Downset (tau k)`: `3k^2 + 9k + 5` for all `k ≥ 1`. -/ +theorem family_width (k : ℕ) (hk : 1 ≤ k) : + width (Downset (tau k)) = 3 * k ^ 2 + 9 * k + 5 := by + apply le_antisymm + · calc + width (Downset (tau k)) ≤ (familyChainIndices k).card := + width_le_of_indexed_chain_cover (fun idx _ => familyChain_isChain k idx) + (familyChain_covers k) + _ = 3 * k ^ 2 + 9 * k + 5 := familyChainIndices_card k + · calc + 3 * k ^ 2 + 9 * k + 5 = (familyAntichain k).card := (familyAntichain_card k hk).symm + _ ≤ width (Downset (tau k)) := + card_le_width_of_antichain (familyAntichain_subset k hk) + (familyAntichain_isAntichain k hk) + +/-! ### Exact Largest Rank of `Downset (tau k)`: `3k^2 + 8k + 5` -/ + +/-- Upper bound on every rank level of `Downset (tau k)`: at most `3k^2 + 8k + 5`. -/ +theorem family_rankLevel_card_le (k : ℕ) (hk : 1 ≤ k) (l : ℕ) : + (RankLevel (Downset (tau k)) l).card ≤ 3 * k ^ 2 + 8 * k + 5 := by + by_cases hl0 : l = 0 + · subst hl0 + have hsub : RankLevel (Downset (tau k)) 0 ⊆ {patD 0} := by + intro π hπ + rw [RankLevel, Finset.mem_filter, mem_downset_iff] at hπ + rw [Finset.mem_singleton] + apply Perm.ext_val hπ.2 + intro i + exact absurd i.isLt (by omega) + calc + (RankLevel (Downset (tau k)) 0).card ≤ ({patD 0} : Finset Perm).card := + Finset.card_le_card hsub + _ = 1 := Finset.card_singleton _ + _ ≤ 3 * k ^ 2 + 8 * k + 5 := by omega + · by_cases hl1 : l = 1 + · subst hl1 + have hsub : RankLevel (Downset (tau k)) 1 ⊆ {patD 1} := by + intro π hπ + rw [RankLevel, Finset.mem_filter, mem_downset_iff] at hπ + rw [Finset.mem_singleton] + apply Perm.ext_val hπ.2 + intro i + have hi0 : i.val = 0 := by omega + have hpi0 : (π.perm i).val = 0 := by have := (π.perm i).isLt; omega + change (π.perm i).val = 1 - 1 - i.val + omega + calc + (RankLevel (Downset (tau k)) 1).card ≤ ({patD 1} : Finset Perm).card := + Finset.card_le_card hsub + _ = 1 := Finset.card_singleton _ + _ ≤ 3 * k ^ 2 + 8 * k + 5 := by omega + · -- General case `l ≥ 2` + have hl2 : 2 ≤ l := by omega + let V : Finset Perm := (boxSlice k (l - 2)).image (fun t => patP t.1 t.2.1 t.2.2) + let Q : Finset Perm := + (Finset.Icc 1 (min (l - 1) (4 * k + 2))).image (fun p => patQ p (l - 1 - p)) + let VF : Finset Perm := insert (patD l) Q + have hsub : RankLevel (Downset (tau k)) l ⊆ V ∪ VF := by + intro π hπ + rw [RankLevel, Finset.mem_filter, mem_downset_iff] at hπ + rcases hπ with ⟨hle, hlen⟩ + rcases downset_tau_classify hle with + ⟨x, y, z, hx, hy, hz, _, rfl⟩ | ⟨p, q, hp1, hbounds, rfl⟩ | ⟨l', _, rfl⟩ + · apply Finset.mem_union_left + refine Finset.mem_image.mpr ⟨(x, y, z), ?_, rfl⟩ + rw [mem_boxSlice] + change x + y + z + 2 = l at hlen + dsimp + exact ⟨hx, hy, hz, by omega⟩ + · apply Finset.mem_union_right + apply Finset.mem_insert_of_mem + refine Finset.mem_image.mpr ⟨p, ?_, ?_⟩ + · rw [Finset.mem_Icc] + change p + q + 1 = l at hlen + have hpmax : p ≤ 4 * k + 2 := by + rcases hbounds with ⟨hp, _⟩ | ⟨hp, _⟩ <;> omega + omega + · change p + q + 1 = l at hlen + have hq : l - 1 - p = q := by omega + rw [hq] + · apply Finset.mem_union_right + change l' = l at hlen + rw [hlen] + exact Finset.mem_insert_self _ _ + have hcard_V : V.card ≤ (boxSlice k (l - 2)).card := Finset.card_image_le + have hcard_VF : VF.card ≤ min l (4 * k + 3) := by + calc + VF.card ≤ Q.card + 1 := Finset.card_insert_le _ _ + _ ≤ (Finset.Icc 1 (min (l - 1) (4 * k + 2))).card + 1 := + Nat.add_le_add_right Finset.card_image_le 1 + _ = min l (4 * k + 3) := by simp [Nat.card_Icc]; omega + have htotal : (RankLevel (Downset (tau k)) l).card ≤ + (boxSlice k (l - 2)).card + min l (4 * k + 3) := by + calc + (RankLevel (Downset (tau k)) l).card ≤ (V ∪ VF).card := Finset.card_le_card hsub + _ ≤ V.card + VF.card := Finset.card_union_le _ _ + _ ≤ (boxSlice k (l - 2)).card + min l (4 * k + 3) := + Nat.add_le_add hcard_V hcard_VF + -- Three-case bound on `B(l - 2) + min(l, 4k + 3)` + by_cases hc1 : l ≤ 3 * k + 3 + · have hB : (boxSlice k (l - 2)).card ≤ 3 * k ^ 2 + 5 * k + 2 := by + rw [← boxSlice_mid_card k] + exact boxSlice_card_le_mid k (l - 2) + omega + · by_cases hc2 : l ≤ 4 * k + 3 + · set t := l - (3 * k + 3) + have ht1 : 1 ≤ t := by omega + have htk : t ≤ k := by omega + have hl_eq : l - 2 = 3 * k + 1 + t := by omega + have hB : (boxSlice k (l - 2)).card = 3 * k ^ 2 + 5 * k + 2 - t ^ 2 := by + rw [hl_eq] + exact boxSlice_card k t htk + have ht_le_sq : t ≤ t ^ 2 := by nlinarith + have hsq_le : t ^ 2 ≤ 3 * k ^ 2 + 5 * k + 2 := by nlinarith + omega + · -- `l > 4k + 3`, so `l - 2 ≥ 4k + 2 ≥ 4k + 1` + have hB1 : (boxSlice k (l - 2)).card ≤ (boxSlice k (4 * k + 1)).card := + boxSlice_card_antitone (by omega) (by omega) + have hB2 : (boxSlice k (4 * k + 1)).card = 3 * k ^ 2 + 5 * k + 2 - k ^ 2 := by + have : 4 * k + 1 = 3 * k + 1 + k := by omega + rw [this] + exact boxSlice_card k k (le_refl k) + have hk_le_sq : k ≤ k ^ 2 := by nlinarith + have hsq_le : k ^ 2 ≤ 3 * k ^ 2 + 5 * k + 2 := by nlinarith + omega + +/-- Exact size of rank `3k + 3` in `Downset (tau k)`: `3k^2 + 8k + 5`. -/ +theorem family_rankLevel_mid_card (k : ℕ) (hk : 1 ≤ k) : + (RankLevel (Downset (tau k)) (3 * k + 3)).card = 3 * k ^ 2 + 8 * k + 5 := by + apply le_antisymm (family_rankLevel_card_le k hk (3 * k + 3)) + let M : Finset Perm := + (boxSlice k (3 * k + 1)).image (fun t => patP t.1 t.2.1 t.2.2) ∪ + (insert (patD (3 * k + 3)) + ((Finset.Icc 1 (3 * k + 2)).image (fun p => patQ p (3 * k + 2 - p)))) + have hsub : M ⊆ RankLevel (Downset (tau k)) (3 * k + 3) := by + intro π hπ + rw [RankLevel, Finset.mem_filter, mem_downset_iff] + rcases Finset.mem_union.mp hπ with hval | hvf + · rcases Finset.mem_image.mp hval with ⟨t, ht, rfl⟩ + rw [mem_boxSlice] at ht + refine ⟨patP_le_tau ht.1 ht.2.1 ht.2.2.1, ?_⟩ + change t.1 + t.2.1 + t.2.2 + 2 = 3 * k + 3 + omega + · rcases Finset.mem_insert.mp hvf with rfl | hq + · exact ⟨patD_le_tau (by omega), rfl⟩ + · rcases Finset.mem_image.mp hq with ⟨p, hp, rfl⟩ + rw [Finset.mem_Icc] at hp + constructor + · by_cases hple : p ≤ 2 * k + 1 + · exact patQ_le_tau (Or.inl ⟨hple, by omega⟩) + · exact patQ_le_tau (Or.inr ⟨by omega, by omega⟩) + · dsimp [patQ]; omega + have hcard : M.card = 3 * k ^ 2 + 8 * k + 5 := by + dsimp only [M] + have hdisj : Disjoint + ((boxSlice k (3 * k + 1)).image (fun t => patP t.1 t.2.1 t.2.2)) + (insert (patD (3 * k + 3)) + ((Finset.Icc 1 (3 * k + 2)).image (fun p => patQ p (3 * k + 2 - p)))) := by + rw [Finset.disjoint_left] + intro x hxV hxVF + rcases Finset.mem_image.mp hxV with ⟨t, ht, rfl⟩ + rw [mem_boxSlice] at ht + rcases Finset.mem_insert.mp hxVF with heq | hq + · exact patP_ne_patD (by omega) heq + · rcases Finset.mem_image.mp hq with ⟨p, _, heq⟩ + exact patP_ne_patQ (by omega) heq.symm + rw [Finset.card_union_of_disjoint hdisj] + have hcard1 : ((boxSlice k (3 * k + 1)).image (fun t => patP t.1 t.2.1 t.2.2)).card = + 3 * k ^ 2 + 5 * k + 2 := by + rw [Finset.card_image_of_injective _ (fun a b h => by + have := patP_injective h + rcases a with ⟨x₁, y₁, z₁⟩; rcases b with ⟨x₂, y₂, z₂⟩ + simp only at this + exact Prod.ext this.1 (Prod.ext this.2.1 this.2.2)), boxSlice_mid_card] + have hnotmem : patD (3 * k + 3) ∉ + (Finset.Icc 1 (3 * k + 2)).image (fun p => patQ p (3 * k + 2 - p)) := by + intro hm + rcases Finset.mem_image.mp hm with ⟨p, hp, heq⟩ + rw [Finset.mem_Icc] at hp + exact patQ_ne_patD hp.1 heq + rw [Finset.card_insert_of_notMem hnotmem] + have hcard2 : ((Finset.Icc 1 (3 * k + 2)).image (fun p => patQ p (3 * k + 2 - p))).card = + 3 * k + 2 := by + rw [Finset.card_image_of_injOn (fun p₁ _ p₂ _ h => (patQ_injective h).1)] + simp [Nat.card_Icc] + rw [hcard1, hcard2] + omega + rw [← hcard] + exact Finset.card_le_card hsub + +/-- Exact largest rank of `Downset (tau k)`: `3k^2 + 8k + 5` for all `k ≥ 1`. -/ +theorem family_largestRank (k : ℕ) (hk : 1 ≤ k) : + largestRank (Downset (tau k)) = 3 * k ^ 2 + 8 * k + 5 := + largestRank_eq_of_bounds (family_rankLevel_card_le k hk) + (le_of_eq (family_rankLevel_mid_card k hk).symm) + +/-- **Main Theorem (Exact Sperner Deficiency `k`)**: For every `k ≥ 1`, the principal downset +`Downset (tau k)` of the permutation `tau k` of length `6k + 4` has exact Sperner deficiency `k`: +`width (Downset (tau k)) = largestRank (Downset (tau k)) + k`. -/ +theorem family_exact_deficiency (k : ℕ) (hk : 1 ≤ k) : + width (Downset (tau k)) = largestRank (Downset (tau k)) + k := by + rw [family_width k hk, family_largestRank k hk] + omega + +/-- Every member of the infinite family `tau k` (`k ≥ 1`) has a non-Sperner principal downset. -/ +theorem family_not_sperner (k : ℕ) (hk : 1 ≤ k) : + ¬ IsSperner (Downset (tau k)) := by + unfold IsSperner + rw [family_exact_deficiency k hk] + omega + +end PatternPoset diff --git a/LeanPool/PatternPosetNotSperner/Imports.lean b/LeanPool/PatternPosetNotSperner/Imports.lean new file mode 100644 index 0000000000..9cb0c9eace --- /dev/null +++ b/LeanPool/PatternPosetNotSperner/Imports.lean @@ -0,0 +1,13 @@ +/- +Copyright (c) 2026 Lean Pool contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Lean Pool contributors +-/ +module -- shake: keep-all --deprecated_module: ignore + +-- Generated project imports; run `lake exe mk_all`. +public import LeanPool.PatternPosetNotSperner +public import LeanPool.PatternPosetNotSperner.BoxChains +public import LeanPool.PatternPosetNotSperner.Defs +public import LeanPool.PatternPosetNotSperner.Family +public import LeanPool.PatternPosetNotSperner.SevenPoint diff --git a/LeanPool/PatternPosetNotSperner/SevenPoint.lean b/LeanPool/PatternPosetNotSperner/SevenPoint.lean new file mode 100644 index 0000000000..16b2ff466a --- /dev/null +++ b/LeanPool/PatternPosetNotSperner/SevenPoint.lean @@ -0,0 +1,627 @@ +/- +Copyright (c) 2026 Tyler B. Hughes. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Tyler B. Hughes +-/ + +-- Modified for Lean Pool: Lean 4.36 module and import port with style and linter fixes. + +module + +public import Mathlib.Data.Fin.VecNotation +public import LeanPool.PatternPosetNotSperner.Defs + +import Mathlib.Tactic.FinCases +import Mathlib.Tactic.Tauto + +/-! +# The Seven-Entry Counterexample `[213, 2574613]` to McNamara–Steingrímsson Question 9.5 + +Disproves McNamara–Steingrímsson (2015) Question 9.5 ("Are all intervals in the +classical permutation pattern poset Sperner?") via the explicit 7-entry interval +`[σ₇, τ₇] = [213, 2574613]`: +- `sigma7_le_tau7 : σ₇ ≤ τ₇` +- `interval7_card : (Interval σ₇ τ₇).card = 19` (genuinely proved equal to the 19-member set + from the true definition `Interval σ₇ τ₇`, checking all `2^7 = 128` subsequences in-kernel) +- `interval7_rank_sizes`: exact rank sizes `1, 3, 7, 7, 1` for ranks `3, 4, 5, 6, 7` + and `0` elsewhere, giving `interval7_largestRank : largestRank (Interval σ₇ τ₇) = 7` +- `interval7_width : width (Interval σ₇ τ₇) = 8` via the explicit 8-element antichain + `{13524, 14352, 24351, 35241, 43512, 246513, 256413, 264513}` and an explicit 8-chain cover +- `not_sperner_interval7 : ¬ IsSperner (Interval σ₇ τ₇)` +- `mcnamara_steingrimsson_Q9_5_false` : + `∃ σ τ : Perm, σ ≤ τ ∧ ¬ IsSperner (Interval σ τ)` +-/ + +@[expose] public section + +namespace PatternPoset + +/-! ### Bitmask Standardization Bridge (100% In-Kernel, Zero `native_decide`) -/ + +/-- Computable inverse on `Fin n` by linear search. -/ +def invFin {n : ℕ} (f : Fin n → Fin n) (y : Fin n) : Fin n := + match (List.finRange n).find? (fun x => decide (f x = y)) with + | some x => x + | none => y + +/-- Construct a `Perm` from a concrete function `Fin n → Fin n` verified bijective in-kernel. -/ +def mkPerm {n : ℕ} (f : Fin n → Fin n) + (hl : ∀ x : Fin n, invFin f (f x) = x := by decide) + (hr : ∀ y : Fin n, f (invFin f y) = y := by decide) : Perm := + ⟨n, ⟨f, invFin f, hl, hr⟩⟩ + +/-- Values of `τ` selected by a boolean mask `b : Fin τ.len → Bool`. -/ +def maskVals (τ : Perm) (b : Fin τ.len → Bool) : List ℕ := + ((List.finRange τ.len).filter b).map (fun i => (τ.perm i).val) + +/-- Decode a `Fin (2 ^ n)` bitmask into a boolean predicate on `Fin n`. -/ +def bitMask (n : ℕ) (m : Fin (2 ^ n)) (i : Fin n) : Bool := + m.val.testBit i.val + +/-- Encode a boolean predicate `b : Fin n → Bool` as a `Fin (2 ^ n)` bitmask. -/ +def encodeMask : ∀ {n : ℕ}, (Fin n → Bool) → Fin (2 ^ n) + | 0, _ => ⟨0, by simp⟩ + | n + 1, b => + let r := encodeMask (fun i : Fin n => b i.succ) + ⟨2 * r.val + if b 0 then 1 else 0, by + have hr := r.isLt + rw [pow_succ'] + split_ifs <;> omega⟩ + +theorem bitMask_encodeMask : ∀ {n : ℕ} (b : Fin n → Bool) (i : Fin n), + bitMask n (encodeMask b) i = b i + | 0, _, i => Fin.elim0 i + | n + 1, b, i => by + refine Fin.cases ?_ ?_ i + · simp only [bitMask, encodeMask, Fin.val_zero] + cases hb : b 0 <;> simp [Nat.testBit_zero] + · intro j + simp only [bitMask, encodeMask, Fin.val_succ] + rw [Nat.testBit_succ] + have hdiv : (2 * (encodeMask fun k : Fin n => b k.succ).val + + if b 0 = true then 1 else 0) / 2 = + (encodeMask fun k : Fin n => b k.succ).val := by + split_ifs <;> omega + rw [hdiv] + exact bitMask_encodeMask (fun k : Fin n => b k.succ) j + +private theorem list_eq_of_pairwise_lt {α : Type*} [LinearOrder α] : + ∀ {l₁ l₂ : List α}, l₁.Pairwise (· < ·) → l₂.Pairwise (· < ·) → + (∀ x, x ∈ l₁ ↔ x ∈ l₂) → l₁ = l₂ + | [], [], _, _, _ => rfl + | [], b :: _, _, _, h => absurd ((h b).mpr (by simp)) (by simp) + | a :: _, [], _, _, h => absurd ((h a).mp (by simp)) (by simp) + | a :: t₁, b :: t₂, hp₁, hp₂, h => by + rw [List.pairwise_cons] at hp₁ hp₂ + have hab : a = b := by + rcases lt_trichotomy a b with hlt | heq | hgt + · exfalso + rcases List.mem_cons.mp ((h a).mp (by simp)) with rfl | hmem + · exact lt_irrefl _ hlt + · exact lt_asymm hlt (hp₂.1 a hmem) + · exact heq + · exfalso + rcases List.mem_cons.mp ((h b).mpr (by simp)) with rfl | hmem + · exact lt_irrefl _ hgt + · exact lt_asymm hgt (hp₁.1 b hmem) + subst hab + congr 1 + apply list_eq_of_pairwise_lt hp₁.2 hp₂.2 + intro x + constructor + · intro hx + rcases List.mem_cons.mp ((h x).mp (List.mem_cons_of_mem _ hx)) with rfl | hmem + · exact absurd (hp₁.1 _ hx) (lt_irrefl _) + · exact hmem + · intro hx + rcases List.mem_cons.mp ((h x).mpr (List.mem_cons_of_mem _ hx)) with rfl | hmem + · exact absurd (hp₂.1 _ hx) (lt_irrefl _) + · exact hmem + +private theorem pairwise_lt_finRange (n : ℕ) : (List.finRange n).Pairwise (· < ·) := by + rw [List.pairwise_iff_getElem] + intro i j hi hj hij + simpa using hij + +/-- The standardized list of `subseqPerm τ S` for a boolean mask `b` equals +`standardizeList (maskVals τ b)`. -/ +theorem toList_subseqPerm_eq_standardizeList (τ : Perm) (b : Fin τ.len → Bool) : + (subseqPerm τ (Finset.univ.filter (fun i : Fin τ.len => b i = true))).toList = + standardizeList (maskVals τ b) := by + set S : Finset (Fin τ.len) := Finset.univ.filter (fun i => b i = true) + let ePos : Fin S.card ≃o S := S.orderIsoOfFin rfl + let f : Fin S.card ↪o Fin τ.len := ePos.toOrderEmbedding.trans (OrderEmbedding.subtype _) + have hle_f : ∀ i j : Fin S.card, + (subseqPerm τ S).perm i < (subseqPerm τ S).perm j ↔ τ.perm (f i) < τ.perm (f j) := by + intro i j + let V : Finset (Fin τ.len) := S.image τ.perm + have hV : V.card = S.card := Finset.card_image_of_injective S τ.perm.injective + let eVal : Fin S.card ≃o V := V.orderIsoOfFin hV + change (eVal.symm ⟨τ.perm (ePos i).1, _⟩) < (eVal.symm ⟨τ.perm (ePos j).1, _⟩) ↔ + τ.perm (ePos i).1 < τ.perm (ePos j).1 + exact eVal.symm.lt_iff_lt + have htoList := toList_eq_standardizeList_of_le (σ := subseqPerm τ S) (τ := τ) f hle_f + rw [htoList] + congr 1 + have hpos_list : List.ofFn f = (List.finRange τ.len).filter b := by + apply list_eq_of_pairwise_lt + · rw [List.pairwise_iff_getElem] + intro i j hi hj hij + simp only [List.getElem_ofFn] + exact f.strictMono hij + · exact (pairwise_lt_finRange τ.len).filter b + · intro x + rw [List.mem_ofFn, List.mem_filter] + constructor + · rintro ⟨idx, rfl⟩ + have hmem : (ePos idx).1 ∈ S := (ePos idx).2 + rw [Finset.mem_filter] at hmem + exact ⟨List.mem_finRange _, hmem.2⟩ + · rintro ⟨_, hbx⟩ + have hmem : x ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_univ _, hbx⟩ + refine ⟨ePos.symm ⟨x, hmem⟩, ?_⟩ + change (ePos (ePos.symm ⟨x, hmem⟩)).1 = x + simp + unfold maskVals + rw [← hpos_list, List.map_ofFn] + rfl + +/-- Exact bitmask characterization of pattern containment `σ ≤ τ`. -/ +theorem le_iff_exists_bitmask {σ τ : Perm} : + σ ≤ τ ↔ ∃ m : Fin (2 ^ τ.len), + σ.toList = standardizeList (maskVals τ (bitMask τ.len m)) := by + constructor + · intro hle + rcases le_iff_contains.mp hle with ⟨f, hf⟩ + let b : Fin τ.len → Bool := fun x => decide (x ∈ Finset.univ.image f) + refine ⟨encodeMask b, ?_⟩ + have hS : Finset.univ.filter (fun x : Fin τ.len => bitMask τ.len (encodeMask b) x = true) = + Finset.univ.image f := by + ext x + simp only [Finset.mem_filter, Finset.mem_univ, true_and, bitMask_encodeMask, b, + decide_eq_true_eq] + have hsub : σ = subseqPerm τ (Finset.univ.image f) := eq_subseqPerm_of_le f hf + rw [hsub, ← hS] + exact toList_subseqPerm_eq_standardizeList τ (bitMask τ.len (encodeMask b)) + · rintro ⟨m, hm⟩ + set S := Finset.univ.filter (fun i : Fin τ.len => bitMask τ.len m i = true) + have hlist : σ.toList = (subseqPerm τ S).toList := by + rw [hm, toList_subseqPerm_eq_standardizeList] + have heq : σ = subseqPerm τ S := Perm.toList_injective hlist + rw [heq] + exact subseqPerm_le τ S + +/-- Helper test checking whether a list contains entries `b < a < c` in order. -/ +def hasPairAfter (a : ℕ) : List ℕ → Bool + | [] => false + | b :: rest => (decide (b < a) && rest.any (fun c => decide (a < c))) || hasPairAfter a rest + +/-- Computable test for the `213` pattern on a list of natural numbers. -/ +def has213List : List ℕ → Bool + | [] => false + | a :: rest => hasPairAfter a rest || has213List rest + +private theorem hasPairAfter_true_of_getElem {a : ℕ} : + ∀ {l : List ℕ} {j k : ℕ} (hj : j < l.length) (hk : k < l.length), + j < k → l[j] < a → a < l[k] → hasPairAfter a l = true + | [], _, _, hj, _, _, _, _ => absurd hj (Nat.not_lt_zero _) + | b :: rest, 0, k + 1, _, hk, _, hba, hak => by + simp only [List.getElem_cons_zero] at hba + simp only [List.getElem_cons_succ] at hak + simp only [hasPairAfter, Bool.or_eq_true, Bool.and_eq_true, decide_eq_true_eq, + List.any_eq_true] + left + exact ⟨hba, rest[k]'(Nat.lt_of_succ_lt_succ hk), List.getElem_mem _, hak⟩ + | _ :: rest, j + 1, k + 1, hj, hk, hjk, hba, hak => by + simp only [List.getElem_cons_succ] at hba hak + simp only [hasPairAfter, Bool.or_eq_true] + right + exact hasPairAfter_true_of_getElem (Nat.lt_of_succ_lt_succ hj) (Nat.lt_of_succ_lt_succ hk) + (Nat.lt_of_succ_lt_succ hjk) hba hak + +private theorem has213List_true_of_getElem : + ∀ {l : List ℕ} {i j k : ℕ} (hi : i < l.length) (hj : j < l.length) (hk : k < l.length), + i < j → j < k → l[j] < l[i] → l[i] < l[k] → has213List l = true + | [], _, _, _, hi, _, _, _, _, _, _ => absurd hi (Nat.not_lt_zero _) + | a :: rest, 0, j + 1, k + 1, _, hj, hk, _, hjk, hji, hik => by + simp only [List.getElem_cons_zero] at hji hik + simp only [List.getElem_cons_succ] at hji hik + simp only [has213List, Bool.or_eq_true] + left + exact hasPairAfter_true_of_getElem (Nat.lt_of_succ_lt_succ hj) (Nat.lt_of_succ_lt_succ hk) + (Nat.lt_of_succ_lt_succ hjk) hji hik + | _ :: rest, i + 1, j + 1, k + 1, hi, hj, hk, hij, hjk, hji, hik => by + simp only [List.getElem_cons_succ] at hji hik + simp only [has213List, Bool.or_eq_true] + right + exact has213List_true_of_getElem (Nat.lt_of_succ_lt_succ hi) (Nat.lt_of_succ_lt_succ hj) + (Nat.lt_of_succ_lt_succ hk) (Nat.lt_of_succ_lt_succ hij) (Nat.lt_of_succ_lt_succ hjk) + hji hik + +/-! ### The 19 Permutations of `[213, 2574613]` -/ + +/-- `σ₇ = 213` (0-indexed: `[1, 0, 2]`). -/ +def σ₇ : Perm := mkPerm (n := 3) ![1, 0, 2] + +/-- `τ₇ = 2574613` (0-indexed: `[1, 4, 6, 3, 5, 0, 2]`). -/ +def τ₇ : Perm := mkPerm (n := 7) ![1, 4, 6, 3, 5, 0, 2] + +/-- Rank-4 member `1324` of `[213, 2574613]`. -/ +def p1324 : Perm := mkPerm (n := 4) ![0, 2, 1, 3] +/-- Rank-4 member `2413` of `[213, 2574613]`. -/ +def p2413 : Perm := mkPerm (n := 4) ![1, 3, 0, 2] +/-- Rank-4 member `3241` of `[213, 2574613]`. -/ +def p3241 : Perm := mkPerm (n := 4) ![2, 1, 3, 0] + +/-- Rank-5 member `13524` of `[213, 2574613]`. -/ +def p13524 : Perm := mkPerm (n := 5) ![0, 2, 4, 1, 3] +/-- Rank-5 member `14352` of `[213, 2574613]`. -/ +def p14352 : Perm := mkPerm (n := 5) ![0, 3, 2, 4, 1] +/-- Rank-5 member `24351` of `[213, 2574613]`. -/ +def p24351 : Perm := mkPerm (n := 5) ![1, 3, 2, 4, 0] +/-- Rank-5 member `24513` of `[213, 2574613]`. -/ +def p24513 : Perm := mkPerm (n := 5) ![1, 3, 4, 0, 2] +/-- Rank-5 member `25413` of `[213, 2574613]`. -/ +def p25413 : Perm := mkPerm (n := 5) ![1, 4, 3, 0, 2] +/-- Rank-5 member `35241` of `[213, 2574613]`. -/ +def p35241 : Perm := mkPerm (n := 5) ![2, 4, 1, 3, 0] +/-- Rank-5 member `43512` of `[213, 2574613]`. -/ +def p43512 : Perm := mkPerm (n := 5) ![3, 2, 4, 0, 1] + +/-- Rank-6 member `146352` of `[213, 2574613]`. -/ +def p146352 : Perm := mkPerm (n := 6) ![0, 3, 5, 2, 4, 1] +/-- Rank-6 member `246351` of `[213, 2574613]`. -/ +def p246351 : Perm := mkPerm (n := 6) ![1, 3, 5, 2, 4, 0] +/-- Rank-6 member `246513` of `[213, 2574613]`. -/ +def p246513 : Perm := mkPerm (n := 6) ![1, 3, 5, 4, 0, 2] +/-- Rank-6 member `254613` of `[213, 2574613]`. -/ +def p254613 : Perm := mkPerm (n := 6) ![1, 4, 3, 5, 0, 2] +/-- Rank-6 member `256413` of `[213, 2574613]`. -/ +def p256413 : Perm := mkPerm (n := 6) ![1, 4, 5, 3, 0, 2] +/-- Rank-6 member `264513` of `[213, 2574613]`. -/ +def p264513 : Perm := mkPerm (n := 6) ![1, 5, 3, 4, 0, 2] +/-- Rank-6 member `463512` of `[213, 2574613]`. -/ +def p463512 : Perm := mkPerm (n := 6) ![3, 5, 2, 4, 0, 1] + +/-- List of all 19 members of `[213, 2574613]`. -/ +def interval7List : List Perm := + [σ₇, + p1324, p2413, p3241, + p13524, p14352, p24351, p24513, p25413, p35241, p43512, + p146352, p246351, p246513, p254613, p256413, p264513, p463512, + τ₇] + +/-- Explicit 19-member `Finset` that we prove equals the genuine `Interval σ₇ τ₇`. -/ +def interval7Explicit : Finset Perm := interval7List.toFinset + +/-- Soundness of `has213List` for containment of `σ₇ = 213`. -/ +theorem has213List_of_sigma7_le {π : Perm} (h : σ₇ ≤ π) : has213List π.toList = true := by + rcases le_iff_contains.mp h with ⟨f, hf⟩ + have hlen : π.toList.length = π.len := Perm.toList_length π + let i0 : Fin σ₇.len := ⟨0, by decide⟩ + let i1 : Fin σ₇.len := ⟨1, by decide⟩ + let i2 : Fin σ₇.len := ⟨2, by decide⟩ + have h10 : σ₇.perm i1 < σ₇.perm i0 := by decide + have h02 : σ₇.perm i0 < σ₇.perm i2 := by decide + have hji : (π.perm (f i1)).val < (π.perm (f i0)).val := (hf i1 i0).mp h10 + have hik : (π.perm (f i0)).val < (π.perm (f i2)).val := (hf i0 i2).mp h02 + have h01 : (f i0).val < (f i1).val := f.strictMono (by decide : i0 < i1) + have h12 : (f i1).val < (f i2).val := f.strictMono (by decide : i1 < i2) + apply has213List_true_of_getElem (i := (f i0).val) (j := (f i1).val) (k := (f i2).val) + (hlen.symm ▸ (f i0).isLt) (hlen.symm ▸ (f i1).isLt) (hlen.symm ▸ (f i2).isLt) h01 h12 + · simp [Perm.toList, hji] + · simp [Perm.toList, hik] + +private theorem le_of_bitmask {σ τ : Perm} (m : Fin (2 ^ τ.len)) + (h : σ.toList = standardizeList (maskVals τ (bitMask τ.len m)) := by decide) : + σ ≤ τ := + le_iff_exists_bitmask.mpr ⟨m, h⟩ + +private theorem all_128_masks_classified : + ∀ m : Fin (2 ^ 7), + has213List (standardizeList (maskVals τ₇ (bitMask 7 m))) = true → + standardizeList (maskVals τ₇ (bitMask 7 m)) ∈ interval7List.map Perm.toList := by + decide + +private theorem all_19_in_interval : ∀ p ∈ interval7List, σ₇ ≤ p ∧ p ≤ τ₇ := by + intro p hp + simp only [interval7List, List.mem_cons, List.not_mem_nil, or_false] at hp + rcases hp with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | + rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl + · exact ⟨le_of_bitmask ⟨7, by decide⟩, le_of_bitmask ⟨26, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨14, by decide⟩, le_of_bitmask ⟨27, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨13, by decide⟩, le_of_bitmask ⟨30, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨7, by decide⟩, le_of_bitmask ⟨58, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨26, by decide⟩, le_of_bitmask ⟨31, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨14, by decide⟩, le_of_bitmask ⟨91, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨14, by decide⟩, le_of_bitmask ⟨59, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨25, by decide⟩, le_of_bitmask ⟨103, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨25, by decide⟩, le_of_bitmask ⟨107, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨13, by decide⟩, le_of_bitmask ⟨62, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨7, by decide⟩, le_of_bitmask ⟨122, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨26, by decide⟩, le_of_bitmask ⟨95, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨26, by decide⟩, le_of_bitmask ⟨63, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨49, by decide⟩, le_of_bitmask ⟨119, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨14, by decide⟩, le_of_bitmask ⟨123, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨49, by decide⟩, le_of_bitmask ⟨111, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨49, by decide⟩, le_of_bitmask ⟨125, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨13, by decide⟩, le_of_bitmask ⟨126, by decide⟩⟩ + · exact ⟨le_of_bitmask ⟨26, by decide⟩, le_of_bitmask ⟨127, by decide⟩⟩ + +/-- `213 ≤ 2574613`. -/ +theorem sigma7_le_tau7 : σ₇ ≤ τ₇ := + (all_19_in_interval σ₇ (by simp [interval7List])).2 + +/-- Exact equality between the genuine interval `Interval σ₇ τ₇` and the 19 explicit +permutations. -/ +theorem interval7_eq : Interval σ₇ τ₇ = interval7Explicit := by + ext π + rw [mem_interval_iff, interval7Explicit, List.mem_toFinset] + constructor + · rintro ⟨hlow, hhigh⟩ + have h213 : has213List π.toList = true := has213List_of_sigma7_le hlow + rcases le_iff_exists_bitmask.mp hhigh with ⟨m, hm⟩ + have hmem_list : π.toList ∈ interval7List.map Perm.toList := by + rw [hm] + exact all_128_masks_classified m (hm ▸ h213) + rcases List.mem_map.mp hmem_list with ⟨q, hq, hqeq⟩ + rw [← Perm.toList_injective hqeq] + exact hq + · exact all_19_in_interval π + +private theorem interval7List_toList_nodup : (interval7List.map Perm.toList).Nodup := by + decide + +private theorem interval7List_nodup : interval7List.Nodup := + List.Nodup.of_map Perm.toList interval7List_toList_nodup + +/-- The interval `[213, 2574613]` has exact cardinality 19. -/ +theorem interval7_card : (Interval σ₇ τ₇).card = 19 := by + rw [interval7_eq, interval7Explicit, List.toFinset_card_of_nodup interval7List_nodup] + rfl + +private theorem rankLevel_card_eq_filter_len (r : ℕ) : + (RankLevel (Interval σ₇ τ₇) r).card = + (interval7List.filter (fun π => decide (π.len = r))).length := by + rw [interval7_eq, RankLevel, interval7Explicit] + have heq : interval7List.toFinset.filter (fun π => π.len = r) = + (interval7List.filter (fun π => decide (π.len = r))).toFinset := by + ext π + simp + rw [heq, List.toFinset_card_of_nodup (interval7List_nodup.filter _)] + +/-- Exact rank sizes of `[213, 2574613]`: `1, 3, 7, 7, 1` for ranks `3, 4, 5, 6, 7`, +and `0` for every other rank. -/ +theorem interval7_rank_sizes : + (RankLevel (Interval σ₇ τ₇) 3).card = 1 ∧ + (RankLevel (Interval σ₇ τ₇) 4).card = 3 ∧ + (RankLevel (Interval σ₇ τ₇) 5).card = 7 ∧ + (RankLevel (Interval σ₇ τ₇) 6).card = 7 ∧ + (RankLevel (Interval σ₇ τ₇) 7).card = 1 ∧ + ∀ r : ℕ, r ≠ 3 → r ≠ 4 → r ≠ 5 → r ≠ 6 → r ≠ 7 → + (RankLevel (Interval σ₇ τ₇) r).card = 0 := by + refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ + · rw [rankLevel_card_eq_filter_len]; decide + · rw [rankLevel_card_eq_filter_len]; decide + · rw [rankLevel_card_eq_filter_len]; decide + · rw [rankLevel_card_eq_filter_len]; decide + · rw [rankLevel_card_eq_filter_len]; decide + · intro r h3 h4 h5 h6 h7 + rw [rankLevel_card_eq_filter_len, List.length_eq_zero_iff, List.filter_eq_nil_iff] + intro π hπ + have hlen : π.len ∈ ([3, 4, 5, 6, 7] : List ℕ) := by + revert π hπ + decide + simp only [List.mem_cons, List.not_mem_nil, or_false] at hlen + simp only [decide_eq_true_eq] + rcases hlen with h | h | h | h | h <;> omega + +/-- The largest rank size of `[213, 2574613]` is `7`. -/ +theorem interval7_largestRank : largestRank (Interval σ₇ τ₇) = 7 := by + have hr := interval7_rank_sizes + apply largestRank_eq_of_bounds (r := 5) + · intro r + by_cases h3 : r = 3 + · rw [h3, hr.1]; omega + by_cases h4 : r = 4 + · rw [h4, hr.2.1]; omega + by_cases h5 : r = 5 + · rw [h5, hr.2.2.1] + by_cases h6 : r = 6 + · rw [h6, hr.2.2.2.1] + by_cases h7 : r = 7 + · rw [h7, hr.2.2.2.2.1]; omega + rw [hr.2.2.2.2.2 r h3 h4 h5 h6 h7] + exact Nat.zero_le _ + · exact le_of_eq hr.2.2.1.symm + +/-! ### Explicit 8-Element Antichain and 8-Chain Cover of `[213, 2574613]` -/ + +/-- The 8-element antichain inside `[213, 2574613]`: +5 members of length 5 and 3 members of length 6. -/ +def anti7List : List Perm := + [p13524, p14352, p24351, p35241, p43512, p246513, p256413, p264513] + +/-- The 8-element antichain inside `[213, 2574613]` as a `Finset`. -/ +def anti7 : Finset Perm := anti7List.toFinset + +private theorem anti7List_toList_nodup : (anti7List.map Perm.toList).Nodup := by decide + +private theorem anti7List_nodup : anti7List.Nodup := + List.Nodup.of_map Perm.toList anti7List_toList_nodup + +theorem anti7_card : anti7.card = 8 := by + rw [anti7, List.toFinset_card_of_nodup anti7List_nodup] + rfl + +theorem anti7_subset : anti7 ⊆ Interval σ₇ τ₇ := by + rw [interval7_eq, anti7, interval7Explicit] + intro π hπ + rw [List.mem_toFinset] at hπ ⊢ + simp only [anti7List, interval7List, List.mem_cons, List.not_mem_nil, or_false] at hπ ⊢ + rcases hπ with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> tauto + +private theorem anti7_no_5_le_6 : + ∀ x ∈ ([p13524, p14352, p24351, p35241, p43512] : List Perm), + ∀ y ∈ ([p246513, p256413, p264513] : List Perm), + ∀ m : Fin (2 ^ y.len), + x.toList ≠ standardizeList (maskVals y (bitMask y.len m)) := by + decide + +theorem anti7_isAntichain : IsAntichain anti7 := by + intro x hx y hy hxy + rw [anti7, List.mem_toFinset] at hx hy + have hlen_le := le_len_le hxy + by_cases heq : x.len = y.len + · exact eq_of_le_of_len_eq hxy heq + · exfalso + have hx_split : x ∈ ([p13524, p14352, p24351, p35241, p43512] : List Perm) ∨ + x ∈ ([p246513, p256413, p264513] : List Perm) := by + simp only [anti7List, List.mem_cons, List.not_mem_nil, or_false] at hx ⊢ + rcases hx with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> tauto + have hy_split : y ∈ ([p13524, p14352, p24351, p35241, p43512] : List Perm) ∨ + y ∈ ([p246513, p256413, p264513] : List Perm) := by + simp only [anti7List, List.mem_cons, List.not_mem_nil, or_false] at hy ⊢ + rcases hy with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> tauto + have hlen5 : ∀ z ∈ ([p13524, p14352, p24351, p35241, p43512] : List Perm), z.len = 5 := by + decide + have hlen6 : ∀ z ∈ ([p246513, p256413, p264513] : List Perm), z.len = 6 := by + decide + rcases hx_split with hx5 | hx6 <;> rcases hy_split with hy5 | hy6 + · exact heq ((hlen5 x hx5).trans (hlen5 y hy5).symm) + · rcases le_iff_exists_bitmask.mp hxy with ⟨m, hm⟩ + exact anti7_no_5_le_6 x hx5 y hy6 m hm + · have := hlen6 x hx6; have := hlen5 y hy5; omega + · exact heq ((hlen6 x hx6).trans (hlen6 y hy6).symm) + +/-- Explicit 8-chain cover of `[213, 2574613]`. -/ +def chain7List : Fin 8 → List Perm + | ⟨0, _⟩ => [p2413, p13524] + | ⟨1, _⟩ => [p3241, p14352, p146352] + | ⟨2, _⟩ => [p35241, p246351] + | ⟨3, _⟩ => [p25413, p246513] + | ⟨4, _⟩ => [σ₇, p1324, p24351, p254613] + | ⟨5, _⟩ => [p24513, p256413] + | ⟨6, _⟩ => [p264513] + | ⟨7, _⟩ => [p43512, p463512, τ₇] + +/-- The 8 chains covering `[213, 2574613]` as `Finset`s. -/ +def chains7 (i : Fin 8) : Finset Perm := (chain7List i).toFinset + +private theorem isChain_list1 {a : Perm} : IsChain ([a].toFinset) := by + intro x hx y hy + simp only [List.mem_toFinset, List.mem_cons, List.not_mem_nil, or_false] at hx hy + subst hx; subst hy; exact Or.inl le_rfl + +private theorem isChain_list2 {a b : Perm} (h : a ≤ b) : IsChain ([a, b].toFinset) := by + intro x hx y hy + simp only [List.mem_toFinset, List.mem_cons, List.not_mem_nil, or_false] at hx hy + rcases hx with rfl | rfl <;> rcases hy with rfl | rfl + · exact Or.inl le_rfl + · exact Or.inl h + · exact Or.inr h + · exact Or.inl le_rfl + +private theorem isChain_list3 {a b c : Perm} (h1 : a ≤ b) (h2 : b ≤ c) : + IsChain ([a, b, c].toFinset) := by + intro x hx y hy + simp only [List.mem_toFinset, List.mem_cons, List.not_mem_nil, or_false] at hx hy + rcases hx with rfl | rfl | rfl <;> rcases hy with rfl | rfl | rfl + · exact Or.inl le_rfl + · exact Or.inl h1 + · exact Or.inl (h1.trans h2) + · exact Or.inr h1 + · exact Or.inl le_rfl + · exact Or.inl h2 + · exact Or.inr (h1.trans h2) + · exact Or.inr h2 + · exact Or.inl le_rfl + +private theorem isChain_list4 {a b c d : Perm} (h1 : a ≤ b) (h2 : b ≤ c) (h3 : c ≤ d) : + IsChain ([a, b, c, d].toFinset) := by + intro x hx y hy + simp only [List.mem_toFinset, List.mem_cons, List.not_mem_nil, or_false] at hx hy + rcases hx with rfl | rfl | rfl | rfl <;> rcases hy with rfl | rfl | rfl | rfl + · exact Or.inl le_rfl + · exact Or.inl h1 + · exact Or.inl (h1.trans h2) + · exact Or.inl ((h1.trans h2).trans h3) + · exact Or.inr h1 + · exact Or.inl le_rfl + · exact Or.inl h2 + · exact Or.inl (h2.trans h3) + · exact Or.inr (h1.trans h2) + · exact Or.inr h2 + · exact Or.inl le_rfl + · exact Or.inl h3 + · exact Or.inr ((h1.trans h2).trans h3) + · exact Or.inr (h2.trans h3) + · exact Or.inr h3 + · exact Or.inl le_rfl + +theorem chains7_isChain (i : Fin 8) : IsChain (chains7 i) := by + fin_cases i + · exact isChain_list2 (le_of_bitmask ⟨30, by decide⟩) + · exact isChain_list3 (le_of_bitmask ⟨30, by decide⟩) (le_of_bitmask ⟨59, by decide⟩) + · exact isChain_list2 (le_of_bitmask ⟨62, by decide⟩) + · exact isChain_list2 (le_of_bitmask ⟨61, by decide⟩) + · exact isChain_list4 (le_of_bitmask ⟨14, by decide⟩) (le_of_bitmask ⟨15, by decide⟩) + (le_of_bitmask ⟨31, by decide⟩) + · exact isChain_list2 (le_of_bitmask ⟨55, by decide⟩) + · exact isChain_list1 + · exact isChain_list3 (le_of_bitmask ⟨61, by decide⟩) (le_of_bitmask ⟨126, by decide⟩) + +theorem chains7_covers : ∀ π ∈ Interval σ₇ τ₇, ∃ i : Fin 8, π ∈ chains7 i := by + intro π hπ + rw [interval7_eq, interval7Explicit, List.mem_toFinset] at hπ + simp only [interval7List, List.mem_cons, List.not_mem_nil, or_false] at hπ + rcases hπ with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | + rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl + · exact ⟨⟨4, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨4, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨0, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨1, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨0, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨1, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨4, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨5, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨3, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨2, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨7, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨1, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨2, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨3, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨4, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨5, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨6, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨7, by decide⟩, by simp [chains7, chain7List]⟩ + · exact ⟨⟨7, by decide⟩, by simp [chains7, chain7List]⟩ + +/-- The width of `[213, 2574613]` is `8`. -/ +theorem interval7_width : width (Interval σ₇ τ₇) = 8 := by + apply le_antisymm + · calc + width (Interval σ₇ τ₇) ≤ (Finset.univ : Finset (Fin 8)).card := + width_le_of_indexed_chain_cover (fun i _ => chains7_isChain i) + (fun π hπ => by + rcases chains7_covers π hπ with ⟨i, hi⟩ + exact ⟨i, Finset.mem_univ i, hi⟩) + _ = 8 := by simp + · calc + 8 = anti7.card := anti7_card.symm + _ ≤ width (Interval σ₇ τ₇) := + card_le_width_of_antichain anti7_subset anti7_isAntichain + +/-- `[213, 2574613]` is NOT Sperner (`width = 8 ≠ 7 = largestRank`). -/ +theorem not_sperner_interval7 : ¬ IsSperner (Interval σ₇ τ₇) := by + unfold IsSperner + rw [interval7_width, interval7_largestRank] + omega + +/-- **Refutation of McNamara–Steingrímsson (2015) Question 9.5**: +Not every interval in the classical permutation pattern poset is Sperner. -/ +theorem mcnamara_steingrimsson_Q9_5_false : + ∃ σ τ : Perm, σ ≤ τ ∧ ¬ IsSperner (Interval σ τ) := + ⟨σ₇, τ₇, sigma7_le_tau7, not_sperner_interval7⟩ + +end PatternPoset diff --git a/LeanPool/projects/pattern-poset-not-sperner.yaml b/LeanPool/projects/pattern-poset-not-sperner.yaml new file mode 100644 index 0000000000..5dd9ca0aec --- /dev/null +++ b/LeanPool/projects/pattern-poset-not-sperner.yaml @@ -0,0 +1,97 @@ +slug: pattern-poset-not-sperner +title: Non-Sperner Intervals and Exact Deficiency Family in the Permutation Pattern Poset +summary: >- + Refutes Question 9.5 of McNamara and Steingrímsson (J. Combin. Theory Ser. A 134, 2015, 1–35), + which asked whether every interval in the classical permutation pattern poset is Sperner, and + constructs an infinite family of principal downsets with unbounded exact additive Sperner + deficiency. Proves unconditionally in Lean 4 + Mathlib (standard axioms only, no native_decide): + (1) the explicit 19-element closed interval [213, 2574613] has rank sizes 1, 3, 7, 7, 1 (largest + rank size 7) and width 8 (via an explicit 8-element antichain and an explicit 8-chain cover), so + it is not Sperner; and (2) for every integer k ≥ 1, the two-leader permutation τ_k of length + 6k + 4 has principal downset [∅, τ_k] with largest rank size 3k² + 8k + 5 and width + 3k² + 9k + 5, via a complete classification of Downset (τ_k) and an explicit 3D box symmetric + chain decomposition, giving exact Sperner deficiency k. Exhaustive minimality among intervals + with top element of length ≤ 8 is left outside the formalization. +branch: combinatorics +entry_module: LeanPool.PatternPosetNotSperner +authors: +- Tyler B. Hughes +source: + title: On the topology of the permutation pattern poset + authors: + - Peter R. W. McNamara + - Einar Steingrímsson + arxiv: '1305.5569' + doi: 10.1016/j.jcta.2015.02.009 + url: https://mathdiscoveries.org/results/pattern-poset-not-sperner/ + github_repo: mathdiscoveries/pattern-poset-not-sperner + commit: b19cebeafa288f2f6996b120918d3845da39996f +license: Apache-2.0 +status: verified +provenance: AI +main_declarations: +- PatternPoset.mcnamara_steingrimsson_Q9_5_false +- PatternPoset.not_sperner_interval7 +- PatternPoset.interval7_card +- PatternPoset.interval7_largestRank +- PatternPoset.interval7_width +- PatternPoset.family_exact_deficiency +- PatternPoset.family_not_sperner +- PatternPoset.family_largestRank +- PatternPoset.family_width +main_results: +- declaration: PatternPoset.mcnamara_steingrimsson_Q9_5_false + informal: >- + Refutes McNamara–Steingrímsson (2015) Question 9.5: there exist permutations σ ≤ τ in the + classical permutation pattern poset whose closed interval [σ, τ] is not Sperner. +- declaration: PatternPoset.not_sperner_interval7 + informal: >- + The explicit closed interval [213, 2574613] in the classical permutation pattern poset is not + Sperner (width 8 exceeds largest rank size 7). +- declaration: PatternPoset.interval7_card + informal: >- + The closed interval [213, 2574613] has exact cardinality 19. +- declaration: PatternPoset.interval7_rank_sizes + informal: >- + The closed interval [213, 2574613] has rank sizes 1, 3, 7, 7, 1 at lengths 3, 4, 5, 6, 7 and + 0 at all other ranks. +- declaration: PatternPoset.interval7_largestRank + informal: >- + The largest rank size of [213, 2574613] is 7. +- declaration: PatternPoset.interval7_width + informal: >- + The width of [213, 2574613] is 8, established by an explicit 8-element antichain and a + matching 8-chain cover. +- declaration: PatternPoset.family_exact_deficiency + informal: >- + For every k ≥ 1, the principal downset [∅, τ_k] of the length-(6k + 4) two-leader permutation + τ_k satisfies width (Downset (τ_k)) = largestRank (Downset (τ_k)) + k. +- declaration: PatternPoset.family_not_sperner + informal: >- + For every k ≥ 1, the principal downset [∅, τ_k] is not Sperner. +- declaration: PatternPoset.family_largestRank + informal: >- + For every k ≥ 1, the largest rank size of Downset (τ_k) is 3k² + 8k + 5, attained at rank + 3k + 3. +- declaration: PatternPoset.family_width + informal: >- + For every k ≥ 1, the width of Downset (τ_k) is 3k² + 9k + 5, established by an explicit + antichain and a matching chain cover combining a 3D box symmetric chain decomposition with + 4k + 3 valley-free chains. +- declaration: PatternPoset.downset_tau_classify + informal: >- + Classifies every pattern π ≤ τ_k into two-leader valley patterns P(x, y, z), one-leader + valley-free patterns Q(p, q), and strictly decreasing patterns D(l). +- declaration: PatternPoset.boxSlice_card + informal: >- + For the 3D integer box [0, 2k + 1] × [0, 2k + 1] × [0, 2k] and 0 ≤ t ≤ k, the slice of + triples with coordinate sum 3k + 1 + t has cardinality 3k² + 5k + 2 − t². +tags: +- combinatorics +- permutation-patterns +- posets +- sperner-property +- symmetric-chain-decomposition +msc: +- 05A05 +- 06A07