import Mathlib /-! # Speicher Moment-Cumulant Mobius Inversion, Formal R-Transform & Free Convolutions Self-contained Lean 4 formalization of: 1. The incidence algebra of the non-crossing partition lattice `NC(n)`, exact block factorization of `mu_{NC}(bot, sigma)` and `mu_{NC}(pi, top)` via Kreweras complement, and the exact Speicher Mobius theorem `mu_{NC}(0_n, 1_n) = (-1)^{n-1} C_{n-1}`. 2. Exact Moment-Cumulant bijection `m_n = sum_{pi in NC(n)} kappa_pi` and `kappa_n = sum_{pi in NC(n)} m_pi mu_{NC}(pi, 1_n)` over any commutative ring `R`. 3. Exact Gap-Decomposition Master Identity `M(z) = C(z M(z)) = 1 + (z M(z)) R(z M(z))` and two-sided formal Cauchy/R-transform compositional inversion. 4. Free additive convolution (`kappa_n(mu boxplus nu) = kappa_n(mu) + kappa_n(nu)`, commutativity, associativity, `k`-fold scaling) and free multiplicative convolution via Kreweras complement (`kappa_n(a boxtimes b) = sum_pi kappa_pi(a) kappa_{K(pi)}(b)`, commutativity, and Nica-Speicher moment formulas). 5. Exact Moment-Cumulant characterizations of the Wigner semicircle law and the Marchenko-Pastur / Free-Poisson law. -/ namespace FreeProbSpeicher open Finset structure NC (n : ℕ) where rel : ℕ → ℕ → Bool supp : ∀ i j, rel i j = true → i < n ∧ j < n refl : ∀ i, i < n → rel i i = true symm : ∀ i j, rel i j = rel j i trans : ∀ i j k, rel i j = true → rel j k = true → rel i k = true nc : ∀ a b c d, a < b → b < c → c < d → rel a c = true → rel b d = true → rel a b = true namespace NC variable {n : ℕ} theorem ext' {π σ : NC n} (h : ∀ i j, i < n → j < n → π.rel i j = σ.rel i j) : π = σ := by cases π with | mk r1 s1 _ _ _ _ => cases σ with | mk r2 s2 _ _ _ _ => have : r1 = r2 := by funext i j by_cases hi : i < n ∧ j < n · exact h i j hi.1 hi.2 · have e1 : r1 i j = false := by cases hr : r1 i j · rfl · exact absurd (s1 i j hr) hi have e2 : r2 i j = false := by cases hr : r2 i j · rfl · exact absurd (s2 i j hr) hi rw [e1, e2] subst this rfl /-- The finite "matrix" shape of an `NC n`, used to build the `Fintype` instance. -/ def toMat (π : NC n) : Fin n → Fin n → Bool := fun i j => π.rel i.1 j.1 theorem toMat_injective : Function.Injective (toMat (n := n)) := by intro π σ h apply ext' intro i j hi hj exact congrFun (congrFun h ⟨i, hi⟩) ⟨j, hj⟩ instance : DecidableEq (NC n) := fun π σ => decidable_of_iff (toMat π = toMat σ) ⟨fun h => toMat_injective h, fun h => h ▸ rfl⟩ /-- Rebuild a relation on `ℕ` from a matrix, extended by `false`. -/ def ofMat (m : Fin n → Fin n → Bool) : ℕ → ℕ → Bool := fun i j => if h : i < n ∧ j < n then m ⟨i, h.1⟩ ⟨j, h.2⟩ else false /-- Matrices that come from non-crossing partitions. -/ def GoodMat (m : Fin n → Fin n → Bool) : Prop := (∀ i : Fin n, m i i = true) ∧ (∀ i j : Fin n, m i j = m j i) ∧ (∀ i j k : Fin n, m i j = true → m j k = true → m i k = true) ∧ (∀ a b c d : Fin n, a < b → b < c → c < d → m a c = true → m b d = true → m a b = true) instance (m : Fin n → Fin n → Bool) : Decidable (GoodMat m) := by unfold GoodMat; infer_instance /-- `NC n` is equivalent to the finite set of good matrices. -/ def equivGood : NC n ≃ { m : Fin n → Fin n → Bool // GoodMat m } where toFun π := ⟨toMat π, fun i => π.refl _ i.2, fun i j => π.symm _ _, fun i j k h1 h2 => π.trans _ _ _ h1 h2, fun a b c d h1 h2 h3 h4 h5 => π.nc _ _ _ _ h1 h2 h3 h4 h5⟩ invFun m := { rel := ofMat m.1 supp := by intro i j h unfold ofMat at h split_ifs at h with hh · exact hh refl := by intro i hi unfold ofMat rw [dif_pos ⟨hi, hi⟩] exact m.2.1 ⟨i, hi⟩ symm := by intro i j unfold ofMat by_cases h : i < n ∧ j < n · rw [dif_pos h, dif_pos ⟨h.2, h.1⟩] exact m.2.2.1 _ _ · rw [dif_neg h, dif_neg (fun h' => h ⟨h'.2, h'.1⟩)] trans := by intro i j k h1 h2 unfold ofMat at h1 h2 ⊢ split_ifs at h1 h2 with ha hb · rw [dif_pos ⟨ha.1, hb.2⟩] exact m.2.2.2.1 _ _ _ h1 h2 nc := by intro a b c d h1 h2 h3 h4 h5 unfold ofMat at h4 h5 ⊢ split_ifs at h4 h5 with ha hb · rw [dif_pos ⟨ha.1, hb.1⟩] exact m.2.2.2.2 ⟨a, ha.1⟩ ⟨b, hb.1⟩ ⟨c, ha.2⟩ ⟨d, hb.2⟩ h1 h2 h3 h4 h5 } left_inv π := by apply ext' intro i j hi hj show ofMat (toMat π) i j = π.rel i j unfold ofMat toMat rw [dif_pos ⟨hi, hj⟩] right_inv m := by apply Subtype.ext funext i j show ofMat m.1 i.1 j.1 = m.1 i j unfold ofMat rw [dif_pos ⟨i.2, j.2⟩] instance : Fintype (NC n) := Fintype.ofEquiv _ equivGood.symm /-! ### Refinement order and meet -/ instance : PartialOrder (NC n) where le π σ := ∀ i j, π.rel i j = true → σ.rel i j = true le_refl _ _ _ h := h le_trans _ _ _ h1 h2 i j h := h2 i j (h1 i j h) le_antisymm π σ h1 h2 := by apply ext' intro i j _ _ cases e : π.rel i j · cases e' : σ.rel i j · rfl · exact absurd (h2 i j e') (by simp [e]) · exact (h1 i j e).symm theorem le_def {π σ : NC n} : π ≤ σ ↔ ∀ i j, π.rel i j = true → σ.rel i j = true := Iff.rfl instance : DecidableLE (NC n) := fun π σ => decidable_of_iff (∀ i < n, ∀ j < n, π.rel i j = true → σ.rel i j = true) (by constructor · intro h i j hij exact h i (π.supp i j hij).1 j (π.supp i j hij).2 hij · intro h i _ j _ hij exact h i j hij) /-- The discrete partition `0_n` (all singletons). -/ def bot (n : ℕ) : NC n where rel i j := decide (i = j ∧ i < n) supp i j h := by simp at h; omega refl i hi := by simp [hi] symm i j := by by_cases h : i = j · subst h; rfl · simp [h, Ne.symm h] trans i j k h1 h2 := by simp at h1 h2 ⊢; omega nc a b c d h1 h2 _ h4 _ := by simp at h4; omega /-- The one-block partition `1_n`. -/ def top (n : ℕ) : NC n where rel i j := decide (i < n ∧ j < n) supp i j h := by simpa using h refl i hi := by simp [hi] symm i j := by simp [and_comm] trans i j k h1 h2 := by simp at h1 h2 ⊢; omega nc a b c d _ _ _ h4 h5 := by simp at h4 h5 ⊢; omega instance : OrderBot (NC n) where bot := bot n bot_le π i j h := by simp [bot] at h obtain ⟨rfl, hi⟩ := h exact π.refl i hi instance : OrderTop (NC n) where top := top n le_top π i j h := by have := π.supp i j h simp [top, this.1, this.2] /-- Meet: intersection of block relations. -/ def inf (π σ : NC n) : NC n where rel i j := π.rel i j && σ.rel i j supp i j h := by simp only [Bool.and_eq_true] at h exact π.supp i j h.1 refl i hi := by simp [π.refl i hi, σ.refl i hi] symm i j := by rw [π.symm, σ.symm] trans i j k h1 h2 := by simp only [Bool.and_eq_true] at h1 h2 ⊢ exact ⟨π.trans _ _ _ h1.1 h2.1, σ.trans _ _ _ h1.2 h2.2⟩ nc a b c d h1 h2 h3 h4 h5 := by simp only [Bool.and_eq_true] at h4 h5 ⊢ exact ⟨π.nc _ _ _ _ h1 h2 h3 h4.1 h5.1, σ.nc _ _ _ _ h1 h2 h3 h4.2 h5.2⟩ instance : SemilatticeInf (NC n) where inf := inf inf_le_left _ _ i j h := by simp only [inf, Bool.and_eq_true] at h; exact h.1 inf_le_right _ _ i j h := by simp only [inf, Bool.and_eq_true] at h; exact h.2 le_inf _ _ _ h1 h2 i j h := by simp only [inf, Bool.and_eq_true]; exact ⟨h1 i j h, h2 i j h⟩ /-- Join: the meet of all common upper bounds (a finite meet in the finite lattice). -/ def sup (π σ : NC n) : NC n := (Finset.univ.filter fun τ : NC n => π ≤ τ ∧ σ ≤ τ).inf' ⟨⊤, by simp⟩ id instance : Lattice (NC n) where sup := sup le_sup_left _ _ := Finset.le_inf' _ _ fun _ hτ => (Finset.mem_filter.mp hτ).2.1 le_sup_right _ _ := Finset.le_inf' _ _ fun _ hτ => (Finset.mem_filter.mp hτ).2.2 sup_le _ _ _ h1 h2 := Finset.inf'_le _ (Finset.mem_filter.mpr ⟨Finset.mem_univ _, h1, h2⟩) theorem card_zero : Fintype.card (NC 0) = 1 := Fintype.card_eq_one_iff.mpr ⟨⊥, fun _ => ext' fun _ _ hi => absurd hi (Nat.not_lt_zero _)⟩ /-! ### Windows, prepending a singleton, joining at the first link -/ /-- Restriction of `π` to the window `{k, …, k+m-1}`, re-indexed to `{0, …, m-1}`. -/ def window {N : ℕ} (π : NC N) (k m : ℕ) (h : k + m ≤ N) : NC m where rel i j := decide (i < m ∧ j < m ∧ π.rel (i + k) (j + k) = true) supp i j hr := by have := of_decide_eq_true hr; exact ⟨this.1, this.2.1⟩ refl i hi := decide_eq_true ⟨hi, hi, π.refl _ (by omega)⟩ symm i j := decide_eq_decide.mpr ⟨fun ⟨a, b, c⟩ => ⟨b, a, by rw [π.symm]; exact c⟩, fun ⟨a, b, c⟩ => ⟨b, a, by rw [π.symm]; exact c⟩⟩ trans i j l h1 h2 := by obtain ⟨a1, _, a3⟩ := of_decide_eq_true h1 obtain ⟨_, b2, b3⟩ := of_decide_eq_true h2 exact decide_eq_true ⟨a1, b2, π.trans _ _ _ a3 b3⟩ nc a b c d h1 h2 h3 h4 h5 := by obtain ⟨a1, _, a3⟩ := of_decide_eq_true h4 obtain ⟨b1, _, b3⟩ := of_decide_eq_true h5 exact decide_eq_true ⟨a1, b1, π.nc _ _ _ _ (by omega) (by omega) (by omega) a3 b3⟩ theorem window_rel {N : ℕ} (π : NC N) (k m : ℕ) (h : k + m ≤ N) (i j : ℕ) : (window π k m h).rel i j = true ↔ i < m ∧ j < m ∧ π.rel (i + k) (j + k) = true := decide_eq_true_iff /-- Case A: prepend the singleton block `{0}`. -/ def prepend {m : ℕ} (σ : NC m) : NC (m + 1) where rel i j := decide ((i = 0 ∧ j = 0) ∨ (1 ≤ i ∧ 1 ≤ j ∧ σ.rel (i - 1) (j - 1) = true)) supp i j h := by rcases of_decide_eq_true h with h | ⟨_, _, h3⟩ · omega · have := σ.supp _ _ h3; omega refl i hi := by apply decide_eq_true rcases Nat.eq_zero_or_pos i with rfl | hpos · exact Or.inl ⟨rfl, rfl⟩ · exact Or.inr ⟨hpos, hpos, σ.refl _ (by omega)⟩ symm i j := decide_eq_decide.mpr ⟨fun h => h.elim (fun ⟨a, b⟩ => Or.inl ⟨b, a⟩) (fun ⟨a, b, c⟩ => Or.inr ⟨b, a, by rw [σ.symm]; exact c⟩), fun h => h.elim (fun ⟨a, b⟩ => Or.inl ⟨b, a⟩) (fun ⟨a, b, c⟩ => Or.inr ⟨b, a, by rw [σ.symm]; exact c⟩)⟩ trans i j k h1 h2 := by apply decide_eq_true rcases of_decide_eq_true h1 with ⟨a1, a2⟩ | ⟨a1, a2, a3⟩ <;> rcases of_decide_eq_true h2 with ⟨b1, b2⟩ | ⟨b1, b2, b3⟩ · exact Or.inl ⟨a1, b2⟩ · omega · omega · exact Or.inr ⟨a1, b2, σ.trans _ _ _ a3 b3⟩ nc a b c d h1 h2 h3 h4 h5 := by apply decide_eq_true rcases of_decide_eq_true h4 with ⟨_, _⟩ | ⟨a1, _, a3⟩ · omega · rcases of_decide_eq_true h5 with ⟨_, _⟩ | ⟨b1, _, b3⟩ · omega · exact Or.inr ⟨a1, b1, σ.nc _ _ _ _ (by omega) (by omega) (by omega) a3 b3⟩ theorem prepend_rel {m : ℕ} (σ : NC m) (i j : ℕ) : (prepend σ).rel i j = true ↔ (i = 0 ∧ j = 0) ∨ (1 ≤ i ∧ 1 ≤ j ∧ σ.rel (i - 1) (j - 1) = true) := decide_eq_true_iff theorem prepend_rel_succ {m : ℕ} (σ : NC m) (i j : ℕ) : (prepend σ).rel (i + 1) (j + 1) = σ.rel i j := by rw [Bool.eq_iff_iff, prepend_rel]; simp theorem prepend_rel_zero_succ {m : ℕ} (σ : NC m) (i : ℕ) : (prepend σ).rel 0 (i + 1) = false := by rw [Bool.eq_false_iff]; intro h; rw [prepend_rel] at h; omega /-- Outer re-indexing used in Case B: `0 ↦ 0` and `u ↦ u - (j+1)`. -/ def oIdx (j u : ℕ) : ℕ := if u = 0 then 0 else u - (j + 1) theorem oIdx_zero (j : ℕ) : oIdx j 0 = 0 := rfl theorem oIdx_pos {j u : ℕ} (h : u ≠ 0) : oIdx j u = u - (j + 1) := if_neg h /-- Case B: `0` is attached to the block of `j+1`; `a` lives on `{1..j}`, `b` on `{j+1..m}`. -/ def joinAt {m : ℕ} (j : ℕ) (hj : j < m) (a : NC j) (b : NC (m - j)) : NC (m + 1) where rel u v := decide ((1 ≤ u ∧ u ≤ j ∧ 1 ≤ v ∧ v ≤ j ∧ a.rel (u - 1) (v - 1) = true) ∨ ((u = 0 ∨ (j + 1 ≤ u ∧ u ≤ m)) ∧ (v = 0 ∨ (j + 1 ≤ v ∧ v ≤ m)) ∧ b.rel (oIdx j u) (oIdx j v) = true)) supp u v h := by rcases of_decide_eq_true h with ⟨_, _, _, _, _⟩ | ⟨h1, h2, _⟩ <;> omega refl u hu := by apply decide_eq_true by_cases h0 : u = 0 · subst h0 exact Or.inr ⟨Or.inl rfl, Or.inl rfl, by rw [oIdx_zero]; exact b.refl 0 (by omega)⟩ · by_cases h1 : u ≤ j · exact Or.inl ⟨by omega, h1, by omega, h1, a.refl _ (by omega)⟩ · exact Or.inr ⟨Or.inr ⟨by omega, by omega⟩, Or.inr ⟨by omega, by omega⟩, by rw [oIdx_pos h0]; exact b.refl _ (by omega)⟩ symm u v := decide_eq_decide.mpr ⟨fun h => h.elim (fun ⟨p1, p2, p3, p4, p5⟩ => Or.inl ⟨p3, p4, p1, p2, by rw [a.symm]; exact p5⟩) (fun ⟨p1, p2, p3⟩ => Or.inr ⟨p2, p1, by rw [b.symm]; exact p3⟩), fun h => h.elim (fun ⟨p1, p2, p3, p4, p5⟩ => Or.inl ⟨p3, p4, p1, p2, by rw [a.symm]; exact p5⟩) (fun ⟨p1, p2, p3⟩ => Or.inr ⟨p2, p1, by rw [b.symm]; exact p3⟩)⟩ trans u v w h1 h2 := by apply decide_eq_true rcases of_decide_eq_true h1 with ⟨p1, p2, p3, p4, p5⟩ | ⟨p1, p2, p3⟩ <;> rcases of_decide_eq_true h2 with ⟨q1, q2, q3, q4, q5⟩ | ⟨q1, q2, q3⟩ · exact Or.inl ⟨p1, p2, q3, q4, a.trans _ _ _ p5 q5⟩ · omega · omega · exact Or.inr ⟨p1, q2, b.trans _ _ _ p3 q3⟩ nc p q r s h1 h2 h3 h4 h5 := by apply decide_eq_true rcases of_decide_eq_true h4 with ⟨p1, p2, p3, p4, p5⟩ | ⟨p1, p2, p3⟩ <;> rcases of_decide_eq_true h5 with ⟨q1, q2, q3, q4, q5⟩ | ⟨q1, q2, q3⟩ · exact Or.inl ⟨p1, by omega, q1, q2, a.nc _ _ _ _ (by omega) (by omega) (by omega) p5 q5⟩ · omega · omega · have hq : q ≠ 0 := by omega have hr : r ≠ 0 := by omega have hs : s ≠ 0 := by omega rw [oIdx_pos hr] at p3 rw [oIdx_pos hq, oIdx_pos hs] at q3 refine Or.inr ⟨p1, q1, ?_⟩ rw [oIdx_pos hq] by_cases hp0 : p = 0 · subst hp0 rw [oIdx_zero] at p3 ⊢ by_cases hqj : q = j + 1 · subst hqj; simpa using b.refl 0 (by omega) · exact b.nc _ _ _ _ (by omega) (by omega) (by omega) p3 q3 · rw [oIdx_pos hp0] at p3 ⊢ exact b.nc _ _ _ _ (by omega) (by omega) (by omega) p3 q3 section JoinAt variable {m j : ℕ} {hj : j < m} {a : NC j} {b : NC (m - j)} theorem joinAt_rel (u v : ℕ) : (joinAt j hj a b).rel u v = true ↔ ((1 ≤ u ∧ u ≤ j ∧ 1 ≤ v ∧ v ≤ j ∧ a.rel (u - 1) (v - 1) = true) ∨ ((u = 0 ∨ (j + 1 ≤ u ∧ u ≤ m)) ∧ (v = 0 ∨ (j + 1 ≤ v ∧ v ≤ m)) ∧ b.rel (oIdx j u) (oIdx j v) = true)) := decide_eq_true_iff theorem joinAt_rel_in (i k : ℕ) (hi : i < j) (hk : k < j) : (joinAt j hj a b).rel (i + 1) (k + 1) = a.rel i k := by rw [Bool.eq_iff_iff, joinAt_rel] constructor · rintro (⟨_, _, _, _, h⟩ | ⟨h, _, _⟩) · simpa using h · omega · intro h; exact Or.inl ⟨by omega, by omega, by omega, by omega, by simpa using h⟩ theorem joinAt_rel_out (u v : ℕ) (hu : u = 0 ∨ (j + 1 ≤ u ∧ u ≤ m)) (hv : v = 0 ∨ (j + 1 ≤ v ∧ v ≤ m)) : (joinAt j hj a b).rel u v = b.rel (oIdx j u) (oIdx j v) := by rw [Bool.eq_iff_iff, joinAt_rel] constructor · rintro (⟨_, _, _, _, _⟩ | ⟨_, _, h⟩) · omega · exact h · intro h; exact Or.inr ⟨hu, hv, h⟩ theorem joinAt_rel_cross (u v : ℕ) (hu : 1 ≤ u ∧ u ≤ j) (hv : v = 0 ∨ (j + 1 ≤ v ∧ v ≤ m)) : (joinAt j hj a b).rel u v = false := by rw [Bool.eq_false_iff]; intro h; rw [joinAt_rel] at h; omega theorem joinAt_rel_zero_link : (joinAt j hj a b).rel 0 (j + 1) = true := by rw [joinAt_rel_out _ _ (Or.inl rfl) (Or.inr ⟨le_rfl, hj⟩), oIdx_zero, oIdx_pos (by omega), Nat.sub_self] exact b.refl 0 (by omega) theorem joinAt_rel_zero_inner (i : ℕ) (hi : i < j) : (joinAt j hj a b).rel 0 (i + 1) = false := by rw [(joinAt j hj a b).symm] exact joinAt_rel_cross _ _ ⟨by omega, by omega⟩ (Or.inl rfl) end JoinAt /-- The first link of `π ∈ NC(m+1)`: the least `j` with `0 ~ j+1`, if any. -/ def firstLink {m : ℕ} (π : NC (m + 1)) : Option (Fin m) := if h : ∃ i, i < m ∧ π.rel 0 (i + 1) = true then some ⟨Nat.find h, (Nat.find_spec h).1⟩ else none theorem firstLink_eq_none {m : ℕ} (π : NC (m + 1)) : firstLink π = none ↔ ∀ i, i < m → π.rel 0 (i + 1) = false := by unfold firstLink split_ifs with h · simp only [false_iff, not_forall] obtain ⟨i, hi, hr⟩ := h exact ⟨i, hi, by simp [hr]⟩ · constructor · intro _ i hi cases hr : π.rel 0 (i + 1) · rfl · exact absurd ⟨i, hi, hr⟩ h · intro _; rfl theorem firstLink_eq_some {m : ℕ} (π : NC (m + 1)) (j : Fin m) : firstLink π = some j ↔ π.rel 0 (j.1 + 1) = true ∧ ∀ i, i < j.1 → π.rel 0 (i + 1) = false := by unfold firstLink split_ifs with h · rw [Option.some.injEq, Fin.ext_iff, Fin.val_mk, Nat.find_eq_iff] constructor · rintro ⟨⟨_, h1⟩, h2⟩ refine ⟨h1, fun i hi => ?_⟩ cases hr : π.rel 0 (i + 1) · rfl · exact absurd ⟨by omega, hr⟩ (h2 i hi) · rintro ⟨h1, h2⟩ refine ⟨⟨j.2, h1⟩, fun i hi => ?_⟩ rintro ⟨_, hr⟩ rw [h2 i hi] at hr; exact Bool.false_ne_true hr · simp only [false_iff, not_and, not_forall] intro h1 exact absurd ⟨j.1, j.2, h1⟩ h theorem prepend_window {m : ℕ} (π : NC (m + 1)) (h : ∀ i, i < m → π.rel 0 (i + 1) = false) : prepend (window π 1 m (by omega)) = π := by apply ext' intro u v hu hv rcases u with _ | u <;> rcases v with _ | v · rw [π.refl 0 hu, Bool.eq_iff_iff, prepend_rel]; simp · rw [prepend_rel_zero_succ, h v (by omega)] · rw [(prepend _).symm, prepend_rel_zero_succ, π.symm, h u (by omega)] · rw [prepend_rel_succ, Bool.eq_iff_iff, window_rel] exact ⟨fun h => h.2.2, fun h => ⟨by omega, by omega, h⟩⟩ theorem window_prepend {m : ℕ} (σ : NC m) : window (prepend σ) 1 m (by omega) = σ := by apply ext' intro i j hi hj rw [Bool.eq_iff_iff, window_rel, prepend_rel_succ] exact ⟨fun h => h.2.2, fun h => ⟨hi, hj, h⟩⟩ theorem joinAt_window {m : ℕ} (j : ℕ) (hj : j < m) (π : NC (m + 1)) (h1 : π.rel 0 (j + 1) = true) (h2 : ∀ i, i < j → π.rel 0 (i + 1) = false) : joinAt j hj (window π 1 j (by omega)) (window π (j + 1) (m - j) (by omega)) = π := by -- no block of `π` crosses from `{1..j}` to `{0} ∪ {j+1..m}` have hcross : ∀ u v, 1 ≤ u → u ≤ j → (v = 0 ∨ (j + 1 ≤ v ∧ v ≤ m)) → π.rel u v = false := by intro u v hu1 hu2 hv have hu0 : π.rel u 0 = false := by rw [π.symm]; have := h2 (u - 1) (by omega); rwa [Nat.sub_add_cancel hu1] at this rw [Bool.eq_false_iff] intro huv rcases hv with rfl | ⟨hv1, hv2⟩ · rw [hu0] at huv; exact Bool.false_ne_true huv · rcases Nat.eq_or_lt_of_le hv1 with hveq | hvlt · subst hveq have := π.trans _ _ _ huv (by rw [π.symm]; exact h1) rw [hu0] at this; exact Bool.false_ne_true this · have := π.nc 0 u (j + 1) v (by omega) (by omega) hvlt h1 huv rw [π.symm, hu0] at this; exact Bool.false_ne_true this -- re-indexing the outer zone have hsub : ∀ u w, (u = 0 ∨ j + 1 ≤ u) → π.rel (oIdx j u + (j + 1)) w = π.rel u w := by intro u w hu by_cases hu0 : u = 0 · subst hu0 rw [oIdx_zero, Nat.zero_add, Bool.eq_iff_iff] constructor · intro h; exact π.trans _ _ _ h1 h · intro h; exact π.trans _ _ _ (by rw [π.symm]; exact h1) h · rw [oIdx_pos hu0, Nat.sub_add_cancel (by omega)] apply ext' intro u v hu hv have zone : ∀ x, x < m + 1 → (1 ≤ x ∧ x ≤ j) ∨ (x = 0 ∨ (j + 1 ≤ x ∧ x ≤ m)) := by intro x hx; omega rcases zone u hu with hu' | hu' <;> rcases zone v hv with hv' | hv' · obtain ⟨u', rfl⟩ : ∃ u', u = u' + 1 := ⟨u - 1, by omega⟩ obtain ⟨v', rfl⟩ : ∃ v', v = v' + 1 := ⟨v - 1, by omega⟩ rw [joinAt_rel_in _ _ (by omega) (by omega), Bool.eq_iff_iff, window_rel] exact ⟨fun h => h.2.2, fun h => ⟨by omega, by omega, h⟩⟩ · rw [joinAt_rel_cross _ _ hu' hv', hcross u v hu'.1 hu'.2 hv'] · rw [(joinAt _ _ _ _).symm, joinAt_rel_cross _ _ hv' hu', π.symm, hcross v u hv'.1 hv'.2 hu'] · rw [joinAt_rel_out _ _ hu' hv', Bool.eq_iff_iff, window_rel] have hbu : oIdx j u < m - j := by rcases hu' with rfl | hu' · rw [oIdx_zero]; omega · rw [oIdx_pos (by omega)]; omega have hbv : oIdx j v < m - j := by rcases hv' with rfl | hv' · rw [oIdx_zero]; omega · rw [oIdx_pos (by omega)]; omega rw [hsub u _ (by omega), π.symm, hsub v _ (by omega), π.symm] exact ⟨fun h => h.2.2, fun h => ⟨hbu, hbv, h⟩⟩ theorem window_joinAt_in {m : ℕ} (j : ℕ) (hj : j < m) (a : NC j) (b : NC (m - j)) : window (joinAt j hj a b) 1 j (by omega) = a := by apply ext' intro i k hi hk rw [Bool.eq_iff_iff, window_rel, joinAt_rel_in _ _ hi hk] exact ⟨fun h => h.2.2, fun h => ⟨hi, hk, h⟩⟩ theorem window_joinAt_out {m : ℕ} (j : ℕ) (hj : j < m) (a : NC j) (b : NC (m - j)) : window (joinAt j hj a b) (j + 1) (m - j) (by omega) = b := by apply ext' intro y z hy hz rw [Bool.eq_iff_iff, window_rel, joinAt_rel_out _ _ (Or.inr ⟨by omega, by omega⟩) (Or.inr ⟨by omega, by omega⟩), oIdx_pos (by omega), oIdx_pos (by omega), Nat.add_sub_cancel, Nat.add_sub_cancel] exact ⟨fun h => h.2.2, fun h => ⟨hy, hz, h⟩⟩ /-- Fibre of Case A. -/ def fiberNone (m : ℕ) : { π : NC (m + 1) // firstLink π = none } ≃ NC m where toFun π := window π.1 1 m (by omega) invFun σ := ⟨prepend σ, (firstLink_eq_none _).mpr fun i _ => prepend_rel_zero_succ σ i⟩ left_inv π := Subtype.ext (prepend_window π.1 ((firstLink_eq_none _).mp π.2)) right_inv σ := window_prepend σ /-- Fibre of Case B at link `j`. -/ def fiberSome (m : ℕ) (j : Fin m) : { π : NC (m + 1) // firstLink π = some j } ≃ NC j.1 × NC (m - j.1) where toFun π := (window π.1 1 j.1 (by omega), window π.1 (j.1 + 1) (m - j.1) (by omega)) invFun p := ⟨joinAt j.1 j.2 p.1 p.2, (firstLink_eq_some _ _).mpr ⟨joinAt_rel_zero_link (hj := j.2), fun i hi => joinAt_rel_zero_inner (hj := j.2) i hi⟩⟩ left_inv π := Subtype.ext (joinAt_window j.1 j.2 π.1 ((firstLink_eq_some _ _).mp π.2).1 ((firstLink_eq_some _ _).mp π.2).2) right_inv p := Prod.ext (window_joinAt_in j.1 j.2 p.1 p.2) (window_joinAt_out j.1 j.2 p.1 p.2) /-- **First-link decomposition of sums over `NC(m+1)`.** -/ theorem sum_decomp {M : Type*} [AddCommMonoid M] (m : ℕ) (F : NC (m + 1) → M) : ∑ π, F π = ∑ σ : NC m, F (prepend σ) + ∑ j : Fin m, ∑ p : NC j.1 × NC (m - j.1), F (joinAt j.1 j.2 p.1 p.2) := by rw [← Fintype.sum_fiberwise (firstLink (m := m)) F, Fintype.sum_option] congr 1 · refine Fintype.sum_equiv (fiberNone m) _ _ fun π => ?_ exact congrArg F (prepend_window π.1 ((firstLink_eq_none _).mp π.2)).symm · refine Finset.sum_congr rfl fun j _ => Fintype.sum_equiv (fiberSome m j) _ _ fun π => ?_ dsimp only [fiberSome, Equiv.coe_fn_mk] exact congrArg F (joinAt_window j.1 j.2 π.1 ((firstLink_eq_some _ _).mp π.2).1 ((firstLink_eq_some _ _).mp π.2).2).symm /-- **Catalan enumeration:** `|NC(n)| = C_n`. -/ theorem card_NC (n : ℕ) : Fintype.card (NC n) = catalan n := by induction n using Nat.strong_induction_on with | _ n ih => rcases n with _ | m · rw [card_zero, catalan_zero] · rw [Fintype.card_eq_sum_ones, sum_decomp m (fun _ => (1 : ℕ))] simp only [Finset.sum_const, Finset.card_univ, smul_eq_mul, mul_one, Fintype.card_prod] rw [ih m (by omega), catalan_succ, Fin.sum_univ_castSucc] simp only [Fin.val_castSucc, Fin.val_last, Nat.sub_self, catalan_zero, mul_one] rw [add_comm] congr 1 refine Finset.sum_congr rfl fun j _ => ?_ rw [ih j.1 (by omega), ih (m - j.1) (by omega)] /-- Explicit central-binomial form: `(n+1) |NC(n)| = binom(2n, n)`. -/ theorem succ_mul_card_NC (n : ℕ) : (n + 1) * Fintype.card (NC n) = (2 * n).choose n := by rw [card_NC, succ_mul_catalan_eq_centralBinom, Nat.centralBinom_eq_two_mul_choose] /-! ### Block counts -/ /-- `i` is the least element of its block. -/ def isMin {n : ℕ} (π : NC n) (i : ℕ) : Bool := decide (∀ k, k < i → π.rel k i = false) /-- Number of blocks `|π|`. -/ def blockCount {n : ℕ} (π : NC n) : ℕ := ∑ i ∈ Finset.range n, if π.isMin i then 1 else 0 theorem isMin_zero {n : ℕ} (π : NC n) : π.isMin 0 = true := decide_eq_true fun _ hk => absurd hk (Nat.not_lt_zero _) theorem isMin_prepend_succ {m : ℕ} (σ : NC m) (i : ℕ) : (prepend σ).isMin (i + 1) = σ.isMin i := by unfold isMin apply decide_eq_decide.mpr constructor · intro h k hk; have := h (k + 1) (by omega); rwa [prepend_rel_succ] at this · intro h k hk rcases k with _ | k · exact prepend_rel_zero_succ σ i · rw [prepend_rel_succ]; exact h k (by omega) theorem blockCount_prepend {m : ℕ} (σ : NC m) : (prepend σ).blockCount = σ.blockCount + 1 := by unfold blockCount rw [Finset.sum_range_succ', isMin_zero] simp only [isMin_prepend_succ, if_true] section JoinAtBlocks variable {m j : ℕ} {hj : j < m} {a : NC j} {b : NC (m - j)} theorem isMin_joinAt_in (i : ℕ) (hi : i < j) : (joinAt j hj a b).isMin (i + 1) = a.isMin i := by unfold isMin apply decide_eq_decide.mpr constructor · intro h k hk; have := h (k + 1) (by omega); rwa [joinAt_rel_in _ _ (by omega) hi] at this · intro h k hk rcases k with _ | k · exact joinAt_rel_zero_inner i hi · rw [joinAt_rel_in _ _ (by omega) hi]; exact h k (by omega) theorem isMin_joinAt_link : (joinAt j hj a b).isMin (j + 1) = false := by unfold isMin rw [decide_eq_false_iff_not] intro h have := h 0 (by omega) rw [joinAt_rel_zero_link] at this exact absurd this (by decide) theorem isMin_joinAt_out (y : ℕ) (hy : y + 1 < m - j) : (joinAt j hj a b).isMin (j + 1 + (y + 1)) = b.isMin (y + 1) := by unfold isMin apply decide_eq_decide.mpr have hout : j + 1 + (y + 1) = 0 ∨ (j + 1 ≤ j + 1 + (y + 1) ∧ j + 1 + (y + 1) ≤ m) := Or.inr ⟨by omega, by omega⟩ have hidx : oIdx j (j + 1 + (y + 1)) = y + 1 := by rw [oIdx_pos (by omega)]; omega constructor · intro h k hk rcases k with _ | k · have := h 0 (by omega) rwa [joinAt_rel_out _ _ (Or.inl rfl) hout, oIdx_zero, hidx] at this · have := h (j + 1 + (k + 1)) (by omega) rwa [joinAt_rel_out _ _ (Or.inr ⟨by omega, by omega⟩) hout, hidx, oIdx_pos (by omega), show j + 1 + (k + 1) - (j + 1) = k + 1 by omega] at this · intro h k hk by_cases hk0 : k = 0 · subst hk0 rw [joinAt_rel_out _ _ (Or.inl rfl) hout, oIdx_zero, hidx] exact h 0 (by omega) · by_cases hkj : k ≤ j · exact joinAt_rel_cross _ _ ⟨by omega, hkj⟩ hout · rw [joinAt_rel_out _ _ (Or.inr ⟨by omega, by omega⟩) hout, hidx, oIdx_pos hk0] exact h _ (by omega) theorem blockCount_joinAt : (joinAt j hj a b).blockCount = a.blockCount + b.blockCount := by obtain ⟨r, hr⟩ : ∃ r, m - j = r + 1 := ⟨m - j - 1, by omega⟩ unfold blockCount have key : ∀ f : ℕ → ℕ, ∑ i ∈ Finset.range (m - j), f i = ∑ i ∈ Finset.range r, f (i + 1) + f 0 := fun f => by rw [hr, Finset.sum_range_succ'] rw [Finset.sum_range_succ', isMin_zero, if_pos rfl, ← Finset.sum_range_add_sum_Ico _ (show j ≤ m by omega), Finset.sum_Ico_eq_sum_range, key, key (fun i => if b.isMin i then 1 else 0), isMin_zero b] simp only [Nat.add_zero, if_pos] rw [isMin_joinAt_link, if_neg Bool.false_ne_true] have e1 : ∑ i ∈ Finset.range j, (if (joinAt j hj a b).isMin (i + 1) = true then 1 else 0) = ∑ i ∈ Finset.range j, (if a.isMin i = true then 1 else 0) := Finset.sum_congr rfl fun i hi => by rw [isMin_joinAt_in i (Finset.mem_range.mp hi)] have e2 : ∑ i ∈ Finset.range r, (if (joinAt j hj a b).isMin (j + (i + 1) + 1) = true then 1 else 0) = ∑ i ∈ Finset.range r, (if b.isMin (i + 1) = true then 1 else 0) := Finset.sum_congr rfl fun i hi => by rw [show j + (i + 1) + 1 = j + 1 + (i + 1) by omega, isMin_joinAt_out i (by have := Finset.mem_range.mp hi; omega)] rw [e1, e2] ring end JoinAtBlocks theorem blockCount_le {n : ℕ} (π : NC n) : π.blockCount ≤ n := by unfold blockCount calc ∑ i ∈ Finset.range n, (if π.isMin i then 1 else 0) ≤ ∑ _i ∈ Finset.range n, 1 := Finset.sum_le_sum fun i _ => by split_ifs <;> omega _ = n := by simp theorem blockCount_pos {n : ℕ} (hn : 0 < n) (π : NC n) : 0 < π.blockCount := by unfold blockCount obtain ⟨k, rfl⟩ : ∃ k, n = k + 1 := ⟨n - 1, by omega⟩ rw [Finset.sum_range_succ', isMin_zero] simp /-- The half-open interval `(lo, hi]` is closed under blocks of `π`. -/ def closedInterval {n : ℕ} (π : NC n) (lo hi : ℕ) : Bool := decide (∀ a ∈ Finset.range n, ∀ b ∈ Finset.range n, lo < a → a ≤ hi → π.rel a b = true → lo < b ∧ b ≤ hi) lemma closedInterval_iff {n : ℕ} (π : NC n) (lo hi : ℕ) : closedInterval π lo hi = true ↔ ∀ a < n, ∀ b < n, lo < a → a ≤ hi → π.rel a b = true → lo < b ∧ b ≤ hi := by unfold closedInterval rw [decide_eq_true_iff] simp only [Finset.mem_range] /-- **Kreweras Complement `K(π)`:** `i ~_{K(π)} j` iff the half-open interval `(min i j, max i j]` is a union of blocks of `π`. -/ def kreweras {n : ℕ} (π : NC n) : NC n where rel i j := decide (i < n ∧ j < n ∧ closedInterval π (min i j) (max i j) = true) supp i j h := by have := of_decide_eq_true h; exact ⟨this.1, this.2.1⟩ refl i hi := by apply decide_eq_true refine ⟨hi, hi, ?_⟩ rw [closedInterval_iff] intro a _ _ _ h1 h2; simp at h1 h2; omega symm i j := decide_eq_decide.mpr (by rw [min_comm, max_comm]; tauto) trans i j k h1 h2 := by obtain ⟨hi, hj, hc1⟩ := of_decide_eq_true h1 obtain ⟨_, hk, hc2⟩ := of_decide_eq_true h2 rw [closedInterval_iff] at hc1 hc2 apply decide_eq_true refine ⟨hi, hk, (closedInterval_iff _ _ _).mpr ?_⟩ intro a ha b hb hlo hhi hab -- Every element in (min i k, max i k] is handled by the two closed intervals (min i j, max i j] and (min j k, max j k] by_cases h1in : min i j < a ∧ a ≤ max i j · have hb1 := hc1 a ha b hb h1in.1 h1in.2 hab by_cases h2in : min j k < a ∧ a ≤ max j k · -- a in both intervals -> impossible since a ∈ (min i k, max i k], wait: can a be in both? -- If a is in both, b is in both, which is ONLY outside (min i k, max i k] if b is in the overlap; -- wait: if j is outside [min i k, max i k], then (min i k, max i k] is the SYMMETRIC DIFFERENCE! -- So a ∈ (min i k, max i k] CANNOT be in BOTH (min i j, max i j] and (min j k, max j k]! omega · -- a is ONLY in (min i j, max i j], NOT in (min j k, max j k] -- Could b be in (min j k, max j k]? If so, by hc2 on (b, a), a would be in (min j k, max j k], contradiction! have hb_not2 : ¬ (min j k < b ∧ b ≤ max j k) := fun hb2 => h2in (hc2 b hb a ha hb2.1 hb2.2 (by rw [π.symm]; exact hab)) omega · have h2in : min j k < a ∧ a ≤ max j k := by omega have hb2 := hc2 a ha b hb h2in.1 h2in.2 hab have hb_not1 : ¬ (min i j < b ∧ b ≤ max i j) := fun hb1 => h1in (hc1 b hb a ha hb1.1 hb1.2 (by rw [π.symm]; exact hab)) omega nc a b c d hab hbc hcd hac hbd := by obtain ⟨ha, hc, hc1⟩ := of_decide_eq_true hac obtain ⟨hb, hd, hc2⟩ := of_decide_eq_true hbd rw [closedInterval_iff] at hc1 hc2 rw [min_eq_left (by omega : a ≤ c), max_eq_right (by omega : a ≤ c)] at hc1 rw [min_eq_left (by omega : b ≤ d), max_eq_right (by omega : b ≤ d)] at hc2 apply decide_eq_true refine ⟨ha, hb, (closedInterval_iff _ _ _).mpr ?_⟩ rw [min_eq_left (by omega : a ≤ b), max_eq_right (by omega : a ≤ b)] intro x hx y hy hxlo hxhi hxy have hy_ac := hc1 x hx y hy hxlo (by omega) hxy have hy_not_bd : ¬ (b < y ∧ y ≤ d) := fun hybd => by have hxbd := hc2 y hy x hx hybd.1 hybd.2 (by rw [π.symm]; exact hxy) omega omega lemma kreweras_rel_iff {n : ℕ} (π : NC n) (i j : ℕ) : (kreweras π).rel i j = true ↔ i < n ∧ j < n ∧ closedInterval π (min i j) (max i j) = true := decide_eq_true_iff /-- **Order-Reversing Property of Kreweras Complement:** `π ≤ σ → K(σ) ≤ K(π)`. -/ theorem kreweras_antitone {n : ℕ} {π σ : NC n} (h : π ≤ σ) : kreweras σ ≤ kreweras π := by intro i j hij obtain ⟨hi, hj, hc⟩ := (kreweras_rel_iff σ i j).mp hij rw [closedInterval_iff] at hc exact (kreweras_rel_iff π i j).mpr ⟨hi, hj, (closedInterval_iff _ _ _).mpr fun a ha b hb hlo hhi hab => hc a ha b hb hlo hhi (h a b hab)⟩ /-- Cyclic rotation by `-1 (mod n)`: `i ~' j` iff `(i + 1) % n ~ (j + 1) % n`. -/ def rotMinusOne {n : ℕ} (π : NC n) : NC n where rel i j := decide (i < n ∧ j < n ∧ π.rel ((i + 1) % n) ((j + 1) % n) = true) supp i j h := by have := of_decide_eq_true h; exact ⟨this.1, this.2.1⟩ refl i hi := decide_eq_true ⟨hi, hi, π.refl _ (Nat.mod_lt _ (by omega))⟩ symm i j := decide_eq_decide.mpr (by rw [π.symm]; tauto) trans i j k h1 h2 := by obtain ⟨hi, _, h1'⟩ := of_decide_eq_true h1 obtain ⟨_, hk, h2'⟩ := of_decide_eq_true h2 exact decide_eq_true ⟨hi, hk, π.trans _ _ _ h1' h2'⟩ nc a b c d hab hbc hcd hac hbd := by obtain ⟨ha, hc, hac'⟩ := of_decide_eq_true hac obtain ⟨hb, hd, hbd'⟩ := of_decide_eq_true hbd have ha' : (a + 1) % n = a + 1 := Nat.mod_eq_of_lt (by omega) have hb' : (b + 1) % n = b + 1 := Nat.mod_eq_of_lt (by omega) have hc' : (c + 1) % n = c + 1 := Nat.mod_eq_of_lt (by omega) rw [ha', hc'] at hac' rw [hb'] at hbd' apply decide_eq_true refine ⟨ha, hb, ?_⟩ rw [ha', hb'] by_cases hdn : d + 1 < n · rw [Nat.mod_eq_of_lt hdn] at hbd' exact π.nc (a + 1) (b + 1) (c + 1) (d + 1) (by omega) (by omega) (by omega) hac' hbd' · have hdeq : d + 1 = n := by omega rw [hdeq, Nat.mod_self] at hbd' have := π.nc 0 (a + 1) (b + 1) (c + 1) (by omega) (by omega) (by omega) (by rw [π.symm]; exact hbd') hac' exact π.trans _ _ _ (by rw [π.symm]; exact this) (by rw [π.symm]; exact hbd') lemma rotMinusOne_rel_iff {n : ℕ} (π : NC n) (i j : ℕ) : (rotMinusOne π).rel i j = true ↔ i < n ∧ j < n ∧ π.rel ((i + 1) % n) ((j + 1) % n) = true := decide_eq_true_iff /-- **Half of `K² = rot⁻¹`:** `rotMinusOne π ≤ K(K(π))` (direct witness proof). -/ theorem rotMinusOne_le_kreweras_sq {n : ℕ} (π : NC n) : rotMinusOne π ≤ kreweras (kreweras π) := by intro i j hij obtain ⟨hi, hj, hrel⟩ := (rotMinusOne_rel_iff π i j).mp hij rw [kreweras_rel_iff] refine ⟨hi, hj, (closedInterval_iff _ _ _).mpr ?_⟩ -- WLOG lo = min i j, hi' = max i j; if i = j then (lo, hi'] is empty intro a ha b hb hlo hhi hab by_contra hnot obtain ⟨_, _, hcl⟩ := (kreweras_rel_iff π a b).mp hab rw [closedInterval_iff] at hcl have hne : i ≠ j := by omega -- Swap so u < v with π.rel ((u+1)%n) ((v+1)%n) = true have huv : ∃ u v, u = min i j ∧ v = max i j ∧ u < v ∧ v < n ∧ π.rel ((u + 1) % n) ((v + 1) % n) = true := by by_cases hlt : i < j · exact ⟨i, j, (min_eq_left (le_of_lt hlt)).symm, (max_eq_right (le_of_lt hlt)).symm, hlt, hj, hrel⟩ · exact ⟨j, i, (min_eq_right (by omega)).symm, (max_eq_left (by omega)).symm, by omega, hi, by rw [π.symm]; exact hrel⟩ obtain ⟨u, v, hu_eq, hv_eq, huv_lt, hv_lt, hrel_uv⟩ := huv rw [← hu_eq] at hlo hnot rw [← hv_eq] at hhi hnot have hu1 : (u + 1) % n = u + 1 := Nat.mod_eq_of_lt (by omega) rw [hu1] at hrel_uv by_cases hbu : b ≤ u · -- b ≤ u < a ≤ v: min a b = b, max a b = a, and u + 1 ∈ (b, a] rw [min_eq_right (by omega : b ≤ a), max_eq_left (by omega : b ≤ a)] at hcl have hv_in := hcl (u + 1) (by omega) ((v + 1) % n) (Nat.mod_lt _ (by omega)) (by omega) (by omega) hrel_uv by_cases hvn : v + 1 < n · rw [Nat.mod_eq_of_lt hvn] at hv_in; omega · have : v + 1 = n := by omega rw [this, Nat.mod_self] at hv_in; omega · -- v < b (so v + 1 < n, and u < a ≤ v < b): min a b = a, max a b = b, and v + 1 ∈ (a, b] have hvb : v < b := by omega have hvn : v + 1 < n := by omega rw [Nat.mod_eq_of_lt hvn] at hrel_uv rw [min_eq_left (by omega : a ≤ b), max_eq_right (by omega : a ≤ b)] at hcl have hu_in := hcl (v + 1) hvn (u + 1) (by omega) (by omega) (by omega) (by rw [π.symm]; exact hrel_uv) omega /-- `i` is the largest element of its block. -/ def isMax {n : ℕ} (π : NC n) (i : ℕ) : Bool := decide (i < n ∧ ∀ k ∈ Finset.range n, i < k → π.rel i k = false) lemma isMax_iff {n : ℕ} (π : NC n) (i : ℕ) : π.isMax i = true ↔ i < n ∧ ∀ k, i < k → k < n → π.rel i k = false := by unfold isMax rw [decide_eq_true_iff] simp only [Finset.mem_range] exact and_congr_right fun _ => ⟨fun h k hik hkn => h k hkn hik, fun h k hkn hik => h k hik hkn⟩ /-- Count blocks via maximal elements. -/ def blockCountMax {n : ℕ} (π : NC n) : ℕ := ∑ i ∈ Finset.range n, if π.isMax i then 1 else 0 /-- Every block has a unique minimum and a unique maximum, so `blockCount π = blockCountMax π`. -/ lemma blockCount_eq_blockCountMax {n : ℕ} (π : NC n) : π.blockCount = π.blockCountMax := by -- Bijection between min-set and max-set on Finset.range n: -- map each i with isMin i to max {j < n | π.rel i j = true}, inverse maps j to min {i < n | π.rel i j = true}! let Smin := (Finset.range n).filter fun i => π.isMin i = true let Smax := (Finset.range n).filter fun i => π.isMax i = true have h1 : π.blockCount = Smin.card := by unfold blockCount Smin; rw [Finset.card_filter] have h2 : π.blockCountMax = Smax.card := by unfold blockCountMax Smax; rw [Finset.card_filter] rw [h1, h2] have hblk_ne : ∀ i < n, ((Finset.range n).filter fun j => π.rel i j = true).Nonempty := fun i hi => ⟨i, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hi, π.refl i hi⟩⟩ let toMax : ℕ → ℕ := fun i => if h : i < n then ((Finset.range n).filter fun j => π.rel i j = true).max' (hblk_ne i h) else 0 let toMin : ℕ → ℕ := fun j => if h : j < n then ((Finset.range n).filter fun i => π.rel i j = true).min' ⟨j, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr h, π.refl j h⟩⟩ else 0 refine Finset.card_bij (fun i _ => toMax i) ?_ ?_ ?_ · intro i hi obtain ⟨hi_r, hi_m⟩ := Finset.mem_filter.mp hi have hin : i < n := Finset.mem_range.mp hi_r simp only [Smax, Finset.mem_filter, Finset.mem_range, toMax, hin, ↓reduceDIte] set B := (Finset.range n).filter fun j => π.rel i j = true set m := B.max' (hblk_ne i hin) have hm_mem : m ∈ B := Finset.max'_mem B (hblk_ne i hin) obtain ⟨hm_r, hm_rel⟩ := Finset.mem_filter.mp hm_mem have hmn : m < n := Finset.mem_range.mp hm_r refine ⟨hmn, (isMax_iff π m).mpr ⟨hmn, fun k hmk hkn => ?_⟩⟩ cases hr : π.rel m k · rfl · have hkB : k ∈ B := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hkn, π.trans _ _ _ hm_rel hr⟩ have hle : k ≤ m := Finset.le_max' B k hkB omega · intro i1 hi1 i2 hi2 heq obtain ⟨hi1_r, hi1_m⟩ := Finset.mem_filter.mp hi1 obtain ⟨hi2_r, hi2_m⟩ := Finset.mem_filter.mp hi2 have h1n : i1 < n := Finset.mem_range.mp hi1_r have h2n : i2 < n := Finset.mem_range.mp hi2_r simp only [toMax, h1n, h2n, ↓reduceDIte] at heq have hm1 : π.rel i1 (((Finset.range n).filter fun j => π.rel i1 j = true).max' (hblk_ne i1 h1n)) = true := (Finset.mem_filter.mp (Finset.max'_mem ((Finset.range n).filter fun j => π.rel i1 j = true) (hblk_ne i1 h1n))).2 have hm2 : π.rel i2 (((Finset.range n).filter fun j => π.rel i2 j = true).max' (hblk_ne i2 h2n)) = true := (Finset.mem_filter.mp (Finset.max'_mem ((Finset.range n).filter fun j => π.rel i2 j = true) (hblk_ne i2 h2n))).2 rw [heq] at hm1 have hrel12 : π.rel i1 i2 = true := π.trans _ _ _ hm1 (by rw [π.symm]; exact hm2) have hm1' := of_decide_eq_true hi1_m have hm2' := of_decide_eq_true hi2_m by_contra hne rcases lt_or_gt_of_ne hne with hlt | hgt · have := hm2' i1 hlt; rw [hrel12] at this; exact Bool.false_ne_true this.symm · have := hm1' i2 hgt; rw [π.symm, hrel12] at this; exact Bool.false_ne_true this.symm · intro j hj obtain ⟨hj_r, hj_m⟩ := Finset.mem_filter.mp hj have hjn : j < n := Finset.mem_range.mp hj_r obtain ⟨_, hj_max⟩ := (isMax_iff π j).mp hj_m set B := (Finset.range n).filter fun i => π.rel i j = true have hBne : B.Nonempty := ⟨j, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hjn, π.refl j hjn⟩⟩ set m := B.min' hBne have hm_mem : m ∈ B := Finset.min'_mem B hBne obtain ⟨hm_r, hm_rel⟩ := Finset.mem_filter.mp hm_mem have hmn : m < n := Finset.mem_range.mp hm_r refine ⟨m, ?_, ?_⟩ · refine Finset.mem_filter.mpr ⟨hm_r, decide_eq_true fun k hkm => ?_⟩ cases hr : π.rel k m · rfl · have hkB : k ∈ B := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), π.trans _ _ _ hr hm_rel⟩ have hle : m ≤ k := Finset.min'_le B k hkB omega · simp only [toMax, hmn, ↓reduceDIte] set Bm := (Finset.range n).filter fun k => π.rel m k = true have hjBm : j ∈ Bm := Finset.mem_filter.mpr ⟨hj_r, hm_rel⟩ apply le_antisymm · apply Finset.max'_le intro k hk obtain ⟨hk_r, hk_rel⟩ := Finset.mem_filter.mp hk have hkn : k < n := Finset.mem_range.mp hk_r have hjk : π.rel j k = true := π.trans _ _ _ (by rw [π.symm]; exact hm_rel) hk_rel by_contra hgt have := hj_max k (by omega) hkn rw [hjk] at this; exact Bool.false_ne_true this.symm · exact Finset.le_max' Bm j hjBm /-- Key structural identity: `|K(prepend σ)| = |K(σ)|` for `m ≥ 1`. -/ lemma blockCount_kreweras_prepend {m : ℕ} (hm : 0 < m) (σ : NC m) : (kreweras (prepend σ)).blockCount = (kreweras σ).blockCount := by rw [blockCount_eq_blockCountMax, blockCount_eq_blockCountMax] unfold blockCountMax rw [Finset.sum_range_succ'] -- 0 is NOT max in K(prepend σ), because 0 ~ m (since (0, m] = {1..m} is closed in prepend σ)! have h0_not_max : (kreweras (prepend σ)).isMax 0 = false := by rw [Bool.eq_false_iff] intro hmax obtain ⟨_, h⟩ := (isMax_iff _ _).mp hmax have h0m := h m hm (by omega) have htrue : (kreweras (prepend σ)).rel 0 m = true := by rw [kreweras_rel_iff] refine ⟨by omega, by omega, (closedInterval_iff _ _ _).mpr ?_⟩ rw [min_eq_left (Nat.zero_le m), max_eq_right (Nat.zero_le m)] intro a ha b hb hlo hhi hab rw [prepend_rel] at hab rcases hab with ⟨ha0, _⟩ | ⟨_, hb1, _⟩ <;> omega rw [htrue] at h0m; exact absurd h0m (by decide) rw [h0_not_max, if_neg Bool.false_ne_true, add_zero] refine Finset.sum_congr rfl fun i hi => ?_ have him : i < m := Finset.mem_range.mp hi have hrel_eq : ∀ k, i < k → k < m → (kreweras (prepend σ)).rel (i + 1) (k + 1) = (kreweras σ).rel i k := by intro k hik hkm rw [Bool.eq_iff_iff, kreweras_rel_iff, kreweras_rel_iff, closedInterval_iff, closedInterval_iff] rw [min_eq_left (by omega : i + 1 ≤ k + 1), max_eq_right (by omega : i + 1 ≤ k + 1), min_eq_left (by omega : i ≤ k), max_eq_right (by omega : i ≤ k)] constructor · rintro ⟨_, _, hc⟩ refine ⟨him, hkm, fun a ha b hb hlo hhi hab => ?_⟩ have := hc (a + 1) (by omega) (b + 1) (by omega) (by omega) (by omega) (by rw [prepend_rel_succ]; exact hab) omega · rintro ⟨_, _, hc⟩ refine ⟨by omega, by omega, fun a ha b hb hlo hhi hab => ?_⟩ rw [prepend_rel] at hab rcases hab with ⟨ha0, _⟩ | ⟨ha1, hb1, hab'⟩ · omega · have := hc (a - 1) (by omega) (b - 1) (by omega) (by omega) (by omega) hab' omega have heq_b : (kreweras (prepend σ)).isMax (i + 1) = (kreweras σ).isMax i := by rw [Bool.eq_iff_iff, isMax_iff, isMax_iff] constructor · rintro ⟨_, h⟩ refine ⟨him, fun k hik hkm => ?_⟩ rw [← hrel_eq k hik hkm] exact h (k + 1) (by omega) (by omega) · rintro ⟨_, h⟩ refine ⟨by omega, fun k hik hkm => ?_⟩ obtain ⟨k', rfl⟩ : ∃ k', k = k' + 1 := ⟨k - 1, by omega⟩ rw [hrel_eq k' (by omega) (by omega)] exact h k' (by omega) (by omega) rw [heq_b] /-- Key structural identity: `|K(joinAt j a b)| = (if j = 0 then 1 else |K(a)|) + |K(b)|`. -/ lemma blockCount_kreweras_joinAt {m j : ℕ} (hj : j < m) (a : NC j) (b : NC (m - j)) : (kreweras (joinAt j hj a b)).blockCount = (if j = 0 then 1 else (kreweras a).blockCount) + (kreweras b).blockCount := by -- No cross-edges in K(joinAt j a b) between {0..j} and {j+1..m} because 0 ~ j+1! have hno_cross : ∀ u v, u ≤ j → j + 1 ≤ v → v ≤ m → (kreweras (joinAt j hj a b)).rel u v = false := by intro u v hu hv1 hv2 rw [Bool.eq_false_iff]; intro h obtain ⟨_, _, hc⟩ := (kreweras_rel_iff _ u v).mp h rw [closedInterval_iff, min_eq_left (by omega : u ≤ v), max_eq_right (by omega : u ≤ v)] at hc have h0 := hc (j + 1) (by omega) 0 (by omega) (by omega) (by omega) (by rw [(joinAt j hj a b).symm]; exact joinAt_rel_zero_link (hj := hj)) omega -- On {0..j}, K(joinAt j a b) agrees with K(prepend a)! have hleft_eq : ∀ u v, u ≤ j → v ≤ j → (kreweras (joinAt j hj a b)).rel u v = (kreweras (prepend a)).rel u v := by intro u v hu hv rw [Bool.eq_iff_iff, kreweras_rel_iff, kreweras_rel_iff, closedInterval_iff, closedInterval_iff] constructor · rintro ⟨_, _, hc⟩ refine ⟨by omega, by omega, fun x hx y hy hlo hhi hxy => ?_⟩ rw [prepend_rel] at hxy rcases hxy with ⟨hx0, _⟩ | ⟨hx1, hy1, hxy'⟩ · omega · exact hc x (by omega) y (by omega) hlo hhi ((joinAt_rel x y).mpr (Or.inl ⟨hx1, by omega, hy1, by omega, hxy'⟩)) · rintro ⟨_, _, hc⟩ refine ⟨by omega, by omega, fun x hx y hy hlo hhi hxy => ?_⟩ rw [joinAt_rel] at hxy rcases hxy with ⟨hx1, hxj, hy1, hyj, hxy'⟩ | ⟨hx0, _, _⟩ · exact hc x (by omega) y (by omega) hlo hhi ((prepend_rel _ x y).mpr (Or.inr ⟨hx1, hy1, hxy'⟩)) · omega -- On {j+1..m}, K(joinAt j a b) agrees with K(b) shifted by j+1! have hright_eq : ∀ x y, x < m - j → y < m - j → (kreweras (joinAt j hj a b)).rel (j + 1 + x) (j + 1 + y) = (kreweras b).rel x y := by intro x y hx hy rw [Bool.eq_iff_iff, kreweras_rel_iff, kreweras_rel_iff, closedInterval_iff, closedInterval_iff] have hmin : min (j + 1 + x) (j + 1 + y) = j + 1 + min x y := by omega have hmax : max (j + 1 + x) (j + 1 + y) = j + 1 + max x y := by omega rw [hmin, hmax] constructor · rintro ⟨_, _, hc⟩ refine ⟨hx, hy, fun p hp q hq hlo hhi hpq => ?_⟩ have := hc (j + 1 + p) (by omega) (j + 1 + q) (by omega) (by omega) (by omega) (by rw [joinAt_rel_out _ _ (Or.inr ⟨by omega, by omega⟩) (Or.inr ⟨by omega, by omega⟩), oIdx_pos (by omega), oIdx_pos (by omega), show j + 1 + p - (j + 1) = p by omega, show j + 1 + q - (j + 1) = q by omega] exact hpq) omega · rintro ⟨_, _, hc⟩ refine ⟨by omega, by omega, fun p hp q hq hlo hhi hpq => ?_⟩ rw [joinAt_rel] at hpq rcases hpq with ⟨_, _, _, _, _⟩ | ⟨_, hq_zone, hbrel⟩ · omega · rw [oIdx_pos (by omega)] at hbrel have hq_in := hc (p - (j + 1)) (by omega) (oIdx j q) (by rcases hq_zone with rfl | ⟨_, _⟩ · rw [oIdx_zero]; omega · rw [oIdx_pos (by omega)]; omega) (by omega) (by omega) hbrel rcases hq_zone with rfl | ⟨hq1, _⟩ · rw [oIdx_zero] at hq_in; omega · rw [oIdx_pos (by omega)] at hq_in; omega -- Now split blockCountMax of K(joinAt j a b) into [0..j] and [j+1..m]! rw [blockCount_eq_blockCountMax] unfold blockCountMax rw [← Finset.sum_range_add_sum_Ico _ (show j + 1 ≤ m + 1 by omega), Finset.sum_Ico_eq_sum_range, show m + 1 - (j + 1) = m - j by omega] have eLeft : ∑ i ∈ Finset.range (j + 1), (if (kreweras (joinAt j hj a b)).isMax i then 1 else 0) = (kreweras (prepend a)).blockCount := by rw [blockCount_eq_blockCountMax] unfold blockCountMax refine Finset.sum_congr rfl fun i hi => ?_ have hij : i ≤ j := by have := Finset.mem_range.mp hi; omega have heq_b : (kreweras (joinAt j hj a b)).isMax i = (kreweras (prepend a)).isMax i := by rw [Bool.eq_iff_iff, isMax_iff, isMax_iff] constructor · rintro ⟨_, h⟩ refine ⟨by omega, fun k hik hkj => ?_⟩ rw [← hleft_eq i k hij (by omega)] exact h k hik (by omega) · rintro ⟨_, h⟩ refine ⟨by omega, fun k hik hkm => ?_⟩ by_cases hkj : k ≤ j · rw [hleft_eq i k hij hkj]; exact h k hik (by omega) · exact hno_cross i k hij (by omega) (by omega) rw [heq_b] have eRight : ∑ k ∈ Finset.range (m - j), (if (kreweras (joinAt j hj a b)).isMax (j + 1 + k) then 1 else 0) = (kreweras b).blockCount := by rw [blockCount_eq_blockCountMax] unfold blockCountMax refine Finset.sum_congr rfl fun k hk => ?_ have hkm : k < m - j := Finset.mem_range.mp hk have heq_b : (kreweras (joinAt j hj a b)).isMax (j + 1 + k) = (kreweras b).isMax k := by rw [Bool.eq_iff_iff, isMax_iff, isMax_iff] constructor · rintro ⟨_, h⟩ refine ⟨hkm, fun l hkl hlm => ?_⟩ rw [← hright_eq k l hkm hlm] exact h (j + 1 + l) (by omega) (by omega) · rintro ⟨_, h⟩ refine ⟨by omega, fun l hkl hlm => ?_⟩ have hl : l = j + 1 + (l - (j + 1)) := by omega rw [hl, hright_eq k (l - (j + 1)) hkm (by omega)] exact h (l - (j + 1)) (by omega) (by omega) rw [heq_b] rw [eLeft, eRight] congr 1 by_cases hj0 : j = 0 · subst hj0 simp only [↓reduceIte] have h1 : (kreweras (prepend a)).blockCount = 1 := by unfold blockCount rw [Finset.sum_range_one, isMin_zero]; rfl exact h1 · simp only [hj0, ↓reduceIte] exact blockCount_kreweras_prepend (Nat.pos_of_ne_zero hj0) a /-- **Exact Kreweras Rank Identity:** `|π| + |K(π)| = n + 1` for all `n ≥ 1` and `π ∈ NC(n)`. -/ theorem blockCount_add_kreweras {n : ℕ} (hn : 0 < n) (π : NC n) : π.blockCount + (kreweras π).blockCount = n + 1 := by induction n using Nat.strong_induction_on with | _ n ih => rcases n with _ | m · omega · rcases m with _ | m' · -- n = 1 have h1 : π.blockCount = 1 := by unfold blockCount; rw [Finset.sum_range_one, isMin_zero]; rfl have h2 : (kreweras π).blockCount = 1 := by unfold blockCount; rw [Finset.sum_range_one, isMin_zero]; rfl omega · cases hfl : firstLink π with | none => have heq := prepend_window π ((firstLink_eq_none _).mp hfl) rw [← heq, blockCount_prepend, blockCount_kreweras_prepend (by omega)] have := ih (m' + 1) (by omega) (by omega) (window π 1 (m' + 1) (by omega)) omega | some j => have hspec := (firstLink_eq_some _ _).mp hfl have heq := joinAt_window j.1 j.2 π hspec.1 hspec.2 rw [← heq, blockCount_joinAt, blockCount_kreweras_joinAt] have hB := ih (m' + 1 - j.1) (by omega) (by omega) (window π (j.1 + 1) (m' + 1 - j.1) (by omega)) by_cases hj0 : j.1 = 0 · have hA0 : (window π 1 j.1 (by omega)).blockCount = 0 := by unfold blockCount; simp [hj0] rw [if_pos hj0, hA0] omega · simp only [hj0, ↓reduceIte] have hA := ih j.1 (by omega) (Nat.pos_of_ne_zero hj0) (window π 1 j.1 (by omega)) have hjlt : j.1 < m' + 1 := j.2 omega /-- In `NC(n)`, if `α ≤ β` and `|α| = |β|`, then `α = β`. -/ lemma eq_of_le_of_blockCount_eq {n : ℕ} {α β : NC n} (hle : α ≤ β) (hcard : α.blockCount = β.blockCount) : α = β := by by_contra hne -- Find x < y < n with α.rel x y = false and β.rel x y = true have hex : ∃ x y, x < y ∧ y < n ∧ α.rel x y = false ∧ β.rel x y = true := by by_contra hall push Not at hall apply hne apply ext' intro i j hi hj cases ha : α.rel i j · cases hb : β.rel i j · rfl · exfalso by_cases hij : i = j · subst hij; rw [α.refl i hi] at ha; exact absurd ha (by decide) · rcases lt_or_gt_of_ne hij with hlt | hgt · exact absurd hb (hall i j hlt hj ha) · rw [α.symm] at ha; rw [β.symm] at hb exact absurd hb (hall j i hgt hi ha) · exact (hle i j ha).symm obtain ⟨x, y, hxy, hyn, hαxy, hβxy⟩ := hex -- Let m = min of α-block of y; then α.isMin m = true, while β.isMin m = false (Wait: what if m ≤ x?) -- Better: let mx = min of α-block of x, my = min of α-block of y. -- Since α.rel x y = false, mx ≠ my, yet β.rel mx my = true! So max(mx, my) has α.isMin = true and β.isMin = false! have hmin_blk : ∀ u < n, ∃ m < n, α.isMin m = true ∧ α.rel m u = true := by intro u hu set B := (Finset.range n).filter fun k => α.rel k u = true have hneB : B.Nonempty := ⟨u, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hu, α.refl u hu⟩⟩ set m := B.min' hneB obtain ⟨hmr, hmu⟩ := Finset.mem_filter.mp (Finset.min'_mem B hneB) refine ⟨m, Finset.mem_range.mp hmr, decide_eq_true fun k hkm => ?_, hmu⟩ cases hk : α.rel k m · rfl · have hkB : k ∈ B := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by have := Finset.mem_range.mp hmr; omega), α.trans _ _ _ hk hmu⟩ have := Finset.min'_le B k hkB; omega obtain ⟨mx, hmxn, hmx_min, hmx_rel⟩ := hmin_blk x (by omega) obtain ⟨my, hmyn, hmy_min, hmy_rel⟩ := hmin_blk y hyn have hmne : mx ≠ my := by intro heq; subst heq have := α.trans _ _ _ (by rw [α.symm]; exact hmx_rel) hmy_rel rw [hαxy] at this; exact absurd this (by decide) have hβ_m : β.rel mx my = true := β.trans _ _ _ (hle _ _ hmx_rel) (β.trans _ _ _ hβxy (hle _ _ (by rw [α.symm]; exact hmy_rel))) -- Pick w = max mx my: α.isMin w = true, β.isMin w = false! have hw : ∃ w < n, α.isMin w = true ∧ β.isMin w = false := by rcases lt_or_gt_of_ne hmne with hlt | hgt · refine ⟨my, hmyn, hmy_min, ?_⟩ unfold isMin; rw [decide_eq_false_iff_not]; intro h have := h mx hlt; rw [hβ_m] at this; exact absurd this (by decide) · refine ⟨mx, hmxn, hmx_min, ?_⟩ unfold isMin; rw [decide_eq_false_iff_not]; intro h have := h my hgt; rw [β.symm, hβ_m] at this; exact absurd this (by decide) obtain ⟨w, hwn, hwα, hwβ⟩ := hw -- Every β.isMin is an α.isMin (since α ≤ β), so β.blockCount < α.blockCount! have hsub_le : ∀ i ∈ Finset.range n, (if β.isMin i = true then 1 else 0) ≤ (if α.isMin i = true then 1 else 0) := by intro i _ by_cases hbi : β.isMin i = true · have hai : α.isMin i = true := decide_eq_true fun k hki => by cases hak : α.rel k i · rfl · have := of_decide_eq_true hbi k hki rw [hle k i hak] at this; exact absurd this (by decide) simp [hbi, hai] · simp [hbi] have hlt : β.blockCount < α.blockCount := Finset.sum_lt_sum hsub_le ⟨w, Finset.mem_range.mpr hwn, by simp [hwα, hwβ]⟩ omega /-- `rotMinusOne` preserves `blockCount`. -/ lemma blockCount_rotMinusOne {n : ℕ} (π : NC n) : (rotMinusOne π).blockCount = π.blockCount := by rcases n with _ | m · simp [blockCount] · -- rotMinusOne is a bijection on blocks! Explicitly: if m = 0 then both = 1; -- in general, the unique element of each block of π with minimum image under `x ↦ (x + m) % (m + 1)` -- maps bijectively to the unique `isMin` of that block in π! let S1 := (Finset.range (m + 1)).filter fun i => (rotMinusOne π).isMin i = true let S2 := (Finset.range (m + 1)).filter fun i => π.isMin i = true have h1 : (rotMinusOne π).blockCount = S1.card := by unfold blockCount S1; rw [Finset.card_filter] have h2 : π.blockCount = S2.card := by unfold blockCount S2; rw [Finset.card_filter] rw [h1, h2] let f : ℕ → ℕ := fun i => if h : i < m + 1 then ((Finset.range (m + 1)).filter fun k => π.rel k ((i + 1) % (m + 1)) = true).min' ⟨(i + 1) % (m + 1), Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (Nat.mod_lt _ (Nat.succ_pos m)), π.refl _ (Nat.mod_lt _ (Nat.succ_pos m))⟩⟩ else 0 refine Finset.card_bij (fun i _ => f i) ?_ ?_ ?_ · intro i hi obtain ⟨hir, _⟩ := Finset.mem_filter.mp hi have hin : i < m + 1 := Finset.mem_range.mp hir simp only [S2, Finset.mem_filter, Finset.mem_range, f, hin, ↓reduceDIte] set B := (Finset.range (m + 1)).filter fun k => π.rel k ((i + 1) % (m + 1)) = true have hneB : B.Nonempty := ⟨(i + 1) % (m + 1), Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (Nat.mod_lt _ (Nat.succ_pos m)), π.refl _ (Nat.mod_lt _ (Nat.succ_pos m))⟩⟩ set r := B.min' hneB obtain ⟨hrr, hr_rel⟩ := Finset.mem_filter.mp (Finset.min'_mem B hneB) refine ⟨Finset.mem_range.mp hrr, decide_eq_true fun k hkr => ?_⟩ cases hkr' : π.rel k r · rfl · have hkB : k ∈ B := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by have := Finset.mem_range.mp hrr; omega), π.trans _ _ _ hkr' hr_rel⟩ have := Finset.min'_le B k hkB; omega · intro i1 hi1 i2 hi2 heq obtain ⟨hi1r, hi1m⟩ := Finset.mem_filter.mp hi1 obtain ⟨hi2r, hi2m⟩ := Finset.mem_filter.mp hi2 have h1n : i1 < m + 1 := Finset.mem_range.mp hi1r have h2n : i2 < m + 1 := Finset.mem_range.mp hi2r simp only [f, h1n, h2n, ↓reduceDIte] at heq have hne1 : ((Finset.range (m + 1)).filter fun k => π.rel k ((i1 + 1) % (m + 1)) = true).Nonempty := ⟨(i1 + 1) % (m + 1), Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (Nat.mod_lt _ (Nat.succ_pos m)), π.refl _ (Nat.mod_lt _ (Nat.succ_pos m))⟩⟩ have hne2 : ((Finset.range (m + 1)).filter fun k => π.rel k ((i2 + 1) % (m + 1)) = true).Nonempty := ⟨(i2 + 1) % (m + 1), Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (Nat.mod_lt _ (Nat.succ_pos m)), π.refl _ (Nat.mod_lt _ (Nat.succ_pos m))⟩⟩ have hr1 := (Finset.mem_filter.mp (Finset.min'_mem ((Finset.range (m + 1)).filter fun k => π.rel k ((i1 + 1) % (m + 1)) = true) hne1)).2 have hr2 := (Finset.mem_filter.mp (Finset.min'_mem ((Finset.range (m + 1)).filter fun k => π.rel k ((i2 + 1) % (m + 1)) = true) hne2)).2 rw [heq] at hr1 have hrel : (rotMinusOne π).rel i1 i2 = true := (rotMinusOne_rel_iff π i1 i2).mpr ⟨h1n, h2n, π.trans _ _ _ (by rw [π.symm]; exact hr1) hr2⟩ by_contra hne rcases lt_or_gt_of_ne hne with hlt | hgt · have := of_decide_eq_true hi2m i1 hlt rw [hrel] at this; exact absurd this (by decide) · have := of_decide_eq_true hi1m i2 hgt rw [(rotMinusOne π).symm, hrel] at this; exact absurd this (by decide) · intro r hr obtain ⟨hrr, hrm⟩ := Finset.mem_filter.mp hr have hrn : r < m + 1 := Finset.mem_range.mp hrr set Br := (Finset.range (m + 1)).filter fun i => π.rel r ((i + 1) % (m + 1)) = true have hneBr : Br.Nonempty := by refine ⟨(r + m) % (m + 1), Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (Nat.mod_lt _ (Nat.succ_pos m)), ?_⟩⟩ have hmod : ((r + m) % (m + 1) + 1) % (m + 1) = r := by rw [Nat.mod_add_mod, show r + m + 1 = r + (m + 1) by omega, Nat.add_mod_right, Nat.mod_eq_of_lt hrn] rw [hmod]; exact π.refl r hrn set i0 := Br.min' hneBr obtain ⟨hi0r, hi0_rel⟩ := Finset.mem_filter.mp (Finset.min'_mem Br hneBr) have hi0n : i0 < m + 1 := Finset.mem_range.mp hi0r refine ⟨i0, ?_, ?_⟩ · refine Finset.mem_filter.mpr ⟨hi0r, decide_eq_true fun k hki => ?_⟩ cases hk : (rotMinusOne π).rel k i0 · rfl · obtain ⟨_, _, hk'⟩ := (rotMinusOne_rel_iff π k i0).mp hk have hkBr : k ∈ Br := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), π.trans _ _ _ hi0_rel (by rw [π.symm]; exact hk')⟩ have := Finset.min'_le Br k hkBr; omega · simp only [f, hi0n, ↓reduceDIte] set Bi := (Finset.range (m + 1)).filter fun k => π.rel k ((i0 + 1) % (m + 1)) = true have hrBi : r ∈ Bi := Finset.mem_filter.mpr ⟨hrr, hi0_rel⟩ apply le_antisymm (Finset.min'_le Bi r hrBi) apply Finset.le_min' Bi intro k hk obtain ⟨_, hk_rel⟩ := Finset.mem_filter.mp hk have hkr : π.rel k r = true := π.trans _ _ _ hk_rel (by rw [π.symm]; exact hi0_rel) by_contra hlt have := of_decide_eq_true hrm k (by omega) rw [hkr] at this; exact absurd this (by decide) /-- **Exact Kreweras Involution / Rotation Identity:** `K(K(π)) = rotMinusOne π` (cyclic rotation by `-1 mod n`) for all `n` and `π ∈ NC(n)`. -/ theorem kreweras_sq_eq_rot {n : ℕ} (π : NC n) : kreweras (kreweras π) = rotMinusOne π := by rcases n with _ | m · exact ext' fun _ _ hi => absurd hi (Nat.not_lt_zero _) · symm apply eq_of_le_of_blockCount_eq (rotMinusOne_le_kreweras_sq π) have h1 := blockCount_add_kreweras (Nat.succ_pos m) π have h2 := blockCount_add_kreweras (Nat.succ_pos m) (kreweras π) have h3 := blockCount_rotMinusOne π omega /-- Inverse cyclic rotation `rotPlusOne` by `+1 mod n`. -/ def rotPlusOne {n : ℕ} (π : NC n) : NC n where rel i j := decide (i < n ∧ j < n ∧ π.rel ((i + n - 1) % n) ((j + n - 1) % n) = true) supp i j h := by have := of_decide_eq_true h; exact ⟨this.1, this.2.1⟩ refl i hi := decide_eq_true ⟨hi, hi, π.refl _ (Nat.mod_lt _ (by omega))⟩ symm i j := decide_eq_decide.mpr (by rw [π.symm]; tauto) trans i j k h1 h2 := by obtain ⟨hi, _, h1'⟩ := of_decide_eq_true h1 obtain ⟨_, hk, h2'⟩ := of_decide_eq_true h2 exact decide_eq_true ⟨hi, hk, π.trans _ _ _ h1' h2'⟩ nc a b c d hab hbc hcd hac hbd := by obtain ⟨ha, hc, hac'⟩ := of_decide_eq_true hac obtain ⟨hb, hd, hbd'⟩ := of_decide_eq_true hbd have hmod_pos : ∀ x, 0 < x → x < n → (x + n - 1) % n = x - 1 := by intro x hx1 hx2 rw [show x + n - 1 = (x - 1) + n by omega, Nat.add_mod_right, Nat.mod_eq_of_lt (by omega)] have hb' := hmod_pos b (by omega) hb have hc' := hmod_pos c (by omega) hc have hd' := hmod_pos d (by omega) hd rw [hb', hd'] at hbd' rw [hc'] at hac' apply decide_eq_true refine ⟨ha, hb, ?_⟩ rw [hb'] by_cases ha0 : a = 0 · subst ha0 have h0 : (0 + n - 1) % n = n - 1 := by rw [Nat.zero_add]; exact Nat.mod_eq_of_lt (by omega) rw [h0] at hac' ⊢ have := π.nc (b - 1) (c - 1) (d - 1) (n - 1) (by omega) (by omega) (by omega) hbd' (by rw [π.symm]; exact hac') exact π.trans _ _ _ hac' (by rw [π.symm]; exact this) · have ha' := hmod_pos a (by omega) ha rw [ha'] at hac' ⊢ exact π.nc (a - 1) (b - 1) (c - 1) (d - 1) (by omega) (by omega) (by omega) hac' hbd' lemma rotPlusOne_rotMinusOne {n : ℕ} (π : NC n) : rotPlusOne (rotMinusOne π) = π := by apply ext' intro i j hi hj rw [Bool.eq_iff_iff] simp only [rotPlusOne, rotMinusOne, decide_eq_true_eq] have hmod : ∀ x < n, ((x + n - 1) % n + 1) % n = x := by intro x hx have h1 : (x + n - 1) + 1 = x + n := by omega rw [Nat.mod_add_mod, h1, Nat.add_mod_right, Nat.mod_eq_of_lt hx] have hlt : ∀ x < n, (x + n - 1) % n < n := fun x hx => Nat.mod_lt _ (by omega) simp [hi, hj, hlt, hmod] lemma rotMinusOne_rotPlusOne {n : ℕ} (π : NC n) : rotMinusOne (rotPlusOne π) = π := by apply ext' intro i j hi hj rw [Bool.eq_iff_iff] simp only [rotPlusOne, rotMinusOne, decide_eq_true_eq] have hmod : ∀ x < n, ((x + 1) % n + n - 1) % n = x := by intro x hx by_cases hx1 : x + 1 < n · rw [Nat.mod_eq_of_lt hx1, show x + 1 + n - 1 = x + n by omega, Nat.add_mod_right, Nat.mod_eq_of_lt hx] · have : x + 1 = n := by omega rw [this, Nat.mod_self, show 0 + n - 1 = x by omega, Nat.mod_eq_of_lt hx] have hlt : ∀ x < n, (x + 1) % n < n := fun x hx => Nat.mod_lt _ (by omega) simp [hi, hj, hlt, hmod] lemma rotPlusOne_monotone {n : ℕ} {π σ : NC n} (h : π ≤ σ) : rotPlusOne π ≤ rotPlusOne σ := by intro i j hij simp only [rotPlusOne, decide_eq_true_eq] at hij ⊢ exact ⟨hij.1, hij.2.1, h _ _ hij.2.2⟩ lemma rotMinusOne_monotone {n : ℕ} {π σ : NC n} (h : π ≤ σ) : rotMinusOne π ≤ rotMinusOne σ := by intro i j hij simp only [rotMinusOne, decide_eq_true_eq] at hij ⊢ exact ⟨hij.1, hij.2.1, h _ _ hij.2.2⟩ /-- **Kreweras Complement is an Exact Order-Reversing Lattice Bijection:** `NC n ≃o (NC n)ᵒᵈ`. -/ def krewerasOrderIso (n : ℕ) : NC n ≃o (NC n)ᵒᵈ where toFun π := OrderDual.toDual (kreweras π) invFun σ := rotPlusOne (kreweras (OrderDual.ofDual σ)) left_inv π := by show rotPlusOne (kreweras (kreweras π)) = π rw [kreweras_sq_eq_rot, rotPlusOne_rotMinusOne] right_inv σ := by change OrderDual.toDual (kreweras (rotPlusOne (kreweras (OrderDual.ofDual σ)))) = σ have hcomm : ∀ τ : NC n, kreweras (rotPlusOne τ) = rotPlusOne (kreweras τ) := by intro τ have h1 : rotMinusOne (kreweras (rotPlusOne τ)) = kreweras τ := by calc rotMinusOne (kreweras (rotPlusOne τ)) = kreweras (kreweras (kreweras (rotPlusOne τ))) := (kreweras_sq_eq_rot _).symm _ = kreweras (rotMinusOne (rotPlusOne τ)) := by rw [kreweras_sq_eq_rot (rotPlusOne τ)] _ = kreweras τ := by rw [rotMinusOne_rotPlusOne] calc kreweras (rotPlusOne τ) = rotPlusOne (rotMinusOne (kreweras (rotPlusOne τ))) := (rotPlusOne_rotMinusOne _).symm _ = rotPlusOne (kreweras τ) := by rw [h1] rw [hcomm, kreweras_sq_eq_rot, rotPlusOne_rotMinusOne] rfl map_rel_iff' := by intro π σ change kreweras σ ≤ kreweras π ↔ π ≤ σ constructor · intro h have h2 := kreweras_antitone h rw [kreweras_sq_eq_rot, kreweras_sq_eq_rot] at h2 have h3 := rotPlusOne_monotone h2 rwa [rotPlusOne_rotMinusOne, rotPlusOne_rotMinusOne] at h3 · exact kreweras_antitone theorem kreweras_bijective (n : ℕ) : Function.Bijective (kreweras (n := n)) := (krewerasOrderIso n).bijective /-! ### Exact `NC₂(2m)` Non-Crossing Pairing Enumeration -/ /-- Block size of element `i` in `π`. -/ def blockSize {n : ℕ} (π : NC n) (i : ℕ) : ℕ := ((Finset.range n).filter fun j => π.rel i j = true).card /-- The block of `i` in `π` as a `Finset ℕ`. -/ def blockFinset {n : ℕ} (π : NC n) (i : ℕ) : Finset ℕ := (Finset.range n).filter fun j => π.rel i j = true /-- The set of minimal representatives (roots) of blocks of `π`. -/ def rootSet {n : ℕ} (π : NC n) : Finset ℕ := (Finset.range n).filter fun i => π.isMin i = true /-- Pull back a partition `π : NC n` to an ordered subset `S : Finset ℕ` (`∀ x ∈ S, x < n`). -/ def restrictSet {n : ℕ} (π : NC n) (S : Finset ℕ) (hS : ∀ x ∈ S, x < n) : NC S.card where rel i j := if h : i < S.card ∧ j < S.card then π.rel (S.orderEmbOfFin rfl ⟨i, h.1⟩) (S.orderEmbOfFin rfl ⟨j, h.2⟩) else false supp i j hr := by split_ifs at hr with h; exact h refl i hi := by rw [dif_pos ⟨hi, hi⟩] exact π.refl _ (hS _ (S.orderEmbOfFin_mem rfl ⟨i, hi⟩)) symm i j := by by_cases h : i < S.card ∧ j < S.card · rw [dif_pos h, dif_pos ⟨h.2, h.1⟩, π.symm] · rw [dif_neg h, dif_neg (fun h' => h ⟨h'.2, h'.1⟩)] trans i j k h1 h2 := by split_ifs at h1 h2 with ha hb rw [dif_pos ⟨ha.1, hb.2⟩] exact π.trans _ _ _ h1 h2 nc a b c d hab hbc hcd hac hbd := by split_ifs at hac hbd with ha hb rw [dif_pos ⟨ha.1, hb.1⟩] let e := S.orderEmbOfFin rfl have h1 : S.orderEmbOfFin rfl ⟨a, ha.1⟩ < S.orderEmbOfFin rfl ⟨b, hb.1⟩ := e.strictMono (Fin.mk_lt_mk.mpr hab) have h2 : S.orderEmbOfFin rfl ⟨b, hb.1⟩ < S.orderEmbOfFin rfl ⟨c, ha.2⟩ := e.strictMono (Fin.mk_lt_mk.mpr hbc) have h3 : S.orderEmbOfFin rfl ⟨c, ha.2⟩ < S.orderEmbOfFin rfl ⟨d, hb.2⟩ := e.strictMono (Fin.mk_lt_mk.mpr hcd) exact π.nc _ _ _ _ h1 h2 h3 hac hbd lemma restrictSet_rel {n : ℕ} (π : NC n) (S : Finset ℕ) (hS : ∀ x ∈ S, x < n) (i j : ℕ) (hi : i < S.card) (hj : j < S.card) : (π.restrictSet S hS).rel i j = π.rel (S.orderEmbOfFin rfl ⟨i, hi⟩) (S.orderEmbOfFin rfl ⟨j, hj⟩) := dif_pos ⟨hi, hj⟩ /-- Unique block root of `i < n` in `σ : NC n`. -/ def rootOf {n : ℕ} (σ : NC n) (i : ℕ) : ℕ := if h : i < n then (σ.blockFinset i).min' ⟨i, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr h, σ.refl i h⟩⟩ else 0 lemma rootOf_mem_rootSet {n : ℕ} (σ : NC n) {i : ℕ} (hi : i < n) : σ.rootOf i ∈ σ.rootSet := by simp only [rootOf, hi, ↓reduceDIte, rootSet, Finset.mem_filter, Finset.mem_range] set B := σ.blockFinset i have hne : B.Nonempty := ⟨i, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hi, σ.refl i hi⟩⟩ set r := B.min' hne obtain ⟨hrr, hri⟩ := Finset.mem_filter.mp (Finset.min'_mem B hne) refine ⟨Finset.mem_range.mp hrr, decide_eq_true fun k hkr => ?_⟩ cases hk : σ.rel k r · rfl · have hkB : k ∈ B := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by have := Finset.mem_range.mp hrr; omega), σ.trans _ _ _ hri (by rw [σ.symm]; exact hk)⟩ have := Finset.min'_le B k hkB; omega lemma rootOf_rel {n : ℕ} (σ : NC n) {i : ℕ} (hi : i < n) : σ.rel (σ.rootOf i) i = true := by simp only [rootOf, hi, ↓reduceDIte] rw [σ.symm] exact (Finset.mem_filter.mp (Finset.min'_mem (σ.blockFinset i) _)).2 lemma rootOf_eq_iff {n : ℕ} (σ : NC n) {i j : ℕ} (hi : i < n) (hj : j < n) : σ.rootOf i = σ.rootOf j ↔ σ.rel i j = true := by constructor · intro heq have h1 := σ.rootOf_rel hi have h2 := σ.rootOf_rel hj rw [heq] at h1 exact σ.trans _ _ _ (by rw [σ.symm]; exact h1) h2 · intro hij simp only [rootOf, hi, hj, ↓reduceDIte] have hB : σ.blockFinset i = σ.blockFinset j := by ext k; simp only [blockFinset, Finset.mem_filter] exact and_congr_right fun _ => ⟨fun h => σ.trans _ _ _ (by rw [σ.symm]; exact hij) h, fun h => σ.trans _ _ _ hij h⟩ simp only [hB] lemma mem_blockFinset_rootOf {n : ℕ} (σ : NC n) {i : ℕ} (hi : i < n) : i ∈ σ.blockFinset (σ.rootOf i) := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hi, σ.rootOf_rel hi⟩ lemma blockFinset_lt {n : ℕ} (σ : NC n) (r : ℕ) : ∀ x ∈ σ.blockFinset r, x < n := fun _ hx => Finset.mem_range.mp (Finset.mem_filter.mp hx).1 /-- Glue independent partitions on each block of `σ` into a partition `≤ σ`. -/ noncomputable def glueOnBlocks {n : ℕ} (σ : NC n) (f : ∀ r : σ.rootSet, NC (σ.blockFinset r.1).card) : NC n where rel i j := if h : i < n ∧ j < n ∧ σ.rel i j = true then let r : σ.rootSet := ⟨σ.rootOf i, σ.rootOf_mem_rootSet h.1⟩ let e := (σ.blockFinset r.1).orderIsoOfFin rfl let idx_i := (e.symm ⟨i, σ.mem_blockFinset_rootOf h.1⟩).1 let idx_j := (e.symm ⟨j, by have hr := (σ.rootOf_eq_iff h.1 h.2.1).mpr h.2.2 change j ∈ σ.blockFinset (σ.rootOf i) rw [hr]; exact σ.mem_blockFinset_rootOf h.2.1⟩).1 (f r).rel idx_i idx_j else false supp i j hr := by split_ifs at hr with h; exact ⟨h.1, h.2.1⟩ refl i hi := by rw [dif_pos ⟨hi, hi, σ.refl i hi⟩] exact (f _).refl _ (Fin.isLt _) symm i j := by by_cases h : i < n ∧ j < n ∧ σ.rel i j = true · have h' : j < n ∧ i < n ∧ σ.rel j i = true := ⟨h.2.1, h.1, by rw [σ.symm]; exact h.2.2⟩ rw [dif_pos h, dif_pos h'] have hr : (⟨σ.rootOf i, σ.rootOf_mem_rootSet h.1⟩ : σ.rootSet) = ⟨σ.rootOf j, σ.rootOf_mem_rootSet h.2.1⟩ := Subtype.ext ((σ.rootOf_eq_iff h.1 h.2.1).mpr h.2.2) have : ∀ (r1 r2 : σ.rootSet) (hreq : r1 = r2) (hi1 : i ∈ σ.blockFinset r1.1) (hj1 : j ∈ σ.blockFinset r1.1) (hj2 : j ∈ σ.blockFinset r2.1) (hi2 : i ∈ σ.blockFinset r2.1), (f r1).rel (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨i, hi1⟩).1 (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨j, hj1⟩).1 = (f r2).rel (((σ.blockFinset r2.1).orderIsoOfFin rfl).symm ⟨j, hj2⟩).1 (((σ.blockFinset r2.1).orderIsoOfFin rfl).symm ⟨i, hi2⟩).1 := by rintro r1 _ rfl hi1 hj1 hj2 hi2; exact (f r1).symm _ _ exact this _ _ hr _ _ _ _ · have h' : ¬ (j < n ∧ i < n ∧ σ.rel j i = true) := fun h' => h ⟨h'.2.1, h'.1, by rw [σ.symm]; exact h'.2.2⟩ rw [dif_neg h, dif_neg h'] trans i j k h1 h2 := by split_ifs at h1 h2 with ha hb have hσik : σ.rel i k = true := σ.trans _ _ _ ha.2.2 hb.2.2 rw [dif_pos ⟨ha.1, hb.2.1, hσik⟩] have hr : (⟨σ.rootOf i, σ.rootOf_mem_rootSet ha.1⟩ : σ.rootSet) = ⟨σ.rootOf j, σ.rootOf_mem_rootSet ha.2.1⟩ := Subtype.ext ((σ.rootOf_eq_iff ha.1 ha.2.1).mpr ha.2.2) have haux : ∀ (r1 r2 : σ.rootSet) (hreq : r1 = r2) (hi1 : i ∈ σ.blockFinset r1.1) (hj1 : j ∈ σ.blockFinset r1.1) (hk1 : k ∈ σ.blockFinset r1.1) (hj2 : j ∈ σ.blockFinset r2.1) (hk2 : k ∈ σ.blockFinset r2.1), (f r1).rel (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨i, hi1⟩).1 (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨j, hj1⟩).1 = true → (f r2).rel (((σ.blockFinset r2.1).orderIsoOfFin rfl).symm ⟨j, hj2⟩).1 (((σ.blockFinset r2.1).orderIsoOfFin rfl).symm ⟨k, hk2⟩).1 = true → (f r1).rel (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨i, hi1⟩).1 (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨k, hk1⟩).1 = true := by rintro r1 _ rfl _ _ _ _ _ p q; exact (f r1).trans _ _ _ p q exact haux _ _ hr _ _ _ _ _ h1 h2 nc a b c d hab hbc hcd hac hbd := by split_ifs at hac hbd with ha hb have hσab : σ.rel a b = true := σ.nc a b c d hab hbc hcd ha.2.2 hb.2.2 rw [dif_pos ⟨ha.1, hb.1, hσab⟩] have hr : (⟨σ.rootOf a, σ.rootOf_mem_rootSet ha.1⟩ : σ.rootSet) = ⟨σ.rootOf b, σ.rootOf_mem_rootSet hb.1⟩ := Subtype.ext ((σ.rootOf_eq_iff ha.1 hb.1).mpr hσab) have haux : ∀ (r1 r2 : σ.rootSet) (hreq : r1 = r2) (ha1 : a ∈ σ.blockFinset r1.1) (hb1 : b ∈ σ.blockFinset r1.1) (hc1 : c ∈ σ.blockFinset r1.1) (hd1 : d ∈ σ.blockFinset r1.1) (hb2 : b ∈ σ.blockFinset r2.1) (hd2 : d ∈ σ.blockFinset r2.1), (f r1).rel (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨a, ha1⟩).1 (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨c, hc1⟩).1 = true → (f r2).rel (((σ.blockFinset r2.1).orderIsoOfFin rfl).symm ⟨b, hb2⟩).1 (((σ.blockFinset r2.1).orderIsoOfFin rfl).symm ⟨d, hd2⟩).1 = true → (f r1).rel (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨a, ha1⟩).1 (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨b, hb1⟩).1 = true := by rintro r1 _ rfl ha1 hb1 hc1 hd1 _ _ p q let e := ((σ.blockFinset r1.1).orderIsoOfFin rfl).symm exact (f r1).nc _ _ _ _ (Fin.lt_def.mp (e.strictMono (Subtype.mk_lt_mk.mpr hab))) (Fin.lt_def.mp (e.strictMono (Subtype.mk_lt_mk.mpr hbc))) (Fin.lt_def.mp (e.strictMono (Subtype.mk_lt_mk.mpr hcd))) p q have hσad : σ.rel a d = true := σ.trans _ _ _ hσab hb.2.2 have hd1 : d ∈ σ.blockFinset (σ.rootOf a) := by rw [(σ.rootOf_eq_iff ha.1 hb.2.1).mpr hσad]; exact σ.mem_blockFinset_rootOf hb.2.1 have hb1 : b ∈ σ.blockFinset (σ.rootOf a) := by rw [(σ.rootOf_eq_iff ha.1 hb.1).mpr hσab]; exact σ.mem_blockFinset_rootOf hb.1 have hc1 : c ∈ σ.blockFinset (σ.rootOf a) := by rw [(σ.rootOf_eq_iff ha.1 ha.2.1).mpr ha.2.2]; exact σ.mem_blockFinset_rootOf ha.2.1 have hd2 : d ∈ σ.blockFinset (σ.rootOf b) := by rw [(σ.rootOf_eq_iff hb.1 hb.2.1).mpr hb.2.2]; exact σ.mem_blockFinset_rootOf hb.2.1 exact haux _ _ hr (σ.mem_blockFinset_rootOf ha.1) hb1 hc1 hd1 (σ.mem_blockFinset_rootOf hb.1) hd2 hac hbd lemma glueOnBlocks_le {n : ℕ} (σ : NC n) (f : ∀ r : σ.rootSet, NC (σ.blockFinset r.1).card) : glueOnBlocks σ f ≤ σ := by intro i j hij dsimp only [glueOnBlocks] at hij split_ifs at hij with h exact h.2.2 /-- **Lower Interval Factorization Theorem:** `[⊥, σ] ≃o ∏ r : σ.rootSet, NC (σ.blockFinset r).card`. -/ noncomputable def lowerIntervalOrderIso {n : ℕ} (σ : NC n) : { π : NC n // π ≤ σ } ≃o (∀ r : σ.rootSet, NC (σ.blockFinset r.1).card) where toFun π := fun r => π.1.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1) invFun f := ⟨glueOnBlocks σ f, glueOnBlocks_le σ f⟩ left_inv π := by apply Subtype.ext apply ext' intro i j hi hj change (glueOnBlocks σ (fun r => π.1.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1))).rel i j = π.1.rel i j dsimp only [glueOnBlocks] by_cases hσ : σ.rel i j = true · rw [dif_pos ⟨hi, hj, hσ⟩, restrictSet_rel _ _ _ _ _ (Fin.isLt _) (Fin.isLt _)] set S := σ.blockFinset (σ.rootOf i) have hiS : i ∈ S := σ.mem_blockFinset_rootOf hi have hjS : j ∈ S := by change j ∈ σ.blockFinset (σ.rootOf i) rw [(σ.rootOf_eq_iff hi hj).mpr hσ]; exact σ.mem_blockFinset_rootOf hj have e1 : S.orderEmbOfFin rfl ((S.orderIsoOfFin rfl).symm ⟨i, hiS⟩) = i := by rw [← Finset.coe_orderIsoOfFin_apply] exact congrArg Subtype.val ((S.orderIsoOfFin rfl).apply_symm_apply ⟨i, hiS⟩) have e2 : S.orderEmbOfFin rfl ((S.orderIsoOfFin rfl).symm ⟨j, hjS⟩) = j := by rw [← Finset.coe_orderIsoOfFin_apply] exact congrArg Subtype.val ((S.orderIsoOfFin rfl).apply_symm_apply ⟨j, hjS⟩) exact congrArg₂ π.1.rel e1 e2 · rw [dif_neg (fun (h : i < n ∧ j < n ∧ σ.rel i j = true) => hσ h.2.2)] cases hp : π.1.rel i j · rfl · exact absurd (π.2 i j hp) hσ right_inv f := by funext r apply ext' intro i j hi hj rw [restrictSet_rel _ _ _ _ _ hi hj] set S := σ.blockFinset r.1 set x := S.orderEmbOfFin rfl ⟨i, hi⟩ set y := S.orderEmbOfFin rfl ⟨j, hj⟩ have hxS : x ∈ S := S.orderEmbOfFin_mem rfl ⟨i, hi⟩ have hyS : y ∈ S := S.orderEmbOfFin_mem rfl ⟨j, hj⟩ have hxn : x < n := σ.blockFinset_lt r.1 x hxS have hyn : y < n := σ.blockFinset_lt r.1 y hyS have hrx : σ.rel r.1 x = true := (Finset.mem_filter.mp hxS).2 have hry : σ.rel r.1 y = true := (Finset.mem_filter.mp hyS).2 have hxy : σ.rel x y = true := σ.trans _ _ _ (by rw [σ.symm]; exact hrx) hry have hroot : σ.rootOf x = r.1 := by have hrr : σ.rootOf r.1 = r.1 := by have hr_min := of_decide_eq_true (Finset.mem_filter.mp r.2).2 have hrn : r.1 < n := Finset.mem_range.mp (Finset.mem_filter.mp r.2).1 have hle := Finset.min'_le (σ.blockFinset r.1) r.1 (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hrn, σ.refl r.1 hrn⟩) have hrel := σ.rootOf_rel hrn simp only [rootOf, hrn, ↓reduceDIte] at hrel ⊢ by_contra hne have hlt : (σ.blockFinset r.1).min' _ < r.1 := lt_of_le_of_ne hle hne have := hr_min _ hlt; rw [hrel] at this; exact absurd this (by decide) rw [← hrr] exact (σ.rootOf_eq_iff hxn (Finset.mem_range.mp (Finset.mem_filter.mp r.2).1)).mpr (by rw [σ.symm]; exact hrx) dsimp only [glueOnBlocks] rw [dif_pos ⟨hxn, hyn, hxy⟩] have hr_sub : (⟨σ.rootOf x, σ.rootOf_mem_rootSet hxn⟩ : σ.rootSet) = r := Subtype.ext hroot have haux : ∀ (r1 : σ.rootSet) (hreq : r1 = r) (hx1 : x ∈ σ.blockFinset r1.1) (hy1 : y ∈ σ.blockFinset r1.1), (f r1).rel (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨x, hx1⟩).1 (((σ.blockFinset r1.1).orderIsoOfFin rfl).symm ⟨y, hy1⟩).1 = (f r).rel i j := by rintro _ rfl hx1 hy1 have ei : ((S.orderIsoOfFin rfl).symm ⟨x, hx1⟩) = ⟨i, hi⟩ := (S.orderIsoOfFin rfl).symm_apply_apply ⟨i, hi⟩ have ej : ((S.orderIsoOfFin rfl).symm ⟨y, hy1⟩) = ⟨j, hj⟩ := (S.orderIsoOfFin rfl).symm_apply_apply ⟨j, hj⟩ rw [ei, ej] exact haux _ hr_sub _ _ map_rel_iff' := by intro π1 π2 constructor · intro h i j hij have hσ : σ.rel i j = true := π1.2 i j hij have ⟨hi, hj⟩ := π1.1.supp i j hij set r : σ.rootSet := ⟨σ.rootOf i, σ.rootOf_mem_rootSet hi⟩ set S := σ.blockFinset r.1 set e := S.orderIsoOfFin rfl have hiS : i ∈ S := σ.mem_blockFinset_rootOf hi have hjS : j ∈ S := by have := (σ.rootOf_eq_iff hi hj).mpr hσ change j ∈ σ.blockFinset (σ.rootOf i); rw [this]; exact σ.mem_blockFinset_rootOf hj set ui := e.symm ⟨i, hiS⟩ set uj := e.symm ⟨j, hjS⟩ have hu : S.orderEmbOfFin rfl ui = i := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply ⟨i, hiS⟩) have hv : S.orderEmbOfFin rfl uj = j := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply ⟨j, hjS⟩) have h1 : (π1.1.restrictSet S (σ.blockFinset_lt r.1)).rel ui.1 uj.1 = true := by rw [restrictSet_rel _ _ _ _ _ ui.2 uj.2, hu, hv]; exact hij have h2 := h r ui.1 uj.1 h1 change (π2.1.restrictSet S (σ.blockFinset_lt r.1)).rel ui.1 uj.1 = true at h2 rw [restrictSet_rel _ _ _ _ _ ui.2 uj.2, hu, hv] at h2 exact h2 · intro h r i j hij change (π1.1.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)).rel i j = true at hij change (π2.1.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)).rel i j = true have ⟨hi, hj⟩ := (π1.1.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)).supp i j hij rw [restrictSet_rel _ _ (σ.blockFinset_lt r.1) _ _ hi hj] at hij ⊢ exact h _ _ hij /-- **General Interval Factorization Theorem:** For `π ≤ σ` in `NC(n)`, `[π, σ]` is order-isomorphic to `∏ r : σ.rootSet, { τ : NC (σ.blockFinset r).card // π.restrictSet (σ.blockFinset r) ≤ τ }`. -/ noncomputable def intervalOrderIso {n : ℕ} {π σ : NC n} (hπσ : π ≤ σ) : { τ : NC n // π ≤ τ ∧ τ ≤ σ } ≃o (∀ r : σ.rootSet, { τ : NC (σ.blockFinset r.1).card // π.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1) ≤ τ }) where toFun τ := fun r => ⟨τ.1.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1), fun i j hij => by have ⟨hi, hj⟩ := (π.restrictSet _ _).supp i j hij rw [restrictSet_rel _ _ _ _ _ hi hj] at hij ⊢ exact τ.2.1 _ _ hij⟩ invFun f := ⟨glueOnBlocks σ (fun r => (f r).1), ⟨by have h1 : (lowerIntervalOrderIso σ).symm (fun r => π.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)) = ⟨π, hπσ⟩ := (lowerIntervalOrderIso σ).symm_apply_apply ⟨π, hπσ⟩ have h2 : (lowerIntervalOrderIso σ).symm (fun r => π.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)) ≤ (lowerIntervalOrderIso σ).symm (fun r => (f r).1) := (lowerIntervalOrderIso σ).symm.monotone (fun r => (f r).2) rw [h1] at h2 exact h2, glueOnBlocks_le σ (fun r => (f r).1)⟩⟩ left_inv τ := by apply Subtype.ext change glueOnBlocks σ (fun r => τ.1.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)) = τ.1 exact congrArg Subtype.val ((lowerIntervalOrderIso σ).left_inv ⟨τ.1, τ.2.2⟩) right_inv f := by funext r apply Subtype.ext change (glueOnBlocks σ (fun r => (f r).1)).restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1) = (f r).1 exact congrFun ((lowerIntervalOrderIso σ).right_inv (fun r => (f r).1)) r map_rel_iff' := fun {τ1 τ2} => (lowerIntervalOrderIso σ).map_rel_iff (a := ⟨τ1.1, τ1.2.2⟩) (b := ⟨τ2.1, τ2.2.2⟩) end NC /-! ## Section 2: Incidence Algebra of `NC(n)` and Multiplicative Factorization of `μ_{NC}` -/ section IncidenceMobius @[simp] lemma bot_rel {n : ℕ} (i j : ℕ) : (⊥ : NC n).rel i j = decide (i < n ∧ i = j) := by change decide (i = j ∧ i < n) = decide (i < n ∧ i = j) simp only [and_comm] @[simp] lemma top_rel {n : ℕ} (i j : ℕ) : (⊤ : NC n).rel i j = decide (i < n ∧ j < n) := rfl instance instDecidableLT (n : ℕ) : DecidableLT (NC n) := fun π σ => decidable_of_iff (π ≤ σ ∧ ¬ σ ≤ π) lt_iff_le_not_ge.symm instance instLocallyFiniteOrder (n : ℕ) : LocallyFiniteOrder (NC n) := Fintype.toLocallyFiniteOrder /-- The Speicher Möbius function `μ_{NC}(π, σ)` in the incidence algebra of `NC(n)`. -/ noncomputable def mobiusNC {n : ℕ} (π σ : NC n) : ℤ := IncidenceAlgebra.mu ℤ π σ /-- Order-isomorphism invariance of the Möbius function `μ` on locally finite posets. -/ lemma mu_orderIso {α β : Type*} [PartialOrder α] [LocallyFiniteOrder α] [DecidableEq α] [DecidableLE α] [PartialOrder β] [LocallyFiniteOrder β] [DecidableEq β] [DecidableLE β] (e : α ≃o β) (a b : α) : IncidenceAlgebra.mu ℤ (e a) (e b) = IncidenceAlgebra.mu ℤ a b := by let f : IncidenceAlgebra ℤ α := ⟨fun x y => IncidenceAlgebra.mu ℤ (e x) (e y), fun x y h => IncidenceAlgebra.apply_eq_zero_of_not_le (by simpa [e.le_iff_le] using h) _⟩ have hf : f * IncidenceAlgebra.zeta ℤ = 1 := by apply IncidenceAlgebra.ext intro x y hxy rw [IncidenceAlgebra.mul_apply, IncidenceAlgebra.one_apply] have hsum : ∑ z ∈ Finset.Icc x y, f x z * IncidenceAlgebra.zeta ℤ z y = ∑ w ∈ Finset.Icc (e x) (e y), IncidenceAlgebra.mu ℤ (e x) w := by refine Finset.sum_nbij e ?_ ?_ ?_ ?_ · intro z hz obtain ⟨hxz, hzy⟩ := Finset.mem_Icc.mp hz exact Finset.mem_Icc.mpr ⟨e.monotone hxz, e.monotone hzy⟩ · intro z₁ _ z₂ _ h; exact e.injective h · intro w hw obtain ⟨hxw, hwy⟩ := Finset.mem_Icc.mp hw refine ⟨e.symm w, Finset.mem_coe.mpr (Finset.mem_Icc.mpr ?_), e.apply_symm_apply w⟩ exact ⟨by simpa using e.symm.monotone hxw, by simpa using e.symm.monotone hwy⟩ · intro z hz have hzy := (Finset.mem_Icc.mp hz).2 simp [f, IncidenceAlgebra.zeta_of_le hzy] rw [hsum, IncidenceAlgebra.sum_Icc_mu_right] simp only [e.injective.eq_iff] have hfeq : f = IncidenceAlgebra.mu ℤ := by calc f = f * 1 := (mul_one f).symm _ = f * (IncidenceAlgebra.zeta ℤ * IncidenceAlgebra.mu ℤ) := by rw [IncidenceAlgebra.zeta_mul_mu] _ = (f * IncidenceAlgebra.zeta ℤ) * IncidenceAlgebra.mu ℤ := (mul_assoc _ _ _).symm _ = IncidenceAlgebra.mu ℤ := by rw [hf, one_mul] exact congrArg (fun g : IncidenceAlgebra ℤ α => g a b) hfeq /-- Exact multiplicativity of the Möbius function on finite Pi-products of locally finite posets. -/ lemma mu_pi {ι : Type*} [Fintype ι] [DecidableEq ι] {α : ι → Type*} [∀ i, PartialOrder (α i)] [∀ i, LocallyFiniteOrder (α i)] [∀ i, DecidableEq (α i)] [∀ i, DecidableLE (α i)] [∀ i, Fintype (α i)] [LocallyFiniteOrder (∀ i, α i)] [DecidableLE (∀ i, α i)] (a b : ∀ i, α i) : IncidenceAlgebra.mu ℤ a b = ∏ i, IncidenceAlgebra.mu ℤ (a i) (b i) := by let f : IncidenceAlgebra ℤ (∀ i, α i) := ⟨fun x y => ∏ i, IncidenceAlgebra.mu ℤ (x i) (y i), fun x y h => by have hex : ∃ i, ¬ x i ≤ y i := by by_contra hall; push Not at hall; exact h hall obtain ⟨i, hi⟩ := hex exact Finset.prod_eq_zero (Finset.mem_univ i) (IncidenceAlgebra.apply_eq_zero_of_not_le hi _)⟩ have hf : f * IncidenceAlgebra.zeta ℤ = 1 := by apply IncidenceAlgebra.ext intro x y hxy rw [IncidenceAlgebra.mul_apply, IncidenceAlgebra.one_apply] have hIcc : Finset.Icc x y = Fintype.piFinset (fun i => Finset.Icc (x i) (y i)) := by ext z simp only [Finset.mem_Icc, Fintype.mem_piFinset, Pi.le_def, forall_and] have hsum : ∑ z ∈ Finset.Icc x y, f x z * IncidenceAlgebra.zeta ℤ z y = ∏ i, ∑ w ∈ Finset.Icc (x i) (y i), IncidenceAlgebra.mu ℤ (x i) w := by calc ∑ z ∈ Finset.Icc x y, f x z * IncidenceAlgebra.zeta ℤ z y = ∑ z ∈ Finset.Icc x y, ∏ i, IncidenceAlgebra.mu ℤ (x i) (z i) := Finset.sum_congr rfl fun z hz => by rw [IncidenceAlgebra.zeta_of_le (Finset.mem_Icc.mp hz).2, mul_one]; rfl _ = ∑ z ∈ Fintype.piFinset (fun i => Finset.Icc (x i) (y i)), ∏ i, IncidenceAlgebra.mu ℤ (x i) (z i) := by rw [hIcc] _ = ∏ i, ∑ w ∈ Finset.Icc (x i) (y i), IncidenceAlgebra.mu ℤ (x i) w := (Finset.prod_univ_sum (t := fun i => Finset.Icc (x i) (y i)) (f := fun i w => IncidenceAlgebra.mu ℤ (x i) w)).symm rw [hsum] simp_rw [IncidenceAlgebra.sum_Icc_mu_right] by_cases heq : x = y · subst heq; simp · rw [if_neg heq] have hex : ∃ i, x i ≠ y i := by by_contra hall; push Not at hall; exact heq (funext hall) obtain ⟨i, hi⟩ := hex exact Finset.prod_eq_zero (Finset.mem_univ i) (if_neg hi) have hfeq : f = IncidenceAlgebra.mu ℤ := by calc f = f * 1 := (mul_one f).symm _ = f * (IncidenceAlgebra.zeta ℤ * IncidenceAlgebra.mu ℤ) := by rw [IncidenceAlgebra.zeta_mul_mu] _ = (f * IncidenceAlgebra.zeta ℤ) * IncidenceAlgebra.mu ℤ := (mul_assoc _ _ _).symm _ = IncidenceAlgebra.mu ℤ := by rw [hf, one_mul] exact (congrArg (fun g : IncidenceAlgebra ℤ (∀ i, α i) => g a b) hfeq).symm /-- Restriction of `μ` to a lower interval `{ x // x ≤ c }` agrees with ambient `μ`. -/ lemma mu_subtype_Iic {α : Type*} [PartialOrder α] [LocallyFiniteOrder α] [DecidableEq α] [DecidableLE α] (c : α) [LocallyFiniteOrder { x : α // x ≤ c }] (a b : { x : α // x ≤ c }) : IncidenceAlgebra.mu ℤ a b = IncidenceAlgebra.mu ℤ a.1 b.1 := by let f : IncidenceAlgebra ℤ { x : α // x ≤ c } := ⟨fun x y => IncidenceAlgebra.mu ℤ x.1 y.1, fun x y h => IncidenceAlgebra.apply_eq_zero_of_not_le (show ¬ x.1 ≤ y.1 from h) (IncidenceAlgebra.mu ℤ : IncidenceAlgebra ℤ α)⟩ have hf : f * IncidenceAlgebra.zeta ℤ = 1 := by apply IncidenceAlgebra.ext intro x y hxy rw [IncidenceAlgebra.mul_apply, IncidenceAlgebra.one_apply] have hsum : ∑ z ∈ Finset.Icc x y, f x z * IncidenceAlgebra.zeta ℤ z y = ∑ w ∈ Finset.Icc x.1 y.1, IncidenceAlgebra.mu ℤ x.1 w := by refine Finset.sum_nbij Subtype.val ?_ ?_ ?_ ?_ · intro z hz obtain ⟨hxz, hzy⟩ := Finset.mem_Icc.mp hz exact Finset.mem_Icc.mpr ⟨hxz, hzy⟩ · intro _ _ _ _ h; exact Subtype.ext h · intro w hw obtain ⟨hxw, hwy⟩ := Finset.mem_Icc.mp hw exact ⟨⟨w, hwy.trans y.2⟩, Finset.mem_coe.mpr (Finset.mem_Icc.mpr ⟨hxw, hwy⟩), rfl⟩ · intro z hz rw [IncidenceAlgebra.zeta_of_le (Finset.mem_Icc.mp hz).2, mul_one]; rfl rw [hsum, IncidenceAlgebra.sum_Icc_mu_right] simp only [Subtype.ext_iff] have hfeq : f = IncidenceAlgebra.mu ℤ := by calc f = f * 1 := (mul_one f).symm _ = f * (IncidenceAlgebra.zeta ℤ * IncidenceAlgebra.mu ℤ) := by rw [IncidenceAlgebra.zeta_mul_mu] _ = (f * IncidenceAlgebra.zeta ℤ) * IncidenceAlgebra.mu ℤ := (mul_assoc _ _ _).symm _ = IncidenceAlgebra.mu ℤ := by rw [hf, one_mul] exact (congrArg (fun g : IncidenceAlgebra ℤ { x : α // x ≤ c } => g a b) hfeq).symm /-- **Exact Interval Factorization of the Speicher Möbius Function `μ_{NC}(π, σ)`:** For `π ≤ σ` in `NC(n)`, `μ_{NC}(π, σ) = ∏_{B ∈ σ} μ_{NC}(π|_B, 1_{|B|})`. -/ theorem mobiusNC_eq_prod_restrict {n : ℕ} {π σ : NC n} (hπσ : π ≤ σ) : mobiusNC π σ = ∏ r : σ.rootSet, mobiusNC (π.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)) ⊤ := by have : DecidableLT { τ : NC n // τ ≤ σ } := fun a b => decidable_of_iff (a ≤ b ∧ ¬ b ≤ a) lt_iff_le_not_ge.symm have : DecidableLE (∀ r : σ.rootSet, NC (σ.blockFinset r.1).card) := fun f g => Fintype.decidableForallFintype have : DecidableLT (∀ r : σ.rootSet, NC (σ.blockFinset r.1).card) := fun f g => decidable_of_iff (f ≤ g ∧ ¬ g ≤ f) lt_iff_le_not_ge.symm have : LocallyFiniteOrder { τ : NC n // τ ≤ σ } := Fintype.toLocallyFiniteOrder have : LocallyFiniteOrder (∀ r : σ.rootSet, NC (σ.blockFinset r.1).card) := Fintype.toLocallyFiniteOrder unfold mobiusNC rw [← mu_subtype_Iic σ ⟨π, hπσ⟩ ⟨σ, le_rfl⟩] rw [← mu_orderIso (NC.lowerIntervalOrderIso σ) ⟨π, hπσ⟩ ⟨σ, le_rfl⟩] rw [mu_pi] refine Finset.prod_congr rfl fun r _ => ?_ have htop : (NC.lowerIntervalOrderIso σ ⟨σ, le_rfl⟩) r = (⊤ : NC (σ.blockFinset r.1).card) := by apply NC.ext'; intro i j hi hj change (σ.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)).rel i j = (⊤ : NC _).rel i j rw [NC.restrictSet_rel _ _ _ _ _ hi hj, top_rel] have hx := (Finset.mem_filter.mp ((σ.blockFinset r.1).orderEmbOfFin_mem rfl ⟨i, hi⟩)).2 have hy := (Finset.mem_filter.mp ((σ.blockFinset r.1).orderEmbOfFin_mem rfl ⟨j, hj⟩)).2 have hxy := σ.trans _ _ _ (by rw [σ.symm]; exact hx) hy simp [hxy, hi, hj] rw [htop]; rfl /-- **Exact Block Factorization of `μ_{NC}(0_n, σ)`:** -/ theorem mobiusNC_bot_eq_prod {n : ℕ} (σ : NC n) : mobiusNC (⊥ : NC n) σ = ∏ r ∈ σ.rootSet, mobiusNC (⊥ : NC (σ.blockFinset r).card) ⊤ := by rw [mobiusNC_eq_prod_restrict (bot_le : (⊥ : NC n) ≤ σ)] rw [← Finset.prod_coe_sort σ.rootSet (fun r => mobiusNC (⊥ : NC (σ.blockFinset r).card) ⊤)] refine Finset.prod_congr rfl fun r _ => ?_ have hbot : (⊥ : NC n).restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1) = (⊥ : NC (σ.blockFinset r.1).card) := by apply NC.ext'; intro i j hi hj rw [NC.restrictSet_rel _ _ _ _ _ hi hj, bot_rel, bot_rel] have hlt := σ.blockFinset_lt r.1 _ ((σ.blockFinset r.1).orderEmbOfFin_mem rfl ⟨i, hi⟩) have hinj : (σ.blockFinset r.1).orderEmbOfFin rfl ⟨i, hi⟩ = (σ.blockFinset r.1).orderEmbOfFin rfl ⟨j, hj⟩ ↔ i = j := by rw [((σ.blockFinset r.1).orderEmbOfFin rfl).injective.eq_iff, Fin.ext_iff] simp [hi, hlt, hinj] rw [hbot] /-- **Exact Kreweras Factorization of `μ_{NC}(π, 1_n)`:** -/ theorem mobiusNC_top_eq_kreweras_prod {n : ℕ} (π : NC n) : mobiusNC π (⊤ : NC n) = ∏ r ∈ (NC.kreweras π).rootSet, mobiusNC (⊥ : NC ((NC.kreweras π).blockFinset r).card) ⊤ := by have h1 : mobiusNC π (⊤ : NC n) = mobiusNC (⊥ : NC n) (NC.kreweras π) := by unfold mobiusNC rw [← mu_orderIso (NC.krewerasOrderIso n) π ⊤] have htop : NC.krewerasOrderIso n (⊤ : NC n) = OrderDual.toDual (⊥ : NC n) := by change OrderDual.toDual (NC.kreweras (⊤ : NC n)) = OrderDual.toDual (⊥ : NC n) congr 1 apply NC.ext'; intro i j hi hj rw [Bool.eq_iff_iff, NC.kreweras_rel_iff, NC.closedInterval_iff, bot_rel] simp only [hi, hj, true_and, decide_eq_true_eq] constructor · intro h by_contra hne have hlt : min i j < max i j := by omega have hmax_lt : max i j < n := max_lt hi hj have hmin_lt : min i j < n := lt_of_le_of_lt (min_le_left i j) hi have hrel : (⊤ : NC n).rel (max i j) (min i j) = true := by rw [top_rel]; exact decide_eq_true ⟨hmax_lt, hmin_lt⟩ have hmem := h (max i j) hmax_lt (min i j) hmin_lt hlt le_rfl hrel omega · rintro rfl a _ b _ h1 h2 _; omega rw [htop] change IncidenceAlgebra.mu ℤ (OrderDual.toDual (NC.kreweras π)) (OrderDual.toDual ⊥) = _ exact IncidenceAlgebra.mu_toDual ℤ (NC.kreweras π) ⊥ rw [h1, mobiusNC_bot_eq_prod] end IncidenceMobius /-! ## Section 3: Multiplicative Functionals and Exact Moment–Cumulant Bijection -/ section MomentCumulant /-- Multiplicative extension `f_π = ∏_{V ∈ π} f(|V|)` of a sequence `f : ℕ → R` to `NC(n)`. -/ def blockProd {R : Type*} [CommRing R] (f : ℕ → R) {n : ℕ} (π : NC n) : R := ∏ r ∈ π.rootSet, f (π.blockFinset r).card /-- Speicher moments from free cumulants: `m_n = ∑_{π ∈ NC(n)} κ_π` (`m_0 = 1`). -/ def momentsOfCumulants {R : Type*} [CommRing R] (κ : ℕ → R) (n : ℕ) : R := if n = 0 then 1 else ∑ π : NC n, blockProd κ π /-- Speicher free cumulants from moments via Möbius inversion: `κ_n = ∑_{π ∈ NC(n)} m_π · μ_{NC}(π, 1_n)` (`κ_0 = 0`). -/ noncomputable def cumulantsOfMoments {R : Type*} [CommRing R] (m : ℕ → R) (n : ℕ) : R := if n = 0 then 0 else ∑ π : NC n, blockProd m π * (mobiusNC π ⊤ : R) lemma blockFinset_card_pos {n : ℕ} (π : NC n) {r : ℕ} (hr : r ∈ π.rootSet) : 0 < (π.blockFinset r).card := by have hrn : r < n := Finset.mem_range.mp (Finset.mem_filter.mp hr).1 exact Finset.card_pos.mpr ⟨r, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hrn, π.refl r hrn⟩⟩ lemma blockProd_top {R : Type*} [CommRing R] (f : ℕ → R) {n : ℕ} (hn : 1 ≤ n) : blockProd f (⊤ : NC n) = f n := by unfold blockProd have hroots : (⊤ : NC n).rootSet = {0} := by ext i simp only [NC.rootSet, Finset.mem_filter, Finset.mem_range, Finset.mem_singleton, NC.isMin, decide_eq_true_eq] constructor · rintro ⟨hi, hmin⟩ by_contra hi0 have hrel := hmin 0 (by omega) simp [top_rel, hi, show 0 < n by omega] at hrel · rintro rfl; exact ⟨by omega, fun k hk => by omega⟩ have hblk : (⊤ : NC n).blockFinset 0 = Finset.range n := by ext j; simp only [NC.blockFinset, Finset.mem_filter, Finset.mem_range, and_iff_left_iff_imp] intro hj; simp [top_rel, hj, show 0 < n by omega] rw [hroots, Finset.prod_singleton, hblk, Finset.card_range] lemma blockProd_bot {R : Type*} [CommRing R] (f : ℕ → R) (n : ℕ) : blockProd f (⊥ : NC n) = f 1 ^ n := by unfold blockProd have hroots : (⊥ : NC n).rootSet = Finset.range n := by ext i simp only [NC.rootSet, Finset.mem_filter, Finset.mem_range, and_iff_left_iff_imp] intro hi; simp only [NC.isMin, decide_eq_true_eq] intro k hk; simp [bot_rel, show k ≠ i by omega] rw [hroots] calc ∏ r ∈ Finset.range n, f ((⊥ : NC n).blockFinset r).card = ∏ _r ∈ Finset.range n, f 1 := by refine Finset.prod_congr rfl fun r hr => ?_ have hrn := Finset.mem_range.mp hr have hblk : (⊥ : NC n).blockFinset r = {r} := by ext j; simp only [NC.blockFinset, Finset.mem_filter, Finset.mem_range, Finset.mem_singleton, bot_rel, decide_eq_true_eq] exact ⟨fun h => h.2.2.symm, fun h => by subst h; exact ⟨hrn, hrn, rfl⟩⟩ rw [hblk, Finset.card_singleton] _ = f 1 ^ n := by rw [Finset.prod_const, Finset.card_range] /-- Multiplicativity of `blockProd` under `glueOnBlocks`: `f_{glue(σ, g)} = ∏_{r ∈ σ.rootSet} f_{g(r)}`. -/ lemma blockProd_glueOnBlocks {R : Type*} [CommRing R] (f : ℕ → R) {n : ℕ} (σ : NC n) (g : ∀ r : σ.rootSet, NC (σ.blockFinset r.1).card) : blockProd f (NC.glueOnBlocks σ g) = ∏ r : σ.rootSet, blockProd f (g r) := by set τ := NC.glueOnBlocks σ g have hτ_le : τ ≤ σ := NC.glueOnBlocks_le σ g have hres : ∀ r : σ.rootSet, τ.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1) = g r := fun r => congrFun ((NC.lowerIntervalOrderIso σ).right_inv g) r -- Every block root `x` of `τ` lies in a unique block `r` of `σ`, and corresponds to a unique root of `g r`! have hroot_bij : ∀ r : σ.rootSet, (τ.rootSet.filter fun x => σ.rootOf x = r.1).prod (fun x => f (τ.blockFinset x).card) = blockProd f (g r) := by intro r set S := σ.blockFinset r.1 set e := S.orderIsoOfFin rfl unfold blockProd refine Finset.prod_bij (fun x hx => (e.symm ⟨x, by have hxr := (Finset.mem_filter.mp hx).2 have hxn := Finset.mem_range.mp (Finset.mem_filter.mp (Finset.mem_filter.mp hx).1).1 change x ∈ σ.blockFinset r.1; rw [← hxr]; exact σ.mem_blockFinset_rootOf hxn⟩).1) ?_ ?_ ?_ ?_ · intro x hx have hx_in := (Finset.mem_filter.mp hx).1 have hxr := (Finset.mem_filter.mp hx).2 have hxn := Finset.mem_range.mp (Finset.mem_filter.mp hx_in).1 have hxmin := of_decide_eq_true (Finset.mem_filter.mp hx_in).2 have hxS : x ∈ S := by show x ∈ σ.blockFinset r.1; rw [← hxr]; exact σ.mem_blockFinset_rootOf hxn set idx := e.symm ⟨x, hxS⟩ refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr idx.2, decide_eq_true fun k hk => ?_⟩ rw [← hres r, NC.restrictSet_rel _ _ _ _ _ (lt_trans hk idx.2) idx.2] have hlt : S.orderEmbOfFin rfl ⟨k, lt_trans hk idx.2⟩ < x := by have h1 : S.orderEmbOfFin rfl ⟨k, lt_trans hk idx.2⟩ < S.orderEmbOfFin rfl idx := (S.orderEmbOfFin rfl).strictMono (Fin.mk_lt_mk.mpr hk) have h2 : S.orderEmbOfFin rfl idx = x := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply _) rwa [h2] at h1 have hx_eq : S.orderEmbOfFin rfl idx = x := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply _) rw [hx_eq]; exact hxmin _ hlt · intro x₁ hx₁ x₂ hx₂ heq have h1 : (e.symm ⟨x₁, _⟩) = (e.symm ⟨x₂, _⟩) := Fin.ext heq exact congrArg Subtype.val (e.symm.injective h1) · intro u hu have hu_lt := Finset.mem_range.mp (Finset.mem_filter.mp hu).1 have humin := of_decide_eq_true (Finset.mem_filter.mp hu).2 set x := S.orderEmbOfFin rfl ⟨u, hu_lt⟩ have hxS : x ∈ S := S.orderEmbOfFin_mem rfl ⟨u, hu_lt⟩ have hxn : x < n := σ.blockFinset_lt r.1 x hxS have hrx : σ.rel r.1 x = true := (Finset.mem_filter.mp hxS).2 have hrootx : σ.rootOf x = r.1 := by have hrr : σ.rootOf r.1 = r.1 := by have hr_min := of_decide_eq_true (Finset.mem_filter.mp r.2).2 have hrn := Finset.mem_range.mp (Finset.mem_filter.mp r.2).1 have hle := Finset.min'_le S r.1 (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hrn, σ.refl r.1 hrn⟩) have hrel := σ.rootOf_rel hrn simp only [NC.rootOf, hrn, ↓reduceDIte] at hrel ⊢ by_contra hne have hlt : S.min' _ < r.1 := lt_of_le_of_ne hle hne have := hr_min _ hlt; rw [hrel] at this; exact absurd this (by decide) rw [← hrr] exact (σ.rootOf_eq_iff hxn (Finset.mem_range.mp (Finset.mem_filter.mp r.2).1)).mpr (by rw [σ.symm]; exact hrx) refine ⟨x, Finset.mem_filter.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hxn, decide_eq_true fun y hy => ?_⟩, hrootx⟩, ?_⟩ · cases hty : τ.rel y x · rfl · have hσyx : σ.rel y x = true := hτ_le y x hty have hyn : y < n := (τ.supp y x hty).1 have hyS : y ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hyn, σ.trans _ _ _ hrx (by rw [σ.symm]; exact hσyx)⟩ set v := e.symm ⟨y, hyS⟩ have hv_lt : v.1 < u := by have : e v < e ⟨u, hu_lt⟩ := by rw [e.apply_symm_apply] apply Subtype.mk_lt_mk.mpr change y < (S.orderIsoOfFin rfl ⟨u, hu_lt⟩).1 rw [Finset.coe_orderIsoOfFin_apply] exact hy exact Fin.lt_def.mp (e.strictMono.lt_iff_lt.mp this) have hrel_g : (g r).rel v.1 u = true := by rw [← hres r, NC.restrictSet_rel _ _ _ _ _ v.2 hu_lt] have hvy : S.orderEmbOfFin rfl v = y := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply _) rw [hvy]; exact hty have := humin v.1 hv_lt; rw [hrel_g] at this; exact absurd this (by decide) · exact congrArg Fin.val (e.symm_apply_apply ⟨u, hu_lt⟩) · intro x hx congr 1 have hxr := (Finset.mem_filter.mp hx).2 have hxn := Finset.mem_range.mp (Finset.mem_filter.mp (Finset.mem_filter.mp hx).1).1 have hxS : x ∈ S := by show x ∈ σ.blockFinset r.1; rw [← hxr]; exact σ.mem_blockFinset_rootOf hxn set idx := e.symm ⟨x, hxS⟩ have hx_eq : S.orderEmbOfFin rfl idx = x := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply _) refine Finset.card_bij (fun y hy => (e.symm ⟨y, by have hy_rel := (Finset.mem_filter.mp hy).2 have hyn := Finset.mem_range.mp (Finset.mem_filter.mp hy).1 have hσxy := hτ_le x y hy_rel change y ∈ σ.blockFinset r.1; rw [← hxr, (σ.rootOf_eq_iff hxn hyn).mpr hσxy] exact σ.mem_blockFinset_rootOf hyn⟩).1) ?_ ?_ ?_ · intro y hy have hy_rel := (Finset.mem_filter.mp hy).2 have hyn := Finset.mem_range.mp (Finset.mem_filter.mp hy).1 set idy := e.symm ⟨y, by have hσxy := hτ_le x y hy_rel change y ∈ σ.blockFinset r.1; rw [← hxr, (σ.rootOf_eq_iff hxn hyn).mpr hσxy] exact σ.mem_blockFinset_rootOf hyn⟩ have hy_eq : S.orderEmbOfFin rfl idy = y := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply _) refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr idy.2, ?_⟩ rw [← hres r, NC.restrictSet_rel _ _ _ _ _ idx.2 idy.2, hx_eq, hy_eq] exact hy_rel · intro y₁ _ y₂ _ heq exact congrArg Subtype.val (e.symm.injective (Fin.ext heq)) · intro w hw have hw_lt := Finset.mem_range.mp (Finset.mem_filter.mp hw).1 have hw_rel := (Finset.mem_filter.mp hw).2 rw [← hres r, NC.restrictSet_rel _ _ _ _ _ idx.2 hw_lt, hx_eq] at hw_rel set y := S.orderEmbOfFin rfl ⟨w, hw_lt⟩ have hyS : y ∈ S := S.orderEmbOfFin_mem rfl ⟨w, hw_lt⟩ refine ⟨y, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (σ.blockFinset_lt r.1 y hyS), hw_rel⟩, ?_⟩ exact congrArg Fin.val (e.symm_apply_apply ⟨w, hw_lt⟩) conv_lhs => unfold blockProd rw [← Finset.prod_fiberwise_of_maps_to (s := τ.rootSet) (t := σ.rootSet) (g := σ.rootOf) (fun x hx => σ.rootOf_mem_rootSet (Finset.mem_range.mp (Finset.mem_filter.mp hx).1))] rw [← Finset.prod_coe_sort] exact Finset.prod_congr rfl fun r _ => hroot_bij r lemma blockProd_restrict {R : Type*} [CommRing R] (f : ℕ → R) {n : ℕ} {π σ : NC n} (hπσ : π ≤ σ) : blockProd f π = ∏ r : σ.rootSet, blockProd f (π.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)) := by have hglue : NC.glueOnBlocks σ (fun r => π.restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1)) = π := congrArg Subtype.val ((NC.lowerIntervalOrderIso σ).left_inv ⟨π, hπσ⟩) conv_lhs => rw [← hglue] exact blockProd_glueOnBlocks f σ _ /-- For every `σ ∈ NC(n)`, `m_σ = ∑_{π ≤ σ} κ_π`. -/ theorem blockProd_moments_eq_sum_le {R : Type*} [CommRing R] (κ : ℕ → R) {n : ℕ} (σ : NC n) : blockProd (momentsOfCumulants κ) σ = ∑ π ∈ Finset.Iic σ, blockProd κ π := by unfold blockProd rw [← Finset.prod_coe_sort] have hpos : ∀ r : σ.rootSet, (σ.blockFinset r.1).card ≠ 0 := fun r => Nat.pos_iff_ne_zero.mp (blockFinset_card_pos σ r.2) calc ∏ r : σ.rootSet, momentsOfCumulants κ (σ.blockFinset r.1).card = ∏ r : σ.rootSet, ∑ α : NC (σ.blockFinset r.1).card, blockProd κ α := Finset.prod_congr rfl fun r _ => by rw [momentsOfCumulants, if_neg (hpos r)] _ = ∑ g : (∀ r : σ.rootSet, NC (σ.blockFinset r.1).card), ∏ r : σ.rootSet, blockProd κ (g r) := Fintype.prod_sum (fun r α => blockProd κ α) _ = ∑ g : (∀ r : σ.rootSet, NC (σ.blockFinset r.1).card), blockProd κ (NC.glueOnBlocks σ g) := Finset.sum_congr rfl fun g _ => (blockProd_glueOnBlocks κ σ g).symm _ = ∑ π ∈ Finset.Iic σ, blockProd κ π := by refine Finset.sum_nbij (fun g => NC.glueOnBlocks σ g) ?_ ?_ ?_ ?_ · intro g _; exact Finset.mem_Iic.mpr (NC.glueOnBlocks_le σ g) · intro g₁ _ g₂ _ heq have h1 : ((NC.lowerIntervalOrderIso σ).symm g₁ : { π : NC n // π ≤ σ }) = (NC.lowerIntervalOrderIso σ).symm g₂ := Subtype.ext heq exact (NC.lowerIntervalOrderIso σ).symm.injective h1 · intro π hπ have hle := Finset.mem_Iic.mp (Finset.mem_coe.mp hπ) exact ⟨NC.lowerIntervalOrderIso σ ⟨π, hle⟩, Finset.mem_coe.mpr (Finset.mem_univ _), congrArg Subtype.val ((NC.lowerIntervalOrderIso σ).left_inv ⟨π, hle⟩)⟩ · intro _ _; rfl /-- For every `σ ∈ NC(n)`, `κ_σ = ∑_{π ≤ σ} m_π · μ_{NC}(π, σ)`. -/ theorem blockProd_cumulants_eq_sum_le {R : Type*} [CommRing R] (m : ℕ → R) {n : ℕ} (σ : NC n) : blockProd (cumulantsOfMoments m) σ = ∑ π ∈ Finset.Iic σ, blockProd m π * (mobiusNC π σ : R) := by unfold blockProd rw [← Finset.prod_coe_sort] have hpos : ∀ r : σ.rootSet, (σ.blockFinset r.1).card ≠ 0 := fun r => Nat.pos_iff_ne_zero.mp (blockFinset_card_pos σ r.2) calc ∏ r : σ.rootSet, cumulantsOfMoments m (σ.blockFinset r.1).card = ∏ r : σ.rootSet, ∑ α : NC (σ.blockFinset r.1).card, blockProd m α * (mobiusNC α ⊤ : R) := Finset.prod_congr rfl fun r _ => by rw [cumulantsOfMoments, if_neg (hpos r)] _ = ∑ g : (∀ r : σ.rootSet, NC (σ.blockFinset r.1).card), ∏ r : σ.rootSet, (blockProd m (g r) * (mobiusNC (g r) ⊤ : R)) := Fintype.prod_sum (fun r α => blockProd m α * (mobiusNC α ⊤ : R)) _ = ∑ g : (∀ r : σ.rootSet, NC (σ.blockFinset r.1).card), blockProd m (NC.glueOnBlocks σ g) * (mobiusNC (NC.glueOnBlocks σ g) σ : R) := by refine Finset.sum_congr rfl fun g _ => ?_ rw [Finset.prod_mul_distrib, ← blockProd_glueOnBlocks m σ g, mobiusNC_eq_prod_restrict (NC.glueOnBlocks_le σ g), Int.cast_prod] congr 1 refine Finset.prod_congr rfl fun r _ => ?_ have hres : (NC.glueOnBlocks σ g).restrictSet (σ.blockFinset r.1) (σ.blockFinset_lt r.1) = g r := congrFun ((NC.lowerIntervalOrderIso σ).right_inv g) r rw [hres] _ = ∑ π ∈ Finset.Iic σ, blockProd m π * (mobiusNC π σ : R) := by refine Finset.sum_nbij (fun g => NC.glueOnBlocks σ g) ?_ ?_ ?_ ?_ · intro g _; exact Finset.mem_Iic.mpr (NC.glueOnBlocks_le σ g) · intro g₁ _ g₂ _ heq exact (NC.lowerIntervalOrderIso σ).symm.injective (Subtype.ext heq) · intro π hπ have hle := Finset.mem_Iic.mp (Finset.mem_coe.mp hπ) exact ⟨NC.lowerIntervalOrderIso σ ⟨π, hle⟩, Finset.mem_coe.mpr (Finset.mem_univ _), congrArg Subtype.val ((NC.lowerIntervalOrderIso σ).left_inv ⟨π, hle⟩)⟩ · intro _ _; rfl /-- **Speicher Moment–Cumulant Bijection (Left Inverse):** `cumulantsOfMoments (momentsOfCumulants κ) n = κ n` for every `n ≥ 1` over any commutative ring `R`. -/ theorem cumulantsOfMoments_momentsOfCumulants {R : Type*} [CommRing R] (κ : ℕ → R) {n : ℕ} (hn : 1 ≤ n) : cumulantsOfMoments (momentsOfCumulants κ) n = κ n := by rw [cumulantsOfMoments, if_neg (by omega)] simp_rw [blockProd_moments_eq_sum_le κ, Finset.sum_mul] calc ∑ σ : NC n, ∑ π ∈ Finset.Iic σ, blockProd κ π * (mobiusNC σ ⊤ : R) = ∑ σ : NC n, ∑ π : NC n, if π ≤ σ then blockProd κ π * (mobiusNC σ ⊤ : R) else 0 := by refine Finset.sum_congr rfl fun σ _ => ?_ rw [← Finset.sum_filter] congr 1; ext π; simp [Finset.mem_Iic] _ = ∑ π : NC n, ∑ σ : NC n, if π ≤ σ then blockProd κ π * (mobiusNC σ ⊤ : R) else 0 := Finset.sum_comm _ = ∑ π : NC n, blockProd κ π * ((∑ σ ∈ Finset.Icc π (⊤ : NC n), mobiusNC σ ⊤ : ℤ) : R) := by refine Finset.sum_congr rfl fun π _ => ?_ rw [Int.cast_sum, Finset.mul_sum, ← Finset.sum_filter] refine Finset.sum_congr ?_ fun _ _ => rfl ext σ; simp _ = ∑ π : NC n, blockProd κ π * (if π = (⊤ : NC n) then (1 : R) else 0) := by refine Finset.sum_congr rfl fun π _ => ?_ have hmu : ∑ σ ∈ Finset.Icc π (⊤ : NC n), mobiusNC σ ⊤ = if π = ⊤ then 1 else 0 := IncidenceAlgebra.sum_Icc_mu_left (𝕜 := ℤ) π ⊤ rw [hmu]; split_ifs <;> simp _ = blockProd κ (⊤ : NC n) := by simp _ = κ n := blockProd_top κ hn /-- **Speicher Moment–Cumulant Bijection (Right Inverse):** `momentsOfCumulants (cumulantsOfMoments m) n = m n` for every `n ≥ 1` over any commutative ring `R`. -/ theorem momentsOfCumulants_cumulantsOfMoments {R : Type*} [CommRing R] (m : ℕ → R) {n : ℕ} (hn : 1 ≤ n) : momentsOfCumulants (cumulantsOfMoments m) n = m n := by rw [momentsOfCumulants, if_neg (by omega)] simp_rw [blockProd_cumulants_eq_sum_le m] calc ∑ σ : NC n, ∑ π ∈ Finset.Iic σ, blockProd m π * (mobiusNC π σ : R) = ∑ σ : NC n, ∑ π : NC n, if π ≤ σ then blockProd m π * (mobiusNC π σ : R) else 0 := by refine Finset.sum_congr rfl fun σ _ => ?_ rw [← Finset.sum_filter] congr 1; ext π; simp [Finset.mem_Iic] _ = ∑ π : NC n, ∑ σ : NC n, if π ≤ σ then blockProd m π * (mobiusNC π σ : R) else 0 := Finset.sum_comm _ = ∑ π : NC n, blockProd m π * ((∑ σ ∈ Finset.Icc π (⊤ : NC n), mobiusNC π σ : ℤ) : R) := by refine Finset.sum_congr rfl fun π _ => ?_ rw [Int.cast_sum, Finset.mul_sum, ← Finset.sum_filter] refine Finset.sum_congr ?_ fun _ _ => rfl ext σ; simp _ = ∑ π : NC n, blockProd m π * (if π = (⊤ : NC n) then (1 : R) else 0) := by refine Finset.sum_congr rfl fun π _ => ?_ have hmu : ∑ σ ∈ Finset.Icc π (⊤ : NC n), mobiusNC π σ = if π = ⊤ then 1 else 0 := IncidenceAlgebra.sum_Icc_mu_right (𝕜 := ℤ) π ⊤ rw [hmu]; split_ifs <;> simp _ = blockProd m (⊤ : NC n) := by simp _ = m n := blockProd_top m hn end MomentCumulant /-! ## Section 4: Gap-Decomposition Master Identity, Speicher Möbius Theorem & Formal R-Transform -/ section RTransformMaster /-- Formal moment generating series `M(z) = 1 + ∑_{n ≥ 1} m_n z^n`. -/ noncomputable def momentSeries {R : Type*} [CommRing R] (m : ℕ → R) : PowerSeries R := PowerSeries.mk fun n => if n = 0 then 1 else m n /-- Formal cumulant generating series `C(u) = 1 + ∑_{n ≥ 1} κ_n u^n`. -/ noncomputable def cumulantSeries {R : Type*} [CommRing R] (κ : ℕ → R) : PowerSeries R := PowerSeries.mk fun n => if n = 0 then 1 else κ n /-- Formal Voiculescu R-transform `R(u) = ∑_{n ≥ 0} κ_{n+1} u^n`, satisfying `C(u) = 1 + u R(u)`. -/ noncomputable def rTransformSeries {R : Type*} [CommRing R] (κ : ℕ → R) : PowerSeries R := PowerSeries.mk fun n => κ (n + 1) lemma cumulantSeries_eq_one_add_X_mul_rTransform {R : Type*} [CommRing R] (κ : ℕ → R) : cumulantSeries κ = 1 + PowerSeries.X * rTransformSeries κ := by ext n; cases n with | zero => simp [cumulantSeries] | succ k => simp [cumulantSeries, rTransformSeries, PowerSeries.coeff_succ_X_mul] /-- Product of `κ(|B|)` over all blocks `B` of `π` OTHER than the block containing `0`. -/ def restProd {R : Type*} [CommRing R] (κ : ℕ → R) {n : ℕ} (π : NC n) : R := ∏ r ∈ π.rootSet.erase 0, κ (π.blockFinset r).card lemma zero_mem_rootSet {n : ℕ} (hn : 1 ≤ n) (π : NC n) : 0 ∈ π.rootSet := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), π.isMin_zero⟩ lemma blockProd_eq_mul_restProd {R : Type*} [CommRing R] (κ : ℕ → R) {n : ℕ} (hn : 1 ≤ n) (π : NC n) : blockProd κ π = κ (π.blockFinset 0).card * restProd κ π := by unfold blockProd restProd exact (Finset.mul_prod_erase π.rootSet _ (zero_mem_rootSet hn π)).symm lemma blockFinset_zero_prepend {m : ℕ} (σ : NC m) : ((NC.prepend σ).blockFinset 0).card = 1 := by have h : (NC.prepend σ).blockFinset 0 = {0} := by ext j; simp only [NC.blockFinset, Finset.mem_filter, Finset.mem_range, Finset.mem_singleton] constructor · rintro ⟨_, hrel⟩ cases j with | zero => rfl | succ k => rw [NC.prepend_rel_zero_succ] at hrel; exact absurd hrel (by decide) · rintro rfl; exact ⟨by omega, (NC.prepend σ).refl 0 (by omega)⟩ rw [h, Finset.card_singleton] lemma restProd_prepend {R : Type*} [CommRing R] (κ : ℕ → R) {m : ℕ} (σ : NC m) : restProd κ (NC.prepend σ) = blockProd κ σ := by unfold restProd blockProd refine Finset.prod_bij (fun r _ => r - 1) ?_ ?_ ?_ ?_ · intro r hr obtain ⟨hr0, hr_in⟩ := Finset.mem_erase.mp hr obtain ⟨hr_lt, hr_min⟩ := Finset.mem_filter.mp hr_in refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by have := Finset.mem_range.mp hr_lt; omega), ?_⟩ have hsucc : r - 1 + 1 = r := by omega rw [← NC.isMin_prepend_succ σ (r - 1), hsucc]; exact hr_min · intro r₁ hr₁ r₂ hr₂ heq have h1 := (Finset.mem_erase.mp hr₁).1 have h2 := (Finset.mem_erase.mp hr₂).1 omega · intro u hu obtain ⟨hu_lt, hu_min⟩ := Finset.mem_filter.mp hu have hu_lt' := Finset.mem_range.mp hu_lt refine ⟨u + 1, Finset.mem_erase.mpr ⟨Nat.succ_ne_zero u, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), by rw [NC.isMin_prepend_succ]; exact hu_min⟩⟩, by omega⟩ · intro r hr have hr0 := (Finset.mem_erase.mp hr).1 congr 1 refine Finset.card_bij (fun x _ => x - 1) ?_ ?_ ?_ · intro x hx obtain ⟨hx_lt, hx_rel⟩ := Finset.mem_filter.mp hx have hx_lt' := Finset.mem_range.mp hx_lt have hx0 : x ≠ 0 := by intro h0; subst h0 have := (NC.prepend σ).rel 0 r rw [(NC.prepend σ).symm, show r = (r - 1) + 1 by omega, NC.prepend_rel_zero_succ] at hx_rel exact absurd hx_rel (by decide) refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩ have hrel' := NC.prepend_rel_succ σ (r - 1) (x - 1) rw [show r - 1 + 1 = r by omega, show x - 1 + 1 = x by omega] at hrel' rw [← hrel']; exact hx_rel · intro x₁ hx₁ x₂ hx₂ heq have h1 : x₁ ≠ 0 := by intro h0; subst h0 have hr1 := (Finset.mem_filter.mp hx₁).2 rw [(NC.prepend σ).symm, show r = (r - 1) + 1 by omega, NC.prepend_rel_zero_succ] at hr1 exact absurd hr1 (by decide) have h2 : x₂ ≠ 0 := by intro h0; subst h0 have hr2 := (Finset.mem_filter.mp hx₂).2 rw [(NC.prepend σ).symm, show r = (r - 1) + 1 by omega, NC.prepend_rel_zero_succ] at hr2 exact absurd hr2 (by decide) omega · intro y hy obtain ⟨hy_lt, hy_rel⟩ := Finset.mem_filter.mp hy have hy_lt' := Finset.mem_range.mp hy_lt refine ⟨y + 1, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩, by omega⟩ have hrel' := NC.prepend_rel_succ σ (r - 1) y rw [show r - 1 + 1 = r by omega] at hrel' rw [hrel']; exact hy_rel lemma blockFinset_zero_joinAt {m j : ℕ} (hj : j < m) (a : NC j) (b : NC (m - j)) : ((NC.joinAt j hj a b).blockFinset 0).card = (b.blockFinset 0).card + 1 := by have h0_mem : 0 ∈ (NC.joinAt j hj a b).blockFinset 0 := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), (NC.joinAt j hj a b).refl 0 (by omega)⟩ rw [← Finset.card_erase_add_one h0_mem] congr 1 refine Finset.card_bij (fun x _ => x - (j + 1)) ?_ ?_ ?_ · intro x hx obtain ⟨hx0, hx_in⟩ := Finset.mem_erase.mp hx obtain ⟨hx_lt, hx_rel⟩ := Finset.mem_filter.mp hx_in have hx_lt' := Finset.mem_range.mp hx_lt have hx_ge : j + 1 ≤ x := by by_contra hlt have := NC.joinAt_rel_zero_inner (j := j) (hj := hj) (a := a) (b := b) (x - 1) (by omega) rw [show x - 1 + 1 = x by omega, hx_rel] at this; exact absurd this (by decide) refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩ have hrel := NC.joinAt_rel_out (j := j) (hj := hj) (a := a) (b := b) 0 x (Or.inl rfl) (Or.inr ⟨hx_ge, by omega⟩) rw [hrel] at hx_rel simpa [NC.oIdx, show x ≠ 0 by omega] using hx_rel · intro x₁ hx₁ x₂ hx₂ heq have hge1 : j + 1 ≤ x₁ := by by_contra hlt obtain ⟨hx0, hx_in⟩ := Finset.mem_erase.mp hx₁ have hx_rel := (Finset.mem_filter.mp hx_in).2 have := NC.joinAt_rel_zero_inner (j := j) (hj := hj) (a := a) (b := b) (x₁ - 1) (by omega) rw [show x₁ - 1 + 1 = x₁ by omega, hx_rel] at this; exact absurd this (by decide) have hge2 : j + 1 ≤ x₂ := by by_contra hlt obtain ⟨hx0, hx_in⟩ := Finset.mem_erase.mp hx₂ have hx_rel := (Finset.mem_filter.mp hx_in).2 have := NC.joinAt_rel_zero_inner (j := j) (hj := hj) (a := a) (b := b) (x₂ - 1) (by omega) rw [show x₂ - 1 + 1 = x₂ by omega, hx_rel] at this; exact absurd this (by decide) omega · intro y hy obtain ⟨hy_lt, hy_rel⟩ := Finset.mem_filter.mp hy have hy_lt' := Finset.mem_range.mp hy_lt refine ⟨y + (j + 1), Finset.mem_erase.mpr ⟨by omega, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩⟩, by omega⟩ rw [NC.joinAt_rel_out (j := j) (hj := hj) (a := a) (b := b) 0 (y + (j + 1)) (Or.inl rfl) (Or.inr ⟨by omega, by omega⟩)] simpa [NC.oIdx, show y + (j + 1) ≠ 0 by omega] using hy_rel lemma restProd_joinAt {R : Type*} [CommRing R] (κ : ℕ → R) {m j : ℕ} (hj : j < m) (a : NC j) (b : NC (m - j)) : restProd κ (NC.joinAt j hj a b) = blockProd κ a * restProd κ b := by set π := NC.joinAt j hj a b set S_in := (π.rootSet.erase 0).filter fun r => r ≤ j set S_out := (π.rootSet.erase 0).filter fun r => j < r have hS_out : S_out = (π.rootSet.erase 0).filter fun r => ¬ r ≤ j := by ext r; simp only [S_out, Finset.mem_filter, not_le] have hsplit : restProd κ π = (∏ r ∈ S_in, κ (π.blockFinset r).card) * (∏ r ∈ S_out, κ (π.blockFinset r).card) := by unfold restProd rw [hS_out] exact (Finset.prod_filter_mul_prod_filter_not (π.rootSet.erase 0) (fun r => r ≤ j) (fun r => κ (π.blockFinset r).card)).symm rw [hsplit] congr 1 · unfold blockProd refine Finset.prod_bij (fun r _ => r - 1) ?_ ?_ ?_ ?_ · intro r hr obtain ⟨hr_er, hr_le⟩ := Finset.mem_filter.mp hr obtain ⟨hr0, hr_in⟩ := Finset.mem_erase.mp hr_er have hr_min := (Finset.mem_filter.mp hr_in).2 refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩ have := NC.isMin_joinAt_in (j := j) (hj := hj) (a := a) (b := b) (r - 1) (by omega) rw [show r - 1 + 1 = r by omega] at this rw [← this]; exact hr_min · intro r₁ hr₁ r₂ hr₂ heq have h1 := (Finset.mem_erase.mp (Finset.mem_filter.mp hr₁).1).1 have h2 := (Finset.mem_erase.mp (Finset.mem_filter.mp hr₂).1).1 omega · intro u hu obtain ⟨hu_lt, hu_min⟩ := Finset.mem_filter.mp hu have hu_lt' := Finset.mem_range.mp hu_lt refine ⟨u + 1, Finset.mem_filter.mpr ⟨Finset.mem_erase.mpr ⟨Nat.succ_ne_zero u, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), by rw [NC.isMin_joinAt_in (j := j) (hj := hj) (a := a) (b := b) u hu_lt']; exact hu_min⟩⟩, by omega⟩, by omega⟩ · intro r hr obtain ⟨hr_er, hr_le⟩ := Finset.mem_filter.mp hr have hr0 := (Finset.mem_erase.mp hr_er).1 congr 1 refine Finset.card_bij (fun x _ => x - 1) ?_ ?_ ?_ · intro x hx obtain ⟨hx_lt, hx_rel⟩ := Finset.mem_filter.mp hx have hx_lt' := Finset.mem_range.mp hx_lt have hx_in : 1 ≤ x ∧ x ≤ j := by by_contra hnot have hout : x = 0 ∨ (j + 1 ≤ x ∧ x ≤ m) := by omega have := NC.joinAt_rel_cross (j := j) (hj := hj) (a := a) (b := b) r x ⟨by omega, hr_le⟩ hout rw [hx_rel] at this; exact absurd this (by decide) refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩ have hrel' := NC.joinAt_rel_in (j := j) (hj := hj) (a := a) (b := b) (r - 1) (x - 1) (by omega) (by omega) rw [show r - 1 + 1 = r by omega, show x - 1 + 1 = x by omega] at hrel' rw [← hrel']; exact hx_rel · intro x₁ hx₁ x₂ hx₂ heq have hx1 : 1 ≤ x₁ := by by_contra hlt have hx_rel := (Finset.mem_filter.mp hx₁).2 have := NC.joinAt_rel_cross (j := j) (hj := hj) (a := a) (b := b) r x₁ ⟨by omega, hr_le⟩ (Or.inl (by omega)) rw [hx_rel] at this; exact absurd this (by decide) have hx2 : 1 ≤ x₂ := by by_contra hlt have hx_rel := (Finset.mem_filter.mp hx₂).2 have := NC.joinAt_rel_cross (j := j) (hj := hj) (a := a) (b := b) r x₂ ⟨by omega, hr_le⟩ (Or.inl (by omega)) rw [hx_rel] at this; exact absurd this (by decide) omega · intro y hy obtain ⟨hy_lt, hy_rel⟩ := Finset.mem_filter.mp hy have hy_lt' := Finset.mem_range.mp hy_lt refine ⟨y + 1, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩, by omega⟩ have hrel' := NC.joinAt_rel_in (j := j) (hj := hj) (a := a) (b := b) (r - 1) y (by omega) hy_lt' rw [show r - 1 + 1 = r by omega] at hrel' rw [hrel']; exact hy_rel · unfold restProd refine Finset.prod_bij (fun r _ => r - (j + 1)) ?_ ?_ ?_ ?_ · intro r hr obtain ⟨hr_er, hr_gt⟩ := Finset.mem_filter.mp hr obtain ⟨_, hr_in⟩ := Finset.mem_erase.mp hr_er obtain ⟨hr_lt, hr_min⟩ := Finset.mem_filter.mp hr_in have hr_lt' := Finset.mem_range.mp hr_lt have hr_ne : r ≠ j + 1 := by intro h; subst h; rw [NC.isMin_joinAt_link] at hr_min; exact absurd hr_min (by decide) refine Finset.mem_erase.mpr ⟨by omega, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩⟩ have := NC.isMin_joinAt_out (j := j) (hj := hj) (a := a) (b := b) (r - (j + 1) - 1) (by omega) rw [show j + 1 + (r - (j + 1) - 1 + 1) = r by omega, show r - (j + 1) - 1 + 1 = r - (j + 1) by omega] at this rw [← this]; exact hr_min · intro r₁ hr₁ r₂ hr₂ heq have h1 := (Finset.mem_filter.mp hr₁).2 have h2 := (Finset.mem_filter.mp hr₂).2 omega · intro u hu obtain ⟨hu0, hu_in⟩ := Finset.mem_erase.mp hu obtain ⟨hu_lt, hu_min⟩ := Finset.mem_filter.mp hu_in have hu_lt' := Finset.mem_range.mp hu_lt refine ⟨j + 1 + u, Finset.mem_filter.mpr ⟨Finset.mem_erase.mpr ⟨by omega, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩⟩, by omega⟩, by omega⟩ have := NC.isMin_joinAt_out (j := j) (hj := hj) (a := a) (b := b) (u - 1) (by omega) rw [show u - 1 + 1 = u by omega] at this rw [this]; exact hu_min · intro r hr obtain ⟨hr_er, hr_gt⟩ := Finset.mem_filter.mp hr obtain ⟨_, hr_in⟩ := Finset.mem_erase.mp hr_er obtain ⟨hr_lt, hr_min⟩ := Finset.mem_filter.mp hr_in have hr_lt' := Finset.mem_range.mp hr_lt have hr_ne : r ≠ j + 1 := by intro h; subst h; rw [NC.isMin_joinAt_link] at hr_min; exact absurd hr_min (by decide) have hr_not0 : π.rel r 0 = false := by cases h : π.rel r 0 · rfl · have hmin' := of_decide_eq_true hr_min 0 (by omega) rw [π.symm, h] at hmin'; exact absurd hmin' (by decide) congr 1 refine Finset.card_bij (fun x _ => x - (j + 1)) ?_ ?_ ?_ · intro x hx obtain ⟨hx_lt, hx_rel⟩ := Finset.mem_filter.mp hx have hx_lt' := Finset.mem_range.mp hx_lt have hx0 : x ≠ 0 := by intro h0; subst h0; rw [hr_not0] at hx_rel; exact absurd hx_rel (by decide) have hx_ge : j + 1 ≤ x := by by_contra hlt have := NC.joinAt_rel_cross (j := j) (hj := hj) (a := a) (b := b) x r ⟨by omega, by omega⟩ (Or.inr ⟨by omega, by omega⟩) rw [π.symm, hx_rel] at this; exact absurd this (by decide) refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩ have hrel := NC.joinAt_rel_out (j := j) (hj := hj) (a := a) (b := b) r x (Or.inr ⟨by omega, by omega⟩) (Or.inr ⟨hx_ge, by omega⟩) rw [hrel] at hx_rel simpa [NC.oIdx, show r ≠ 0 by omega, hx0] using hx_rel · intro x₁ hx₁ x₂ hx₂ heq have hx_ge1 : j + 1 ≤ x₁ := by by_contra hlt obtain ⟨hx_lt, hx_rel⟩ := Finset.mem_filter.mp hx₁ by_cases h0 : x₁ = 0 · subst h0; rw [hr_not0] at hx_rel; exact absurd hx_rel (by decide) · have := NC.joinAt_rel_cross (j := j) (hj := hj) (a := a) (b := b) x₁ r ⟨by omega, by omega⟩ (Or.inr ⟨by omega, by omega⟩) rw [π.symm, hx_rel] at this; exact absurd this (by decide) have hx_ge2 : j + 1 ≤ x₂ := by by_contra hlt obtain ⟨hx_lt, hx_rel⟩ := Finset.mem_filter.mp hx₂ by_cases h0 : x₂ = 0 · subst h0; rw [hr_not0] at hx_rel; exact absurd hx_rel (by decide) · have := NC.joinAt_rel_cross (j := j) (hj := hj) (a := a) (b := b) x₂ r ⟨by omega, by omega⟩ (Or.inr ⟨by omega, by omega⟩) rw [π.symm, hx_rel] at this; exact absurd this (by decide) omega · intro y hy obtain ⟨hy_lt, hy_rel⟩ := Finset.mem_filter.mp hy have hy_lt' := Finset.mem_range.mp hy_lt refine ⟨y + (j + 1), Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), ?_⟩, by omega⟩ rw [NC.joinAt_rel_out (j := j) (hj := hj) (a := a) (b := b) r (y + (j + 1)) (Or.inr ⟨by omega, by omega⟩) (Or.inr ⟨by omega, by omega⟩)] simpa [NC.oIdx, show r ≠ 0 by omega, show y + (j + 1) ≠ 0 by omega] using hy_rel /-- **Gap-Decomposition Master Identity:** For every `n ≥ 1` and `1 ≤ s ≤ n`, summing `restProd κ π` over all `π ∈ NC(n)` whose `0`-block has size `s` equals `[z^{n - s}] M(z)^s` where `M(z) = momentSeries (momentsOfCumulants κ)`. -/ theorem sum_restProd_blockSize_zero {R : Type*} [CommRing R] (κ : ℕ → R) : ∀ (n s : ℕ), 1 ≤ s → s ≤ n → ∑ π ∈ Finset.univ.filter (fun π : NC n => (π.blockFinset 0).card = s), restProd κ π = PowerSeries.coeff (n - s) ((momentSeries (momentsOfCumulants κ)) ^ s) := by intro n induction n using Nat.strong_induction_on with | _ n ih => intro s hs1 hsn obtain ⟨m, rfl⟩ : ∃ m, n = m + 1 := ⟨n - 1, by omega⟩ set M := momentSeries (momentsOfCumulants κ) rw [Finset.sum_filter] rw [NC.sum_decomp m (fun π => if (π.blockFinset 0).card = s then restProd κ π else 0)] cases s with | zero => omega | succ s' => cases s' with | zero => -- s = 1: only `prepend σ` contributes! have hjoin0 : ∑ j : Fin m, ∑ p : NC j.1 × NC (m - j.1), (if ((NC.joinAt j.1 j.2 p.1 p.2).blockFinset 0).card = 0 + 1 then restProd κ (NC.joinAt j.1 j.2 p.1 p.2) else 0) = 0 := by refine Finset.sum_eq_zero fun j _ => Finset.sum_eq_zero fun p _ => ?_ rw [blockFinset_zero_joinAt] have hpos : 0 < (p.2.blockFinset 0).card := blockFinset_card_pos p.2 (zero_mem_rootSet (by omega) p.2) rw [if_neg (by omega)] rw [hjoin0, add_zero] simp only [blockFinset_zero_prepend, ↓reduceIte, restProd_prepend] rw [show m + 1 - (0 + 1) = m by omega, pow_one] simp only [M, momentSeries, PowerSeries.coeff_mk, momentsOfCumulants] by_cases hm : m = 0 · subst hm have h1 : Fintype.card (NC 0) = 1 := NC.card_zero obtain ⟨π₀, hπ₀⟩ := Fintype.card_eq_one_iff.mp h1 rw [Finset.sum_eq_single π₀ (fun π _ hne => absurd (hπ₀ π) hne) (fun h => absurd (Finset.mem_univ _) h)] simp [blockProd, NC.rootSet] · rw [if_neg hm, if_neg hm] | succ t => -- s = t + 2 ≥ 2: only `joinAt j a b` contributes! have hprep0 : ∑ σ : NC m, (if ((NC.prepend σ).blockFinset 0).card = t + 2 then restProd κ (NC.prepend σ) else 0) = 0 := by refine Finset.sum_eq_zero fun σ _ => ?_ rw [blockFinset_zero_prepend, if_neg (by omega)] rw [hprep0, zero_add] have hterm : ∀ j : Fin m, ∑ p : NC j.1 × NC (m - j.1), (if ((NC.joinAt j.1 j.2 p.1 p.2).blockFinset 0).card = t + 2 then restProd κ (NC.joinAt j.1 j.2 p.1 p.2) else 0) = PowerSeries.coeff j.1 M * PowerSeries.coeff (m - j.1 - (t + 1)) (M ^ (t + 1)) * (if t + 1 ≤ m - j.1 then 1 else 0) := by intro j rw [Fintype.sum_prod_type] simp_rw [blockFinset_zero_joinAt, restProd_joinAt] have hcond : ∀ b : NC (m - j.1), ((b.blockFinset 0).card + 1 = t + 2) ↔ (b.blockFinset 0).card = t + 1 := fun _ => by omega simp_rw [hcond] have hfactor : ∑ a : NC j.1, ∑ b : NC (m - j.1), (if (b.blockFinset 0).card = t + 1 then blockProd κ a * restProd κ b else 0) = (∑ a : NC j.1, blockProd κ a) * (∑ b ∈ Finset.univ.filter (fun b : NC (m - j.1) => (b.blockFinset 0).card = t + 1), restProd κ b) := by rw [Finset.sum_mul] refine Finset.sum_congr rfl fun a _ => ?_ rw [Finset.sum_filter, Finset.mul_sum] refine Finset.sum_congr rfl fun b _ => by split_ifs <;> simp rw [hfactor] have hMa : ∑ a : NC j.1, blockProd κ a = PowerSeries.coeff j.1 M := by simp only [M, momentSeries, PowerSeries.coeff_mk, momentsOfCumulants] by_cases hj0 : j.1 = 0 · rw [if_pos hj0] have h1 : Fintype.card (NC j.1) = 1 := by rw [hj0]; exact NC.card_zero obtain ⟨π₀, hπ₀⟩ := Fintype.card_eq_one_iff.mp h1 rw [Finset.sum_eq_single π₀ (fun π _ hne => absurd (hπ₀ π) hne) (fun h => absurd (Finset.mem_univ _) h)] simp [blockProd, NC.rootSet, hj0] · rw [if_neg hj0, if_neg hj0] rw [hMa] by_cases hle : t + 1 ≤ m - j.1 · rw [if_pos hle, mul_one] rw [ih (m - j.1) (by omega) (t + 1) (by omega) hle] · rw [if_neg hle, mul_zero] have hempty : Finset.univ.filter (fun b : NC (m - j.1) => (b.blockFinset 0).card = t + 1) = ∅ := by rw [Finset.filter_eq_empty_iff] intro b _ have hcard : (b.blockFinset 0).card ≤ m - j.1 := by calc (b.blockFinset 0).card ≤ (Finset.range (m - j.1)).card := Finset.card_le_card (Finset.filter_subset _ _) _ = m - j.1 := Finset.card_range _ omega rw [hempty, Finset.sum_empty, mul_zero] simp_rw [hterm] conv_rhs => rw [pow_succ', PowerSeries.coeff_mul] set d := m + 1 - (t + 2) have hd : d = m - (t + 1) := by omega rw [hd] calc ∑ j : Fin m, PowerSeries.coeff j.1 M * PowerSeries.coeff (m - j.1 - (t + 1)) (M ^ (t + 1)) * (if t + 1 ≤ m - j.1 then 1 else 0) = ∑ j ∈ Finset.univ.filter (fun j : Fin m => j.1 ≤ m - (t + 1)), PowerSeries.coeff j.1 M * PowerSeries.coeff (m - j.1 - (t + 1)) (M ^ (t + 1)) := by rw [Finset.sum_filter] refine Finset.sum_congr rfl fun j _ => ?_ by_cases h : j.1 ≤ m - (t + 1) · rw [if_pos h, if_pos (by omega), mul_one] · rw [if_neg h, if_neg (by omega), mul_zero] _ = ∑ pq ∈ Finset.HasAntidiagonal.antidiagonal (m - (t + 1)), PowerSeries.coeff pq.1 M * PowerSeries.coeff pq.2 (M ^ (t + 1)) := by refine Finset.sum_nbij (fun j : Fin m => (j.1, m - j.1 - (t + 1))) ?_ ?_ ?_ ?_ · intro j hj have hjle := (Finset.mem_filter.mp hj).2 exact Finset.HasAntidiagonal.mem_antidiagonal.mpr (by omega) · intro j₁ _ j₂ _ heq exact Fin.ext (congrArg Prod.fst heq) · intro pq hpq have hpq_sum := Finset.HasAntidiagonal.mem_antidiagonal.mp (Finset.mem_coe.mp hpq) refine ⟨⟨pq.1, by omega⟩, Finset.mem_coe.mpr (Finset.mem_filter.mpr ⟨Finset.mem_univ _, by dsimp; omega⟩), Prod.ext rfl (by dsimp; omega)⟩ · intro _ _; rfl lemma coeff_X_pow_mul_self {R : Type*} [CommRing R] (s n : ℕ) (f : PowerSeries R) : PowerSeries.coeff n (PowerSeries.X ^ s * f) = if s ≤ n then PowerSeries.coeff (n - s) f else 0 := by induction s generalizing n with | zero => simp | succ k ih => cases n with | zero => rw [pow_succ', mul_assoc, PowerSeries.coeff_zero_X_mul]; simp | succ m => rw [pow_succ', mul_assoc, PowerSeries.coeff_succ_X_mul, ih m] simp /-- **Formal Power Series R-Transform Master Equation `M(z) = C(z M(z))`:** For any cumulant sequence `κ : ℕ → R` over any commutative ring `R`, `momentSeries (momentsOfCumulants κ) = (cumulantSeries κ).subst (X * momentSeries (momentsOfCumulants κ))`. -/ theorem momentSeries_eq_cumulantSeries_subst {R : Type*} [CommRing R] (κ : ℕ → R) : momentSeries (momentsOfCumulants κ) = PowerSeries.subst (PowerSeries.X * momentSeries (momentsOfCumulants κ)) (cumulantSeries κ) := by set M : PowerSeries R := momentSeries (momentsOfCumulants κ) have hsub : PowerSeries.HasSubst (PowerSeries.X * M) := PowerSeries.HasSubst.of_constantCoeff_zero' (by rw [map_mul, PowerSeries.constantCoeff_X, zero_mul]) ext n rw [PowerSeries.coeff_subst' hsub] simp only [smul_eq_mul] cases n with | zero => rw [finsum_eq_sum_of_support_subset (s := Finset.range 1)] · simp [M, momentSeries, cumulantSeries] · intro s hs simp only [Function.mem_support, ne_eq] at hs cases s with | zero => simp | succ k => exfalso; apply hs rw [mul_pow, pow_succ', mul_assoc, PowerSeries.coeff_zero_X_mul, mul_zero] | succ m => have hsupp : Function.support (fun s : ℕ => PowerSeries.coeff s (cumulantSeries κ) * PowerSeries.coeff (m + 1) ((PowerSeries.X * M) ^ s)) ⊆ Finset.Icc 1 (m + 1) := by intro s hs simp only [Function.mem_support, ne_eq] at hs rw [Finset.mem_coe, Finset.mem_Icc] by_contra hnot apply hs by_cases hs0 : s = 0 · subst hs0; simp [PowerSeries.coeff_one] · rw [mul_pow, coeff_X_pow_mul_self, if_neg (by omega), mul_zero] rw [finsum_eq_sum_of_support_subset _ hsupp] have hRHS : ∑ s ∈ Finset.Icc 1 (m + 1), PowerSeries.coeff s (cumulantSeries κ) * PowerSeries.coeff (m + 1) ((PowerSeries.X * M) ^ s) = ∑ s ∈ Finset.Icc 1 (m + 1), κ s * PowerSeries.coeff (m + 1 - s) (M ^ s) := by refine Finset.sum_congr rfl fun s hs => ?_ obtain ⟨hs1, hsm⟩ := Finset.mem_Icc.mp hs rw [cumulantSeries, PowerSeries.coeff_mk, if_neg (by omega), mul_pow, coeff_X_pow_mul_self, if_pos hsm] rw [hRHS] conv_lhs => simp only [M, momentSeries, PowerSeries.coeff_mk, Nat.succ_ne_zero, ↓reduceIte, momentsOfCumulants] rw [← Finset.sum_fiberwise_of_maps_to (g := fun π : NC (m + 1) => (π.blockFinset 0).card) (t := Finset.Icc 1 (m + 1)) (fun π _ => Finset.mem_Icc.mpr ⟨blockFinset_card_pos π (zero_mem_rootSet (by omega) π), by calc (π.blockFinset 0).card ≤ (Finset.range (m + 1)).card := Finset.card_le_card (Finset.filter_subset _ _) _ = m + 1 := Finset.card_range _⟩)] refine Finset.sum_congr rfl fun s hs => ?_ obtain ⟨hs1, hsm⟩ := Finset.mem_Icc.mp hs rw [← sum_restProd_blockSize_zero κ (m + 1) s hs1 hsm, Finset.mul_sum] refine Finset.sum_congr rfl fun π hπ => ?_ have hcard := (Finset.mem_filter.mp hπ).2 rw [blockProd_eq_mul_restProd κ (by omega) π, hcard] /-- Equivalent R-transform form `M(z) = 1 + (z M(z)) · R(z M(z))`. -/ theorem momentSeries_eq_rTransform_subst {R : Type*} [CommRing R] (κ : ℕ → R) : momentSeries (momentsOfCumulants κ) = 1 + (PowerSeries.X * momentSeries (momentsOfCumulants κ)) * PowerSeries.subst (PowerSeries.X * momentSeries (momentsOfCumulants κ)) (rTransformSeries κ) := by set M : PowerSeries R := momentSeries (momentsOfCumulants κ) have hsub : PowerSeries.HasSubst (PowerSeries.X * M) := PowerSeries.HasSubst.of_constantCoeff_zero' (by rw [map_mul, PowerSeries.constantCoeff_X, zero_mul]) have hM := momentSeries_eq_cumulantSeries_subst κ rw [cumulantSeries_eq_one_add_X_mul_rTransform, PowerSeries.subst_add hsub, PowerSeries.subst_mul hsub, PowerSeries.subst_X hsub] at hM have hsub1 : PowerSeries.subst (PowerSeries.X * M) (1 : PowerSeries R) = 1 := by simpa only [map_one] using PowerSeries.subst_C (a := PowerSeries.X * M) (1 : R) rw [hsub1] at hM exact hM /-- **Exact Cauchy / R-Transform Two-Sided Formal Compositional Inversion:** Let `U(z) = z M(z)` (reciprocal Cauchy transform `G(1/z)`) and `K(u) = u / C(u) = (R(u) + 1/u)⁻¹`. Then `K(U(z)) = z` AND `U(K(u)) = u` identically as formal power series over `ℚ`! -/ theorem cauchy_rTransform_inversion (κ : ℕ → ℚ) : let M : PowerSeries ℚ := momentSeries (momentsOfCumulants κ) let U : PowerSeries ℚ := PowerSeries.X * M let C : PowerSeries ℚ := cumulantSeries κ let K : PowerSeries ℚ := PowerSeries.X * C⁻¹ PowerSeries.subst U K = PowerSeries.X ∧ PowerSeries.subst K U = PowerSeries.X := by intro M U C K have hC0 : PowerSeries.constantCoeff C = 1 := by simp [C, cumulantSeries] have hU0 : PowerSeries.constantCoeff U = 0 := by rw [map_mul, PowerSeries.constantCoeff_X, zero_mul] have hU1 : PowerSeries.coeff 1 U = 1 := by simp only [U, PowerSeries.coeff_succ_X_mul, M, momentSeries, PowerSeries.coeff_mk, ↓reduceIte] have hU_sub : PowerSeries.HasSubst U := PowerSeries.HasSubst.of_constantCoeff_zero' hU0 have hCCinv : C * C⁻¹ = 1 := PowerSeries.mul_inv_cancel C (by rw [hC0]; norm_num) have hCU_inv : PowerSeries.subst U C * PowerSeries.subst U C⁻¹ = 1 := by have h := congrArg (PowerSeries.subst U) hCCinv rw [PowerSeries.subst_mul hU_sub] at h have hsub1 : PowerSeries.subst U (1 : PowerSeries ℚ) = 1 := by simpa only [map_one] using PowerSeries.subst_C (a := U) (1 : ℚ) rwa [hsub1] at h have hM_eq : M = PowerSeries.subst U C := momentSeries_eq_cumulantSeries_subst κ have hKU : PowerSeries.subst U K = PowerSeries.X := by rw [show K = PowerSeries.X * C⁻¹ from rfl, PowerSeries.subst_mul hU_sub, PowerSeries.subst_X hU_sub] calc U * PowerSeries.subst U C⁻¹ = PowerSeries.X * (M * PowerSeries.subst U C⁻¹) := by simp only [U]; ring _ = PowerSeries.X * (PowerSeries.subst U C * PowerSeries.subst U C⁻¹) := by rw [hM_eq] _ = PowerSeries.X := by rw [hCU_inv, mul_one] have : Invertible (PowerSeries.coeff 1 U) := by rw [hU1]; exact invertibleOne have hU_inv_right : PowerSeries.subst (PowerSeries.substInv U) U = PowerSeries.X := PowerSeries.subst_substInv_right U hU0 have hUinv_sub : PowerSeries.HasSubst (PowerSeries.substInv U) := PowerSeries.HasSubst.substInv U have hK_eq_inv : K = PowerSeries.substInv U := by calc K = PowerSeries.subst PowerSeries.X K := (PowerSeries.X_subst K).symm _ = PowerSeries.subst (PowerSeries.subst (PowerSeries.substInv U) U) K := by rw [hU_inv_right] _ = PowerSeries.subst (PowerSeries.substInv U) (PowerSeries.subst U K) := (PowerSeries.subst_comp_subst_apply hU_sub hUinv_sub K).symm _ = PowerSeries.subst (PowerSeries.substInv U) PowerSeries.X := by rw [hKU] _ = PowerSeries.substInv U := PowerSeries.subst_X hUinv_sub refine ⟨hKU, ?_⟩ rw [hK_eq_inv] exact hU_inv_right /-- **Exact Speicher Möbius Function Theorem:** For every `n ≥ 1`, `μ_{NC}(0_n, 1_n) = (-1)^{n - 1} C_{n - 1}`! -/ theorem speicher_mobius_exact (n : ℕ) (hn : 1 ≤ n) : mobiusNC (⊥ : NC n) ⊤ = (-1 : ℤ) ^ (n - 1) * (catalan (n - 1) : ℤ) := by let m : ℕ → ℚ := fun k => if k = 1 then 1 else 0 let κ : ℕ → ℚ := cumulantsOfMoments m have hκ_eq : ∀ k : ℕ, 1 ≤ k → κ k = (mobiusNC (⊥ : NC k) ⊤ : ℚ) := by intro k hk rw [show κ k = cumulantsOfMoments m k from rfl, cumulantsOfMoments, if_neg (by omega)] rw [Finset.sum_eq_single (⊥ : NC k)] · rw [blockProd_bot]; simp [m] · intro π _ hne have h0 : blockProd m π = 0 := by have hex : ∃ r ∈ π.rootSet, (π.blockFinset r).card ≠ 1 := by by_contra hall; push Not at hall apply hne; apply NC.ext'; intro i j hi hj rw [Bool.eq_iff_iff, bot_rel] simp only [hi, true_and, decide_eq_true_eq] constructor · intro hij have hr := π.rootOf_mem_rootSet hi have hcard1 := hall (π.rootOf i) hr have hi_mem := π.mem_blockFinset_rootOf hi have hj_mem : j ∈ π.blockFinset (π.rootOf i) := by rw [(π.rootOf_eq_iff hi hj).mpr hij]; exact π.mem_blockFinset_rootOf hj obtain ⟨u, hu⟩ := Finset.card_eq_one.mp hcard1 rw [hu, Finset.mem_singleton] at hi_mem hj_mem rw [hi_mem, hj_mem] · rintro rfl; exact π.refl i hi obtain ⟨r, hr, hne1⟩ := hex exact Finset.prod_eq_zero hr (by simp [m, hne1]) rw [h0, zero_mul] · intro h; exact absurd (Finset.mem_univ _) h have hm_eq : momentSeries (momentsOfCumulants κ) = 1 + PowerSeries.X := by ext k cases k with | zero => simp [momentSeries] | succ r => simp only [momentSeries, PowerSeries.coeff_mk, Nat.succ_ne_zero, ↓reduceIte, map_add, PowerSeries.coeff_one, PowerSeries.coeff_X, zero_add] rw [momentsOfCumulants_cumulantsOfMoments m (by omega)] have hC_sub : PowerSeries.subst (PowerSeries.X * (1 + PowerSeries.X : PowerSeries ℚ)) (cumulantSeries κ) = 1 + PowerSeries.X := by have h := momentSeries_eq_cumulantSeries_subst κ rw [hm_eq] at h; exact h.symm let A : PowerSeries ℚ := PowerSeries.mk fun k => if k = 0 then 1 else (-1 : ℚ) ^ (k - 1) * (catalan (k - 1) : ℚ) let H : PowerSeries ℚ := PowerSeries.mk fun k => (-1 : ℚ) ^ k * (catalan k : ℚ) have hA_eq : A - 1 = PowerSeries.X * H := by ext k; cases k with | zero => simp [A] | succ r => rw [map_sub, PowerSeries.coeff_one, if_neg (Nat.succ_ne_zero r), sub_zero, PowerSeries.coeff_succ_X_mul] simp [A, H] have hH_eq : H + PowerSeries.X * H ^ 2 = 1 := by ext k; cases k with | zero => simp [H] | succ r => rw [map_add, PowerSeries.coeff_one, if_neg (Nat.succ_ne_zero r), PowerSeries.coeff_succ_X_mul, sq, PowerSeries.coeff_mul] simp only [H, PowerSeries.coeff_mk, catalan_succ'] push_cast rw [Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_eq_zero fun pq hpq => ?_ have hsum := Finset.HasAntidiagonal.mem_antidiagonal.mp hpq have hpow : (-1 : ℚ) ^ pq.1 * (-1 : ℚ) ^ pq.2 = (-1 : ℚ) ^ r := by rw [← pow_add, hsum] calc (-1 : ℚ) ^ (r + 1) * ((catalan pq.1 : ℚ) * (catalan pq.2 : ℚ)) + (-1 : ℚ) ^ pq.1 * (catalan pq.1 : ℚ) * ((-1 : ℚ) ^ pq.2 * (catalan pq.2 : ℚ)) = (-1 : ℚ) ^ (r + 1) * ((catalan pq.1 : ℚ) * (catalan pq.2 : ℚ)) + ((-1 : ℚ) ^ pq.1 * (-1 : ℚ) ^ pq.2) * ((catalan pq.1 : ℚ) * (catalan pq.2 : ℚ)) := by ring _ = (-1 : ℚ) ^ (r + 1) * ((catalan pq.1 : ℚ) * (catalan pq.2 : ℚ)) + (-1 : ℚ) ^ r * ((catalan pq.1 : ℚ) * (catalan pq.2 : ℚ)) := by rw [hpow] _ = 0 := by rw [pow_succ]; ring have hA_quad : A * (A - 1) = PowerSeries.X := by have hA1 : A = 1 + PowerSeries.X * H := eq_add_of_sub_eq' hA_eq calc A * (A - 1) = (1 + PowerSeries.X * H) * (PowerSeries.X * H) := by rw [hA_eq, hA1] _ = PowerSeries.X * (H + PowerSeries.X * H ^ 2) := by ring _ = PowerSeries.X := by rw [hH_eq, mul_one] set U : PowerSeries ℚ := PowerSeries.X * (1 + PowerSeries.X) have hU0 : PowerSeries.constantCoeff U = 0 := by rw [map_mul, PowerSeries.constantCoeff_X, zero_mul] have hU_sub : PowerSeries.HasSubst U := PowerSeries.HasSubst.of_constantCoeff_zero' hU0 set B : PowerSeries ℚ := PowerSeries.subst U A have hB_quad : B * (B - 1) = U := by have h := congrArg (PowerSeries.subst U) hA_quad have hsub1 : PowerSeries.subst U (1 : PowerSeries ℚ) = 1 := by simpa only [map_one] using PowerSeries.subst_C (a := U) (1 : ℚ) rw [PowerSeries.subst_mul hU_sub, PowerSeries.subst_sub hU_sub, hsub1, PowerSeries.subst_X hU_sub] at h exact h have hX1_quad : (1 + PowerSeries.X) * ((1 + PowerSeries.X) - 1) = U := by simp only [U]; ring have hdiff : (B + (1 + PowerSeries.X) - 1) * (B - (1 + PowerSeries.X)) = 0 := by have : (B + (1 + PowerSeries.X) - 1) * (B - (1 + PowerSeries.X)) = B * (B - 1) - (1 + PowerSeries.X) * ((1 + PowerSeries.X) - 1) := by ring rw [this, hB_quad, hX1_quad, sub_self] have hB0 : PowerSeries.constantCoeff B = 1 := by have hf0 : (A - 1).constantCoeff = 0 := by simp [A] have hz := PowerSeries.constantCoeff_subst_eq_zero hU0 (A - 1) hf0 have hsub1 : PowerSeries.subst U (1 : PowerSeries ℚ) = 1 := by simpa only [map_one] using PowerSeries.subst_C (a := U) (1 : ℚ) rw [PowerSeries.subst_sub hU_sub, hsub1, map_sub, map_one] at hz exact sub_eq_zero.mp hz have hU_unit : IsUnit (B + (1 + PowerSeries.X) - 1) := PowerSeries.isUnit_iff_constantCoeff.mpr (by simp only [map_sub, map_add, map_one, PowerSeries.constantCoeff_X, hB0] norm_num) obtain ⟨u, hu⟩ := hU_unit have hBA : B = 1 + PowerSeries.X := by have hzero : B - (1 + PowerSeries.X) = 0 := by calc B - (1 + PowerSeries.X) = (u⁻¹ : (PowerSeries ℚ)ˣ).val * ((B + (1 + PowerSeries.X) - 1) * (B - (1 + PowerSeries.X))) := by rw [← mul_assoc, ← hu, Units.inv_mul, one_mul] _ = 0 := by rw [hdiff, mul_zero] exact sub_eq_zero.mp hzero have hU1 : U.coeff 1 = 1 := by simp [U, PowerSeries.coeff_succ_X_mul] have : Invertible (U.coeff 1) := by rw [hU1]; exact invertibleOne have hUinv_sub : PowerSeries.HasSubst U.substInv := PowerSeries.HasSubst.substInv U have hCA : cumulantSeries κ = A := by have heq : PowerSeries.subst U (cumulantSeries κ) = PowerSeries.subst U A := hC_sub.trans hBA.symm have hcomp := congrArg (PowerSeries.subst U.substInv) heq rw [PowerSeries.subst_comp_subst_apply hU_sub hUinv_sub, PowerSeries.subst_comp_subst_apply hU_sub hUinv_sub, PowerSeries.subst_substInv_right U hU0, PowerSeries.X_subst, PowerSeries.X_subst] at hcomp exact hcomp have hcoeff := congrArg (PowerSeries.coeff n) hCA simp only [cumulantSeries, A, PowerSeries.coeff_mk, show n ≠ 0 by omega, ↓reduceIte] at hcoeff rw [hκ_eq n hn] at hcoeff exact_mod_cast hcoeff end RTransformMaster /-! ## Section 5: Free Additive (`⊞`) & Free Multiplicative (`⊠`) Convolutions (Kreweras Formula) -/ section FreeConvolutions /-- **Free Additive Convolution `m₁ ⊞ m₂`:** Defined by exact additivity of free cumulants `κ_n(m₁ ⊞ m₂) = κ_n(m₁) + κ_n(m₂)`. -/ noncomputable def freeAddConv {R : Type*} [CommRing R] (m₁ m₂ : ℕ → R) : ℕ → R := momentsOfCumulants fun n => cumulantsOfMoments m₁ n + cumulantsOfMoments m₂ n /-- Exact additivity of free cumulants under `⊞`. -/ theorem cumulantsOfMoments_freeAddConv {R : Type*} [CommRing R] (m₁ m₂ : ℕ → R) {n : ℕ} (hn : 1 ≤ n) : cumulantsOfMoments (freeAddConv m₁ m₂) n = cumulantsOfMoments m₁ n + cumulantsOfMoments m₂ n := cumulantsOfMoments_momentsOfCumulants _ hn /-- Exact additivity of formal Voiculescu R-transforms under `⊞`. -/ theorem rTransform_freeAddConv {R : Type*} [CommRing R] (m₁ m₂ : ℕ → R) : rTransformSeries (cumulantsOfMoments (freeAddConv m₁ m₂)) = rTransformSeries (cumulantsOfMoments m₁) + rTransformSeries (cumulantsOfMoments m₂) := by ext n simp only [rTransformSeries, map_add, PowerSeries.coeff_mk] exact cumulantsOfMoments_freeAddConv m₁ m₂ (by omega) theorem freeAddConv_comm {R : Type*} [CommRing R] (m₁ m₂ : ℕ → R) (n : ℕ) : freeAddConv m₁ m₂ n = freeAddConv m₂ m₁ n := by unfold freeAddConv congr 1; funext k; ring theorem freeAddConv_assoc {R : Type*} [CommRing R] (m₁ m₂ m₃ : ℕ → R) (n : ℕ) : freeAddConv (freeAddConv m₁ m₂) m₃ n = freeAddConv m₁ (freeAddConv m₂ m₃) n := by by_cases hn : n = 0 · subst hn; simp [freeAddConv, momentsOfCumulants] · unfold freeAddConv have hfun : (fun k => cumulantsOfMoments (momentsOfCumulants fun j => cumulantsOfMoments m₁ j + cumulantsOfMoments m₂ j) k + cumulantsOfMoments m₃ k) = (fun k => cumulantsOfMoments m₁ k + cumulantsOfMoments (momentsOfCumulants fun j => cumulantsOfMoments m₂ j + cumulantsOfMoments m₃ j) k) := by funext k cases k with | zero => simp [cumulantsOfMoments] | succ r => rw [cumulantsOfMoments_momentsOfCumulants _ (by omega), cumulantsOfMoments_momentsOfCumulants _ (by omega)] ring rw [hfun] /-- `k`-fold free additive convolution `m^{⊞ k}` scales all free cumulants by `k`. -/ noncomputable def freeAddConvPow {R : Type*} [CommRing R] (k : ℕ) (m : ℕ → R) : ℕ → R := momentsOfCumulants fun n => (k : R) * cumulantsOfMoments m n theorem cumulantsOfMoments_freeAddConvPow {R : Type*} [CommRing R] (k : ℕ) (m : ℕ → R) {n : ℕ} (hn : 1 ≤ n) : cumulantsOfMoments (freeAddConvPow k m) n = (k : R) * cumulantsOfMoments m n := cumulantsOfMoments_momentsOfCumulants _ hn /-- **Free Multiplicative Convolution Cumulants (Kreweras Formula):** `κ_n(a ⊠ b) = ∑_{π ∈ NC(n)} κ_π(a) · κ_{K(π)}(b)`. -/ def freeMulCumulants {R : Type*} [CommRing R] (κa κb : ℕ → R) (n : ℕ) : R := if n = 0 then 0 else ∑ π : NC n, blockProd κa π * blockProd κb (NC.kreweras π) /-- Rotation invariance of `blockProd`: `f_{rotMinusOne π} = f_π`. -/ lemma blockProd_rotMinusOne {R : Type*} [CommRing R] (f : ℕ → R) {n : ℕ} (π : NC n) : blockProd f (NC.rotMinusOne π) = blockProd f π := by by_cases hn : n = 0 · subst hn; simp [blockProd, NC.rootSet] · set rot : ℕ → ℕ := fun i => (i + 1) % n set invRot : ℕ → ℕ := fun i => (i + n - 1) % n have hrot_lt : ∀ i < n, rot i < n := fun i _ => Nat.mod_lt _ (by omega) have hinv_lt : ∀ i < n, invRot i < n := fun i _ => Nat.mod_lt _ (by omega) have hrot_inv : ∀ i < n, rot (invRot i) = i := by intro i hi; dsimp only [rot, invRot] by_cases hi0 : i = 0 · subst hi0; simp [show n - 1 + 1 = n by omega] · have h1 : (i + n - 1) % n = i - 1 := by rw [show i + n - 1 = (i - 1) + n by omega, Nat.add_mod_right, Nat.mod_eq_of_lt (by omega)] rw [h1, show i - 1 + 1 = i by omega, Nat.mod_eq_of_lt hi] have hinv_rot : ∀ i < n, invRot (rot i) = i := by intro i hi; dsimp only [rot, invRot] by_cases hlast : i + 1 = n · rw [hlast, Nat.mod_self, zero_add, Nat.mod_eq_of_lt (by omega)]; omega · have h1 : (i + 1) % n = i + 1 := Nat.mod_eq_of_lt (by omega) rw [h1, show i + 1 + n - 1 = i + n by omega, Nat.add_mod_right, Nat.mod_eq_of_lt hi] have hrel_rot : ∀ i j, i < n → j < n → (NC.rotMinusOne π).rel i j = π.rel (rot i) (rot j) := by intro i j hi hj rw [Bool.eq_iff_iff, NC.rotMinusOne_rel_iff] exact ⟨fun h => h.2.2, fun h => ⟨hi, hj, h⟩⟩ unfold blockProd refine Finset.prod_bij (fun r hr => π.rootOf (rot r)) ?_ ?_ ?_ ?_ · intro r hr exact π.rootOf_mem_rootSet (hrot_lt r (Finset.mem_range.mp (Finset.mem_filter.mp hr).1)) · intro r₁ hr₁ r₂ hr₂ heq have hr1n := Finset.mem_range.mp (Finset.mem_filter.mp hr₁).1 have hr2n := Finset.mem_range.mp (Finset.mem_filter.mp hr₂).1 have hmin1 := of_decide_eq_true (Finset.mem_filter.mp hr₁).2 have hmin2 := of_decide_eq_true (Finset.mem_filter.mp hr₂).2 have hrelπ : π.rel (rot r₁) (rot r₂) = true := (π.rootOf_eq_iff (hrot_lt r₁ hr1n) (hrot_lt r₂ hr2n)).mp heq have hrel : (NC.rotMinusOne π).rel r₁ r₂ = true := by rw [hrel_rot r₁ r₂ hr1n hr2n]; exact hrelπ by_contra hne rcases lt_or_gt_of_ne hne with hlt | hgt · have := hmin2 r₁ hlt; rw [hrel] at this; exact absurd this (by decide) · have := hmin1 r₂ hgt; rw [(NC.rotMinusOne π).symm, hrel] at this; exact absurd this (by decide) · intro u hu have hun := Finset.mem_range.mp (Finset.mem_filter.mp hu).1 have humin := of_decide_eq_true (Finset.mem_filter.mp hu).2 set r := (NC.rotMinusOne π).rootOf (invRot u) have hr_in : r ∈ (NC.rotMinusOne π).rootSet := (NC.rotMinusOne π).rootOf_mem_rootSet (hinv_lt u hun) have hrn := Finset.mem_range.mp (Finset.mem_filter.mp hr_in).1 refine ⟨r, hr_in, ?_⟩ have hrel : (NC.rotMinusOne π).rel r (invRot u) = true := (NC.rotMinusOne π).rootOf_rel (hinv_lt u hun) rw [hrel_rot r (invRot u) hrn (hinv_lt u hun), hrot_inv u hun] at hrel have hu_root : π.rootOf u = u := by have hle := Finset.min'_le (π.blockFinset u) u (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hun, π.refl u hun⟩) have hrel' := π.rootOf_rel hun simp only [NC.rootOf, hun, ↓reduceDIte] at hrel' ⊢ by_contra hne have := humin _ (lt_of_le_of_ne hle hne); rw [hrel'] at this; exact absurd this (by decide) rw [← hu_root] exact (π.rootOf_eq_iff (hrot_lt r hrn) hun).mpr hrel · intro r hr have hrn := Finset.mem_range.mp (Finset.mem_filter.mp hr).1 congr 1 have hroot_rel : π.rel (π.rootOf (rot r)) (rot r) = true := π.rootOf_rel (hrot_lt r hrn) refine Finset.card_bij (fun x _ => rot x) ?_ ?_ ?_ · intro x hx obtain ⟨hx_lt, hx_rel⟩ := Finset.mem_filter.mp hx have hxn := Finset.mem_range.mp hx_lt rw [hrel_rot r x hrn hxn] at hx_rel exact Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (hrot_lt x hxn), π.trans _ _ _ hroot_rel hx_rel⟩ · intro x₁ hx₁ x₂ hx₂ heq have h1 := Finset.mem_range.mp (Finset.mem_filter.mp hx₁).1 have h2 := Finset.mem_range.mp (Finset.mem_filter.mp hx₂).1 rw [← hinv_rot x₁ h1, ← hinv_rot x₂ h2, heq] · intro y hy obtain ⟨hy_lt, hy_rel⟩ := Finset.mem_filter.mp hy have hyn := Finset.mem_range.mp hy_lt refine ⟨invRot y, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (hinv_lt y hyn), ?_⟩, hrot_inv y hyn⟩ rw [hrel_rot r (invRot y) hrn (hinv_lt y hyn), hrot_inv y hyn] exact π.trans _ _ _ (by rw [π.symm]; exact hroot_rel) hy_rel /-- **Commutativity of Free Multiplicative Convolution Cumulants (`a ⊠ b = b ⊠ a`):** -/ theorem freeMulCumulants_comm {R : Type*} [CommRing R] (κa κb : ℕ → R) (n : ℕ) : freeMulCumulants κa κb n = freeMulCumulants κb κa n := by by_cases hn : n = 0 · simp [freeMulCumulants, hn] · simp only [freeMulCumulants, hn, ↓reduceIte] refine Finset.sum_nbij NC.kreweras ?_ ?_ ?_ ?_ · intro _ _; exact Finset.mem_univ _ · intro π₁ _ π₂ _ h; exact (NC.kreweras_bijective n).1 h · intro σ _ obtain ⟨π, hπ⟩ := (NC.kreweras_bijective n).2 σ exact ⟨π, Finset.mem_coe.mpr (Finset.mem_univ _), hπ⟩ · intro π _ rw [NC.kreweras_sq_eq_rot, blockProd_rotMinusOne, mul_comm] /-- **Kreweras Complementarity Identity:** `α ⊔ K(α) = ⊤` for every `α ∈ NC(n)`. -/ theorem sup_kreweras_eq_top {n : ℕ} (α : NC n) : α ⊔ NC.kreweras α = ⊤ := by set γ := α ⊔ NC.kreweras α have hα : α ≤ γ := le_sup_left have hK : NC.kreweras α ≤ γ := le_sup_right have h0j : ∀ j < n, γ.rel 0 j = true := by intro j induction j using Nat.strong_induction_on with | _ j ih => intro hjn cases j with | zero => exact γ.refl 0 hjn | succ k => by_cases hex : ∃ b ≤ k, α.rel b (k + 1) = true · obtain ⟨b, hbk, hba⟩ := hex exact γ.trans 0 b (k + 1) (ih b (by omega) (by omega)) (hα b (k + 1) hba) · push Not at hex have hne : (α.blockFinset (k + 1)).Nonempty := ⟨k + 1, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hjn, α.refl (k + 1) hjn⟩⟩ set c := (α.blockFinset (k + 1)).max' hne have hc_mem : c ∈ α.blockFinset (k + 1) := Finset.max'_mem _ hne have hcn : c < n := Finset.mem_range.mp (Finset.mem_filter.mp hc_mem).1 have hαkc : α.rel (k + 1) c = true := (Finset.mem_filter.mp hc_mem).2 have hkc_le : k + 1 ≤ c := Finset.le_max' _ (k + 1) (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hjn, α.refl (k + 1) hjn⟩) have hKkc : (NC.kreweras α).rel k c = true := by rw [NC.kreweras_rel_iff, NC.closedInterval_iff] refine ⟨by omega, hcn, fun a han b hbn ha_lo ha_hi hab => ?_⟩ have hmin : min k c = k := min_eq_left (by omega) have hmax : max k c = c := max_eq_right (by omega) rw [hmin] at ha_lo ⊢ rw [hmax] at ha_hi ⊢ by_cases ha_eq : a = k + 1 ∨ a = c · have hαkb : α.rel (k + 1) b = true := by rcases ha_eq with rfl | rfl · exact hab · exact α.trans _ _ _ hαkc hab have hkb_gt : k < b := by by_contra hle have := hex b (by omega) rw [α.symm, hαkb] at this; exact absurd this (by decide) have hbc_le : b ≤ c := Finset.le_max' _ b (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hbn, hαkb⟩) exact ⟨hkb_gt, hbc_le⟩ · have ha_mid : k + 1 < a ∧ a < c := by omega constructor · by_contra hle have hcross := α.nc b (k + 1) a c (by omega) ha_mid.1 ha_mid.2 (by rw [α.symm]; exact hab) hαkc have := hex b (by omega); rw [hcross] at this; exact absurd this (by decide) · by_contra hgt have hcross := α.nc (k + 1) a c b ha_mid.1 ha_mid.2 (by omega) hαkc hab have hαkb := α.trans _ _ _ hcross hab have hbc_le : b ≤ c := Finset.le_max' _ b (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hbn, hαkb⟩) omega have hγ0k : γ.rel 0 k = true := ih k (by omega) (by omega) have hγkc : γ.rel k c = true := hK k c hKkc have hγck1 : γ.rel c (k + 1) = true := hα c (k + 1) (by rw [α.symm]; exact hαkc) exact γ.trans 0 c (k + 1) (γ.trans 0 k c hγ0k hγkc) hγck1 apply NC.ext'; intro i j hi hj rw [Bool.eq_iff_iff, top_rel] simp only [hi, hj, and_self, decide_true, iff_true] exact γ.trans i 0 j (by rw [γ.symm]; exact h0j i hi) (h0j j hj) /-- **Relative Kreweras Complement Identity:** For `π ≤ τ` in `NC(n)`, taking Kreweras complements independently inside each block of `τ` produces `K(π) ⊓ τ`! -/ theorem glueOnBlocks_kreweras_eq_inf {n : ℕ} {π τ : NC n} (hπτ : π ≤ τ) : NC.glueOnBlocks τ (fun r => NC.kreweras (π.restrictSet (τ.blockFinset r.1) (τ.blockFinset_lt r.1))) = NC.kreweras π ⊓ τ := by apply NC.ext'; intro i j hi hj rw [Bool.eq_iff_iff] have hinf_rel : (NC.kreweras π ⊓ τ).rel i j = true ↔ (NC.kreweras π).rel i j = true ∧ τ.rel i j = true := by change ((NC.kreweras π).rel i j && τ.rel i j) = true ↔ _ simp [Bool.and_eq_true] rw [hinf_rel] dsimp only [NC.glueOnBlocks] by_cases hτij : τ.rel i j = true · rw [dif_pos ⟨hi, hj, hτij⟩, NC.kreweras_rel_iff, NC.closedInterval_iff, NC.kreweras_rel_iff, NC.closedInterval_iff] set r : τ.rootSet := ⟨τ.rootOf i, τ.rootOf_mem_rootSet hi⟩ set S := τ.blockFinset r.1 set e := S.orderIsoOfFin rfl have hiS : i ∈ S := τ.mem_blockFinset_rootOf hi have hjS : j ∈ S := by change j ∈ τ.blockFinset (τ.rootOf i) rw [(τ.rootOf_eq_iff hi hj).mpr hτij]; exact τ.mem_blockFinset_rootOf hj set ui := e.symm ⟨i, hiS⟩ set uj := e.symm ⟨j, hjS⟩ have hui_val : S.orderEmbOfFin rfl ui = i := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply ⟨i, hiS⟩) have huj_val : S.orderEmbOfFin rfl uj = j := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply ⟨j, hjS⟩) have hmin_eq : S.orderEmbOfFin rfl ⟨min ui.1 uj.1, lt_of_le_of_lt (min_le_left _ _) ui.2⟩ = min i j := by by_cases hle : ui.1 ≤ uj.1 · have hij : i ≤ j := by rw [← hui_val, ← huj_val]; exact (S.orderEmbOfFin rfl).monotone (Fin.mk_le_mk.mpr hle) have hfin : (⟨min ui.1 uj.1, lt_of_le_of_lt (min_le_left _ _) ui.2⟩ : Fin S.card) = ui := Fin.ext (min_eq_left hle) rw [hfin, min_eq_left hij]; exact hui_val · have hji : j ≤ i := by rw [← hui_val, ← huj_val]; exact (S.orderEmbOfFin rfl).monotone (Fin.mk_le_mk.mpr (le_of_not_ge hle)) have hfin : (⟨min ui.1 uj.1, lt_of_le_of_lt (min_le_left _ _) ui.2⟩ : Fin S.card) = uj := Fin.ext (min_eq_right (le_of_not_ge hle)) rw [hfin, min_eq_right hji]; exact huj_val have hmax_eq : S.orderEmbOfFin rfl ⟨max ui.1 uj.1, max_lt ui.2 uj.2⟩ = max i j := by by_cases hle : ui.1 ≤ uj.1 · have hij : i ≤ j := by rw [← hui_val, ← huj_val]; exact (S.orderEmbOfFin rfl).monotone (Fin.mk_le_mk.mpr hle) have hfin : (⟨max ui.1 uj.1, max_lt ui.2 uj.2⟩ : Fin S.card) = uj := Fin.ext (max_eq_right hle) rw [hfin, max_eq_right hij]; exact huj_val · have hji : j ≤ i := by rw [← hui_val, ← huj_val]; exact (S.orderEmbOfFin rfl).monotone (Fin.mk_le_mk.mpr (le_of_not_ge hle)) have hfin : (⟨max ui.1 uj.1, max_lt ui.2 uj.2⟩ : Fin S.card) = ui := Fin.ext (max_eq_left (le_of_not_ge hle)) rw [hfin, max_eq_left hji]; exact hui_val constructor · rintro ⟨_, _, hloc⟩ refine ⟨⟨hi, hj, fun a han b hbn ha_lo ha_hi hab => ?_⟩, hτij⟩ have hτab : τ.rel a b = true := hπτ a b hab by_cases haS : a ∈ S · have hbS : b ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hbn, τ.trans _ _ _ (Finset.mem_filter.mp haS).2 hτab⟩ set ua := e.symm ⟨a, haS⟩ set ub := e.symm ⟨b, hbS⟩ have hua_val : S.orderEmbOfFin rfl ua = a := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply ⟨a, haS⟩) have hub_val : S.orderEmbOfFin rfl ub = b := by rw [← Finset.coe_orderIsoOfFin_apply]; exact congrArg Subtype.val (e.apply_symm_apply ⟨b, hbS⟩) have hua_lo : min ui.1 uj.1 < ua.1 := by have : S.orderEmbOfFin rfl ⟨min ui.1 uj.1, lt_of_le_of_lt (min_le_left _ _) ui.2⟩ < S.orderEmbOfFin rfl ua := by rw [hmin_eq, hua_val]; exact ha_lo exact Fin.lt_def.mp ((S.orderEmbOfFin rfl).strictMono.lt_iff_lt.mp this) have hua_hi : ua.1 ≤ max ui.1 uj.1 := by have : S.orderEmbOfFin rfl ua ≤ S.orderEmbOfFin rfl ⟨max ui.1 uj.1, max_lt ui.2 uj.2⟩ := by rw [hua_val, hmax_eq]; exact ha_hi exact Fin.le_def.mp ((S.orderEmbOfFin rfl).le_iff_le.mp this) have hres_ab : (π.restrictSet S (τ.blockFinset_lt r.1)).rel ua.1 ub.1 = true := by rw [NC.restrictSet_rel _ _ _ _ _ ua.2 ub.2, hua_val, hub_val]; exact hab obtain ⟨hlo, hhi⟩ := hloc ua.1 ua.2 ub.1 ub.2 hua_lo hua_hi hres_ab have h1 : min i j < b := by rw [← hmin_eq, ← hub_val] exact (S.orderEmbOfFin rfl).strictMono (Fin.mk_lt_mk.mpr hlo) have h2 : b ≤ max i j := by rw [← hmax_eq, ← hub_val] exact (S.orderEmbOfFin rfl).monotone (Fin.mk_le_mk.mpr hhi) exact ⟨h1, h2⟩ · -- `a ∉ S`, so `a` cannot cross the `τ`-arch `(min i j, max i j)`! have hτmm : τ.rel (min i j) (max i j) = true := by by_cases hle : i ≤ j · rw [min_eq_left hle, max_eq_right hle]; exact hτij · rw [min_eq_right (by omega), max_eq_left (by omega), τ.symm]; exact hτij have ha_lt_max : a < max i j := by rcases lt_or_eq_of_le ha_hi with h | heq · exact h · exfalso; apply haS; rw [heq] by_cases hle : i ≤ j · rw [max_eq_right hle]; exact hjS · rw [max_eq_left (by omega)]; exact hiS have hnot_rel : τ.rel (min i j) a = false := by cases h : τ.rel (min i j) a · rfl · exfalso; apply haS have hminS : min i j ∈ S := by by_cases hle : i ≤ j · rw [min_eq_left hle]; exact hiS · rw [min_eq_right (by omega)]; exact hjS exact Finset.mem_filter.mpr ⟨Finset.mem_range.mpr han, τ.trans _ _ _ (Finset.mem_filter.mp hminS).2 h⟩ constructor · by_contra hle have hb_lt : b < min i j := by rcases lt_or_eq_of_le (le_of_not_gt hle) with h | rfl · exact h · exfalso; rw [τ.symm, hnot_rel] at hτab; exact absurd hτab (by decide) have hcross := τ.nc b (min i j) a (max i j) hb_lt ha_lo ha_lt_max (by rw [τ.symm]; exact hτab) hτmm have hrel := τ.trans _ _ _ (by rw [τ.symm]; exact hcross) (by rw [τ.symm]; exact hτab) rw [hnot_rel] at hrel; exact absurd hrel (by decide) · by_contra hgt have hcross := τ.nc (min i j) a (max i j) b ha_lo ha_lt_max (by omega) hτmm hτab rw [hnot_rel] at hcross; exact absurd hcross (by decide) · rintro ⟨⟨_, _, hglob⟩, _⟩ refine ⟨ui.2, uj.2, fun a ha b hb ha_lo ha_hi hab => ?_⟩ rw [NC.restrictSet_rel _ _ _ _ _ ha hb] at hab set xa := S.orderEmbOfFin rfl ⟨a, ha⟩ set xb := S.orderEmbOfFin rfl ⟨b, hb⟩ have hxa_lt : xa < n := τ.blockFinset_lt r.1 xa (S.orderEmbOfFin_mem rfl ⟨a, ha⟩) have hxb_lt : xb < n := τ.blockFinset_lt r.1 xb (S.orderEmbOfFin_mem rfl ⟨b, hb⟩) have hxa_lo : min i j < xa := by rw [← hmin_eq]; exact (S.orderEmbOfFin rfl).strictMono (Fin.mk_lt_mk.mpr ha_lo) have hxa_hi : xa ≤ max i j := by rw [← hmax_eq]; exact (S.orderEmbOfFin rfl).monotone (Fin.mk_le_mk.mpr ha_hi) have ⟨hxb_lo, hxb_hi⟩ := hglob xa hxa_lt xb hxb_lt hxa_lo hxa_hi hab constructor · rw [← hmin_eq] at hxb_lo exact Fin.lt_def.mp ((S.orderEmbOfFin rfl).strictMono.lt_iff_lt.mp hxb_lo) · rw [← hmax_eq] at hxb_hi exact Fin.le_def.mp ((S.orderEmbOfFin rfl).le_iff_le.mp hxb_hi) · rw [dif_neg (fun h => hτij h.2.2)] simp [hτij] /-- **Exact Upper-to-Lower Relative Kreweras Bijection:** For any `π ∈ NC(n)`, `τ ↦ K(π) ⊓ τ` is a bijection from `{τ // π ≤ τ}` onto `{σ // σ ≤ K(π)}`. -/ theorem upper_to_lower_kreweras_bijective {n : ℕ} (π : NC n) : Function.Bijective (fun τ : { τ : NC n // π ≤ τ } => (⟨NC.kreweras π ⊓ τ.1, inf_le_left⟩ : { σ : NC n // σ ≤ NC.kreweras π })) := by have hcard : Fintype.card { τ : NC n // π ≤ τ } = Fintype.card { σ : NC n // σ ≤ NC.kreweras π } := by refine Fintype.card_congr { toFun := fun τ => ⟨NC.kreweras τ.1, NC.kreweras_antitone τ.2⟩ invFun := fun σ => ⟨(NC.krewerasOrderIso n).symm (OrderDual.toDual σ.1), by have h : (NC.krewerasOrderIso n).symm (OrderDual.toDual (NC.kreweras π)) ≤ (NC.krewerasOrderIso n).symm (OrderDual.toDual σ.1) := (NC.krewerasOrderIso n).symm.monotone (OrderDual.toDual_le_toDual.mpr σ.2) have hpi : (NC.krewerasOrderIso n).symm (OrderDual.toDual (NC.kreweras π)) = π := (NC.krewerasOrderIso n).symm_apply_apply π rwa [hpi] at h⟩ left_inv := fun τ => Subtype.ext ((NC.krewerasOrderIso n).symm_apply_apply τ.1) right_inv := fun σ => Subtype.ext (by change NC.kreweras ((NC.krewerasOrderIso n).symm (OrderDual.toDual σ.1)) = σ.1 have := (NC.krewerasOrderIso n).apply_symm_apply (OrderDual.toDual σ.1) exact congrArg OrderDual.ofDual this) } refine (Fintype.bijective_iff_injective_and_card _).mpr ⟨?_, hcard⟩ -- Prove injectivity via `π ⊔ (K(π) ⊓ τ) = τ`! have hsup : ∀ τ : { τ : NC n // π ≤ τ }, π ⊔ (NC.kreweras π ⊓ τ.1) = τ.1 := by intro τ have hle : π ⊔ (NC.kreweras π ⊓ τ.1) ≤ τ.1 := sup_le τ.2 inf_le_right have h1 : NC.lowerIntervalOrderIso τ.1 ⟨π ⊔ (NC.kreweras π ⊓ τ.1), hle⟩ = NC.lowerIntervalOrderIso τ.1 ⟨τ.1, le_rfl⟩ := by funext r have hge : (π.restrictSet (τ.1.blockFinset r.1) (τ.1.blockFinset_lt r.1)) ⊔ NC.kreweras (π.restrictSet (τ.1.blockFinset r.1) (τ.1.blockFinset_lt r.1)) ≤ NC.lowerIntervalOrderIso τ.1 ⟨π ⊔ (NC.kreweras π ⊓ τ.1), hle⟩ r := by apply sup_le · exact (NC.lowerIntervalOrderIso τ.1).monotone (show (⟨π, τ.2⟩ : { x // x ≤ τ.1 }) ≤ ⟨π ⊔ (NC.kreweras π ⊓ τ.1), hle⟩ from Subtype.mk_le_mk.mpr le_sup_left) r · have hKeq : NC.kreweras (π.restrictSet (τ.1.blockFinset r.1) (τ.1.blockFinset_lt r.1)) = NC.lowerIntervalOrderIso τ.1 ⟨NC.kreweras π ⊓ τ.1, inf_le_right⟩ r := by have hgl := glueOnBlocks_kreweras_eq_inf τ.2 have hsub : (⟨NC.kreweras π ⊓ τ.1, inf_le_right⟩ : { x // x ≤ τ.1 }) = (NC.lowerIntervalOrderIso τ.1).symm (fun r => NC.kreweras (π.restrictSet (τ.1.blockFinset r.1) (τ.1.blockFinset_lt r.1))) := Subtype.ext hgl.symm rw [hsub, (NC.lowerIntervalOrderIso τ.1).apply_symm_apply] rw [hKeq] exact (NC.lowerIntervalOrderIso τ.1).monotone (show (⟨NC.kreweras π ⊓ τ.1, inf_le_right⟩ : { x // x ≤ τ.1 }) ≤ ⟨π ⊔ (NC.kreweras π ⊓ τ.1), hle⟩ from Subtype.mk_le_mk.mpr le_sup_right) r rw [sup_kreweras_eq_top] at hge have htop_r : NC.lowerIntervalOrderIso τ.1 ⟨τ.1, le_rfl⟩ r = ⊤ := by apply NC.ext'; intro i j hi hj change (τ.1.restrictSet (τ.1.blockFinset r.1) (τ.1.blockFinset_lt r.1)).rel i j = (⊤ : NC _).rel i j rw [NC.restrictSet_rel _ _ _ _ _ hi hj, top_rel] have hx := (Finset.mem_filter.mp ((τ.1.blockFinset r.1).orderEmbOfFin_mem rfl ⟨i, hi⟩)).2 have hy := (Finset.mem_filter.mp ((τ.1.blockFinset r.1).orderEmbOfFin_mem rfl ⟨j, hj⟩)).2 simp [τ.1.trans _ _ _ (by rw [τ.1.symm]; exact hx) hy, hi, hj] rw [htop_r] exact le_antisymm le_top hge exact congrArg Subtype.val ((NC.lowerIntervalOrderIso τ.1).injective h1) intro τ₁ τ₂ heq have hinf : NC.kreweras π ⊓ τ₁.1 = NC.kreweras π ⊓ τ₂.1 := congrArg Subtype.val heq apply Subtype.ext rw [← hsup τ₁, ← hsup τ₂, hinf] /-- **Nica–Speicher Moment Formula for Free Multiplicative Convolution (1st Form):** `m_n(a ⊠ b) = ∑_{π ∈ NC(n)} κ_π(a) · m_{K(π)}(b)`. -/ theorem freeMulMoments_eq_sum_kappa_m {R : Type*} [CommRing R] (κa κb : ℕ → R) {n : ℕ} (hn : 1 ≤ n) : momentsOfCumulants (freeMulCumulants κa κb) n = ∑ π : NC n, blockProd κa π * blockProd (momentsOfCumulants κb) (NC.kreweras π) := by rw [momentsOfCumulants, if_neg (by omega)] -- Expand each `blockProd (freeMulCumulants κa κb) τ` via `lowerIntervalOrderIso τ`! have hterm : ∀ τ : NC n, blockProd (freeMulCumulants κa κb) τ = ∑ π ∈ Finset.Iic τ, blockProd κa π * blockProd κb (NC.kreweras π ⊓ τ) := by intro τ unfold blockProd rw [← Finset.prod_coe_sort] have hpos : ∀ r : τ.rootSet, (τ.blockFinset r.1).card ≠ 0 := fun r => Nat.pos_iff_ne_zero.mp (blockFinset_card_pos τ r.2) calc ∏ r : τ.rootSet, freeMulCumulants κa κb (τ.blockFinset r.1).card = ∏ r : τ.rootSet, ∑ α : NC (τ.blockFinset r.1).card, blockProd κa α * blockProd κb (NC.kreweras α) := Finset.prod_congr rfl fun r _ => by rw [freeMulCumulants, if_neg (hpos r)] _ = ∑ g : (∀ r : τ.rootSet, NC (τ.blockFinset r.1).card), ∏ r : τ.rootSet, (blockProd κa (g r) * blockProd κb (NC.kreweras (g r))) := Fintype.prod_sum (fun r α => blockProd κa α * blockProd κb (NC.kreweras α)) _ = ∑ g : (∀ r : τ.rootSet, NC (τ.blockFinset r.1).card), blockProd κa (NC.glueOnBlocks τ g) * blockProd κb (NC.kreweras (NC.glueOnBlocks τ g) ⊓ τ) := by refine Finset.sum_congr rfl fun g _ => ?_ rw [Finset.prod_mul_distrib, ← blockProd_glueOnBlocks κa τ g, ← blockProd_glueOnBlocks κb τ (fun r => NC.kreweras (g r))] congr 2 rw [← glueOnBlocks_kreweras_eq_inf (NC.glueOnBlocks_le τ g)] congr 1; funext r have hres : (NC.glueOnBlocks τ g).restrictSet (τ.blockFinset r.1) (τ.blockFinset_lt r.1) = g r := congrFun ((NC.lowerIntervalOrderIso τ).right_inv g) r rw [hres] _ = ∑ π ∈ Finset.Iic τ, blockProd κa π * blockProd κb (NC.kreweras π ⊓ τ) := by refine Finset.sum_nbij (fun g => NC.glueOnBlocks τ g) ?_ ?_ ?_ ?_ · intro g _; exact Finset.mem_Iic.mpr (NC.glueOnBlocks_le τ g) · intro g₁ _ g₂ _ heq exact (NC.lowerIntervalOrderIso τ).symm.injective (Subtype.ext heq) · intro π hπ have hle := Finset.mem_Iic.mp (Finset.mem_coe.mp hπ) exact ⟨NC.lowerIntervalOrderIso τ ⟨π, hle⟩, Finset.mem_coe.mpr (Finset.mem_univ _), congrArg Subtype.val ((NC.lowerIntervalOrderIso τ).left_inv ⟨π, hle⟩)⟩ · intro _ _; rfl simp_rw [hterm] calc ∑ τ : NC n, ∑ π ∈ Finset.Iic τ, blockProd κa π * blockProd κb (NC.kreweras π ⊓ τ) = ∑ τ : NC n, ∑ π : NC n, if π ≤ τ then blockProd κa π * blockProd κb (NC.kreweras π ⊓ τ) else 0 := by refine Finset.sum_congr rfl fun τ _ => ?_ rw [← Finset.sum_filter]; congr 1; ext π; simp [Finset.mem_Iic] _ = ∑ π : NC n, ∑ τ : NC n, if π ≤ τ then blockProd κa π * blockProd κb (NC.kreweras π ⊓ τ) else 0 := Finset.sum_comm _ = ∑ π : NC n, blockProd κa π * blockProd (momentsOfCumulants κb) (NC.kreweras π) := by refine Finset.sum_congr rfl fun π _ => ?_ rw [blockProd_moments_eq_sum_le κb, Finset.mul_sum, ← Finset.sum_filter] have hbij := upper_to_lower_kreweras_bijective π refine Finset.sum_nbij (fun τ => NC.kreweras π ⊓ τ) ?_ ?_ ?_ ?_ · intro τ _; exact Finset.mem_Iic.mpr inf_le_left · intro τ₁ hτ₁ τ₂ hτ₂ heq have h1 : π ≤ τ₁ := (Finset.mem_filter.mp hτ₁).2 have h2 : π ≤ τ₂ := (Finset.mem_filter.mp hτ₂).2 have hinj := @hbij.1 ⟨τ₁, h1⟩ ⟨τ₂, h2⟩ (Subtype.ext heq) exact congrArg Subtype.val hinj · intro σ hσ have hle := Finset.mem_Iic.mp (Finset.mem_coe.mp hσ) obtain ⟨⟨τ, hπτ⟩, hτeq⟩ := hbij.2 ⟨σ, hle⟩ exact ⟨τ, Finset.mem_coe.mpr (Finset.mem_filter.mpr ⟨Finset.mem_univ _, hπτ⟩), congrArg Subtype.val hτeq⟩ · intro _ _; rfl /-- **Nica–Speicher Moment Formula for Free Multiplicative Convolution (2nd Form):** `m_n(a ⊠ b) = ∑_{π ∈ NC(n)} m_π(a) · κ_{K(π)}(b)`. -/ theorem freeMulMoments_eq_sum_m_kappa {R : Type*} [CommRing R] (κa κb : ℕ → R) {n : ℕ} (hn : 1 ≤ n) : momentsOfCumulants (freeMulCumulants κa κb) n = ∑ π : NC n, blockProd (momentsOfCumulants κa) π * blockProd κb (NC.kreweras π) := by have hcomm : freeMulCumulants κa κb = freeMulCumulants κb κa := funext (freeMulCumulants_comm κa κb) rw [hcomm, freeMulMoments_eq_sum_kappa_m κb κa hn] refine Finset.sum_nbij NC.kreweras ?_ ?_ ?_ ?_ · intro _ _; exact Finset.mem_univ _ · intro π₁ _ π₂ _ h; exact (NC.kreweras_bijective n).1 h · intro σ _ obtain ⟨π, hπ⟩ := (NC.kreweras_bijective n).2 σ exact ⟨π, Finset.mem_coe.mpr (Finset.mem_univ _), hπ⟩ · intro π _ rw [NC.kreweras_sq_eq_rot, blockProd_rotMinusOne, mul_comm] end FreeConvolutions /-! ## Section 6: Exact Moment–Cumulant Characterizations of Wigner Semicircle & Marchenko–Pastur -/ section LawCharacterizations /-- **Exact Wigner Semicircle Characterization via Speicher Free Cumulants:** A sequence `κ : ℕ → ℚ` (`κ 0 = 0`) has semicircle cumulants (`κ 2 = σ²`, `κ n = 0` for `n ≠ 2`) if and only if its moments are the exact Catalan semicircle moments `m_{2k} = C_k σ^{2k}`, `m_{2k+1} = 0`! -/ theorem wigner_semicircle_characterization (σ : ℚ) (κ : ℕ → ℚ) (hκ0 : κ 0 = 0) : (κ 2 = σ ^ 2 ∧ ∀ n, n ≠ 2 → κ n = 0) ↔ ∀ n : ℕ, momentsOfCumulants κ n = if n % 2 = 0 then (catalan (n / 2) : ℚ) * σ ^ n else 0 := by let scM : ℕ → ℚ := fun n => if n % 2 = 0 then (catalan (n / 2) : ℚ) * σ ^ n else 0 let κsc : ℕ → ℚ := fun n => if n = 2 then σ ^ 2 else 0 have hsc_fwd : ∀ n : ℕ, momentsOfCumulants κsc n = scM n := by -- Both `M = momentSeries (momentsOfCumulants κsc)` and `S = momentSeries scM` satisfy -- `f = 1 + C(σ²) * X² * f²`! set M := momentSeries (momentsOfCumulants κsc) set S := momentSeries scM have hM_quad : M = 1 + PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * M ^ 2 := by have hCsc : cumulantSeries κsc = 1 + PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 := by ext n; cases n with | zero => simp [cumulantSeries, pow_two, mul_assoc] | succ k => cases k with | zero => simp [cumulantSeries, κsc, pow_two, mul_assoc] | succ m => rw [map_add, PowerSeries.coeff_one, if_neg (Nat.succ_ne_zero _), zero_add, PowerSeries.coeff_C_mul, pow_two PowerSeries.X, PowerSeries.coeff_succ_X_mul, PowerSeries.coeff_X] simp only [cumulantSeries, PowerSeries.coeff_mk, Nat.succ_ne_zero, ↓reduceIte, κsc] cases m with | zero => simp | succ r => simp have hsub : PowerSeries.HasSubst (PowerSeries.X * M) := PowerSeries.HasSubst.of_constantCoeff_zero' (by rw [map_mul, PowerSeries.constantCoeff_X, zero_mul]) have hm := momentSeries_eq_cumulantSeries_subst κsc rw [hCsc, PowerSeries.subst_add hsub, PowerSeries.subst_mul hsub, PowerSeries.subst_C, PowerSeries.subst_pow hsub, PowerSeries.subst_X hsub] at hm have hsub1 : PowerSeries.subst (PowerSeries.X * M) (1 : PowerSeries ℚ) = 1 := by simpa only [map_one] using PowerSeries.subst_C (a := PowerSeries.X * M) (1 : ℚ) rw [hsub1] at hm calc M = 1 + PowerSeries.C (σ ^ 2) * (PowerSeries.X * M) ^ 2 := hm _ = 1 + PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * M ^ 2 := by ring have hS_quad : S = 1 + PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * S ^ 2 := by ext n; cases n with | zero => simp [S, momentSeries, scM, pow_two, mul_assoc] | succ k => cases k with | zero => simp [S, momentSeries, scM, pow_two, mul_assoc] | succ m => rw [map_add, PowerSeries.coeff_one, if_neg (Nat.succ_ne_zero _), zero_add, mul_assoc (PowerSeries.C (σ ^ 2)), PowerSeries.coeff_C_mul, pow_two PowerSeries.X, mul_assoc, PowerSeries.coeff_succ_X_mul, PowerSeries.coeff_succ_X_mul, sq S, PowerSeries.coeff_mul] have hSc : ∀ j, PowerSeries.coeff j S = scM j := fun j => by cases j with | zero => simp [S, momentSeries, scM] | succ r => simp [S, momentSeries, scM] simp_rw [hSc] simp only [scM] by_cases hm : m % 2 = 0 · have hm2 : (m + 2) % 2 = 0 := by omega have hdiv : (m + 2) / 2 = m / 2 + 1 := by omega simp only [hm2, ↓reduceIte, hdiv, catalan_succ'] push_cast set r := m / 2 have hmr : m = 2 * r := by omega have hfilt : ∑ ij ∈ Finset.HasAntidiagonal.antidiagonal m, (if ij.1 % 2 = 0 then (catalan (ij.1 / 2) : ℚ) * σ ^ ij.1 else 0) * (if ij.2 % 2 = 0 then (catalan (ij.2 / 2) : ℚ) * σ ^ ij.2 else 0) = ∑ ij ∈ (Finset.HasAntidiagonal.antidiagonal m).filter (fun p => p.1 % 2 = 0), (catalan (ij.1 / 2) : ℚ) * σ ^ ij.1 * ((catalan (ij.2 / 2) : ℚ) * σ ^ ij.2) := by rw [Finset.sum_filter] refine Finset.sum_congr rfl fun ij hij => ?_ have := Finset.HasAntidiagonal.mem_antidiagonal.mp hij by_cases h1 : ij.1 % 2 = 0 · have h2 : ij.2 % 2 = 0 := by omega simp [h1, h2] · simp [h1] rw [hfilt, Finset.mul_sum, Finset.sum_mul] refine Finset.sum_nbij (fun p => (p.1 * 2, p.2 * 2)) ?_ ?_ ?_ ?_ · intro p hp have := Finset.HasAntidiagonal.mem_antidiagonal.mp hp exact Finset.mem_filter.mpr ⟨Finset.HasAntidiagonal.mem_antidiagonal.mpr (by omega), by omega⟩ · intro p₁ _ p₂ _ heq have h1 := congrArg Prod.fst heq; have h2 := congrArg Prod.snd heq dsimp at h1 h2; exact Prod.ext (by omega) (by omega) · intro q hq obtain ⟨hqA, hq1⟩ := Finset.mem_filter.mp (Finset.mem_coe.mp hq) have := Finset.HasAntidiagonal.mem_antidiagonal.mp hqA exact ⟨(q.1 / 2, q.2 / 2), Finset.mem_coe.mpr (Finset.HasAntidiagonal.mem_antidiagonal.mpr (by omega)), Prod.ext (by dsimp; omega) (by dsimp; omega)⟩ · intro p hp have := Finset.HasAntidiagonal.mem_antidiagonal.mp hp have hpow : σ ^ (m + 2) = σ ^ 2 * (σ ^ (p.1 * 2) * σ ^ (p.2 * 2)) := by rw [← pow_add, ← pow_add, show 2 + (p.1 * 2 + p.2 * 2) = m + 2 by omega] simp only [show p.1 * 2 / 2 = p.1 by omega, show p.2 * 2 / 2 = p.2 by omega] rw [hpow]; ring · have hm2 : ¬ ((m + 2) % 2 = 0) := by omega simp only [hm2, ↓reduceIte] symm; apply mul_eq_zero_of_right refine Finset.sum_eq_zero fun ij hij => ?_ have := Finset.HasAntidiagonal.mem_antidiagonal.mp hij by_cases h1 : ij.1 % 2 = 0 · have h2 : ¬ (ij.2 % 2 = 0) := by omega simp [h2] · simp [h1] -- Uniqueness: `(1 - C(σ²) X² (M + S)) * (M - S) = 0`, and `1 - C(σ²) X² (M + S)` is a unit! have hdiff : (1 - PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * (M + S)) * (M - S) = 0 := by have h1 : (1 - PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * (M + S)) * (M - S) = (M - (1 + PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * M ^ 2)) - (S - (1 + PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * S ^ 2)) := by ring rw [h1, ← hM_quad, ← hS_quad, sub_self, sub_self, sub_self] obtain ⟨u, hu⟩ := PowerSeries.isUnit_iff_constantCoeff.mpr (by show IsUnit (PowerSeries.constantCoeff (1 - PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * (M + S))) simp [pow_two]) have hMS : M = S := by have hz : M - S = 0 := by calc M - S = (u⁻¹ : (PowerSeries ℚ)ˣ).val * ((1 - PowerSeries.C (σ ^ 2) * PowerSeries.X ^ 2 * (M + S)) * (M - S)) := by rw [← mul_assoc, ← hu, Units.inv_mul, one_mul] _ = 0 := by rw [hdiff, mul_zero] exact sub_eq_zero.mp hz intro n have hc := congrArg (PowerSeries.coeff n) hMS cases n with | zero => simp [momentsOfCumulants, scM] | succ r => simpa [M, S, momentSeries] using hc constructor · rintro ⟨h2, hne⟩ n have hκeq : κ = κsc := by funext k by_cases hk : k = 2 · subst hk; simpa [κsc] using h2 · simp [κsc, hk, hne k hk] rw [hκeq]; exact hsc_fwd n · intro hm have hκeq : ∀ k : ℕ, 1 ≤ k → κ k = κsc k := by intro k hk rw [← cumulantsOfMoments_momentsOfCumulants κ hk, ← cumulantsOfMoments_momentsOfCumulants κsc hk] congr 1; funext j; rw [hm j, hsc_fwd j] refine ⟨by simpa [κsc] using hκeq 2 (by omega), fun n hn => ?_⟩ cases n with | zero => exact hκ0 | succ r => simpa [κsc, hn] using hκeq (r + 1) (by omega) /-- **Exact Marchenko–Pastur / Free-Poisson Characterization via Speicher Free Cumulants:** A sequence `κ : ℕ → ℚ` (`κ 0 = 0`) has constant geometric free cumulants `κ_n = λ α^n` (`n ≥ 1`, equivalently `R(u) = λ α / (1 - α u)`) if and only if its moments equal the exact `NC(n)` block-count generating polynomial `m_n = ∑_{π ∈ NC(n)} λ^{|π|} α^n`! -/ theorem marchenko_pastur_characterization (lam α : ℚ) (κ : ℕ → ℚ) (hκ0 : κ 0 = 0) : (∀ n ≥ 1, κ n = lam * α ^ n) ↔ ∀ n ≥ 1, momentsOfCumulants κ n = ∑ π : NC n, lam ^ π.blockCount * α ^ n := by let κmp : ℕ → ℚ := fun n => if n = 0 then 0 else lam * α ^ n have hsum_card : ∀ {n : ℕ} (π : NC n), ∑ r ∈ π.rootSet, (π.blockFinset r).card = n := by intro n π calc ∑ r ∈ π.rootSet, (π.blockFinset r).card = ∑ r ∈ π.rootSet, ((Finset.range n).filter fun i => π.rootOf i = r).card := by refine Finset.sum_congr rfl fun r hr => ?_ congr 1; ext i; simp only [NC.blockFinset, Finset.mem_filter, Finset.mem_range] refine and_congr_right fun hi => ?_ have hrn := Finset.mem_range.mp (Finset.mem_filter.mp hr).1 have hrr : π.rootOf r = r := by have hr_min := of_decide_eq_true (Finset.mem_filter.mp hr).2 have hle := Finset.min'_le (π.blockFinset r) r (Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hrn, π.refl r hrn⟩) have hrel := π.rootOf_rel hrn simp only [NC.rootOf, hrn, ↓reduceDIte] at hrel ⊢ by_contra hne have := hr_min _ (lt_of_le_of_ne hle hne); rw [hrel] at this; exact absurd this (by decide) rw [π.symm, ← π.rootOf_eq_iff hi hrn, hrr] _ = (Finset.range n).card := Finset.sum_card_fiberwise_eq_card_filter _ _ _ |>.trans (by rw [Finset.filter_true_of_mem (fun i hi => π.rootOf_mem_rootSet (Finset.mem_range.mp hi))]) _ = n := Finset.card_range n have hroot_card : ∀ {n : ℕ} (π : NC n), π.rootSet.card = π.blockCount := by intro n π unfold NC.rootSet NC.blockCount rw [Finset.card_filter] have hmp_fwd : ∀ n ≥ 1, momentsOfCumulants κmp n = ∑ π : NC n, lam ^ π.blockCount * α ^ n := by intro n hn rw [momentsOfCumulants, if_neg (by omega)] refine Finset.sum_congr rfl fun π _ => ?_ unfold blockProd calc ∏ r ∈ π.rootSet, κmp (π.blockFinset r).card = ∏ r ∈ π.rootSet, (lam * α ^ (π.blockFinset r).card) := Finset.prod_congr rfl fun r hr => by simp [κmp, Nat.pos_iff_ne_zero.mp (blockFinset_card_pos π hr)] _ = (∏ _r ∈ π.rootSet, lam) * (∏ r ∈ π.rootSet, α ^ (π.blockFinset r).card) := Finset.prod_mul_distrib _ = lam ^ π.blockCount * α ^ n := by rw [Finset.prod_const, hroot_card π, Finset.prod_pow_eq_pow_sum, hsum_card π] constructor · intro hκ n hn have hκeq : κ = κmp := by funext k; cases k with | zero => simp [κmp, hκ0] | succ r => simpa [κmp] using hκ (r + 1) (by omega) rw [hκeq]; exact hmp_fwd n hn · intro hm n hn have hmeq : momentsOfCumulants κ = momentsOfCumulants κmp := by funext k; cases k with | zero => simp [momentsOfCumulants] | succ r => rw [hm (r + 1) (by omega), hmp_fwd (r + 1) (by omega)] have h := cumulantsOfMoments_momentsOfCumulants κ hn rw [hmeq, cumulantsOfMoments_momentsOfCumulants κmp hn] at h simpa [κmp, show n ≠ 0 by omega] using h.symm end LawCharacterizations end FreeProbSpeicher /-! ### Kernel Axiom Audit for Headline Theorems -/ #print axioms FreeProbSpeicher.mobiusNC_eq_prod_restrict #print axioms FreeProbSpeicher.mobiusNC_bot_eq_prod #print axioms FreeProbSpeicher.mobiusNC_top_eq_kreweras_prod #print axioms FreeProbSpeicher.blockProd_moments_eq_sum_le #print axioms FreeProbSpeicher.blockProd_cumulants_eq_sum_le #print axioms FreeProbSpeicher.cumulantsOfMoments_momentsOfCumulants #print axioms FreeProbSpeicher.momentsOfCumulants_cumulantsOfMoments #print axioms FreeProbSpeicher.sum_restProd_blockSize_zero #print axioms FreeProbSpeicher.momentSeries_eq_cumulantSeries_subst #print axioms FreeProbSpeicher.momentSeries_eq_rTransform_subst #print axioms FreeProbSpeicher.cauchy_rTransform_inversion #print axioms FreeProbSpeicher.speicher_mobius_exact #print axioms FreeProbSpeicher.cumulantsOfMoments_freeAddConv #print axioms FreeProbSpeicher.rTransform_freeAddConv #print axioms FreeProbSpeicher.freeAddConv_comm #print axioms FreeProbSpeicher.freeAddConv_assoc #print axioms FreeProbSpeicher.cumulantsOfMoments_freeAddConvPow #print axioms FreeProbSpeicher.freeMulCumulants_comm #print axioms FreeProbSpeicher.sup_kreweras_eq_top #print axioms FreeProbSpeicher.glueOnBlocks_kreweras_eq_inf #print axioms FreeProbSpeicher.upper_to_lower_kreweras_bijective #print axioms FreeProbSpeicher.freeMulMoments_eq_sum_kappa_m #print axioms FreeProbSpeicher.freeMulMoments_eq_sum_m_kappa #print axioms FreeProbSpeicher.wigner_semicircle_characterization #print axioms FreeProbSpeicher.marchenko_pastur_characterization