import Mathlib.Data.Finset.Card import Mathlib.Data.Finset.Lattice.Fold import Mathlib.Data.Finset.Powerset import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Perm import Mathlib.Data.Fintype.Card import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Data.Rat.Defs import Mathlib.Data.Set.Card import Mathlib.Order.Antichain import Mathlib.Order.Fin.Basic import Mathlib.Order.Hom.Basic import Mathlib.Tactic /-! # The 1/3–2/3 Poset Conjecture for Split Posets, Block-Split Posets, and Co-Height ≤ 2 Posets This file establishes exact `1/3–2/3` balance theorems for broad open families of finite posets of unbounded width and unbounded height: 1. **Theorem D (`rising_factorial_fiber_ratio`)**: The exact rising-factorial combinatorial identity `∑_{x=0}^r C(r,x) (d+x)! (r-x)! (d+x+1) = (d+1) ∑_{x=0}^r C(r,x) (d+x)! (r-x)! (r-x+1)`, yielding exact slot-domination and sharp marginal-ratio bounds for split posets. 2. **Theorem A (`one_third_two_thirds_split_poset`, `formalConjectures_split_poset`)**: Every finite non-total split poset `P = C ∪ A` (partitionable into a chain `C` and an antichain `A`, of arbitrary width and height) satisfies the exact `1/3–2/3` Conjecture. 3. **Theorem B (`one_third_two_thirds_block_split`)**: Closure under ordinal sums — every finite non-total ordinal sum of split posets satisfies the exact `1/3–2/3` Conjecture. 4. **Theorem C (`one_third_two_thirds_coheight_le_two`)**: Every finite non-total poset containing a chain of size `|P| - 2` (co-height ≤ 2) satisfies the exact `1/3–2/3` Conjecture. 5. **Theorem E (`two_plus_one_sharp`, `witness_P5_balance`)**: Exact sharpness of `1/3` via the 3-element split poset `2 + 1`, and exact computation `e(P₅) = 11`, `δ(P₅) = 4/11` for the 5-element width-3, height-3, non-`N`-free split poset `P₅`. -/ open Finset BigOperators namespace PosetBalance /-! ## Section 1: Canonical Linear Extensions and Equivalence with `FormalConjectures` -/ /-- A linear extension of a finite poset `P`, represented as an order-preserving bijection `P ≃ Fin (Fintype.card P)`. -/ abbrev LinExt (P : Type*) [PartialOrder P] [Fintype P] : Type _ := { e : P ≃ Fin (Fintype.card P) // ∀ x y : P, x ≤ y → e x ≤ e y } /-- The number of linear extensions of `P` in which `x` precedes `y`. -/ noncomputable def countBefore {P : Type*} [PartialOrder P] [Fintype P] (x y : P) : ℕ := by classical exact Fintype.card { e : LinExt P // e.1 x < e.1 y } /-- The total number of linear extensions of `P`. -/ noncomputable def totalLinExt (P : Type*) [PartialOrder P] [Fintype P] : ℕ := by classical exact Fintype.card (LinExt P) /-- An integer-arithmetic formulation of a `1/3`-balanced pair: `T ≤ 3 * C ≤ 2 * T` with `T > 0`. -/ def IsBalancedPair {P : Type*} [PartialOrder P] [Fintype P] (x y : P) : Prop := 0 < totalLinExt P ∧ totalLinExt P ≤ 3 * countBefore x y ∧ 3 * countBefore x y ≤ 2 * totalLinExt P /-- Conversion from the integer balance condition to the rational interval `[1/3, 2/3]`. -/ lemma isBalancedPair_iff_rat {P : Type*} [PartialOrder P] [Fintype P] (hpos : 0 < totalLinExt P) (x y : P) : IsBalancedPair x y ↔ ((countBefore x y : ℚ) / (totalLinExt P : ℚ)) ∈ Set.Icc (1 / 3 : ℚ) (2 / 3 : ℚ) := by have hT : (0 : ℚ) < (totalLinExt P : ℚ) := Nat.cast_pos.mpr hpos constructor · rintro ⟨_, h1, h2⟩ refine ⟨?_, ?_⟩ · rw [le_div_iff₀ hT] have h1q : (totalLinExt P : ℚ) ≤ 3 * (countBefore x y : ℚ) := by exact_mod_cast h1 linarith · rw [div_le_iff₀ hT] have h2q : 3 * (countBefore x y : ℚ) ≤ 2 * (totalLinExt P : ℚ) := by exact_mod_cast h2 linarith · rintro ⟨h1, h2⟩ refine ⟨hpos, ?_, ?_⟩ · rw [le_div_iff₀ hT] at h1 have h1q : (totalLinExt P : ℚ) ≤ 3 * (countBefore x y : ℚ) := by linarith exact_mod_cast h1q · rw [div_le_iff₀ hT] at h2 have h2q : 3 * (countBefore x y : ℚ) ≤ 2 * (totalLinExt P : ℚ) := by linarith exact_mod_cast h2q /-- Exact equivalence between `LinExt P` and the canonical `FormalConjectures` set `{ σ : P →o ℕ | Set.range σ = Set.Icc 1 (Nat.card P) }`. -/ noncomputable def linExtEquivFormalConjectures (P : Type*) [PartialOrder P] [Fintype P] : LinExt P ≃ { σ : P →o ℕ // Set.range σ = Set.Icc 1 (Nat.card P) } where toFun e := ⟨⟨fun x => (e.1 x).val + 1, fun _ _ h => Nat.add_le_add_right (e.2 _ _ h) 1⟩, by ext k simp only [Set.mem_range, Set.mem_Icc, Nat.card_eq_fintype_card] constructor · rintro ⟨x, rfl⟩ exact ⟨Nat.succ_le_succ (Nat.zero_le _), Nat.succ_le_of_lt (e.1 x).isLt⟩ · rintro ⟨h1, h2⟩ refine ⟨e.1.symm ⟨k - 1, by omega⟩, ?_⟩ change (e.1 (e.1.symm ⟨k - 1, by omega⟩)).val + 1 = k rw [Equiv.apply_symm_apply] dsimp omega⟩ invFun σ := by have hcard : Nat.card P = Fintype.card P := Nat.card_eq_fintype_card have hmem : ∀ x : P, 1 ≤ σ.1 x ∧ σ.1 x ≤ Fintype.card P := by intro x have hx : σ.1 x ∈ Set.range σ.1 := Set.mem_range_self x rw [σ.2, Set.mem_Icc] at hx exact ⟨hx.1, hcard ▸ hx.2⟩ let f : P → Fin (Fintype.card P) := fun x => ⟨σ.1 x - 1, by have := hmem x; omega⟩ have hsurj : Function.Surjective f := by intro ⟨k, hk⟩ have hk_mem : k + 1 ∈ Set.range σ.1 := by rw [σ.2, Set.mem_Icc] omega rcases hk_mem with ⟨x, hx⟩ refine ⟨x, Fin.ext ?_⟩ change σ.1 x - 1 = k omega have hbij : Function.Bijective f := (Fintype.bijective_iff_surjective_and_card f).mpr ⟨hsurj, (Fintype.card_fin _).symm⟩ refine ⟨Equiv.ofBijective f hbij, ?_⟩ intro x y hxy change σ.1 x - 1 ≤ σ.1 y - 1 exact Nat.sub_le_sub_right (σ.1.monotone hxy) 1 left_inv e := by apply Subtype.ext ext x change (e.1 x).val + 1 - 1 = (e.1 x).val omega right_inv σ := by apply Subtype.ext ext x have hx : σ.1 x ∈ Set.range σ.1 := Set.mem_range_self x rw [σ.2, Set.mem_Icc] at hx have h1 : 1 ≤ σ.1 x := hx.1 change σ.1 x - 1 + 1 = σ.1 x omega /-- Any `IsBalancedPair x y` directly yields the exact `FormalConjectures` rational balance statement for `{ σ : P →o ℕ | Set.range σ = Set.Icc 1 (Nat.card P) }`. -/ theorem formalConjectures_of_isBalancedPair (P : Type*) [Finite P] [PartialOrder P] (total_ext : Set (P →o ℕ)) (total_ext_def : ∀ σ, σ ∈ total_ext ↔ Set.range σ = Set.Icc 1 (Nat.card P)) : letI := Fintype.ofFinite P ∀ {x y : P}, IsBalancedPair x y → (({σ ∈ total_ext | σ x < σ y}.ncard : ℚ) / (total_ext.ncard : ℚ)) ∈ Set.Icc (1 / 3 : ℚ) (2 / 3 : ℚ) := by let _ : Fintype P := Fintype.ofFinite P intro x y hbal have hset : total_ext = { σ : P →o ℕ | Set.range σ = Set.Icc 1 (Nat.card P) } := by ext σ; exact total_ext_def σ let eEquiv := linExtEquivFormalConjectures P have htot_ncard : total_ext.ncard = totalLinExt P := by classical rw [hset] change Set.ncard { σ : P →o ℕ | Set.range σ = Set.Icc 1 (Nat.card P) } = Fintype.card (LinExt P) rw [← Nat.card_coe_set_eq] exact (Nat.card_congr eEquiv.symm).trans Nat.card_eq_fintype_card have hlt_iff : ∀ (e : LinExt P), (eEquiv e).1 x < (eEquiv e).1 y ↔ e.1 x < e.1 y := by intro e change (e.1 x).val + 1 < (e.1 y).val + 1 ↔ (e.1 x).val < (e.1 y).val omega have hsub_equiv : { e : LinExt P // e.1 x < e.1 y } ≃ { σ : P →o ℕ // σ ∈ total_ext ∧ σ x < σ y } := { toFun := fun e => ⟨(eEquiv e.1).1, (total_ext_def _).mpr (eEquiv e.1).2, (hlt_iff e.1).mpr e.2⟩ invFun := fun σ => ⟨eEquiv.symm ⟨σ.1, (total_ext_def _).mp σ.2.1⟩, by rw [← hlt_iff] have hrt := congrArg Subtype.val (eEquiv.right_inv ⟨σ.1, (total_ext_def _).mp σ.2.1⟩) simpa [hrt] using σ.2.2⟩ left_inv := fun e => by apply Subtype.ext exact eEquiv.left_inv e.1 right_inv := fun σ => by apply Subtype.ext change (eEquiv (eEquiv.symm ⟨σ.1, (total_ext_def _).mp σ.2.1⟩)).1 = σ.1 rw [eEquiv.apply_symm_apply] } have hsub_ncard : {σ ∈ total_ext | σ x < σ y}.ncard = countBefore x y := by classical rw [← Nat.card_coe_set_eq] exact (Nat.card_congr hsub_equiv.symm).trans Nat.card_eq_fintype_card rw [htot_ncard, hsub_ncard] exact (isBalancedPair_iff_rat hbal.1 x y).mp hbal /-! ## Section 2: Discrete Intermediate-Value Lemma (Cumulative Step Bound) -/ /-- If a nonnegative sequence `p : Fin (m + 1) → ℕ` with positive sum `T = ∑ j, p j` satisfies `3 * p j ≤ T` for every `j`, then some proper prefix sum `∑ t ≤ i, p t` (`i : Fin m`) lies in `[T/3, 2T/3]`. -/ lemma exists_balanced_prefix {m : ℕ} (p : Fin (m + 1) → ℕ) (hT : 0 < ∑ j : Fin (m + 1), p j) (hstep : ∀ j : Fin (m + 1), 3 * p j ≤ ∑ t : Fin (m + 1), p t) : ∃ i : Fin m, (∑ t : Fin (m + 1), p t) ≤ 3 * (∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val ≤ i.val), p t) ∧ 3 * (∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val ≤ i.val), p t) ≤ 2 * (∑ t : Fin (m + 1), p t) := by set T := ∑ t : Fin (m + 1), p t let S : ℕ → ℕ := fun k => ∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val < k), p t have hS0 : S 0 = 0 := by simp [S] have hS_full : S (m + 1) = T := by simp only [S, T] congr 1 exact Finset.filter_true_of_mem fun t _ => t.isLt have hS_succ : ∀ k (hk : k < m + 1), S (k + 1) = S k + p ⟨k, hk⟩ := by intro k hk simp only [S] have hfilt : Finset.univ.filter (fun t : Fin (m + 1) => t.val < k + 1) = insert ⟨k, hk⟩ (Finset.univ.filter (fun t : Fin (m + 1) => t.val < k)) := by ext t simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert, Fin.ext_iff] omega rw [hfilt, Finset.sum_insert] · ring · simp have hex : ∃ k, T ≤ 3 * S k := ⟨m + 1, by omega⟩ classical let k₀ := Nat.find hex have hk₀_spec : T ≤ 3 * S k₀ := Nat.find_spec hex have hk₀_pos : 0 < k₀ := by by_contra h0 have hk0 : k₀ = 0 := by omega rw [hk0, hS0] at hk₀_spec omega have hk₀_le : k₀ ≤ m + 1 := Nat.find_min' hex (by omega) have hprev : 3 * S (k₀ - 1) < T := by have := Nat.find_min hex (show k₀ - 1 < k₀ by omega) omega have hk₀_pred_lt : k₀ - 1 < m + 1 := by omega have hS_k₀ : S k₀ = S (k₀ - 1) + p ⟨k₀ - 1, hk₀_pred_lt⟩ := by have heq : k₀ = (k₀ - 1) + 1 := by omega conv_lhs => rw [heq] exact hS_succ (k₀ - 1) hk₀_pred_lt have hupper : 3 * S k₀ ≤ 2 * T := by have hst := hstep ⟨k₀ - 1, hk₀_pred_lt⟩ omega have hk₀_lt_succ : k₀ ≤ m := by by_contra hgt have hk_eq : k₀ = m + 1 := by omega rw [hk_eq, hS_full] at hupper omega have hfilt_eq : Finset.univ.filter (fun t : Fin (m + 1) => t.val ≤ k₀ - 1) = Finset.univ.filter (fun t : Fin (m + 1) => t.val < k₀) := by ext t; simp only [Finset.mem_filter, Finset.mem_univ, true_and]; omega refine ⟨⟨k₀ - 1, by omega⟩, ?_, ?_⟩ · rw [hfilt_eq]; exact hk₀_spec · rw [hfilt_eq]; exact hupper /-! ## Section 3: Theorem D — The Exact Rising-Factorial Fiber Ratio Identity -/ /-- Standard hockey-stick identity in the shifted form `∑_{x=0}^r C(d+x, d) = C(d+r+1, d+1)`. -/ lemma hockey_stick_shifted (d r : ℕ) : ∑ x ∈ Finset.range (r + 1), (d + x).choose d = (d + r + 1).choose (d + 1) := by induction r with | zero => simp | succ r ih => rw [Finset.sum_range_succ, ih] have h1 : d + (r + 1) + 1 = (d + r + 1) + 1 := by omega have h2 : d + (r + 1) = d + r + 1 := by omega rw [h1, h2, Nat.choose_succ_succ (d + r + 1) d, add_comm] /-- Weighted hockey-stick identity: `∑_{x=0}^r C(d+x+1, d+1) = ∑_{x=0}^r C(d+x, d) * (r - x + 1)`. -/ lemma hockey_stick_weighted (d r : ℕ) : ∑ x ∈ Finset.range (r + 1), (d + x + 1).choose (d + 1) = ∑ x ∈ Finset.range (r + 1), (d + x).choose d * (r - x + 1) := by induction r with | zero => simp | succ r ih => rw [Finset.sum_range_succ, ih] have hsplit : ∑ x ∈ Finset.range (r + 2), (d + x).choose d * (r + 1 - x + 1) = (∑ x ∈ Finset.range (r + 1), (d + x).choose d * (r - x + 1)) + ∑ x ∈ Finset.range (r + 2), (d + x).choose d := by rw [Finset.sum_range_succ (fun x => (d + x).choose d * (r + 1 - x + 1)) (r + 1)] rw [Finset.sum_range_succ (fun x => (d + x).choose d) (r + 1)] have hterm : ∑ x ∈ Finset.range (r + 1), (d + x).choose d * (r + 1 - x + 1) = (∑ x ∈ Finset.range (r + 1), (d + x).choose d * (r - x + 1)) + ∑ x ∈ Finset.range (r + 1), (d + x).choose d := by rw [← Finset.sum_add_distrib] apply Finset.sum_congr rfl intro x hx have hxr : x ≤ r := Nat.lt_succ_iff.mp (Finset.mem_range.mp hx) have hsub : r + 1 - x + 1 = (r - x + 1) + 1 := by omega rw [hsub, mul_add, mul_one] rw [hterm] have hlast : r + 1 - (r + 1) + 1 = 1 := by omega rw [hlast, mul_one] ring rw [hsplit, hockey_stick_shifted d (r + 1)] /-- **Theorem D (Exact Rising-Factorial Fiber Ratio Identity)**: For all natural numbers `d, r : ℕ`, `∑_{x=0}^r C(r, x) (d+x)! (r-x)! (d+x+1) = (d+1) ∑_{x=0}^r C(r, x) (d+x)! (r-x)! (r-x+1)`. -/ theorem rising_factorial_fiber_ratio (d r : ℕ) : ∑ x ∈ Finset.range (r + 1), r.choose x * (d + x).factorial * (r - x).factorial * (d + x + 1) = (d + 1) * ∑ x ∈ Finset.range (r + 1), r.choose x * (d + x).factorial * (r - x).factorial * (r - x + 1) := by have hL : ∀ x ∈ Finset.range (r + 1), r.choose x * (d + x).factorial * (r - x).factorial * (d + x + 1) = r.factorial * (d + 1).factorial * (d + x + 1).choose (d + 1) := by intro x hx have hxr : x ≤ r := Nat.lt_succ_iff.mp (Finset.mem_range.mp hx) have h1 := Nat.choose_mul_factorial_mul_factorial hxr have h2 : (d + x + 1).choose (d + 1) * (d + 1).factorial * x.factorial = (d + x + 1).factorial := by have hle : d + 1 ≤ d + x + 1 := by omega have h := Nat.choose_mul_factorial_mul_factorial hle have hsub : d + x + 1 - (d + 1) = x := by omega simpa [hsub] using h have hfac : (d + x + 1).factorial = (d + x + 1) * (d + x).factorial := Nat.factorial_succ (d + x) have hmul : (r.choose x * (d + x).factorial * (r - x).factorial * (d + x + 1)) * x.factorial = (r.factorial * (d + 1).factorial * (d + x + 1).choose (d + 1)) * x.factorial := by calc (r.choose x * (d + x).factorial * (r - x).factorial * (d + x + 1)) * x.factorial = (r.choose x * x.factorial * (r - x).factorial) * ((d + x + 1) * (d + x).factorial) := by ring _ = r.factorial * (d + x + 1).factorial := by rw [h1, hfac] _ = r.factorial * ((d + x + 1).choose (d + 1) * (d + 1).factorial * x.factorial) := by rw [← h2] _ = (r.factorial * (d + 1).factorial * (d + x + 1).choose (d + 1)) * x.factorial := by ring exact Nat.eq_of_mul_eq_mul_right (Nat.factorial_pos x) hmul have hR : ∀ x ∈ Finset.range (r + 1), r.choose x * (d + x).factorial * (r - x).factorial * (r - x + 1) = r.factorial * d.factorial * ((d + x).choose d * (r - x + 1)) := by intro x hx have hxr : x ≤ r := Nat.lt_succ_iff.mp (Finset.mem_range.mp hx) have h1 := Nat.choose_mul_factorial_mul_factorial hxr have h2 : (d + x).choose d * d.factorial * x.factorial = (d + x).factorial := by have hle : d ≤ d + x := by omega have h := Nat.choose_mul_factorial_mul_factorial hle have hsub : d + x - d = x := by omega simpa [hsub] using h have hmul : (r.choose x * (d + x).factorial * (r - x).factorial * (r - x + 1)) * x.factorial = (r.factorial * d.factorial * ((d + x).choose d * (r - x + 1))) * x.factorial := by calc (r.choose x * (d + x).factorial * (r - x).factorial * (r - x + 1)) * x.factorial = (r.choose x * x.factorial * (r - x).factorial) * (d + x).factorial * (r - x + 1) := by ring _ = r.factorial * ((d + x).choose d * d.factorial * x.factorial) * (r - x + 1) := by rw [h1, ← h2] _ = (r.factorial * d.factorial * ((d + x).choose d * (r - x + 1))) * x.factorial := by ring exact Nat.eq_of_mul_eq_mul_right (Nat.factorial_pos x) hmul rw [Finset.sum_congr rfl hL, Finset.sum_congr rfl hR] rw [← Finset.mul_sum, ← Finset.mul_sum, hockey_stick_weighted d r] rw [Nat.factorial_succ d] ring /-! ## Section 4: Pure Slot-Assignment Model and Exact Balance Proof -/ /-- Interval constraints `[l a, r a] ⊆ {0, ..., m}` for elements of an antichain `A` relative to a chain of length `m`, satisfying the Helly intersection condition `l a ≤ r b`. -/ structure SplitIntervals (A : Type*) (m : ℕ) where l : A → ℕ r : A → ℕ hle : ∀ a, l a ≤ r a hrm : ∀ a, r a ≤ m hhelly : ∀ a b, l a ≤ r b /-- Valid slot assignments `s : A → Fin (m + 1)` respecting `I.l a ≤ s a ≤ I.r a`. -/ abbrev ValidSlot {A : Type*} {m : ℕ} (I : SplitIntervals A m) : Type _ := { s : A → Fin (m + 1) // ∀ a, I.l a ≤ (s a).val ∧ (s a).val ≤ I.r a } /-- Number of elements of `A` assigned to slot `j`. -/ def slotCount {A : Type*} [Fintype A] {m : ℕ} (s : A → Fin (m + 1)) (j : Fin (m + 1)) : ℕ := (Finset.univ.filter (fun a : A => s a = j)).card /-- Factorial multiplicity weight `∏_j (n_j(s))!` of a slot assignment `s`. -/ def slotWeight {A : Type*} [Fintype A] {m : ℕ} (s : A → Fin (m + 1)) : ℕ := ∏ j : Fin (m + 1), (slotCount s j).factorial lemma slotWeight_pos {A : Type*} [Fintype A] {m : ℕ} (s : A → Fin (m + 1)) : 0 < slotWeight s := by unfold slotWeight exact Finset.prod_pos fun j _ => Nat.factorial_pos _ /-- Restriction of `SplitIntervals A m` to `{ b : A // b ≠ a }`. -/ def SplitIntervals.erase {A : Type*} {m : ℕ} (I : SplitIntervals A m) (a : A) : SplitIntervals { b : A // b ≠ a } m where l b := I.l b.1 r b := I.r b.1 hle b := I.hle b.1 hrm b := I.hrm b.1 hhelly b₁ b₂ := I.hhelly b₁.1 b₂.1 /-- Total weight of all valid slot assignments. -/ def totalWeight {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) : ℕ := ∑ s : ValidSlot I, slotWeight s.1 /-- Marginal weight of valid slot assignments placing `a` in slot `j`. -/ def marginalWeight {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) (a : A) (j : Fin (m + 1)) : ℕ := ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => s.1 a = j), slotWeight s.1 /-- Weight of valid slot assignments with `s a < s b`. -/ def slotLtWeight {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) (a b : A) : ℕ := ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => s.1 a < s.1 b), slotWeight s.1 /-- Weight of valid slot assignments with `s a = s b`. -/ def slotEqWeight {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) (a b : A) : ℕ := ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => s.1 a = s.1 b), slotWeight s.1 lemma totalWeight_pos {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) : 0 < totalWeight I := by unfold totalWeight let s₀ : ValidSlot I := ⟨fun a => ⟨I.l a, Nat.lt_succ_of_le ((I.hle a).trans (I.hrm a))⟩, fun a => ⟨le_rfl, I.hle a⟩⟩ exact Finset.sum_pos' (fun s _ => Nat.zero_le _) ⟨s₀, Finset.mem_univ _, slotWeight_pos s₀.1⟩ lemma sum_marginalWeight {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) (a : A) : ∑ j : Fin (m + 1), marginalWeight I a j = totalWeight I := by unfold marginalWeight totalWeight rw [Finset.sum_fiberwise_of_maps_to (g := fun s : ValidSlot I => s.1 a) (fun _ _ => Finset.mem_univ _)] /-- **Exact Marginal Formula**: placing `a` in slot `j ∈ I_a` multiplies the residual weight of `s'` on `A \ {a}` by `slotCount s' j + 1`. -/ lemma marginalWeight_eq_erase {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) (a : A) (j : Fin (m + 1)) (hj : I.l a ≤ j.val ∧ j.val ≤ I.r a) : marginalWeight I a j = ∑ s' : ValidSlot (I.erase a), slotWeight s'.1 * (slotCount s'.1 j + 1) := by unfold marginalWeight let e : { s : ValidSlot I // s.1 a = j } ≃ ValidSlot (I.erase a) := { toFun := fun s => ⟨fun b => s.1.1 b.1, fun b => s.1.2 b.1⟩ invFun := fun s' => ⟨⟨fun x => if h : x = a then j else s'.1 ⟨x, h⟩, fun x => by by_cases h : x = a · subst h; simpa using hj · dsimp only; rw [dif_neg h]; exact s'.2 ⟨x, h⟩⟩, by simp⟩ left_inv := fun s => by apply Subtype.ext; apply Subtype.ext; funext x by_cases h : x = a · subst h; simp [s.2] · simp [h] right_inv := fun s' => by apply Subtype.ext; funext b simp [b.2] } have hcoe : ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => s.1 a = j), slotWeight s.1 = ∑ s : { s : ValidSlot I // s.1 a = j }, slotWeight s.1.1 := Finset.sum_subtype (Finset.univ.filter (fun s : ValidSlot I => s.1 a = j)) (p := fun s : ValidSlot I => s.1 a = j) (fun _ => by simp) (fun s => slotWeight s.1) rw [hcoe] refine Fintype.sum_equiv e _ _ ?_ intro s have hcount : ∀ t : Fin (m + 1), slotCount s.1.1 t = slotCount (e s).1 t + (if t = j then 1 else 0) := by intro t unfold slotCount have hbij : (Finset.univ.filter (fun b : { b : A // b ≠ a } => s.1.1 b.1 = t)).card = ((Finset.univ.filter (fun x : A => s.1.1 x = t)).erase a).card := by refine Finset.card_bij (fun b _ => b.1) ?_ ?_ ?_ · intro b hb simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hb exact Finset.mem_erase.mpr ⟨b.2, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hb⟩⟩ · intro b₁ _ b₂ _ h; exact Subtype.ext h · intro x hx rw [Finset.mem_erase, Finset.mem_filter] at hx exact ⟨⟨x, hx.1⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx.2.2⟩, rfl⟩ change (Finset.univ.filter (fun x : A => s.1.1 x = t)).card = (Finset.univ.filter (fun b : { b : A // b ≠ a } => s.1.1 b.1 = t)).card + (if t = j then 1 else 0) rw [hbij] by_cases ht : t = j · subst ht have hmem : a ∈ Finset.univ.filter (fun x : A => s.1.1 x = t) := Finset.mem_filter.mpr ⟨Finset.mem_univ _, s.2⟩ simp only [↓reduceIte] exact (Finset.card_erase_add_one hmem).symm · have hnmem : a ∉ Finset.univ.filter (fun x : A => s.1.1 x = t) := by simp [s.2, Ne.symm ht] simp only [ht, ↓reduceIte, add_zero] rw [Finset.erase_eq_of_notMem hnmem] unfold slotWeight rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ j)] rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ j)] have hprod_eq : ∏ t ∈ Finset.univ.erase j, (slotCount s.1.1 t).factorial = ∏ t ∈ Finset.univ.erase j, (slotCount (e s).1 t).factorial := by refine Finset.prod_congr rfl fun t ht => ?_ have hne : t ≠ j := (Finset.mem_erase.mp ht).1 rw [hcount t, if_neg hne, add_zero] rw [hprod_eq, hcount j, if_pos rfl, Nat.factorial_succ] ring /-- **Unified Fiber-Ratio Comparison Theorem**: Suppose every `b : A'` can enter slot `u`, and let `v ≠ u`. Let `D = { b : A' // ¬ (I.l b ≤ v ≤ I.r b) }` be the elements forbidden from slot `v`. Partitioning `ValidSlot I` into fibers indexed by `(s|_D, R, s|_{B \ R})` and applying `rising_factorial_fiber_ratio` on each fiber yields: 1. `∑ s', w(s') * (n_u(s') + 1) ≥ ∑ s', w(s') * (n_v(s') + 1)` always; 2. Equality holds when `D` is empty; 3. Strict `< 2 * ...` holds when `|D| ≤ 1` and some valid `s'` has `n_u(s'|_D) = 0`. -/ lemma fiber_sum_comparison {A' : Type*} [Fintype A'] [DecidableEq A'] {m : ℕ} (I : SplitIntervals A' m) (u v : Fin (m + 1)) (huv : u ≠ v) (hu : ∀ b : A', I.l b ≤ u.val ∧ u.val ≤ I.r b) : let D := { b : A' // ¬ (I.l b ≤ v.val ∧ v.val ≤ I.r b) } let Su := ∑ s : ValidSlot I, slotWeight s.1 * (slotCount s.1 u + 1) let Sv := ∑ s : ValidSlot I, slotWeight s.1 * (slotCount s.1 v + 1) Sv ≤ Su ∧ (IsEmpty D → Su = Sv) ∧ ((∀ d₁ d₂ : D, d₁ = d₂) → (∃ s₀ : ValidSlot I, ∀ d : D, s₀.1 d.1 ≠ u) → Su < 2 * Sv) := by classical let inV : A' → Prop := fun b => I.l b ≤ v.val ∧ v.val ≤ I.r b let D := { b : A' // ¬ inV b } let B := { b : A' // inV b } let FiberKey := (D → Fin (m + 1)) × Finset B × (B → Fin (m + 1)) let keyOf : ValidSlot I → FiberKey := fun s => (fun d => s.1 d.1, Finset.univ.filter (fun b : B => s.1 b.1 = u ∨ s.1 b.1 = v), fun b => if s.1 b.1 = u ∨ s.1 b.1 = v then u else s.1 b.1) have hkey_decomp : ∀ (f : ValidSlot I → ℕ), ∑ s : ValidSlot I, f s = ∑ k ∈ Finset.univ.image keyOf, ∑ s ∈ Finset.univ.filter (fun s => keyOf s = k), f s := by intro f rw [Finset.sum_fiberwise_of_maps_to (g := keyOf) (fun s _ => Finset.mem_image_of_mem keyOf (Finset.mem_univ s))] have hfiber : ∀ s₀ : ValidSlot I, let k := keyOf s₀ let d := (Finset.univ.filter (fun x : D => s₀.1 x.1 = u)).card let Fu := ∑ s ∈ Finset.univ.filter (fun s => keyOf s = k), slotWeight s.1 * (slotCount s.1 u + 1) let Fv := ∑ s ∈ Finset.univ.filter (fun s => keyOf s = k), slotWeight s.1 * (slotCount s.1 v + 1) Fu = (d + 1) * Fv ∧ 0 < Fv := by intro s₀ set k := keyOf s₀ set R : Finset B := Finset.univ.filter (fun b : B => s₀.1 b.1 = u ∨ s₀.1 b.1 = v) set d := (Finset.univ.filter (fun x : D => s₀.1 x.1 = u)).card let toPow : { s : ValidSlot I // keyOf s = k } → { X : Finset B // X ⊆ R } := fun s => ⟨Finset.univ.filter (fun b : B => s.1.1 b.1 = u), by intro b hb simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hb have hR : Finset.univ.filter (fun b : B => s.1.1 b.1 = u ∨ s.1.1 b.1 = v) = R := congrArg (fun z => z.2.1) s.2 rw [← hR] exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, Or.inl hb⟩⟩ let fromPow : { X : Finset B // X ⊆ R } → { s : ValidSlot I // keyOf s = k } := fun X => let f : A' → Fin (m + 1) := fun a => if h : inV a then if ⟨a, h⟩ ∈ R then (if ⟨a, h⟩ ∈ X.1 then u else v) else s₀.1 a else s₀.1 a ⟨⟨f, fun a => by dsimp only [f] split_ifs with h1 h2 h3 · exact hu a · exact h1 · exact s₀.2 a · exact s₀.2 a⟩, by refine Prod.ext ?_ (Prod.ext ?_ ?_) · funext x dsimp only [keyOf, k, f] rw [dif_neg x.2] · ext b simp only [keyOf, k, Finset.mem_filter, Finset.mem_univ, true_and, f, dif_pos b.2] by_cases hb : b ∈ R · have hb0 : s₀.1 b.1 = u ∨ s₀.1 b.1 = v := (Finset.mem_filter.mp hb).2 rw [if_pos hb] by_cases hX : b ∈ X.1 · rw [if_pos hX]; exact iff_of_true (Or.inl rfl) hb0 · rw [if_neg hX]; exact iff_of_true (Or.inr rfl) hb0 · rw [if_neg hb] · funext b dsimp only [keyOf, k, f] have hb_eq : (if h : inV b.1 then if ⟨b.1, h⟩ ∈ R then if ⟨b.1, h⟩ ∈ X.1 then u else v else s₀.1 b.1 else s₀.1 b.1) = if b ∈ R then if b ∈ X.1 then u else v else s₀.1 b.1 := by rw [dif_pos b.2] simp only [hb_eq] by_cases hb : b ∈ R · have hb0 : s₀.1 b.1 = u ∨ s₀.1 b.1 = v := (Finset.mem_filter.mp hb).2 simp only [hb, ↓reduceIte, hb0] by_cases hX : b ∈ X.1 · simp [hX] · simp [hX] · simp [hb]⟩ let eFib : { s : ValidSlot I // keyOf s = k } ≃ { X : Finset B // X ⊆ R } := { toFun := toPow invFun := fromPow left_inv := fun s => by apply Subtype.ext; apply Subtype.ext; funext a have hD : ∀ x : D, s.1.1 x.1 = s₀.1 x.1 := fun x => congrFun (congrArg Prod.fst s.2) x have hR : Finset.univ.filter (fun b : B => s.1.1 b.1 = u ∨ s.1.1 b.1 = v) = R := congrArg (fun z => z.2.1) s.2 have hOut : ∀ b : B, (if s.1.1 b.1 = u ∨ s.1.1 b.1 = v then u else s.1.1 b.1) = (if s₀.1 b.1 = u ∨ s₀.1 b.1 = v then u else s₀.1 b.1) := fun b => congrFun (congrArg (fun z => z.2.2) s.2) b dsimp only [fromPow, toPow] by_cases ha : inV a · rw [dif_pos ha] by_cases hbR : (⟨a, ha⟩ : B) ∈ R · rw [if_pos hbR] have hmem : s.1.1 a = u ∨ s.1.1 a = v := by have := hbR; rw [← hR] at this exact (Finset.mem_filter.mp this).2 by_cases hsu : s.1.1 a = u · have hmemU : (⟨a, ha⟩ : B) ∈ Finset.univ.filter (fun b : B => s.1.1 b.1 = u) := Finset.mem_filter.mpr ⟨Finset.mem_univ _, hsu⟩ rw [if_pos hmemU, hsu] · have hsv : s.1.1 a = v := hmem.resolve_left hsu have hnot : (⟨a, ha⟩ : B) ∉ Finset.univ.filter (fun b : B => s.1.1 b.1 = u) := by simp [hsu] rw [if_neg hnot, hsv] · rw [if_neg hbR] have hb0 : ¬ (s₀.1 a = u ∨ s₀.1 a = v) := by intro h; exact hbR (Finset.mem_filter.mpr ⟨Finset.mem_univ _, h⟩) have hbs : ¬ (s.1.1 a = u ∨ s.1.1 a = v) := by intro h; exact hbR (hR ▸ Finset.mem_filter.mpr ⟨Finset.mem_univ _, h⟩) have ho := hOut ⟨a, ha⟩ simp [hb0, hbs] at ho exact ho.symm · rw [dif_neg ha] exact (hD ⟨a, ha⟩).symm right_inv := fun X => by apply Subtype.ext; ext b simp only [toPow, fromPow, Finset.mem_filter, Finset.mem_univ, true_and, dif_pos b.2] by_cases hbR : b ∈ R · rw [if_pos hbR] by_cases hbX : b ∈ X.1 · rw [if_pos hbX]; exact iff_of_true rfl hbX · rw [if_neg hbX]; exact iff_of_false (Ne.symm huv) hbX · rw [if_neg hbR] have hnotX : b ∉ X.1 := fun h => hbR (X.2 h) have hnotu : s₀.1 b.1 ≠ u := fun h => hbR (Finset.mem_filter.mpr ⟨Finset.mem_univ _, Or.inl h⟩) exact iff_of_false hnotu hnotX } have hcnt_other : ∀ (X : { X : Finset B // X ⊆ R }) (t : Fin (m + 1)), t ≠ u → t ≠ v → slotCount (fromPow X).1.1 t = slotCount s₀.1 t := by intro X t htu htv unfold slotCount congr 1; ext a simp only [Finset.mem_filter, Finset.mem_univ, true_and, fromPow] by_cases ha : inV a · rw [dif_pos ha] by_cases hbR : (⟨a, ha⟩ : B) ∈ R · rw [if_pos hbR] have h0 : s₀.1 a = u ∨ s₀.1 a = v := (Finset.mem_filter.mp hbR).2 have hne0 : s₀.1 a ≠ t := by rcases h0 with h | h <;> exact h ▸ Ne.symm (by assumption) split_ifs · exact iff_of_false (Ne.symm htu) hne0 · exact iff_of_false (Ne.symm htv) hne0 · rw [if_neg hbR] · rw [dif_neg ha] have hcnt_u : ∀ (X : { X : Finset B // X ⊆ R }), slotCount (fromPow X).1.1 u = d + X.1.card := by intro X unfold slotCount let S := Finset.univ.filter (fun a : A' => (fromPow X).1.1 a = u) let S_D := S.filter (fun a => ¬ inV a) let S_B := S.filter (fun a => inV a) have hpart : S.card = S_D.card + S_B.card := by rw [← Finset.card_union_of_disjoint (Finset.disjoint_filter.mpr fun a _ h1 h2 => h1 h2)] congr 1; ext a simp only [Finset.mem_union, Finset.mem_filter] tauto have hSD : S_D.card = d := by refine Finset.card_bij (fun a ha => ⟨a, (Finset.mem_filter.mp ha).2⟩) ?_ ?_ ?_ · intro a ha simp only [S_D, S, Finset.mem_filter, Finset.mem_univ, true_and, fromPow] at ha rw [dif_neg ha.2] at ha exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, ha.1⟩ · intro a₁ _ a₂ _ h; exact congrArg Subtype.val h · intro x hx simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hx refine ⟨x.1, ?_, rfl⟩ simp only [S_D, S, Finset.mem_filter, Finset.mem_univ, true_and, fromPow, dif_neg x.2] exact ⟨hx, x.2⟩ have hSB : S_B.card = X.1.card := by refine Finset.card_bij (fun a ha => ⟨a, (Finset.mem_filter.mp ha).2⟩) ?_ ?_ ?_ · intro a ha simp only [S_B, S, Finset.mem_filter, Finset.mem_univ, true_and, fromPow] at ha rw [dif_pos ha.2] at ha by_cases hbR : (⟨a, ha.2⟩ : B) ∈ R · rw [if_pos hbR] at ha by_contra hnot rw [if_neg hnot] at ha exact huv ha.1.symm · rw [if_neg hbR] at ha exfalso exact hbR (Finset.mem_filter.mpr ⟨Finset.mem_univ _, Or.inl ha.1⟩) · intro a₁ _ a₂ _ h; exact congrArg Subtype.val h · intro b hb refine ⟨b.1, ?_, rfl⟩ simp only [S_B, S, Finset.mem_filter, Finset.mem_univ, true_and, fromPow, dif_pos b.2] rw [if_pos (X.2 hb), if_pos hb] exact ⟨rfl, b.2⟩ rw [hpart, hSD, hSB] have hcnt_v : ∀ (X : { X : Finset B // X ⊆ R }), slotCount (fromPow X).1.1 v = R.card - X.1.card := by intro X unfold slotCount have hcard_eq : (Finset.univ.filter (fun a : A' => (fromPow X).1.1 a = v)).card = (R \ X.1).card := by refine Finset.card_bij (fun a ha => ⟨a, ?_⟩) ?_ ?_ ?_ · simp only [Finset.mem_filter, Finset.mem_univ, true_and] at ha have hmem : I.l a ≤ v.val ∧ v.val ≤ I.r a := by have := (fromPow X).1.2 a rw [ha] at this exact this exact hmem · intro a ha simp only [Finset.mem_filter, Finset.mem_univ, true_and] at ha have haV : inV a := by have := (fromPow X).1.2 a; rw [ha] at this; exact this dsimp only [fromPow] at ha rw [dif_pos haV] at ha by_cases hbR : (⟨a, haV⟩ : B) ∈ R · rw [if_pos hbR] at ha have hnotX : (⟨a, haV⟩ : B) ∉ X.1 := by intro hX; rw [if_pos hX] at ha; exact huv ha exact Finset.mem_sdiff.mpr ⟨hbR, hnotX⟩ · rw [if_neg hbR] at ha exfalso exact hbR (Finset.mem_filter.mpr ⟨Finset.mem_univ _, Or.inr ha⟩) · intro a₁ _ a₂ _ h; exact congrArg Subtype.val h · intro b hb rw [Finset.mem_sdiff] at hb refine ⟨b.1, ?_, rfl⟩ simp only [Finset.mem_filter, Finset.mem_univ, true_and, fromPow, dif_pos b.2] rw [if_pos hb.1, if_neg hb.2] rw [hcard_eq, Finset.card_sdiff_of_subset X.2] let C_fib := ∏ t ∈ (Finset.univ.erase u).erase v, (slotCount s₀.1 t).factorial have hC_pos : 0 < C_fib := Finset.prod_pos fun t _ => Nat.factorial_pos _ have hw_eq : ∀ X : { X : Finset B // X ⊆ R }, slotWeight (fromPow X).1.1 = C_fib * (d + X.1.card).factorial * (R.card - X.1.card).factorial := by intro X unfold slotWeight have hvu : v ∈ Finset.univ.erase u := Finset.mem_erase.mpr ⟨Ne.symm huv, Finset.mem_univ v⟩ rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ u)] rw [← Finset.mul_prod_erase (Finset.univ.erase u) _ hvu] have hrest : ∏ t ∈ (Finset.univ.erase u).erase v, (slotCount (fromPow X).1.1 t).factorial = C_fib := by refine Finset.prod_congr rfl fun t ht => ?_ have htv : t ≠ v := (Finset.mem_erase.mp ht).1 have htu : t ≠ u := (Finset.mem_erase.mp (Finset.mem_erase.mp ht).2).1 rw [hcnt_other X t htu htv] rw [hrest, hcnt_u X, hcnt_v X] ring have hsum_card : ∀ (g : ℕ → ℕ), ∑ X : { X : Finset B // X ⊆ R }, g X.1.card = ∑ x ∈ Finset.range (R.card + 1), R.card.choose x * g x := by intro g have h1 : ∑ X : { X : Finset B // X ⊆ R }, g X.1.card = ∑ X ∈ R.powerset, g X.card := by rw [← Finset.sum_coe_sort R.powerset] refine Fintype.sum_equiv (Equiv.subtypeEquivRight fun X => Finset.mem_powerset.symm) _ _ ?_ intro _; rfl rw [h1] rw [← Finset.sum_fiberwise_of_maps_to (g := Finset.card) (t := Finset.range (R.card + 1)) (fun X hX => Finset.mem_range.mpr (Nat.lt_succ_of_le (Finset.card_le_card (Finset.mem_powerset.mp hX))))] refine Finset.sum_congr rfl fun x _ => ?_ have hfilt : R.powerset.filter (fun X => X.card = x) = R.powersetCard x := by ext X; simp [Finset.mem_powersetCard] rw [hfilt, Finset.sum_const_nat (fun X hX => by rw [(Finset.mem_powersetCard.mp hX).2])] rw [Finset.card_powersetCard] have hFu : ∑ s ∈ Finset.univ.filter (fun s => keyOf s = k), slotWeight s.1 * (slotCount s.1 u + 1) = C_fib * ∑ x ∈ Finset.range (R.card + 1), R.card.choose x * (d + x).factorial * (R.card - x).factorial * (d + x + 1) := by have hcoe : ∑ s ∈ Finset.univ.filter (fun s => keyOf s = k), slotWeight s.1 * (slotCount s.1 u + 1) = ∑ s : { s : ValidSlot I // keyOf s = k }, slotWeight s.1.1 * (slotCount s.1.1 u + 1) := Finset.sum_subtype (Finset.univ.filter (fun s => keyOf s = k)) (p := fun s : ValidSlot I => keyOf s = k) (fun _ => by simp) (fun s => slotWeight s.1 * (slotCount s.1 u + 1)) rw [hcoe] have htr : ∑ s : { s : ValidSlot I // keyOf s = k }, slotWeight s.1.1 * (slotCount s.1.1 u + 1) = ∑ X : { X : Finset B // X ⊆ R }, C_fib * ((d + X.1.card).factorial * (R.card - X.1.card).factorial * (d + X.1.card + 1)) := by refine (Fintype.sum_equiv eFib.symm _ _ ?_).symm intro X change C_fib * ((d + X.1.card).factorial * (R.card - X.1.card).factorial * (d + X.1.card + 1)) = slotWeight (fromPow X).1.1 * (slotCount (fromPow X).1.1 u + 1) rw [hw_eq X, hcnt_u X]; ring rw [htr, hsum_card (fun x => C_fib * ((d + x).factorial * (R.card - x).factorial * (d + x + 1))), Finset.mul_sum] refine Finset.sum_congr rfl fun x _ => by ring have hFv : ∑ s ∈ Finset.univ.filter (fun s => keyOf s = k), slotWeight s.1 * (slotCount s.1 v + 1) = C_fib * ∑ x ∈ Finset.range (R.card + 1), R.card.choose x * (d + x).factorial * (R.card - x).factorial * (R.card - x + 1) := by have hcoe : ∑ s ∈ Finset.univ.filter (fun s => keyOf s = k), slotWeight s.1 * (slotCount s.1 v + 1) = ∑ s : { s : ValidSlot I // keyOf s = k }, slotWeight s.1.1 * (slotCount s.1.1 v + 1) := Finset.sum_subtype (Finset.univ.filter (fun s => keyOf s = k)) (p := fun s : ValidSlot I => keyOf s = k) (fun _ => by simp) (fun s => slotWeight s.1 * (slotCount s.1 v + 1)) rw [hcoe] have htr : ∑ s : { s : ValidSlot I // keyOf s = k }, slotWeight s.1.1 * (slotCount s.1.1 v + 1) = ∑ X : { X : Finset B // X ⊆ R }, C_fib * ((d + X.1.card).factorial * (R.card - X.1.card).factorial * (R.card - X.1.card + 1)) := by refine (Fintype.sum_equiv eFib.symm _ _ ?_).symm intro X change C_fib * ((d + X.1.card).factorial * (R.card - X.1.card).factorial * (R.card - X.1.card + 1)) = slotWeight (fromPow X).1.1 * (slotCount (fromPow X).1.1 v + 1) rw [hw_eq X, hcnt_v X]; ring rw [htr, hsum_card (fun x => C_fib * ((d + x).factorial * (R.card - x).factorial * (R.card - x + 1))), Finset.mul_sum] refine Finset.sum_congr rfl fun x _ => by ring refine ⟨?_, ?_⟩ · rw [hFu, hFv, rising_factorial_fiber_ratio d R.card] ring · rw [hFv] refine Nat.mul_pos hC_pos ?_ refine Finset.sum_pos' (fun _ _ => Nat.zero_le _) ⟨0, Finset.mem_range.mpr (Nat.succ_pos _), ?_⟩ simp only [Nat.choose_zero_right, add_zero, tsub_zero, one_mul] exact Nat.mul_pos (Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _)) (Nat.succ_pos _) refine ⟨?_, ?_, ?_⟩ · rw [hkey_decomp (fun s => slotWeight s.1 * (slotCount s.1 v + 1)), hkey_decomp (fun s => slotWeight s.1 * (slotCount s.1 u + 1))] refine Finset.sum_le_sum fun k hk => ?_ rcases Finset.mem_image.mp hk with ⟨s₀, _, rfl⟩ have ⟨heq, _⟩ := hfiber s₀ rw [heq] exact Nat.le_mul_of_pos_left _ (Nat.succ_pos _) · intro hD rw [hkey_decomp (fun s => slotWeight s.1 * (slotCount s.1 u + 1)), hkey_decomp (fun s => slotWeight s.1 * (slotCount s.1 v + 1))] refine Finset.sum_congr rfl fun k hk => ?_ rcases Finset.mem_image.mp hk with ⟨s₀, _, rfl⟩ have ⟨heq, _⟩ := hfiber s₀ have hd0 : (Finset.univ.filter (fun x : D => s₀.1 x.1 = u)).card = 0 := Finset.card_eq_zero.mpr (Finset.eq_empty_of_isEmpty _) rw [heq, hd0, zero_add, one_mul] · intro hD_sub ⟨s₀, hs₀⟩ rw [hkey_decomp (fun s => slotWeight s.1 * (slotCount s.1 u + 1)), hkey_decomp (fun s => slotWeight s.1 * (slotCount s.1 v + 1)), Finset.mul_sum] have hsubD : Subsingleton D := ⟨hD_sub⟩ refine Finset.sum_lt_sum ?_ ?_ · intro k hk rcases Finset.mem_image.mp hk with ⟨s₁, _, rfl⟩ have ⟨heq, _⟩ := hfiber s₁ have hd_le : (Finset.univ.filter (fun x : D => s₁.1 x.1 = u)).card ≤ 1 := (Finset.card_le_univ _).trans (Fintype.card_le_one_iff_subsingleton.mpr hsubD) rw [heq] exact Nat.mul_le_mul_right _ (by omega) · refine ⟨keyOf s₀, Finset.mem_image_of_mem keyOf (Finset.mem_univ s₀), ?_⟩ have ⟨heq, hpos⟩ := hfiber s₀ have hd0 : (Finset.univ.filter (fun x : D => s₀.1 x.1 = u)).card = 0 := by rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff] intro d _; exact hs₀ d rw [heq, hd0, zero_add, one_mul] omega /-- **One-Line Tail Balance Lemma**: For any `a, b : A` and any reference slot `j₀ : Fin (m + 1)`, if `3 * (L b + R a) ≤ T` and `3 * (L a + R b) ≤ T`, then `(a, b)` is `1/3`-balanced! -/ lemma one_line_tail_balance {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) (a b : A) (j₀ : Fin (m + 1)) : let T := totalWeight I let L := fun x : A => ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => s.1 x < j₀), slotWeight s.1 let R := fun x : A => ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => j₀ < s.1 x), slotWeight s.1 let W₂ := 2 * slotLtWeight I a b + slotEqWeight I a b 3 * (L b + R a) ≤ T → 3 * (L a + R b) ≤ T → 2 * T ≤ 3 * W₂ ∧ 3 * W₂ ≤ 4 * T := by intro T L R W₂ h1 h2 have hsum : slotLtWeight I a b + slotEqWeight I a b + slotLtWeight I b a = T := by unfold slotLtWeight slotEqWeight T totalWeight have hdisj1 : Disjoint (Finset.univ.filter (fun s : ValidSlot I => s.1 a < s.1 b)) (Finset.univ.filter (fun s : ValidSlot I => s.1 a = s.1 b)) := Finset.disjoint_filter.mpr fun s _ hlt heq => (ne_of_lt hlt) heq have hdisj2 : Disjoint ((Finset.univ.filter (fun s : ValidSlot I => s.1 a < s.1 b)) ∪ (Finset.univ.filter (fun s : ValidSlot I => s.1 a = s.1 b))) (Finset.univ.filter (fun s : ValidSlot I => s.1 b < s.1 a)) := by rw [Finset.disjoint_union_left] exact ⟨Finset.disjoint_filter.mpr fun s _ h1 h2 => lt_asymm h1 h2, Finset.disjoint_filter.mpr fun s _ h1 h2 => (ne_of_lt h2) h1.symm⟩ rw [← Finset.sum_union hdisj1, ← Finset.sum_union hdisj2] congr 1; ext s simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, iff_true] rcases lt_trichotomy (s.1 a) (s.1 b) with h | h | h · exact Or.inl (Or.inl h) · exact Or.inl (Or.inr h) · exact Or.inr h have hsum_union_le : ∀ (S₁ S₂ : Finset (ValidSlot I)), ∑ s ∈ S₁ ∪ S₂, slotWeight s.1 ≤ ∑ s ∈ S₁, slotWeight s.1 + ∑ s ∈ S₂, slotWeight s.1 := by intro S₁ S₂ rw [← Finset.sdiff_union_self_eq_union, Finset.sum_union Finset.sdiff_disjoint] exact Nat.add_le_add_right (Finset.sum_le_sum_of_subset Finset.sdiff_subset) _ have hbound : ∀ x y : A, slotLtWeight I y x ≤ L y + R x := by intro x y unfold slotLtWeight have hsub : Finset.univ.filter (fun s : ValidSlot I => s.1 y < s.1 x) ⊆ Finset.univ.filter (fun s : ValidSlot I => s.1 y < j₀) ∪ Finset.univ.filter (fun s : ValidSlot I => j₀ < s.1 x) := by intro s hs simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hs simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] by_contra h push Not at h exact not_lt_of_ge (h.2.trans h.1) hs exact (Finset.sum_le_sum_of_subset hsub).trans (hsum_union_le _ _) have hb1 := hbound a b have hb2 := hbound b a dsimp only [W₂] omega /-- **Core Combinatorial Theorem (`splitIntervals_exists_balanced`)**: Every non-trivial `SplitIntervals A m` system (where `A` is nonempty and not a single singleton interval) admits either a `1/3`-balanced `(a, c_i)` pair or a `1/3`-balanced `(a, b)` pair! -/ theorem splitIntervals_exists_balanced {A : Type*} [Fintype A] [DecidableEq A] {m : ℕ} (I : SplitIntervals A m) (hne : Nonempty A) (hnt : ¬ (Fintype.card A = 1 ∧ ∀ a : A, I.l a = I.r a)) : (∃ (a : A) (i : Fin m), totalWeight I ≤ 3 * (∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val), slotWeight s.1) ∧ 3 * (∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val), slotWeight s.1) ≤ 2 * totalWeight I) ∨ (∃ (a b : A), a ≠ b ∧ 2 * totalWeight I ≤ 3 * (2 * slotLtWeight I a b + slotEqWeight I a b) ∧ 3 * (2 * slotLtWeight I a b + slotEqWeight I a b) ≤ 4 * totalWeight I) := by classical have hT_pos : 0 < totalWeight I := totalWeight_pos I have hA_ne : (Finset.univ : Finset A).Nonempty := Finset.univ_nonempty let Lstar := Finset.univ.sup' hA_ne I.l let Rstar := Finset.univ.inf' hA_ne I.r have hL_le : ∀ a : A, I.l a ≤ Lstar := fun a => Finset.le_sup' I.l (Finset.mem_univ a) have hR_ge : ∀ a : A, Rstar ≤ I.r a := fun a => Finset.inf'_le I.r (Finset.mem_univ a) have hLR : Lstar ≤ Rstar := by rw [Finset.sup'_le_iff] intro a _ rw [Finset.le_inf'_iff] intro b _ exact I.hhelly a b have hR_le_m : Rstar ≤ m := by rcases hne with ⟨a₀⟩ exact (hR_ge a₀).trans (I.hrm a₀) have hL_lt : Lstar < m + 1 := by omega have hcommon : ∀ (j : Fin (m + 1)), Lstar ≤ j.val → j.val ≤ Rstar → ∀ a : A, I.l a ≤ j.val ∧ j.val ≤ I.r a := fun j h1 h2 a => ⟨(hL_le a).trans h1, h2.trans (hR_ge a)⟩ have hdom : ∀ (a : A) (u v : Fin (m + 1)), Lstar ≤ u.val → u.val ≤ Rstar → marginalWeight I a v ≤ marginalWeight I a u := by intro a u v hu1 hu2 by_cases huv : u = v · subst huv; exact le_rfl · by_cases hv : I.l a ≤ v.val ∧ v.val ≤ I.r a · rw [marginalWeight_eq_erase I a u (hcommon u hu1 hu2 a), marginalWeight_eq_erase I a v hv] exact (fiber_sum_comparison (I.erase a) u v huv (fun b => hcommon u hu1 hu2 b.1)).1 · have hzero : marginalWeight I a v = 0 := by unfold marginalWeight apply Finset.sum_eq_zero intro s hs exfalso have hsa := s.2 a rw [(Finset.mem_filter.mp hs).2] at hsa exact hv hsa rw [hzero]; exact Nat.zero_le _ have hdom_eq : ∀ (a : A) (u v : Fin (m + 1)), Lstar ≤ u.val → u.val ≤ Rstar → Lstar ≤ v.val → v.val ≤ Rstar → marginalWeight I a u = marginalWeight I a v := fun a u v hu1 hu2 hv1 hv2 => le_antisymm (hdom a v u hv1 hv2) (hdom a u v hu1 hu2) have hprefix_eq : ∀ (a : A) (k : ℕ), ∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val ≤ k), marginalWeight I a t = ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ k), slotWeight s.1 := by intro a k unfold marginalWeight rw [← Finset.sum_fiberwise_of_maps_to (g := fun s : ValidSlot I => s.1 a) (t := Finset.univ.filter (fun t : Fin (m + 1) => t.val ≤ k)) (fun s hs => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hs).2⟩)] refine Finset.sum_congr rfl fun t ht => ?_ refine Finset.sum_congr ?_ (fun _ _ => rfl) ext s simp only [Finset.mem_filter, Finset.mem_univ, true_and] have ht_le : t.val ≤ k := (Finset.mem_filter.mp ht).2 constructor · intro h; exact ⟨h ▸ ht_le, h⟩ · rintro ⟨_, h⟩; exact h -- CASE 1: L* < R* (at least 2 common slots) by_cases hcase : Lstar < Rstar · left rcases hne with ⟨a₀⟩ let u₀ : Fin (m + 1) := ⟨Lstar, hL_lt⟩ let u₁ : Fin (m + 1) := ⟨Lstar + 1, by omega⟩ by_cases hsmall : 3 * marginalWeight I a₀ u₀ ≤ totalWeight I · have hstep : ∀ t : Fin (m + 1), 3 * marginalWeight I a₀ t ≤ ∑ j, marginalWeight I a₀ j := by intro t rw [sum_marginalWeight I a₀] exact (Nat.mul_le_mul_left 3 (hdom a₀ u₀ t le_rfl hLR)).trans hsmall have hsum_pos : 0 < ∑ j, marginalWeight I a₀ j := by rw [sum_marginalWeight I a₀]; exact hT_pos rcases exists_balanced_prefix (marginalWeight I a₀) hsum_pos hstep with ⟨i, hi1, hi2⟩ rw [sum_marginalWeight I a₀, hprefix_eq a₀ i.val] at hi1 hi2 exact ⟨a₀, i, hi1, hi2⟩ · have heq01 : marginalWeight I a₀ u₁ = marginalWeight I a₀ u₀ := hdom_eq a₀ u₁ u₀ (by dsimp [u₁]; omega) (by dsimp [u₁]; omega) le_rfl hLR let i₀ : Fin m := ⟨Lstar, by omega⟩ refine ⟨a₀, i₀, ?_, ?_⟩ · rw [← hprefix_eq a₀ i₀.val] have hle : marginalWeight I a₀ u₀ ≤ ∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val ≤ i₀.val), marginalWeight I a₀ t := Finset.single_le_sum (fun _ _ => Nat.zero_le _) (Finset.mem_filter.mpr ⟨Finset.mem_univ _, le_rfl⟩) omega · rw [← hprefix_eq a₀ i₀.val] have hcomp : (∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val ≤ i₀.val), marginalWeight I a₀ t) + (∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => ¬ t.val ≤ i₀.val), marginalWeight I a₀ t) = totalWeight I := by rw [Finset.sum_filter_add_sum_filter_not, sum_marginalWeight I a₀] have hle1 : marginalWeight I a₀ u₁ ≤ ∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => ¬ t.val ≤ i₀.val), marginalWeight I a₀ t := Finset.single_le_sum (fun _ _ => Nat.zero_le _) (Finset.mem_filter.mpr ⟨Finset.mem_univ _, by change ¬ (Lstar + 1 ≤ Lstar); omega⟩) omega · -- CASE 2: L* = R* = j₀ have hLR_eq : Lstar = Rstar := le_antisymm hLR (Nat.le_of_not_lt hcase) let j₀ : Fin (m + 1) := ⟨Lstar, hL_lt⟩ have hj0_val : j₀.val = Lstar := rfl by_cases hAC : ∃ (a : A) (i : Fin m), totalWeight I ≤ 3 * (∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val), slotWeight s.1) ∧ 3 * (∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val), slotWeight s.1) ≤ 2 * totalWeight I · exact Or.inl hAC · right push Not at hAC let L := fun x : A => ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => s.1 x < j₀), slotWeight s.1 let R := fun x : A => ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => j₀ < s.1 x), slotWeight s.1 have hsplit_a : ∀ a : A, L a + marginalWeight I a j₀ + R a = totalWeight I := by intro a have h1 : L a + marginalWeight I a j₀ = ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => s.1 a ≤ j₀), slotWeight s.1 := by unfold L marginalWeight rw [← Finset.sum_union (Finset.disjoint_filter.mpr fun s _ h1 h2 => (ne_of_lt h1) h2)] congr 1; ext s simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] exact le_iff_lt_or_eq.symm rw [h1] have h2 : Finset.univ.filter (fun s : ValidSlot I => j₀ < s.1 a) = Finset.univ.filter (fun s : ValidSlot I => ¬ s.1 a ≤ j₀) := by ext s; simp only [Finset.mem_filter, Finset.mem_univ, true_and, not_le] dsimp only [R] rw [h2, Finset.sum_filter_add_sum_filter_not] rfl have hmid_big : ∀ a : A, totalWeight I < 3 * marginalWeight I a j₀ := by intro a by_contra hle push Not at hle have hstep : ∀ t : Fin (m + 1), 3 * marginalWeight I a t ≤ ∑ j, marginalWeight I a j := by intro t rw [sum_marginalWeight I a] exact (Nat.mul_le_mul_left 3 (hdom a j₀ t le_rfl hLR)).trans hle have hsum_pos : 0 < ∑ j, marginalWeight I a j := by rw [sum_marginalWeight I a]; exact hT_pos rcases exists_balanced_prefix (marginalWeight I a) hsum_pos hstep with ⟨i, hi1, hi2⟩ rw [sum_marginalWeight I a, hprefix_eq a i.val] at hi1 hi2 exact not_le_of_gt (hAC a i hi1) hi2 have hL_small : ∀ a : A, 3 * L a < totalWeight I := by intro a by_cases hj0 : j₀.val = 0 · have hL0 : L a = 0 := by unfold L apply Finset.sum_eq_zero intro s hs have hlt : (s.1 a).val < j₀.val := (Finset.mem_filter.mp hs).2 omega rw [hL0]; omega · let i : Fin m := ⟨j₀.val - 1, by omega⟩ have hLi : L a = ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val), slotWeight s.1 := by unfold L congr 1; ext s simp only [Finset.mem_filter, Finset.mem_univ, true_and, Fin.lt_def, i] omega by_contra hge push Not at hge rw [hLi] at hge have hgt := hAC a i hge rw [← hLi] at hgt have hsp := hsplit_a a have hmb := hmid_big a omega have hR_small : ∀ a : A, 3 * R a < totalWeight I := by intro a by_cases hjm : j₀.val = m · have hR0 : R a = 0 := by unfold R apply Finset.sum_eq_zero intro s hs have hlt : j₀.val < (s.1 a).val := (Finset.mem_filter.mp hs).2 have hle : (s.1 a).val ≤ m := (s.2 a).2.trans (I.hrm a) omega rw [hR0]; omega · let i : Fin m := ⟨j₀.val, by omega⟩ have hRi : ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val), slotWeight s.1 + R a = totalWeight I := by have h1 : Finset.univ.filter (fun s : ValidSlot I => j₀ < s.1 a) = Finset.univ.filter (fun s : ValidSlot I => ¬ (s.1 a).val ≤ i.val) := by ext s; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Fin.lt_def, i, not_le] dsimp only [R] rw [h1, Finset.sum_filter_add_sum_filter_not] rfl by_contra hge push Not at hge have hsp := hsplit_a a have hmb := hmid_big a have hge_prefix : totalWeight I ≤ 3 * ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val), slotWeight s.1 := by omega have hgt_prefix := hAC a i hge_prefix omega let AL := Finset.univ.filter (fun a : A => I.r a = j₀.val) let AR := Finset.univ.filter (fun a : A => I.l a = j₀.val) have hAL_ne : AL.Nonempty := by rcases Finset.exists_mem_eq_inf' hA_ne I.r with ⟨a, _, ha⟩ exact ⟨a, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by change I.r a = Lstar; omega⟩⟩ have hAR_ne : AR.Nonempty := by rcases Finset.exists_mem_eq_sup' hA_ne I.l with ⟨a, _, ha⟩ exact ⟨a, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by change I.l a = Lstar; omega⟩⟩ have hR_zero_of_AL : ∀ a ∈ AL, R a = 0 := by intro a ha have hra : I.r a = j₀.val := (Finset.mem_filter.mp ha).2 unfold R apply Finset.sum_eq_zero intro s hs have hlt : j₀.val < (s.1 a).val := (Finset.mem_filter.mp hs).2 have hle : (s.1 a).val ≤ j₀.val := hra ▸ (s.2 a).2 omega have hL_zero_of_AR : ∀ a ∈ AR, L a = 0 := by intro a ha have hla : I.l a = j₀.val := (Finset.mem_filter.mp ha).2 unfold L apply Finset.sum_eq_zero intro s hs have hlt : (s.1 a).val < j₀.val := (Finset.mem_filter.mp hs).2 have hge : j₀.val ≤ (s.1 a).val := hla ▸ (s.2 a).1 omega -- Subcase 2a: |AL| ≥ 2 by_cases hAL2 : 2 ≤ AL.card · rcases Finset.one_lt_card.mp (by omega : 1 < AL.card) with ⟨a, ha, b, hb, hab⟩ refine ⟨a, b, hab, one_line_tail_balance I a b j₀ ?_ ?_⟩ · change 3 * (L b + R a) ≤ totalWeight I rw [hR_zero_of_AL a ha, add_zero]; exact le_of_lt (hL_small b) · change 3 * (L a + R b) ≤ totalWeight I rw [hR_zero_of_AL b hb, add_zero]; exact le_of_lt (hL_small a) · -- Subcase 2b: |AR| ≥ 2 by_cases hAR2 : 2 ≤ AR.card · rcases Finset.one_lt_card.mp (by omega : 1 < AR.card) with ⟨a, ha, b, hb, hab⟩ refine ⟨a, b, hab, one_line_tail_balance I a b j₀ ?_ ?_⟩ · change 3 * (L b + R a) ≤ totalWeight I rw [hL_zero_of_AR b hb, zero_add]; exact le_of_lt (hR_small a) · change 3 * (L a + R b) ≤ totalWeight I rw [hL_zero_of_AR a ha, zero_add]; exact le_of_lt (hR_small b) · have hAL1 : AL.card = 1 := by have := Finset.Nonempty.card_pos hAL_ne; omega have hAR1 : AR.card = 1 := by have := Finset.Nonempty.card_pos hAR_ne; omega rcases Finset.card_eq_one.mp hAL1 with ⟨aL, haL_eq⟩ rcases Finset.card_eq_one.mp hAR1 with ⟨aR, haR_eq⟩ have haL_mem : aL ∈ AL := haL_eq ▸ Finset.mem_singleton_self aL have haR_mem : aR ∈ AR := haR_eq ▸ Finset.mem_singleton_self aR -- Subcase 2c: aL = aR by_cases hsame : aL = aR · have hA2 : 2 ≤ Fintype.card A := by by_contra hlt have hcard1 : Fintype.card A = 1 := by have := Fintype.card_pos (α := A); omega apply hnt refine ⟨hcard1, fun x => ?_⟩ have hsubA : Subsingleton A := Fintype.card_le_one_iff_subsingleton.mp (by omega) have hxa : x = aL := hsubA.elim x aL rw [hxa] have hr : I.r aL = j₀.val := (Finset.mem_filter.mp haL_mem).2 have hl : I.l aL = j₀.val := by rw [hsame]; exact (Finset.mem_filter.mp haR_mem).2 omega have hne_other : (Finset.univ.erase aL).Nonempty := by rw [Finset.nonempty_iff_ne_empty] intro hemp have hc : (Finset.univ.erase aL).card = 0 := by rw [hemp]; rfl rw [Finset.card_erase_of_mem (Finset.mem_univ aL), Finset.card_univ] at hc omega rcases hne_other with ⟨b, hb⟩ have hba : aL ≠ b := (Finset.mem_erase.mp hb).1.symm refine ⟨aL, b, hba, one_line_tail_balance I aL b j₀ ?_ ?_⟩ · change 3 * (L b + R aL) ≤ totalWeight I rw [hR_zero_of_AL aL haL_mem, add_zero]; exact le_of_lt (hL_small b) · change 3 * (L aL + R b) ≤ totalWeight I rw [hsame, hL_zero_of_AR aR haR_mem, zero_add]; exact le_of_lt (hR_small b) · -- Subcase 2d: aL ≠ aR! Derive contradiction via fiber_sum_comparison! exfalso have hl_aL_lt : I.l aL < j₀.val := by have hle : I.l aL ≤ j₀.val := hL_le aL have hne : I.l aL ≠ j₀.val := by intro heq have : aL ∈ AR := Finset.mem_filter.mpr ⟨Finset.mem_univ _, heq⟩ rw [haR_eq, Finset.mem_singleton] at this exact hsame this omega have hr_aR_gt : j₀.val < I.r aR := by have hge : j₀.val ≤ I.r aR := by rw [hj0_val, hLR_eq]; exact hR_ge aR have hne : I.r aR ≠ j₀.val := by intro heq have : aR ∈ AL := Finset.mem_filter.mpr ⟨Finset.mem_univ _, heq⟩ rw [haL_eq, Finset.mem_singleton] at this exact hsame this.symm omega let v : Fin (m + 1) := ⟨j₀.val - 1, by omega⟩ have hv_val : v.val = j₀.val - 1 := rfl have huv : j₀ ≠ v := by intro h; have := congrArg Fin.val h; rw [hv_val] at this; omega have hv_aL : I.l aL ≤ v.val ∧ v.val ≤ I.r aL := by have hraL : I.r aL = j₀.val := (Finset.mem_filter.mp haL_mem).2 rw [hv_val]; omega have hcomp := (fiber_sum_comparison (I.erase aL) j₀ v huv (fun b => hcommon j₀ le_rfl hLR b.1)).2.2 have hd_eq_aR : ∀ d : { b : { x : A // x ≠ aL } // ¬ ((I.erase aL).l b ≤ v.val ∧ v.val ≤ (I.erase aL).r b) }, d.1.1 = aR := by intro d have hv_le_r : v.val ≤ I.r d.1.1 := by have hge := hR_ge d.1.1 omega have hgt : v.val < I.l d.1.1 := by have hnot := d.2 change ¬ (I.l d.1.1 ≤ v.val ∧ v.val ≤ I.r d.1.1) at hnot omega have hle_L : I.l d.1.1 ≤ j₀.val := hL_le d.1.1 have heq_l : I.l d.1.1 = j₀.val := by omega have hmem : d.1.1 ∈ AR := Finset.mem_filter.mpr ⟨Finset.mem_univ _, heq_l⟩ rw [haR_eq, Finset.mem_singleton] at hmem exact hmem have hD_sub : ∀ d₁ d₂ : { b : { x : A // x ≠ aL } // ¬ ((I.erase aL).l b ≤ v.val ∧ v.val ≤ (I.erase aL).r b) }, d₁ = d₂ := by intro d₁ d₂ apply Subtype.ext; apply Subtype.ext rw [hd_eq_aR d₁, hd_eq_aR d₂] have hs0_ex : ∃ s₀ : ValidSlot (I.erase aL), ∀ d : { b : { x : A // x ≠ aL } // ¬ ((I.erase aL).l b ≤ v.val ∧ v.val ≤ (I.erase aL).r b) }, s₀.1 d.1 ≠ j₀ := by let s₀ : ValidSlot (I.erase aL) := ⟨fun b => if b.1 = aR then ⟨I.r aR, Nat.lt_succ_of_le (I.hrm aR)⟩ else j₀, fun b => by dsimp only by_cases hb : b.1 = aR · rw [if_pos hb] change I.l b.1 ≤ I.r aR ∧ I.r aR ≤ I.r b.1 rw [hb]; exact ⟨I.hle aR, le_rfl⟩ · rw [if_neg hb]; exact hcommon j₀ le_rfl hLR b.1⟩ refine ⟨s₀, fun d => ?_⟩ dsimp only [s₀] rw [if_pos (hd_eq_aR d)] intro heq have := congrArg Fin.val heq dsimp at this omega have hstrict := hcomp hD_sub hs0_ex rw [← marginalWeight_eq_erase I aL j₀ (hcommon j₀ le_rfl hLR aL), ← marginalWeight_eq_erase I aL v hv_aL] at hstrict have hv_le_L : marginalWeight I aL v ≤ L aL := by unfold marginalWeight L refine Finset.sum_le_sum_of_subset fun s hs => ?_ simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hs ⊢ rw [hs] change v.val < j₀.val rw [hv_val]; omega have hsp := hsplit_a aL have hR0 := hR_zero_of_AL aL haL_mem have hLs := hL_small aL omega /-! ## Section 5: Theorem A — The Exact 1/3–2/3 Conjecture for ALL Split Posets -/ /-- A poset `P` is a **split poset** if its ground set can be partitioned into a chain `C` (pairwise comparable elements) and an antichain `A` (no two distinct elements comparable). Equivalently, the comparability graph of `P` is a split graph. -/ def IsSplitPoset (P : Type*) [PartialOrder P] : Prop := ∃ C A : Set P, C ∪ A = Set.univ ∧ Disjoint C A ∧ (∀ x ∈ C, ∀ y ∈ C, x ≤ y ∨ y ≤ x) ∧ (∀ x ∈ A, ∀ y ∈ A, x ≤ y → x = y) /-- A downward-closed subset `S` of `Fin m` consists precisely of `{ i : Fin m | i.val < S.card }`. -/ lemma downward_filter_fin_iff {m : ℕ} (S : Finset (Fin m)) (hdown : ∀ j k : Fin m, j ≤ k → k ∈ S → j ∈ S) (i : Fin m) : i ∈ S ↔ i.val < S.card := by classical by_cases hfull : S = Finset.univ · subst hfull rw [Finset.card_univ, Fintype.card_fin] exact iff_of_true (Finset.mem_univ i) i.isLt · have hex_nat : ∃ k : ℕ, ∃ hk : k < m, (⟨k, hk⟩ : Fin m) ∉ S := by by_contra hall; push Not at hall exact hfull (Finset.eq_univ_iff_forall.mpr fun j => hall j.val j.isLt) let k₀ := Nat.find hex_nat rcases Nat.find_spec hex_nat with ⟨hk₀, hk₀_not⟩ have hmem_k0 : ∀ j : Fin m, j ∈ S ↔ j.val < k₀ := by intro j; constructor · intro hj; by_contra hge; push Not at hge exact hk₀_not (hdown ⟨k₀, hk₀⟩ j hge hj) · intro hlt; by_contra hj_not exact Nat.find_min hex_nat hlt ⟨j.isLt, hj_not⟩ have hcard : S.card = k₀ := by have hbij : S.card = (Finset.range k₀).card := Finset.card_bij (fun j _ => j.val) (fun j hj => Finset.mem_range.mpr ((hmem_k0 j).mp hj)) (fun _ _ _ _ h => Fin.ext h) (fun t ht => ⟨⟨t, (Finset.mem_range.mp ht).trans hk₀⟩, (hmem_k0 _).mpr (Finset.mem_range.mp ht), rfl⟩) rw [hbij, Finset.card_range] rw [hcard] exact hmem_k0 i /-- An upward-closed subset `U` of `Fin m` consists precisely of `{ i : Fin m | m - U.card ≤ i.val }`. -/ lemma upward_filter_fin_iff {m : ℕ} (U : Finset (Fin m)) (hup : ∀ j k : Fin m, j ≤ k → j ∈ U → k ∈ U) (i : Fin m) : i ∈ U ↔ m - U.card ≤ i.val := by classical by_cases hemp : U = ∅ · subst hemp rw [Finset.card_empty, tsub_zero] exact iff_of_false (Finset.notMem_empty i) (not_le_of_gt i.isLt) · have hex_nat : ∃ k : ℕ, ∃ hk : k < m, (⟨k, hk⟩ : Fin m) ∈ U := by rcases Finset.nonempty_iff_ne_empty.mpr hemp with ⟨j, hj⟩ exact ⟨j.val, j.isLt, hj⟩ let k₀ := Nat.find hex_nat rcases Nat.find_spec hex_nat with ⟨hk₀, hk₀_mem⟩ have hmem_k0 : ∀ j : Fin m, j ∈ U ↔ k₀ ≤ j.val := by intro j; constructor · intro hj; by_contra hlt; push Not at hlt exact Nat.find_min hex_nat hlt ⟨j.isLt, hj⟩ · intro hge; exact hup ⟨k₀, hk₀⟩ j hge hk₀_mem have hcard : U.card = m - k₀ := by have hbij : U.card = (Finset.Ico k₀ m).card := Finset.card_bij (fun j _ => j.val) (fun j hj => Finset.mem_Ico.mpr ⟨(hmem_k0 j).mp hj, j.isLt⟩) (fun _ _ _ _ h => Fin.ext h) (fun t ht => ⟨⟨t, (Finset.mem_Ico.mp ht).2⟩, (hmem_k0 _).mpr (Finset.mem_Ico.mp ht).1, rfl⟩) rw [hbij, Nat.card_Ico] have hsub : m - U.card = k₀ := by rw [hcard]; omega rw [hsub] exact hmem_k0 i /-- Order-isomorphism from any finite linear order `L` to `Fin (Fintype.card L)`, constructed explicitly via the strict-predecessor rank function. -/ noncomputable def linearOrderEquivFin (L : Type*) [PartialOrder L] [Fintype L] (htot : ∀ x y : L, x ≤ y ∨ y ≤ x) : { e : L ≃ Fin (Fintype.card L) // ∀ x y : L, x ≤ y ↔ e x ≤ e y } := by classical let rank : L → Fin (Fintype.card L) := fun x => ⟨(Finset.univ.filter (fun y : L => y < x)).card, by have hlt : (Finset.univ.filter (fun y : L => y < x)) ⊂ Finset.univ := by rw [Finset.ssubset_iff_subset_ne] refine ⟨Finset.subset_univ _, fun heq => ?_⟩ have hx : x ∈ Finset.univ.filter (fun y : L => y < x) := by rw [heq]; exact Finset.mem_univ x exact lt_irrefl x (Finset.mem_filter.mp hx).2 exact Finset.card_lt_card hlt⟩ have hstrict : ∀ x y : L, x < y → rank x < rank y := by intro x y hxy change (Finset.univ.filter (fun z : L => z < x)).card < (Finset.univ.filter (fun z : L => z < y)).card refine Finset.card_lt_card ?_ rw [Finset.ssubset_iff_subset_ne] refine ⟨fun z hz => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hz).2.trans hxy⟩, ?_⟩ intro heq have hx : x ∈ Finset.univ.filter (fun z : L => z < y) := Finset.mem_filter.mpr ⟨Finset.mem_univ _, hxy⟩ rw [← heq] at hx exact lt_irrefl x (Finset.mem_filter.mp hx).2 have hinj : Function.Injective rank := by intro x y hxy rcases htot x y with hle | hle · rcases eq_or_lt_of_le hle with rfl | hlt · rfl · exact absurd hxy (ne_of_lt (hstrict x y hlt)) · rcases eq_or_lt_of_le hle with rfl | hlt · rfl · exact absurd hxy.symm (ne_of_lt (hstrict y x hlt)) have hbij : Function.Bijective rank := (Fintype.bijective_iff_injective_and_card rank).mpr ⟨hinj, (Fintype.card_fin _).symm⟩ refine ⟨Equiv.ofBijective rank hbij, fun x y => ?_⟩ constructor · intro hxy rcases eq_or_lt_of_le hxy with rfl | hlt · exact le_rfl · exact le_of_lt (hstrict x y hlt) · intro hle rcases htot x y with h | h · exact h · rcases eq_or_lt_of_le h with rfl | hlt · exact le_rfl · exact absurd hle (not_le_of_gt (hstrict y x hlt)) /-- Pure antichain case (`C = ∅`): in a finite antichain of cardinality `≥ 2`, every distinct pair `(x, y)` has `2 * countBefore x y = totalLinExt P`, hence is `1/3`-balanced. -/ lemma antichain_balanced {P : Type*} [PartialOrder P] [Fintype P] (hanti : ∀ x y : P, x ≤ y → x = y) (x y : P) (hxy : x ≠ y) : IsBalancedPair x y := by classical have hT_pos : 0 < totalLinExt P := by unfold totalLinExt let e₀ : LinExt P := ⟨Fintype.equivFin P, fun a b hab => by rw [hanti a b hab]⟩ exact Fintype.card_pos_iff.mpr ⟨e₀⟩ let swapExt : { e : LinExt P // e.1 x < e.1 y } ≃ { e : LinExt P // e.1 y < e.1 x } := { toFun := fun e => ⟨⟨(Equiv.swap x y).trans e.1.1, fun a b hab => by rw [hanti a b hab]⟩, by change e.1.1 (Equiv.swap x y y) < e.1.1 (Equiv.swap x y x) rw [Equiv.swap_apply_right, Equiv.swap_apply_left] exact e.2⟩ invFun := fun e => ⟨⟨(Equiv.swap x y).trans e.1.1, fun a b hab => by rw [hanti a b hab]⟩, by change e.1.1 (Equiv.swap x y x) < e.1.1 (Equiv.swap x y y) rw [Equiv.swap_apply_left, Equiv.swap_apply_right] exact e.2⟩ left_inv := fun e => by apply Subtype.ext; apply Subtype.ext; apply Equiv.ext; intro z simp right_inv := fun e => by apply Subtype.ext; apply Subtype.ext; apply Equiv.ext; intro z simp } have hsum : Fintype.card { e : LinExt P // e.1 x < e.1 y } + Fintype.card { e : LinExt P // e.1 y < e.1 x } = Fintype.card (LinExt P) := by have h1 : Fintype.card { e : LinExt P // e.1 x < e.1 y } + Fintype.card { e : LinExt P // ¬ e.1 x < e.1 y } = Fintype.card (LinExt P) := by rw [Fintype.card_subtype_compl] exact Nat.add_sub_cancel' (Fintype.card_subtype_le _) have h2 : Fintype.card { e : LinExt P // ¬ e.1 x < e.1 y } = Fintype.card { e : LinExt P // e.1 y < e.1 x } := by refine Fintype.card_congr (Equiv.subtypeEquivRight fun e => ?_) constructor · intro hnot have hne : e.1 x ≠ e.1 y := fun heq => hxy (e.1.injective heq) exact lt_of_le_of_ne (le_of_not_gt hnot) hne.symm · intro hlt; exact not_lt_of_gt hlt rw [← h2]; exact h1 have heq : Fintype.card { e : LinExt P // e.1 x < e.1 y } = Fintype.card { e : LinExt P // e.1 y < e.1 x } := Fintype.card_congr swapExt have hC : countBefore x y = Fintype.card { e : LinExt P // e.1 x < e.1 y } := by unfold countBefore; convert rfl have hT : totalLinExt P = Fintype.card (LinExt P) := by unfold totalLinExt; convert rfl refine ⟨hT_pos, ?_, ?_⟩ <;> omega /- Exact Slot-Assignment Bijection for Split Posets -/ section SplitBijection variable {P : Type*} [PartialOrder P] [Fintype P] [DecidableEq P] /-- Extract `SplitIntervals A m` from a chain embedding `c : Fin m → P` and its antichain complement. -/ noncomputable def splitIntervalsOfChain {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) : SplitIntervals { x : P // x ∉ Set.range c } m := by classical let A := { x : P // x ∉ Set.range c } let l : A → ℕ := fun a => (Finset.univ.filter (fun i : Fin m => c i < a.1)).card let r : A → ℕ := fun a => m - (Finset.univ.filter (fun i : Fin m => a.1 < c i)).card have hl_iff : ∀ (a : A) (i : Fin m), c i < a.1 ↔ i.val < l a := by intro a i have h := downward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => c j < a.1)) (fun j k hjk hk => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_lt ((hc j k).mp hjk) (Finset.mem_filter.mp hk).2⟩) i simpa [l] using h have hr_iff : ∀ (a : A) (i : Fin m), a.1 < c i ↔ r a ≤ i.val := by intro a i have h := upward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => a.1 < c j)) (fun j k hjk hj => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_lt_of_le (Finset.mem_filter.mp hj).2 ((hc j k).mp hjk)⟩) i simpa [r] using h have hhelly : ∀ a b : A, l a ≤ r b := by intro a b by_contra hgt; push Not at hgt have hla_le : l a ≤ m := (Finset.card_le_univ _).trans (by rw [Fintype.card_fin]) have hrm_b : r b < m := by omega let i : Fin m := ⟨r b, hrm_b⟩ have h1 : b.1 < c i := (hr_iff b i).mpr le_rfl have h2 : c i < a.1 := (hl_iff a i).mpr hgt have hba : b.1 < a.1 := h1.trans h2 exact ne_of_lt hba (congrArg Subtype.val (hanti b a (le_of_lt hba))) exact { l := l r := r hle := fun a => hhelly a a hrm := fun a => Nat.sub_le m _ hhelly := hhelly } omit [Fintype P] [DecidableEq P] in /-- Characterize `c i < a.1` and `a.1 < c i` in terms of `splitIntervalsOfChain`. -/ lemma splitIntervalsOfChain_lt_iff {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) (a : { x : P // x ∉ Set.range c }) (i : Fin m) : (c i < a.1 ↔ i.val < (splitIntervalsOfChain c hc hanti).l a) ∧ (a.1 < c i ↔ (splitIntervalsOfChain c hc hanti).r a ≤ i.val) := by classical constructor · have h := downward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => c j < a.1)) (fun j k hjk hk => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_lt ((hc j k).mp hjk) (Finset.mem_filter.mp hk).2⟩) i simpa [splitIntervalsOfChain] using h · have h := upward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => a.1 < c j)) (fun j k hjk hj => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_lt_of_le (Finset.mem_filter.mp hj).2 ((hc j k).mp hjk)⟩) i simpa [splitIntervalsOfChain] using h /-- Forward slot-assignment map from a linear extension `e : LinExt P` of a split poset. -/ noncomputable def toSlotOfLinExt {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) (e : LinExt P) : ValidSlot (splitIntervalsOfChain c hc hanti) := by classical refine ⟨fun a => ⟨(Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 a.1)).card, Nat.lt_succ_of_le ((Finset.card_le_univ _).trans (by rw [Fintype.card_fin]))⟩, fun a => ?_⟩ have h1 : (splitIntervalsOfChain c hc hanti).l a ≤ (Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 a.1)).card := by change (Finset.univ.filter (fun i : Fin m => c i < a.1)).card ≤ _ refine Finset.card_le_card fun i hi => ?_ have hlt : c i < a.1 := (Finset.mem_filter.mp hi).2 refine Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩ exact lt_of_le_of_ne (e.2 _ _ (le_of_lt hlt)) (fun h => ne_of_lt hlt (e.1.injective h)) have h2 : (Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 a.1)).card ≤ (splitIntervalsOfChain c hc hanti).r a := by have hdisj : Disjoint (Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 a.1)) (Finset.univ.filter (fun i : Fin m => a.1 < c i)) := Finset.disjoint_filter.mpr fun i _ h1 h2 => not_lt_of_ge (e.2 _ _ (le_of_lt h2)) h1 have hsum_le : (Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 a.1)).card + (Finset.univ.filter (fun i : Fin m => a.1 < c i)).card ≤ m := by rw [← Finset.card_union_of_disjoint hdisj] exact (Finset.card_le_univ _).trans (by rw [Fintype.card_fin]) change _ ≤ m - (Finset.univ.filter (fun i : Fin m => a.1 < c i)).card omega exact ⟨h1, h2⟩ /-- Forward per-slot ordering map from a linear extension `e : LinExt P`. -/ noncomputable def toPermOfLinExt {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) (e : LinExt P) (j : Fin (m + 1)) : { a : { x : P // x ∉ Set.range c } // (toSlotOfLinExt c hc hanti e).1 a = j } ≃ Fin (slotCount (toSlotOfLinExt c hc hanti e).1 j) := by classical let s := toSlotOfLinExt c hc hanti e let S_j := { a : { x : P // x ∉ Set.range c } // s.1 a = j } have hcard_Sj : Fintype.card S_j = slotCount s.1 j := by unfold slotCount; rw [Fintype.card_subtype] let f : S_j → Fin (slotCount s.1 j) := fun a => ⟨(Finset.univ.filter (fun b : S_j => e.1 b.1.1 < e.1 a.1.1)).card, by rw [← hcard_Sj] refine Finset.card_lt_card ?_ rw [Finset.ssubset_iff_subset_ne] refine ⟨Finset.subset_univ _, fun heq => ?_⟩ have ha : a ∈ Finset.univ.filter (fun b : S_j => e.1 b.1.1 < e.1 a.1.1) := by rw [heq]; exact Finset.mem_univ a exact lt_irrefl _ (Finset.mem_filter.mp ha).2⟩ have hf_strict : ∀ a b : S_j, e.1 a.1.1 < e.1 b.1.1 → f a < f b := by intro a b hab change (Finset.univ.filter (fun z : S_j => e.1 z.1.1 < e.1 a.1.1)).card < (Finset.univ.filter (fun z : S_j => e.1 z.1.1 < e.1 b.1.1)).card refine Finset.card_lt_card ?_ rw [Finset.ssubset_iff_subset_ne] refine ⟨fun z hz => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hz).2.trans hab⟩, ?_⟩ intro heq have ha : a ∈ Finset.univ.filter (fun z : S_j => e.1 z.1.1 < e.1 b.1.1) := Finset.mem_filter.mpr ⟨Finset.mem_univ _, hab⟩ rw [← heq] at ha exact lt_irrefl _ (Finset.mem_filter.mp ha).2 have hf_inj : Function.Injective f := by intro a b hab rcases lt_trichotomy (e.1 a.1.1) (e.1 b.1.1) with h | h | h · exact absurd hab (ne_of_lt (hf_strict a b h)) · exact Subtype.ext (Subtype.ext (e.1.injective h)) · exact absurd hab.symm (ne_of_lt (hf_strict b a h)) exact Equiv.ofBijective f ((Fintype.bijective_iff_injective_and_card f).mpr ⟨hf_inj, by rw [Fintype.card_fin, hcard_Sj]⟩) omit [DecidableEq P] in lemma toSlotOfLinExt_lt_iff {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) (e : LinExt P) (a : { x : P // x ∉ Set.range c }) (i : Fin m) : e.1 (c i) < e.1 a.1 ↔ i.val < ((toSlotOfLinExt c hc hanti e).1 a).val := by classical have h := downward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => e.1 (c j) < e.1 a.1)) (fun j k hjk hk => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_lt (e.2 _ _ ((hc j k).mp hjk)) (Finset.mem_filter.mp hk).2⟩) i simpa [toSlotOfLinExt] using h omit [DecidableEq P] in lemma toSlotOfLinExt_le_iff {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) (e : LinExt P) (a : { x : P // x ∉ Set.range c }) (i : Fin m) : e.1 a.1 < e.1 (c i) ↔ ((toSlotOfLinExt c hc hanti e).1 a).val ≤ i.val := by have hne : e.1 a.1 ≠ e.1 (c i) := fun h => a.2 ⟨i, (e.1.injective h).symm⟩ constructor · intro hlt by_contra hgt; push Not at hgt exact lt_asymm hlt ((toSlotOfLinExt_lt_iff c hc hanti e a i).mpr hgt) · intro hle have hnot : ¬ e.1 (c i) < e.1 a.1 := fun h => not_lt_of_ge hle ((toSlotOfLinExt_lt_iff c hc hanti e a i).mp h) exact lt_of_le_of_ne (le_of_not_gt hnot) hne lemma toPermOfLinExt_lt_iff {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) (e : LinExt P) (a b : { x : P // x ∉ Set.range c }) (h : (toSlotOfLinExt c hc hanti e).1 a = (toSlotOfLinExt c hc hanti e).1 b) : e.1 a.1 < e.1 b.1 ↔ toPermOfLinExt c hc hanti e ((toSlotOfLinExt c hc hanti e).1 b) ⟨a, h⟩ < toPermOfLinExt c hc hanti e ((toSlotOfLinExt c hc hanti e).1 b) ⟨b, rfl⟩ := by classical let s := toSlotOfLinExt c hc hanti e let j := s.1 b let S_j := { x : { x : P // x ∉ Set.range c } // s.1 x = j } have hstrict : ∀ u v : S_j, e.1 u.1.1 < e.1 v.1.1 → toPermOfLinExt c hc hanti e j u < toPermOfLinExt c hc hanti e j v := by intro u v huv change (Finset.univ.filter (fun z : S_j => e.1 z.1.1 < e.1 u.1.1)).card < (Finset.univ.filter (fun z : S_j => e.1 z.1.1 < e.1 v.1.1)).card refine Finset.card_lt_card ?_ rw [Finset.ssubset_iff_subset_ne] refine ⟨fun z hz => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hz).2.trans huv⟩, fun hEq => ?_⟩ have hu : u ∈ Finset.univ.filter (fun z : S_j => e.1 z.1.1 < e.1 v.1.1) := Finset.mem_filter.mpr ⟨Finset.mem_univ _, huv⟩ rw [← hEq] at hu exact lt_irrefl _ (Finset.mem_filter.mp hu).2 constructor · exact hstrict ⟨a, h⟩ ⟨b, rfl⟩ · intro hlt rcases lt_trichotomy (e.1 a.1) (e.1 b.1) with h1 | h1 | h1 · exact h1 · have hab : a = b := Subtype.ext (e.1.injective h1) subst hab; exact absurd hlt (lt_irrefl _) · exact absurd hlt (lt_asymm (hstrict ⟨b, rfl⟩ ⟨a, h⟩ h1)) /-- Explicit bijection between `LinExt P` and `Σ s : ValidSlot I, ∀ j, ({a : A // s a = j} ≃ Fin (slotCount s j))` for a split poset `P = range c ⊔ A`. -/ noncomputable def splitLinExtEquiv {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) : let A := { x : P // x ∉ Set.range c } let I := splitIntervalsOfChain c hc hanti LinExt P ≃ Σ s : ValidSlot I, ∀ j : Fin (m + 1), ({ a : A // s.1 a = j } ≃ Fin (slotCount s.1 j)) := by classical let A := { x : P // x ∉ Set.range c } let I := splitIntervalsOfChain c hc hanti have hc_inj : Function.Injective c := fun i j hij => le_antisymm ((hc i j).mpr (le_of_eq hij)) ((hc j i).mpr (le_of_eq hij.symm)) let eSum : P ≃ Fin m ⊕ A := { toFun := fun x => if h : x ∈ Set.range c then Sum.inl (Classical.choose h) else Sum.inr ⟨x, h⟩ invFun := Sum.elim c Subtype.val left_inv := fun x => by dsimp only by_cases h : x ∈ Set.range c · rw [dif_pos h]; exact Classical.choose_spec h · rw [dif_neg h]; rfl right_inv := fun z => by rcases z with i | a · have hmem : c i ∈ Set.range c := ⟨i, rfl⟩ dsimp only [Sum.elim] rw [dif_pos hmem] exact congrArg Sum.inl (hc_inj (Classical.choose_spec hmem)) · dsimp only [Sum.elim] rw [dif_neg a.2] } have heSum_inl : ∀ {x : P} {i : Fin m}, eSum x = Sum.inl i → x = c i := fun h => by have := congrArg eSum.symm h rw [eSum.symm_apply_apply] at this exact this have heSum_inr : ∀ {x : P} {a : A}, eSum x = Sum.inr a → x = a.1 := fun h => by have := congrArg eSum.symm h rw [eSum.symm_apply_apply] at this exact this have hcardP : Fintype.card P = m + Fintype.card A := by rw [Fintype.card_congr eSum, Fintype.card_sum, Fintype.card_fin] let pref : (A → Fin (m + 1)) → ℕ → ℕ := fun s k => k + ∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val < k), slotCount s t have hpref_succ : ∀ (s : A → Fin (m + 1)) (j : Fin (m + 1)), pref s (j.val + 1) = pref s j.val + slotCount s j + 1 := by intro s j dsimp only [pref] have hfilt : Finset.univ.filter (fun t : Fin (m + 1) => t.val < j.val + 1) = insert j (Finset.univ.filter (fun t : Fin (m + 1) => t.val < j.val)) := by ext t; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert, Fin.ext_iff] omega rw [hfilt, Finset.sum_insert (by simp)] ring have hpref_mono : ∀ (s : A → Fin (m + 1)) {a b : ℕ}, a ≤ b → pref s a ≤ pref s b := by intro s a b hab dsimp only [pref] refine Nat.add_le_add hab (Finset.sum_le_sum_of_subset fun t ht => ?_) simp only [Finset.mem_filter, Finset.mem_univ, true_and] at ht ⊢ omega have hsum_counts : ∀ (s : A → Fin (m + 1)), ∑ t : Fin (m + 1), slotCount s t = Fintype.card A := by intro s; unfold slotCount have h := Finset.card_eq_sum_card_fiberwise (f := s) (s := Finset.univ) (t := Finset.univ) (fun _ _ => Finset.mem_univ _) simpa [Finset.card_univ] using h.symm have hpref_bound : ∀ (s : A → Fin (m + 1)) (j : Fin (m + 1)), pref s j.val + slotCount s j ≤ m + Fintype.card A := by intro s j have hle_m : j.val ≤ m := Nat.lt_succ_iff.mp j.isLt have hfilt_le : (∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val < j.val), slotCount s t) + slotCount s j ≤ ∑ t : Fin (m + 1), slotCount s t := by have h1 := Finset.sum_le_sum_of_subset (f := slotCount s) (Finset.subset_univ (insert j (Finset.univ.filter (fun t : Fin (m + 1) => t.val < j.val)))) rw [Finset.sum_insert (by simp)] at h1 omega dsimp only [pref]; rw [hsum_counts s] at hfilt_le; omega let mkPos : ∀ (s : ValidSlot I) (π : ∀ j : Fin (m + 1), { a : A // s.1 a = j } ≃ Fin (slotCount s.1 j)), P → Fin (Fintype.card P) := fun s π x => match eSum x with | Sum.inl i => ⟨pref s.1 i.val + slotCount s.1 ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩, by rw [hcardP] have hlt_m : i.val < m := i.isLt have hfilt_le : (∑ t ∈ Finset.univ.filter (fun t : Fin (m + 1) => t.val < i.val), slotCount s.1 t) + slotCount s.1 ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ ≤ Fintype.card A := by rw [← hsum_counts s.1] have h := Finset.sum_le_sum_of_subset (f := slotCount s.1) (Finset.subset_univ (insert (⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ : Fin (m + 1)) (Finset.univ.filter (fun t : Fin (m + 1) => t.val < i.val)))) rw [Finset.sum_insert (by simp)] at h; omega dsimp only [pref]; omega⟩ | Sum.inr a => ⟨pref s.1 (s.1 a).val + (π (s.1 a) ⟨a, rfl⟩).val, by rw [hcardP] have hlt := (π (s.1 a) ⟨a, rfl⟩).isLt have hb := hpref_bound s.1 (s.1 a) omega⟩ have hmkPos_c : ∀ s π (i : Fin m), (mkPos s π (c i)).val = pref s.1 i.val + slotCount s.1 ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ := by intro s π i have he : eSum (c i) = Sum.inl i := eSum.right_inv (Sum.inl i) simp [mkPos, he] have hmkPos_a : ∀ s π (a : A), (mkPos s π a.1).val = pref s.1 (s.1 a).val + (π (s.1 a) ⟨a, rfl⟩).val := by intro s π a have he : eSum a.1 = Sum.inr a := eSum.right_inv (Sum.inr a) simp [mkPos, he] have hpi_cast : ∀ (s : ValidSlot I) (π : ∀ j : Fin (m + 1), { a : A // s.1 a = j } ≃ Fin (slotCount s.1 j)) (j₁ j₂ : Fin (m + 1)) (h : j₁ = j₂) (a : A) (ha : s.1 a = j₁), (π j₁ ⟨a, ha⟩).val = (π j₂ ⟨a, ha.trans h⟩).val := by rintro s π j₁ _ rfl a ha; rfl -- Strict order comparison lemma for mkPos! have hmkPos_lt_of_slot : ∀ s π (a : A) (i : Fin m), ((s.1 a).val ≤ i.val → (mkPos s π a.1).val < (mkPos s π (c i)).val) ∧ (i.val < (s.1 a).val → (mkPos s π (c i)).val < (mkPos s π a.1).val) := by intro s π a i rw [hmkPos_a, hmkPos_c] have hlt_a := (π (s.1 a) ⟨a, rfl⟩).isLt constructor · intro hle rcases eq_or_lt_of_le hle with heq | hlt · have hfin : s.1 a = ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ := Fin.ext heq have hcnt : slotCount s.1 (s.1 a) = slotCount s.1 ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ := congrArg (slotCount s.1) hfin rw [heq]; omega · have h1 := hpref_succ s.1 (s.1 a) have h2 := hpref_mono s.1 (show (s.1 a).val + 1 ≤ i.val by omega) omega · intro hlt have h1 := hpref_succ s.1 ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ have h2 := hpref_mono s.1 (show i.val + 1 ≤ (s.1 a).val by omega) dsimp at h1; omega have hmkPos_c_lt : ∀ s π (i j : Fin m), i < j → (mkPos s π (c i)).val < (mkPos s π (c j)).val := by intro s π i j hij rw [hmkPos_c, hmkPos_c] have h1 := hpref_succ s.1 ⟨i.val, Nat.lt_succ_of_lt i.isLt⟩ have h2 := hpref_mono s.1 (show i.val + 1 ≤ j.val by omega) dsimp at h1; omega have hmkPos_a_lt_of_slot : ∀ s π (a b : A), s.1 a < s.1 b → (mkPos s π a.1).val < (mkPos s π b.1).val := by intro s π a b hab rw [hmkPos_a, hmkPos_a] have hlt_a := (π (s.1 a) ⟨a, rfl⟩).isLt have h1 := hpref_succ s.1 (s.1 a) have h2 := hpref_mono s.1 (show (s.1 a).val + 1 ≤ (s.1 b).val by exact hab) omega have hmkPos_inj : ∀ s π, Function.Injective (mkPos s π) := by intro s π x y hxy have hval := congrArg Fin.val hxy cases hx : eSum x with | inl i => have hx' : x = c i := heSum_inl hx subst hx' cases hy : eSum y with | inl j => have hy' : y = c j := heSum_inl hy subst hy' rcases lt_trichotomy i j with hij | rfl | hij · exact absurd hval (ne_of_lt (hmkPos_c_lt s π i j hij)) · rfl · exact absurd hval.symm (ne_of_lt (hmkPos_c_lt s π j i hij)) | inr b => have hy' : y = b.1 := heSum_inr hy subst hy' by_cases hle : (s.1 b).val ≤ i.val · exact absurd hval.symm (ne_of_lt ((hmkPos_lt_of_slot s π b i).1 hle)) · exact absurd hval (ne_of_lt ((hmkPos_lt_of_slot s π b i).2 (by omega))) | inr a => have hx' : x = a.1 := heSum_inr hx subst hx' cases hy : eSum y with | inl j => have hy' : y = c j := heSum_inl hy subst hy' by_cases hle : (s.1 a).val ≤ j.val · exact absurd hval (ne_of_lt ((hmkPos_lt_of_slot s π a j).1 hle)) · exact absurd hval.symm (ne_of_lt ((hmkPos_lt_of_slot s π a j).2 (by omega))) | inr b => have hy' : y = b.1 := heSum_inr hy subst hy' rcases lt_trichotomy (s.1 a) (s.1 b) with hab | hab | hab · exact absurd hval (ne_of_lt (hmkPos_a_lt_of_slot s π a b hab)) · rw [hmkPos_a, hmkPos_a] at hval have h1 := hpi_cast s π (s.1 a) (s.1 b) hab a rfl have hval2 : (π (s.1 b) ⟨a, hab⟩).val = (π (s.1 b) ⟨b, rfl⟩).val := by have hpeq : pref s.1 (s.1 a).val = pref s.1 (s.1 b).val := congrArg (pref s.1 ∘ Fin.val) hab omega have ha_eq : (⟨a, hab⟩ : { x : A // s.1 x = s.1 b }) = ⟨b, rfl⟩ := (π (s.1 b)).injective (Fin.ext hval2) exact congrArg (fun z => z.1.1) ha_eq · exact absurd hval.symm (ne_of_lt (hmkPos_a_lt_of_slot s π b a hab)) let mkExt : ∀ (s : ValidSlot I) (π : ∀ j : Fin (m + 1), { a : A // s.1 a = j } ≃ Fin (slotCount s.1 j)), LinExt P := fun s π => ⟨Equiv.ofBijective (mkPos s π) ((Fintype.bijective_iff_injective_and_card (mkPos s π)).mpr ⟨hmkPos_inj s π, (Fintype.card_fin _).symm⟩), fun x y hxy => by change (mkPos s π x).val ≤ (mkPos s π y).val cases hx : eSum x with | inl i => have hx' : x = c i := heSum_inl hx subst hx' cases hy : eSum y with | inl j => have hy' : y = c j := heSum_inl hy subst hy' rcases eq_or_lt_of_le ((hc i j).mpr hxy) with rfl | hlt · exact le_rfl · exact le_of_lt (hmkPos_c_lt s π i j hlt) | inr b => have hy' : y = b.1 := heSum_inr hy subst hy' have hlt_cb : c i < b.1 := lt_of_le_of_ne hxy (fun h => b.2 ⟨i, h⟩) have hi_lt : i.val < I.l b := (splitIntervalsOfChain_lt_iff c hc hanti b i).1.mp hlt_cb exact le_of_lt ((hmkPos_lt_of_slot s π b i).2 (lt_of_lt_of_le hi_lt (s.2 b).1)) | inr a => have hx' : x = a.1 := heSum_inr hx subst hx' cases hy : eSum y with | inl j => have hy' : y = c j := heSum_inl hy subst hy' have hlt_ac : a.1 < c j := lt_of_le_of_ne hxy (fun h => a.2 ⟨j, h.symm⟩) have hr_le : I.r a ≤ j.val := (splitIntervalsOfChain_lt_iff c hc hanti a j).2.mp hlt_ac exact le_of_lt ((hmkPos_lt_of_slot s π a j).1 ((s.2 a).2.trans hr_le)) | inr b => have hy' : y = b.1 := heSum_inr hy subst hy' have hab : a = b := hanti a b hxy subst hab; exact le_rfl⟩ have hmkExt_lt_c : ∀ s π (a : A) (i : Fin m), (mkExt s π).1 (c i) < (mkExt s π).1 a.1 ↔ i.val < (s.1 a).val := by intro s π a i change (mkPos s π (c i)).val < (mkPos s π a.1).val ↔ i.val < (s.1 a).val constructor · intro hlt; by_contra hge; push Not at hge exact lt_asymm hlt ((hmkPos_lt_of_slot s π a i).1 hge) · exact (hmkPos_lt_of_slot s π a i).2 refine { toFun := fun e => ⟨toSlotOfLinExt c hc hanti e, toPermOfLinExt c hc hanti e⟩ invFun := fun p => mkExt p.1 p.2 left_inv := fun e => by apply Subtype.ext; apply Equiv.ext; intro x have hcase_lt : ∀ y z : P, e.1 y < e.1 z → (mkExt (toSlotOfLinExt c hc hanti e) (toPermOfLinExt c hc hanti e)).1 y < (mkExt (toSlotOfLinExt c hc hanti e) (toPermOfLinExt c hc hanti e)).1 z := by intro y z hyz change (mkPos (toSlotOfLinExt c hc hanti e) (toPermOfLinExt c hc hanti e) y).val < (mkPos (toSlotOfLinExt c hc hanti e) (toPermOfLinExt c hc hanti e) z).val cases hy : eSum y with | inl i => have hy' : y = c i := heSum_inl hy; subst hy' cases hz : eSum z with | inl j => have hz' : z = c j := heSum_inl hz; subst hz' have hij : i < j := by by_contra hge; push Not at hge exact not_lt_of_ge (e.2 _ _ ((hc j i).mp hge)) hyz exact hmkPos_c_lt _ _ i j hij | inr b => have hz' : z = b.1 := heSum_inr hz; subst hz' exact (hmkPos_lt_of_slot _ _ b i).2 ((toSlotOfLinExt_lt_iff c hc hanti e b i).mp hyz) | inr a => have hy' : y = a.1 := heSum_inr hy; subst hy' cases hz : eSum z with | inl j => have hz' : z = c j := heSum_inl hz; subst hz' exact (hmkPos_lt_of_slot _ _ a j).1 ((toSlotOfLinExt_le_iff c hc hanti e a j).mp hyz) | inr b => have hz' : z = b.1 := heSum_inr hz; subst hz' have hslot_le : ((toSlotOfLinExt c hc hanti e).1 a).val ≤ ((toSlotOfLinExt c hc hanti e).1 b).val := by change (Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 a.1)).card ≤ (Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 b.1)).card exact Finset.card_le_card fun i hi => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hi).2.trans hyz⟩ rcases eq_or_lt_of_le hslot_le with heq | hlt · have hfin : (toSlotOfLinExt c hc hanti e).1 a = (toSlotOfLinExt c hc hanti e).1 b := Fin.ext heq rw [hmkPos_a, hmkPos_a] have h1 := hpi_cast (toSlotOfLinExt c hc hanti e) (toPermOfLinExt c hc hanti e) ((toSlotOfLinExt c hc hanti e).1 a) ((toSlotOfLinExt c hc hanti e).1 b) hfin a rfl have h2 := (toPermOfLinExt_lt_iff c hc hanti e a b hfin).mp hyz have hpeq : pref (toSlotOfLinExt c hc hanti e).1 ((toSlotOfLinExt c hc hanti e).1 a).val = pref (toSlotOfLinExt c hc hanti e).1 ((toSlotOfLinExt c hc hanti e).1 b).val := congrArg (pref _ ∘ Fin.val) hfin change ((toPermOfLinExt c hc hanti e _ ⟨a, hfin⟩).val < (toPermOfLinExt c hc hanti e _ ⟨b, rfl⟩).val) at h2 omega · exact hmkPos_a_lt_of_slot _ _ a b hlt have hord : ∀ y z : P, (mkExt (toSlotOfLinExt c hc hanti e) (toPermOfLinExt c hc hanti e)).1 y < (mkExt (toSlotOfLinExt c hc hanti e) (toPermOfLinExt c hc hanti e)).1 z ↔ e.1 y < e.1 z := by intro y z; constructor · intro hlt rcases lt_trichotomy (e.1 y) (e.1 z) with h | h | h · exact h · have hyz : y = z := e.1.injective h; subst hyz; exact absurd hlt (lt_irrefl _) · exact absurd hlt (lt_asymm (hcase_lt z y h)) · exact hcase_lt y z have hval_eq : ∀ (f : P ≃ Fin (Fintype.card P)) (x : P), (f x).val = (Finset.univ.filter (fun y : P => f y < f x)).card := by intro f x have hbij : (Finset.univ.filter (fun y : P => f y < f x)).card = (Finset.range (f x).val).card := Finset.card_bij (fun y _ => (f y).val) (fun y hy => Finset.mem_range.mpr (Finset.mem_filter.mp hy).2) (fun y₁ _ y₂ _ h => f.injective (Fin.ext h)) (fun t ht => ⟨f.symm ⟨t, (Finset.mem_range.mp ht).trans (f x).isLt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by change (f (f.symm ⟨t, _⟩)).val < (f x).val rw [Equiv.apply_symm_apply]; exact Finset.mem_range.mp ht⟩, by simp⟩) rw [hbij, Finset.card_range] apply Fin.ext rw [hval_eq _ x, hval_eq e.1 x] congr 1; ext y simp only [Finset.mem_filter, Finset.mem_univ, true_and] exact hord y x right_inv := fun ⟨s, π⟩ => by dsimp only have hs : toSlotOfLinExt c hc hanti (mkExt s π) = s := by apply Subtype.ext; funext a; apply Fin.ext change (Finset.univ.filter (fun i : Fin m => (mkExt s π).1 (c i) < (mkExt s π).1 a.1)).card = (s.1 a).val have hfilt : Finset.univ.filter (fun i : Fin m => (mkExt s π).1 (c i) < (mkExt s π).1 a.1) = Finset.univ.filter (fun i : Fin m => i.val < (s.1 a).val) := by ext i; simp only [Finset.mem_filter, Finset.mem_univ, true_and] exact hmkExt_lt_c s π a i rw [hfilt] have hbij : (Finset.univ.filter (fun i : Fin m => i.val < (s.1 a).val)).card = (Finset.range (s.1 a).val).card := Finset.card_bij (fun i _ => i.val) (fun i hi => Finset.mem_range.mpr (Finset.mem_filter.mp hi).2) (fun _ _ _ _ h => Fin.ext h) (fun t ht => ⟨⟨t, lt_of_lt_of_le (Finset.mem_range.mp ht) ((s.2 a).2.trans (I.hrm a))⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_range.mp ht⟩, rfl⟩) rw [hbij, Finset.card_range] have hsigma_eq : ∀ {s₁ s₂ : ValidSlot I} {π₁ : ∀ j : Fin (m + 1), { a : A // s₁.1 a = j } ≃ Fin (slotCount s₁.1 j)} {π₂ : ∀ j : Fin (m + 1), { a : A // s₂.1 a = j } ≃ Fin (slotCount s₂.1 j)} (h : s₁ = s₂), (h ▸ π₁) = π₂ → (⟨s₁, π₁⟩ : Σ s : ValidSlot I, ∀ j : Fin (m + 1), { a : A // s.1 a = j } ≃ Fin (slotCount s.1 j)) = ⟨s₂, π₂⟩ := by rintro s₁ _ π₁ _ rfl rfl; rfl refine hsigma_eq hs ?_ funext j; apply Equiv.ext; intro ⟨a, ha⟩ have hcast : ∀ (s' : ValidSlot I) (h : s' = s) (f : ∀ j : Fin (m + 1), { a : A // s'.1 a = j } ≃ Fin (slotCount s'.1 j)) (j : Fin (m + 1)) (x : { a : A // s.1 a = j }), ((h ▸ f) j x).val = (f j ⟨x.1, h ▸ x.2⟩).val := by rintro s' rfl f j x; rfl apply Fin.ext rw [hcast (toSlotOfLinExt c hc hanti (mkExt s π)) hs (toPermOfLinExt c hc hanti (mkExt s π)) j ⟨a, ha⟩] change (Finset.univ.filter (fun b : { x : A // (toSlotOfLinExt c hc hanti (mkExt s π)).1 x = j } => (mkExt s π).1 b.1.1 < (mkExt s π).1 a.1)).card = (π j ⟨a, ha⟩).val have hbij : (Finset.univ.filter (fun b : { x : A // (toSlotOfLinExt c hc hanti (mkExt s π)).1 x = j } => (mkExt s π).1 b.1.1 < (mkExt s π).1 a.1)).card = (Finset.range (π j ⟨a, ha⟩).val).card := by refine Finset.card_bij (fun b _ => (π j ⟨b.1, (congrFun (congrArg Subtype.val hs) b.1).symm.trans b.2⟩).val) ?_ ?_ ?_ · intro b hb have hlt : (mkPos s π b.1.1).val < (mkPos s π a.1).val := (Finset.mem_filter.mp hb).2 rw [hmkPos_a, hmkPos_a] at hlt have hsb : s.1 b.1 = j := (congrFun (congrArg Subtype.val hs) b.1).symm.trans b.2 have h1 := hpi_cast s π (s.1 b.1) j hsb b.1 rfl have h2 := hpi_cast s π (s.1 a) j ha a rfl have hp1 : pref s.1 (s.1 b.1).val = pref s.1 j.val := congrArg (pref s.1 ∘ Fin.val) hsb have hp2 : pref s.1 (s.1 a).val = pref s.1 j.val := congrArg (pref s.1 ∘ Fin.val) ha exact Finset.mem_range.mpr (by omega) · intro b₁ _ b₂ _ h have heq := (π j).injective (Fin.ext h) exact Subtype.ext (congrArg (fun z : { x : A // s.1 x = j } => z.1) heq) · intro t ht have hlt : t < slotCount s.1 j := (Finset.mem_range.mp ht).trans (π j ⟨a, ha⟩).isLt let b_pair := (π j).symm ⟨t, hlt⟩ refine ⟨⟨b_pair.1, by rw [hs]; exact b_pair.2⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, ?_⟩ · change (mkPos s π b_pair.1.1).val < (mkPos s π a.1).val rw [hmkPos_a, hmkPos_a] have hsb : s.1 b_pair.1 = j := b_pair.2 have h1 := hpi_cast s π (s.1 b_pair.1) j hsb b_pair.1 rfl have h2 := hpi_cast s π (s.1 a) j ha a rfl have hp1 : pref s.1 (s.1 b_pair.1).val = pref s.1 j.val := congrArg (pref s.1 ∘ Fin.val) hsb have hp2 : pref s.1 (s.1 a).val = pref s.1 j.val := congrArg (pref s.1 ∘ Fin.val) ha have h3 : (π j ⟨b_pair.1, hsb⟩).val = t := by simp [b_pair] have htm := Finset.mem_range.mp ht omega · change (π j b_pair).val = t simp [b_pair] rw [hbij, Finset.card_range] } private lemma sigma_sub_eq {β : Type*} {γ : β → Type*} {p : β → Prop} {z : Σ x : β, γ x} {x₂ : β} {y₂ : γ x₂} (hz : z = ⟨x₂, y₂⟩) (h₁ : p z.1) (h₂ : p x₂) : (⟨⟨z.1, h₁⟩, z.2⟩ : Σ x : { x : β // p x }, γ x.1) = ⟨⟨x₂, h₂⟩, y₂⟩ := by cases hz; rfl private lemma sigma_sub_sub_eq {β : Type*} {γ : β → Type*} {p : β → Prop} {r : ∀ x : β, p x → γ x → Prop} {z : Σ x : β, γ x} {x₂ : β} {y₂ : γ x₂} (hz : z = ⟨x₂, y₂⟩) (h₁ : p z.1) (h₂ : p x₂) (hr₁ : r z.1 h₁ z.2) (hr₂ : r x₂ h₂ y₂) : (⟨⟨z.1, h₁⟩, ⟨z.2, hr₁⟩⟩ : Σ x : { x : β // p x }, { y : γ x.1 // r x.1 x.2 y }) = ⟨⟨x₂, h₂⟩, ⟨y₂, hr₂⟩⟩ := by cases hz; rfl /-- Generic subtype-of-sigma equivalence (avoids unfolding concrete equivalences). -/ def subtypeSigmaEquiv {α β : Type*} {γ : β → Type*} (e : α ≃ Σ x : β, γ x) (q : α → Prop) (p : β → Prop) (hqp : ∀ a, q a ↔ p (e a).1) : { a : α // q a } ≃ Σ x : { x : β // p x }, γ x.1 where toFun a := ⟨⟨(e a.1).1, (hqp a.1).mp a.2⟩, (e a.1).2⟩ invFun s := ⟨e.symm ⟨s.1.1, s.2⟩, by rw [hqp, e.apply_symm_apply]; exact s.1.2⟩ left_inv a := Subtype.ext (e.left_inv a.1) right_inv s := by rcases s with ⟨⟨x, hx⟩, y⟩ exact sigma_sub_eq (e.apply_symm_apply ⟨x, y⟩) _ hx /-- Generic disjoint-two-case subtype-of-sigma equivalence. -/ def subtypeSigmaSplitEquiv {α β : Type*} {γ : β → Type*} (e : α ≃ Σ x : β, γ x) (q : α → Prop) (p₁ p₂ : β → Prop) [DecidablePred p₁] (r₂ : ∀ x : β, p₂ x → γ x → Prop) (hdisj : ∀ x, p₁ x → ¬ p₂ x) (hqp : ∀ a, q a ↔ p₁ (e a).1 ∨ ∃ h : p₂ (e a).1, r₂ (e a).1 h (e a).2) : { a : α // q a } ≃ (Σ x : { x : β // p₁ x }, γ x.1) ⊕ (Σ x : { x : β // p₂ x }, { y : γ x.1 // r₂ x.1 x.2 y }) where toFun a := if h1 : p₁ (e a.1).1 then Sum.inl ⟨⟨(e a.1).1, h1⟩, (e a.1).2⟩ else have h2 := ((hqp a.1).mp a.2).resolve_left h1 Sum.inr ⟨⟨(e a.1).1, h2.1⟩, ⟨(e a.1).2, h2.2⟩⟩ invFun z := match z with | Sum.inl ⟨x, y⟩ => ⟨e.symm ⟨x.1, y⟩, by rw [hqp, e.apply_symm_apply]; exact Or.inl x.2⟩ | Sum.inr ⟨x, y⟩ => ⟨e.symm ⟨x.1, y.1⟩, by rw [hqp, e.apply_symm_apply]; exact Or.inr ⟨x.2, y.2⟩⟩ left_inv a := by apply Subtype.ext by_cases h1 : p₁ (e a.1).1 · simp only [dif_pos h1]; exact e.left_inv a.1 · simp only [dif_neg h1]; exact e.left_inv a.1 right_inv z := by rcases z with ⟨⟨x, hx⟩, y⟩ | ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ · dsimp only have h1 : p₁ (e (e.symm ⟨x, y⟩)).1 := by rw [e.apply_symm_apply]; exact hx rw [dif_pos h1] exact congrArg Sum.inl (sigma_sub_eq (e.apply_symm_apply ⟨x, y⟩) h1 hx) · dsimp only have hnot : ¬ p₁ (e (e.symm ⟨x, y⟩)).1 := by rw [e.apply_symm_apply]; exact fun h1 => hdisj x h1 hx rw [dif_neg hnot] exact congrArg Sum.inr (sigma_sub_sub_eq (e.apply_symm_apply ⟨x, y⟩) _ hx _ hy) /-- Exact cardinality formulas linking `LinExt P` of a split poset to `SplitIntervals`: 1. `totalLinExt P = totalWeight I` 2. `countBefore a.1 (c i) = ∑_{s(a) ≤ i} slotWeight s` 3. `2 * countBefore a.1 b.1 = 2 * slotLtWeight I a b + slotEqWeight I a b` (for `a ≠ b`). -/ lemma splitPoset_counts {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (hanti : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y) : let A := { x : P // x ∉ Set.range c } let I := splitIntervalsOfChain c hc hanti totalLinExt P = totalWeight I ∧ (∀ (a : A) (i : Fin m), countBefore a.1 (c i) = ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val), slotWeight s.1) ∧ (∀ (a b : A), a ≠ b → 2 * countBefore a.1 b.1 = 2 * slotLtWeight I a b + slotEqWeight I a b) := by classical let A := { x : P // x ∉ Set.range c } let I := splitIntervalsOfChain c hc hanti let eSplit := splitLinExtEquiv c hc hanti have hfiber_card : ∀ s : ValidSlot I, Fintype.card (∀ j : Fin (m + 1), { a : A // s.1 a = j } ≃ Fin (slotCount s.1 j)) = slotWeight s.1 := by intro s rw [Fintype.card_pi] unfold slotWeight refine Finset.prod_congr rfl fun j _ => ?_ have hcard_j : Fintype.card { a : A // s.1 a = j } = slotCount s.1 j := by unfold slotCount; rw [Fintype.card_subtype] have e1 : ({ a : A // s.1 a = j } ≃ Fin (slotCount s.1 j)) ≃ Equiv.Perm (Fin (slotCount s.1 j)) := Equiv.equivCongr (Fintype.equivFinOfCardEq hcard_j) (Equiv.refl _) rw [Fintype.card_congr e1, Fintype.card_perm, Fintype.card_fin] have hslot_ac : ∀ (e : LinExt P) (a : A) (i : Fin m), e.1 a.1 < e.1 (c i) ↔ ((eSplit e).1.1 a).val ≤ i.val := fun e a i => toSlotOfLinExt_le_iff c hc hanti e a i have hslot_ab : ∀ (e : LinExt P) (a b : A), e.1 a.1 < e.1 b.1 ↔ (eSplit e).1.1 a < (eSplit e).1.1 b ∨ ∃ h : (eSplit e).1.1 a = (eSplit e).1.1 b, (eSplit e).2 ((eSplit e).1.1 b) ⟨a, h⟩ < (eSplit e).2 ((eSplit e).1.1 b) ⟨b, rfl⟩ := by intro e a b have hmono : ∀ x y : A, e.1 x.1 < e.1 y.1 → ((eSplit e).1.1 x).val ≤ ((eSplit e).1.1 y).val := by intro x y hxy change (Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 x.1)).card ≤ (Finset.univ.filter (fun i : Fin m => e.1 (c i) < e.1 y.1)).card exact Finset.card_le_card fun i hi => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hi).2.trans hxy⟩ constructor · intro hab rcases eq_or_lt_of_le (hmono a b hab) with heq | hlt · exact Or.inr ⟨Fin.ext heq, (toPermOfLinExt_lt_iff c hc hanti e a b (Fin.ext heq)).mp hab⟩ · exact Or.inl hlt · rintro (hlt | ⟨heq, hplt⟩) · by_contra hge; push Not at hge rcases eq_or_lt_of_le hge with heq | hgt · have hab : b = a := Subtype.ext (e.1.injective heq); subst hab; exact lt_irrefl _ hlt · exact not_lt_of_ge (hmono b a hgt) hlt · exact (toPermOfLinExt_lt_iff c hc hanti e a b heq).mpr hplt refine ⟨?_, ?_, ?_⟩ · have hT : totalLinExt P = Fintype.card (LinExt P) := by unfold totalLinExt; convert rfl rw [hT, Fintype.card_congr eSplit, Fintype.card_sigma] unfold totalWeight exact Finset.sum_congr rfl fun s _ => hfiber_card s · intro a i have hC : countBefore a.1 (c i) = Fintype.card { e : LinExt P // e.1 a.1 < e.1 (c i) } := by unfold countBefore; convert rfl rw [hC] let eSub := subtypeSigmaEquiv eSplit (fun e => e.1 a.1 < e.1 (c i)) (fun s => (s.1 a).val ≤ i.val) (fun e => hslot_ac e a i) rw [Fintype.card_congr eSub, Fintype.card_sigma] have hsum_eq : ∑ s : { s : ValidSlot I // (s.1 a).val ≤ i.val }, Fintype.card (∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j)) = ∑ s : { s : ValidSlot I // (s.1 a).val ≤ i.val }, slotWeight s.1.1 := Finset.sum_congr rfl fun s _ => hfiber_card s.1 rw [hsum_eq] convert (Finset.sum_subtype (Finset.univ.filter (fun s : ValidSlot I => (s.1 a).val ≤ i.val)) (p := fun s : ValidSlot I => (s.1 a).val ≤ i.val) (fun _ => by simp) (fun s => slotWeight s.1)).symm · intro a b hab have hC : countBefore a.1 b.1 = Fintype.card { e : LinExt P // e.1 a.1 < e.1 b.1 } := by unfold countBefore; convert rfl rw [hC] let ePart := subtypeSigmaSplitEquiv eSplit (fun e => e.1 a.1 < e.1 b.1) (fun s => s.1 a < s.1 b) (fun s => s.1 a = s.1 b) (fun s hs π => π (s.1 b) ⟨a, hs⟩ < π (s.1 b) ⟨b, rfl⟩) (fun s hlt heq => ne_of_lt hlt heq) (fun e => hslot_ab e a b) rw [Fintype.card_congr ePart, Fintype.card_sum, mul_add] refine congrArg₂ (· + ·) ?_ ?_ · apply congrArg (2 * ·) rw [Fintype.card_sigma] have hsum_eq : ∑ s : { s : ValidSlot I // s.1 a < s.1 b }, Fintype.card (∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j)) = ∑ s : { s : ValidSlot I // s.1 a < s.1 b }, slotWeight s.1.1 := Finset.sum_congr rfl fun s _ => hfiber_card s.1 rw [hsum_eq] unfold slotLtWeight convert (Finset.sum_subtype (Finset.univ.filter (fun s : ValidSlot I => s.1 a < s.1 b)) (p := fun s : ValidSlot I => s.1 a < s.1 b) (fun _ => by simp) (fun s => slotWeight s.1)).symm · rw [Fintype.card_sigma, Finset.mul_sum] have hper : ∀ s : { s : ValidSlot I // s.1 a = s.1 b }, 2 * Fintype.card { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // π (s.1.1 b) ⟨a, s.2⟩ < π (s.1.1 b) ⟨b, rfl⟩ } = slotWeight s.1.1 := by intro s let j₀ := s.1.1 b let a' : { x : A // s.1.1 x = j₀ } := ⟨a, s.2⟩ let b' : { x : A // s.1.1 x = j₀ } := ⟨b, rfl⟩ have hab' : a' ≠ b' := fun h => hab (congrArg Subtype.val h) let flipPi : (∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j)) → (∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j)) := fun π j => if h : j = j₀ then h ▸ ((Equiv.swap a' b').trans (π j₀)) else π j have hflip_j0 : ∀ π, flipPi π j₀ = (Equiv.swap a' b').trans (π j₀) := fun π => by simp [flipPi] have hflip_inv : ∀ π, flipPi (flipPi π) = π := by intro π; funext j by_cases h : j = j₀ · subst h; rw [hflip_j0, hflip_j0]; ext x; simp · simp [flipPi, h] let eSwap : { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // π j₀ a' < π j₀ b' } ≃ { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // π j₀ b' < π j₀ a' } := { toFun := fun π => ⟨flipPi π.1, by rw [hflip_j0] change π.1 j₀ (Equiv.swap a' b' b') < π.1 j₀ (Equiv.swap a' b' a') rw [Equiv.swap_apply_right, Equiv.swap_apply_left]; exact π.2⟩ invFun := fun π => ⟨flipPi π.1, by rw [hflip_j0] change π.1 j₀ (Equiv.swap a' b' a') < π.1 j₀ (Equiv.swap a' b' b') rw [Equiv.swap_apply_left, Equiv.swap_apply_right]; exact π.2⟩ left_inv := fun π => Subtype.ext (hflip_inv π.1) right_inv := fun π => Subtype.ext (hflip_inv π.1) } have hsum_pi : Fintype.card { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // π j₀ a' < π j₀ b' } + Fintype.card { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // π j₀ b' < π j₀ a' } = Fintype.card (∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j)) := by have h1 : Fintype.card { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // π j₀ a' < π j₀ b' } + Fintype.card { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // ¬ π j₀ a' < π j₀ b' } = Fintype.card (∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j)) := by rw [Fintype.card_subtype_compl] exact Nat.add_sub_cancel' (Fintype.card_subtype_le _) have h2 : Fintype.card { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // ¬ π j₀ a' < π j₀ b' } = Fintype.card { π : ∀ j : Fin (m + 1), { x : A // s.1.1 x = j } ≃ Fin (slotCount s.1.1 j) // π j₀ b' < π j₀ a' } := by refine Fintype.card_congr (Equiv.subtypeEquivRight fun π => ?_) constructor · intro hnot have hne : π j₀ a' ≠ π j₀ b' := fun h => hab' ((π j₀).injective h) exact lt_of_le_of_ne (le_of_not_gt hnot) hne.symm · intro hlt; exact not_lt_of_gt hlt rw [← h2]; exact h1 have heq_swap := Fintype.card_congr eSwap have htot_pi := hfiber_card s.1 dsimp only [j₀, a', b'] at hsum_pi heq_swap omega rw [Finset.sum_congr rfl fun s _ => hper s] unfold slotEqWeight convert (Finset.sum_subtype (Finset.univ.filter (fun s : ValidSlot I => s.1 a = s.1 b)) (p := fun s : ValidSlot I => s.1 a = s.1 b) (fun _ => by simp) (fun s => slotWeight s.1)).symm end SplitBijection /-- Every finite split poset admits at least one linear extension (`0 < totalLinExt P`). -/ lemma splitPoset_totalLinExt_pos {P : Type*} [PartialOrder P] [Fintype P] (hsplit : IsSplitPoset P) : 0 < totalLinExt P := by classical rcases hsplit with ⟨C, A, hCA, hdisj, hchain, hanti⟩ let m := Fintype.card C rcases linearOrderEquivFin C (fun x y => hchain x.1 x.2 y.1 y.2) with ⟨eC, heC⟩ let c : Fin m → P := fun i => (eC.symm i).1 have hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j := fun i j => by have h := heC (eC.symm i) (eC.symm j) simpa [c] using h.symm have hrange : Set.range c = C := by ext x; constructor · rintro ⟨i, rfl⟩; exact (eC.symm i).2 · intro hx; exact ⟨eC ⟨x, hx⟩, by simp [c]⟩ have hanti' : ∀ x y : { x : P // x ∉ Set.range c }, x.1 ≤ y.1 → x = y := by intro x y hxy have hxA : x.1 ∈ A := by have : x.1 ∈ C ∪ A := by rw [hCA]; trivial exact this.resolve_left (hrange ▸ x.2) have hyA : y.1 ∈ A := by have : y.1 ∈ C ∪ A := by rw [hCA]; trivial exact this.resolve_left (hrange ▸ y.2) exact Subtype.ext (hanti x.1 hxA y.1 hyA hxy) have ⟨hT, _, _⟩ := splitPoset_counts c hc hanti' rw [hT] exact totalWeight_pos _ /-- **Theorem A (Exact 1/3–2/3 Conjecture for ALL Split Posets)**: Every finite non-total split poset `P = C ∪ A` (arbitrary chain size `m`, arbitrary antichain size `k`, unbounded width and height) contains a `1/3`-balanced pair `(x, y)`. -/ theorem one_third_two_thirds_split_poset {P : Type*} [PartialOrder P] [Fintype P] (hsplit : IsSplitPoset P) (hnt : ¬ ∀ x y : P, x ≤ y ∨ y ≤ x) : ∃ x y : P, IsBalancedPair x y := by classical rcases hsplit with ⟨C, A, hCA, hdisj, hchain, hanti⟩ let m := Fintype.card C rcases linearOrderEquivFin C (fun x y => hchain x.1 x.2 y.1 y.2) with ⟨eC, heC⟩ let c : Fin m → P := fun i => (eC.symm i).1 have hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j := fun i j => by have h := heC (eC.symm i) (eC.symm j) simpa [c] using h.symm have hrange : Set.range c = C := by ext x; constructor · rintro ⟨i, rfl⟩; exact (eC.symm i).2 · intro hx; exact ⟨eC ⟨x, hx⟩, by simp [c]⟩ let Ac := { x : P // x ∉ Set.range c } have hmemA : ∀ x : Ac, x.1 ∈ A := fun x => by have hu : x.1 ∈ C ∪ A := by rw [hCA]; trivial exact hu.resolve_left (hrange ▸ x.2) have hanti' : ∀ x y : Ac, x.1 ≤ y.1 → x = y := fun x y hxy => Subtype.ext (hanti x.1 (hmemA x) y.1 (hmemA y) hxy) by_cases hm : m = 0 · have hC_empty : C = ∅ := by ext x; simp only [Set.mem_empty_iff_false, iff_false] intro hx have : 0 < m := Fintype.card_pos_iff.mpr ⟨⟨x, hx⟩⟩ omega have hP_anti : ∀ x y : P, x ≤ y → x = y := by intro x y hxy have hxA : x ∈ A := by have hu : x ∈ C ∪ A := by rw [hCA]; trivial exact hu.resolve_left (by simp [hC_empty]) have hyA : y ∈ A := by have hu : y ∈ C ∪ A := by rw [hCA]; trivial exact hu.resolve_left (by simp [hC_empty]) exact hanti x hxA y hyA hxy push Not at hnt rcases hnt with ⟨x, y, h1, h2⟩ have hxy : x ≠ y := fun h => h1 (le_of_eq h) exact ⟨x, y, antichain_balanced hP_anti x y hxy⟩ · set I := splitIntervalsOfChain c hc hanti' have ⟨hT, hAC, hAA⟩ := splitPoset_counts c hc hanti' have hT_pos : 0 < totalLinExt P := hT ▸ totalWeight_pos I have hne : Nonempty Ac := by by_contra hempty rw [not_nonempty_iff] at hempty apply hnt; intro x y have hxC : x ∈ C := by by_contra hx; exact hempty.false ⟨x, hrange.symm ▸ hx⟩ have hyC : y ∈ C := by by_contra hy; exact hempty.false ⟨y, hrange.symm ▸ hy⟩ exact hchain x hxC y hyC have hI_nt : ¬ (Fintype.card Ac = 1 ∧ ∀ a : Ac, I.l a = I.r a) := by rintro ⟨hcard1, hlr⟩ have hsubAc : Subsingleton Ac := Fintype.card_le_one_iff_subsingleton.mp (by omega) apply hnt; intro x y by_cases hx : x ∈ Set.range c · by_cases hy : y ∈ Set.range c · exact hchain x (hrange ▸ hx) y (hrange ▸ hy) · rcases hx with ⟨i, rfl⟩ let b : Ac := ⟨y, hy⟩ have hlb := hlr b by_cases hil : i.val < I.l b · exact Or.inl (le_of_lt ((splitIntervalsOfChain_lt_iff c hc hanti' b i).1.mpr hil)) · exact Or.inr (le_of_lt ((splitIntervalsOfChain_lt_iff c hc hanti' b i).2.mpr (by change I.r b ≤ i.val; omega))) · by_cases hy : y ∈ Set.range c · rcases hy with ⟨j, rfl⟩ let a : Ac := ⟨x, hx⟩ have hla := hlr a by_cases hjl : j.val < I.l a · exact Or.inr (le_of_lt ((splitIntervalsOfChain_lt_iff c hc hanti' a j).1.mpr hjl)) · exact Or.inl (le_of_lt ((splitIntervalsOfChain_lt_iff c hc hanti' a j).2.mpr (by change I.r a ≤ j.val; omega))) · have heq : (⟨x, hx⟩ : Ac) = ⟨y, hy⟩ := hsubAc.elim _ _ exact Or.inl (le_of_eq (congrArg Subtype.val heq)) rcases splitIntervals_exists_balanced I hne hI_nt with ⟨a, i, h1, h2⟩ | ⟨a, b, hab, h1, h2⟩ · refine ⟨a.1, c i, hT_pos, ?_, ?_⟩ · rw [hT, hAC a i]; exact h1 · rw [hT, hAC a i]; exact h2 · refine ⟨a.1, b.1, hT_pos, ?_, ?_⟩ · have h2C : 2 * countBefore a.1 b.1 = 2 * slotLtWeight I a b + slotEqWeight I a b := hAA a b hab have hT' : totalLinExt P = totalWeight I := hT rw [hT']; omega · have h2C : 2 * countBefore a.1 b.1 = 2 * slotLtWeight I a b + slotEqWeight I a b := hAA a b hab have hT' : totalLinExt P = totalWeight I := hT rw [hT']; omega /-- **Theorem A (`FormalConjectures` Interface)**: Exact `FormalConjectures`-format theorem for every finite non-total split poset. -/ theorem formalConjectures_split_poset (P : Type*) [Finite P] [PartialOrder P] (hsplit : IsSplitPoset P) (not_total : ¬ Std.Total (α := P) (· ≤ ·)) (total_ext : Set (P →o ℕ)) (total_ext_def : ∀ σ, σ ∈ total_ext ↔ Set.range σ = Set.Icc 1 (Nat.card P)) : ∃ x y : P, (({σ ∈ total_ext | σ x < σ y}.ncard : ℚ) / (total_ext.ncard : ℚ)) ∈ Set.Icc (1 / 3 : ℚ) (2 / 3 : ℚ) := by let _ : Fintype P := Fintype.ofFinite P have hnt : ¬ ∀ x y : P, x ≤ y ∨ y ≤ x := fun h => not_total ⟨h⟩ rcases one_third_two_thirds_split_poset hsplit hnt with ⟨x, y, hbal⟩ exact ⟨x, y, formalConjectures_of_isBalancedPair P total_ext total_ext_def hbal⟩ /-! ## Section 6: Theorem B — Ordinal Sum Closure and Block-Split Posets -/ /-- `S : Set P` is an **ordinal prefix** of `P` if every element of `S` is strictly less than every element outside `S`. -/ def IsOrdinalPrefix {P : Type*} [PartialOrder P] (S : Set P) : Prop := ∀ x ∈ S, ∀ y ∉ S, x < y /-- Exact product decomposition `LinExt P ≃ LinExt S × LinExt (Sᶜ)` for an ordinal prefix `S`. -/ noncomputable def ordinalPrefixLinExtEquiv {P : Type*} [PartialOrder P] [Fintype P] (S : Set P) [DecidablePred (· ∈ S)] (hpref : IsOrdinalPrefix S) : LinExt P ≃ LinExt { x : P // x ∈ S } × LinExt { x : P // x ∉ S } := by classical let m := Fintype.card { x : P // x ∈ S } let k := Fintype.card { x : P // x ∉ S } have hcardP : Fintype.card P = m + k := by have e : P ≃ { x : P // x ∈ S } ⊕ { x : P // x ∉ S } := { toFun := fun x => if h : x ∈ S then Sum.inl ⟨x, h⟩ else Sum.inr ⟨x, h⟩ invFun := Sum.elim Subtype.val Subtype.val left_inv := fun x => by by_cases h : x ∈ S <;> simp [h] right_inv := fun z => by rcases z with ⟨x, hx⟩ | ⟨x, hx⟩ <;> simp [hx] } rw [Fintype.card_congr e, Fintype.card_sum] have hlt_m : ∀ (e : LinExt P) (x : P), x ∈ S → (e.1 x).val < m := by intro e x hx have hsub : Finset.univ.filter (fun z : P => e.1 z ≤ e.1 x) ⊆ Finset.univ.filter (fun z : P => z ∈ S) := by intro z hz simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hz ⊢ by_contra hzS have hlt : x < z := hpref x hx z hzS have hle : e.1 x ≤ e.1 z := e.2 _ _ (le_of_lt hlt) have heq : x = z := e.1.injective (le_antisymm hle hz) exact ne_of_lt hlt heq have hcard_le : (Finset.univ.filter (fun z : P => e.1 z ≤ e.1 x)).card ≤ m := by have h1 := Finset.card_le_card hsub have h2 : (Finset.univ.filter (fun z : P => z ∈ S)).card = m := by dsimp [m]; rw [Fintype.card_subtype] omega have hcard_eq : (Finset.univ.filter (fun z : P => e.1 z ≤ e.1 x)).card = (e.1 x).val + 1 := by have hbij : (Finset.univ.filter (fun z : P => e.1 z ≤ e.1 x)).card = (Finset.range ((e.1 x).val + 1)).card := Finset.card_bij (fun z _ => (e.1 z).val) (fun z hz => Finset.mem_range.mpr (Nat.lt_succ_of_le (Finset.mem_filter.mp hz).2)) (fun z₁ _ z₂ _ h => e.1.injective (Fin.ext h)) (fun t ht => have htle : t ≤ (e.1 x).val := Nat.lt_succ_iff.mp (Finset.mem_range.mp ht) ⟨e.1.symm ⟨t, lt_of_le_of_lt htle (e.1 x).isLt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by change (e.1 (e.1.symm ⟨t, _⟩)).val ≤ (e.1 x).val rw [Equiv.apply_symm_apply]; exact htle⟩, by simp⟩) rw [hbij, Finset.card_range] omega have hge_m : ∀ (e : LinExt P) (y : P), y ∉ S → m ≤ (e.1 y).val := by intro e y hy have hsub : Finset.univ.filter (fun z : P => z ∈ S) ⊆ Finset.univ.filter (fun z : P => e.1 z < e.1 y) := by intro z hz simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hz ⊢ have hlt : z < y := hpref z hz y hy exact lt_of_le_of_ne (e.2 _ _ (le_of_lt hlt)) (fun h => ne_of_lt hlt (e.1.injective h)) have hcard_le := Finset.card_le_card hsub have h1 : (Finset.univ.filter (fun z : P => z ∈ S)).card = m := by dsimp [m]; rw [Fintype.card_subtype] have h2 : (Finset.univ.filter (fun z : P => e.1 z < e.1 y)).card = (e.1 y).val := by have hbij : (Finset.univ.filter (fun z : P => e.1 z < e.1 y)).card = (Finset.range (e.1 y).val).card := Finset.card_bij (fun z _ => (e.1 z).val) (fun z hz => Finset.mem_range.mpr (Finset.mem_filter.mp hz).2) (fun z₁ _ z₂ _ h => e.1.injective (Fin.ext h)) (fun t ht => ⟨e.1.symm ⟨t, (Finset.mem_range.mp ht).trans (e.1 y).isLt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by change (e.1 (e.1.symm ⟨t, _⟩)).val < (e.1 y).val rw [Equiv.apply_symm_apply]; exact Finset.mem_range.mp ht⟩, by simp⟩) rw [hbij, Finset.card_range] omega refine { toFun := fun e => let f₁ : { x : P // x ∈ S } → Fin m := fun x => ⟨(e.1 x.1).val, hlt_m e x.1 x.2⟩ let f₂ : { x : P // x ∉ S } → Fin k := fun y => ⟨(e.1 y.1).val - m, by have := (e.1 y.1).isLt; have := hge_m e y.1 y.2; omega⟩ have hf₁_inj : Function.Injective f₁ := fun a b h => by have hv : (f₁ a).val = (f₁ b).val := congrArg Fin.val h exact Subtype.ext (e.1.injective (Fin.ext hv)) have hf₂_inj : Function.Injective f₂ := fun a b h => by have hv : (e.1 a.1).val - m = (e.1 b.1).val - m := congrArg Fin.val h have ha := hge_m e a.1 a.2 have hb := hge_m e b.1 b.2 exact Subtype.ext (e.1.injective (Fin.ext (by omega))) (⟨Equiv.ofBijective f₁ ((Fintype.bijective_iff_injective_and_card f₁).mpr ⟨hf₁_inj, (Fintype.card_fin m).symm⟩), fun a b hab => e.2 a.1 b.1 hab⟩, ⟨Equiv.ofBijective f₂ ((Fintype.bijective_iff_injective_and_card f₂).mpr ⟨hf₂_inj, (Fintype.card_fin k).symm⟩), fun a b hab => Nat.sub_le_sub_right (e.2 a.1 b.1 hab) m⟩) invFun := fun p => let g : P → Fin (Fintype.card P) := fun x => if h : x ∈ S then ⟨(p.1.1 ⟨x, h⟩).val, by rw [hcardP]; exact lt_of_lt_of_le (p.1.1 ⟨x, h⟩).isLt (Nat.le_add_right m k)⟩ else ⟨m + (p.2.1 ⟨x, h⟩).val, by rw [hcardP]; exact Nat.add_lt_add_left (p.2.1 ⟨x, h⟩).isLt m⟩ have hg_inj : Function.Injective g := by intro x y hxy have hv := congrArg Fin.val hxy dsimp [g] at hv by_cases hx : x ∈ S <;> by_cases hy : y ∈ S · simp only [dif_pos hx, dif_pos hy] at hv exact congrArg Subtype.val (p.1.1.injective (Fin.ext hv)) · simp only [dif_pos hx, dif_neg hy] at hv have := (p.1.1 ⟨x, hx⟩).isLt; omega · simp only [dif_neg hx, dif_pos hy] at hv have := (p.1.1 ⟨y, hy⟩).isLt; omega · simp only [dif_neg hx, dif_neg hy] at hv have hv2 : (p.2.1 ⟨x, hx⟩).val = (p.2.1 ⟨y, hy⟩).val := by omega exact congrArg Subtype.val (p.2.1.injective (Fin.ext hv2)) ⟨Equiv.ofBijective g ((Fintype.bijective_iff_injective_and_card g).mpr ⟨hg_inj, (Fintype.card_fin _).symm⟩), fun x y hxy => by change (g x).val ≤ (g y).val dsimp only [g] by_cases hx : x ∈ S <;> by_cases hy : y ∈ S · simp only [dif_pos hx, dif_pos hy]; exact p.1.2 ⟨x, hx⟩ ⟨y, hy⟩ hxy · simp only [dif_pos hx, dif_neg hy]; have := (p.1.1 ⟨x, hx⟩).isLt; omega · exfalso have hlt : y < x := hpref y hy x hx exact not_le_of_gt hlt hxy · simp only [dif_neg hx, dif_neg hy] exact Nat.add_le_add_left (p.2.2 ⟨x, hx⟩ ⟨y, hy⟩ hxy) m⟩ left_inv := fun e => by apply Subtype.ext; apply Equiv.ext; intro x; apply Fin.ext by_cases hx : x ∈ S · simp [hx] · have hge := hge_m e x hx simp only [Equiv.ofBijective_apply, dif_neg hx] omega right_inv := fun ⟨e₁, e₂⟩ => by refine Prod.ext ?_ ?_ · apply Subtype.ext; apply Equiv.ext; intro x; apply Fin.ext simp · apply Subtype.ext; apply Equiv.ext; intro y; apply Fin.ext simp [y.2] } /-- **Ordinal Prefix Preservation Lemma**: If `S` is an ordinal prefix of `P` and both `S` and `Sᶜ` have positive linear extension counts, then any `1/3`-balanced pair inside `S` or inside `Sᶜ` remains `1/3`-balanced in `P`! -/ lemma ordinalPrefix_lift_balanced {P : Type*} [PartialOrder P] [Fintype P] (S : Set P) [DecidablePred (· ∈ S)] (hpref : IsOrdinalPrefix S) : (0 < totalLinExt { x : P // x ∉ S } → ∀ x y : { x : P // x ∈ S }, IsBalancedPair x y → IsBalancedPair x.1 y.1) ∧ (0 < totalLinExt { x : P // x ∈ S } → ∀ x y : { x : P // x ∉ S }, IsBalancedPair x y → IsBalancedPair x.1 y.1) := by classical let eOrd := ordinalPrefixLinExtEquiv S hpref have hT_eq : totalLinExt P = totalLinExt { x : P // x ∈ S } * totalLinExt { x : P // x ∉ S } := by have h1 : totalLinExt P = Fintype.card (LinExt P) := by unfold totalLinExt; convert rfl have h2 : totalLinExt { x : P // x ∈ S } = Fintype.card (LinExt { x : P // x ∈ S }) := by unfold totalLinExt; convert rfl have h3 : totalLinExt { x : P // x ∉ S } = Fintype.card (LinExt { x : P // x ∉ S }) := by unfold totalLinExt; convert rfl rw [h1, h2, h3, Fintype.card_congr eOrd, Fintype.card_prod] refine ⟨?_, ?_⟩ · intro hT2_pos x y ⟨hT1_pos, h1, h2⟩ have hC_eq : countBefore x.1 y.1 = countBefore x y * totalLinExt { x : P // x ∉ S } := by have hcP : countBefore x.1 y.1 = Fintype.card { e : LinExt P // e.1 x.1 < e.1 y.1 } := by unfold countBefore; convert rfl have hcS : countBefore x y = Fintype.card { e : LinExt { z : P // z ∈ S } // e.1 x < e.1 y } := by unfold countBefore; convert rfl have hT2 : totalLinExt { z : P // z ∉ S } = Fintype.card (LinExt { z : P // z ∉ S }) := by unfold totalLinExt; convert rfl rw [hcP, hcS, hT2, ← Fintype.card_prod] refine Fintype.card_congr { toFun := fun e => (⟨(eOrd e.1).1, e.2⟩, (eOrd e.1).2) invFun := fun p => ⟨eOrd.symm (p.1.1, p.2), by have h := congrArg Prod.fst (eOrd.apply_symm_apply (p.1.1, p.2)) change ((eOrd (eOrd.symm (p.1.1, p.2))).1.1 x).val < ((eOrd (eOrd.symm (p.1.1, p.2))).1.1 y).val rw [h]; exact p.1.2⟩ left_inv := fun e => Subtype.ext (eOrd.left_inv e.1) right_inv := fun ⟨⟨e₁, he₁⟩, e₂⟩ => by simp only [Equiv.apply_symm_apply] } refine ⟨by rw [hT_eq]; exact Nat.mul_pos hT1_pos hT2_pos, ?_, ?_⟩ · rw [hT_eq, hC_eq, ← mul_assoc]; exact Nat.mul_le_mul_right _ h1 · rw [hT_eq, hC_eq, ← mul_assoc, ← mul_assoc]; exact Nat.mul_le_mul_right _ h2 · intro hT1_pos x y ⟨hT2_pos, h1, h2⟩ have hC_eq : countBefore x.1 y.1 = totalLinExt { x : P // x ∈ S } * countBefore x y := by have hcP : countBefore x.1 y.1 = Fintype.card { e : LinExt P // e.1 x.1 < e.1 y.1 } := by unfold countBefore; convert rfl have hcSc : countBefore x y = Fintype.card { e : LinExt { z : P // z ∉ S } // e.1 x < e.1 y } := by unfold countBefore; convert rfl have hT1 : totalLinExt { z : P // z ∈ S } = Fintype.card (LinExt { z : P // z ∈ S }) := by unfold totalLinExt; convert rfl rw [hcP, hcSc, hT1, ← Fintype.card_prod] have hlt_iff : ∀ (e : LinExt P), e.1 x.1 < e.1 y.1 ↔ (eOrd e).2.1 x < (eOrd e).2.1 y := by intro e have hx_eq : (e.1 x.1).val = Fintype.card { z : P // z ∈ S } + ((eOrd e).2.1 x).val := by have := congrArg (fun f : LinExt P => (f.1 x.1).val) (eOrd.left_inv e) simpa [eOrd, ordinalPrefixLinExtEquiv, x.2] using this.symm have hy_eq : (e.1 y.1).val = Fintype.card { z : P // z ∈ S } + ((eOrd e).2.1 y).val := by have := congrArg (fun f : LinExt P => (f.1 y.1).val) (eOrd.left_inv e) simpa [eOrd, ordinalPrefixLinExtEquiv, y.2] using this.symm change (e.1 x.1).val < (e.1 y.1).val ↔ ((eOrd e).2.1 x).val < ((eOrd e).2.1 y).val omega refine Fintype.card_congr { toFun := fun e => ((eOrd e.1).1, ⟨(eOrd e.1).2, (hlt_iff e.1).mp e.2⟩) invFun := fun p => ⟨eOrd.symm (p.1, p.2.1), by rw [hlt_iff, eOrd.apply_symm_apply]; exact p.2.2⟩ left_inv := fun e => Subtype.ext (eOrd.left_inv e.1) right_inv := fun ⟨e₁, ⟨e₂, he₂⟩⟩ => by simp only [Equiv.apply_symm_apply] } refine ⟨by rw [hT_eq]; exact Nat.mul_pos hT1_pos hT2_pos, ?_, ?_⟩ · rw [hT_eq, hC_eq, mul_left_comm]; exact Nat.mul_le_mul_left _ h1 · rw [hT_eq, hC_eq, mul_left_comm 3, mul_left_comm 2]; exact Nat.mul_le_mul_left _ h2 /-- A poset `P` is a **block-split poset** (finite ordinal sum of split posets) if there is a block index `b : P → Fin t` such that `b x < b y → x < y` and every fiber `{ x // b x = k }` is a split poset. -/ def IsBlockSplitPoset (P : Type*) [PartialOrder P] : Prop := ∃ (t : ℕ) (b : P → Fin t), (∀ x y : P, b x < b y → x < y) ∧ (∀ k : Fin t, IsSplitPoset { x : P // b x = k }) /-- Every finite block-split poset admits at least one linear extension. -/ lemma blockSplit_totalLinExt_pos : ∀ (t : ℕ) {P : Type*} [PartialOrder P] [Fintype P] (b : P → Fin t), (∀ x y : P, b x < b y → x < y) → (∀ k : Fin t, IsSplitPoset { x : P // b x = k }) → 0 < totalLinExt P | 0, P, _, _, b, _, _ => by classical have hEmpty : IsEmpty P := ⟨fun x => Fin.elim0 (b x)⟩ have hT : totalLinExt P = Fintype.card (LinExt P) := by unfold totalLinExt; convert rfl rw [hT] exact Fintype.card_pos_iff.mpr ⟨⟨Fintype.equivFin P, fun x => hEmpty.elim x⟩⟩ | t + 1, P, _, _, b, hord, hfib => by classical let S : Set P := { x : P | b x = 0 } have hpref : IsOrdinalPrefix S := fun x hx y hy => hord x y (by have hx0 : (b x).val = 0 := congrArg Fin.val hx have hy0 : (b y).val ≠ 0 := fun h => hy (Fin.ext h) change (b x).val < (b y).val; omega) have hT1 : 0 < totalLinExt { x : P // x ∈ S } := splitPoset_totalLinExt_pos (hfib 0) let b' : { x : P // x ∉ S } → Fin t := fun y => ⟨(b y.1).val - 1, by have hne : (b y.1).val ≠ 0 := fun h => y.2 (Fin.ext h) have hlt := (b y.1).isLt; omega⟩ have hord' : ∀ x y : { z : P // z ∉ S }, b' x < b' y → x < y := fun x y hxy => by have hne1 : (b x.1).val ≠ 0 := fun h => x.2 (Fin.ext h) have hne2 : (b y.1).val ≠ 0 := fun h => y.2 (Fin.ext h) have hlt : b x.1 < b y.1 := by change (b x.1).val < (b y.1).val have : (b x.1).val - 1 < (b y.1).val - 1 := hxy omega exact hord x.1 y.1 hlt have hfib' : ∀ k : Fin t, IsSplitPoset { y : { z : P // z ∉ S } // b' y = k } := by intro k rcases hfib k.succ with ⟨C, A, hCA, hdisj, hch, han⟩ let eK : { y : { z : P // z ∉ S } // b' y = k } ≃ { z : P // b z = k.succ } := { toFun := fun y => ⟨y.1.1, by apply Fin.ext have hne : (b y.1.1).val ≠ 0 := fun h => y.1.2 (Fin.ext h) have hk : (b y.1.1).val - 1 = k.val := congrArg Fin.val y.2 change (b y.1.1).val = k.val + 1; omega⟩ invFun := fun z => ⟨⟨z.1, fun h => by have h1 := congrArg Fin.val z.2; have h2 := congrArg Fin.val h simp only [Fin.val_succ, Fin.val_zero] at h1 h2; omega⟩, Fin.ext (by change (b z.1).val - 1 = k.val; rw [z.2]; simp)⟩ left_inv := fun y => Subtype.ext (Subtype.ext rfl) right_inv := fun z => Subtype.ext rfl } refine ⟨eK ⁻¹' C, eK ⁻¹' A, ?_, ?_, ?_, ?_⟩ · ext y; simp only [Set.mem_union, Set.mem_preimage, Set.mem_univ, iff_true] have hu : eK y ∈ C ∪ A := by rw [hCA]; trivial exact hu · exact hdisj.preimage eK · intro x hx y hy; exact hch (eK x) hx (eK y) hy · intro x hx y hy hxy; exact eK.injective (han (eK x) hx (eK y) hy hxy) have hT2 : 0 < totalLinExt { x : P // x ∉ S } := blockSplit_totalLinExt_pos t b' hord' hfib' have hT : totalLinExt P = totalLinExt { x : P // x ∈ S } * totalLinExt { x : P // x ∉ S } := by have h1 : totalLinExt P = Fintype.card (LinExt P) := by unfold totalLinExt; convert rfl have h2 : totalLinExt { x : P // x ∈ S } = Fintype.card (LinExt { x : P // x ∈ S }) := by unfold totalLinExt; convert rfl have h3 : totalLinExt { x : P // x ∉ S } = Fintype.card (LinExt { x : P // x ∉ S }) := by unfold totalLinExt; convert rfl rw [h1, h2, h3, Fintype.card_congr (ordinalPrefixLinExtEquiv S hpref), Fintype.card_prod] rw [hT]; exact Nat.mul_pos hT1 hT2 /-- **Theorem B (Exact 1/3–2/3 Conjecture for ALL Block-Split Posets)**: Every finite non-total ordinal sum of split posets contains a `1/3`-balanced pair. -/ theorem one_third_two_thirds_block_split_aux : ∀ (t : ℕ) {P : Type*} [PartialOrder P] [Fintype P] (b : P → Fin t), (∀ x y : P, b x < b y → x < y) → (∀ k : Fin t, IsSplitPoset { x : P // b x = k }) → (¬ ∀ x y : P, x ≤ y ∨ y ≤ x) → ∃ x y : P, IsBalancedPair x y | 0, P, _, _, b, _, _, hnt => by exfalso; apply hnt; intro x; exact Fin.elim0 (b x) | t + 1, P, _, _, b, hord, hfib, hnt => by classical let S : Set P := { x : P | b x = 0 } have hpref : IsOrdinalPrefix S := fun x hx y hy => hord x y (by have hx0 : (b x).val = 0 := congrArg Fin.val hx have hy0 : (b y).val ≠ 0 := fun h => hy (Fin.ext h) change (b x).val < (b y).val; omega) let b' : { x : P // x ∉ S } → Fin t := fun y => ⟨(b y.1).val - 1, by have hne : (b y.1).val ≠ 0 := fun h => y.2 (Fin.ext h) have hlt := (b y.1).isLt; omega⟩ have hord' : ∀ x y : { z : P // z ∉ S }, b' x < b' y → x < y := fun x y hxy => by have hne1 : (b x.1).val ≠ 0 := fun h => x.2 (Fin.ext h) have hne2 : (b y.1).val ≠ 0 := fun h => y.2 (Fin.ext h) have hlt : b x.1 < b y.1 := by change (b x.1).val < (b y.1).val have : (b x.1).val - 1 < (b y.1).val - 1 := hxy omega exact hord x.1 y.1 hlt have hfib' : ∀ k : Fin t, IsSplitPoset { y : { z : P // z ∉ S } // b' y = k } := by intro k rcases hfib k.succ with ⟨C, A, hCA, hdisj, hch, han⟩ let eK : { y : { z : P // z ∉ S } // b' y = k } ≃ { z : P // b z = k.succ } := { toFun := fun y => ⟨y.1.1, by apply Fin.ext have hne : (b y.1.1).val ≠ 0 := fun h => y.1.2 (Fin.ext h) have hk : (b y.1.1).val - 1 = k.val := congrArg Fin.val y.2 change (b y.1.1).val = k.val + 1; omega⟩ invFun := fun z => ⟨⟨z.1, fun h => by have h1 := congrArg Fin.val z.2; have h2 := congrArg Fin.val h simp only [Fin.val_succ, Fin.val_zero] at h1 h2; omega⟩, Fin.ext (by change (b z.1).val - 1 = k.val; rw [z.2]; simp)⟩ left_inv := fun y => Subtype.ext (Subtype.ext rfl) right_inv := fun z => Subtype.ext rfl } refine ⟨eK ⁻¹' C, eK ⁻¹' A, ?_, ?_, ?_, ?_⟩ · ext y; simp only [Set.mem_union, Set.mem_preimage, Set.mem_univ, iff_true] have hu : eK y ∈ C ∪ A := by rw [hCA]; trivial exact hu · exact hdisj.preimage eK · intro x hx y hy; exact hch (eK x) hx (eK y) hy · intro x hx y hy hxy; exact eK.injective (han (eK x) hx (eK y) hy hxy) by_cases hStot : ∀ x y : { z : P // z ∈ S }, x ≤ y ∨ y ≤ x · have hSc_nt : ¬ ∀ x y : { z : P // z ∉ S }, x ≤ y ∨ y ≤ x := by intro hSc apply hnt; intro x y by_cases hx : x ∈ S <;> by_cases hy : y ∈ S · exact hStot ⟨x, hx⟩ ⟨y, hy⟩ · exact Or.inl (le_of_lt (hpref x hx y hy)) · exact Or.inr (le_of_lt (hpref y hy x hx)) · exact hSc ⟨x, hx⟩ ⟨y, hy⟩ rcases one_third_two_thirds_block_split_aux t b' hord' hfib' hSc_nt with ⟨x, y, hbal⟩ have hT1 : 0 < totalLinExt { z : P // z ∈ S } := splitPoset_totalLinExt_pos (hfib 0) exact ⟨x.1, y.1, (ordinalPrefix_lift_balanced S hpref).2 hT1 x y hbal⟩ · rcases one_third_two_thirds_split_poset (hfib 0) hStot with ⟨x, y, hbal⟩ have hT2 : 0 < totalLinExt { z : P // z ∉ S } := blockSplit_totalLinExt_pos t b' hord' hfib' exact ⟨x.1, y.1, (ordinalPrefix_lift_balanced S hpref).1 hT2 x y hbal⟩ /-- **Theorem B (Block-Split Poset Balance Theorem)**: Every finite non-total block-split poset satisfies the exact `1/3–2/3` Conjecture. -/ theorem one_third_two_thirds_block_split {P : Type*} [PartialOrder P] [Fintype P] (hbs : IsBlockSplitPoset P) (hnt : ¬ ∀ x y : P, x ≤ y ∨ y ≤ x) : ∃ x y : P, IsBalancedPair x y := by rcases hbs with ⟨t, b, hord, hfib⟩ exact one_third_two_thirds_block_split_aux t b hord hfib hnt /-- **Theorem B (`FormalConjectures` Interface)**: Exact `FormalConjectures`-format theorem for every finite non-total block-split poset. -/ theorem formalConjectures_block_split (P : Type*) [Finite P] [PartialOrder P] (hbs : IsBlockSplitPoset P) (not_total : ¬ Std.Total (α := P) (· ≤ ·)) (total_ext : Set (P →o ℕ)) (total_ext_def : ∀ σ, σ ∈ total_ext ↔ Set.range σ = Set.Icc 1 (Nat.card P)) : ∃ x y : P, (({σ ∈ total_ext | σ x < σ y}.ncard : ℚ) / (total_ext.ncard : ℚ)) ∈ Set.Icc (1 / 3 : ℚ) (2 / 3 : ℚ) := by let _ : Fintype P := Fintype.ofFinite P have hnt : ¬ ∀ x y : P, x ≤ y ∨ y ≤ x := fun h => not_total ⟨h⟩ rcases one_third_two_thirds_block_split hbs hnt with ⟨x, y, hbal⟩ exact ⟨x, y, formalConjectures_of_isBalancedPair P total_ext total_ext_def hbal⟩ /-! ## Section 7: Theorem C — The Exact 1/3–2/3 Conjecture for ALL Co-Height ≤ 2 Posets -/ /-- A poset `P` has **co-height ≤ 2** if it contains a chain `C` whose complement contains at most 2 elements (`|P| - h(P) ≤ 2`). -/ def HasCoheightLeTwo (P : Type*) [PartialOrder P] : Prop := ∃ C : Set P, (∀ x ∈ C, ∀ y ∈ C, x ≤ y ∨ y ≤ x) ∧ Cᶜ.ncard ≤ 2 /-- Direct 6-line arithmetic proof for a chain `C` of size `m` plus a comparable 2-chain `x < y`. -/ lemma chain_plus_two_chain_balanced {P : Type*} [PartialOrder P] [Fintype P] [DecidableEq P] {m : ℕ} (c : Fin m → P) (hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j) (x y : P) (hxC : x ∉ Set.range c) (hyC : y ∉ Set.range c) (hxy : x < y) (hcover : ∀ z : P, z ∈ Set.range c ∨ z = x ∨ z = y) (hnt : ¬ ∀ u v : P, u ≤ v ∨ v ≤ u) : ∃ u v : P, IsBalancedPair u v := by classical have hne_xy : x ≠ y := ne_of_lt hxy have hc_inj : Function.Injective c := fun i j hij => le_antisymm ((hc i j).mpr (le_of_eq hij)) ((hc j i).mpr (le_of_eq hij.symm)) -- Slot intervals [a₁, b₁] for x and [a₂, b₂] for y let a₁ := (Finset.univ.filter (fun i : Fin m => c i < x)).card let b₁ := m - (Finset.univ.filter (fun i : Fin m => x < c i)).card let a₂ := (Finset.univ.filter (fun i : Fin m => c i < y)).card let b₂ := m - (Finset.univ.filter (fun i : Fin m => y < c i)).card have ha₁_iff : ∀ i : Fin m, c i < x ↔ i.val < a₁ := fun i => by have h := downward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => c j < x)) (fun j k hjk hk => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_lt ((hc j k).mp hjk) (Finset.mem_filter.mp hk).2⟩) i simpa [a₁] using h have hb₁_iff : ∀ i : Fin m, x < c i ↔ b₁ ≤ i.val := fun i => by have h := upward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => x < c j)) (fun j k hjk hj => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_lt_of_le (Finset.mem_filter.mp hj).2 ((hc j k).mp hjk)⟩) i simpa [b₁] using h have ha₂_iff : ∀ i : Fin m, c i < y ↔ i.val < a₂ := fun i => by have h := downward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => c j < y)) (fun j k hjk hk => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_lt ((hc j k).mp hjk) (Finset.mem_filter.mp hk).2⟩) i simpa [a₂] using h have hb₂_iff : ∀ i : Fin m, y < c i ↔ b₂ ≤ i.val := fun i => by have h := upward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => y < c j)) (fun j k hjk hj => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_lt_of_le (Finset.mem_filter.mp hj).2 ((hc j k).mp hjk)⟩) i simpa [b₂] using h have ha₁_le_b₁ : a₁ ≤ b₁ := by have hdisj : Disjoint (Finset.univ.filter (fun i : Fin m => c i < x)) (Finset.univ.filter (fun i : Fin m => x < c i)) := Finset.disjoint_filter.mpr fun i _ h1 h2 => lt_asymm h1 h2 have hsum : a₁ + (Finset.univ.filter (fun i : Fin m => x < c i)).card ≤ m := by rw [← Finset.card_union_of_disjoint hdisj] exact (Finset.card_le_univ _).trans (by rw [Fintype.card_fin]) omega have ha₂_le_b₂ : a₂ ≤ b₂ := by have hdisj : Disjoint (Finset.univ.filter (fun i : Fin m => c i < y)) (Finset.univ.filter (fun i : Fin m => y < c i)) := Finset.disjoint_filter.mpr fun i _ h1 h2 => lt_asymm h1 h2 have hsum : a₂ + (Finset.univ.filter (fun i : Fin m => y < c i)).card ≤ m := by rw [← Finset.card_union_of_disjoint hdisj] exact (Finset.card_le_univ _).trans (by rw [Fintype.card_fin]) omega have ha₁_le_a₂ : a₁ ≤ a₂ := Finset.card_le_card fun i hi => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hi).2.trans hxy⟩ have hb₁_le_b₂ : b₁ ≤ b₂ := by have hsub : (Finset.univ.filter (fun i : Fin m => y < c i)).card ≤ (Finset.univ.filter (fun i : Fin m => x < c i)).card := Finset.card_le_card fun i hi => Finset.mem_filter.mpr ⟨Finset.mem_univ _, hxy.trans (Finset.mem_filter.mp hi).2⟩ omega have hb₁_le_m : b₁ ≤ m := Nat.sub_le m _ have hb₂_le_m : b₂ ≤ m := Nat.sub_le m _ -- If a₁ = b₁, then x is comparable to EVERY element of C and x < y, so C ∪ {x} is a chain -- with singleton complement {y} → split poset → reuse Theorem A! by_cases ha1b1 : a₁ = b₁ · have hsplit : IsSplitPoset P := by refine ⟨insert x (Set.range c), {y}, ?_, ?_, ?_, ?_⟩ · ext z; simp only [Set.mem_union, Set.mem_insert_iff, Set.mem_singleton_iff, Set.mem_univ, iff_true] rcases hcover z with h | h | h · exact Or.inl (Or.inr h) · exact Or.inl (Or.inl h) · exact Or.inr h · rw [Set.disjoint_singleton_right] rintro (rfl | h) · exact hne_xy rfl · exact hyC h · rintro u (rfl | ⟨i, rfl⟩) v (rfl | ⟨j, rfl⟩) · exact Or.inl le_rfl · by_cases hj : j.val < a₁ · exact Or.inr (le_of_lt ((ha₁_iff j).mpr hj)) · exact Or.inl (le_of_lt ((hb₁_iff j).mpr (by omega))) · by_cases hi : i.val < a₁ · exact Or.inl (le_of_lt ((ha₁_iff i).mpr hi)) · exact Or.inr (le_of_lt ((hb₁_iff i).mpr (by omega))) · rcases le_total i j with h | h · exact Or.inl ((hc i j).mp h) · exact Or.inr ((hc j i).mp h) · rintro u rfl v rfl _; rfl exact one_third_two_thirds_split_poset hsplit hnt · -- Now a₁ < b₁! Build exact bijection LinExt P ≃ ValidPair have ha1_lt_b1 : a₁ < b₁ := lt_of_le_of_ne ha₁_le_b₁ ha1b1 let ValidPair := { p : Fin (m + 1) × Fin (m + 1) // a₁ ≤ p.1.val ∧ p.1.val ≤ b₁ ∧ a₂ ≤ p.2.val ∧ p.2.val ≤ b₂ ∧ p.1.val ≤ p.2.val } -- Partition P ≃ Fin m ⊕ Bool (false = x, true = y) let eP : P ≃ Fin m ⊕ Bool := { toFun := fun z => if h : z ∈ Set.range c then Sum.inl (Classical.choose h) else if z = x then Sum.inr false else Sum.inr true invFun := fun s => match s with | Sum.inl i => c i | Sum.inr false => x | Sum.inr true => y left_inv := fun z => by dsimp only by_cases h : z ∈ Set.range c · rw [dif_pos h]; exact Classical.choose_spec h · rw [dif_neg h] by_cases hzx : z = x · rw [if_pos hzx]; exact hzx.symm · rw [if_neg hzx] rcases hcover z with h' | h' | h' · exact absurd h' h · exact absurd h' hzx · exact h'.symm right_inv := fun s => by rcases s with i | b · have hmem : c i ∈ Set.range c := ⟨i, rfl⟩ dsimp only; rw [dif_pos hmem] exact congrArg Sum.inl (hc_inj (Classical.choose_spec hmem)) · cases b · dsimp only; rw [dif_neg hxC, if_pos rfl] · dsimp only; rw [dif_neg hyC, if_neg hne_xy.symm] } have hcardP : Fintype.card P = m + 2 := by rw [Fintype.card_congr eP, Fintype.card_sum, Fintype.card_fin, Fintype.card_bool] have heP_c : ∀ i : Fin m, eP (c i) = Sum.inl i := fun i => eP.right_inv (Sum.inl i) have heP_x : eP x = Sum.inr false := eP.right_inv (Sum.inr false) have heP_y : eP y = Sum.inr true := eP.right_inv (Sum.inr true) have heP_inl : ∀ {z : P} {i : Fin m}, eP z = Sum.inl i → z = c i := fun h => by have := congrArg eP.symm h; rw [eP.symm_apply_apply] at this; exact this have heP_false : ∀ {z : P}, eP z = Sum.inr false → z = x := fun h => by have := congrArg eP.symm h; rw [eP.symm_apply_apply] at this; exact this have heP_true : ∀ {z : P}, eP z = Sum.inr true → z = y := fun h => by have := congrArg eP.symm h; rw [eP.symm_apply_apply] at this; exact this -- Explicit position formula for a ValidPair (i, j) with i ≤ j: -- pos(x) = i, pos(y) = j + 1, pos(c_k) = k + (if i ≤ k then 1 else 0) + (if j ≤ k then 1 else 0) let mkPos : ValidPair → P → Fin (Fintype.card P) := fun p z => match eP z with | Sum.inl k => ⟨k.val + (if p.1.1.val ≤ k.val then 1 else 0) + (if p.1.2.val ≤ k.val then 1 else 0), by rw [hcardP]; split_ifs <;> omega⟩ | Sum.inr false => ⟨p.1.1.val, by rw [hcardP]; have := p.1.1.isLt; omega⟩ | Sum.inr true => ⟨p.1.2.val + 1, by rw [hcardP]; have := p.1.2.isLt; omega⟩ have hmkPos_c : ∀ p (k : Fin m), (mkPos p (c k)).val = k.val + (if p.1.1.val ≤ k.val then 1 else 0) + (if p.1.2.val ≤ k.val then 1 else 0) := by intro p k; simp [mkPos, heP_c] have hmkPos_x : ∀ p, (mkPos p x).val = p.1.1.val := fun p => by simp [mkPos, heP_x] have hmkPos_y : ∀ p, (mkPos p y).val = p.1.2.val + 1 := fun p => by simp [mkPos, heP_y] have hmkPos_inj : ∀ p, Function.Injective (mkPos p) := by intro p u v huv have hv := congrArg Fin.val huv have hij : p.1.1.val ≤ p.1.2.val := p.2.2.2.2.2 cases hu : eP u with | inl k₁ => have hu' := heP_inl hu; subst hu' cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst hv'' rw [hmkPos_c, hmkPos_c] at hv apply congrArg c; apply Fin.ext split_ifs at hv <;> omega | inr b => cases b · have hv'' := heP_false hv'; subst hv'' rw [hmkPos_c, hmkPos_x] at hv; split_ifs at hv <;> omega · have hv'' := heP_true hv'; subst hv'' rw [hmkPos_c, hmkPos_y] at hv; split_ifs at hv <;> omega | inr b₁ => cases b₁ · have hu' := heP_false hu; subst hu' cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst hv'' rw [hmkPos_x, hmkPos_c] at hv; split_ifs at hv <;> omega | inr b₂ => cases b₂ · exact (heP_false hv').symm · have hv'' := heP_true hv'; subst hv'' rw [hmkPos_x, hmkPos_y] at hv; omega · have hu' := heP_true hu; subst hu' cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst hv'' rw [hmkPos_y, hmkPos_c] at hv; split_ifs at hv <;> omega | inr b₂ => cases b₂ · have hv'' := heP_false hv'; subst hv'' rw [hmkPos_y, hmkPos_x] at hv; omega · exact (heP_true hv').symm let mkExt : ValidPair → LinExt P := fun p => ⟨Equiv.ofBijective (mkPos p) ((Fintype.bijective_iff_injective_and_card (mkPos p)).mpr ⟨hmkPos_inj p, (Fintype.card_fin _).symm⟩), fun u v huv => by change (mkPos p u).val ≤ (mkPos p v).val have hij : p.1.1.val ≤ p.1.2.val := p.2.2.2.2.2 cases hu : eP u with | inl k₁ => have hu' := heP_inl hu; subst hu' cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst hv'' have hle : k₁.val ≤ k₂.val := (hc k₁ k₂).mpr huv rw [hmkPos_c, hmkPos_c]; split_ifs <;> omega | inr b => cases b · have hv'' := heP_false hv'; subst v have hlt : c k₁ < x := lt_of_le_of_ne huv (fun h => hxC ⟨k₁, h⟩) have hk : k₁.val < a₁ := (ha₁_iff k₁).mp hlt have ha1 : a₁ ≤ p.1.1.val := p.2.1 rw [hmkPos_c, hmkPos_x]; split_ifs <;> omega · have hv'' := heP_true hv'; subst v have hlt : c k₁ < y := lt_of_le_of_ne huv (fun h => hyC ⟨k₁, h⟩) have hk : k₁.val < a₂ := (ha₂_iff k₁).mp hlt have ha2 : a₂ ≤ p.1.2.val := p.2.2.2.1 rw [hmkPos_c, hmkPos_y]; split_ifs <;> omega | inr b₁ => cases b₁ · have hu' := heP_false hu; subst u cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst v have hlt : x < c k₂ := lt_of_le_of_ne huv (fun h => hxC ⟨k₂, h.symm⟩) have hk : b₁ ≤ k₂.val := (hb₁_iff k₂).mp hlt have hb1 : p.1.1.val ≤ b₁ := p.2.2.1 rw [hmkPos_x, hmkPos_c]; split_ifs <;> omega | inr b₂ => cases b₂ · have hv'' := heP_false hv'; subst v; exact le_rfl · have hv'' := heP_true hv'; subst v rw [hmkPos_x, hmkPos_y]; omega · have hu' := heP_true hu; subst u cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst v have hlt : y < c k₂ := lt_of_le_of_ne huv (fun h => hyC ⟨k₂, h.symm⟩) have hk : b₂ ≤ k₂.val := (hb₂_iff k₂).mp hlt have hb2 : p.1.2.val ≤ b₂ := p.2.2.2.2.1 rw [hmkPos_y, hmkPos_c]; split_ifs <;> omega | inr b₂ => cases b₂ · have hv'' := heP_false hv'; subst v exact absurd huv (not_le_of_gt hxy) · have hv'' := heP_true hv'; subst v; exact le_rfl⟩ let toPair : LinExt P → ValidPair := fun e => let ix := (Finset.univ.filter (fun k : Fin m => e.1 (c k) < e.1 x)).card let iy := (Finset.univ.filter (fun k : Fin m => e.1 (c k) < e.1 y)).card ⟨(⟨ix, Nat.lt_succ_of_le ((Finset.card_le_univ _).trans (by rw [Fintype.card_fin]))⟩, ⟨iy, Nat.lt_succ_of_le ((Finset.card_le_univ _).trans (by rw [Fintype.card_fin]))⟩), by have hex_lt : e.1 x < e.1 y := lt_of_le_of_ne (e.2 _ _ (le_of_lt hxy)) (fun h => hne_xy (e.1.injective h)) have h1 : a₁ ≤ ix := Finset.card_le_card fun k hk => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_ne (e.2 _ _ (le_of_lt (Finset.mem_filter.mp hk).2)) (fun h => hxC ⟨k, e.1.injective h⟩)⟩ have h2 : ix ≤ b₁ := by have hdisj : Disjoint (Finset.univ.filter (fun k : Fin m => e.1 (c k) < e.1 x)) (Finset.univ.filter (fun k : Fin m => x < c k)) := Finset.disjoint_filter.mpr fun k _ hk1 hk2 => not_lt_of_ge (e.2 _ _ (le_of_lt hk2)) hk1 have hsum : ix + (Finset.univ.filter (fun k : Fin m => x < c k)).card ≤ m := by rw [← Finset.card_union_of_disjoint hdisj] exact (Finset.card_le_univ _).trans (by rw [Fintype.card_fin]) omega have h3 : a₂ ≤ iy := Finset.card_le_card fun k hk => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_ne (e.2 _ _ (le_of_lt (Finset.mem_filter.mp hk).2)) (fun h => hyC ⟨k, e.1.injective h⟩)⟩ have h4 : iy ≤ b₂ := by have hdisj : Disjoint (Finset.univ.filter (fun k : Fin m => e.1 (c k) < e.1 y)) (Finset.univ.filter (fun k : Fin m => y < c k)) := Finset.disjoint_filter.mpr fun k _ hk1 hk2 => not_lt_of_ge (e.2 _ _ (le_of_lt hk2)) hk1 have hsum : iy + (Finset.univ.filter (fun k : Fin m => y < c k)).card ≤ m := by rw [← Finset.card_union_of_disjoint hdisj] exact (Finset.card_le_univ _).trans (by rw [Fintype.card_fin]) omega have h5 : ix ≤ iy := Finset.card_le_card fun k hk => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hk).2.trans hex_lt⟩ exact ⟨h1, h2, h3, h4, h5⟩⟩ have htoPair_x_lt : ∀ (e : LinExt P) (k : Fin m), e.1 (c k) < e.1 x ↔ k.val < (toPair e).1.1.val := fun e k => by have h := downward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => e.1 (c j) < e.1 x)) (fun j₁ j₂ hj h2 => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_lt (e.2 _ _ ((hc j₁ j₂).mp hj)) (Finset.mem_filter.mp h2).2⟩) k simpa [toPair] using h have htoPair_y_lt : ∀ (e : LinExt P) (k : Fin m), e.1 (c k) < e.1 y ↔ k.val < (toPair e).1.2.val := fun e k => by have h := downward_filter_fin_iff (Finset.univ.filter (fun j : Fin m => e.1 (c j) < e.1 y)) (fun j₁ j₂ hj h2 => Finset.mem_filter.mpr ⟨Finset.mem_univ _, lt_of_le_of_lt (e.2 _ _ ((hc j₁ j₂).mp hj)) (Finset.mem_filter.mp h2).2⟩) k simpa [toPair] using h have htoPair_x_le : ∀ (e : LinExt P) (k : Fin m), e.1 x < e.1 (c k) ↔ (toPair e).1.1.val ≤ k.val := by intro e k have hne : e.1 x ≠ e.1 (c k) := fun h => hxC ⟨k, (e.1.injective h).symm⟩ constructor · intro hlt; by_contra hgt; push Not at hgt exact lt_asymm hlt ((htoPair_x_lt e k).mpr hgt) · intro hle have hnot : ¬ e.1 (c k) < e.1 x := fun h => not_lt_of_ge hle ((htoPair_x_lt e k).mp h) exact lt_of_le_of_ne (le_of_not_gt hnot) hne let ePair : LinExt P ≃ ValidPair := { toFun := toPair invFun := mkExt left_inv := fun e => by apply Subtype.ext; apply Equiv.ext; intro z have hex_lt : e.1 x < e.1 y := lt_of_le_of_ne (e.2 _ _ (le_of_lt hxy)) (fun h => hne_xy (e.1.injective h)) have hij : (toPair e).1.1.val ≤ (toPair e).1.2.val := (toPair e).2.2.2.2.2 have hcase_lt : ∀ u v : P, e.1 u < e.1 v → (mkExt (toPair e)).1 u < (mkExt (toPair e)).1 v := by intro u v huv change (mkPos (toPair e) u).val < (mkPos (toPair e) v).val cases hu : eP u with | inl k₁ => have hu' := heP_inl hu; subst hu' cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst hv'' have hk : k₁.val < k₂.val := by by_contra hge; push Not at hge exact not_lt_of_ge (e.2 _ _ ((hc k₂ k₁).mp hge)) huv rw [hmkPos_c, hmkPos_c]; split_ifs <;> omega | inr b => cases b · have hv'' := heP_false hv'; subst hv'' have hk := (htoPair_x_lt e k₁).mp huv rw [hmkPos_c, hmkPos_x]; split_ifs <;> omega · have hv'' := heP_true hv'; subst hv'' have hk := (htoPair_y_lt e k₁).mp huv rw [hmkPos_c, hmkPos_y]; split_ifs <;> omega | inr b₁ => cases b₁ · have hu' := heP_false hu; subst hu' cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst hv'' have hk := (htoPair_x_le e k₂).mp huv rw [hmkPos_x, hmkPos_c]; split_ifs <;> omega | inr b₂ => cases b₂ · have hv'' := heP_false hv'; subst hv''; exact absurd huv (lt_irrefl _) · have hv'' := heP_true hv'; subst hv'' rw [hmkPos_x, hmkPos_y]; omega · have hu' := heP_true hu; subst u cases hv' : eP v with | inl k₂ => have hv'' := heP_inl hv'; subst v have hnot : ¬ e.1 (c k₂) < e.1 y := lt_asymm huv have hk : (toPair e).1.2.val ≤ k₂.val := by by_contra hlt; push Not at hlt exact hnot ((htoPair_y_lt e k₂).mpr hlt) rw [hmkPos_y, hmkPos_c]; split_ifs <;> omega | inr b₂ => cases b₂ · have hv'' := heP_false hv'; subst v; exact absurd huv (lt_asymm hex_lt) · have hv'' := heP_true hv'; subst v; exact absurd huv (lt_irrefl _) have hord : ∀ u v : P, (mkExt (toPair e)).1 u < (mkExt (toPair e)).1 v ↔ e.1 u < e.1 v := by intro u v; constructor · intro hlt rcases lt_trichotomy (e.1 u) (e.1 v) with h | h | h · exact h · have heq := e.1.injective h; subst heq; exact absurd hlt (lt_irrefl _) · exact absurd hlt (lt_asymm (hcase_lt v u h)) · exact hcase_lt u v have hval_eq : ∀ (f : P ≃ Fin (Fintype.card P)) (u : P), (f u).val = (Finset.univ.filter (fun v : P => f v < f u)).card := by intro f u have hbij : (Finset.univ.filter (fun v : P => f v < f u)).card = (Finset.range (f u).val).card := Finset.card_bij (fun v _ => (f v).val) (fun v hv => Finset.mem_range.mpr (Finset.mem_filter.mp hv).2) (fun v₁ _ v₂ _ h => f.injective (Fin.ext h)) (fun t ht => ⟨f.symm ⟨t, (Finset.mem_range.mp ht).trans (f u).isLt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by change (f (f.symm ⟨t, _⟩)).val < (f u).val rw [Equiv.apply_symm_apply]; exact Finset.mem_range.mp ht⟩, by simp⟩) rw [hbij, Finset.card_range] apply Fin.ext rw [hval_eq (mkExt (toPair e)).1 z, hval_eq e.1 z] congr 1; ext v; simp only [Finset.mem_filter, Finset.mem_univ, true_and] exact hord v z right_inv := fun p => by have hij : p.1.1.val ≤ p.1.2.val := p.2.2.2.2.2 have hfx : (Finset.univ.filter (fun k : Fin m => (mkExt p).1 (c k) < (mkExt p).1 x)).card = p.1.1.val := by have hfilt : Finset.univ.filter (fun k : Fin m => (mkExt p).1 (c k) < (mkExt p).1 x) = Finset.univ.filter (fun k : Fin m => k.val < p.1.1.val) := by ext k; simp only [Finset.mem_filter, Finset.mem_univ, true_and] change (mkPos p (c k)).val < (mkPos p x).val ↔ k.val < p.1.1.val rw [hmkPos_c, hmkPos_x]; split_ifs <;> omega rw [hfilt] have hbij : (Finset.univ.filter (fun k : Fin m => k.val < p.1.1.val)).card = (Finset.range p.1.1.val).card := Finset.card_bij (fun k _ => k.val) (fun k hk => Finset.mem_range.mpr (Finset.mem_filter.mp hk).2) (fun _ _ _ _ h => Fin.ext h) (fun t ht => ⟨⟨t, lt_of_lt_of_le (Finset.mem_range.mp ht) (p.2.2.1.trans hb₁_le_m)⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_range.mp ht⟩, rfl⟩) rw [hbij, Finset.card_range] have hfy : (Finset.univ.filter (fun k : Fin m => (mkExt p).1 (c k) < (mkExt p).1 y)).card = p.1.2.val := by have hfilt : Finset.univ.filter (fun k : Fin m => (mkExt p).1 (c k) < (mkExt p).1 y) = Finset.univ.filter (fun k : Fin m => k.val < p.1.2.val) := by ext k; simp only [Finset.mem_filter, Finset.mem_univ, true_and] change (mkPos p (c k)).val < (mkPos p y).val ↔ k.val < p.1.2.val rw [hmkPos_c, hmkPos_y]; split_ifs <;> omega rw [hfilt] have hbij : (Finset.univ.filter (fun k : Fin m => k.val < p.1.2.val)).card = (Finset.range p.1.2.val).card := Finset.card_bij (fun k _ => k.val) (fun k hk => Finset.mem_range.mpr (Finset.mem_filter.mp hk).2) (fun _ _ _ _ h => Fin.ext h) (fun t ht => ⟨⟨t, lt_of_lt_of_le (Finset.mem_range.mp ht) (p.2.2.2.2.1.trans hb₂_le_m)⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.mem_range.mp ht⟩, rfl⟩) rw [hbij, Finset.card_range] apply Subtype.ext; apply Prod.ext <;> apply Fin.ext · exact hfx · exact hfy } -- Marginal weights w(i) = |{ p : ValidPair // p.1.1 = i }| let w : Fin (m + 1) → ℕ := fun i => (Finset.univ.filter (fun p : ValidPair => p.1.1 = i)).card have hT_eq : totalLinExt P = ∑ i : Fin (m + 1), w i := by have h1 : totalLinExt P = Fintype.card (LinExt P) := by unfold totalLinExt; convert rfl rw [h1, Fintype.card_congr ePair] have hfib := Finset.card_eq_sum_card_fiberwise (f := fun p : ValidPair => p.1.1) (s := Finset.univ) (t := Finset.univ) (fun _ _ => Finset.mem_univ _) simpa [w, Finset.card_univ] using hfib have hC_eq : ∀ k : Fin m, countBefore x (c k) = ∑ i ∈ Finset.univ.filter (fun i : Fin (m + 1) => i.val ≤ k.val), w i := by intro k have h1 : countBefore x (c k) = Fintype.card { e : LinExt P // e.1 x < e.1 (c k) } := by unfold countBefore; convert rfl rw [h1] have heSub : { e : LinExt P // e.1 x < e.1 (c k) } ≃ { p : ValidPair // p.1.1.val ≤ k.val } := { toFun := fun e => ⟨ePair e.1, (htoPair_x_le e.1 k).mp e.2⟩ invFun := fun p => ⟨ePair.symm p.1, by rw [htoPair_x_le]; change (ePair (ePair.symm p.1)).1.1.val ≤ k.val; rw [ePair.apply_symm_apply]; exact p.2⟩ left_inv := fun e => Subtype.ext (ePair.left_inv e.1) right_inv := fun p => Subtype.ext (ePair.right_inv p.1) } rw [Fintype.card_congr heSub, Fintype.card_subtype] have hfib := Finset.card_eq_sum_card_fiberwise (f := fun p : ValidPair => p.1.1) (s := Finset.univ.filter (fun p : ValidPair => p.1.1.val ≤ k.val)) (t := Finset.univ.filter (fun i : Fin (m + 1) => i.val ≤ k.val)) (fun p hp => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hp).2⟩) rw [hfib] refine Finset.sum_congr rfl fun i hi => ?_ have hik : i.val ≤ k.val := (Finset.mem_filter.mp hi).2 congr 1; ext p simp only [Finset.mem_filter, Finset.mem_univ, true_and] constructor · rintro ⟨_, h⟩; exact h · intro h; exact ⟨h ▸ hik, h⟩ -- Exact formula for w i: have hw_val : ∀ i : Fin (m + 1), w i = if a₁ ≤ i.val ∧ i.val ≤ b₁ then b₂ + 1 - max a₂ i.val else 0 := by intro i by_cases hi : a₁ ≤ i.val ∧ i.val ≤ b₁ · rw [if_pos hi] unfold w have hbij : (Finset.univ.filter (fun p : ValidPair => p.1.1 = i)).card = (Finset.Ico (max a₂ i.val) (b₂ + 1)).card := by refine Finset.card_bij (fun p _ => p.1.2.val) ?_ ?_ ?_ · intro p hp have hpi : p.1.1 = i := (Finset.mem_filter.mp hp).2 have hp2 := p.2 rw [hpi] at hp2 exact Finset.mem_Ico.mpr ⟨max_le hp2.2.2.1 hp2.2.2.2.2, Nat.lt_succ_of_le hp2.2.2.2.1⟩ · intro p₁ hp₁ p₂ hp₂ h apply Subtype.ext; apply Prod.ext · rw [(Finset.mem_filter.mp hp₁).2, (Finset.mem_filter.mp hp₂).2] · exact Fin.ext h · intro t ht rcases Finset.mem_Ico.mp ht with ⟨ht1, ht2⟩ have hle_b2 : t ≤ b₂ := Nat.lt_succ_iff.mp ht2 let p : ValidPair := ⟨(i, ⟨t, by omega⟩), ⟨hi.1, hi.2, le_of_max_le_left ht1, hle_b2, le_of_max_le_right ht1⟩⟩ exact ⟨p, Finset.mem_filter.mpr ⟨Finset.mem_univ _, rfl⟩, rfl⟩ rw [hbij, Nat.card_Ico] · rw [if_neg hi] unfold w rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff] intro p _ hpi have hp2 := p.2 rw [hpi] at hp2 exact hi ⟨hp2.1, hp2.2.1⟩ -- 6-line arithmetic finale! let i₁ : Fin (m + 1) := ⟨a₁, by omega⟩ let i₂ : Fin (m + 1) := ⟨a₁ + 1, by omega⟩ have hi₁_val : w i₁ = b₂ + 1 - a₂ := by rw [hw_val i₁, if_pos ⟨le_rfl, ha₁_le_b₁⟩] change b₂ + 1 - max a₂ a₁ = b₂ + 1 - a₂ rw [max_eq_left ha₁_le_a₂] have hi₂_ge : b₂ - a₂ ≤ w i₂ := by rw [hw_val i₂, if_pos ⟨by dsimp [i₂]; omega, by dsimp [i₂]; omega⟩] change b₂ - a₂ ≤ b₂ + 1 - max a₂ (a₁ + 1) omega have hw_le : ∀ i : Fin (m + 1), w i ≤ w i₁ := by intro i rw [hw_val i, hi₁_val] split_ifs <;> omega have hsum_ge : w i₁ + w i₂ ≤ ∑ i : Fin (m + 1), w i := by have hne : i₁ ≠ i₂ := by intro h; have := congrArg Fin.val h; dsimp [i₁, i₂] at this; omega have hsub : ({i₁, i₂} : Finset (Fin (m + 1))) ⊆ Finset.univ := Finset.subset_univ _ have h := Finset.sum_le_sum_of_subset (f := w) hsub rw [Finset.sum_pair hne] at h exact h have hL2_pos : 1 ≤ w i₁ := by rw [hi₁_val]; omega have hT_pos : 0 < totalLinExt P := by rw [hT_eq]; omega have h3L2_le_2T : 3 * w i₁ ≤ 2 * ∑ i : Fin (m + 1), w i := by by_cases heq : a₁ = a₂ · -- L₂ = b₂ + 1 - a₁ ≥ 2 since a₁ < b₁ ≤ b₂! have hge2 : 2 ≤ w i₁ := by rw [hi₁_val]; omega omega · -- a₁ < a₂ → a₁ + 1 ≤ a₂ → w i₂ = w i₁! have hi₂_eq : w i₂ = w i₁ := by rw [hw_val i₂, if_pos ⟨by dsimp [i₂]; omega, by dsimp [i₂]; omega⟩, hi₁_val] change b₂ + 1 - max a₂ (a₁ + 1) = b₂ + 1 - a₂ rw [max_eq_left (by omega)] omega by_cases hbig : ∑ i : Fin (m + 1), w i ≤ 3 * w i₁ · -- (x, c a₁) is immediately 1/3-balanced! let k₀ : Fin m := ⟨a₁, by omega⟩ have hfilt : ∑ i ∈ Finset.univ.filter (fun i : Fin (m + 1) => i.val ≤ k₀.val), w i = w i₁ := by have hsub : Finset.univ.filter (fun i : Fin (m + 1) => i.val ≤ k₀.val) = insert i₁ (Finset.univ.filter (fun i : Fin (m + 1) => i.val < a₁)) := by ext i; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert, Fin.ext_iff, k₀, i₁]; omega rw [hsub, Finset.sum_insert (by simp [i₁])] have hzero : ∑ i ∈ Finset.univ.filter (fun i : Fin (m + 1) => i.val < a₁), w i = 0 := by apply Finset.sum_eq_zero; intro i hi rw [hw_val i, if_neg (by have := (Finset.mem_filter.mp hi).2; omega)] omega refine ⟨x, c k₀, hT_pos, ?_, ?_⟩ · rw [hT_eq, hC_eq k₀, hfilt]; exact hbig · rw [hT_eq, hC_eq k₀, hfilt]; exact h3L2_le_2T · -- Every step 3 * w i ≤ T → apply exists_balanced_prefix! have hstep : ∀ i : Fin (m + 1), 3 * w i ≤ ∑ j : Fin (m + 1), w j := fun i => (Nat.mul_le_mul_left 3 (hw_le i)).trans (by omega) rcases exists_balanced_prefix w (by rw [← hT_eq]; exact hT_pos) hstep with ⟨k, hk1, hk2⟩ refine ⟨x, c k, hT_pos, ?_, ?_⟩ · rw [hT_eq, hC_eq k]; exact hk1 · rw [hT_eq, hC_eq k]; exact hk2 /-- **Theorem C (Exact 1/3–2/3 Conjecture for ALL Co-Height ≤ 2 Posets)**: Every finite non-total poset `P` containing a chain of size `|P| - 2` (arbitrary width 2 or 3, arbitrary height, arbitrary relations among the two off-chain elements) contains a `1/3`-balanced pair. -/ theorem one_third_two_thirds_coheight_le_two {P : Type*} [PartialOrder P] [Fintype P] (hcoh : HasCoheightLeTwo P) (hnt : ¬ ∀ x y : P, x ≤ y ∨ y ≤ x) : ∃ x y : P, IsBalancedPair x y := by classical rcases hcoh with ⟨Cset, hchain, hcard⟩ let C : Finset P := Cset.toFinset let A : Finset P := Finset.univ \ C have hA_coe : (A : Set P) = Csetᶜ := by ext z; simp [A, C] have hle2 : A.card ≤ 2 := by have hnc : (A : Set P).ncard = A.card := Set.ncard_coe_finset A rw [hA_coe] at hnc omega by_cases hA1 : A.card ≤ 1 · -- Complement has size ≤ 1, hence is trivially an antichain → Split Poset! have hsplit : IsSplitPoset P := by refine ⟨(C : Set P), (A : Set P), ?_, ?_, ?_, ?_⟩ · ext z; simp only [Set.mem_union, Finset.mem_coe, Set.mem_univ, iff_true, A, Finset.mem_sdiff, Finset.mem_univ, true_and]; tauto · rw [Finset.disjoint_coe]; exact Finset.disjoint_sdiff · intro x hx y hy exact hchain x (Set.mem_toFinset.mp hx) y (Set.mem_toFinset.mp hy) · intro x hx y hy _ exact Finset.card_le_one.mp hA1 x hx y hy exact one_third_two_thirds_split_poset hsplit hnt · -- Complement has exact size 2: A = {x, y} with x ≠ y have hA2 : A.card = 2 := by omega rcases Finset.card_eq_two.mp hA2 with ⟨x, y, hxy, hAeq⟩ by_cases hcomp : x ≤ y ∨ y ≤ x · -- Comparable off-chain pair → use chain_plus_two_chain_balanced! let m := Fintype.card { z : P // z ∈ C } rcases linearOrderEquivFin { z : P // z ∈ C } (fun u v => hchain u.1 (Set.mem_toFinset.mp u.2) v.1 (Set.mem_toFinset.mp v.2)) with ⟨eC, heC⟩ let c : Fin m → P := fun i => (eC.symm i).1 have hc : ∀ i j : Fin m, i ≤ j ↔ c i ≤ c j := fun i j => by have h := heC (eC.symm i) (eC.symm j) rw [eC.apply_symm_apply, eC.apply_symm_apply] at h exact h.symm have hrange : Set.range c = (C : Set P) := by ext z; simp only [Set.mem_range, Finset.mem_coe]; constructor · rintro ⟨i, rfl⟩; exact (eC.symm i).2 · intro hz refine ⟨eC ⟨z, hz⟩, ?_⟩ simp [c] have hxC : x ∉ Set.range c := by rw [hrange]; intro hx have hmem : x ∈ A := hAeq ▸ Finset.mem_insert_self x {y} exact (Finset.mem_sdiff.mp hmem).2 hx have hyC : y ∉ Set.range c := by rw [hrange]; intro hy have hmem : y ∈ A := hAeq ▸ Finset.mem_insert_of_mem (Finset.mem_singleton_self y) exact (Finset.mem_sdiff.mp hmem).2 hy have hcover : ∀ z : P, z ∈ Set.range c ∨ z = x ∨ z = y := by intro z by_cases hz : z ∈ C · exact Or.inl (hrange.symm ▸ hz) · have hmem : z ∈ A := Finset.mem_sdiff.mpr ⟨Finset.mem_univ _, hz⟩ rw [hAeq, Finset.mem_insert, Finset.mem_singleton] at hmem exact Or.inr hmem rcases hcomp with hle | hle · exact chain_plus_two_chain_balanced c hc x y hxC hyC (lt_of_le_of_ne hle hxy) hcover hnt · exact chain_plus_two_chain_balanced c hc y x hyC hxC (lt_of_le_of_ne hle hxy.symm) (fun z => by rcases hcover z with h | h | h; exact Or.inl h; exact Or.inr (Or.inr h); exact Or.inr (Or.inl h)) hnt · -- Incomparable off-chain pair → A = {x, y} is an antichain → Split Poset! push Not at hcomp have hsplit : IsSplitPoset P := by refine ⟨(C : Set P), (A : Set P), ?_, ?_, ?_, ?_⟩ · ext z; simp only [Set.mem_union, Finset.mem_coe, Set.mem_univ, iff_true, A, Finset.mem_sdiff, Finset.mem_univ, true_and]; tauto · rw [Finset.disjoint_coe]; exact Finset.disjoint_sdiff · intro u hu v hv exact hchain u (Set.mem_toFinset.mp hu) v (Set.mem_toFinset.mp hv) · intro u hu v hv huv rw [Finset.mem_coe, hAeq, Finset.mem_insert, Finset.mem_singleton] at hu hv rcases hu with rfl | rfl <;> rcases hv with rfl | rfl · rfl · exact absurd huv hcomp.1 · exact absurd huv hcomp.2 · rfl exact one_third_two_thirds_split_poset hsplit hnt /-- **Theorem C (`FormalConjectures` Interface)**: Exact `FormalConjectures`-format theorem for every finite non-total co-height ≤ 2 poset. -/ theorem formalConjectures_coheight_le_two (P : Type*) [Finite P] [PartialOrder P] (hcoh : HasCoheightLeTwo P) (not_total : ¬ Std.Total (α := P) (· ≤ ·)) (total_ext : Set (P →o ℕ)) (total_ext_def : ∀ σ, σ ∈ total_ext ↔ Set.range σ = Set.Icc 1 (Nat.card P)) : ∃ x y : P, (({σ ∈ total_ext | σ x < σ y}.ncard : ℚ) / (total_ext.ncard : ℚ)) ∈ Set.Icc (1 / 3 : ℚ) (2 / 3 : ℚ) := by let _ : Fintype P := Fintype.ofFinite P have hnt : ¬ ∀ x y : P, x ≤ y ∨ y ≤ x := fun h => not_total ⟨h⟩ rcases one_third_two_thirds_coheight_le_two hcoh hnt with ⟨x, y, hbal⟩ exact ⟨x, y, formalConjectures_of_isBalancedPair P total_ext total_ext_def hbal⟩ /-! ## Section 8: Theorem E — Exact Sharpness (`2 + 1`) and Width-3 Non-`N`-Free Witness (`P₅`) -/ /-- The 3-element split poset `2 + 1`: chain `0 < 1` plus isolated element `2`. -/ inductive TwoPlusOne : Type | c0 | c1 | a deriving DecidableEq instance : Fintype TwoPlusOne where elems := {.c0, .c1, .a} complete x := by cases x <;> simp instance : PartialOrder TwoPlusOne where le x y := x = y ∨ (x = .c0 ∧ y = .c1) le_refl x := Or.inl rfl le_trans x y z h1 h2 := by cases x <;> cases y <;> cases z <;> simp_all le_antisymm x y h1 h2 := by cases x <;> cases y <;> simp_all instance : DecidableRel (· ≤ · : TwoPlusOne → TwoPlusOne → Prop) := fun x y => by change Decidable (x = y ∨ (x = .c0 ∧ y = .c1)) infer_instance instance : DecidableRel (· < · : TwoPlusOne → TwoPlusOne → Prop) := fun x y => by change Decidable (x ≤ y ∧ ¬ y ≤ x) infer_instance /-- **Theorem E.1 (Sharpness Witness `2 + 1`)**: The 3-element poset `2 + 1` is a non-total split poset with `totalLinExt (2 + 1) = 3` and exact balance constant `1/3` (every incomparable pair splits `1:2` or `2:1`). -/ theorem two_plus_one_sharp : IsSplitPoset TwoPlusOne ∧ (¬ ∀ x y : TwoPlusOne, x ≤ y ∨ y ≤ x) ∧ totalLinExt TwoPlusOne = 3 ∧ countBefore TwoPlusOne.a TwoPlusOne.c0 = 1 ∧ countBefore TwoPlusOne.a TwoPlusOne.c1 = 2 ∧ ∀ x y : TwoPlusOne, ¬ (x ≤ y) → ¬ (y ≤ x) → min (countBefore x y) (countBefore y x) = 1 := by let c : Fin 2 → TwoPlusOne := ![.c0, .c1] have hc : ∀ i j : Fin 2, i ≤ j ↔ c i ≤ c j := by decide have hanti : ∀ x y : { x : TwoPlusOne // x ∉ Set.range c }, x.1 ≤ y.1 → x = y := by rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy have hx' : x = .a := by cases x · exact absurd ⟨0, rfl⟩ hx · exact absurd ⟨1, rfl⟩ hx · rfl have hy' : y = .a := by cases y · exact absurd ⟨0, rfl⟩ hy · exact absurd ⟨1, rfl⟩ hy · rfl subst hx'; subst hy'; rfl have hsplit : IsSplitPoset TwoPlusOne := by refine ⟨{.c0, .c1}, {.a}, ?_, ?_, ?_, ?_⟩ · ext x; cases x <;> simp · rw [Set.disjoint_singleton_right]; simp · rintro x (rfl | rfl) y (rfl | rfl) <;> decide · rintro x rfl y rfl _; rfl have hnt : ¬ ∀ x y : TwoPlusOne, x ≤ y ∨ y ≤ x := by intro h; rcases h .c0 .a with h1 | h1 <;> cases h1 <;> simp_all have ⟨hT, hAC, _⟩ := splitPoset_counts c hc hanti have ha_mem : TwoPlusOne.a ∉ Set.range c := by rintro ⟨i, hi⟩; fin_cases i <;> simp [c] at hi let aSub : { x : TwoPlusOne // x ∉ Set.range c } := ⟨.a, ha_mem⟩ -- Evaluate totalWeight and marginal weights directly! let I := splitIntervalsOfChain c hc hanti have hIa_l : I.l aSub = 0 := by dsimp only [I, splitIntervalsOfChain, aSub] suffices h0 : (Finset.univ.filter (fun i : Fin 2 => c i < TwoPlusOne.a)).card = 0 by convert h0 rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff] intro i _; fin_cases i <;> decide have hIa_r : I.r aSub = 2 := by dsimp only [I, splitIntervalsOfChain, aSub] suffices h0 : (Finset.univ.filter (fun i : Fin 2 => TwoPlusOne.a < c i)).card = 0 by convert congrArg (2 - ·) h0 rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff] intro i _; fin_cases i <;> decide have hsubA : ∀ x : { x : TwoPlusOne // x ∉ Set.range c }, x = aSub := by rintro ⟨x, hx⟩; apply Subtype.ext; cases x · exact absurd ⟨0, rfl⟩ hx · exact absurd ⟨1, rfl⟩ hx · rfl let eSlot : ValidSlot I ≃ Fin 3 := { toFun := fun s => s.1 aSub invFun := fun j => ⟨fun _ => j, fun x => by rw [hsubA x, hIa_l, hIa_r]; exact ⟨Nat.zero_le _, Nat.lt_succ_iff.mp j.isLt⟩⟩ left_inv := fun s => by apply Subtype.ext; funext x; rw [hsubA x] right_inv := fun j => rfl } have hw1 : ∀ s : ValidSlot I, slotWeight s.1 = 1 := by intro s; unfold slotWeight refine Finset.prod_eq_one fun j _ => ?_ unfold slotCount have hle : (Finset.univ.filter (fun x : { x : TwoPlusOne // x ∉ Set.range c } => s.1 x = j)).card ≤ 1 := Finset.card_le_one.mpr fun x _ y _ => by rw [hsubA x, hsubA y] interval_cases (Finset.univ.filter (fun x : { x : TwoPlusOne // x ∉ Set.range c } => s.1 x = j)).card <;> rfl have hT3 : totalLinExt TwoPlusOne = 3 := by rw [hT]; unfold totalWeight rw [Finset.sum_congr rfl fun s _ => hw1 s, Finset.sum_const, Finset.card_univ, smul_eq_mul, mul_one, Fintype.card_congr eSlot, Fintype.card_fin] have hCa0 : countBefore TwoPlusOne.a TwoPlusOne.c0 = 1 := by change countBefore aSub.1 (c 0) = 1 rw [hAC aSub 0, Finset.sum_congr rfl fun s _ => hw1 s, Finset.sum_const, smul_eq_mul, mul_one] simp only [Fin.val_zero] have hbij : (Finset.univ.filter (fun s : ValidSlot I => (s.1 aSub).val ≤ 0)).card = (Finset.univ.filter (fun j : Fin 3 => j.val ≤ 0)).card := Finset.card_bij (fun s _ => eSlot s) (fun s hs => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hs).2⟩) (fun _ _ _ _ h => eSlot.injective h) (fun j hj => ⟨eSlot.symm j, Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hj).2⟩, eSlot.apply_symm_apply j⟩) rw [hbij]; decide have hCa1 : countBefore TwoPlusOne.a TwoPlusOne.c1 = 2 := by change countBefore aSub.1 (c 1) = 2 rw [hAC aSub 1, Finset.sum_congr rfl fun s _ => hw1 s, Finset.sum_const, smul_eq_mul, mul_one] simp only [Fin.val_one] have hbij : (Finset.univ.filter (fun s : ValidSlot I => (s.1 aSub).val ≤ 1)).card = (Finset.univ.filter (fun j : Fin 3 => j.val ≤ 1)).card := Finset.card_bij (fun s _ => eSlot s) (fun s hs => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hs).2⟩) (fun _ _ _ _ h => eSlot.injective h) (fun j hj => ⟨eSlot.symm j, Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hj).2⟩, eSlot.apply_symm_apply j⟩) rw [hbij]; decide have hsum_pair : ∀ x y : TwoPlusOne, x ≠ y → countBefore x y + countBefore y x = 3 := by intro x y hxy classical have h1 : countBefore x y = Fintype.card { e : LinExt TwoPlusOne // e.1 x < e.1 y } := by unfold countBefore; convert rfl have h2 : countBefore y x = Fintype.card { e : LinExt TwoPlusOne // e.1 y < e.1 x } := by unfold countBefore; convert rfl have h3 : totalLinExt TwoPlusOne = Fintype.card (LinExt TwoPlusOne) := by unfold totalLinExt; convert rfl rw [h1, h2, ← hT3, h3] have hcompl : Fintype.card { e : LinExt TwoPlusOne // e.1 x < e.1 y } + Fintype.card { e : LinExt TwoPlusOne // ¬ e.1 x < e.1 y } = Fintype.card (LinExt TwoPlusOne) := by rw [Fintype.card_subtype_compl] exact Nat.add_sub_cancel' (Fintype.card_subtype_le _) have heq : Fintype.card { e : LinExt TwoPlusOne // ¬ e.1 x < e.1 y } = Fintype.card { e : LinExt TwoPlusOne // e.1 y < e.1 x } := by refine Fintype.card_congr (Equiv.subtypeEquivRight fun e => ?_) constructor · intro hnot have hne : e.1 x ≠ e.1 y := fun h => hxy (e.1.injective h) exact lt_of_le_of_ne (le_of_not_gt hnot) hne.symm · intro hlt; exact not_lt_of_gt hlt rw [← heq]; exact hcompl refine ⟨hsplit, hnt, hT3, hCa0, hCa1, ?_⟩ intro x y h1 h2 cases x <;> cases y · exact absurd le_rfl h1 · exact absurd (Or.inr ⟨rfl, rfl⟩) h1 · have := hsum_pair .a .c0 (by decide); omega · exact absurd (Or.inr ⟨rfl, rfl⟩) h2 · exact absurd le_rfl h1 · have := hsum_pair .a .c1 (by decide); omega · have := hsum_pair .a .c0 (by decide); omega · have := hsum_pair .a .c1 (by decide); omega · exact absurd le_rfl h1 /-- The 5-element width-3, height-3, non-`N`-free split poset `P₅`: chain `c0 < c1 < c2`, antichain `{a0, a1}` with `a0 < c2` and `c0 < a1`. -/ inductive WitnessP5 : Type | c0 | c1 | c2 | a0 | a1 deriving DecidableEq instance : Fintype WitnessP5 where elems := {.c0, .c1, .c2, .a0, .a1} complete x := by cases x <;> simp instance : PartialOrder WitnessP5 where le x y := x = y ∨ (x = .c0 ∧ (y = .c1 ∨ y = .c2 ∨ y = .a1)) ∨ (x = .c1 ∧ y = .c2) ∨ (x = .a0 ∧ y = .c2) le_refl x := Or.inl rfl le_trans x y z h1 h2 := by cases x <;> cases y <;> cases z <;> simp_all le_antisymm x y h1 h2 := by cases x <;> cases y <;> simp_all instance : DecidableRel (· ≤ · : WitnessP5 → WitnessP5 → Prop) := fun x y => by change Decidable (x = y ∨ (x = .c0 ∧ (y = .c1 ∨ y = .c2 ∨ y = .a1)) ∨ (x = .c1 ∧ y = .c2) ∨ (x = .a0 ∧ y = .c2)) infer_instance instance : DecidableRel (· < · : WitnessP5 → WitnessP5 → Prop) := fun x y => by change Decidable (x ≤ y ∧ ¬ y ≤ x) infer_instance /-- **Theorem E.2 (Width-3, Height-3, Non-`N`-Free Split Witness `P₅`)**: `P₅` is a split poset outside all classical width-2, height-2, and `N`-free families (it contains a 3-antichain `{c1, a0, a1}`, a 3-chain `c0 < c1 < c2`, and an induced `N` on `{c0, c2, a0, a1}`), with exact linear extension count `e(P₅) = 11` and exact optimal balance `4/11` attained by `(a0, c1)` and `(c1, a1)`! -/ theorem witness_P5_balance : IsSplitPoset WitnessP5 ∧ -- Width ≥ 3: {c1, a0, a1} is a 3-element antichain (¬ (WitnessP5.c1 ≤ .a0) ∧ ¬ (WitnessP5.a0 ≤ .c1) ∧ ¬ (WitnessP5.c1 ≤ .a1) ∧ ¬ (WitnessP5.a1 ≤ .c1) ∧ ¬ (WitnessP5.a0 ≤ .a1) ∧ ¬ (WitnessP5.a1 ≤ .a0)) ∧ -- Height ≥ 3: c0 < c1 < c2 (WitnessP5.c0 < .c1 ∧ WitnessP5.c1 < .c2) ∧ -- Induced N on {c0, c2, a0, a1}: c0 < c2, c0 < a1, a0 < c2, and no other comparabilities (WitnessP5.c0 < .c2 ∧ WitnessP5.c0 < .a1 ∧ WitnessP5.a0 < .c2 ∧ ¬ (WitnessP5.c0 ≤ .a0) ∧ ¬ (WitnessP5.a0 ≤ .c0) ∧ ¬ (WitnessP5.a1 ≤ .c2) ∧ ¬ (WitnessP5.c2 ≤ .a1) ∧ ¬ (WitnessP5.a0 ≤ .a1) ∧ ¬ (WitnessP5.a1 ≤ .a0)) ∧ -- Exact linear extension count and balanced pair count: 4/11 totalLinExt WitnessP5 = 11 ∧ countBefore WitnessP5.a0 WitnessP5.c1 = 7 ∧ countBefore WitnessP5.c1 WitnessP5.a0 = 4 ∧ IsBalancedPair WitnessP5.c1 WitnessP5.a0 := by let c : Fin 3 → WitnessP5 := ![.c0, .c1, .c2] have hc : ∀ i j : Fin 3, i ≤ j ↔ c i ≤ c j := by decide have ha0_mem : WitnessP5.a0 ∉ Set.range c := by rintro ⟨i, hi⟩; fin_cases i <;> simp [c] at hi have ha1_mem : WitnessP5.a1 ∉ Set.range c := by rintro ⟨i, hi⟩; fin_cases i <;> simp [c] at hi let a0Sub : { x : WitnessP5 // x ∉ Set.range c } := ⟨.a0, ha0_mem⟩ let a1Sub : { x : WitnessP5 // x ∉ Set.range c } := ⟨.a1, ha1_mem⟩ have hmemA : ∀ x : { x : WitnessP5 // x ∉ Set.range c }, x = a0Sub ∨ x = a1Sub := by rintro ⟨x, hx⟩ cases x · exact absurd ⟨0, rfl⟩ hx · exact absurd ⟨1, rfl⟩ hx · exact absurd ⟨2, rfl⟩ hx · exact Or.inl rfl · exact Or.inr rfl have hanti : ∀ x y : { x : WitnessP5 // x ∉ Set.range c }, x.1 ≤ y.1 → x = y := by intro x y hxy rcases hmemA x with rfl | rfl <;> rcases hmemA y with rfl | rfl · rfl · have hnot : ¬ (WitnessP5.a0 ≤ .a1) := by decide exact absurd hxy hnot · have hnot : ¬ (WitnessP5.a1 ≤ .a0) := by decide exact absurd hxy hnot · rfl have hsplit : IsSplitPoset WitnessP5 := by refine ⟨{.c0, .c1, .c2}, {.a0, .a1}, ?_, ?_, ?_, ?_⟩ · ext x; cases x <;> simp · rw [Set.disjoint_left]; rintro x (rfl | rfl | rfl) <;> simp · rintro x (rfl | rfl | rfl) y (rfl | rfl | rfl) <;> decide · rintro x (rfl | rfl) y (rfl | rfl) h <;> first | rfl | exact absurd h (by decide) have ⟨hT, hAC, _⟩ := splitPoset_counts c hc hanti let I := splitIntervalsOfChain c hc hanti have hl0 : I.l a0Sub = 0 := by dsimp only [I, splitIntervalsOfChain, a0Sub] suffices h0 : (Finset.univ.filter (fun i : Fin 3 => c i < WitnessP5.a0)).card = 0 by convert h0 rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff]; intro i _; fin_cases i <;> decide have hr0 : I.r a0Sub = 2 := by dsimp only [I, splitIntervalsOfChain, a0Sub] suffices h1 : (Finset.univ.filter (fun i : Fin 3 => WitnessP5.a0 < c i)).card = 1 by convert congrArg (3 - ·) h1 have hfilt : Finset.univ.filter (fun i : Fin 3 => WitnessP5.a0 < c i) = {2} := by ext i; fin_cases i <;> decide rw [hfilt, Finset.card_singleton] have hl1 : I.l a1Sub = 1 := by dsimp only [I, splitIntervalsOfChain, a1Sub] suffices h1 : (Finset.univ.filter (fun i : Fin 3 => c i < WitnessP5.a1)).card = 1 by convert h1 have hfilt : Finset.univ.filter (fun i : Fin 3 => c i < WitnessP5.a1) = {0} := by ext i; fin_cases i <;> decide rw [hfilt, Finset.card_singleton] have hr1 : I.r a1Sub = 3 := by dsimp only [I, splitIntervalsOfChain, a1Sub] suffices h0 : (Finset.univ.filter (fun i : Fin 3 => WitnessP5.a1 < c i)).card = 0 by convert congrArg (3 - ·) h0 rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff]; intro i _; fin_cases i <;> decide have hne10 : a1Sub ≠ a0Sub := fun h => by have := congrArg Subtype.val h; cases this have hne01 : a0Sub ≠ a1Sub := hne10.symm -- Bijection ValidSlot I ≃ Fin 3 × Fin 3 (a0 ∈ {0, 1, 2}, a1 ∈ {1, 2, 3}) let eSlot : ValidSlot I ≃ Fin 3 × Fin 3 := { toFun := fun s => (⟨(s.1 a0Sub).val, by have := (s.2 a0Sub).2; omega⟩, ⟨(s.1 a1Sub).val - 1, by have := (s.2 a1Sub).1; have := (s.2 a1Sub).2; omega⟩) invFun := fun p => ⟨fun x => if x = a0Sub then ⟨p.1.val, by omega⟩ else ⟨p.2.val + 1, by omega⟩, fun x => by rcases hmemA x with rfl | rfl · simp only [↓reduceIte, hl0, hr0]; omega · simp only [hne10, ↓reduceIte, hl1, hr1]; omega⟩ left_inv := fun s => by apply Subtype.ext; funext x rcases hmemA x with rfl | rfl · simp · have hge : 1 ≤ (s.1 a1Sub).val := by have := (s.2 a1Sub).1; rw [hl1] at this; exact this simp only [hne10, ↓reduceIte] apply Fin.ext; dsimp; omega right_inv := fun ⟨p1, p2⟩ => by apply Prod.ext <;> apply Fin.ext <;> simp [hne10] } -- Weight of each (p1, p2) ∈ Fin 3 × Fin 3 is (if p1.val = p2.val + 1 then 2 else 1) have hw_pair : ∀ s : ValidSlot I, slotWeight s.1 = if (eSlot s).1.val = (eSlot s).2.val + 1 then 2 else 1 := by intro s have hge1 : 1 ≤ (s.1 a1Sub).val := by have := (s.2 a1Sub).1; rw [hl1] at this; exact this have hiff : (eSlot s).1.val = (eSlot s).2.val + 1 ↔ s.1 a0Sub = s.1 a1Sub := by simp only [eSlot, Equiv.coe_fn_mk, Fin.ext_iff]; omega by_cases heq : s.1 a0Sub = s.1 a1Sub · rw [if_pos (hiff.mpr heq)] unfold slotWeight rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ (s.1 a0Sub))] have hc0 : slotCount s.1 (s.1 a0Sub) = 2 := by unfold slotCount have hfilt : Finset.univ.filter (fun x : { x : WitnessP5 // x ∉ Set.range c } => s.1 x = s.1 a0Sub) = {a0Sub, a1Sub} := by ext x; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert, Finset.mem_singleton] rcases hmemA x with rfl | rfl · exact iff_of_true rfl (Or.inl rfl) · exact iff_of_true heq.symm (Or.inr rfl) rw [hfilt, Finset.card_pair hne01] have hrest : ∏ j ∈ Finset.univ.erase (s.1 a0Sub), (slotCount s.1 j).factorial = 1 := by refine Finset.prod_eq_one fun j hj => ?_ have hjne : j ≠ s.1 a0Sub := (Finset.mem_erase.mp hj).1 have h0 : slotCount s.1 j = 0 := by unfold slotCount rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff] intro x _; rcases hmemA x with rfl | rfl · exact hjne.symm · rw [← heq]; exact hjne.symm rw [h0]; rfl rw [hc0, hrest]; rfl · rw [if_neg (fun h => heq (hiff.mp h))] unfold slotWeight refine Finset.prod_eq_one fun j _ => ?_ have hle1 : slotCount s.1 j ≤ 1 := by unfold slotCount refine Finset.card_le_one.mpr fun x hx y hy => ?_ have hsx := (Finset.mem_filter.mp hx).2 have hsy := (Finset.mem_filter.mp hy).2 rcases hmemA x with rfl | rfl <;> rcases hmemA y with rfl | rfl · rfl · exact absurd (hsx.trans hsy.symm) heq · exact absurd (hsy.trans hsx.symm) heq · rfl interval_cases (slotCount s.1 j) <;> rfl have hT11 : totalLinExt WitnessP5 = 11 := by rw [hT]; unfold totalWeight rw [Finset.sum_congr rfl fun s _ => hw_pair s] rw [Fintype.sum_equiv eSlot _ (fun p : Fin 3 × Fin 3 => if p.1.val = p.2.val + 1 then 2 else 1) (fun _ => rfl)] decide have hCa0_c1 : countBefore WitnessP5.a0 WitnessP5.c1 = 7 := by change countBefore a0Sub.1 (c 1) = 7 rw [hAC a0Sub 1, Finset.sum_congr rfl fun s _ => hw_pair s] simp only [Fin.val_one] have hsum : ∑ s ∈ Finset.univ.filter (fun s : ValidSlot I => (s.1 a0Sub).val ≤ 1), (if (eSlot s).1.val = (eSlot s).2.val + 1 then 2 else 1) = ∑ p ∈ Finset.univ.filter (fun p : Fin 3 × Fin 3 => p.1.val ≤ 1), (if p.1.val = p.2.val + 1 then 2 else 1) := Finset.sum_bij (fun s _ => eSlot s) (fun s hs => Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hs).2⟩) (fun _ _ _ _ h => eSlot.injective h) (fun p hp => ⟨eSlot.symm p, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by have := (Finset.mem_filter.mp hp).2 simpa [eSlot] using this⟩, eSlot.apply_symm_apply p⟩) (fun _ _ => rfl) rw [hsum]; decide have hCc1_a0 : countBefore WitnessP5.c1 WitnessP5.a0 = 4 := by classical have h1 : countBefore WitnessP5.a0 WitnessP5.c1 = Fintype.card { e : LinExt WitnessP5 // e.1 .a0 < e.1 .c1 } := by unfold countBefore; convert rfl have h2 : countBefore WitnessP5.c1 WitnessP5.a0 = Fintype.card { e : LinExt WitnessP5 // e.1 .c1 < e.1 .a0 } := by unfold countBefore; convert rfl have h3 : totalLinExt WitnessP5 = Fintype.card (LinExt WitnessP5) := by unfold totalLinExt; convert rfl have hcompl : Fintype.card { e : LinExt WitnessP5 // e.1 .a0 < e.1 .c1 } + Fintype.card { e : LinExt WitnessP5 // ¬ e.1 .a0 < e.1 .c1 } = Fintype.card (LinExt WitnessP5) := by rw [Fintype.card_subtype_compl] exact Nat.add_sub_cancel' (Fintype.card_subtype_le _) have heq : Fintype.card { e : LinExt WitnessP5 // ¬ e.1 .a0 < e.1 .c1 } = Fintype.card { e : LinExt WitnessP5 // e.1 .c1 < e.1 .a0 } := by refine Fintype.card_congr (Equiv.subtypeEquivRight fun e => ?_) constructor · intro hnot have hne : e.1 .a0 ≠ e.1 .c1 := fun h => by have := e.1.injective h; cases this exact lt_of_le_of_ne (le_of_not_gt hnot) hne.symm · intro hlt; exact not_lt_of_gt hlt omega refine ⟨hsplit, by decide, by decide, by decide, hT11, hCa0_c1, hCc1_a0, ?_⟩ refine ⟨by omega, by omega, by omega⟩ end PosetBalance /-! ## Axiom Verification -/ #print axioms PosetBalance.rising_factorial_fiber_ratio #print axioms PosetBalance.splitIntervals_exists_balanced #print axioms PosetBalance.one_third_two_thirds_split_poset #print axioms PosetBalance.formalConjectures_split_poset #print axioms PosetBalance.one_third_two_thirds_block_split #print axioms PosetBalance.formalConjectures_block_split #print axioms PosetBalance.one_third_two_thirds_coheight_le_two #print axioms PosetBalance.formalConjectures_coheight_le_two #print axioms PosetBalance.two_plus_one_sharp #print axioms PosetBalance.witness_P5_balance