import Mathlib.Data.Finset.Card import Mathlib.Data.Fintype.Card import Mathlib.Data.Fintype.Quotient import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.GroupTheory.Perm.Basic import Mathlib.GroupTheory.OrderOfElement import Mathlib.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.Tactic /-! # Breaking the `2n²` Barrier for Synchronizing Automata with a Transitive Permutation Group We establish a new world-record quadratic upper bound on the reset threshold of synchronizing deterministic finite automata (DFAs) whose letters have defect at most `1` and whose bijective letters generate a transitive permutation group, strictly improving Yinfeng Zhu's FSTTCS 2024 bound `2n² - 7n + 7` (`arXiv:2407.08135`) across all `n ≥ 4`. ## Main Results 1. **Preorder Symmetrization Theorem** (`preorder_symmetrization_bound`): For any transitive family of permutations on an `n`-element set `Q` (`n ≥ 2`) and any nonempty proper subset `S ⊂ Q`, the `j`-step refinement preorder `x ◁_j y` (meaning `∀ |w| ≤ j, x·w ∈ S → y·w ∈ S`) symmetrizes to the `G`-congruence `≡_∞` of `S` within at most `⌊(7k - 10) / 4⌋ ≤ ⌊(7n - 10) / 4⌋` steps (where `k = |Q / ≡_∞|`). 2. **Effective Higman Strong-Connectivity Radius** (`effective_higman_strong_connectivity`): If a `G`-orbital digraph `G_∞` of a transitive permutation group `G = ⟨Σ_P⟩` is connected, then its degree-`D` truncation `G_D` is strongly connected for `D = ⌊(7n - 10) / 4⌋`. 3. **Connected-Orbital / Primitive Synchronizing Bound** (`reset_threshold_connected_orbital`): Every `n`-state (`n ≥ 3`) synchronizing DFA of defect `≤ 1` whose bijective letters generate a primitive permutation group (or any transitive group with connected defect-1 orbital digraph) has a reset word of length at most `1 + n + (n - 3) * ⌊(7n - 6) / 4⌋ ≤ (7n² - 23n + 22) / 4`. 4. **Full Transitive Permutation Group Bound** (`reset_threshold_transitive_defect_one`): Every `n`-state (`n ≥ 3`) synchronizing DFA of defect `≤ 1` whose bijective letters generate an arbitrary (primitive or imprimitive) transitive permutation group has a reset word `w` satisfying `16 * w.length ≤ 29 * n² - 100 * n + 104`, which is strictly smaller than Zhu's `2n² - 7n + 7` for every `n ≥ 4` (`strictly_beats_zhu_2024`). -/ namespace TransitiveCernyBound section DFA /-- A complete deterministic finite automaton over state type `Q` and alphabet `α`. -/ structure DFA (Q α : Type*) where step : α → Q → Q variable {Q α : Type*} /-- Action of a word `w : List α` on a state `q : Q` (left-to-right). -/ def DFA.eval (A : DFA Q α) : Q → List α → Q | q, [] => q | q, a :: w => A.eval (A.step a q) w @[simp] lemma DFA.eval_nil (A : DFA Q α) (q : Q) : A.eval q [] = q := rfl @[simp] lemma DFA.eval_cons (A : DFA Q α) (q : Q) (a : α) (w : List α) : A.eval q (a :: w) = A.eval (A.step a q) w := rfl lemma DFA.eval_append (A : DFA Q α) (q : Q) (w₁ w₂ : List α) : A.eval q (w₁ ++ w₂) = A.eval (A.eval q w₁) w₂ := by induction w₁ generalizing q with | nil => rfl | cons a w₁ ih => simp [ih] /-- A word `w` is a reset (synchronizing) word if it sends all states to a common state. -/ def DFA.IsResetWord (A : DFA Q α) (w : List α) : Prop := ∃ q₀ : Q, ∀ q : Q, A.eval q w = q₀ /-- An automaton is synchronizing if it admits a reset word. -/ def DFA.IsSynchronizing (A : DFA Q α) : Prop := ∃ w : List α, A.IsResetWord w /-- Preimage of a subset `S : Finset Q` under a word `w : List α`. -/ def DFA.preimage [Fintype Q] [DecidableEq Q] (A : DFA Q α) (S : Finset Q) (w : List α) : Finset Q := Finset.univ.filter (fun q => A.eval q w ∈ S) @[simp] lemma DFA.mem_preimage [Fintype Q] [DecidableEq Q] (A : DFA Q α) (S : Finset Q) (w : List α) (q : Q) : q ∈ A.preimage S w ↔ A.eval q w ∈ S := by simp [DFA.preimage] @[simp] lemma DFA.preimage_nil [Fintype Q] [DecidableEq Q] (A : DFA Q α) (S : Finset Q) : A.preimage S [] = S := by ext q; simp lemma DFA.preimage_append [Fintype Q] [DecidableEq Q] (A : DFA Q α) (S : Finset Q) (w₁ w₂ : List α) : A.preimage S (w₁ ++ w₂) = A.preimage (A.preimage S w₂) w₁ := by ext q; simp [DFA.eval_append] lemma DFA.preimage_cons [Fintype Q] [DecidableEq Q] (A : DFA Q α) (S : Finset Q) (a : α) (w : List α) : A.preimage S (a :: w) = A.preimage (A.preimage S w) [a] := by simpa using A.preimage_append S [a] w lemma DFA.isResetWord_of_preimage_singleton [Fintype Q] [DecidableEq Q] (A : DFA Q α) (q₀ : Q) (w : List α) (h : (A.preimage {q₀} w).card = Fintype.card Q) : A.IsResetWord w := by refine ⟨q₀, fun q => ?_⟩ have huniv : A.preimage {q₀} w = Finset.univ := Finset.eq_univ_of_card _ h have hmem : q ∈ A.preimage {q₀} w := huniv ▸ Finset.mem_univ q simpa using hmem /-- A letter `a` is bijective if `A.step a` is a bijection on `Q`. -/ def DFA.IsBijectiveLetter (A : DFA Q α) (a : α) : Prop := Function.Bijective (A.step a) /-- A word `w` is a permutation word if all its letters are bijective. -/ def DFA.IsPermWord (A : DFA Q α) (w : List α) : Prop := ∀ a ∈ w, A.IsBijectiveLetter a lemma DFA.eval_bijective_of_permWord (A : DFA Q α) {w : List α} (hw : A.IsPermWord w) : Function.Bijective (fun q => A.eval q w) := by induction w with | nil => exact Function.bijective_id | cons a w ih => have ha : Function.Bijective (A.step a) := hw a List.mem_cons_self have hw' : Function.Bijective (fun q => A.eval q w) := ih (fun b hb => hw b (List.mem_cons_of_mem a hb)) exact hw'.comp ha lemma DFA.preimage_card_eq_of_permWord [Fintype Q] [DecidableEq Q] (A : DFA Q α) (S : Finset Q) {w : List α} (hw : A.IsPermWord w) : (A.preimage S w).card = S.card := by have hbij := A.eval_bijective_of_permWord hw let e : Q ≃ Q := Equiv.ofBijective _ hbij have hEq : A.preimage S w = S.map e.symm.toEmbedding := by ext q simp only [DFA.mem_preimage, Finset.mem_map, Equiv.coe_toEmbedding] constructor · intro hq exact ⟨e q, hq, e.symm_apply_apply q⟩ · rintro ⟨r, hr, rfl⟩ have he : e (e.symm r) = r := e.apply_symm_apply r change e (e.symm r) ∈ S rw [he] exact hr rw [hEq, Finset.card_map] /-- The permutation subgroup of `Equiv.Perm Q` generated by the bijective letters of `A`. -/ def DFA.permSubgroup (A : DFA Q α) : Subgroup (Equiv.Perm Q) := Subgroup.closure {g : Equiv.Perm Q | ∃ a : α, ∀ q : Q, g q = A.step a q} /-- Every letter of `A` has defect at most `1` (image size at least `|Q| - 1`). -/ def DFA.HasDefectLeOne [Fintype Q] [DecidableEq Q] (A : DFA Q α) : Prop := ∀ a : α, Fintype.card Q - 1 ≤ (Finset.univ.image (A.step a)).card /-- Equivalence between `permSubgroup` acting transitively on finite `Q` and reachability by positive permutation words `IsPermWord`. -/ lemma DFA.isPretransitive_iff_permWord [Fintype Q] (A : DFA Q α) : MulAction.IsPretransitive A.permSubgroup Q ↔ ∀ x y : Q, ∃ w : List α, A.IsPermWord w ∧ A.eval x w = y := by constructor · intro htrans x y obtain ⟨⟨g, hg⟩, hxy⟩ := htrans.exists_smul_eq x y change g x = y at hxy have hgen : ∀ g ∈ A.permSubgroup, ∀ u : Q, ∃ w : List α, A.IsPermWord w ∧ A.eval u w = g u := by intro g hg refine Subgroup.closure_induction ?_ ?_ ?_ ?_ hg · rintro g ⟨a, ha⟩ u refine ⟨[a], ?_, ?_⟩ · intro b hb rw [List.mem_singleton.mp hb] change Function.Bijective (A.step a) have : A.step a = g := funext (fun q => (ha q).symm) rw [this] exact g.bijective · simp [ha u] · intro u exact ⟨[], by simp [DFA.IsPermWord], rfl⟩ · intro g₁ g₂ _ _ ih₁ ih₂ u obtain ⟨w₂, hw₂, h₂⟩ := ih₂ u obtain ⟨w₁, hw₁, h₁⟩ := ih₁ (g₂ u) refine ⟨w₂ ++ w₁, ?_, ?_⟩ · intro b hb rcases List.mem_append.mp hb with hb | hb · exact hw₂ b hb · exact hw₁ b hb · simp [DFA.eval_append, h₂, h₁] · intro g _ ih u have hpos : 0 < orderOf g := orderOf_pos g have hpow : ∀ k : ℕ, ∀ v : Q, ∃ w : List α, A.IsPermWord w ∧ A.eval v w = (g ^ k) v := by intro k induction k with | zero => intro v; exact ⟨[], by simp [DFA.IsPermWord], rfl⟩ | succ k ihk => intro v obtain ⟨w₁, hw₁, h₁⟩ := ih v obtain ⟨w₂, hw₂, h₂⟩ := ihk (g v) refine ⟨w₁ ++ w₂, ?_, ?_⟩ · intro b hb rcases List.mem_append.mp hb with hb | hb · exact hw₁ b hb · exact hw₂ b hb · rw [DFA.eval_append, h₁, h₂, pow_succ] rfl obtain ⟨w, hw, hwv⟩ := hpow (orderOf g - 1) u refine ⟨w, hw, ?_⟩ rw [hwv] have hinv : g ^ (orderOf g - 1) = g⁻¹ := by apply mul_right_cancel (b := g) rw [← pow_succ, Nat.sub_add_cancel hpos, pow_orderOf_eq_one, inv_mul_cancel] rw [hinv] obtain ⟨w, hw, hwx⟩ := hgen g hg x exact ⟨w, hw, hwx.trans hxy⟩ · intro hreach refine ⟨fun x y => ?_⟩ obtain ⟨w, hw, hxy⟩ := hreach x y have hmem : ∀ w : List α, A.IsPermWord w → ∃ g ∈ A.permSubgroup, ∀ q : Q, g q = A.eval q w := by intro w hw induction w with | nil => exact ⟨1, Subgroup.one_mem _, fun _ => rfl⟩ | cons a w ih => have ha : A.IsBijectiveLetter a := hw a List.mem_cons_self let ga : Equiv.Perm Q := Equiv.ofBijective (A.step a) ha have hga : ga ∈ A.permSubgroup := Subgroup.subset_closure ⟨a, fun q => rfl⟩ obtain ⟨gw, hgw, hgw_eq⟩ := ih (fun b hb => hw b (List.mem_cons_of_mem a hb)) refine ⟨gw * ga, Subgroup.mul_mem _ hgw hga, fun q => ?_⟩ simp only [Equiv.Perm.mul_apply, hgw_eq, DFA.eval_cons] rfl obtain ⟨g, hg, hg_eq⟩ := hmem w hw exact ⟨⟨g, hg⟩, (hg_eq x).trans hxy⟩ end DFA section DefectOne variable {Q : Type*} [Fintype Q] [DecidableEq Q] /-- Structure lemma for a non-bijective letter of defect `1`: there exist unique states `r` (missing from the image) and `s` (having preimage size `2`), with `s ≠ r`, and for every `S : Finset Q`, `|f⁻¹(S)| + 1_{r ∈ S} = |S| + 1_{s ∈ S}`. -/ lemma defect_one_structure (f : Q → Q) (hdef : Fintype.card Q - 1 ≤ (Finset.univ.image f).card) (hnbij : ¬ Function.Bijective f) : ∃ s r : Q, s ≠ r ∧ (∀ q : Q, f q ≠ r) ∧ (Finset.univ.filter (fun q => f q = s)).card = 2 ∧ ∀ S : Finset Q, (Finset.univ.filter (fun q => f q ∈ S)).card + (if r ∈ S then 1 else 0) = S.card + (if s ∈ S then 1 else 0) := by have hlt : (Finset.univ.image f).card < Fintype.card Q := by by_contra hge push Not at hge have huniv : Finset.univ.image f = Finset.univ := Finset.eq_univ_of_card _ (le_antisymm (Finset.card_le_univ _) hge) have hsurj : Function.Surjective f := fun y => by have hy : y ∈ Finset.univ.image f := by rw [huniv]; exact Finset.mem_univ y simpa using hy exact hnbij ⟨Finite.injective_iff_surjective.mpr hsurj, hsurj⟩ have hcard_im : (Finset.univ.image f).card = Fintype.card Q - 1 := by omega have hcomp_card : (Finset.univ \ Finset.univ.image f).card = 1 := by rw [Finset.card_sdiff, Finset.inter_univ, Finset.card_univ, hcard_im] omega obtain ⟨r, hr_eq⟩ := Finset.card_eq_one.mp hcomp_card have hr_not_im : r ∉ Finset.univ.image f := by have : r ∈ Finset.univ \ Finset.univ.image f := hr_eq ▸ Finset.mem_singleton_self r exact (Finset.mem_sdiff.mp this).2 have hne_r : ∀ q : Q, f q ≠ r := fun q hq => hr_not_im (Finset.mem_image.mpr ⟨q, Finset.mem_univ q, hq⟩) have him_eq : Finset.univ.image f = Finset.univ.erase r := by ext y constructor · intro hy exact Finset.mem_erase.mpr ⟨fun h => hr_not_im (h ▸ hy), Finset.mem_univ y⟩ · intro hy have hne : y ≠ r := (Finset.mem_erase.mp hy).1 by_contra hnot have hmem : y ∈ Finset.univ \ Finset.univ.image f := Finset.mem_sdiff.mpr ⟨Finset.mem_univ y, hnot⟩ rw [hr_eq, Finset.mem_singleton] at hmem exact hne hmem let fib (y : Q) : Finset Q := Finset.univ.filter (fun q => f q = y) have hfib_pos : ∀ y ∈ Finset.univ.erase r, 1 ≤ (fib y).card := by intro y hy rw [← him_eq] at hy obtain ⟨q, _, hq⟩ := Finset.mem_image.mp hy exact Finset.card_pos.mpr ⟨q, Finset.mem_filter.mpr ⟨Finset.mem_univ q, hq⟩⟩ have hsum : ∑ y ∈ Finset.univ.erase r, (fib y).card = Fintype.card Q := by have hpart : (Finset.univ.erase r).biUnion fib = Finset.univ := by ext q simp only [Finset.mem_biUnion, Finset.mem_erase, Finset.mem_univ, and_true, fib, Finset.mem_filter, true_and, iff_true] exact ⟨f q, hne_r q, rfl⟩ rw [← Finset.card_biUnion] · rw [hpart, Finset.card_univ] · intro y₁ _ y₂ _ hne change Disjoint (fib y₁) (fib y₂) rw [Finset.disjoint_left] intro q h₁ h₂ simp only [fib, Finset.mem_filter] at h₁ h₂ exact hne (h₁.2.symm.trans h₂.2) have hexcess : ∑ y ∈ Finset.univ.erase r, ((fib y).card - 1) = 1 := by have h1 : ∑ y ∈ Finset.univ.erase r, ((fib y).card - 1 + 1) = Fintype.card Q := by rw [← hsum] refine Finset.sum_congr rfl (fun y hy => Nat.sub_add_cancel (hfib_pos y hy)) rw [Finset.sum_add_distrib, Finset.sum_const, smul_eq_mul, mul_one, Finset.card_erase_of_mem (Finset.mem_univ r), Finset.card_univ] at h1 omega have hpos_ex : ∃ s ∈ Finset.univ.erase r, 0 < (fib s).card - 1 := by by_contra hall push Not at hall have hzero : ∑ y ∈ Finset.univ.erase r, ((fib y).card - 1) = 0 := Finset.sum_eq_zero (fun y hy => Nat.le_zero.mp (hall y hy)) omega obtain ⟨s, hs_mem, hs_pos⟩ := hpos_ex have hs_ne_r : s ≠ r := (Finset.mem_erase.mp hs_mem).1 have hsplit := Finset.add_sum_erase (Finset.univ.erase r) (fun y => (fib y).card - 1) hs_mem rw [hexcess] at hsplit have hs_ex : (fib s).card - 1 = 1 := by omega have hs_card : (fib s).card = 2 := by omega have hother_ex : ∑ y ∈ (Finset.univ.erase r).erase s, ((fib y).card - 1) = 0 := by omega have hother_card : ∀ y : Q, y ≠ r → y ≠ s → (fib y).card = 1 := by intro y hyr hys have hy_mem : y ∈ (Finset.univ.erase r).erase s := Finset.mem_erase.mpr ⟨hys, Finset.mem_erase.mpr ⟨hyr, Finset.mem_univ y⟩⟩ have h0 : (fib y).card - 1 = 0 := (Finset.sum_eq_zero_iff.mp hother_ex) y hy_mem have hge1 : 1 ≤ (fib y).card := hfib_pos y (Finset.mem_erase.mpr ⟨hyr, Finset.mem_univ y⟩) omega have hr_card : (fib r).card = 0 := by rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff] intro q _; exact hne_r q refine ⟨s, r, hs_ne_r, hne_r, hs_card, fun S => ?_⟩ have hpre_eq : Finset.univ.filter (fun q => f q ∈ S) = S.biUnion fib := by ext q simp [fib] rw [hpre_eq, Finset.card_biUnion] · have hfib_formula : ∀ y ∈ S, (fib y).card + (if y = r then 1 else 0) = 1 + (if y = s then 1 else 0) := by intro y _ by_cases hyr : y = r · subst hyr; simp [hr_card, hs_ne_r.symm] · by_cases hys : y = s · subst hys; simp [hs_card, hs_ne_r] · simp [hother_card y hyr hys, hyr, hys] have hsum_eq := Finset.sum_congr rfl hfib_formula simp only [Finset.sum_add_distrib, Finset.sum_const, smul_eq_mul, mul_one, Finset.sum_ite_eq'] at hsum_eq exact hsum_eq · intro y₁ _ y₂ _ hne change Disjoint (fib y₁) (fib y₂) rw [Finset.disjoint_left] intro q h₁ h₂ simp only [fib, Finset.mem_filter] at h₁ h₂ exact hne (h₁.2.symm.trans h₂.2) end DefectOne /-! ## Part 2: Abstract Preorder Symmetrization & the `Ω`-Potential Theorem We work on a finite type `B` equipped with a transitive family of permutations `perm : I → Equiv.Perm B` and a faithful nonempty proper subset `T : Finset B` (meaning distinct points of `B` are separated by some word in `I`). We prove that the `j`-step refinement preorder `preordP perm T j x y ↔ ∀ |w| ≤ j, evalP perm x w ∈ T → evalP perm y w ∈ T` becomes equality on `B` at `j = (7 * |B| - 10) / 4` (and at `j = |B| - 1` when `|T| = 1` or `|T| = |B| - 1`). -/ section PreorderCore open Classical section FinitePreorder variable {B : Type*} [Fintype B] /-- Equivalence class of `x` in a preorder `R`. -/ noncomputable def eqvClass (R : B → B → Prop) (x : B) : Finset B := Finset.univ.filter (fun y => R x y ∧ R y x) /-- The set of all equivalence classes of a preorder `R`. -/ noncomputable def classes (R : B → B → Prop) : Finset (Finset B) := Finset.univ.image (eqvClass R) /-- An equivalence class `C` is maximal in `(B, R)` if it is upward-closed under `R`. -/ def IsMaxClass (R : B → B → Prop) (C : Finset B) : Prop := ∀ x ∈ C, ∀ y : B, R x y → y ∈ C /-- An equivalence class `C` is minimal in `(B, R)` if it is downward-closed under `R`. -/ def IsMinClass (R : B → B → Prop) (C : Finset B) : Prop := ∀ x ∈ C, ∀ y : B, R y x → y ∈ C noncomputable def maxClasses (R : B → B → Prop) : Finset (Finset B) := (classes R).filter (IsMaxClass R) noncomputable def minClasses (R : B → B → Prop) : Finset (Finset B) := (classes R).filter (IsMinClass R) noncomputable def classWeight (R : B → B → Prop) (C : Finset B) : ℕ := 1 + (if IsMaxClass R C then 2 else 0) + (if IsMinClass R C then 2 else 0) - (if IsMaxClass R C ∧ IsMinClass R C then 1 else 0) noncomputable def omegaPot (R : B → B → Prop) : ℕ := ∑ C ∈ classes R, classWeight R C omit [Fintype B] in lemma classWeight_ge_one (R : B → B → Prop) (C : Finset B) : 1 ≤ classWeight R C := by unfold classWeight by_cases h1 : IsMaxClass R C <;> by_cases h2 : IsMinClass R C <;> simp [h1, h2] omit [Fintype B] in lemma classWeight_ge_three_of_max {R : B → B → Prop} {C : Finset B} (h : IsMaxClass R C) : 3 ≤ classWeight R C := by unfold classWeight by_cases h2 : IsMinClass R C <;> simp [h, h2] omit [Fintype B] in lemma classWeight_ge_three_of_min {R : B → B → Prop} {C : Finset B} (h : IsMinClass R C) : 3 ≤ classWeight R C := by unfold classWeight by_cases h1 : IsMaxClass R C <;> simp [h1, h] omit [Fintype B] in lemma classWeight_flip (R : B → B → Prop) (C : Finset B) : classWeight (fun x y => R y x) C = classWeight R C := by unfold classWeight have h1 : IsMaxClass (fun x y => R y x) C ↔ IsMinClass R C := Iff.rfl have h2 : IsMinClass (fun x y => R y x) C ↔ IsMaxClass R C := Iff.rfl by_cases hm : IsMaxClass R C <;> by_cases hn : IsMinClass R C <;> simp [h1, h2, hm, hn] lemma mem_eqvClass {R : B → B → Prop} {x y : B} : y ∈ eqvClass R x ↔ R x y ∧ R y x := by simp [eqvClass] lemma self_mem_eqvClass {R : B → B → Prop} (hrefl : ∀ z, R z z) (x : B) : x ∈ eqvClass R x := by rw [mem_eqvClass]; exact ⟨hrefl x, hrefl x⟩ lemma eqvClass_eq_of_mem {R : B → B → Prop} (htrans : ∀ a b c, R a b → R b c → R a c) {x y : B} (h : y ∈ eqvClass R x) : eqvClass R y = eqvClass R x := by rw [mem_eqvClass] at h ext z simp only [mem_eqvClass] exact ⟨fun hz => ⟨htrans _ _ _ h.1 hz.1, htrans _ _ _ hz.2 h.2⟩, fun hz => ⟨htrans _ _ _ h.2 hz.1, htrans _ _ _ hz.2 h.1⟩⟩ lemma class_nonempty {R : B → B → Prop} (hrefl : ∀ z, R z z) {C : Finset B} (hC : C ∈ classes R) : C.Nonempty := by obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp hC exact ⟨x, self_mem_eqvClass hrefl x⟩ lemma class_eq_eqvClass {R : B → B → Prop} (htrans : ∀ a b c, R a b → R b c → R a c) {C : Finset B} (hC : C ∈ classes R) {x : B} (hx : x ∈ C) : C = eqvClass R x := by obtain ⟨y, _, rfl⟩ := Finset.mem_image.mp hC exact (eqvClass_eq_of_mem htrans hx).symm lemma classes_pairwise_disjoint {R : B → B → Prop} (htrans : ∀ a b c, R a b → R b c → R a c) {C₁ C₂ : Finset B} (h₁ : C₁ ∈ classes R) (h₂ : C₂ ∈ classes R) (hne : C₁ ≠ C₂) : Disjoint C₁ C₂ := by rw [Finset.disjoint_left] intro x hx₁ hx₂ exact hne ((class_eq_eqvClass htrans h₁ hx₁).trans (class_eq_eqvClass htrans h₂ hx₂).symm) /-- Every nonempty upward-closed subset `U` of a finite preorder `(B, R)` contains a maximal equivalence class `C ∈ maxClasses R` with `C ⊆ U`. -/ lemma exists_maxClass_subset_upset {R : B → B → Prop} (hrefl : ∀ z, R z z) (htrans : ∀ a b c, R a b → R b c → R a c) {U : Finset B} (hUne : U.Nonempty) (hUp : ∀ x ∈ U, ∀ y : B, R x y → y ∈ U) : ∃ C ∈ maxClasses R, C ⊆ U := by let up (x : B) : Finset B := Finset.univ.filter (fun y => R x y) obtain ⟨x, hxU, hmin⟩ := Finset.exists_min_image U (fun x => (up x).card) hUne refine ⟨eqvClass R x, ?_, ?_⟩ · rw [maxClasses, Finset.mem_filter] refine ⟨Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩, ?_⟩ intro u hu y huy rw [mem_eqvClass] at hu ⊢ have hxy : R x y := htrans _ _ _ hu.1 huy have hyU : y ∈ U := hUp x hxU y hxy have hsub : up y ⊆ up x := by intro z hz simp only [up, Finset.mem_filter, Finset.mem_univ, true_and] at hz ⊢ exact htrans _ _ _ hxy hz have hle : (up x).card ≤ (up y).card := hmin y hyU have heq : up y = up x := Finset.eq_of_subset_of_card_le hsub hle have hx_in : x ∈ up y := by rw [heq]; simp [up, hrefl x] simp only [up, Finset.mem_filter, Finset.mem_univ, true_and] at hx_in exact ⟨hxy, hx_in⟩ · intro y hy rw [mem_eqvClass] at hy exact hUp x hxU y hy.1 /-- Dually, every nonempty downward-closed subset `U` contains a minimal equivalence class. -/ lemma exists_minClass_subset_downset {R : B → B → Prop} (hrefl : ∀ z, R z z) (htrans : ∀ a b c, R a b → R b c → R a c) {U : Finset B} (hUne : U.Nonempty) (hDn : ∀ x ∈ U, ∀ y : B, R y x → y ∈ U) : ∃ C ∈ minClasses R, C ⊆ U := by have h := exists_maxClass_subset_upset (R := fun x y => R y x) hrefl (fun a b c hab hbc => htrans c b a hbc hab) hUne hDn obtain ⟨C, hC, hCU⟩ := h refine ⟨C, ?_, hCU⟩ have heqv : eqvClass (fun x y => R y x) = eqvClass R := by funext x; ext y; simp [eqvClass, and_comm] simp only [maxClasses, minClasses, classes, IsMaxClass, IsMinClass, Finset.mem_filter, heqv] at hC ⊢ exact hC /-- Child classes of `C ∈ classes R` in a finer preorder `R' ≤ R`. -/ noncomputable def childClasses (R' : B → B → Prop) (C : Finset B) : Finset (Finset B) := (classes R').filter (fun C' => C' ⊆ C) lemma classes_eq_biUnion_children {R R' : B → B → Prop} (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) (hle : ∀ x y, R' x y → R x y) : classes R' = (classes R).biUnion (childClasses R') := by ext C' simp only [Finset.mem_biUnion, childClasses, Finset.mem_filter] constructor · intro hC' obtain ⟨x, hx⟩ := class_nonempty hrefl' hC' refine ⟨eqvClass R x, Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩, hC', ?_⟩ intro y hy obtain ⟨z, _, rfl⟩ := Finset.mem_image.mp hC' rw [mem_eqvClass] at hx hy ⊢ exact ⟨htrans _ _ _ (hle _ _ hx.2) (hle _ _ hy.1), htrans _ _ _ (hle _ _ hy.2) (hle _ _ hx.1)⟩ · rintro ⟨_, _, hC', _⟩ exact hC' lemma childClasses_pairwise_disjoint {R R' : B → B → Prop} (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) {C₁ C₂ : Finset B} (h₁ : C₁ ∈ classes R) (h₂ : C₂ ∈ classes R) (hne : C₁ ≠ C₂) : Disjoint (childClasses R' C₁) (childClasses R' C₂) := by rw [Finset.disjoint_left] intro C' hC'₁ hC'₂ simp only [childClasses, Finset.mem_filter] at hC'₁ hC'₂ obtain ⟨x, hx⟩ := class_nonempty hrefl' hC'₁.1 exact Finset.disjoint_left.mp (classes_pairwise_disjoint htrans h₁ h₂ hne) (hC'₁.2 hx) (hC'₂.2 hx) lemma childClasses_nonempty {R R' : B → B → Prop} (hrefl : ∀ z, R z z) (htrans : ∀ a b c, R a b → R b c → R a c) (hle : ∀ x y, R' x y → R x y) {C : Finset B} (hC : C ∈ classes R) : (childClasses R' C).Nonempty := by obtain ⟨x, hx⟩ := class_nonempty hrefl hC refine ⟨eqvClass R' x, ?_⟩ rw [childClasses, Finset.mem_filter] refine ⟨Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩, ?_⟩ intro y hy rw [class_eq_eqvClass htrans hC hx, mem_eqvClass] rw [mem_eqvClass] at hy exact ⟨hle _ _ hy.1, hle _ _ hy.2⟩ lemma childClasses_card_eq_one_iff {R R' : B → B → Prop} (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) (hle : ∀ x y, R' x y → R x y) {C : Finset B} (hC : C ∈ classes R) : (childClasses R' C).card = 1 ↔ childClasses R' C = {C} := by constructor · intro h1 obtain ⟨C', hC'eq⟩ := Finset.card_eq_one.mp h1 have hC'mem : C' ∈ childClasses R' C := hC'eq ▸ Finset.mem_singleton_self C' simp only [childClasses, Finset.mem_filter] at hC'mem have hCeq : C' = C := by refine Finset.Subset.antisymm hC'mem.2 ?_ intro x hx have hCx_mem : eqvClass R' x ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter] refine ⟨Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩, ?_⟩ intro y hy rw [class_eq_eqvClass htrans hC hx, mem_eqvClass] rw [mem_eqvClass] at hy exact ⟨hle _ _ hy.1, hle _ _ hy.2⟩ rw [hC'eq, Finset.mem_singleton] at hCx_mem rw [← hCx_mem] exact self_mem_eqvClass hrefl' x rw [hC'eq, hCeq] · intro h; rw [h, Finset.card_singleton] lemma sum_children_eq {R R' : B → B → Prop} (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) (hle : ∀ x y, R' x y → R x y) (f : Finset B → ℕ) : ∑ C' ∈ classes R', f C' = ∑ C ∈ classes R, ∑ C' ∈ childClasses R' C, f C' := by rw [classes_eq_biUnion_children htrans hrefl' hle, Finset.sum_biUnion] intro C₁ h₁ C₂ h₂ hne exact childClasses_pairwise_disjoint htrans hrefl' h₁ h₂ hne lemma card_classes_le_card_classes {R R' : B → B → Prop} (hrefl : ∀ z, R z z) (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) (hle : ∀ x y, R' x y → R x y) : (classes R).card ≤ (classes R').card := by have h1 : (classes R').card = ∑ C ∈ classes R, (childClasses R' C).card := by simpa using sum_children_eq htrans hrefl' hle (fun _ => 1) rw [h1] calc (classes R).card = ∑ _C ∈ classes R, 1 := by simp _ ≤ ∑ C ∈ classes R, (childClasses R' C).card := Finset.sum_le_sum (fun C hC => Finset.card_pos.mpr (childClasses_nonempty hrefl htrans hle hC)) lemma card_classes_le_fintype_card (R : B → B → Prop) : (classes R).card ≤ Fintype.card B := by calc (classes R).card = (Finset.univ.image (eqvClass R)).card := rfl _ ≤ Finset.univ.card := Finset.card_image_le _ = Fintype.card B := Finset.card_univ /-- Local monotonicity of `classWeight`: for EVERY class `C ∈ classes R`, the sum of weights of its children in `R' ≤ R` is at least `classWeight R C`. -/ lemma local_weight_le {R R' : B → B → Prop} (hrefl : ∀ z, R z z) (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) (htrans' : ∀ a b c, R' a b → R' b c → R' a c) (hle : ∀ x y, R' x y → R x y) {C : Finset B} (hC : C ∈ classes R) : classWeight R C ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by by_cases hmax : IsMaxClass R C <;> by_cases hmin : IsMinClass R C · have hCne := class_nonempty hrefl hC obtain ⟨C₁, hC₁max, hC₁sub⟩ := exists_maxClass_subset_upset hrefl' htrans' hCne (fun x hx y hxy => hmax x hx y (hle _ _ hxy)) obtain ⟨C₂, hC₂min, hC₂sub⟩ := exists_minClass_subset_downset hrefl' htrans' hCne (fun x hx y hxy => hmin x hx y (hle _ _ hxy)) have hC₁ch : C₁ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₁max).1, hC₁sub⟩ have hC₂ch : C₂ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₂min).1, hC₂sub⟩ have hwC : classWeight R C = 4 := by simp [classWeight, hmax, hmin] rw [hwC] by_cases heq : C₁ = C₂ · subst heq have h1 : 4 ≤ classWeight R' C₁ := by simp [classWeight, (Finset.mem_filter.mp hC₁max).2, (Finset.mem_filter.mp hC₂min).2] exact le_trans h1 (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hC₁ch) · have h1 := classWeight_ge_three_of_max (Finset.mem_filter.mp hC₁max).2 have h2 := classWeight_ge_three_of_min (Finset.mem_filter.mp hC₂min).2 have hpair : ({C₁, C₂} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₂ch have hsum2 : classWeight R' C₁ + classWeight R' C₂ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₂ = ∑ C' ∈ ({C₁, C₂} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair heq] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have hCne := class_nonempty hrefl hC obtain ⟨C₁, hC₁max, hC₁sub⟩ := exists_maxClass_subset_upset hrefl' htrans' hCne (fun x hx y hxy => hmax x hx y (hle _ _ hxy)) have hC₁ch : C₁ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₁max).1, hC₁sub⟩ have hwC : classWeight R C = 3 := by simp [classWeight, hmax, hmin] rw [hwC] exact le_trans (classWeight_ge_three_of_max (Finset.mem_filter.mp hC₁max).2) (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hC₁ch) · have hCne := class_nonempty hrefl hC obtain ⟨C₂, hC₂min, hC₂sub⟩ := exists_minClass_subset_downset hrefl' htrans' hCne (fun x hx y hxy => hmin x hx y (hle _ _ hxy)) have hC₂ch : C₂ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₂min).1, hC₂sub⟩ have hwC : classWeight R C = 3 := by simp [classWeight, hmax, hmin] rw [hwC] exact le_trans (classWeight_ge_three_of_min (Finset.mem_filter.mp hC₂min).2) (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hC₂ch) · have hwC : classWeight R C = 1 := by simp [classWeight, hmax, hmin] rw [hwC] obtain ⟨C₁, hC₁⟩ := childClasses_nonempty hrefl htrans hle hC exact le_trans (classWeight_ge_one R' C₁) (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hC₁) /-- When an isolated class splits (`2 ≤ (childClasses R' C).card`), its local weight increases by at least `2`. -/ lemma isolated_split_gain {R R' : B → B → Prop} (hrefl : ∀ z, R z z) (hrefl' : ∀ z, R' z z) (htrans' : ∀ a b c, R' a b → R' b c → R' a c) (hle : ∀ x y, R' x y → R x y) {C : Finset B} (hC : C ∈ classes R) (hmax : IsMaxClass R C) (hmin : IsMinClass R C) (hsplit : 2 ≤ (childClasses R' C).card) : classWeight R C + 2 ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by have hwC : classWeight R C = 4 := by simp [classWeight, hmax, hmin] rw [hwC] have hCne := class_nonempty hrefl hC obtain ⟨C₁, hC₁max, hC₁sub⟩ := exists_maxClass_subset_upset hrefl' htrans' hCne (fun x hx y hxy => hmax x hx y (hle _ _ hxy)) obtain ⟨C₂, hC₂min, hC₂sub⟩ := exists_minClass_subset_downset hrefl' htrans' hCne (fun x hx y hxy => hmin x hx y (hle _ _ hxy)) have hC₁ch : C₁ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₁max).1, hC₁sub⟩ have hC₂ch : C₂ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₂min).1, hC₂sub⟩ by_cases heq : C₁ = C₂ · subst heq have h1max : IsMaxClass R' C₁ := (Finset.mem_filter.mp hC₁max).2 have h1min : IsMinClass R' C₁ := (Finset.mem_filter.mp hC₂min).2 have h1w : classWeight R' C₁ = 4 := by simp [classWeight, h1max, h1min] have hdiff_ne : (C \ C₁).Nonempty := by obtain ⟨C₃, hC₃ch, hC₃ne⟩ := Finset.exists_mem_ne (by omega : 1 < (childClasses R' C).card) C₁ have hC₃mem := Finset.mem_filter.mp hC₃ch obtain ⟨x, hx⟩ := class_nonempty hrefl' hC₃mem.1 refine ⟨x, Finset.mem_sdiff.mpr ⟨hC₃mem.2 hx, fun hx1 => ?_⟩⟩ exact hC₃ne ((class_eq_eqvClass htrans' hC₃mem.1 hx).trans (class_eq_eqvClass htrans' (Finset.mem_filter.mp hC₁max).1 hx1).symm) have hdiff_up : ∀ x ∈ C \ C₁, ∀ y : B, R' x y → y ∈ C \ C₁ := by intro x hx y hxy rw [Finset.mem_sdiff] at hx ⊢ refine ⟨hmax x hx.1 y (hle _ _ hxy), fun hy1 => hx.2 (h1min y hy1 x hxy)⟩ obtain ⟨C₃, hC₃max, hC₃sub⟩ := exists_maxClass_subset_upset hrefl' htrans' hdiff_ne hdiff_up have hC₃ch : C₃ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter] exact ⟨(Finset.mem_filter.mp hC₃max).1, Finset.Subset.trans hC₃sub Finset.sdiff_subset⟩ have hC₃ne : C₃ ≠ C₁ := by intro h obtain ⟨x, hx⟩ := class_nonempty hrefl' (Finset.mem_filter.mp hC₃max).1 exact (Finset.mem_sdiff.mp (hC₃sub hx)).2 (h ▸ hx) have h3w := classWeight_ge_three_of_max (Finset.mem_filter.mp hC₃max).2 have hpair : ({C₁, C₃} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₃ch have hsum : classWeight R' C₁ + classWeight R' C₃ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₃ = ∑ C' ∈ ({C₁, C₃} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair hC₃ne.symm] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have h1w := classWeight_ge_three_of_max (Finset.mem_filter.mp hC₁max).2 have h2w := classWeight_ge_three_of_min (Finset.mem_filter.mp hC₂min).2 have hpair : ({C₁, C₂} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₂ch have hsum : classWeight R' C₁ + classWeight R' C₂ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₂ = ∑ C' ∈ ({C₁, C₂} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair heq] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega /-- Any splitting class gains at least `1` in local weight. -/ lemma split_gain_ge_one {R R' : B → B → Prop} (hrefl : ∀ z, R z z) (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) (htrans' : ∀ a b c, R' a b → R' b c → R' a c) (hle : ∀ x y, R' x y → R x y) {C : Finset B} (hC : C ∈ classes R) (hsplit : 2 ≤ (childClasses R' C).card) : classWeight R C + 1 ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by by_cases hmax : IsMaxClass R C <;> by_cases hmin : IsMinClass R C · have h := isolated_split_gain hrefl hrefl' htrans' hle hC hmax hmin hsplit omega · have hCne := class_nonempty hrefl hC obtain ⟨C₁, hC₁max, hC₁sub⟩ := exists_maxClass_subset_upset hrefl' htrans' hCne (fun x hx y hxy => hmax x hx y (hle _ _ hxy)) have hC₁ch : C₁ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₁max).1, hC₁sub⟩ obtain ⟨C₂, hC₂ch, hC₂ne⟩ := Finset.exists_mem_ne (by omega : 1 < (childClasses R' C).card) C₁ have hwC : classWeight R C = 3 := by simp [classWeight, hmax, hmin] have h1w := classWeight_ge_three_of_max (Finset.mem_filter.mp hC₁max).2 have h2w := classWeight_ge_one R' C₂ have hpair : ({C₁, C₂} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₂ch have hsum : classWeight R' C₁ + classWeight R' C₂ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₂ = ∑ C' ∈ ({C₁, C₂} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair hC₂ne.symm] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have hCne := class_nonempty hrefl hC obtain ⟨C₁, hC₁min, hC₁sub⟩ := exists_minClass_subset_downset hrefl' htrans' hCne (fun x hx y hxy => hmin x hx y (hle _ _ hxy)) have hC₁ch : C₁ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₁min).1, hC₁sub⟩ obtain ⟨C₂, hC₂ch, hC₂ne⟩ := Finset.exists_mem_ne (by omega : 1 < (childClasses R' C).card) C₁ have hwC : classWeight R C = 3 := by simp [classWeight, hmax, hmin] have h1w := classWeight_ge_three_of_min (Finset.mem_filter.mp hC₁min).2 have h2w := classWeight_ge_one R' C₂ have hpair : ({C₁, C₂} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₂ch have hsum : classWeight R' C₁ + classWeight R' C₂ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₂ = ∑ C' ∈ ({C₁, C₂} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair hC₂ne.symm] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have hwC : classWeight R C = 1 := by simp [classWeight, hmax, hmin] obtain ⟨C₁, hC₁ch⟩ := childClasses_nonempty hrefl htrans hle hC obtain ⟨C₂, hC₂ch, hC₂ne⟩ := Finset.exists_mem_ne (by omega : 1 < (childClasses R' C).card) C₁ have hpair : ({C₁, C₂} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₂ch have hsum : classWeight R' C₁ + classWeight R' C₂ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₂ = ∑ C' ∈ ({C₁, C₂} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair hC₂ne.symm] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair have := classWeight_ge_one R' C₁ have := classWeight_ge_one R' C₂ omega /-- Any class that gains a new maximal child (when it was not maximal) or gains a second maximal child gains at least `1` in local weight. -/ lemma new_max_child_gain {R R' : B → B → Prop} (hrefl : ∀ z, R z z) (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) (htrans' : ∀ a b c, R' a b → R' b c → R' a c) (hle : ∀ x y, R' x y → R x y) {C : Finset B} (hC : C ∈ classes R) (hgain : (¬ IsMaxClass R C ∧ ∃ C' ∈ childClasses R' C, IsMaxClass R' C') ∨ 2 ≤ ((childClasses R' C).filter (IsMaxClass R')).card) : classWeight R C + 1 ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by rcases hgain with ⟨hnmax, C₁, hC₁ch, hC₁max⟩ | h2max · by_cases hmin : IsMinClass R C · have hwC : classWeight R C = 3 := by simp [classWeight, hnmax, hmin] have hCne := class_nonempty hrefl hC obtain ⟨C₂, hC₂min, hC₂sub⟩ := exists_minClass_subset_downset hrefl' htrans' hCne (fun x hx y hxy => hmin x hx y (hle _ _ hxy)) have hC₂ch : C₂ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₂min).1, hC₂sub⟩ by_cases heq : C₁ = C₂ · subst heq have h1w : classWeight R' C₁ = 4 := by simp [classWeight, hC₁max, (Finset.mem_filter.mp hC₂min).2] have := Finset.single_le_sum (f := classWeight R') (fun _ _ => Nat.zero_le _) hC₁ch omega · have h1w := classWeight_ge_three_of_max hC₁max have h2w := classWeight_ge_three_of_min (Finset.mem_filter.mp hC₂min).2 have hpair : ({C₁, C₂} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₂ch have hsum : classWeight R' C₁ + classWeight R' C₂ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₂ = ∑ C' ∈ ({C₁, C₂} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair heq] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have hwC : classWeight R C = 1 := by simp [classWeight, hnmax, hmin] have h1w := classWeight_ge_three_of_max hC₁max have := Finset.single_le_sum (f := classWeight R') (fun _ _ => Nat.zero_le _) hC₁ch omega · have hsplit : 2 ≤ (childClasses R' C).card := le_trans h2max (Finset.card_le_card (Finset.filter_subset _ _)) exact split_gain_ge_one hrefl htrans hrefl' htrans' hle hC hsplit /-- Dual of `new_max_child_gain`. -/ lemma new_min_child_gain {R R' : B → B → Prop} (hrefl : ∀ z, R z z) (htrans : ∀ a b c, R a b → R b c → R a c) (hrefl' : ∀ z, R' z z) (htrans' : ∀ a b c, R' a b → R' b c → R' a c) (hle : ∀ x y, R' x y → R x y) {C : Finset B} (hC : C ∈ classes R) (hgain : (¬ IsMinClass R C ∧ ∃ C' ∈ childClasses R' C, IsMinClass R' C') ∨ 2 ≤ ((childClasses R' C).filter (IsMinClass R')).card) : classWeight R C + 1 ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by have heqvR : eqvClass (fun x y => R y x) = eqvClass R := by funext x; ext y; simp [eqvClass, and_comm] have heqvR' : eqvClass (fun x y => R' y x) = eqvClass R' := by funext x; ext y; simp [eqvClass, and_comm] have hwR : classWeight (fun x y => R y x) = classWeight R := funext (classWeight_flip R) have hwR' : classWeight (fun x y => R' y x) = classWeight R' := funext (classWeight_flip R') have h := new_max_child_gain (R := fun x y => R y x) (R' := fun x y => R' y x) hrefl (fun a b c hab hbc => htrans c b a hbc hab) hrefl' (fun a b c hab hbc => htrans' c b a hbc hab) (fun x y hxy => hle y x hxy) (C := C) simp only [classes, childClasses, IsMaxClass, heqvR, heqvR', hwR, hwR'] at h ⊢ exact h hC hgain /-- If a class `C` splits AND (`¬ IsMinClass R C` with a minimal child, OR `¬ IsMaxClass R C` with a maximal child), then its local weight increases by at least `2`. -/ lemma split_with_new_extremal_gain {R R' : B → B → Prop} (hrefl : ∀ z, R z z) (hrefl' : ∀ z, R' z z) (htrans' : ∀ a b c, R' a b → R' b c → R' a c) (hle : ∀ x y, R' x y → R x y) {C : Finset B} (hC : C ∈ classes R) (hsplit : 2 ≤ (childClasses R' C).card) (hnew : (¬ IsMinClass R C ∧ ∃ C' ∈ childClasses R' C, IsMinClass R' C') ∨ (¬ IsMaxClass R C ∧ ∃ C' ∈ childClasses R' C, IsMaxClass R' C')) : classWeight R C + 2 ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by rcases hnew with ⟨hnmin, C₂, hC₂ch, hC₂min⟩ | ⟨hnmax, C₁, hC₁ch, hC₁max⟩ · by_cases hmax : IsMaxClass R C · have hwC : classWeight R C = 3 := by simp [classWeight, hmax, hnmin] have hCne := class_nonempty hrefl hC obtain ⟨C₁, hC₁max, hC₁sub⟩ := exists_maxClass_subset_upset hrefl' htrans' hCne (fun x hx y hxy => hmax x hx y (hle _ _ hxy)) have hC₁ch : C₁ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₁max).1, hC₁sub⟩ by_cases heq : C₁ = C₂ · subst heq have h1w : classWeight R' C₁ = 4 := by simp [classWeight, (Finset.mem_filter.mp hC₁max).2, hC₂min] obtain ⟨C₃, hC₃ch, hC₃ne⟩ := Finset.exists_mem_ne (by omega : 1 < (childClasses R' C).card) C₁ have h3w := classWeight_ge_one R' C₃ have hpair : ({C₁, C₃} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₃ch have hsum : classWeight R' C₁ + classWeight R' C₃ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₃ = ∑ C' ∈ ({C₁, C₃} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair hC₃ne.symm] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have h1w := classWeight_ge_three_of_max (Finset.mem_filter.mp hC₁max).2 have h2w := classWeight_ge_three_of_min hC₂min have hpair : ({C₁, C₂} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₂ch have hsum : classWeight R' C₁ + classWeight R' C₂ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₂ = ∑ C' ∈ ({C₁, C₂} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair heq] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have hwC : classWeight R C = 1 := by simp [classWeight, hmax, hnmin] have h2w := classWeight_ge_three_of_min hC₂min have := Finset.single_le_sum (f := classWeight R') (fun _ _ => Nat.zero_le _) hC₂ch omega · by_cases hmin : IsMinClass R C · have hwC : classWeight R C = 3 := by simp [classWeight, hnmax, hmin] have hCne := class_nonempty hrefl hC obtain ⟨C₂, hC₂min, hC₂sub⟩ := exists_minClass_subset_downset hrefl' htrans' hCne (fun x hx y hxy => hmin x hx y (hle _ _ hxy)) have hC₂ch : C₂ ∈ childClasses R' C := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC₂min).1, hC₂sub⟩ by_cases heq : C₁ = C₂ · subst heq have h1w : classWeight R' C₁ = 4 := by simp [classWeight, hC₁max, (Finset.mem_filter.mp hC₂min).2] obtain ⟨C₃, hC₃ch, hC₃ne⟩ := Finset.exists_mem_ne (by omega : 1 < (childClasses R' C).card) C₁ have h3w := classWeight_ge_one R' C₃ have hpair : ({C₁, C₃} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₃ch have hsum : classWeight R' C₁ + classWeight R' C₃ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₃ = ∑ C' ∈ ({C₁, C₃} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair hC₃ne.symm] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have h1w := classWeight_ge_three_of_max hC₁max have h2w := classWeight_ge_three_of_min (Finset.mem_filter.mp hC₂min).2 have hpair : ({C₁, C₂} : Finset (Finset B)) ⊆ childClasses R' C := by intro x hx; rcases Finset.mem_insert.mp hx with rfl | hx · exact hC₁ch · rw [Finset.mem_singleton.mp hx]; exact hC₂ch have hsum : classWeight R' C₁ + classWeight R' C₂ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := by calc classWeight R' C₁ + classWeight R' C₂ = ∑ C' ∈ ({C₁, C₂} : Finset (Finset B)), classWeight R' C' := by rw [Finset.sum_pair heq] _ ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := Finset.sum_le_sum_of_subset hpair omega · have hwC : classWeight R C = 1 := by simp [classWeight, hnmax, hmin] have h1w := classWeight_ge_three_of_max hC₁max have := Finset.single_le_sum (f := classWeight R') (fun _ _ => Nat.zero_le _) hC₁ch omega end FinitePreorder section TransitivePermPreorder variable {B I : Type*} /-- Action of a word `w : List I` via a family of permutations `perm : I → Equiv.Perm B`. -/ def evalP (perm : I → Equiv.Perm B) : B → List I → B | x, [] => x | x, a :: w => evalP perm (perm a x) w @[simp] lemma evalP_nil (perm : I → Equiv.Perm B) (x : B) : evalP perm x [] = x := rfl @[simp] lemma evalP_cons (perm : I → Equiv.Perm B) (x : B) (a : I) (w : List I) : evalP perm x (a :: w) = evalP perm (perm a x) w := rfl lemma evalP_append (perm : I → Equiv.Perm B) (x : B) (w₁ w₂ : List I) : evalP perm x (w₁ ++ w₂) = evalP perm (evalP perm x w₁) w₂ := by induction w₁ generalizing x with | nil => rfl | cons a w₁ ih => simp [ih] /-- The `j`-step refinement preorder `x ◁_j y` with respect to `T : Finset B`. -/ def preordP (perm : I → Equiv.Perm B) (T : Finset B) (j : ℕ) (x y : B) : Prop := ∀ w : List I, w.length ≤ j → (evalP perm x w ∈ T → evalP perm y w ∈ T) lemma preordP_refl (perm : I → Equiv.Perm B) (T : Finset B) (j : ℕ) (x : B) : preordP perm T j x x := fun _ _ h => h lemma preordP_trans (perm : I → Equiv.Perm B) (T : Finset B) (j : ℕ) {x y z : B} (h₁ : preordP perm T j x y) (h₂ : preordP perm T j y z) : preordP perm T j x z := fun w hw hx => h₂ w hw (h₁ w hw hx) lemma preordP_succ_iff (perm : I → Equiv.Perm B) (T : Finset B) (j : ℕ) (x y : B) : preordP perm T (j + 1) x y ↔ preordP perm T j x y ∧ ∀ a : I, preordP perm T j (perm a x) (perm a y) := by constructor · intro h refine ⟨fun w hw => h w (Nat.le_succ_of_le hw), fun a w hw => ?_⟩ have hlen : (a :: w).length ≤ j + 1 := by simp; omega exact h (a :: w) hlen · rintro ⟨h₀, h₁⟩ w hw cases w with | nil => exact h₀ [] (Nat.zero_le j) | cons a w' => have hlen : w'.length ≤ j := by simp at hw; omega exact h₁ a w' hlen lemma preordP_antitone (perm : I → Equiv.Perm B) (T : Finset B) {j₁ j₂ : ℕ} (hle : j₁ ≤ j₂) {x y : B} (h : preordP perm T j₂ x y) : preordP perm T j₁ x y := fun w hw => h w (le_trans hw hle) variable [Fintype B] lemma preordP_compl_iff (perm : I → Equiv.Perm B) (T : Finset B) (j : ℕ) (x y : B) : preordP perm Tᶜ j x y ↔ preordP perm T j y x := by simp only [preordP, Finset.mem_compl] constructor · intro h w hw hy by_contra hx exact h w hw hx hy · intro h w hw hx hy exact hx (h w hw hy) lemma maxClasses_compl_eq_minClasses (perm : I → Equiv.Perm B) (T : Finset B) (j : ℕ) : maxClasses (preordP perm Tᶜ j) = minClasses (preordP perm T j) := by have hR : preordP perm Tᶜ j = fun x y => preordP perm T j y x := by funext x y; exact propext (preordP_compl_iff perm T j x y) have heqv : eqvClass (fun x y => preordP perm T j y x) = eqvClass (preordP perm T j) := by funext x; ext y; simp [eqvClass, and_comm] rw [hR] ext C simp only [maxClasses, minClasses, classes, Finset.mem_filter, heqv, IsMaxClass, IsMinClass] /-- **Max-Progress Lemma**: On a faithful transitive permutation system `(B, perm, T)`, at any step `j`, if `(maxClasses (preordP j + 1)).card = (maxClasses (preordP j)).card` AND every maximal class `C ∈ maxClasses (preordP j)` remains unsplit, then `preordP j` is ALREADY equality on `B`! -/ lemma max_progress_lemma (perm : I → Equiv.Perm B) (T : Finset B) (htrans : ∀ x y : B, ∃ w : List I, evalP perm x w = y) (hfaith : ∀ x y : B, (∀ w : List I, evalP perm x w ∈ T ↔ evalP perm y w ∈ T) → x = y) (j : ℕ) (hcard : (maxClasses (preordP perm T (j + 1))).card = (maxClasses (preordP perm T j)).card) (hnosplit : ∀ C ∈ maxClasses (preordP perm T j), C ∈ maxClasses (preordP perm T (j + 1))) : ∀ x y : B, preordP perm T j x y → x = y := by set R := preordP perm T j set R' := preordP perm T (j + 1) have hrefl : ∀ z, R z z := preordP_refl perm T j have htransR : ∀ a b c, R a b → R b c → R a c := fun _ _ _ => preordP_trans perm T j have hrefl' : ∀ z, R' z z := preordP_refl perm T (j + 1) have htransR' : ∀ a b c, R' a b → R' b c → R' a c := fun _ _ _ => preordP_trans perm T (j + 1) have hmax_eq : maxClasses R' = maxClasses R := (Finset.eq_of_subset_of_card_le hnosplit (le_of_eq hcard)).symm have hpull_upset : ∀ a : I, ∀ C ∈ maxClasses R, ∃ D ∈ maxClasses R, D ⊆ C.image (perm a).symm := by intro a C hC have hCmem := Finset.mem_filter.mp hC have hCne := class_nonempty hrefl hCmem.1 have hU_ne : (C.image (perm a).symm).Nonempty := hCne.image _ have hU_up : ∀ x ∈ C.image (perm a).symm, ∀ y : B, R' x y → y ∈ C.image (perm a).symm := by intro x hx y hxy obtain ⟨u, huC, rfl⟩ := Finset.mem_image.mp hx have hstep : R (perm a ((perm a).symm u)) (perm a y) := ((preordP_succ_iff perm T j _ _).mp hxy).2 a rw [Equiv.apply_symm_apply] at hstep have hyC : perm a y ∈ C := hCmem.2 u huC (perm a y) hstep exact Finset.mem_image.mpr ⟨perm a y, hyC, (perm a).symm_apply_apply y⟩ obtain ⟨D, hD, hDsub⟩ := exists_maxClass_subset_upset hrefl' htransR' hU_ne hU_up rw [hmax_eq] at hD exact ⟨D, hD, hDsub⟩ have hperm_max : ∀ a : I, ∀ C ∈ maxClasses R, C.image (perm a).symm ∈ maxClasses R := by intro a choose φ hφ_mem hφ_sub using hpull_upset a let f : Finset B → Finset B := fun C => if h : C ∈ maxClasses R then φ C h else ∅ have hφ_inj : Set.InjOn f (maxClasses R : Set (Finset B)) := by intro C₁ h₁ C₂ h₂ heq have h₁' : C₁ ∈ maxClasses R := h₁ have h₂' : C₂ ∈ maxClasses R := h₂ have heq' : φ C₁ h₁' = φ C₂ h₂' := by simpa [f, h₁', h₂'] using heq by_contra hne obtain ⟨x, hx⟩ := class_nonempty hrefl (Finset.mem_filter.mp (hφ_mem C₁ h₁')).1 have hx₁ : x ∈ C₁.image (perm a).symm := hφ_sub C₁ h₁' hx have hx₂ : x ∈ C₂.image (perm a).symm := hφ_sub C₂ h₂' (heq' ▸ hx) obtain ⟨u₁, hu₁, hux₁⟩ := Finset.mem_image.mp hx₁ obtain ⟨u₂, hu₂, hux₂⟩ := Finset.mem_image.mp hx₂ have hu_eq : u₁ = u₂ := (perm a).symm.injective (hux₁.trans hux₂.symm) subst hu_eq exact Finset.disjoint_left.mp (classes_pairwise_disjoint htransR (Finset.mem_filter.mp h₁').1 (Finset.mem_filter.mp h₂').1 hne) hu₁ hu₂ have hf_maps : (maxClasses R).image f = maxClasses R := by refine Finset.eq_of_subset_of_card_le ?_ ?_ · intro D hD obtain ⟨C, hC, rfl⟩ := Finset.mem_image.mp hD simp only [f, hC, ↓reduceDIte] exact hφ_mem C hC · rw [Finset.card_image_of_injOn hφ_inj] have hsum_eq : ∑ C ∈ maxClasses R, (f C).card = ∑ C ∈ maxClasses R, (C.image (perm a).symm).card := by calc ∑ C ∈ maxClasses R, (f C).card = ∑ D ∈ (maxClasses R).image f, D.card := (Finset.sum_image hφ_inj).symm _ = ∑ D ∈ maxClasses R, D.card := by rw [hf_maps] _ = ∑ C ∈ maxClasses R, (C.image (perm a).symm).card := Finset.sum_congr rfl (fun C _ => (Finset.card_image_of_injective C (perm a).symm.injective).symm) have hle_each : ∀ C ∈ maxClasses R, (f C).card ≤ (C.image (perm a).symm).card := by intro C hC simp only [f, hC, ↓reduceDIte] exact Finset.card_le_card (hφ_sub C hC) have heq_each : ∀ C ∈ maxClasses R, (f C).card = (C.image (perm a).symm).card := by intro C hC by_contra hne have hlt : (f C).card < (C.image (perm a).symm).card := lt_of_le_of_ne (hle_each C hC) hne have hsum_lt := Finset.sum_lt_sum hle_each ⟨C, hC, hlt⟩ omega intro C hC have hsub : f C ⊆ C.image (perm a).symm := by simp only [f, hC, ↓reduceDIte]; exact hφ_sub C hC have hEq : f C = C.image (perm a).symm := Finset.eq_of_subset_of_card_le hsub (le_of_eq (heq_each C hC).symm) rw [← hEq] simp only [f, hC, ↓reduceDIte] exact hφ_mem C hC have hperm_fwd : ∀ a : I, ∀ C ∈ maxClasses R, C.image (perm a) ∈ maxClasses R := by intro a have hinj : Set.InjOn (fun C : Finset B => C.image (perm a).symm) (maxClasses R : Set (Finset B)) := by intro C₁ _ C₂ _ h ext x have hx := Finset.ext_iff.mp h ((perm a).symm x) simp only [Finset.mem_image, (perm a).symm.injective.eq_iff, exists_eq_right] at hx exact hx have hsurj : (maxClasses R).image (fun C : Finset B => C.image (perm a).symm) = maxClasses R := by refine Finset.eq_of_subset_of_card_le ?_ ?_ · intro D hD obtain ⟨C, hC, rfl⟩ := Finset.mem_image.mp hD exact hperm_max a C hC · rw [Finset.card_image_of_injOn hinj] intro C hC have hC' : C ∈ (maxClasses R).image (fun D : Finset B => D.image (perm a).symm) := by rw [hsurj]; exact hC obtain ⟨D, hD, hDeq⟩ := Finset.mem_image.mp hC' have hEq : C.image (perm a) = D := by rw [← hDeq] ext x simp only [Finset.mem_image] constructor · rintro ⟨_, ⟨u, huD, rfl⟩, rfl⟩; simpa using huD · intro hxD; exact ⟨(perm a).symm x, ⟨x, hxD, rfl⟩, (perm a).apply_symm_apply x⟩ rw [hEq] exact hD let U : Finset B := (maxClasses R).biUnion id have hU_inv : ∀ w : List I, ∀ x ∈ U, evalP perm x w ∈ U := by intro w induction w with | nil => intro x hx; exact hx | cons a w ih => intro x hx apply ih obtain ⟨C, hC, hxC⟩ := Finset.mem_biUnion.mp hx exact Finset.mem_biUnion.mpr ⟨C.image (perm a), hperm_fwd a C hC, Finset.mem_image.mpr ⟨x, hxC, rfl⟩⟩ have hclass_sing : ∀ C ∈ maxClasses R, ∀ u ∈ C, ∀ v ∈ C, u = v := by have hstay : ∀ w : List I, ∀ C ∈ maxClasses R, ∀ u ∈ C, ∀ v ∈ C, ∃ D ∈ maxClasses R, evalP perm u w ∈ D ∧ evalP perm v w ∈ D := by intro w induction w with | nil => intro C hC u hu v hv; exact ⟨C, hC, hu, hv⟩ | cons a w ih => intro C hC u hu v hv exact ih (C.image (perm a)) (hperm_fwd a C hC) (perm a u) (Finset.mem_image.mpr ⟨u, hu, rfl⟩) (perm a v) (Finset.mem_image.mpr ⟨v, hv, rfl⟩) intro C hC u hu v hv apply hfaith u v intro w obtain ⟨D, hD, huD, hvD⟩ := hstay w C hC u hu v hv have hDeq : eqvClass R (evalP perm u w) = D := (class_eq_eqvClass htransR (Finset.mem_filter.mp hD).1 huD).symm have huv : evalP perm v w ∈ eqvClass R (evalP perm u w) := hDeq ▸ hvD rw [mem_eqvClass] at huv exact ⟨huv.1 [] (Nat.zero_le j), huv.2 [] (Nat.zero_le j)⟩ intro x y hxy have hBne : (Finset.univ : Finset B).Nonempty := ⟨x, Finset.mem_univ x⟩ obtain ⟨C₀, hC₀, _⟩ := exists_maxClass_subset_upset hrefl htransR hBne (fun _ _ z _ => Finset.mem_univ z) obtain ⟨x₀, hx₀⟩ := class_nonempty hrefl (Finset.mem_filter.mp hC₀).1 have hx₀U : x₀ ∈ U := Finset.mem_biUnion.mpr ⟨C₀, hC₀, hx₀⟩ obtain ⟨w, rfl⟩ := htrans x₀ x have hxU : evalP perm x₀ w ∈ U := hU_inv w x₀ hx₀U obtain ⟨C, hC, hxC⟩ := Finset.mem_biUnion.mp hxU have hyC : y ∈ C := (Finset.mem_filter.mp hC).2 _ hxC y hxy exact hclass_sing C hC _ hxC y hyC /-- **Min-Progress Lemma** (by exact order-duality via `Tᶜ`). -/ lemma min_progress_lemma (perm : I → Equiv.Perm B) (T : Finset B) (htrans : ∀ x y : B, ∃ w : List I, evalP perm x w = y) (hfaith : ∀ x y : B, (∀ w : List I, evalP perm x w ∈ T ↔ evalP perm y w ∈ T) → x = y) (j : ℕ) (hcard : (minClasses (preordP perm T (j + 1))).card = (minClasses (preordP perm T j)).card) (hnosplit : ∀ C ∈ minClasses (preordP perm T j), C ∈ minClasses (preordP perm T (j + 1))) : ∀ x y : B, preordP perm T j x y → x = y := by have hfaith_c : ∀ x y : B, (∀ w : List I, evalP perm x w ∈ Tᶜ ↔ evalP perm y w ∈ Tᶜ) → x = y := by intro x y h apply hfaith x y intro w have hw := h w simp only [Finset.mem_compl] at hw tauto have h := max_progress_lemma perm Tᶜ htrans hfaith_c j (by simpa [maxClasses_compl_eq_minClasses] using hcard) (by simpa [maxClasses_compl_eq_minClasses] using hnosplit) intro x y hxy exact (h y x ((preordP_compl_iff perm T j y x).mpr hxy)).symm /-- Monotonicity of `maxClasses` cardinality. -/ lemma maxClasses_card_mono (perm : I → Equiv.Perm B) (T : Finset B) (j : ℕ) : (maxClasses (preordP perm T j)).card ≤ (maxClasses (preordP perm T (j + 1))).card := by set R := preordP perm T j set R' := preordP perm T (j + 1) have hrefl := preordP_refl perm T j have htransR := fun a b c => preordP_trans perm T j (x := a) (y := b) (z := c) have hrefl' := preordP_refl perm T (j + 1) have htransR' := fun a b c => preordP_trans perm T (j + 1) (x := a) (y := b) (z := c) have hle : ∀ x y, R' x y → R x y := fun _ _ h => (preordP_succ_iff perm T j _ _).mp h |>.1 have hpick : ∀ C ∈ maxClasses R, ∃ C' ∈ maxClasses R', C' ⊆ C := by intro C hC have hCm := Finset.mem_filter.mp hC exact exists_maxClass_subset_upset hrefl' htransR' (class_nonempty hrefl hCm.1) (fun x hx y hxy => hCm.2 x hx y (hle _ _ hxy)) choose φ hφ_mem hφ_sub using hpick let f : Finset B → Finset B := fun C => if h : C ∈ maxClasses R then φ C h else ∅ have hinj : Set.InjOn f (maxClasses R : Set (Finset B)) := by intro C₁ h₁ C₂ h₂ heq have h₁' : C₁ ∈ maxClasses R := h₁ have h₂' : C₂ ∈ maxClasses R := h₂ have heq' : φ C₁ h₁' = φ C₂ h₂' := by simpa [f, h₁', h₂'] using heq by_contra hne obtain ⟨x, hx⟩ := class_nonempty hrefl' (Finset.mem_filter.mp (hφ_mem C₁ h₁')).1 exact Finset.disjoint_left.mp (classes_pairwise_disjoint htransR (Finset.mem_filter.mp h₁').1 (Finset.mem_filter.mp h₂').1 hne) (hφ_sub C₁ h₁' hx) (hφ_sub C₂ h₂' (heq' ▸ hx)) calc (maxClasses R).card = ((maxClasses R).image f).card := (Finset.card_image_of_injOn hinj).symm _ ≤ (maxClasses R').card := Finset.card_le_card (by intro D hD obtain ⟨C, hC, rfl⟩ := Finset.mem_image.mp hD simp only [f, hC, ↓reduceDIte] exact hφ_mem C hC) /-- **Phase 1 Strict Increment Theorem**: At every step `j` where at least one equivalence class splits (`(classes (preordP j)).card < (classes (preordP (j + 1))).card`), the potential `omegaPot` strictly increases by at least `2`! -/ lemma omegaPot_step_ge_two (perm : I → Equiv.Perm B) (T : Finset B) (htrans : ∀ x y : B, ∃ w : List I, evalP perm x w = y) (hfaith : ∀ x y : B, (∀ w : List I, evalP perm x w ∈ T ↔ evalP perm y w ∈ T) → x = y) (j : ℕ) (hsplit_global : (classes (preordP perm T j)).card < (classes (preordP perm T (j + 1))).card) : omegaPot (preordP perm T j) + 2 ≤ omegaPot (preordP perm T (j + 1)) := by set R := preordP perm T j set R' := preordP perm T (j + 1) have hrefl : ∀ z, R z z := preordP_refl perm T j have htransR : ∀ a b c, R a b → R b c → R a c := fun _ _ _ => preordP_trans perm T j have hrefl' : ∀ z, R' z z := preordP_refl perm T (j + 1) have htransR' : ∀ a b c, R' a b → R' b c → R' a c := fun _ _ _ => preordP_trans perm T (j + 1) have hle : ∀ x y, R' x y → R x y := fun _ _ h => (preordP_succ_iff perm T j _ _).mp h |>.1 have hnot_eq : ¬ ∀ x y : B, R x y → x = y := by intro heq have hcl_eq : classes R' = classes R := by have heq' : ∀ x y : B, R' x y → x = y := fun x y hxy => heq x y (hle x y hxy) have h1 : ∀ x : B, eqvClass R x = {x} := fun x => by ext y; rw [mem_eqvClass, Finset.mem_singleton] exact ⟨fun h => (heq x y h.1).symm, fun h => by subst h; exact ⟨hrefl y, hrefl y⟩⟩ have h2 : ∀ x : B, eqvClass R' x = {x} := fun x => by ext y; rw [mem_eqvClass, Finset.mem_singleton] exact ⟨fun h => (heq' x y h.1).symm, fun h => by subst h; exact ⟨hrefl' y, hrefl' y⟩⟩ change Finset.univ.image (eqvClass R') = Finset.univ.image (eqvClass R) congr 1; funext x; rw [h2 x, h1 x] rw [hcl_eq] at hsplit_global exact lt_irrefl _ hsplit_global have hex_split : ∃ C ∈ classes R, 2 ≤ (childClasses R' C).card := by by_contra hall push Not at hall have hcard_le : (classes R').card ≤ (classes R).card := by have hsum : (classes R').card = ∑ C ∈ classes R, (childClasses R' C).card := by simpa using sum_children_eq htransR hrefl' hle (fun _ => 1) rw [hsum] calc ∑ C ∈ classes R, (childClasses R' C).card ≤ ∑ _C ∈ classes R, 1 := Finset.sum_le_sum (fun C hC => Nat.lt_succ_iff.mp (hall C hC)) _ = (classes R).card := by simp omega have hsum_eq : omegaPot R' = ∑ C ∈ classes R, ∑ C' ∈ childClasses R' C, classWeight R' C' := sum_children_eq htransR hrefl' hle (classWeight R') have hloc : ∀ C ∈ classes R, classWeight R C ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' := fun C hC => local_weight_le hrefl htransR hrefl' htransR' hle hC have hfrom_one : ∀ C ∈ classes R, classWeight R C + 2 ≤ ∑ C' ∈ childClasses R' C, classWeight R' C' → omegaPot R + 2 ≤ omegaPot R' := by intro C hC hgain2 rw [hsum_eq, omegaPot, ← Finset.add_sum_erase _ _ hC, ← Finset.add_sum_erase _ _ hC] have hrest : ∑ D ∈ (classes R).erase C, classWeight R D ≤ ∑ D ∈ (classes R).erase C, ∑ C' ∈ childClasses R' D, classWeight R' C' := Finset.sum_le_sum (fun D hD => hloc D (Finset.mem_of_mem_erase hD)) omega have hfrom_two : ∀ C₁ ∈ classes R, ∀ C₂ ∈ classes R, C₁ ≠ C₂ → classWeight R C₁ + 1 ≤ ∑ C' ∈ childClasses R' C₁, classWeight R' C' → classWeight R C₂ + 1 ≤ ∑ C' ∈ childClasses R' C₂, classWeight R' C' → omegaPot R + 2 ≤ omegaPot R' := by intro C₁ h₁ C₂ h₂ hne hg₁ hg₂ rw [hsum_eq, omegaPot, ← Finset.add_sum_erase _ _ h₁, ← Finset.add_sum_erase _ _ h₁] have h₂' : C₂ ∈ (classes R).erase C₁ := Finset.mem_erase.mpr ⟨hne.symm, h₂⟩ rw [← Finset.add_sum_erase _ _ h₂', ← Finset.add_sum_erase _ _ h₂'] have hrest : ∑ D ∈ ((classes R).erase C₁).erase C₂, classWeight R D ≤ ∑ D ∈ ((classes R).erase C₁).erase C₂, ∑ C' ∈ childClasses R' D, classWeight R' C' := Finset.sum_le_sum (fun D hD => hloc D (Finset.mem_of_mem_erase (Finset.mem_of_mem_erase hD))) omega have hmax_witness : ∃ D ∈ classes R, (IsMaxClass R D ∧ 2 ≤ (childClasses R' D).card) ∨ (¬ IsMaxClass R D ∧ ∃ C' ∈ childClasses R' D, IsMaxClass R' C') ∨ 2 ≤ ((childClasses R' D).filter (IsMaxClass R')).card := by by_cases hcard_eq : (maxClasses R').card = (maxClasses R).card · have hnotall : ¬ ∀ C ∈ maxClasses R, C ∈ maxClasses R' := fun hall => hnot_eq (max_progress_lemma perm T htrans hfaith j hcard_eq hall) push Not at hnotall obtain ⟨D, hDmax, hDnot⟩ := hnotall have hDm := Finset.mem_filter.mp hDmax refine ⟨D, hDm.1, Or.inl ⟨hDm.2, ?_⟩⟩ by_contra hlt2 have hpos : 1 ≤ (childClasses R' D).card := Finset.card_pos.mpr (childClasses_nonempty hrefl htransR hle hDm.1) have h1 : (childClasses R' D).card = 1 := by omega have hch := (childClasses_card_eq_one_iff htransR hrefl' hle hDm.1).mp h1 obtain ⟨C', hC'max, hC'sub⟩ := exists_maxClass_subset_upset hrefl' htransR' (class_nonempty hrefl hDm.1) (fun x hx y hxy => hDm.2 x hx y (hle _ _ hxy)) have hC'ch : C' ∈ childClasses R' D := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC'max).1, hC'sub⟩ rw [hch, Finset.mem_singleton] at hC'ch exact hDnot (hC'ch ▸ hC'max) · have hlt : (maxClasses R).card < (maxClasses R').card := lt_of_le_of_ne (maxClasses_card_mono perm T j) (Ne.symm hcard_eq) have hmax_part : (maxClasses R').card = ∑ D ∈ classes R, ((childClasses R' D).filter (IsMaxClass R')).card := by have hEq : maxClasses R' = (classes R).biUnion (fun D => (childClasses R' D).filter (IsMaxClass R')) := by ext C' simp only [maxClasses, Finset.mem_filter, Finset.mem_biUnion] rw [classes_eq_biUnion_children htransR hrefl' hle, Finset.mem_biUnion] constructor · rintro ⟨⟨D, hD, hch⟩, hm⟩; exact ⟨D, hD, hch, hm⟩ · rintro ⟨D, hD, hch, hm⟩; exact ⟨⟨D, hD, hch⟩, hm⟩ rw [hEq, Finset.card_biUnion] intro D₁ h₁ D₂ h₂ hne exact Disjoint.mono (Finset.filter_subset _ _) (Finset.filter_subset _ _) (childClasses_pairwise_disjoint htransR hrefl' h₁ h₂ hne) by_contra hnone push Not at hnone have hle_sum : ∑ D ∈ classes R, ((childClasses R' D).filter (IsMaxClass R')).card ≤ (maxClasses R).card := by calc ∑ D ∈ classes R, ((childClasses R' D).filter (IsMaxClass R')).card ≤ ∑ D ∈ classes R, (if IsMaxClass R D then 1 else 0) := by refine Finset.sum_le_sum (fun D hD => ?_) obtain ⟨_, h2, h3⟩ := hnone D hD by_cases hDm : IsMaxClass R D · simp only [hDm, ↓reduceIte]; omega · simp only [hDm, ↓reduceIte] have hempty : (childClasses R' D).filter (IsMaxClass R') = ∅ := by rw [Finset.filter_eq_empty_iff] intro C' hC'; exact h2 hDm C' hC' rw [hempty, Finset.card_empty] _ = (maxClasses R).card := by rw [maxClasses, Finset.card_filter] omega have hmin_witness : ∃ D ∈ classes R, (IsMinClass R D ∧ 2 ≤ (childClasses R' D).card) ∨ (¬ IsMinClass R D ∧ ∃ C' ∈ childClasses R' D, IsMinClass R' C') ∨ 2 ≤ ((childClasses R' D).filter (IsMinClass R')).card := by by_cases hcard_eq : (minClasses R').card = (minClasses R).card · have hnotall : ¬ ∀ C ∈ minClasses R, C ∈ minClasses R' := fun hall => hnot_eq (min_progress_lemma perm T htrans hfaith j hcard_eq hall) push Not at hnotall obtain ⟨D, hDmin, hDnot⟩ := hnotall have hDm := Finset.mem_filter.mp hDmin refine ⟨D, hDm.1, Or.inl ⟨hDm.2, ?_⟩⟩ by_contra hlt2 have hpos : 1 ≤ (childClasses R' D).card := Finset.card_pos.mpr (childClasses_nonempty hrefl htransR hle hDm.1) have h1 : (childClasses R' D).card = 1 := by omega have hch := (childClasses_card_eq_one_iff htransR hrefl' hle hDm.1).mp h1 obtain ⟨C', hC'min, hC'sub⟩ := exists_minClass_subset_downset hrefl' htransR' (class_nonempty hrefl hDm.1) (fun x hx y hxy => hDm.2 x hx y (hle _ _ hxy)) have hC'ch : C' ∈ childClasses R' D := by rw [childClasses, Finset.mem_filter]; exact ⟨(Finset.mem_filter.mp hC'min).1, hC'sub⟩ rw [hch, Finset.mem_singleton] at hC'ch exact hDnot (hC'ch ▸ hC'min) · have hmono_min : (minClasses R).card ≤ (minClasses R').card := by simpa [R, R', maxClasses_compl_eq_minClasses] using maxClasses_card_mono perm Tᶜ j have hlt : (minClasses R).card < (minClasses R').card := lt_of_le_of_ne hmono_min (Ne.symm hcard_eq) have hmin_part : (minClasses R').card = ∑ D ∈ classes R, ((childClasses R' D).filter (IsMinClass R')).card := by have hEq : minClasses R' = (classes R).biUnion (fun D => (childClasses R' D).filter (IsMinClass R')) := by ext C' simp only [minClasses, Finset.mem_filter, Finset.mem_biUnion] rw [classes_eq_biUnion_children htransR hrefl' hle, Finset.mem_biUnion] constructor · rintro ⟨⟨D, hD, hch⟩, hm⟩; exact ⟨D, hD, hch, hm⟩ · rintro ⟨D, hD, hch, hm⟩; exact ⟨⟨D, hD, hch⟩, hm⟩ rw [hEq, Finset.card_biUnion] intro D₁ h₁ D₂ h₂ hne exact Disjoint.mono (Finset.filter_subset _ _) (Finset.filter_subset _ _) (childClasses_pairwise_disjoint htransR hrefl' h₁ h₂ hne) by_contra hnone push Not at hnone have hle_sum : ∑ D ∈ classes R, ((childClasses R' D).filter (IsMinClass R')).card ≤ (minClasses R).card := by calc ∑ D ∈ classes R, ((childClasses R' D).filter (IsMinClass R')).card ≤ ∑ D ∈ classes R, (if IsMinClass R D then 1 else 0) := by refine Finset.sum_le_sum (fun D hD => ?_) obtain ⟨_, h2, h3⟩ := hnone D hD by_cases hDm : IsMinClass R D · simp only [hDm, ↓reduceIte]; omega · simp only [hDm, ↓reduceIte] have hempty : (childClasses R' D).filter (IsMinClass R') = ∅ := by rw [Finset.filter_eq_empty_iff] intro C' hC'; exact h2 hDm C' hC' rw [hempty, Finset.card_empty] _ = (minClasses R).card := by rw [minClasses, Finset.card_filter] omega obtain ⟨C, hC, hCsplit⟩ := hex_split by_cases hCmax : IsMaxClass R C <;> by_cases hCmin : IsMinClass R C · exact hfrom_one C hC (isolated_split_gain hrefl hrefl' htransR' hle hC hCmax hCmin hCsplit) · obtain ⟨D, hD, hDw⟩ := hmin_witness by_cases hCD : D = C · rcases hCD with rfl rcases hDw with ⟨hmin', _⟩ | ⟨_, C', hC'ch, hC'min⟩ | h2min · exact False.elim (hCmin hmin') · exact hfrom_one D hC (split_with_new_extremal_gain hrefl hrefl' htransR' hle hC hCsplit (Or.inl ⟨hCmin, C', hC'ch, hC'min⟩)) · obtain ⟨C', hC'mem⟩ := Finset.card_pos.mp (by omega : 0 < ((childClasses R' D).filter (IsMinClass R')).card) have hC'f := Finset.mem_filter.mp hC'mem exact hfrom_one D hC (split_with_new_extremal_gain hrefl hrefl' htransR' hle hC hCsplit (Or.inl ⟨hCmin, C', hC'f.1, hC'f.2⟩)) · have hDgain : classWeight R D + 1 ≤ ∑ C' ∈ childClasses R' D, classWeight R' C' := by rcases hDw with ⟨_, hDs⟩ | hnew | h2min · exact split_gain_ge_one hrefl htransR hrefl' htransR' hle hD hDs · exact new_min_child_gain hrefl htransR hrefl' htransR' hle hD (Or.inl hnew) · exact new_min_child_gain hrefl htransR hrefl' htransR' hle hD (Or.inr h2min) exact hfrom_two C hC D hD (Ne.symm hCD) (split_gain_ge_one hrefl htransR hrefl' htransR' hle hC hCsplit) hDgain · obtain ⟨D, hD, hDw⟩ := hmax_witness by_cases hCD : D = C · rcases hCD with rfl rcases hDw with ⟨hmax', _⟩ | ⟨_, C', hC'ch, hC'max⟩ | h2max · exact False.elim (hCmax hmax') · exact hfrom_one D hC (split_with_new_extremal_gain hrefl hrefl' htransR' hle hC hCsplit (Or.inr ⟨hCmax, C', hC'ch, hC'max⟩)) · obtain ⟨C', hC'mem⟩ := Finset.card_pos.mp (by omega : 0 < ((childClasses R' D).filter (IsMaxClass R')).card) have hC'f := Finset.mem_filter.mp hC'mem exact hfrom_one D hC (split_with_new_extremal_gain hrefl hrefl' htransR' hle hC hCsplit (Or.inr ⟨hCmax, C', hC'f.1, hC'f.2⟩)) · have hDgain : classWeight R D + 1 ≤ ∑ C' ∈ childClasses R' D, classWeight R' C' := by rcases hDw with ⟨_, hDs⟩ | hnew | h2max · exact split_gain_ge_one hrefl htransR hrefl' htransR' hle hD hDs · exact new_max_child_gain hrefl htransR hrefl' htransR' hle hD (Or.inl hnew) · exact new_max_child_gain hrefl htransR hrefl' htransR' hle hD (Or.inr h2max) exact hfrom_two C hC D hD (Ne.symm hCD) (split_gain_ge_one hrefl htransR hrefl' htransR' hle hC hCsplit) hDgain · obtain ⟨D, hD, hDw⟩ := hmax_witness by_cases hCD : D = C · rcases hCD with rfl rcases hDw with ⟨hmax', _⟩ | ⟨_, C', hC'ch, hC'max⟩ | h2max · exact False.elim (hCmax hmax') · exact hfrom_one D hC (split_with_new_extremal_gain hrefl hrefl' htransR' hle hC hCsplit (Or.inr ⟨hCmax, C', hC'ch, hC'max⟩)) · obtain ⟨C', hC'mem⟩ := Finset.card_pos.mp (by omega : 0 < ((childClasses R' D).filter (IsMaxClass R')).card) have hC'f := Finset.mem_filter.mp hC'mem exact hfrom_one D hC (split_with_new_extremal_gain hrefl hrefl' htransR' hle hC hCsplit (Or.inr ⟨hCmax, C', hC'f.1, hC'f.2⟩)) · have hDgain : classWeight R D + 1 ≤ ∑ C' ∈ childClasses R' D, classWeight R' C' := by rcases hDw with ⟨_, hDs⟩ | hnew | h2max · exact split_gain_ge_one hrefl htransR hrefl' htransR' hle hD hDs · exact new_max_child_gain hrefl htransR hrefl' htransR' hle hD (Or.inl hnew) · exact new_max_child_gain hrefl htransR hrefl' htransR' hle hD (Or.inr h2max) exact hfrom_two C hC D hD (Ne.symm hCD) (split_gain_ge_one hrefl htransR hrefl' htransR' hle hC hCsplit) hDgain /-- **Phase 1 Summary Lemma**: On a faithful transitive permutation system `(B, perm, T)` with nonempty proper `T`, there exists a stabilization step `j₀` at which all `≡_{j₀}` classes are singletons and `j₀ + min H L ≤ (7k - 10) / 4`. -/ lemma preorder_phase1_summary (perm : I → Equiv.Perm B) (T : Finset B) (htrans : ∀ x y : B, ∃ w : List I, evalP perm x w = y) (hfaith : ∀ x y : B, (∀ w : List I, evalP perm x w ∈ T ↔ evalP perm y w ∈ T) → x = y) (hTne : T.Nonempty) (hTlt : T.card < Fintype.card B) : ∃ j₀ : ℕ, (∀ x y : B, preordP perm T j₀ x y → preordP perm T j₀ y x → x = y) ∧ j₀ + min (Fintype.card B - (maxClasses (preordP perm T j₀)).card) (Fintype.card B - (minClasses (preordP perm T j₀)).card) ≤ (7 * Fintype.card B - 10) / 4 := by set k := Fintype.card B have hk2 : 2 ≤ k := by have hpos : 1 ≤ T.card := Finset.card_pos.mpr hTne omega have hTcne : Tᶜ.Nonempty := by rw [Finset.nonempty_iff_ne_empty] intro hemp have hTu : T = Finset.univ := by ext x; simp only [Finset.mem_univ, iff_true] by_contra hnx have : x ∈ Tᶜ := Finset.mem_compl.mpr hnx rw [hemp] at this; exact Finset.notMem_empty x this rw [hTu, Finset.card_univ] at hTlt exact lt_irrefl _ hTlt have h0_eqv : ∀ x : B, eqvClass (preordP perm T 0) x = if x ∈ T then T else Tᶜ := by intro x ext y simp only [mem_eqvClass, preordP] by_cases hx : x ∈ T · simp only [hx, ↓reduceIte] constructor · intro h; exact h.1 [] (Nat.le_refl 0) hx · intro hy; refine ⟨fun w hw _ => ?_, fun w hw _ => ?_⟩ · cases w with | nil => exact hy | cons _ _ => simp at hw · cases w with | nil => exact hx | cons _ _ => simp at hw · simp only [hx, ↓reduceIte, Finset.mem_compl] constructor · intro h hy; exact hx (h.2 [] (Nat.le_refl 0) hy) · intro hny; refine ⟨fun w hw hxw => ?_, fun w hw hyw => ?_⟩ · cases w with | nil => exact False.elim (hx hxw) | cons _ _ => simp at hw · cases w with | nil => exact False.elim (hny hyw) | cons _ _ => simp at hw have hT_ne_Tc : T ≠ Tᶜ := by intro h obtain ⟨x, hx⟩ := hTne exact (Finset.mem_compl.mp (h ▸ hx)) hx have h0_classes : classes (preordP perm T 0) = {T, Tᶜ} := by ext C simp only [classes, Finset.mem_image, Finset.mem_univ, true_and, Finset.mem_insert, Finset.mem_singleton] constructor · rintro ⟨x, rfl⟩ rw [h0_eqv x] split_ifs <;> [exact Or.inl rfl; exact Or.inr rfl] · rintro (rfl | rfl) · obtain ⟨x, hx⟩ := hTne; exact ⟨x, by rw [h0_eqv x, if_pos hx]⟩ · obtain ⟨x, hx⟩ := hTcne; exact ⟨x, by rw [h0_eqv x, if_neg (Finset.mem_compl.mp hx)]⟩ have h0_card : (classes (preordP perm T 0)).card = 2 := by rw [h0_classes, Finset.card_pair hT_ne_Tc] have h0_T_max : IsMaxClass (preordP perm T 0) T := fun x hx y hxy => hxy [] (Nat.le_refl 0) hx have h0_T_nmin : ¬ IsMinClass (preordP perm T 0) T := by intro hmin obtain ⟨x, hx⟩ := hTne; obtain ⟨y, hy⟩ := hTcne have hyx : preordP perm T 0 y x := fun w hw hyw => by cases w with | nil => exact False.elim ((Finset.mem_compl.mp hy) hyw) | cons _ _ => simp at hw exact (Finset.mem_compl.mp hy) (hmin x hx y hyx) have h0_Tc_min : IsMinClass (preordP perm T 0) Tᶜ := fun x hx y hyx => by rw [Finset.mem_compl] at hx ⊢; intro hy; exact hx (hyx [] (Nat.le_refl 0) hy) have h0_Tc_nmax : ¬ IsMaxClass (preordP perm T 0) Tᶜ := by intro hmax obtain ⟨x, hx⟩ := hTne; obtain ⟨y, hy⟩ := hTcne have hyx : preordP perm T 0 y x := fun w hw hyw => by cases w with | nil => exact False.elim ((Finset.mem_compl.mp hy) hyw) | cons _ _ => simp at hw exact (Finset.mem_compl.mp (hmax y hy x hyx)) hx have h0_omega : omegaPot (preordP perm T 0) = 6 := by rw [omegaPot, h0_classes, Finset.sum_pair hT_ne_Tc] simp [classWeight, h0_T_max, h0_T_nmin, h0_Tc_min, h0_Tc_nmax] have hex_stab : ∃ j : ℕ, (classes (preordP perm T j)).card = (classes (preordP perm T (j + 1))).card := by by_contra hnone push Not at hnone have hgrow : ∀ j : ℕ, 2 + j ≤ (classes (preordP perm T j)).card := by intro j induction j with | zero => omega | succ j ih => have hle := card_classes_le_card_classes (preordP_refl perm T j) (fun _ _ _ => preordP_trans perm T j) (preordP_refl perm T (j + 1)) (fun _ _ h => (preordP_succ_iff perm T j _ _).mp h |>.1) have hne := hnone j omega have hbig := hgrow k have hcap := card_classes_le_fintype_card (preordP perm T k) omega have hj₀_ex : ∃ j₀ : ℕ, (classes (preordP perm T j₀)).card = (classes (preordP perm T (j₀ + 1))).card ∧ ∀ j < j₀, (classes (preordP perm T j)).card < (classes (preordP perm T (j + 1))).card := by refine ⟨Nat.find hex_stab, Nat.find_spec hex_stab, fun j hj => ?_⟩ have hle := card_classes_le_card_classes (preordP_refl perm T j) (fun _ _ _ => preordP_trans perm T j) (preordP_refl perm T (j + 1)) (fun _ _ h => (preordP_succ_iff perm T j _ _).mp h |>.1) exact lt_of_le_of_ne hle (Nat.find_min hex_stab hj) obtain ⟨j₀, hj₀_eq, hj₀_lt⟩ := hj₀_ex have hj₀_sing : ∀ x y : B, preordP perm T j₀ x y → preordP perm T j₀ y x → x = y := by have heqv_eq : ∀ x y : B, (preordP perm T j₀ x y ∧ preordP perm T j₀ y x) → (preordP perm T (j₀ + 1) x y ∧ preordP perm T (j₀ + 1) y x) := by intro x y hxy set R := preordP perm T j₀ set R' := preordP perm T (j₀ + 1) have hrefl : ∀ z, R z z := preordP_refl perm T j₀ have htransR : ∀ a b c, R a b → R b c → R a c := fun _ _ _ => preordP_trans perm T j₀ have hrefl' : ∀ z, R' z z := preordP_refl perm T (j₀ + 1) have hle : ∀ u v, R' u v → R u v := fun _ _ h => (preordP_succ_iff perm T j₀ _ _).mp h |>.1 have hsum : (classes R').card = ∑ C ∈ classes R, (childClasses R' C).card := by simpa using sum_children_eq htransR hrefl' hle (fun _ => 1) have hall1 : ∀ C ∈ classes R, (childClasses R' C).card = 1 := by intro C hC have hpos : 1 ≤ (childClasses R' C).card := Finset.card_pos.mpr (childClasses_nonempty hrefl htransR hle hC) by_contra hne1 have hge2 : 1 < (childClasses R' C).card := by omega have hgt : (classes R).card < ∑ D ∈ classes R, (childClasses R' D).card := by calc (classes R).card = ∑ _D ∈ classes R, 1 := by simp _ < ∑ D ∈ classes R, (childClasses R' D).card := Finset.sum_lt_sum (fun D hD => Finset.card_pos.mpr (childClasses_nonempty hrefl htransR hle hD)) ⟨C, hC, hge2⟩ rw [← hsum] at hgt omega have hCx : eqvClass R x ∈ classes R := Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩ have hch1 := (childClasses_card_eq_one_iff htransR hrefl' hle hCx).mp (hall1 _ hCx) have hRx_ch : eqvClass R' x ∈ childClasses R' (eqvClass R x) := by rw [childClasses, Finset.mem_filter] exact ⟨Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩, fun z hz => by rw [mem_eqvClass] at hz ⊢; exact ⟨hle _ _ hz.1, hle _ _ hz.2⟩⟩ rw [hch1, Finset.mem_singleton] at hRx_ch have hy : y ∈ eqvClass R' x := by rw [hRx_ch, mem_eqvClass]; exact hxy exact mem_eqvClass.mp hy have hstep : ∀ a : I, ∀ x y : B, (preordP perm T j₀ x y ∧ preordP perm T j₀ y x) → (preordP perm T j₀ (perm a x) (perm a y) ∧ preordP perm T j₀ (perm a y) (perm a x)) := by intro a x y hxy have h1 := heqv_eq x y hxy exact ⟨((preordP_succ_iff perm T j₀ x y).mp h1.1).2 a, ((preordP_succ_iff perm T j₀ y x).mp h1.2).2 a⟩ have hword : ∀ w : List I, ∀ x y : B, (preordP perm T j₀ x y ∧ preordP perm T j₀ y x) → (preordP perm T j₀ (evalP perm x w) (evalP perm y w) ∧ preordP perm T j₀ (evalP perm y w) (evalP perm x w)) := by intro w induction w with | nil => intro x y h; exact h | cons a w ih => intro x y h; exact ih (perm a x) (perm a y) (hstep a x y h) intro x y hxy hyx apply hfaith x y intro w have hw := hword w x y ⟨hxy, hyx⟩ exact ⟨hw.1 [] (Nat.zero_le j₀), hw.2 [] (Nat.zero_le j₀)⟩ have hj₀_card : (classes (preordP perm T j₀)).card = k := by have hsing : ∀ x : B, eqvClass (preordP perm T j₀) x = {x} := fun x => by ext y; rw [mem_eqvClass, Finset.mem_singleton] exact ⟨fun h => (hj₀_sing x y h.1 h.2).symm, fun h => by subst h; exact ⟨preordP_refl perm T j₀ y, preordP_refl perm T j₀ y⟩⟩ have hEq : classes (preordP perm T j₀) = Finset.univ.image (fun x : B => ({x} : Finset B)) := by change Finset.univ.image (eqvClass (preordP perm T j₀)) = _ congr 1; funext x; exact hsing x rw [hEq, Finset.card_image_of_injective _ (fun _ _ h => Finset.singleton_injective h), Finset.card_univ] have hphase1 : ∀ j ≤ j₀, 2 + j ≤ (classes (preordP perm T j)).card ∧ 6 + 2 * j ≤ omegaPot (preordP perm T j) := by intro j hj induction j with | zero => omega | succ j ih => have ⟨hc, ho⟩ := ih (Nat.le_of_succ_le hj) have hlt := hj₀_lt j hj have hgain := omegaPot_step_ge_two perm T htrans hfaith j hlt omega have ⟨hj₀_bound, hj₀_omega⟩ := hphase1 j₀ (le_refl j₀) rw [hj₀_card] at hj₀_bound have hmax_le_k : (maxClasses (preordP perm T j₀)).card ≤ k := by rw [← hj₀_card]; exact Finset.card_le_card (Finset.filter_subset _ _) have hmin_le_k : (minClasses (preordP perm T j₀)).card ≤ k := by rw [← hj₀_card]; exact Finset.card_le_card (Finset.filter_subset _ _) have homega_ub : omegaPot (preordP perm T j₀) ≤ k + 2 * (maxClasses (preordP perm T j₀)).card + 2 * (minClasses (preordP perm T j₀)).card := by set R := preordP perm T j₀ calc omegaPot R = ∑ C ∈ classes R, classWeight R C := rfl _ ≤ ∑ C ∈ classes R, (1 + (if IsMaxClass R C then 2 else 0) + (if IsMinClass R C then 2 else 0)) := by refine Finset.sum_le_sum (fun C _ => ?_) unfold classWeight; omega _ = (classes R).card + 2 * (maxClasses R).card + 2 * (minClasses R).card := by simp only [Finset.sum_add_distrib, Finset.sum_const, smul_eq_mul, mul_one, Finset.sum_ite, maxClasses, minClasses] ring _ = k + 2 * (maxClasses R).card + 2 * (minClasses R).card := by rw [hj₀_card] refine ⟨j₀, hj₀_sing, ?_⟩ have harith : ∀ (a b c d : ℕ), 2 + a ≤ d → 6 + 2 * a ≤ d + 2 * b + 2 * c → b ≤ d → c ≤ d → a + min (d - b) (d - c) ≤ (7 * d - 10) / 4 := by intro a b c d _ _ _ _; omega exact harith j₀ _ _ k hj₀_bound (le_trans hj₀_omega homega_ub) hmax_le_k hmin_le_k /-- **Abstract Preorder Symmetrization Bound**: On a faithful transitive permutation system `(B, perm, T)` with `k = Fintype.card B ≥ 2` and nonempty proper `T`, the preorder `preordP` becomes equality on `B` at step `D = (7 * k - 10) / 4`. -/ theorem abstract_preorder_symmetrization_bound (perm : I → Equiv.Perm B) (T : Finset B) (htrans : ∀ x y : B, ∃ w : List I, evalP perm x w = y) (hfaith : ∀ x y : B, (∀ w : List I, evalP perm x w ∈ T ↔ evalP perm y w ∈ T) → x = y) (hTne : T.Nonempty) (hTlt : T.card < Fintype.card B) : ∀ x y : B, preordP perm T ((7 * Fintype.card B - 10) / 4) x y → x = y := by set k := Fintype.card B obtain ⟨j₀, hj₀_sing, hcomb⟩ := preorder_phase1_summary perm T htrans hfaith hTne hTlt let H : ℕ := k - (maxClasses (preordP perm T j₀)).card let L : ℕ := k - (minClasses (preordP perm T j₀)).card have hall_sing : ∀ j ≥ j₀, ∀ x y : B, preordP perm T j x y → preordP perm T j y x → x = y := fun j hj x y hxy hyx => hj₀_sing x y (preordP_antitone perm T hj hxy) (preordP_antitone perm T hj hyx) have hsing_ge : ∀ j ≥ j₀, ∀ x : B, eqvClass (preordP perm T j) x = {x} := by intro j hj x ext y rw [mem_eqvClass, Finset.mem_singleton] exact ⟨fun h => (hall_sing j hj x y h.1 h.2).symm, fun h => by subst h; exact ⟨preordP_refl perm T j y, preordP_refl perm T j y⟩⟩ have hnosplit_ge : ∀ j ≥ j₀, ∀ C ∈ maxClasses (preordP perm T j), C ∈ maxClasses (preordP perm T (j + 1)) := by intro j hj C hC have hCm := Finset.mem_filter.mp hC obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp hCm.1 rw [maxClasses, Finset.mem_filter] refine ⟨?_, fun u hu v huv => hCm.2 u hu v ((preordP_succ_iff perm T j u v).mp huv).1⟩ rw [hsing_ge j hj x, ← hsing_ge (j + 1) (Nat.le_succ_of_le hj) x] exact Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩ have hnosplit_min_ge : ∀ j ≥ j₀, ∀ C ∈ minClasses (preordP perm T j), C ∈ minClasses (preordP perm T (j + 1)) := by intro j hj C hC have hCm := Finset.mem_filter.mp hC obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp hCm.1 rw [minClasses, Finset.mem_filter] refine ⟨?_, fun u hu v huv => hCm.2 u hu v ((preordP_succ_iff perm T j v u).mp huv).1⟩ rw [hsing_ge j hj x, ← hsing_ge (j + 1) (Nat.le_succ_of_le hj) x] exact Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩ have hphase2_max : ∀ x y : B, preordP perm T (j₀ + H) x y → x = y := by by_contra hnot have hgrow : ∀ r ≤ H, (maxClasses (preordP perm T j₀)).card + r ≤ (maxClasses (preordP perm T (j₀ + r))).card := by intro r hr induction r with | zero => simp | succ r ih => have hstep_le := maxClasses_card_mono perm T (j₀ + r) have hne : (maxClasses (preordP perm T (j₀ + r + 1))).card ≠ (maxClasses (preordP perm T (j₀ + r))).card := by intro heq have hall_eq := max_progress_lemma perm T htrans hfaith (j₀ + r) heq (hnosplit_ge (j₀ + r) (Nat.le_add_right j₀ r)) exact hnot (fun x y hxy => hall_eq x y (preordP_antitone perm T (by omega) hxy)) have := ih (Nat.le_of_succ_le hr) rw [show j₀ + (r + 1) = j₀ + r + 1 by omega] omega have hk_eq : (maxClasses (preordP perm T (j₀ + H))).card = k := by have hge := hgrow H (le_refl H) have hle : (maxClasses (preordP perm T (j₀ + H))).card ≤ k := le_trans (Finset.card_le_card (Finset.filter_subset _ _)) (card_classes_le_fintype_card _) omega have hnext_eq : (maxClasses (preordP perm T (j₀ + H + 1))).card = (maxClasses (preordP perm T (j₀ + H))).card := by have hge := maxClasses_card_mono perm T (j₀ + H) have hle : (maxClasses (preordP perm T (j₀ + H + 1))).card ≤ k := le_trans (Finset.card_le_card (Finset.filter_subset _ _)) (card_classes_le_fintype_card _) omega exact hnot (max_progress_lemma perm T htrans hfaith (j₀ + H) hnext_eq (hnosplit_ge (j₀ + H) (Nat.le_add_right j₀ H))) have hphase2_min : ∀ x y : B, preordP perm T (j₀ + L) x y → x = y := by by_contra hnot have hgrow : ∀ r ≤ L, (minClasses (preordP perm T j₀)).card + r ≤ (minClasses (preordP perm T (j₀ + r))).card := by intro r hr induction r with | zero => simp | succ r ih => have hstep_le : (minClasses (preordP perm T (j₀ + r))).card ≤ (minClasses (preordP perm T (j₀ + r + 1))).card := by simpa [maxClasses_compl_eq_minClasses] using maxClasses_card_mono perm Tᶜ (j₀ + r) have hne : (minClasses (preordP perm T (j₀ + r + 1))).card ≠ (minClasses (preordP perm T (j₀ + r))).card := by intro heq have hall_eq := min_progress_lemma perm T htrans hfaith (j₀ + r) heq (hnosplit_min_ge (j₀ + r) (Nat.le_add_right j₀ r)) exact hnot (fun x y hxy => hall_eq x y (preordP_antitone perm T (by omega) hxy)) have := ih (Nat.le_of_succ_le hr) rw [show j₀ + (r + 1) = j₀ + r + 1 by omega] omega have hk_eq : (minClasses (preordP perm T (j₀ + L))).card = k := by have hge := hgrow L (le_refl L) have hle : (minClasses (preordP perm T (j₀ + L))).card ≤ k := le_trans (Finset.card_le_card (Finset.filter_subset _ _)) (card_classes_le_fintype_card _) omega have hnext_eq : (minClasses (preordP perm T (j₀ + L + 1))).card = (minClasses (preordP perm T (j₀ + L))).card := by have hge : (minClasses (preordP perm T (j₀ + L))).card ≤ (minClasses (preordP perm T (j₀ + L + 1))).card := by simpa [maxClasses_compl_eq_minClasses] using maxClasses_card_mono perm Tᶜ (j₀ + L) have hle : (minClasses (preordP perm T (j₀ + L + 1))).card ≤ k := le_trans (Finset.card_le_card (Finset.filter_subset _ _)) (card_classes_le_fintype_card _) omega exact hnot (min_progress_lemma perm T htrans hfaith (j₀ + L) hnext_eq (hnosplit_min_ge (j₀ + L) (Nat.le_add_right j₀ L))) intro x y hxy by_cases hHL : H ≤ L · have hle : j₀ + H ≤ (7 * k - 10) / 4 := by omega exact hphase2_max x y (preordP_antitone perm T hle hxy) · have hle : j₀ + L ≤ (7 * k - 10) / 4 := by omega exact hphase2_min x y (preordP_antitone perm T hle hxy) /-- **Singleton / Co-singleton Exact `k - 1` Bound**: When `T.card = 1` or `T.card = Fintype.card B - 1`, `preordP` becomes equality on `B` at step `Fintype.card B - 1`. -/ theorem abstract_preorder_singleton_bound (perm : I → Equiv.Perm B) (T : Finset B) (htrans : ∀ x y : B, ∃ w : List I, evalP perm x w = y) (hcard : T.card = 1 ∨ T.card = Fintype.card B - 1) : ∀ x y : B, preordP perm T (Fintype.card B - 1) x y → x = y := by have hsing : ∀ U : Finset B, U.card = 1 → ∀ x y : B, preordP perm U (Fintype.card B - 1) x y → x = y := by intro U hU obtain ⟨u₀, rfl⟩ := Finset.card_eq_one.mp hU let Smax (j : ℕ) : Finset B := Finset.univ.filter (fun x => ∀ y : B, preordP perm {u₀} j x y → y = x) have h0 : u₀ ∈ Smax 0 := by simp only [Smax, Finset.mem_filter, Finset.mem_univ, true_and] intro y hy exact Finset.mem_singleton.mp (hy [] (Nat.le_refl 0) (Finset.mem_singleton_self u₀)) have hmono : ∀ j, Smax j ⊆ Smax (j + 1) := by intro j x hx simp only [Smax, Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢ intro y hy; exact hx y ((preordP_succ_iff perm {u₀} j x y).mp hy).1 have hpull : ∀ j (a : I), ∀ x ∈ Smax j, (perm a).symm x ∈ Smax (j + 1) := by intro j a x hx simp only [Smax, Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢ intro y hy have h1 : preordP perm {u₀} j (perm a ((perm a).symm x)) (perm a y) := ((preordP_succ_iff perm {u₀} j _ _).mp hy).2 a rw [Equiv.apply_symm_apply] at h1 have hpy : perm a y = x := hx (perm a y) h1 calc y = (perm a).symm (perm a y) := ((perm a).symm_apply_apply y).symm _ = (perm a).symm x := by rw [hpy] have hgrow : ∀ j, min (Fintype.card B) (1 + j) ≤ (Smax j).card := by intro j induction j with | zero => have h1 : 1 ≤ (Smax 0).card := Finset.card_pos.mpr ⟨u₀, h0⟩ omega | succ j ih => by_cases hfull : (Smax j).card = Fintype.card B · have hle := Finset.card_le_card (hmono j) omega · have hlt : (Smax j).card < (Smax (j + 1)).card := by by_contra hge have heq : Smax (j + 1) = Smax j := (Finset.eq_of_subset_of_card_le (hmono j) (by omega)).symm have hinv : ∀ a : I, ∀ x ∈ Smax j, perm a x ∈ Smax j := by intro a have hsub : (Smax j).image (perm a).symm ⊆ Smax j := by intro z hz obtain ⟨x, hx, rfl⟩ := Finset.mem_image.mp hz exact heq ▸ hpull j a x hx have heq_im : (Smax j).image (perm a).symm = Smax j := Finset.eq_of_subset_of_card_le hsub (by rw [Finset.card_image_of_injective _ (perm a).symm.injective]) intro x hx have hx' : x ∈ (Smax j).image (perm a).symm := by rw [heq_im]; exact hx obtain ⟨z, hz, hzx⟩ := Finset.mem_image.mp hx' have hax : perm a x = z := by rw [← hzx, Equiv.apply_symm_apply] exact hax ▸ hz have hinvW : ∀ w : List I, ∀ x ∈ Smax j, evalP perm x w ∈ Smax j := by intro w induction w with | nil => intro x hx; exact hx | cons a w ihw => intro x hx; exact ihw (perm a x) (hinv a x hx) have huniv : Smax j = Finset.univ := by ext z; simp only [Finset.mem_univ, iff_true] obtain ⟨w, rfl⟩ := htrans u₀ z have hu₀ : u₀ ∈ Smax j := by clear ih hfull hge heq hinv hinvW w induction j with | zero => exact h0 | succ m ihm => exact hmono m ihm exact hinvW w u₀ hu₀ rw [huniv, Finset.card_univ] at hfull exact hfull rfl omega have hall : Smax (Fintype.card B - 1) = Finset.univ := by apply Finset.eq_univ_of_card have hge := hgrow (Fintype.card B - 1) have hle := Finset.card_le_univ (Smax (Fintype.card B - 1)) have hpos : 0 < Fintype.card B := Fintype.card_pos_iff.mpr ⟨u₀⟩ omega intro x y hxy have hx : x ∈ Smax (Fintype.card B - 1) := hall ▸ Finset.mem_univ x simp only [Smax, Finset.mem_filter, Finset.mem_univ, true_and] at hx exact (hx y hxy).symm intro x y hxy rcases hcard with h1 | hnm1 · exact hsing T h1 x y hxy · have hTc : Tᶜ.card = 1 := by have hpos : 0 < Fintype.card B := Fintype.card_pos_iff.mpr ⟨x⟩ rw [Finset.card_compl] omega exact (hsing Tᶜ hTc y x ((preordP_compl_iff perm T _ y x).mpr hxy)).symm end TransitivePermPreorder end PreorderCore /-! ## Part 3: Lifting to DFAs, Effective Higman Strong Connectivity, and Connected-Orbital / Primitive Bounds -/ section PreorderDFA open Classical variable {Q α : Type*} [Fintype Q] [DecidableEq Q] /-- The `j`-step permutation-word refinement preorder of a subset `S ⊆ Q` in a DFA `A`. -/ def DFA.preord (A : DFA Q α) (S : Finset Q) (j : ℕ) (x y : Q) : Prop := ∀ w : List α, A.IsPermWord w → w.length ≤ j → A.eval x w ∈ S → A.eval y w ∈ S /-- The `G`-congruence `≡_∞` generated by membership in `S` under all permutation words. -/ def DFA.equivInf (A : DFA Q α) (S : Finset Q) (x y : Q) : Prop := ∀ w : List α, A.IsPermWord w → (A.eval x w ∈ S ↔ A.eval y w ∈ S) /-- `DFA.equivInf` as a `Setoid` on `Q`. -/ def DFA.equivInfSetoid (A : DFA Q α) (S : Finset Q) : Setoid Q where r := A.equivInf S iseqv := ⟨fun _ _ _ => Iff.rfl, fun h w hw => (h w hw).symm, fun h₁ h₂ w hw => (h₁ w hw).trans (h₂ w hw)⟩ omit [Fintype Q] [DecidableEq Q] in lemma DFA.preord_antitone (A : DFA Q α) (S : Finset Q) {j₁ j₂ : ℕ} (h : j₁ ≤ j₂) {x y : Q} (hxy : A.preord S j₂ x y) : A.preord S j₁ x y := fun w hw hlen hx => hxy w hw (le_trans hlen h) hx omit [Fintype Q] [DecidableEq Q] in lemma DFA.equivInf_step (A : DFA Q α) (S : Finset Q) {a : α} (ha : A.IsBijectiveLetter a) {x y : Q} (hxy : A.equivInf S x y) : A.equivInf S (A.step a x) (A.step a y) := by intro w hw have haw : A.IsPermWord (a :: w) := by intro b hb rcases List.mem_cons.mp hb with rfl | hb · exact ha · exact hw b hb simpa [DFA.eval_cons] using hxy (a :: w) haw omit [Fintype Q] [DecidableEq Q] in lemma DFA.equivInf_permWord (A : DFA Q α) (S : Finset Q) {w : List α} (hw : A.IsPermWord w) {x y : Q} (hxy : A.equivInf S x y) : A.equivInf S (A.eval x w) (A.eval y w) := by induction w generalizing x y with | nil => exact hxy | cons a w ih => exact ih (fun b hb => hw b (List.mem_cons_of_mem a hb)) (A.equivInf_step S (hw a List.mem_cons_self) hxy) omit [Fintype Q] [DecidableEq Q] in lemma DFA.permWord_lift (A : DFA Q α) : ∀ w : List α, A.IsPermWord w → ∃ w' : List {a : α // A.IsBijectiveLetter a}, w'.map Subtype.val = w ∧ w'.length = w.length | [], _ => ⟨[], rfl, rfl⟩ | a :: w, hw => by have ha : A.IsBijectiveLetter a := hw a List.mem_cons_self obtain ⟨w', hw'_map, hw'_len⟩ := A.permWord_lift w (fun b hb => hw b (List.mem_cons_of_mem a hb)) exact ⟨⟨a, ha⟩ :: w', by simp [hw'_map], by simp [hw'_len]⟩ omit [Fintype Q] [DecidableEq Q] in lemma DFA.isPermWord_map_val (A : DFA Q α) (w : List {a : α // A.IsBijectiveLetter a}) : A.IsPermWord (w.map Subtype.val) := by intro b hb obtain ⟨⟨a, ha⟩, _, rfl⟩ := List.mem_map.mp hb exact ha /-- **Quotient Preorder Symmetrization Theorem**: On any finite DFA `A` whose bijective letters generate a transitive permutation group on `Q`, for every nonempty proper subset `S ⊂ Q`, the refinement preorder `A.preord S D` symmetrizes to `A.equivInf S` at depth `D = (7 * k - 10) / 4`, where `k = |Q / ≡_∞|`. -/ theorem preorder_symmetrization_bound_quot (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (S : Finset Q) (hSne : S.Nonempty) (hSlt : S.card < Fintype.card Q) : ∀ x y : Q, A.preord S ((7 * Fintype.card (Quotient (A.equivInfSetoid S)) - 10) / 4) x y → A.equivInf S x y := by let sQ := A.equivInfSetoid S let B := Quotient sQ let mk : Q → B := Quotient.mk sQ let I := {a : α // A.IsBijectiveLetter a} have hstep_compat : ∀ (a : I) (x y : Q), sQ.r x y → sQ.r (A.step a.1 x) (A.step a.1 y) := fun a _ _ h => A.equivInf_step S a.2 h have hsymm_compat : ∀ (a : I) (x y : Q), sQ.r x y → sQ.r ((Equiv.ofBijective (A.step a.1) a.2).symm x) ((Equiv.ofBijective (A.step a.1) a.2).symm y) := by intro a x y hxy let g : Equiv.Perm Q := Equiv.ofBijective (A.step a.1) a.2 have hpow : ∀ m : ℕ, ∀ u v : Q, sQ.r u v → sQ.r ((g ^ m) u) ((g ^ m) v) := by intro m induction m with | zero => intro u v h; exact h | succ m ih => intro u v h have hstep : sQ.r (g u) (g v) := hstep_compat a u v h have h1 : (g ^ (m + 1)) u = (g ^ m) (g u) := by rw [pow_succ]; rfl have h2 : (g ^ (m + 1)) v = (g ^ m) (g v) := by rw [pow_succ]; rfl rw [h1, h2] exact ih (g u) (g v) hstep have hinv : g ^ (orderOf g - 1) = g⁻¹ := by apply mul_right_cancel (b := g) rw [← pow_succ, Nat.sub_add_cancel (orderOf_pos g), pow_orderOf_eq_one, inv_mul_cancel] have hsymm : g.symm = g⁻¹ := rfl change sQ.r (g.symm x) (g.symm y) rw [hsymm, ← hinv] exact hpow (orderOf g - 1) x y hxy let permQ : I → Equiv.Perm B := fun a => { toFun := Quotient.lift (fun x => mk (A.step a.1 x)) (fun x y h => Quotient.sound (hstep_compat a x y h)) invFun := Quotient.lift (fun x => mk ((Equiv.ofBijective (A.step a.1) a.2).symm x)) (fun x y h => Quotient.sound (hsymm_compat a x y h)) left_inv := fun q => Quotient.inductionOn q fun x => by change mk ((Equiv.ofBijective (A.step a.1) a.2).symm (A.step a.1 x)) = mk x congr 1 exact (Equiv.ofBijective (A.step a.1) a.2).symm_apply_apply x right_inv := fun q => Quotient.inductionOn q fun x => by change mk (A.step a.1 ((Equiv.ofBijective (A.step a.1) a.2).symm x)) = mk x congr 1 exact (Equiv.ofBijective (A.step a.1) a.2).apply_symm_apply x } have hevalQ : ∀ (w : List I) (x : Q), evalP permQ (mk x) w = mk (A.eval x (w.map Subtype.val)) := by intro w induction w with | nil => intro x; rfl | cons a w ih => intro x simp only [evalP_cons, List.map_cons, DFA.eval_cons] exact ih (A.step a.1 x) let T : Finset B := S.image mk have hmemT : ∀ x : Q, mk x ∈ T ↔ x ∈ S := by intro x simp only [T, Finset.mem_image] constructor · rintro ⟨z, hzS, hzx⟩ have heqv : A.equivInf S z x := Quotient.exact hzx exact (heqv [] (by simp [DFA.IsPermWord])).mp hzS · intro hxS; exact ⟨x, hxS, rfl⟩ have htransQ : ∀ p q : B, ∃ w : List I, evalP permQ p w = q := by intro p q obtain ⟨x, rfl⟩ := Quotient.exists_rep p obtain ⟨y, rfl⟩ := Quotient.exists_rep q obtain ⟨w, hw, hxy⟩ := (A.isPretransitive_iff_permWord.mp htrans) x y obtain ⟨w', hw'_map, _⟩ := A.permWord_lift w hw refine ⟨w', ?_⟩ change evalP permQ (mk x) w' = mk y rw [hevalQ, hw'_map, hxy] have hfaithQ : ∀ p q : B, (∀ w : List I, evalP permQ p w ∈ T ↔ evalP permQ q w ∈ T) → p = q := by intro p q h obtain ⟨x, rfl⟩ := Quotient.exists_rep p obtain ⟨y, rfl⟩ := Quotient.exists_rep q apply Quotient.sound intro w hw obtain ⟨w', hw'_map, _⟩ := A.permWord_lift w hw have h1 : evalP permQ (mk x) w' ∈ T ↔ evalP permQ (mk y) w' ∈ T := h w' rw [hevalQ, hevalQ, hw'_map, hmemT, hmemT] at h1 exact h1 have hTne : T.Nonempty := by obtain ⟨x, hx⟩ := hSne exact ⟨mk x, (hmemT x).mpr hx⟩ have hTlt : T.card < Fintype.card B := by have hnot : ∃ x : Q, x ∉ S := by by_contra hall push Not at hall have hSu : S = Finset.univ := Finset.eq_univ_iff_forall.mpr hall rw [hSu, Finset.card_univ] at hSlt exact lt_irrefl _ hSlt obtain ⟨x, hx⟩ := hnot have hnx : mk x ∉ T := fun h => hx ((hmemT x).mp h) have hsub : T ⊂ Finset.univ := Finset.ssubset_iff_subset_ne.mpr ⟨Finset.subset_univ T, fun h => hnx (h ▸ Finset.mem_univ _)⟩ simpa [Finset.card_univ] using Finset.card_lt_card hsub have hpreord_iff : ∀ (j : ℕ) (x y : Q), preordP permQ T j (mk x) (mk y) ↔ A.preord S j x y := by intro j x y constructor · intro h w hw hlen hxS obtain ⟨w', hw'_map, hw'_len⟩ := A.permWord_lift w hw have h1 := h w' (by omega) rw [hevalQ, hevalQ, hw'_map, hmemT, hmemT] at h1 exact h1 hxS · intro h w' hlen hxT rw [hevalQ, hmemT] at hxT ⊢ exact h (w'.map Subtype.val) (A.isPermWord_map_val w') (by simp [hlen]) hxT intro x y hxy have h1 := abstract_preorder_symmetrization_bound permQ T htransQ hfaithQ hTne hTlt (mk x) (mk y) ((hpreord_iff _ x y).mpr hxy) exact Quotient.exact h1 /-- **Headline Theorem 1 (Preorder Symmetrization Bound)**: For any transitive permutation group action generated by the bijective letters of `A` on `Q` (`n = |Q|`) and any nonempty proper subset `S ⊂ Q`, the refinement preorder `A.preord S D` symmetrizes to `A.equivInf S` at depth `D = (7 * n - 10) / 4`. -/ theorem preorder_symmetrization_bound (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (S : Finset Q) (hSne : S.Nonempty) (hSlt : S.card < Fintype.card Q) : ∀ x y : Q, A.preord S ((7 * Fintype.card Q - 10) / 4) x y → A.equivInf S x y := by have hk_le : Fintype.card (Quotient (A.equivInfSetoid S)) ≤ Fintype.card Q := Fintype.card_le_of_surjective (Quotient.mk (A.equivInfSetoid S)) Quotient.exists_rep have hD_le : (7 * Fintype.card (Quotient (A.equivInfSetoid S)) - 10) / 4 ≤ (7 * Fintype.card Q - 10) / 4 := Nat.div_le_div_right (by omega) intro x y hxy exact preorder_symmetrization_bound_quot A htrans S hSne hSlt x y (A.preord_antitone S hD_le hxy) omit [DecidableEq Q] in /-- **Singleton / Co-singleton Preorder Bound on DFAs**: When `|S| = 1` or `|S| = n - 1`, the refinement preorder `A.preord S (n - 1)` is already equality on `Q`. -/ theorem preorder_singleton_bound (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (S : Finset Q) (hcard : S.card = 1 ∨ S.card = Fintype.card Q - 1) : ∀ x y : Q, A.preord S (Fintype.card Q - 1) x y → x = y := by let I := {a : α // A.IsBijectiveLetter a} let permQ : I → Equiv.Perm Q := fun a => Equiv.ofBijective (A.step a.1) a.2 have hevalQ : ∀ (w : List I) (x : Q), evalP permQ x w = A.eval x (w.map Subtype.val) := by intro w induction w with | nil => intro x; rfl | cons a w ih => intro x simp only [evalP_cons, List.map_cons, DFA.eval_cons, ih] rfl have htransQ : ∀ x y : Q, ∃ w : List I, evalP permQ x w = y := by intro x y obtain ⟨w, hw, hxy⟩ := (A.isPretransitive_iff_permWord.mp htrans) x y obtain ⟨w', hw'_map, _⟩ := A.permWord_lift w hw exact ⟨w', by rw [hevalQ, hw'_map, hxy]⟩ intro x y hxy apply abstract_preorder_singleton_bound permQ S htransQ hcard x y intro w' hlen hxS rw [hevalQ] at hxS ⊢ exact hxy (w'.map Subtype.val) (A.isPermWord_map_val w') (by simp [hlen]) hxS end PreorderDFA section EffectiveHigman open Classical variable {Q α : Type*} [Fintype Q] [DecidableEq Q] /-- Directed edge in the depth-`D` orbital digraph `G_D(E₀)`: `(x, y)` is an image of an edge `(u, v)` of `E₀` under a permutation word of length at most `D`. -/ def orbEdge (A : DFA Q α) (E₀ : Q → Q → Prop) (D : ℕ) (x y : Q) : Prop := ∃ u v : Q, E₀ u v ∧ ∃ w : List α, A.IsPermWord w ∧ w.length ≤ D ∧ A.eval u w = x ∧ A.eval v w = y /-- Directed edge in the full `G`-orbital digraph `G_∞(E₀)`. -/ def orbEdgeInf (A : DFA Q α) (E₀ : Q → Q → Prop) (x y : Q) : Prop := ∃ u v : Q, E₀ u v ∧ ∃ w : List α, A.IsPermWord w ∧ A.eval u w = x ∧ A.eval v w = y /-- The orbital-component equivalence relation `C₀`: equivalence closure of `G_∞(E₀)`. -/ def orbConn (A : DFA Q α) (E₀ : Q → Q → Prop) : Q → Q → Prop := Relation.EqvGen (orbEdgeInf A E₀) /-- A subset `S ⊆ Q` is a union of equivalence classes (`C`-blocks) of `C`. -/ def IsBlockUnion (C : Q → Q → Prop) (S : Finset Q) : Prop := ∀ x y : Q, C x y → (x ∈ S ↔ y ∈ S) omit [Fintype Q] [DecidableEq Q] in lemma orbConn_equiv (A : DFA Q α) (E₀ : Q → Q → Prop) : Equivalence (orbConn A E₀) := Relation.EqvGen.is_equivalence _ omit [Fintype Q] [DecidableEq Q] in lemma orbConn_permWord (A : DFA Q α) (E₀ : Q → Q → Prop) {w : List α} (hw : A.IsPermWord w) {x y : Q} (h : orbConn A E₀ x y) : orbConn A E₀ (A.eval x w) (A.eval y w) := by induction h with | rel a b hab => obtain ⟨u, v, huv, w₁, hw₁, rfl, rfl⟩ := hab refine Relation.EqvGen.rel _ _ ⟨u, v, huv, w₁ ++ w, ?_, A.eval_append u w₁ w, A.eval_append v w₁ w⟩ intro c hc rcases List.mem_append.mp hc with hc | hc · exact hw₁ c hc · exact hw c hc | refl a => exact Relation.EqvGen.refl _ | symm a b _ ih => exact Relation.EqvGen.symm _ _ ih | trans a b c _ _ ih₁ ih₂ => exact Relation.EqvGen.trans _ _ _ ih₁ ih₂ /-- **Master Cut Lemma**: If `S` is a nonempty proper subset of `Q` that is NOT a union of `orbConn A E₀`-blocks, then `G_D(E₀)` has an outgoing edge from `S` to `Sᶜ` at depth `D = (7 * n - 10) / 4`. -/ lemma exists_short_outgoing_edge_of_not_blockUnion (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (E₀ : Q → Q → Prop) (S : Finset Q) (hSne : S.Nonempty) (hSlt : S.card < Fintype.card Q) (hnotB : ¬ IsBlockUnion (orbConn A E₀) S) : ∃ x y : Q, orbEdge A E₀ ((7 * Fintype.card Q - 10) / 4) x y ∧ x ∈ S ∧ y ∉ S := by by_contra hnone push Not at hnone have hpre : ∀ u v : Q, E₀ u v → A.preord S ((7 * Fintype.card Q - 10) / 4) u v := by intro u v huv w hw hlen huS exact hnone (A.eval u w) (A.eval v w) ⟨u, v, huv, w, hw, hlen, rfl, rfl⟩ huS have heqv : ∀ u v : Q, E₀ u v → A.equivInf S u v := fun u v huv => preorder_symmetrization_bound A htrans S hSne hSlt u v (hpre u v huv) have hsub : ∀ x y : Q, orbConn A E₀ x y → A.equivInf S x y := by intro x y hxy induction hxy with | rel a b hab => obtain ⟨u, v, huv, w, hw, rfl, rfl⟩ := hab exact A.equivInf_permWord S hw (heqv u v huv) | refl a => exact (A.equivInfSetoid S).iseqv.refl a | symm a b _ ih => exact (A.equivInfSetoid S).iseqv.symm ih | trans a b c _ _ ih₁ ih₂ => exact (A.equivInfSetoid S).iseqv.trans ih₁ ih₂ apply hnotB intro x y hxy exact hsub x y hxy [] (by simp [DFA.IsPermWord]) /-- **Headline Theorem 2 (Effective Higman Strong-Connectivity Radius)**: If the `G`-orbital digraph `G_∞(E₀)` of a transitive permutation group `G = ⟨Σ_P⟩` on `n` points is weakly connected, then its truncation `G_D(E₀)` at word length `D = (7 * n - 10) / 4` is strongly connected. -/ theorem effective_higman_strong_connectivity (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (E₀ : Q → Q → Prop) (hconn : ∀ x y : Q, orbConn A E₀ x y) : ∀ x y : Q, Relation.ReflTransGen (orbEdge A E₀ ((7 * Fintype.card Q - 10) / 4)) x y := by intro x y let R := orbEdge A E₀ ((7 * Fintype.card Q - 10) / 4) let S : Finset Q := Finset.univ.filter (fun z => Relation.ReflTransGen R x z) have hxS : x ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_univ x, Relation.ReflTransGen.refl⟩ by_contra hny have hyS : y ∉ S := fun h => hny (Finset.mem_filter.mp h).2 have hSlt : S.card < Fintype.card Q := by have hsub : S ⊂ Finset.univ := Finset.ssubset_iff_subset_ne.mpr ⟨Finset.subset_univ S, fun h => hyS (h ▸ Finset.mem_univ y)⟩ simpa [Finset.card_univ] using Finset.card_lt_card hsub have hnotB : ¬ IsBlockUnion (orbConn A E₀) S := by intro hB exact hyS ((hB x y (hconn x y)).mp hxS) obtain ⟨u, v, huv, huS, hvS⟩ := exists_short_outgoing_edge_of_not_blockUnion A htrans E₀ S ⟨x, hxS⟩ hSlt hnotB have hxu : Relation.ReflTransGen R x u := (Finset.mem_filter.mp huS).2 have hxv : Relation.ReflTransGen R x v := Relation.ReflTransGen.tail hxu huv exact hvS (Finset.mem_filter.mpr ⟨Finset.mem_univ v, hxv⟩) end EffectiveHigman section ConnectedOrbital open Classical variable {Q α : Type*} [Fintype Q] [DecidableEq Q] /-- Witness that `b : α` is a defect-1 letter with double-preimage state `s` and missing state `r`. -/ def defectPair (A : DFA Q α) (b : α) (s r : Q) : Prop := s ≠ r ∧ (∀ q : Q, A.step b q ≠ r) ∧ (Finset.univ.filter (fun q => A.step b q = s)).card = 2 ∧ ∀ S : Finset Q, (A.preimage S [b]).card + (if r ∈ S then 1 else 0) = S.card + (if s ∈ S then 1 else 0) /-- The generating edge relation `E₀` of defect-1 pairs `(s_b, r_b)`. -/ def defectEdges (A : DFA Q α) (s r : Q) : Prop := ∃ b : α, defectPair A b s r lemma exists_defectPair_of_synchronizing (A : DFA Q α) (hsync : A.IsSynchronizing) (hdef : A.HasDefectLeOne) (hn : 2 ≤ Fintype.card Q) : ∃ b : α, ∃ s r : Q, defectPair A b s r := by obtain ⟨w, q₀, hq₀⟩ := hsync have hnot_perm : ¬ A.IsPermWord w := by intro hpw have hbij := A.eval_bijective_of_permWord hpw have hcard_pos : 1 < Fintype.card Q := by omega obtain ⟨q₁, q₂, hne⟩ := Fintype.exists_pair_of_one_lt_card hcard_pos exact hne (hbij.1 ((hq₀ q₁).trans (hq₀ q₂).symm)) simp only [DFA.IsPermWord, not_forall] at hnot_perm obtain ⟨b, _, hnbij⟩ := hnot_perm obtain ⟨s, r, hne, hr, hs, hform⟩ := defect_one_structure (A.step b) (hdef b) hnbij refine ⟨b, s, r, hne, hr, hs, fun S => ?_⟩ have hpre : A.preimage S [b] = Finset.univ.filter (fun q => A.step b q ∈ S) := by ext q; simp only [DFA.mem_preimage, DFA.eval_cons, DFA.eval_nil, Finset.mem_filter, Finset.mem_univ, true_and] rw [hpre] exact hform S lemma extend_step_of_orbEdge (A : DFA Q α) {D : ℕ} {S : Finset Q} {x y : Q} (hxy : orbEdge A (defectEdges A) D x y) (hxS : x ∈ S) (hyS : y ∉ S) : ∃ w : List α, w.length ≤ D + 1 ∧ (A.preimage S w).card = S.card + 1 := by obtain ⟨s, r, ⟨b, _, _, _, hform⟩, w, hw, hlen, hsw, hrw⟩ := hxy refine ⟨b :: w, by simp [hlen], ?_⟩ rw [A.preimage_cons] have hcardT : (A.preimage S w).card = S.card := A.preimage_card_eq_of_permWord S hw have hsT : s ∈ A.preimage S w := by simp [hsw, hxS] have hrT : r ∉ A.preimage S w := by simp [hrw, hyS] have hf := hform (A.preimage S w) simp only [hsT, hrT, ↓reduceIte] at hf omega lemma extend_step_n_sub_one (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (hb : ∃ b : α, ∃ s r : Q, defectPair A b s r) {S : Finset Q} (hcard : S.card = Fintype.card Q - 1) : ∃ w : List α, w.length ≤ Fintype.card Q ∧ (A.preimage S w).card = Fintype.card Q := by obtain ⟨b, s, r, hne, _, _, hform⟩ := hb have hnot_pre : ¬ A.preord S (Fintype.card Q - 1) s r := fun h => hne (preorder_singleton_bound A htrans S (Or.inr hcard) s r h) simp only [DFA.preord, not_forall] at hnot_pre obtain ⟨w, hw, hlen, hs, hr⟩ := hnot_pre have hpos : 0 < Fintype.card Q := Fintype.card_pos_iff.mpr ⟨s⟩ refine ⟨b :: w, by simp; omega, ?_⟩ rw [A.preimage_cons] have hcardT : (A.preimage S w).card = S.card := A.preimage_card_eq_of_permWord S hw have hsT : s ∈ A.preimage S w := by simp [hs] have hrT : r ∉ A.preimage S w := by simp [hr] have hf := hform (A.preimage S w) simp only [hsT, hrT, ↓reduceIte] at hf omega /-- **Headline Theorem 3 (Connected-Orbital Synchronizing Bound)**: Every synchronizing `n`-state (`n ≥ 3`) defect-`≤ 1` DFA whose bijective letters generate a transitive permutation group and whose defect-1 pairs generate a connected orbital digraph admits a reset word of length at most `1 + n + (n - 3) * ((7 * n - 6) / 4)`, hence `4 * w.length + 23 * n ≤ 7 * n ^ 2 + 22`. -/ theorem reset_threshold_connected_orbital (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (hsync : A.IsSynchronizing) (hdef : A.HasDefectLeOne) (hconn : ∀ x y : Q, orbConn A (defectEdges A) x y) (hn : 3 ≤ Fintype.card Q) : ∃ w : List α, A.IsResetWord w ∧ w.length ≤ 1 + Fintype.card Q + (Fintype.card Q - 3) * ((7 * Fintype.card Q - 6) / 4) ∧ 4 * w.length + 23 * Fintype.card Q ≤ 7 * Fintype.card Q ^ 2 + 22 := by set n := Fintype.card Q have hb := exists_defectPair_of_synchronizing A hsync hdef (by omega) obtain ⟨b₀, s₀, r₀, hne₀, hr₀, hs₀, hform₀⟩ := hb have hb' : ∃ b : α, ∃ s r : Q, defectPair A b s r := ⟨b₀, s₀, r₀, hne₀, hr₀, hs₀, hform₀⟩ have hstep1 : ∃ w₁ : List α, w₁.length = 1 ∧ (A.preimage {s₀} w₁).card = 2 := by refine ⟨[b₀], rfl, ?_⟩ have hf := hform₀ {s₀} have hr_not : r₀ ∉ ({s₀} : Finset Q) := by simp [hne₀.symm] simp only [Finset.mem_singleton_self, hr_not, ↓reduceIte, Finset.card_singleton] at hf omega have hgrow : ∀ t : ℕ, 2 ≤ t → t ≤ n - 1 → ∃ w : List α, w.length ≤ 1 + (t - 2) * ((7 * n - 6) / 4) ∧ (A.preimage {s₀} w).card = t := by intro t ht2 ht_le induction t with | zero => omega | succ t ih => by_cases ht1 : t = 1 · subst ht1 obtain ⟨w₁, hw₁_len, hw₁_card⟩ := hstep1 exact ⟨w₁, by simp [hw₁_len], hw₁_card⟩ · obtain ⟨w, hw_len, hw_card⟩ := ih (by omega) (by omega) set S := A.preimage {s₀} w have hSne : S.Nonempty := Finset.card_pos.mp (by omega) have hSlt : S.card < n := by omega have hnotB : ¬ IsBlockUnion (orbConn A (defectEdges A)) S := by intro hB obtain ⟨x, hx⟩ := hSne have hnot_all : ∃ y : Q, y ∉ S := by by_contra hall; push Not at hall have hSu : S = Finset.univ := Finset.eq_univ_iff_forall.mpr hall rw [hSu, Finset.card_univ] at hSlt; exact lt_irrefl _ hSlt obtain ⟨y, hy⟩ := hnot_all exact hy ((hB x y (hconn x y)).mp hx) obtain ⟨x, y, hxy, hxS, hyS⟩ := exists_short_outgoing_edge_of_not_blockUnion A htrans (defectEdges A) S hSne hSlt hnotB obtain ⟨u, hu_len, hu_card⟩ := extend_step_of_orbEdge A hxy hxS hyS refine ⟨u ++ w, ?_, ?_⟩ · rw [List.length_append] have hdiv : (7 * n - 10) / 4 + 1 = (7 * n - 6) / 4 := by omega have hmul : (t + 1 - 2) * ((7 * n - 6) / 4) = (t - 2) * ((7 * n - 6) / 4) + (7 * n - 6) / 4 := by have : t + 1 - 2 = (t - 2) + 1 := by omega rw [this, Nat.add_mul, one_mul] omega · rw [A.preimage_append] change (A.preimage S u).card = t + 1 omega obtain ⟨w_mid, hw_mid_len, hw_mid_card⟩ := hgrow (n - 1) (by omega) (le_refl _) rw [show n - 1 - 2 = n - 3 by omega] at hw_mid_len obtain ⟨w_last, hw_last_len, hw_last_card⟩ := extend_step_n_sub_one A htrans hb' hw_mid_card refine ⟨w_last ++ w_mid, ?_, ?_, ?_⟩ · apply A.isResetWord_of_preimage_singleton s₀ rw [A.preimage_append] exact hw_last_card · rw [List.length_append] omega · rw [List.length_append] have hL : w_last.length + w_mid.length ≤ 1 + n + (n - 3) * ((7 * n - 6) / 4) := by omega have hmul4 : 4 * ((7 * n - 6) / 4) ≤ 7 * n - 6 := Nat.mul_div_le (7 * n - 6) 4 have hmul_step : 4 * ((n - 3) * ((7 * n - 6) / 4)) ≤ (n - 3) * (7 * n - 6) := by calc 4 * ((n - 3) * ((7 * n - 6) / 4)) = (n - 3) * (4 * ((7 * n - 6) / 4)) := by ring _ ≤ (n - 3) * (7 * n - 6) := Nat.mul_le_mul_left (n - 3) hmul4 have h4 : 4 * (w_last.length + w_mid.length) ≤ 4 + 4 * n + (n - 3) * (7 * n - 6) := by omega have h6 : 6 ≤ 7 * n := by omega zify [hn, h6] at h4 ⊢ nlinarith /-- A transitive permutation group action on `Q` is primitive if every `G`-invariant equivalence relation on `Q` is either equality or the universal relation. -/ def DFA.IsPrimitivePermGroup (A : DFA Q α) : Prop := MulAction.IsPretransitive A.permSubgroup Q ∧ ∀ C : Q → Q → Prop, Equivalence C → (∀ w : List α, A.IsPermWord w → ∀ x y : Q, C x y → C (A.eval x w) (A.eval y w)) → (∀ x y : Q, C x y → x = y) ∨ (∀ x y : Q, C x y) /-- **Headline Theorem 4 (Primitive Permutation Group Bound)**: Every synchronizing `n`-state (`n ≥ 3`) defect-`≤ 1` DFA whose bijective letters generate a primitive permutation group admits a reset word of length at most `1 + n + (n - 3) * ((7 * n - 6) / 4)` with `4 * w.length + 23 * n ≤ 7 * n ^ 2 + 22`. -/ theorem reset_threshold_primitive_defect_one (A : DFA Q α) (hprim : A.IsPrimitivePermGroup) (hsync : A.IsSynchronizing) (hdef : A.HasDefectLeOne) (hn : 3 ≤ Fintype.card Q) : ∃ w : List α, A.IsResetWord w ∧ w.length ≤ 1 + Fintype.card Q + (Fintype.card Q - 3) * ((7 * Fintype.card Q - 6) / 4) ∧ 4 * w.length + 23 * Fintype.card Q ≤ 7 * Fintype.card Q ^ 2 + 22 := by obtain ⟨htrans, hprim_eqv⟩ := hprim have hconn : ∀ x y : Q, orbConn A (defectEdges A) x y := by rcases hprim_eqv (orbConn A (defectEdges A)) (orbConn_equiv A _) (fun _ hw _ _ h => orbConn_permWord A _ hw h) with htriv | hall · obtain ⟨b, s, r, hne, hpair⟩ := exists_defectPair_of_synchronizing A hsync hdef (by omega) have hsr : orbConn A (defectEdges A) s r := Relation.EqvGen.rel s r ⟨s, r, ⟨b, hne, hpair⟩, [], by simp [DFA.IsPermWord], rfl, rfl⟩ exact False.elim (hne (htriv s r hsr)) · exact hall exact reset_threshold_connected_orbital A htrans hsync hdef hconn hn end ConnectedOrbital /-! ## Part 4: Imprimitive Orbital Congruence, Linear Algebra Block-Breaking, and the Full World Record -/ section ImprimitiveCerny open Classical variable {Q α : Type*} [Fintype Q] [DecidableEq Q] /-- Equivalence class (block) of `x` under an equivalence relation `C`. -/ noncomputable def congBlock (C : Q → Q → Prop) (x : Q) : Finset Q := Finset.univ.filter (fun y => C x y) /-- The set of all `C`-blocks. -/ noncomputable def congBlocks (C : Q → Q → Prop) : Finset (Finset Q) := Finset.univ.image (congBlock C) omit [DecidableEq Q] in lemma mem_congBlock {C : Q → Q → Prop} {x y : Q} : y ∈ congBlock C x ↔ C x y := by simp [congBlock] omit [DecidableEq Q] in lemma congBlock_eq_of_rel {C : Q → Q → Prop} (heqv : Equivalence C) {x y : Q} (h : C x y) : congBlock C x = congBlock C y := by ext z simp only [mem_congBlock] exact ⟨fun hx => heqv.trans (heqv.symm h) hx, fun hy => heqv.trans h hy⟩ lemma congBlocks_pairwise_disjoint {C : Q → Q → Prop} (heqv : Equivalence C) {B₁ B₂ : Finset Q} (h₁ : B₁ ∈ congBlocks C) (h₂ : B₂ ∈ congBlocks C) (hne : B₁ ≠ B₂) : Disjoint B₁ B₂ := by rw [Finset.disjoint_left] intro z hz₁ hz₂ obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp h₁ obtain ⟨y, _, rfl⟩ := Finset.mem_image.mp h₂ rw [mem_congBlock] at hz₁ hz₂ exact hne (congBlock_eq_of_rel heqv (heqv.trans hz₁ (heqv.symm hz₂))) lemma congBlock_card_const (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (C : Q → Q → Prop) (_heqv : Equivalence C) (hinv : ∀ w : List α, A.IsPermWord w → ∀ x y : Q, C x y → C (A.eval x w) (A.eval y w)) (x y : Q) : (congBlock C x).card = (congBlock C y).card := by have hle : ∀ u v : Q, (congBlock C u).card ≤ (congBlock C v).card := by intro u v obtain ⟨w, hw, huv⟩ := (A.isPretransitive_iff_permWord.mp htrans) u v have hinj := (A.eval_bijective_of_permWord hw).1 have hsub : (congBlock C u).image (fun q => A.eval q w) ⊆ congBlock C v := by intro z hz obtain ⟨q, hq, rfl⟩ := Finset.mem_image.mp hz rw [mem_congBlock] at hq ⊢ rw [← huv] exact hinv w hw u q hq calc (congBlock C u).card = ((congBlock C u).image (fun q => A.eval q w)).card := (Finset.card_image_of_injective _ hinj).symm _ ≤ (congBlock C v).card := Finset.card_le_card hsub exact le_antisymm (hle x y) (hle y x) lemma congBlocks_card_mul_block_card (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (C : Q → Q → Prop) (heqv : Equivalence C) (hinv : ∀ w : List α, A.IsPermWord w → ∀ x y : Q, C x y → C (A.eval x w) (A.eval y w)) (q₀ : Q) : (congBlocks C).card * (congBlock C q₀).card = Fintype.card Q := by have hpart : (congBlocks C).biUnion id = Finset.univ := by ext x simp only [Finset.mem_biUnion, id_eq, Finset.mem_univ, iff_true] exact ⟨congBlock C x, Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩, mem_congBlock.mpr (heqv.refl x)⟩ have hcard : Fintype.card Q = ∑ B ∈ congBlocks C, B.card := by rw [← Finset.card_univ, ← hpart, Finset.card_biUnion] · rfl · intro B₁ h₁ B₂ h₂ hne exact congBlocks_pairwise_disjoint heqv h₁ h₂ hne have hconst : ∀ B ∈ congBlocks C, B.card = (congBlock C q₀).card := by intro B hB obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp hB exact congBlock_card_const A htrans C heqv hinv x q₀ rw [hcard, Finset.sum_congr rfl hconst, Finset.sum_const, smul_eq_mul] lemma block_card_dvd_of_isBlockUnion (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (C : Q → Q → Prop) (heqv : Equivalence C) (hinv : ∀ w : List α, A.IsPermWord w → ∀ x y : Q, C x y → C (A.eval x w) (A.eval y w)) (q₀ : Q) {S : Finset Q} (hB : IsBlockUnion C S) : (congBlock C q₀).card ∣ S.card := by let subB := (congBlocks C).filter (fun B => B ⊆ S) have hpart : subB.biUnion id = S := by ext x simp only [subB, Finset.mem_biUnion, Finset.mem_filter, id_eq] constructor · rintro ⟨B, ⟨_, hBS⟩, hxB⟩; exact hBS hxB · intro hxS refine ⟨congBlock C x, ⟨Finset.mem_image.mpr ⟨x, Finset.mem_univ x, rfl⟩, ?_⟩, mem_congBlock.mpr (heqv.refl x)⟩ intro y hy exact (hB x y (mem_congBlock.mp hy)).mp hxS have hsum : S.card = ∑ B ∈ subB, B.card := by rw [← hpart, Finset.card_biUnion] · rfl · intro B₁ h₁ B₂ h₂ hne exact congBlocks_pairwise_disjoint heqv (Finset.mem_filter.mp h₁).1 (Finset.mem_filter.mp h₂).1 hne have hconst : ∀ B ∈ subB, B.card = (congBlock C q₀).card := by intro B hB' obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp (Finset.mem_filter.mp hB').1 exact congBlock_card_const A htrans C heqv hinv x q₀ rw [hsum, Finset.sum_congr rfl hconst, Finset.sum_const, smul_eq_mul] exact dvd_mul_left _ _ /-- Any letter preserves the cardinality of a `C₀`-block union `T` (because every defect-1 pair `(s_b, r_b)` lies in the same `C₀`-block, so `s_b ∈ T ↔ r_b ∈ T`). -/ lemma preimage_letter_card_eq_of_blockUnion (A : DFA Q α) (hdef : A.HasDefectLeOne) {T : Finset Q} (hB : IsBlockUnion (orbConn A (defectEdges A)) T) (a : α) : (A.preimage T [a]).card = T.card := by by_cases hbij : A.IsBijectiveLetter a · exact A.preimage_card_eq_of_permWord T (fun b hb => by rw [List.mem_singleton.mp hb]; exact hbij) · obtain ⟨s, r, hne, hr, hs, hform⟩ := defect_one_structure (A.step a) (hdef a) hbij have hpre : A.preimage T [a] = Finset.univ.filter (fun q => A.step a q ∈ T) := by ext q; simp only [DFA.mem_preimage, DFA.eval_cons, DFA.eval_nil, Finset.mem_filter, Finset.mem_univ, true_and] have hpair : defectPair A a s r := by refine ⟨hne, hr, hs, fun S => ?_⟩ have hp : A.preimage S [a] = Finset.univ.filter (fun q => A.step a q ∈ S) := by ext q; simp only [DFA.mem_preimage, DFA.eval_cons, DFA.eval_nil, Finset.mem_filter, Finset.mem_univ, true_and] rw [hp]; exact hform S have hsr : orbConn A (defectEdges A) s r := Relation.EqvGen.rel s r ⟨s, r, ⟨a, hpair⟩, [], by simp [DFA.IsPermWord], rfl, rfl⟩ have hiff : s ∈ T ↔ r ∈ T := hB s r hsr have hf := hform T rw [← hpre] at hf by_cases hsT : s ∈ T · have hrT : r ∈ T := hiff.mp hsT simp only [hsT, hrT, ↓reduceIte] at hf omega · have hrT : r ∉ T := fun h => hsT (hiff.mpr h) simp only [hsT, hrT, ↓reduceIte] at hf omega /-- Subspace of `C`-block-constant functions `Q → ℚ`. -/ def congBlockSubmodule (C : Q → Q → Prop) : Submodule ℚ (Q → ℚ) where carrier := {f | ∀ x y : Q, C x y → f x = f y} add_mem' := fun hf hg x y h => by simp [hf x y h, hg x y h] zero_mem' := fun _ _ _ => rfl smul_mem' := fun c _ hf x y h => by simp [hf x y h] lemma congBlockSubmodule_finrank (C : Q → Q → Prop) (heqv : Equivalence C) : Module.finrank ℚ (congBlockSubmodule C) = (congBlocks C).card := by let sC : Setoid Q := ⟨C, heqv⟩ let B₀ := Quotient sC have hk₀_eq : Fintype.card B₀ = (congBlocks C).card := by let f : B₀ → Finset Q := Quotient.lift (congBlock C) (fun _ _ h => congBlock_eq_of_rel heqv h) have hfinj : Function.Injective f := by intro p q hpq obtain ⟨x, rfl⟩ := Quotient.exists_rep p obtain ⟨y, rfl⟩ := Quotient.exists_rep q apply Quotient.sound have hx : x ∈ congBlock C y := by change x ∈ f (Quotient.mk sC y) rw [← hpq] exact mem_congBlock.mpr (heqv.refl x) exact heqv.symm (mem_congBlock.mp hx) have hf_im : Finset.univ.image f = congBlocks C := by ext B simp only [congBlocks, Finset.mem_image, Finset.mem_univ, true_and] constructor · rintro ⟨p, rfl⟩ obtain ⟨x, rfl⟩ := Quotient.exists_rep p exact ⟨x, rfl⟩ · rintro ⟨x, rfl⟩ exact ⟨Quotient.mk sC x, rfl⟩ calc Fintype.card B₀ = (Finset.univ : Finset B₀).card := (Finset.card_univ).symm _ = (Finset.univ.image f).card := (Finset.card_image_of_injective _ hfinj).symm _ = (congBlocks C).card := by rw [hf_im] let eW : (B₀ → ℚ) ≃ₗ[ℚ] congBlockSubmodule C := { toFun := fun g => ⟨fun q => g (Quotient.mk sC q), fun x y h => by dsimp only; congr 1; exact Quotient.sound h⟩ invFun := fun f => Quotient.lift f.1 f.2 map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl left_inv := fun g => by funext p; obtain ⟨x, rfl⟩ := Quotient.exists_rep p; rfl right_inv := fun f => by ext q; rfl } rw [← eW.finrank_eq, Module.finrank_fintype_fun_eq_card, hk₀_eq] /-- **Linear Algebra Block-Breaking Lemma**: If `S` is a nonempty proper `C₀`-block union in a synchronizing defect-`≤ 1` DFA with `k₀ = (congBlocks C₀).card` blocks, then there exists a word `w` of length at most `k₀ - 1` such that `(A.preimage S w).card = S.card` and `A.preimage S w` is NOT a `C₀`-block union. -/ lemma break_block_union_short (A : DFA Q α) (hsync : A.IsSynchronizing) (hdef : A.HasDefectLeOne) {S : Finset Q} (hSne : S.Nonempty) (hSlt : S.card < Fintype.card Q) (hB : IsBlockUnion (orbConn A (defectEdges A)) S) : ∃ w : List α, w.length ≤ (congBlocks (orbConn A (defectEdges A))).card - 1 ∧ (A.preimage S w).card = S.card ∧ ¬ IsBlockUnion (orbConn A (defectEdges A)) (A.preimage S w) := by let C₀ := orbConn A (defectEdges A) have heqv : Equivalence C₀ := orbConn_equiv A _ let k₀ := (congBlocks C₀).card have hnot_all : ∃ y₀ : Q, y₀ ∉ S := by by_contra hall; push Not at hall have hSu : S = Finset.univ := Finset.eq_univ_iff_forall.mpr hall rw [hSu, Finset.card_univ] at hSlt; exact lt_irrefl _ hSlt obtain ⟨x₀, hx₀⟩ := hSne obtain ⟨y₀, hy₀⟩ := hnot_all have hk₀_ge2 : 2 ≤ k₀ := by have hne : congBlock C₀ x₀ ≠ congBlock C₀ y₀ := by intro heq have hxy : C₀ x₀ y₀ := by have : y₀ ∈ congBlock C₀ x₀ := by rw [heq]; exact mem_congBlock.mpr (heqv.refl y₀) exact mem_congBlock.mp this exact hy₀ ((hB x₀ y₀ hxy).mp hx₀) have hsub : ({congBlock C₀ x₀, congBlock C₀ y₀} : Finset (Finset Q)) ⊆ congBlocks C₀ := by intro B hBm rcases Finset.mem_insert.mp hBm with rfl | hBm · exact Finset.mem_image.mpr ⟨x₀, Finset.mem_univ x₀, rfl⟩ · rw [Finset.mem_singleton.mp hBm] exact Finset.mem_image.mpr ⟨y₀, Finset.mem_univ y₀, rfl⟩ have := Finset.card_le_card hsub rw [Finset.card_pair hne] at this exact this let W : Submodule ℚ (Q → ℚ) := congBlockSubmodule C₀ have hfinrank_W : Module.finrank ℚ W = k₀ := congBlockSubmodule_finrank C₀ heqv let constOne : Q → ℚ := fun _ => 1 let indVec (T : Finset Q) : Q → ℚ := fun q => if q ∈ T then 1 else 0 have hind_mem_W : ∀ T : Finset Q, indVec T ∈ W ↔ IsBlockUnion C₀ T := by intro T constructor · intro hT x y hxy have hEq : (if x ∈ T then (1 : ℚ) else 0) = (if y ∈ T then 1 else 0) := hT x y hxy by_cases hx : x ∈ T <;> by_cases hy : y ∈ T <;> simp [hx, hy] at hEq ⊢ · intro hT x y hxy change (if x ∈ T then (1 : ℚ) else 0) = (if y ∈ T then 1 else 0) by_cases hx : x ∈ T · simp [hx, (hT x y hxy).mp hx] · have hy : y ∉ T := fun h => hx ((hT x y hxy).mpr h) simp [hx, hy] let U (d : ℕ) : Submodule ℚ (Q → ℚ) := Submodule.span ℚ ({constOne} ∪ {v : Q → ℚ | ∃ w : List α, w.length ≤ d ∧ v = indVec (A.preimage S w)}) have hU_mono : ∀ d : ℕ, U d ≤ U (d + 1) := by intro d apply Submodule.span_mono intro v hv rcases hv with rfl | ⟨w, hw, rfl⟩ · exact Or.inl rfl · exact Or.inr ⟨w, Nat.le_succ_of_le hw, rfl⟩ have hU0_finrank : 2 ≤ Module.finrank ℚ (U 0) := by let e₂ : (Fin 2 → ℚ) →ₗ[ℚ] (Q → ℚ) := { toFun := fun c => c 0 • constOne + c 1 • indVec S map_add' := fun c d => by ext q; simp [add_mul]; ring map_smul' := fun r c => by ext q; simp [mul_add, mul_assoc] } have he₂_inj : Function.Injective e₂ := by rw [injective_iff_map_eq_zero] intro c hc have hcy : e₂ c y₀ = 0 := congrFun hc y₀ have hcx : e₂ c x₀ = 0 := congrFun hc x₀ simp only [e₂, LinearMap.coe_mk, AddHom.coe_mk, Pi.add_apply, Pi.smul_apply, smul_eq_mul, constOne, indVec, hx₀, hy₀, ↓reduceIte, mul_one, mul_zero, add_zero] at hcx hcy funext i fin_cases i · exact hcy · change c 1 = 0; linarith have hrng_le : LinearMap.range e₂ ≤ U 0 := by rintro _ ⟨c, rfl⟩ have h1 : constOne ∈ U 0 := Submodule.subset_span (Or.inl rfl) have h2 : indVec S ∈ U 0 := Submodule.subset_span (Or.inr ⟨[], Nat.le_refl 0, by simp [indVec]⟩) exact Submodule.add_mem _ (Submodule.smul_mem _ _ h1) (Submodule.smul_mem _ _ h2) have h2 : Module.finrank ℚ (LinearMap.range e₂) = 2 := by rw [LinearMap.finrank_range_of_inj he₂_inj, Module.finrank_fin_fun] rw [← h2] exact Submodule.finrank_mono hrng_le have hex_break : ∃ l ≤ k₀ - 1, ∃ w : List α, w.length = l ∧ ¬ IsBlockUnion C₀ (A.preimage S w) := by by_contra hnone push Not at hnone have hall_le : ∀ w : List α, w.length ≤ k₀ - 1 → IsBlockUnion C₀ (A.preimage S w) := fun w hw => hnone w.length hw w rfl have hU_le_W : ∀ d ≤ k₀ - 1, U d ≤ W := by intro d hd rw [Submodule.span_le] intro v hv rcases hv with rfl | ⟨w, hw, rfl⟩ · intro _ _ _; rfl · exact (hind_mem_W _).mpr (hall_le w (le_trans hw hd)) have hex_eq : ∃ d < k₀ - 1, U d = U (d + 1) := by by_contra hne push Not at hne have hgrow : ∀ d ≤ k₀ - 1, 2 + d ≤ Module.finrank ℚ (U d) := by intro d hd induction d with | zero => exact hU0_finrank | succ d ih => have hlt_sub : U d < U (d + 1) := lt_of_le_of_ne (hU_mono d) (hne d (by omega)) have hlt_rk : Module.finrank ℚ (U d) < Module.finrank ℚ (U (d + 1)) := Submodule.finrank_lt_finrank_of_lt hlt_sub have := ih (by omega) omega have hbig := hgrow (k₀ - 1) (le_refl _) have hcap : Module.finrank ℚ (U (k₀ - 1)) ≤ k₀ := by have hle := Submodule.finrank_mono (hU_le_W (k₀ - 1) (le_refl _)) exact le_trans hle (le_of_eq hfinrank_W) omega obtain ⟨d, hd_lt, hd_eq⟩ := hex_eq let pullMap (a : α) : (Q → ℚ) →ₗ[ℚ] (Q → ℚ) := { toFun := fun f q => f (A.step a q) map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } have hpull_inv : ∀ a : α, ∀ v ∈ U d, pullMap a v ∈ U d := by intro a v hv refine Submodule.span_induction ?_ ?_ ?_ ?_ hv · intro g hg rw [hd_eq] rcases hg with rfl | ⟨w, hw, rfl⟩ · exact Submodule.subset_span (Or.inl rfl) · refine Submodule.subset_span (Or.inr ⟨a :: w, by simp; omega, ?_⟩) funext q simp [pullMap, indVec, A.preimage_cons] · simp · intro u₁ u₂ _ _ ih₁ ih₂; rw [map_add]; exact Submodule.add_mem _ ih₁ ih₂ · intro r u _ ih; rw [map_smul]; exact Submodule.smul_mem _ r ih have hall_in_Ud : ∀ w : List α, indVec (A.preimage S w) ∈ U d := by intro w induction w with | nil => exact Submodule.subset_span (Or.inr ⟨[], Nat.zero_le d, by simp [indVec]⟩) | cons a w ih => have hstep := hpull_inv a _ ih have heq : pullMap a (indVec (A.preimage S w)) = indVec (A.preimage S (a :: w)) := by funext q; simp [pullMap, indVec, A.preimage_cons] rwa [heq] at hstep have hall_block : ∀ w : List α, IsBlockUnion C₀ (A.preimage S w) := fun w => (hind_mem_W _).mp (hU_le_W d (by omega) (hall_in_Ud w)) have hall_card : ∀ w : List α, (A.preimage S w).card = S.card := by intro w induction w with | nil => simp | cons a w ih => rw [A.preimage_cons, preimage_letter_card_eq_of_blockUnion A hdef (hall_block w) a, ih] obtain ⟨w₀, q₀, hq₀⟩ := hsync have hcard_w₀ := hall_card w₀ by_cases hq₀S : q₀ ∈ S · have huniv : A.preimage S w₀ = Finset.univ := by ext q; simp [hq₀ q, hq₀S] rw [huniv, Finset.card_univ] at hcard_w₀ omega · have hemp : A.preimage S w₀ = ∅ := by ext q; simp [hq₀ q, hq₀S] rw [hemp, Finset.card_empty] at hcard_w₀ have hpos : 0 < S.card := Finset.card_pos.mpr ⟨x₀, hx₀⟩ omega have hex_nat : ∃ l : ℕ, ∃ w : List α, w.length = l ∧ ¬ IsBlockUnion C₀ (A.preimage S w) := by obtain ⟨l, _, hw⟩ := hex_break; exact ⟨l, hw⟩ let l₀ := Nat.find hex_nat have hl₀_le : l₀ ≤ k₀ - 1 := by obtain ⟨l, hl, hw⟩ := hex_break exact le_trans (Nat.find_min' hex_nat hw) hl obtain ⟨w, hw_len, hw_notB⟩ := Nat.find_spec hex_nat have hcard_le : ∀ u : List α, u.length ≤ l₀ → (A.preimage S u).card = S.card := by intro u hu induction u with | nil => simp | cons a v ih => have hv_lt : v.length < l₀ := by simp at hu; omega have hv_block : IsBlockUnion C₀ (A.preimage S v) := by by_contra hnv exact Nat.find_min hex_nat hv_lt ⟨v, rfl, hnv⟩ rw [A.preimage_cons, preimage_letter_card_eq_of_blockUnion A hdef hv_block a, ih (by omega)] exact ⟨w, hw_len ▸ hl₀_le, hcard_le w (le_of_eq hw_len), hw_notB⟩ omit [DecidableEq Q] in /-- Vertex propagation for a `G`-covariant ascending family of subsets of `Q`: if `F 0` is nonempty, `F d ⊆ F (d + 1)`, and every bijective letter maps `F d` into `F (d + 1)`, then `F (|Q| - 1) = Finset.univ`. -/ lemma vertex_prop_full (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (F : ℕ → Finset Q) (h0 : (F 0).Nonempty) (hmono : ∀ d, F d ⊆ F (d + 1)) (hstep : ∀ d (a : α), A.IsBijectiveLetter a → ∀ x ∈ F d, A.step a x ∈ F (d + 1)) : F (Fintype.card Q - 1) = Finset.univ := by have hgrow : ∀ d, min (Fintype.card Q) (1 + d) ≤ (F d).card := by intro d induction d with | zero => have h1 : 1 ≤ (F 0).card := Finset.card_pos.mpr h0 omega | succ d ih => by_cases hfull : (F d).card = Fintype.card Q · have hle := Finset.card_le_card (hmono d) omega · have hlt : (F d).card < (F (d + 1)).card := by by_contra hge have heq : F (d + 1) = F d := (Finset.eq_of_subset_of_card_le (hmono d) (by omega)).symm have hinv : ∀ a : α, A.IsBijectiveLetter a → ∀ x ∈ F d, A.step a x ∈ F d := fun a ha x hx => heq ▸ hstep d a ha x hx have hinvW : ∀ w : List α, A.IsPermWord w → ∀ x ∈ F d, A.eval x w ∈ F d := by intro w induction w with | nil => intro _ x hx; exact hx | cons a w ihw => intro hw x hx exact ihw (fun b hb => hw b (List.mem_cons_of_mem a hb)) (A.step a x) (hinv a (hw a List.mem_cons_self) x hx) obtain ⟨x₀, hx₀⟩ := h0 have hx₀d : x₀ ∈ F d := by clear ih hfull hge heq hinv hinvW induction d with | zero => exact hx₀ | succ m ihm => exact hmono m ihm have huniv : F d = Finset.univ := by ext z; simp only [Finset.mem_univ, iff_true] obtain ⟨w, hw, rfl⟩ := (A.isPretransitive_iff_permWord.mp htrans) x₀ z exact hinvW w hw x₀ hx₀d rw [huniv, Finset.card_univ] at hfull exact hfull rfl omega apply Finset.eq_univ_of_card obtain ⟨x₀, _⟩ := h0 have hpos : 0 < Fintype.card Q := Fintype.card_pos_iff.mpr ⟨x₀⟩ have hge := hgrow (Fintype.card Q - 1) have hle := Finset.card_le_univ (F (Fintype.card Q - 1)) omega /-- **Unified `m ≤ 3` Strong-Block-Connectivity Lemma**: When every `C₀`-block has size `m ≤ 3`, every subset `S` that is NOT a `C₀`-block union has an outgoing edge in `G_{n - 1}` and therefore extends to cardinality `S.card + 1` in at most `n` steps. -/ lemma extend_step_small_block (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (hb : ∃ b : α, ∃ s r : Q, defectPair A b s r) (hm3 : ∀ x : Q, (congBlock (orbConn A (defectEdges A)) x).card ≤ 3) {S : Finset Q} (hnotB : ¬ IsBlockUnion (orbConn A (defectEdges A)) S) : ∃ w : List α, w.length ≤ Fintype.card Q ∧ (A.preimage S w).card = S.card + 1 := by let C₀ := orbConn A (defectEdges A) have heqv : Equivalence C₀ := orbConn_equiv A _ let Out (d : ℕ) : Finset Q := Finset.univ.filter (fun x => ∃ y : Q, orbEdge A (defectEdges A) d x y) let In (d : ℕ) : Finset Q := Finset.univ.filter (fun y => ∃ x : Q, orbEdge A (defectEdges A) d x y) obtain ⟨b₀, s₀, r₀, hpair₀⟩ := hb have h0_edge : orbEdge A (defectEdges A) 0 s₀ r₀ := ⟨s₀, r₀, ⟨b₀, hpair₀⟩, [], by simp [DFA.IsPermWord], le_refl 0, rfl, rfl⟩ have hOut_full : Out (Fintype.card Q - 1) = Finset.univ := by refine vertex_prop_full A htrans Out ⟨s₀, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ⟨r₀, h0_edge⟩⟩⟩ ?_ ?_ · intro d x hx obtain ⟨y, u, v, huv, w, hw, hlen, hu, hv⟩ := (Finset.mem_filter.mp hx).2 exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, ⟨y, u, v, huv, w, hw, Nat.le_succ_of_le hlen, hu, hv⟩⟩ · intro d a ha x hx obtain ⟨y, u, v, huv, w, hw, hlen, hu, hv⟩ := (Finset.mem_filter.mp hx).2 refine Finset.mem_filter.mpr ⟨Finset.mem_univ _, ⟨A.step a y, u, v, huv, w ++ [a], ?_, ?_, ?_, ?_⟩⟩ · intro c hc rcases List.mem_append.mp hc with hc | hc · exact hw c hc · rw [List.mem_singleton.mp hc]; exact ha · simp; omega · simp [A.eval_append, hu] · simp [A.eval_append, hv] have hIn_full : In (Fintype.card Q - 1) = Finset.univ := by refine vertex_prop_full A htrans In ⟨r₀, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ⟨s₀, h0_edge⟩⟩⟩ ?_ ?_ · intro d y hy obtain ⟨x, u, v, huv, w, hw, hlen, hu, hv⟩ := (Finset.mem_filter.mp hy).2 exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, ⟨x, u, v, huv, w, hw, Nat.le_succ_of_le hlen, hu, hv⟩⟩ · intro d a ha y hy obtain ⟨x, u, v, huv, w, hw, hlen, hu, hv⟩ := (Finset.mem_filter.mp hy).2 refine Finset.mem_filter.mpr ⟨Finset.mem_univ _, ⟨A.step a x, u, v, huv, w ++ [a], ?_, ?_, ?_, ?_⟩⟩ · intro c hc rcases List.mem_append.mp hc with hc | hc · exact hw c hc · rw [List.mem_singleton.mp hc]; exact ha · simp; omega · simp [A.eval_append, hu] · simp [A.eval_append, hv] have hedge_prop : ∀ d x y, orbEdge A (defectEdges A) d x y → C₀ x y ∧ x ≠ y := by rintro d x y ⟨u, v, ⟨b, hne, hr, hs, hform⟩, w, hw, _, rfl, rfl⟩ refine ⟨Relation.EqvGen.rel _ _ ⟨u, v, ⟨b, hne, hr, hs, hform⟩, w, hw, rfl, rfl⟩, ?_⟩ intro heq exact hne ((A.eval_bijective_of_permWord hw).1 heq) have hex_cut : ∃ x y : Q, C₀ x y ∧ x ∈ S ∧ y ∉ S := by by_contra hnone push Not at hnone apply hnotB intro x y hxy exact ⟨fun hx => hnone x y hxy hx, fun hy => hnone y x (heqv.symm hxy) hy⟩ obtain ⟨x, y, hxy, hxS, hyS⟩ := hex_cut let B := congBlock C₀ x have hBcard : B.card ≤ 3 := hm3 x have hxB : x ∈ B ∩ S := Finset.mem_inter.mpr ⟨mem_congBlock.mpr (heqv.refl x), hxS⟩ have hyB : y ∈ B \ S := Finset.mem_sdiff.mpr ⟨mem_congBlock.mpr hxy, hyS⟩ have hsum : (B ∩ S).card + (B \ S).card = B.card := Finset.card_inter_add_card_sdiff B S have hpos1 : 1 ≤ (B ∩ S).card := Finset.card_pos.mpr ⟨x, hxB⟩ have hpos2 : 1 ≤ (B \ S).card := Finset.card_pos.mpr ⟨y, hyB⟩ have hposQ : 0 < Fintype.card Q := Fintype.card_pos_iff.mpr ⟨x⟩ have h1_or_1 : (B ∩ S).card = 1 ∨ (B \ S).card = 1 := by omega rcases h1_or_1 with h1 | h1 · have hsing : B ∩ S = {x} := by obtain ⟨z, hz⟩ := Finset.card_eq_one.mp h1 have hxz : x = z := Finset.mem_singleton.mp (hz ▸ hxB) rw [hz, ← hxz] have hxOut : x ∈ Out (Fintype.card Q - 1) := hOut_full ▸ Finset.mem_univ x obtain ⟨z, hxz⟩ := (Finset.mem_filter.mp hxOut).2 have ⟨hCxz, hne_xz⟩ := hedge_prop _ _ _ hxz have hzS : z ∉ S := by intro hzS have hz_in : z ∈ B ∩ S := Finset.mem_inter.mpr ⟨mem_congBlock.mpr hCxz, hzS⟩ rw [hsing, Finset.mem_singleton] at hz_in exact hne_xz hz_in.symm obtain ⟨w, hw_len, hw_card⟩ := extend_step_of_orbEdge A hxz hxS hzS exact ⟨w, by omega, hw_card⟩ · have hsing : B \ S = {y} := by obtain ⟨z, hz⟩ := Finset.card_eq_one.mp h1 have hyz : y = z := Finset.mem_singleton.mp (hz ▸ hyB) rw [hz, ← hyz] have hyIn : y ∈ In (Fintype.card Q - 1) := hIn_full ▸ Finset.mem_univ y obtain ⟨z, hzy⟩ := (Finset.mem_filter.mp hyIn).2 have ⟨hCzy, hne_zy⟩ := hedge_prop _ _ _ hzy have hzS : z ∈ S := by by_contra hnz have hzB : z ∈ B := mem_congBlock.mpr (heqv.trans hxy (heqv.symm hCzy)) have hz_in : z ∈ B \ S := Finset.mem_sdiff.mpr ⟨hzB, hnz⟩ rw [hsing, Finset.mem_singleton] at hz_in exact hne_zy hz_in obtain ⟨w, hw_len, hw_card⟩ := extend_step_of_orbEdge A hzy hzS hyS exact ⟨w, by omega, hw_card⟩ /-- Generic inductive reset-word builder: given an extension bound `L_ext` for every non-`C₀`-block union of size `2 ≤ |S| ≤ n - 2`, produces a reset word of length at most `1 + n + (n - 3) * L_ext + (k₀ - 1) ^ 2`. -/ lemma build_reset_word_with_blocks (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (hsync : A.IsSynchronizing) (hdef : A.HasDefectLeOne) (hn : 3 ≤ Fintype.card Q) (L_ext : ℕ) (hext : ∀ S : Finset Q, S.Nonempty → S.card < Fintype.card Q → ¬ IsBlockUnion (orbConn A (defectEdges A)) S → ∃ w : List α, w.length ≤ L_ext ∧ (A.preimage S w).card = S.card + 1) : ∃ w : List α, A.IsResetWord w ∧ w.length ≤ 1 + Fintype.card Q + (Fintype.card Q - 3) * L_ext + ((congBlocks (orbConn A (defectEdges A))).card - 1) ^ 2 := by set n := Fintype.card Q set C₀ := orbConn A (defectEdges A) have heqv : Equivalence C₀ := orbConn_equiv A _ have hinv : ∀ w : List α, A.IsPermWord w → ∀ x y : Q, C₀ x y → C₀ (A.eval x w) (A.eval y w) := fun _ hw _ _ h => orbConn_permWord A _ hw h have hb := exists_defectPair_of_synchronizing A hsync hdef (by omega) obtain ⟨b₀, s₀, r₀, hne₀, hr₀, hs₀, hform₀⟩ := hb have hb' : ∃ b : α, ∃ s r : Q, defectPair A b s r := ⟨b₀, s₀, r₀, hne₀, hr₀, hs₀, hform₀⟩ set m := (congBlock C₀ s₀).card set k₀ := (congBlocks C₀).card have hkm : k₀ * m = n := congBlocks_card_mul_block_card A htrans C₀ heqv hinv s₀ have hm2 : 2 ≤ m := by have hsr : C₀ s₀ r₀ := Relation.EqvGen.rel s₀ r₀ ⟨s₀, r₀, ⟨b₀, hne₀, hr₀, hs₀, hform₀⟩, [], by simp [DFA.IsPermWord], rfl, rfl⟩ have hsub : ({s₀, r₀} : Finset Q) ⊆ congBlock C₀ s₀ := by intro z hz rcases Finset.mem_insert.mp hz with rfl | hz · exact mem_congBlock.mpr (heqv.refl z) · rw [Finset.mem_singleton.mp hz]; exact mem_congBlock.mpr hsr have := Finset.card_le_card hsub rw [Finset.card_pair hne₀] at this exact this let multCount (t : ℕ) : ℕ := ((Finset.Ico 2 t).filter (fun j => m ∣ j)).card have hmult_succ : ∀ t ≥ 2, multCount (t + 1) = multCount t + (if m ∣ t then 1 else 0) := by intro t ht simp only [multCount] have hIco : Finset.Ico 2 (t + 1) = insert t (Finset.Ico 2 t) := by ext j; simp only [Finset.mem_Ico, Finset.mem_insert]; omega have hnt : t ∉ Finset.Ico 2 t := by simp rw [hIco, Finset.filter_insert] split_ifs with hd · rw [Finset.card_insert_of_notMem (fun h => hnt (Finset.mem_filter.mp h).1)] · simp have hmult_bound : multCount (n - 1) ≤ k₀ - 1 := by have hinj : Set.InjOn (fun j : ℕ => j / m) (((Finset.Ico 2 (n - 1)).filter (fun j => m ∣ j)) : Set ℕ) := by intro a ha b hb hab dsimp only at hab have ha' := (Finset.mem_filter.mp ha).2 have hb' := (Finset.mem_filter.mp hb).2 have h1 : a / m * m = a := Nat.div_mul_cancel ha' have h2 : b / m * m = b := Nat.div_mul_cancel hb' rw [← h1, ← h2, hab] have hsub : ((Finset.Ico 2 (n - 1)).filter (fun j => m ∣ j)).image (fun j => j / m) ⊆ Finset.Ico 1 k₀ := by intro r hr obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hr have hjI := Finset.mem_Ico.mp (Finset.mem_filter.mp hj).1 have hjd := (Finset.mem_filter.mp hj).2 rw [Finset.mem_Ico] obtain ⟨q, rfl⟩ := hjd have hq : m * q / m = q := Nat.mul_div_cancel_left q (by omega) rw [hq] have hq_pos : 1 ≤ q := by by_contra h0 have hq0 : q = 0 := by omega subst hq0; omega have hq_lt : q < k₀ := by by_contra hge have : k₀ * m ≤ m * q := by nlinarith omega exact ⟨hq_pos, hq_lt⟩ calc multCount (n - 1) = (((Finset.Ico 2 (n - 1)).filter (fun j => m ∣ j)).image (fun j => j / m)).card := (Finset.card_image_of_injOn hinj).symm _ ≤ (Finset.Ico 1 k₀).card := Finset.card_le_card hsub _ = k₀ - 1 := Nat.card_Ico 1 k₀ have hstep1 : ∃ w₁ : List α, w₁.length = 1 ∧ (A.preimage {s₀} w₁).card = 2 := by refine ⟨[b₀], rfl, ?_⟩ have hf := hform₀ {s₀} have hr_not : r₀ ∉ ({s₀} : Finset Q) := by simp [hne₀.symm] simp only [Finset.mem_singleton_self, hr_not, ↓reduceIte, Finset.card_singleton] at hf omega have hgrow : ∀ t : ℕ, 2 ≤ t → t ≤ n - 1 → ∃ w : List α, w.length ≤ 1 + (t - 2) * L_ext + multCount t * (k₀ - 1) ∧ (A.preimage {s₀} w).card = t := by intro t ht2 ht_le induction t with | zero => omega | succ t ih => by_cases ht1 : t = 1 · subst ht1 obtain ⟨w₁, hw₁_len, hw₁_card⟩ := hstep1 have hmc : multCount 2 = 0 := by simp [multCount] exact ⟨w₁, by simp [hw₁_len, hmc], hw₁_card⟩ · obtain ⟨w, hw_len, hw_card⟩ := ih (by omega) (by omega) set S := A.preimage {s₀} w have hSne : S.Nonempty := Finset.card_pos.mp (by omega) have hSlt : S.card < n := by omega have hmc := hmult_succ t (by omega) have hmul_t : (t + 1 - 2) * L_ext = (t - 2) * L_ext + L_ext := by have : t + 1 - 2 = (t - 2) + 1 := by omega rw [this, Nat.add_mul, one_mul] by_cases hB : IsBlockUnion C₀ S · have hdvd : m ∣ t := hw_card ▸ block_card_dvd_of_isBlockUnion A htrans C₀ heqv hinv s₀ hB obtain ⟨w_brk, hw_brk_len, hw_brk_card, hw_brk_notB⟩ := break_block_union_short A hsync hdef hSne hSlt hB change w_brk.length ≤ k₀ - 1 at hw_brk_len set S' := A.preimage S w_brk have hS'ne : S'.Nonempty := Finset.card_pos.mp (by omega) have hS'lt : S'.card < n := by omega obtain ⟨u, hu_len, hu_card⟩ := hext S' hS'ne hS'lt hw_brk_notB refine ⟨u ++ w_brk ++ w, ?_, ?_⟩ · rw [List.length_append, List.length_append, hmc, if_pos hdvd, Nat.add_mul, one_mul, hmul_t] omega · rw [A.preimage_append, A.preimage_append] change (A.preimage S' u).card = t + 1 omega · obtain ⟨u, hu_len, hu_card⟩ := hext S hSne hSlt hB refine ⟨u ++ w, ?_, ?_⟩ · rw [List.length_append, hmc, hmul_t] have hle_mc : multCount t * (k₀ - 1) ≤ (multCount t + if m ∣ t then 1 else 0) * (k₀ - 1) := Nat.mul_le_mul_right _ (Nat.le_add_right _ _) omega · rw [A.preimage_append] change (A.preimage S u).card = t + 1 omega obtain ⟨w_mid, hw_mid_len, hw_mid_card⟩ := hgrow (n - 1) (by omega) (le_refl _) rw [show n - 1 - 2 = n - 3 by omega] at hw_mid_len obtain ⟨w_last, hw_last_len, hw_last_card⟩ := extend_step_n_sub_one A htrans hb' hw_mid_card refine ⟨w_last ++ w_mid, ?_, ?_⟩ · apply A.isResetWord_of_preimage_singleton s₀ rw [A.preimage_append] exact hw_last_card · rw [List.length_append] have hsq : multCount (n - 1) * (k₀ - 1) ≤ (k₀ - 1) ^ 2 := by rw [sq]; exact Nat.mul_le_mul_right _ hmult_bound omega /-- **Small-Block Imprimitive Bound (`m ≤ 3`)**: When the orbital-component congruence `C₀` has block size `m ≤ 3` (i.e. `m = 2` or `m = 3`) and `k₀` blocks (`k₀ * m = n`), every synchronizing defect-`≤ 1` DFA with transitive `permSubgroup` admits a reset word of length at most `1 + n * (n - 2) + (k₀ - 1) ^ 2` (yielding `(5n² - 12n + 8)/4` for `m = 2` and `(10n² - 24n + 18)/9` for `m = 3`). -/ theorem reset_threshold_small_block (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (hsync : A.IsSynchronizing) (hdef : A.HasDefectLeOne) (hn : 3 ≤ Fintype.card Q) (hm3 : ∀ x : Q, (congBlock (orbConn A (defectEdges A)) x).card ≤ 3) : ∃ w : List α, A.IsResetWord w ∧ w.length ≤ 1 + Fintype.card Q * (Fintype.card Q - 2) + ((congBlocks (orbConn A (defectEdges A))).card - 1) ^ 2 := by have hb := exists_defectPair_of_synchronizing A hsync hdef (by omega) obtain ⟨w, hw_res, hw_len⟩ := build_reset_word_with_blocks A htrans hsync hdef hn (Fintype.card Q) (fun _ _ _ hnotB => extend_step_small_block A htrans hb hm3 hnotB) refine ⟨w, hw_res, ?_⟩ set n := Fintype.card Q have hmul : n + (n - 3) * n = n * (n - 2) := by zify [hn, (by omega : 2 ≤ n)]; ring omega /-- **Headline Theorem 5 (Full Transitive Permutation Group World Record)**: Every synchronizing `n`-state (`n ≥ 3`) DFA of defect `≤ 1` whose bijective letters generate a transitive permutation group (primitive or imprimitive) admits a reset word `w` satisfying `16 * w.length + 100 * n ≤ 29 * n ^ 2 + 104` (leading constant `29 / 16 = 1.8125`). -/ theorem reset_threshold_transitive_defect_one (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (hsync : A.IsSynchronizing) (hdef : A.HasDefectLeOne) (hn : 3 ≤ Fintype.card Q) : ∃ w : List α, A.IsResetWord w ∧ 16 * w.length + 100 * Fintype.card Q ≤ 29 * Fintype.card Q ^ 2 + 104 := by set n := Fintype.card Q let C₀ := orbConn A (defectEdges A) have heqv : Equivalence C₀ := orbConn_equiv A _ have hinv : ∀ w : List α, A.IsPermWord w → ∀ x y : Q, C₀ x y → C₀ (A.eval x w) (A.eval y w) := fun _ hw _ _ h => orbConn_permWord A _ hw h have hb := exists_defectPair_of_synchronizing A hsync hdef (by omega) obtain ⟨b₀, s₀, r₀, hne₀, hr₀, hs₀, hform₀⟩ := hb have hb' : ∃ b : α, ∃ s r : Q, defectPair A b s r := ⟨b₀, s₀, r₀, hne₀, hr₀, hs₀, hform₀⟩ set m := (congBlock C₀ s₀).card set k₀ := (congBlocks C₀).card have hkm : k₀ * m = n := congBlocks_card_mul_block_card A htrans C₀ heqv hinv s₀ have hm_const : ∀ x : Q, (congBlock C₀ x).card = m := fun x => congBlock_card_const A htrans C₀ heqv hinv x s₀ have hm2 : 2 ≤ m := by have hsr : C₀ s₀ r₀ := Relation.EqvGen.rel s₀ r₀ ⟨s₀, r₀, ⟨b₀, hne₀, hr₀, hs₀, hform₀⟩, [], by simp [DFA.IsPermWord], rfl, rfl⟩ have hsub : ({s₀, r₀} : Finset Q) ⊆ congBlock C₀ s₀ := by intro z hz rcases Finset.mem_insert.mp hz with rfl | hz · exact mem_congBlock.mpr (heqv.refl z) · rw [Finset.mem_singleton.mp hz]; exact mem_congBlock.mpr hsr have := Finset.card_le_card hsub rw [Finset.card_pair hne₀] at this exact this have hk₀_pos : 1 ≤ k₀ := by by_contra h0; have : k₀ = 0 := by omega rw [this, zero_mul] at hkm; omega by_cases hk1 : k₀ = 1 · obtain ⟨w, hw_res, hw_len⟩ := build_reset_word_with_blocks A htrans hsync hdef hn ((7 * n - 6) / 4) (fun S hSne hSlt hnotB => by obtain ⟨x, y, hxy, hxS, hyS⟩ := exists_short_outgoing_edge_of_not_blockUnion A htrans (defectEdges A) S hSne hSlt hnotB obtain ⟨u, hu_len, hu_card⟩ := extend_step_of_orbEdge A hxy hxS hyS exact ⟨u, by omega, hu_card⟩) refine ⟨w, hw_res, ?_⟩ change w.length ≤ 1 + n + (n - 3) * ((7 * n - 6) / 4) + (k₀ - 1) ^ 2 at hw_len have hk_sub : (k₀ - 1) ^ 2 = 0 := by rw [hk1]; simp rw [hk_sub, add_zero] at hw_len have hmul4 : 4 * ((7 * n - 6) / 4) ≤ 7 * n - 6 := Nat.mul_div_le (7 * n - 6) 4 have hmul_step : 4 * ((n - 3) * ((7 * n - 6) / 4)) ≤ (n - 3) * (7 * n - 6) := by calc 4 * ((n - 3) * ((7 * n - 6) / 4)) = (n - 3) * (4 * ((7 * n - 6) / 4)) := by ring _ ≤ (n - 3) * (7 * n - 6) := Nat.mul_le_mul_left (n - 3) hmul4 have h4 : 4 * w.length ≤ 4 + 4 * n + (n - 3) * (7 * n - 6) := by omega have h6 : 6 ≤ 7 * n := by omega zify [hn, h6] at h4 ⊢ nlinarith [sq_nonneg ((n : ℤ) - 4)] · have hk2 : 2 ≤ k₀ := by omega by_cases hm3 : m ≤ 3 · obtain ⟨w, hw_res, hw_len⟩ := build_reset_word_with_blocks A htrans hsync hdef hn n (fun S _ _ hnotB => extend_step_small_block A htrans hb' (fun x => by rw [hm_const x]; exact hm3) hnotB) refine ⟨w, hw_res, ?_⟩ change w.length ≤ 1 + n + (n - 3) * n + (k₀ - 1) ^ 2 at hw_len have h2k : 2 * k₀ ≤ n := by nlinarith have hn4 : 4 ≤ n := by nlinarith zify [hn, hk₀_pos] at hw_len h2k hn4 ⊢ nlinarith · have hm4 : 4 ≤ m := by omega obtain ⟨w, hw_res, hw_len⟩ := build_reset_word_with_blocks A htrans hsync hdef hn ((7 * n - 6) / 4) (fun S hSne hSlt hnotB => by obtain ⟨x, y, hxy, hxS, hyS⟩ := exists_short_outgoing_edge_of_not_blockUnion A htrans (defectEdges A) S hSne hSlt hnotB obtain ⟨u, hu_len, hu_card⟩ := extend_step_of_orbEdge A hxy hxS hyS exact ⟨u, by omega, hu_card⟩) refine ⟨w, hw_res, ?_⟩ change w.length ≤ 1 + n + (n - 3) * ((7 * n - 6) / 4) + (k₀ - 1) ^ 2 at hw_len have h4k : 4 * k₀ ≤ n := by nlinarith have hmul4 : 4 * ((7 * n - 6) / 4) ≤ 7 * n - 6 := Nat.mul_div_le (7 * n - 6) 4 have hmul_step : 4 * ((n - 3) * ((7 * n - 6) / 4)) ≤ (n - 3) * (7 * n - 6) := by calc 4 * ((n - 3) * ((7 * n - 6) / 4)) = (n - 3) * (4 * ((7 * n - 6) / 4)) := by ring _ ≤ (n - 3) * (7 * n - 6) := Nat.mul_le_mul_left (n - 3) hmul4 have h16 : 16 * w.length ≤ 16 + 16 * n + 4 * ((n - 3) * (7 * n - 6)) + 16 * (k₀ - 1) ^ 2 := by omega have h6 : 6 ≤ 7 * n := by omega zify [hn, hk₀_pos, h6] at h16 h4k ⊢ nlinarith /-- **Headline Theorem 6 (Strict Improvement over Zhu, FSTTCS 2024)**: For every `n ≥ 4`, every synchronizing `n`-state defect-`≤ 1` DFA whose bijective letters generate a transitive permutation group admits a reset word strictly shorter than Zhu's `2n² - 7n + 7` world record. -/ theorem strictly_beats_zhu_2024 (A : DFA Q α) (htrans : MulAction.IsPretransitive A.permSubgroup Q) (hsync : A.IsSynchronizing) (hdef : A.HasDefectLeOne) (hn : 4 ≤ Fintype.card Q) : ∃ w : List α, A.IsResetWord w ∧ w.length < 2 * Fintype.card Q ^ 2 - 7 * Fintype.card Q + 7 := by obtain ⟨w, hw_res, hw_bound⟩ := reset_threshold_transitive_defect_one A htrans hsync hdef (by omega) refine ⟨w, hw_res, ?_⟩ set n := Fintype.card Q have h7 : 7 * n ≤ 2 * n ^ 2 := by nlinarith zify [h7] at hw_bound ⊢ nlinarith end ImprimitiveCerny end TransitiveCernyBound #print axioms TransitiveCernyBound.preorder_symmetrization_bound #print axioms TransitiveCernyBound.effective_higman_strong_connectivity #print axioms TransitiveCernyBound.reset_threshold_connected_orbital #print axioms TransitiveCernyBound.reset_threshold_primitive_defect_one #print axioms TransitiveCernyBound.reset_threshold_small_block #print axioms TransitiveCernyBound.reset_threshold_transitive_defect_one #print axioms TransitiveCernyBound.strictly_beats_zhu_2024