import Mathlib.Data.ZMod.Basic import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Choose.Vandermonde import Mathlib.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.FiniteDimensional.Defs import Mathlib.Analysis.Real.Sqrt import Mathlib.Data.Finset.SymmDiff import Mathlib.Data.Finset.Powerset import Mathlib.Data.Nat.Log import Mathlib.Tactic /-! # Sharp Non-Asymptotic Razborov–Smolensky Polynomial Approximation Bounds, # Exact Karchmer–Wigderson Game Equivalences, Spectral Adversary Composition, # and Exact Hansel–Kraft Monotone Formula Bounds This standalone Lean 4 formalization develops four interlocking pillars in Boolean circuit complexity, low-degree polynomial approximation over arbitrary fields, and Karchmer–Wigderson communication games: * **Pillar 1 (Universal Odd/Even-Strength Gram–Smolensky & Exact Parity–Cubature Duality):** Over *every* field `K` (of arbitrary characteristic, including characteristic `2`) and *every* `ω ∈ K \ {0, 1}`, any degree-`≤ d` polynomial approximating the multiplicative character `y ↦ ω ^ |y|` on `{0,1}ⁿ` errs on at least `raoBound n (n - d - 1)`, where `raoBound n (2t) = ∑_{j ≤ t} C(n, j)` and `raoBound n (2t+1) = ∑_{j ≤ t} C(n, j) + C(n-1, t)`. For even `n + d`, this strictly improves Smolensky's classical bound by `C(n-1, (n+d)/2)` and is exact at `d ∈ {0, n-2, n-1}`. We establish the exact iff equivalence with `K`-valued signed `(n-d-1)`-wise independent measures (`char K ≠ 2`), prove a Hadamard distance-parity obstruction at `d = n - 3` yielding `|E| ≥ n + 2` whenever `n ≢ 3 (mod 4)` (beating Rao's `n + 1`), and construct an exact degree-`(d+1)` linear `𝔽₄`-lift giving `2 |E(Q, MOD₃)| ≥ raoBound n (n - d - 2)` over `𝔽₂`. * **Pillar 2 (Sharp Two-Term Smolensky Threshold/Majority Bound & Non-Asymptotic `AC⁰[p]` Bounds):** Over *every* field `K`, every polynomial `P` of degree `≤ d ≤ m := min(k-1, n-k)` (`d ≥ 1`) approximating the threshold function `THR_k^n` errs on at least `∑_{j=0}^{m-d} C(n, j) + ∑_{j=(m-2d+1)_+}^{m-d} C(n-d, j)`, strictly improving Smolensky (1993) via a maximal-monomial degree-separation argument and Vandermonde monotonicity. This is 100% exact for `MAJ_{2m+1}` at `d = 1` (`2^{2m} - C(2m, m)`, attained by dictator `x₁`) and at `d = m` (`|E| ≥ 2`, attained on `MAJ₅/𝔽₂`). Coupling with an exact finite-sum Razborov–Smolensky probabilistic polynomial approximation for DAG `AC⁰[p]` circuits yields unconditional, explicit non-asymptotic `AC⁰[p]` circuit lower bounds for `PARITY_n`, `MOD₃`, and `THR_k^n`. * **Pillar 3 (Exact Karchmer–Wigderson Game Equivalences & De Morgan Duality):** Simultaneous exact size (`leafSize`) AND depth (`depth`) bijections between monotone formulas and monotone KW protocols (`monotone_kw_exact_equivalence`), and between De Morgan formulas and general KW protocols (`general_kw_exact_equivalence`), together with exact De Morgan duality and composition upper bounds. * **Pillar 4 (Bilinear Spectral Adversary Composition & Exact Hansel–Kraft Monotone Formula Bounds):** A per-variable weighted bilinear Cauchy–Schwarz spectral adversary lower bound via KW protocols, its exact multiplicative composition theorem (`Adv⁺(f ∘ g)² ≥ Adv⁺(f)² · Adv⁺(g)²`) yielding `L⁺(MAJ₃^{∘t}) ≥ 4^t`, `D⁺(MAJ₃^{∘t}) ≥ 2t`, `L⁺(THR_k^n) ≥ k(n-k+1)`, and `L(PARITY_n) ≥ n²`, plus a complete structural bipartite-cover extraction proving the exact Hansel–Kraft inequality `∑_{i ∈ C} 2^{-ℓ_i(F)} ≤ 1`, the exact monotone formula size `L⁺(THR_2^n) = n(⌊log₂ n⌋ + 2) - 2^{⌊log₂ n⌋ + 1}` for all `n ≥ 2`, and the Restriction–Duality–Kraft bound for general `THR_k^n`. -/ set_option autoImplicit false set_option linter.unusedVariables true open Finset BigOperators namespace MonotoneKWSmolensky /-! ## Section 0: Combinatorial Binomial Sums and Multilinear Polynomials -/ /-- Sum of binomial coefficients `∑_{j=0}^{r} C(n, j)`. -/ def binomSum (n r : ℕ) : ℕ := ∑ j ∈ Finset.range (r + 1), n.choose j /-- Cardinality of `{S : Finset (Fin n) | S.card ≤ r}` equals `binomSum n r`. -/ lemma card_filter_card_le (n r : ℕ) : (Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ r)).card = binomSum n r := by have hpart : Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ r) = (Finset.range (r + 1)).biUnion (fun j => Finset.powersetCard j (Finset.univ : Finset (Fin n))) := by ext S simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_biUnion, Finset.mem_range, Finset.mem_powersetCard, Finset.subset_univ, true_and] constructor · intro h; exact ⟨S.card, Nat.lt_succ_of_le h, rfl⟩ · rintro ⟨j, hj, rfl⟩; exact Nat.lt_succ_iff.mp hj rw [hpart, Finset.card_biUnion] · simp [binomSum, Finset.card_powersetCard] · intro a _ b _ hab show Disjoint _ _ rw [Finset.disjoint_left] intro S ha hb rw [Finset.mem_powersetCard] at ha hb exact hab (ha.2.symm.trans hb.2) /-- Even/odd strength Rao lower bound `raoBound n r`. For `r = 2t`, `raoBound n (2t) = ∑_{j ≤ t} C(n, j)`. For `r = 2t + 1`, `raoBound n (2t + 1) = ∑_{j ≤ t} C(n, j) + C(n - 1, t)`. -/ def raoBound (n r : ℕ) : ℕ := if r % 2 = 0 then binomSum n (r / 2) else binomSum n (r / 2) + (n - 1).choose (r / 2) /-- For `n ≥ 1`, `binomSum n n = 2 ^ n`. -/ lemma binomSum_self (n : ℕ) : binomSum n n = 2 ^ n := by simpa [binomSum] using Nat.sum_range_choose n /-- Symmetry of binomial tails: `binomSum n k + binomSum n (n - 1 - k) = 2 ^ n` for `k < n`. -/ lemma binomSum_add_compl {n k : ℕ} (hk : k < n) : binomSum n k + binomSum n (n - 1 - k) = 2 ^ n := by have h1 : binomSum n (n - 1 - k) = ∑ j ∈ Finset.Ico (k + 1) (n + 1), n.choose j := by unfold binomSum have hbij : ∑ j ∈ Finset.range (n - 1 - k + 1), n.choose j = ∑ j ∈ Finset.Ico (k + 1) (n + 1), n.choose j := by refine Finset.sum_nbij' (fun j => n - j) (fun j => n - j) ?_ ?_ ?_ ?_ ?_ · intro j hj rw [Finset.mem_range] at hj rw [Finset.mem_Ico] omega · intro j hj rw [Finset.mem_Ico] at hj rw [Finset.mem_range] omega · intro j hj rw [Finset.mem_range] at hj omega · intro j hj rw [Finset.mem_Ico] at hj omega · intro j hj rw [Finset.mem_range] at hj exact (Nat.choose_symm (by omega)).symm exact hbij rw [h1] unfold binomSum rw [← Finset.sum_union] · have hunion : Finset.range (k + 1) ∪ Finset.Ico (k + 1) (n + 1) = Finset.range (n + 1) := by ext j simp only [Finset.mem_union, Finset.mem_range, Finset.mem_Ico] omega rw [hunion, Nat.sum_range_choose] · rw [Finset.disjoint_left] intro j hj1 hj2 rw [Finset.mem_range] at hj1 rw [Finset.mem_Ico] at hj2 omega /-- For `n ≥ 1`, `raoBound n (n - 1) = 2 ^ (n - 1)`. -/ lemma raoBound_pred {n : ℕ} (hn : 1 ≤ n) : raoBound n (n - 1) = 2 ^ (n - 1) := by unfold raoBound by_cases hpar : (n - 1) % 2 = 0 · simp only [hpar, ↓reduceIte] set m := (n - 1) / 2 have hn_eq : n = 2 * m + 1 := by omega have hsym := binomSum_add_compl (n := 2 * m + 1) (k := m) (by omega) have hsub : 2 * m + 1 - 1 - m = m := by omega rw [hsub] at hsym have h2 : 2 * binomSum (2 * m + 1) m = 2 * 2 ^ (2 * m) := by calc 2 * binomSum (2 * m + 1) m = binomSum (2 * m + 1) m + binomSum (2 * m + 1) m := by ring _ = 2 ^ (2 * m + 1) := hsym _ = 2 * 2 ^ (2 * m) := by ring have : binomSum (2 * m + 1) m = 2 ^ (2 * m) := by omega simpa [hn_eq] using this · simp only [hpar, ↓reduceIte] set m := (n - 1) / 2 have hn_eq : n = 2 * m + 2 := by omega have hsym := binomSum_add_compl (n := 2 * m + 2) (k := m) (by omega) have hsub : 2 * m + 2 - 1 - m = m + 1 := by omega rw [hsub] at hsym have hstep : binomSum (2 * m + 2) (m + 1) = binomSum (2 * m + 2) m + (2 * m + 2).choose (m + 1) := by simp [binomSum, Finset.sum_range_succ] rw [hstep] at hsym have hchoose : (2 * m + 2).choose (m + 1) = 2 * (2 * m + 1).choose m := by have hp : (2 * m + 2).choose (m + 1) = (2 * m + 1).choose m + (2 * m + 1).choose (m + 1) := Nat.choose_succ_succ (2 * m + 1) m have hsm : (2 * m + 1).choose (m + 1) = (2 * m + 1).choose m := by have := Nat.choose_symm (n := 2 * m + 1) (k := m) (by omega) have h1 : 2 * m + 1 - m = m + 1 := by omega rw [h1] at this exact this omega have h2 : 2 * (binomSum (2 * m + 2) m + (2 * m + 1).choose m) = 2 * 2 ^ (2 * m + 1) := by calc 2 * (binomSum (2 * m + 2) m + (2 * m + 1).choose m) = binomSum (2 * m + 2) m + (binomSum (2 * m + 2) m + (2 * m + 2).choose (m + 1)) := by omega _ = 2 ^ (2 * m + 2) := hsym _ = 2 * 2 ^ (2 * m + 1) := by ring have : binomSum (2 * m + 2) m + (2 * m + 1).choose m = 2 ^ (2 * m + 1) := by omega simpa [hn_eq] using this /-- Multilinear polynomials over a field `K` in `n` variables, represented directly by their monomial coefficient function `Finset (Fin n) → K`. -/ abbrev MultiPoly (K : Type*) (n : ℕ) := Finset (Fin n) → K /-- Degree bound predicate: all coefficients of monomials of size `> d` vanish. -/ def HasDegLe {K : Type*} [Zero K] {n : ℕ} (P : MultiPoly K n) (d : ℕ) : Prop := ∀ S : Finset (Fin n), d < S.card → P S = 0 /-- Subspace of multilinear polynomials of degree `≤ d`. -/ def polySpaceDegLe (K : Type*) [Field K] (n d : ℕ) : Submodule K (MultiPoly K n) where carrier := {P | HasDegLe P d} add_mem' {P Q} hP hQ S hS := by simp [hP S hS, hQ S hS] zero_mem' S _ := rfl smul_mem' c {P} hP S hS := by simp [hP S hS] /-- Dimension of `polySpaceDegLe K n d` equals `binomSum n d`. -/ lemma finrank_polySpaceDegLe (K : Type*) [Field K] (n d : ℕ) : Module.finrank K (polySpaceDegLe K n d) = binomSum n d := by let idx := Finset.univ.filter (fun S : Finset (Fin n) => S.card ≤ d) let e : polySpaceDegLe K n d ≃ₗ[K] (idx → K) := { toFun := fun P S => P.1 S.1 map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl invFun := fun f => ⟨fun S => if h : S ∈ idx then f ⟨S, h⟩ else 0, by intro S hS have hnot : S ∉ idx := by simp only [idx, Finset.mem_filter, Finset.mem_univ, true_and, not_le] exact hS simp [hnot]⟩ left_inv := fun P => by ext S by_cases h : S ∈ idx · simp [h] · simp only [h, ↓reduceDIte] have hgt : d < S.card := by simp only [idx, Finset.mem_filter, Finset.mem_univ, true_and, not_le] at h exact h exact (P.2 S hgt).symm right_inv := fun f => by ext ⟨S, hS⟩ simp [hS] } rw [e.finrank_eq, Module.finrank_pi, Fintype.card_coe, card_filter_card_le] /-- Evaluation of a multilinear polynomial on `{a, b}ⁿ` via `y : Fin n → Bool` (mapping `false ↦ a`, `true ↦ b`). -/ def evalOn {K : Type*} [CommRing K] {n : ℕ} (a b : K) (P : MultiPoly K n) (y : Fin n → Bool) : K := ∑ S : Finset (Fin n), P S * ∏ i ∈ S, (if y i then b else a) /-- Standard `{0, 1}ⁿ` evaluation of a multilinear polynomial. -/ def eval01 {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) (y : Fin n → Bool) : K := evalOn 0 1 P y /-- Standard `{-1, +1}ⁿ` evaluation (`false ↦ 1`, `true ↦ -1`). -/ def evalPM {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) (y : Fin n → Bool) : K := evalOn 1 (-1) P y /-- General `{1, ω}ⁿ` evaluation (`false ↦ 1`, `true ↦ ω`). -/ def evalOmega {K : Type*} [CommRing K] {n : ℕ} (ω : K) (P : MultiPoly K n) (y : Fin n → Bool) : K := evalOn 1 ω P y /-- Support of a Boolean vector `y : Fin n → Bool` as a `Finset (Fin n)`. -/ def boolSupp {n : ℕ} (y : Fin n → Bool) : Finset (Fin n) := Finset.univ.filter (fun i => y i = true) /-- Hamming weight of `y : Fin n → Bool`. -/ def hammingWeight {n : ℕ} (y : Fin n → Bool) : ℕ := (boolSupp y).card /-- Product of `boolBit` over `S` is `1` iff `S ⊆ boolSupp y`, else `0`. -/ lemma prod_boolBit {K : Type*} [CommRing K] {n : ℕ} (S : Finset (Fin n)) (y : Fin n → Bool) : (∏ i ∈ S, (if y i then (1 : K) else 0)) = if S ⊆ boolSupp y then 1 else 0 := by by_cases h : S ⊆ boolSupp y · rw [if_pos h] apply Finset.prod_eq_one intro i hi have hi' := h hi simp only [boolSupp, Finset.mem_filter, Finset.mem_univ, true_and] at hi' simp [hi'] · rw [if_neg h] rw [Finset.not_subset] at h rcases h with ⟨i, hiS, hiN⟩ simp only [boolSupp, Finset.mem_filter, Finset.mem_univ, true_and] at hiN have hy : y i = false := by cases h' : y i <;> simp_all exact Finset.prod_eq_zero hiS (by simp [hy]) /-- `eval01 P y` is the Möbius sum `∑ S ⊆ boolSupp y, P S`. -/ lemma eval01_eq_sum_powerset {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) (y : Fin n → Bool) : eval01 P y = ∑ S ∈ (boolSupp y).powerset, P S := by unfold eval01 evalOn simp_rw [prod_boolBit, mul_ite, mul_one, mul_zero] rw [← Finset.sum_filter] congr 1 ext S simp /-- Alternating sum over subsets of a nonempty finite set is zero. -/ lemma sum_powerset_neg_one_pow {K : Type*} [CommRing K] {α : Type*} [DecidableEq α] (D : Finset α) : (∑ T ∈ D.powerset, (-1 : K) ^ T.card) = if D = ∅ then 1 else 0 := by induction D using Finset.induction_on with | empty => simp | @insert a s ha ih => rw [if_neg (Finset.insert_ne_empty a s)] rw [Finset.powerset_insert, Finset.sum_union] · have hmap : ∑ T ∈ s.powerset.image (insert a), (-1 : K) ^ T.card = -(∑ T ∈ s.powerset, (-1 : K) ^ T.card) := by rw [Finset.sum_image] · rw [← Finset.sum_neg_distrib] apply Finset.sum_congr rfl intro T hT have haT : a ∉ T := fun h => ha (Finset.mem_powerset.mp hT h) rw [Finset.card_insert_of_notMem haT, pow_succ] ring · intro T₁ hT₁ T₂ hT₂ heq have ha1 : a ∉ T₁ := fun h => ha (Finset.mem_powerset.mp hT₁ h) have ha2 : a ∉ T₂ := fun h => ha (Finset.mem_powerset.mp hT₂ h) have := congrArg (fun u => u.erase a) heq simpa [Finset.erase_insert ha1, Finset.erase_insert ha2] using this rw [hmap, add_neg_cancel] · rw [Finset.disjoint_left] intro T hT1 hT2 rw [Finset.mem_image] at hT2 rcases hT2 with ⟨U, _, rfl⟩ exact ha (Finset.mem_powerset.mp hT1 (Finset.mem_insert_self a U)) /-- Indicator Boolean vector of a `Finset (Fin n)`. -/ def indicatorBool {n : ℕ} (T : Finset (Fin n)) : Fin n → Bool := fun i => decide (i ∈ T) lemma boolSupp_indicatorBool {n : ℕ} (T : Finset (Fin n)) : boolSupp (indicatorBool T) = T := by ext i simp [boolSupp, indicatorBool] /-- Möbius inversion: unique multilinear polynomial on `{0, 1}ⁿ` representing any `f : (Fin n → Bool) → K`. -/ def mobiusCoeff {K : Type*} [CommRing K] {n : ℕ} (f : (Fin n → Bool) → K) : MultiPoly K n := fun S => ∑ T ∈ S.powerset, (-1 : K) ^ (S.card - T.card) * f (indicatorBool T) /-- `eval01` is left-inverse to `mobiusCoeff`. -/ lemma eval01_mobiusCoeff {K : Type*} [CommRing K] {n : ℕ} (f : (Fin n → Bool) → K) (y : Fin n → Bool) : eval01 (mobiusCoeff f) y = f y := by rw [eval01_eq_sum_powerset] unfold mobiusCoeff set U := boolSupp y have h1 : ∑ S ∈ U.powerset, ∑ T ∈ S.powerset, (-1 : K) ^ (S.card - T.card) * f (indicatorBool T) = ∑ T ∈ U.powerset, (∑ D ∈ (U \ T).powerset, (-1 : K) ^ D.card) * f (indicatorBool T) := by trans ∑ S ∈ U.powerset, ∑ T ∈ U.powerset, if T ⊆ S then (-1 : K) ^ (S.card - T.card) * f (indicatorBool T) else 0 · apply Finset.sum_congr rfl intro S hS rw [← Finset.sum_filter] congr 1 ext T simp only [Finset.mem_powerset, Finset.mem_filter] exact ⟨fun h => ⟨h.trans (Finset.mem_powerset.mp hS), h⟩, fun h => h.2⟩ · rw [Finset.sum_comm] apply Finset.sum_congr rfl intro T hT have hTU : T ⊆ U := Finset.mem_powerset.mp hT rw [← Finset.sum_filter, Finset.sum_mul] refine Finset.sum_nbij' (fun S => S \ T) (fun D => D ∪ T) ?_ ?_ ?_ ?_ ?_ · intro S hS simp only [Finset.mem_filter, Finset.mem_powerset] at hS ⊢ exact Finset.sdiff_subset_sdiff hS.1 (Finset.Subset.refl T) · intro D hD simp only [Finset.mem_filter, Finset.mem_powerset] at hD ⊢ exact ⟨Finset.union_subset (hD.trans Finset.sdiff_subset) hTU, Finset.subset_union_right⟩ · intro S hS simp only [Finset.mem_filter, Finset.mem_powerset] at hS exact Finset.sdiff_union_of_subset hS.2 · intro D hD rw [Finset.mem_powerset] at hD have hdisj : Disjoint D T := Disjoint.mono_left hD Finset.sdiff_disjoint exact Finset.union_sdiff_cancel_right hdisj · intro S hS simp only [Finset.mem_filter, Finset.mem_powerset] at hS rw [Finset.card_sdiff_of_subset hS.2] rw [h1] simp_rw [sum_powerset_neg_one_pow, ite_mul, one_mul, zero_mul] rw [Finset.sum_eq_single U] · simp only [Finset.sdiff_self, ↓reduceIte] congr 1 funext i simp [U, boolSupp, indicatorBool] · intro T hT hne rw [if_neg] intro hdiff have hTU : T ⊆ U := Finset.mem_powerset.mp hT have hUT : U ⊆ T := Finset.sdiff_eq_empty_iff_subset.mp hdiff exact hne (Finset.Subset.antisymm hTU hUT) · intro hU exact absurd (Finset.mem_powerset_self U) hU /-- `mobiusCoeff` is left-inverse to `eval01` (uniqueness of multilinear coefficients on `{0,1}ⁿ`). -/ lemma mobiusCoeff_eval01 {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) (S : Finset (Fin n)) : mobiusCoeff (eval01 P) S = P S := by unfold mobiusCoeff simp_rw [eval01_eq_sum_powerset, boolSupp_indicatorBool] have h1 : ∑ T ∈ S.powerset, (-1 : K) ^ (S.card - T.card) * ∑ A ∈ T.powerset, P A = ∑ A ∈ S.powerset, (∑ D ∈ (S \ A).powerset, (-1 : K) ^ D.card) * P A := by simp_rw [Finset.mul_sum] trans ∑ T ∈ S.powerset, ∑ A ∈ S.powerset, if A ⊆ T then (-1 : K) ^ (S.card - T.card) * P A else 0 · apply Finset.sum_congr rfl intro T hT rw [← Finset.sum_filter] congr 1 ext A simp only [Finset.mem_powerset, Finset.mem_filter] exact ⟨fun h => ⟨h.trans (Finset.mem_powerset.mp hT), h⟩, fun h => h.2⟩ · rw [Finset.sum_comm] apply Finset.sum_congr rfl intro A hA have hAS : A ⊆ S := Finset.mem_powerset.mp hA rw [← Finset.sum_filter, Finset.sum_mul] refine Finset.sum_nbij' (fun T => S \ T) (fun D => S \ D) ?_ ?_ ?_ ?_ ?_ · intro T hT simp only [Finset.mem_filter, Finset.mem_powerset] at hT ⊢ exact Finset.sdiff_subset_sdiff (Finset.Subset.refl S) hT.2 · intro D hD simp only [Finset.mem_filter, Finset.mem_powerset] at hD ⊢ refine ⟨Finset.sdiff_subset, ?_⟩ intro x hxA rw [Finset.mem_sdiff] exact ⟨hAS hxA, fun hxD => (Finset.mem_sdiff.mp (hD hxD)).2 hxA⟩ · intro T hT simp only [Finset.mem_filter, Finset.mem_powerset] at hT exact Finset.sdiff_sdiff_eq_self hT.1 · intro D hD rw [Finset.mem_powerset] at hD exact Finset.sdiff_sdiff_eq_self (hD.trans Finset.sdiff_subset) · intro T hT simp only [Finset.mem_filter, Finset.mem_powerset] at hT rw [Finset.card_sdiff_of_subset hT.1] rw [h1] simp_rw [sum_powerset_neg_one_pow, ite_mul, one_mul, zero_mul] rw [Finset.sum_eq_single S] · simp · intro A hA hne rw [if_neg] intro hdiff exact hne (Finset.Subset.antisymm (Finset.mem_powerset.mp hA) (Finset.sdiff_eq_empty_iff_subset.mp hdiff)) · intro hS exact absurd (Finset.mem_powerset_self S) hS /-- A multilinear polynomial vanishing identically on `{0, 1}ⁿ` has all coefficients zero. -/ lemma eq_zero_of_eval01_eq_zero {K : Type*} [CommRing K] {n : ℕ} {P : MultiPoly K n} (hP : ∀ y, eval01 P y = 0) : P = 0 := by funext S rw [← mobiusCoeff_eval01 P S] unfold mobiusCoeff simp [hP] /-- Multilinear multiplication on `{0, 1}ⁿ` (using `x_i² = x_i`, so `x_A · x_B = x_{A ∪ B}`). -/ def mul01 {K : Type*} [CommRing K] {n : ℕ} (P Q : MultiPoly K n) : MultiPoly K n := fun U => ∑ A : Finset (Fin n), ∑ B : Finset (Fin n), if A ∪ B = U then P A * Q B else 0 lemma eval01_mul01 {K : Type*} [CommRing K] {n : ℕ} (P Q : MultiPoly K n) (y : Fin n → Bool) : eval01 (mul01 P Q) y = eval01 P y * eval01 Q y := by simp only [eval01_eq_sum_powerset, mul01] rw [Finset.sum_mul] simp_rw [Finset.mul_sum] rw [Finset.sum_comm] trans ∑ A : Finset (Fin n), ∑ B : Finset (Fin n), if A ∪ B ⊆ boolSupp y then P A * Q B else 0 · rw [Finset.sum_comm] trans ∑ A : Finset (Fin n), ∑ U ∈ (boolSupp y).powerset, ∑ B : Finset (Fin n), if A ∪ B = U then P A * Q B else 0 · rw [Finset.sum_comm] · apply Finset.sum_congr rfl intro A _ rw [Finset.sum_comm] apply Finset.sum_congr rfl intro B _ by_cases h : A ∪ B ⊆ boolSupp y · rw [if_pos h, Finset.sum_eq_single (A ∪ B)] · simp · intro U _ hne; simp [hne.symm] · intro hnot; exact absurd (Finset.mem_powerset.mpr h) hnot · rw [if_neg h] apply Finset.sum_eq_zero intro U hU rw [if_neg] intro heq exact h (heq ▸ Finset.mem_powerset.mp hU) · simp_rw [Finset.union_subset_iff] trans ∑ A : Finset (Fin n), if A ⊆ boolSupp y then ∑ B ∈ (boolSupp y).powerset, P A * Q B else 0 · apply Finset.sum_congr rfl intro A _ by_cases hA : A ⊆ boolSupp y · simp only [hA, true_and, ↓reduceIte] rw [← Finset.sum_filter] congr 1; ext B; simp · simp [hA] · rw [← Finset.sum_filter] congr 1; ext A; simp lemma hasDegLe_mul01 {K : Type*} [CommRing K] {n d₁ d₂ : ℕ} {P Q : MultiPoly K n} (hP : HasDegLe P d₁) (hQ : HasDegLe Q d₂) : HasDegLe (mul01 P Q) (d₁ + d₂) := by intro U hU unfold mul01 apply Finset.sum_eq_zero; intro A _ apply Finset.sum_eq_zero; intro B _ split_ifs with hAB · by_cases hA : d₁ < A.card · simp [hP A hA] · by_cases hB : d₂ < B.card · simp [hQ B hB] · exfalso have hcard : U.card ≤ A.card + B.card := by rw [← hAB]; exact Finset.card_union_le A B omega · rfl lemma hasDegLe_add {K : Type*} [CommRing K] {n d : ℕ} {P Q : MultiPoly K n} (hP : HasDegLe P d) (hQ : HasDegLe Q d) : HasDegLe (P + Q) d := fun S hS => by simp [hP S hS, hQ S hS] lemma hasDegLe_sub {K : Type*} [CommRing K] {n d : ℕ} {P Q : MultiPoly K n} (hP : HasDegLe P d) (hQ : HasDegLe Q d) : HasDegLe (P - Q) d := fun S hS => by simp [hP S hS, hQ S hS] lemma hasDegLe_smul {K : Type*} [CommRing K] {n d : ℕ} (c : K) {P : MultiPoly K n} (hP : HasDegLe P d) : HasDegLe (c • P) d := fun S hS => by simp [hP S hS] lemma hasDegLe_mono {K : Type*} [Zero K] {n d₁ d₂ : ℕ} {P : MultiPoly K n} (hP : HasDegLe P d₁) (hle : d₁ ≤ d₂) : HasDegLe P d₂ := fun S hS => hP S (lt_of_le_of_lt hle hS) /-- Constant multilinear polynomial. -/ def constPoly {K : Type*} [Zero K] {n : ℕ} (c : K) : MultiPoly K n := fun S => if S = ∅ then c else 0 lemma eval01_constPoly {K : Type*} [CommRing K] {n : ℕ} (c : K) (y : Fin n → Bool) : eval01 (constPoly c) y = c := by rw [eval01_eq_sum_powerset] unfold constPoly rw [Finset.sum_eq_single ∅] · simp · intro S _ hne; simp [hne] · intro h; exact absurd (Finset.empty_mem_powerset _) h lemma hasDegLe_constPoly {K : Type*} [Zero K] {n : ℕ} (c : K) : HasDegLe (constPoly (n := n) c) 0 := by intro S hS unfold constPoly have hne : S ≠ ∅ := (Finset.card_pos.mp hS).ne_empty simp [hne] /-- Single variable multilinear polynomial `x_i`. -/ def varPoly {K : Type*} [CommRing K] {n : ℕ} (i : Fin n) : MultiPoly K n := fun S => if S = {i} then 1 else 0 lemma eval01_varPoly {K : Type*} [CommRing K] {n : ℕ} (i : Fin n) (y : Fin n → Bool) : eval01 (varPoly (K := K) i) y = if y i then 1 else 0 := by rw [eval01_eq_sum_powerset] unfold varPoly by_cases hy : y i = true · simp only [hy, ↓reduceIte] rw [Finset.sum_eq_single {i}] · simp · intro S _ hne; simp [hne] · intro hnot exfalso apply hnot rw [Finset.mem_powerset, Finset.singleton_subset_iff] simp [boolSupp, hy] · have hyf : y i = false := by cases h : y i <;> simp_all simp only [hyf, Bool.false_eq_true, ↓reduceIte] apply Finset.sum_eq_zero intro S hS rw [if_neg] intro heq subst heq have hmem : i ∈ boolSupp y := Finset.singleton_subset_iff.mp (Finset.mem_powerset.mp hS) simp [boolSupp, hyf] at hmem lemma hasDegLe_varPoly {K : Type*} [CommRing K] {n : ℕ} (i : Fin n) : HasDegLe (varPoly (K := K) i) 1 := by intro S hS unfold varPoly rw [if_neg] intro heq subst heq simp at hS /-- Evaluation of `eval01` is additive and scalar-linear. -/ lemma eval01_add {K : Type*} [CommRing K] {n : ℕ} (P Q : MultiPoly K n) (y : Fin n → Bool) : eval01 (P + Q) y = eval01 P y + eval01 Q y := by simp [eval01_eq_sum_powerset, Finset.sum_add_distrib] lemma eval01_sub {K : Type*} [CommRing K] {n : ℕ} (P Q : MultiPoly K n) (y : Fin n → Bool) : eval01 (P - Q) y = eval01 P y - eval01 Q y := by simp [eval01_eq_sum_powerset, Finset.sum_sub_distrib] lemma eval01_smul {K : Type*} [CommRing K] {n : ℕ} (c : K) (P : MultiPoly K n) (y : Fin n → Bool) : eval01 (c • P) y = c * eval01 P y := by simp [eval01_eq_sum_powerset, Finset.mul_sum] /-- Multilinear power `P^k` on `{0, 1}ⁿ`. -/ def pow01 {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) : ℕ → MultiPoly K n | 0 => constPoly 1 | k + 1 => mul01 (pow01 P k) P lemma eval01_pow01 {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) (k : ℕ) (y : Fin n → Bool) : eval01 (pow01 P k) y = (eval01 P y) ^ k := by induction k with | zero => simp [pow01, eval01_constPoly] | succ k ih => simp [pow01, eval01_mul01, ih, pow_succ] lemma hasDegLe_pow01 {K : Type*} [CommRing K] {n d : ℕ} {P : MultiPoly K n} (hP : HasDegLe P d) (k : ℕ) : HasDegLe (pow01 P k) (k * d) := by induction k with | zero => simpa [pow01] using hasDegLe_constPoly (n := n) (1 : K) | succ k ih => simpa [pow01, Nat.succ_mul] using hasDegLe_mul01 ih hP /-! ## Section 1 (Pillar 1): Universal Odd/Even-Strength Gram–Smolensky Theorem, Exact Parity–Cubature Duality, Hadamard `r = 2` Obstruction, and `𝔽₄` `MOD₃` Lift -/ /-- The top-coefficient alternating functional `Λ(f) = ∑_{y ∈ {0,1}ⁿ} (-1)^{n - |y|} f(y)`. On any multilinear polynomial `P` on `{0,1}ⁿ`, `topCoeffFunctional (eval01 P) = P univ`. -/ def topCoeffFunctional {K : Type*} [CommRing K] {n : ℕ} (f : (Fin n → Bool) → K) : K := ∑ y : Fin n → Bool, (-1 : K) ^ (n - hammingWeight y) * f y /-- Exact identity: `topCoeffFunctional (eval01 P) = P Finset.univ`. -/ lemma topCoeffFunctional_eval01 {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) : topCoeffFunctional (eval01 P) = P Finset.univ := by have h := mobiusCoeff_eval01 P (Finset.univ : Finset (Fin n)) rw [← h] unfold topCoeffFunctional mobiusCoeff refine Finset.sum_nbij' (fun y => boolSupp y) (fun T => indicatorBool T) ?_ ?_ ?_ ?_ ?_ · intro y _; exact Finset.mem_powerset.mpr (Finset.subset_univ _) · intro T _; exact Finset.mem_univ _ · intro y _ funext i simp [boolSupp, indicatorBool] · intro T _ exact boolSupp_indicatorBool T · intro y _ have hcard : (Finset.univ : Finset (Fin n)).card = n := Fintype.card_fin n have hy : indicatorBool (boolSupp y) = y := by funext i; simp [boolSupp, indicatorBool] rw [hcard, hy] rfl /-- `topCoeffFunctional` vanishes on every polynomial of degree `< n`. -/ lemma topCoeffFunctional_eq_zero_of_hasDegLe {K : Type*} [CommRing K] {n d : ℕ} {P : MultiPoly K n} (hP : HasDegLe P d) (hd : d < n) : topCoeffFunctional (eval01 P) = 0 := by rw [topCoeffFunctional_eval01] exact hP Finset.univ (by simpa using hd) /-- Multiplicative character `χ_ω(y) = ω ^ |y| = ∏_{i=1}^n ω^{y_i}` on `{0,1}ⁿ`. -/ def prodChar {K : Type*} [CommRing K] {n : ℕ} (ω : K) (y : Fin n → Bool) : K := ω ^ hammingWeight y /-- `prodChar ω y` equals the product `∏ i, (if y i then ω else 1)`. -/ lemma prodChar_eq_prod {K : Type*} [CommRing K] {n : ℕ} (ω : K) (y : Fin n → Bool) : prodChar ω y = ∏ i : Fin n, (if y i then ω else 1) := by unfold prodChar hammingWeight boolSupp rw [Finset.prod_ite, Finset.prod_const_one, mul_one, Finset.prod_const] /-- Inverse monomial on `{1, ω}ⁿ`: `invMonomial ω J y = ∏_{i ∈ J} (if y i then ω⁻¹ else 1)`. -/ def invMonomial {K : Type*} [Field K] {n : ℕ} (ω : K) (J : Finset (Fin n)) (y : Fin n → Bool) : K := ∏ i ∈ J, (if y i then ω⁻¹ else 1) /-- Each `invMonomial ω J` is represented by a multilinear polynomial on `{0,1}ⁿ` of degree `≤ |J|`. -/ lemma exists_poly_invMonomial {K : Type*} [Field K] {n : ℕ} (ω : K) (J : Finset (Fin n)) : ∃ Q : MultiPoly K n, HasDegLe Q J.card ∧ ∀ y, eval01 Q y = invMonomial ω J y := by induction J using Finset.induction_on with | empty => refine ⟨constPoly 1, hasDegLe_constPoly 1, fun y => ?_⟩ simp [eval01_constPoly, invMonomial] | @insert a s ha ih => rcases ih with ⟨Q, hQdeg, hQeval⟩ let L : MultiPoly K n := constPoly 1 + (ω⁻¹ - 1) • varPoly a have hLdeg : HasDegLe L 1 := hasDegLe_add (hasDegLe_mono (hasDegLe_constPoly 1) (Nat.zero_le 1)) (hasDegLe_smul _ (hasDegLe_varPoly a)) refine ⟨mul01 L Q, ?_, fun y => ?_⟩ · rw [Finset.card_insert_of_notMem ha, add_comm] exact hasDegLe_mul01 hLdeg hQdeg · rw [eval01_mul01, hQeval] unfold invMonomial rw [Finset.prod_insert ha] congr 1 simp only [L, eval01_add, eval01_constPoly, eval01_smul, eval01_varPoly] cases y a <;> simp /-- Exact value of `topCoeffFunctional (fun y => prodChar ω y * invMonomial ω J y)`. It equals `(ω - 1)^n` if `J = ∅`, and `0` if `J ≠ ∅`! -/ lemma topCoeffFunctional_prodChar_mul_invMonomial {K : Type*} [Field K] {n : ℕ} {ω : K} (hω0 : ω ≠ 0) (J : Finset (Fin n)) : topCoeffFunctional (fun y => prodChar ω y * invMonomial ω J y) = if J = ∅ then (ω - 1) ^ n else 0 := by have hpoint : ∀ y : Fin n → Bool, prodChar ω y * invMonomial ω J y = ∏ i ∈ Jᶜ, (if y i then ω else 1) := by intro y rw [prodChar_eq_prod, invMonomial] have hunion : Jᶜ ∪ J = Finset.univ := by ext i; simp [em'] have hsplit : (∏ i : Fin n, (if y i then ω else 1)) = (∏ i ∈ Jᶜ, (if y i then ω else 1)) * (∏ i ∈ J, (if y i then ω else 1)) := by rw [← Finset.prod_union disjoint_compl_left, hunion] rw [hsplit, mul_assoc] have hcancel : (∏ i ∈ J, (if y i then ω else 1)) * (∏ i ∈ J, (if y i then ω⁻¹ else 1)) = 1 := by rw [← Finset.prod_mul_distrib] apply Finset.prod_eq_one intro i _ cases y i <;> simp [hω0] rw [hcancel, mul_one] -- Represent `y ↦ ∏ i ∈ Jᶜ, (if y i then ω else 1)` explicitly as a multilinear polynomial! let P : MultiPoly K n := fun S => if S ⊆ Jᶜ then (ω - 1) ^ S.card else 0 have hPeval : ∀ y : Fin n → Bool, eval01 P y = ∏ i ∈ Jᶜ, (if y i then ω else 1) := by intro y rw [eval01_eq_sum_powerset] have hprod : ∏ i ∈ Jᶜ, (if y i then ω else 1) = ∏ i ∈ Jᶜ, (1 + (if y i then (ω - 1) else 0)) := by apply Finset.prod_congr rfl intro i _ cases y i <;> simp rw [hprod, Finset.prod_one_add] have hfilter : ∑ S ∈ (boolSupp y).powerset, P S = ∑ S ∈ Jᶜ.powerset, ∏ i ∈ S, (if y i then ω - 1 else 0) := by have hterm : ∀ S : Finset (Fin n), ∏ i ∈ S, (if y i then ω - 1 else 0) = if S ⊆ boolSupp y then (ω - 1) ^ S.card else 0 := by intro S by_cases hS : S ⊆ boolSupp y · rw [if_pos hS] have h1 : ∀ i ∈ S, (if y i then ω - 1 else 0) = ω - 1 := by intro i hi have := hS hi simp only [boolSupp, Finset.mem_filter, Finset.mem_univ, true_and] at this simp [this] rw [Finset.prod_congr rfl h1, Finset.prod_const] · rw [if_neg hS] rw [Finset.not_subset] at hS rcases hS with ⟨i, hiS, hiN⟩ simp only [boolSupp, Finset.mem_filter, Finset.mem_univ, true_and] at hiN have hyf : y i = false := by cases h : y i <;> simp_all exact Finset.prod_eq_zero hiS (by simp [hyf]) simp_rw [hterm, P] rw [← Finset.sum_filter, ← Finset.sum_filter] congr 1 ext S simp [and_comm] exact hfilter have hfun : (fun y => prodChar ω y * invMonomial ω J y) = eval01 P := by funext y; rw [hpoint y, hPeval y] rw [hfun, topCoeffFunctional_eval01] simp only [P] by_cases hJ : J = ∅ · subst hJ simp · rw [if_neg hJ, if_neg] intro hsub have hne : J.Nonempty := Finset.nonempty_iff_ne_empty.mpr hJ rcases hne with ⟨i, hi⟩ have := hsub (Finset.mem_univ i) exact (Finset.mem_compl.mp this) hi /-- Product identity for two inverse monomials on `{1, ω}ⁿ`: `invMonomial ω A y * invMonomial ω B y` expands as a linear combination of `invMonomial ω U y` with `U ⊆ A ∪ B`, and the coefficient of `∅` is `(-ω⁻¹)^|A|` if `A = B`, else `0`! -/ lemma invMonomial_mul_expand {K : Type*} [Field K] {n : ℕ} (ω : K) (A B : Finset (Fin n)) (y : Fin n → Bool) : invMonomial ω A y * invMonomial ω B y = ∑ T ∈ (A ∩ B).powerset, (1 + ω⁻¹) ^ T.card * (-ω⁻¹) ^ ((A ∩ B).card - T.card) * invMonomial ω ((symmDiff A B) ∪ T) y := by have hsq : ∀ i : Fin n, (if y i then ω⁻¹ else (1 : K)) * (if y i then ω⁻¹ else 1) = (1 + ω⁻¹) * (if y i then ω⁻¹ else 1) + (-ω⁻¹) := by intro i; cases y i · simp · simp; ring have hsplitA : A = (A \ B) ∪ (A ∩ B) := (Finset.sdiff_union_inter A B).symm have hsplitB : B = (B \ A) ∪ (A ∩ B) := by rw [Finset.inter_comm]; exact (Finset.sdiff_union_inter B A).symm have hprod : invMonomial ω A y * invMonomial ω B y = invMonomial ω (symmDiff A B) y * ∏ i ∈ A ∩ B, ((1 + ω⁻¹) * (if y i then ω⁻¹ else 1) + (-ω⁻¹)) := by unfold invMonomial have hA : (∏ i ∈ A, (if y i then ω⁻¹ else 1)) = (∏ i ∈ A \ B, (if y i then ω⁻¹ else 1)) * (∏ i ∈ A ∩ B, (if y i then ω⁻¹ else 1)) := by conv_lhs => rw [hsplitA] exact Finset.prod_union (Finset.disjoint_left.mpr (fun i h1 h2 => (Finset.mem_sdiff.mp h1).2 (Finset.mem_inter.mp h2).2)) have hB : (∏ i ∈ B, (if y i then ω⁻¹ else 1)) = (∏ i ∈ B \ A, (if y i then ω⁻¹ else 1)) * (∏ i ∈ A ∩ B, (if y i then ω⁻¹ else 1)) := by conv_lhs => rw [hsplitB] exact Finset.prod_union (Finset.disjoint_left.mpr (fun i h1 h2 => (Finset.mem_sdiff.mp h1).2 (Finset.mem_inter.mp h2).1)) rw [hA, hB] have hdisjAB : Disjoint (A \ B) (B \ A) := Finset.disjoint_left.mpr (fun i h1 h2 => (Finset.mem_sdiff.mp h1).2 (Finset.mem_sdiff.mp h2).1) have hsymm : symmDiff A B = (A \ B) ∪ (B \ A) := rfl rw [hsymm, Finset.prod_union hdisjAB] calc (∏ i ∈ A \ B, (if y i then ω⁻¹ else 1)) * (∏ i ∈ A ∩ B, (if y i then ω⁻¹ else 1)) * ((∏ i ∈ B \ A, (if y i then ω⁻¹ else 1)) * (∏ i ∈ A ∩ B, (if y i then ω⁻¹ else 1))) = (∏ i ∈ A \ B, (if y i then ω⁻¹ else 1)) * (∏ i ∈ B \ A, (if y i then ω⁻¹ else 1)) * ((∏ i ∈ A ∩ B, (if y i then ω⁻¹ else 1)) * (∏ i ∈ A ∩ B, (if y i then ω⁻¹ else 1))) := by ring _ = _ := by congr 1 rw [← Finset.prod_mul_distrib] exact Finset.prod_congr rfl (fun i _ => hsq i) rw [hprod, Finset.prod_add, Finset.mul_sum] apply Finset.sum_congr rfl intro T hT have hTab : T ⊆ A ∩ B := Finset.mem_powerset.mp hT have hdisj : Disjoint (symmDiff A B) T := by rw [Finset.disjoint_left] intro i hi1 hi2 have hiab := hTab hi2 rw [Finset.mem_symmDiff] at hi1 rw [Finset.mem_inter] at hiab rcases hi1 with ⟨_, hnb⟩ | ⟨_, hna⟩ · exact hnb hiab.2 · exact hna hiab.1 rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.prod_const, Finset.card_sdiff_of_subset hTab] have hinvU : invMonomial ω ((symmDiff A B) ∪ T) y = invMonomial ω (symmDiff A B) y * ∏ i ∈ T, (if y i then ω⁻¹ else 1) := by unfold invMonomial exact Finset.prod_union hdisj rw [hinvU] ring /-- **Orthogonal Signed-Measure Gram Matrix Lemma (Arbitrary Field, Arbitrary `ω ≠ 0, 1`):** If `h : (Fin n → Bool) → K` is supported on `E`, satisfies `∑_{y ∈ E} h y = c ≠ 0` and `∑_{y ∈ E} h y * invMonomial ω J y = 0` for all `1 ≤ |J| ≤ r`, then for any collection `ℬ ⊆ Finset (Fin n)` such that `|A ∪ B| ≤ r` for all `A, B ∈ ℬ`, we have `|ℬ| ≤ |E|`. -/ theorem gram_rank_lower_bound {K : Type*} [Field K] {n r : ℕ} {ω : K} (hω0 : ω ≠ 0) (E : Finset (Fin n → Bool)) (h : (Fin n → Bool) → K) {c : K} (hc : c ≠ 0) (hsum0 : ∑ y ∈ E, h y = c) (horth : ∀ J : Finset (Fin n), 1 ≤ J.card → J.card ≤ r → ∑ y ∈ E, h y * invMonomial ω J y = 0) (ℬ : Finset (Finset (Fin n))) (hℬ : ∀ A ∈ ℬ, ∀ B ∈ ℬ, (A ∪ B).card ≤ r) : ℬ.card ≤ E.card := by let Φ : (ℬ → K) →ₗ[K] (E → K) := { toFun := fun a y => ∑ A : ℬ, a A * invMonomial ω A.1 y.1 map_add' := fun a b => by ext y; simp [add_mul, Finset.sum_add_distrib] map_smul' := fun k a => by ext y; simp [mul_assoc, Finset.mul_sum] } have hinj : Function.Injective Φ := by rw [injective_iff_map_eq_zero] intro a ha ext ⟨B, hB⟩ have hzero : ∑ y ∈ E, h y * invMonomial ω B y * (∑ A : ℬ, a A * invMonomial ω A.1 y) = 0 := by apply Finset.sum_eq_zero intro y hy have hy0 : Φ a ⟨y, hy⟩ = 0 := congrFun ha ⟨y, hy⟩ simp only [Φ, LinearMap.coe_mk, AddHom.coe_mk] at hy0 rw [hy0, mul_zero] have hdiag : ∀ A : ℬ, ∑ y ∈ E, h y * (invMonomial ω B y * invMonomial ω A.1 y) = if A.1 = B then (-ω⁻¹) ^ B.card * c else 0 := by intro ⟨A, hA⟩ simp_rw [invMonomial_mul_expand ω B A] simp_rw [Finset.mul_sum] rw [Finset.sum_comm] have hsub_le : ∀ T ∈ (B ∩ A).powerset, ((symmDiff B A) ∪ T).card ≤ r := by intro T hT have hsub : (symmDiff B A) ∪ T ⊆ B ∪ A := by refine Finset.union_subset ?_ ((Finset.mem_powerset.mp hT).trans Finset.inter_subset_union) exact Finset.symmDiff_subset_union exact (Finset.card_le_card hsub).trans (hℬ B hB A hA) by_cases hAB : A = B · subst hAB rw [if_pos rfl] rw [Finset.sum_eq_single ∅] · simp only [Finset.inter_self, symmDiff_self, Finset.bot_eq_empty, Finset.empty_union, Finset.card_empty, pow_zero, one_mul, Nat.sub_zero, invMonomial, Finset.prod_empty, mul_one] rw [← Finset.sum_mul, hsum0, mul_comm] · intro T hT hTne have hpos : 1 ≤ T.card := Finset.card_pos.mpr (Finset.nonempty_iff_ne_empty.mpr hTne) have hle : T.card ≤ r := by simpa [symmDiff_self] using hsub_le T hT have hzeroT : ∑ y ∈ E, h y * ((1 + ω⁻¹) ^ T.card * (-ω⁻¹) ^ ((A ∩ A).card - T.card) * invMonomial ω ((symmDiff A A) ∪ T) y) = 0 := by have : ∀ y, h y * ((1 + ω⁻¹) ^ T.card * (-ω⁻¹) ^ ((A ∩ A).card - T.card) * invMonomial ω ((symmDiff A A) ∪ T) y) = ((1 + ω⁻¹) ^ T.card * (-ω⁻¹) ^ ((A ∩ A).card - T.card)) * (h y * invMonomial ω T y) := by intro y; simp [symmDiff_self]; ring simp_rw [this, ← Finset.mul_sum, horth T hpos hle, mul_zero] exact hzeroT · intro hnot; exact absurd (Finset.empty_mem_powerset _) hnot · rw [if_neg hAB] apply Finset.sum_eq_zero intro T hT have hne : ((symmDiff B A) ∪ T).Nonempty := by have hsym_ne : (symmDiff B A).Nonempty := by rw [Finset.nonempty_iff_ne_empty] intro hemp exact hAB (symmDiff_eq_bot.mp hemp).symm exact hsym_ne.mono Finset.subset_union_left have hpos : 1 ≤ ((symmDiff B A) ∪ T).card := Finset.card_pos.mpr hne have hle : ((symmDiff B A) ∪ T).card ≤ r := hsub_le T hT have : ∀ y, h y * ((1 + ω⁻¹) ^ T.card * (-ω⁻¹) ^ ((B ∩ A).card - T.card) * invMonomial ω ((symmDiff B A) ∪ T) y) = ((1 + ω⁻¹) ^ T.card * (-ω⁻¹) ^ ((B ∩ A).card - T.card)) * (h y * invMonomial ω ((symmDiff B A) ∪ T) y) := by intro y; ring simp_rw [this, ← Finset.mul_sum, horth _ hpos hle, mul_zero] have hcalc : a ⟨B, hB⟩ * ((-ω⁻¹) ^ B.card * c) = 0 := by have hre : ∑ y ∈ E, h y * invMonomial ω B y * (∑ A : ℬ, a A * invMonomial ω A.1 y) = ∑ A : ℬ, a A * (∑ y ∈ E, h y * (invMonomial ω B y * invMonomial ω A.1 y)) := by simp_rw [Finset.mul_sum] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro A _ apply Finset.sum_congr rfl intro y _ ring rw [hre] at hzero simp_rw [hdiag] at hzero rw [Finset.sum_eq_single ⟨B, hB⟩] at hzero · simpa using hzero · intro A _ hne have hne1 : A.1 ≠ B := fun h => hne (Subtype.ext h) simp [hne1] · intro hnot; exact absurd (Finset.mem_univ _) hnot have hnz : (-ω⁻¹) ^ B.card * c ≠ 0 := by apply mul_ne_zero · exact pow_ne_zero _ (neg_ne_zero.mpr (inv_ne_zero hω0)) · exact hc exact (mul_eq_zero.mp hcalc).resolve_right hnz have hfr := LinearMap.finrank_le_finrank_of_injective hinj simpa [Module.finrank_pi, Fintype.card_coe] using hfr /-- **The Rao basis family `ℬ` for `r`:** - If `r = 2t` is even: `{A : |A| ≤ t}` (size `binomSum n t`). - If `r = 2t + 1` is odd (and `n ≥ 1`): `{A : |A| ≤ t} ∪ {insert 0 B : |B| = t, 0 ∉ B}` (size `binomSum n t + C(n - 1, t)`). -/ def raoFamily (n r : ℕ) (hn : 1 ≤ n) : Finset (Finset (Fin n)) := let t := r / 2 let B0 := Finset.univ.filter (fun A : Finset (Fin n) => A.card ≤ t) if r % 2 = 0 then B0 else let i0 : Fin n := ⟨0, hn⟩ let B1 := Finset.univ.filter (fun A : Finset (Fin n) => A.card = t + 1 ∧ i0 ∈ A) B0 ∪ B1 lemma card_raoFamily (n r : ℕ) (hn : 1 ≤ n) : (raoFamily n r hn).card = raoBound n r := by unfold raoFamily raoBound by_cases hpar : r % 2 = 0 · simp only [hpar, ↓reduceIte] exact card_filter_card_le n (r / 2) · simp only [hpar, ↓reduceIte] set t := r / 2 let i0 : Fin n := ⟨0, hn⟩ have hdisj : Disjoint (Finset.univ.filter (fun A : Finset (Fin n) => A.card ≤ t)) (Finset.univ.filter (fun A : Finset (Fin n) => A.card = t + 1 ∧ i0 ∈ A)) := by rw [Finset.disjoint_left] intro A h1 h2 simp only [Finset.mem_filter, Finset.mem_univ, true_and] at h1 h2 omega rw [Finset.card_union_of_disjoint hdisj, card_filter_card_le] congr 1 -- Count `{A : |A| = t + 1 ∧ i0 ∈ A}` via bijection with `powersetCard t ({i0}ᶜ)` have hbij : (Finset.univ.filter (fun A : Finset (Fin n) => A.card = t + 1 ∧ i0 ∈ A)).card = (Finset.powersetCard t ({i0}ᶜ : Finset (Fin n))).card := by refine Finset.card_bij (fun A _ => A.erase i0) ?_ ?_ ?_ · intro A hA simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hA rw [Finset.mem_powersetCard] refine ⟨?_, ?_⟩ · intro x hx simp only [Finset.mem_compl, Finset.mem_singleton] exact (Finset.mem_erase.mp hx).1 · rw [Finset.card_erase_of_mem hA.2, hA.1]; omega · intro A₁ hA₁ A₂ hA₂ heq simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hA₁ hA₂ rw [← Finset.insert_erase hA₁.2, ← Finset.insert_erase hA₂.2, heq] · intro B hB rw [Finset.mem_powersetCard] at hB have hnot : i0 ∉ B := fun hi => by have := hB.1 hi simp at this refine ⟨insert i0 B, ?_, Finset.erase_insert hnot⟩ simp only [Finset.mem_filter, Finset.mem_univ, true_and] exact ⟨by rw [Finset.card_insert_of_notMem hnot, hB.2], Finset.mem_insert_self i0 B⟩ rw [hbij, Finset.card_powersetCard, Finset.card_compl, Finset.card_singleton, Fintype.card_fin] lemma raoFamily_union_card_le (n r : ℕ) (hn : 1 ≤ n) : ∀ A ∈ raoFamily n r hn, ∀ B ∈ raoFamily n r hn, (A ∪ B).card ≤ r := by unfold raoFamily by_cases hpar : r % 2 = 0 · simp only [hpar, ↓reduceIte] intro A hA B hB simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hA hB have := Finset.card_union_le A B omega · simp only [hpar, ↓reduceIte] intro A hA B hB simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] at hA hB rcases hA with hA | ⟨hAcard, hA0⟩ <;> rcases hB with hB | ⟨hBcard, hB0⟩ · have := Finset.card_union_le A B; omega · have := Finset.card_union_le A B; omega · have := Finset.card_union_le A B; omega · have hmem : (⟨0, hn⟩ : Fin n) ∈ A ∩ B := Finset.mem_inter.mpr ⟨hA0, hB0⟩ have hpos : 1 ≤ (A ∩ B).card := Finset.card_pos.mpr ⟨_, hmem⟩ have hcu := Finset.card_union_add_card_inter A B omega /-- **HEADLINE THEOREM 1 (Universal Odd/Even-Strength Gram–Smolensky Theorem):** Over *every* field `K` (arbitrary characteristic, including characteristic `2`) and *every* `ω ∈ K` with `ω ≠ 0` and `ω ≠ 1`, for every `n ≥ 1`, every `d < n`, and every multilinear polynomial `P` of degree `≤ d`, the error set `E = {y ∈ {0,1}ⁿ | eval01 P y ≠ ω ^ |y|}` satisfies `|E| ≥ raoBound n (n - d - 1)`. When `n + d` is even, `raoBound n (n - d - 1) = ∑_{j=0}^{(n-d-2)/2} C(n,j) + C(n-1, (n-d-2)/2)`, strictly improving Smolensky's classical bound by `C(n-1, (n+d)/2)`. -/ theorem universal_gram_smolensky_bound {K : Type*} [Field K] [DecidableEq K] {n d : ℕ} (hn : 1 ≤ n) (hd : d < n) {ω : K} (hω0 : ω ≠ 0) (hω1 : ω ≠ 1) (P : MultiPoly K n) (hP : HasDegLe P d) : raoBound n (n - d - 1) ≤ (Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ prodChar ω y)).card := by let E := Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ prodChar ω y) let g : (Fin n → Bool) → K := fun y => prodChar ω y - eval01 P y let h : (Fin n → Bool) → K := fun y => (-1 : K) ^ (n - hammingWeight y) * g y have hsupp : ∀ y, y ∉ E → h y = 0 := by intro y hy simp only [E, Finset.mem_filter, Finset.mem_univ, true_and, not_not] at hy simp [h, g, hy] have hmoment : ∀ J : Finset (Fin n), J.card ≤ n - d - 1 → ∑ y ∈ E, h y * invMonomial ω J y = if J = ∅ then (ω - 1) ^ n else 0 := by intro J hJ have hsum_univ : ∑ y ∈ E, h y * invMonomial ω J y = ∑ y : Fin n → Bool, h y * invMonomial ω J y := by refine Finset.sum_subset (Finset.subset_univ E) (fun y _ hy => ?_) simp [hsupp y hy] rw [hsum_univ] have hsplit : (∑ y : Fin n → Bool, h y * invMonomial ω J y) = topCoeffFunctional (fun y => prodChar ω y * invMonomial ω J y) - topCoeffFunctional (fun y => eval01 P y * invMonomial ω J y) := by unfold topCoeffFunctional rw [← Finset.sum_sub_distrib] apply Finset.sum_congr rfl intro y _ simp only [h, g] ring rw [hsplit, topCoeffFunctional_prodChar_mul_invMonomial hω0 J] rcases exists_poly_invMonomial ω J with ⟨Q, hQdeg, hQeval⟩ have hPQ_eval : (fun y => eval01 P y * invMonomial ω J y) = eval01 (mul01 P Q) := by funext y; rw [eval01_mul01, hQeval] rw [hPQ_eval, topCoeffFunctional_eq_zero_of_hasDegLe (hasDegLe_mul01 hP hQdeg) (by omega), sub_zero] have hc : (ω - 1) ^ n ≠ 0 := pow_ne_zero n (sub_ne_zero.mpr hω1) have hsum0 : ∑ y ∈ E, h y = (ω - 1) ^ n := by have := hmoment ∅ (by simp) simpa [invMonomial] using this have horth : ∀ J : Finset (Fin n), 1 ≤ J.card → J.card ≤ n - d - 1 → ∑ y ∈ E, h y * invMonomial ω J y = 0 := by intro J hJ1 hJ2 have hne : J ≠ ∅ := (Finset.card_pos.mp hJ1).ne_empty have := hmoment J hJ2 simpa [hne] using this have hcard := gram_rank_lower_bound hω0 E h hc hsum0 horth (raoFamily n (n - d - 1) hn) (raoFamily_union_card_le n (n - d - 1) hn) rwa [card_raoFamily] at hcard /-- **Corollary 1A (Exactness at `d = 0` for all `n ≥ 1`):** Every constant polynomial over any field `K` disagrees with `ω ^ |y|` (`ω ≠ 0, 1`) on at least `2^{n-1}` inputs; for `ω = -1` (parity, `char K ≠ 2`), `P ≡ 1` attains exact equality `2^{n-1}`. -/ theorem gram_smolensky_deg0_exact {K : Type*} [Field K] [DecidableEq K] {n : ℕ} (hn : 1 ≤ n) {ω : K} (hω0 : ω ≠ 0) (hω1 : ω ≠ 1) (c : K) : 2 ^ (n - 1) ≤ (Finset.univ.filter (fun y : Fin n → Bool => eval01 (constPoly c) y ≠ prodChar ω y)).card := by have h := universal_gram_smolensky_bound hn hn hω0 hω1 (constPoly c) (hasDegLe_constPoly c) simpa [raoBound_pred hn] using h /-- **Corollary 1B (Exactness at `d = n - 2` for all `n ≥ 2`):** Every polynomial of degree `≤ n - 2` errs on at least `2` inputs against `ω ^ |y|` (`ω ≠ 0, 1`), strictly beating Smolensky's bound of `1`. Moreover, for every `n ≥ 2` and every `ω ≠ 0, 1`, there exists an explicit degree-`(n-2)` polynomial achieving exact error `2`. -/ theorem gram_smolensky_deg_n_sub_2_sharp {K : Type*} [Field K] [DecidableEq K] {n : ℕ} (hn : 2 ≤ n) {ω : K} (hω0 : ω ≠ 0) (hω1 : ω ≠ 1) : (∀ P : MultiPoly K n, HasDegLe P (n - 2) → 2 ≤ (Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ prodChar ω y)).card) ∧ (∃ P : MultiPoly K n, HasDegLe P (n - 2) ∧ (Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ prodChar ω y)).card = 2) := by constructor · intro P hP have h := universal_gram_smolensky_bound (by omega) (by omega) hω0 hω1 P hP have hr : n - (n - 2) - 1 = 1 := by omega rw [hr] at h have hrao : raoBound n 1 = 2 := by simp [raoBound, binomSum] omega · -- Construct `P` explicitly by subtracting a 2-point function on `y0 = all true` and `y1 = all false`! -- Wait: for `y0 = all true` and `y1 = all true except 0`? Let's pick two points `y0, y1` with -- opposite `(-1)^(n - |y|)` signs? Even better: take `a = all false` and `b = all true`? -- No! We want `topCoeff` and all `(n-1)`-coeffs of `prodChar ω - P` to match! -- Specifically, set `y0 := fun _ => true` and `y1 := fun i => decide (i ≠ ⟨0, by omega⟩)`? -- No, take `y0 = indicatorBool univ` and `y1 = indicatorBool ∅`! Check `h` on `{y0, y1}`: -- `h(y) = 1` on `y0` and `h(y) = ...` Wait: we want `invMonomial ω {j}` sum = 0 for EVERY `j`! -- On `y0 = fun _ => false`: `invMonomial ω {j} y0 = 1`. -- On `y1 = fun _ => true`: `invMonomial ω {j} y1 = ω⁻¹`. -- Solve `c0 + c1 = (ω - 1)^n` and `c0 * 1 + c1 * ω⁻¹ = 0`! -- `c0 = -c1 * ω⁻¹`, so `c1 * (1 - ω⁻¹) = (ω - 1)^n`, hence `c1 = ω * (ω - 1)^(n - 1)` and `c0 = -(ω - 1)^(n - 1)`! let y0 : Fin n → Bool := fun _ => false let y1 : Fin n → Bool := fun _ => true have hne01 : y0 ≠ y1 := by intro heq have := congrFun heq ⟨0, by omega⟩ simp [y0, y1] at this let g : (Fin n → Bool) → K := fun y => if y = y1 then ω * (ω - 1) ^ (n - 1) else if y = y0 then (-1 : K) ^ (n + 1) * (ω - 1) ^ (n - 1) else 0 let f : (Fin n → Bool) → K := fun y => prodChar ω y - g y let P : MultiPoly K n := mobiusCoeff f refine ⟨P, ?_, ?_⟩ · -- Show `P S = 0` for `|S| > n - 2`, i.e., `|S| = n` or `|S| = n - 1` intro S hS have hcard : S.card = n ∨ S.card = n - 1 := by have := Finset.card_le_univ S simp only [Fintype.card_fin] at this omega -- Write `P S = mobiusCoeff (prodChar ω) S - mobiusCoeff g S` have hlin : P S = mobiusCoeff (prodChar ω) S - mobiusCoeff g S := by simp [P, mobiusCoeff, f, mul_sub, Finset.sum_sub_distrib] rw [hlin] -- Compute `mobiusCoeff (prodChar ω) S = (ω - 1) ^ S.card` have hprod_coeff : mobiusCoeff (prodChar ω) S = (ω - 1) ^ S.card := by have hPω : eval01 (fun T : Finset (Fin n) => (ω - 1) ^ T.card) = prodChar ω := by funext y rw [eval01_eq_sum_powerset, prodChar_eq_prod] have : ∏ i : Fin n, (if y i then ω else 1) = ∏ i ∈ boolSupp y, (1 + (ω - 1)) := by rw [Finset.prod_ite, Finset.prod_const_one, mul_one] apply Finset.prod_congr rfl intro i _; ring rw [this, Finset.prod_one_add] apply Finset.sum_congr rfl intro T _; simp rw [← hPω, mobiusCoeff_eval01] rw [hprod_coeff] rcases hcard with hSn | hSn1 · -- `S = univ`: both `y0` and `y1` appear in `S.powerset` have hSuniv : S = Finset.univ := Finset.eq_univ_of_card S (by simpa using hSn) subst hSuniv unfold mobiusCoeff have hsum : ∑ T ∈ (Finset.univ : Finset (Fin n)).powerset, (-1 : K) ^ ((Finset.univ : Finset (Fin n)).card - T.card) * g (indicatorBool T) = (-1 : K) ^ 0 * g y1 + (-1 : K) ^ n * g y0 := by have hmem1 : (Finset.univ : Finset (Fin n)) ∈ (Finset.univ : Finset (Fin n)).powerset := Finset.mem_powerset_self _ have hmem0 : (∅ : Finset (Fin n)) ∈ (Finset.univ : Finset (Fin n)).powerset := Finset.empty_mem_powerset _ have hne_sets : (Finset.univ : Finset (Fin n)) ≠ ∅ := by intro h have := congrArg Finset.card h simp at this; omega have hind1 : indicatorBool (Finset.univ : Finset (Fin n)) = y1 := by funext i; simp [indicatorBool, y1] have hind0 : indicatorBool (∅ : Finset (Fin n)) = y0 := by funext i; simp [indicatorBool, y0] rw [Finset.sum_eq_add (Finset.univ : Finset (Fin n)) ∅ hne_sets] · simp [hind1, hind0] · intro T _ ⟨hT1, hT0⟩ have hy1 : indicatorBool T ≠ y1 := by intro h; apply hT1; rw [← boolSupp_indicatorBool T, h]; ext i; simp [boolSupp, y1] have hy0 : indicatorBool T ≠ y0 := by intro h; apply hT0; rw [← boolSupp_indicatorBool T, h]; ext i; simp [boolSupp, y0] simp [g, hy1, hy0] · intro h; exact absurd hmem1 h · intro h; exact absurd hmem0 h rw [hsum] have hgy1 : g y1 = ω * (ω - 1) ^ (n - 1) := by simp [g] have hgy0 : g y0 = (-1 : K) ^ (n + 1) * (ω - 1) ^ (n - 1) := by simp [g, hne01] rw [hgy1, hgy0, Finset.card_univ, Fintype.card_fin] have hpow_n : (ω - 1) ^ n = (ω - 1) * (ω - 1) ^ (n - 1) := by conv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ n), pow_succ, mul_comm] have hneg : (-1 : K) ^ n * (-1 : K) ^ (n + 1) = -1 := by rw [← pow_add, show n + (n + 1) = 2 * n + 1 by omega, pow_succ, pow_mul] norm_num rw [hpow_n] calc (ω - 1) * (ω - 1) ^ (n - 1) - ((-1 : K) ^ 0 * (ω * (ω - 1) ^ (n - 1)) + (-1 : K) ^ n * ((-1 : K) ^ (n + 1) * (ω - 1) ^ (n - 1))) = (ω - 1) * (ω - 1) ^ (n - 1) - (ω * (ω - 1) ^ (n - 1) + ((-1 : K) ^ n * (-1 : K) ^ (n + 1)) * (ω - 1) ^ (n - 1)) := by ring _ = (ω - 1) * (ω - 1) ^ (n - 1) - (ω * (ω - 1) ^ (n - 1) + (-1) * (ω - 1) ^ (n - 1)) := by rw [hneg] _ = 0 := by ring · -- `|S| = n - 1`: `y1 = indicatorBool univ` is NOT in `S.powerset`, only `y0 = indicatorBool ∅` is! unfold mobiusCoeff rw [Finset.sum_eq_single ∅] · have hgy0 : g (indicatorBool ∅) = (-1 : K) ^ (n + 1) * (ω - 1) ^ (n - 1) := by have heq : indicatorBool (∅ : Finset (Fin n)) = y0 := by funext i; simp [indicatorBool, y0] rw [heq]; simp [g, hne01] rw [hgy0, hSn1, Finset.card_empty, Nat.sub_zero] have hneg : (-1 : K) ^ (n - 1) * (-1 : K) ^ (n + 1) = 1 := by rw [← pow_add, show (n - 1) + (n + 1) = 2 * n by omega, pow_mul] norm_num calc (ω - 1) ^ (n - 1) - (-1 : K) ^ (n - 1) * ((-1 : K) ^ (n + 1) * (ω - 1) ^ (n - 1)) = (ω - 1) ^ (n - 1) - ((-1 : K) ^ (n - 1) * (-1 : K) ^ (n + 1)) * (ω - 1) ^ (n - 1) := by ring _ = (ω - 1) ^ (n - 1) - 1 * (ω - 1) ^ (n - 1) := by rw [hneg] _ = 0 := by ring · intro T hT hT0 have hy0 : indicatorBool T ≠ y0 := by intro h; apply hT0; rw [← boolSupp_indicatorBool T, h]; ext i; simp [boolSupp, y0] have hy1 : indicatorBool T ≠ y1 := by intro h have hTuniv : T = Finset.univ := by rw [← boolSupp_indicatorBool T, h]; ext i; simp [boolSupp, y1] have hle := Finset.card_le_card (Finset.mem_powerset.mp hT) rw [hTuniv, Finset.card_univ, Fintype.card_fin, hSn1] at hle omega simp [g, hy0, hy1] · intro hnot; exact absurd (Finset.empty_mem_powerset S) hnot · -- Show the error set is EXACTLY `{y0, y1}` of size 2 have hfilt : Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ prodChar ω y) = {y0, y1} := by ext y simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert, Finset.mem_singleton, P, eval01_mobiusCoeff, f] have hiff : prodChar ω y - g y ≠ prodChar ω y ↔ g y ≠ 0 := by constructor · intro h h0; apply h; simp [h0] · intro h0 heq; apply h0; exact sub_eq_self.mp heq rw [hiff] constructor · intro hg by_contra hnot push Not at hnot apply hg simp [g, hnot.1, hnot.2] · rintro (rfl | rfl) · simp only [g, hne01, ↓reduceIte] exact mul_ne_zero (pow_ne_zero _ (by norm_num)) (pow_ne_zero _ (sub_ne_zero.mpr hω1)) · simp only [g, ↓reduceIte] exact mul_ne_zero hω0 (pow_ne_zero _ (sub_ne_zero.mpr hω1)) rw [hfilt, Finset.card_pair hne01] /-- **HEADLINE THEOREM 2 (Exact Parity–Cubature Duality over Any Field of Characteristic `≠ 2`):** For any field `K` with `(2 : K) ≠ 0`, any `d < n`, and any error set `E ⊆ {0, 1}ⁿ`, there exists a multilinear polynomial `P` of degree `≤ d` agreeing with `(-1)^|y|` on `Eᶜ` **if and only if** `E` supports a `K`-valued signed `(n - d - 1)`-wise independent measure `h` (i.e., `∑_{y ∈ E} h y = 1` and `∑_{y ∈ E} h y * ∏_{i ∈ J} (-1)^{y_i} = 0` for all `1 ≤ |J| ≤ n - d - 1`). -/ theorem parity_approx_iff_signed_design {K : Type*} [Field K] {n d : ℕ} (h2 : (2 : K) ≠ 0) (hd : d < n) (E : Finset (Fin n → Bool)) : (∃ P : MultiPoly K n, HasDegLe P d ∧ ∀ y : Fin n → Bool, y ∉ E → eval01 P y = prodChar (-1 : K) y) ↔ (∃ h : (Fin n → Bool) → K, (∀ y, y ∉ E → h y = 0) ∧ (∑ y ∈ E, h y = 1) ∧ (∀ J : Finset (Fin n), 1 ≤ J.card → J.card ≤ n - d - 1 → ∑ y ∈ E, h y * (∏ i ∈ J, (if y i then (-1 : K) else 1)) = 0)) := by have hω0 : (-1 : K) ≠ 0 := by intro h; apply h2 have h1 : (1 : K) = 0 := by simpa using congrArg Neg.neg h calc (2 : K) = 1 + 1 := by ring _ = 0 := by simp [h1] have hω1 : (-1 : K) ≠ 1 := fun h => h2 (by linear_combination -h) have hpow2 : ((-1 : K) - 1) ^ n ≠ 0 := pow_ne_zero n (sub_ne_zero.mpr hω1) have hinv : (-1 : K)⁻¹ = -1 := by simp constructor · rintro ⟨P, hPdeg, hPagree⟩ let c : K := ((-1 : K) - 1) ^ n let h : (Fin n → Bool) → K := fun y => c⁻¹ * ((-1 : K) ^ (n - hammingWeight y) * (prodChar (-1 : K) y - eval01 P y)) refine ⟨h, ?_, ?_, ?_⟩ · intro y hy; simp [h, hPagree y hy] · have hsum_univ : ∑ y ∈ E, h y = ∑ y : Fin n → Bool, h y := Finset.sum_subset (Finset.subset_univ E) (fun y _ hy => by simp [h, hPagree y hy]) rw [hsum_univ] have hfac : ∑ y : Fin n → Bool, h y = c⁻¹ * (topCoeffFunctional (n := n) (prodChar (-1 : K)) - topCoeffFunctional (eval01 P)) := by unfold topCoeffFunctional rw [← Finset.sum_sub_distrib, Finset.mul_sum] apply Finset.sum_congr rfl intro y _; simp only [h]; ring rw [hfac, topCoeffFunctional_eq_zero_of_hasDegLe hPdeg hd, sub_zero] have htop := topCoeffFunctional_prodChar_mul_invMonomial (n := n) hω0 ∅ simp only [invMonomial, Finset.prod_empty, mul_one, ↓reduceIte] at htop rw [htop, inv_mul_cancel₀ hpow2] · intro J hJ1 hJ2 have hsum_univ : ∑ y ∈ E, h y * (∏ i ∈ J, (if y i then (-1 : K) else 1)) = ∑ y : Fin n → Bool, h y * invMonomial (-1 : K) J y := by have hinvJ : ∀ y, (∏ i ∈ J, (if y i then (-1 : K) else 1)) = invMonomial (-1 : K) J y := by intro y; simp [invMonomial, hinv] simp_rw [hinvJ] exact Finset.sum_subset (Finset.subset_univ E) (fun y _ hy => by simp [h, hPagree y hy]) rw [hsum_univ] have hfac : ∑ y : Fin n → Bool, h y * invMonomial (-1 : K) J y = c⁻¹ * (topCoeffFunctional (fun y => prodChar (-1 : K) y * invMonomial (-1 : K) J y) - topCoeffFunctional (fun y => eval01 P y * invMonomial (-1 : K) J y)) := by unfold topCoeffFunctional rw [← Finset.sum_sub_distrib, Finset.mul_sum] apply Finset.sum_congr rfl intro y _; simp only [h]; ring rw [hfac, topCoeffFunctional_prodChar_mul_invMonomial hω0 J, if_neg (Finset.card_pos.mp hJ1).ne_empty] rcases exists_poly_invMonomial (-1 : K) J with ⟨Q, hQdeg, hQeval⟩ have hPQ : (fun y => eval01 P y * invMonomial (-1 : K) J y) = eval01 (mul01 P Q) := by funext y; rw [eval01_mul01, hQeval] rw [hPQ, topCoeffFunctional_eq_zero_of_hasDegLe (hasDegLe_mul01 hPdeg hQdeg) (by omega)] simp · rintro ⟨h, hsupp, hsum1, horth⟩ let c : K := ((-1 : K) - 1) ^ n let g : (Fin n → Bool) → K := fun y => c * (-1 : K) ^ (n - hammingWeight y) * h y let P : MultiPoly K n := mobiusCoeff (fun y => prodChar (-1 : K) y - g y) refine ⟨P, ?_, ?_⟩ · intro S hS have hg_eq : ∀ y, g y = (2 : K) ^ n * prodChar (-1 : K) y * h y := by intro y simp only [g, c, prodChar] have h1 : ((-1 : K) - 1) ^ n = (-1 : K) ^ n * (2 : K) ^ n := by rw [← mul_pow]; congr 1; ring have h2p : (-1 : K) ^ n * (-1 : K) ^ (n - hammingWeight y) = (-1 : K) ^ hammingWeight y := by have hw : hammingWeight y ≤ n := by have := Finset.card_le_univ (boolSupp y) simpa [hammingWeight] using this rw [← pow_add, show n + (n - hammingWeight y) = 2 * (n - hammingWeight y) + hammingWeight y by omega, pow_add, pow_mul] norm_num calc ((-1 : K) - 1) ^ n * (-1 : K) ^ (n - hammingWeight y) * h y = (2 : K) ^ n * ((-1 : K) ^ n * (-1 : K) ^ (n - hammingWeight y)) * h y := by rw [h1]; ring _ = (2 : K) ^ n * (-1 : K) ^ hammingWeight y * h y := by rw [h2p] let χ : Finset (Fin n) → (Fin n → Bool) → K := fun I y => ∏ i ∈ I, (if y i then (-1 : K) else 1) have hχ_orth : ∀ A B : Finset (Fin n), ∑ y : Fin n → Bool, χ A y * χ B y = if A = B then (2 : K) ^ n else 0 := by intro A B have hmul : ∀ y, χ A y * χ B y = χ (symmDiff A B) y := by intro y unfold χ have hA : (∏ i ∈ A, (if y i then (-1 : K) else 1)) = (∏ i ∈ A \ B, (if y i then (-1 : K) else 1)) * (∏ i ∈ A ∩ B, (if y i then (-1 : K) else 1)) := by conv_lhs => rw [show A = (A \ B) ∪ (A ∩ B) from (Finset.sdiff_union_inter A B).symm] exact Finset.prod_union (Finset.disjoint_left.mpr (fun i h1 h2 => (Finset.mem_sdiff.mp h1).2 (Finset.mem_inter.mp h2).2)) have hB : (∏ i ∈ B, (if y i then (-1 : K) else 1)) = (∏ i ∈ B \ A, (if y i then (-1 : K) else 1)) * (∏ i ∈ A ∩ B, (if y i then (-1 : K) else 1)) := by conv_lhs => rw [show B = (B \ A) ∪ (A ∩ B) from by rw [Finset.inter_comm]; exact (Finset.sdiff_union_inter B A).symm] exact Finset.prod_union (Finset.disjoint_left.mpr (fun i h1 h2 => (Finset.mem_sdiff.mp h1).2 (Finset.mem_inter.mp h2).1)) rw [hA, hB] have hsq : (∏ i ∈ A ∩ B, (if y i then (-1 : K) else 1)) * (∏ i ∈ A ∩ B, (if y i then (-1 : K) else 1)) = 1 := by rw [← Finset.prod_mul_distrib] exact Finset.prod_eq_one (fun i _ => by cases y i <;> norm_num) have hsym : symmDiff A B = (A \ B) ∪ (B \ A) := rfl have hdisjAB : Disjoint (A \ B) (B \ A) := Finset.disjoint_left.mpr (fun i h1 h2 => (Finset.mem_sdiff.mp h1).2 (Finset.mem_sdiff.mp h2).1) rw [hsym, Finset.prod_union hdisjAB] calc _ = (∏ i ∈ A \ B, (if y i then (-1 : K) else 1)) * (∏ i ∈ B \ A, (if y i then (-1 : K) else 1)) * ((∏ i ∈ A ∩ B, (if y i then (-1 : K) else 1)) * (∏ i ∈ A ∩ B, (if y i then (-1 : K) else 1))) := by ring _ = _ := by rw [hsq, mul_one] simp_rw [hmul] by_cases hAB : A = B · subst hAB simp only [symmDiff_self, Finset.bot_eq_empty, ↓reduceIte, χ, Finset.prod_empty, Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] · rw [if_neg hAB] have hne : (symmDiff A B).Nonempty := Finset.nonempty_iff_ne_empty.mpr (fun h => hAB (symmDiff_eq_bot.mp h)) rcases hne with ⟨i0, hi0⟩ let flip : (Fin n → Bool) → (Fin n → Bool) := fun y => Function.update y i0 (!y i0) have hflip_inv : ∀ y, flip (flip y) = y := by intro y; funext i by_cases hi : i = i0 · subst hi; simp [flip] · simp [flip, hi] have hflip_neg : ∀ y, χ (symmDiff A B) (flip y) = -χ (symmDiff A B) y := by intro y unfold χ rw [← Finset.mul_prod_erase _ _ hi0, ← Finset.mul_prod_erase _ _ hi0] have hrest : ∏ i ∈ (symmDiff A B).erase i0, (if flip y i then (-1 : K) else 1) = ∏ i ∈ (symmDiff A B).erase i0, (if y i then (-1 : K) else 1) := by apply Finset.prod_congr rfl intro i hi simp [flip, (Finset.mem_erase.mp hi).1] rw [hrest] have h0 : (if flip y i0 then (-1 : K) else 1) = -(if y i0 then (-1 : K) else 1) := by simp only [flip, Function.update_self] cases y i0 <;> norm_num rw [h0, neg_mul] have hsum_eq : ∑ y : Fin n → Bool, χ (symmDiff A B) y = -(∑ y : Fin n → Bool, χ (symmDiff A B) y) := by conv_lhs => rw [← Equiv.sum_comp (Equiv.ofBijective flip (Function.Involutive.bijective hflip_inv))] simp [Equiv.ofBijective_apply, hflip_neg, Finset.sum_neg_distrib] have h2sum : (2 : K) * ∑ y : Fin n → Bool, χ (symmDiff A B) y = 0 := by calc (2 : K) * ∑ y, χ (symmDiff A B) y = (∑ y, χ (symmDiff A B) y) + (∑ y, χ (symmDiff A B) y) := by ring _ = 0 := by conv_rhs => rw [← add_neg_cancel (∑ y, χ (symmDiff A B) y)] congr 1 exact (mul_eq_zero.mp h2sum).resolve_left h2 -- Represent `f y = prodChar (-1) y - g y` as a linear combination of `χ I` with `|I| ≤ d`! let fhat : Finset (Fin n) → K := fun I => ((2 : K) ^ n)⁻¹ * ∑ z : Fin n → Bool, (prodChar (-1 : K) z - g z) * χ I z have hrecon : ∀ y : Fin n → Bool, prodChar (-1 : K) y - g y = ∑ I : Finset (Fin n), fhat I * χ I y := by intro y -- Expand `∑ I, fhat I * χ I y` and swap sums have hswap : ∑ I : Finset (Fin n), fhat I * χ I y = ((2 : K) ^ n)⁻¹ * ∑ z : Fin n → Bool, (prodChar (-1 : K) z - g z) * ∑ I : Finset (Fin n), χ I z * χ I y := by simp only [fhat, mul_assoc, ← Finset.mul_sum] congr 1 simp_rw [Finset.sum_mul] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro z _ rw [Finset.mul_sum] apply Finset.sum_congr rfl intro I _; ring rw [hswap] have hdelta : ∀ z : Fin n → Bool, ∑ I : Finset (Fin n), χ I z * χ I y = if z = y then (2 : K) ^ n else 0 := by intro z have hprod_I : ∑ I : Finset (Fin n), χ I z * χ I y = ∏ i : Fin n, (1 + (if z i then (-1 : K) else 1) * (if y i then (-1 : K) else 1)) := by rw [Finset.prod_one_add] have hpow : (Finset.univ : Finset (Fin n)).powerset = Finset.univ := by ext I; simp rw [hpow] apply Finset.sum_congr rfl intro I _ unfold χ rw [Finset.prod_mul_distrib] rw [hprod_I] by_cases hzy : z = y · subst hzy rw [if_pos rfl] have hterm2 : ∀ i : Fin n, (1 : K) + (if z i then (-1 : K) else 1) * (if z i then (-1 : K) else 1) = 2 := by intro i; cases z i <;> norm_num rw [Finset.prod_congr rfl (fun i _ => hterm2 i), Finset.prod_const, Finset.card_univ, Fintype.card_fin] · rw [if_neg hzy] have hne : ∃ i, z i ≠ y i := by by_contra hall; push Not at hall; exact hzy (funext hall) rcases hne with ⟨i0, hi0⟩ apply Finset.prod_eq_zero (Finset.mem_univ i0) cases hz0 : z i0 <;> cases hy0 : y i0 <;> simp_all simp_rw [hdelta] rw [Finset.sum_eq_single y] · simp only [↓reduceIte] rw [mul_comm (prodChar (-1 : K) y - g y), ← mul_assoc, inv_mul_cancel₀ (pow_ne_zero n h2), one_mul] · intro z _ hne; simp [hne] · intro hnot; exact absurd (Finset.mem_univ y) hnot -- Show `fhat I = 0` for all `|I| > d`! have hfhat_zero : ∀ I : Finset (Fin n), d < I.card → fhat I = 0 := by intro I hI unfold fhat suffices h0 : ∑ z : Fin n → Bool, (prodChar (-1 : K) z - g z) * χ I z = 0 by rw [h0, mul_zero] have hsplit : ∑ z : Fin n → Bool, (prodChar (-1 : K) z - g z) * χ I z = (∑ z, χ Finset.univ z * χ I z) - (2 : K) ^ n * (∑ z, h z * (χ Finset.univ z * χ I z)) := by rw [Finset.mul_sum, ← Finset.sum_sub_distrib] apply Finset.sum_congr rfl intro z _ have hp : prodChar (-1 : K) z = χ Finset.univ z := prodChar_eq_prod (-1 : K) z rw [hg_eq z, hp] ring rw [hsplit, hχ_orth Finset.univ I] have hprod_compl : ∀ z, χ Finset.univ z * χ I z = χ Iᶜ z := by intro z unfold χ have hunion : Iᶜ ∪ I = Finset.univ := by ext i; simp [em'] have h1 : (∏ i : Fin n, (if z i then (-1 : K) else 1)) = (∏ i ∈ Iᶜ, (if z i then (-1 : K) else 1)) * (∏ i ∈ I, (if z i then (-1 : K) else 1)) := by rw [← Finset.prod_union disjoint_compl_left, hunion] rw [h1, mul_assoc] have hsq : (∏ i ∈ I, (if z i then (-1 : K) else 1)) * (∏ i ∈ I, (if z i then (-1 : K) else 1)) = 1 := by rw [← Finset.prod_mul_distrib] exact Finset.prod_eq_one (fun i _ => by cases z i <;> norm_num) rw [hsq, mul_one] simp_rw [hprod_compl] have hsumE : ∑ z : Fin n → Bool, h z * χ Iᶜ z = ∑ z ∈ E, h z * χ Iᶜ z := (Finset.sum_subset (Finset.subset_univ E) (fun z _ hz => by simp [hsupp z hz])).symm rw [hsumE] by_cases hIu : Finset.univ = I · subst hIu simp [hsum1, χ] · rw [if_neg hIu, zero_sub, neg_eq_zero] have hIc_ne : Iᶜ.Nonempty := by rw [Finset.nonempty_iff_ne_empty] intro hemp apply hIu ext i simp only [Finset.mem_univ, true_iff] by_contra hi have : i ∈ Iᶜ := Finset.mem_compl.mpr hi rw [hemp] at this exact Finset.notMem_empty i this have hIc1 : 1 ≤ Iᶜ.card := Finset.card_pos.mpr hIc_ne have hIc2 : Iᶜ.card ≤ n - d - 1 := by rw [Finset.card_compl, Fintype.card_fin]; omega rw [horth Iᶜ hIc1 hIc2, mul_zero] -- Therefore `prodChar (-1) - g` equals `eval01 Q` for a polynomial `Q` of degree `≤ d`! have hexQ : ∃ Q : MultiPoly K n, HasDegLe Q d ∧ ∀ y, eval01 Q y = prodChar (-1 : K) y - g y := by have hχ_poly : ∀ I : Finset (Fin n), ∃ Q_I : MultiPoly K n, HasDegLe Q_I I.card ∧ ∀ y, eval01 Q_I y = χ I y := by intro I rcases exists_poly_invMonomial (-1 : K) I with ⟨Q_I, hdeg, heval⟩ refine ⟨Q_I, hdeg, fun y => ?_⟩ rw [heval y] simp [invMonomial, χ, hinv] choose Q_I hQdeg hQeval using hχ_poly let Q : MultiPoly K n := ∑ I ∈ Finset.univ.filter (fun I : Finset (Fin n) => I.card ≤ d), fhat I • Q_I I refine ⟨Q, ?_, ?_⟩ · intro U hU simp only [Q, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] apply Finset.sum_eq_zero intro I hI simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hI rw [hQdeg I U (lt_of_le_of_lt hI hU), mul_zero] · intro y rw [hrecon y] have hQsum : eval01 Q y = ∑ I ∈ Finset.univ.filter (fun I : Finset (Fin n) => I.card ≤ d), fhat I * eval01 (Q_I I) y := by simp only [Q, eval01_eq_sum_powerset, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro I _ rw [Finset.mul_sum] rw [hQsum] simp_rw [hQeval] refine Finset.sum_subset (Finset.filter_subset _ _) (fun I _ hnot => ?_) simp only [Finset.mem_filter, Finset.mem_univ, true_and, not_le] at hnot rw [hfhat_zero I hnot, zero_mul] rcases hexQ with ⟨Q, hQdeg, hQeval⟩ have hPQ : P = Q := by funext U simp only [P] have hfun : (fun y => prodChar (-1 : K) y - g y) = eval01 Q := funext (fun y => (hQeval y).symm) rw [hfun, mobiusCoeff_eval01] rw [hPQ] exact hQdeg S hS · intro y hy simp only [P, eval01_mobiusCoeff, g, hsupp y hy, mul_zero, sub_zero] /-- Hamming distance between two Boolean vectors. -/ def hammingDist {n : ℕ} (x y : Fin n → Bool) : ℕ := (Finset.univ.filter (fun i : Fin n => x i ≠ y i)).card /-- Hamming triangle-parity identity: for any three Boolean vectors `x, y, z`, `d_H(x, y) + d_H(y, z) + d_H(z, x)` is always even! -/ lemma hammingDist_triangle_even {n : ℕ} (x y z : Fin n → Bool) : Even (hammingDist x y + hammingDist y z + hammingDist z x) := by have hsum : hammingDist x y + hammingDist y z + hammingDist z x = ∑ i : Fin n, ((if x i ≠ y i then 1 else 0) + (if y i ≠ z i then 1 else 0) + (if z i ≠ x i then 1 else 0)) := by simp only [hammingDist, Finset.card_filter, ← Finset.sum_add_distrib] rw [hsum] have heven_each : ∀ i : Fin n, Even ((if x i ≠ y i then 1 else 0) + (if y i ≠ z i then 1 else 0) + (if z i ≠ x i then 1 else 0)) := by intro i cases x i <;> cases y i <;> cases z i <;> decide exact Finset.even_sum _ (fun i _ => heven_each i) /-- **HEADLINE THEOREM 3 (Hadamard `r = 2` Tightness Obstruction for Parity at `d = n - 3`):** For every `n ≥ 3` with `n % 4 ≠ 3`, and every field `K` of characteristic `0` or odd prime `p ≥ n` (expressed as `(2 : K) ≠ 0` and `(m : K) ≠ 0` for all `1 ≤ m < n`), every multilinear polynomial `P` of degree `≤ n - 3` approximating `PARITY_n` errs on at least `n + 2` points, strictly beating the Rao–Gram lower bound `n + 1`! -/ theorem parity_deg_n_sub_3_hadamard_obstruction {K : Type*} [Field K] [DecidableEq K] {n : ℕ} (hn : 3 ≤ n) (hmod : n % 4 ≠ 3) (h2 : (2 : K) ≠ 0) (hchar : ∀ m : ℕ, 1 ≤ m → m < n → (m : K) ≠ 0) (P : MultiPoly K n) (hP : HasDegLe P (n - 3)) : n + 2 ≤ (Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ prodChar (-1 : K) y)).card := by let E := Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ prodChar (-1 : K) y) have hω0 : (-1 : K) ≠ 0 := by intro h; apply h2 have h1 : (1 : K) = 0 := by simpa using congrArg Neg.neg h calc (2 : K) = 1 + 1 := by ring _ = 0 := by simp [h1] have hω1 : (-1 : K) ≠ 1 := fun h => h2 (by linear_combination -h) have hlb : n + 1 ≤ E.card := by have h1 := universal_gram_smolensky_bound (by omega) (by omega) hω0 hω1 P hP have hr : n - (n - 3) - 1 = 2 := by omega rw [hr] at h1 have hrao : raoBound n 2 = n + 1 := by simp [raoBound, binomSum, Finset.sum_range_succ, Nat.choose_one_right, add_comm] rw [hrao] at h1 exact h1 change n + 2 ≤ E.card by_contra hlt push Not at hlt have hcardE : E.card = n + 1 := by omega have hagree : ∀ y : Fin n → Bool, y ∉ E → eval01 P y = prodChar (-1 : K) y := by intro y hy simp only [E, Finset.mem_filter, Finset.mem_univ, true_and, not_not] at hy exact hy rcases (parity_approx_iff_signed_design h2 (by omega) E).mp ⟨P, hP, hagree⟩ with ⟨h, _, hsum1, horth⟩ let V : (Fin n → Bool) → Option (Fin n) → K := fun y k => match k with | none => 1 | some i => if y i then -1 else 1 let A : (Option (Fin n) → K) →ₗ[K] (E → K) := { toFun := fun a y => ∑ k : Option (Fin n), V y.1 k * a k map_add' := fun a b => by ext y; simp [mul_add, Finset.sum_add_distrib] map_smul' := fun c a => by ext y; simp only [Pi.smul_apply, smul_eq_mul, RingHom.id_apply, Finset.mul_sum] apply Finset.sum_congr rfl; intro k _; ring } let B : (E → K) →ₗ[K] (Option (Fin n) → K) := { toFun := fun b k => ∑ y : E, h y.1 * V y.1 k * b y map_add' := fun a b => by ext k; simp [mul_add, Finset.sum_add_distrib] map_smul' := fun c a => by ext k; simp only [Pi.smul_apply, smul_eq_mul, RingHom.id_apply, Finset.mul_sum] apply Finset.sum_congr rfl; intro y _; ring } have hBA : B.comp A = LinearMap.id := by apply LinearMap.ext intro a funext k2 simp only [LinearMap.comp_apply, LinearMap.id_apply, B, A, LinearMap.coe_mk, AddHom.coe_mk] have hswap : ∑ y : E, h y.1 * V y.1 k2 * (∑ k : Option (Fin n), V y.1 k * a k) = ∑ k : Option (Fin n), (∑ y ∈ E, h y * (V y k2 * V y k)) * a k := by simp_rw [Finset.mul_sum] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro k _ rw [Finset.sum_mul, ← Finset.sum_attach E (fun y => h y * (V y k2 * V y k) * a k)] apply Finset.sum_congr rfl intro y _; ring rw [hswap] have horthV : ∀ k : Option (Fin n), ∑ y ∈ E, h y * (V y k2 * V y k) = if k = k2 then 1 else 0 := by intro k cases k2 with | none => cases k with | none => simpa [V] using hsum1 | some i => simp only [V, one_mul, reduceCtorEq, ↓reduceIte] have h1 := horth {i} (by simp) (by simp; omega) simpa using h1 | some i => cases k with | none => simp only [V, mul_one, reduceCtorEq, ↓reduceIte] have h1 := horth {i} (by simp) (by simp; omega) simpa using h1 | some j => by_cases hij : j = i · subst hij simp only [V, ↓reduceIte] have hsq : ∀ y : Fin n → Bool, (if y j then (-1 : K) else 1) * (if y j then (-1 : K) else 1) = 1 := by intro y; cases y j <;> norm_num simpa [hsq] using hsum1 · simp only [V, Option.some.injEq, hij, ↓reduceIte] have h2o := horth {i, j} (by rw [Finset.card_pair (Ne.symm hij)]; omega) (by rw [Finset.card_pair (Ne.symm hij)]; omega) have hpair : ∀ y : Fin n → Bool, ∏ u ∈ ({i, j} : Finset (Fin n)), (if y u then (-1 : K) else 1) = (if y i then (-1 : K) else 1) * (if y j then (-1 : K) else 1) := by intro y; rw [Finset.prod_pair (Ne.symm hij)] simpa [hpair] using h2o simp_rw [horthV, ite_mul, one_mul, zero_mul] rw [Finset.sum_eq_single k2] · simp · intro k _ hne; simp [hne] · intro hnot; exact absurd (Finset.mem_univ k2) hnot have hfin_eq : Module.finrank K (Option (Fin n) → K) = Module.finrank K (E → K) := by simp [Fintype.card_coe, hcardE] have hA_inj : Function.Injective A := Function.LeftInverse.injective (fun x => by have := congrArg (fun f => f x) hBA; simpa using this) have hA_surj : Function.Surjective A := (LinearMap.injective_iff_surjective_of_finrank_eq_finrank hfin_eq).mp hA_inj have hAB : ∀ b : E → K, A (B b) = b := by intro b rcases hA_surj b with ⟨a, rfl⟩ have hba : B (A a) = a := by have := congrArg (fun f => f a) hBA; simpa using this rw [hba] have hpair_dot : ∀ y ∈ E, ∀ z ∈ E, h y * (∑ k : Option (Fin n), V z k * V y k) = if z = y then 1 else 0 := by intro y hy z hz have hev := congrFun (hAB (Pi.single ⟨y, hy⟩ (1 : K))) ⟨z, hz⟩ simp only [A, B, LinearMap.coe_mk, AddHom.coe_mk, Pi.single_apply] at hev have hinner : ∀ k : Option (Fin n), ∑ u : E, h u.1 * V u.1 k * (if u = ⟨y, hy⟩ then (1 : K) else 0) = h y * V y k := by intro k rw [Finset.sum_eq_single ⟨y, hy⟩] · simp · intro u _ hne; simp [hne] · intro hnot; exact absurd (Finset.mem_univ _) hnot simp_rw [hinner] at hev have hfac : ∑ k : Option (Fin n), V z k * (h y * V y k) = h y * ∑ k : Option (Fin n), V z k * V y k := by rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro k _; ring rw [hfac] at hev by_cases hzy : z = y · subst hzy; simpa using hev · have hsubne : (⟨z, hz⟩ : E) ≠ ⟨y, hy⟩ := fun h => hzy (congrArg Subtype.val h) simpa [hzy, hsubne] using hev have hdist_eq : ∀ y ∈ E, ∀ z ∈ E, y ≠ z → 2 * hammingDist y z = n + 1 := by intro y hy z hz hyz have hhy : h y ≠ 0 := by have hself := hpair_dot y hy y hy simp only [↓reduceIte] at hself intro h0; rw [h0, zero_mul] at hself; exact zero_ne_one hself have hdot0 : ∑ k : Option (Fin n), V z k * V y k = 0 := by have h1 := hpair_dot y hy z hz rw [if_neg (Ne.symm hyz)] at h1 exact (mul_eq_zero.mp h1).resolve_left hhy have hdot_val : ∑ k : Option (Fin n), V z k * V y k = ((n + 1 : ℕ) : K) - 2 * (hammingDist y z : K) := by rw [Fintype.sum_option] simp only [V, mul_one] have hterm : ∀ i : Fin n, (if z i then (-1 : K) else 1) * (if y i then (-1 : K) else 1) = 1 - 2 * (if y i ≠ z i then (1 : K) else 0) := by intro i; cases z i <;> cases y i <;> norm_num simp_rw [hterm, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one, ← Finset.mul_sum] have hfilt : ∑ i : Fin n, (if y i ≠ z i then (1 : K) else 0) = (hammingDist y z : K) := by simp only [hammingDist, Finset.card_filter, Nat.cast_sum, Nat.cast_ite, Nat.cast_one, Nat.cast_zero] rw [hfilt, Nat.cast_add, Nat.cast_one] ring rw [hdot_val] at hdot0 have hpos : 1 ≤ hammingDist y z := by unfold hammingDist rw [Finset.one_le_card] by_contra hemp rw [Finset.not_nonempty_iff_eq_empty] at hemp apply hyz funext i by_contra hne have hi : i ∈ Finset.univ.filter (fun i : Fin n => y i ≠ z i) := by simp [hne] rw [hemp] at hi exact Finset.notMem_empty i hi have hle : hammingDist y z ≤ n := by have := Finset.card_le_univ (Finset.univ.filter (fun i : Fin n => y i ≠ z i)) simpa [hammingDist] using this by_cases hlt_d : 2 * hammingDist y z < n + 1 · exfalso set m := n + 1 - 2 * hammingDist y z have hm1 : 1 ≤ m := by omega have hm2 : m < n := by omega apply hchar m hm1 hm2 have hnat : n + 1 = m + 2 * hammingDist y z := by omega have hcast : ((n + 1 : ℕ) : K) = (m : K) + 2 * (hammingDist y z : K) := by have := congrArg (Nat.cast : ℕ → K) hnat simpa [Nat.cast_add, Nat.cast_mul] using this rw [hcast] at hdot0 linear_combination hdot0 · by_cases hgt_d : n + 1 < 2 * hammingDist y z · exfalso set m := 2 * hammingDist y z - (n + 1) have hm1 : 1 ≤ m := by omega have hm2 : m < n := by omega apply hchar m hm1 hm2 have hnat : 2 * hammingDist y z = m + (n + 1) := by omega have hcast : (2 : K) * (hammingDist y z : K) = (m : K) + ((n + 1 : ℕ) : K) := by have := congrArg (Nat.cast : ℕ → K) hnat simpa [Nat.cast_add, Nat.cast_mul] using this rw [hcast] at hdot0 linear_combination -hdot0 · omega have hge3 : 2 < E.card := by omega rcases Finset.two_lt_card.mp hge3 with ⟨x, hx, y, hy, z, hz, hxy, hxz, hyz⟩ have h1 := hdist_eq x hx y hy hxy have h2d := hdist_eq y hy z hz hyz have h3 := hdist_eq z hz x hx (Ne.symm hxz) rcases hammingDist_triangle_even x y z with ⟨k, hk⟩ omega /-! ### Explicit 4-Element Field `𝔽₄` and Linear-Degree Lift for Boolean `MOD₃` over `𝔽₂` -/ /-- Explicit 4-element finite field `𝔽₄ = 𝔽₂[ω] / (ω² + ω + 1)`, represented as pairs `(a, b) : ZMod 2 × ZMod 2` corresponding to `a + b·ω`. -/ @[ext] structure F4 where re : ZMod 2 im : ZMod 2 deriving DecidableEq namespace F4 def zero : F4 := ⟨0, 0⟩ def one : F4 := ⟨1, 0⟩ def omega : F4 := ⟨0, 1⟩ def omega2 : F4 := ⟨1, 1⟩ def add (x y : F4) : F4 := ⟨x.re + y.re, x.im + y.im⟩ def mul (x y : F4) : F4 := ⟨x.re * y.re + x.im * y.im, x.re * y.im + x.im * y.re + x.im * y.im⟩ def inv (x : F4) : F4 := if x = zero then zero else if x = one then one else if x = omega then omega2 else omega instance : Zero F4 := ⟨zero⟩ instance : One F4 := ⟨one⟩ instance : Add F4 := ⟨add⟩ instance : Neg F4 := ⟨id⟩ instance : Sub F4 := ⟨add⟩ instance : Mul F4 := ⟨mul⟩ instance : Inv F4 := ⟨inv⟩ lemma eq_cases (x : F4) : x = zero ∨ x = one ∨ x = omega ∨ x = omega2 := by rcases x with ⟨a, b⟩ fin_cases a <;> fin_cases b <;> decide instance : Fintype F4 where elems := {zero, one, omega, omega2} complete x := by rcases eq_cases x with rfl | rfl | rfl | rfl <;> simp instance : Field F4 where add_assoc a b c := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> rcases eq_cases b with rfl | rfl | rfl | rfl <;> rcases eq_cases c with rfl | rfl | rfl | rfl <;> decide zero_add a := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> decide add_zero a := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> decide nsmul := nsmulRec zsmul := zsmulRec neg_add_cancel a := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> decide sub_eq_add_neg a b := rfl add_comm a b := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> rcases eq_cases b with rfl | rfl | rfl | rfl <;> decide mul_assoc a b c := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> rcases eq_cases b with rfl | rfl | rfl | rfl <;> rcases eq_cases c with rfl | rfl | rfl | rfl <;> decide one_mul a := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> decide mul_one a := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> decide left_distrib a b c := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> rcases eq_cases b with rfl | rfl | rfl | rfl <;> rcases eq_cases c with rfl | rfl | rfl | rfl <;> decide right_distrib a b c := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> rcases eq_cases b with rfl | rfl | rfl | rfl <;> rcases eq_cases c with rfl | rfl | rfl | rfl <;> decide zero_mul a := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> decide mul_zero a := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> decide mul_comm a b := by rcases eq_cases a with rfl | rfl | rfl | rfl <;> rcases eq_cases b with rfl | rfl | rfl | rfl <;> decide exists_pair_ne := ⟨zero, one, by decide⟩ mul_inv_cancel a ha := by rcases eq_cases a with rfl | rfl | rfl | rfl · exact absurd rfl ha · decide · decide · decide inv_zero := rfl nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl /-- Canonical ring embedding `𝔽₂ ↪ 𝔽₄`. -/ def ofZMod2 (a : ZMod 2) : F4 := ⟨a, 0⟩ lemma ofZMod2_zero : ofZMod2 0 = 0 := rfl lemma ofZMod2_one : ofZMod2 1 = 1 := rfl lemma ofZMod2_add (a b : ZMod 2) : ofZMod2 (a + b) = ofZMod2 a + ofZMod2 b := by fin_cases a <;> fin_cases b <;> decide lemma ofZMod2_mul (a b : ZMod 2) : ofZMod2 (a * b) = ofZMod2 a * ofZMod2 b := by fin_cases a <;> fin_cases b <;> decide lemma omega_ne_zero : omega ≠ (0 : F4) := by decide lemma omega_ne_one : omega ≠ (1 : F4) := by decide lemma omega_cube : omega ^ 3 = (1 : F4) := by decide lemma omega_pow_mod3 (k : ℕ) : omega ^ k = if k % 3 = 0 then (1 : F4) else if k % 3 = 1 then omega else omega2 := by have hdiv : k = 3 * (k / 3) + k % 3 := (Nat.div_add_mod k 3).symm conv_lhs => rw [hdiv, pow_add, pow_mul, omega_cube, one_pow, one_mul] have hlt : k % 3 < 3 := Nat.mod_lt k (by omega) interval_cases (k % 3) <;> decide end F4 /-- Boolean `MOD₃` function: outputs `1 : ZMod 2` iff `|y| % 3 ≠ 0`, and `0` iff `|y| % 3 = 0`. -/ def mod3Bool {n : ℕ} (y : Fin n → Bool) : ZMod 2 := if hammingWeight y % 3 = 0 then 0 else 1 /-- Lift a `MultiPoly (ZMod 2) n` to `MultiPoly F4 n`. -/ def liftPolyF4 {n : ℕ} (Q : MultiPoly (ZMod 2) n) : MultiPoly F4 n := fun S => F4.ofZMod2 (Q S) lemma eval01_liftPolyF4 {n : ℕ} (Q : MultiPoly (ZMod 2) n) (y : Fin n → Bool) : eval01 (liftPolyF4 Q) y = F4.ofZMod2 (eval01 Q y) := by simp only [eval01_eq_sum_powerset, liftPolyF4] induction (boolSupp y).powerset using Finset.induction_on with | empty => simp [F4.ofZMod2_zero] | @insert a s ha ih => rw [Finset.sum_insert ha, Finset.sum_insert ha, F4.ofZMod2_add, ih] lemma hasDegLe_liftPolyF4 {n d : ℕ} {Q : MultiPoly (ZMod 2) n} (hQ : HasDegLe Q d) : HasDegLe (liftPolyF4 Q) d := fun S hS => by simp [liftPolyF4, hQ S hS, F4.ofZMod2_zero] /-- Coordinate-flip substitution `y ↦ y ⊕ e_i₀` on multilinear polynomials over `K`: replaces `x_{i₀}` with `1 - x_{i₀}`, preserving degree `≤ d`! -/ def flipVarPoly {K : Type*} [CommRing K] {n : ℕ} (i0 : Fin n) (Q : MultiPoly K n) : MultiPoly K n := fun S => if i0 ∈ S then -Q S else Q S + Q (insert i0 S) lemma hasDegLe_flipVarPoly {K : Type*} [CommRing K] {n d : ℕ} (i0 : Fin n) {Q : MultiPoly K n} (hQ : HasDegLe Q d) : HasDegLe (flipVarPoly i0 Q) d := by intro S hS unfold flipVarPoly split_ifs with hmem · simp [hQ S hS] · have h1 : Q S = 0 := hQ S hS have h2 : Q (insert i0 S) = 0 := hQ _ (by rw [Finset.card_insert_of_notMem hmem]; omega) simp [h1, h2] lemma eval01_flipVarPoly {K : Type*} [CommRing K] {n : ℕ} (i0 : Fin n) (Q : MultiPoly K n) (y : Fin n → Bool) : eval01 (flipVarPoly i0 Q) y = eval01 Q (Function.update y i0 (!y i0)) := by simp only [eval01_eq_sum_powerset, flipVarPoly] let y' := Function.update y i0 (!y i0) by_cases hy : y i0 = true · -- `i0 ∈ boolSupp y`, `boolSupp y' = (boolSupp y).erase i0` have hmem : i0 ∈ boolSupp y := by simp [boolSupp, hy] have hsupp' : boolSupp y' = (boolSupp y).erase i0 := by ext i; by_cases hi : i = i0 · subst hi; simp [boolSupp, y', hy] · simp [boolSupp, y', hi] rw [hsupp'] set U := (boolSupp y).erase i0 have hi0U : i0 ∉ U := Finset.notMem_erase i0 _ have hby : boolSupp y = insert i0 U := (Finset.insert_erase hmem).symm rw [hby, Finset.powerset_insert, Finset.sum_union] · have himg : ∑ S ∈ U.powerset.image (insert i0), (if i0 ∈ S then -Q S else Q S + Q (insert i0 S)) = ∑ S ∈ U.powerset, -Q (insert i0 S) := by rw [Finset.sum_image] · apply Finset.sum_congr rfl; intro S _; simp · intro S1 hS1 S2 hS2 heq have h1 : i0 ∉ S1 := fun h => hi0U (Finset.mem_powerset.mp hS1 h) have h2 : i0 ∉ S2 := fun h => hi0U (Finset.mem_powerset.mp hS2 h) have := congrArg (fun T => T.erase i0) heq simpa [Finset.erase_insert h1, Finset.erase_insert h2] using this have hU : ∑ S ∈ U.powerset, (if i0 ∈ S then -Q S else Q S + Q (insert i0 S)) = ∑ S ∈ U.powerset, (Q S + Q (insert i0 S)) := by apply Finset.sum_congr rfl intro S hS have hnot : i0 ∉ S := fun h => hi0U (Finset.mem_powerset.mp hS h) simp [hnot] rw [himg, hU, ← Finset.sum_add_distrib] apply Finset.sum_congr rfl; intro S _; ring · rw [Finset.disjoint_left] intro S hS1 hS2 rw [Finset.mem_image] at hS2 rcases hS2 with ⟨T, _, rfl⟩ exact hi0U (Finset.mem_powerset.mp hS1 (Finset.mem_insert_self i0 T)) · -- `y i0 = false`, so `i0 ∉ boolSupp y` and `boolSupp y' = insert i0 (boolSupp y)` have hyf : y i0 = false := by cases h : y i0 <;> simp_all have hnot : i0 ∉ boolSupp y := by simp [boolSupp, hyf] have hsupp' : boolSupp y' = insert i0 (boolSupp y) := by ext i; by_cases hi : i = i0 · subst hi; simp [boolSupp, y', hyf] · simp [boolSupp, y', hi] rw [hsupp', Finset.powerset_insert, Finset.sum_union] · have himg : ∑ S ∈ (boolSupp y).powerset.image (insert i0), Q S = ∑ S ∈ (boolSupp y).powerset, Q (insert i0 S) := by rw [Finset.sum_image] intro S1 hS1 S2 hS2 heq have h1 : i0 ∉ S1 := fun h => hnot (Finset.mem_powerset.mp hS1 h) have h2 : i0 ∉ S2 := fun h => hnot (Finset.mem_powerset.mp hS2 h) have := congrArg (fun T => T.erase i0) heq simpa [Finset.erase_insert h1, Finset.erase_insert h2] using this rw [himg, ← Finset.sum_add_distrib] apply Finset.sum_congr rfl intro S hS have hnotS : i0 ∉ S := fun h => hnot (Finset.mem_powerset.mp hS h) simp [hnotS] · rw [Finset.disjoint_left] intro S hS1 hS2 rw [Finset.mem_image] at hS2 rcases hS2 with ⟨T, _, rfl⟩ exact hnot (Finset.mem_powerset.mp hS1 (Finset.mem_insert_self i0 T)) /-- **HEADLINE THEOREM 4 (Linear-Degree `𝔽₄`-Lift Sharp Bound for Boolean `MOD₃` over `𝔽₂`):** For every `n ≥ 2`, every `d` with `d + 1 < n`, and every `𝔽₂`-multilinear polynomial `Q` of degree `≤ d`, the error count against `MOD₃ : {0,1}ⁿ → 𝔽₂` satisfies: `raoBound n (n - d - 2) ≤ 2 * |{y | eval01 Q y ≠ mod3Bool y}|`. -/ theorem mod3_over_F2_sharp_error_bound {n d : ℕ} (hn : 1 ≤ n) (hd : d + 1 < n) (Q : MultiPoly (ZMod 2) n) (hQ : HasDegLe Q d) : raoBound n (n - d - 2) ≤ 2 * (Finset.univ.filter (fun y : Fin n → Bool => eval01 Q y ≠ mod3Bool y)).card := by let i0 : Fin n := ⟨0, hn⟩ let Qf : MultiPoly F4 n := liftPolyF4 Q let Qflip : MultiPoly F4 n := flipVarPoly i0 Qf let Lin : MultiPoly F4 n := constPoly F4.omega2 + varPoly i0 let P : MultiPoly F4 n := mul01 Lin Qf + Qflip have hLin_deg : HasDegLe Lin 1 := hasDegLe_add (hasDegLe_mono (hasDegLe_constPoly F4.omega2) (Nat.zero_le 1)) (hasDegLe_varPoly i0) have hQf_deg : HasDegLe Qf d := hasDegLe_liftPolyF4 hQ have hP_deg : HasDegLe P (d + 1) := by have h1 : HasDegLe (mul01 Lin Qf) (d + 1) := by rw [add_comm]; exact hasDegLe_mul01 hLin_deg hQf_deg have h2 : HasDegLe Qflip (d + 1) := hasDegLe_mono (hasDegLe_flipVarPoly i0 hQf_deg) (Nat.le_succ d) exact hasDegLe_add h1 h2 -- Apply Theorem 1 to `P` over `F4` with `ω = F4.omega`! have hgram := universal_gram_smolensky_bound hn hd F4.omega_ne_zero F4.omega_ne_one P hP_deg have hr : n - (d + 1) - 1 = n - d - 2 := by omega rw [hr] at hgram -- Bound `|E(P)| ≤ 2 * |E(Q)|` via `E(P) ⊆ E(Q) ∪ flip(E(Q))` let EQ := Finset.univ.filter (fun y : Fin n → Bool => eval01 Q y ≠ mod3Bool y) let EP := Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ prodChar F4.omega y) let flip : (Fin n → Bool) → (Fin n → Bool) := fun y => Function.update y i0 (!y i0) have hsub : EP ⊆ EQ ∪ EQ.image flip := by intro y hy simp only [EP, Finset.mem_filter, Finset.mem_univ, true_and] at hy by_contra hnot simp only [Finset.mem_union, Finset.mem_image, EQ, Finset.mem_filter, Finset.mem_univ, true_and, not_or, not_exists, not_and, not_not] at hnot rcases hnot with ⟨hyQ, hflipQ⟩ have hflip_agree : eval01 Q (flip y) = mod3Bool (flip y) := by by_contra hne have hff : flip (flip y) = y := by funext i; by_cases hi : i = i0 · subst hi; simp [flip] · simp [flip, hi] exact hflipQ (flip y) hne hff -- Now prove `eval01 P y = prodChar F4.omega y`, contradicting `hy`! apply hy have hPy : eval01 P y = (F4.omega2 + (if y i0 then (1 : F4) else 0)) * F4.ofZMod2 (mod3Bool y) + F4.ofZMod2 (mod3Bool (flip y)) := by simp only [P, Lin, Qf, Qflip, eval01_add, eval01_mul01, eval01_constPoly, eval01_varPoly, eval01_flipVarPoly, eval01_liftPolyF4, hyQ] change (F4.omega2 + (if y i0 = true then (1 : F4) else 0)) * F4.ofZMod2 (mod3Bool y) + F4.ofZMod2 (eval01 Q (flip y)) = _ rw [hflip_agree] rw [hPy] unfold prodChar rw [F4.omega_pow_mod3] -- Case split on `y i0` and `hammingWeight y % 3` have hw_flip : (y i0 = false → hammingWeight (flip y) = hammingWeight y + 1) ∧ (y i0 = true → hammingWeight y = hammingWeight (flip y) + 1) := by constructor · intro hf have hnot_i0 : i0 ∉ boolSupp y := by simp [boolSupp, hf] have heq : boolSupp (flip y) = insert i0 (boolSupp y) := by ext i; by_cases hi : i = i0 · subst hi; simp [boolSupp, flip, hf] · simp [boolSupp, flip, hi] simp [hammingWeight, heq, Finset.card_insert_of_notMem hnot_i0] · intro ht have hmem_i0 : i0 ∈ boolSupp y := by simp [boolSupp, ht] have heq : boolSupp y = insert i0 (boolSupp (flip y)) := by ext i; by_cases hi : i = i0 · subst hi; simp [boolSupp, flip, ht] · simp [boolSupp, flip, hi] have hnot_i0 : i0 ∉ boolSupp (flip y) := by simp [boolSupp, flip, ht] simp [hammingWeight, heq, Finset.card_insert_of_notMem hnot_i0] cases hy0 : y i0 · have hwf := hw_flip.1 hy0 have hmod_lt : hammingWeight y % 3 < 3 := Nat.mod_lt _ (by omega) have hwf_mod : hammingWeight (flip y) % 3 = (hammingWeight y % 3 + 1) % 3 := by omega simp only [Bool.false_eq_true, ↓reduceIte, add_zero, mod3Bool, hwf_mod] interval_cases (hammingWeight y % 3) <;> decide · have hwt := hw_flip.2 hy0 have hmod_lt : hammingWeight y % 3 < 3 := Nat.mod_lt _ (by omega) have hwf_mod : hammingWeight (flip y) % 3 = (hammingWeight y % 3 + 2) % 3 := by omega simp only [↓reduceIte, mod3Bool, hwf_mod] interval_cases (hammingWeight y % 3) <;> decide have hcard_le : EP.card ≤ 2 * EQ.card := by calc EP.card ≤ (EQ ∪ EQ.image flip).card := Finset.card_le_card hsub _ ≤ EQ.card + (EQ.image flip).card := Finset.card_union_le _ _ _ ≤ EQ.card + EQ.card := Nat.add_le_add_left Finset.card_image_le _ _ = 2 * EQ.card := by omega exact hgram.trans hcard_le /-! ## Section 2 (Pillar 2): Sharp Two-Term Smolensky Threshold & Majority Bound over Arbitrary ## Fields, Exact Sharpness at `d = 1` and `d = m`, and Non-Asymptotic `AC⁰[p]` Lower Bounds -/ /-- Threshold Boolean function `THR_k^n : {0,1}ⁿ → K`: `1` if `|y| ≥ k`, else `0`. -/ def thrFun {K : Type*} [Zero K] [One K] {n : ℕ} (k : ℕ) (y : Fin n → Bool) : K := if k ≤ hammingWeight y then 1 else 0 /-- Majority Boolean function `MAJ_n : {0,1}ⁿ → K` for odd `n = 2m + 1` (threshold `m + 1`). -/ def majFun {K : Type*} [Zero K] [One K] (m : ℕ) (y : Fin (2 * m + 1) → Bool) : K := thrFun (m + 1) y /-- The sharp two-term Smolensky threshold bound: `sharpThrBound n m d = ∑_{j=0}^{m-d} C(n, j) + ∑_{j=(m-2d+1)_+}^{m-d} C(n - d, j)`. -/ def sharpThrBound (n m d : ℕ) : ℕ := let r := m - d binomSum n r + ∑ j ∈ Finset.Icc (r + 1 - d) r, (n - d).choose j /-- Complement substitution `x_i ↦ 1 - x_i` on all variables of a multilinear polynomial. -/ def compPoly {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) : MultiPoly K n := fun S => (-1 : K) ^ S.card * ∑ T ∈ Finset.univ.filter (fun T : Finset (Fin n) => S ⊆ T), P T lemma hasDegLe_compPoly {K : Type*} [CommRing K] {n d : ℕ} {P : MultiPoly K n} (hP : HasDegLe P d) : HasDegLe (compPoly P) d := by intro S hS unfold compPoly suffices h0 : ∑ T ∈ Finset.univ.filter (fun T : Finset (Fin n) => S ⊆ T), P T = 0 by rw [h0, mul_zero] apply Finset.sum_eq_zero intro T hT simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hT exact hP T (lt_of_lt_of_le hS (Finset.card_le_card hT)) lemma eval01_compPoly {K : Type*} [CommRing K] {n : ℕ} (P : MultiPoly K n) (y : Fin n → Bool) : eval01 (compPoly P) y = eval01 P (fun i => !y i) := by rw [eval01_eq_sum_powerset, eval01_eq_sum_powerset] unfold compPoly -- Expand LHS: `∑ S ⊆ supp(y), (-1)^|S| * ∑_{T ⊇ S} P T = ∑ T, P T * ∑_{S ⊆ supp(y) ∩ T} (-1)^|S|` have hlhs : ∑ S ∈ (boolSupp y).powerset, (-1 : K) ^ S.card * ∑ T ∈ Finset.univ.filter (fun T : Finset (Fin n) => S ⊆ T), P T = ∑ T : Finset (Fin n), P T * ∑ S ∈ (boolSupp y ∩ T).powerset, (-1 : K) ^ S.card := by trans ∑ S ∈ (boolSupp y).powerset, ∑ T : Finset (Fin n), if S ⊆ T then (-1 : K) ^ S.card * P T else 0 · apply Finset.sum_congr rfl intro S _ rw [Finset.mul_sum, ← Finset.sum_filter] · rw [Finset.sum_comm] apply Finset.sum_congr rfl intro T _ rw [Finset.mul_sum, ← Finset.sum_filter] have hset : (boolSupp y).powerset.filter (fun S => S ⊆ T) = (boolSupp y ∩ T).powerset := by ext S simp only [Finset.mem_filter, Finset.mem_powerset, Finset.subset_inter_iff] rw [hset] apply Finset.sum_congr rfl intro S _; ring rw [hlhs] simp_rw [sum_powerset_neg_one_pow, mul_ite, mul_one, mul_zero] rw [← Finset.sum_filter] congr 1 ext T simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_powerset] constructor · intro hemp i hiT simp only [boolSupp, Finset.mem_filter, Finset.mem_univ, true_and, Bool.not_eq_true'] by_contra hyi have hytrue : y i = true := by cases h : y i <;> simp_all have hmem : i ∈ boolSupp y ∩ T := Finset.mem_inter.mpr ⟨by simp [boolSupp, hytrue], hiT⟩ rw [hemp] at hmem exact Finset.notMem_empty i hmem · intro hsub rw [Finset.eq_empty_iff_forall_notMem] intro i hi rcases Finset.mem_inter.mp hi with ⟨hyi, hiT⟩ have h1 := hsub hiT simp only [boolSupp, Finset.mem_filter, Finset.mem_univ, true_and, Bool.not_eq_true'] at hyi h1 rw [hyi] at h1 exact Bool.noConfusion h1 /-- Vanishing on the low-weight Hamming ball `{|y| ≤ k}` forces a degree-`≤ k` polynomial to be `0`. -/ lemma eq_zero_of_eval01_eq_zero_on_low_weight {K : Type*} [CommRing K] {n k : ℕ} {P : MultiPoly K n} (hdeg : HasDegLe P k) (hvan : ∀ y : Fin n → Bool, hammingWeight y ≤ k → eval01 P y = 0) : P = 0 := by have hstrong : ∀ m : ℕ, ∀ S : Finset (Fin n), S.card = m → P S = 0 := by intro m induction m using Nat.strong_induction_on with | h m ih => intro S hScard by_cases hmk : k < m · exact hdeg S (hScard.symm ▸ hmk) · have hle : hammingWeight (indicatorBool S) ≤ k := by simp only [hammingWeight, boolSupp_indicatorBool, hScard]; omega have hev := hvan (indicatorBool S) hle rw [eval01_eq_sum_powerset, boolSupp_indicatorBool] at hev rw [Finset.sum_eq_single S] at hev · exact hev · intro T hT hne have hsub : T ⊂ S := Finset.ssubset_iff_subset_ne.mpr ⟨Finset.mem_powerset.mp hT, hne⟩ have hlt : T.card < m := by rw [← hScard]; exact Finset.card_lt_card hsub exact ih T.card hlt T rfl · intro hnot; exact absurd (Finset.mem_powerset_self S) hnot funext S exact hstrong S.card S rfl /-- Vanishing on the high-weight Hamming ball `{|y| ≥ n - k}` forces a degree-`≤ k` polynomial to be `0`. -/ lemma eq_zero_of_eval01_eq_zero_on_high_weight {K : Type*} [CommRing K] {n k : ℕ} (hk : k ≤ n) {P : MultiPoly K n} (hdeg : HasDegLe P k) (hvan : ∀ y : Fin n → Bool, n - k ≤ hammingWeight y → eval01 P y = 0) : P = 0 := by have hcomp_zero : compPoly P = 0 := by apply eq_zero_of_eval01_eq_zero_on_low_weight (hasDegLe_compPoly hdeg) intro y hy rw [eval01_compPoly] apply hvan have hcomp_supp : boolSupp (fun i => !y i) = (boolSupp y)ᶜ := by ext i; simp [boolSupp] have hcomp_w : hammingWeight (fun i => !y i) = n - hammingWeight y := by simp [hammingWeight, hcomp_supp, Finset.card_compl, Fintype.card_fin] omega apply eq_zero_of_eval01_eq_zero intro y have h1 : eval01 (compPoly P) (fun i => !y i) = 0 := by rw [hcomp_zero]; simp [eval01_eq_sum_powerset] rw [eval01_compPoly] at h1 simpa using h1 /-- **Maximal-Monomial Degree-Separation Lemma:** If `P` has degree `≤ d₁` with `P I ≠ 0` (`|I| = d₁`), and `Q ≠ 0` is supported on subsets `J` disjoint from `I` with `r < d₁ + |J|`, then `mul01 P Q` has a nonzero monomial of size `> r`! -/ lemma mul01_has_high_monomial {K : Type*} [Field K] [DecidableEq K] {n d₁ r : ℕ} {P Q : MultiPoly K n} {I : Finset (Fin n)} (hIcard : I.card = d₁) (hPI : P I ≠ 0) (hPdeg : HasDegLe P d₁) (hQsupp : ∀ J : Finset (Fin n), Q J ≠ 0 → Disjoint I J ∧ r < d₁ + J.card) (hQne : Q ≠ 0) : ∃ U : Finset (Fin n), r < U.card ∧ mul01 P Q U ≠ 0 := by let suppQ := Finset.univ.filter (fun J : Finset (Fin n) => Q J ≠ 0) have hsupp_ne : suppQ.Nonempty := by by_contra hemp rw [Finset.not_nonempty_iff_eq_empty] at hemp apply hQne funext J by_contra hne have hmem : J ∈ suppQ := by simp only [suppQ, Finset.mem_filter, Finset.mem_univ, true_and]; exact hne rw [hemp] at hmem exact Finset.notMem_empty J hmem rcases Finset.exists_max_image suppQ Finset.card hsupp_ne with ⟨J₀, hJ₀_mem, hJ₀_max⟩ have hQJ₀ : Q J₀ ≠ 0 := (Finset.mem_filter.mp hJ₀_mem).2 rcases hQsupp J₀ hQJ₀ with ⟨hdisj₀, hgt₀⟩ refine ⟨I ∪ J₀, ?_, ?_⟩ · rw [Finset.card_union_of_disjoint hdisj₀, hIcard]; exact hgt₀ · -- Compute `mul01 P Q (I ∪ J₀) = P I * Q J₀ ≠ 0`! have hval : mul01 P Q (I ∪ J₀) = P I * Q J₀ := by unfold mul01 rw [Finset.sum_eq_single I] · rw [Finset.sum_eq_single J₀] · simp · intro B _ hBne split_ifs with hIB · by_contra hmul have hQB : Q B ≠ 0 := fun h => hmul (by simp [h]) have hdisjB : Disjoint I B := (hQsupp B hQB).1 -- `I ∪ B = I ∪ J₀` with both disjoint from `I` forces `B = J₀`! have hBeq : B = J₀ := by have h1 : (I ∪ B) \ I = B := Finset.union_sdiff_cancel_left hdisjB have h2 : (I ∪ J₀) \ I = J₀ := Finset.union_sdiff_cancel_left hdisj₀ rw [← h1, hIB, h2] exact hBne hBeq · rfl · intro hnot; exact absurd (Finset.mem_univ J₀) hnot · intro A _ hAne apply Finset.sum_eq_zero intro B _ split_ifs with hAB · by_contra hmul have hPA : P A ≠ 0 := fun h => hmul (by simp [h]) have hQB : Q B ≠ 0 := fun h => hmul (by simp [h]) have hAcard : A.card ≤ d₁ := by by_contra hgt; push Not at hgt; exact hPA (hPdeg A hgt) have hdisjB : Disjoint I B := (hQsupp B hQB).1 -- `I ⊆ I ∪ J₀ = A ∪ B` and `Disjoint I B` forces `I ⊆ A`! have hIsubA : I ⊆ A := by intro x hxI have hxAB : x ∈ A ∪ B := hAB.symm ▸ Finset.mem_union_left J₀ hxI rcases Finset.mem_union.mp hxAB with hxA | hxB · exact hxA · exact absurd hxB (Finset.disjoint_left.mp hdisjB hxI) have hAeq : A = I := (Finset.eq_of_subset_of_card_le hIsubA (hIcard.symm ▸ hAcard)).symm exact hAne hAeq · rfl · intro hnot; exact absurd (Finset.mem_univ I) hnot rw [hval] exact mul_ne_zero hPI hQJ₀ /-- Cardinality of `{J ⊆ Iᶜ | r + 1 - d₁ ≤ |J| ≤ r}` when `|I| = d₁` equals `∑ j ∈ Icc (r + 1 - d₁) r, (n - d₁).choose j`. -/ lemma card_disjoint_high_layer {n d₁ r : ℕ} (I : Finset (Fin n)) (hI : I.card = d₁) : (Finset.univ.filter (fun J : Finset (Fin n) => Disjoint I J ∧ r + 1 - d₁ ≤ J.card ∧ J.card ≤ r)).card = ∑ j ∈ Finset.Icc (r + 1 - d₁) r, (n - d₁).choose j := by have hpart : Finset.univ.filter (fun J : Finset (Fin n) => Disjoint I J ∧ r + 1 - d₁ ≤ J.card ∧ J.card ≤ r) = (Finset.Icc (r + 1 - d₁) r).biUnion (fun j => Finset.powersetCard j Iᶜ) := by ext J simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_biUnion, Finset.mem_Icc, Finset.mem_powersetCard, Finset.subset_compl_iff_disjoint_left] constructor · rintro ⟨hd, h1, h2⟩; exact ⟨J.card, ⟨h1, h2⟩, hd, rfl⟩ · rintro ⟨j, ⟨h1, h2⟩, hd, rfl⟩; exact ⟨hd, h1, h2⟩ rw [hpart, Finset.card_biUnion] · simp [Finset.card_powersetCard, Finset.card_compl, Fintype.card_fin, hI] · intro a _ b _ hab show Disjoint _ _ rw [Finset.disjoint_left] intro J ha hb rw [Finset.mem_powersetCard] at ha hb exact hab (ha.2.symm.trans hb.2) lemma mul01_add_right {K : Type*} [CommRing K] {n : ℕ} (P Q R : MultiPoly K n) : mul01 P (Q + R) = mul01 P Q + mul01 P R := by have h0 : mul01 P (Q + R) - (mul01 P Q + mul01 P R) = 0 := by apply eq_zero_of_eval01_eq_zero intro y simp only [eval01_sub, eval01_add, eval01_mul01] ring exact sub_eq_zero.mp h0 lemma mul01_smul_right {K : Type*} [CommRing K] {n : ℕ} (c : K) (P Q : MultiPoly K n) : mul01 P (c • Q) = c • mul01 P Q := by have h0 : mul01 P (c • Q) - c • mul01 P Q = 0 := by apply eq_zero_of_eval01_eq_zero intro y simp only [eval01_sub, eval01_smul, eval01_mul01] ring exact sub_eq_zero.mp h0 lemma mul01_one_sub {K : Type*} [CommRing K] {n : ℕ} (P Q : MultiPoly K n) : mul01 (constPoly 1 - P) Q = Q - mul01 P Q := by have h0 : mul01 (constPoly 1 - P) Q - (Q - mul01 P Q) = 0 := by apply eq_zero_of_eval01_eq_zero intro y simp only [eval01_sub, eval01_mul01, eval01_constPoly] ring exact sub_eq_zero.mp h0 /-- **Core Exact-Degree Two-Term Threshold Theorem:** Over any field `K`, if `P` has exact degree `d₁` (`1 ≤ d₁ ≤ m := min (k - 1) (n - k)`), then `P` errs against `THR_k^n` on at least `sharpThrBound n m d₁` inputs. -/ theorem sharp_threshold_exact_deg {K : Type*} [Field K] [DecidableEq K] {n k d₁ : ℕ} (hk1 : 1 ≤ k) (hkn : k ≤ n) (_hd1 : 1 ≤ d₁) (hdm : d₁ ≤ min (k - 1) (n - k)) (P : MultiPoly K n) (hPdeg : HasDegLe P d₁) (hPtop : ∃ I : Finset (Fin n), I.card = d₁ ∧ P I ≠ 0) : sharpThrBound n (min (k - 1) (n - k)) d₁ ≤ (Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ thrFun k y)).card := by set m := min (k - 1) (n - k) set r := m - d₁ have hm_le_k1 : m ≤ k - 1 := min_le_left _ _ have hm_le_nk : m ≤ n - k := min_le_right _ _ have hdr_k1 : d₁ + r ≤ k - 1 := by omega have hdr_nk : d₁ + r ≤ n - k := by omega rcases hPtop with ⟨I, hIcard, hPI⟩ let E := Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ thrFun k y) let EB := Finset.univ.filter (fun y : Fin n → Bool => hammingWeight y < k ∧ eval01 P y ≠ 0) let EA := Finset.univ.filter (fun y : Fin n → Bool => k ≤ hammingWeight y ∧ eval01 P y ≠ 1) have hE_eq : E = EB ∪ EA := by ext y simp only [E, EB, EA, Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] unfold thrFun by_cases hy : k ≤ hammingWeight y · have hnot : ¬(hammingWeight y < k) := not_lt.mpr hy simp [hy, hnot] · have hlt : hammingWeight y < k := not_le.mp hy simp [hy, hlt] have hE_disj : Disjoint EB EA := by rw [Finset.disjoint_left] intro y h1 h2 simp only [EB, EA, Finset.mem_filter, Finset.mem_univ, true_and] at h1 h2 omega have hE_card : E.card = EB.card + EA.card := by rw [hE_eq, Finset.card_union_of_disjoint hE_disj] -- Define linear maps `μP : Vr → MultiPoly`, `ΨB : Vr → (EB → K)`, `ΨA : Vr → (EA → K)` let Vr := polySpaceDegLe K n r let μP : Vr →ₗ[K] MultiPoly K n := { toFun := fun Q => mul01 P Q.1 map_add' := fun Q1 Q2 => mul01_add_right P Q1.1 Q2.1 map_smul' := fun c Q => mul01_smul_right c P Q.1 } let ΨB : Vr →ₗ[K] (EB → K) := { toFun := fun Q y => eval01 (mul01 P Q.1) y.1 map_add' := fun Q1 Q2 => by ext y; simp [mul01_add_right, eval01_add] map_smul' := fun c Q => by ext y; simp [mul01_smul_right, eval01_smul] } let ΨA : Vr →ₗ[K] (EA → K) := { toFun := fun Q y => eval01 (mul01 (constPoly 1 - P) Q.1) y.1 map_add' := fun Q1 Q2 => by ext y; simp [mul01_add_right, eval01_add] map_smul' := fun c Q => by ext y; simp [mul01_smul_right, eval01_smul] } -- Step 1: `ΨB.ker = μP.ker`, hence `finrank μP.range ≤ EB.card` have hkerB : ΨB.ker = μP.ker := by ext Q simp only [LinearMap.mem_ker, ΨB, μP, LinearMap.coe_mk, AddHom.coe_mk] constructor · intro hQ have hdegPQ : HasDegLe (mul01 P Q.1) (k - 1) := hasDegLe_mono (hasDegLe_mul01 hPdeg Q.2) hdr_k1 apply eq_zero_of_eval01_eq_zero_on_low_weight hdegPQ intro y hy by_cases hPy : eval01 P y = 0 · rw [eval01_mul01, hPy, zero_mul] · have hyEB : y ∈ EB := by simp only [EB, Finset.mem_filter, Finset.mem_univ, true_and]; exact ⟨by omega, hPy⟩ exact congrFun hQ ⟨y, hyEB⟩ · intro hQ ext y; rw [hQ]; simp [eval01_eq_sum_powerset] have hEB_ge : Module.finrank K (LinearMap.range μP) ≤ EB.card := by have h1 := LinearMap.finrank_range_add_finrank_ker μP have h2 := LinearMap.finrank_range_add_finrank_ker ΨB rw [hkerB] at h2 have hrange_eq : Module.finrank K (LinearMap.range μP) = Module.finrank K (LinearMap.range ΨB) := by omega have hle : Module.finrank K (LinearMap.range ΨB) ≤ Module.finrank K (EB → K) := Submodule.finrank_le (LinearMap.range ΨB) simpa [hrange_eq, Module.finrank_pi, Fintype.card_coe] using hle -- Step 2: `finrank Vr - finrank ΨA.ker ≤ EA.card` have hEA_ge : binomSum n r ≤ EA.card + Module.finrank K (LinearMap.ker ΨA) := by have h2 := LinearMap.finrank_range_add_finrank_ker ΨA have hle : Module.finrank K (LinearMap.range ΨA) ≤ Module.finrank K (EA → K) := Submodule.finrank_le (LinearMap.range ΨA) have hdimV : Module.finrank K Vr = binomSum n r := finrank_polySpaceDegLe K n r have hdimE : Module.finrank K (EA → K) = EA.card := by simp [Fintype.card_coe] omega -- Step 3: For every `Q ∈ ΨA.ker`, `mul01 P Q.1 = Q.1`, so `K_A := ΨA.ker.map (Submodule.subtype Vr) ≤ μP.range`! have hKA_fixed : ∀ Q ∈ LinearMap.ker ΨA, mul01 P Q.1 = Q.1 := by intro Q hQ have h1Pdeg : HasDegLe (constPoly 1 - P) d₁ := hasDegLe_sub (hasDegLe_mono (hasDegLe_constPoly 1) (Nat.zero_le d₁)) hPdeg have hdeg1PQ : HasDegLe (mul01 (constPoly 1 - P) Q.1) (n - k) := hasDegLe_mono (hasDegLe_mul01 h1Pdeg Q.2) hdr_nk have hzero : mul01 (constPoly 1 - P) Q.1 = 0 := by apply eq_zero_of_eval01_eq_zero_on_high_weight (by omega) hdeg1PQ intro y hy have hyk : k ≤ hammingWeight y := by omega by_cases hPy : eval01 P y = 1 · rw [eval01_mul01, eval01_sub, eval01_constPoly, hPy, sub_self, zero_mul] · have hyEA : y ∈ EA := by simp only [EA, Finset.mem_filter, Finset.mem_univ, true_and]; exact ⟨hyk, hPy⟩ exact congrFun hQ ⟨y, hyEA⟩ rw [mul01_one_sub] at hzero exact (sub_eq_zero.mp hzero).symm let KA_sub : Submodule K (MultiPoly K n) := (LinearMap.ker ΨA).map (Submodule.subtype Vr) have hKA_le : KA_sub ≤ LinearMap.range μP := by rintro _ ⟨Q, hQ, rfl⟩ exact ⟨Q, hKA_fixed Q hQ⟩ have hKA_dim : Module.finrank K KA_sub = Module.finrank K (LinearMap.ker ΨA) := (Submodule.equivMapOfInjective Vr.subtype (Submodule.injective_subtype Vr) _).symm.finrank_eq -- Step 4: Define the disjoint high-layer subspace `WI ≤ Vr` let idxWI := Finset.univ.filter (fun J : Finset (Fin n) => Disjoint I J ∧ r + 1 - d₁ ≤ J.card ∧ J.card ≤ r) let WI : Submodule K Vr := { carrier := {Q : Vr | ∀ J : Finset (Fin n), Q.1 J ≠ 0 → J ∈ idxWI} add_mem' := fun {Q1 Q2} h1 h2 J hne => by by_contra hnot apply hne have hq1 : Q1.1 J = 0 := by by_contra h; exact hnot (h1 J h) have hq2 : Q2.1 J = 0 := by by_contra h; exact hnot (h2 J h) simp [hq1, hq2] zero_mem' := fun J hne => absurd rfl hne smul_mem' := fun c {Q} hQ J hne => by apply hQ J intro h0; apply hne; simp [h0] } have hWI_dim : Module.finrank K WI = ∑ j ∈ Finset.Icc (r + 1 - d₁) r, (n - d₁).choose j := by let e : WI ≃ₗ[K] (idxWI → K) := { toFun := fun Q J => Q.1.1 J.1 map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl invFun := fun f => ⟨⟨fun J => if h : J ∈ idxWI then f ⟨J, h⟩ else 0, by intro J hJ have hnot : J ∉ idxWI := by simp only [idxWI, Finset.mem_filter, Finset.mem_univ, true_and] omega simp [hnot]⟩, by intro J hne by_contra hnot exact hne (by simp [hnot])⟩ left_inv := fun Q => by apply Subtype.ext; apply Subtype.ext; funext J by_cases h : J ∈ idxWI · simp [h] · simp only [h, ↓reduceDIte] by_contra hne exact h (Q.2 J (Ne.symm hne)) right_inv := fun f => by ext ⟨J, hJ⟩; simp [hJ] } rw [e.finrank_eq, Module.finrank_pi, Fintype.card_coe, card_disjoint_high_layer I hIcard] -- Step 5: `μP` is injective on `WI`, and `KA_sub ⊓ (WI.map μP) = ⊥`! have hWI_high : ∀ Q ∈ WI, Q ≠ 0 → ∃ U : Finset (Fin n), r < U.card ∧ mul01 P Q.1 U ≠ 0 := by intro Q hQ hQne have hQ1ne : Q.1 ≠ 0 := fun h => hQne (Subtype.ext h) apply mul01_has_high_monomial hIcard hPI hPdeg _ hQ1ne intro J hQJ have hmem := hQ J hQJ simp only [idxWI, Finset.mem_filter, Finset.mem_univ, true_and] at hmem exact ⟨hmem.1, by omega⟩ have hμP_inj_WI : Function.Injective (μP.domRestrict WI) := by rw [injective_iff_map_eq_zero] intro ⟨Q, hQ⟩ h0 by_contra hne have hQne : Q ≠ 0 := fun h => hne (Subtype.ext h) rcases hWI_high Q hQ hQne with ⟨U, _, hU⟩ have : mul01 P Q.1 U = 0 := congrFun h0 U exact hU this have hWI_map_dim : Module.finrank K (WI.map μP) = Module.finrank K WI := by have hrange : LinearMap.range (μP.domRestrict WI) = WI.map μP := by ext x simp only [LinearMap.mem_range, Submodule.mem_map, LinearMap.domRestrict_apply] constructor · rintro ⟨⟨Q, hQ⟩, rfl⟩; exact ⟨Q, hQ, rfl⟩ · rintro ⟨Q, hQ, rfl⟩; exact ⟨⟨Q, hQ⟩, rfl⟩ rw [← hrange, LinearMap.finrank_range_of_inj hμP_inj_WI] have hdisj_sub : KA_sub ⊓ WI.map μP = ⊥ := by rw [Submodule.eq_bot_iff] rintro x ⟨hxK, hxW⟩ rcases hxK with ⟨Q1, _, rfl⟩ rcases hxW with ⟨Q2, hQ2, hQ2eq⟩ by_contra hne have hQ2ne : Q2 ≠ 0 := by intro h0; apply hne rw [← hQ2eq, h0] show mul01 P 0 = 0 funext U; simp [mul01] rcases hWI_high Q2 hQ2 hQ2ne with ⟨U, hUr, hUne⟩ have hQ1U : Q1.1 U = 0 := Q1.2 U hUr have hμeq : mul01 P Q2.1 = Q1.1 := hQ2eq rw [hμeq, hQ1U] at hUne exact hUne rfl -- Step 6: Combine `KA_sub ⊔ WI.map μP ≤ μP.range`! have hsup_le : KA_sub ⊔ WI.map μP ≤ LinearMap.range μP := sup_le hKA_le (by rintro _ ⟨Q, _, rfl⟩; exact ⟨Q, rfl⟩) have hEB_final : Module.finrank K (LinearMap.ker ΨA) + Module.finrank K WI ≤ EB.card := by have hadd := Submodule.finrank_sup_add_finrank_inf_eq KA_sub (WI.map μP) rw [hdisj_sub, finrank_bot, add_zero, hKA_dim, hWI_map_dim] at hadd have hle := Submodule.finrank_mono hsup_le omega change sharpThrBound n m d₁ ≤ E.card unfold sharpThrBound change binomSum n r + ∑ j ∈ Finset.Icc (r + 1 - d₁) r, (n - d₁).choose j ≤ E.card rw [hE_card] rw [hWI_dim] at hEB_final omega /-- **Vandermonde Monotonicity Lemma:** For `2 * m + 1 ≤ n` and `1 ≤ d < m`, `sharpThrBound n m (d + 1) ≤ sharpThrBound n m d`. -/ lemma sharpThrBound_antitone_step {n m d : ℕ} (hnm : 2 * m + 1 ≤ n) (hd1 : 1 ≤ d) (hdm : d < m) : sharpThrBound n m (d + 1) ≤ sharpThrBound n m d := by unfold sharpThrBound dsimp only set r := m - d have hr1 : 1 ≤ r := by omega have hr_next : m - (d + 1) = r - 1 := by omega rw [hr_next] -- `binomSum n r = binomSum n (r - 1) + n.choose r` have hbinom_step : binomSum n r = binomSum n (r - 1) + n.choose r := by unfold binomSum have hr_eq : r = (r - 1) + 1 := by omega conv_lhs => rw [hr_eq, Finset.sum_range_succ] rw [← hr_eq] rw [hbinom_step] -- It suffices to prove: -- `∑ j ∈ Icc (r - 1 + 1 - (d + 1)) (r - 1), (n - (d + 1)).choose j ≤ n.choose r + ∑ j ∈ Icc (r + 1 - d) r, (n - d).choose j` suffices h : ∑ j ∈ Finset.Icc (r - 1 + 1 - (d + 1)) (r - 1), (n - (d + 1)).choose j ≤ n.choose r + ∑ j ∈ Finset.Icc (r + 1 - d) r, (n - d).choose j by omega -- Split `Icc (r - 1 + 1 - (d + 1)) (r - 1)` into `< r + 1 - d` and `≥ r + 1 - d`! let L := Finset.Icc (r - 1 + 1 - (d + 1)) (r - 1) let Lhi := L.filter (fun j => r + 1 - d ≤ j) let Llo := L.filter (fun j => ¬(r + 1 - d ≤ j)) have hsplit : ∑ j ∈ L, (n - (d + 1)).choose j = (∑ j ∈ Llo, (n - (d + 1)).choose j) + (∑ j ∈ Lhi, (n - (d + 1)).choose j) := by dsimp only [Llo, Lhi] have h := Finset.sum_filter_add_sum_filter_not L (fun j => r + 1 - d ≤ j) (fun j => (n - (d + 1)).choose j) linarith rw [hsplit] -- Part 1: `∑ j ∈ Lhi, (n - (d + 1)).choose j ≤ ∑ j ∈ Icc (r + 1 - d) r, (n - d).choose j` have hhi : ∑ j ∈ Lhi, (n - (d + 1)).choose j ≤ ∑ j ∈ Finset.Icc (r + 1 - d) r, (n - d).choose j := by have hsub : Lhi ⊆ Finset.Icc (r + 1 - d) r := by intro j hj simp only [Lhi, L, Finset.mem_filter, Finset.mem_Icc] at hj ⊢ omega calc ∑ j ∈ Lhi, (n - (d + 1)).choose j ≤ ∑ j ∈ Lhi, (n - d).choose j := by apply Finset.sum_le_sum; intro j _ exact Nat.choose_le_choose j (by omega) _ ≤ ∑ j ∈ Finset.Icc (r + 1 - d) r, (n - d).choose j := Finset.sum_le_sum_of_subset hsub -- Part 2: `∑ j ∈ Llo, (n - (d + 1)).choose j ≤ n.choose r` have hlo : ∑ j ∈ Llo, (n - (d + 1)).choose j ≤ n.choose r := by by_cases hrd : r < d · -- `Llo` is empty! have hemp : Llo = ∅ := by rw [Finset.eq_empty_iff_forall_notMem] intro j hj simp only [Llo, L, Finset.mem_filter, Finset.mem_Icc] at hj omega simp [hemp] · -- `d ≤ r`: every `j ∈ Llo` is one of `{r - d - 1, r - d}` (wait: check `r - 1 + 1 - (d + 1) = r - d - 1` and `< r + 1 - d` means `≤ r - d`!) -- WAIT A SECOND!! `r - 1 + 1 - (d + 1) = r - d - 1`, and `< r + 1 - d` means `≤ r - d`! -- SO `Llo` HAS AT MOST **TWO** ELEMENTS: `r - d - 1` AND `r - d`!! -- AND `(n - d - 1).choose (r - d - 1) + (n - d - 1).choose (r - d) = (n - d).choose (r - d) ≤ n.choose r`!! have hsub_pair : Llo ⊆ {r - d - 1, r - d} := by intro j hj simp only [Llo, L, Finset.mem_filter, Finset.mem_Icc, Finset.mem_insert, Finset.mem_singleton] at hj ⊢ omega have hsum_le : ∑ j ∈ Llo, (n - (d + 1)).choose j ≤ (n - d).choose (r - d) := by by_cases h1 : r - d = 0 · have hsub1 : Llo ⊆ {0} := by intro j hj have := hsub_pair hj simp only [Finset.mem_insert, Finset.mem_singleton] at this ⊢ omega calc ∑ j ∈ Llo, (n - (d + 1)).choose j ≤ ∑ j ∈ ({0} : Finset ℕ), (n - (d + 1)).choose j := Finset.sum_le_sum_of_subset hsub1 _ = 1 := by simp _ = (n - d).choose (r - d) := by simp [h1] · have hne : r - d - 1 ≠ r - d := by omega calc ∑ j ∈ Llo, (n - (d + 1)).choose j ≤ ∑ j ∈ ({r - d - 1, r - d} : Finset ℕ), (n - (d + 1)).choose j := Finset.sum_le_sum_of_subset hsub_pair _ = (n - (d + 1)).choose (r - d - 1) + (n - (d + 1)).choose (r - d) := Finset.sum_pair hne _ = (n - d).choose (r - d) := by have hnd : n - d = (n - (d + 1)) + 1 := by omega have hrd1 : r - d = (r - d - 1) + 1 := by omega conv_rhs => rw [hnd, hrd1, Nat.choose_succ_succ] rw [Nat.succ_eq_add_one, ← hrd1] -- And `(n - d).choose (r - d) ≤ n.choose r` via Vandermonde! have hvand : (n - d).choose (r - d) ≤ n.choose r := by have hnd : n = d + (n - d) := by omega conv_rhs => rw [hnd, Nat.add_choose_eq] have hmem : (d, r - d) ∈ Finset.antidiagonal r := by rw [Finset.mem_antidiagonal]; omega have hsingle := Finset.single_le_sum (f := fun ij : ℕ × ℕ => d.choose ij.1 * (n - d).choose ij.2) (fun _ _ => Nat.zero_le _) hmem simpa using hsingle exact hsum_le.trans hvand omega lemma sharpThrBound_antitone {n m d₁ d₂ : ℕ} (hnm : 2 * m + 1 ≤ n) (hd1 : 1 ≤ d₁) (hle : d₁ ≤ d₂) (hd2m : d₂ ≤ m) : sharpThrBound n m d₂ ≤ sharpThrBound n m d₁ := by obtain ⟨t, rfl⟩ := Nat.exists_eq_add_of_le hle induction t with | zero => simp | succ t ih => have h1 := sharpThrBound_antitone_step hnm (by omega : 1 ≤ d₁ + t) (by omega : d₁ + t < m) have h2 := ih (by omega) (by omega) exact h1.trans h2 /-- **HEADLINE THEOREM 5 (Sharp Two-Term Smolensky Threshold & Majority Bound over Every Field):** Over *every* field `K` (of arbitrary characteristic), for every `1 ≤ k ≤ n`, setting `m := min (k - 1) (n - k)`, every degree `1 ≤ d ≤ m`, and *every* multilinear polynomial `P` (constant or nonconstant) of degree `≤ d`: `sharpThrBound n m d ≤ |{y ∈ {0,1}ⁿ | eval01 P y ≠ thrFun k y}|`, i.e., `|E| ≥ ∑_{j=0}^{m-d} C(n, j) + ∑_{j=(m-2d+1)_+}^{m-d} C(n - d, j)`. This strictly improves Smolensky (1993) (`∑_{j=0}^{m-d} C(n, j)`) for every `n, k, d`. -/ theorem sharp_threshold_polynomial_error_bound {K : Type*} [Field K] [DecidableEq K] {n k d : ℕ} (hk1 : 1 ≤ k) (hkn : k ≤ n) (hd1 : 1 ≤ d) (hdm : d ≤ min (k - 1) (n - k)) (P : MultiPoly K n) (hP : HasDegLe P d) : sharpThrBound n (min (k - 1) (n - k)) d ≤ (Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ thrFun k y)).card := by set m := min (k - 1) (n - k) have hnm : 2 * m + 1 ≤ n := by omega -- Case split: is `P` constant (all `S ≠ ∅` have `P S = 0`) or nonconstant? let nonConstSupp := Finset.univ.filter (fun S : Finset (Fin n) => 1 ≤ S.card ∧ P S ≠ 0) by_cases hnc : nonConstSupp.Nonempty · -- Nonconstant: let `I` maximize `S.card` on `nonConstSupp`, giving exact degree `d₁ ∈ [1, d]`! rcases Finset.exists_max_image nonConstSupp Finset.card hnc with ⟨I, hI_mem, hI_max⟩ have hI_prop := (Finset.mem_filter.mp hI_mem).2 set d₁ := I.card have hd1_ge : 1 ≤ d₁ := hI_prop.1 have hd1_le_d : d₁ ≤ d := by by_contra hgt; push Not at hgt; exact hI_prop.2 (hP I hgt) have hPdeg1 : HasDegLe P d₁ := by intro S hS by_contra hPS have hSmem : S ∈ nonConstSupp := by simp only [nonConstSupp, Finset.mem_filter, Finset.mem_univ, true_and] exact ⟨by omega, hPS⟩ have := hI_max S hSmem omega have hexact := sharp_threshold_exact_deg hk1 hkn hd1_ge (hd1_le_d.trans hdm) P hPdeg1 ⟨I, rfl, hI_prop.2⟩ have hmono := sharpThrBound_antitone hnm hd1_ge hd1_le_d hdm exact hmono.trans hexact · -- Constant polynomial: `eval01 P y = P ∅` for all `y`! rw [Finset.not_nonempty_iff_eq_empty] at hnc have hconst : ∀ y : Fin n → Bool, eval01 P y = P ∅ := by intro y rw [eval01_eq_sum_powerset, Finset.sum_eq_single ∅] · intro S _ hSne by_contra hPS have hmem : S ∈ nonConstSupp := by simp only [nonConstSupp, Finset.mem_filter, Finset.mem_univ, true_and] exact ⟨Finset.card_pos.mpr (Finset.nonempty_iff_ne_empty.mpr hSne), hPS⟩ rw [hnc] at hmem exact Finset.notMem_empty S hmem · intro hnot; exact absurd (Finset.empty_mem_powerset _) hnot -- Any constant errs on at least `min(|{|y| < k}|, |{|y| ≥ k}|) ≥ binomSum n m ≥ sharpThrBound n m 1 ≥ sharpThrBound n m d`! have hstep1 : sharpThrBound n m 1 ≤ binomSum n m := by unfold sharpThrBound dsimp only have h1 : m - 1 + 1 - 1 = m - 1 := by omega rw [h1, Finset.Icc_self, Finset.sum_singleton] have hbs : binomSum n m = binomSum n (m - 1) + n.choose m := by unfold binomSum have hm1 : m = (m - 1) + 1 := by omega conv_lhs => rw [hm1, Finset.sum_range_succ] rw [← hm1] rw [hbs] have hch : (n - 1).choose (m - 1) ≤ n.choose m := by have hn1 : n = (n - 1) + 1 := by omega have hm1 : m = (m - 1) + 1 := by omega conv_rhs => rw [hn1, hm1, Nat.choose_succ_succ] omega omega have hmono : sharpThrBound n m d ≤ sharpThrBound n m 1 := sharpThrBound_antitone hnm le_rfl hd1 hdm have hconst_err : binomSum n m ≤ (Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ thrFun k y)).card := by by_cases hc0 : P ∅ = 0 · -- Errs on all `y` with `|y| ≥ k` (count `≥ binomSum n (n - k) ≥ binomSum n m`) have hsub : Finset.univ.filter (fun y : Fin n → Bool => k ≤ hammingWeight y) ⊆ Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ thrFun k y) := by intro y hy simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hy ⊢ rw [hconst y, hc0, thrFun, if_pos hy] exact zero_ne_one have hcnt : binomSum n m ≤ (Finset.univ.filter (fun y : Fin n → Bool => k ≤ hammingWeight y)).card := by have hbij : (Finset.univ.filter (fun y : Fin n → Bool => hammingWeight y ≤ m)).card = binomSum n m := by rw [← card_filter_card_le n m] refine Finset.card_bij (fun y _ => boolSupp y) ?_ ?_ ?_ · intro y hy; simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hy ⊢; exact hy · intro y1 _ y2 _ heq; funext i have := Finset.ext_iff.mp heq i simp [boolSupp] at this; exact this · intro S hS; simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hS refine ⟨indicatorBool S, ?_, boolSupp_indicatorBool S⟩ rw [Finset.mem_filter] exact ⟨Finset.mem_univ _, by simpa [hammingWeight, boolSupp_indicatorBool] using hS⟩ rw [← hbij] -- Complement map `y ↦ !y` injects `{|y| ≤ m}` into `{|y| ≥ k}` since `n - m ≥ k`! refine Finset.card_le_card_of_injOn (fun y i => !y i) ?_ ?_ · intro y hy simp only [Finset.mem_coe, Finset.mem_filter, Finset.mem_univ, true_and] at hy ⊢ have hcomp : hammingWeight (fun i => !y i) = n - hammingWeight y := by have hs : boolSupp (fun i => !y i) = (boolSupp y)ᶜ := by ext i; simp [boolSupp] simp [hammingWeight, hs, Finset.card_compl, Fintype.card_fin] omega · intro y1 _ y2 _ heq funext i; have := congrFun heq i; simpa using this exact hcnt.trans (Finset.card_le_card hsub) · -- `P ∅ ≠ 0`: errs on all `y` with `|y| < k` (count `≥ binomSum n m`) have hsub : Finset.univ.filter (fun y : Fin n → Bool => hammingWeight y ≤ m) ⊆ Finset.univ.filter (fun y : Fin n → Bool => eval01 P y ≠ thrFun k y) := by intro y hy simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hy ⊢ rw [hconst y, thrFun, if_neg (by omega)] exact hc0 have hcnt : (Finset.univ.filter (fun y : Fin n → Bool => hammingWeight y ≤ m)).card = binomSum n m := by rw [← card_filter_card_le n m] refine Finset.card_bij (fun y _ => boolSupp y) ?_ ?_ ?_ · intro y hy; simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hy ⊢; exact hy · intro y1 _ y2 _ heq; funext i have := Finset.ext_iff.mp heq i simp [boolSupp] at this; exact this · intro S hS; simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hS refine ⟨indicatorBool S, ?_, boolSupp_indicatorBool S⟩ rw [Finset.mem_filter] exact ⟨Finset.mem_univ _, by simpa [hammingWeight, boolSupp_indicatorBool] using hS⟩ rw [← hcnt] exact Finset.card_le_card hsub exact (hmono.trans hstep1).trans hconst_err /-- **HEADLINE THEOREM 6 (Exact Degree-1 & Half-Degree Sharpness for Majority over Every Field):** For every odd `n = 2m + 1` (`m ≥ 1`) and every field `K`: 1. Every degree-`≤ 1` polynomial errs against `MAJ_{2m+1}` on at least `2 * binomSum (2*m) (m - 1)` inputs, AND this exact minimum is attained by the dictator `varPoly 0`! 2. Every degree-`≤ m` polynomial errs against `MAJ_{2m+1}` on at least `2` inputs (strictly doubling Smolensky's bound of `1`), AND exact equality `2` is attained on `MAJ₅` over `𝔽₂`! -/ theorem majority_deg1_exact {K : Type*} [Field K] [DecidableEq K] {m : ℕ} (hm : 1 ≤ m) : (∀ P : MultiPoly K (2 * m + 1), HasDegLe P 1 → 2 * binomSum (2 * m) (m - 1) ≤ (Finset.univ.filter (fun y : Fin (2 * m + 1) → Bool => eval01 P y ≠ majFun m y)).card) ∧ (∃ P : MultiPoly K (2 * m + 1), HasDegLe P 1 ∧ (Finset.univ.filter (fun y : Fin (2 * m + 1) → Bool => eval01 P y ≠ majFun m y)).card = 2 * binomSum (2 * m) (m - 1)) := by have hmin : min (m + 1 - 1) (2 * m + 1 - (m + 1)) = m := by omega constructor · intro P hP have h := sharp_threshold_polynomial_error_bound (k := m + 1) (d := 1) (by omega) (by omega) le_rfl (by omega) P hP rw [hmin] at h -- Show `sharpThrBound (2 * m + 1) m 1 = 2 * binomSum (2 * m) (m - 1)`! have hval : sharpThrBound (2 * m + 1) m 1 = 2 * binomSum (2 * m) (m - 1) := by unfold sharpThrBound dsimp only have h1 : m - 1 + 1 - 1 = m - 1 := by omega rw [h1, Finset.Icc_self, Finset.sum_singleton, show 2 * m + 1 - 1 = 2 * m by omega] -- By Pascal's identity: `binomSum (2*m + 1) (m - 1) + (2*m).choose (m - 1) = 2 * binomSum (2*m) (m - 1)`! have hpascal : ∀ r : ℕ, binomSum (2 * m + 1) r + (2 * m).choose r = 2 * binomSum (2 * m) r := by intro r induction r with | zero => simp [binomSum] | succ r ih => have h1s : binomSum (2 * m + 1) (r + 1) = binomSum (2 * m + 1) r + (2 * m + 1).choose (r + 1) := by simp [binomSum, Finset.sum_range_succ] have h2s : binomSum (2 * m) (r + 1) = binomSum (2 * m) r + (2 * m).choose (r + 1) := by simp [binomSum, Finset.sum_range_succ] have hch : (2 * m + 1).choose (r + 1) = (2 * m).choose r + (2 * m).choose (r + 1) := Nat.choose_succ_succ (2 * m) r omega exact hpascal (m - 1) rw [hval] at h exact h · -- Dictator `P = varPoly 0` attains exact error `2 * binomSum (2*m) (m - 1)`! let i0 : Fin (2 * m + 1) := ⟨0, by omega⟩ refine ⟨varPoly i0, hasDegLe_varPoly i0, ?_⟩ -- Partition errors into `{y i0 = true ∧ |y| ≤ m}` and `{y i0 = false ∧ |y| ≥ m + 1}`! let E1 := Finset.univ.filter (fun y : Fin (2 * m + 1) → Bool => y i0 = true ∧ hammingWeight y ≤ m) let E0 := Finset.univ.filter (fun y : Fin (2 * m + 1) → Bool => y i0 = false ∧ m + 1 ≤ hammingWeight y) have hfilt : Finset.univ.filter (fun y : Fin (2 * m + 1) → Bool => eval01 (varPoly (K := K) i0) y ≠ majFun m y) = E1 ∪ E0 := by ext y simp only [E1, E0, Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, eval01_varPoly, majFun, thrFun] cases hy : y i0 <;> by_cases hw : m + 1 ≤ hammingWeight y · simp [hw] · simp [hw, show hammingWeight y ≤ m by omega] · simp [hw, show ¬(hammingWeight y ≤ m) by omega] · simp [hw, show hammingWeight y ≤ m by omega] have hdisj : Disjoint E1 E0 := by rw [Finset.disjoint_left] intro y h1 h2 simp only [E1, E0, Finset.mem_filter, Finset.mem_univ, true_and] at h1 h2 rw [h1.1] at h2; exact Bool.noConfusion h2.1 rw [hfilt, Finset.card_union_of_disjoint hdisj] have hE1 : E1.card = binomSum (2 * m) (m - 1) := by rw [← card_filter_card_le (2 * m) (m - 1)] refine Finset.card_bij (fun y _ => Finset.univ.filter (fun j : Fin (2 * m) => y j.succ = true)) ?_ ?_ ?_ · intro y hy simp only [E1, Finset.mem_filter, Finset.mem_univ, true_and] at hy ⊢ -- `hammingWeight y = 1 + #{j : Fin (2*m) | y j.succ = true}` have hsplit : hammingWeight y = 1 + (Finset.univ.filter (fun j : Fin (2 * m) => y j.succ = true)).card := by unfold hammingWeight boolSupp have hmem0 : i0 ∈ Finset.univ.filter (fun i : Fin (2 * m + 1) => y i = true) := by simp [hy.1] rw [← Finset.card_erase_add_one hmem0, add_comm] congr 1 refine Finset.card_bij (fun i _ => i.pred (by intro h0; exact (Finset.mem_erase.mp ‹_›).1 (by ext; simpa [i0] using congrArg Fin.val h0))) ?_ ?_ ?_ · intro i hi simp only [Finset.mem_erase, Finset.mem_filter, Finset.mem_univ, true_and] at hi ⊢ simpa [Fin.succ_pred] using hi.2 · intro i1 h1 i2 h2 heq have := congrArg Fin.succ heq simpa [Fin.succ_pred] using this · intro j hj simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hj refine ⟨j.succ, ?_, by simp⟩ simp only [Finset.mem_erase, Finset.mem_filter, Finset.mem_univ, true_and] exact ⟨Fin.succ_ne_zero j, hj⟩ omega · intro y1 h1 y2 h2 heq simp only [E1, Finset.mem_filter, Finset.mem_univ, true_and] at h1 h2 funext i refine Fin.cases ?_ ?_ i · exact h1.1.trans h2.1.symm · intro j have := Finset.ext_iff.mp heq j simp only [Finset.mem_filter, Finset.mem_univ, true_and] at this cases hj1 : y1 j.succ <;> cases hj2 : y2 j.succ <;> simp_all · intro S hS simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hS let y : Fin (2 * m + 1) → Bool := Fin.cases true (fun j => decide (j ∈ S)) refine ⟨y, ?_, ?_⟩ · simp only [E1, Finset.mem_filter, Finset.mem_univ, true_and] refine ⟨rfl, ?_⟩ have hw : hammingWeight y = 1 + S.card := by unfold hammingWeight boolSupp have hmem0 : i0 ∈ Finset.univ.filter (fun i : Fin (2 * m + 1) => y i = true) := by simp [y, i0] rw [← Finset.card_erase_add_one hmem0, add_comm] congr 1 refine Finset.card_bij (fun i hi => i.pred (by intro h0; exact (Finset.mem_erase.mp hi).1 (by ext; simpa [i0] using congrArg Fin.val h0))) ?_ ?_ ?_ · intro i hi simp only [Finset.mem_erase, Finset.mem_filter, Finset.mem_univ, true_and] at hi have hne : i ≠ 0 := hi.1 have hval := hi.2 rw [← Fin.succ_pred i hne] at hval simp only [y, Fin.cases_succ, decide_eq_true_eq] at hval exact hval · intro i1 h1 i2 h2 heq have := congrArg Fin.succ heq simpa [Fin.succ_pred] using this · intro j hj refine ⟨j.succ, ?_, by simp⟩ simp [y, hj, i0] omega · ext j; simp [y] have hE0 : E0.card = E1.card := by refine Finset.card_bij (fun y _ i => !y i) ?_ ?_ ?_ · intro y hy simp only [E0, E1, Finset.mem_filter, Finset.mem_univ, true_and] at hy ⊢ have hcomp : hammingWeight (fun i => !y i) = 2 * m + 1 - hammingWeight y := by have hs : boolSupp (fun i => !y i) = (boolSupp y)ᶜ := by ext i; simp [boolSupp] simp [hammingWeight, hs, Finset.card_compl, Fintype.card_fin] exact ⟨by simp [hy.1], by omega⟩ · intro y1 _ y2 _ heq; funext i; have := congrFun heq i; simpa using this · intro y hy simp only [E1, Finset.mem_filter, Finset.mem_univ, true_and] at hy refine ⟨fun i => !y i, ?_, by funext i; simp⟩ simp only [E0, Finset.mem_filter, Finset.mem_univ, true_and] have hcomp : hammingWeight (fun i => !y i) = 2 * m + 1 - hammingWeight y := by have hs : boolSupp (fun i => !y i) = (boolSupp y)ᶜ := by ext i; simp [boolSupp] simp [hammingWeight, hs, Finset.card_compl, Fintype.card_fin] exact ⟨by simp [hy.1], by omega⟩ omega /-- **Half-Degree Majority Sharpness (`d = m` on `MAJ_{2m+1}`):** Over every field `K`, every degree-`≤ m` polynomial errs on at least `2` inputs against `MAJ_{2m+1}` (strictly doubling Smolensky's bound of `1`), and on `MAJ₅` over `𝔽₂` the degree-2 symmetric polynomial `e₂ + e₁ + 1` achieves exact error `2`! -/ theorem majority_deg_half_sharp {K : Type*} [Field K] [DecidableEq K] {m : ℕ} (hm : 1 ≤ m) (P : MultiPoly K (2 * m + 1)) (hP : HasDegLe P m) : 2 ≤ (Finset.univ.filter (fun y : Fin (2 * m + 1) → Bool => eval01 P y ≠ majFun m y)).card := by have h := sharp_threshold_polynomial_error_bound (k := m + 1) (d := m) (by omega) (by omega) hm (by omega) P hP have hmin : min (m + 1 - 1) (2 * m + 1 - (m + 1)) = m := by omega rw [hmin] at h have hval : sharpThrBound (2 * m + 1) m m = 2 := by unfold sharpThrBound dsimp only rw [Nat.sub_self, show 0 + 1 - m = 0 by omega] simp [binomSum] rw [hval] at h exact h theorem majority5_deg2_F2_attains_two : ∃ P : MultiPoly (ZMod 2) 5, HasDegLe P 2 ∧ (Finset.univ.filter (fun y : Fin 5 → Bool => eval01 P y ≠ majFun 2 y)).card = 2 := by let P : MultiPoly (ZMod 2) 5 := fun S => if S.card ≤ 2 then 1 else 0 refine ⟨P, fun S hS => by simp [P, not_le.mpr hS], ?_⟩ have hfilt : Finset.univ.filter (fun y : Fin 5 → Bool => eval01 P y ≠ majFun 2 y) = {fun _ => false, fun _ => true} := by ext y simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_insert, Finset.mem_singleton] have hval : eval01 P y = ((1 + hammingWeight y + (hammingWeight y).choose 2 : ℕ) : ZMod 2) := by rw [eval01_eq_sum_powerset] simp only [P] rw [← Finset.sum_filter, Finset.sum_const, nsmul_eq_mul, mul_one] congr 1 set U := boolSupp y have hpart : U.powerset.filter (fun S => S.card ≤ 2) = Finset.powersetCard 0 U ∪ (Finset.powersetCard 1 U ∪ Finset.powersetCard 2 U) := by ext S simp only [Finset.mem_filter, Finset.mem_powerset, Finset.mem_union, Finset.mem_powersetCard] constructor · rintro ⟨hsub, hle⟩ have hc : S.card = 0 ∨ S.card = 1 ∨ S.card = 2 := by omega rcases hc with h | h | h · left; exact ⟨hsub, h⟩ · right; left; exact ⟨hsub, h⟩ · right; right; exact ⟨hsub, h⟩ · rintro (⟨hsub, h⟩ | ⟨hsub, h⟩ | ⟨hsub, h⟩) <;> exact ⟨hsub, by omega⟩ rw [hpart, Finset.card_union_of_disjoint, Finset.card_union_of_disjoint] · simp [Finset.card_powersetCard, hammingWeight, U, add_assoc] · rw [Finset.disjoint_left]; intro S h1 h2 rw [Finset.mem_powersetCard] at h1 h2; omega · rw [Finset.disjoint_left]; intro S h1 h2 simp only [Finset.mem_powersetCard, Finset.mem_union] at h1 h2; omega rw [hval, majFun, thrFun] have hw_le : hammingWeight y ≤ 5 := by have := Finset.card_le_univ (boolSupp y); simpa [hammingWeight] using this have hfalse : hammingWeight y = 0 ↔ y = fun _ => false := by constructor · intro hw; funext i; by_contra hne have ht : y i = true := by cases h : y i <;> simp_all have hpos : 0 < hammingWeight y := Finset.card_pos.mpr ⟨i, by simp [boolSupp, ht]⟩ omega · rintro rfl; simp [hammingWeight, boolSupp] have htrue : hammingWeight y = 5 ↔ y = fun _ => true := by constructor · intro hw; funext i have huniv : boolSupp y = Finset.univ := Finset.eq_univ_of_card _ (by simpa [hammingWeight] using hw) have hmem : i ∈ boolSupp y := by rw [huniv]; exact Finset.mem_univ i simpa [boolSupp] using hmem · rintro rfl; simp [hammingWeight, boolSupp] rw [← hfalse, ← htrue] have hcases : hammingWeight y = 0 ∨ hammingWeight y = 1 ∨ hammingWeight y = 2 ∨ hammingWeight y = 3 ∨ hammingWeight y = 4 ∨ hammingWeight y = 5 := by omega rcases hcases with h | h | h | h | h | h <;> (rw [h]; decide) rw [hfilt, Finset.card_pair] intro h; have := congrFun h 0; simp at this /-! ### Complete Non-Asymptotic Razborov–Smolensky `AC⁰[p]` Circuit-to-Polynomial Lower Bounds -/ /-- Gate types of an unbounded fan-in `AC⁰[p]` circuit. -/ inductive AC0pGateKind where | orGate | andGate | modPGate | notGate deriving DecidableEq /-- A gate in a topologically ordered DAG `AC⁰[p]` circuit on `n` Boolean inputs with `m` gates. Wire indices `0 .. n-1` are input variables; `n + g` is the output of gate `g : Fin m`. -/ structure AC0pGate (n m : ℕ) (g : Fin m) where kind : AC0pGateKind inputs : Finset (Fin (n + m)) acyclic : ∀ w ∈ inputs, w.val < n + g.val notWire : Fin (n + m) notAcyclic : notWire.val < n + g.val /-- An `AC⁰[p]` DAG circuit on `n` inputs with `m` gates and designated output wire. -/ structure AC0pCircuit (p n : ℕ) where numGates : ℕ gates : ∀ g : Fin numGates, AC0pGate n numGates g outWire : Fin (n + numGates) /-- Number of `OR` / `AND` gates in an `AC⁰[p]` circuit. -/ def AC0pCircuit.orAndCount {p n : ℕ} (C : AC0pCircuit p n) : ℕ := (Finset.univ.filter (fun g : Fin C.numGates => (C.gates g).kind = .orGate ∨ (C.gates g).kind = .andGate)).card /-- `mul01` is associative and commutative with identity `constPoly 1` (needed for `Finset.fold`). -/ lemma mul01_comm {K : Type*} [CommRing K] {n : ℕ} (P Q : MultiPoly K n) : mul01 P Q = mul01 Q P := sub_eq_zero.mp (eq_zero_of_eval01_eq_zero (fun y => by simp [eval01_sub, eval01_mul01, mul_comm])) lemma mul01_assoc {K : Type*} [CommRing K] {n : ℕ} (P Q R : MultiPoly K n) : mul01 (mul01 P Q) R = mul01 P (mul01 Q R) := sub_eq_zero.mp (eq_zero_of_eval01_eq_zero (fun y => by simp [eval01_sub, eval01_mul01, mul_assoc])) instance instStdCommMul01 {K : Type*} [CommRing K] {n : ℕ} : Std.Commutative (mul01 (K := K) (n := n)) := ⟨mul01_comm⟩ instance instStdAssocMul01 {K : Type*} [CommRing K] {n : ℕ} : Std.Associative (mul01 (K := K) (n := n)) := ⟨mul01_assoc⟩ /-- Exact Boolean evaluation of wire `w < n + C.numGates` on input `x : Fin n → Bool`. -/ def AC0pCircuit.evalWire {p n : ℕ} (C : AC0pCircuit p n) (x : Fin n → Bool) : (w : ℕ) → w < n + C.numGates → Bool | w, hw => if h : w < n then x ⟨w, h⟩ else let g : Fin C.numGates := ⟨w - n, by omega⟩ let gate := C.gates g let childVal : {u : Fin (n + C.numGates) // u ∈ gate.inputs} → Bool := fun u => have _ : u.1.val < w := by have := gate.acyclic u.1 u.2; change u.1.val < n + (w - n) at this; omega C.evalWire x u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega)) match gate.kind with | .orGate => decide (∃ u ∈ gate.inputs.attach, childVal u = true) | .andGate => decide (∀ u ∈ gate.inputs.attach, childVal u = true) | .modPGate => decide ((∑ u ∈ gate.inputs.attach, if childVal u then 1 else 0) % p ≠ 0) | .notGate => have _ : gate.notWire.val < w := by have := gate.notAcyclic; change gate.notWire.val < n + (w - n) at this; omega !(C.evalWire x gate.notWire.val (lt_trans gate.notAcyclic (by omega))) termination_by w => w /-- Exact Boolean output of `C` on input `x : Fin n → Bool` (as `0` or `1` in `ZMod p`). -/ def AC0pCircuit.evalBool {p n : ℕ} (C : AC0pCircuit p n) (x : Fin n → Bool) : Bool := C.evalWire x C.outWire.val C.outWire.isLt def AC0pCircuit.evalZMod {p n : ℕ} (C : AC0pCircuit p n) (x : Fin n → Bool) : ZMod p := if C.evalBool x then 1 else 0 /-- Polynomial degree upper bound for wire `w` under approximation parameter `k ≥ 1`. -/ def AC0pCircuit.wireDeg {p n : ℕ} (C : AC0pCircuit p n) (k : ℕ) : (w : ℕ) → w < n + C.numGates → ℕ | w, hw => if h : w < n then 1 else let g : Fin C.numGates := ⟨w - n, by omega⟩ let gate := C.gates g let maxIn : ℕ := gate.inputs.attach.sup (fun u => have _ : u.1.val < w := by have := gate.acyclic u.1 u.2; change u.1.val < n + (w - n) at this; omega C.wireDeg k u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega))) match gate.kind with | .orGate => k * (p - 1) * maxIn | .andGate => k * (p - 1) * maxIn | .modPGate => (p - 1) * maxIn | .notGate => have _ : gate.notWire.val < w := by have := gate.notAcyclic; change gate.notWire.val < n + (w - n) at this; omega C.wireDeg k gate.notWire.val (lt_trans gate.notAcyclic (by omega)) termination_by w => w /-- Total degree upper bound of the Razborov–Smolensky approximating polynomial for `C`. -/ def AC0pCircuit.polyDeg {p n : ℕ} (C : AC0pCircuit p n) (k : ℕ) : ℕ := C.wireDeg k C.outWire.val C.outWire.isLt /-- Randomness space for Razborov–Smolensky approximation of `C` with parameter `k`: each gate `g` gets `k` random linear coefficient vectors over `ZMod p`. -/ abbrev RSSeed (p n m k : ℕ) := Fin m → Fin k → Fin (n + m) → ZMod p /-- Deterministic polynomial constructed for wire `w` given seed `r : RSSeed p n C.numGates k`. -/ def AC0pCircuit.wirePoly {p n k : ℕ} (C : AC0pCircuit p n) (r : RSSeed p n C.numGates k) : (w : ℕ) → w < n + C.numGates → MultiPoly (ZMod p) n | w, hw => if h : w < n then varPoly ⟨w, h⟩ else let g : Fin C.numGates := ⟨w - n, by omega⟩ let gate := C.gates g match gate.kind with | .orGate => constPoly 1 - (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ gate.inputs.attach, have _ : u.1.val < w := by have := gate.acyclic u.1 u.2; change u.1.val < n + (w - n) at this; omega (r g j u.1) • C.wirePoly r u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega))) (p - 1)) | .andGate => (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ gate.inputs.attach, have _ : u.1.val < w := by have := gate.acyclic u.1 u.2; change u.1.val < n + (w - n) at this; omega (r g j u.1) • (constPoly 1 - C.wirePoly r u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega)))) (p - 1)) | .modPGate => pow01 (∑ u ∈ gate.inputs.attach, have _ : u.1.val < w := by have := gate.acyclic u.1 u.2; change u.1.val < n + (w - n) at this; omega C.wirePoly r u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega))) (p - 1) | .notGate => have _ : gate.notWire.val < w := by have := gate.notAcyclic; change gate.notWire.val < n + (w - n) at this; omega constPoly 1 - C.wirePoly r gate.notWire.val (lt_trans gate.notAcyclic (by omega)) termination_by w => w /-- Clean unfolding lemma for `evalWire` at a gate wire `n + g.val`. -/ lemma AC0pCircuit.evalWire_gate {p n : ℕ} (C : AC0pCircuit p n) (x : Fin n → Bool) (g : Fin C.numGates) (hw : n + g.val < n + C.numGates) : C.evalWire x (n + g.val) hw = match (C.gates g).kind with | .orGate => decide (∃ u ∈ (C.gates g).inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true) | .andGate => decide (∀ u ∈ (C.gates g).inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true) | .modPGate => decide ((∑ u ∈ (C.gates g).inputs.attach, if C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) then 1 else 0) % p ≠ 0) | .notGate => !(C.evalWire x (C.gates g).notWire.val (lt_trans (C.gates g).notAcyclic (by omega))) := by rw [AC0pCircuit.evalWire, dif_neg (by omega)] dsimp only have hsub : ∀ g' : Fin C.numGates, g' = g → (match (C.gates g').kind with | .orGate => decide (∃ u ∈ (C.gates g').inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g').acyclic u.1 u.2) (by omega)) = true) | .andGate => decide (∀ u ∈ (C.gates g').inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g').acyclic u.1 u.2) (by omega)) = true) | .modPGate => decide ((∑ u ∈ (C.gates g').inputs.attach, if C.evalWire x u.1.val (lt_trans ((C.gates g').acyclic u.1 u.2) (by omega)) then 1 else 0) % p ≠ 0) | .notGate => !(C.evalWire x (C.gates g').notWire.val (lt_trans (C.gates g').notAcyclic (by omega)))) = (match (C.gates g).kind with | .orGate => decide (∃ u ∈ (C.gates g).inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true) | .andGate => decide (∀ u ∈ (C.gates g).inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true) | .modPGate => decide ((∑ u ∈ (C.gates g).inputs.attach, if C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) then 1 else 0) % p ≠ 0) | .notGate => !(C.evalWire x (C.gates g).notWire.val (lt_trans (C.gates g).notAcyclic (by omega)))) := by rintro _ rfl; rfl exact hsub ⟨n + g.val - n, by omega⟩ (Fin.ext (Nat.add_sub_cancel_left n g.val)) /-- Clean unfolding lemma for `wirePoly` at a gate wire `n + g.val`. -/ lemma AC0pCircuit.wirePoly_gate {p n k : ℕ} (C : AC0pCircuit p n) (r : RSSeed p n C.numGates k) (g : Fin C.numGates) (hw : n + g.val < n + C.numGates) : C.wirePoly r (n + g.val) hw = match (C.gates g).kind with | .orGate => constPoly 1 - (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (r g j u.1) • C.wirePoly r u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1)) | .andGate => (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (r g j u.1) • (constPoly 1 - C.wirePoly r u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)))) (p - 1)) | .modPGate => pow01 (∑ u ∈ (C.gates g).inputs.attach, C.wirePoly r u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1) | .notGate => constPoly 1 - C.wirePoly r (C.gates g).notWire.val (lt_trans (C.gates g).notAcyclic (by omega)) := by rw [AC0pCircuit.wirePoly, dif_neg (by omega)] dsimp only have hsub : ∀ g' : Fin C.numGates, g' = g → (match (C.gates g').kind with | .orGate => constPoly 1 - (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g').inputs.attach, (r g' j u.1) • C.wirePoly r u.1.val (lt_trans ((C.gates g').acyclic u.1 u.2) (by omega))) (p - 1)) | .andGate => (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g').inputs.attach, (r g' j u.1) • (constPoly 1 - C.wirePoly r u.1.val (lt_trans ((C.gates g').acyclic u.1 u.2) (by omega)))) (p - 1)) | .modPGate => pow01 (∑ u ∈ (C.gates g').inputs.attach, C.wirePoly r u.1.val (lt_trans ((C.gates g').acyclic u.1 u.2) (by omega))) (p - 1) | .notGate => constPoly 1 - C.wirePoly r (C.gates g').notWire.val (lt_trans (C.gates g').notAcyclic (by omega))) = (match (C.gates g).kind with | .orGate => constPoly 1 - (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (r g j u.1) • C.wirePoly r u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1)) | .andGate => (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (r g j u.1) • (constPoly 1 - C.wirePoly r u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)))) (p - 1)) | .modPGate => pow01 (∑ u ∈ (C.gates g).inputs.attach, C.wirePoly r u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1) | .notGate => constPoly 1 - C.wirePoly r (C.gates g).notWire.val (lt_trans (C.gates g).notAcyclic (by omega))) := by rintro _ rfl; rfl exact hsub ⟨n + g.val - n, by omega⟩ (Fin.ext (Nat.add_sub_cancel_left n g.val)) lemma eval01_fold_mul01 {K : Type*} [CommRing K] {n : ℕ} {α : Type*} [DecidableEq α] (s : Finset α) (f : α → MultiPoly K n) (y : Fin n → Bool) : eval01 (s.fold mul01 (constPoly 1) f) y = ∏ a ∈ s, eval01 (f a) y := by induction s using Finset.induction_on with | empty => simp [eval01_constPoly] | @insert a s ha ih => rw [Finset.fold_insert ha, eval01_mul01, ih, Finset.prod_insert ha] lemma hasDegLe_fold_mul01 {K : Type*} [CommRing K] {n d : ℕ} {α : Type*} [DecidableEq α] (s : Finset α) (f : α → MultiPoly K n) (hf : ∀ a ∈ s, HasDegLe (f a) d) : HasDegLe (s.fold mul01 (constPoly 1) f) (s.card * d) := by induction s using Finset.induction_on with | empty => simpa using hasDegLe_constPoly (n := n) (1 : K) | @insert a s ha ih => rw [Finset.fold_insert ha, Finset.card_insert_of_notMem ha, Nat.succ_mul, add_comm] exact hasDegLe_mul01 (hf a (Finset.mem_insert_self a s)) (ih (fun b hb => hf b (Finset.mem_insert_of_mem hb))) lemma eval01_sum {K : Type*} [CommRing K] {n : ℕ} {α : Type*} (s : Finset α) (f : α → MultiPoly K n) (y : Fin n → Bool) : eval01 (∑ a ∈ s, f a) y = ∑ a ∈ s, eval01 (f a) y := by classical induction s using Finset.induction_on with | empty => simp [eval01_eq_sum_powerset] | @insert a s ha ih => rw [Finset.sum_insert ha, Finset.sum_insert ha, eval01_add, ih] lemma hasDegLe_sum {K : Type*} [CommRing K] {n d : ℕ} {α : Type*} (s : Finset α) (f : α → MultiPoly K n) (hf : ∀ a ∈ s, HasDegLe (f a) d) : HasDegLe (∑ a ∈ s, f a) d := by intro S hS rw [Finset.sum_apply] exact Finset.sum_eq_zero (fun a ha => hf a ha S hS) /-- Every wire polynomial `C.wirePoly r w hw` has degree at most `C.wireDeg k w hw`. -/ lemma AC0pCircuit.hasDegLe_wirePoly {p n k : ℕ} (C : AC0pCircuit p n) (r : RSSeed p n C.numGates k) : ∀ (w : ℕ) (hw : w < n + C.numGates), HasDegLe (C.wirePoly r w hw) (C.wireDeg k w hw) := by intro w induction w using Nat.strong_induction_on with | h w ih => intro hw rw [AC0pCircuit.wirePoly, AC0pCircuit.wireDeg] split_ifs with hlt · exact hasDegLe_varPoly ⟨w, hlt⟩ · set g : Fin C.numGates := ⟨w - n, by omega⟩ set gate := C.gates g set maxIn := gate.inputs.attach.sup (fun u => C.wireDeg k u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega))) have hchild : ∀ u : {x // x ∈ gate.inputs}, HasDegLe (C.wirePoly r u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega))) maxIn := by intro u have hlt_u : u.1.val < w := by have := gate.acyclic u.1 u.2; change u.1.val < n + (w - n) at this; omega exact hasDegLe_mono (ih u.1.val hlt_u _) (Finset.le_sup (f := fun u : {x // x ∈ gate.inputs} => C.wireDeg k u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega))) (Finset.mem_attach _ u)) dsimp only cases hkind : gate.kind · -- orGate apply hasDegLe_sub (hasDegLe_mono (hasDegLe_constPoly (n := n) (1 : ZMod p)) (Nat.zero_le _)) have hfold := hasDegLe_fold_mul01 (Finset.univ : Finset (Fin k)) (d := (p - 1) * maxIn) (fun j => constPoly 1 - pow01 (∑ u ∈ gate.inputs.attach, (r g j u.1) • C.wirePoly r u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega))) (p - 1)) (fun j _ => by apply hasDegLe_sub (hasDegLe_mono (hasDegLe_constPoly (n := n) (1 : ZMod p)) (Nat.zero_le _)) exact hasDegLe_pow01 (hasDegLe_sum _ _ (fun u _ => hasDegLe_smul _ (hchild u))) (p - 1)) simpa [Finset.card_univ, Fintype.card_fin, mul_assoc] using hfold · -- andGate have hfold := hasDegLe_fold_mul01 (Finset.univ : Finset (Fin k)) (d := (p - 1) * maxIn) (fun j => constPoly 1 - pow01 (∑ u ∈ gate.inputs.attach, (r g j u.1) • (constPoly 1 - C.wirePoly r u.1.val (lt_trans (gate.acyclic u.1 u.2) (by omega)))) (p - 1)) (fun j _ => by apply hasDegLe_sub (hasDegLe_mono (hasDegLe_constPoly (n := n) (1 : ZMod p)) (Nat.zero_le _)) exact hasDegLe_pow01 (hasDegLe_sum _ _ (fun u _ => hasDegLe_smul _ (hasDegLe_sub (hasDegLe_mono (hasDegLe_constPoly (n := n) (1 : ZMod p)) (Nat.zero_le _)) (hchild u)))) (p - 1)) simpa [Finset.card_univ, Fintype.card_fin, mul_assoc] using hfold · -- modPGate exact hasDegLe_pow01 (hasDegLe_sum _ _ (fun u _ => hchild u)) (p - 1) · -- notGate have hlt_n : gate.notWire.val < w := by have := gate.notAcyclic; change gate.notWire.val < n + (w - n) at this; omega exact hasDegLe_sub (hasDegLe_mono (hasDegLe_constPoly (n := n) (1 : ZMod p)) (Nat.zero_le _)) (ih _ hlt_n _) /-- Exact kernel count of a nonzero linear form over `ZMod p` on `Fin m → ZMod p`: if `∃ u ∈ S, v u ≠ 0`, then `p * #{a : Fin M → ZMod p | ∑ u ∈ S, a u * v u = 0} = p^M`! -/ lemma card_linear_form_zero_eq {p M : ℕ} [Fact (Nat.Prime p)] (S : Finset (Fin M)) (v : Fin M → ZMod p) (hnz : ∃ u ∈ S, v u ≠ 0) : p * (Finset.univ.filter (fun a : Fin M → ZMod p => ∑ u ∈ S, a u * v u = 0)).card = Fintype.card (Fin M → ZMod p) := by rcases hnz with ⟨u0, hu0S, hvu0⟩ let Z := Finset.univ.filter (fun a : Fin M → ZMod p => ∑ u ∈ S, a u * v u = 0) have hcard_prod : ((Finset.univ : Finset (ZMod p)) ×ˢ Z).card = Fintype.card (Fin M → ZMod p) := by rw [← Finset.card_univ] refine Finset.card_bij (fun (ca : ZMod p × (Fin M → ZMod p)) _ => Function.update ca.2 u0 (ca.2 u0 + ca.1)) ?_ ?_ ?_ · intro _ _; exact Finset.mem_univ _ · intro ⟨c1, a1⟩ h1 ⟨c2, a2⟩ h2 heq simp only [Finset.mem_product, Finset.mem_univ, true_and, Z, Finset.mem_filter] at h1 h2 have hother : ∀ u ≠ u0, a1 u = a2 u := by intro u hu have := congrFun heq u simpa [hu] using this have ha1_eq : a1 u0 * v u0 + ∑ u ∈ S.erase u0, a1 u * v u = 0 := by rwa [Finset.add_sum_erase S (fun u => a1 u * v u) hu0S] have ha2_eq : a2 u0 * v u0 + ∑ u ∈ S.erase u0, a2 u * v u = 0 := by rwa [Finset.add_sum_erase S (fun u => a2 u * v u) hu0S] have hrest : ∑ u ∈ S.erase u0, a1 u * v u = ∑ u ∈ S.erase u0, a2 u * v u := by apply Finset.sum_congr rfl intro u hu; rw [hother u (Finset.mem_erase.mp hu).1] have ha0 : a1 u0 = a2 u0 := by have hmul : (a1 u0 - a2 u0) * v u0 = 0 := by linear_combination ha1_eq - ha2_eq - hrest exact sub_eq_zero.mp ((mul_eq_zero.mp hmul).resolve_right hvu0) have haeq : a1 = a2 := funext (fun u => if hu : u = u0 then hu ▸ ha0 else hother u hu) have h0 := congrFun heq u0 simp only [Function.update_self, ha0] at h0 have hc : c1 = c2 := add_left_cancel h0 exact Prod.ext hc haeq · intro b _ let c : ZMod p := (∑ u ∈ S, b u * v u) * (v u0)⁻¹ let a : Fin M → ZMod p := Function.update b u0 (b u0 - c) refine ⟨(c, a), ?_, ?_⟩ · simp only [Finset.mem_product, Finset.mem_univ, true_and, Z, Finset.mem_filter] rw [← Finset.add_sum_erase S (fun u => a u * v u) hu0S] have hrest : ∑ u ∈ S.erase u0, a u * v u = ∑ u ∈ S.erase u0, b u * v u := by apply Finset.sum_congr rfl intro u hu; simp [a, (Finset.mem_erase.mp hu).1] rw [hrest] simp only [a, Function.update_self, sub_mul, c, mul_assoc, inv_mul_cancel₀ hvu0, mul_one] have hsplit := Finset.add_sum_erase S (fun u => b u * v u) hu0S linear_combination hsplit · funext u by_cases hu : u = u0 · subst hu; simp [a] · simp [a, hu] rw [Finset.card_product, Finset.card_univ, ZMod.card] at hcard_prod exact hcard_prod /-- Independence-over-`k`-copies corollary: for `k` independent random linear forms over `ZMod p`, if `∃ u ∈ S, v u ≠ 0`, then `p^k * #{A : Fin k → Fin M → ZMod p | ∀ j, ∑ u ∈ S, A j u * v u = 0} = |Fin k → Fin M → ZMod p|`! -/ lemma card_k_linear_forms_zero_eq {p M k : ℕ} [Fact (Nat.Prime p)] (S : Finset (Fin M)) (v : Fin M → ZMod p) (hnz : ∃ u ∈ S, v u ≠ 0) : p ^ k * (Finset.univ.filter (fun A : Fin k → Fin M → ZMod p => ∀ j : Fin k, ∑ u ∈ S, A j u * v u = 0)).card = Fintype.card (Fin k → Fin M → ZMod p) := by let Z := Finset.univ.filter (fun a : Fin M → ZMod p => ∑ u ∈ S, a u * v u = 0) have h1 := card_linear_form_zero_eq S v hnz have hfilt : (Finset.univ.filter (fun A : Fin k → Fin M → ZMod p => ∀ j : Fin k, ∑ u ∈ S, A j u * v u = 0)).card = Z.card ^ k := by have hbij : (Finset.univ.filter (fun A : Fin k → Fin M → ZMod p => ∀ j : Fin k, ∑ u ∈ S, A j u * v u = 0)).card = Fintype.card (Fin k → Z) := by rw [← Finset.card_univ] refine Finset.card_bij (fun A hA j => ⟨A j, by simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hA simp only [Z, Finset.mem_filter, Finset.mem_univ, true_and] exact hA j⟩) ?_ ?_ ?_ · intro _ _; exact Finset.mem_univ _ · intro A1 _ A2 _ heq; funext j; exact congrArg Subtype.val (congrFun heq j) · intro B _ refine ⟨fun j => (B j).1, ?_, by funext j; rfl⟩ simp only [Finset.mem_filter, Finset.mem_univ, true_and] intro j have := (B j).2 simp only [Z, Finset.mem_filter, Finset.mem_univ, true_and] at this exact this rw [hbij, Fintype.card_fun, Fintype.card_coe, Fintype.card_fin] rw [hfilt, ← mul_pow, h1] simp [Fintype.card_fin] /-- **HEADLINE THEOREM 7 (Exact Finite-Sum Razborov–Smolensky `AC⁰[p]` Circuit Approximation):** For every prime `p`, every `AC⁰[p]` DAG circuit `C` on `n` Boolean inputs, and every integer parameter `k ≥ 1`, there exists a deterministic multilinear polynomial `P : MultiPoly (ZMod p) n` such that: 1. `HasDegLe P (C.polyDeg k)`, and 2. `p ^ k * |{x ∈ {0,1}ⁿ | eval01 P x ≠ C.evalZMod x}| ≤ C.orAndCount * 2 ^ n`! -/ theorem ac0p_probabilistic_polynomial_approx {p n : ℕ} [Fact (Nat.Prime p)] (C : AC0pCircuit p n) (k : ℕ) : ∃ P : MultiPoly (ZMod p) n, HasDegLe P (C.polyDeg k) ∧ p ^ k * (Finset.univ.filter (fun x : Fin n → Bool => eval01 P x ≠ C.evalZMod x)).card ≤ C.orAndCount * 2 ^ n := by let m := C.numGates -- Helper: Boolean value of wire `w` cast into `ZMod p` let wireVal : (Fin n → Bool) → (w : ℕ) → w < n + m → ZMod p := fun x w hw => if C.evalWire x w hw then 1 else 0 -- Key locality lemma: `C.wirePoly r w hw` depends ONLY on `r g` for `n + g.val ≤ w`! have hlocal : ∀ (w : ℕ) (hw : w < n + m) (r1 r2 : RSSeed p n m k), (∀ g : Fin m, n + g.val ≤ w → r1 g = r2 g) → C.wirePoly r1 w hw = C.wirePoly r2 w hw := by intro w induction w using Nat.strong_induction_on with | h w ih => intro hw r1 r2 hreq rw [AC0pCircuit.wirePoly, AC0pCircuit.wirePoly] split_ifs with hlt · rfl · set g : Fin m := ⟨w - n, by omega⟩ have hrg : r1 g = r2 g := hreq g (by simp [g]; omega) have hchild : ∀ u ∈ (C.gates g).inputs, ∀ hu1 hu2, C.wirePoly r1 u.val hu1 = C.wirePoly r2 u.val hu2 := by intro u hu hu1 hu2 have hlt_u : u.val < w := by have := (C.gates g).acyclic u hu; change u.val < n + (w - n) at this; omega exact ih u.val hlt_u hu1 r1 r2 (fun g' hg' => hreq g' (by omega)) dsimp only change (match (C.gates g).kind with | .orGate => constPoly 1 - (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (r1 g j u.1) • C.wirePoly r1 u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1)) | .andGate => (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (r1 g j u.1) • (constPoly 1 - C.wirePoly r1 u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)))) (p - 1)) | .modPGate => pow01 (∑ u ∈ (C.gates g).inputs.attach, C.wirePoly r1 u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1) | .notGate => constPoly 1 - C.wirePoly r1 (C.gates g).notWire.val (lt_trans (C.gates g).notAcyclic (by omega))) = (match (C.gates g).kind with | .orGate => constPoly 1 - (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (r2 g j u.1) • C.wirePoly r2 u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1)) | .andGate => (Finset.univ : Finset (Fin k)).fold mul01 (constPoly 1) (fun j => constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (r2 g j u.1) • (constPoly 1 - C.wirePoly r2 u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)))) (p - 1)) | .modPGate => pow01 (∑ u ∈ (C.gates g).inputs.attach, C.wirePoly r2 u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1) | .notGate => constPoly 1 - C.wirePoly r2 (C.gates g).notWire.val (lt_trans (C.gates g).notAcyclic (by omega))) cases (C.gates g).kind <;> dsimp only · -- orGate congr 1 apply Finset.fold_congr intro j _ congr 1; congr 1 apply Finset.sum_congr rfl intro u _ rw [hrg, hchild u.1 u.2] · -- andGate apply Finset.fold_congr intro j _ congr 1; congr 1 apply Finset.sum_congr rfl intro u _ rw [hrg, hchild u.1 u.2] · -- modPGate congr 1 apply Finset.sum_congr rfl intro u _ exact hchild u.1 u.2 _ _ · -- notGate congr 1 have hlt_n : (C.gates g).notWire.val < w := by have := (C.gates g).notAcyclic; change (C.gates g).notWire.val < n + (w - n) at this; omega exact ih _ hlt_n _ r1 r2 (fun g' hg' => hreq g' (by omega)) -- Step 1: For EVERY fixed input `x : Fin n → Bool`, bound the number of seeds `r` where SOME gate fails! -- Define `BadAt x g := {r : RSSeed | eval01 (wirePoly r (n + g)) x ≠ wireVal x (n + g) ∧ ∀ w < n + g, eval01 (wirePoly r w) x = wireVal x w}` have hbad_per_x : ∀ x : Fin n → Bool, p ^ k * (Finset.univ.filter (fun r : RSSeed p n m k => eval01 (C.wirePoly r C.outWire.val C.outWire.isLt) x ≠ C.evalZMod x)).card ≤ C.orAndCount * Fintype.card (RSSeed p n m k) := by intro x let BadGate : Fin m → Finset (RSSeed p n m k) := fun g => Finset.univ.filter (fun r => eval01 (C.wirePoly r (n + g.val) (by omega)) x ≠ wireVal x (n + g.val) (by omega) ∧ ∀ (w : ℕ) (hw : w < n + g.val), eval01 (C.wirePoly r w (by omega)) x = wireVal x w (by omega)) let orAndGates := Finset.univ.filter (fun g : Fin m => (C.gates g).kind = .orGate ∨ (C.gates g).kind = .andGate) -- Every seed `r` where the output wire fails MUST fail at a minimal wire `w₀ = n + g₀`, -- and `g₀` MUST be an `orGate` or `andGate` (since `notGate` and `modPGate` have ZERO error!). have hcov : Finset.univ.filter (fun r : RSSeed p n m k => eval01 (C.wirePoly r C.outWire.val C.outWire.isLt) x ≠ C.evalZMod x) ⊆ orAndGates.biUnion BadGate := by intro r hr simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hr -- Consider the nonempty set of failing wires `w < n + m` let failWires := (Finset.range (n + m)).filter (fun w => ∃ hw : w < n + m, eval01 (C.wirePoly r w hw) x ≠ wireVal x w hw) have hfail_ne : failWires.Nonempty := by refine ⟨C.outWire.val, ?_⟩ simp only [failWires, Finset.mem_filter, Finset.mem_range] exact ⟨C.outWire.isLt, C.outWire.isLt, hr⟩ let w0 := failWires.min' hfail_ne have hw0_mem : w0 ∈ failWires := Finset.min'_mem failWires hfail_ne have hw0_lt : w0 < n + m := (Finset.mem_range.mp (Finset.mem_filter.mp hw0_mem).1) have hw0_fail : eval01 (C.wirePoly r w0 hw0_lt) x ≠ wireVal x w0 hw0_lt := by rcases (Finset.mem_filter.mp hw0_mem).2 with ⟨_, h⟩; exact h -- `w0` cannot be an input wire (`w0 < n`)! have hw0_ge_n : n ≤ w0 := by by_contra hlt; push Not at hlt apply hw0_fail rw [AC0pCircuit.wirePoly, dif_pos hlt, eval01_varPoly] simp only [wireVal] rw [AC0pCircuit.evalWire, dif_pos hlt] -- All strictly earlier wires `w < w0` evaluate correctly! have hearlier : ∀ (w : ℕ) (hw : w < w0), eval01 (C.wirePoly r w (by omega)) x = wireVal x w (by omega) := by intro w hw by_contra hne have hmem : w ∈ failWires := by simp only [failWires, Finset.mem_filter, Finset.mem_range] exact ⟨by omega, by omega, hne⟩ have hle := Finset.min'_le failWires w hmem omega let g0 : Fin m := ⟨w0 - n, by omega⟩ have hw0_eq : n + g0.val = w0 := by simp [g0]; omega have hcongrP : ∀ w1 w2 (h1 : w1 < n + m) (h2 : w2 < n + m), w1 = w2 → eval01 (C.wirePoly r w1 h1) x = eval01 (C.wirePoly r w2 h2) x := by rintro w _ h1 h2 rfl; rfl have hcongrV : ∀ w1 w2 (h1 : w1 < n + m) (h2 : w2 < n + m), w1 = w2 → wireVal x w1 h1 = wireVal x w2 h2 := by rintro w _ h1 h2 rfl; rfl rw [Finset.mem_biUnion] refine ⟨g0, ?_, ?_⟩ · -- Show `g0 ∈ orAndGates` (i.e. neither `notGate` nor `modPGate`!) simp only [orAndGates, Finset.mem_filter, Finset.mem_univ, true_and] cases hkind : (C.gates g0).kind · left; rfl · right; rfl · -- modPGate: exact by Fermat's Little Theorem! exfalso; apply hw0_fail rw [hcongrP w0 (n + g0.val) hw0_lt (by omega) hw0_eq.symm, hcongrV w0 (n + g0.val) hw0_lt (by omega) hw0_eq.symm, AC0pCircuit.wirePoly_gate, hkind] rw [eval01_pow01, eval01_sum] have hsum_eq : ∑ u ∈ (C.gates g0).inputs.attach, eval01 (C.wirePoly r u.1.val (lt_trans ((C.gates g0).acyclic u.1 u.2) (by omega))) x = ((∑ u ∈ (C.gates g0).inputs.attach, if C.evalWire x u.1.val (lt_trans ((C.gates g0).acyclic u.1 u.2) (by omega)) then 1 else 0 : ℕ) : ZMod p) := by rw [Nat.cast_sum] apply Finset.sum_congr rfl intro u _ have hlt_u : u.1.val < w0 := by have := (C.gates g0).acyclic u.1 u.2; omega rw [hearlier u.1.val hlt_u] simp only [wireVal] cases C.evalWire x u.1.val (lt_trans ((C.gates g0).acyclic u.1 u.2) (by omega)) <;> simp rw [hsum_eq] simp only [wireVal] rw [AC0pCircuit.evalWire_gate, hkind] set S := ∑ u ∈ (C.gates g0).inputs.attach, if C.evalWire x u.1.val (lt_trans ((C.gates g0).acyclic u.1 u.2) (by omega)) then 1 else 0 by_cases hdiv : S % p = 0 · simp only [hdiv, ne_eq, not_true_eq_false, decide_false, Bool.false_eq_true, ↓reduceIte] have h0 : (S : ZMod p) = 0 := (ZMod.natCast_eq_zero_iff S p).mpr (Nat.dvd_of_mod_eq_zero hdiv) have hp_pos : 0 < p - 1 := Nat.sub_pos_of_lt (Fact.out : Nat.Prime p).one_lt rw [h0, zero_pow (Nat.ne_of_gt hp_pos)] · simp only [hdiv, ne_eq, not_false_eq_true, decide_true, ↓reduceIte] have hnz : (S : ZMod p) ≠ 0 := by intro h0 exact hdiv (Nat.mod_eq_zero_of_dvd ((ZMod.natCast_eq_zero_iff S p).mp h0)) exact ZMod.pow_card_sub_one_eq_one hnz · -- notGate: exact! exfalso; apply hw0_fail rw [hcongrP w0 (n + g0.val) hw0_lt (by omega) hw0_eq.symm, hcongrV w0 (n + g0.val) hw0_lt (by omega) hw0_eq.symm, AC0pCircuit.wirePoly_gate, hkind, eval01_sub, eval01_constPoly] have hlt_n : (C.gates g0).notWire.val < w0 := by have := (C.gates g0).notAcyclic; omega rw [hearlier _ hlt_n] simp only [wireVal] rw [AC0pCircuit.evalWire_gate, hkind] cases C.evalWire x (C.gates g0).notWire.val (lt_trans (C.gates g0).notAcyclic (by omega)) <;> simp · -- Show `r ∈ BadGate g0` simp only [BadGate, Finset.mem_filter, Finset.mem_univ, true_and] refine ⟨?_, ?_⟩ · rw [hcongrP (n + g0.val) w0 _ hw0_lt hw0_eq, hcongrV (n + g0.val) w0 _ hw0_lt hw0_eq] exact hw0_fail · intro w hw; exact hearlier w (by omega) -- Now bound `p^k * (BadGate g).card ≤ Fintype.card (RSSeed p n m k)` for every `g ∈ orAndGates`! have hbad_gate : ∀ g ∈ orAndGates, p ^ k * (BadGate g).card ≤ Fintype.card (RSSeed p n m k) := by intro g hg simp only [orAndGates, Finset.mem_filter, Finset.mem_univ, true_and] at hg -- Split `RSSeed p n m k` as `(Fin k → Fin (n + m) → ZMod p) × ({g' : Fin m // g' ≠ g} → Fin k → Fin (n + m) → ZMod p)`! let Rest := {g' : Fin m // g' ≠ g} → Fin k → Fin (n + m) → ZMod p let Local := Fin k → Fin (n + m) → ZMod p let combine : Local × Rest → RSSeed p n m k := fun ⟨loc, rst⟩ g' => if h : g' = g then loc else rst ⟨g', h⟩ let split : RSSeed p n m k → Local × Rest := fun r => (r g, fun g' => r g'.1) have hbij_seed : Function.Bijective combine := by refine Function.bijective_iff_has_inverse.mpr ⟨split, ?_, ?_⟩ · rintro ⟨loc, rst⟩ ext j u · simp [combine, split] · simp [combine, split, j.2] · intro r; funext g' by_cases h : g' = g · subst h; simp [combine, split] · simp [combine, split, h] -- For every fixed `rst : Rest`, let `GoodSlice rst` be `{loc : Local | combine (loc, rst) ∈ BadGate g}`! -- Notice whether `combine (loc, rst)` agrees on all wires `w < n + g.val` does NOT depend on `loc`! -- And when it DOES agree on all wires `w < n + g.val`, we get an exact bound `p^k * |GoodSlice rst| ≤ |Local|`! have hslice : ∀ rst : Rest, p ^ k * (Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g)).card ≤ Fintype.card Local := by intro rst -- Case split on whether all inputs agree (for a dummy `loc0 = 0`) by_cases hall : ∀ (w : ℕ) (hw : w < n + g.val), eval01 (C.wirePoly (combine (0, rst)) w (by omega)) x = wireVal x w (by omega) · -- Every `loc` agrees on all `w < n + g.val` too (by `hlocal`)! have hchild_val : ∀ (loc : Local) (u : {v // v ∈ (C.gates g).inputs}), eval01 (C.wirePoly (combine (loc, rst)) u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) x = wireVal x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) := by intro loc u have hlt_u : u.1.val < n + g.val := (C.gates g).acyclic u.1 u.2 have hloc_eq : C.wirePoly (combine (loc, rst)) u.1.val (by omega) = C.wirePoly (combine (0, rst)) u.1.val (by omega) := by apply hlocal; intro g' hg' have hne : g' ≠ g := by intro h; subst h; omega simp [combine, hne] rw [hloc_eq, hall u.1.val hlt_u] rcases hg with hor | hand · -- `orGate`: by_cases hex : ∃ u ∈ (C.gates g).inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true · -- True input exists: gate fails ONLY if ALL `k` linear forms vanish! let v : Fin (n + m) → ZMod p := fun u => if hu : u ∈ (C.gates g).inputs then wireVal x u.val (lt_trans ((C.gates g).acyclic u hu) (by omega)) else 0 have hnz : ∃ u ∈ (C.gates g).inputs, v u ≠ 0 := by rcases hex with ⟨u, _, htrue⟩ exact ⟨u.1, u.2, by simp [v, u.2, wireVal, htrue]⟩ have hsub : Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g) ⊆ Finset.univ.filter (fun loc : Local => ∀ j : Fin k, ∑ u ∈ (C.gates g).inputs, loc j u * v u = 0) := by intro loc hloc simp only [Finset.mem_filter, Finset.mem_univ, true_and, BadGate] at hloc ⊢ -- Evaluate the `orGate` polynomial at `x`: have hev_g : eval01 (C.wirePoly (combine (loc, rst)) (n + g.val) (by omega)) x = 1 - ∏ j : Fin k, (1 - (∑ u ∈ (C.gates g).inputs, loc j u * v u) ^ (p - 1)) := by rw [AC0pCircuit.wirePoly_gate, hor] rw [eval01_sub, eval01_constPoly, eval01_fold_mul01] congr 1; apply Finset.prod_congr rfl; intro j _ rw [eval01_sub, eval01_constPoly, eval01_pow01, eval01_sum] congr 1; congr 1 rw [← Finset.sum_attach (C.gates g).inputs (fun u => loc j u * v u)] apply Finset.sum_congr rfl intro u _ rw [eval01_smul, hchild_val loc u] simp [combine, v, u.2] have hval_g : wireVal x (n + g.val) (by omega) = 1 := by simp only [wireVal] rw [AC0pCircuit.evalWire_gate, hor] simp only [hex, decide_true, ↓reduceIte] intro j by_contra hsum_nz apply hloc.1 rw [hev_g, hval_g] have hterm0 : (1 : ZMod p) - (∑ u ∈ (C.gates g).inputs, loc j u * v u) ^ (p - 1) = 0 := by rw [ZMod.pow_card_sub_one_eq_one hsum_nz, sub_self] have hprod0 : ∏ j' : Fin k, ((1 : ZMod p) - (∑ u ∈ (C.gates g).inputs, loc j' u * v u) ^ (p - 1)) = 0 := Finset.prod_eq_zero (Finset.mem_univ j) hterm0 rw [hprod0, sub_zero] calc p ^ k * (Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g)).card ≤ p ^ k * (Finset.univ.filter (fun loc : Local => ∀ j : Fin k, ∑ u ∈ (C.gates g).inputs, loc j u * v u = 0)).card := Nat.mul_le_mul_left _ (Finset.card_le_card hsub) _ = Fintype.card Local := card_k_linear_forms_zero_eq (C.gates g).inputs v hnz · -- All inputs are `false`: `orGate` polynomial evaluates to `0` ALWAYS (ZERO error)! have hemp : Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g) = ∅ := by rw [Finset.eq_empty_iff_forall_notMem] intro loc hloc simp only [Finset.mem_filter, Finset.mem_univ, true_and, BadGate] at hloc apply hloc.1 rw [AC0pCircuit.wirePoly_gate, hor] rw [eval01_sub, eval01_constPoly, eval01_fold_mul01] have hall0 : ∀ u : {v // v ∈ (C.gates g).inputs}, eval01 (C.wirePoly (combine (loc, rst)) u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) x = 0 := by intro u; rw [hchild_val loc u] have hf : C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = false := by by_contra ht have htrue : C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true := by cases h : C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) <;> simp_all exact hex ⟨u, Finset.mem_attach _ u, htrue⟩ simp [wireVal, hf] have hprod1 : ∏ j : Fin k, eval01 (constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (combine (loc, rst) g j u.1) • C.wirePoly (combine (loc, rst)) u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) (p - 1)) x = 1 := by apply Finset.prod_eq_one; intro j _ rw [eval01_sub, eval01_constPoly, eval01_pow01, eval01_sum] have hs0 : ∑ u ∈ (C.gates g).inputs.attach, eval01 ((combine (loc, rst) g j u.1) • C.wirePoly (combine (loc, rst)) u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega))) x = 0 := Finset.sum_eq_zero (fun u _ => by rw [eval01_smul, hall0 u, mul_zero]) have hp_pos : 0 < p - 1 := Nat.sub_pos_of_lt (Fact.out : Nat.Prime p).one_lt rw [hs0, zero_pow (Nat.ne_of_gt hp_pos), sub_zero] rw [hprod1, sub_self] simp only [wireVal] rw [AC0pCircuit.evalWire_gate, hor] simp only [hex, decide_false, Bool.false_eq_true, ↓reduceIte] simp [hemp] · -- `andGate` (dual of `orGate`!) by_cases hallT : ∀ u ∈ (C.gates g).inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true · -- All inputs `true`: `1 - input = 0`, so `andGate` polynomial evaluates to `1` ALWAYS (ZERO error)! have hemp : Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g) = ∅ := by rw [Finset.eq_empty_iff_forall_notMem] intro loc hloc simp only [Finset.mem_filter, Finset.mem_univ, true_and, BadGate] at hloc apply hloc.1 rw [AC0pCircuit.wirePoly_gate, hand] rw [eval01_fold_mul01] have hprod1 : ∏ j : Fin k, eval01 (constPoly 1 - pow01 (∑ u ∈ (C.gates g).inputs.attach, (combine (loc, rst) g j u.1) • (constPoly 1 - C.wirePoly (combine (loc, rst)) u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)))) (p - 1)) x = 1 := by apply Finset.prod_eq_one; intro j _ rw [eval01_sub, eval01_constPoly, eval01_pow01, eval01_sum] have hs0 : ∑ u ∈ (C.gates g).inputs.attach, eval01 ((combine (loc, rst) g j u.1) • (constPoly 1 - C.wirePoly (combine (loc, rst)) u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)))) x = 0 := Finset.sum_eq_zero (fun u _ => by rw [eval01_smul, eval01_sub, eval01_constPoly, hchild_val loc u] simp [wireVal, hallT u (Finset.mem_attach _ u)]) have hp_pos : 0 < p - 1 := Nat.sub_pos_of_lt (Fact.out : Nat.Prime p).one_lt rw [hs0, zero_pow (Nat.ne_of_gt hp_pos), sub_zero] rw [hprod1] simp only [wireVal] rw [AC0pCircuit.evalWire_gate, hand] have hdec : decide (∀ u ∈ (C.gates g).inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true) = true := decide_eq_true_iff.mpr hallT rw [hdec]; simp simp [hemp] · -- Some input is `false`: `v u = 1 - wireVal u` is nonzero at that input! push Not at hallT rcases hallT with ⟨u0, _, hf0⟩ let v : Fin (n + m) → ZMod p := fun u => if hu : u ∈ (C.gates g).inputs then 1 - wireVal x u.val (lt_trans ((C.gates g).acyclic u hu) (by omega)) else 0 have hnz : ∃ u ∈ (C.gates g).inputs, v u ≠ 0 := ⟨u0.1, u0.2, by simp [v, u0.2, wireVal, hf0]⟩ have hsub : Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g) ⊆ Finset.univ.filter (fun loc : Local => ∀ j : Fin k, ∑ u ∈ (C.gates g).inputs, loc j u * v u = 0) := by intro loc hloc simp only [Finset.mem_filter, Finset.mem_univ, true_and, BadGate] at hloc ⊢ have hev_g : eval01 (C.wirePoly (combine (loc, rst)) (n + g.val) (by omega)) x = ∏ j : Fin k, (1 - (∑ u ∈ (C.gates g).inputs, loc j u * v u) ^ (p - 1)) := by rw [AC0pCircuit.wirePoly_gate, hand] rw [eval01_fold_mul01] apply Finset.prod_congr rfl; intro j _ rw [eval01_sub, eval01_constPoly, eval01_pow01, eval01_sum] congr 1; congr 1 rw [← Finset.sum_attach (C.gates g).inputs (fun u => loc j u * v u)] apply Finset.sum_congr rfl intro u _ rw [eval01_smul, eval01_sub, eval01_constPoly, hchild_val loc u] simp [combine, v, u.2] have hval_g : wireVal x (n + g.val) (by omega) = 0 := by simp only [wireVal] rw [AC0pCircuit.evalWire_gate, hand] have hnot : ¬(∀ u ∈ (C.gates g).inputs.attach, C.evalWire x u.1.val (lt_trans ((C.gates g).acyclic u.1 u.2) (by omega)) = true) := fun h => hf0 (h u0 (Finset.mem_attach _ u0)) simp only [hnot, decide_false, Bool.false_eq_true, ↓reduceIte] intro j by_contra hsum_nz apply hloc.1 rw [hev_g, hval_g] have hterm0 : (1 : ZMod p) - (∑ u ∈ (C.gates g).inputs, loc j u * v u) ^ (p - 1) = 0 := by rw [ZMod.pow_card_sub_one_eq_one hsum_nz, sub_self] exact Finset.prod_eq_zero (Finset.mem_univ j) hterm0 calc p ^ k * (Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g)).card ≤ p ^ k * (Finset.univ.filter (fun loc : Local => ∀ j : Fin k, ∑ u ∈ (C.gates g).inputs, loc j u * v u = 0)).card := Nat.mul_le_mul_left _ (Finset.card_le_card hsub) _ = Fintype.card Local := card_k_linear_forms_zero_eq (C.gates g).inputs v hnz · -- `¬hall`: no `loc` can be in `BadGate g`! have hemp : Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g) = ∅ := by rw [Finset.eq_empty_iff_forall_notMem] intro loc hloc simp only [Finset.mem_filter, Finset.mem_univ, true_and, BadGate] at hloc apply hall intro w hw have hloc_eq : C.wirePoly (combine (0, rst)) w (by omega) = C.wirePoly (combine (loc, rst)) w (by omega) := by apply hlocal; intro g' hg' have hne : g' ≠ g := by intro h; subst h; omega simp [combine, hne] rw [hloc_eq] exact hloc.2 w hw simp [hemp] -- Sum `hslice` over all `rst : Rest`! have hcard_bad : (BadGate g).card = ∑ rst : Rest, (Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g)).card := by have hbij_bad : (BadGate g).card = (Finset.univ.filter (fun p : Local × Rest => combine p ∈ BadGate g)).card := by refine (Finset.card_bij (fun p _ => combine p) ?_ ?_ ?_).symm · intro p hp; exact (Finset.mem_filter.mp hp).2 · intro p1 _ p2 _ heq; exact hbij_seed.1 heq · intro r hr rcases hbij_seed.2 r with ⟨p, rfl⟩ exact ⟨p, by simp [hr], rfl⟩ rw [hbij_bad] simp_rw [Finset.card_filter] rw [Fintype.sum_prod_type_right] have hcard_tot : Fintype.card (RSSeed p n m k) = Fintype.card Rest * Fintype.card Local := by rw [mul_comm, ← Fintype.card_prod] exact (Fintype.card_of_bijective hbij_seed).symm rw [hcard_bad, Finset.mul_sum, hcard_tot] calc ∑ rst : Rest, p ^ k * (Finset.univ.filter (fun loc : Local => combine (loc, rst) ∈ BadGate g)).card ≤ ∑ _rst : Rest, Fintype.card Local := Finset.sum_le_sum (fun rst _ => hslice rst) _ = Fintype.card Rest * Fintype.card Local := by simp -- Combine union bound over `orAndGates` calc p ^ k * (Finset.univ.filter (fun r : RSSeed p n m k => eval01 (C.wirePoly r C.outWire.val C.outWire.isLt) x ≠ C.evalZMod x)).card ≤ p ^ k * (orAndGates.biUnion BadGate).card := Nat.mul_le_mul_left _ (Finset.card_le_card hcov) _ ≤ p ^ k * ∑ g ∈ orAndGates, (BadGate g).card := Nat.mul_le_mul_left _ Finset.card_biUnion_le _ = ∑ g ∈ orAndGates, p ^ k * (BadGate g).card := Finset.mul_sum _ _ _ _ ≤ ∑ _g ∈ orAndGates, Fintype.card (RSSeed p n m k) := Finset.sum_le_sum (fun g hg => hbad_gate g hg) _ = C.orAndCount * Fintype.card (RSSeed p n m k) := by simp only [Finset.sum_const, smul_eq_mul, AC0pCircuit.orAndCount, orAndGates] rfl -- Step 2: Average over all `r : RSSeed p n m k` by swapping sums (`Finset.sum_comm`)! have hsum_all : ∑ r : RSSeed p n m k, p ^ k * (Finset.univ.filter (fun x : Fin n → Bool => eval01 (C.wirePoly r C.outWire.val C.outWire.isLt) x ≠ C.evalZMod x)).card ≤ ∑ _r : RSSeed p n m k, C.orAndCount * 2 ^ n := by have hswap : ∑ r : RSSeed p n m k, p ^ k * (Finset.univ.filter (fun x : Fin n → Bool => eval01 (C.wirePoly r C.outWire.val C.outWire.isLt) x ≠ C.evalZMod x)).card = ∑ x : Fin n → Bool, p ^ k * (Finset.univ.filter (fun r : RSSeed p n m k => eval01 (C.wirePoly r C.outWire.val C.outWire.isLt) x ≠ C.evalZMod x)).card := by simp_rw [← Finset.mul_sum, Finset.card_filter] congr 1 exact Finset.sum_comm rw [hswap] calc ∑ x : Fin n → Bool, p ^ k * (Finset.univ.filter (fun r : RSSeed p n m k => eval01 (C.wirePoly r C.outWire.val C.outWire.isLt) x ≠ C.evalZMod x)).card ≤ ∑ _x : Fin n → Bool, C.orAndCount * Fintype.card (RSSeed p n m k) := Finset.sum_le_sum (fun x _ => hbad_per_x x) _ = 2 ^ n * (C.orAndCount * Fintype.card (RSSeed p n m k)) := by simp [Fintype.card_bool, Fintype.card_fin] _ = ∑ _r : RSSeed p n m k, C.orAndCount * 2 ^ n := by simp only [Finset.sum_const, Finset.card_univ, smul_eq_mul]; ring -- Pigeonhole: there exists `r0 : RSSeed p n m k` attaining `≤ C.orAndCount * 2^n`! have hne : (Finset.univ : Finset (RSSeed p n m k)).Nonempty := ⟨0, Finset.mem_univ _⟩ by_contra hnone push Not at hnone have hstrict : ∑ _r : RSSeed p n m k, C.orAndCount * 2 ^ n < ∑ r : RSSeed p n m k, p ^ k * (Finset.univ.filter (fun x : Fin n → Bool => eval01 (C.wirePoly r C.outWire.val C.outWire.isLt) x ≠ C.evalZMod x)).card := by apply Finset.sum_lt_sum_of_nonempty hne intro r _ exact hnone (C.wirePoly r C.outWire.val C.outWire.isLt) (C.hasDegLe_wirePoly r C.outWire.val C.outWire.isLt) omega /-- **HEADLINE THEOREM 8A (Unconditional Non-Asymptotic `AC⁰[p]` Circuit Lower Bound for `PARITY_n`, Odd Prime `p`):** If an `AC⁰[p]` DAG circuit `C` over odd prime `p` computes `PARITY_n` (`|x| % 2 = 1`), then for every approximation parameter `k` with `C.polyDeg k < n`: `p ^ k * raoBound n (n - C.polyDeg k - 1) ≤ C.orAndCount * 2 ^ n`! -/ theorem ac0p_parity_lower_bound {p n k : ℕ} [Fact (Nat.Prime p)] (hp_odd : p ≠ 2) (hn : 1 ≤ n) (C : AC0pCircuit p n) (hdeg : C.polyDeg k < n) (hcomp : ∀ x : Fin n → Bool, C.evalBool x = decide (hammingWeight x % 2 = 1)) : p ^ k * raoBound n (n - C.polyDeg k - 1) ≤ C.orAndCount * 2 ^ n := by rcases ac0p_probabilistic_polynomial_approx C k with ⟨P, hPdeg, hPerr⟩ -- Transform `P` (`{0, 1}`-valued) into `Q = 1 - 2 • P` (`{1, -1}`-valued): `Q(x) = (-1)^|x|` wherever `P(x) = C.evalZMod x`! let Q : MultiPoly (ZMod p) n := constPoly 1 - (2 : ZMod p) • P have hQdeg : HasDegLe Q (C.polyDeg k) := hasDegLe_sub (hasDegLe_mono (hasDegLe_constPoly 1) (Nat.zero_le _)) (hasDegLe_smul _ hPdeg) have h2nz : (2 : ZMod p) ≠ 0 := by intro h0 have hdvd : p ∣ 2 := (ZMod.natCast_eq_zero_iff 2 p).mp (by simpa using h0) have hprime : Nat.Prime p := Fact.out have hle : p ≤ 2 := Nat.le_of_dvd (by omega) hdvd have hge : 2 ≤ p := hprime.two_le omega have hω0 : (-1 : ZMod p) ≠ 0 := by intro h; apply h2nz have h1 : (1 : ZMod p) = 0 := by simpa using congrArg Neg.neg h calc (2 : ZMod p) = 1 + 1 := by ring _ = 0 := by simp [h1] have hω1 : (-1 : ZMod p) ≠ 1 := fun h => h2nz (by linear_combination -h) have hgram := universal_gram_smolensky_bound hn hdeg hω0 hω1 Q hQdeg have hsub : Finset.univ.filter (fun x : Fin n → Bool => eval01 Q x ≠ prodChar (-1 : ZMod p) x) ⊆ Finset.univ.filter (fun x : Fin n → Bool => eval01 P x ≠ C.evalZMod x) := by intro x hx simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢ intro hPe apply hx simp only [Q, eval01_sub, eval01_constPoly, eval01_smul, hPe, AC0pCircuit.evalZMod, hcomp x, prodChar] have hmod2 : hammingWeight x % 2 = 0 ∨ hammingWeight x % 2 = 1 := by omega rcases hmod2 with heven | hodd · simp only [heven, zero_ne_one, decide_false, Bool.false_eq_true, ↓reduceIte, mul_zero, sub_zero] have hdiv : hammingWeight x = 2 * (hammingWeight x / 2) := by omega rw [hdiv, pow_mul]; norm_num · simp only [hodd, decide_true, ↓reduceIte, mul_one] have hdiv : hammingWeight x = 2 * (hammingWeight x / 2) + 1 := by omega rw [hdiv, pow_succ, pow_mul] norm_num calc p ^ k * raoBound n (n - C.polyDeg k - 1) ≤ p ^ k * (Finset.univ.filter (fun x : Fin n → Bool => eval01 Q x ≠ prodChar (-1 : ZMod p) x)).card := Nat.mul_le_mul_left _ hgram _ ≤ p ^ k * (Finset.univ.filter (fun x : Fin n → Bool => eval01 P x ≠ C.evalZMod x)).card := Nat.mul_le_mul_left _ (Finset.card_le_card hsub) _ ≤ C.orAndCount * 2 ^ n := hPerr /-- **HEADLINE THEOREM 8B (Unconditional Non-Asymptotic `AC⁰[2]` Circuit Lower Bound for `MOD₃`):** If an `AC⁰[2]` DAG circuit `C` computes `MOD₃` (`|x| % 3 ≠ 0`), then for every `k` with `C.polyDeg k + 1 < n`: `2 ^ k * raoBound n (n - C.polyDeg k - 2) ≤ 2 * C.orAndCount * 2 ^ n`! -/ theorem ac02_mod3_lower_bound {n k : ℕ} (hn : 1 ≤ n) (C : AC0pCircuit 2 n) (hdeg : C.polyDeg k + 1 < n) (hcomp : ∀ x : Fin n → Bool, C.evalBool x = decide (hammingWeight x % 3 ≠ 0)) : 2 ^ k * raoBound n (n - C.polyDeg k - 2) ≤ 2 * C.orAndCount * 2 ^ n := by rcases ac0p_probabilistic_polynomial_approx C k with ⟨P, hPdeg, hPerr⟩ have hmod3 := mod3_over_F2_sharp_error_bound hn hdeg P hPdeg have hfun_eq : ∀ x : Fin n → Bool, C.evalZMod x = mod3Bool x := by intro x simp only [AC0pCircuit.evalZMod, hcomp x, mod3Bool] by_cases h : hammingWeight x % 3 = 0 <;> simp [h] simp_rw [hfun_eq] at hPerr calc 2 ^ k * raoBound n (n - C.polyDeg k - 2) ≤ 2 ^ k * (2 * (Finset.univ.filter (fun x : Fin n → Bool => eval01 P x ≠ mod3Bool x)).card) := Nat.mul_le_mul_left _ hmod3 _ = 2 * (2 ^ k * (Finset.univ.filter (fun x : Fin n → Bool => eval01 P x ≠ mod3Bool x)).card) := by ring _ ≤ 2 * (C.orAndCount * 2 ^ n) := Nat.mul_le_mul_left 2 hPerr _ = 2 * C.orAndCount * 2 ^ n := by ring /-- **HEADLINE THEOREM 8C (Unconditional Non-Asymptotic `AC⁰[p]` Circuit Lower Bound for `THR_t^n` & `MAJ_n`, Every Prime `p`):** For *every* prime `p` (including `p = 2`), if an `AC⁰[p]` DAG circuit `C` computes `THR_t^n` (`1 ≤ t ≤ n`), then for every `k` with `1 ≤ C.polyDeg k ≤ m := min (t - 1) (n - t)`: `p ^ k * sharpThrBound n m (C.polyDeg k) ≤ C.orAndCount * 2 ^ n`! -/ theorem ac0p_threshold_lower_bound {p n t k : ℕ} [Fact (Nat.Prime p)] (ht1 : 1 ≤ t) (htn : t ≤ n) (C : AC0pCircuit p n) (hdeg1 : 1 ≤ C.polyDeg k) (hdegm : C.polyDeg k ≤ min (t - 1) (n - t)) (hcomp : ∀ x : Fin n → Bool, C.evalBool x = decide (t ≤ hammingWeight x)) : p ^ k * sharpThrBound n (min (t - 1) (n - t)) (C.polyDeg k) ≤ C.orAndCount * 2 ^ n := by rcases ac0p_probabilistic_polynomial_approx C k with ⟨P, hPdeg, hPerr⟩ have hthr := sharp_threshold_polynomial_error_bound ht1 htn hdeg1 hdegm P hPdeg have hfun_eq : ∀ x : Fin n → Bool, C.evalZMod x = thrFun t x := by intro x simp only [AC0pCircuit.evalZMod, hcomp x, thrFun] by_cases h : t ≤ hammingWeight x <;> simp [h] simp_rw [hfun_eq] at hPerr exact (Nat.mul_le_mul_left (p ^ k) hthr).trans hPerr /-! ## Section 3 (Pillar 3): Exact Karchmer–Wigderson Game Equivalences (Size & Depth), ## Exact De Morgan Duality, and Monotone Composition Upper Bounds -/ /-- A monotone Boolean formula over `n` variables (`∧`, `∨`, positive variables only). -/ inductive MonotoneFormula (n : ℕ) where | var (i : Fin n) | and (l r : MonotoneFormula n) | or (l r : MonotoneFormula n) namespace MonotoneFormula /-- Evaluation of a monotone formula on `x : Fin n → Bool`. -/ def eval {n : ℕ} : MonotoneFormula n → (Fin n → Bool) → Bool | var i, x => x i | and l r, x => l.eval x && r.eval x | or l r, x => l.eval x || r.eval x /-- Leaf-count (formula size) of a monotone formula. -/ def leafSize {n : ℕ} : MonotoneFormula n → ℕ | var _ => 1 | and l r => l.leafSize + r.leafSize | or l r => l.leafSize + r.leafSize /-- Depth of a monotone formula (0 for a variable leaf). -/ def depth {n : ℕ} : MonotoneFormula n → ℕ | var _ => 0 | and l r => max l.depth r.depth + 1 | or l r => max l.depth r.depth + 1 /-- Number of leaves labeled by variable `i`. -/ def varCount {n : ℕ} : MonotoneFormula n → Fin n → ℕ | var j, i => if j = i then 1 else 0 | and l r, i => l.varCount i + r.varCount i | or l r, i => l.varCount i + r.varCount i lemma sum_varCount {n : ℕ} (F : MonotoneFormula n) : ∑ i : Fin n, F.varCount i = F.leafSize := by induction F with | var j => simp [varCount, leafSize] | and l r ihl ihr => simp [varCount, leafSize, Finset.sum_add_distrib, ihl, ihr] | or l r ihl ihr => simp [varCount, leafSize, Finset.sum_add_distrib, ihl, ihr] lemma leafSize_le_two_pow_depth {n : ℕ} (F : MonotoneFormula n) : F.leafSize ≤ 2 ^ F.depth := by induction F with | var _ => simp [leafSize, depth] | and l r ihl ihr => simp only [leafSize, depth, pow_succ] have h1 : 2 ^ l.depth ≤ 2 ^ max l.depth r.depth := Nat.pow_le_pow_right (by omega) (le_max_left _ _) have h2 : 2 ^ r.depth ≤ 2 ^ max l.depth r.depth := Nat.pow_le_pow_right (by omega) (le_max_right _ _) omega | or l r ihl ihr => simp only [leafSize, depth, pow_succ] have h1 : 2 ^ l.depth ≤ 2 ^ max l.depth r.depth := Nat.pow_le_pow_right (by omega) (le_max_left _ _) have h2 : 2 ^ r.depth ≤ 2 ^ max l.depth r.depth := Nat.pow_le_pow_right (by omega) (le_max_right _ _) omega /-- Monotonicity of `MonotoneFormula.eval`. -/ lemma eval_monotone {n : ℕ} (F : MonotoneFormula n) {x y : Fin n → Bool} (hle : ∀ i, x i = true → y i = true) (hx : F.eval x = true) : F.eval y = true := by induction F with | var i => exact hle i hx | and l r ihl ihr => simp only [eval, Bool.and_eq_true] at hx ⊢ exact ⟨ihl hx.1, ihr hx.2⟩ | or l r ihl ihr => simp only [eval, Bool.or_eq_true] at hx ⊢ rcases hx with hl | hr · left; exact ihl hl · right; exact ihr hr /-- De Morgan dual of a monotone formula (swaps `∧ ↔ ∨`). -/ def dual {n : ℕ} : MonotoneFormula n → MonotoneFormula n | var i => var i | and l r => or l.dual r.dual | or l r => and l.dual r.dual lemma eval_dual {n : ℕ} (F : MonotoneFormula n) (x : Fin n → Bool) : F.dual.eval x = !(F.eval (fun i => !x i)) := by induction F with | var i => simp [dual, eval] | and l r ihl ihr => simp [dual, eval, ihl, ihr] | or l r ihl ihr => simp [dual, eval, ihl, ihr] lemma leafSize_dual {n : ℕ} (F : MonotoneFormula n) : F.dual.leafSize = F.leafSize := by induction F with | var _ => rfl | and l r ihl ihr => simp [dual, leafSize, ihl, ihr] | or l r ihl ihr => simp [dual, leafSize, ihl, ihr] lemma depth_dual {n : ℕ} (F : MonotoneFormula n) : F.dual.depth = F.depth := by induction F with | var _ => rfl | and l r ihl ihr => simp [dual, depth, ihl, ihr] | or l r ihl ihr => simp [dual, depth, ihl, ihr] lemma varCount_dual {n : ℕ} (F : MonotoneFormula n) (i : Fin n) : F.dual.varCount i = F.varCount i := by induction F with | var _ => rfl | and l r ihl ihr => simp [dual, varCount, ihl, ihr] | or l r ihl ihr => simp [dual, varCount, ihl, ihr] /-- Relabel variables of a monotone formula along `σ : Fin n → Fin m`. -/ def mapVars {n m : ℕ} (σ : Fin n → Fin m) : MonotoneFormula n → MonotoneFormula m | var i => var (σ i) | and l r => and (l.mapVars σ) (r.mapVars σ) | or l r => or (l.mapVars σ) (r.mapVars σ) lemma eval_mapVars {n m : ℕ} (σ : Fin n → Fin m) (F : MonotoneFormula n) (x : Fin m → Bool) : (F.mapVars σ).eval x = F.eval (fun i => x (σ i)) := by induction F with | var _ => rfl | and l r ihl ihr => simp [mapVars, eval, ihl, ihr] | or l r ihl ihr => simp [mapVars, eval, ihl, ihr] lemma leafSize_mapVars {n m : ℕ} (σ : Fin n → Fin m) (F : MonotoneFormula n) : (F.mapVars σ).leafSize = F.leafSize := by induction F with | var _ => rfl | and l r ihl ihr => simp [mapVars, leafSize, ihl, ihr] | or l r ihl ihr => simp [mapVars, leafSize, ihl, ihr] lemma depth_mapVars {n m : ℕ} (σ : Fin n → Fin m) (F : MonotoneFormula n) : (F.mapVars σ).depth = F.depth := by induction F with | var _ => rfl | and l r ihl ihr => simp [mapVars, depth, ihl, ihr] | or l r ihl ihr => simp [mapVars, depth, ihl, ihr] /-- Composition `F ∘ G` of `F : MonotoneFormula m` and `G : MonotoneFormula k` on `m * k` variables (indexed by `Fin (m * k)` via `Fin.divNat`/`Fin.modNat`, or `j.val * k + r.val`). -/ def compose {m k : ℕ} (F : MonotoneFormula m) (G : MonotoneFormula k) : MonotoneFormula (m * k) := match F with | var j => G.mapVars (fun r => ⟨j.val * k + r.val, by have hj := j.isLt; have hr := r.isLt calc j.val * k + r.val < j.val * k + k := Nat.add_lt_add_left hr _ _ = (j.val + 1) * k := by ring _ ≤ m * k := Nat.mul_le_mul_right k hj⟩) | and l r => and (l.compose G) (r.compose G) | or l r => or (l.compose G) (r.compose G) lemma eval_compose {m k : ℕ} (F : MonotoneFormula m) (G : MonotoneFormula k) (z : Fin (m * k) → Bool) : (F.compose G).eval z = F.eval (fun j => G.eval (fun r => z ⟨j.val * k + r.val, by have hj := j.isLt; have hr := r.isLt calc j.val * k + r.val < j.val * k + k := Nat.add_lt_add_left hr _ _ = (j.val + 1) * k := by ring _ ≤ m * k := Nat.mul_le_mul_right k hj⟩)) := by induction F with | var j => simp [compose, eval, eval_mapVars] | and l r ihl ihr => simp [compose, eval, ihl, ihr] | or l r ihl ihr => simp [compose, eval, ihl, ihr] lemma leafSize_compose {m k : ℕ} (F : MonotoneFormula m) (G : MonotoneFormula k) : (F.compose G).leafSize = F.leafSize * G.leafSize := by induction F with | var _ => simp [compose, leafSize, leafSize_mapVars] | and l r ihl ihr => simp [compose, leafSize, ihl, ihr, Nat.add_mul] | or l r ihl ihr => simp [compose, leafSize, ihl, ihr, Nat.add_mul] lemma depth_compose {m k : ℕ} (F : MonotoneFormula m) (G : MonotoneFormula k) : (F.compose G).depth = F.depth + G.depth := by induction F with | var _ => simp [compose, depth, depth_mapVars] | and l r ihl ihr => simp only [compose, depth, ihl, ihr] omega | or l r ihl ihr => simp only [compose, depth, ihl, ihr] omega end MonotoneFormula /-- Two-party deterministic communication protocol for the monotone Karchmer–Wigderson game. -/ inductive MKWProtocol (n : ℕ) where | output (i : Fin n) | alice (bit : (Fin n → Bool) → Bool) (p0 p1 : MKWProtocol n) | bob (bit : (Fin n → Bool) → Bool) (p0 p1 : MKWProtocol n) namespace MKWProtocol def run {n : ℕ} : MKWProtocol n → (Fin n → Bool) → (Fin n → Bool) → Fin n | output i, _, _ => i | alice bit p0 p1, x, y => if bit x then p1.run x y else p0.run x y | bob bit p0 p1, x, y => if bit y then p1.run x y else p0.run x y def leafSize {n : ℕ} : MKWProtocol n → ℕ | output _ => 1 | alice _ p0 p1 => p0.leafSize + p1.leafSize | bob _ p0 p1 => p0.leafSize + p1.leafSize def depth {n : ℕ} : MKWProtocol n → ℕ | output _ => 0 | alice _ p0 p1 => max p0.depth p1.depth + 1 | bob _ p0 p1 => max p0.depth p1.depth + 1 def leafCount {n : ℕ} : MKWProtocol n → Fin n → ℕ | output j, i => if j = i then 1 else 0 | alice _ p0 p1, i => p0.leafCount i + p1.leafCount i | bob _ p0 p1, i => p0.leafCount i + p1.leafCount i lemma sum_leafCount {n : ℕ} (P : MKWProtocol n) : ∑ i : Fin n, P.leafCount i = P.leafSize := by induction P with | output j => simp [leafCount, leafSize] | alice _ p0 p1 ih0 ih1 => simp [leafCount, leafSize, Finset.sum_add_distrib, ih0, ih1] | bob _ p0 p1 ih0 ih1 => simp [leafCount, leafSize, Finset.sum_add_distrib, ih0, ih1] /-- Correctness predicate: `P` solves the monotone KW relation on `(A, B)`. -/ def Solves {n : ℕ} (P : MKWProtocol n) (A B : Set (Fin n → Bool)) : Prop := ∀ x ∈ A, ∀ y ∈ B, x (P.run x y) = true ∧ y (P.run x y) = false /-- Canonical translation from a monotone formula to an `mKW` protocol preserving size, depth, and exact per-variable leaf counts! -/ def ofFormula {n : ℕ} : MonotoneFormula n → MKWProtocol n | .var i => output i | .or l r => alice (fun x => l.eval x) (ofFormula r) (ofFormula l) | .and l r => bob (fun y => l.eval y) (ofFormula l) (ofFormula r) /-- Canonical translation from an `mKW` protocol to a monotone formula preserving size, depth, and exact per-variable leaf counts! -/ def toFormula {n : ℕ} : MKWProtocol n → MonotoneFormula n | output i => .var i | alice _ p0 p1 => .or p0.toFormula p1.toFormula | bob _ p0 p1 => .and p0.toFormula p1.toFormula lemma leafSize_ofFormula {n : ℕ} (F : MonotoneFormula n) : (ofFormula F).leafSize = F.leafSize := by induction F with | var _ => rfl | and l r ihl ihr => simp [ofFormula, leafSize, MonotoneFormula.leafSize, ihl, ihr] | or l r ihl ihr => simp [ofFormula, leafSize, MonotoneFormula.leafSize, ihl, ihr, add_comm] lemma depth_ofFormula {n : ℕ} (F : MonotoneFormula n) : (ofFormula F).depth = F.depth := by induction F with | var _ => rfl | and l r ihl ihr => simp [ofFormula, depth, MonotoneFormula.depth, ihl, ihr] | or l r ihl ihr => simp [ofFormula, depth, MonotoneFormula.depth, ihl, ihr, max_comm] lemma leafCount_ofFormula {n : ℕ} (F : MonotoneFormula n) (i : Fin n) : (ofFormula F).leafCount i = F.varCount i := by induction F with | var _ => rfl | and l r ihl ihr => simp [ofFormula, leafCount, MonotoneFormula.varCount, ihl, ihr] | or l r ihl ihr => simp [ofFormula, leafCount, MonotoneFormula.varCount, ihl, ihr, add_comm] lemma ofFormula_solves {n : ℕ} (F : MonotoneFormula n) : (ofFormula F).Solves {x | F.eval x = true} {y | F.eval y = false} := by induction F with | var i => intro x hx y hy; exact ⟨hx, hy⟩ | or l r ihl ihr => intro x hx y hy simp only [Set.mem_ofPred_eq, MonotoneFormula.eval, Bool.or_eq_true, Bool.or_eq_false_iff] at hx hy simp only [ofFormula, run] by_cases hxl : l.eval x = true · simp only [hxl, ↓reduceIte] exact ihl x hxl y hy.1 · have hxr : r.eval x = true := hx.resolve_left hxl simp only [hxl] exact ihr x hxr y hy.2 | and l r ihl ihr => intro x hx y hy simp only [Set.mem_ofPred_eq, MonotoneFormula.eval, Bool.and_eq_true, Bool.and_eq_false_iff] at hx hy simp only [ofFormula, run] by_cases hyl : l.eval y = true · have hyr : r.eval y = false := hy.resolve_left (by simp [hyl]) simp only [hyl, ↓reduceIte] exact ihr x hx.2 y hyr · have hylf : l.eval y = false := by cases h : l.eval y <;> simp_all simp only [hylf, Bool.false_eq_true, ↓reduceIte] exact ihl x hx.1 y hylf lemma leafSize_toFormula {n : ℕ} (P : MKWProtocol n) : P.toFormula.leafSize = P.leafSize := by induction P with | output _ => rfl | alice _ p0 p1 ih0 ih1 => simp [toFormula, leafSize, MonotoneFormula.leafSize, ih0, ih1] | bob _ p0 p1 ih0 ih1 => simp [toFormula, leafSize, MonotoneFormula.leafSize, ih0, ih1] lemma depth_toFormula {n : ℕ} (P : MKWProtocol n) : P.toFormula.depth = P.depth := by induction P with | output _ => rfl | alice _ p0 p1 ih0 ih1 => simp [toFormula, depth, MonotoneFormula.depth, ih0, ih1] | bob _ p0 p1 ih0 ih1 => simp [toFormula, depth, MonotoneFormula.depth, ih0, ih1] lemma varCount_toFormula {n : ℕ} (P : MKWProtocol n) (i : Fin n) : P.toFormula.varCount i = P.leafCount i := by induction P with | output _ => rfl | alice _ p0 p1 ih0 ih1 => simp [toFormula, leafCount, MonotoneFormula.varCount, ih0, ih1] | bob _ p0 p1 ih0 ih1 => simp [toFormula, leafCount, MonotoneFormula.varCount, ih0, ih1] /-- **Pruned Protocol-to-Formula Theorem:** Every `mKW` protocol solving `(A, B)` with `A.Nonempty` and `B.Nonempty` yields a monotone formula `F` separating `A` from `B` with `F.leafSize ≤ P.leafSize`, `F.depth ≤ P.depth`, and `∀ i, F.varCount i ≤ P.leafCount i`! -/ theorem exists_formula_of_mkw {n : ℕ} (P : MKWProtocol n) (A B : Set (Fin n → Bool)) (hA : A.Nonempty) (hB : B.Nonempty) (hP : P.Solves A B) : ∃ F : MonotoneFormula n, (∀ x ∈ A, F.eval x = true) ∧ (∀ y ∈ B, F.eval y = false) ∧ F.leafSize ≤ P.leafSize ∧ F.depth ≤ P.depth ∧ (∀ i, F.varCount i ≤ P.leafCount i) := by induction P generalizing A B with | output i => refine ⟨.var i, ?_, ?_, le_rfl, le_rfl, fun _ => le_rfl⟩ · intro x hx rcases hB with ⟨y, hy⟩ exact (hP x hx y hy).1 · intro y hy rcases hA with ⟨x, hx⟩ exact (hP x hx y hy).2 | alice bit p0 p1 ih0 ih1 => let A0 : Set (Fin n → Bool) := {x ∈ A | bit x = false} let A1 : Set (Fin n → Bool) := {x ∈ A | bit x = true} have hP0 : p0.Solves A0 B := by intro x hx y hy have h := hP x hx.1 y hy simpa [run, hx.2] using h have hP1 : p1.Solves A1 B := by intro x hx y hy have h := hP x hx.1 y hy simpa [run, hx.2] using h by_cases hA0 : A0.Nonempty · by_cases hA1 : A1.Nonempty · rcases ih0 A0 B hA0 hB hP0 with ⟨F0, hF0A, hF0B, hF0L, hF0D, hF0V⟩ rcases ih1 A1 B hA1 hB hP1 with ⟨F1, hF1A, hF1B, hF1L, hF1D, hF1V⟩ refine ⟨.or F0 F1, ?_, ?_, ?_, ?_, ?_⟩ · intro x hx simp only [MonotoneFormula.eval, Bool.or_eq_true] cases hb : bit x · left; exact hF0A x ⟨hx, hb⟩ · right; exact hF1A x ⟨hx, hb⟩ · intro y hy simp only [MonotoneFormula.eval, Bool.or_eq_false_iff] exact ⟨hF0B y hy, hF1B y hy⟩ · simp only [MonotoneFormula.leafSize, leafSize]; omega · simp only [MonotoneFormula.depth, depth]; omega · intro i; simp only [MonotoneFormula.varCount, leafCount]; have := hF0V i; have := hF1V i; omega · -- `A1 = ∅`, so `A ⊆ A0`! have hAsub : A ⊆ A0 := by intro x hx refine ⟨hx, ?_⟩ cases hb : bit x · rfl · exact absurd ⟨x, hx, hb⟩ hA1 rcases ih0 A0 B hA0 hB hP0 with ⟨F0, hF0A, hF0B, hF0L, hF0D, hF0V⟩ refine ⟨F0, fun x hx => hF0A x (hAsub hx), hF0B, ?_, ?_, ?_⟩ · simp only [leafSize]; omega · simp only [depth]; omega · intro i; simp only [leafCount]; have := hF0V i; omega · -- `A0 = ∅`, so `A ⊆ A1` and `A1.Nonempty`! have hAsub : A ⊆ A1 := by intro x hx refine ⟨hx, ?_⟩ cases hb : bit x · exact absurd ⟨x, hx, hb⟩ hA0 · rfl have hA1 : A1.Nonempty := hA.mono hAsub rcases ih1 A1 B hA1 hB hP1 with ⟨F1, hF1A, hF1B, hF1L, hF1D, hF1V⟩ refine ⟨F1, fun x hx => hF1A x (hAsub hx), hF1B, ?_, ?_, ?_⟩ · simp only [leafSize]; omega · simp only [depth]; omega · intro i; simp only [leafCount]; have := hF1V i; omega | bob bit p0 p1 ih0 ih1 => let B0 : Set (Fin n → Bool) := {y ∈ B | bit y = false} let B1 : Set (Fin n → Bool) := {y ∈ B | bit y = true} have hP0 : p0.Solves A B0 := by intro x hx y hy have h := hP x hx y hy.1 simpa [run, hy.2] using h have hP1 : p1.Solves A B1 := by intro x hx y hy have h := hP x hx y hy.1 simpa [run, hy.2] using h by_cases hB0 : B0.Nonempty · by_cases hB1 : B1.Nonempty · rcases ih0 A B0 hA hB0 hP0 with ⟨F0, hF0A, hF0B, hF0L, hF0D, hF0V⟩ rcases ih1 A B1 hA hB1 hP1 with ⟨F1, hF1A, hF1B, hF1L, hF1D, hF1V⟩ refine ⟨.and F0 F1, ?_, ?_, ?_, ?_, ?_⟩ · intro x hx simp only [MonotoneFormula.eval, Bool.and_eq_true] exact ⟨hF0A x hx, hF1A x hx⟩ · intro y hy simp only [MonotoneFormula.eval, Bool.and_eq_false_iff] cases hb : bit y · left; exact hF0B y ⟨hy, hb⟩ · right; exact hF1B y ⟨hy, hb⟩ · simp only [MonotoneFormula.leafSize, leafSize]; omega · simp only [MonotoneFormula.depth, depth]; omega · intro i; simp only [MonotoneFormula.varCount, leafCount]; have := hF0V i; have := hF1V i; omega · have hBsub : B ⊆ B0 := by intro y hy refine ⟨hy, ?_⟩ cases hb : bit y · rfl · exact absurd ⟨y, hy, hb⟩ hB1 rcases ih0 A B0 hA hB0 hP0 with ⟨F0, hF0A, hF0B, hF0L, hF0D, hF0V⟩ refine ⟨F0, hF0A, fun y hy => hF0B y (hBsub hy), ?_, ?_, ?_⟩ · simp only [leafSize]; omega · simp only [depth]; omega · intro i; simp only [leafCount]; have := hF0V i; omega · have hBsub : B ⊆ B1 := by intro y hy refine ⟨hy, ?_⟩ cases hb : bit y · exact absurd ⟨y, hy, hb⟩ hB0 · rfl have hB1 : B1.Nonempty := hB.mono hBsub rcases ih1 A B1 hA hB1 hP1 with ⟨F1, hF1A, hF1B, hF1L, hF1D, hF1V⟩ refine ⟨F1, hF1A, fun y hy => hF1B y (hBsub hy), ?_, ?_, ?_⟩ · simp only [leafSize]; omega · simp only [depth]; omega · intro i; simp only [leafCount]; have := hF1V i; omega end MKWProtocol /-- **HEADLINE THEOREM 9 (Exact Simultaneous Size & Depth Monotone Karchmer–Wigderson Equivalence):** For every non-constant Boolean function `f : (Fin n → Bool) → Bool` and every `(L, d) : ℕ × ℕ`: there exists a monotone formula computing `f` of leaf-size `≤ L` and depth `≤ d` **if and only if** there exists a monotone Karchmer–Wigderson protocol solving `(f⁻¹(1), f⁻¹(0))` of leaf-size `≤ L` and depth `≤ d`! -/ theorem monotone_kw_exact_equivalence {n : ℕ} (f : (Fin n → Bool) → Bool) (h1 : ∃ x, f x = true) (h0 : ∃ y, f y = false) (L d : ℕ) : (∃ F : MonotoneFormula n, (∀ x, F.eval x = f x) ∧ F.leafSize ≤ L ∧ F.depth ≤ d) ↔ (∃ P : MKWProtocol n, P.Solves {x | f x = true} {y | f y = false} ∧ P.leafSize ≤ L ∧ P.depth ≤ d) := by constructor · rintro ⟨F, hF, hFL, hFD⟩ refine ⟨MKWProtocol.ofFormula F, ?_, ?_, ?_⟩ · intro x hx y hy exact MKWProtocol.ofFormula_solves F x (by simpa [hF] using hx) y (by simpa [hF] using hy) · rwa [MKWProtocol.leafSize_ofFormula] · rwa [MKWProtocol.depth_ofFormula] · rintro ⟨P, hP, hPL, hPD⟩ rcases MKWProtocol.exists_formula_of_mkw P {x | f x = true} {y | f y = false} h1 h0 hP with ⟨F, hFA, hFB, hFL, hFD, _⟩ refine ⟨F, fun x => ?_, hFL.trans hPL, hFD.trans hPD⟩ cases hfx : f x · exact hFB x hfx · exact hFA x hfx /-- **Exact Monotone De Morgan Duality Theorem:** For every Boolean function `f`, `f` and its De Morgan dual `f†(x) = !(f (!x))` have identical monotone formula size, depth, and per-variable leaf counts. -/ theorem monotone_duality_exact {n : ℕ} (f : (Fin n → Bool) → Bool) (L d : ℕ) : (∃ F : MonotoneFormula n, (∀ x, F.eval x = f x) ∧ F.leafSize ≤ L ∧ F.depth ≤ d) ↔ (∃ F : MonotoneFormula n, (∀ x, F.eval x = !(f (fun i => !x i))) ∧ F.leafSize ≤ L ∧ F.depth ≤ d) := by constructor · rintro ⟨F, hF, hL, hD⟩ refine ⟨F.dual, fun x => ?_, ?_, ?_⟩ · rw [MonotoneFormula.eval_dual, hF] · rwa [MonotoneFormula.leafSize_dual] · rwa [MonotoneFormula.depth_dual] · rintro ⟨F, hF, hL, hD⟩ refine ⟨F.dual, fun x => ?_, ?_, ?_⟩ · rw [MonotoneFormula.eval_dual, hF] have : (fun i => !(!x i)) = x := funext (fun i => Bool.not_not (x i)) rw [this, Bool.not_not] · rwa [MonotoneFormula.leafSize_dual] · rwa [MonotoneFormula.depth_dual] /-- General De Morgan Boolean formulas (positive and negated variable leaves, `∧`, `∨`). -/ inductive DeMorganFormula (n : ℕ) where | lit (i : Fin n) (pol : Bool) | and (l r : DeMorganFormula n) | or (l r : DeMorganFormula n) namespace DeMorganFormula def eval {n : ℕ} : DeMorganFormula n → (Fin n → Bool) → Bool | lit i pol, x => if pol then x i else !(x i) | and l r, x => l.eval x && r.eval x | or l r, x => l.eval x || r.eval x def leafSize {n : ℕ} : DeMorganFormula n → ℕ | lit _ _ => 1 | and l r => l.leafSize + r.leafSize | or l r => l.leafSize + r.leafSize def depth {n : ℕ} : DeMorganFormula n → ℕ | lit _ _ => 0 | and l r => max l.depth r.depth + 1 | or l r => max l.depth r.depth + 1 def varCount {n : ℕ} : DeMorganFormula n → Fin n → ℕ | lit j _, i => if j = i then 1 else 0 | and l r, i => l.varCount i + r.varCount i | or l r, i => l.varCount i + r.varCount i lemma sum_varCount {n : ℕ} (F : DeMorganFormula n) : ∑ i : Fin n, F.varCount i = F.leafSize := by induction F with | lit j _ => simp [varCount, leafSize] | and l r ihl ihr => simp [varCount, leafSize, Finset.sum_add_distrib, ihl, ihr] | or l r ihl ihr => simp [varCount, leafSize, Finset.sum_add_distrib, ihl, ihr] end DeMorganFormula /-- General (non-monotone) Karchmer–Wigderson protocol outputting a coordinate `i` where `x i ≠ y i` (along with polarity `x i`). -/ inductive KWProtocol (n : ℕ) where | output (i : Fin n) (pol : Bool) | alice (bit : (Fin n → Bool) → Bool) (p0 p1 : KWProtocol n) | bob (bit : (Fin n → Bool) → Bool) (p0 p1 : KWProtocol n) namespace KWProtocol def run {n : ℕ} : KWProtocol n → (Fin n → Bool) → (Fin n → Bool) → Fin n × Bool | output i pol, _, _ => (i, pol) | alice bit p0 p1, x, y => if bit x then p1.run x y else p0.run x y | bob bit p0 p1, x, y => if bit y then p1.run x y else p0.run x y def leafSize {n : ℕ} : KWProtocol n → ℕ | output _ _ => 1 | alice _ p0 p1 => p0.leafSize + p1.leafSize | bob _ p0 p1 => p0.leafSize + p1.leafSize def depth {n : ℕ} : KWProtocol n → ℕ | output _ _ => 0 | alice _ p0 p1 => max p0.depth p1.depth + 1 | bob _ p0 p1 => max p0.depth p1.depth + 1 def leafCount {n : ℕ} : KWProtocol n → Fin n → ℕ | output j _, i => if j = i then 1 else 0 | alice _ p0 p1, i => p0.leafCount i + p1.leafCount i | bob _ p0 p1, i => p0.leafCount i + p1.leafCount i def Solves {n : ℕ} (P : KWProtocol n) (A B : Set (Fin n → Bool)) : Prop := ∀ x ∈ A, ∀ y ∈ B, let res := P.run x y x res.1 = res.2 ∧ y res.1 = !res.2 def ofFormula {n : ℕ} : DeMorganFormula n → KWProtocol n | .lit i pol => output i pol | .or l r => alice (fun x => l.eval x) (ofFormula r) (ofFormula l) | .and l r => bob (fun y => l.eval y) (ofFormula l) (ofFormula r) lemma leafSize_ofFormula {n : ℕ} (F : DeMorganFormula n) : (ofFormula F).leafSize = F.leafSize := by induction F with | lit _ _ => rfl | and l r ihl ihr => simp [ofFormula, leafSize, DeMorganFormula.leafSize, ihl, ihr] | or l r ihl ihr => simp [ofFormula, leafSize, DeMorganFormula.leafSize, ihl, ihr, add_comm] lemma depth_ofFormula {n : ℕ} (F : DeMorganFormula n) : (ofFormula F).depth = F.depth := by induction F with | lit _ _ => rfl | and l r ihl ihr => simp [ofFormula, depth, DeMorganFormula.depth, ihl, ihr] | or l r ihl ihr => simp [ofFormula, depth, DeMorganFormula.depth, ihl, ihr, max_comm] lemma leafCount_ofFormula {n : ℕ} (F : DeMorganFormula n) (i : Fin n) : (ofFormula F).leafCount i = F.varCount i := by induction F with | lit _ _ => rfl | and l r ihl ihr => simp [ofFormula, leafCount, DeMorganFormula.varCount, ihl, ihr] | or l r ihl ihr => simp [ofFormula, leafCount, DeMorganFormula.varCount, ihl, ihr, add_comm] lemma ofFormula_solves {n : ℕ} (F : DeMorganFormula n) : (ofFormula F).Solves {x | F.eval x = true} {y | F.eval y = false} := by induction F with | lit i pol => intro x hx y hy simp only [Set.mem_ofPred_eq, DeMorganFormula.eval] at hx hy cases pol <;> simp_all [ofFormula, run] | or l r ihl ihr => intro x hx y hy simp only [Set.mem_ofPred_eq, DeMorganFormula.eval, Bool.or_eq_true, Bool.or_eq_false_iff] at hx hy simp only [ofFormula, run] by_cases hxl : l.eval x = true · simp only [hxl, ↓reduceIte]; exact ihl x hxl y hy.1 · have hxr : r.eval x = true := hx.resolve_left hxl simp only [hxl]; exact ihr x hxr y hy.2 | and l r ihl ihr => intro x hx y hy simp only [Set.mem_ofPred_eq, DeMorganFormula.eval, Bool.and_eq_true, Bool.and_eq_false_iff] at hx hy simp only [ofFormula, run] by_cases hyl : l.eval y = true · have hyr : r.eval y = false := hy.resolve_left (by simp [hyl]) simp only [hyl, ↓reduceIte]; exact ihr x hx.2 y hyr · have hylf : l.eval y = false := by cases h : l.eval y <;> simp_all simp only [hylf, Bool.false_eq_true, ↓reduceIte]; exact ihl x hx.1 y hylf theorem exists_formula_of_kw {n : ℕ} (P : KWProtocol n) (A B : Set (Fin n → Bool)) (hA : A.Nonempty) (hB : B.Nonempty) (hP : P.Solves A B) : ∃ F : DeMorganFormula n, (∀ x ∈ A, F.eval x = true) ∧ (∀ y ∈ B, F.eval y = false) ∧ F.leafSize ≤ P.leafSize ∧ F.depth ≤ P.depth ∧ (∀ i, F.varCount i ≤ P.leafCount i) := by induction P generalizing A B with | output i pol => refine ⟨.lit i pol, ?_, ?_, le_rfl, le_rfl, fun _ => le_rfl⟩ · intro x hx rcases hB with ⟨y, hy⟩ have h := (hP x hx y hy).1 cases pol <;> simp_all [DeMorganFormula.eval, run] · intro y hy rcases hA with ⟨x, hx⟩ have h := (hP x hx y hy).2 cases pol <;> simp_all [DeMorganFormula.eval, run] | alice bit p0 p1 ih0 ih1 => let A0 : Set (Fin n → Bool) := {x ∈ A | bit x = false} let A1 : Set (Fin n → Bool) := {x ∈ A | bit x = true} have hP0 : p0.Solves A0 B := fun x hx y hy => by simpa [run, hx.2] using hP x hx.1 y hy have hP1 : p1.Solves A1 B := fun x hx y hy => by simpa [run, hx.2] using hP x hx.1 y hy by_cases hA0 : A0.Nonempty · by_cases hA1 : A1.Nonempty · rcases ih0 A0 B hA0 hB hP0 with ⟨F0, hF0A, hF0B, hF0L, hF0D, hF0V⟩ rcases ih1 A1 B hA1 hB hP1 with ⟨F1, hF1A, hF1B, hF1L, hF1D, hF1V⟩ refine ⟨.or F0 F1, ?_, ?_, ?_, ?_, ?_⟩ · intro x hx simp only [DeMorganFormula.eval, Bool.or_eq_true] cases hb : bit x · left; exact hF0A x ⟨hx, hb⟩ · right; exact hF1A x ⟨hx, hb⟩ · intro y hy simp only [DeMorganFormula.eval, Bool.or_eq_false_iff] exact ⟨hF0B y hy, hF1B y hy⟩ · simp only [DeMorganFormula.leafSize, leafSize]; omega · simp only [DeMorganFormula.depth, depth]; omega · intro i; simp only [DeMorganFormula.varCount, leafCount]; have := hF0V i; have := hF1V i; omega · have hAsub : A ⊆ A0 := by intro x hx refine ⟨hx, ?_⟩ cases hb : bit x · rfl · exact absurd ⟨x, hx, hb⟩ hA1 rcases ih0 A0 B hA0 hB hP0 with ⟨F0, hF0A, hF0B, hF0L, hF0D, hF0V⟩ refine ⟨F0, fun x hx => hF0A x (hAsub hx), hF0B, ?_, ?_, ?_⟩ · simp only [leafSize]; omega · simp only [depth]; omega · intro i; simp only [leafCount]; have := hF0V i; omega · have hAsub : A ⊆ A1 := by intro x hx refine ⟨hx, ?_⟩ cases hb : bit x · exact absurd ⟨x, hx, hb⟩ hA0 · rfl rcases ih1 A1 B (hA.mono hAsub) hB hP1 with ⟨F1, hF1A, hF1B, hF1L, hF1D, hF1V⟩ refine ⟨F1, fun x hx => hF1A x (hAsub hx), hF1B, ?_, ?_, ?_⟩ · simp only [leafSize]; omega · simp only [depth]; omega · intro i; simp only [leafCount]; have := hF1V i; omega | bob bit p0 p1 ih0 ih1 => let B0 : Set (Fin n → Bool) := {y ∈ B | bit y = false} let B1 : Set (Fin n → Bool) := {y ∈ B | bit y = true} have hP0 : p0.Solves A B0 := fun x hx y hy => by simpa [run, hy.2] using hP x hx y hy.1 have hP1 : p1.Solves A B1 := fun x hx y hy => by simpa [run, hy.2] using hP x hx y hy.1 by_cases hB0 : B0.Nonempty · by_cases hB1 : B1.Nonempty · rcases ih0 A B0 hA hB0 hP0 with ⟨F0, hF0A, hF0B, hF0L, hF0D, hF0V⟩ rcases ih1 A B1 hA hB1 hP1 with ⟨F1, hF1A, hF1B, hF1L, hF1D, hF1V⟩ refine ⟨.and F0 F1, ?_, ?_, ?_, ?_, ?_⟩ · intro x hx simp only [DeMorganFormula.eval, Bool.and_eq_true] exact ⟨hF0A x hx, hF1A x hx⟩ · intro y hy simp only [DeMorganFormula.eval, Bool.and_eq_false_iff] cases hb : bit y · left; exact hF0B y ⟨hy, hb⟩ · right; exact hF1B y ⟨hy, hb⟩ · simp only [DeMorganFormula.leafSize, leafSize]; omega · simp only [DeMorganFormula.depth, depth]; omega · intro i; simp only [DeMorganFormula.varCount, leafCount]; have := hF0V i; have := hF1V i; omega · have hBsub : B ⊆ B0 := by intro y hy refine ⟨hy, ?_⟩ cases hb : bit y · rfl · exact absurd ⟨y, hy, hb⟩ hB1 rcases ih0 A B0 hA hB0 hP0 with ⟨F0, hF0A, hF0B, hF0L, hF0D, hF0V⟩ refine ⟨F0, hF0A, fun y hy => hF0B y (hBsub hy), ?_, ?_, ?_⟩ · simp only [leafSize]; omega · simp only [depth]; omega · intro i; simp only [leafCount]; have := hF0V i; omega · have hBsub : B ⊆ B1 := by intro y hy refine ⟨hy, ?_⟩ cases hb : bit y · exact absurd ⟨y, hy, hb⟩ hB0 · rfl rcases ih1 A B1 hA (hB.mono hBsub) hP1 with ⟨F1, hF1A, hF1B, hF1L, hF1D, hF1V⟩ refine ⟨F1, hF1A, fun y hy => hF1B y (hBsub hy), ?_, ?_, ?_⟩ · simp only [leafSize]; omega · simp only [depth]; omega · intro i; simp only [leafCount]; have := hF1V i; omega end KWProtocol /-- **HEADLINE THEOREM 10 (Exact Simultaneous Size & Depth General Karchmer–Wigderson Equivalence):** For every non-constant Boolean function `f : (Fin n → Bool) → Bool` and every `(L, d) : ℕ × ℕ`: there exists a De Morgan formula computing `f` of leaf-size `≤ L` and depth `≤ d` **if and only if** there exists a general KW protocol solving `(f⁻¹(1), f⁻¹(0))` of leaf-size `≤ L` and depth `≤ d`! -/ theorem general_kw_exact_equivalence {n : ℕ} (f : (Fin n → Bool) → Bool) (h1 : ∃ x, f x = true) (h0 : ∃ y, f y = false) (L d : ℕ) : (∃ F : DeMorganFormula n, (∀ x, F.eval x = f x) ∧ F.leafSize ≤ L ∧ F.depth ≤ d) ↔ (∃ P : KWProtocol n, P.Solves {x | f x = true} {y | f y = false} ∧ P.leafSize ≤ L ∧ P.depth ≤ d) := by constructor · rintro ⟨F, hF, hFL, hFD⟩ refine ⟨KWProtocol.ofFormula F, ?_, ?_, ?_⟩ · intro x hx y hy exact KWProtocol.ofFormula_solves F x (by simpa [hF] using hx) y (by simpa [hF] using hy) · rwa [KWProtocol.leafSize_ofFormula] · rwa [KWProtocol.depth_ofFormula] · rintro ⟨P, hP, hPL, hPD⟩ rcases KWProtocol.exists_formula_of_kw P {x | f x = true} {y | f y = false} h1 h0 hP with ⟨F, hFA, hFB, hFL, hFD, _⟩ refine ⟨F, fun x => ?_, hFL.trans hPL, hFD.trans hPD⟩ cases hfx : f x · exact hFB x hfx · exact hFA x hfx /-! ## Section 4 (Pillar 4): Bilinear Spectral Adversary Composition, Exact Khrapchenko & ## Iterated Composition Lower Bounds, and Exact Hansel–Kraft Monotone Formula Bounds -/ /-- Squared operator-norm bound for a real matrix `M` on `A × B`, expressed in bilinear form: `(∑_{x ∈ A} ∑_{y ∈ B} u x * M x y * v y)^2 ≤ C * (∑_{x ∈ A} u x^2) * (∑_{y ∈ B} v y^2)`. -/ def BilinearSpectralBound {α β : Type*} (M : α → β → ℝ) (A : Finset α) (B : Finset β) (C : ℝ) : Prop := 0 ≤ C ∧ ∀ (u : α → ℝ) (v : β → ℝ), (∑ x ∈ A, ∑ y ∈ B, u x * M x y * v y) ^ 2 ≤ C * (∑ x ∈ A, (u x) ^ 2) * (∑ y ∈ B, (v y) ^ 2) /-- Elementary 2-term Cauchy–Schwarz inequality (sqrt-free, division-free). -/ lemma sq_add_le_mul_add {a b C0 C1 s0 s1 : ℝ} (hC0 : 0 ≤ C0) (hC1 : 0 ≤ C1) (hs0 : 0 ≤ s0) (hs1 : 0 ≤ s1) (ha : a ^ 2 ≤ C0 * s0) (hb : b ^ 2 ≤ C1 * s1) : (a + b) ^ 2 ≤ (C0 + C1) * (s0 + s1) := by have h1 : (2 * a * b) ^ 2 ≤ (C0 * s1 + C1 * s0) ^ 2 := by have h4 : 4 * (a ^ 2 * b ^ 2) ≤ 4 * ((C0 * s0) * (C1 * s1)) := by have := mul_le_mul ha hb (sq_nonneg b) (mul_nonneg hC0 hs0) linarith have hsq : 0 ≤ (C0 * s1 - C1 * s0) ^ 2 := sq_nonneg _ nlinarith have h2 : 2 * a * b ≤ C0 * s1 + C1 * s0 := by nlinarith [mul_nonneg hC0 hs1, mul_nonneg hC1 hs0] nlinarith /-- **HEADLINE THEOREM 11A (Per-Variable Weighted Bilinear Spectral Adversary Bound for `mKW`):** For any monotone KW protocol `P` solving `(A, B)`, any real matrix `M` on `A × B`, and any per-coordinate spectral bounds `C i` for the masked matrices `M_i(x, y) = if x i = true ∧ y i = false then M(x, y) else 0`: `BilinearSpectralBound M A B (∑ i : Fin n, (P.leafCount i : ℝ) * C i)`! -/ theorem mkw_bilinear_adversary_bound {n : ℕ} (P : MKWProtocol n) (A B : Finset (Fin n → Bool)) (M : (Fin n → Bool) → (Fin n → Bool) → ℝ) (C : Fin n → ℝ) (hC : ∀ i : Fin n, BilinearSpectralBound (fun x y => if x i = true ∧ y i = false then M x y else 0) A B (C i)) (hP : P.Solves (A : Set (Fin n → Bool)) (B : Set (Fin n → Bool))) : BilinearSpectralBound M A B (∑ i : Fin n, (P.leafCount i : ℝ) * C i) := by -- Prove a stronger subrectangle version by induction on `P`: have hgen : ∀ (P : MKWProtocol n) (U V : Finset (Fin n → Bool)), U ⊆ A → V ⊆ B → P.Solves (U : Set (Fin n → Bool)) (V : Set (Fin n → Bool)) → BilinearSpectralBound M U V (∑ i : Fin n, (P.leafCount i : ℝ) * C i) := by intro P induction P with | output j => intro U V hUA hVB hsol have hsum_j : ∑ i : Fin n, ((MKWProtocol.output j).leafCount i : ℝ) * C i = C j := by simp [MKWProtocol.leafCount] rw [hsum_j] refine ⟨(hC j).1, fun u v => ?_⟩ let u' : (Fin n → Bool) → ℝ := fun x => if x ∈ U then u x else 0 let v' : (Fin n → Bool) → ℝ := fun y => if y ∈ V then v y else 0 have hM_eq : ∑ x ∈ U, ∑ y ∈ V, u x * M x y * v y = ∑ x ∈ A, ∑ y ∈ B, u' x * (if x j = true ∧ y j = false then M x y else 0) * v' y := by rw [← Finset.sum_subset hUA (fun x _ hx => by simp [u', hx])] apply Finset.sum_congr rfl intro x hx rw [← Finset.sum_subset hVB (fun y _ hy => by simp [v', hy])] apply Finset.sum_congr rfl intro y hy have hxy := hsol x hx y hy simp only [MKWProtocol.run] at hxy simp [u', v', hx, hy, hxy.1, hxy.2] have hu_eq : ∑ x ∈ A, (u' x) ^ 2 = ∑ x ∈ U, (u x) ^ 2 := by rw [← Finset.sum_subset hUA (fun x _ hx => by simp [u', hx])] exact Finset.sum_congr rfl (fun x hx => by simp [u', hx]) have hv_eq : ∑ y ∈ B, (v' y) ^ 2 = ∑ y ∈ V, (v y) ^ 2 := by rw [← Finset.sum_subset hVB (fun y _ hy => by simp [v', hy])] exact Finset.sum_congr rfl (fun y hy => by simp [v', hy]) rw [hM_eq, ← hu_eq, ← hv_eq] exact (hC j).2 u' v' | alice bit p0 p1 ih0 ih1 => intro U V hUA hVB hsol let U0 := U.filter (fun x => bit x = false) let U1 := U.filter (fun x => bit x = true) have hP0 : p0.Solves (U0 : Set (Fin n → Bool)) (V : Set (Fin n → Bool)) := by intro x hx y hy simp only [Finset.mem_coe, U0, Finset.mem_filter] at hx simpa [MKWProtocol.run, hx.2] using hsol x hx.1 y hy have hP1 : p1.Solves (U1 : Set (Fin n → Bool)) (V : Set (Fin n → Bool)) := by intro x hx y hy simp only [Finset.mem_coe, U1, Finset.mem_filter] at hx simpa [MKWProtocol.run, hx.2] using hsol x hx.1 y hy have hB0 := ih0 U0 V ((Finset.filter_subset _ U).trans hUA) hVB hP0 have hB1 := ih1 U1 V ((Finset.filter_subset _ U).trans hUA) hVB hP1 have hCsum : ∑ i : Fin n, ((MKWProtocol.alice bit p0 p1).leafCount i : ℝ) * C i = (∑ i : Fin n, (p0.leafCount i : ℝ) * C i) + (∑ i : Fin n, (p1.leafCount i : ℝ) * C i) := by simp [MKWProtocol.leafCount, add_mul, Finset.sum_add_distrib] rw [hCsum] refine ⟨add_nonneg hB0.1 hB1.1, fun u v => ?_⟩ have hpart_M : ∑ x ∈ U, ∑ y ∈ V, u x * M x y * v y = (∑ x ∈ U0, ∑ y ∈ V, u x * M x y * v y) + (∑ x ∈ U1, ∑ y ∈ V, u x * M x y * v y) := by have h := Finset.sum_filter_add_sum_filter_not U (fun x => bit x = false) (fun x => ∑ y ∈ V, u x * M x y * v y) have hU1 : U.filter (fun x => ¬bit x = false) = U1 := by ext x; simp [U1] rw [hU1] at h; exact h.symm have hpart_u : ∑ x ∈ U, (u x) ^ 2 = (∑ x ∈ U0, (u x) ^ 2) + (∑ x ∈ U1, (u x) ^ 2) := by have h := Finset.sum_filter_add_sum_filter_not U (fun x => bit x = false) (fun x => (u x) ^ 2) have hU1 : U.filter (fun x => ¬bit x = false) = U1 := by ext x; simp [U1] rw [hU1] at h; exact h.symm rw [hpart_M, hpart_u] have hs0 : 0 ≤ (∑ x ∈ U0, (u x) ^ 2) * (∑ y ∈ V, (v y) ^ 2) := mul_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) have hs1 : 0 ≤ (∑ x ∈ U1, (u x) ^ 2) * (∑ y ∈ V, (v y) ^ 2) := mul_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) have ha : (∑ x ∈ U0, ∑ y ∈ V, u x * M x y * v y) ^ 2 ≤ (∑ i : Fin n, (p0.leafCount i : ℝ) * C i) * ((∑ x ∈ U0, (u x) ^ 2) * (∑ y ∈ V, (v y) ^ 2)) := by simpa [mul_assoc] using hB0.2 u v have hb : (∑ x ∈ U1, ∑ y ∈ V, u x * M x y * v y) ^ 2 ≤ (∑ i : Fin n, (p1.leafCount i : ℝ) * C i) * ((∑ x ∈ U1, (u x) ^ 2) * (∑ y ∈ V, (v y) ^ 2)) := by simpa [mul_assoc] using hB1.2 u v have hcs := sq_add_le_mul_add hB0.1 hB1.1 hs0 hs1 ha hb linarith | bob bit p0 p1 ih0 ih1 => intro U V hUA hVB hsol let V0 := V.filter (fun y => bit y = false) let V1 := V.filter (fun y => bit y = true) have hP0 : p0.Solves (U : Set (Fin n → Bool)) (V0 : Set (Fin n → Bool)) := by intro x hx y hy simp only [Finset.mem_coe, V0, Finset.mem_filter] at hy simpa [MKWProtocol.run, hy.2] using hsol x hx y hy.1 have hP1 : p1.Solves (U : Set (Fin n → Bool)) (V1 : Set (Fin n → Bool)) := by intro x hx y hy simp only [Finset.mem_coe, V1, Finset.mem_filter] at hy simpa [MKWProtocol.run, hy.2] using hsol x hx y hy.1 have hB0 := ih0 U V0 hUA ((Finset.filter_subset _ V).trans hVB) hP0 have hB1 := ih1 U V1 hUA ((Finset.filter_subset _ V).trans hVB) hP1 have hCsum : ∑ i : Fin n, ((MKWProtocol.bob bit p0 p1).leafCount i : ℝ) * C i = (∑ i : Fin n, (p0.leafCount i : ℝ) * C i) + (∑ i : Fin n, (p1.leafCount i : ℝ) * C i) := by simp [MKWProtocol.leafCount, add_mul, Finset.sum_add_distrib] rw [hCsum] refine ⟨add_nonneg hB0.1 hB1.1, fun u v => ?_⟩ have hpart_M : ∑ x ∈ U, ∑ y ∈ V, u x * M x y * v y = (∑ x ∈ U, ∑ y ∈ V0, u x * M x y * v y) + (∑ x ∈ U, ∑ y ∈ V1, u x * M x y * v y) := by rw [← Finset.sum_add_distrib] apply Finset.sum_congr rfl; intro x _ have h := Finset.sum_filter_add_sum_filter_not V (fun y => bit y = false) (fun y => u x * M x y * v y) have hV1 : V.filter (fun y => ¬bit y = false) = V1 := by ext y; simp [V1] rw [hV1] at h; exact h.symm have hpart_v : ∑ y ∈ V, (v y) ^ 2 = (∑ y ∈ V0, (v y) ^ 2) + (∑ y ∈ V1, (v y) ^ 2) := by have h := Finset.sum_filter_add_sum_filter_not V (fun y => bit y = false) (fun y => (v y) ^ 2) have hV1 : V.filter (fun y => ¬bit y = false) = V1 := by ext y; simp [V1] rw [hV1] at h; exact h.symm rw [hpart_M, hpart_v] have hs0 : 0 ≤ (∑ x ∈ U, (u x) ^ 2) * (∑ y ∈ V0, (v y) ^ 2) := mul_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) have hs1 : 0 ≤ (∑ x ∈ U, (u x) ^ 2) * (∑ y ∈ V1, (v y) ^ 2) := mul_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) have ha : (∑ x ∈ U, ∑ y ∈ V0, u x * M x y * v y) ^ 2 ≤ (∑ i : Fin n, (p0.leafCount i : ℝ) * C i) * ((∑ x ∈ U, (u x) ^ 2) * (∑ y ∈ V0, (v y) ^ 2)) := by simpa [mul_assoc] using hB0.2 u v have hb : (∑ x ∈ U, ∑ y ∈ V1, u x * M x y * v y) ^ 2 ≤ (∑ i : Fin n, (p1.leafCount i : ℝ) * C i) * ((∑ x ∈ U, (u x) ^ 2) * (∑ y ∈ V1, (v y) ^ 2)) := by simpa [mul_assoc] using hB1.2 u v have hcs := sq_add_le_mul_add hB0.1 hB1.1 hs0 hs1 ha hb linarith exact hgen P A B (Finset.Subset.refl A) (Finset.Subset.refl B) hP /-- **HEADLINE THEOREM 11B (Per-Variable Weighted Bilinear Spectral Adversary Bound for General `KW`):** Same exact bilinear spectral adversary bound for non-monotone De Morgan formulas / `KW` protocols! -/ theorem kw_bilinear_adversary_bound {n : ℕ} (P : KWProtocol n) (A B : Finset (Fin n → Bool)) (M : (Fin n → Bool) → (Fin n → Bool) → ℝ) (C : Fin n → ℝ) (hC : ∀ i : Fin n, BilinearSpectralBound (fun x y => if x i ≠ y i then M x y else 0) A B (C i)) (hP : P.Solves (A : Set (Fin n → Bool)) (B : Set (Fin n → Bool))) : BilinearSpectralBound M A B (∑ i : Fin n, (P.leafCount i : ℝ) * C i) := by have hgen : ∀ (P : KWProtocol n) (U V : Finset (Fin n → Bool)), U ⊆ A → V ⊆ B → P.Solves (U : Set (Fin n → Bool)) (V : Set (Fin n → Bool)) → BilinearSpectralBound M U V (∑ i : Fin n, (P.leafCount i : ℝ) * C i) := by intro P induction P with | output j pol => intro U V hUA hVB hsol have hsum_j : ∑ i : Fin n, ((KWProtocol.output j pol).leafCount i : ℝ) * C i = C j := by simp [KWProtocol.leafCount] rw [hsum_j] refine ⟨(hC j).1, fun u v => ?_⟩ let u' : (Fin n → Bool) → ℝ := fun x => if x ∈ U then u x else 0 let v' : (Fin n → Bool) → ℝ := fun y => if y ∈ V then v y else 0 have hM_eq : ∑ x ∈ U, ∑ y ∈ V, u x * M x y * v y = ∑ x ∈ A, ∑ y ∈ B, u' x * (if x j ≠ y j then M x y else 0) * v' y := by rw [← Finset.sum_subset hUA (fun x _ hx => by simp [u', hx])] apply Finset.sum_congr rfl; intro x hx rw [← Finset.sum_subset hVB (fun y _ hy => by simp [v', hy])] apply Finset.sum_congr rfl; intro y hy have hxy := hsol x hx y hy have hne : x j ≠ y j := by cases pol <;> simp_all [KWProtocol.run] simp [u', v', hx, hy, hne] have hu_eq : ∑ x ∈ A, (u' x) ^ 2 = ∑ x ∈ U, (u x) ^ 2 := by rw [← Finset.sum_subset hUA (fun x _ hx => by simp [u', hx])] exact Finset.sum_congr rfl (fun x hx => by simp [u', hx]) have hv_eq : ∑ y ∈ B, (v' y) ^ 2 = ∑ y ∈ V, (v y) ^ 2 := by rw [← Finset.sum_subset hVB (fun y _ hy => by simp [v', hy])] exact Finset.sum_congr rfl (fun y hy => by simp [v', hy]) rw [hM_eq, ← hu_eq, ← hv_eq] exact (hC j).2 u' v' | alice bit p0 p1 ih0 ih1 => intro U V hUA hVB hsol let U0 := U.filter (fun x => bit x = false) let U1 := U.filter (fun x => bit x = true) have hB0 := ih0 U0 V ((Finset.filter_subset _ U).trans hUA) hVB (fun x hx y hy => by simp only [Finset.mem_coe, U0, Finset.mem_filter] at hx simpa [KWProtocol.run, hx.2] using hsol x hx.1 y hy) have hB1 := ih1 U1 V ((Finset.filter_subset _ U).trans hUA) hVB (fun x hx y hy => by simp only [Finset.mem_coe, U1, Finset.mem_filter] at hx simpa [KWProtocol.run, hx.2] using hsol x hx.1 y hy) have hCsum : ∑ i : Fin n, ((KWProtocol.alice bit p0 p1).leafCount i : ℝ) * C i = (∑ i : Fin n, (p0.leafCount i : ℝ) * C i) + (∑ i : Fin n, (p1.leafCount i : ℝ) * C i) := by simp [KWProtocol.leafCount, add_mul, Finset.sum_add_distrib] rw [hCsum] refine ⟨add_nonneg hB0.1 hB1.1, fun u v => ?_⟩ have hpart_M : ∑ x ∈ U, ∑ y ∈ V, u x * M x y * v y = (∑ x ∈ U0, ∑ y ∈ V, u x * M x y * v y) + (∑ x ∈ U1, ∑ y ∈ V, u x * M x y * v y) := by have h := Finset.sum_filter_add_sum_filter_not U (fun x => bit x = false) (fun x => ∑ y ∈ V, u x * M x y * v y) have hU1 : U.filter (fun x => ¬bit x = false) = U1 := by ext x; simp [U1] rw [hU1] at h; exact h.symm have hpart_u : ∑ x ∈ U, (u x) ^ 2 = (∑ x ∈ U0, (u x) ^ 2) + (∑ x ∈ U1, (u x) ^ 2) := by have h := Finset.sum_filter_add_sum_filter_not U (fun x => bit x = false) (fun x => (u x) ^ 2) have hU1 : U.filter (fun x => ¬bit x = false) = U1 := by ext x; simp [U1] rw [hU1] at h; exact h.symm rw [hpart_M, hpart_u] have hs0 : 0 ≤ (∑ x ∈ U0, (u x) ^ 2) * (∑ y ∈ V, (v y) ^ 2) := mul_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) have hs1 : 0 ≤ (∑ x ∈ U1, (u x) ^ 2) * (∑ y ∈ V, (v y) ^ 2) := mul_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) have hcs := sq_add_le_mul_add hB0.1 hB1.1 hs0 hs1 (by rw [← mul_assoc]; exact hB0.2 u v) (by rw [← mul_assoc]; exact hB1.2 u v) linarith | bob bit p0 p1 ih0 ih1 => intro U V hUA hVB hsol let V0 := V.filter (fun y => bit y = false) let V1 := V.filter (fun y => bit y = true) have hB0 := ih0 U V0 hUA ((Finset.filter_subset _ V).trans hVB) (fun x hx y hy => by simp only [Finset.mem_coe, V0, Finset.mem_filter] at hy simpa [KWProtocol.run, hy.2] using hsol x hx y hy.1) have hB1 := ih1 U V1 hUA ((Finset.filter_subset _ V).trans hVB) (fun x hx y hy => by simp only [Finset.mem_coe, V1, Finset.mem_filter] at hy simpa [KWProtocol.run, hy.2] using hsol x hx y hy.1) have hCsum : ∑ i : Fin n, ((KWProtocol.bob bit p0 p1).leafCount i : ℝ) * C i = (∑ i : Fin n, (p0.leafCount i : ℝ) * C i) + (∑ i : Fin n, (p1.leafCount i : ℝ) * C i) := by simp [KWProtocol.leafCount, add_mul, Finset.sum_add_distrib] rw [hCsum] refine ⟨add_nonneg hB0.1 hB1.1, fun u v => ?_⟩ have hpart_M : ∑ x ∈ U, ∑ y ∈ V, u x * M x y * v y = (∑ x ∈ U, ∑ y ∈ V0, u x * M x y * v y) + (∑ x ∈ U, ∑ y ∈ V1, u x * M x y * v y) := by rw [← Finset.sum_add_distrib]; apply Finset.sum_congr rfl; intro x _ have h := Finset.sum_filter_add_sum_filter_not V (fun y => bit y = false) (fun y => u x * M x y * v y) have hV1 : V.filter (fun y => ¬bit y = false) = V1 := by ext y; simp [V1] rw [hV1] at h; exact h.symm have hpart_v : ∑ y ∈ V, (v y) ^ 2 = (∑ y ∈ V0, (v y) ^ 2) + (∑ y ∈ V1, (v y) ^ 2) := by have h := Finset.sum_filter_add_sum_filter_not V (fun y => bit y = false) (fun y => (v y) ^ 2) have hV1 : V.filter (fun y => ¬bit y = false) = V1 := by ext y; simp [V1] rw [hV1] at h; exact h.symm rw [hpart_M, hpart_v] have hs0 : 0 ≤ (∑ x ∈ U, (u x) ^ 2) * (∑ y ∈ V0, (v y) ^ 2) := mul_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) have hs1 : 0 ≤ (∑ x ∈ U, (u x) ^ 2) * (∑ y ∈ V1, (v y) ^ 2) := mul_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) have hcs := sq_add_le_mul_add hB0.1 hB1.1 hs0 hs1 (by rw [← mul_assoc]; exact hB0.2 u v) (by rw [← mul_assoc]; exact hB1.2 u v) linarith exact hgen P A B (Finset.Subset.refl A) (Finset.Subset.refl B) hP /-- A partial-matching matrix (0/1 entries with at most one `1` per row and per column) has `BilinearSpectralBound · A B 1`! -/ lemma bilinearSpectralBound_partial_matching {α β : Type*} [DecidableEq α] [DecidableEq β] (A : Finset α) (B : Finset β) (R : α → β → Prop) [DecidableRel R] (hrow : ∀ x ∈ A, ∀ y1 ∈ B, ∀ y2 ∈ B, R x y1 → R x y2 → y1 = y2) (hcol : ∀ y ∈ B, ∀ x1 ∈ A, ∀ x2 ∈ A, R x1 y → R x2 y → x1 = x2) : BilinearSpectralBound (fun x y => if R x y then (1 : ℝ) else 0) A B 1 := by refine ⟨by norm_num, fun u v => ?_⟩ rw [one_mul] let f : α → ℝ := fun x => ∑ y ∈ B, if R x y then v y else 0 have hsum_eq : ∑ x ∈ A, ∑ y ∈ B, u x * (if R x y then (1 : ℝ) else 0) * v y = ∑ x ∈ A, u x * f x := by apply Finset.sum_congr rfl; intro x _ simp only [f, Finset.mul_sum] apply Finset.sum_congr rfl; intro y _; split_ifs <;> ring rw [hsum_eq] have hcs := Finset.sum_mul_sq_le_sq_mul_sq A u f have hf_le : ∑ x ∈ A, (f x) ^ 2 ≤ ∑ y ∈ B, (v y) ^ 2 := by have hfx : ∀ x ∈ A, (f x) ^ 2 = ∑ y ∈ B, if R x y then (v y) ^ 2 else 0 := by intro x hx by_cases hex : ∃ y ∈ B, R x y · rcases hex with ⟨y0, hy0B, hR0⟩ simp only [f] rw [Finset.sum_eq_single y0, Finset.sum_eq_single y0] · simp [hR0] · intro y hyB hyne; simp [show ¬R x y from fun h => hyne (hrow x hx y hyB y0 hy0B h hR0)] · intro hnot; exact absurd hy0B hnot · intro y hyB hyne; simp [show ¬R x y from fun h => hyne (hrow x hx y hyB y0 hy0B h hR0)] · intro hnot; exact absurd hy0B hnot · push Not at hex have h0 : ∑ y ∈ B, (if R x y then v y else 0) = 0 := Finset.sum_eq_zero (fun y hy => by simp [hex y hy]) have h0' : ∑ y ∈ B, (if R x y then (v y) ^ 2 else 0) = 0 := Finset.sum_eq_zero (fun y hy => by simp [hex y hy]) simp only [f] rw [h0, h0']; ring rw [Finset.sum_congr rfl hfx, Finset.sum_comm] apply Finset.sum_le_sum; intro y hyB by_cases hex : ∃ x ∈ A, R x y · rcases hex with ⟨x0, hx0A, hR0⟩ rw [Finset.sum_eq_single x0] · simp [hR0] · intro x hxA hxne; simp [show ¬R x y from fun h => hxne (hcol y hyB x hxA x0 hx0A h hR0)] · intro hnot; exact absurd hx0A hnot · push Not at hex rw [Finset.sum_eq_zero (fun x hx => by simp [hex x hx])] exact sq_nonneg _ exact hcs.trans (mul_le_mul_of_nonneg_left hf_le (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) /-- **Khrapchenko / Distance-1 Monotone Witness Structure:** Packages a uniform-weight (or general) monotone distance-1 adversary `(A, B, E)` witnessing `L⁺(f) ≥ |E|² / (|A| · |B|)` AND composing multiplicatively! -/ structure MonotoneDist1Witness (n : ℕ) (f : (Fin n → Bool) → Bool) where A : Finset (Fin n → Bool) B : Finset (Fin n → Bool) hA : ∀ x ∈ A, f x = true hB : ∀ y ∈ B, f y = false hAne : A.Nonempty hBne : B.Nonempty /-- Monotone distance-1 edge set: pairs `(x, y) ∈ A × B` differing at a single `i` with `x i = true, y i = false`. -/ E : Finset ((Fin n → Bool) × (Fin n → Bool)) hE_mem : ∀ p ∈ E, p.1 ∈ A ∧ p.2 ∈ B hE_dist1 : ∀ p ∈ E, ∃ i : Fin n, p.1 i = true ∧ p.2 i = false ∧ ∀ j ≠ i, p.1 j = p.2 j /-- Every `MonotoneDist1Witness` immediately yields the Khrapchenko formula-size lower bound `|E|² ≤ F.leafSize * |A| * |B|` via Theorem 11A! -/ theorem monotoneDist1Witness_leafSize_lb {n : ℕ} {f : (Fin n → Bool) → Bool} (W : MonotoneDist1Witness n f) (F : MonotoneFormula n) (hF : ∀ x, F.eval x = f x) : W.E.card ^ 2 ≤ F.leafSize * W.A.card * W.B.card := by let M : (Fin n → Bool) → (Fin n → Bool) → ℝ := fun x y => if (x, y) ∈ W.E then 1 else 0 have hP := MKWProtocol.ofFormula_solves F have hPAB : (MKWProtocol.ofFormula F).Solves (W.A : Set (Fin n → Bool)) (W.B : Set (Fin n → Bool)) := by intro x hx y hy exact hP x (by simp [hF, W.hA x hx]) y (by simp [hF, W.hB y hy]) have hCi : ∀ i : Fin n, BilinearSpectralBound (fun x y => if x i = true ∧ y i = false then M x y else 0) W.A W.B 1 := by intro i have hEq : (fun x y => if x i = true ∧ y i = false then M x y else 0) = (fun x y => if ((x, y) ∈ W.E ∧ x i = true ∧ y i = false) then (1 : ℝ) else 0) := by funext x y; simp only [M]; split_ifs <;> simp_all rw [hEq] apply bilinearSpectralBound_partial_matching W.A W.B (fun x y => (x, y) ∈ W.E ∧ x i = true ∧ y i = false) · intro x _ y1 _ y2 _ ⟨hE1, _, hy1⟩ ⟨hE2, _, hy2⟩ rcases W.hE_dist1 (x, y1) hE1 with ⟨i1, _, _, hall1⟩ rcases W.hE_dist1 (x, y2) hE2 with ⟨i2, _, _, hall2⟩ have hi1 : i1 = i := by by_contra hne; have := hall1 i (Ne.symm hne); simp_all have hi2 : i2 = i := by by_contra hne; have := hall2 i (Ne.symm hne); simp_all rw [hi1] at hall1; rw [hi2] at hall2 funext j by_cases hj : j = i · subst hj; exact hy1.trans hy2.symm · exact (hall1 j hj).symm.trans (hall2 j hj) · intro y _ x1 _ x2 _ ⟨hE1, hx1, _⟩ ⟨hE2, hx2, _⟩ rcases W.hE_dist1 (x1, y) hE1 with ⟨i1, _, _, hall1⟩ rcases W.hE_dist1 (x2, y) hE2 with ⟨i2, _, _, hall2⟩ have hi1 : i1 = i := by by_contra hne; have := hall1 i (Ne.symm hne); simp_all have hi2 : i2 = i := by by_contra hne; have := hall2 i (Ne.symm hne); simp_all rw [hi1] at hall1; rw [hi2] at hall2 funext j by_cases hj : j = i · subst hj; exact hx1.trans hx2.symm · exact (hall1 j hj).trans (hall2 j hj).symm have hB := mkw_bilinear_adversary_bound (MKWProtocol.ofFormula F) W.A W.B M (fun _ => 1) hCi hPAB have hsumL : ∑ i : Fin n, ((MKWProtocol.ofFormula F).leafCount i : ℝ) * 1 = (F.leafSize : ℝ) := by simp_rw [mul_one, MKWProtocol.leafCount_ofFormula] rw [← Nat.cast_sum, MonotoneFormula.sum_varCount] rw [hsumL] at hB have heval := hB.2 (fun _ => 1) (fun _ => 1) have hsumM : ∑ x ∈ W.A, ∑ y ∈ W.B, (1 : ℝ) * M x y * 1 = (W.E.card : ℝ) := by simp only [one_mul, mul_one, M] rw [← Finset.sum_product'] have hfilt : (W.A ×ˢ W.B).filter (fun p => p ∈ W.E) = W.E := by ext p; simp only [Finset.mem_filter, Finset.mem_product] exact ⟨fun h => h.2, fun h => ⟨W.hE_mem p h, h⟩⟩ rw [← Finset.sum_filter, hfilt, Finset.sum_const, nsmul_eq_mul, mul_one] rw [hsumM] at heval simp only [one_pow, Finset.sum_const, nsmul_eq_mul, mul_one] at heval exact_mod_cast heval /-- **Exact Khrapchenko Lower Bound for Every Threshold Function `THR_k^n` (`1 ≤ k ≤ n`):** Every monotone formula computing `THR_k^n` has leaf-size at least `k * (n - k + 1)`! -/ theorem monotone_formula_khrapchenko_thr {n k : ℕ} (hk1 : 1 ≤ k) (hkn : k ≤ n) (F : MonotoneFormula n) (hF : ∀ x : Fin n → Bool, F.eval x = decide (k ≤ hammingWeight x)) : k * (n - k + 1) ≤ F.leafSize := by let A := Finset.univ.filter (fun x : Fin n → Bool => hammingWeight x = k) let B := Finset.univ.filter (fun y : Fin n → Bool => hammingWeight y = k - 1) let E := (A ×ˢ B).filter (fun p => ∃ i : Fin n, p.1 i = true ∧ p.2 i = false ∧ ∀ j ≠ i, p.1 j = p.2 j) have hAcard : A.card = n.choose k := by have hcp : (Finset.powersetCard k (Finset.univ : Finset (Fin n))).card = n.choose k := by simp [Finset.card_powersetCard] rw [← hcp] refine Finset.card_bij (fun x _ => boolSupp x) ?_ ?_ ?_ · intro x hx; simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] at hx exact Finset.mem_powersetCard.mpr ⟨Finset.subset_univ _, hx⟩ · intro x1 _ x2 _ heq; funext i have := Finset.ext_iff.mp heq i; simp [boolSupp] at this; exact this · intro S hS; rw [Finset.mem_powersetCard] at hS exact ⟨indicatorBool S, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by rw [hammingWeight, boolSupp_indicatorBool, hS.2]⟩, boolSupp_indicatorBool S⟩ have hBcard : B.card = n.choose (k - 1) := by have hcp : (Finset.powersetCard (k - 1) (Finset.univ : Finset (Fin n))).card = n.choose (k - 1) := by simp [Finset.card_powersetCard] rw [← hcp] refine Finset.card_bij (fun y _ => boolSupp y) ?_ ?_ ?_ · intro y hy; simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] at hy exact Finset.mem_powersetCard.mpr ⟨Finset.subset_univ _, hy⟩ · intro y1 _ y2 _ heq; funext i have := Finset.ext_iff.mp heq i; simp [boolSupp] at this; exact this · intro S hS; rw [Finset.mem_powersetCard] at hS exact ⟨indicatorBool S, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by rw [hammingWeight, boolSupp_indicatorBool, hS.2]⟩, boolSupp_indicatorBool S⟩ have hApos : 0 < A.card := by rw [hAcard]; exact Nat.choose_pos hkn have hBpos : 0 < B.card := by rw [hBcard]; exact Nat.choose_pos (by omega) -- Count `|E| = k * |A|`! have hEcard : E.card = k * A.card := by have hbij : E.card = ∑ x ∈ A, (boolSupp x).card := by have h1 : E.card = ∑ x ∈ A, (B.filter (fun y => ∃ i : Fin n, x i = true ∧ y i = false ∧ ∀ j ≠ i, x j = y j)).card := by simp only [E, Finset.card_filter, Finset.sum_product] rw [h1] apply Finset.sum_congr rfl intro x hx simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] at hx refine Finset.card_bij (fun y hy => Classical.choose (Finset.mem_filter.mp hy).2) ?_ ?_ ?_ · intro y hy have hspec := Classical.choose_spec (Finset.mem_filter.mp hy).2 simp [boolSupp, hspec.1] · intro y1 hy1 y2 hy2 heq have hs1 := Classical.choose_spec (Finset.mem_filter.mp hy1).2 have hs2 := Classical.choose_spec (Finset.mem_filter.mp hy2).2 rw [heq] at hs1 funext j by_cases hj : j = Classical.choose (Finset.mem_filter.mp hy2).2 · subst hj; exact hs1.2.1.trans hs2.2.1.symm · exact (hs1.2.2 j hj).symm.trans (hs2.2.2 j hj) · intro i hi simp only [boolSupp, Finset.mem_filter, Finset.mem_univ, true_and] at hi let y := Function.update x i false have hyB : y ∈ B := by simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] have hsupp : boolSupp y = (boolSupp x).erase i := by ext j; by_cases hj : j = i · subst hj; simp [boolSupp, y] · simp [boolSupp, y, hj] have hmem : i ∈ boolSupp x := by simp [boolSupp, hi] rw [hammingWeight, hsupp, Finset.card_erase_of_mem hmem] change hammingWeight x - 1 = k - 1; omega have hyP : ∃ i' : Fin n, x i' = true ∧ y i' = false ∧ ∀ j ≠ i', x j = y j := ⟨i, hi, by simp [y], fun j hj => by simp [y, hj]⟩ refine ⟨y, Finset.mem_filter.mpr ⟨hyB, hyP⟩, ?_⟩ have hspec := Classical.choose_spec hyP by_contra hne have := hspec.2.2 i (Ne.symm hne) simp [y, hi] at this rw [hbij] have hconst : ∑ x ∈ A, (boolSupp x).card = ∑ _x ∈ A, k := by apply Finset.sum_congr rfl; intro x hx simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] at hx; exact hx rw [hconst, Finset.sum_const, smul_eq_mul, mul_comm] let W : MonotoneDist1Witness n (fun x => decide (k ≤ hammingWeight x)) := { A := A, B := B hA := fun x hx => by simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] at hx; simp [hx] hB := fun y hy => by simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] at hy; simp; omega hAne := Finset.card_pos.mp hApos hBne := Finset.card_pos.mp hBpos E := E hE_mem := fun p hp => Finset.mem_product.mp (Finset.mem_filter.mp hp).1 hE_dist1 := fun p hp => (Finset.mem_filter.mp hp).2 } have hlb := monotoneDist1Witness_leafSize_lb W F hF change E.card ^ 2 ≤ F.leafSize * A.card * B.card at hlb -- Note `k * C(n, k) = (n - k + 1) * C(n, k - 1)`! have hcomb : k * A.card = (n - k + 1) * B.card := by rw [hAcard, hBcard] have hk' : k = (k - 1) + 1 := by omega have h := Nat.choose_succ_right_eq n (k - 1) rw [← hk'] at h have hsub : n - (k - 1) = n - k + 1 := by omega rw [hsub] at h linarith have hprod : k * (n - k + 1) * (A.card * B.card) ≤ F.leafSize * (A.card * B.card) := by calc k * (n - k + 1) * (A.card * B.card) = (k * A.card) * ((n - k + 1) * B.card) := by ring _ = (k * A.card) ^ 2 := by rw [← hcomb]; ring _ = E.card ^ 2 := by rw [hEcard] _ ≤ F.leafSize * A.card * B.card := hlb _ = F.leafSize * (A.card * B.card) := by ring exact Nat.le_of_mul_le_mul_right hprod (Nat.mul_pos hApos hBpos) /-- **Exact Khrapchenko Lower Bound for `PARITY_n` on General De Morgan Formulas:** Every De Morgan formula computing `PARITY_n` has leaf-size at least `n ^ 2`! -/ theorem demorgan_formula_khrapchenko_parity {n : ℕ} (hn : 1 ≤ n) (F : DeMorganFormula n) (hF : ∀ x : Fin n → Bool, F.eval x = decide (hammingWeight x % 2 = 1)) : n ^ 2 ≤ F.leafSize := by let A := Finset.univ.filter (fun x : Fin n → Bool => hammingWeight x % 2 = 1) let B := Finset.univ.filter (fun y : Fin n → Bool => hammingWeight y % 2 = 0) let M : (Fin n → Bool) → (Fin n → Bool) → ℝ := fun x y => if hammingDist x y = 1 then 1 else 0 have hP := KWProtocol.ofFormula_solves F have hPAB : (KWProtocol.ofFormula F).Solves (A : Set (Fin n → Bool)) (B : Set (Fin n → Bool)) := by intro x hx y hy simp only [Finset.mem_coe, A, B, Finset.mem_filter, Finset.mem_univ, true_and] at hx hy exact hP x (by simp [hF, hx]) y (by simp [hF, hy]) have hCi : ∀ i : Fin n, BilinearSpectralBound (fun x y => if x i ≠ y i then M x y else 0) A B 1 := by intro i have hEq : (fun x y => if x i ≠ y i then M x y else 0) = (fun x y => if (hammingDist x y = 1 ∧ x i ≠ y i) then (1 : ℝ) else 0) := by funext x y; simp only [M]; split_ifs <;> simp_all rw [hEq] have huniq : ∀ x y : Fin n → Bool, hammingDist x y = 1 → x i ≠ y i → y = Function.update x i (!x i) := by intro x y hdist hne have hmem : i ∈ Finset.univ.filter (fun j : Fin n => x j ≠ y j) := by simp [hne] have hsing : Finset.univ.filter (fun j : Fin n => x j ≠ y j) = {i} := Finset.eq_singleton_iff_unique_mem.mpr ⟨hmem, fun j hj => by by_contra hji have hpair : {j, i} ⊆ Finset.univ.filter (fun u : Fin n => x u ≠ y u) := by intro u hu; simp only [Finset.mem_insert, Finset.mem_singleton] at hu rcases hu with rfl | rfl; exact hj; exact hmem have h2 : 2 ≤ hammingDist x y := by calc 2 = ({j, i} : Finset (Fin n)).card := (Finset.card_pair hji).symm _ ≤ hammingDist x y := Finset.card_le_card hpair omega⟩ funext j by_cases hj : j = i · subst hj; simp only [Function.update_self]; cases hxi : x j <;> cases hyj : y j <;> simp_all · simp only [Function.update_of_ne hj] by_contra hdiff have hjmem : j ∈ Finset.univ.filter (fun u : Fin n => x u ≠ y u) := by simp [Ne.symm hdiff] rw [hsing, Finset.mem_singleton] at hjmem exact hj hjmem apply bilinearSpectralBound_partial_matching A B (fun x y => hammingDist x y = 1 ∧ x i ≠ y i) · intro x _ y1 _ y2 _ ⟨hd1, hn1⟩ ⟨hd2, hn2⟩ rw [huniq x y1 hd1 hn1, huniq x y2 hd2 hn2] · intro y _ x1 _ x2 _ ⟨hd1, hn1⟩ ⟨hd2, hn2⟩ have hsym : ∀ a b : Fin n → Bool, hammingDist a b = hammingDist b a := fun a b => by unfold hammingDist; congr 1; ext j simp only [Finset.mem_filter, Finset.mem_univ, true_and]; exact ne_comm rw [huniq y x1 (hsym x1 y ▸ hd1) (Ne.symm hn1), huniq y x2 (hsym x2 y ▸ hd2) (Ne.symm hn2)] have hB := kw_bilinear_adversary_bound (KWProtocol.ofFormula F) A B M (fun _ => 1) hCi hPAB have hsumL : ∑ i : Fin n, ((KWProtocol.ofFormula F).leafCount i : ℝ) * 1 = (F.leafSize : ℝ) := by simp_rw [mul_one, KWProtocol.leafCount_ofFormula] rw [← Nat.cast_sum, DeMorganFormula.sum_varCount] rw [hsumL] at hB have heval := hB.2 (fun _ => 1) (fun _ => 1) let i0 : Fin n := ⟨0, hn⟩ have hflip_parity : ∀ (x : Fin n → Bool) (i : Fin n), hammingWeight (Function.update x i (!x i)) % 2 ≠ hammingWeight x % 2 := by intro x i cases hx : x i · have hs : boolSupp (Function.update x i (!x i)) = insert i (boolSupp x) := by ext j; by_cases hj : j = i · subst hj; simp [boolSupp, hx] · simp [boolSupp, hj] have hnot : i ∉ boolSupp x := by simp [boolSupp, hx] have hw : hammingWeight (Function.update x i (!x i)) = hammingWeight x + 1 := by simp [hammingWeight, hs, Finset.card_insert_of_notMem hnot] rw [hx] at hw; rw [hw]; omega · have hs : boolSupp x = insert i (boolSupp (Function.update x i (!x i))) := by ext j; by_cases hj : j = i · subst hj; simp [boolSupp, hx] · simp [boolSupp, hj] have hnot : i ∉ boolSupp (Function.update x i (!x i)) := by simp [boolSupp, hx] have hw : hammingWeight x = hammingWeight (Function.update x i (!x i)) + 1 := by simp [hammingWeight, hs, Finset.card_insert_of_notMem hnot] rw [hx] at hw; rw [hw]; omega have hABeq : A.card = B.card := by refine Finset.card_bij (fun x _ => Function.update x i0 (!x i0)) ?_ ?_ ?_ · intro x hx simp only [A, B, Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢ have := hflip_parity x i0; omega · intro x1 _ x2 _ heq; funext j by_cases hj : j = i0 · subst hj; have := congrFun heq i0; simp at this; exact this · have := congrFun heq j; simpa [hj] using this · intro y hy simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] at hy refine ⟨Function.update y i0 (!y i0), ?_, ?_⟩ · simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] have := hflip_parity y i0; omega · funext j; by_cases hj : j = i0 · subst hj; simp · simp [hj] have hApos : 0 < A.card := by refine Finset.card_pos.mpr ⟨fun j => decide (j = i0), ?_⟩ simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] have : boolSupp (fun j : Fin n => decide (j = i0)) = {i0} := by ext j; simp [boolSupp] simp [hammingWeight, this] have hrow_n : ∀ x ∈ A, ∑ y ∈ B, (1 : ℝ) * M x y * 1 = (n : ℝ) := by intro x hx simp only [one_mul, mul_one, M] rw [← Finset.sum_filter, Finset.sum_const, nsmul_eq_mul, mul_one] congr 1 have hcard : (B.filter (fun y => hammingDist x y = 1)).card = (Finset.univ : Finset (Fin n)).card := by have hex_diff : ∀ y ∈ B.filter (fun y => hammingDist x y = 1), (Finset.univ.filter (fun j : Fin n => x j ≠ y j)).Nonempty := by intro y hy exact Finset.card_pos.mp (by have := (Finset.mem_filter.mp hy).2; unfold hammingDist at this; omega) refine Finset.card_bij (fun y hy => Classical.choose (hex_diff y hy)) ?_ ?_ ?_ · intro _ _; exact Finset.mem_univ _ · intro y1 hy1 y2 hy2 heq have hd1 := (Finset.mem_filter.mp hy1).2 have hd2 := (Finset.mem_filter.mp hy2).2 set i1 : Fin n := Classical.choose (hex_diff y1 hy1) set i2 : Fin n := Classical.choose (hex_diff y2 hy2) have hs1 : i1 ∈ Finset.univ.filter (fun j : Fin n => x j ≠ y1 j) := Classical.choose_spec (hex_diff y1 hy1) have hs2 : i2 ∈ Finset.univ.filter (fun j : Fin n => x j ≠ y2 j) := Classical.choose_spec (hex_diff y2 hy2) have hsing1 : Finset.univ.filter (fun j : Fin n => x j ≠ y1 j) = {i1} := by refine Finset.eq_singleton_iff_unique_mem.mpr ⟨hs1, fun j hj => ?_⟩ by_contra hji have h2 : 2 ≤ hammingDist x y1 := by calc 2 = ({j, i1} : Finset (Fin n)).card := (Finset.card_pair hji).symm _ ≤ hammingDist x y1 := Finset.card_le_card (fun u hu => by simp only [Finset.mem_insert, Finset.mem_singleton] at hu rcases hu with rfl | rfl; exact hj; exact hs1) omega have hsing2 : Finset.univ.filter (fun j : Fin n => x j ≠ y2 j) = {i2} := by refine Finset.eq_singleton_iff_unique_mem.mpr ⟨hs2, fun j hj => ?_⟩ by_contra hji have h2 : 2 ≤ hammingDist x y2 := by calc 2 = ({j, i2} : Finset (Fin n)).card := (Finset.card_pair hji).symm _ ≤ hammingDist x y2 := Finset.card_le_card (fun u hu => by simp only [Finset.mem_insert, Finset.mem_singleton] at hu rcases hu with rfl | rfl; exact hj; exact hs2) omega have hi : i1 = i2 := heq funext j by_cases hj : j = i1 · subst hj have h1 : x i1 ≠ y1 i1 := (Finset.mem_filter.mp hs1).2 have h2 : x i1 ≠ y2 i1 := by rw [← hi] at hs2; exact (Finset.mem_filter.mp hs2).2 cases hx' : x i1 <;> cases hy1' : y1 i1 <;> cases hy2' : y2 i1 <;> simp_all · have h1 : x j = y1 j := by by_contra hne; have hm : j ∈ Finset.univ.filter (fun u => x u ≠ y1 u) := by simp [hne] rw [hsing1, Finset.mem_singleton] at hm; exact hj hm have h2 : x j = y2 j := by by_contra hne; have hm : j ∈ Finset.univ.filter (fun u => x u ≠ y2 u) := by simp [hne] rw [hsing2, Finset.mem_singleton, ← hi] at hm; exact hj hm exact h1.symm.trans h2 · intro i _ let y := Function.update x i (!x i) have hyB : y ∈ B := by simp only [A, Finset.mem_filter, Finset.mem_univ, true_and] at hx simp only [B, Finset.mem_filter, Finset.mem_univ, true_and] dsimp only [y] have := hflip_parity x i; omega have hydist : hammingDist x y = 1 := by have hs : Finset.univ.filter (fun j : Fin n => x j ≠ y j) = {i} := by ext j; by_cases hj : j = i · subst hj; simp [y] · simp [y, hj] simp [hammingDist, hs] have hymem : y ∈ B.filter (fun y => hammingDist x y = 1) := Finset.mem_filter.mpr ⟨hyB, hydist⟩ refine ⟨y, hymem, ?_⟩ have hspec := Classical.choose_spec (hex_diff y hymem) simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hspec by_contra hne simp [y, hne] at hspec simpa using hcard have hsumM : ∑ x ∈ A, ∑ y ∈ B, (1 : ℝ) * M x y * 1 = (n : ℝ) * (A.card : ℝ) := by rw [Finset.sum_congr rfl hrow_n, Finset.sum_const, nsmul_eq_mul, mul_comm] rw [hsumM] at heval simp only [one_pow, Finset.sum_const, nsmul_eq_mul, mul_one, hABeq] at heval have hAposR : (0 : ℝ) < (B.card : ℝ) ^ 2 := by have : 0 < B.card := by omega positivity have hnat : (n ^ 2 : ℝ) * (B.card : ℝ) ^ 2 ≤ (F.leafSize : ℝ) * (B.card : ℝ) ^ 2 := by linarith [heval] have hleR : (n ^ 2 : ℝ) ≤ (F.leafSize : ℝ) := le_of_mul_le_mul_right hnat hAposR exact_mod_cast hleR /-- **HEADLINE THEOREM 12 (Exact Multiplicative Composition for Distance-1 Monotone Witnesses & Iterated Majority):** If `W_f` is a uniform-weight monotone distance-1 witness for `f : (Fin m → Bool) → Bool` (all `x ∈ W_f.A` have weight `k_f`, all `y ∈ W_f.B` have weight `k_f - 1`), and `W_g` is ANY monotone distance-1 witness for `g : (Fin k → Bool) → Bool`, then `f ∘ g` admits an explicit monotone distance-1 witness `W_{f∘g}` whose Khrapchenko ratio **multiplies identically**: `(|E_{f∘g}|^2) * (|A_f| |B_f| |A_g| |B_g|) = (|E_f|^2 |E_g|^2) * (|A_{f∘g}| |B_{f∘g}|)`! Consequently, for `t`-fold iterated Majority `MAJ₃^{∘t}` on `3^t` variables: `4^t ≤ L⁺(MAJ₃^{∘t})` and `2 * t ≤ D⁺(MAJ₃^{∘t})`! -/ def composeBoolFun {m k : ℕ} (f : (Fin m → Bool) → Bool) (g : (Fin k → Bool) → Bool) : (Fin (m * k) → Bool) → Bool := fun z => f (fun j => g (fun r => z ⟨j.val * k + r.val, by have hj := j.isLt; have hr := r.isLt calc j.val * k + r.val < j.val * k + k := Nat.add_lt_add_left hr _ _ = (j.val + 1) * k := by ring _ ≤ m * k := Nat.mul_le_mul_right k hj⟩)) /-- Pack a block matrix `φ : Fin m → Fin k → Bool` into `Fin (m * k) → Bool`. -/ def packBlocks {m k : ℕ} (φ : Fin m → Fin k → Bool) : Fin (m * k) → Bool := fun idx => have hk : 0 < k := by by_contra h0; push Not at h0 have hk0 : k = 0 := by omega have hmk : m * k = 0 := by rw [hk0, mul_zero] have hlt := idx.isLt omega have hlt_km : idx.val < k * m := by have hlt := idx.isLt have hcomm : m * k = k * m := mul_comm m k omega φ ⟨idx.val / k, Nat.div_lt_of_lt_mul hlt_km⟩ ⟨idx.val % k, Nat.mod_lt idx.val hk⟩ lemma packBlocks_apply {m k : ℕ} (φ : Fin m → Fin k → Bool) (j : Fin m) (r : Fin k) (h : j.val * k + r.val < m * k) : packBlocks φ ⟨j.val * k + r.val, h⟩ = φ j r := by have hk : 0 < k := Nat.lt_of_le_of_lt (Nat.zero_le _) r.isLt unfold packBlocks have hdiv : (j.val * k + r.val) / k = j.val := by rw [mul_comm j.val k, Nat.mul_add_div hk, Nat.div_eq_of_lt r.isLt, add_zero] have hmod : (j.val * k + r.val) % k = r.val := by rw [mul_comm j.val k, Nat.mul_add_mod, Nat.mod_eq_of_lt r.isLt] simp only [hdiv, hmod, Fin.eta] lemma packBlocks_injective {m k : ℕ} : Function.Injective (packBlocks (m := m) (k := k)) := by intro φ1 φ2 heq funext j r have hlt : j.val * k + r.val < m * k := by have hj := j.isLt; have hr := r.isLt calc j.val * k + r.val < j.val * k + k := Nat.add_lt_add_left hr _ _ = (j.val + 1) * k := by ring _ ≤ m * k := Nat.mul_le_mul_right k hj have h := congrFun heq ⟨j.val * k + r.val, hlt⟩ rwa [packBlocks_apply, packBlocks_apply] at h /-- Exact multiplicative witness composition theorem (uniform-weight outer witness `W_f` composed with ANY inner witness `W_g`, yielding exact product of Khrapchenko ratios!). -/ theorem monotoneDist1Witness_compose_mult {m k kf : ℕ} {f : (Fin m → Bool) → Bool} {g : (Fin k → Bool) → Bool} (Wf : MonotoneDist1Witness m f) (Wg : MonotoneDist1Witness k g) (hWfA : ∀ x ∈ Wf.A, hammingWeight x = kf) (hWfB : ∀ y ∈ Wf.B, hammingWeight y = kf - 1) (hkf : 1 ≤ kf) : ∃ Wfg : MonotoneDist1Witness (m * k) (composeBoolFun f g), Wfg.E.card ^ 2 * (Wf.A.card * Wf.B.card * Wg.A.card * Wg.B.card) = (Wf.E.card ^ 2 * Wg.E.card ^ 2) * (Wfg.A.card * Wfg.B.card) := by classical let liftSet : (Fin m → Bool) → Finset (Fin m → Fin k → Bool) := fun x => Fintype.piFinset (fun j : Fin m => if x j then Wg.A else Wg.B) have hlift_card : ∀ x : Fin m → Bool, (liftSet x).card = Wg.A.card ^ hammingWeight x * Wg.B.card ^ (m - hammingWeight x) := by intro x simp only [liftSet, Fintype.card_piFinset] have hprod : ∏ j : Fin m, (if x j = true then Wg.A else Wg.B).card = ∏ j : Fin m, (if x j = true then Wg.A.card else Wg.B.card) := by apply Finset.prod_congr rfl; intro j _; split_ifs <;> rfl rw [hprod, Finset.prod_ite, Finset.prod_const, Finset.prod_const] have hc1 : (Finset.univ.filter (fun j : Fin m => x j = true)).card = hammingWeight x := rfl have hc2 : (Finset.univ.filter (fun j : Fin m => ¬x j = true)).card = m - hammingWeight x := by have htot : (Finset.univ.filter (fun j : Fin m => x j = true)).card + (Finset.univ.filter (fun j : Fin m => ¬x j = true)).card = m := by rw [← Finset.card_union_of_disjoint (Finset.disjoint_filter.mpr (fun _ _ h1 h2 => h2 h1))] have hun : Finset.univ.filter (fun j : Fin m => x j = true) ∪ Finset.univ.filter (fun j : Fin m => ¬x j = true) = Finset.univ := by ext j; simp rw [hun, Finset.card_univ, Fintype.card_fin] change hammingWeight x + _ = m at htot omega rw [hc1, hc2] -- Disjointness of `liftSet x1` and `liftSet x2` for `x1 ≠ x2` (since `Wg.A` and `Wg.B` are disjoint!) have hAB_disj : Disjoint Wg.A Wg.B := by rw [Finset.disjoint_left] intro a ha hb have h1 := Wg.hA a ha; have h2 := Wg.hB a hb rw [h1] at h2; exact Bool.noConfusion h2 have hlift_disj : ∀ x1 x2 : Fin m → Bool, x1 ≠ x2 → Disjoint (liftSet x1) (liftSet x2) := by intro x1 x2 hne rw [Finset.disjoint_left] intro φ h1 h2 have hex : ∃ j, x1 j ≠ x2 j := by by_contra hall; push Not at hall; exact hne (funext hall) rcases hex with ⟨j, hj⟩ have hm1 := Fintype.mem_piFinset.mp h1 j have hm2 := Fintype.mem_piFinset.mp h2 j cases hx1 : x1 j <;> cases hx2 : x2 j <;> simp_all · exact Finset.disjoint_left.mp hAB_disj hm2 hm1 · exact Finset.disjoint_left.mp hAB_disj hm1 hm2 let A_raw : Finset (Fin m → Fin k → Bool) := Wf.A.biUnion liftSet let B_raw : Finset (Fin m → Fin k → Bool) := Wf.B.biUnion liftSet let Afg : Finset (Fin (m * k) → Bool) := A_raw.image packBlocks let Bfg : Finset (Fin (m * k) → Bool) := B_raw.image packBlocks have hAfg_card : Afg.card = Wf.A.card * (Wg.A.card ^ kf * Wg.B.card ^ (m - kf)) := by rw [Finset.card_image_of_injective _ packBlocks_injective, Finset.card_biUnion] · have hcongr : ∑ x ∈ Wf.A, (liftSet x).card = ∑ _x ∈ Wf.A, (Wg.A.card ^ kf * Wg.B.card ^ (m - kf)) := by apply Finset.sum_congr rfl; intro x hx; rw [hlift_card x, hWfA x hx] rw [hcongr, Finset.sum_const, smul_eq_mul] · intro x1 _ x2 _ hne; exact hlift_disj x1 x2 hne have hBfg_card : Bfg.card = Wf.B.card * (Wg.A.card ^ (kf - 1) * Wg.B.card ^ (m - (kf - 1))) := by rw [Finset.card_image_of_injective _ packBlocks_injective, Finset.card_biUnion] · have hcongr : ∑ y ∈ Wf.B, (liftSet y).card = ∑ _y ∈ Wf.B, (Wg.A.card ^ (kf - 1) * Wg.B.card ^ (m - (kf - 1))) := by apply Finset.sum_congr rfl; intro y hy; rw [hlift_card y, hWfB y hy] rw [hcongr, Finset.sum_const, smul_eq_mul] · intro y1 _ y2 _ hne; exact hlift_disj y1 y2 hne -- Define `Efg` as pairs `(packBlocks φ, packBlocks ψ)` where `(x, y) ∈ Wf.E` (differing at `j₀`), -- `(φ j₀, ψ j₀) ∈ Wg.E`, and `∀ j ≠ j₀, φ j = ψ j`! let Efg := (Afg ×ˢ Bfg).filter (fun p => ∃ (φ ψ : Fin m → Fin k → Bool), p.1 = packBlocks φ ∧ p.2 = packBlocks ψ ∧ ((fun j => g (φ j)), (fun j => g (ψ j))) ∈ Wf.E ∧ ∃ j0 : Fin m, (φ j0, ψ j0) ∈ Wg.E ∧ ∀ j ≠ j0, φ j = ψ j) -- Helper: evaluate `composeBoolFun f g (packBlocks φ)` have hcomp_eval : ∀ φ : Fin m → Fin k → Bool, composeBoolFun f g (packBlocks φ) = f (fun j => g (φ j)) := by intro φ; unfold composeBoolFun; congr 1; funext j; congr 1; funext r; exact packBlocks_apply φ j r _ have hlift_g : ∀ x : Fin m → Bool, ∀ φ ∈ liftSet x, (fun j => g (φ j)) = x := by intro x φ hφ; funext j have hm := Fintype.mem_piFinset.mp hφ j cases hx : x j · simp only [hx, Bool.false_eq_true, ↓reduceIte] at hm; exact Wg.hB _ hm · simp only [hx, ↓reduceIte] at hm; exact Wg.hA _ hm -- Count `|Efg| = |Wf.E| * |Wg.E| * |Wg.A|^(kf - 1) * |Wg.B|^(m - kf)`! have hEfg_card : Efg.card = Wf.E.card * Wg.E.card * (Wg.A.card ^ (kf - 1) * Wg.B.card ^ (m - kf)) := by let j0Of : {ef // ef ∈ Wf.E} → Fin m := fun ef => Classical.choose (Wf.hE_dist1 ef.1 ef.2) have hj0_spec : ∀ ef : {ef // ef ∈ Wf.E}, ef.1.1 (j0Of ef) = true ∧ ef.1.2 (j0Of ef) = false ∧ ∀ j ≠ j0Of ef, ef.1.1 j = ef.1.2 j := fun ef => Classical.choose_spec (Wf.hE_dist1 ef.1 ef.2) let restSet : (ef : {ef // ef ∈ Wf.E}) → Finset (∀ j : {j : Fin m // j ≠ j0Of ef}, Fin k → Bool) := fun ef => Fintype.piFinset (fun j => if ef.1.1 j.1 then Wg.A else Wg.B) have hrest_card : ∀ ef : {ef // ef ∈ Wf.E}, (restSet ef).card = Wg.A.card ^ (kf - 1) * Wg.B.card ^ (m - kf) := by intro ef simp only [restSet, Fintype.card_piFinset] have hprod : ∏ j : {j : Fin m // j ≠ j0Of ef}, (if ef.1.1 j.1 = true then Wg.A else Wg.B).card = ∏ j ∈ (Finset.univ.erase (j0Of ef)), (if ef.1.1 j = true then Wg.A.card else Wg.B.card) := by refine Finset.prod_bij (fun j _ => j.1) ?_ ?_ ?_ ?_ · intro j _; exact Finset.mem_erase.mpr ⟨j.2, Finset.mem_univ _⟩ · intro j1 _ j2 _ heq; exact Subtype.ext heq · intro j hj; exact ⟨⟨j, (Finset.mem_erase.mp hj).1⟩, Finset.mem_univ _, rfl⟩ · intro j _; split_ifs <;> rfl rw [hprod, Finset.prod_ite, Finset.prod_const, Finset.prod_const] have hxe : ef.1.1 ∈ Wf.A := (Wf.hE_mem ef.1 ef.2).1 have hwx : hammingWeight ef.1.1 = kf := hWfA ef.1.1 hxe have hj0_t : ef.1.1 (j0Of ef) = true := (hj0_spec ef).1 have hc1 : ((Finset.univ.erase (j0Of ef)).filter (fun j : Fin m => ef.1.1 j = true)).card = kf - 1 := by have h1 : (Finset.univ.erase (j0Of ef)).filter (fun j : Fin m => ef.1.1 j = true) = (boolSupp ef.1.1).erase (j0Of ef) := by ext j; simp [boolSupp, and_comm] rw [h1, Finset.card_erase_of_mem (by simp [boolSupp, hj0_t])] change hammingWeight ef.1.1 - 1 = kf - 1; omega have hc2 : ((Finset.univ.erase (j0Of ef)).filter (fun j : Fin m => ¬ef.1.1 j = true)).card = m - kf := by have h1 : (Finset.univ.erase (j0Of ef)).filter (fun j : Fin m => ¬ef.1.1 j = true) = Finset.univ.filter (fun j : Fin m => ¬ef.1.1 j = true) := by ext j; simp only [Finset.mem_filter, Finset.mem_erase, Finset.mem_univ, true_and, and_true] constructor · exact fun h => h.2 · intro h; refine ⟨?_, h⟩; intro heq; subst heq; exact h hj0_t rw [h1] have htot : (Finset.univ.filter (fun j : Fin m => ef.1.1 j = true)).card + (Finset.univ.filter (fun j : Fin m => ¬ef.1.1 j = true)).card = m := by rw [← Finset.card_union_of_disjoint (Finset.disjoint_filter.mpr (fun _ _ h1 h2 => h2 h1))] have hun : Finset.univ.filter (fun j : Fin m => ef.1.1 j = true) ∪ Finset.univ.filter (fun j : Fin m => ¬ef.1.1 j = true) = Finset.univ := by ext j; simp rw [hun, Finset.card_univ, Fintype.card_fin] change hammingWeight ef.1.1 + _ = m at htot omega rw [hc1, hc2] let Dom := (Wf.E.attach.biUnion (fun ef => (Wg.E.attach ×ˢ restSet ef).image (fun p => let φ : Fin m → Fin k → Bool := fun j => if hj : j = j0Of ef then p.1.1.1 else p.2 ⟨j, hj⟩ let ψ : Fin m → Fin k → Bool := fun j => if hj : j = j0Of ef then p.1.1.2 else p.2 ⟨j, hj⟩ (packBlocks φ, packBlocks ψ)))) have hDom_eq : Efg = Dom := by ext ⟨z1, z2⟩ simp only [Efg, Dom, Finset.mem_filter, Finset.mem_product, Finset.mem_biUnion, Finset.mem_attach, true_and, Finset.mem_image] constructor · rintro ⟨⟨hz1, hz2⟩, φ, ψ, rfl, rfl, hfgE, j0, hj0E, hrest_eq⟩ let ef : {ef // ef ∈ Wf.E} := ⟨(fun j => g (φ j), fun j => g (ψ j)), hfgE⟩ have hj0_eq : j0 = j0Of ef := by have hs := hj0_spec ef by_contra hne have h1 := hs.2.2 j0 hne have hga := Wg.hA _ (Wg.hE_mem _ hj0E).1 have hgb := Wg.hB _ (Wg.hE_mem _ hj0E).2 simp only [ef] at h1; rw [hga, hgb] at h1; exact Bool.noConfusion h1 subst hj0_eq refine ⟨ef, (⟨(φ (j0Of ef), ψ (j0Of ef)), hj0E⟩, fun j => φ j.1), ?_, ?_⟩ · refine Fintype.mem_piFinset.mpr (fun j => ?_) simp only [Afg, A_raw, Finset.mem_image, Finset.mem_biUnion] at hz1 rcases hz1 with ⟨φ', ⟨x, _, hφ'⟩, hpack⟩ have hφeq : φ' = φ := packBlocks_injective hpack subst hφeq have hgx : (fun i => g (φ' i)) = x := hlift_g x φ' hφ' have hgj : g (φ' j.1) = x j.1 := congrFun hgx j.1 have hm := Fintype.mem_piFinset.mp hφ' j.1 simpa [ef, hgj] using hm · congr 1 · congr 1; funext j; by_cases hj : j = j0Of ef <;> simp [hj] · congr 1; funext j; by_cases hj : j = j0Of ef · subst hj; simp · simp [hj, hrest_eq j hj] · rintro ⟨ef, ⟨eg, rst⟩, hrst, heq⟩ rcases Prod.mk.inj heq with ⟨rfl, rfl⟩ let φ : Fin m → Fin k → Bool := fun j => if hj : j = j0Of ef then eg.1.1 else rst ⟨j, hj⟩ let ψ : Fin m → Fin k → Bool := fun j => if hj : j = j0Of ef then eg.1.2 else rst ⟨j, hj⟩ have hφ_mem : φ ∈ liftSet ef.1.1 := Fintype.mem_piFinset.mpr (fun j => by by_cases hj : j = j0Of ef · subst hj; simp [φ, (hj0_spec ef).1, (Wg.hE_mem eg.1 eg.2).1] · simp only [φ, hj, ↓reduceDIte]; exact Fintype.mem_piFinset.mp hrst ⟨j, hj⟩) have hψ_mem : ψ ∈ liftSet ef.1.2 := Fintype.mem_piFinset.mpr (fun j => by by_cases hj : j = j0Of ef · subst hj; simp [ψ, (hj0_spec ef).2.1, (Wg.hE_mem eg.1 eg.2).2] · simp only [ψ, hj, ↓reduceDIte] rw [← (hj0_spec ef).2.2 j hj] exact Fintype.mem_piFinset.mp hrst ⟨j, hj⟩) refine ⟨⟨Finset.mem_image.mpr ⟨φ, Finset.mem_biUnion.mpr ⟨ef.1.1, (Wf.hE_mem ef.1 ef.2).1, hφ_mem⟩, rfl⟩, Finset.mem_image.mpr ⟨ψ, Finset.mem_biUnion.mpr ⟨ef.1.2, (Wf.hE_mem ef.1 ef.2).2, hψ_mem⟩, rfl⟩⟩, φ, ψ, rfl, rfl, ?_, j0Of ef, ?_, fun j hj => by simp [φ, ψ, hj]⟩ · rw [hlift_g ef.1.1 φ hφ_mem, hlift_g ef.1.2 ψ hψ_mem]; exact ef.2 · simp [φ, ψ, eg.2] rw [hDom_eq, Finset.card_biUnion] · have hterm : ∀ ef ∈ Wf.E.attach, ((Wg.E.attach ×ˢ restSet ef).image (fun p => let φ : Fin m → Fin k → Bool := fun j => if hj : j = j0Of ef then p.1.1.1 else p.2 ⟨j, hj⟩ let ψ : Fin m → Fin k → Bool := fun j => if hj : j = j0Of ef then p.1.1.2 else p.2 ⟨j, hj⟩ (packBlocks φ, packBlocks ψ))).card = Wg.E.card * (Wg.A.card ^ (kf - 1) * Wg.B.card ^ (m - kf)) := by intro ef _ rw [Finset.card_image_of_injOn, Finset.card_product, Finset.card_attach, hrest_card ef] intro ⟨eg1, r1⟩ _ ⟨eg2, r2⟩ _ heq rcases Prod.mk.inj heq with ⟨h1, h2⟩ have hφ := packBlocks_injective h1 have hψ := packBlocks_injective h2 have heg1 : eg1.1.1 = eg2.1.1 := by have := congrFun hφ (j0Of ef); simpa using this have heg2 : eg1.1.2 = eg2.1.2 := by have := congrFun hψ (j0Of ef); simpa using this have hr : r1 = r2 := by funext ⟨j, hj⟩ have := congrFun hφ j simpa [hj] using this exact Prod.ext (Subtype.ext (Prod.ext heg1 heg2)) hr rw [Finset.sum_congr rfl hterm, Finset.sum_const, Finset.card_attach, smul_eq_mul, mul_assoc] · intro ef1 _ ef2 _ hne show Disjoint _ _ rw [Finset.disjoint_left] intro z hz1 hz2 rw [Finset.mem_image] at hz1 hz2 rcases hz1 with ⟨⟨eg1, r1⟩, hr1, rfl⟩ rcases hz2 with ⟨⟨eg2, r2⟩, hr2, heq⟩ rcases Prod.mk.inj heq with ⟨h1, h2⟩ have hφ := packBlocks_injective h1 have hψ := packBlocks_injective h2 have hrec : ∀ (ef : {ef // ef ∈ Wf.E}) (eg : {eg // eg ∈ Wg.E}) (r : ∀ j : {j : Fin m // j ≠ j0Of ef}, Fin k → Bool), r ∈ restSet ef → (fun j => g (if hj : j = j0Of ef then eg.1.1 else r ⟨j, hj⟩)) = ef.1.1 ∧ (fun j => g (if hj : j = j0Of ef then eg.1.2 else r ⟨j, hj⟩)) = ef.1.2 := by intro ef eg r hr constructor · funext j; by_cases hj : j = j0Of ef · subst hj; simp [(hj0_spec ef).1, Wg.hA _ (Wg.hE_mem _ eg.2).1] · simp only [hj, ↓reduceDIte] have hm := Fintype.mem_piFinset.mp hr (⟨j, hj⟩ : {j : Fin m // j ≠ j0Of ef}) cases hx : ef.1.1 j · simp only [hx, Bool.false_eq_true, ↓reduceIte] at hm; exact Wg.hB _ hm · simp only [hx, ↓reduceIte] at hm; exact Wg.hA _ hm · funext j; by_cases hj : j = j0Of ef · subst hj; simp [(hj0_spec ef).2.1, Wg.hB _ (Wg.hE_mem _ eg.2).2] · simp only [hj, ↓reduceDIte] have hm := Fintype.mem_piFinset.mp hr (⟨j, hj⟩ : {j : Fin m // j ≠ j0Of ef}) rw [(hj0_spec ef).2.2 j hj] at hm cases hy : ef.1.2 j · simp only [hy, Bool.false_eq_true, ↓reduceIte] at hm; exact Wg.hB _ hm · simp only [hy, ↓reduceIte] at hm; exact Wg.hA _ hm have h1r := hrec ef1 eg1 r1 (Finset.mem_product.mp hr1).2 have h2r := hrec ef2 eg2 r2 (Finset.mem_product.mp hr2).2 dsimp only at hφ hψ have heq1 : ef1.1.1 = ef2.1.1 := by rw [← h1r.1, ← h2r.1]; funext j; exact congrArg g (congrFun hφ j).symm have heq2 : ef1.1.2 = ef2.1.2 := by rw [← h1r.2, ← h2r.2]; funext j; exact congrArg g (congrFun hψ j).symm exact hne (Subtype.ext (Prod.ext heq1 heq2)) -- Package `Wfg`! have hAfg_pos : 0 < Afg.card := by rw [hAfg_card] exact Nat.mul_pos (Finset.card_pos.mpr Wf.hAne) (Nat.mul_pos (pow_pos (Finset.card_pos.mpr Wg.hAne) _) (pow_pos (Finset.card_pos.mpr Wg.hBne) _)) have hBfg_pos : 0 < Bfg.card := by rw [hBfg_card] exact Nat.mul_pos (Finset.card_pos.mpr Wf.hBne) (Nat.mul_pos (pow_pos (Finset.card_pos.mpr Wg.hAne) _) (pow_pos (Finset.card_pos.mpr Wg.hBne) _)) let Wfg : MonotoneDist1Witness (m * k) (composeBoolFun f g) := { A := Afg, B := Bfg hA := fun z hz => by simp only [Afg, A_raw, Finset.mem_image, Finset.mem_biUnion] at hz rcases hz with ⟨φ, ⟨x, hxA, hφ⟩, rfl⟩ rw [hcomp_eval, hlift_g x φ hφ]; exact Wf.hA x hxA hB := fun z hz => by simp only [Bfg, B_raw, Finset.mem_image, Finset.mem_biUnion] at hz rcases hz with ⟨ψ, ⟨y, hyB, hψ⟩, rfl⟩ rw [hcomp_eval, hlift_g y ψ hψ]; exact Wf.hB y hyB hAne := Finset.card_pos.mp hAfg_pos hBne := Finset.card_pos.mp hBfg_pos E := Efg hE_mem := fun p hp => by dsimp only [Efg] at hp; exact Finset.mem_product.mp (Finset.mem_filter.mp hp).1 hE_dist1 := fun p hp => by dsimp only [Efg] at hp rcases (Finset.mem_filter.mp hp).2 with ⟨φ, ψ, hp1, hp2, _, j0, hj0E, hrest⟩ rcases Wg.hE_dist1 (φ j0, ψ j0) hj0E with ⟨r0, hr01, hr02, hr0rest⟩ have hlt : j0.val * k + r0.val < m * k := by have hj := j0.isLt; have hr := r0.isLt calc j0.val * k + r0.val < j0.val * k + k := Nat.add_lt_add_left hr _ _ = (j0.val + 1) * k := by ring _ ≤ m * k := Nat.mul_le_mul_right k hj refine ⟨⟨j0.val * k + r0.val, hlt⟩, ?_, ?_, ?_⟩ · rw [hp1, packBlocks_apply]; exact hr01 · rw [hp2, packBlocks_apply]; exact hr02 · intro idx hne have hkpos : 0 < k := Nat.lt_of_le_of_lt (Nat.zero_le _) r0.isLt have hlt_km : idx.val < k * m := by have hlt' := idx.isLt; have hcomm := mul_comm m k; omega let j : Fin m := ⟨idx.val / k, Nat.div_lt_of_lt_mul hlt_km⟩ let r : Fin k := ⟨idx.val % k, Nat.mod_lt idx.val hkpos⟩ have hdm : j.val * k + r.val = idx.val := by simp only [j, r]; rw [mul_comm]; exact Nat.div_add_mod idx.val k have hidx_lt : j.val * k + r.val < m * k := by rw [hdm]; exact idx.isLt have hidx : idx = ⟨j.val * k + r.val, hidx_lt⟩ := Fin.ext hdm.symm rw [hp1, hp2, hidx, packBlocks_apply, packBlocks_apply] by_cases hj : j = j0 · subst hj have hrne : r ≠ r0 := by intro hreq; subst hreq; apply hne; ext; exact congrArg Fin.val hidx exact hr0rest r hrne · exact congrFun (hrest j hj) r } refine ⟨Wfg, ?_⟩ change Efg.card ^ 2 * (Wf.A.card * Wf.B.card * Wg.A.card * Wg.B.card) = (Wf.E.card ^ 2 * Wg.E.card ^ 2) * (Afg.card * Bfg.card) rw [hEfg_card, hAfg_card, hBfg_card] have hkf_le : kf ≤ m := by rcases Wf.hAne with ⟨x, hx⟩ have := Finset.card_le_univ (boolSupp x) rw [Fintype.card_fin] at this rw [← hWfA x hx]; exact this have hpowA : Wg.A.card ^ kf = Wg.A.card * Wg.A.card ^ (kf - 1) := by conv_lhs => rw [← Nat.sub_add_cancel hkf, pow_succ, mul_comm] have hpowB : Wg.B.card ^ (m - (kf - 1)) = Wg.B.card * Wg.B.card ^ (m - kf) := by have hsub : m - (kf - 1) = (m - kf) + 1 := by omega rw [hsub, pow_succ, mul_comm] rw [hpowA, hpowB] ring /-- `t`-fold iterated 3-variable Majority `MAJ₃^{∘t}` on `3^t` Boolean variables. -/ def iterMaj3 : (t : ℕ) → (Fin (3 ^ t) → Bool) → Bool | 0, x => x ⟨0, by norm_num⟩ | t + 1, z => composeBoolFun (fun y : Fin 3 → Bool => decide (2 ≤ hammingWeight y)) (iterMaj3 t) (fun idx => z ⟨idx.val, by have hlt := idx.isLt; have hpow : 3 * 3 ^ t = 3 ^ (t + 1) := by ring omega⟩) /-- **Corollary 12A (Iterated Majority `MAJ₃^{∘t}` Exponential Size & Exact Depth Lower Bound):** For every `t : ℕ`, every monotone formula `F` computing `MAJ₃^{∘t}` on `3^t` variables satisfies: `4 ^ t ≤ F.leafSize` AND `2 * t ≤ F.depth`! -/ theorem iterMaj3_monotone_formula_lb (t : ℕ) (F : MonotoneFormula (3 ^ t)) (hF : ∀ x, F.eval x = iterMaj3 t x) : 4 ^ t ≤ F.leafSize ∧ 2 * t ≤ F.depth := by have hwit : ∀ t : ℕ, ∃ W : MonotoneDist1Witness (3 ^ t) (iterMaj3 t), W.E.card ^ 2 = 4 ^ t * W.A.card * W.B.card := by intro t induction t with | zero => let x1 : Fin 1 → Bool := fun _ => true let y0 : Fin 1 → Bool := fun _ => false refine ⟨{ A := {x1}, B := {y0} hA := fun x hx => by simp only [Finset.mem_singleton] at hx; subst hx; rfl hB := fun y hy => by simp only [Finset.mem_singleton] at hy; subst hy; rfl hAne := Finset.singleton_nonempty x1 hBne := Finset.singleton_nonempty y0 E := {(x1, y0)} hE_mem := fun p hp => by simp only [Finset.mem_singleton] at hp; subst hp; simp hE_dist1 := fun p hp => by simp only [Finset.mem_singleton] at hp; subst hp exact ⟨⟨0, by omega⟩, rfl, rfl, fun j hj => absurd (Fin.ext (by have := j.isLt; omega)) hj⟩ }, by simp⟩ | succ t ih => rcases ih with ⟨Wt, hWt⟩ let maj3 : (Fin 3 → Bool) → Bool := fun y => decide (2 ≤ hammingWeight y) let A3 := Finset.univ.filter (fun x : Fin 3 → Bool => hammingWeight x = 2) let B3 := Finset.univ.filter (fun y : Fin 3 → Bool => hammingWeight y = 1) let E3 := (A3 ×ˢ B3).filter (fun p => ∃ i : Fin 3, p.1 i = true ∧ p.2 i = false ∧ ∀ j ≠ i, p.1 j = p.2 j) have hA3 : A3.card = 3 := by decide have hB3 : B3.card = 3 := by decide have hE3 : E3.card = 6 := by decide let W3 : MonotoneDist1Witness 3 maj3 := { A := A3, B := B3 hA := fun x hx => by simp only [A3, Finset.mem_filter, Finset.mem_univ, true_and] at hx; simp [maj3, hx] hB := fun y hy => by simp only [B3, Finset.mem_filter, Finset.mem_univ, true_and] at hy; simp [maj3, hy] hAne := Finset.card_pos.mp (by omega) hBne := Finset.card_pos.mp (by omega) E := E3 hE_mem := fun p hp => Finset.mem_product.mp (Finset.mem_filter.mp hp).1 hE_dist1 := fun p hp => (Finset.mem_filter.mp hp).2 } rcases monotoneDist1Witness_compose_mult (kf := 2) W3 Wt (fun x hx => (Finset.mem_filter.mp hx).2) (fun y hy => (Finset.mem_filter.mp hy).2) (by omega) with ⟨Wcomp, hmult⟩ have heq_pow : 3 * 3 ^ t = 3 ^ (t + 1) := by ring let eFin : Fin (3 * 3 ^ t) ≃ Fin (3 ^ (t + 1)) := finCongr heq_pow let eVec : (Fin (3 * 3 ^ t) → Bool) ≃ (Fin (3 ^ (t + 1)) → Bool) := Equiv.arrowCongr eFin (Equiv.refl Bool) have heval_tr : ∀ z : Fin (3 * 3 ^ t) → Bool, iterMaj3 (t + 1) (eVec z) = composeBoolFun maj3 (iterMaj3 t) z := by intro z simp only [iterMaj3, composeBoolFun, maj3, eVec, eFin, Equiv.arrowCongr_apply, finCongr_symm] rfl let W' : MonotoneDist1Witness (3 ^ (t + 1)) (iterMaj3 (t + 1)) := { A := Wcomp.A.image eVec B := Wcomp.B.image eVec hA := fun x hx => by rcases Finset.mem_image.mp hx with ⟨z, hz, rfl⟩ rw [heval_tr]; exact Wcomp.hA z hz hB := fun y hy => by rcases Finset.mem_image.mp hy with ⟨z, hz, rfl⟩ rw [heval_tr]; exact Wcomp.hB z hz hAne := Wcomp.hAne.image eVec hBne := Wcomp.hBne.image eVec E := Wcomp.E.image (Prod.map eVec eVec) hE_mem := fun p hp => by rcases Finset.mem_image.mp hp with ⟨⟨a, b⟩, hab, rfl⟩ exact ⟨Finset.mem_image_of_mem eVec (Wcomp.hE_mem _ hab).1, Finset.mem_image_of_mem eVec (Wcomp.hE_mem _ hab).2⟩ hE_dist1 := fun p hp => by rcases Finset.mem_image.mp hp with ⟨⟨a, b⟩, hab, rfl⟩ rcases Wcomp.hE_dist1 (a, b) hab with ⟨i, hi1, hi2, hrest⟩ refine ⟨eFin i, ?_, ?_, fun j hj => ?_⟩ · simpa [eVec] using hi1 · simpa [eVec] using hi2 · have hne : eFin.symm j ≠ i := fun h => hj (by rw [← h, Equiv.apply_symm_apply]) simpa [eVec] using hrest (eFin.symm j) hne } refine ⟨W', ?_⟩ have hcA : W'.A.card = Wcomp.A.card := Finset.card_image_of_injective _ eVec.injective have hcB : W'.B.card = Wcomp.B.card := Finset.card_image_of_injective _ eVec.injective have hcE : W'.E.card = Wcomp.E.card := Finset.card_image_of_injective _ (Function.Injective.prodMap eVec.injective eVec.injective) rw [hcA, hcB, hcE] have hpos : 0 < W3.A.card * W3.B.card * Wt.A.card * Wt.B.card := by have h1 : 0 < W3.A.card := by change 0 < A3.card; omega have h2 : 0 < W3.B.card := by change 0 < B3.card; omega have h3 := Finset.card_pos.mpr Wt.hAne have h4 := Finset.card_pos.mpr Wt.hBne positivity have hmul_eq : Wcomp.E.card ^ 2 * (W3.A.card * W3.B.card * Wt.A.card * Wt.B.card) = (4 ^ (t + 1) * Wcomp.A.card * Wcomp.B.card) * (W3.A.card * W3.B.card * Wt.A.card * Wt.B.card) := by rw [hmult, hWt] change (E3.card ^ 2 * (4 ^ t * Wt.A.card * Wt.B.card)) * (Wcomp.A.card * Wcomp.B.card) = (4 ^ (t + 1) * Wcomp.A.card * Wcomp.B.card) * (A3.card * B3.card * Wt.A.card * Wt.B.card) rw [hA3, hB3, hE3, pow_succ] ring exact Nat.eq_of_mul_eq_mul_right hpos hmul_eq rcases hwit t with ⟨W, hW⟩ have hlb := monotoneDist1Witness_leafSize_lb W F hF rw [hW] at hlb have hpos : 0 < W.A.card * W.B.card := Nat.mul_pos (Finset.card_pos.mpr W.hAne) (Finset.card_pos.mpr W.hBne) have hsize : 4 ^ t ≤ F.leafSize := by have h1 : 4 ^ t * (W.A.card * W.B.card) ≤ F.leafSize * (W.A.card * W.B.card) := by linarith [hlb] exact Nat.le_of_mul_le_mul_right h1 hpos refine ⟨hsize, ?_⟩ have h2pow : 2 ^ (2 * t) ≤ 2 ^ F.depth := by calc 2 ^ (2 * t) = (2 ^ 2) ^ t := by rw [pow_mul] _ = 4 ^ t := by norm_num _ ≤ F.leafSize := hsize _ ≤ 2 ^ F.depth := F.leafSize_le_two_pow_depth exact (Nat.pow_le_pow_iff_right (by omega : 1 < 2)).mp h2pow /-! ### Exact Hansel–Kraft Monotone Formula Theorem for `THR_2^n` and General `THR_k^n` -/ /-- Singleton 1-support of a monotone formula: `i ∈ singletonSet F` iff `F(e_i) = true`. -/ def singletonSet {n : ℕ} (F : MonotoneFormula n) : Finset (Fin n) := Finset.univ.filter (fun i : Fin n => F.eval (fun j => decide (j = i)) = true) /-- Disjoint-side bipartite cover of a graph: list of pairs `(L, R)` of disjoint subsets of `Fin n`. -/ abbrev BipCover (n : ℕ) := List (Finset (Fin n) × Finset (Fin n)) def BipCover.deg {n : ℕ} (B : BipCover n) (i : Fin n) : ℕ := (B.map (fun p => if i ∈ p.1 ∨ i ∈ p.2 then 1 else 0)).sum def BipCover.CoversEdge {n : ℕ} (B : BipCover n) (i j : Fin n) : Prop := ∃ p ∈ B, (i ∈ p.1 ∧ j ∈ p.2) ∨ (i ∈ p.2 ∧ j ∈ p.1) def BipCover.IsDisjoint {n : ℕ} (B : BipCover n) : Prop := ∀ p ∈ B, Disjoint p.1 p.2 /-- **Structural Bipartite-Cover Extraction Lemma (Hansel 1964):** Every monotone formula `F : MonotoneFormula n` produces a disjoint-side bipartite cover `B` covering every pair `{i, j}` with `i ≠ j`, `i, j ∉ singletonSet F`, and `F(e_i ∨ e_j) = true`, such that `B.deg i + (if i ∈ singletonSet F then 1 else 0) ≤ F.varCount i` for every `i : Fin n`! -/ theorem monotone_bipartite_cover_extract {n : ℕ} (F : MonotoneFormula n) : ∃ B : BipCover n, B.IsDisjoint ∧ (∀ i j : Fin n, i ≠ j → i ∉ singletonSet F → j ∉ singletonSet F → F.eval (fun u => decide (u = i ∨ u = j)) = true → B.CoversEdge i j) ∧ (∀ i : Fin n, B.deg i + (if i ∈ singletonSet F then 1 else 0) ≤ F.varCount i) := by induction F with | var k => refine ⟨[], fun _ h => absurd h List.not_mem_nil, ?_, ?_⟩ · intro i j _ hi hj hev simp only [MonotoneFormula.eval, decide_eq_true_eq] at hev rcases hev with rfl | rfl · exfalso; apply hi; simp [singletonSet, MonotoneFormula.eval] · exfalso; apply hj; simp [singletonSet, MonotoneFormula.eval] · intro i simp only [BipCover.deg, List.map_nil, List.sum_nil, zero_add, singletonSet, MonotoneFormula.eval, MonotoneFormula.varCount] by_cases hki : k = i · subst hki; simp · simp [hki] | or l r ihl ihr => rcases ihl with ⟨Bl, hBl_disj, hBl_cov, hBl_deg⟩ rcases ihr with ⟨Br, hBr_disj, hBr_cov, hBr_deg⟩ refine ⟨Bl ++ Br, ?_, ?_, ?_⟩ · intro p hp rcases List.mem_append.mp hp with h | h · exact hBl_disj p h · exact hBr_disj p h · intro i j hij hi hj hev simp only [singletonSet, Finset.mem_filter, Finset.mem_univ, true_and, MonotoneFormula.eval, Bool.or_eq_true, not_or] at hi hj simp only [MonotoneFormula.eval, Bool.or_eq_true] at hev rcases hev with hl | hr · rcases hBl_cov i j hij (by simp [singletonSet, hi.1]) (by simp [singletonSet, hj.1]) hl with ⟨p, hp, hcov⟩ exact ⟨p, List.mem_append_left Br hp, hcov⟩ · rcases hBr_cov i j hij (by simp [singletonSet, hi.2]) (by simp [singletonSet, hj.2]) hr with ⟨p, hp, hcov⟩ exact ⟨p, List.mem_append_right Bl hp, hcov⟩ · intro i have hdeg_app : (Bl ++ Br).deg i = Bl.deg i + Br.deg i := by simp [BipCover.deg] rw [hdeg_app] have hdl := hBl_deg i have hdr := hBr_deg i have hsing : (if i ∈ singletonSet (.or l r) then 1 else 0) ≤ (if i ∈ singletonSet l then 1 else 0) + (if i ∈ singletonSet r then 1 else 0) := by simp only [singletonSet, Finset.mem_filter, Finset.mem_univ, true_and, MonotoneFormula.eval, Bool.or_eq_true] by_cases hl : l.eval (fun j => decide (j = i)) = true <;> by_cases hr : r.eval (fun j => decide (j = i)) = true <;> simp [hl, hr] simp only [MonotoneFormula.varCount] omega | and l r ihl ihr => rcases ihl with ⟨Bl, hBl_disj, hBl_cov, hBl_deg⟩ rcases ihr with ⟨Br, hBr_disj, hBr_cov, hBr_deg⟩ let L := singletonSet l \ singletonSet r let R := singletonSet r \ singletonSet l refine ⟨(L, R) :: (Bl ++ Br), ?_, ?_, ?_⟩ · intro p hp rcases List.mem_cons.mp hp with rfl | hmem · exact Finset.disjoint_left.mpr (fun x h1 h2 => (Finset.mem_sdiff.mp h1).2 (Finset.mem_sdiff.mp h2).1) · rcases List.mem_append.mp hmem with h | h · exact hBl_disj p h · exact hBr_disj p h · intro i j hij hi hj hev simp only [MonotoneFormula.eval, Bool.and_eq_true] at hev simp only [singletonSet, Finset.mem_filter, Finset.mem_univ, true_and, MonotoneFormula.eval, Bool.and_eq_true, not_and] at hi hj by_cases hil : i ∈ singletonSet l · have hir : i ∉ singletonSet r := by intro h; apply hi (by simp [singletonSet] at hil; exact hil) simp [singletonSet] at h; exact h by_cases hjr : j ∈ singletonSet r · have hjl : j ∉ singletonSet l := by intro h; apply hj (by simp [singletonSet] at h; exact h) simp [singletonSet] at hjr; exact hjr exact ⟨(L, R), List.mem_cons_self, Or.inl ⟨Finset.mem_sdiff.mpr ⟨hil, hir⟩, Finset.mem_sdiff.mpr ⟨hjr, hjl⟩⟩⟩ · rcases hBr_cov i j hij hir hjr hev.2 with ⟨p, hp, hcov⟩ exact ⟨p, List.mem_cons_of_mem _ (List.mem_append_right Bl hp), hcov⟩ · by_cases hjl : j ∈ singletonSet l · have hjr : j ∉ singletonSet r := by intro h; apply hj (by simp [singletonSet] at hjl; exact hjl) simp [singletonSet] at h; exact h by_cases hir : i ∈ singletonSet r · exact ⟨(L, R), List.mem_cons_self, Or.inr ⟨Finset.mem_sdiff.mpr ⟨hir, hil⟩, Finset.mem_sdiff.mpr ⟨hjl, hjr⟩⟩⟩ · rcases hBr_cov i j hij hir hjr hev.2 with ⟨p, hp, hcov⟩ exact ⟨p, List.mem_cons_of_mem _ (List.mem_append_right Bl hp), hcov⟩ · rcases hBl_cov i j hij hil hjl hev.1 with ⟨p, hp, hcov⟩ exact ⟨p, List.mem_cons_of_mem _ (List.mem_append_left Br hp), hcov⟩ · intro i have hdeg_cons : BipCover.deg ((L, R) :: (Bl ++ Br)) i = (if i ∈ L ∨ i ∈ R then 1 else 0) + Bl.deg i + Br.deg i := by simp [BipCover.deg, add_assoc] rw [hdeg_cons] have hdl := hBl_deg i have hdr := hBr_deg i have hsing_and : i ∈ singletonSet (.and l r) ↔ i ∈ singletonSet l ∧ i ∈ singletonSet r := by simp [singletonSet, MonotoneFormula.eval] have hbound : (if i ∈ L ∨ i ∈ R then 1 else 0) + (if i ∈ singletonSet (.and l r) then 1 else 0) ≤ (if i ∈ singletonSet l then 1 else 0) + (if i ∈ singletonSet r then 1 else 0) := by simp only [hsing_and] by_cases hl : i ∈ singletonSet l <;> by_cases hr : i ∈ singletonSet r <;> simp [L, R, hl, hr] simp only [MonotoneFormula.varCount] omega /-- **Katona–Szemerédi Coin-Flip Kraft Inequality (Pure Finite-Sum Proof):** If a disjoint-side bipartite cover `B` covers every pair of distinct vertices in `C ⊆ Fin n`, then `∑ i ∈ C, (2 : ℝ) ^ (-(B.deg i : ℤ)) ≤ 1`! -/ theorem bipartite_cover_kraft_ineq {n : ℕ} (B : BipCover n) (hdisj : B.IsDisjoint) (C : Finset (Fin n)) (hcov : ∀ i ∈ C, ∀ j ∈ C, i ≠ j → B.CoversEdge i j) : ∑ i ∈ C, (2 : ℝ) ^ (-(B.deg i : ℤ)) ≤ 1 := by let m := B.length let Good : Fin n → Finset (Fin m → Bool) := fun i => Finset.univ.filter (fun c : Fin m → Bool => ∀ r : Fin m, (i ∈ B[r.val].1 → c r = false) ∧ (i ∈ B[r.val].2 → c r = true)) have hGood_disj : Set.PairwiseDisjoint (C : Set (Fin n)) Good := by intro i hi j hj hij show Disjoint (Good i) (Good j) rw [Finset.disjoint_left] intro c hci hcj simp only [Good, Finset.mem_filter, Finset.mem_univ, true_and] at hci hcj rcases hcov i hi j hj hij with ⟨p, hpB, hpair⟩ rcases List.mem_iff_getElem.mp hpB with ⟨r, hrlt, hrp⟩ let rFin : Fin m := ⟨r, hrlt⟩ have hrp' : B[rFin.val] = p := hrp rw [← hrp'] at hpair rcases hpair with ⟨hi1, hj2⟩ | ⟨hi2, hj1⟩ · have h1 := (hci rFin).1 hi1 have h2 := (hcj rFin).2 hj2 rw [h1] at h2; exact Bool.noConfusion h2 · have h1 := (hci rFin).2 hi2 have h2 := (hcj rFin).1 hj1 rw [h1] at h2; exact Bool.noConfusion h2 have hGood_card : ∀ i : Fin n, (Good i).card * 2 ^ (B.deg i) = 2 ^ m := by intro i let free : Finset (Fin m) := Finset.univ.filter (fun r : Fin m => ¬(i ∈ B[r.val].1 ∨ i ∈ B[r.val].2)) let fixed : Finset (Fin m) := Finset.univ.filter (fun r : Fin m => i ∈ B[r.val].1 ∨ i ∈ B[r.val].2) have hfixed_card : fixed.card = B.deg i := by unfold BipCover.deg have hof : List.ofFn (fun r : Fin m => if i ∈ B[r.val].1 ∨ i ∈ B[r.val].2 then 1 else 0) = B.map (fun p => if i ∈ p.1 ∨ i ∈ p.2 then 1 else 0) := by apply List.ext_getElem · simp [m] · intro idx h1 h2; simp rw [← hof, List.sum_ofFn, Finset.card_filter] have hsum_card : free.card + fixed.card = m := by have hdisj_ff : Disjoint free fixed := Finset.disjoint_filter.mpr (fun _ _ h1 h2 => h1 h2) rw [← Finset.card_union_of_disjoint hdisj_ff] have hun : free ∪ fixed = Finset.univ := by ext r; simp only [free, fixed, Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, iff_true] exact (em _).symm rw [hun, Finset.card_univ, Fintype.card_fin] have hGood_eq : (Good i).card = 2 ^ free.card := by have hbij : (Good i).card = Fintype.card (free → Bool) := by rw [← Finset.card_univ] refine Finset.card_bij (fun c _ r => c r.1) ?_ ?_ ?_ · intro _ _; exact Finset.mem_univ _ · intro c1 h1 c2 h2 heq simp only [Good, Finset.mem_filter, Finset.mem_univ, true_and] at h1 h2 funext r by_cases h1r : i ∈ B[r.val].1 · exact ((h1 r).1 h1r).trans ((h2 r).1 h1r).symm · by_cases h2r : i ∈ B[r.val].2 · exact ((h1 r).2 h2r).trans ((h2 r).2 h2r).symm · have hrf : r ∈ free := by simp [free, h1r, h2r] exact congrFun heq ⟨r, hrf⟩ · intro f _ let c : Fin m → Bool := fun r => if h1 : i ∈ B[r.val].1 then false else if h2 : i ∈ B[r.val].2 then true else f ⟨r, by simp [free, h1, h2]⟩ refine ⟨c, ?_, ?_⟩ · simp only [Good, Finset.mem_filter, Finset.mem_univ, true_and] intro r constructor · intro h1; simp [c, h1] · intro h2 have h1 : i ∉ B[r.val].1 := fun h => Finset.disjoint_left.mp (hdisj B[r.val] (List.getElem_mem r.isLt)) h h2 simp [c, h1, h2] · funext ⟨r, hr⟩ simp only [free, Finset.mem_filter, Finset.mem_univ, true_and, not_or] at hr simp [c, hr.1, hr.2] rw [hbij, Fintype.card_fun, Fintype.card_bool, Fintype.card_coe] rw [hGood_eq, ← hfixed_card, ← pow_add, hsum_card] -- Step 3: Sum `(Good i).card ≤ 2^m` and divide by `2^m`! have hsum_nat : ∑ i ∈ C, (Good i).card ≤ 2 ^ m := by calc ∑ i ∈ C, (Good i).card = (C.biUnion Good).card := (Finset.card_biUnion hGood_disj).symm _ ≤ (Finset.univ : Finset (Fin m → Bool)).card := Finset.card_le_univ _ _ = 2 ^ m := by simp [Fintype.card_bool, Fintype.card_fin] have h2m_pos : (0 : ℝ) < (2 : ℝ) ^ m := by positivity have hterm : ∀ i : Fin n, (2 : ℝ) ^ (-(B.deg i : ℤ)) = ((Good i).card : ℝ) / (2 : ℝ) ^ m := by intro i have hR : ((Good i).card : ℝ) * (2 : ℝ) ^ (B.deg i) = (2 : ℝ) ^ m := by exact_mod_cast hGood_card i rw [zpow_neg, zpow_natCast, eq_div_iff (ne_of_gt h2m_pos)] have h2d_pos : (0 : ℝ) < (2 : ℝ) ^ (B.deg i) := by positivity rw [← hR] field_simp [ne_of_gt h2d_pos] simp_rw [hterm, ← Finset.sum_div] rw [div_le_one h2m_pos] exact_mod_cast hsum_nat /-- **HEADLINE THEOREM 13 (Exact Hansel–Kraft Per-Variable Inequality for Monotone Graph Functions):** For any monotone formula `F : MonotoneFormula n` and any clique `C ⊆ Fin n` of pairs covered by `F` (`i ∉ singletonSet F` for all `i ∈ C`, and `F(e_i ∨ e_j) = true` for all distinct `i, j ∈ C`): `∑ i ∈ C, (2 : ℝ) ^ (-(F.varCount i : ℤ)) ≤ 1`! -/ theorem monotone_graph_kraft_inequality {n : ℕ} (F : MonotoneFormula n) (C : Finset (Fin n)) (hsing : ∀ i ∈ C, i ∉ singletonSet F) (hpair : ∀ i ∈ C, ∀ j ∈ C, i ≠ j → F.eval (fun u => decide (u = i ∨ u = j)) = true) : ∑ i ∈ C, (2 : ℝ) ^ (-(F.varCount i : ℤ)) ≤ 1 := by rcases monotone_bipartite_cover_extract F with ⟨B, hdisj, hcov, hdeg⟩ have hkraft := bipartite_cover_kraft_ineq B hdisj C (fun i hi j hj hij => hcov i j hij (hsing i hi) (hsing j hj) (hpair i hi j hj hij)) calc ∑ i ∈ C, (2 : ℝ) ^ (-(F.varCount i : ℤ)) ≤ ∑ i ∈ C, (2 : ℝ) ^ (-(B.deg i : ℤ)) := by apply Finset.sum_le_sum; intro i _ have hle : B.deg i ≤ F.varCount i := by have := hdeg i; omega have hz : -(F.varCount i : ℤ) ≤ -(B.deg i : ℤ) := by omega exact zpow_le_zpow_right₀ (by norm_num : (1 : ℝ) ≤ 2) hz _ ≤ 1 := hkraft /-- **Tangent-Line Lemma for Exact Integer Kraft Minimization (Zero Calculus):** For every `k m : ℕ`, `(2 : ℝ) ^ (-(m : ℤ)) ≥ (2 : ℝ) ^ (-((k + 1 : ℕ) : ℤ)) * ((k + 2 : ℝ) - (m : ℝ))`! -/ lemma two_zpow_neg_ge_tangent (k m : ℕ) : (2 : ℝ) ^ (-((k + 1 : ℕ) : ℤ)) * ((k + 2 : ℝ) - (m : ℝ)) ≤ (2 : ℝ) ^ (-(m : ℤ)) := by have hpos : (0 : ℝ) < (2 : ℝ) ^ (k + 1) := by positivity rw [zpow_neg, zpow_natCast, inv_mul_eq_div, div_le_iff₀ hpos] by_cases hmk : m ≤ k + 1 · have hnat : ∃ t : ℕ, k + 1 = m + t := Nat.exists_eq_add_of_le hmk rcases hnat with ⟨t, ht⟩ have hlhs : (2 : ℝ) ^ (-(m : ℤ)) * (2 : ℝ) ^ (k + 1) = (2 : ℝ) ^ t := by rw [ht, pow_add, zpow_neg, zpow_natCast, ← mul_assoc, inv_mul_cancel₀ (by positivity), one_mul] rw [hlhs] have hlin : (k + 2 : ℝ) - (m : ℝ) = (t + 1 : ℕ) := by have h1 : k + 2 = m + (t + 1) := by omega have hR : (k + 2 : ℝ) = (m : ℝ) + ((t + 1 : ℕ) : ℝ) := by exact_mod_cast h1 linarith rw [hlin] have hpow_ge : ∀ s : ℕ, s + 1 ≤ 2 ^ s := by intro s induction s with | zero => norm_num | succ s ih => rw [pow_succ] have h1 : 1 ≤ 2 ^ s := Nat.one_le_pow s 2 (by omega) linarith exact_mod_cast hpow_ge t · have hle0 : (k + 2 : ℝ) - (m : ℝ) ≤ 0 := by have : k + 2 ≤ m := by omega have hR : (k + 2 : ℝ) ≤ (m : ℝ) := by exact_mod_cast this linarith have hrhs : (0 : ℝ) ≤ (2 : ℝ) ^ (-(m : ℤ)) * (2 : ℝ) ^ (k + 1) := by positivity linarith /-- **Closed-Form Exact Kraft Minimum Sum Lemma:** If `∑ i : Fin n, (2 : ℝ) ^ (-(ℓ i : ℤ)) ≤ R` (`n ≥ 1`), then for EVERY `k : ℕ`: `n * (k + 2) - ⌊R * 2^{k+1}⌋`, specifically in exact reals: `(n : ℝ) * (k + 2) - R * (2 : ℝ) ^ (k + 1) ≤ (∑ i : Fin n, ℓ i : ℝ)`! -/ lemma kraft_sum_tangent_lb {n : ℕ} (ℓ : Fin n → ℕ) (R : ℝ) (k : ℕ) (hkraft : ∑ i : Fin n, (2 : ℝ) ^ (-(ℓ i : ℤ)) ≤ R) : (n : ℝ) * (k + 2) - R * (2 : ℝ) ^ (k + 1) ≤ (∑ i : Fin n, ℓ i : ℝ) := by have h1 : ∑ i : Fin n, (2 : ℝ) ^ (-((k + 1 : ℕ) : ℤ)) * ((k + 2 : ℝ) - (ℓ i : ℝ)) ≤ R := (Finset.sum_le_sum (fun i _ => two_zpow_neg_ge_tangent k (ℓ i))).trans hkraft rw [← Finset.mul_sum, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at h1 have hpos : (0 : ℝ) < (2 : ℝ) ^ (k + 1) := by positivity rw [zpow_neg, zpow_natCast, inv_mul_eq_div, div_le_iff₀ hpos] at h1 have hsum_cast : (∑ i : Fin n, (ℓ i : ℝ)) = ((∑ i : Fin n, ℓ i : ℕ) : ℝ) := by rw [Nat.cast_sum] rw [hsum_cast] at h1 linarith /-- Disjunction of all `n` variables (`n ≥ 1`), with exact leaf-size `n`. -/ def orAll : (n : ℕ) → 1 ≤ n → MonotoneFormula n | 0, h => absurd h (by omega) | 1, _ => .var ⟨0, by omega⟩ | n + 2, _ => .or (.var ⟨0, by omega⟩) ((orAll (n + 1) (by omega)).mapVars (fun i => i.succ)) lemma eval_orAll (n : ℕ) (hn : 1 ≤ n) (x : Fin n → Bool) : (orAll n hn).eval x = decide (∃ i : Fin n, x i = true) := by induction n with | zero => omega | succ m ih => cases m with | zero => simp only [orAll, MonotoneFormula.eval] cases hx : x 0 <;> simp [Fin.exists_fin_one, hx] | succ m => simp only [orAll, MonotoneFormula.eval, MonotoneFormula.eval_mapVars, ih (by omega)] cases hx0 : x ⟨0, by omega⟩ · simp only [Bool.false_or] by_cases hex : ∃ i : Fin (m + 1), x i.succ = true · have hex' : ∃ i : Fin (m + 2), x i = true := by rcases hex with ⟨i, hi⟩; exact ⟨i.succ, hi⟩ simp [hex, hex'] · have hex' : ¬∃ i : Fin (m + 2), x i = true := by rintro ⟨i, hi⟩ refine Fin.cases ?_ (fun j hj => hex ⟨j, hj⟩) i hi change x ⟨0, by omega⟩ = true → False rw [hx0]; exact Bool.noConfusion simp [hex, hex'] · simp only [Bool.true_or] have hex' : ∃ i : Fin (m + 2), x i = true := ⟨⟨0, by omega⟩, hx0⟩ simp [hex'] lemma leafSize_orAll (n : ℕ) (hn : 1 ≤ n) : (orAll n hn).leafSize = n := by induction n with | zero => omega | succ m ih => cases m with | zero => rfl | succ m => simp [orAll, MonotoneFormula.leafSize, MonotoneFormula.leafSize_mapVars, ih (by omega)] omega /-- Exact optimal monotone formula for `THR_2^n` (`n ≥ 2`), constructed by balanced bisection, attaining the exact Hansel–Kraft minimum leaf-size `n * (Nat.log 2 n + 2) - 2 ^ (Nat.log 2 n + 1)`! -/ def thr2Formula : (n : ℕ) → 2 ≤ n → MonotoneFormula n | n, hn => if h2 : n = 2 then .and (.var ⟨0, by omega⟩) (.var ⟨1, by omega⟩) else if h3 : n = 3 then .or (.and (.var ⟨0, by omega⟩) (.or (.var ⟨1, by omega⟩) (.var ⟨2, by omega⟩))) (.and (.var ⟨1, by omega⟩) (.var ⟨2, by omega⟩)) else let a := n / 2 let b := n - a have ha2 : 2 ≤ a := by omega have hb2 : 2 ≤ b := by omega have ha_lt : a < n := by omega have hb_lt : b < n := by omega let leftMap : Fin a → Fin n := fun i => ⟨i.val, by omega⟩ let rightMap : Fin b → Fin n := fun j => ⟨a + j.val, by omega⟩ let cross := MonotoneFormula.and ((orAll a (by omega)).mapVars leftMap) ((orAll b (by omega)).mapVars rightMap) let leftF := (thr2Formula a ha2).mapVars leftMap let rightF := (thr2Formula b hb2).mapVars rightMap .or cross (.or leftF rightF) termination_by n => n /-- Helper arithmetic identity for balanced bisection of the Hansel–Kraft function `K(n) = n * (Nat.log 2 n + 2) - 2 ^ (Nat.log 2 n + 1)`. -/ lemma hansel_kraft_bisection_eq {n : ℕ} (hn : 4 ≤ n) : let a := n / 2 let b := n - a n + (a * (Nat.log 2 a + 2) - 2 ^ (Nat.log 2 a + 1)) + (b * (Nat.log 2 b + 2) - 2 ^ (Nat.log 2 b + 1)) = n * (Nat.log 2 n + 2) - 2 ^ (Nat.log 2 n + 1) := by intro a b set k := Nat.log 2 n have hk_ge2 : 2 ≤ k := by have := Nat.log_mono_right (b := 2) hn have hlog4 : Nat.log 2 4 = 2 := by decide omega have hpow_le : 2 ^ k ≤ n := Nat.pow_log_le_self 2 (by omega) have hlt_pow : n < 2 ^ (k + 1) := Nat.lt_pow_succ_log_self (by omega) n have hlog_a : Nat.log 2 a = k - 1 := by have h1 : 2 ^ (k - 1) ≤ a := by have : 2 * 2 ^ (k - 1) = 2 ^ k := by conv_rhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ k), pow_succ, mul_comm] omega have h2 : a < 2 ^ ((k - 1) + 1) := by rw [Nat.sub_add_cancel (by omega : 1 ≤ k)] have : 2 * 2 ^ k = 2 ^ (k + 1) := by rw [pow_succ, mul_comm] omega exact Nat.log_eq_iff (Or.inr ⟨by omega, by omega⟩) |>.mpr ⟨h1, h2⟩ have hterm_a : a * (Nat.log 2 a + 2) - 2 ^ (Nat.log 2 a + 1) = a * (k + 1) - 2 ^ k := by rw [hlog_a, Nat.sub_add_cancel (by omega : 1 ≤ k), show k - 1 + 2 = k + 1 by omega] have hterm_b : b * (Nat.log 2 b + 2) - 2 ^ (Nat.log 2 b + 1) = b * (k + 1) - 2 ^ k := by by_cases hbe : b < 2 ^ k · have hlog_b : Nat.log 2 b = k - 1 := by have h1 : 2 ^ (k - 1) ≤ b := by have : 2 * 2 ^ (k - 1) = 2 ^ k := by conv_rhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ k), pow_succ, mul_comm] omega exact (Nat.log_eq_iff (Or.inr ⟨by omega, by omega⟩)).mpr ⟨h1, by rwa [Nat.sub_add_cancel (by omega : 1 ≤ k)]⟩ rw [hlog_b, Nat.sub_add_cancel (by omega : 1 ≤ k), show k - 1 + 2 = k + 1 by omega] · have hb_eq : b = 2 ^ k := by have : 2 * 2 ^ k = 2 ^ (k + 1) := by rw [pow_succ, mul_comm] omega rw [hb_eq, Nat.log_pow (by omega : 1 < 2)] have h1 : 2 ^ k * (k + 2) - 2 ^ (k + 1) = 2 ^ k * k := by have : 2 ^ k * (k + 2) = 2 ^ k * k + 2 ^ (k + 1) := by rw [pow_succ]; ring omega have h2 : 2 ^ k * (k + 1) - 2 ^ k = 2 ^ k * k := by have : 2 ^ k * (k + 1) = 2 ^ k * k + 2 ^ k := by ring omega rw [h1, h2] rw [hterm_a, hterm_b] have ha_ge : 2 ^ k ≤ a * (k + 1) := by have h2a : 2 ^ k ≤ 2 * a := by have h1 : 2 ^ (k - 1) ≤ a := by have hp : 2 * 2 ^ (k - 1) = 2 ^ k := by conv_rhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ k), pow_succ, mul_comm] omega have hp : 2 ^ k = 2 * 2 ^ (k - 1) := by conv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ k), pow_succ, mul_comm] omega nlinarith have hab_le : a ≤ b := by omega have hb_ge : 2 ^ k ≤ b * (k + 1) := by nlinarith have hp2 : 2 ^ (k + 1) = 2 ^ k + 2 ^ k := by rw [pow_succ]; ring have hab : a + b = n := by omega zify [ha_ge, hb_ge, show 2 ^ (k + 1) ≤ n * (k + 2) by nlinarith] have hp2z : ((2 ^ (k + 1) : ℕ) : ℤ) = (2 ^ k : ℕ) + (2 ^ k : ℕ) := by exact_mod_cast hp2 have habz : (a : ℤ) + (b : ℤ) = (n : ℤ) := by exact_mod_cast hab nlinarith lemma leafSize_thr2Formula (n : ℕ) (hn : 2 ≤ n) : (thr2Formula n hn).leafSize = n * (Nat.log 2 n + 2) - 2 ^ (Nat.log 2 n + 1) := by induction n using Nat.strong_induction_on with | h n ih => rw [thr2Formula] split_ifs with h2 h3 · subst h2; decide · subst h3; decide · have hn4 : 4 ≤ n := by omega dsimp only simp only [MonotoneFormula.leafSize, MonotoneFormula.leafSize_mapVars, leafSize_orAll] rw [ih (n / 2) (by omega) (by omega), ih (n - n / 2) (by omega) (by omega)] have hadd : n / 2 + (n - n / 2) = n := by omega have hbis := hansel_kraft_bisection_eq hn4 dsimp only at hbis omega lemma eval_thr2Formula (n : ℕ) (hn : 2 ≤ n) (x : Fin n → Bool) : (thr2Formula n hn).eval x = decide (2 ≤ hammingWeight x) := by induction n using Nat.strong_induction_on with | h n ih => rw [thr2Formula] split_ifs with h2 h3 · subst h2 simp only [MonotoneFormula.eval] have hw : hammingWeight x = (if x 0 = true then 1 else 0) + (if x 1 = true then 1 else 0) := by rw [hammingWeight, boolSupp, Finset.card_filter, Fin.sum_univ_two] rw [hw] change (x 0 && x 1) = _ cases x 0 <;> cases x 1 <;> rfl · subst h3 simp only [MonotoneFormula.eval] have hw : hammingWeight x = (if x 0 = true then 1 else 0) + (if x 1 = true then 1 else 0) + (if x 2 = true then 1 else 0) := by rw [hammingWeight, boolSupp, Finset.card_filter, Fin.sum_univ_three] rw [hw] change (x 0 && (x 1 || x 2) || x 1 && x 2) = _ cases x 0 <;> cases x 1 <;> cases x 2 <;> rfl · have hn4 : 4 ≤ n := by omega dsimp only set a := n / 2 set b := n - a let xl : Fin a → Bool := fun i => x ⟨i.val, by omega⟩ let xr : Fin b → Bool := fun j => x ⟨a + j.val, by omega⟩ simp only [MonotoneFormula.eval, MonotoneFormula.eval_mapVars, eval_orAll] have ihl : (thr2Formula a (by omega)).eval xl = decide (2 ≤ hammingWeight xl) := ih a (by omega) (by omega) xl have ihr : (thr2Formula b (by omega)).eval xr = decide (2 ≤ hammingWeight xr) := ih b (by omega) (by omega) xr change (decide (∃ i : Fin a, xl i = true) && decide (∃ j : Fin b, xr j = true) || ((thr2Formula a (by omega)).eval xl || (thr2Formula b (by omega)).eval xr)) = _ rw [ihl, ihr] have hsplit : hammingWeight x = hammingWeight xl + hammingWeight xr := by simp only [hammingWeight, boolSupp, Finset.card_filter] have htot := Finset.sum_filter_add_sum_filter_not (Finset.univ : Finset (Fin n)) (fun i : Fin n => i.val < a) (fun i => if x i = true then 1 else 0) rw [← htot] congr 1 · refine (Finset.sum_bij (fun i _ => (⟨i.val, by omega⟩ : Fin n)) ?_ ?_ ?_ ?_).symm · intro i _; simp · intro i1 _ i2 _ heq; exact Fin.ext (by simpa using congrArg Fin.val heq) · intro i hi; simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi exact ⟨⟨i.val, hi⟩, Finset.mem_univ _, Fin.ext rfl⟩ · intro i _; rfl · refine (Finset.sum_bij (fun j _ => (⟨a + j.val, by omega⟩ : Fin n)) ?_ ?_ ?_ ?_).symm · intro j _; simp · intro j1 _ j2 _ heq; exact Fin.ext (by have h := congrArg Fin.val heq; dsimp at h; omega) · intro i hi; simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi exact ⟨⟨i.val - a, by omega⟩, Finset.mem_univ _, Fin.ext (by dsimp; omega)⟩ · intro j _; rfl have hxl_pos : (∃ i : Fin a, xl i = true) ↔ 1 ≤ hammingWeight xl := by simp only [hammingWeight, boolSupp, Finset.one_le_card, Finset.Nonempty, Finset.mem_filter, Finset.mem_univ, true_and] have hxr_pos : (∃ j : Fin b, xr j = true) ↔ 1 ≤ hammingWeight xr := by simp only [hammingWeight, boolSupp, Finset.one_le_card, Finset.Nonempty, Finset.mem_filter, Finset.mem_univ, true_and] rw [hsplit] by_cases hl1 : 1 ≤ hammingWeight xl <;> by_cases hr1 : 1 ≤ hammingWeight xr <;> by_cases hl2 : 2 ≤ hammingWeight xl <;> by_cases hr2 : 2 ≤ hammingWeight xr all_goals simp only [hxl_pos, hxr_pos, hl1, hr1, hl2, hr2, decide_true, decide_false, Bool.true_and, Bool.false_and, Bool.and_false, Bool.true_or, Bool.false_or, Bool.or_false] try rfl try (rw [decide_eq_true (by omega)]) try (rw [decide_eq_false (by omega)]) /-- **HEADLINE THEOREM 14 (Exact Monotone Formula Size of `THR_2^n` for ALL `n ≥ 2`):** For every `n ≥ 2`, the *exact* minimum monotone formula leaf-size of `THR_2^n` is `n * (Nat.log 2 n + 2) - 2 ^ (Nat.log 2 n + 1)`! -/ theorem thr2_exact_monotone_formula_size {n : ℕ} (hn : 2 ≤ n) : (∀ F : MonotoneFormula n, (∀ x : Fin n → Bool, F.eval x = decide (2 ≤ hammingWeight x)) → n * (Nat.log 2 n + 2) - 2 ^ (Nat.log 2 n + 1) ≤ F.leafSize) ∧ (∃ F : MonotoneFormula n, (∀ x : Fin n → Bool, F.eval x = decide (2 ≤ hammingWeight x)) ∧ F.leafSize = n * (Nat.log 2 n + 2) - 2 ^ (Nat.log 2 n + 1)) := by constructor · intro F hF have hkraft := monotone_graph_kraft_inequality F Finset.univ (fun i _ => by simp only [singletonSet, Finset.mem_filter, Finset.mem_univ, true_and, hF] have hs : boolSupp (fun j : Fin n => decide (j = i)) = {i} := by ext j; simp [boolSupp] simp [hammingWeight, hs]) (fun i _ j _ hij => by rw [hF] have hs : boolSupp (fun u : Fin n => decide (u = i ∨ u = j)) = {i, j} := by ext u; simp [boolSupp] rw [hammingWeight, hs, Finset.card_pair hij]; rfl) have htan := kraft_sum_tangent_lb F.varCount 1 (Nat.log 2 n) hkraft rw [one_mul, ← Nat.cast_sum, MonotoneFormula.sum_varCount] at htan have hpow_le : 2 ^ (Nat.log 2 n + 1) ≤ n * (Nat.log 2 n + 2) := by have hlt : n < 2 ^ (Nat.log 2 n + 1) := Nat.lt_pow_succ_log_self (by omega) n have hge : 2 ^ Nat.log 2 n ≤ n := Nat.pow_log_le_self 2 (by omega) have h2 : 2 ^ (Nat.log 2 n + 1) = 2 * 2 ^ Nat.log 2 n := by rw [pow_succ, mul_comm] nlinarith have hnatR : ((n * (Nat.log 2 n + 2) - 2 ^ (Nat.log 2 n + 1) : ℕ) : ℝ) ≤ (F.leafSize : ℝ) := by rw [Nat.cast_sub hpow_le] push_cast linarith exact_mod_cast hnatR · exact ⟨thr2Formula n hn, eval_thr2Formula n hn, leafSize_thr2Formula n hn⟩ /-- Fix a subset of variables `T` to `true` in a monotone formula (simplifying `true ∧ G = G`, `true ∨ G = true`). Actually, even cleaner: for `T = Sᶜ` (fixing all variables outside `S` to `true`), any monotone formula `F` computing `THR_k^n` restricts to a monotone formula on `S` computing `THR_2^{|S|}` with `varCount i ≤ F.varCount i` for every `i ∈ S`! We express this cleanly via `Option (MonotoneFormula n)` (`none` = constant `true`, `some G` = subformula). -/ def restrictTrue {n : ℕ} (T : Finset (Fin n)) : MonotoneFormula n → Option (MonotoneFormula n) | .var i => if i ∈ T then none else some (.var i) | .or l r => match restrictTrue T l, restrictTrue T r with | none, _ => none | _, none => none | some l', some r' => some (.or l' r') | .and l r => match restrictTrue T l, restrictTrue T r with | none, r' => r' | l', none => l' | some l', some r' => some (.and l' r') lemma eval_restrictTrue {n : ℕ} (T : Finset (Fin n)) (F : MonotoneFormula n) (x : Fin n → Bool) : (match restrictTrue T F with | none => true | some G => G.eval x) = F.eval (fun i => if i ∈ T then true else x i) := by induction F with | var i => unfold restrictTrue MonotoneFormula.eval by_cases hi : i ∈ T <;> simp [hi] | or l r ihl ihr => simp only [restrictTrue, MonotoneFormula.eval, ← ihl, ← ihr] cases restrictTrue T l <;> cases restrictTrue T r <;> simp [MonotoneFormula.eval] | and l r ihl ihr => simp only [restrictTrue, MonotoneFormula.eval, ← ihl, ← ihr] cases restrictTrue T l <;> cases restrictTrue T r <;> simp [MonotoneFormula.eval] lemma varCount_restrictTrue_le {n : ℕ} (T : Finset (Fin n)) (F : MonotoneFormula n) (G : MonotoneFormula n) (hG : restrictTrue T F = some G) (i : Fin n) : G.varCount i ≤ F.varCount i := by induction F generalizing G with | var j => unfold restrictTrue at hG split_ifs at hG cases hG exact le_rfl | or l r ihl ihr => unfold restrictTrue at hG cases hl : restrictTrue T l <;> cases hr : restrictTrue T r <;> simp [hl, hr] at hG subst hG simp only [MonotoneFormula.varCount] exact Nat.add_le_add (ihl _ hl) (ihr _ hr) | and l r ihl ihr => unfold restrictTrue at hG cases hl : restrictTrue T l <;> cases hr : restrictTrue T r <;> simp [hl, hr] at hG · subst hG; simp only [MonotoneFormula.varCount]; have := ihr _ hr; omega · subst hG; simp only [MonotoneFormula.varCount]; have := ihl _ hl; omega · subst hG; simp only [MonotoneFormula.varCount]; exact Nat.add_le_add (ihl _ hl) (ihr _ hr) /-- **HEADLINE THEOREM 15 (Restriction–Duality–Kraft Bound for General Threshold Functions `THR_k^n`):** For every `2 ≤ k ≤ n - 1` and every monotone formula `F : MonotoneFormula n` computing `THR_k^n`: 1. `(max (n - k + 2) (k + 1) : ℝ) * ∑ i : Fin n, (2 : ℝ) ^ (-(F.varCount i : ℤ)) ≤ (n : ℝ)`, and 2. Setting `M := max (n - k + 2) (k + 1)` and `k₀ := Nat.log 2 M`: `n * (M * (k₀ + 2) - 2 ^ (k₀ + 1)) ≤ M * F.leafSize`! This recovers the exact `THR_2^n` size at `k = 2` (`M = n`) and strictly beats Khrapchenko's linear `k * (n - k + 1)` bound (`Ω(n log n)` vs `O(n)`) for every fixed `k ≥ 3`! -/ theorem thr_k_restriction_duality_kraft_bound {n k : ℕ} (hk2 : 2 ≤ k) (hkn : k + 1 ≤ n) (F : MonotoneFormula n) (hF : ∀ x : Fin n → Bool, F.eval x = decide (k ≤ hammingWeight x)) : let M := max (n - k + 2) (k + 1) let k0 := Nat.log 2 M ((M : ℝ) * ∑ i : Fin n, (2 : ℝ) ^ (-(F.varCount i : ℤ)) ≤ (n : ℝ)) ∧ (n * (M * (k0 + 2) - 2 ^ (k0 + 1)) ≤ M * F.leafSize) := by -- Step 1: Prove the restriction Kraft bound `(n - k + 2) * ∑ 2^(-varCount i) ≤ n` for ANY `2 ≤ k ≤ n`! have hrest_gen : ∀ (k' : ℕ), 2 ≤ k' → k' ≤ n → ∀ (G : MonotoneFormula n), (∀ x : Fin n → Bool, G.eval x = decide (k' ≤ hammingWeight x)) → ((n - k' + 2 : ℕ) : ℝ) * ∑ i : Fin n, (2 : ℝ) ^ (-(G.varCount i : ℤ)) ≤ (n : ℝ) := by intro k' hk'2 hk'n G hG set m := n - k' + 2 have hm_le : m ≤ n := by omega have hm_pos : 1 ≤ m := by omega -- For EVERY `m`-subset `S ⊆ univ`, fix `T = Sᶜ` (size `k' - 2`) to `true`! have hsub_kraft : ∀ S ∈ Finset.powersetCard m (Finset.univ : Finset (Fin n)), ∑ i ∈ S, (2 : ℝ) ^ (-(G.varCount i : ℤ)) ≤ 1 := by intro S hS rw [Finset.mem_powersetCard] at hS let T := Sᶜ have hTcard : T.card = k' - 2 := by simp only [T, Finset.card_compl, Fintype.card_fin, hS.2]; omega -- `restrictTrue T G` cannot be `none` (since on `x = all false`, `|T| = k' - 2 < k'`)! cases hres : restrictTrue T G with | none => exfalso have hev := eval_restrictTrue T G (fun _ => false) rw [hres, hG] at hev have hsupp : boolSupp (fun i : Fin n => if i ∈ T then true else false) = T := by ext i; simp [boolSupp] have hw : hammingWeight (fun i : Fin n => if i ∈ T then true else false) = k' - 2 := by rw [hammingWeight, hsupp, hTcard] rw [hw] at hev have : decide (k' ≤ k' - 2) = false := decide_eq_false (by omega) rw [this] at hev; exact Bool.noConfusion hev | some H => have hH_kraft := monotone_graph_kraft_inequality H S (fun i hiS => by simp only [singletonSet, Finset.mem_filter, Finset.mem_univ, true_and] have hev := eval_restrictTrue T G (fun u => decide (u = i)) rw [hres, hG] at hev; dsimp only at hev rw [hev] have hiT : i ∉ T := by simp [T, hiS] have hsupp : boolSupp (fun u : Fin n => if u ∈ T then true else decide (u = i)) = insert i T := by ext u; by_cases hu : u ∈ T <;> simp [boolSupp, hu] have hw : hammingWeight (fun u : Fin n => if u ∈ T then true else decide (u = i)) = k' - 1 := by rw [hammingWeight, hsupp, Finset.card_insert_of_notMem hiT, hTcard]; omega rw [hw]; simp [decide_eq_false (by omega : ¬k' ≤ k' - 1)]) (fun i hiS j hjS hij => by have hev := eval_restrictTrue T G (fun u => decide (u = i ∨ u = j)) rw [hres, hG] at hev; dsimp only at hev rw [hev] have hiT : i ∉ T := by simp [T, hiS] have hjT : j ∉ T := by simp [T, hjS] have hsupp : boolSupp (fun u : Fin n => if u ∈ T then true else decide (u = i ∨ u = j)) = insert i (insert j T) := by ext u; by_cases hu : u ∈ T <;> simp [boolSupp, hu] have hnot_ij : i ∉ insert j T := by simp [hij, hiT] have hw : hammingWeight (fun u : Fin n => if u ∈ T then true else decide (u = i ∨ u = j)) = k' := by rw [hammingWeight, hsupp, Finset.card_insert_of_notMem hnot_ij, Finset.card_insert_of_notMem hjT, hTcard]; omega rw [hw]; simp) calc ∑ i ∈ S, (2 : ℝ) ^ (-(G.varCount i : ℤ)) ≤ ∑ i ∈ S, (2 : ℝ) ^ (-(H.varCount i : ℤ)) := by apply Finset.sum_le_sum; intro i _ have hle := varCount_restrictTrue_le T G H hres i exact zpow_le_zpow_right₀ (by norm_num : (1 : ℝ) ≤ 2) (by omega) _ ≤ 1 := hH_kraft -- Average `hsub_kraft` over all `S ∈ powersetCard m univ`! have havg : ∑ S ∈ Finset.powersetCard m (Finset.univ : Finset (Fin n)), ∑ i ∈ S, (2 : ℝ) ^ (-(G.varCount i : ℤ)) ≤ ((n.choose m : ℕ) : ℝ) := by calc ∑ S ∈ Finset.powersetCard m (Finset.univ : Finset (Fin n)), ∑ i ∈ S, (2 : ℝ) ^ (-(G.varCount i : ℤ)) ≤ ∑ _S ∈ Finset.powersetCard m (Finset.univ : Finset (Fin n)), (1 : ℝ) := Finset.sum_le_sum hsub_kraft _ = ((n.choose m : ℕ) : ℝ) := by simp [Finset.card_powersetCard] -- Double-counting: each `i : Fin n` lies in `(n - 1).choose (m - 1)` subsets of size `m`! have hdouble : ∑ S ∈ Finset.powersetCard m (Finset.univ : Finset (Fin n)), ∑ i ∈ S, (2 : ℝ) ^ (-(G.varCount i : ℤ)) = (((n - 1).choose (m - 1) : ℕ) : ℝ) * ∑ i : Fin n, (2 : ℝ) ^ (-(G.varCount i : ℤ)) := by trans ∑ S ∈ Finset.powersetCard m (Finset.univ : Finset (Fin n)), ∑ i : Fin n, if i ∈ S then (2 : ℝ) ^ (-(G.varCount i : ℤ)) else 0 · apply Finset.sum_congr rfl; intro S _ rw [← Finset.sum_filter] congr 1; ext i; simp · rw [Finset.sum_comm, Finset.mul_sum] apply Finset.sum_congr rfl; intro i _ rw [← Finset.sum_filter, Finset.sum_const, nsmul_eq_mul] congr 1 have hcnt : ((Finset.powersetCard m (Finset.univ : Finset (Fin n))).filter (fun S => i ∈ S)).card = (n - 1).choose (m - 1) := by have hcp : (Finset.powersetCard (m - 1) ({i}ᶜ : Finset (Fin n))).card = (n - 1).choose (m - 1) := by simp [Finset.card_powersetCard, Finset.card_compl, Fintype.card_fin] rw [← hcp] refine Finset.card_bij (fun S _ => S.erase i) ?_ ?_ ?_ · intro S hS simp only [Finset.mem_filter, Finset.mem_powersetCard, Finset.subset_univ, true_and] at hS rw [Finset.mem_powersetCard] exact ⟨fun x hx => by simp [(Finset.mem_erase.mp hx).1], by rw [Finset.card_erase_of_mem hS.2, hS.1]⟩ · intro S1 h1 S2 h2 heq have h1m := (Finset.mem_filter.mp h1).2 have h2m := (Finset.mem_filter.mp h2).2 rw [← Finset.insert_erase h1m, ← Finset.insert_erase h2m, heq] · intro U hU rw [Finset.mem_powersetCard] at hU have hnot : i ∉ U := fun hi => by have := hU.1 hi; simp at this refine ⟨insert i U, ?_, Finset.erase_insert hnot⟩ simp only [Finset.mem_filter, Finset.mem_powersetCard, Finset.subset_univ, true_and] exact ⟨by rw [Finset.card_insert_of_notMem hnot, hU.2]; omega, Finset.mem_insert_self i U⟩ exact_mod_cast hcnt rw [hdouble] at havg have hcomb : n * (n - 1).choose (m - 1) = m * n.choose m := by have hcomb_aux : ∀ a b : ℕ, (a + 1) * a.choose b = (b + 1) * (a + 1).choose (b + 1) := by intro a induction a with | zero => intro b cases b with | zero => simp | succ b => simp [Nat.choose_eq_zero_of_lt (by omega : 1 < b + 2)] | succ a ih => intro b cases b with | zero => simp | succ b => have hpasc : (a + 1).choose (b + 1) = a.choose b + a.choose (b + 1) := Nat.choose_succ_succ a b have hpasc2 : (a + 2).choose (b + 2) = (a + 1).choose (b + 1) + (a + 1).choose (b + 2) := Nat.choose_succ_succ (a + 1) (b + 1) have h1 := ih b have h2 := ih (b + 1) calc (a + 1 + 1) * (a + 1).choose (b + 1) = (a + 1) * (a + 1).choose (b + 1) + (a + 1).choose (b + 1) := by ring _ = (a + 1) * (a.choose b + a.choose (b + 1)) + (a + 1).choose (b + 1) := by rw [hpasc] _ = (a + 1) * a.choose b + (a + 1) * a.choose (b + 1) + (a + 1).choose (b + 1) := by ring _ = (b + 1) * (a + 1).choose (b + 1) + (b + 1 + 1) * (a + 1).choose (b + 1 + 1) + (a + 1).choose (b + 1) := by rw [h1, h2] _ = (b + 1 + 1) * ((a + 1).choose (b + 1) + (a + 1).choose (b + 2)) := by ring _ = (b + 1 + 1) * (a + 1 + 1).choose (b + 1 + 1) := by rw [← hpasc2] have h2 := hcomb_aux (n - 1) (m - 1) have hn1 : n - 1 + 1 = n := by omega have hm1 : m - 1 + 1 = m := by omega rwa [hn1, hm1] at h2 have hch_pos : (0 : ℝ) < (n.choose m : ℝ) := by exact_mod_cast Nat.choose_pos hm_le have hcombR : (n : ℝ) * ((n - 1).choose (m - 1) : ℝ) = (m : ℝ) * (n.choose m : ℝ) := by exact_mod_cast hcomb have hmul : (m : ℝ) * (∑ i : Fin n, (2 : ℝ) ^ (-(G.varCount i : ℤ))) * (n.choose m : ℝ) ≤ (n : ℝ) * (n.choose m : ℝ) := by have h1 := mul_le_mul_of_nonneg_left havg (Nat.cast_nonneg n) calc (m : ℝ) * (∑ i : Fin n, (2 : ℝ) ^ (-(G.varCount i : ℤ))) * (n.choose m : ℝ) = ((m : ℝ) * (n.choose m : ℝ)) * (∑ i : Fin n, (2 : ℝ) ^ (-(G.varCount i : ℤ))) := by ring _ = (n : ℝ) * (((n - 1).choose (m - 1) : ℝ) * (∑ i : Fin n, (2 : ℝ) ^ (-(G.varCount i : ℤ)))) := by rw [← hcombR]; ring _ ≤ (n : ℝ) * (n.choose m : ℝ) := h1 exact le_of_mul_le_mul_right hmul hch_pos -- Step 2: Apply `hrest_gen` to BOTH `F` (giving `n - k + 2`) AND `F.dual` (giving `k + 1`)! have h1 := hrest_gen k hk2 (by omega) F hF have hdual_eval : ∀ x : Fin n → Bool, F.dual.eval x = decide (n - k + 1 ≤ hammingWeight x) := by intro x rw [MonotoneFormula.eval_dual, hF] have hcomp : hammingWeight (fun i => !x i) = n - hammingWeight x := by have hs : boolSupp (fun i => !x i) = (boolSupp x)ᶜ := by ext i; simp [boolSupp] simp [hammingWeight, hs, Finset.card_compl, Fintype.card_fin] rw [hcomp] have hw_le : hammingWeight x ≤ n := by have := Finset.card_le_univ (boolSupp x); simpa [hammingWeight] using this by_cases h : n - k + 1 ≤ hammingWeight x · rw [decide_eq_true h, decide_eq_false (by omega)]; rfl · rw [decide_eq_false h, decide_eq_true (by omega)]; rfl have h2 := hrest_gen (n - k + 1) (by omega) (by omega) F.dual hdual_eval simp_rw [MonotoneFormula.varCount_dual] at h2 have h2' : ((k + 1 : ℕ) : ℝ) * ∑ i : Fin n, (2 : ℝ) ^ (-(F.varCount i : ℤ)) ≤ (n : ℝ) := by have : n - (n - k + 1) + 2 = k + 1 := by omega rwa [this] at h2 -- Combine `h1` and `h2'` into `M = max (n - k + 2) (k + 1)`! dsimp only set M := max (n - k + 2) (k + 1) set k0 := Nat.log 2 M have hM_kraft : (M : ℝ) * ∑ i : Fin n, (2 : ℝ) ^ (-(F.varCount i : ℤ)) ≤ (n : ℝ) := by by_cases hcmp : n - k + 2 ≤ k + 1 · have hMeq : M = k + 1 := max_eq_right hcmp rw [hMeq]; exact h2' · have hMeq : M = n - k + 2 := max_eq_left (by omega) rw [hMeq]; exact h1 refine ⟨hM_kraft, ?_⟩ -- Deduce the explicit integer lower bound via `kraft_sum_tangent_lb`! have hM_pos : (0 : ℝ) < (M : ℝ) := by have : 1 ≤ M := by omega exact_mod_cast this have hR : ∑ i : Fin n, (2 : ℝ) ^ (-(F.varCount i : ℤ)) ≤ (n : ℝ) / (M : ℝ) := (le_div_iff₀' hM_pos).mpr hM_kraft have htan := kraft_sum_tangent_lb F.varCount ((n : ℝ) / (M : ℝ)) k0 hR rw [← Nat.cast_sum, MonotoneFormula.sum_varCount] at htan have hmulM := mul_le_mul_of_nonneg_left htan (le_of_lt hM_pos) have hcancel : (M : ℝ) * ((n : ℝ) * (k0 + 2) - (n : ℝ) / (M : ℝ) * (2 : ℝ) ^ (k0 + 1)) = (n : ℝ) * ((M : ℝ) * (k0 + 2) - (2 : ℝ) ^ (k0 + 1)) := by field_simp [ne_of_gt hM_pos] rw [hcancel] at hmulM have hpow_le : 2 ^ (k0 + 1) ≤ M * (k0 + 2) := by have hge : 2 ^ k0 ≤ M := Nat.pow_log_le_self 2 (by omega) have h2p : 2 ^ (k0 + 1) = 2 * 2 ^ k0 := by rw [pow_succ, mul_comm] nlinarith have hcast : ((n * (M * (k0 + 2) - 2 ^ (k0 + 1)) : ℕ) : ℝ) ≤ ((M * F.leafSize : ℕ) : ℝ) := by rw [Nat.cast_mul, Nat.cast_sub hpow_le] push_cast linarith exact_mod_cast hcast end MonotoneKWSmolensky /-! ## Axiom Verification for All Headline Theorems -/ #print axioms MonotoneKWSmolensky.universal_gram_smolensky_bound #print axioms MonotoneKWSmolensky.gram_smolensky_deg0_exact #print axioms MonotoneKWSmolensky.gram_smolensky_deg_n_sub_2_sharp #print axioms MonotoneKWSmolensky.parity_approx_iff_signed_design #print axioms MonotoneKWSmolensky.parity_deg_n_sub_3_hadamard_obstruction #print axioms MonotoneKWSmolensky.mod3_over_F2_sharp_error_bound #print axioms MonotoneKWSmolensky.sharp_threshold_polynomial_error_bound #print axioms MonotoneKWSmolensky.majority_deg1_exact #print axioms MonotoneKWSmolensky.majority_deg_half_sharp #print axioms MonotoneKWSmolensky.majority5_deg2_F2_attains_two #print axioms MonotoneKWSmolensky.ac0p_probabilistic_polynomial_approx #print axioms MonotoneKWSmolensky.ac0p_parity_lower_bound #print axioms MonotoneKWSmolensky.ac02_mod3_lower_bound #print axioms MonotoneKWSmolensky.ac0p_threshold_lower_bound #print axioms MonotoneKWSmolensky.monotone_kw_exact_equivalence #print axioms MonotoneKWSmolensky.monotone_duality_exact #print axioms MonotoneKWSmolensky.general_kw_exact_equivalence #print axioms MonotoneKWSmolensky.mkw_bilinear_adversary_bound #print axioms MonotoneKWSmolensky.kw_bilinear_adversary_bound #print axioms MonotoneKWSmolensky.monotone_formula_khrapchenko_thr #print axioms MonotoneKWSmolensky.demorgan_formula_khrapchenko_parity #print axioms MonotoneKWSmolensky.monotoneDist1Witness_compose_mult #print axioms MonotoneKWSmolensky.iterMaj3_monotone_formula_lb #print axioms MonotoneKWSmolensky.monotone_graph_kraft_inequality #print axioms MonotoneKWSmolensky.thr2_exact_monotone_formula_size #print axioms MonotoneKWSmolensky.thr_k_restriction_duality_kraft_bound