import Mathlib.Algebra.Polynomial.Roots import Mathlib.Algebra.MvPolynomial.Degrees import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Data.ZMod.Basic import Mathlib.Data.Fintype.BigOperators import Mathlib.Analysis.Real.Sqrt import Mathlib.Tactic /-! # Exact Non-Asymptotic Foundations of Interactive Proofs, Sum-Check, BLR / Low-Degree Testing & Algebraic Zero-Knowledge This file formalizes three sharp, non-asymptotic pillars of interactive proofs, probabilistically checkable proofs (PCPs), property testing, and algebraic zero-knowledge. -/ open scoped BigOperators open Finset namespace ZkPcpSumcheck /-! ============================================================================ PILLAR 1: EXACT SUM-CHECK, OPTIMAL CHEATING PROVERS & SCHWARTZ–ZIPPEL ============================================================================ -/ section Pillar1Helpers /-- Product-complement composition bound `1 - ∏ i, (1 - p i)` for `p : Fin v → ℝ`. -/ noncomputable def prodComplement {v : ℕ} (p : Fin v → ℝ) : ℝ := 1 - ∏ i : Fin v, (1 - p i) lemma prodComplement_zero (p : Fin 0 → ℝ) : prodComplement p = 0 := by simp [prodComplement] lemma prodComplement_succ {v : ℕ} (p : Fin (v + 1) → ℝ) : prodComplement p = p 0 + (1 - p 0) * prodComplement (fun i : Fin v => p i.succ) := by unfold prodComplement rw [Fin.prod_univ_succ] ring lemma prodComplement_nonneg {v : ℕ} (p : Fin v → ℝ) (hp0 : ∀ i, 0 ≤ p i) (hp1 : ∀ i, p i ≤ 1) : 0 ≤ prodComplement p := by unfold prodComplement have hle : ∏ i : Fin v, (1 - p i) ≤ 1 := Finset.prod_le_one (fun i _ => by linarith [hp1 i]) (fun i _ => by linarith [hp0 i]) linarith lemma prodComplement_le_one {v : ℕ} (p : Fin v → ℝ) (hp1 : ∀ i, p i ≤ 1) : prodComplement p ≤ 1 := by unfold prodComplement have hge : 0 ≤ ∏ i : Fin v, (1 - p i) := Finset.prod_nonneg (fun i _ => by linarith [hp1 i]) linarith /-- Exact comparison: `1 - ∏ (1 - p_i) ≤ ∑ p_i` for `p_i ∈ [0, 1]`. -/ theorem prodComplement_le_sum {v : ℕ} (p : Fin v → ℝ) (hp0 : ∀ i, 0 ≤ p i) (hp1 : ∀ i, p i ≤ 1) : prodComplement p ≤ ∑ i : Fin v, p i := by induction v with | zero => simp [prodComplement] | succ v ih => rw [prodComplement_succ, Fin.sum_univ_succ] have htail_le : prodComplement (fun i : Fin v => p i.succ) ≤ ∑ i : Fin v, p i.succ := ih (fun i => p i.succ) (fun i => hp0 i.succ) (fun i => hp1 i.succ) have htail_nn : 0 ≤ prodComplement (fun i : Fin v => p i.succ) := prodComplement_nonneg (fun i => p i.succ) (fun i => hp0 i.succ) (fun i => hp1 i.succ) have h1 : (1 - p 0) * prodComplement (fun i : Fin v => p i.succ) ≤ prodComplement (fun i : Fin v => p i.succ) := by nlinarith [hp0 0] linarith /-- Strict sharpening over the classical LFKN union bound: whenever `v ≥ 2` and every `p_i ∈ (0, 1]`, `1 - ∏ (1 - p_i) < ∑ p_i`. -/ theorem prodComplement_lt_sum {v : ℕ} (hv : 2 ≤ v) (p : Fin v → ℝ) (hp0 : ∀ i, 0 < p i) (hp1 : ∀ i, p i ≤ 1) : prodComplement p < ∑ i : Fin v, p i := by cases v with | zero => omega | succ v => cases v with | zero => omega | succ v => rw [prodComplement_succ, Fin.sum_univ_succ] have htail_pos : 0 < prodComplement (fun i : Fin (v + 1) => p i.succ) := by unfold prodComplement have hlt : ∏ i : Fin (v + 1), (1 - p i.succ) < 1 := by rw [Fin.prod_univ_succ] have h0 : 1 - p (Fin.succ 0) < 1 := by linarith [hp0 (Fin.succ 0)] have h0_nn : 0 ≤ 1 - p (Fin.succ 0) := by linarith [hp1 (Fin.succ 0)] have hrest_le : ∏ i : Fin v, (1 - p i.succ.succ) ≤ 1 := Finset.prod_le_one (fun i _ => by linarith [hp1 i.succ.succ]) (fun i _ => by linarith [hp0 i.succ.succ]) have hrest_nn : 0 ≤ ∏ i : Fin v, (1 - p i.succ.succ) := Finset.prod_nonneg (fun i _ => by linarith [hp1 i.succ.succ]) nlinarith linarith have htail_le : prodComplement (fun i : Fin (v + 1) => p i.succ) ≤ ∑ i : Fin (v + 1), p i.succ := prodComplement_le_sum (fun i => p i.succ) (fun i => le_of_lt (hp0 i.succ)) (fun i => hp1 i.succ) nlinarith [hp0 0] /-- Equivalence between `Fintype.piFinset H` on `Fin (v + 1)` and `H 0 ×ˢ Fintype.piFinset (H ∘ succ)`. -/ lemma sum_piFinset_succ {F α : Type*} [AddCommMonoid α] {v : ℕ} (H : Fin (v + 1) → Finset F) (f : (Fin (v + 1) → F) → α) : ∑ x ∈ Fintype.piFinset H, f x = ∑ a ∈ H 0, ∑ tail ∈ Fintype.piFinset (fun i : Fin v => H i.succ), f (Fin.cons a tail) := by rw [← Finset.sum_product'] refine Finset.sum_bij (fun x _ => (x 0, fun i : Fin v => x i.succ)) ?_ ?_ ?_ ?_ · intro x hx rw [Finset.mem_product, Fintype.mem_piFinset] rw [Fintype.mem_piFinset] at hx exact ⟨hx 0, fun i => hx i.succ⟩ · intro x _ y _ hxy simp only [Prod.mk.injEq] at hxy ext i cases i using Fin.cases with | zero => exact hxy.1 | succ j => exact congrFun hxy.2 j · intro ⟨a, tail⟩ h rw [Finset.mem_product, Fintype.mem_piFinset] at h refine ⟨Fin.cons a tail, ?_, ?_⟩ · rw [Fintype.mem_piFinset] intro i cases i using Fin.cases with | zero => simpa using h.1 | succ j => simpa using h.2 j · ext <;> simp · intro x _ congr 1 ext i cases i using Fin.cases <;> simp lemma card_piFinset_succ {F : Type*} {v : ℕ} (S : Fin (v + 1) → Finset F) : (Fintype.piFinset S).card = (S 0).card * (Fintype.piFinset (fun i : Fin v => S i.succ)).card := by have h := sum_piFinset_succ S (fun _ => (1 : ℕ)) simp only [Finset.sum_const, smul_eq_mul, mul_one] at h exact h lemma card_filter_piFinset_succ {F : Type*} {v : ℕ} (S : Fin (v + 1) → Finset F) (P : (Fin (v + 1) → F) → Prop) [DecidablePred P] : ((Fintype.piFinset S).filter P).card = ∑ a ∈ S 0, ((Fintype.piFinset (fun i : Fin v => S i.succ)).filter (fun tail => P (Fin.cons a tail))).card := by rw [Finset.card_filter, sum_piFinset_succ] refine Finset.sum_congr rfl (fun a _ => ?_) rw [Finset.card_filter] lemma piFinset_fin0_eq_singleton {F : Type*} (H : Fin 0 → Finset F) : Fintype.piFinset H = {Fin.elim0} := by ext x simp only [Fintype.mem_piFinset, Finset.mem_singleton] exact ⟨fun _ => Subsingleton.elim x Fin.elim0, fun _ i => Fin.elim0 i⟩ lemma coeff_le_degreeOf {F : Type*} [CommSemiring F] {σ : Type*} (i : σ) {g : MvPolynomial σ F} {m : σ →₀ ℕ} (hm : m ∈ g.support) : m i ≤ g.degreeOf i := by rw [MvPolynomial.degreeOf_eq_sup] exact Finset.le_sup (f := fun s : σ →₀ ℕ => s i) hm end Pillar1Helpers section Pillar1 variable {F : Type*} [Field F] [DecidableEq F] /-- Sum of a multivariate polynomial `g` over the finite box `∏ i, H i`. -/ noncomputable def hypercubeSum {v : ℕ} (g : MvPolynomial (Fin v) F) (H : Fin v → Finset F) : F := ∑ x ∈ Fintype.piFinset H, MvPolynomial.eval x g /-- Specialize variable `0` of `g ∈ F[X₀, …, Xᵥ]` to `r₀ : F`, yielding a `v`-variate polynomial. -/ noncomputable def specialize₀ {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (r₀ : F) : MvPolynomial (Fin v) F := MvPolynomial.eval₂ MvPolynomial.C (Fin.cases (MvPolynomial.C r₀) MvPolynomial.X) g /-- Round-1 univariate marginal polynomial `g₁(X) = ∑_{tail ∈ ∏ H_{i+1}} g(X, tail)`. -/ noncomputable def roundPoly {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (H : Fin (v + 1) → Finset F) : Polynomial F := ∑ tail ∈ Fintype.piFinset (fun i : Fin v => H i.succ), MvPolynomial.eval₂ Polynomial.C (Fin.cases Polynomial.X (fun i => Polynomial.C (tail i))) g omit [DecidableEq F] in lemma eval_specialize₀ {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (r₀ : F) (tail : Fin v → F) : MvPolynomial.eval tail (specialize₀ g r₀) = MvPolynomial.eval (Fin.cons r₀ tail) g := by unfold specialize₀ induction g using MvPolynomial.induction_on with | C a => simp | add p q hp hq => simp [hp, hq] | mul_X p i hp => rw [MvPolynomial.eval₂_mul, map_mul, map_mul, hp, MvPolynomial.eval₂_X, MvPolynomial.eval_X] cases i using Fin.cases <;> simp omit [DecidableEq F] in lemma eval_roundPoly_term {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (r₀ : F) (tail : Fin v → F) : (MvPolynomial.eval₂ Polynomial.C (Fin.cases Polynomial.X (fun i => Polynomial.C (tail i))) g).eval r₀ = MvPolynomial.eval (Fin.cons r₀ tail) g := by induction g using MvPolynomial.induction_on with | C a => simp | add p q hp hq => simp [hp, hq] | mul_X p i hp => rw [MvPolynomial.eval₂_mul, Polynomial.eval_mul, map_mul, hp, MvPolynomial.eval₂_X, MvPolynomial.eval_X] cases i using Fin.cases <;> simp omit [DecidableEq F] in /-- Evaluating the round-1 marginal polynomial at `r₀` yields the exact sub-hypercube sum of `specialize₀ g r₀`. -/ lemma eval_roundPoly {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (H : Fin (v + 1) → Finset F) (r₀ : F) : (roundPoly g H).eval r₀ = hypercubeSum (specialize₀ g r₀) (fun i => H i.succ) := by unfold roundPoly hypercubeSum rw [Polynomial.eval_finsetSum] refine Finset.sum_congr rfl (fun tail _ => ?_) rw [eval_roundPoly_term, eval_specialize₀] omit [DecidableEq F] in /-- Summing `roundPoly g H` over `H 0` recovers the full `hypercubeSum g H`. -/ lemma sum_eval_roundPoly {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (H : Fin (v + 1) → Finset F) : ∑ a ∈ H 0, (roundPoly g H).eval a = hypercubeSum g H := by unfold hypercubeSum rw [sum_piFinset_succ] refine Finset.sum_congr rfl (fun a _ => ?_) rw [eval_roundPoly] unfold hypercubeSum refine Finset.sum_congr rfl (fun tail _ => ?_) rw [eval_specialize₀] omit [DecidableEq F] in /-- Degree bound for a single term in `roundPoly g H`. -/ lemma natDegree_eval₂_roundTerm_le {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (tail : Fin v → F) : (MvPolynomial.eval₂ Polynomial.C (Fin.cases Polynomial.X (fun i => Polynomial.C (tail i))) g).natDegree ≤ g.degreeOf 0 := by rw [MvPolynomial.eval₂_eq'] refine Polynomial.natDegree_sum_le_of_forall_le _ _ (fun d hd => ?_) have hd_le : d 0 ≤ g.degreeOf 0 := coeff_le_degreeOf 0 hd have h1 : (Polynomial.C (MvPolynomial.coeff d g) * ∏ i : Fin (v + 1), (Fin.cases (motive := fun _ => Polynomial F) Polynomial.X (fun j => Polynomial.C (tail j)) i) ^ d i).natDegree ≤ (∏ i : Fin (v + 1), (Fin.cases (motive := fun _ => Polynomial F) Polynomial.X (fun j => Polynomial.C (tail j)) i) ^ d i).natDegree := Polynomial.natDegree_C_mul_le _ _ refine h1.trans ?_ rw [Fin.prod_univ_succ] simp only [Fin.cases_zero, Fin.cases_succ] have hconst : (∏ i : Fin v, Polynomial.C (tail i) ^ d i.succ) = Polynomial.C (∏ i : Fin v, (tail i) ^ d i.succ) := by simp [map_prod, map_pow] rw [hconst, mul_comm] refine (Polynomial.natDegree_C_mul_le _ _).trans ?_ simpa [Polynomial.natDegree_X_pow] using hd_le omit [DecidableEq F] in /-- The round-1 marginal polynomial has degree at most `g.degreeOf 0`. -/ lemma natDegree_roundPoly_le {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (H : Fin (v + 1) → Finset F) : (roundPoly g H).natDegree ≤ g.degreeOf 0 := by unfold roundPoly exact Polynomial.natDegree_sum_le_of_forall_le _ _ (fun tail _ => natDegree_eval₂_roundTerm_le g tail) omit [DecidableEq F] in /-- Specializing variable `0` does not increase the individual degree in any remaining variable. -/ lemma degreeOf_specialize₀_le {v : ℕ} (g : MvPolynomial (Fin (v + 1)) F) (r₀ : F) (i : Fin v) : (specialize₀ g r₀).degreeOf i ≤ g.degreeOf i.succ := by unfold specialize₀ rw [MvPolynomial.eval₂_eq', MvPolynomial.degreeOf_eq_sup, Finset.sup_le_iff] intro s hs have hfin := MvPolynomial.support_sum hs rw [Finset.mem_biUnion] at hfin rcases hfin with ⟨d, hd, hsd⟩ have hterm : MvPolynomial.C (MvPolynomial.coeff d g) * ∏ j : Fin (v + 1), (Fin.cases (MvPolynomial.C r₀) MvPolynomial.X j) ^ d j = MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (fun k : Fin v => d k.succ)) (MvPolynomial.coeff d g * r₀ ^ d 0) := by rw [Fin.prod_univ_succ] simp only [Fin.cases_zero, Fin.cases_succ, ← map_pow, ← mul_assoc, ← map_mul] rw [MvPolynomial.monomial_eq, Finsupp.prod_fintype _ _ (fun _ => pow_zero _)] congr 1 rw [hterm] at hsd have hse := Finset.mem_singleton.mp (MvPolynomial.support_monomial_subset hsd) rw [hse] simpa using coeff_le_degreeOf i.succ hd /-- An adaptive deterministic Sum-Check prover for `v` rounds. -/ inductive SumCheckProver (F : Type*) [CommSemiring F] : ℕ → Type _ | base : SumCheckProver F 0 | step {v : ℕ} (send : F → Polynomial F) (next : F → F → SumCheckProver F v) : SumCheckProver F (v + 1) /-- The honest Sum-Check prover for polynomial `g` over box `H`. -/ noncomputable def honestProver : {v : ℕ} → MvPolynomial (Fin v) F → (Fin v → Finset F) → SumCheckProver F v | 0, _, _ => SumCheckProver.base | _ + 1, g, H => SumCheckProver.step (fun _ => roundPoly g H) (fun _ r₀ => honestProver (specialize₀ g r₀) (fun i => H i.succ)) /-- Verifier acceptance predicate for `v`-round Sum-Check on challenges `r : Fin v → F`. -/ def sumCheckAccept : {v : ℕ} → MvPolynomial (Fin v) F → (Fin v → Finset F) → (Fin v → ℕ) → SumCheckProver F v → F → (Fin v → F) → Prop | 0, g, _, _, .base, claim, _ => claim = MvPolynomial.eval Fin.elim0 g | _ + 1, g, H, d, .step send next, claim, r => let p := send claim p.natDegree ≤ d 0 ∧ (∑ a ∈ H 0, p.eval a = claim) ∧ sumCheckAccept (specialize₀ g (r 0)) (fun i => H i.succ) (fun i => d i.succ) (next claim (r 0)) (p.eval (r 0)) (fun i => r i.succ) open Classical in /-- Exact acceptance probability of a Sum-Check prover over uniform challenges `r ∈ ∏ S_i`. -/ noncomputable def sumCheckAcceptProb {v : ℕ} (g : MvPolynomial (Fin v) F) (H S : Fin v → Finset F) (d : Fin v → ℕ) (P : SumCheckProver F v) (claim : F) : ℝ := (((Fintype.piFinset S).filter (fun r => sumCheckAccept g H d P claim r)).card : ℝ) / ((Fintype.piFinset S).card : ℝ) omit [DecidableEq F] in /-- **Theorem 1.1 (Perfect Sum-Check Completeness)**: The honest prover is accepted on EVERY challenge tuple `r`, hence with probability `1`. -/ theorem sumCheck_honest_accept {v : ℕ} (g : MvPolynomial (Fin v) F) (H : Fin v → Finset F) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) (r : Fin v → F) : sumCheckAccept g H d (honestProver g H) (hypercubeSum g H) r := by induction v with | zero => simp only [honestProver, sumCheckAccept, hypercubeSum, piFinset_fin0_eq_singleton, Finset.sum_singleton] | succ v ih => simp only [honestProver, sumCheckAccept] refine ⟨(natDegree_roundPoly_le g H).trans (hdeg 0), sum_eval_roundPoly g H, ?_⟩ rw [eval_roundPoly] exact ih (specialize₀ g (r 0)) (fun i => H i.succ) (fun i => d i.succ) (fun i => (degreeOf_specialize₀_le g (r 0) i).trans (hdeg i.succ)) (fun i => r i.succ) omit [DecidableEq F] in theorem sumCheck_honest_completeness {v : ℕ} (g : MvPolynomial (Fin v) F) (H S : Fin v → Finset F) (hS : ∀ i, (S i).Nonempty) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) : sumCheckAcceptProb g H S d (honestProver g H) (hypercubeSum g H) = 1 := by classical unfold sumCheckAcceptProb have hfilt : (Fintype.piFinset S).filter (fun r => sumCheckAccept g H d (honestProver g H) (hypercubeSum g H) r) = Fintype.piFinset S := by rw [Finset.filter_eq_self] intro r _ exact sumCheck_honest_accept g H d hdeg r rw [hfilt] have hpos : (0 : ℝ) < (Fintype.piFinset S).card := by have hne : (Fintype.piFinset S).Nonempty := ⟨fun i => (hS i).choose, Fintype.mem_piFinset.mpr (fun i => (hS i).choose_spec)⟩ exact_mod_cast hne.card_pos exact div_self (ne_of_gt hpos) /-- Helper: number of elements in `S` where two distinct polynomials of degree `≤ d` agree is at most `min d S.card`. -/ lemma card_filter_poly_eq_le {p q : Polynomial F} {S : Finset F} {d : ℕ} (hp : p.natDegree ≤ d) (hq : q.natDegree ≤ d) (hne : p ≠ q) : (S.filter (fun r => p.eval r = q.eval r)).card ≤ min d S.card := by rw [le_min_iff] refine ⟨?_, Finset.card_filter_le _ _⟩ have hsub_ne : p - q ≠ 0 := sub_ne_zero.mpr hne have hsub_deg : (p - q).natDegree ≤ d := (Polynomial.natDegree_sub_le p q).trans (max_le hp hq) have hsub_card : (S.filter (fun r => p.eval r = q.eval r)).card ≤ (p - q).roots.card := by have hle : (S.filter (fun r => p.eval r = q.eval r)).val ≤ (p - q).roots := by rw [Multiset.le_iff_count] intro r by_cases hr : r ∈ S.filter (fun r => p.eval r = q.eval r) · rw [Multiset.count_eq_one_of_mem (Finset.nodup _) hr] have hev : (p - q).eval r = 0 := by simp [(Finset.mem_filter.mp hr).2] exact Multiset.one_le_count_iff_mem.mpr ((Polynomial.mem_roots hsub_ne).mpr hev) · rw [Multiset.count_eq_zero.mpr hr] exact Nat.zero_le _ exact Multiset.card_le_card hle exact hsub_card.trans ((Polynomial.card_roots' (p - q)).trans hsub_deg) /-- Refined root count when `H ⊆ S` and `∑_{a ∈ H} p(a) ≠ ∑_{a ∈ H} q(a)`: `p` and `q` must disagree on at least one point of `H ⊆ S`, so the agreement count is at most `min d (S.card - 1)`. -/ lemma card_filter_poly_eq_le_sub_one {p q : Polynomial F} {H S : Finset F} {d : ℕ} (hp : p.natDegree ≤ d) (hq : q.natDegree ≤ d) (hHS : H ⊆ S) (hsum : ∑ a ∈ H, p.eval a ≠ ∑ a ∈ H, q.eval a) : (S.filter (fun r => p.eval r = q.eval r)).card ≤ min d (S.card - 1) := by have hne : p ≠ q := fun h => hsum (by rw [h]) have h1 : (S.filter (fun r => p.eval r = q.eval r)).card ≤ d := (le_min_iff.mp (card_filter_poly_eq_le (S := S) hp hq hne)).1 have hex : ∃ a ∈ H, p.eval a ≠ q.eval a := by by_contra hall push Not at hall exact hsum (Finset.sum_congr rfl hall) rcases hex with ⟨a, haH, hane⟩ have hssub : S.filter (fun r => p.eval r = q.eval r) ⊆ S.erase a := by intro r hr rw [Finset.mem_filter] at hr rw [Finset.mem_erase] exact ⟨fun h => hane (h ▸ hr.2), hr.1⟩ have h2 : (S.filter (fun r => p.eval r = q.eval r)).card ≤ S.card - 1 := by have hle := Finset.card_le_card hssub rwa [Finset.card_erase_of_mem (hHS haH)] at hle exact le_min h1 h2 /-- **Theorem 1.2 (Exact Product-Complement Sum-Check Soundness)**: For EVERY `v`-variate polynomial `g` with `degreeOf i ≤ d i`, EVERY false claim `claim ≠ hypercubeSum g H`, and EVERY adaptive prover `P`, the acceptance probability obeys `Pr[accept] ≤ 1 - ∏ i, (1 - min (d i) |S i| / |S i|)`. -/ theorem sumCheck_exact_product_soundness {v : ℕ} (g : MvPolynomial (Fin v) F) (H S : Fin v → Finset F) (hS : ∀ i, (S i).Nonempty) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) (P : SumCheckProver F v) (claim : F) (hfalse : claim ≠ hypercubeSum g H) : sumCheckAcceptProb g H S d P claim ≤ prodComplement (fun i => ((min (d i) (S i).card : ℕ) : ℝ) / ((S i).card : ℝ)) := by classical induction v generalizing claim with | zero => unfold sumCheckAcceptProb prodComplement cases P with | base => have hne_eval : claim ≠ MvPolynomial.eval Fin.elim0 g := by intro h; apply hfalse rw [hypercubeSum, piFinset_fin0_eq_singleton, Finset.sum_singleton] exact h have hfilt : (Fintype.piFinset S).filter (fun r => sumCheckAccept g H d SumCheckProver.base claim r) = ∅ := by ext r; simp [sumCheckAccept, hne_eval] rw [hfilt]; simp | succ v ih => cases P with | step send next => set p := send claim by_cases hvalid : p.natDegree ≤ d 0 ∧ ∑ a ∈ H 0, p.eval a = claim · rcases hvalid with ⟨hpdeg, hpsum⟩ have hpne : p ≠ roundPoly g H := by intro heq; apply hfalse; rw [← hpsum, heq, sum_eval_roundPoly] set Z := (S 0).filter (fun r₀ => p.eval r₀ = (roundPoly g H).eval r₀) have hZcard : Z.card ≤ min (d 0) (S 0).card := card_filter_poly_eq_le hpdeg ((natDegree_roundPoly_le g H).trans (hdeg 0)) hpne set T := Fintype.piFinset (fun i : Fin v => S i.succ) have hS0pos : (0 : ℝ) < (S 0).card := by exact_mod_cast (hS 0).card_pos have hTpos : (0 : ℝ) < T.card := by have hne : T.Nonempty := ⟨fun i => (hS i.succ).choose, Fintype.mem_piFinset.mpr (fun i => (hS i.succ).choose_spec)⟩ exact_mod_cast hne.card_pos set E_tail := prodComplement (fun i : Fin v => ((min (d i.succ) (S i.succ).card : ℕ) : ℝ) / ((S i.succ).card : ℝ)) have hE_le1 : E_tail ≤ 1 := prodComplement_le_one _ (fun i => by rw [div_le_one (by exact_mod_cast (hS i.succ).card_pos)] exact_mod_cast min_le_right _ _) have hcount : (((Fintype.piFinset S).filter (fun r => sumCheckAccept g H d (SumCheckProver.step send next) claim r)).card : ℝ) ≤ (Z.card : ℝ) * (T.card : ℝ) + (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by rw [card_filter_piFinset_succ] push_cast have hsplit := (Finset.sum_filter_add_sum_filter_not (S 0) (fun r₀ => p.eval r₀ = (roundPoly g H).eval r₀) (fun r₀ => ((T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail))).card : ℝ))).symm rw [hsplit] have hpart1 : ∑ r₀ ∈ Z, ((T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail))).card : ℝ) ≤ (Z.card : ℝ) * (T.card : ℝ) := by calc ∑ r₀ ∈ Z, ((T.filter _).card : ℝ) ≤ ∑ _r₀ ∈ Z, (T.card : ℝ) := Finset.sum_le_sum (fun r₀ _ => by exact_mod_cast Finset.card_filter_le _ _) _ = (Z.card : ℝ) * (T.card : ℝ) := by simp have hpart2 : ∑ r₀ ∈ (S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀), ((T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail))).card : ℝ) ≤ (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by have hcard_not : ((S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀)).card = (S 0).card - Z.card := by have hadd : Z.card + ((S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀)).card = (S 0).card := Finset.card_filter_add_card_filter_not (s := S 0) (p := fun r₀ => p.eval r₀ = (roundPoly g H).eval r₀) omega calc ∑ r₀ ∈ (S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀), ((T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail))).card : ℝ) ≤ ∑ _r₀ ∈ (S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀), (E_tail * (T.card : ℝ)) := by refine Finset.sum_le_sum (fun r₀ hr₀ => ?_) have hr₀ne : p.eval r₀ ≠ hypercubeSum (specialize₀ g r₀) (fun i => H i.succ) := by rw [← eval_roundPoly]; exact (Finset.mem_filter.mp hr₀).2 have hih := ih (specialize₀ g r₀) (fun i => H i.succ) (fun i => S i.succ) (fun i => hS i.succ) (fun i => d i.succ) (fun i => (degreeOf_specialize₀_le g r₀ i).trans (hdeg i.succ)) (next claim r₀) (p.eval r₀) hr₀ne unfold sumCheckAcceptProb at hih have hsub_eq : T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail)) = T.filter (fun tail => sumCheckAccept (specialize₀ g r₀) (fun i => H i.succ) (fun i => d i.succ) (next claim r₀) (p.eval r₀) tail) := by ext tail simp only [Finset.mem_filter, sumCheckAccept, Fin.cons_zero, Fin.cons_succ] exact ⟨fun ⟨ht, _, _, hacc⟩ => ⟨ht, hacc⟩, fun ⟨ht, hacc⟩ => ⟨ht, hpdeg, hpsum, hacc⟩⟩ rw [hsub_eq] exact (div_le_iff₀ hTpos).mp hih _ = (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by simp [hcard_not] linarith unfold sumCheckAcceptProb rw [card_piFinset_succ, Nat.cast_mul] have hZleS : Z.card ≤ (S 0).card := Finset.card_filter_le _ _ rw [Nat.cast_sub hZleS] at hcount rw [div_le_iff₀ (mul_pos hS0pos hTpos)] rw [prodComplement_succ] have hZle : (Z.card : ℝ) ≤ ((min (d 0) (S 0).card : ℕ) : ℝ) := by exact_mod_cast hZcard have hstep : (Z.card : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - (Z.card : ℝ)) * (E_tail * (T.card : ℝ)) ≤ ((min (d 0) (S 0).card : ℕ) : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - ((min (d 0) (S 0).card : ℕ) : ℝ)) * (E_tail * (T.card : ℝ)) := by have hdiff : 0 ≤ (((min (d 0) (S 0).card : ℕ) : ℝ) - (Z.card : ℝ)) * (1 - E_tail) * (T.card : ℝ) := mul_nonneg (mul_nonneg (by linarith) (by linarith)) (le_of_lt hTpos) linarith have halg : (((min (d 0) (S 0).card : ℕ) : ℝ) / ((S 0).card : ℝ) + (1 - ((min (d 0) (S 0).card : ℕ) : ℝ) / ((S 0).card : ℝ)) * E_tail) * (((S 0).card : ℝ) * (T.card : ℝ)) = ((min (d 0) (S 0).card : ℕ) : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - ((min (d 0) (S 0).card : ℕ) : ℝ)) * (E_tail * (T.card : ℝ)) := by field_simp [ne_of_gt hS0pos] linarith · unfold sumCheckAcceptProb have hfilt : (Fintype.piFinset S).filter (fun r => sumCheckAccept g H d (SumCheckProver.step send next) claim r) = ∅ := by ext r simp only [Finset.mem_filter, Finset.notMem_empty, iff_false, not_and] intro _ hacc; exact hvalid ⟨hacc.1, hacc.2.1⟩ rw [hfilt, Finset.card_empty, Nat.cast_zero, zero_div] exact prodComplement_nonneg _ (fun i => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) (fun i => by rw [div_le_one (by exact_mod_cast (hS i).card_pos)] exact_mod_cast min_le_right _ _) /-- **Corollary (Classical LFKN Union Bound from Exact Product-Complement Bound)**. -/ theorem sumCheck_lfkn_union_bound {v : ℕ} (g : MvPolynomial (Fin v) F) (H S : Fin v → Finset F) (hS : ∀ i, (S i).Nonempty) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) (P : SumCheckProver F v) (claim : F) (hfalse : claim ≠ hypercubeSum g H) : sumCheckAcceptProb g H S d P claim ≤ ∑ i : Fin v, (d i : ℝ) / ((S i).card : ℝ) := by refine (sumCheck_exact_product_soundness g H S hS d hdeg P claim hfalse).trans ?_ have h1 : prodComplement (fun i => ((min (d i) (S i).card : ℕ) : ℝ) / ((S i).card : ℝ)) ≤ ∑ i : Fin v, ((min (d i) (S i).card : ℕ) : ℝ) / ((S i).card : ℝ) := prodComplement_le_sum _ (fun i => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) (fun i => by rw [div_le_one (by exact_mod_cast (hS i).card_pos)] exact_mod_cast min_le_right _ _) refine h1.trans (Finset.sum_le_sum (fun i _ => ?_)) exact div_le_div_of_nonneg_right (by exact_mod_cast min_le_left _ _) (Nat.cast_nonneg _) /-- **Theorem 1.3 (Refined `H i ⊆ S i` Sum-Check Soundness Cap)**: When `H i ⊆ S i`, each round has at most `min (d i) (|S i| - 1)` lucky challenges, giving a strictly nontrivial `< 1` soundness bound even when `d i ≥ |S i|`. -/ theorem sumCheck_subset_refined_soundness {v : ℕ} (g : MvPolynomial (Fin v) F) (H S : Fin v → Finset F) (hS : ∀ i, (S i).Nonempty) (hHS : ∀ i, H i ⊆ S i) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) (P : SumCheckProver F v) (claim : F) (hfalse : claim ≠ hypercubeSum g H) : sumCheckAcceptProb g H S d P claim ≤ prodComplement (fun i => ((min (d i) ((S i).card - 1) : ℕ) : ℝ) / ((S i).card : ℝ)) := by classical induction v generalizing claim with | zero => unfold sumCheckAcceptProb prodComplement cases P with | base => have hne_eval : claim ≠ MvPolynomial.eval Fin.elim0 g := by intro h; apply hfalse rw [hypercubeSum, piFinset_fin0_eq_singleton, Finset.sum_singleton]; exact h have hfilt : (Fintype.piFinset S).filter (fun r => sumCheckAccept g H d SumCheckProver.base claim r) = ∅ := by ext r; simp [sumCheckAccept, hne_eval] rw [hfilt]; simp | succ v ih => cases P with | step send next => set p := send claim by_cases hvalid : p.natDegree ≤ d 0 ∧ ∑ a ∈ H 0, p.eval a = claim · rcases hvalid with ⟨hpdeg, hpsum⟩ have hsum_ne : ∑ a ∈ H 0, p.eval a ≠ ∑ a ∈ H 0, (roundPoly g H).eval a := by rw [hpsum, sum_eval_roundPoly]; exact hfalse set Z := (S 0).filter (fun r₀ => p.eval r₀ = (roundPoly g H).eval r₀) have hZcard : Z.card ≤ min (d 0) ((S 0).card - 1) := card_filter_poly_eq_le_sub_one hpdeg ((natDegree_roundPoly_le g H).trans (hdeg 0)) (hHS 0) hsum_ne set T := Fintype.piFinset (fun i : Fin v => S i.succ) have hS0pos : (0 : ℝ) < (S 0).card := by exact_mod_cast (hS 0).card_pos have hTpos : (0 : ℝ) < T.card := by have hne : T.Nonempty := ⟨fun i => (hS i.succ).choose, Fintype.mem_piFinset.mpr (fun i => (hS i.succ).choose_spec)⟩ exact_mod_cast hne.card_pos set E_tail := prodComplement (fun i : Fin v => ((min (d i.succ) ((S i.succ).card - 1) : ℕ) : ℝ) / ((S i.succ).card : ℝ)) have hE_le1 : E_tail ≤ 1 := prodComplement_le_one _ (fun i => by rw [div_le_one (by exact_mod_cast (hS i.succ).card_pos)] exact_mod_cast (min_le_right _ _).trans (Nat.sub_le _ _)) have hcount : (((Fintype.piFinset S).filter (fun r => sumCheckAccept g H d (SumCheckProver.step send next) claim r)).card : ℝ) ≤ (Z.card : ℝ) * (T.card : ℝ) + (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by rw [card_filter_piFinset_succ] push_cast have hsplit := (Finset.sum_filter_add_sum_filter_not (S 0) (fun r₀ => p.eval r₀ = (roundPoly g H).eval r₀) (fun r₀ => ((T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail))).card : ℝ))).symm rw [hsplit] have hpart1 : ∑ r₀ ∈ Z, ((T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail))).card : ℝ) ≤ (Z.card : ℝ) * (T.card : ℝ) := by calc ∑ r₀ ∈ Z, ((T.filter _).card : ℝ) ≤ ∑ _r₀ ∈ Z, (T.card : ℝ) := Finset.sum_le_sum (fun r₀ _ => by exact_mod_cast Finset.card_filter_le _ _) _ = (Z.card : ℝ) * (T.card : ℝ) := by simp have hpart2 : ∑ r₀ ∈ (S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀), ((T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail))).card : ℝ) ≤ (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by have hcard_not : ((S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀)).card = (S 0).card - Z.card := by have hadd : Z.card + ((S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀)).card = (S 0).card := Finset.card_filter_add_card_filter_not (s := S 0) (p := fun r₀ => p.eval r₀ = (roundPoly g H).eval r₀) omega calc ∑ r₀ ∈ (S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀), ((T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail))).card : ℝ) ≤ ∑ _r₀ ∈ (S 0).filter (fun r₀ => ¬ p.eval r₀ = (roundPoly g H).eval r₀), (E_tail * (T.card : ℝ)) := by refine Finset.sum_le_sum (fun r₀ hr₀ => ?_) have hr₀ne : p.eval r₀ ≠ hypercubeSum (specialize₀ g r₀) (fun i => H i.succ) := by rw [← eval_roundPoly]; exact (Finset.mem_filter.mp hr₀).2 have hih := ih (specialize₀ g r₀) (fun i => H i.succ) (fun i => S i.succ) (fun i => hS i.succ) (fun i => hHS i.succ) (fun i => d i.succ) (fun i => (degreeOf_specialize₀_le g r₀ i).trans (hdeg i.succ)) (next claim r₀) (p.eval r₀) hr₀ne unfold sumCheckAcceptProb at hih have hsub_eq : T.filter (fun tail => sumCheckAccept g H d (SumCheckProver.step send next) claim (Fin.cons r₀ tail)) = T.filter (fun tail => sumCheckAccept (specialize₀ g r₀) (fun i => H i.succ) (fun i => d i.succ) (next claim r₀) (p.eval r₀) tail) := by ext tail simp only [Finset.mem_filter, sumCheckAccept, Fin.cons_zero, Fin.cons_succ] exact ⟨fun ⟨ht, _, _, hacc⟩ => ⟨ht, hacc⟩, fun ⟨ht, hacc⟩ => ⟨ht, hpdeg, hpsum, hacc⟩⟩ rw [hsub_eq] exact (div_le_iff₀ hTpos).mp hih _ = (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by simp [hcard_not] linarith unfold sumCheckAcceptProb rw [card_piFinset_succ, Nat.cast_mul] have hZleS : Z.card ≤ (S 0).card := Finset.card_filter_le _ _ rw [Nat.cast_sub hZleS] at hcount rw [div_le_iff₀ (mul_pos hS0pos hTpos)] rw [prodComplement_succ] have hZle : (Z.card : ℝ) ≤ ((min (d 0) ((S 0).card - 1) : ℕ) : ℝ) := by exact_mod_cast hZcard have hstep : (Z.card : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - (Z.card : ℝ)) * (E_tail * (T.card : ℝ)) ≤ ((min (d 0) ((S 0).card - 1) : ℕ) : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - ((min (d 0) ((S 0).card - 1) : ℕ) : ℝ)) * (E_tail * (T.card : ℝ)) := by have hdiff : 0 ≤ (((min (d 0) ((S 0).card - 1) : ℕ) : ℝ) - (Z.card : ℝ)) * (1 - E_tail) * (T.card : ℝ) := mul_nonneg (mul_nonneg (by linarith) (by linarith)) (le_of_lt hTpos) linarith have halg : (((min (d 0) ((S 0).card - 1) : ℕ) : ℝ) / ((S 0).card : ℝ) + (1 - ((min (d 0) ((S 0).card - 1) : ℕ) : ℝ) / ((S 0).card : ℝ)) * E_tail) * (((S 0).card : ℝ) * (T.card : ℝ)) = ((min (d 0) ((S 0).card - 1) : ℕ) : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - ((min (d 0) ((S 0).card - 1) : ℕ) : ℝ)) * (E_tail * (T.card : ℝ)) := by field_simp [ne_of_gt hS0pos] linarith · unfold sumCheckAcceptProb have hfilt : (Fintype.piFinset S).filter (fun r => sumCheckAccept g H d (SumCheckProver.step send next) claim r) = ∅ := by ext r simp only [Finset.mem_filter, Finset.notMem_empty, iff_false, not_and] intro _ hacc; exact hvalid ⟨hacc.1, hacc.2.1⟩ rw [hfilt, Finset.card_empty, Nat.cast_zero, zero_div] exact prodComplement_nonneg _ (fun i => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) (fun i => by rw [div_le_one (by exact_mod_cast (hS i).card_pos)] exact_mod_cast (min_le_right _ _).trans (Nat.sub_le _ _)) /-- Monic vanishing polynomial `∏_{r ∈ R} (X - r)` for a finite root set `R ⊆ F`. -/ noncomputable def vanishPoly (R : Finset F) : Polynomial F := ∏ r ∈ R, (Polynomial.X - Polynomial.C r) /-- Exact root-weight functional `Φ_H(R) = ∑_{a ∈ H} ∏_{r ∈ R} (a - r)`. -/ def rootWeight (H R : Finset F) : F := ∑ a ∈ H, ∏ r ∈ R, (a - r) omit [DecidableEq F] in lemma eval_vanishPoly (R : Finset F) (x : F) : (vanishPoly R).eval x = ∏ r ∈ R, (x - r) := by unfold vanishPoly rw [Polynomial.eval_prod] refine Finset.prod_congr rfl (fun r _ => by simp) omit [DecidableEq F] in lemma eval_vanishPoly_eq_zero_iff (R : Finset F) (x : F) : (vanishPoly R).eval x = 0 ↔ x ∈ R := by rw [eval_vanishPoly, Finset.prod_eq_zero_iff] simp [sub_eq_zero] omit [DecidableEq F] in lemma natDegree_vanishPoly (R : Finset F) : (vanishPoly R).natDegree = R.card := by unfold vanishPoly rw [Polynomial.natDegree_prod_of_monic _ _ (fun r _ => Polynomial.monic_X_sub_C r)] simp omit [DecidableEq F] in lemma sum_eval_vanishPoly (H R : Finset F) : ∑ a ∈ H, (vanishPoly R).eval a = rootWeight H R := by unfold rootWeight refine Finset.sum_congr rfl (fun a _ => eval_vanishPoly R a) /-- Explicit optimal adaptive cheating prover parameterized by root sets `R : Fin v → Finset F`. -/ noncomputable def optimalCheatingProver : {v : ℕ} → MvPolynomial (Fin v) F → (Fin v → Finset F) → (Fin v → Finset F) → SumCheckProver F v | 0, _, _, _ => SumCheckProver.base | _ + 1, g, H, R => SumCheckProver.step (fun claim => roundPoly g H + Polynomial.C ((claim - hypercubeSum g H) * (rootWeight (H 0) (R 0))⁻¹) * vanishPoly (R 0)) (fun _ r₀ => optimalCheatingProver (specialize₀ g r₀) (fun i => H i.succ) (fun i => R i.succ)) omit [DecidableEq F] in /-- Exact characterization of when `optimalCheatingProver` is accepted on challenge tuple `r`. -/ theorem optimalCheatingProver_accept_iff {v : ℕ} (g : MvPolynomial (Fin v) F) (H : Fin v → Finset F) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) (R : Fin v → Finset F) (hRcard : ∀ i, (R i).card ≤ d i) (hPhi : ∀ i, rootWeight (H i) (R i) ≠ 0) (claim : F) (r : Fin v → F) : sumCheckAccept g H d (optimalCheatingProver g H R) claim r ↔ (claim = hypercubeSum g H ∨ ∃ i : Fin v, r i ∈ R i) := by induction v generalizing claim with | zero => simp only [optimalCheatingProver, sumCheckAccept, IsEmpty.exists_iff, or_false, hypercubeSum, piFinset_fin0_eq_singleton, Finset.sum_singleton] | succ v ih => simp only [optimalCheatingProver, sumCheckAccept] set Δ := claim - hypercubeSum g H set c := Δ * (rootWeight (H 0) (R 0))⁻¹ set p := roundPoly g H + Polynomial.C c * vanishPoly (R 0) have hpdeg : p.natDegree ≤ d 0 := by refine (Polynomial.natDegree_add_le _ _).trans (max_le ?_ ?_) · exact (natDegree_roundPoly_le g H).trans (hdeg 0) · exact (Polynomial.natDegree_C_mul_le _ _).trans ((natDegree_vanishPoly (R 0)).le.trans (hRcard 0)) have hpsum : ∑ a ∈ H 0, p.eval a = claim := by simp only [p, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Finset.sum_add_distrib, ← Finset.mul_sum, sum_eval_roundPoly, sum_eval_vanishPoly] simp only [c, Δ, mul_assoc, inv_mul_cancel₀ (hPhi 0), mul_one, add_sub_cancel] have hrec := ih (specialize₀ g (r 0)) (fun i => H i.succ) (fun i => d i.succ) (fun i => (degreeOf_specialize₀_le g (r 0) i).trans (hdeg i.succ)) (fun i => R i.succ) (fun i => hRcard i.succ) (fun i => hPhi i.succ) (p.eval (r 0)) (fun i => r i.succ) have hpeval : p.eval (r 0) = hypercubeSum (specialize₀ g (r 0)) (fun i => H i.succ) ↔ claim = hypercubeSum g H ∨ r 0 ∈ R 0 := by rw [← eval_roundPoly] simp only [p, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, add_eq_left, mul_eq_zero, eval_vanishPoly_eq_zero_iff] simp only [c, Δ, mul_eq_zero, inv_eq_zero, hPhi 0, or_false, sub_eq_zero] constructor · intro ⟨_, _, htail⟩ rcases hrec.mp htail with heq | ⟨i, hi⟩ · rcases hpeval.mp heq with hcl | hr0 · exact Or.inl hcl · exact Or.inr ⟨0, hr0⟩ · exact Or.inr ⟨i.succ, hi⟩ · intro h refine ⟨hpdeg, hpsum, hrec.mpr ?_⟩ rcases h with hcl | ⟨i, hi⟩ · exact Or.inl (hpeval.mpr (Or.inl hcl)) · cases i using Fin.cases with | zero => exact Or.inl (hpeval.mpr (Or.inr hi)) | succ j => exact Or.inr ⟨j, hi⟩ /-- Helper: exact fraction of tuples in `∏ S_i` hitting at least one `R_i ⊆ S_i`. -/ lemma piFinset_exists_mem_prob {α : Type*} [DecidableEq α] {v : ℕ} (S R : Fin v → Finset α) (hS : ∀ i, (S i).Nonempty) (hRS : ∀ i, R i ⊆ S i) : (((Fintype.piFinset S).filter (fun r => ∃ i : Fin v, r i ∈ R i)).card : ℝ) / ((Fintype.piFinset S).card : ℝ) = prodComplement (fun i => ((R i).card : ℝ) / ((S i).card : ℝ)) := by classical have hcompl : ((Fintype.piFinset S).filter (fun r => ¬ ∃ i : Fin v, r i ∈ R i)) = Fintype.piFinset (fun i => S i \ R i) := by ext r simp only [Finset.mem_filter, Fintype.mem_piFinset, Finset.mem_sdiff, not_exists] exact ⟨fun ⟨h1, h2⟩ i => ⟨h1 i, h2 i⟩, fun h => ⟨fun i => (h i).1, fun i => (h i).2⟩⟩ have hadd := Finset.card_filter_add_card_filter_not (s := Fintype.piFinset S) (p := fun r => ∃ i : Fin v, r i ∈ R i) rw [hcompl] at hadd have hcard_S : (Fintype.piFinset S).card = ∏ i : Fin v, (S i).card := Fintype.card_piFinset S have hcard_diff : (Fintype.piFinset (fun i => S i \ R i)).card = ∏ i : Fin v, ((S i).card - (R i).card) := by rw [Fintype.card_piFinset] refine Finset.prod_congr rfl (fun i _ => Finset.card_sdiff_of_subset (hRS i)) have hSpos : ∀ i : Fin v, (0 : ℝ) < (S i).card := fun i => by exact_mod_cast (hS i).card_pos have hprod_pos : (0 : ℝ) < ∏ i : Fin v, ((S i).card : ℝ) := Finset.prod_pos (fun i _ => hSpos i) have hreal_add : (((Fintype.piFinset S).filter (fun r => ∃ i : Fin v, r i ∈ R i)).card : ℝ) = (∏ i : Fin v, ((S i).card : ℝ)) - ∏ i : Fin v, (((S i).card : ℝ) - ((R i).card : ℝ)) := by have h1 : (((Fintype.piFinset S).filter (fun r => ∃ i : Fin v, r i ∈ R i)).card : ℝ) + ((Fintype.piFinset (fun i => S i \ R i)).card : ℝ) = ((Fintype.piFinset S).card : ℝ) := by exact_mod_cast hadd rw [hcard_S, hcard_diff] at h1 push_cast at h1 have h2 : (∏ i : Fin v, (((S i).card - (R i).card : ℕ) : ℝ)) = ∏ i : Fin v, (((S i).card : ℝ) - ((R i).card : ℝ)) := by refine Finset.prod_congr rfl (fun i _ => Nat.cast_sub (Finset.card_le_card (hRS i))) rw [h2] at h1 linarith unfold prodComplement rw [hreal_add, hcard_S] push_cast have hprod_div : (∏ i : Fin v, (((S i).card : ℝ) - ((R i).card : ℝ))) / (∏ i : Fin v, ((S i).card : ℝ)) = ∏ i : Fin v, (1 - ((R i).card : ℝ) / ((S i).card : ℝ)) := by rw [← Finset.prod_div_distrib] refine Finset.prod_congr rfl (fun i _ => by field_simp [ne_of_gt (hSpos i)]) rw [sub_div, div_self (ne_of_gt hprod_pos), hprod_div] /-- **Theorem 1.4 (Exact Optimal Adaptive Cheating Prover Soundness Equality)**: For EVERY polynomial `g` with `degreeOf i ≤ d i` and EVERY false claim `claim ≠ hypercubeSum g H`, `optimalCheatingProver g H R` achieves exact acceptance probability `1 - ∏ i, (1 - |R i| / |S i|)`. -/ theorem sumCheck_optimal_cheating_prover_exact {v : ℕ} (g : MvPolynomial (Fin v) F) (H S : Fin v → Finset F) (hS : ∀ i, (S i).Nonempty) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) (R : Fin v → Finset F) (hRS : ∀ i, R i ⊆ S i) (hRcard : ∀ i, (R i).card ≤ d i) (hPhi : ∀ i, rootWeight (H i) (R i) ≠ 0) (claim : F) (hfalse : claim ≠ hypercubeSum g H) : sumCheckAcceptProb g H S d (optimalCheatingProver g H R) claim = prodComplement (fun i => ((R i).card : ℝ) / ((S i).card : ℝ)) := by classical unfold sumCheckAcceptProb have hfilt : (Fintype.piFinset S).filter (fun r => sumCheckAccept g H d (optimalCheatingProver g H R) claim r) = (Fintype.piFinset S).filter (fun r => ∃ i : Fin v, r i ∈ R i) := by ext r simp only [Finset.mem_filter, and_congr_right_iff] intro _ rw [optimalCheatingProver_accept_iff g H d hdeg R hRcard hPhi claim r] simp [hfalse] rw [hfilt] exact piFinset_exists_mem_prob S R hS hRS /-- **Lemma (Universal Non-Vanishing Root Set Existence)**: For ANY field `F`, ANY `H ⊆ S` with `H` nonempty, and ANY `d` with `|H| - 1 ≤ d ≤ |S| - 1`, there exists `R ⊆ S` of exact size `d` with `rootWeight H R ≠ 0`. -/ lemma exists_nonvanishing_rootSet {H S : Finset F} {d : ℕ} (hHne : H.Nonempty) (hHS : H ⊆ S) (hd_lo : H.card - 1 ≤ d) (hd_hi : d ≤ S.card - 1) : ∃ R : Finset F, R ⊆ S ∧ R.card = d ∧ rootWeight H R ≠ 0 := by rcases hHne with ⟨a₀, ha₀⟩ have hH_er_card : (H.erase a₀).card = H.card - 1 := Finset.card_erase_of_mem ha₀ have hdiff_card : (S \ H).card = S.card - H.card := Finset.card_sdiff_of_subset hHS have hH_pos : 1 ≤ H.card := Finset.one_le_card.mpr ⟨a₀, ha₀⟩ have hneed : d - (H.card - 1) ≤ (S \ H).card := by omega rcases Finset.exists_subset_card_eq hneed with ⟨T, hTsub, hTcard⟩ refine ⟨(H.erase a₀) ∪ T, ?_, ?_, ?_⟩ · refine Finset.union_subset ?_ (hTsub.trans Finset.sdiff_subset) exact (Finset.erase_subset a₀ H).trans hHS · have hdisj : Disjoint (H.erase a₀) T := by rw [Finset.disjoint_left] intro x hx1 hx2 exact (Finset.mem_sdiff.mp (hTsub hx2)).2 (Finset.mem_of_mem_erase hx1) rw [Finset.card_union_of_disjoint hdisj, hH_er_card, hTcard] omega · unfold rootWeight rw [← Finset.add_sum_erase H _ ha₀] have hrest : ∑ a ∈ H.erase a₀, ∏ r ∈ (H.erase a₀) ∪ T, (a - r) = 0 := by refine Finset.sum_eq_zero (fun a ha => ?_) exact Finset.prod_eq_zero (Finset.mem_union_left T ha) (sub_self a) rw [hrest, add_zero] refine Finset.prod_ne_zero_iff.mpr (fun r hr => ?_) intro hzero have heq : a₀ = r := sub_eq_zero.mp hzero subst heq rcases Finset.mem_union.mp hr with h1 | h2 · exact (Finset.mem_erase.mp h1).1 rfl · exact (Finset.mem_sdiff.mp (hTsub h2)).2 ha₀ /-- **Theorem 1.5 (Universal Sum-Check Sharpness)**: Whenever `H i ⊆ S i`, `(H i).Nonempty`, and `|H i| - 1 ≤ d i ≤ |S i| - 1`, there exists an adaptive cheating prover achieving exact equality `1 - ∏ i, (1 - d i / |S i|)` for EVERY polynomial `g` (of degree `≤ d`) and EVERY false claim simultaneously. -/ theorem sumCheck_universal_sharpness {v : ℕ} (g : MvPolynomial (Fin v) F) (H S : Fin v → Finset F) (hHne : ∀ i, (H i).Nonempty) (hHS : ∀ i, H i ⊆ S i) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) (hd_lo : ∀ i, (H i).card - 1 ≤ d i) (hd_hi : ∀ i, d i ≤ (S i).card - 1) (claim : F) (hfalse : claim ≠ hypercubeSum g H) : ∃ P : SumCheckProver F v, sumCheckAcceptProb g H S d P claim = prodComplement (fun i => (d i : ℝ) / ((S i).card : ℝ)) := by have hex : ∀ i, ∃ R : Finset F, R ⊆ S i ∧ R.card = d i ∧ rootWeight (H i) R ≠ 0 := fun i => exists_nonvanishing_rootSet (hHne i) (hHS i) (hd_lo i) (hd_hi i) choose R hRS hRcard hPhi using hex have hS : ∀ i, (S i).Nonempty := fun i => (hHne i).mono (hHS i) refine ⟨optimalCheatingProver g H R, ?_⟩ rw [sumCheck_optimal_cheating_prover_exact g H S hS d hdeg R hRS (fun i => (hRcard i).le) hPhi claim hfalse] congr 1 ext i rw [hRcard i] /-! ### Multiplicative-Subgroup Sum-Check Identity & Zero-Challenge Obstruction -/ omit [DecidableEq F] in lemma sum_subgroup_pow_eq_zero {H : Subgroup Fˣ} [Fintype H] {k : ℕ} (hk : ∃ u : H, ((u : Fˣ) : F) ^ k ≠ 1) : ∑ a : H, ((a : Fˣ) : F) ^ k = 0 := by rcases hk with ⟨u, hu⟩ have hmul : ((u : Fˣ) : F) ^ k * ∑ a : H, ((a : Fˣ) : F) ^ k = ∑ a : H, ((a : Fˣ) : F) ^ k := by rw [Finset.mul_sum] have hbij : ∑ a : H, ((u : Fˣ) : F) ^ k * ((a : Fˣ) : F) ^ k = ∑ a : H, (((u * a : H) : Fˣ) : F) ^ k := by refine Finset.sum_congr rfl (fun a _ => ?_) simp [mul_pow] rw [hbij] exact Fintype.sum_equiv (Equiv.mulLeft u) _ _ (fun _ => rfl) have hsub : (((u : Fˣ) : F) ^ k - 1) * ∑ a : H, ((a : Fˣ) : F) ^ k = 0 := by linear_combination hmul exact (mul_eq_zero.mp hsub).resolve_left (sub_ne_zero.mpr hu) /-- **Theorem 1.6 (Multiplicative-Subgroup Polynomial Sum Identity)**: Over ANY finite subgroup `H ≤ Fˣ` of order `m = |H|`, for EVERY univariate polynomial `q` of degree `< m`, `∑_{a ∈ H} q(a) = m · q(0)`. -/ theorem subgroup_poly_sum_eq_card_mul_eval_zero (H : Subgroup Fˣ) [Fintype H] (q : Polynomial F) (hdeg : q.natDegree < Fintype.card H) : ∑ a : H, q.eval ((a : Fˣ) : F) = (Fintype.card H : F) * q.eval 0 := by have hpow0 : ∀ k, 1 ≤ k → k < Fintype.card H → ∑ a : H, ((a : Fˣ) : F) ^ k = 0 := by intro k hk1 hkm apply sum_subgroup_pow_eq_zero by_contra hall push Not at hall have hpoly_ne : (Polynomial.X ^ k - 1 : Polynomial F) ≠ 0 := by intro h0 have hdeg_eq : (Polynomial.X ^ k - 1 : Polynomial F).natDegree = k := by rw [Polynomial.natDegree_sub_eq_left_of_natDegree_lt] · exact Polynomial.natDegree_X_pow k · rw [Polynomial.natDegree_one, Polynomial.natDegree_X_pow]; omega rw [h0, Polynomial.natDegree_zero] at hdeg_eq omega have himg : (Finset.univ.image (fun a : H => ((a : Fˣ) : F))).card = Fintype.card H := by rw [Finset.card_image_of_injective _ (fun a b hab => Subtype.ext (Units.ext hab))] exact Finset.card_univ have hsub : (Finset.univ.image (fun a : H => ((a : Fˣ) : F))).val ≤ (Polynomial.X ^ k - 1 : Polynomial F).roots := by rw [Multiset.le_iff_count] intro r by_cases hr : r ∈ Finset.univ.image (fun a : H => ((a : Fˣ) : F)) · rw [Multiset.count_eq_one_of_mem (Finset.nodup _) hr] rcases Finset.mem_image.mp hr with ⟨a, _, rfl⟩ have hev : (Polynomial.X ^ k - 1 : Polynomial F).eval ((a : Fˣ) : F) = 0 := by simp only [Polynomial.eval_sub, Polynomial.eval_pow, Polynomial.eval_X, Polynomial.eval_one] exact sub_eq_zero.mpr (hall a) exact Multiset.one_le_count_iff_mem.mpr ((Polynomial.mem_roots hpoly_ne).mpr hev) · rw [Multiset.count_eq_zero.mpr hr]; exact Nat.zero_le _ have hcard_le : Fintype.card H ≤ k := by calc Fintype.card H = (Finset.univ.image (fun a : H => ((a : Fˣ) : F))).card := himg.symm _ ≤ (Polynomial.X ^ k - 1 : Polynomial F).roots.card := Multiset.card_le_card hsub _ ≤ (Polynomial.X ^ k - 1 : Polynomial F).natDegree := Polynomial.card_roots' _ _ ≤ k := (Polynomial.natDegree_sub_le _ _).trans (by simp) omega rw [q.as_sum_range_C_mul_X_pow] simp only [Polynomial.eval_finsetSum, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_pow, Polynomial.eval_X] rw [Finset.sum_comm, Finset.sum_range_succ'] simp only [pow_zero, mul_one] have htail : ∑ k ∈ Finset.range q.natDegree, ∑ x : H, q.coeff (k + 1) * ((x : Fˣ) : F) ^ (k + 1) = 0 := by refine Finset.sum_eq_zero (fun k hk => ?_) rw [← Finset.mul_sum, hpow0 (k + 1) (by omega) (by have := Finset.mem_range.mp hk; omega), mul_zero] rw [htail, zero_add] have hrhs : ∑ x ∈ Finset.range (q.natDegree + 1), q.coeff x * (0 : F) ^ x = q.coeff 0 := by rw [Finset.sum_range_succ'] simp [zero_pow (Nat.succ_ne_zero _)] rw [hrhs] simp [Finset.sum_const, nsmul_eq_mul] /-- **Corollary (Subgroup Sum-Check Zero-Challenge Obstruction)**: For `H ≤ Fˣ` with `deg q < |H|` and `∑_{a ∈ H} q(a) ≠ 0`, `q(0) ≠ 0` deterministically. -/ theorem subgroup_zero_challenge_obstruction (H : Subgroup Fˣ) [Fintype H] (q : Polynomial F) (hdeg : q.natDegree < Fintype.card H) (hsum : ∑ a : H, q.eval ((a : Fˣ) : F) ≠ 0) : q.eval 0 ≠ 0 := by rw [subgroup_poly_sum_eq_card_mul_eval_zero H q hdeg] at hsum exact right_ne_zero_of_mul hsum theorem subgroup_rootWeight_vanishPoly (H : Subgroup Fˣ) [Fintype H] (R : Finset F) (hRcard : R.card < Fintype.card H) (hchar : (Fintype.card H : F) ≠ 0) : (∑ a : H, (vanishPoly R).eval ((a : Fˣ) : F)) ≠ 0 ↔ (0 : F) ∉ R := by rw [subgroup_poly_sum_eq_card_mul_eval_zero H (vanishPoly R) (by rwa [natDegree_vanishPoly])] rw [ne_eq, mul_eq_zero, not_or, eval_vanishPoly_eq_zero_iff] exact ⟨fun h => h.2, fun h => ⟨hchar, h⟩⟩ /-! ### Exact Individual-Degree Schwartz–Zippel Lemma & Witness -/ /-- **Theorem 1.7a (Exact Individual-Degree Schwartz–Zippel Lemma)**: For every nonzero `g ∈ F[X₀, …, X_{v-1}]` with `degreeOf i ≤ d i`, the fraction of zeros in `∏ S_i` is at most `1 - ∏ i, (1 - min (d i) |S i| / |S i|) ≤ ∑ i, d i / |S i|`. -/ theorem schwartz_zippel_individual_degree {v : ℕ} (g : MvPolynomial (Fin v) F) (hg : g ≠ 0) (S : Fin v → Finset F) (hS : ∀ i, (S i).Nonempty) (d : Fin v → ℕ) (hdeg : ∀ i, g.degreeOf i ≤ d i) : (((Fintype.piFinset S).filter (fun r => MvPolynomial.eval r g = 0)).card : ℝ) / ((Fintype.piFinset S).card : ℝ) ≤ prodComplement (fun i => ((min (d i) (S i).card : ℕ) : ℝ) / ((S i).card : ℝ)) := by induction v with | zero => unfold prodComplement have hconst : MvPolynomial.eval Fin.elim0 g ≠ 0 := by intro h0 apply hg have heq := MvPolynomial.eq_C_of_isEmpty g rw [heq] at h0 ⊢ simp at h0 ⊢ exact h0 have hfilt : (Fintype.piFinset S).filter (fun r => MvPolynomial.eval r g = 0) = ∅ := by ext r have hr : r = Fin.elim0 := Subsingleton.elim r Fin.elim0 simp [hr, hconst] rw [hfilt]; simp | succ v ih => have hsupp : g.support.Nonempty := MvPolynomial.support_nonempty.mpr hg rcases hsupp with ⟨m, hm⟩ let m_tail : Fin v →₀ ℕ := Finsupp.equivFunOnFinite.symm (fun i : Fin v => m i.succ) let q : Polynomial F := ∑ k ∈ Finset.range (d 0 + 1), Polynomial.C (MvPolynomial.coeff (Finsupp.equivFunOnFinite.symm (Fin.cons k (fun i => m i.succ))) g) * Polynomial.X ^ k have hq_deg : q.natDegree ≤ d 0 := by refine Polynomial.natDegree_sum_le_of_forall_le _ _ (fun k hk => ?_) refine (Polynomial.natDegree_C_mul_le _ _).trans ?_ rw [Polynomial.natDegree_X_pow] exact Nat.lt_succ_iff.mp (Finset.mem_range.mp hk) have hq_coeff : ∀ k ≤ d 0, q.coeff k = MvPolynomial.coeff (Finsupp.equivFunOnFinite.symm (Fin.cons k (fun i => m i.succ))) g := by intro k hk simp only [q, Polynomial.finsetSum_coeff, Polynomial.coeff_C_mul, Polynomial.coeff_X_pow] rw [Finset.sum_eq_single k] · simp · intro j _ hjk; simp [Ne.symm hjk] · intro hk'; exact absurd (Finset.mem_range.mpr (Nat.lt_succ_of_le hk)) hk' have hq_ne : q ≠ 0 := by intro h0 have hm0_le : m 0 ≤ d 0 := (coeff_le_degreeOf 0 hm).trans (hdeg 0) have hc := hq_coeff (m 0) hm0_le rw [h0, Polynomial.coeff_zero] at hc have hmeq : Finsupp.equivFunOnFinite.symm (Fin.cons (m 0) (fun i => m i.succ)) = m := by ext i; cases i using Fin.cases <;> simp rw [hmeq] at hc exact (MvPolynomial.mem_support_iff.mp hm) hc.symm have hspec_imp_q : ∀ r₀ : F, specialize₀ g r₀ = 0 → q.eval r₀ = 0 := by intro r₀ hzero have hcoeff0 : MvPolynomial.coeff m_tail (specialize₀ g r₀) = 0 := by rw [hzero, MvPolynomial.coeff_zero] have hcomp : MvPolynomial.coeff m_tail (specialize₀ g r₀) = q.eval r₀ := by unfold specialize₀ rw [MvPolynomial.eval₂_eq', MvPolynomial.coeff_sum] have hterm_eq : ∀ s ∈ g.support, MvPolynomial.coeff m_tail (MvPolynomial.C (MvPolynomial.coeff s g) * ∏ j : Fin (v + 1), (Fin.cases (MvPolynomial.C r₀) MvPolynomial.X j) ^ s j) = if (∀ i : Fin v, s i.succ = m i.succ) then MvPolynomial.coeff s g * r₀ ^ s 0 else 0 := by intro s _ have hmon : MvPolynomial.C (MvPolynomial.coeff s g) * ∏ j : Fin (v + 1), (Fin.cases (MvPolynomial.C r₀) MvPolynomial.X j) ^ s j = MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (fun k : Fin v => s k.succ)) (MvPolynomial.coeff s g * r₀ ^ s 0) := by rw [Fin.prod_univ_succ] simp only [Fin.cases_zero, Fin.cases_succ, ← map_pow, ← mul_assoc, ← map_mul] rw [MvPolynomial.monomial_eq, Finsupp.prod_fintype _ _ (fun _ => pow_zero _)] congr 1 rw [hmon, MvPolynomial.coeff_monomial] have hiff : Finsupp.equivFunOnFinite.symm (fun k : Fin v => s k.succ) = m_tail ↔ ∀ i : Fin v, s i.succ = m i.succ := by simp [m_tail, funext_iff] by_cases h : ∀ i : Fin v, s i.succ = m i.succ · rw [if_pos (hiff.mpr h), if_pos h] · rw [if_neg (mt hiff.mp h), if_neg h] rw [Finset.sum_congr rfl hterm_eq, ← Finset.sum_filter] simp only [q, Polynomial.eval_finsetSum, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_pow, Polynomial.eval_X] let f_s := fun s : Fin (v + 1) →₀ ℕ => MvPolynomial.coeff s g * r₀ ^ s 0 let f_k := fun k : ℕ => MvPolynomial.coeff (Finsupp.equivFunOnFinite.symm (Fin.cons k (fun i => m i.succ))) g * r₀ ^ k let S_sub := g.support.filter (fun s => ∀ i : Fin v, s i.succ = m i.succ) have himg_val : ∀ s ∈ S_sub, f_k (s 0) = f_s s := by intro s hs have h2 := (Finset.mem_filter.mp hs).2 simp only [f_k, f_s] congr 2 ext i cases i using Fin.cases with | zero => simp | succ j => simp [h2 j] have hsum_img : ∑ s ∈ S_sub, f_s s = ∑ k ∈ S_sub.image (fun s => s 0), f_k k := by rw [Finset.sum_image (fun s₁ hs₁ s₂ hs₂ h0 => by have h1 := (Finset.mem_filter.mp hs₁).2 have h2 := (Finset.mem_filter.mp hs₂).2 ext i; cases i using Fin.cases with | zero => exact h0 | succ j => rw [h1 j, h2 j])] exact (Finset.sum_congr rfl (fun s hs => himg_val s hs)).symm change ∑ s ∈ S_sub, f_s s = ∑ k ∈ Finset.range (d 0 + 1), f_k k rw [hsum_img] refine Finset.sum_subset ?_ ?_ · intro k hk rcases Finset.mem_image.mp hk with ⟨s, hs, rfl⟩ exact Finset.mem_range.mpr (Nat.lt_succ_of_le ((coeff_le_degreeOf 0 (Finset.mem_filter.mp hs).1).trans (hdeg 0))) · intro k _ hk_not simp only [f_k] have hcoeff0' : MvPolynomial.coeff (Finsupp.equivFunOnFinite.symm (Fin.cons k (fun i => m i.succ))) g = 0 := by by_contra hne apply hk_not rw [Finset.mem_image] refine ⟨Finsupp.equivFunOnFinite.symm (Fin.cons k (fun i => m i.succ)), ?_, by simp⟩ rw [Finset.mem_filter] exact ⟨MvPolynomial.mem_support_iff.mpr hne, fun i => by simp⟩ rw [hcoeff0', zero_mul] rw [← hcomp]; exact hcoeff0 set Z := (S 0).filter (fun r₀ => q.eval r₀ = 0) have hZcard : Z.card ≤ min (d 0) (S 0).card := by have h := card_filter_poly_eq_le (p := q) (q := 0) (S := S 0) (d := d 0) hq_deg (by simp) hq_ne simpa using h set T := Fintype.piFinset (fun i : Fin v => S i.succ) have hS0pos : (0 : ℝ) < (S 0).card := by exact_mod_cast (hS 0).card_pos have hTpos : (0 : ℝ) < T.card := by have hne : T.Nonempty := ⟨fun i => (hS i.succ).choose, Fintype.mem_piFinset.mpr (fun i => (hS i.succ).choose_spec)⟩ exact_mod_cast hne.card_pos set E_tail := prodComplement (fun i : Fin v => ((min (d i.succ) (S i.succ).card : ℕ) : ℝ) / ((S i.succ).card : ℝ)) have hE_le1 : E_tail ≤ 1 := prodComplement_le_one _ (fun i => by rw [div_le_one (by exact_mod_cast (hS i.succ).card_pos)] exact_mod_cast min_le_right _ _) have hcount : (((Fintype.piFinset S).filter (fun r => MvPolynomial.eval r g = 0)).card : ℝ) ≤ (Z.card : ℝ) * (T.card : ℝ) + (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by classical rw [card_filter_piFinset_succ] push_cast have hsplit := (Finset.sum_filter_add_sum_filter_not (S 0) (fun r₀ => q.eval r₀ = 0) (fun r₀ => ((T.filter (fun tail => MvPolynomial.eval (Fin.cons r₀ tail) g = 0)).card : ℝ))).symm rw [hsplit] have hpart1 : ∑ r₀ ∈ Z, ((T.filter (fun tail => MvPolynomial.eval (Fin.cons r₀ tail) g = 0)).card : ℝ) ≤ (Z.card : ℝ) * (T.card : ℝ) := by calc ∑ r₀ ∈ Z, ((T.filter _).card : ℝ) ≤ ∑ _r₀ ∈ Z, (T.card : ℝ) := Finset.sum_le_sum (fun r₀ _ => by exact_mod_cast Finset.card_filter_le _ _) _ = (Z.card : ℝ) * (T.card : ℝ) := by simp have hpart2 : ∑ r₀ ∈ (S 0).filter (fun r₀ => ¬ q.eval r₀ = 0), ((T.filter (fun tail => MvPolynomial.eval (Fin.cons r₀ tail) g = 0)).card : ℝ) ≤ (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by have hcard_not : ((S 0).filter (fun r₀ => ¬ q.eval r₀ = 0)).card = (S 0).card - Z.card := by have hadd : Z.card + ((S 0).filter (fun r₀ => ¬ q.eval r₀ = 0)).card = (S 0).card := Finset.card_filter_add_card_filter_not (s := S 0) (p := fun r₀ => q.eval r₀ = 0) omega calc ∑ r₀ ∈ (S 0).filter (fun r₀ => ¬ q.eval r₀ = 0), ((T.filter (fun tail => MvPolynomial.eval (Fin.cons r₀ tail) g = 0)).card : ℝ) ≤ ∑ _r₀ ∈ (S 0).filter (fun r₀ => ¬ q.eval r₀ = 0), (E_tail * (T.card : ℝ)) := by refine Finset.sum_le_sum (fun r₀ hr₀ => ?_) have hspec_ne : specialize₀ g r₀ ≠ 0 := mt (hspec_imp_q r₀) (Finset.mem_filter.mp hr₀).2 have hih := ih (specialize₀ g r₀) hspec_ne (fun i => S i.succ) (fun i => hS i.succ) (fun i => d i.succ) (fun i => (degreeOf_specialize₀_le g r₀ i).trans (hdeg i.succ)) have hsub_eq : T.filter (fun tail => MvPolynomial.eval (Fin.cons r₀ tail) g = 0) = T.filter (fun tail => MvPolynomial.eval tail (specialize₀ g r₀) = 0) := by ext tail; simp [eval_specialize₀] rw [hsub_eq] exact (div_le_iff₀ hTpos).mp hih _ = (((S 0).card - Z.card : ℕ) : ℝ) * (E_tail * (T.card : ℝ)) := by simp [hcard_not] linarith rw [card_piFinset_succ, Nat.cast_mul] have hZleS : Z.card ≤ (S 0).card := Finset.card_filter_le _ _ rw [Nat.cast_sub hZleS] at hcount rw [div_le_iff₀ (mul_pos hS0pos hTpos)] rw [prodComplement_succ] have hZle : (Z.card : ℝ) ≤ ((min (d 0) (S 0).card : ℕ) : ℝ) := by exact_mod_cast hZcard have hstep : (Z.card : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - (Z.card : ℝ)) * (E_tail * (T.card : ℝ)) ≤ ((min (d 0) (S 0).card : ℕ) : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - ((min (d 0) (S 0).card : ℕ) : ℝ)) * (E_tail * (T.card : ℝ)) := by have hdiff : 0 ≤ (((min (d 0) (S 0).card : ℕ) : ℝ) - (Z.card : ℝ)) * (1 - E_tail) * (T.card : ℝ) := mul_nonneg (mul_nonneg (by linarith) (by linarith)) (le_of_lt hTpos) linarith have halg : (((min (d 0) (S 0).card : ℕ) : ℝ) / ((S 0).card : ℝ) + (1 - ((min (d 0) (S 0).card : ℕ) : ℝ) / ((S 0).card : ℝ)) * E_tail) * (((S 0).card : ℝ) * (T.card : ℝ)) = ((min (d 0) (S 0).card : ℕ) : ℝ) * (T.card : ℝ) + (((S 0).card : ℝ) - ((min (d 0) (S 0).card : ℕ) : ℝ)) * (E_tail * (T.card : ℝ)) := by field_simp [ne_of_gt hS0pos] linarith /-- **Theorem 1.7b (Exact Individual-Degree Schwartz–Zippel Witness)**: The product polynomial `g(X) = ∏ i, ∏ s ∈ R i, (X i - C s)` (with `R i ⊆ S i`, `|R i| = d i`) has `degreeOf i ≤ d i` and vanishes on EXACTLY a `1 - ∏ i, (1 - d i / |S i|)` fraction of `∏ S_i`. -/ theorem schwartz_zippel_individual_degree_sharp {v : ℕ} (S R : Fin v → Finset F) (hS : ∀ i, (S i).Nonempty) (hRS : ∀ i, R i ⊆ S i) : let g : MvPolynomial (Fin v) F := ∏ i : Fin v, ∏ s ∈ R i, (MvPolynomial.X i - MvPolynomial.C s) (∀ i, g.degreeOf i ≤ (R i).card) ∧ (((Fintype.piFinset S).filter (fun r => MvPolynomial.eval r g = 0)).card : ℝ) / ((Fintype.piFinset S).card : ℝ) = prodComplement (fun i => ((R i).card : ℝ) / ((S i).card : ℝ)) := by classical intro g constructor · intro i have hdeg_prod : g.degreeOf i ≤ ∑ j : Fin v, (∏ s ∈ R j, (MvPolynomial.X j - MvPolynomial.C s : MvPolynomial (Fin v) F)).degreeOf i := MvPolynomial.degreeOf_prod_le _ _ _ refine hdeg_prod.trans ?_ have hterm : ∀ j : Fin v, (∏ s ∈ R j, (MvPolynomial.X j - MvPolynomial.C s : MvPolynomial (Fin v) F)).degreeOf i ≤ if j = i then (R i).card else 0 := by intro j refine (MvPolynomial.degreeOf_prod_le _ _ _).trans ?_ by_cases hji : j = i · subst hji rw [if_pos rfl] calc ∑ s ∈ R j, (MvPolynomial.X j - MvPolynomial.C s : MvPolynomial (Fin v) F).degreeOf j ≤ ∑ _s ∈ R j, 1 := by refine Finset.sum_le_sum (fun s _ => ?_) refine (MvPolynomial.degreeOf_sub_le _ _ _).trans (max_le ?_ ?_) · rw [MvPolynomial.degreeOf_X]; simp · simp [MvPolynomial.degreeOf_C] _ = (R j).card := by simp · rw [if_neg hji] have hzero : ∀ s ∈ R j, (MvPolynomial.X j - MvPolynomial.C s : MvPolynomial (Fin v) F).degreeOf i = 0 := by intro s _ have hle : (MvPolynomial.X j - MvPolynomial.C s : MvPolynomial (Fin v) F).degreeOf i ≤ 0 := by refine (MvPolynomial.degreeOf_sub_le _ _ _).trans (max_le ?_ ?_) · rw [MvPolynomial.degreeOf_X, if_neg (Ne.symm hji)] · simp [MvPolynomial.degreeOf_C] omega simp [Finset.sum_eq_zero hzero] refine (Finset.sum_le_sum (fun j _ => hterm j)).trans ?_ simp · have heval0 : ∀ r : Fin v → F, MvPolynomial.eval r g = 0 ↔ ∃ i : Fin v, r i ∈ R i := by intro r simp only [g, map_prod, map_sub, MvPolynomial.eval_X, MvPolynomial.eval_C, Finset.prod_eq_zero_iff, Finset.mem_univ, true_and, sub_eq_zero] exact ⟨fun ⟨i, s, hs, heq⟩ => ⟨i, heq ▸ hs⟩, fun ⟨i, hi⟩ => ⟨i, r i, hi, rfl⟩⟩ have hfilt : (Fintype.piFinset S).filter (fun r => MvPolynomial.eval r g = 0) = (Fintype.piFinset S).filter (fun r => ∃ i : Fin v, r i ∈ R i) := by ext r; simp [heval0] rw [hfilt] exact piFinset_exists_mem_prob S R hS hRS /-- **Theorem 1.8 (Exact Round-by-Round Soundness Product Composition)**: For any `v`-round interactive protocol over finite challenge sets `S i` with a bad-state predicate `Bad` where initially `Bad 0 Fin.elim0` is false and from any non-bad prefix at most an `ε i ∈ [0, 1]` fraction of next challenges transition to a bad state, the final probability of reaching a bad state is at most `1 - ∏ i, (1 - ε i) ≤ ∑ i, ε i`. -/ theorem round_by_round_product_composition {α : Type*} [DecidableEq α] : ∀ {v : ℕ} (S : Fin v → Finset α) (_hS : ∀ i, (S i).Nonempty) (ε : Fin v → ℝ) (_hε0 : ∀ i, 0 ≤ ε i) (_hε1 : ∀ i, ε i ≤ 1) (Bad : (k : ℕ) → (Fin k → α) → Prop) [∀ k, DecidablePred (Bad k)] (_hinit : ¬ Bad 0 Fin.elim0) (_hstep : ∀ (k : Fin v) (pref : Fin k.val → α), ¬ Bad k.val pref → (((S k).filter (fun r => Bad (k.val + 1) (Fin.snoc pref r))).card : ℝ) / ((S k).card : ℝ) ≤ ε k), (((Fintype.piFinset S).filter (fun r => Bad v r)).card : ℝ) / ((Fintype.piFinset S).card : ℝ) ≤ prodComplement ε := by intro v induction v with | zero => intro S _ ε _ _ Bad _ hinit _ unfold prodComplement have hfilt : (Fintype.piFinset S).filter (fun r => Bad 0 r) = ∅ := by ext r have hr : r = Fin.elim0 := Subsingleton.elim r Fin.elim0 simp [hr, hinit] rw [hfilt]; simp | succ v ih => intro S hS ε hε0 hε1 Bad _ hinit hstep classical set S_init : Fin v → Finset α := fun i => S i.castSucc have hS_init : ∀ i, (S_init i).Nonempty := fun i => hS i.castSucc have hih := ih S_init hS_init (fun i => ε i.castSucc) (fun i => hε0 i.castSucc) (fun i => hε1 i.castSucc) (fun k pref => Bad k pref) hinit (fun k pref hnb => hstep k.castSucc pref hnb) have hsum_snoc : ∀ (f : (Fin (v + 1) → α) → ℕ), ∑ r ∈ Fintype.piFinset S, f r = ∑ pref ∈ Fintype.piFinset S_init, ∑ last ∈ S (Fin.last v), f (Fin.snoc pref last) := by intro f rw [← Finset.sum_product'] refine Finset.sum_bij (fun r _ => (Fin.init r, r (Fin.last v))) ?_ ?_ ?_ ?_ · intro r hr rw [Finset.mem_product, Fintype.mem_piFinset] rw [Fintype.mem_piFinset] at hr exact ⟨fun i => hr i.castSucc, hr (Fin.last v)⟩ · intro r₁ _ r₂ _ heq simp only [Prod.mk.injEq] at heq ext i cases i using Fin.lastCases with | last => exact heq.2 | cast j => exact congrFun heq.1 j · intro ⟨pref, last⟩ h rw [Finset.mem_product, Fintype.mem_piFinset] at h refine ⟨Fin.snoc pref last, ?_, ?_⟩ · rw [Fintype.mem_piFinset] intro i cases i using Fin.lastCases with | last => simpa using h.2 | cast j => simpa using h.1 j · simp [Fin.init_snoc, Fin.snoc_last] · intro r _ simp [Fin.snoc_init_self] have hcard_S : (Fintype.piFinset S).card = (Fintype.piFinset S_init).card * (S (Fin.last v)).card := by have h := hsum_snoc (fun _ => 1) simp only [Finset.sum_const, smul_eq_mul, mul_one] at h exact h set P_fin := Fintype.piFinset S_init set Sl := S (Fin.last v) set ε_last := ε (Fin.last v) set E_init := prodComplement (fun i : Fin v => ε i.castSucc) have hPpos : (0 : ℝ) < P_fin.card := by have hne : P_fin.Nonempty := ⟨fun i => (hS_init i).choose, Fintype.mem_piFinset.mpr (fun i => (hS_init i).choose_spec)⟩ exact_mod_cast hne.card_pos have hSlpos : (0 : ℝ) < Sl.card := by exact_mod_cast (hS (Fin.last v)).card_pos set B_init := P_fin.filter (fun pref => Bad v pref) have hB_le : (B_init.card : ℝ) ≤ E_init * (P_fin.card : ℝ) := (div_le_iff₀ hPpos).mp hih have hcount : (((Fintype.piFinset S).filter (fun r => Bad (v + 1) r)).card : ℝ) ≤ (B_init.card : ℝ) * (Sl.card : ℝ) + (((P_fin.card : ℝ) - (B_init.card : ℝ)) * (ε_last * (Sl.card : ℝ))) := by rw [Finset.card_filter, hsum_snoc] push_cast have hsplit := (Finset.sum_filter_add_sum_filter_not P_fin (fun pref => Bad v pref) (fun pref => ∑ last ∈ Sl, if Bad (v + 1) (Fin.snoc pref last) then (1 : ℝ) else 0)).symm rw [hsplit] have h1 : ∑ pref ∈ B_init, ∑ last ∈ Sl, (if Bad (v + 1) (Fin.snoc pref last) then (1 : ℝ) else 0) ≤ (B_init.card : ℝ) * (Sl.card : ℝ) := by calc ∑ pref ∈ B_init, ∑ last ∈ Sl, (if Bad (v + 1) (Fin.snoc pref last) then (1 : ℝ) else 0) ≤ ∑ _pref ∈ B_init, ∑ _last ∈ Sl, (1 : ℝ) := Finset.sum_le_sum (fun _ _ => Finset.sum_le_sum (fun _ _ => by split_ifs <;> norm_num)) _ = (B_init.card : ℝ) * (Sl.card : ℝ) := by simp have hcard_not : (P_fin.filter (fun pref => ¬ Bad v pref)).card = P_fin.card - B_init.card := by have hadd : B_init.card + (P_fin.filter (fun pref => ¬ Bad v pref)).card = P_fin.card := Finset.card_filter_add_card_filter_not (s := P_fin) (p := fun pref => Bad v pref) omega have h2 : ∑ pref ∈ P_fin.filter (fun pref => ¬ Bad v pref), ∑ last ∈ Sl, (if Bad (v + 1) (Fin.snoc pref last) then (1 : ℝ) else 0) ≤ ((P_fin.card : ℝ) - (B_init.card : ℝ)) * (ε_last * (Sl.card : ℝ)) := by calc ∑ pref ∈ P_fin.filter (fun pref => ¬ Bad v pref), ∑ last ∈ Sl, (if Bad (v + 1) (Fin.snoc pref last) then (1 : ℝ) else 0) ≤ ∑ _pref ∈ P_fin.filter (fun pref => ¬ Bad v pref), (ε_last * (Sl.card : ℝ)) := by refine Finset.sum_le_sum (fun pref hpref => ?_) have hnb : ¬ Bad v pref := (Finset.mem_filter.mp hpref).2 have hs := hstep (Fin.last v) pref hnb have hle := (div_le_iff₀ hSlpos).mp hs have hcast : ((Sl.filter (fun r => Bad (v + 1) (Fin.snoc pref r))).card : ℝ) = ∑ last ∈ Sl, if Bad (v + 1) (Fin.snoc pref last) then (1 : ℝ) else 0 := by rw [Finset.card_filter]; push_cast; rfl rwa [← hcast] _ = (((P_fin.card - B_init.card : ℕ) : ℝ)) * (ε_last * (Sl.card : ℝ)) := by simp [hcard_not] _ = ((P_fin.card : ℝ) - (B_init.card : ℝ)) * (ε_last * (Sl.card : ℝ)) := by rw [Nat.cast_sub (Finset.card_filter_le _ _)] linarith rw [hcard_S] push_cast rw [div_le_iff₀ (mul_pos hPpos hSlpos)] have hprod_last : prodComplement ε = E_init + (1 - E_init) * ε_last := by dsimp only [E_init, ε_last] unfold prodComplement rw [Fin.prod_univ_castSucc] ring rw [hprod_last] have hε_le1 : ε_last ≤ 1 := hε1 (Fin.last v) have hdiff : 0 ≤ (E_init * (P_fin.card : ℝ) - (B_init.card : ℝ)) * (1 - ε_last) * (Sl.card : ℝ) := mul_nonneg (mul_nonneg (by linarith) (by linarith)) (le_of_lt hSlpos) linarith end Pillar1 /-! ============================================================================ PILLAR 2: BLR LINEARITY TESTING, BCHKS PHASE TRANSITIONS, SHARP FINITE-n GOWERS U₂/U₃ & REED–MULLER DEGREE-2 TESTING ============================================================================ -/ section Pillar2 /-- `n`-dimensional binary vector space `𝔽₂ⁿ`. -/ abbrev Vec (n : ℕ) := Fin n → ZMod 2 /-- Boolean sign convention: `false ↦ +1`, `true ↦ -1`. -/ def bSign (b : Bool) : ℝ := if b then -1 else 1 lemma bSign_sq (b : Bool) : (bSign b) ^ 2 = 1 := by cases b <;> norm_num [bSign] lemma bSign_mul_self (b : Bool) : bSign b * bSign b = 1 := by cases b <;> norm_num [bSign] lemma bSign_xor (a b : Bool) : bSign (xor a b) = bSign a * bSign b := by cases a <;> cases b <;> norm_num [bSign] lemma bSign_not (b : Bool) : bSign (!b) = -bSign b := by cases b <;> norm_num [bSign] lemma bSign_abs (b : Bool) : |bSign b| = 1 := by cases b <;> norm_num [bSign] lemma bSign_ne_indicator (a b : Bool) : (if a ≠ b then (1 : ℝ) else 0) = (1 - bSign a * bSign b) / 2 := by cases a <;> cases b <;> norm_num [bSign] lemma card_vec (n : ℕ) : Fintype.card (Vec n) = 2 ^ n := by simp [Vec, ZMod.card] lemma two_pow_pos (n : ℕ) : (0 : ℝ) < (2 : ℝ) ^ n := by positivity lemma zmod2_eq_zero_or_one (z : ZMod 2) : z = 0 ∨ z = 1 := by fin_cases z · exact Or.inl rfl · exact Or.inr rfl lemma zmod2_eq_one_of_ne_zero {z : ZMod 2} (hz : z ≠ 0) : z = 1 := (zmod2_eq_zero_or_one z).resolve_left hz lemma zmod2_add_self (z : ZMod 2) : z + z = 0 := by rcases zmod2_eq_zero_or_one z with rfl | rfl <;> decide /-- Inner product `⟨a, x⟩` over `𝔽₂ⁿ`. -/ def innerProd {n : ℕ} (a x : Vec n) : ZMod 2 := ∑ i : Fin n, a i * x i lemma innerProd_add_right {n : ℕ} (a x y : Vec n) : innerProd a (x + y) = innerProd a x + innerProd a y := by simp [innerProd, mul_add, Finset.sum_add_distrib] lemma innerProd_add_left {n : ℕ} (a b x : Vec n) : innerProd (a + b) x = innerProd a x + innerProd b x := by simp [innerProd, add_mul, Finset.sum_add_distrib] lemma innerProd_zero_left {n : ℕ} (x : Vec n) : innerProd (0 : Vec n) x = 0 := by simp [innerProd] lemma innerProd_zero_right {n : ℕ} (a : Vec n) : innerProd a (0 : Vec n) = 0 := by simp [innerProd] lemma innerProd_comm {n : ℕ} (a x : Vec n) : innerProd a x = innerProd x a := by simp [innerProd, mul_comm] /-- Linear Boolean function `x ↦ (⟨a, x⟩ ≠ 0)`. -/ def chiBool {n : ℕ} (a x : Vec n) : Bool := decide (innerProd a x ≠ 0) /-- Walsh character `χ_a(x) = (-1)^{⟨a, x⟩}`. -/ def chi {n : ℕ} (a x : Vec n) : ℝ := bSign (chiBool a x) lemma zmod2_add_sign (u v : ZMod 2) : bSign (decide (u + v ≠ 0)) = bSign (decide (u ≠ 0)) * bSign (decide (v ≠ 0)) := by rcases zmod2_eq_zero_or_one u with rfl | rfl <;> rcases zmod2_eq_zero_or_one v with rfl | rfl <;> simp [bSign, zmod2_add_self] lemma chi_add_right {n : ℕ} (a x y : Vec n) : chi a (x + y) = chi a x * chi a y := by simp only [chi, chiBool, innerProd_add_right, zmod2_add_sign] lemma chi_add_left {n : ℕ} (a b x : Vec n) : chi (a + b) x = chi a x * chi b x := by simp only [chi, chiBool, innerProd_add_left, zmod2_add_sign] lemma chi_zero_left {n : ℕ} (x : Vec n) : chi (0 : Vec n) x = 1 := by simp [chi, chiBool, innerProd_zero_left, bSign] lemma chi_zero_right {n : ℕ} (a : Vec n) : chi a (0 : Vec n) = 1 := by simp [chi, chiBool, innerProd_zero_right, bSign] lemma chi_comm {n : ℕ} (a x : Vec n) : chi a x = chi x a := by simp [chi, chiBool, innerProd_comm] lemma chi_sq {n : ℕ} (a x : Vec n) : (chi a x) ^ 2 = 1 := bSign_sq _ lemma chi_mul_self {n : ℕ} (a x : Vec n) : chi a x * chi a x = 1 := bSign_mul_self _ lemma chiBool_add_right {n : ℕ} (a x y : Vec n) : chiBool a (x + y) = xor (chiBool a x) (chiBool a y) := by have h : bSign (chiBool a (x + y)) = bSign (xor (chiBool a x) (chiBool a y)) := by rw [bSign_xor]; exact chi_add_right a x y cases h1 : chiBool a (x + y) <;> cases h2 : xor (chiBool a x) (chiBool a y) · rfl · rw [h1, h2] at h; norm_num [bSign] at h · rw [h1, h2] at h; norm_num [bSign] at h · rfl lemma vec_add_self {n : ℕ} (x : Vec n) : x + x = 0 := by ext i; exact zmod2_add_self (x i) /-- Character orthogonality: `∑_{x ∈ 𝔽₂ⁿ} χ_a(x) = 2ⁿ` if `a = 0`, else `0`. -/ lemma sum_chi_eq {n : ℕ} (a : Vec n) : ∑ x : Vec n, chi a x = if a = 0 then (2 : ℝ) ^ n else 0 := by by_cases ha : a = 0 · subst ha simp only [↓reduceIte, chi_zero_left, Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] · rw [if_neg ha] have hex : ∃ i : Fin n, a i ≠ 0 := by by_contra hall; push Not at hall; exact ha (funext hall) rcases hex with ⟨i, hi⟩ have hai : a i = 1 := zmod2_eq_one_of_ne_zero hi let e : Vec n := Pi.single i 1 have hchie : chi a e = -1 := by have hip : innerProd a e = 1 := by unfold innerProd rw [Finset.sum_eq_single i] · simp [e, hai] · intro j _ hji; simp [e, Pi.single_eq_of_ne hji] · intro hi'; exact absurd (Finset.mem_univ i) hi' simp [chi, chiBool, hip, bSign] have hshift : ∑ x : Vec n, chi a (x + e) = ∑ x : Vec n, chi a x := Fintype.sum_equiv (Equiv.addRight e) _ _ (fun _ => rfl) have hneg : ∑ x : Vec n, chi a (x + e) = -(∑ x : Vec n, chi a x) := by calc ∑ x : Vec n, chi a (x + e) = ∑ x : Vec n, (chi a x * (-1)) := Finset.sum_congr rfl (fun x _ => by rw [chi_add_right, hchie]) _ = -(∑ x : Vec n, chi a x) := by simp [Finset.sum_neg_distrib] linarith /-- Walsh–Fourier coefficient `f̂(a) = 2⁻ⁿ ∑_{x ∈ 𝔽₂ⁿ} (-1)^{f(x)} χ_a(x)`. -/ noncomputable def walsh {n : ℕ} (f : Vec n → Bool) (a : Vec n) : ℝ := (∑ x : Vec n, bSign (f x) * chi a x) / (2 : ℝ) ^ n /-- Integer-scaled Walsh sum `W_f(a) = 2ⁿ f̂(a) ∈ ℤ`. -/ def walshInt {n : ℕ} (f : Vec n → Bool) (a : Vec n) : ℤ := ∑ x : Vec n, (if f x then (-1 : ℤ) else 1) * (if chiBool a x then (-1 : ℤ) else 1) lemma walsh_eq_walshInt {n : ℕ} (f : Vec n → Bool) (a : Vec n) : walsh f a = (walshInt f a : ℝ) / (2 : ℝ) ^ n := by unfold walsh walshInt congr 1 push_cast refine Finset.sum_congr rfl (fun x _ => ?_) cases f x <;> cases hc : chiBool a x <;> simp [chi, bSign, hc] /-- Fourier inversion: `bSign (f x) = ∑ a, f̂(a) χ_a(x)`. -/ theorem walsh_inversion {n : ℕ} (f : Vec n → Bool) (x : Vec n) : ∑ a : Vec n, walsh f a * chi a x = bSign (f x) := by unfold walsh calc ∑ a : Vec n, ((∑ y : Vec n, bSign (f y) * chi a y) / (2 : ℝ) ^ n) * chi a x = ∑ a : Vec n, ((∑ y : Vec n, bSign (f y) * chi a y) * chi a x) / (2 : ℝ) ^ n := Finset.sum_congr rfl (fun a _ => by ring) _ = (∑ y : Vec n, bSign (f y) * ∑ a : Vec n, chi (y + x) a) / (2 : ℝ) ^ n := by rw [← Finset.sum_div] congr 1 simp_rw [Finset.sum_mul, Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun y _ => Finset.sum_congr rfl (fun a _ => ?_)) rw [chi_add_left, chi_comm y a, chi_comm x a]; ring _ = (∑ y : Vec n, bSign (f y) * (if y + x = 0 then (2 : ℝ) ^ n else 0)) / (2 : ℝ) ^ n := by congr 1; refine Finset.sum_congr rfl (fun y _ => by rw [sum_chi_eq]) _ = (bSign (f x) * (2 : ℝ) ^ n) / (2 : ℝ) ^ n := by congr 1 rw [Finset.sum_eq_single x] · simp [vec_add_self] · intro y _ hyx have hne : y + x ≠ 0 := by intro h apply hyx calc y = y + (x + x) := by rw [vec_add_self, add_zero] _ = (y + x) + x := by rw [add_assoc] _ = x := by rw [h, zero_add] simp [hne] · intro hx; exact absurd (Finset.mem_univ x) hx _ = bSign (f x) := mul_div_cancel_right₀ _ (ne_of_gt (two_pow_pos n)) /-- Evaluation at zero: `∑ a, f̂(a) = (-1)^{f(0)}`. -/ lemma sum_walsh_eq_eval_zero {n : ℕ} (f : Vec n → Bool) : ∑ a : Vec n, walsh f a = bSign (f 0) := by have h := walsh_inversion f 0 simpa [chi_zero_right] using h /-- Parseval's identity: `∑ a, f̂(a)² = 1`. -/ theorem walsh_parseval {n : ℕ} (f : Vec n → Bool) : ∑ a : Vec n, (walsh f a) ^ 2 = 1 := by have h1 : ∑ a : Vec n, (walsh f a) ^ 2 = (∑ x : Vec n, bSign (f x) * (∑ a : Vec n, walsh f a * chi a x)) / (2 : ℝ) ^ n := by calc ∑ a : Vec n, (walsh f a) ^ 2 = ∑ a : Vec n, (walsh f a * ∑ x : Vec n, bSign (f x) * chi a x) / (2 : ℝ) ^ n := Finset.sum_congr rfl (fun a _ => by rw [sq]; unfold walsh; ring) _ = (∑ a : Vec n, walsh f a * ∑ x : Vec n, bSign (f x) * chi a x) / (2 : ℝ) ^ n := (Finset.sum_div _ _ _).symm _ = (∑ x : Vec n, bSign (f x) * (∑ a : Vec n, walsh f a * chi a x)) / (2 : ℝ) ^ n := by congr 1 simp_rw [Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun x _ => Finset.sum_congr rfl (fun a _ => by ring)) rw [h1] have h2 : ∑ x : Vec n, bSign (f x) * (∑ a : Vec n, walsh f a * chi a x) = (2 : ℝ) ^ n := by calc ∑ x : Vec n, bSign (f x) * (∑ a : Vec n, walsh f a * chi a x) = ∑ _x : Vec n, (1 : ℝ) := Finset.sum_congr rfl (fun x _ => by rw [walsh_inversion, bSign_mul_self]) _ = (2 : ℝ) ^ n := by simp rw [h2, div_self (ne_of_gt (two_pow_pos n))] /-- **Anti-Linear Rigidity**: For any `f : 𝔽₂ⁿ → Bool` (`n ≥ 1`), either `∃ a, 0 < f̂(a)` or `f` is anti-linear (`f(x) = ¬ χ_a(x)` everywhere). In particular `max_a f̂(a) ≥ 0` always. -/ theorem anti_linear_rigidity {n : ℕ} (f : Vec n → Bool) (hall : ∀ a : Vec n, walsh f a ≤ 0) : ∃ a₀ : Vec n, ∀ x : Vec n, bSign (f x) = -chi a₀ x := by have hu : ∀ a, 0 ≤ -walsh f a := fun a => neg_nonneg.mpr (hall a) have hsum_le1 : ∑ a : Vec n, (-walsh f a) ≤ 1 := by rw [Finset.sum_neg_distrib, sum_walsh_eq_eval_zero] cases f 0 <;> norm_num [bSign] have hle1 : ∀ a, -walsh f a ≤ 1 := fun a => (Finset.single_le_sum (fun b _ => hu b) (Finset.mem_univ a)).trans hsum_le1 have hsq_le : ∀ a, (-walsh f a) ^ 2 ≤ -walsh f a := fun a => by nlinarith [hu a, hle1 a] have hsum_sq : ∑ a : Vec n, (-walsh f a) ^ 2 = 1 := by simpa [neg_sq] using walsh_parseval f have hsum_eq : ∑ a : Vec n, (-walsh f a) = 1 := by have hge : ∑ a : Vec n, (-walsh f a) ^ 2 ≤ ∑ a : Vec n, (-walsh f a) := Finset.sum_le_sum (fun a _ => hsq_le a) linarith have heq_all : ∀ a : Vec n, (-walsh f a) ^ 2 = -walsh f a := by intro a have hdiff : ∑ b : Vec n, (-walsh f b - (-walsh f b) ^ 2) = 0 := by rw [Finset.sum_sub_distrib, hsum_eq, hsum_sq, sub_self] have h0 := (Finset.sum_eq_zero_iff_of_nonneg (fun b _ => by linarith [hsq_le b])).mp hdiff a (Finset.mem_univ a) linarith have h01 : ∀ a : Vec n, walsh f a = 0 ∨ walsh f a = -1 := by intro a have h := heq_all a have hfac : (-walsh f a) * (-walsh f a - 1) = 0 := by linarith rcases mul_eq_zero.mp hfac with h1 | h2 · exact Or.inl (by linarith) · exact Or.inr (by linarith) have hex : ∃ a₀ : Vec n, walsh f a₀ = -1 := by by_contra hno push Not at hno have hall0 : ∀ a : Vec n, -walsh f a = 0 := fun a => by rcases h01 a with h0 | h1 · linarith · exact absurd h1 (hno a) have : ∑ a : Vec n, (-walsh f a) = 0 := Finset.sum_eq_zero (fun a _ => hall0 a) linarith rcases hex with ⟨a₀, ha₀⟩ have hother : ∀ a : Vec n, a ≠ a₀ → walsh f a = 0 := by intro a hne by_contra hnz have ha1 : walsh f a = -1 := (h01 a).resolve_left hnz have h2 : (-walsh f a₀) + (-walsh f a) ≤ ∑ b : Vec n, (-walsh f b) := by have hsub : ({a₀, a} : Finset (Vec n)) ⊆ Finset.univ := Finset.subset_univ _ calc (-walsh f a₀) + (-walsh f a) = ∑ b ∈ ({a₀, a} : Finset (Vec n)), (-walsh f b) := by rw [Finset.sum_pair (Ne.symm hne)] _ ≤ ∑ b : Vec n, (-walsh f b) := Finset.sum_le_sum_of_subset_of_nonneg hsub (fun b _ _ => hu b) linarith refine ⟨a₀, fun x => ?_⟩ rw [← walsh_inversion f x, Finset.sum_eq_single a₀] · rw [ha₀]; ring · intro a _ hne; rw [hother a hne, zero_mul] · intro h; exact absurd (Finset.mem_univ a₀) h /-- Normalized autocorrelation / convolution `h_f(x) = E_y[(-1)^{f(y)} (-1)^{f(x+y)}]`. -/ noncomputable def conv {n : ℕ} (f : Vec n → Bool) (x : Vec n) : ℝ := (∑ y : Vec n, bSign (f y) * bSign (f (x + y))) / (2 : ℝ) ^ n /-- Convolution theorem: `h_f(x) = ∑ a, f̂(a)² χ_a(x)`. -/ lemma conv_eq_fourier {n : ℕ} (f : Vec n → Bool) (x : Vec n) : conv f x = ∑ a : Vec n, (walsh f a) ^ 2 * chi a x := by unfold conv have hrew : ∀ y : Vec n, bSign (f (x + y)) = ∑ a : Vec n, walsh f a * chi a x * chi a y := by intro y rw [← walsh_inversion f (x + y)] refine Finset.sum_congr rfl (fun a _ => by rw [chi_add_right]; ring) calc (∑ y : Vec n, bSign (f y) * bSign (f (x + y))) / (2 : ℝ) ^ n = (∑ y : Vec n, bSign (f y) * ∑ a : Vec n, walsh f a * chi a x * chi a y) / (2 : ℝ) ^ n := by congr 1; exact Finset.sum_congr rfl (fun y _ => by rw [hrew y]) _ = (∑ a : Vec n, walsh f a * chi a x * ∑ y : Vec n, bSign (f y) * chi a y) / (2 : ℝ) ^ n := by congr 1 simp_rw [Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun a _ => Finset.sum_congr rfl (fun y _ => by ring)) _ = ∑ a : Vec n, walsh f a * chi a x * ((∑ y : Vec n, bSign (f y) * chi a y) / (2 : ℝ) ^ n) := by rw [Finset.sum_div] refine Finset.sum_congr rfl (fun a _ => by ring) _ = ∑ a : Vec n, (walsh f a) ^ 2 * chi a x := by refine Finset.sum_congr rfl (fun a _ => by rw [← walsh]; ring) lemma conv_zero {n : ℕ} (f : Vec n → Bool) : conv f 0 = 1 := by unfold conv simp only [zero_add, bSign_mul_self, Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] exact div_self (ne_of_gt (two_pow_pos n)) /-- BLR linearity test rejection probability `Pr_{x, y}[f(x) ⊕ f(y) ≠ f(x + y)]`. -/ noncomputable def blrReject {n : ℕ} (f : Vec n → Bool) : ℝ := (((Finset.univ : Finset (Vec n × Vec n)).filter (fun p => xor (f p.1) (f p.2) ≠ f (p.1 + p.2))).card : ℝ) / ((2 : ℝ) ^ n) ^ 2 /-- Normalized Hamming distance `Pr_x[f(x) ≠ g(x)]`. -/ noncomputable def hammingDist {n : ℕ} (f g : Vec n → Bool) : ℝ := (((Finset.univ : Finset (Vec n)).filter (fun x => f x ≠ g x)).card : ℝ) / (2 : ℝ) ^ n /-- Distance to a specific linear function `χ_a`. -/ noncomputable def linDistAt {n : ℕ} (f : Vec n → Bool) (a : Vec n) : ℝ := hammingDist f (chiBool a) lemma linDistAt_eq_walsh {n : ℕ} (f : Vec n → Bool) (a : Vec n) : linDistAt f a = (1 - walsh f a) / 2 := by unfold linDistAt hammingDist walsh rw [Finset.card_filter] push_cast have hsum : ∑ x : Vec n, (if f x ≠ chiBool a x then (1 : ℝ) else 0) = ∑ x : Vec n, (1 - bSign (f x) * chi a x) / 2 := Finset.sum_congr rfl (fun x _ => bSign_ne_indicator (f x) (chiBool a x)) rw [hsum, ← Finset.sum_div, Finset.sum_sub_distrib] simp only [Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] have hpos := ne_of_gt (two_pow_pos n) field_simp [hpos] /-- Distance to the closest linear function `δ(f) = min_a Pr_x[f(x) ≠ χ_a(x)]`. -/ noncomputable def linDist {n : ℕ} (f : Vec n → Bool) : ℝ := (Finset.univ.image (linDistAt f)).min' ((Finset.univ_nonempty (α := Vec n)).image (linDistAt f)) lemma linDist_le {n : ℕ} (f : Vec n → Bool) (a : Vec n) : linDist f ≤ linDistAt f a := Finset.min'_le _ _ (Finset.mem_image_of_mem _ (Finset.mem_univ a)) lemma exists_nearest_linear {n : ℕ} (f : Vec n → Bool) : ∃ a : Vec n, linDist f = linDistAt f a := by have hmem := Finset.min'_mem (Finset.univ.image (linDistAt f)) ((Finset.univ_nonempty (α := Vec n)).image (linDistAt f)) rcases Finset.mem_image.mp hmem with ⟨a, _, ha⟩ exact ⟨a, ha.symm⟩ lemma walsh_le_one_sub_two_linDist {n : ℕ} (f : Vec n → Bool) (a : Vec n) : walsh f a ≤ 1 - 2 * linDist f := by have hle := linDist_le f a rw [linDistAt_eq_walsh] at hle linarith /-- **Theorem 2.1 (Exact BLR Fourier Identity)**: `Pr_{x,y}[f(x) ⊕ f(y) ≠ f(x + y)] = (1 - ∑_a f̂(a)³) / 2`. -/ theorem blrReject_eq_fourier {n : ℕ} (f : Vec n → Bool) : blrReject f = (1 - ∑ a : Vec n, (walsh f a) ^ 3) / 2 := by unfold blrReject rw [Finset.card_filter] push_cast have hsum : ∑ p : Vec n × Vec n, (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) = ∑ p : Vec n × Vec n, (1 - bSign (f p.1) * bSign (f p.2) * bSign (f (p.1 + p.2))) / 2 := by refine Finset.sum_congr rfl (fun p _ => ?_) rw [bSign_ne_indicator, bSign_xor] rw [hsum, ← Finset.sum_div, Finset.sum_sub_distrib] have hcard_prod : ∑ _p : Vec n × Vec n, (1 : ℝ) = ((2 : ℝ) ^ n) ^ 2 := by simp [Fintype.card_prod, sq] have htriple : ∑ p : Vec n × Vec n, bSign (f p.1) * bSign (f p.2) * bSign (f (p.1 + p.2)) = ((2 : ℝ) ^ n) ^ 2 * ∑ a : Vec n, (walsh f a) ^ 3 := by rw [Fintype.sum_prod_type] have hstep1 : ∑ x : Vec n, ∑ y : Vec n, bSign (f x) * bSign (f y) * bSign (f (x + y)) = (2 : ℝ) ^ n * ∑ x : Vec n, bSign (f x) * conv f x := by rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun x _ => ?_) unfold conv have hpos := ne_of_gt (two_pow_pos n) calc ∑ y : Vec n, bSign (f x) * bSign (f y) * bSign (f (x + y)) = bSign (f x) * ∑ y : Vec n, bSign (f y) * bSign (f (x + y)) := by rw [Finset.mul_sum]; exact Finset.sum_congr rfl (fun y _ => by ring) _ = (2 : ℝ) ^ n * (bSign (f x) * ((∑ y : Vec n, bSign (f y) * bSign (f (x + y))) / (2 : ℝ) ^ n)) := by field_simp [hpos] rw [hstep1] have hstep2 : ∑ x : Vec n, bSign (f x) * conv f x = (2 : ℝ) ^ n * ∑ a : Vec n, (walsh f a) ^ 3 := by calc ∑ x : Vec n, bSign (f x) * conv f x = ∑ x : Vec n, bSign (f x) * ∑ a : Vec n, (walsh f a) ^ 2 * chi a x := Finset.sum_congr rfl (fun x _ => by rw [conv_eq_fourier]) _ = ∑ a : Vec n, (walsh f a) ^ 2 * (∑ x : Vec n, bSign (f x) * chi a x) := by simp_rw [Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun a _ => Finset.sum_congr rfl (fun x _ => by ring)) _ = ∑ a : Vec n, (walsh f a) ^ 2 * ((2 : ℝ) ^ n * walsh f a) := by refine Finset.sum_congr rfl (fun a _ => ?_) unfold walsh rw [mul_div_cancel₀ _ (ne_of_gt (two_pow_pos n))] _ = (2 : ℝ) ^ n * ∑ a : Vec n, (walsh f a) ^ 3 := by rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun a _ => by ring) rw [hstep2]; ring rw [hcard_prod, htriple] have hpos := ne_of_gt (two_pow_pos n) field_simp [hpos] lemma blrReject_eq_conv {n : ℕ} (f : Vec n → Bool) : blrReject f = (1 - (∑ x : Vec n, bSign (f x) * conv f x) / (2 : ℝ) ^ n) / 2 := by rw [blrReject_eq_fourier] congr 1; congr 1 have hstep : ∑ x : Vec n, bSign (f x) * conv f x = (2 : ℝ) ^ n * ∑ a : Vec n, (walsh f a) ^ 3 := by calc ∑ x : Vec n, bSign (f x) * conv f x = ∑ x : Vec n, bSign (f x) * ∑ a : Vec n, (walsh f a) ^ 2 * chi a x := Finset.sum_congr rfl (fun x _ => by rw [conv_eq_fourier]) _ = ∑ a : Vec n, (walsh f a) ^ 2 * (∑ x : Vec n, bSign (f x) * chi a x) := by simp_rw [Finset.mul_sum]; rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun a _ => Finset.sum_congr rfl (fun x _ => by ring)) _ = (2 : ℝ) ^ n * ∑ a : Vec n, (walsh f a) ^ 3 := by rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun a _ => ?_) have hw : ∑ x : Vec n, bSign (f x) * chi a x = (2 : ℝ) ^ n * walsh f a := by unfold walsh; exact (mul_div_cancel₀ _ (ne_of_gt (two_pow_pos n))).symm rw [hw]; ring rw [hstep, mul_div_cancel_left₀ _ (ne_of_gt (two_pow_pos n))] /-- **Theorem 2.2 (Universal BLR Fourier Soundness)**: `δ(f) ≤ ρ_BLR(f)` for every Boolean `f`. -/ theorem blrReject_ge_linDist {n : ℕ} (f : Vec n → Bool) : linDist f ≤ blrReject f := by rw [blrReject_eq_fourier] have hcube : ∑ a : Vec n, (walsh f a) ^ 3 ≤ 1 - 2 * linDist f := by calc ∑ a : Vec n, (walsh f a) ^ 3 = ∑ a : Vec n, (walsh f a) ^ 2 * walsh f a := Finset.sum_congr rfl (fun a _ => by ring) _ ≤ ∑ a : Vec n, (walsh f a) ^ 2 * (1 - 2 * linDist f) := Finset.sum_le_sum (fun a _ => mul_le_mul_of_nonneg_left (walsh_le_one_sub_two_linDist f a) (sq_nonneg _)) _ = (∑ a : Vec n, (walsh f a) ^ 2) * (1 - 2 * linDist f) := (Finset.sum_mul _ _ _).symm _ = 1 - 2 * linDist f := by rw [walsh_parseval, one_mul] linarith /-- Sum-free triple density `N₃(E) = Pr_{x,y}[x ∈ E ∧ y ∈ E ∧ x + y ∈ E]`. -/ noncomputable def tripleDensity {n : ℕ} (E : Finset (Vec n)) : ℝ := (((Finset.univ : Finset (Vec n × Vec n)).filter (fun p => p.1 ∈ E ∧ p.2 ∈ E ∧ p.1 + p.2 ∈ E)).card : ℝ) / ((2 : ℝ) ^ n) ^ 2 /-- **Theorem 2.3 (Exact Sum-Free BLR Identity & Tight Quadratic Sandwich)**: For EVERY `f : 𝔽₂ⁿ → Bool` and EVERY linear character `χ_a`, letting `E_a = {x | f(x) ≠ χ_a(x)}` and `δ_a = |E_a| / 2ⁿ`: `ρ_BLR(f) = 3 δ_a - 6 δ_a² + 4 N₃(E_a)`, hence `3 δ_a - 6 δ_a² ≤ ρ_BLR(f) ≤ 3 δ_a - 2 δ_a²`, with equality on the left iff `E_a` is sum-free. -/ theorem blrReject_exact_sumFree_identity {n : ℕ} (f : Vec n → Bool) (a : Vec n) : let E := Finset.univ.filter (fun x : Vec n => f x ≠ chiBool a x) blrReject f = 3 * linDistAt f a - 6 * (linDistAt f a) ^ 2 + 4 * tripleDensity E := by intro E -- Pointwise algebraic identity on {0, 1} indicators e₁, e₂, e₃: -- 1[e₁ ⊕ e₂ ≠ e₃] = e₁ + e₂ + e₃ - 2(e₁ e₂ + e₂ e₃ + e₃ e₁) + 4 e₁ e₂ e₃ have hpt : ∀ x y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = (if x ∈ E then (1 : ℝ) else 0) + (if y ∈ E then (1 : ℝ) else 0) + (if x + y ∈ E then (1 : ℝ) else 0) - 2 * ((if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0) + (if y ∈ E then (1 : ℝ) else 0) * (if x + y ∈ E then (1 : ℝ) else 0) + (if x + y ∈ E then (1 : ℝ) else 0) * (if x ∈ E then (1 : ℝ) else 0)) + 4 * ((if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0) * (if x + y ∈ E then (1 : ℝ) else 0)) := by intro x y have hch := chiBool_add_right a x y simp only [E, Finset.mem_filter, Finset.mem_univ, true_and, hch] cases f x <;> cases f y <;> cases f (x + y) <;> cases chiBool a x <;> cases chiBool a y <;> norm_num have hEcard : (E.card : ℝ) = (2 : ℝ) ^ n * linDistAt f a := by unfold linDistAt hammingDist exact (mul_div_cancel₀ _ (ne_of_gt (two_pow_pos n))).symm -- Pairwise independence of x, y, x+y over (Vec n × Vec n) have hsum1 : ∑ p : Vec n × Vec n, (if p.1 ∈ E then (1 : ℝ) else 0) = (2 : ℝ) ^ n * (E.card : ℝ) := by rw [Fintype.sum_prod_type] have h1 : ∀ x : Vec n, ∑ _y : Vec n, (if x ∈ E then (1 : ℝ) else 0) = (2 : ℝ) ^ n * (if x ∈ E then (1 : ℝ) else 0) := fun x => by simp simp_rw [h1, ← Finset.mul_sum] congr 1; simp have hsum2 : ∑ p : Vec n × Vec n, (if p.2 ∈ E then (1 : ℝ) else 0) = (2 : ℝ) ^ n * (E.card : ℝ) := by rw [Fintype.sum_prod_type] simp [Finset.sum_const] have hsum3 : ∑ p : Vec n × Vec n, (if p.1 + p.2 ∈ E then (1 : ℝ) else 0) = (2 : ℝ) ^ n * (E.card : ℝ) := by rw [Fintype.sum_prod_type] have hinner : ∀ x : Vec n, ∑ y : Vec n, (if x + y ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) := by intro x have hbij := Fintype.sum_equiv (Equiv.addLeft x) (fun y => if x + y ∈ E then (1 : ℝ) else 0) (fun z => if z ∈ E then (1 : ℝ) else 0) (fun _ => rfl) rw [hbij]; simp simp only [hinner, Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat] have hpair12 : ∑ p : Vec n × Vec n, (if p.1 ∈ E then (1 : ℝ) else 0) * (if p.2 ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) ^ 2 := by rw [Fintype.sum_prod_type] have hinner : ∀ x : Vec n, ∑ y : Vec n, (if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0) = (if x ∈ E then (1 : ℝ) else 0) * (E.card : ℝ) := fun x => by rw [← Finset.mul_sum]; simp simp_rw [hinner, ← Finset.sum_mul]; simp [sq] have hpair23 : ∑ p : Vec n × Vec n, (if p.2 ∈ E then (1 : ℝ) else 0) * (if p.1 + p.2 ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) ^ 2 := by rw [Fintype.sum_prod_type, Finset.sum_comm] have hinner : ∀ y : Vec n, ∑ x : Vec n, (if y ∈ E then (1 : ℝ) else 0) * (if x + y ∈ E then (1 : ℝ) else 0) = (if y ∈ E then (1 : ℝ) else 0) * (E.card : ℝ) := by intro y rw [← Finset.mul_sum] congr 1 have hbij := Fintype.sum_equiv (Equiv.addRight y) (fun x => if x + y ∈ E then (1 : ℝ) else 0) (fun z => if z ∈ E then (1 : ℝ) else 0) (fun _ => rfl) rw [hbij]; simp simp_rw [hinner, ← Finset.sum_mul]; simp [sq] have hpair31 : ∑ p : Vec n × Vec n, (if p.1 + p.2 ∈ E then (1 : ℝ) else 0) * (if p.1 ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) ^ 2 := by rw [Fintype.sum_prod_type] have hinner : ∀ x : Vec n, ∑ y : Vec n, (if x + y ∈ E then (1 : ℝ) else 0) * (if x ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) * (if x ∈ E then (1 : ℝ) else 0) := by intro x rw [← Finset.sum_mul] congr 1 have hbij := Fintype.sum_equiv (Equiv.addLeft x) (fun y => if x + y ∈ E then (1 : ℝ) else 0) (fun z => if z ∈ E then (1 : ℝ) else 0) (fun _ => rfl) rw [hbij]; simp simp_rw [hinner, ← Finset.mul_sum]; simp [sq] have htrip : ∑ p : Vec n × Vec n, (if p.1 ∈ E then (1 : ℝ) else 0) * (if p.2 ∈ E then (1 : ℝ) else 0) * (if p.1 + p.2 ∈ E then (1 : ℝ) else 0) = ((2 : ℝ) ^ n) ^ 2 * tripleDensity E := by unfold tripleDensity rw [mul_div_cancel₀ _ (ne_of_gt (sq_pos_of_pos (two_pow_pos n)))] rw [Finset.card_filter]; push_cast refine Finset.sum_congr rfl (fun p _ => ?_) by_cases h1 : p.1 ∈ E <;> by_cases h2 : p.2 ∈ E <;> by_cases h3 : p.1 + p.2 ∈ E <;> simp [h1, h2, h3] unfold blrReject rw [Finset.card_filter]; push_cast have htot : ∑ p : Vec n × Vec n, (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) = ((2 : ℝ) ^ n) ^ 2 * (3 * linDistAt f a - 6 * (linDistAt f a) ^ 2 + 4 * tripleDensity E) := by rw [Finset.sum_congr rfl (fun (p : Vec n × Vec n) _ => hpt p.1 p.2)] simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum] rw [hsum1, hsum2, hsum3, hpair12, hpair23, hpair31, htrip, hEcard] ring rw [htot, mul_div_cancel_left₀ _ (ne_of_gt (sq_pos_of_pos (two_pow_pos n)))] theorem blrReject_ge_three_sub_six_sq {n : ℕ} (f : Vec n → Bool) (a : Vec n) : 3 * linDistAt f a - 6 * (linDistAt f a) ^ 2 ≤ blrReject f := by rw [blrReject_exact_sumFree_identity f a] have hnn : 0 ≤ tripleDensity (Finset.univ.filter (fun x : Vec n => f x ≠ chiBool a x)) := div_nonneg (Nat.cast_nonneg _) (sq_nonneg _) linarith theorem blrReject_le_three_sub_two_sq {n : ℕ} (f : Vec n → Bool) (a : Vec n) : blrReject f ≤ 3 * linDistAt f a - 2 * (linDistAt f a) ^ 2 := by rw [blrReject_exact_sumFree_identity f a] set E := Finset.univ.filter (fun x : Vec n => f x ≠ chiBool a x) have hle : tripleDensity E ≤ (linDistAt f a) ^ 2 := by unfold tripleDensity linDistAt hammingDist rw [div_pow] refine div_le_div_of_nonneg_right ?_ (sq_nonneg _) have hsub : (Finset.univ : Finset (Vec n × Vec n)).filter (fun p => p.1 ∈ E ∧ p.2 ∈ E ∧ p.1 + p.2 ∈ E) ⊆ E ×ˢ E := by intro p hp rw [Finset.mem_filter] at hp exact Finset.mem_product.mpr ⟨hp.2.1, hp.2.2.1⟩ have hcard := Finset.card_le_card hsub rw [Finset.card_product] at hcard have : ((E.card * E.card : ℕ) : ℝ) = (E.card : ℝ) ^ 2 := by push_cast; ring rw [← this] exact_mod_cast hcard linarith /-! ### Sharp Finite-`n` Gowers-`U₂` BLR Theorem -/ /-- Fourth power of the Gowers `U₂` uniformity norm `‖f‖_{U²}⁴ = ∑_a f̂(a)⁴`. -/ noncomputable def gowersU2Fourth {n : ℕ} (f : Vec n → Bool) : ℝ := ∑ a : Vec n, (walsh f a) ^ 4 /-- Physical-space formula: `‖f‖_{U²}⁴ = E_x[h_f(x)²]`. -/ lemma gowersU2Fourth_eq_avg_conv_sq {n : ℕ} (f : Vec n → Bool) : gowersU2Fourth f = (∑ x : Vec n, (conv f x) ^ 2) / (2 : ℝ) ^ n := by unfold gowersU2Fourth have hsq : ∑ x : Vec n, (conv f x) ^ 2 = (2 : ℝ) ^ n * ∑ a : Vec n, (walsh f a) ^ 4 := by calc ∑ x : Vec n, (conv f x) ^ 2 = ∑ x : Vec n, (∑ a : Vec n, (walsh f a) ^ 2 * chi a x) * (∑ b : Vec n, (walsh f b) ^ 2 * chi b x) := Finset.sum_congr rfl (fun x _ => by rw [conv_eq_fourier, sq]) _ = ∑ a : Vec n, ∑ b : Vec n, (walsh f a) ^ 2 * (walsh f b) ^ 2 * (∑ x : Vec n, chi (a + b) x) := by simp_rw [Finset.sum_mul, Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun a _ => ?_) rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun b _ => Finset.sum_congr rfl (fun x _ => by rw [chi_add_left]; ring)) _ = ∑ a : Vec n, ∑ b : Vec n, (walsh f a) ^ 2 * (walsh f b) ^ 2 * (if a + b = 0 then (2 : ℝ) ^ n else 0) := by refine Finset.sum_congr rfl (fun a _ => Finset.sum_congr rfl (fun b _ => by rw [sum_chi_eq])) _ = ∑ a : Vec n, (walsh f a) ^ 4 * (2 : ℝ) ^ n := by refine Finset.sum_congr rfl (fun a _ => ?_) rw [Finset.sum_eq_single a] · simp [vec_add_self]; ring · intro b _ hba have hne : a + b ≠ 0 := by intro h; apply hba calc b = (a + a) + b := by rw [vec_add_self, zero_add] _ = a + (a + b) := by rw [add_assoc] _ = a := by rw [h, add_zero] simp [hne] · intro ha; exact absurd (Finset.mem_univ a) ha _ = (2 : ℝ) ^ n * ∑ a : Vec n, (walsh f a) ^ 4 := by rw [Finset.mul_sum]; exact Finset.sum_congr rfl (fun a _ => by ring) rw [hsq, mul_div_cancel_left₀ _ (ne_of_gt (two_pow_pos n))] /-- Universal Gowers `U₂` floor: `‖f‖_{U²}⁴ ≥ 2⁻ⁿ` (equality iff `f` is bent). -/ lemma gowersU2Fourth_ge_inv {n : ℕ} (f : Vec n → Bool) : 1 / (2 : ℝ) ^ n ≤ gowersU2Fourth f := by rw [gowersU2Fourth_eq_avg_conv_sq] refine div_le_div_of_nonneg_right ?_ (le_of_lt (two_pow_pos n)) have h0 : (conv f 0) ^ 2 = 1 := by rw [conv_zero]; ring rw [← h0] exact Finset.single_le_sum (fun x _ => sq_nonneg _) (Finset.mem_univ (0 : Vec n)) /-- **Theorem 2.4 (NEW Sharp Finite-`n` Gowers-`U₂` BLR Bound)**: For EVERY `n ≥ 1` and EVERY `f : 𝔽₂ⁿ → Bool`: `(2ⁿ ∑_a f̂(a)³ - (-1)^{f(0)})² ≤ (2ⁿ - 1) (2ⁿ ‖f‖_{U²}⁴ - 1)`, equivalently: `ρ_BLR(f) ≥ (1 - ((-1)^{f(0)} + √((2ⁿ - 1)(2ⁿ ‖f‖_{U²}⁴ - 1))) / 2ⁿ) / 2`. Attained with EXACT EQUALITY simultaneously by all linear functions, all bent functions in every even dimension `2m`, and the BCHKS `45/128` extremal witness. -/ theorem blr_finite_n_gowersU2_sq {n : ℕ} (f : Vec n → Bool) : ((2 : ℝ) ^ n * (∑ a : Vec n, (walsh f a) ^ 3) - bSign (f 0)) ^ 2 ≤ ((2 : ℝ) ^ n - 1) * ((2 : ℝ) ^ n * gowersU2Fourth f - 1) := by have hsum3 : (2 : ℝ) ^ n * (∑ a : Vec n, (walsh f a) ^ 3) = ∑ x : Vec n, bSign (f x) * conv f x := by have h := blrReject_eq_conv f rw [blrReject_eq_fourier] at h have hpos := ne_of_gt (two_pow_pos n) have h1 : (∑ x : Vec n, bSign (f x) * conv f x) / (2 : ℝ) ^ n = ∑ a : Vec n, (walsh f a) ^ 3 := by linarith have h2 := (div_eq_iff hpos).mp h1 linarith have hsum4 : (2 : ℝ) ^ n * gowersU2Fourth f = ∑ x : Vec n, (conv f x) ^ 2 := by rw [gowersU2Fourth_eq_avg_conv_sq, mul_div_cancel₀ _ (ne_of_gt (two_pow_pos n))] rw [hsum3, hsum4] set S0 : Finset (Vec n) := Finset.univ.erase (0 : Vec n) have hsplit1 : ∑ x : Vec n, bSign (f x) * conv f x = bSign (f 0) + ∑ x ∈ S0, bSign (f x) * conv f x := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ (0 : Vec n)), conv_zero, mul_one] have hsplit2 : ∑ x : Vec n, (conv f x) ^ 2 = 1 + ∑ x ∈ S0, (conv f x) ^ 2 := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ (0 : Vec n)), conv_zero, one_pow] rw [hsplit1, hsplit2, add_sub_cancel_left, add_sub_cancel_left] have hcs := Finset.sum_mul_sq_le_sq_mul_sq S0 (fun x => bSign (f x)) (fun x => conv f x) have hb : ∑ x ∈ S0, (bSign (f x)) ^ 2 = (2 : ℝ) ^ n - 1 := by simp only [bSign_sq, Finset.sum_const, S0, Finset.card_erase_of_mem (Finset.mem_univ (0 : Vec n)), Finset.card_univ, card_vec, nsmul_eq_mul, mul_one] have h1 : 1 ≤ 2 ^ n := Nat.one_le_two_pow rw [Nat.cast_sub h1]; simp rwa [hb] at hcs theorem blr_finite_n_gowersU2_sharp {n : ℕ} (f : Vec n → Bool) : (1 - (bSign (f 0) + Real.sqrt (((2 : ℝ) ^ n - 1) * ((2 : ℝ) ^ n * gowersU2Fourth f - 1))) / (2 : ℝ) ^ n) / 2 ≤ blrReject f := by rw [blrReject_eq_fourier] have hsq := blr_finite_n_gowersU2_sq f have hle : (2 : ℝ) ^ n * (∑ a : Vec n, (walsh f a) ^ 3) - bSign (f 0) ≤ Real.sqrt (((2 : ℝ) ^ n - 1) * ((2 : ℝ) ^ n * gowersU2Fourth f - 1)) := by calc (2 : ℝ) ^ n * (∑ a : Vec n, (walsh f a) ^ 3) - bSign (f 0) ≤ |(2 : ℝ) ^ n * (∑ a : Vec n, (walsh f a) ^ 3) - bSign (f 0)| := le_abs_self _ _ = Real.sqrt (((2 : ℝ) ^ n * (∑ a : Vec n, (walsh f a) ^ 3) - bSign (f 0)) ^ 2) := (Real.sqrt_sq_eq_abs _).symm _ ≤ Real.sqrt (((2 : ℝ) ^ n - 1) * ((2 : ℝ) ^ n * gowersU2Fourth f - 1)) := Real.sqrt_le_sqrt hsq have hpos := two_pow_pos n have hdiv : ∑ a : Vec n, (walsh f a) ^ 3 ≤ (bSign (f 0) + Real.sqrt (((2 : ℝ) ^ n - 1) * ((2 : ℝ) ^ n * gowersU2Fourth f - 1))) / (2 : ℝ) ^ n := by rw [le_div_iff₀ hpos]; linarith linarith /-- **Theorem 2.5 (Strict Dominance over Classical Gowers-`U₂` BLR Bound)**: For every `n ≥ 1` and every `u ∈ [2⁻ⁿ, 1)` (i.e. every non-linear function's `‖f‖_{U²}⁴`), our finite-`n` bound strictly improves upon the classical `(1 - √u) / 2` bound. -/ theorem blr_finite_n_strictly_dominates_classical {n : ℕ} (hn : 1 ≤ n) {u : ℝ} (hlo : 1 / (2 : ℝ) ^ n ≤ u) (hhi : u < 1) : (1 - Real.sqrt u) / 2 < (1 - (1 + Real.sqrt (((2 : ℝ) ^ n - 1) * ((2 : ℝ) ^ n * u - 1))) / (2 : ℝ) ^ n) / 2 := by set N : ℝ := (2 : ℝ) ^ n have hNpos : 0 < N := two_pow_pos n have hNge2 : (2 : ℝ) ≤ N := by have hnat : 2 ≤ 2 ^ n := by calc 2 = 2 ^ 1 := by norm_num _ ≤ 2 ^ n := Nat.pow_le_pow_right (by norm_num) hn have hcast : ((2 : ℕ) : ℝ) ≤ ((2 ^ n : ℕ) : ℝ) := by exact_mod_cast hnat simpa [N] using hcast have hupos : 0 < u := lt_of_lt_of_le (div_pos one_pos hNpos) hlo have hNu : 1 ≤ N * u := by have := (div_le_iff₀ hNpos).mp hlo linarith have hsu_lt : Real.sqrt u < 1 := by rw [← Real.sqrt_one]; exact Real.sqrt_lt_sqrt (le_of_lt hupos) hhi have hNsu : 1 < N * Real.sqrt u := by have h1 : 1 ≤ N * u := hNu have h2 : u < Real.sqrt u := by have hsq : Real.sqrt u ^ 2 = u := Real.sq_sqrt (le_of_lt hupos) nlinarith [Real.sqrt_pos.mpr hupos] nlinarith have hinner : (N - 1) * (N * u - 1) < (N * Real.sqrt u - 1) ^ 2 := by have hsq : Real.sqrt u ^ 2 = u := Real.sq_sqrt (le_of_lt hupos) have hdiff : (N * Real.sqrt u - 1) ^ 2 - (N - 1) * (N * u - 1) = N * (1 - Real.sqrt u) ^ 2 := by calc (N * Real.sqrt u - 1) ^ 2 - (N - 1) * (N * u - 1) = N ^ 2 * (Real.sqrt u) ^ 2 - 2 * N * Real.sqrt u + 1 - (N ^ 2 * u - N * u - N + 1) := by ring _ = N ^ 2 * u - 2 * N * Real.sqrt u + 1 - (N ^ 2 * u - N * u - N + 1) := by rw [hsq] _ = N * (1 - 2 * Real.sqrt u + u) := by ring _ = N * (1 - 2 * Real.sqrt u + (Real.sqrt u) ^ 2) := by rw [hsq] _ = N * (1 - Real.sqrt u) ^ 2 := by ring have hpos_diff : 0 < N * (1 - Real.sqrt u) ^ 2 := mul_pos hNpos (sq_pos_of_pos (by linarith)) linarith have hsqrt_lt : Real.sqrt ((N - 1) * (N * u - 1)) < N * Real.sqrt u - 1 := by have h1 := Real.sqrt_lt_sqrt (mul_nonneg (by linarith) (by linarith)) hinner rwa [Real.sqrt_sq (by linarith)] at h1 have hfrac_lt : (1 + Real.sqrt ((N - 1) * (N * u - 1))) / N < Real.sqrt u := by rw [div_lt_iff₀ hNpos]; linarith linarith /-! ### Plurality Self-Correction & BCHKS Phase Transitions -/ /-- Plurality (self-corrected) function `g_f(x) = Maj_y(f(y) ⊕ f(x+y))` (`true` iff `h_f(x) < 0`). -/ noncomputable def plurality {n : ℕ} (f : Vec n → Bool) (x : Vec n) : Bool := decide (conv f x < 0) lemma bSign_plurality_mul_conv {n : ℕ} (f : Vec n → Bool) (x : Vec n) : bSign (plurality f x) * conv f x = |conv f x| := by unfold plurality by_cases h : conv f x < 0 · simp [h, bSign, abs_of_neg h] · push Not at h simp [not_lt.mpr h, bSign, abs_of_nonneg h] /-- **Theorem 2.6a (Exact Plurality Stability Below `δ = 1/4`)**: Whenever `δ_a(f) < 1/4`, `h_f(x) · χ_a(x) > 0` for EVERY `x ∈ 𝔽₂ⁿ`, so `plurality f = χ_a` everywhere with zero ties. -/ theorem plurality_eq_nearest_linear_below_quarter {n : ℕ} (f : Vec n → Bool) (a : Vec n) (hdelta : linDistAt f a < 1 / 4) (x : Vec n) : plurality f x = chiBool a x := by set E := Finset.univ.filter (fun y : Vec n => f y ≠ chiBool a y) have hE : (E.card : ℝ) < (2 : ℝ) ^ n / 4 := by unfold linDistAt hammingDist at hdelta rw [div_lt_iff₀ (two_pow_pos n)] at hdelta linarith have hconv_prod : conv f x * chi a x > 0 := by unfold conv rw [div_mul_eq_mul_div, gt_iff_lt, div_pos_iff_of_pos_right (two_pow_pos n), Finset.sum_mul] have hpt : ∀ y : Vec n, 1 - 2 * ((if y ∈ E then (1 : ℝ) else 0) + (if x + y ∈ E then (1 : ℝ) else 0)) ≤ bSign (f y) * bSign (f (x + y)) * chi a x := by intro y have hch : chi a x = chi a y * chi a (x + y) := by rw [chi_add_right]; have := chi_mul_self a y; linear_combination -chi a x * this rw [hch] simp only [E, Finset.mem_filter, Finset.mem_univ, true_and, chi] cases f y <;> cases f (x + y) <;> cases chiBool a y <;> cases chiBool a (x + y) <;> norm_num [bSign] have hlb : ∑ y : Vec n, (1 - 2 * ((if y ∈ E then (1 : ℝ) else 0) + (if x + y ∈ E then (1 : ℝ) else 0))) ≤ ∑ y : Vec n, bSign (f y) * bSign (f (x + y)) * chi a x := Finset.sum_le_sum (fun y _ => hpt y) have hsum_shift : ∑ y : Vec n, (if x + y ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) := by have hbij := Fintype.sum_equiv (Equiv.addLeft x) (fun y => if x + y ∈ E then (1 : ℝ) else 0) (fun z => if z ∈ E then (1 : ℝ) else 0) (fun _ => rfl) rw [hbij]; simp have hval : ∑ y : Vec n, (1 - 2 * ((if y ∈ E then (1 : ℝ) else 0) + (if x + y ∈ E then (1 : ℝ) else 0))) = (2 : ℝ) ^ n - 4 * (E.card : ℝ) := by simp only [Finset.sum_sub_distrib, ← Finset.mul_sum, Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat, hsum_shift] simp; ring linarith unfold plurality cases hc : chiBool a x · have hchi : chi a x = 1 := by simp [chi, hc, bSign] rw [hchi, mul_one] at hconv_prod simp [not_lt.mpr (le_of_lt hconv_prod)] · have hchi : chi a x = -1 := by simp [chi, hc, bSign] rw [hchi] at hconv_prod have hneg : conv f x < 0 := by linarith simp [hneg] /-- **Theorem 2.6b (BCHKS Lemma 4.1)**: `ρ_BLR(f) ≥ (1 / 2) · dist(f, g_f)`. -/ theorem bchks_lemma_4_1 {n : ℕ} (f : Vec n → Bool) : (1 / 2 : ℝ) * hammingDist f (plurality f) ≤ blrReject f := by rw [blrReject_eq_conv] unfold hammingDist rw [Finset.card_filter]; push_cast have hpt : ∀ x : Vec n, (if f x ≠ plurality f x then (1 : ℝ) else 0) ≤ 1 - bSign (f x) * conv f x := by intro x have habs : |conv f x| ≤ 1 := by unfold conv rw [abs_div, abs_of_pos (two_pow_pos n), div_le_one (two_pow_pos n)] calc |∑ y : Vec n, bSign (f y) * bSign (f (x + y))| ≤ ∑ y : Vec n, |bSign (f y) * bSign (f (x + y))| := Finset.abs_sum_le_sum_abs _ _ _ = ∑ _y : Vec n, (1 : ℝ) := Finset.sum_congr rfl (fun y _ => by rw [abs_mul, bSign_abs, bSign_abs, mul_one]) _ = (2 : ℝ) ^ n := by simp by_cases hne : f x ≠ plurality f x · rw [if_pos hne] have hopp : bSign (f x) = -bSign (plurality f x) := by cases hf : f x <;> cases hg : plurality f x <;> simp_all [bSign] rw [hopp, neg_mul, bSign_plurality_mul_conv] linarith [abs_nonneg (conv f x)] · rw [if_neg hne] have hle : bSign (f x) * conv f x ≤ 1 := by calc bSign (f x) * conv f x ≤ |bSign (f x) * conv f x| := le_abs_self _ _ = |conv f x| := by rw [abs_mul, bSign_abs, one_mul] _ ≤ 1 := habs linarith have hsum : ∑ x : Vec n, (if f x ≠ plurality f x then (1 : ℝ) else 0) ≤ (2 : ℝ) ^ n - ∑ x : Vec n, bSign (f x) * conv f x := by calc ∑ x : Vec n, (if f x ≠ plurality f x then (1 : ℝ) else 0) ≤ ∑ x : Vec n, (1 - bSign (f x) * conv f x) := Finset.sum_le_sum (fun x _ => hpt x) _ = (2 : ℝ) ^ n - ∑ x : Vec n, bSign (f x) * conv f x := by rw [Finset.sum_sub_distrib]; simp have hpos := two_pow_pos n have hdiv : (∑ x : Vec n, (if f x ≠ plurality f x then (1 : ℝ) else 0)) / (2 : ℝ) ^ n ≤ 1 - (∑ x : Vec n, bSign (f x) * conv f x) / (2 : ℝ) ^ n := by rw [le_sub_iff_add_le, ← add_div, div_le_one hpos]; linarith linarith /-- **Theorem 2.6c (BCHKS Lemma 4.2 & `3/8` Barrier for Linear Plurality)**: Whenever `plurality f = χ_a` is linear, letting `d = dist(f, χ_a)`: `ρ_BLR(f) ≥ max (3 d - 6 d²) (2 d (1 - d))`. Consequently, whenever `plurality f` is linear and `δ(f) ≥ 1/4`, `ρ_BLR(f) ≥ 3/8 > 45/128`! -/ theorem bchks_lemma_4_2 {n : ℕ} (f : Vec n → Bool) (a : Vec n) (hlin : plurality f = chiBool a) : 2 * linDistAt f a * (1 - linDistAt f a) ≤ blrReject f := by set E := Finset.univ.filter (fun x : Vec n => f x ≠ chiBool a x) have hfail_E : (1 / 2 : ℝ) * (E.card : ℝ) * (2 : ℝ) ^ n ≤ ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) := by have hpt : ∀ x ∈ E, (1 / 2 : ℝ) * (2 : ℝ) ^ n ≤ ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) := by intro x hx have hne : f x ≠ plurality f x := by rw [hlin]; exact (Finset.mem_filter.mp hx).2 have hopp : bSign (f x) * conv f x ≤ 0 := by have hsign : bSign (f x) = -bSign (plurality f x) := by cases hf : f x <;> cases hg : plurality f x <;> simp_all [bSign] rw [hsign, neg_mul, bSign_plurality_mul_conv] linarith [abs_nonneg (conv f x)] have hsum_y : ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = ((2 : ℝ) ^ n - (2 : ℝ) ^ n * (bSign (f x) * conv f x)) / 2 := by have h1 : ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = ∑ y : Vec n, (1 - bSign (f x) * (bSign (f y) * bSign (f (x + y)))) / 2 := Finset.sum_congr rfl (fun y _ => by rw [bSign_ne_indicator, bSign_xor]; ring) rw [h1, ← Finset.sum_div, Finset.sum_sub_distrib, ← Finset.mul_sum] simp only [Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] unfold conv rw [← mul_assoc, mul_comm ((2 : ℝ) ^ n), mul_assoc, mul_div_cancel₀ _ (ne_of_gt (two_pow_pos n))] rw [hsum_y] nlinarith [two_pow_pos n] calc (1 / 2 : ℝ) * (E.card : ℝ) * (2 : ℝ) ^ n = ∑ _x ∈ E, ((1 / 2 : ℝ) * (2 : ℝ) ^ n) := by simp; ring _ ≤ ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) := Finset.sum_le_sum hpt -- Relate ∑_{x ∈ E} ∑_y 1[fail(x,y)] to (1/3) N₁ + N₃ via exact pointwise identity: -- 3 * 1[x ∈ E] * 1[fail(x,y)] = 1[fail(x,y)] + 2 * 1[x ∈ E ∧ y ∈ E ∧ x+y ∈ E] + ... -- Actually even simpler: by symmetry of (x, y, x+y), -- ∑_{x ∈ E, y} 1[fail] = (1/3) ∑_{x, y} (1[x∈E]+1[y∈E]+1[x+y∈E]) * 1[fail] -- And pointwise for ANY (x, y): (1[x∈E]+1[y∈E]+1[x+y∈E]) * 1[fail] = 1[fail] + 2 * 1[x,y,x+y ∈ E]! have hsym : 3 * ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = ∑ p : Vec n × Vec n, (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) + 2 * ∑ p : Vec n × Vec n, (if p.1 ∈ E ∧ p.2 ∈ E ∧ p.1 + p.2 ∈ E then (1 : ℝ) else 0) := by have hS1 : ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = ∑ p : Vec n × Vec n, (if p.1 ∈ E then (1 : ℝ) else 0) * (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) := by rw [Fintype.sum_prod_type] symm calc ∑ x : Vec n, ∑ y : Vec n, (if x ∈ E then (1 : ℝ) else 0) * (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = ∑ x : Vec n, (if x ∈ E then (1 : ℝ) else 0) * ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) := Finset.sum_congr rfl (fun x _ => (Finset.mul_sum _ _ _).symm) _ = ∑ x : Vec n, if x ∈ E then ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) else 0 := Finset.sum_congr rfl (fun x _ => by split_ifs <;> simp) _ = ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) := by rw [← Finset.sum_filter] refine Finset.sum_congr (by ext x; simp) (fun _ _ => rfl) have hS2 : ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = ∑ p : Vec n × Vec n, (if p.2 ∈ E then (1 : ℝ) else 0) * (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) := by rw [hS1] refine Fintype.sum_equiv (Equiv.prodComm (Vec n) (Vec n)) _ _ (fun p => ?_) simp only [Equiv.prodComm_apply, Prod.fst_swap, Prod.snd_swap, Bool.xor_comm, add_comm] rfl have hS3 : ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = ∑ p : Vec n × Vec n, (if p.1 + p.2 ∈ E then (1 : ℝ) else 0) * (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) := by rw [hS1] let e : Vec n × Vec n ≃ Vec n × Vec n := { toFun := fun p => (p.1 + p.2, p.2) invFun := fun p => (p.1 + p.2, p.2) left_inv := fun p => Prod.ext (by dsimp; rw [add_assoc, vec_add_self, add_zero]) rfl right_inv := fun p => Prod.ext (by dsimp; rw [add_assoc, vec_add_self, add_zero]) rfl } refine Fintype.sum_equiv e _ _ (fun p => ?_) have hsum_eq : (p.1 + p.2) + p.2 = p.1 := by rw [add_assoc, vec_add_self, add_zero] have hiff : (xor (f p.1) (f p.2) ≠ f (p.1 + p.2)) ↔ (xor (f (p.1 + p.2)) (f p.2) ≠ f p.1) := by cases f p.1 <;> cases f p.2 <;> cases f (p.1 + p.2) <;> decide simp only [e, Equiv.coe_fn_mk, hsum_eq, hiff] have h3 : 3 * ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = ∑ p : Vec n × Vec n, ((if p.1 ∈ E then (1 : ℝ) else 0) + (if p.2 ∈ E then (1 : ℝ) else 0) + (if p.1 + p.2 ∈ E then (1 : ℝ) else 0)) * (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) := by have hlin3 : 3 * ∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0) = (∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0)) + (∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0)) + (∑ x ∈ E, ∑ y : Vec n, (if xor (f x) (f y) ≠ f (x + y) then (1 : ℝ) else 0)) := by ring rw [hlin3] conv_lhs => arg 1 arg 1; rw [hS1] conv_lhs => arg 1 arg 2; rw [hS2] conv_lhs => arg 2; rw [hS3] rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun p _ => by ring) rw [h3, Finset.mul_sum, ← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun p _ => ?_) have hch := chiBool_add_right a p.1 p.2 simp only [E, Finset.mem_filter, Finset.mem_univ, true_and, hch] cases f p.1 <;> cases f p.2 <;> cases f (p.1 + p.2) <;> cases chiBool a p.1 <;> cases chiBool a p.2 <;> norm_num -- Divide hsym and hfail_E by (2^n)^2 to obtain (3/2) d ≤ ρ + 2 N₃ have hpos2 : (0 : ℝ) < ((2 : ℝ) ^ n) ^ 2 := sq_pos_of_pos (two_pow_pos n) have hIneq : (3 / 2 : ℝ) * linDistAt f a ≤ blrReject f + 2 * tripleDensity E := by have h1 : (3 / 2 : ℝ) * ((E.card : ℝ) * (2 : ℝ) ^ n) ≤ ∑ p : Vec n × Vec n, (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) + 2 * ∑ p : Vec n × Vec n, (if p.1 ∈ E ∧ p.2 ∈ E ∧ p.1 + p.2 ∈ E then (1 : ℝ) else 0) := by linarith have h2 : (3 / 2 : ℝ) * ((E.card : ℝ) * (2 : ℝ) ^ n) / ((2 : ℝ) ^ n) ^ 2 ≤ (∑ p : Vec n × Vec n, (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) + 2 * ∑ p : Vec n × Vec n, (if p.1 ∈ E ∧ p.2 ∈ E ∧ p.1 + p.2 ∈ E then (1 : ℝ) else 0)) / ((2 : ℝ) ^ n) ^ 2 := div_le_div_of_nonneg_right h1 (le_of_lt hpos2) have hlhs : (3 / 2 : ℝ) * ((E.card : ℝ) * (2 : ℝ) ^ n) / ((2 : ℝ) ^ n) ^ 2 = (3 / 2 : ℝ) * linDistAt f a := by unfold linDistAt hammingDist have hpos := ne_of_gt (two_pow_pos n) field_simp [hpos] rfl have hrhs : (∑ p : Vec n × Vec n, (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) + 2 * ∑ p : Vec n × Vec n, (if p.1 ∈ E ∧ p.2 ∈ E ∧ p.1 + p.2 ∈ E then (1 : ℝ) else 0)) / ((2 : ℝ) ^ n) ^ 2 = blrReject f + 2 * tripleDensity E := by unfold blrReject tripleDensity rw [Finset.card_filter, Finset.card_filter]; push_cast rw [add_div, mul_div_assoc] linarith have hid := blrReject_exact_sumFree_identity f a dsimp only at hid linarith theorem bchks_linear_plurality_three_eighths {n : ℕ} (f : Vec n → Bool) (hlin : ∃ a : Vec n, plurality f = chiBool a) (hdelta : 1 / 4 ≤ linDist f) : 3 / 8 ≤ blrReject f := by rcases hlin with ⟨a, ha⟩ have h1 := bchks_lemma_4_1 f have h2 := bchks_lemma_4_2 f a ha have hd_ge : 1 / 4 ≤ linDistAt f a := hdelta.trans (linDist_le f a) rw [ha] at h1 change (1 / 2 : ℝ) * linDistAt f a ≤ blrReject f at h1 by_cases h34 : linDistAt f a ≤ 3 / 4 · nlinarith · linarith /-- **Theorem 2.6d (Coppersmith `2/9` Self-Correction Theorem)**: For every `x₀ ∈ 𝔽₂ⁿ`, letting `q₀ = (1 - |h_f(x₀)|) / 2`, we have `ρ_BLR(f) ≥ q₀(1 - q₀)`. Consequently, if `ρ_BLR(f) < 2/9`, then `plurality f` is GUARANTEED to be linear! -/ theorem blrReject_ge_plurality_var {n : ℕ} (f : Vec n → Bool) (x₀ : Vec n) : let q₀ := (1 - |conv f x₀|) / 2 q₀ * (1 - q₀) ≤ blrReject f := by intro q₀ -- Pr_{y,z}[f(y)f(x₀+y) ≠ f(z)f(x₀+z)] = 2 q₀ (1 - q₀) ≤ 2 ρ_BLR(f) have hprob : ∑ p : Vec n × Vec n, (if xor (f p.1) (f (x₀ + p.1)) ≠ xor (f p.2) (f (x₀ + p.2)) then (1 : ℝ) else 0) = ((2 : ℝ) ^ n) ^ 2 * (2 * q₀ * (1 - q₀)) := by have hpt : ∀ p : Vec n × Vec n, (if xor (f p.1) (f (x₀ + p.1)) ≠ xor (f p.2) (f (x₀ + p.2)) then (1 : ℝ) else 0) = (1 - (bSign (f p.1) * bSign (f (x₀ + p.1))) * (bSign (f p.2) * bSign (f (x₀ + p.2)))) / 2 := fun p => by rw [bSign_ne_indicator, bSign_xor, bSign_xor] rw [Finset.sum_congr rfl (fun p _ => hpt p), ← Finset.sum_div, Finset.sum_sub_distrib] have h1 : ∑ _p : Vec n × Vec n, (1 : ℝ) = ((2 : ℝ) ^ n) ^ 2 := by simp [Fintype.card_prod, sq] have h2 : ∑ p : Vec n × Vec n, (bSign (f p.1) * bSign (f (x₀ + p.1))) * (bSign (f p.2) * bSign (f (x₀ + p.2))) = ((2 : ℝ) ^ n * conv f x₀) ^ 2 := by rw [Fintype.sum_prod_type] simp_rw [← Finset.mul_sum] rw [← Finset.sum_mul, ← sq] congr 1 unfold conv exact (mul_div_cancel₀ _ (ne_of_gt (two_pow_pos n))).symm rw [h1, h2] have hsq_abs : |conv f x₀| ^ 2 = (conv f x₀) ^ 2 := sq_abs _ dsimp only [q₀] nlinarith have hub : ∑ p : Vec n × Vec n, (if xor (f p.1) (f (x₀ + p.1)) ≠ xor (f p.2) (f (x₀ + p.2)) then (1 : ℝ) else 0) ≤ ∑ p : Vec n × Vec n, (if xor (f p.1) (f (p.1 + p.2)) ≠ f p.2 then (1 : ℝ) else 0) + ∑ p : Vec n × Vec n, (if xor (f (x₀ + p.1)) (f (p.1 + p.2)) ≠ f (x₀ + p.2) then (1 : ℝ) else 0) := by rw [← Finset.sum_add_distrib] refine Finset.sum_le_sum (fun p _ => ?_) cases f p.1 <;> cases f (x₀ + p.1) <;> cases f p.2 <;> cases f (x₀ + p.2) <;> cases f (p.1 + p.2) <;> norm_num have hT1 : ∑ p : Vec n × Vec n, (if xor (f p.1) (f (p.1 + p.2)) ≠ f p.2 then (1 : ℝ) else 0) = ((2 : ℝ) ^ n) ^ 2 * blrReject f := by let e : Vec n × Vec n ≃ Vec n × Vec n := { toFun := fun p => (p.1, p.1 + p.2) invFun := fun p => (p.1, p.1 + p.2) left_inv := fun p => Prod.ext rfl (by dsimp; rw [← add_assoc, vec_add_self, zero_add]) right_inv := fun p => Prod.ext rfl (by dsimp; rw [← add_assoc, vec_add_self, zero_add]) } have hbij : ∑ p : Vec n × Vec n, (if xor (f p.1) (f (p.1 + p.2)) ≠ f p.2 then (1 : ℝ) else 0) = ∑ p : Vec n × Vec n, (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) := Fintype.sum_equiv e _ _ (fun p => by have h : p.1 + (p.1 + p.2) = p.2 := by rw [← add_assoc, vec_add_self, zero_add] simp only [e, Equiv.coe_fn_mk, h]) rw [hbij]; unfold blrReject rw [mul_div_cancel₀ _ (ne_of_gt (sq_pos_of_pos (two_pow_pos n))), Finset.card_filter]; push_cast; rfl have hT2 : ∑ p : Vec n × Vec n, (if xor (f (x₀ + p.1)) (f (p.1 + p.2)) ≠ f (x₀ + p.2) then (1 : ℝ) else 0) = ((2 : ℝ) ^ n) ^ 2 * blrReject f := by let e : Vec n × Vec n ≃ Vec n × Vec n := { toFun := fun p => (x₀ + p.1, p.1 + p.2) invFun := fun p => (x₀ + p.1, (x₀ + p.1) + p.2) left_inv := fun p => Prod.ext (by dsimp; rw [← add_assoc, vec_add_self, zero_add]) (by dsimp have h1 : x₀ + (x₀ + p.1) = p.1 := by rw [← add_assoc, vec_add_self, zero_add] rw [h1, ← add_assoc, vec_add_self, zero_add]) right_inv := fun p => Prod.ext (by dsimp; rw [← add_assoc, vec_add_self, zero_add]) (by dsimp; rw [← add_assoc, vec_add_self, zero_add]) } have hbij : ∑ p : Vec n × Vec n, (if xor (f (x₀ + p.1)) (f (p.1 + p.2)) ≠ f (x₀ + p.2) then (1 : ℝ) else 0) = ∑ p : Vec n × Vec n, (if xor (f p.1) (f p.2) ≠ f (p.1 + p.2) then (1 : ℝ) else 0) := Fintype.sum_equiv e _ _ (fun p => by have hsum : (x₀ + p.1) + (p.1 + p.2) = x₀ + p.2 := by rw [add_assoc, ← add_assoc p.1 p.1 p.2, vec_add_self, zero_add] simp only [e, Equiv.coe_fn_mk, hsum]) rw [hbij]; unfold blrReject rw [mul_div_cancel₀ _ (ne_of_gt (sq_pos_of_pos (two_pow_pos n))), Finset.card_filter]; push_cast; rfl rw [hprob, hT1, hT2] at hub have hpos2 : (0 : ℝ) < ((2 : ℝ) ^ n) ^ 2 := sq_pos_of_pos (two_pow_pos n) nlinarith theorem coppersmith_two_ninths_plurality_linear {n : ℕ} (f : Vec n → Bool) (hblr : blrReject f < 2 / 9) (u v : Vec n) : xor (plurality f u) (plurality f v) = plurality f (u + v) := by by_contra hne -- Show q(u) + q(v) + q(u+v) ≥ 1 let q : Vec n → ℝ := fun x => (1 - |conv f x|) / 2 have hq_prob : ∀ x : Vec n, q x = (∑ y : Vec n, (if xor (f y) (f (x + y)) ≠ plurality f x then (1 : ℝ) else 0)) / (2 : ℝ) ^ n := by intro x have h1 : ∑ y : Vec n, (if xor (f y) (f (x + y)) ≠ plurality f x then (1 : ℝ) else 0) = ∑ y : Vec n, (1 - bSign (plurality f x) * (bSign (f y) * bSign (f (x + y)))) / 2 := Finset.sum_congr rfl (fun y _ => by rw [bSign_ne_indicator, bSign_xor]; ring) rw [h1, ← Finset.sum_div, Finset.sum_sub_distrib, ← Finset.mul_sum] simp only [Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] have hc : ∑ y : Vec n, bSign (f y) * bSign (f (x + y)) = (2 : ℝ) ^ n * conv f x := by unfold conv; exact (mul_div_cancel₀ _ (ne_of_gt (two_pow_pos n))).symm rw [hc, ← mul_assoc, mul_comm (bSign (plurality f x)), mul_assoc, bSign_plurality_mul_conv] have hpos := ne_of_gt (two_pow_pos n) dsimp only [q] field_simp [hpos] have htri : 1 ≤ q u + q v + q (u + v) := by rw [hq_prob u, hq_prob v, hq_prob (u + v), ← add_div, ← add_div, le_div_iff₀ (two_pow_pos n), one_mul] have hshift : ∑ y : Vec n, (if xor (f y) (f (v + y)) ≠ plurality f v then (1 : ℝ) else 0) = ∑ y : Vec n, (if xor (f (u + y)) (f ((u + v) + y)) ≠ plurality f v then (1 : ℝ) else 0) := by refine Fintype.sum_equiv (Equiv.addLeft u) _ _ (fun y => ?_) have h1 : u + (u + y) = y := by rw [← add_assoc, vec_add_self, zero_add] have h2 : (u + v) + (u + y) = v + y := by calc (u + v) + (u + y) = (u + u) + (v + y) := by abel _ = v + y := by rw [vec_add_self, zero_add] simp only [Equiv.coe_addLeft, h1, h2] rw [hshift, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib] calc (2 : ℝ) ^ n = ∑ _y : Vec n, (1 : ℝ) := by simp _ ≤ ∑ y : Vec n, ((if xor (f y) (f (u + y)) ≠ plurality f u then (1 : ℝ) else 0) + (if xor (f (u + y)) (f ((u + v) + y)) ≠ plurality f v then (1 : ℝ) else 0) + (if xor (f y) (f ((u + v) + y)) ≠ plurality f (u + v) then (1 : ℝ) else 0)) := by refine Finset.sum_le_sum (fun y _ => ?_) cases f y <;> cases f (u + y) <;> cases f ((u + v) + y) <;> cases hpu : plurality f u <;> cases hpv : plurality f v <;> cases hpuv : plurality f (u + v) <;> simp_all have hq_le : ∀ x : Vec n, q x ≤ 1 / 2 := fun x => by dsimp only [q]; linarith [abs_nonneg (conv f x)] have hmax : 1 / 3 ≤ q u ∨ 1 / 3 ≤ q v ∨ 1 / 3 ≤ q (u + v) := by by_contra h; push Not at h; linarith have hcontra : ∀ x : Vec n, 1 / 3 ≤ q x → False := by intro x hge have hbound : q x * (1 - q x) ≤ blrReject f := blrReject_ge_plurality_var f x have hle := hq_le x have h29 : (2 / 9 : ℝ) ≤ q x * (1 - q x) := by nlinarith linarith rcases hmax with h1 | h2 | h3 · exact hcontra u h1 · exact hcontra v h2 · exact hcontra (u + v) h3 /-! ### Infinite-Family Sharpness Witnesses (Hyperplane Sum-Free, BCHKS `45/128`, & Bent) -/ /-- **Theorem 2.7a (Sum-Free Hyperplane Family — Exact `3δ - 6δ²` for all `δ ≤ 1/4`)**: For EVERY `n ≥ 2` and EVERY `k ≤ 2^(n - 2)`, there exists `f : 𝔽₂ⁿ → Bool` with `linDist f = k / 2ⁿ` and `blrReject f = 3 (k / 2ⁿ) - 6 (k / 2ⁿ)²`. -/ theorem sumFree_hyperplane_witness_exact {n : ℕ} (hn : 2 ≤ n) {k : ℕ} (hk : k ≤ 2 ^ (n - 2)) : ∃ f : Vec n → Bool, linDist f = (k : ℝ) / (2 : ℝ) ^ n ∧ blrReject f = 3 * ((k : ℝ) / (2 : ℝ) ^ n) - 6 * ((k : ℝ) / (2 : ℝ) ^ n) ^ 2 := by let i₀ : Fin n := ⟨0, by omega⟩ let H₁ : Finset (Vec n) := Finset.univ.filter (fun x : Vec n => x i₀ = 1) have hH₁_card : H₁.card = 2 ^ (n - 1) := by -- Bijection with Vec (n - 1) via dropping coordinate 0 have hcard_half : 2 * H₁.card = 2 ^ n := by let H₀ : Finset (Vec n) := Finset.univ.filter (fun x : Vec n => x i₀ = 0) have hdisj : Disjoint H₀ H₁ := by rw [Finset.disjoint_left]; intro x h0 h1 rw [Finset.mem_filter] at h0 h1; rw [h0.2] at h1; exact absurd h1.2 (by decide) have hunion : H₀ ∪ H₁ = Finset.univ := by ext x; simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, iff_true, H₀, H₁] exact zmod2_eq_zero_or_one (x i₀) have hbij : H₀.card = H₁.card := by refine Finset.card_bij (fun x _ => x + Pi.single i₀ 1) ?_ ?_ ?_ · intro x hx rw [Finset.mem_filter] at hx ⊢ refine ⟨Finset.mem_univ _, ?_⟩ simp [hx.2] · intro x _ y _ hxy have h := congrArg (· + Pi.single i₀ 1) hxy simpa [add_assoc, vec_add_self] using h · intro y hy rw [Finset.mem_filter] at hy refine ⟨y + Pi.single i₀ 1, ?_, by simp [add_assoc, vec_add_self]⟩ rw [Finset.mem_filter] refine ⟨Finset.mem_univ _, ?_⟩ simp [hy.2, zmod2_add_self] have htot := Finset.card_union_of_disjoint hdisj rw [hunion, Finset.card_univ, card_vec, hbij] at htot omega have hpow : 2 ^ n = 2 * 2 ^ (n - 1) := by conv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ n)] rw [pow_succ]; ring omega have hk_le : k ≤ H₁.card := by rw [hH₁_card] exact hk.trans (Nat.pow_le_pow_right (by norm_num) (by omega)) rcases Finset.exists_subset_card_eq hk_le with ⟨E, hEH₁, hEcard⟩ let f : Vec n → Bool := fun x => decide (x ∈ E) have hsumfree : ∀ x ∈ E, ∀ y ∈ E, x + y ∉ E := by intro x hx y hy hxy have hx1 := (Finset.mem_filter.mp (hEH₁ hx)).2 have hy1 := (Finset.mem_filter.mp (hEH₁ hy)).2 have hxy1 := (Finset.mem_filter.mp (hEH₁ hxy)).2 have h0 : (x + y) i₀ = 0 := by simp [hx1, hy1, zmod2_add_self] rw [h0] at hxy1; exact absurd hxy1 (by decide) have hdist0 : linDistAt f 0 = (k : ℝ) / (2 : ℝ) ^ n := by unfold linDistAt hammingDist have hfilt : Finset.univ.filter (fun x : Vec n => f x ≠ chiBool 0 x) = E := by ext x; simp [f, chiBool, innerProd_zero_left] rw [hfilt, hEcard] have hdist_min : ∀ a : Vec n, (k : ℝ) / (2 : ℝ) ^ n ≤ linDistAt f a := by intro a by_cases ha0 : a = 0 · rw [ha0, hdist0] · by_cases hae : a = Pi.single i₀ 1 · subst hae -- Distance to χ_{e₀} is (|H₁| - |E|) / 2^n = 1/2 - k/2^n ≥ k/2^n unfold linDistAt hammingDist refine div_le_div_of_nonneg_right ?_ (le_of_lt (two_pow_pos n)) have hsub : H₁ \ E ⊆ Finset.univ.filter (fun x : Vec n => f x ≠ chiBool (Pi.single i₀ 1) x) := by intro x hx rw [Finset.mem_sdiff] at hx rw [Finset.mem_filter] refine ⟨Finset.mem_univ _, ?_⟩ have hx1 := (Finset.mem_filter.mp hx.1).2 have hip : innerProd (Pi.single i₀ 1) x = 1 := by unfold innerProd rw [Finset.sum_eq_single i₀] · simp [hx1] · intro j _ hji; simp [Pi.single_eq_of_ne hji] · intro h; exact absurd (Finset.mem_univ i₀) h simp [f, hx.2, chiBool, hip] have hcard_le := Finset.card_le_card hsub rw [Finset.card_sdiff_of_subset hEH₁, hH₁_card, hEcard] at hcard_le have h2pow : 2 * 2 ^ (n - 2) = 2 ^ (n - 1) := by have : n - 1 = (n - 2) + 1 := by omega rw [this, pow_succ]; ring have : k ≤ 2 ^ (n - 1) - k := by omega exact_mod_cast this.trans hcard_le · -- a ∉ {0, e₀}: on {x i₀ = 0} (where f = false), χ_a takes value true on 2^(n-2) points! unfold linDistAt hammingDist refine div_le_div_of_nonneg_right ?_ (le_of_lt (two_pow_pos n)) have hex : ∃ j : Fin n, j ≠ i₀ ∧ a j ≠ 0 := by by_contra hall; push Not at hall by_cases ha_i0 : a i₀ = 0 · apply ha0; ext j by_cases hj : j = i₀ · rw [hj, ha_i0]; rfl · exact hall j hj · apply hae; ext j by_cases hj : j = i₀ · subst hj; simp only [Pi.single_eq_same] exact zmod2_eq_one_of_ne_zero ha_i0 · simp [Pi.single_eq_of_ne hj, hall j hj] rcases hex with ⟨j, hji₀, haj⟩ have haj1 : a j = 1 := zmod2_eq_one_of_ne_zero haj let A₀ : Finset (Vec n) := Finset.univ.filter (fun x : Vec n => x i₀ = 0 ∧ chiBool a x = false) let A₁ : Finset (Vec n) := Finset.univ.filter (fun x : Vec n => x i₀ = 0 ∧ chiBool a x = true) have hdisj : Disjoint A₀ A₁ := by rw [Finset.disjoint_left]; intro x h0 h1 rw [Finset.mem_filter] at h0 h1; rw [h0.2.2] at h1; exact absurd h1.2.2 (by decide) have hunion : A₀ ∪ A₁ = Finset.univ.filter (fun x : Vec n => x i₀ = 0) := by ext x; simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, A₀, A₁] cases chiBool a x <;> simp have hbij : A₀.card = A₁.card := by let ej : Vec n := Pi.single j 1 have hchi_ej : chiBool a ej = true := by have hip : innerProd a ej = 1 := by unfold innerProd; rw [Finset.sum_eq_single j] · simp [ej, haj1] · intro l _ hlj; simp [ej, Pi.single_eq_of_ne hlj] · intro h; exact absurd (Finset.mem_univ j) h simp [chiBool, hip] refine Finset.card_bij (fun x _ => x + ej) ?_ ?_ ?_ · intro x hx rw [Finset.mem_filter] at hx ⊢ refine ⟨Finset.mem_univ _, ?_, ?_⟩ · simp [ej, Pi.single_eq_of_ne (Ne.symm hji₀), hx.2.1] · rw [chiBool_add_right, hx.2.2, hchi_ej]; rfl · intro x _ y _ hxy have h := congrArg (· + ej) hxy simpa [add_assoc, vec_add_self] using h · intro y hy rw [Finset.mem_filter] at hy refine ⟨y + ej, ?_, by simp [add_assoc, vec_add_self]⟩ rw [Finset.mem_filter] refine ⟨Finset.mem_univ _, ?_, ?_⟩ · simp [ej, Pi.single_eq_of_ne (Ne.symm hji₀), hy.2.1] · rw [chiBool_add_right, hy.2.2, hchi_ej]; rfl have hH0_card : (Finset.univ.filter (fun x : Vec n => x i₀ = 0)).card = 2 ^ (n - 1) := by have hdisj' : Disjoint (Finset.univ.filter (fun x : Vec n => x i₀ = 0)) H₁ := by rw [Finset.disjoint_left]; intro x h0 h1 rw [Finset.mem_filter] at h0 h1; rw [h0.2] at h1; exact absurd h1.2 (by decide) have hunion' : (Finset.univ.filter (fun x : Vec n => x i₀ = 0)) ∪ H₁ = Finset.univ := by ext x; simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, iff_true, H₁] exact zmod2_eq_zero_or_one (x i₀) have htot := Finset.card_union_of_disjoint hdisj' rw [hunion', Finset.card_univ, card_vec, hH₁_card] at htot have hpow : 2 ^ n = 2 * 2 ^ (n - 1) := by conv_lhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ n)] rw [pow_succ]; ring omega have hA1_card : A₁.card = 2 ^ (n - 2) := by have htot := Finset.card_union_of_disjoint hdisj rw [hunion, hH0_card, hbij] at htot have hpow : 2 ^ (n - 1) = 2 * 2 ^ (n - 2) := by have : n - 1 = (n - 2) + 1 := by omega rw [this, pow_succ]; ring omega have hA1_sub : A₁ ⊆ Finset.univ.filter (fun x : Vec n => f x ≠ chiBool a x) := by intro x hx rw [Finset.mem_filter] at hx ⊢ refine ⟨Finset.mem_univ _, ?_⟩ have hxnotE : x ∉ E := fun hxE => by have hx1 := (Finset.mem_filter.mp (hEH₁ hxE)).2 rw [hx.2.1] at hx1; exact absurd hx1 (by decide) simp [f, hxnotE, hx.2.2] have hcard_le := Finset.card_le_card hA1_sub rw [hA1_card] at hcard_le exact_mod_cast hk.trans hcard_le refine ⟨f, ?_, ?_⟩ · apply le_antisymm · rw [← hdist0]; exact linDist_le f 0 · rcases exists_nearest_linear f with ⟨a, ha⟩ rw [ha]; exact hdist_min a · rw [blrReject_exact_sumFree_identity f 0, hdist0] have hEeq : Finset.univ.filter (fun x : Vec n => f x ≠ chiBool 0 x) = E := by ext x; simp [f, chiBool, innerProd_zero_left] rw [hEeq] have htrip0 : tripleDensity E = 0 := by unfold tripleDensity have hemp : (Finset.univ : Finset (Vec n × Vec n)).filter (fun p => p.1 ∈ E ∧ p.2 ∈ E ∧ p.1 + p.2 ∈ E) = ∅ := by ext p; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.notMem_empty, iff_false] intro ⟨h1, h2, h3⟩; exact hsumfree p.1 h1 p.2 h2 h3 rw [hemp]; simp rw [htrip0]; ring /-- Coordinate-projection lifting `liftFn hk g (x₀,…,x_{n-1}) = g (x₀,…,x_{k-1})`. -/ def liftFn {k n : ℕ} (hk : k ≤ n) (g : Vec k → Bool) (x : Vec n) : Bool := g (fun i : Fin k => x ⟨i.val, lt_of_lt_of_le i.isLt hk⟩) /-- Exact Walsh spectrum of a lifted function: supported on frequencies with `a_j = 0` for `j ≥ k`. -/ lemma walsh_liftFn {k n : ℕ} (hk : k ≤ n) (g : Vec k → Bool) (a : Vec n) : walsh (liftFn hk g) a = if ∀ j : Fin n, k ≤ j.val → a j = 0 then walsh g (fun i : Fin k => a ⟨i.val, lt_of_lt_of_le i.isLt hk⟩) else 0 := by by_cases htail : ∀ j : Fin n, k ≤ j.val → a j = 0 · rw [if_pos htail] -- Split Vec n ≃ Vec k × Vec (n - k) let e : Vec n ≃ Vec k × Vec (n - k) := { toFun := fun x => (fun i => x ⟨i.val, lt_of_lt_of_le i.isLt hk⟩, fun j => x ⟨k + j.val, by omega⟩) invFun := fun p i => if h : i.val < k then p.1 ⟨i.val, h⟩ else p.2 ⟨i.val - k, by omega⟩ left_inv := fun x => by ext i; by_cases h : i.val < k · simp [h] · simp only [h, ↓reduceDIte] congr 1; ext; simp only; omega right_inv := fun ⟨x, y⟩ => by ext i · simp [i.isLt] · have hnot : ¬ (k + i.val < k) := by omega simp [hnot] } have hchi : ∀ x : Vec n, chi a x = chi (fun i : Fin k => a ⟨i.val, lt_of_lt_of_le i.isLt hk⟩) (e x).1 := by intro x simp only [chi, chiBool] congr 2 have hip : innerProd a x = innerProd (fun i : Fin k => a ⟨i.val, lt_of_lt_of_le i.isLt hk⟩) (e x).1 := by unfold innerProd have hsplit : ∑ i : Fin n, a i * x i = ∑ i ∈ Finset.univ.filter (fun i : Fin n => i.val < k), a i * x i := by symm refine Finset.sum_subset (Finset.filter_subset _ _) (fun i _ hi => ?_) have hge : k ≤ i.val := by have : ¬ i.val < k := fun hlt => hi (Finset.mem_filter.mpr ⟨Finset.mem_univ i, hlt⟩) omega simp [htail i hge] rw [hsplit] symm refine Finset.sum_bij (fun (i : Fin k) _ => (⟨i.val, lt_of_lt_of_le i.isLt hk⟩ : Fin n)) ?_ ?_ ?_ ?_ · intro i _; exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, i.isLt⟩ · intro i₁ _ i₂ _ h; ext; simpa using congrArg Fin.val h · intro j hj have hlt := (Finset.mem_filter.mp hj).2 exact ⟨⟨j.val, hlt⟩, Finset.mem_univ _, rfl⟩ · intro i _; rfl rw [hip] unfold walsh have hsum : ∑ x : Vec n, bSign (liftFn hk g x) * chi a x = (2 : ℝ) ^ (n - k) * ∑ u : Vec k, bSign (g u) * chi (fun i : Fin k => a ⟨i.val, lt_of_lt_of_le i.isLt hk⟩) u := by have h1 : ∑ x : Vec n, bSign (liftFn hk g x) * chi a x = ∑ p : Vec k × Vec (n - k), bSign (g p.1) * chi (fun i : Fin k => a ⟨i.val, lt_of_lt_of_le i.isLt hk⟩) p.1 := Fintype.sum_equiv e _ _ (fun x => by rw [hchi x]; rfl) rw [h1, Fintype.sum_prod_type] simp only [Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat, ← Finset.mul_sum] rw [hsum] have hpow : (2 : ℝ) ^ n = (2 : ℝ) ^ (n - k) * (2 : ℝ) ^ k := by rw [← pow_add, Nat.sub_add_cancel hk] rw [hpow] have h1 := ne_of_gt (two_pow_pos (n - k)) have h2 := ne_of_gt (two_pow_pos k) field_simp [h1, h2] · rw [if_neg htail] push Not at htail rcases htail with ⟨j, hjk, haj⟩ have haj1 : a j = 1 := zmod2_eq_one_of_ne_zero haj let ej : Vec n := Pi.single j 1 have hlift_inv : ∀ x : Vec n, liftFn hk g (x + ej) = liftFn hk g x := by intro x; unfold liftFn; congr 1; ext i have hne : (⟨i.val, lt_of_lt_of_le i.isLt hk⟩ : Fin n) ≠ j := by intro h; have hv := congrArg Fin.val h; dsimp at hv; omega simp [ej, Pi.single_eq_of_ne hne] have hchi_ej : chi a ej = -1 := by have hip : innerProd a ej = 1 := by unfold innerProd; rw [Finset.sum_eq_single j] · simp [ej, haj1] · intro l _ hlj; simp [ej, Pi.single_eq_of_ne hlj] · intro h; exact absurd (Finset.mem_univ j) h simp [chi, chiBool, hip, bSign] unfold walsh have hshift : ∑ x : Vec n, bSign (liftFn hk g (x + ej)) * chi a (x + ej) = ∑ x : Vec n, bSign (liftFn hk g x) * chi a x := Fintype.sum_equiv (Equiv.addRight ej) _ _ (fun _ => rfl) have hneg : ∑ x : Vec n, bSign (liftFn hk g (x + ej)) * chi a (x + ej) = -(∑ x : Vec n, bSign (liftFn hk g x) * chi a x) := by calc ∑ x : Vec n, bSign (liftFn hk g (x + ej)) * chi a (x + ej) = ∑ x : Vec n, -(bSign (liftFn hk g x) * chi a x) := Finset.sum_congr rfl (fun x _ => by rw [hlift_inv, chi_add_right, hchi_ej]; ring) _ = -(∑ x : Vec n, bSign (liftFn hk g x) * chi a x) := by rw [Finset.sum_neg_distrib] have h0 : ∑ x : Vec n, bSign (liftFn hk g x) * chi a x = 0 := by linarith rw [h0, zero_div] lemma blrReject_liftFn {k n : ℕ} (hk : k ≤ n) (g : Vec k → Bool) : blrReject (liftFn hk g) = blrReject g := by rw [blrReject_eq_fourier, blrReject_eq_fourier] congr 1; congr 1 simp_rw [walsh_liftFn] have hsub : ∑ a : Vec n, (if ∀ j : Fin n, k ≤ j.val → a j = 0 then walsh g (fun i : Fin k => a ⟨i.val, lt_of_lt_of_le i.isLt hk⟩) else 0) ^ 3 = ∑ a ∈ Finset.univ.filter (fun a : Vec n => ∀ j : Fin n, k ≤ j.val → a j = 0), (walsh g (fun i : Fin k => a ⟨i.val, lt_of_lt_of_le i.isLt hk⟩)) ^ 3 := by rw [Finset.sum_filter] refine Finset.sum_congr rfl (fun a _ => by split_ifs <;> norm_num) rw [hsub] refine Finset.sum_bij (fun a _ => fun i : Fin k => a ⟨i.val, lt_of_lt_of_le i.isLt hk⟩) ?_ ?_ ?_ ?_ · intro _ _; exact Finset.mem_univ _ · intro a₁ ha₁ a₂ ha₂ heq have h1 := (Finset.mem_filter.mp ha₁).2 have h2 := (Finset.mem_filter.mp ha₂).2 ext j by_cases hj : j.val < k · exact congrFun heq ⟨j.val, hj⟩ · rw [h1 j (by omega), h2 j (by omega)] · intro b _ refine ⟨fun j => if h : j.val < k then b ⟨j.val, h⟩ else 0, ?_, ?_⟩ · rw [Finset.mem_filter] refine ⟨Finset.mem_univ _, fun j hj => by simp [not_lt.mpr hj]⟩ · ext i; simp [i.isLt] · intro _ _; rfl /-- The 4-variable BCHKS `C₅`-sum-free extremal witness `E₄ = {0011, 0100, 0110, 1000, 1001}` achieving exact `δ = 5/16` and `ρ_BLR = 45/128`. -/ def bchks4 (x : Vec 4) : Bool := (x 0 == 0 && x 1 == 0 && x 2 == 1 && x 3 == 1) || (x 0 == 0 && x 1 == 1 && x 2 == 0 && x 3 == 0) || (x 0 == 0 && x 1 == 1 && x 2 == 1 && x 3 == 0) || (x 0 == 1 && x 1 == 0 && x 2 == 0 && x 3 == 0) || (x 0 == 1 && x 1 == 0 && x 2 == 0 && x 3 == 1) lemma bchks4_walshInt_le_six : ∀ a : Vec 4, walshInt bchks4 a ≤ 6 := by decide lemma bchks4_walshInt_zero : walshInt bchks4 0 = 6 := by decide lemma bchks4_sum_walshInt_cube : ∑ a : Vec 4, (walshInt bchks4 a) ^ 3 = 1216 := by decide lemma bchks4_sum_walshInt_fourth : ∑ a : Vec 4, (walshInt bchks4 a) ^ 4 = 7936 := by decide /-- **Theorem 2.7b (Infinite-Family BCHKS `45/128` Extremal Witness & Non-Monotone Dip)**: For EVERY `n ≥ 4`, the lifted `C₅`-sum-free witness `bchksWitness n hn` satisfies EXACTLY: `linDist = 5/16`, `blrReject = 45/128 < 3/8`! Moreover at `n = 4`, it achieves exact equality in our finite-`n` Gowers-`U₂` theorem! -/ theorem bchks_45_128_witness_all_n {n : ℕ} (hn : 4 ≤ n) : linDist (liftFn hn bchks4) = 5 / 16 ∧ blrReject (liftFn hn bchks4) = 45 / 128 := by have hmax : ∀ a : Vec n, walsh (liftFn hn bchks4) a ≤ 3 / 8 := by intro a rw [walsh_liftFn] split_ifs · rw [walsh_eq_walshInt] have hle : (walshInt bchks4 (fun i : Fin 4 => a ⟨i.val, lt_of_lt_of_le i.isLt hn⟩) : ℝ) ≤ 6 := by exact_mod_cast bchks4_walshInt_le_six _ norm_num; linarith · norm_num have h0 : walsh (liftFn hn bchks4) 0 = 3 / 8 := by rw [walsh_liftFn] have htr : ∀ j : Fin n, 4 ≤ j.val → (0 : Vec n) j = 0 := fun _ _ => rfl rw [if_pos htr] have hzero : (fun i : Fin 4 => (0 : Vec n) ⟨i.val, lt_of_lt_of_le i.isLt hn⟩) = 0 := rfl rw [hzero, walsh_eq_walshInt, bchks4_walshInt_zero]; norm_num constructor · apply le_antisymm · have hle := linDist_le (liftFn hn bchks4) 0 rw [linDistAt_eq_walsh, h0] at hle; linarith · rcases exists_nearest_linear (liftFn hn bchks4) with ⟨a, ha⟩ rw [ha, linDistAt_eq_walsh]; linarith [hmax a] · rw [blrReject_liftFn, blrReject_eq_fourier] have hcube : ∑ a : Vec 4, (walsh bchks4 a) ^ 3 = 19 / 64 := by simp_rw [walsh_eq_walshInt, div_pow, ← Finset.sum_div] have hcast : ∑ a : Vec 4, ((walshInt bchks4 a : ℝ) ^ 3) = (1216 : ℝ) := by exact_mod_cast bchks4_sum_walshInt_cube rw [hcast]; norm_num rw [hcube]; norm_num theorem bchks4_hits_finite_n_gowersU2_equality : ((2 : ℝ) ^ 4 * (∑ a : Vec 4, (walsh bchks4 a) ^ 3) - bSign (bchks4 0)) ^ 2 = ((2 : ℝ) ^ 4 - 1) * ((2 : ℝ) ^ 4 * gowersU2Fourth bchks4 - 1) := by have hcube : ∑ a : Vec 4, (walsh bchks4 a) ^ 3 = 19 / 64 := by simp_rw [walsh_eq_walshInt, div_pow, ← Finset.sum_div] have hcast : ∑ a : Vec 4, ((walshInt bchks4 a : ℝ) ^ 3) = (1216 : ℝ) := by exact_mod_cast bchks4_sum_walshInt_cube rw [hcast]; norm_num have hu2 : gowersU2Fourth bchks4 = 31 / 256 := by unfold gowersU2Fourth simp_rw [walsh_eq_walshInt, div_pow, ← Finset.sum_div] have hcast : ∑ a : Vec 4, ((walshInt bchks4 a : ℝ) ^ 4) = (7936 : ℝ) := by exact_mod_cast bchks4_sum_walshInt_fourth rw [hcast]; norm_num have h0 : bSign (bchks4 0) = 1 := by have : bchks4 0 = false := by decide simp [this, bSign] rw [hcube, hu2, h0]; norm_num /-- Maiorana–McFarland bent function on `2m` variables: `b_m(x, y) = ⟨x, y⟩ mod 2`. -/ def bentFn (m : ℕ) (z : Vec (2 * m)) : Bool := decide (∑ i : Fin m, z ⟨i.val, by omega⟩ * z ⟨m + i.val, by omega⟩ ≠ 0) /-- Exact flat Walsh spectrum of `bentFn m` in every even dimension `2m`: `f̂(a, b) = χ_a(b) / 2^m`. -/ theorem walsh_bentFn (m : ℕ) (c : Vec (2 * m)) : walsh (bentFn m) c = chi (fun i : Fin m => c ⟨i.val, by omega⟩) (fun i : Fin m => c ⟨m + i.val, by omega⟩) / (2 : ℝ) ^ m := by let e : Vec (2 * m) ≃ Vec m × Vec m := { toFun := fun z => (fun i => z ⟨i.val, by omega⟩, fun i => z ⟨m + i.val, by omega⟩) invFun := fun p i => if h : i.val < m then p.1 ⟨i.val, h⟩ else p.2 ⟨i.val - m, by omega⟩ left_inv := fun z => by ext i; by_cases h : i.val < m · simp [h] · simp only [h, ↓reduceDIte] congr 1; ext; simp only; omega right_inv := fun ⟨x, y⟩ => by ext i · simp [i.isLt] · have hnot : ¬ (m + i.val < m) := by omega simp [hnot] } set a : Vec m := (e c).1 set b : Vec m := (e c).2 have hchi_split : ∀ z : Vec (2 * m), chi c z = chi a (e z).1 * chi b (e z).2 := by intro z simp only [chi, chiBool, ← zmod2_add_sign] congr 2 have hsum : innerProd c z = innerProd a (e z).1 + innerProd b (e z).2 := by unfold innerProd rw [← Finset.sum_filter_add_sum_filter_not Finset.univ (fun i : Fin (2 * m) => i.val < m)] congr 1 · symm refine Finset.sum_bij (fun (i : Fin m) _ => (⟨i.val, by omega⟩ : Fin (2 * m))) ?_ ?_ ?_ ?_ · intro i _; exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, i.isLt⟩ · intro i₁ _ i₂ _ h; ext; simpa using congrArg Fin.val h · intro j hj; exact ⟨⟨j.val, (Finset.mem_filter.mp hj).2⟩, Finset.mem_univ _, rfl⟩ · intro i _; rfl · symm refine Finset.sum_bij (fun (i : Fin m) _ => (⟨m + i.val, by omega⟩ : Fin (2 * m))) ?_ ?_ ?_ ?_ · intro i _ refine Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩ simp only; omega · intro i₁ _ i₂ _ h have hv := congrArg Fin.val h; dsimp at hv; ext; omega · intro j hj have hge : m ≤ j.val := not_lt.mp (Finset.mem_filter.mp hj).2 refine ⟨⟨j.val - m, by omega⟩, Finset.mem_univ _, ?_⟩ ext; dsimp; omega · intro i _; rfl rw [hsum] unfold walsh have hsum : ∑ z : Vec (2 * m), bSign (bentFn m z) * chi c z = (2 : ℝ) ^ m * chi a b := by have h1 : ∑ z : Vec (2 * m), bSign (bentFn m z) * chi c z = ∑ p : Vec m × Vec m, chi a p.1 * chi (p.1 + b) p.2 := by refine Fintype.sum_equiv e _ _ (fun z => ?_) rw [hchi_split z] have hb_eq : bSign (bentFn m z) = chi (e z).1 (e z).2 := rfl rw [hb_eq, chi_add_left]; ring rw [h1, Fintype.sum_prod_type] have hinner : ∀ x : Vec m, ∑ y : Vec m, chi a x * chi (x + b) y = chi a x * (if x + b = 0 then (2 : ℝ) ^ m else 0) := by intro x; rw [← Finset.mul_sum, sum_chi_eq] simp_rw [hinner] rw [Finset.sum_eq_single b] · simp [vec_add_self, mul_comm] · intro x _ hxb have hne : x + b ≠ 0 := by intro h; apply hxb calc x = x + (b + b) := by rw [vec_add_self, add_zero] _ = (x + b) + b := by rw [add_assoc] _ = b := by rw [h, zero_add] simp [hne] · intro hb; exact absurd (Finset.mem_univ b) hb rw [hsum] have hpow : (2 : ℝ) ^ (2 * m) = (2 : ℝ) ^ m * (2 : ℝ) ^ m := by rw [← pow_add, two_mul] rw [hpow] have hpos := ne_of_gt (two_pow_pos m) have hab_def : chi a b = chi (fun i : Fin m => c ⟨i.val, by omega⟩) (fun i : Fin m => c ⟨m + i.val, by omega⟩) := rfl rw [hab_def] field_simp [hpos] /-- **Theorem 2.7c (Maiorana–McFarland Bent Family — Exact Flatness, Distance, `U₂`, & BLR)**: For every `m ≥ 1` (`n = 2m`): - `|f̂(c)| = 2⁻ᵐ` for every `c` (perfectly flat spectrum), - `linDist (bentFn m) = 1/2 - 1 / 2^(m + 1)`, - `gowersU2Fourth (bentFn m) = 1 / 2^(2m)`, - `blrReject (bentFn m) = 1/2 - 1 / 2^(2m + 1)` (exponentially above `linDist` and achieving EXACT EQUALITY in our finite-`n` Gowers-`U₂` BLR bound!). -/ theorem maiorana_mcfarland_bent_exact (m : ℕ) : (∀ c : Vec (2 * m), |walsh (bentFn m) c| = 1 / (2 : ℝ) ^ m) ∧ linDist (bentFn m) = 1 / 2 - 1 / (2 : ℝ) ^ (m + 1) ∧ gowersU2Fourth (bentFn m) = 1 / (2 : ℝ) ^ (2 * m) ∧ blrReject (bentFn m) = 1 / 2 - 1 / (2 : ℝ) ^ (2 * m + 1) := by have hpos := two_pow_pos m have hpos2 := two_pow_pos (2 * m) have habs : ∀ c : Vec (2 * m), |walsh (bentFn m) c| = 1 / (2 : ℝ) ^ m := by intro c rw [walsh_bentFn, abs_div, abs_of_pos hpos, chi, bSign_abs] have hle : ∀ c : Vec (2 * m), walsh (bentFn m) c ≤ 1 / (2 : ℝ) ^ m := fun c => (le_abs_self _).trans (le_of_eq (habs c)) have h0 : walsh (bentFn m) 0 = 1 / (2 : ℝ) ^ m := by rw [walsh_bentFn] have h1 : (fun i : Fin m => (0 : Vec (2 * m)) ⟨i.val, by omega⟩) = 0 := rfl rw [h1, chi_zero_left] have halg_dist : (1 - 1 / (2 : ℝ) ^ m) / 2 = 1 / 2 - 1 / (2 : ℝ) ^ (m + 1) := by rw [pow_succ]; have hm := ne_of_gt hpos; field_simp [hm] refine ⟨habs, ?_, ?_, ?_⟩ · apply le_antisymm · have h := linDist_le (bentFn m) 0 rw [linDistAt_eq_walsh, h0, halg_dist] at h exact h · rcases exists_nearest_linear (bentFn m) with ⟨c, hc⟩ rw [hc, linDistAt_eq_walsh, ← halg_dist] linarith [hle c] · unfold gowersU2Fourth have h4 : ∀ c : Vec (2 * m), (walsh (bentFn m) c) ^ 4 = (1 / (2 : ℝ) ^ m) ^ 4 := by intro c have hsq : (walsh (bentFn m) c) ^ 2 = (1 / (2 : ℝ) ^ m) ^ 2 := by rw [← sq_abs, habs c] calc (walsh (bentFn m) c) ^ 4 = ((walsh (bentFn m) c) ^ 2) ^ 2 := by ring _ = ((1 / (2 : ℝ) ^ m) ^ 2) ^ 2 := by rw [hsq] _ = (1 / (2 : ℝ) ^ m) ^ 4 := by ring simp only [h4, Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat] have hpow : ((2 : ℝ) ^ m) ^ 4 = (2 : ℝ) ^ (2 * m) * (2 : ℝ) ^ (2 * m) := by rw [← pow_mul, ← pow_add]; congr 1; omega rw [one_div, inv_pow, hpow] have h2m := ne_of_gt hpos2 field_simp [h2m] · rw [blrReject_eq_fourier] let e : Vec (2 * m) ≃ Vec m × Vec m := { toFun := fun z => (fun i => z ⟨i.val, by omega⟩, fun i => z ⟨m + i.val, by omega⟩) invFun := fun p i => if h : i.val < m then p.1 ⟨i.val, h⟩ else p.2 ⟨i.val - m, by omega⟩ left_inv := fun z => by ext i; by_cases h : i.val < m · simp [h] · simp only [h, ↓reduceDIte] congr 1; ext; simp only; omega right_inv := fun ⟨x, y⟩ => by ext i · simp [i.isLt] · have hnot : ¬ (m + i.val < m) := by omega simp [hnot] } have hcube : ∑ c : Vec (2 * m), (walsh (bentFn m) c) ^ 3 = 1 / (2 : ℝ) ^ (2 * m) := by have hterm : ∀ c : Vec (2 * m), (walsh (bentFn m) c) ^ 3 = chi (e c).1 (e c).2 / ((2 : ℝ) ^ m) ^ 3 := by intro c rw [walsh_bentFn, div_pow] have hch3 : (chi (e c).1 (e c).2) ^ 3 = chi (e c).1 (e c).2 := by have := chi_sq (e c).1 (e c).2 linear_combination chi (e c).1 (e c).2 * this exact congrArg (· / ((2 : ℝ) ^ m) ^ 3) hch3 simp_rw [hterm, ← Finset.sum_div] have hsum_chi : ∑ c : Vec (2 * m), chi (e c).1 (e c).2 = (2 : ℝ) ^ m := by rw [Fintype.sum_equiv e (fun c => chi (e c).1 (e c).2) (fun p => chi p.1 p.2) (fun _ => rfl), Fintype.sum_prod_type] simp_rw [sum_chi_eq] rw [Finset.sum_eq_single (0 : Vec m)] · simp · intro a _ ha; simp [ha] · intro h; exact absurd (Finset.mem_univ (0 : Vec m)) h rw [hsum_chi] have hpow : ((2 : ℝ) ^ m) ^ 3 = (2 : ℝ) ^ m * (2 : ℝ) ^ (2 * m) := by rw [← pow_mul, ← pow_add]; congr 1; omega rw [hpow] have hm := ne_of_gt hpos have h2m := ne_of_gt hpos2 field_simp [hm, h2m] rw [hcube, pow_succ] have h2m := ne_of_gt hpos2 field_simp [h2m] /-! ### Gowers-`U₃` Uniformity Norm, Hyperplane Annihilation & Reed–Muller Degree-2 Testing -/ /-- Multiplicative discrete derivative `(Δ_h f)(x) = f(x) ⊕ f(x + h)`. -/ def deriv {n : ℕ} (f : Vec n → Bool) (h : Vec n) (x : Vec n) : Bool := xor (f x) (f (x + h)) /-- Eighth power of the Gowers `U₃` norm `‖f‖_{U³}⁸ = E_h[‖Δ_h f‖_{U²}⁴]`. -/ noncomputable def gowersU3Eighth {n : ℕ} (f : Vec n → Bool) : ℝ := (∑ h : Vec n, gowersU2Fourth (deriv f h)) / (2 : ℝ) ^ n /-- 8-query AKKLR/BKSZ Reed–Muller degree-2 test rejection probability: `Pr_{x, h₁, h₂, h₃}[⊕_{S ⊆ {1,2,3}} f(x + ∑_{i ∈ S} h_i) = true]`. -/ def cubeParity {n : ℕ} (f : Vec n → Bool) (x h₁ h₂ h₃ : Vec n) : Bool := xor (xor (xor (f x) (f (x + h₁))) (xor (f (x + h₂)) (f (x + h₁ + h₂)))) (xor (xor (f (x + h₃)) (f (x + h₁ + h₃))) (xor (f (x + h₂ + h₃)) (f (x + h₁ + h₂ + h₃)))) noncomputable def rm2Reject {n : ℕ} (f : Vec n → Bool) : ℝ := (((Finset.univ : Finset (Vec n × Vec n × Vec n × Vec n)).filter (fun q => cubeParity f q.1 q.2.1 q.2.2.1 q.2.2.2 = true)).card : ℝ) / ((2 : ℝ) ^ n) ^ 4 /-- **Theorem 2.8a (Exact Gowers-`U₃` Identity for 8-Query Reed–Muller Degree-2 Testing)**: `ρ_{RM₂}(f) = (1 - ‖f‖_{U³}⁸) / 2`. -/ theorem rm2Reject_eq_gowersU3 {n : ℕ} (f : Vec n → Bool) : rm2Reject f = (1 - gowersU3Eighth f) / 2 := by have hsign_cube : ∀ x h₁ h₂ h₃ : Vec n, bSign (cubeParity f x h₁ h₂ h₃) = (bSign (deriv f h₃ x) * bSign (deriv f h₃ (x + h₁))) * (bSign (deriv f h₃ (x + h₂)) * bSign (deriv f h₃ ((x + h₂) + h₁))) := by intro x h₁ h₂ h₃ simp only [cubeParity, deriv, bSign_xor] have ha1 : x + h₂ + h₁ = x + h₁ + h₂ := by rw [add_assoc, add_comm h₂ h₁, ← add_assoc] rw [ha1]; ring have hu2_cube : ∀ g : Vec n → Bool, ∑ p : Vec n × Vec n × Vec n, (bSign (g p.1) * bSign (g (p.1 + p.2.1))) * (bSign (g (p.1 + p.2.2)) * bSign (g ((p.1 + p.2.2) + p.2.1))) = ((2 : ℝ) ^ n) ^ 3 * gowersU2Fourth g := by intro g rw [gowersU2Fourth_eq_avg_conv_sq] rw [Fintype.sum_prod_type] simp_rw [Fintype.sum_prod_type] -- Reorder to sum over h₁ first, then (x, y = x + h₂): -- ∑_x ∑_{h₁} ∑_{h₂} (g(x)g(x+h₁))(g(x+h₂)g(x+h₂+h₁)) = ∑_{h₁} (∑_x g(x)g(x+h₁))² calc ∑ x : Vec n, ∑ h₁ : Vec n, ∑ h₂ : Vec n, (bSign (g x) * bSign (g (x + h₁))) * (bSign (g (x + h₂)) * bSign (g ((x + h₂) + h₁))) = ∑ h₁ : Vec n, ∑ x : Vec n, ∑ h₂ : Vec n, (bSign (g x) * bSign (g (x + h₁))) * (bSign (g (x + h₂)) * bSign (g ((x + h₂) + h₁))) := Finset.sum_comm _ = ∑ h₁ : Vec n, ∑ x : Vec n, (bSign (g x) * bSign (g (x + h₁))) * (∑ y : Vec n, bSign (g y) * bSign (g (y + h₁))) := by refine Finset.sum_congr rfl (fun h₁ _ => Finset.sum_congr rfl (fun x _ => ?_)) rw [← Finset.mul_sum] congr 1 exact Fintype.sum_equiv (Equiv.addLeft x) _ _ (fun _ => rfl) _ = ∑ h₁ : Vec n, ((2 : ℝ) ^ n * conv g h₁) ^ 2 := by refine Finset.sum_congr rfl (fun h₁ _ => ?_) rw [← Finset.sum_mul, ← sq] congr 1 unfold conv rw [mul_div_cancel₀ _ (ne_of_gt (two_pow_pos n))] exact Finset.sum_congr rfl (fun y _ => by rw [add_comm y h₁]) _ = ((2 : ℝ) ^ n) ^ 3 * ((∑ h₁ : Vec n, (conv g h₁) ^ 2) / (2 : ℝ) ^ n) := by simp_rw [mul_pow, ← Finset.mul_sum] have hpos := ne_of_gt (two_pow_pos n) field_simp [hpos] unfold rm2Reject rw [Finset.card_filter]; push_cast have hpt : ∀ q : Vec n × Vec n × Vec n × Vec n, (if cubeParity f q.1 q.2.1 q.2.2.1 q.2.2.2 = true then (1 : ℝ) else 0) = (1 - bSign (cubeParity f q.1 q.2.1 q.2.2.1 q.2.2.2)) / 2 := fun q => by cases cubeParity f q.1 q.2.1 q.2.2.1 q.2.2.2 <;> norm_num [bSign] rw [Finset.sum_congr rfl (fun q _ => hpt q), ← Finset.sum_div, Finset.sum_sub_distrib] have h1 : ∑ _q : Vec n × Vec n × Vec n × Vec n, (1 : ℝ) = ((2 : ℝ) ^ n) ^ 4 := by simp [Fintype.card_prod]; ring have h2 : ∑ q : Vec n × Vec n × Vec n × Vec n, bSign (cubeParity f q.1 q.2.1 q.2.2.1 q.2.2.2) = ((2 : ℝ) ^ n) ^ 4 * gowersU3Eighth f := by let e : (Vec n × Vec n × Vec n × Vec n) ≃ (Vec n × (Vec n × Vec n × Vec n)) := { toFun := fun q => (q.2.2.2, (q.1, q.2.1, q.2.2.1)) invFun := fun r => (r.2.1, r.2.2.1, r.2.2.2, r.1) left_inv := fun _ => rfl right_inv := fun _ => rfl } rw [Fintype.sum_equiv e _ (fun r => (bSign (deriv f r.1 r.2.1) * bSign (deriv f r.1 (r.2.1 + r.2.2.1))) * (bSign (deriv f r.1 (r.2.1 + r.2.2.2)) * bSign (deriv f r.1 ((r.2.1 + r.2.2.2) + r.2.2.1)))) (fun q => hsign_cube q.1 q.2.1 q.2.2.1 q.2.2.2)] rw [Fintype.sum_prod_type] simp_rw [hu2_cube, ← Finset.mul_sum] unfold gowersU3Eighth have hpos := ne_of_gt (two_pow_pos n) field_simp [hpos] rw [h1, h2] have hpos := ne_of_gt (two_pow_pos n) field_simp [hpos] /-- **Theorem 2.8b (Gowers Uniformity Monotonicity)**: `(‖f‖_{U²}⁴)² ≤ ‖f‖_{U³}⁸`. -/ theorem gowers_u2_le_u3 {n : ℕ} (f : Vec n → Bool) : (gowersU2Fourth f) ^ 2 ≤ gowersU3Eighth f := by have h4 : ∀ h : Vec n, (conv f h) ^ 4 ≤ gowersU2Fourth (deriv f h) := by intro h have hwalsh0 : walsh (deriv f h) 0 = conv f h := by unfold walsh conv deriv congr 1 exact Finset.sum_congr rfl (fun x _ => by rw [chi_zero_left, mul_one, bSign_xor, add_comm x h]) rw [← hwalsh0] unfold gowersU2Fourth exact Finset.single_le_sum (f := fun a : Vec n => (walsh (deriv f h) a) ^ 4) (fun a _ => by positivity) (Finset.mem_univ (0 : Vec n)) rw [gowersU2Fourth_eq_avg_conv_sq] unfold gowersU3Eighth have hpos := two_pow_pos n rw [div_pow, div_le_div_iff₀ (sq_pos_of_pos hpos) hpos] have hcs := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset (Vec n)) (fun _ => (1 : ℝ)) (fun h => (conv f h) ^ 2) simp only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, card_vec, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] at hcs have hsum4 : ∑ h : Vec n, ((conv f h) ^ 2) ^ 2 ≤ ∑ h : Vec n, gowersU2Fourth (deriv f h) := Finset.sum_le_sum (fun h _ => by have heq : ((conv f h) ^ 2) ^ 2 = (conv f h) ^ 4 := by ring rw [heq]; exact h4 h) have hmul : (∑ h : Vec n, (conv f h) ^ 2) ^ 2 ≤ (2 : ℝ) ^ n * ∑ h : Vec n, gowersU2Fourth (deriv f h) := hcs.trans (mul_le_mul_of_nonneg_left hsum4 (le_of_lt hpos)) nlinarith /-- **Hyperplane Annihilation Lemma**: For any `h ≠ 0` and any `a` with `⟨a, h⟩ ≠ 0`, `(Δ_h f)^̂(a) = 0`, because `Δ_h f` is invariant under translation by `h`. -/ lemma deriv_walsh_annihilation {n : ℕ} (f : Vec n → Bool) (h a : Vec n) (hip : innerProd a h ≠ 0) : walsh (deriv f h) a = 0 := by have hchih : chi a h = -1 := by simp [chi, chiBool, hip, bSign] have hinv : ∀ x : Vec n, deriv f h (x + h) = deriv f h x := by intro x; unfold deriv rw [add_assoc, vec_add_self, add_zero, Bool.xor_comm] unfold walsh have hshift : ∑ x : Vec n, bSign (deriv f h (x + h)) * chi a (x + h) = ∑ x : Vec n, bSign (deriv f h x) * chi a x := Fintype.sum_equiv (Equiv.addRight h) _ _ (fun _ => rfl) have hneg : ∑ x : Vec n, bSign (deriv f h (x + h)) * chi a (x + h) = -(∑ x : Vec n, bSign (deriv f h x) * chi a x) := by calc ∑ x : Vec n, bSign (deriv f h (x + h)) * chi a (x + h) = ∑ x : Vec n, -(bSign (deriv f h x) * chi a x) := Finset.sum_congr rfl (fun x _ => by rw [hinv, chi_add_right, hchih]; ring) _ = -(∑ x : Vec n, bSign (deriv f h x) * chi a x) := by rw [Finset.sum_neg_distrib] have h0 : ∑ x : Vec n, bSign (deriv f h x) * chi a x = 0 := by linarith rw [h0, zero_div] /-- For every nonzero `h`, `‖Δ_h f‖_{U²}⁴ ≥ 2 / 2ⁿ` (double the generic Parseval floor!). -/ lemma deriv_gowersU2_ge_two_div {n : ℕ} (f : Vec n → Bool) {h : Vec n} (hh : h ≠ 0) : 2 / (2 : ℝ) ^ n ≤ gowersU2Fourth (deriv f h) := by set Hperp : Finset (Vec n) := Finset.univ.filter (fun a : Vec n => innerProd a h = 0) have hcard_perp : (Hperp.card : ℝ) = (2 : ℝ) ^ n / 2 := by have hsum := sum_chi_eq h rw [if_neg hh] at hsum have hc1 : (∑ a : Vec n, if innerProd a h = 0 then (1 : ℝ) else 0) = (Hperp.card : ℝ) := by simp [Hperp] have hc2 : (∑ a : Vec n, if innerProd a h ≠ 0 then (1 : ℝ) else 0) = ((Finset.univ.filter (fun a : Vec n => innerProd a h ≠ 0)).card : ℝ) := by rw [Finset.card_filter]; push_cast; rfl have hsplit : ∑ a : Vec n, chi h a = (Hperp.card : ℝ) - ((Finset.univ.filter (fun a : Vec n => innerProd a h ≠ 0)).card : ℝ) := by rw [← hc1, ← hc2, ← Finset.sum_sub_distrib] refine Finset.sum_congr rfl (fun a _ => ?_) rw [chi_comm] by_cases h0 : innerProd a h = 0 · simp [chi, chiBool, h0, bSign] · simp [chi, chiBool, h0, bSign] have hadd : Hperp.card + (Finset.univ.filter (fun a : Vec n => innerProd a h ≠ 0)).card = 2 ^ n := by have := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset (Vec n))) (p := fun a : Vec n => innerProd a h = 0) simpa [card_vec, Hperp] using this have haddR : (Hperp.card : ℝ) + ((Finset.univ.filter (fun a : Vec n => innerProd a h ≠ 0)).card : ℝ) = (2 : ℝ) ^ n := by exact_mod_cast hadd linarith have hpars_perp : ∑ a ∈ Hperp, (walsh (deriv f h) a) ^ 2 = 1 := by rw [← walsh_parseval (deriv f h)] refine Finset.sum_subset (Finset.subset_univ _) (fun a _ ha => ?_) have hip : innerProd a h ≠ 0 := fun h0 => ha (Finset.mem_filter.mpr ⟨Finset.mem_univ _, h0⟩) rw [deriv_walsh_annihilation f h a hip]; norm_num have hcs := Finset.sum_mul_sq_le_sq_mul_sq Hperp (fun _ => (1 : ℝ)) (fun a => (walsh (deriv f h) a) ^ 2) simp only [one_mul, one_pow, Finset.sum_const, nsmul_eq_mul, mul_one, hpars_perp] at hcs have hu2_ge : ∑ a ∈ Hperp, ((walsh (deriv f h) a) ^ 2) ^ 2 ≤ gowersU2Fourth (deriv f h) := by unfold gowersU2Fourth calc ∑ a ∈ Hperp, ((walsh (deriv f h) a) ^ 2) ^ 2 = ∑ a ∈ Hperp, (walsh (deriv f h) a) ^ 4 := Finset.sum_congr rfl (fun a _ => by ring) _ ≤ ∑ a : Vec n, (walsh (deriv f h) a) ^ 4 := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun a _ _ => by positivity) rw [hcard_perp] at hcs have hpos := two_pow_pos n have hmul : 1 ≤ ((2 : ℝ) ^ n / 2) * gowersU2Fourth (deriv f h) := hcs.trans (mul_le_mul_of_nonneg_left hu2_ge (by positivity)) rw [div_le_iff₀ hpos] linarith /-- **Theorem 2.8c (NEW Sharp Universal Finite-`n` Gowers-`U₃` Floor & RM₂ Test Ceiling)**: For EVERY `n ≥ 1` and EVERY Boolean function `f : 𝔽₂ⁿ → Bool`: `‖f‖_{U³}⁸ ≥ (3 · 2ⁿ - 2) / 2^(2n)` and equivalently: `ρ_{RM₂}(f) ≤ 1/2 - (3 · 2ⁿ - 2) / (2 · 2^(2n))`. -/ theorem gowersU3_sharp_finite_n_floor {n : ℕ} (f : Vec n → Bool) : (3 * (2 : ℝ) ^ n - 2) / ((2 : ℝ) ^ n) ^ 2 ≤ gowersU3Eighth f := by unfold gowersU3Eighth have hpos := two_pow_pos n rw [div_le_div_iff₀ (sq_pos_of_pos hpos) hpos] have h0 : gowersU2Fourth (deriv f 0) = 1 := by have hconst : deriv f 0 = fun _ => false := by ext x; unfold deriv; simp rw [hconst] have hw : ∀ a : Vec n, walsh (fun _ => false) a = if a = 0 then 1 else 0 := by intro a; unfold walsh have hb : ∀ x : Vec n, bSign false * chi a x = chi a x := fun x => by simp [bSign] simp_rw [hb, sum_chi_eq] split_ifs · exact div_self (ne_of_gt hpos) · simp unfold gowersU2Fourth simp_rw [hw] rw [Finset.sum_eq_single (0 : Vec n)] · simp · intro a _ ha; simp [ha] · intro h; exact absurd (Finset.mem_univ (0 : Vec n)) h set S0 : Finset (Vec n) := Finset.univ.erase (0 : Vec n) have hsplit : ∑ h : Vec n, gowersU2Fourth (deriv f h) = 1 + ∑ h ∈ S0, gowersU2Fourth (deriv f h) := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ (0 : Vec n)), h0] have hS0 : ((2 : ℝ) ^ n - 1) * (2 / (2 : ℝ) ^ n) ≤ ∑ h ∈ S0, gowersU2Fourth (deriv f h) := by calc ((2 : ℝ) ^ n - 1) * (2 / (2 : ℝ) ^ n) = ∑ _h ∈ S0, (2 / (2 : ℝ) ^ n) := by simp only [Finset.sum_const, S0, Finset.card_erase_of_mem (Finset.mem_univ (0 : Vec n)), Finset.card_univ, card_vec, nsmul_eq_mul] have h1 : 1 ≤ 2 ^ n := Nat.one_le_two_pow rw [Nat.cast_sub h1]; simp _ ≤ ∑ h ∈ S0, gowersU2Fourth (deriv f h) := Finset.sum_le_sum (fun h hh => deriv_gowersU2_ge_two_div f (Finset.mem_erase.mp hh).1) have halg : (3 * (2 : ℝ) ^ n - 2) * (2 : ℝ) ^ n = (1 + ((2 : ℝ) ^ n - 1) * (2 / (2 : ℝ) ^ n)) * ((2 : ℝ) ^ n) ^ 2 := by have hne := ne_of_gt hpos field_simp [hne]; ring nlinarith [sq_pos_of_pos hpos] theorem rm2Reject_sharp_ceiling {n : ℕ} (f : Vec n → Bool) : rm2Reject f ≤ 1 / 2 - (3 * (2 : ℝ) ^ n - 2) / (2 * ((2 : ℝ) ^ n) ^ 2) := by rw [rm2Reject_eq_gowersU3] have h := gowersU3_sharp_finite_n_floor f have hpos := sq_pos_of_pos (two_pow_pos n) have hdiv : (3 * (2 : ℝ) ^ n - 2) / (2 * ((2 : ℝ) ^ n) ^ 2) = ((3 * (2 : ℝ) ^ n - 2) / ((2 : ℝ) ^ n) ^ 2) / 2 := by ring linarith /-- Exact completeness of `RM₂` on all Maiorana–McFarland bent quadratics `bentFn m`: every bent quadratic satisfies `‖bentFn m‖_{U³}⁸ = 1` and `ρ_{RM₂}(bentFn m) = 0`. -/ theorem bentFn_rm2_complete (m : ℕ) : gowersU3Eighth (bentFn m) = 1 ∧ rm2Reject (bentFn m) = 0 := by have hcube0 : ∀ x h₁ h₂ h₃ : Vec (2 * m), cubeParity (bentFn m) x h₁ h₂ h₃ = false := by intro x h₁ h₂ h₃ -- Check parity of ∑_{S ⊆ {1,2,3}} ⟨x_S, y_S⟩ in ZMod 2: vanishes identically for quadratic! have hsign1 : bSign (cubeParity (bentFn m) x h₁ h₂ h₃) = 1 := by have hterm : ∀ z : Vec (2 * m), bSign (bentFn m z) = bSign (decide (∑ i : Fin m, z ⟨i.val, by omega⟩ * z ⟨m + i.val, by omega⟩ ≠ 0)) := fun _ => rfl simp only [cubeParity, bSign_xor, hterm] -- Combine all 8 signs into one ZMod 2 sum! have hcomb : ∀ u₁ u₂ u₃ u₄ u₅ u₆ u₇ u₈ : ZMod 2, bSign (decide (u₁ ≠ 0)) * bSign (decide (u₂ ≠ 0)) * (bSign (decide (u₃ ≠ 0)) * bSign (decide (u₄ ≠ 0))) * (bSign (decide (u₅ ≠ 0)) * bSign (decide (u₆ ≠ 0)) * (bSign (decide (u₇ ≠ 0)) * bSign (decide (u₈ ≠ 0)))) = bSign (decide (u₁ + u₂ + u₃ + u₄ + u₅ + u₆ + u₇ + u₈ ≠ 0)) := by intro u₁ u₂ u₃ u₄ u₅ u₆ u₇ u₈ simp only [zmod2_add_sign]; ring rw [hcomb] have hsum0 : (∑ i : Fin m, x ⟨i.val, by omega⟩ * x ⟨m + i.val, by omega⟩) + (∑ i : Fin m, (x + h₁) ⟨i.val, by omega⟩ * (x + h₁) ⟨m + i.val, by omega⟩) + (∑ i : Fin m, (x + h₂) ⟨i.val, by omega⟩ * (x + h₂) ⟨m + i.val, by omega⟩) + (∑ i : Fin m, (x + h₁ + h₂) ⟨i.val, by omega⟩ * (x + h₁ + h₂) ⟨m + i.val, by omega⟩) + (∑ i : Fin m, (x + h₃) ⟨i.val, by omega⟩ * (x + h₃) ⟨m + i.val, by omega⟩) + (∑ i : Fin m, (x + h₁ + h₃) ⟨i.val, by omega⟩ * (x + h₁ + h₃) ⟨m + i.val, by omega⟩) + (∑ i : Fin m, (x + h₂ + h₃) ⟨i.val, by omega⟩ * (x + h₂ + h₃) ⟨m + i.val, by omega⟩) + (∑ i : Fin m, (x + h₁ + h₂ + h₃) ⟨i.val, by omega⟩ * (x + h₁ + h₂ + h₃) ⟨m + i.val, by omega⟩) = 0 := by simp only [← Finset.sum_add_distrib] refine Finset.sum_eq_zero (fun i _ => ?_) simp only [Pi.add_apply] have h2 : ∀ a : ZMod 2, a + a = 0 := fun a => by fin_cases a <;> decide have hr : ∀ a b c d e f g k : ZMod 2, a * e + (a + b) * (e + f) + (a + c) * (e + g) + (a + b + c) * (e + f + g) + (a + d) * (e + k) + (a + b + d) * (e + f + k) + (a + c + d) * (e + g + k) + (a + b + c + d) * (e + f + g + k) = 0 := by intro a b c d e f g k have hlin : a * e + (a + b) * (e + f) + (a + c) * (e + g) + (a + b + c) * (e + f + g) + (a + d) * (e + k) + (a + b + d) * (e + f + k) + (a + c + d) * (e + g + k) + (a + b + c + d) * (e + f + g + k) = (a * e + a * e) + (a * e + a * e) + (a * e + a * e) + (a * e + a * e) + (a * f + a * f) + (a * f + a * f) + (a * g + a * g) + (a * g + a * g) + (a * k + a * k) + (a * k + a * k) + (b * e + b * e) + (b * e + b * e) + (b * f + b * f) + (b * f + b * f) + (b * g + b * g) + (b * k + b * k) + (c * e + c * e) + (c * e + c * e) + (c * f + c * f) + (c * g + c * g) + (c * g + c * g) + (c * k + c * k) + (d * e + d * e) + (d * e + d * e) + (d * f + d * f) + (d * g + d * g) + (d * k + d * k) + (d * k + d * k) := by ring rw [hlin] simp [h2] exact hr _ _ _ _ _ _ _ _ rw [hsum0]; simp [bSign] cases hc : cubeParity (bentFn m) x h₁ h₂ h₃ · rfl · rw [hc] at hsign1; norm_num [bSign] at hsign1 have hrm0 : rm2Reject (bentFn m) = 0 := by unfold rm2Reject have hemp : (Finset.univ : Finset (Vec (2 * m) × Vec (2 * m) × Vec (2 * m) × Vec (2 * m))).filter (fun q => cubeParity (bentFn m) q.1 q.2.1 q.2.2.1 q.2.2.2 = true) = ∅ := by ext q; simp [hcube0] rw [hemp]; simp have hu3 : gowersU3Eighth (bentFn m) = 1 := by have h := rm2Reject_eq_gowersU3 (bentFn m) linarith exact ⟨hu3, hrm0⟩ /-- Cubic witness `x₀ x₁ x₂` on `𝔽₂³`, achieving the EXACT finite-`3` Gowers-`U₃` floor `11/32` and the EXACT `RM₂` testing ceiling `21/64`. -/ def cubicWitness (x : Vec 3) : Bool := (x 0 == 1) && (x 1 == 1) && (x 2 == 1) lemma cubicWitness_u3_sumInt : ∑ h : Vec 3, ∑ a : Vec 3, (walshInt (deriv cubicWitness h) a) ^ 4 = 11264 := by decide /-- **Theorem 2.8d (Exact Extremal Cubic Witness for `RM₂` & Gowers-`U₃`)**: `cubicWitness` on `𝔽₂³` achieves exact equality `‖f‖_{U³}⁸ = 11/32` and `ρ_{RM₂}(f) = 21/64`, matching the universal finite-`n` ceiling `(3 · 2ⁿ - 2) / 2^(2n)` at `n = 3`. -/ theorem cubic_witness_rm2_exact_ceiling : gowersU3Eighth cubicWitness = 11 / 32 ∧ rm2Reject cubicWitness = 21 / 64 := by have hu3 : gowersU3Eighth cubicWitness = 11 / 32 := by unfold gowersU3Eighth gowersU2Fourth simp_rw [walsh_eq_walshInt, div_pow, ← Finset.sum_div] have hcast : ∑ h : Vec 3, ∑ a : Vec 3, ((walshInt (deriv cubicWitness h) a : ℝ) ^ 4) = (11264 : ℝ) := by exact_mod_cast cubicWitness_u3_sumInt rw [hcast]; norm_num have hrm : rm2Reject cubicWitness = 21 / 64 := by rw [rm2Reject_eq_gowersU3, hu3]; norm_num exact ⟨hu3, hrm⟩ /-- **Theorem 2.8e (Exact Degree-2 Reed–Muller Pairwise-Lower & 3-Wise-Upper Soundness Sandwich)**: For EVERY `f : 𝔽₂ⁿ → Bool` and EVERY quadratic function `q` (`∀ x h₁ h₂ h₃, cubeParity q = false`) at Hamming distance `δ = hammingDist f q`: `8 δ - 56 δ² ≤ ρ_{RM₂}(f) ≤ 8 δ - 56 δ² + 224 δ³`. -/ theorem rm2Reject_quadratic_lower_cubic_upper {n : ℕ} (f q : Vec n → Bool) (hq : ∀ x h₁ h₂ h₃ : Vec n, cubeParity q x h₁ h₂ h₃ = false) : 8 * hammingDist f q - 56 * (hammingDist f q) ^ 2 ≤ rm2Reject f ∧ rm2Reject f ≤ 8 * hammingDist f q - 56 * (hammingDist f q) ^ 2 + 224 * (hammingDist f q) ^ 3 := by set E : Finset (Vec n) := Finset.univ.filter (fun x : Vec n => f x ≠ q x) let V : Fin 8 → (Vec n × Vec n × Vec n × Vec n) → Vec n := fun j t => t.1 + (if j.val % 2 = 1 then t.2.1 else 0) + (if (j.val / 2) % 2 = 1 then t.2.2.1 else 0) + (if (j.val / 4) % 2 = 1 then t.2.2.2 else 0) let ind : Fin 8 → (Vec n × Vec n × Vec n × Vec n) → ℝ := fun j t => if V j t ∈ E then 1 else 0 have hpt : ∀ t : Vec n × Vec n × Vec n × Vec n, ((∑ j : Fin 8, ind j t) - ∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ind j₁ t * ind j₂ t) ≤ (if cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2 = true then (1 : ℝ) else 0) ∧ (if cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2 = true then (1 : ℝ) else 0) ≤ ((∑ j : Fin 8, ind j t) - (∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ind j₁ t * ind j₂ t) + (2 / 3 : ℝ) * ∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ∑ j₃ ∈ (Finset.univ.erase j₁).erase j₂, ind j₁ t * ind j₂ t * ind j₃ t) := by intro t let S_hit : Finset (Fin 8) := Finset.univ.filter (fun j : Fin 8 => V j t ∈ E) set k : ℕ := S_hit.card have hS1 : ∑ j : Fin 8, ind j t = (k : ℝ) := by simp only [ind, k, S_hit, Finset.card_filter]; push_cast; rfl have hS2 : ∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ind j₁ t * ind j₂ t = (k : ℝ) * ((k : ℝ) - 1) := by have hsq : (∑ j : Fin 8, ind j t) ^ 2 = (∑ j : Fin 8, ind j t) + ∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ind j₁ t * ind j₂ t := by rw [sq, Finset.sum_mul] have hstep : ∀ j₁ : Fin 8, ind j₁ t * ∑ j₂ : Fin 8, ind j₂ t = ind j₁ t + ∑ j₂ ∈ Finset.univ.erase j₁, ind j₁ t * ind j₂ t := by intro j₁ rw [Finset.mul_sum, ← Finset.add_sum_erase _ _ (Finset.mem_univ j₁)] have hsq1 : ind j₁ t * ind j₁ t = ind j₁ t := by dsimp only [ind]; split_ifs <;> norm_num rw [hsq1] simp_rw [hstep, Finset.sum_add_distrib] rw [hS1] at hsq; linarith have hS3 : ∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ∑ j₃ ∈ (Finset.univ.erase j₁).erase j₂, ind j₁ t * ind j₂ t * ind j₃ t = (k : ℝ) * ((k : ℝ) - 1) * ((k : ℝ) - 2) := by have hr1 : ∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ∑ j₃ ∈ (Finset.univ.erase j₁).erase j₂, ind j₁ t * ind j₂ t * ind j₃ t = ∑ j₁ ∈ S_hit, ∑ j₂ ∈ S_hit.erase j₁, ∑ j₃ ∈ (S_hit.erase j₁).erase j₂, (1 : ℝ) := by rw [← Finset.sum_subset (Finset.subset_univ S_hit)] · refine Finset.sum_congr rfl (fun j₁ hj₁ => ?_) have h1 : ind j₁ t = 1 := by simp [ind, (Finset.mem_filter.mp hj₁).2] rw [← Finset.sum_subset (Finset.erase_subset_erase j₁ (Finset.subset_univ S_hit))] · refine Finset.sum_congr rfl (fun j₂ hj₂ => ?_) have h2 : ind j₂ t = 1 := by simp [ind, (Finset.mem_filter.mp (Finset.mem_of_mem_erase hj₂)).2] rw [← Finset.sum_subset (Finset.erase_subset_erase j₂ (Finset.erase_subset_erase j₁ (Finset.subset_univ S_hit)))] · refine Finset.sum_congr rfl (fun j₃ hj₃ => ?_) have h3 : ind j₃ t = 1 := by simp [ind, (Finset.mem_filter.mp (Finset.mem_of_mem_erase (Finset.mem_of_mem_erase hj₃))).2] rw [h1, h2, h3]; norm_num · intro j₃ hj₃ hnot have hne2 := (Finset.mem_erase.mp hj₃).1 have hne1 := (Finset.mem_erase.mp (Finset.mem_of_mem_erase hj₃)).1 have hnotS : j₃ ∉ S_hit := fun hs => hnot (Finset.mem_erase.mpr ⟨hne2, Finset.mem_erase.mpr ⟨hne1, hs⟩⟩) have h3 : ind j₃ t = 0 := by simp only [ind]; rw [if_neg]; intro hE; exact hnotS (Finset.mem_filter.mpr ⟨Finset.mem_univ _, hE⟩) rw [h3, mul_zero] · intro j₂ hj₂ hnot have hne1 := (Finset.mem_erase.mp hj₂).1 have hnotS : j₂ ∉ S_hit := fun hs => hnot (Finset.mem_erase.mpr ⟨hne1, hs⟩) have h2 : ind j₂ t = 0 := by simp only [ind]; rw [if_neg]; intro hE; exact hnotS (Finset.mem_filter.mpr ⟨Finset.mem_univ _, hE⟩) refine Finset.sum_eq_zero (fun j₃ _ => by rw [h2, mul_zero, zero_mul]) · intro j₁ _ hnotS have h1 : ind j₁ t = 0 := by simp only [ind]; rw [if_neg]; intro hE; exact hnotS (Finset.mem_filter.mpr ⟨Finset.mem_univ _, hE⟩) refine Finset.sum_eq_zero (fun j₂ _ => Finset.sum_eq_zero (fun j₃ _ => by rw [h1, zero_mul, zero_mul])) rw [hr1] have hcard_eval : ∑ j₁ ∈ S_hit, ∑ j₂ ∈ S_hit.erase j₁, ∑ _j₃ ∈ (S_hit.erase j₁).erase j₂, (1 : ℝ) = (k : ℝ) * ((k - 1 : ℕ) : ℝ) * ((k - 2 : ℕ) : ℝ) := by have h3 : ∀ j₁ ∈ S_hit, ∀ j₂ ∈ S_hit.erase j₁, ∑ _j₃ ∈ (S_hit.erase j₁).erase j₂, (1 : ℝ) = ((k - 2 : ℕ) : ℝ) := by intro j₁ hj₁ j₂ hj₂ simp only [Finset.sum_const, nsmul_eq_mul, mul_one, Finset.card_erase_of_mem hj₂, Finset.card_erase_of_mem hj₁] rfl have h2 : ∀ j₁ ∈ S_hit, ∑ j₂ ∈ S_hit.erase j₁, ∑ _j₃ ∈ (S_hit.erase j₁).erase j₂, (1 : ℝ) = ((k - 1 : ℕ) : ℝ) * ((k - 2 : ℕ) : ℝ) := by intro j₁ hj₁ rw [Finset.sum_congr rfl (h3 j₁ hj₁)] simp [Finset.card_erase_of_mem hj₁, k] rw [Finset.sum_congr rfl h2] simp [k, mul_assoc] rw [hcard_eval] cases k with | zero => norm_num | succ m => cases m with | zero => norm_num | succ m => push_cast; ring have hpar_sign : bSign (cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2) = (-1 : ℝ) ^ k := by have hq0 := hq t.1 t.2.1 t.2.2.1 t.2.2.2 have hsign_eq : bSign (cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2) = bSign (cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2) * bSign (cubeParity q t.1 t.2.1 t.2.2.1 t.2.2.2) := by rw [hq0]; simp [bSign] have hdiff_sign : ∀ x : Vec n, bSign (f x) * bSign (q x) = if x ∈ E then (-1 : ℝ) else 1 := by intro x; simp only [E, Finset.mem_filter, Finset.mem_univ, true_and] cases f x <;> cases q x <;> norm_num [bSign] have hprod8 : bSign (cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2) = ∏ j : Fin 8, (if V j t ∈ E then (-1 : ℝ) else 1) := by have hV0 : V 0 t = t.1 := by simp [V] have hV1 : V 1 t = t.1 + t.2.1 := by simp [V] have hV2 : V 2 t = t.1 + t.2.2.1 := by simp [V] have hV3 : V 3 t = t.1 + t.2.1 + t.2.2.1 := by simp [V] have hV4 : V 4 t = t.1 + t.2.2.2 := by simp [V] have hV5 : V 5 t = t.1 + t.2.1 + t.2.2.2 := by simp [V] have hV6 : V 6 t = t.1 + t.2.2.1 + t.2.2.2 := by simp [V] have hV7 : V 7 t = t.1 + t.2.1 + t.2.2.1 + t.2.2.2 := by simp [V] rw [hsign_eq, Fin.prod_univ_eight, hV0, hV1, hV2, hV3, hV4, hV5, hV6, hV7] simp only [cubeParity, bSign_xor] have hrearr : (bSign (f t.1) * bSign (f (t.1 + t.2.1)) * (bSign (f (t.1 + t.2.2.1)) * bSign (f (t.1 + t.2.1 + t.2.2.1))) * (bSign (f (t.1 + t.2.2.2)) * bSign (f (t.1 + t.2.1 + t.2.2.2)) * (bSign (f (t.1 + t.2.2.1 + t.2.2.2)) * bSign (f (t.1 + t.2.1 + t.2.2.1 + t.2.2.2))))) * (bSign (q t.1) * bSign (q (t.1 + t.2.1)) * (bSign (q (t.1 + t.2.2.1)) * bSign (q (t.1 + t.2.1 + t.2.2.1))) * (bSign (q (t.1 + t.2.2.2)) * bSign (q (t.1 + t.2.1 + t.2.2.2)) * (bSign (q (t.1 + t.2.2.1 + t.2.2.2)) * bSign (q (t.1 + t.2.1 + t.2.2.1 + t.2.2.2))))) = (bSign (f t.1) * bSign (q t.1)) * (bSign (f (t.1 + t.2.1)) * bSign (q (t.1 + t.2.1))) * (bSign (f (t.1 + t.2.2.1)) * bSign (q (t.1 + t.2.2.1))) * (bSign (f (t.1 + t.2.1 + t.2.2.1)) * bSign (q (t.1 + t.2.1 + t.2.2.1))) * (bSign (f (t.1 + t.2.2.2)) * bSign (q (t.1 + t.2.2.2))) * (bSign (f (t.1 + t.2.1 + t.2.2.2)) * bSign (q (t.1 + t.2.1 + t.2.2.2))) * (bSign (f (t.1 + t.2.2.1 + t.2.2.2)) * bSign (q (t.1 + t.2.2.1 + t.2.2.2))) * (bSign (f (t.1 + t.2.1 + t.2.2.1 + t.2.2.2)) * bSign (q (t.1 + t.2.1 + t.2.2.1 + t.2.2.2))) := by ring rw [hrearr] simp_rw [hdiff_sign] rw [hprod8] rw [← Finset.prod_filter_mul_prod_filter_not Finset.univ (fun j : Fin 8 => V j t ∈ E)] have h1 : ∏ j ∈ S_hit, (if V j t ∈ E then (-1 : ℝ) else 1) = (-1 : ℝ) ^ k := by calc ∏ j ∈ S_hit, (if V j t ∈ E then (-1 : ℝ) else 1) = ∏ _j ∈ S_hit, (-1 : ℝ) := Finset.prod_congr rfl (fun j hj => by simp [(Finset.mem_filter.mp hj).2]) _ = (-1 : ℝ) ^ k := by simp [k] have h2 : ∏ j ∈ Finset.univ.filter (fun j : Fin 8 => ¬ V j t ∈ E), (if V j t ∈ E then (-1 : ℝ) else 1) = 1 := Finset.prod_eq_one (fun j hj => by simp [(Finset.mem_filter.mp hj).2]) change (∏ j ∈ S_hit, (if V j t ∈ E then (-1 : ℝ) else 1)) * (∏ j ∈ Finset.univ.filter (fun j : Fin 8 => ¬ V j t ∈ E), (if V j t ∈ E then (-1 : ℝ) else 1)) = (-1 : ℝ) ^ k rw [h1, h2, mul_one] have hval_ind : (if cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2 = true then (1 : ℝ) else 0) = (1 - (-1 : ℝ) ^ k) / 2 := by rw [← hpar_sign] cases cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2 <;> norm_num [bSign] rw [hS1, hS2, hS3, hval_ind] have hk_le8 : k ≤ 8 := (Finset.card_filter_le _ _).trans (by simp) interval_cases k <;> norm_num -- 2. Unified 1-wise, 2-wise, and 3-wise independence via 3-step elementary Equiv composition! let bit : Fin 8 → Fin 3 → ZMod 2 := fun j r => match r with | ⟨0, _⟩ => if j.val % 2 = 1 then 1 else 0 | ⟨1, _⟩ => if (j.val / 2) % 2 = 1 then 1 else 0 | ⟨2, _⟩ => if (j.val / 4) % 2 = 1 then 1 else 0 let smul2 (c : ZMod 2) (v : Vec n) : Vec n := if c = 1 then v else 0 have hsmul2_add : ∀ c₁ c₂ : ZMod 2, ∀ v : Vec n, smul2 (c₁ + c₂) v = smul2 c₁ v + smul2 c₂ v := by intro c₁ c₂ v rcases zmod2_eq_zero_or_one c₁ with rfl | rfl <;> rcases zmod2_eq_zero_or_one c₂ with rfl | rfl <;> simp [smul2, zmod2_add_self, vec_add_self] have hsmul2_mul : ∀ c₁ c₂ : ZMod 2, ∀ v : Vec n, smul2 (c₁ * c₂) v = smul2 c₁ (smul2 c₂ v) := by intro c₁ c₂ v rcases zmod2_eq_zero_or_one c₁ with rfl | rfl <;> rcases zmod2_eq_zero_or_one c₂ with rfl | rfl <;> simp [smul2] have hsmul2_add_vec : ∀ c : ZMod 2, ∀ u v : Vec n, smul2 c (u + v) = smul2 c u + smul2 c v := by intro c u v; rcases zmod2_eq_zero_or_one c with rfl | rfl <;> simp [smul2] have hV_bit : ∀ (j : Fin 8) (t : Vec n × Vec n × Vec n × Vec n), V j t = t.1 + smul2 (bit j 0) t.2.1 + smul2 (bit j 1) t.2.2.1 + smul2 (bit j 2) t.2.2.2 := by intro j t by_cases h0 : j.val % 2 = 1 <;> by_cases h1 : (j.val / 2) % 2 = 1 <;> by_cases h2 : (j.val / 4) % 2 = 1 <;> simp [V, bit, smul2, h0, h1, h2] have hminor : ∀ a b c : Fin 8, a ≠ b → b ≠ c → a ≠ c → ∃ p q r : Fin 3, p ≠ q ∧ p ≠ r ∧ q ≠ r ∧ (bit b p + bit a p) * (bit c q + bit a q) + (bit b q + bit a q) * (bit c p + bit a p) = 1 := by decide have htriple_equiv : ∀ j₁ j₂ j₃ : Fin 8, j₁ ≠ j₂ → j₂ ≠ j₃ → j₁ ≠ j₃ → ∃ e : (Vec n × Vec n × Vec n × Vec n) ≃ (Vec n × Vec n × Vec n × Vec n), ∀ t, (e t).1 = V j₁ t ∧ (e t).2.1 = V j₂ t ∧ (e t).2.2.1 = V j₃ t := by intro j₁ j₂ j₃ h12 h23 h13 rcases hminor j₁ j₂ j₃ h12 h23 h13 with ⟨p, q, r, hpq, hpr, hqr, hdet⟩ let d10 := bit j₂ p + bit j₁ p; let d11 := bit j₂ q + bit j₁ q; let d12 := bit j₂ r + bit j₁ r let d20 := bit j₃ p + bit j₁ p; let d21 := bit j₃ q + bit j₁ q; let d22 := bit j₃ r + bit j₁ r let a0 := bit j₁ p; let a1 := bit j₁ q; let a2 := bit j₁ r -- Step 0: Permute (h₁, h₂, h₃) ↦ (h_p, h_q, h_r) let perm3 : Fin 3 → Fin 3 := ![p, q, r] have hperm_inj : Function.Injective perm3 := by intro i₁ i₂ h fin_cases i₁ <;> fin_cases i₂ <;> simp [perm3] at h ⊢ <;> first | rfl | exact absurd h hpq | exact absurd h hpq.symm | exact absurd h hpr | exact absurd h hpr.symm | exact absurd h hqr | exact absurd h hqr.symm let ePerm3 : Fin 3 ≃ Fin 3 := Equiv.ofBijective perm3 ((Finite.injective_iff_bijective).mp hperm_inj) let pack3 : (Vec n × Vec n × Vec n) ≃ (Fin 3 → Vec n) := { toFun := fun v => ![v.1, v.2.1, v.2.2] invFun := fun f => (f 0, f 1, f 2) left_inv := fun ⟨_, _, _⟩ => rfl right_inv := fun f => by ext k; fin_cases k <;> rfl } let e0 : (Vec n × Vec n × Vec n × Vec n) ≃ (Vec n × Vec n × Vec n × Vec n) := Equiv.prodCongr (Equiv.refl (Vec n)) ((pack3.trans (Equiv.piCongrLeft' (fun _ => Vec n) ePerm3.symm)).trans pack3.symm) -- Step 1: Shift x ↦ x + a0·hp + a1·hq + a2·hr (involution!) let e1 : (Vec n × Vec n × Vec n × Vec n) ≃ (Vec n × Vec n × Vec n × Vec n) := { toFun := fun u => (u.1 + smul2 a0 u.2.1 + smul2 a1 u.2.2.1 + smul2 a2 u.2.2.2, u.2.1, u.2.2.1, u.2.2.2) invFun := fun u => (u.1 + smul2 a0 u.2.1 + smul2 a1 u.2.2.1 + smul2 a2 u.2.2.2, u.2.1, u.2.2.1, u.2.2.2) left_inv := fun u => by refine Prod.ext ?_ rfl dsimp only have h : ∀ w₁ w₂ w₃ w₄ : Vec n, w₁ + w₂ + w₃ + w₄ + w₂ + w₃ + w₄ = w₁ := fun w₁ w₂ w₃ w₄ => by calc w₁ + w₂ + w₃ + w₄ + w₂ + w₃ + w₄ = w₁ + (w₂ + w₂) + (w₃ + w₃) + (w₄ + w₄) := by abel _ = w₁ := by simp [vec_add_self] exact h _ _ _ _ right_inv := fun u => by refine Prod.ext ?_ rfl dsimp only have h : ∀ w₁ w₂ w₃ w₄ : Vec n, w₁ + w₂ + w₃ + w₄ + w₂ + w₃ + w₄ = w₁ := fun w₁ w₂ w₃ w₄ => by calc w₁ + w₂ + w₃ + w₄ + w₂ + w₃ + w₄ = w₁ + (w₂ + w₂) + (w₃ + w₃) + (w₄ + w₄) := by abel _ = w₁ := by simp [vec_add_self] exact h _ _ _ _ } -- Step 2: 2×2 invertible linear map on (hp, hq) with d10*d21 + d11*d20 = 1! let e2 : (Vec n × Vec n × Vec n × Vec n) ≃ (Vec n × Vec n × Vec n × Vec n) := { toFun := fun u => (u.1, smul2 d10 u.2.1 + smul2 d11 u.2.2.1, smul2 d20 u.2.1 + smul2 d21 u.2.2.1, u.2.2.2) invFun := fun u => (u.1, smul2 d21 u.2.1 + smul2 d11 u.2.2.1, smul2 d20 u.2.1 + smul2 d10 u.2.2.1, u.2.2.2) left_inv := fun u => by refine Prod.ext rfl (Prod.ext ?_ (Prod.ext ?_ rfl)) · dsimp only simp only [hsmul2_add_vec, ← hsmul2_mul] calc smul2 (d21 * d10) u.2.1 + smul2 (d21 * d11) u.2.2.1 + (smul2 (d11 * d20) u.2.1 + smul2 (d11 * d21) u.2.2.1) = (smul2 (d21 * d10) u.2.1 + smul2 (d11 * d20) u.2.1) + (smul2 (d21 * d11) u.2.2.1 + smul2 (d11 * d21) u.2.2.1) := by abel _ = smul2 (d10 * d21 + d11 * d20) u.2.1 + smul2 (d11 * d21 + d11 * d21) u.2.2.1 := by rw [← hsmul2_add, ← hsmul2_add, mul_comm d21 d10, mul_comm d21 d11] _ = u.2.1 := by rw [hdet, zmod2_add_self]; simp [smul2] · dsimp only simp only [hsmul2_add_vec, ← hsmul2_mul] calc smul2 (d20 * d10) u.2.1 + smul2 (d20 * d11) u.2.2.1 + (smul2 (d10 * d20) u.2.1 + smul2 (d10 * d21) u.2.2.1) = (smul2 (d20 * d10) u.2.1 + smul2 (d10 * d20) u.2.1) + (smul2 (d10 * d21) u.2.2.1 + smul2 (d20 * d11) u.2.2.1) := by abel _ = smul2 (d10 * d20 + d10 * d20) u.2.1 + smul2 (d10 * d21 + d11 * d20) u.2.2.1 := by rw [← hsmul2_add, ← hsmul2_add, mul_comm d20 d10, mul_comm d20 d11] _ = u.2.2.1 := by rw [hdet, zmod2_add_self]; simp [smul2] right_inv := fun u => by refine Prod.ext rfl (Prod.ext ?_ (Prod.ext ?_ rfl)) · dsimp only simp only [hsmul2_add_vec, ← hsmul2_mul] calc smul2 (d10 * d21) u.2.1 + smul2 (d10 * d11) u.2.2.1 + (smul2 (d11 * d20) u.2.1 + smul2 (d11 * d10) u.2.2.1) = (smul2 (d10 * d21) u.2.1 + smul2 (d11 * d20) u.2.1) + (smul2 (d10 * d11) u.2.2.1 + smul2 (d11 * d10) u.2.2.1) := by abel _ = smul2 (d10 * d21 + d11 * d20) u.2.1 + smul2 (d10 * d11 + d10 * d11) u.2.2.1 := by rw [← hsmul2_add, ← hsmul2_add, mul_comm d11 d10] _ = u.2.1 := by rw [hdet, zmod2_add_self]; simp [smul2] · dsimp only simp only [hsmul2_add_vec, ← hsmul2_mul] calc smul2 (d20 * d21) u.2.1 + smul2 (d20 * d11) u.2.2.1 + (smul2 (d21 * d20) u.2.1 + smul2 (d21 * d10) u.2.2.1) = (smul2 (d20 * d21) u.2.1 + smul2 (d21 * d20) u.2.1) + (smul2 (d21 * d10) u.2.2.1 + smul2 (d20 * d11) u.2.2.1) := by abel _ = smul2 (d20 * d21 + d20 * d21) u.2.1 + smul2 (d10 * d21 + d11 * d20) u.2.2.1 := by rw [← hsmul2_add, ← hsmul2_add, mul_comm d21 d20, mul_comm d21 d10, mul_comm d20 d11] _ = u.2.2.1 := by rw [hdet, zmod2_add_self]; simp [smul2] } -- Step 3: Shift u₂ ↦ u₁ + u₂ + d12·hr and u₃ ↦ u₁ + u₃ + d22·hr (involution!) let e3 : (Vec n × Vec n × Vec n × Vec n) ≃ (Vec n × Vec n × Vec n × Vec n) := { toFun := fun u => (u.1, u.1 + u.2.1 + smul2 d12 u.2.2.2, u.1 + u.2.2.1 + smul2 d22 u.2.2.2, u.2.2.2) invFun := fun u => (u.1, u.1 + u.2.1 + smul2 d12 u.2.2.2, u.1 + u.2.2.1 + smul2 d22 u.2.2.2, u.2.2.2) left_inv := fun u => by refine Prod.ext rfl (Prod.ext ?_ (Prod.ext ?_ rfl)) <;> dsimp only · calc u.1 + (u.1 + u.2.1 + smul2 d12 u.2.2.2) + smul2 d12 u.2.2.2 = (u.1 + u.1) + u.2.1 + (smul2 d12 u.2.2.2 + smul2 d12 u.2.2.2) := by abel _ = u.2.1 := by simp [vec_add_self] · calc u.1 + (u.1 + u.2.2.1 + smul2 d22 u.2.2.2) + smul2 d22 u.2.2.2 = (u.1 + u.1) + u.2.2.1 + (smul2 d22 u.2.2.2 + smul2 d22 u.2.2.2) := by abel _ = u.2.2.1 := by simp [vec_add_self] right_inv := fun u => by refine Prod.ext rfl (Prod.ext ?_ (Prod.ext ?_ rfl)) <;> dsimp only · calc u.1 + (u.1 + u.2.1 + smul2 d12 u.2.2.2) + smul2 d12 u.2.2.2 = (u.1 + u.1) + u.2.1 + (smul2 d12 u.2.2.2 + smul2 d12 u.2.2.2) := by abel _ = u.2.1 := by simp [vec_add_self] · calc u.1 + (u.1 + u.2.2.1 + smul2 d22 u.2.2.2) + smul2 d22 u.2.2.2 = (u.1 + u.1) + u.2.2.1 + (smul2 d22 u.2.2.2 + smul2 d22 u.2.2.2) := by abel _ = u.2.2.1 := by simp [vec_add_self] } let e := ((e0.trans e1).trans e2).trans e3 -- Helper: ∑_{i : Fin 3} smul2 (bit j i) h_i = smul2 (bit j p) h_p + smul2 (bit j q) h_q + smul2 (bit j r) h_r have hV_perm : ∀ (j : Fin 8) (t : Vec n × Vec n × Vec n × Vec n), V j t = t.1 + smul2 (bit j p) (e0 t).2.1 + smul2 (bit j q) (e0 t).2.2.1 + smul2 (bit j r) (e0 t).2.2.2 := by intro j t rw [hV_bit j t] have hsum3 : smul2 (bit j 0) t.2.1 + smul2 (bit j 1) t.2.2.1 + smul2 (bit j 2) t.2.2.2 = ∑ i : Fin 3, smul2 (bit j i) (pack3 t.2 i) := by rw [Fin.sum_univ_three]; rfl have hsum3' : smul2 (bit j p) (e0 t).2.1 + smul2 (bit j q) (e0 t).2.2.1 + smul2 (bit j r) (e0 t).2.2.2 = ∑ k : Fin 3, smul2 (bit j (ePerm3 k)) (pack3 t.2 (ePerm3 k)) := by rw [Fin.sum_univ_three] have he0_0 : (e0 t).2.1 = pack3 t.2 (ePerm3 0) := by simp [e0, pack3, Equiv.piCongrLeft'] have he0_1 : (e0 t).2.2.1 = pack3 t.2 (ePerm3 1) := by simp [e0, pack3, Equiv.piCongrLeft'] have he0_2 : (e0 t).2.2.2 = pack3 t.2 (ePerm3 2) := by simp [e0, pack3, Equiv.piCongrLeft'] have hp0 : ePerm3 0 = p := rfl have hp1 : ePerm3 1 = q := rfl have hp2 : ePerm3 2 = r := rfl rw [he0_0, he0_1, he0_2, hp0, hp1, hp2] have hperm_eq : ∑ k : Fin 3, smul2 (bit j (ePerm3 k)) (pack3 t.2 (ePerm3 k)) = ∑ i : Fin 3, smul2 (bit j i) (pack3 t.2 i) := Equiv.sum_comp ePerm3 (fun i => smul2 (bit j i) (pack3 t.2 i)) calc t.1 + smul2 (bit j 0) t.2.1 + smul2 (bit j 1) t.2.2.1 + smul2 (bit j 2) t.2.2.2 = t.1 + (smul2 (bit j 0) t.2.1 + smul2 (bit j 1) t.2.2.1 + smul2 (bit j 2) t.2.2.2) := by abel _ = t.1 + (smul2 (bit j p) (e0 t).2.1 + smul2 (bit j q) (e0 t).2.2.1 + smul2 (bit j r) (e0 t).2.2.2) := by rw [hsum3, hsum3', hperm_eq] _ = t.1 + smul2 (bit j p) (e0 t).2.1 + smul2 (bit j q) (e0 t).2.2.1 + smul2 (bit j r) (e0 t).2.2.2 := by abel refine ⟨e, fun t => ⟨?_, ?_, ?_⟩⟩ · rw [hV_perm j₁ t]; rfl · rw [hV_perm j₂ t] have hb2p : a0 + d10 = bit j₂ p := by dsimp [a0, d10]; rw [add_comm, add_assoc, zmod2_add_self, add_zero] have hb2q : a1 + d11 = bit j₂ q := by dsimp [a1, d11]; rw [add_comm, add_assoc, zmod2_add_self, add_zero] have hb2r : a2 + d12 = bit j₂ r := by dsimp [a2, d12]; rw [add_comm, add_assoc, zmod2_add_self, add_zero] change t.1 + smul2 a0 (e0 t).2.1 + smul2 a1 (e0 t).2.2.1 + smul2 a2 (e0 t).2.2.2 + (smul2 d10 (e0 t).2.1 + smul2 d11 (e0 t).2.2.1) + smul2 d12 (e0 t).2.2.2 = t.1 + smul2 (bit j₂ p) (e0 t).2.1 + smul2 (bit j₂ q) (e0 t).2.2.1 + smul2 (bit j₂ r) (e0 t).2.2.2 rw [← hb2p, ← hb2q, ← hb2r] conv_rhs => rw [hsmul2_add a0 d10, hsmul2_add a1 d11, hsmul2_add a2 d12] abel · rw [hV_perm j₃ t] have hb3p : a0 + d20 = bit j₃ p := by dsimp [a0, d20]; rw [add_comm, add_assoc, zmod2_add_self, add_zero] have hb3q : a1 + d21 = bit j₃ q := by dsimp [a1, d21]; rw [add_comm, add_assoc, zmod2_add_self, add_zero] have hb3r : a2 + d22 = bit j₃ r := by dsimp [a2, d22]; rw [add_comm, add_assoc, zmod2_add_self, add_zero] change t.1 + smul2 a0 (e0 t).2.1 + smul2 a1 (e0 t).2.2.1 + smul2 a2 (e0 t).2.2.2 + (smul2 d20 (e0 t).2.1 + smul2 d21 (e0 t).2.2.1) + smul2 d22 (e0 t).2.2.2 = t.1 + smul2 (bit j₃ p) (e0 t).2.1 + smul2 (bit j₃ q) (e0 t).2.2.1 + smul2 (bit j₃ r) (e0 t).2.2.2 rw [← hb3p, ← hb3q, ← hb3r] conv_rhs => rw [hsmul2_add a0 d20, hsmul2_add a1 d21, hsmul2_add a2 d22] abel have h3wise : ∀ j₁ j₂ j₃ : Fin 8, j₁ ≠ j₂ → j₂ ≠ j₃ → j₁ ≠ j₃ → ∑ t : Vec n × Vec n × Vec n × Vec n, ind j₁ t * ind j₂ t * ind j₃ t = (2 : ℝ) ^ n * (E.card : ℝ) ^ 3 := by intro j₁ j₂ j₃ h12 h23 h13 rcases htriple_equiv j₁ j₂ j₃ h12 h23 h13 with ⟨e, he⟩ have heq : ∑ t : Vec n × Vec n × Vec n × Vec n, ind j₁ t * ind j₂ t * ind j₃ t = ∑ u : Vec n × Vec n × Vec n × Vec n, (if u.1 ∈ E then (1 : ℝ) else 0) * (if u.2.1 ∈ E then (1 : ℝ) else 0) * (if u.2.2.1 ∈ E then (1 : ℝ) else 0) := Fintype.sum_equiv e _ _ (fun t => by simp [ind, (he t).1, (he t).2.1, (he t).2.2]) rw [heq, Fintype.sum_prod_type] have hEsum : (∑ x : Vec n, if x ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) := by simp have hstep : ∀ x : Vec n, ∑ q : Vec n × Vec n × Vec n, (if x ∈ E then (1 : ℝ) else 0) * (if q.1 ∈ E then (1 : ℝ) else 0) * (if q.2.1 ∈ E then (1 : ℝ) else 0) = (if x ∈ E then (1 : ℝ) else 0) * ((2 : ℝ) ^ n * (E.card : ℝ) ^ 2) := by intro x rw [Fintype.sum_prod_type] have h1 : ∀ y : Vec n, ∑ r : Vec n × Vec n, (if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0) * (if r.1 ∈ E then (1 : ℝ) else 0) = (if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0) * ((2 : ℝ) ^ n * (E.card : ℝ)) := by intro y rw [Fintype.sum_prod_type] have h2 : ∀ z : Vec n, ∑ _w : Vec n, (if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0) * (if z ∈ E then (1 : ℝ) else 0) = (2 : ℝ) ^ n * ((if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0) * (if z ∈ E then (1 : ℝ) else 0)) := fun z => by simp simp_rw [h2, ← Finset.mul_sum, hEsum]; ring simp_rw [h1, ← Finset.sum_mul, ← Finset.mul_sum, hEsum]; ring simp_rw [hstep, ← Finset.sum_mul, hEsum]; ring have h2wise : ∀ j₁ j₂ : Fin 8, j₁ ≠ j₂ → ∑ t : Vec n × Vec n × Vec n × Vec n, ind j₁ t * ind j₂ t = ((2 : ℝ) ^ n) ^ 2 * (E.card : ℝ) ^ 2 := by intro j₁ j₂ h12 have hex3 : ∃ j₃ : Fin 8, j₂ ≠ j₃ ∧ j₁ ≠ j₃ := by have hne : ((Finset.univ.erase j₁).erase j₂).Nonempty := by rw [← Finset.card_pos] have h1 : (Finset.univ.erase j₁ : Finset (Fin 8)).card = 7 := by simp have h2 : j₂ ∈ Finset.univ.erase j₁ := Finset.mem_erase.mpr ⟨Ne.symm h12, Finset.mem_univ _⟩ rw [Finset.card_erase_of_mem h2, h1]; omega rcases hne with ⟨j₃, hj₃⟩ exact ⟨j₃, Ne.symm (Finset.mem_erase.mp hj₃).1, Ne.symm (Finset.mem_erase.mp (Finset.mem_of_mem_erase hj₃)).1⟩ rcases hex3 with ⟨j₃, h23, h13⟩ rcases htriple_equiv j₁ j₂ j₃ h12 h23 h13 with ⟨e, he⟩ have heq : ∑ t : Vec n × Vec n × Vec n × Vec n, ind j₁ t * ind j₂ t = ∑ u : Vec n × Vec n × Vec n × Vec n, (if u.1 ∈ E then (1 : ℝ) else 0) * (if u.2.1 ∈ E then (1 : ℝ) else 0) := Fintype.sum_equiv e _ _ (fun t => by simp [ind, (he t).1, (he t).2.1]) rw [heq, Fintype.sum_prod_type] have hEsum : (∑ x : Vec n, if x ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) := by simp have hstep : ∀ x : Vec n, ∑ q : Vec n × Vec n × Vec n, (if x ∈ E then (1 : ℝ) else 0) * (if q.1 ∈ E then (1 : ℝ) else 0) = (if x ∈ E then (1 : ℝ) else 0) * (((2 : ℝ) ^ n) ^ 2 * (E.card : ℝ)) := by intro x rw [Fintype.sum_prod_type] have h1 : ∀ y : Vec n, ∑ _r : Vec n × Vec n, (if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0) = ((2 : ℝ) ^ n) ^ 2 * ((if x ∈ E then (1 : ℝ) else 0) * (if y ∈ E then (1 : ℝ) else 0)) := by intro y; simp [Fintype.card_prod, sq] simp_rw [h1, ← Finset.mul_sum, hEsum]; ring simp_rw [hstep, ← Finset.sum_mul, hEsum]; ring have h1wise : ∀ j₁ : Fin 8, ∑ t : Vec n × Vec n × Vec n × Vec n, ind j₁ t = ((2 : ℝ) ^ n) ^ 3 * (E.card : ℝ) := by intro j₁ have hex2 : ∃ j₂ : Fin 8, j₁ ≠ j₂ := by have hne : (Finset.univ.erase j₁ : Finset (Fin 8)).Nonempty := by rw [← Finset.card_pos]; simp rcases hne with ⟨j₂, hj₂⟩ exact ⟨j₂, Ne.symm (Finset.mem_erase.mp hj₂).1⟩ rcases hex2 with ⟨j₂, h12⟩ have hex3 : ∃ j₃ : Fin 8, j₂ ≠ j₃ ∧ j₁ ≠ j₃ := by have hne : ((Finset.univ.erase j₁).erase j₂).Nonempty := by rw [← Finset.card_pos] have h1 : (Finset.univ.erase j₁ : Finset (Fin 8)).card = 7 := by simp have h2 : j₂ ∈ Finset.univ.erase j₁ := Finset.mem_erase.mpr ⟨Ne.symm h12, Finset.mem_univ _⟩ rw [Finset.card_erase_of_mem h2, h1]; omega rcases hne with ⟨j₃, hj₃⟩ exact ⟨j₃, Ne.symm (Finset.mem_erase.mp hj₃).1, Ne.symm (Finset.mem_erase.mp (Finset.mem_of_mem_erase hj₃)).1⟩ rcases hex3 with ⟨j₃, h23, h13⟩ rcases htriple_equiv j₁ j₂ j₃ h12 h23 h13 with ⟨e, he⟩ have heq : ∑ t : Vec n × Vec n × Vec n × Vec n, ind j₁ t = ∑ u : Vec n × Vec n × Vec n × Vec n, (if u.1 ∈ E then (1 : ℝ) else 0) := Fintype.sum_equiv e _ _ (fun t => by simp [ind, (he t).1]) rw [heq, Fintype.sum_prod_type] have hEsum : (∑ x : Vec n, if x ∈ E then (1 : ℝ) else 0) = (E.card : ℝ) := by simp have hstep : ∀ x : Vec n, ∑ _q : Vec n × Vec n × Vec n, (if x ∈ E then (1 : ℝ) else 0) = ((2 : ℝ) ^ n) ^ 3 * (if x ∈ E then (1 : ℝ) else 0) := by intro x; simp only [Finset.sum_const, Finset.card_univ, Fintype.card_prod, card_vec, nsmul_eq_mul]; push_cast; ring simp_rw [hstep, ← Finset.mul_sum, hEsum] -- 3. Sum pointwise bounds over all t ∈ (Vec n)⁴ and divide by (2^n)⁴! have hS1_tot : ∑ t : Vec n × Vec n × Vec n × Vec n, ∑ j : Fin 8, ind j t = 8 * ((2 : ℝ) ^ n) ^ 3 * (E.card : ℝ) := by rw [Finset.sum_comm]; simp_rw [h1wise]; simp; ring have hS2_tot : ∑ t : Vec n × Vec n × Vec n × Vec n, ∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ind j₁ t * ind j₂ t = 56 * ((2 : ℝ) ^ n) ^ 2 * (E.card : ℝ) ^ 2 := by rw [Finset.sum_comm] have h1 : ∀ j₁ : Fin 8, ∑ t : Vec n × Vec n × Vec n × Vec n, ∑ j₂ ∈ Finset.univ.erase j₁, ind j₁ t * ind j₂ t = 7 * (((2 : ℝ) ^ n) ^ 2 * (E.card : ℝ) ^ 2) := by intro j₁; rw [Finset.sum_comm] rw [Finset.sum_congr rfl (fun j₂ hj₂ => h2wise j₁ j₂ (Ne.symm (Finset.mem_erase.mp hj₂).1))] simp [Finset.card_erase_of_mem (Finset.mem_univ j₁)] simp_rw [h1]; simp; ring have hS3_tot : ∑ t : Vec n × Vec n × Vec n × Vec n, ∑ j₁ : Fin 8, ∑ j₂ ∈ Finset.univ.erase j₁, ∑ j₃ ∈ (Finset.univ.erase j₁).erase j₂, ind j₁ t * ind j₂ t * ind j₃ t = 336 * (2 : ℝ) ^ n * (E.card : ℝ) ^ 3 := by rw [Finset.sum_comm] have h1 : ∀ j₁ : Fin 8, ∑ t : Vec n × Vec n × Vec n × Vec n, ∑ j₂ ∈ Finset.univ.erase j₁, ∑ j₃ ∈ (Finset.univ.erase j₁).erase j₂, ind j₁ t * ind j₂ t * ind j₃ t = 42 * ((2 : ℝ) ^ n * (E.card : ℝ) ^ 3) := by intro j₁; rw [Finset.sum_comm] have h2 : ∀ j₂ ∈ Finset.univ.erase j₁, ∑ t : Vec n × Vec n × Vec n × Vec n, ∑ j₃ ∈ (Finset.univ.erase j₁).erase j₂, ind j₁ t * ind j₂ t * ind j₃ t = 6 * ((2 : ℝ) ^ n * (E.card : ℝ) ^ 3) := by intro j₂ hj₂; rw [Finset.sum_comm] have h3 : ∀ j₃ ∈ (Finset.univ.erase j₁).erase j₂, ∑ t : Vec n × Vec n × Vec n × Vec n, ind j₁ t * ind j₂ t * ind j₃ t = (2 : ℝ) ^ n * (E.card : ℝ) ^ 3 := by intro j₃ hj₃ exact h3wise j₁ j₂ j₃ (Ne.symm (Finset.mem_erase.mp hj₂).1) (Ne.symm (Finset.mem_erase.mp hj₃).1) (Ne.symm (Finset.mem_erase.mp (Finset.mem_of_mem_erase hj₃)).1) rw [Finset.sum_congr rfl h3] simp [Finset.card_erase_of_mem hj₂, Finset.card_erase_of_mem (Finset.mem_univ j₁)] rw [Finset.sum_congr rfl h2] simp [Finset.card_erase_of_mem (Finset.mem_univ j₁)]; ring simp_rw [h1]; simp; ring have hpos := ne_of_gt (two_pow_pos n) have hpos4 : (0 : ℝ) < ((2 : ℝ) ^ n) ^ 4 := by positivity have hE_eq : (E.card : ℝ) = (2 : ℝ) ^ n * hammingDist f q := by unfold hammingDist; exact (mul_div_cancel₀ _ hpos).symm have hrm_sum : ∑ t : Vec n × Vec n × Vec n × Vec n, (if cubeParity f t.1 t.2.1 t.2.2.1 t.2.2.2 = true then (1 : ℝ) else 0) = ((2 : ℝ) ^ n) ^ 4 * rm2Reject f := by unfold rm2Reject rw [mul_div_cancel₀ _ (ne_of_gt hpos4), Finset.card_filter]; push_cast; rfl constructor · have hlb := Finset.sum_le_sum (s := (Finset.univ : Finset (Vec n × Vec n × Vec n × Vec n))) (fun t _ => (hpt t).1) rw [Finset.sum_sub_distrib, hS1_tot, hS2_tot, hrm_sum, hE_eq] at hlb have halg : 8 * ((2 : ℝ) ^ n) ^ 3 * ((2 : ℝ) ^ n * hammingDist f q) - 56 * ((2 : ℝ) ^ n) ^ 2 * ((2 : ℝ) ^ n * hammingDist f q) ^ 2 = ((2 : ℝ) ^ n) ^ 4 * (8 * hammingDist f q - 56 * (hammingDist f q) ^ 2) := by ring rw [halg] at hlb exact le_of_mul_le_mul_left hlb hpos4 · have hub := Finset.sum_le_sum (s := (Finset.univ : Finset (Vec n × Vec n × Vec n × Vec n))) (fun t _ => (hpt t).2) rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, hS1_tot, hS2_tot, hS3_tot, hrm_sum, hE_eq] at hub have halg : 8 * ((2 : ℝ) ^ n) ^ 3 * ((2 : ℝ) ^ n * hammingDist f q) - 56 * ((2 : ℝ) ^ n) ^ 2 * ((2 : ℝ) ^ n * hammingDist f q) ^ 2 + (2 / 3 : ℝ) * (336 * (2 : ℝ) ^ n * ((2 : ℝ) ^ n * hammingDist f q) ^ 3) = ((2 : ℝ) ^ n) ^ 4 * (8 * hammingDist f q - 56 * (hammingDist f q) ^ 2 + 224 * (hammingDist f q) ^ 3) := by ring rw [halg] at hub exact le_of_mul_le_mul_left hub hpos4 end Pillar2 /-! ============================================================================ PILLAR 3: EXACT ALGEBRAIC ZERO-KNOWLEDGE, SIGMA-PROTOCOL k-SPECIAL SOUNDNESS, CHALLENGE-ENTROPY EXTRACTION & PRODUCT-TV HVZK ============================================================================ -/ section Pillar3 /-! ### Finite Discrete Distributions & Exact Total Variation Distance -/ /-- A discrete probability distribution on a finite type `α`. -/ def IsProbDist {α : Type*} [Fintype α] (p : α → ℝ) : Prop := (∀ x, 0 ≤ p x) ∧ ∑ x : α, p x = 1 /-- Uniform probability distribution on a nonempty finite type `α`. -/ noncomputable def unifDist (α : Type*) [Fintype α] : α → ℝ := fun _ => 1 / (Fintype.card α : ℝ) lemma isProbDist_unifDist {α : Type*} [Fintype α] [Nonempty α] : IsProbDist (unifDist α) := by refine ⟨fun _ => by unfold unifDist; positivity, ?_⟩ unfold unifDist have hpos : (0 : ℝ) < Fintype.card α := by exact_mod_cast Fintype.card_pos (α := α) rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, one_div, mul_inv_cancel₀ (ne_of_gt hpos)] /-- Uniform distribution on a nonempty finite subset `B : Finset α`. -/ noncomputable def subsetUnif {α : Type*} [DecidableEq α] (B : Finset α) : α → ℝ := fun x => if x ∈ B then 1 / (B.card : ℝ) else 0 lemma isProbDist_subsetUnif {α : Type*} [Fintype α] [DecidableEq α] {B : Finset α} (hB : B.Nonempty) : IsProbDist (subsetUnif B) := by refine ⟨fun x => by unfold subsetUnif; split_ifs <;> positivity, ?_⟩ unfold subsetUnif have hpos : (0 : ℝ) < B.card := by exact_mod_cast hB.card_pos rw [← Finset.sum_filter] have hfilt : Finset.univ.filter (fun x : α => x ∈ B) = B := by ext x; simp rw [hfilt, Finset.sum_const, nsmul_eq_mul, one_div, mul_inv_cancel₀ (ne_of_gt hpos)] /-- Product of two discrete distributions. -/ def prodDist {α β : Type*} (p : α → ℝ) (q : β → ℝ) : α × β → ℝ := fun xy => p xy.1 * q xy.2 lemma isProbDist_prodDist {α β : Type*} [Fintype α] [Fintype β] {p : α → ℝ} {q : β → ℝ} (hp : IsProbDist p) (hq : IsProbDist q) : IsProbDist (prodDist p q) := by refine ⟨fun xy => mul_nonneg (hp.1 xy.1) (hq.1 xy.2), ?_⟩ unfold prodDist rw [Fintype.sum_prod_type] simp_rw [← Finset.mul_sum, hq.2, mul_one, hp.2] /-- Total variation (statistical) distance `TV(p, q) = (1/2) ∑_x |p(x) - q(x)|`. -/ noncomputable def tvDist {α : Type*} [Fintype α] (p q : α → ℝ) : ℝ := (∑ x : α, |p x - q x|) / 2 lemma tvDist_nonneg {α : Type*} [Fintype α] (p q : α → ℝ) : 0 ≤ tvDist p q := div_nonneg (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) (by norm_num) lemma tvDist_self {α : Type*} [Fintype α] (p : α → ℝ) : tvDist p p = 0 := by simp [tvDist] lemma tvDist_comm {α : Type*} [Fintype α] (p q : α → ℝ) : tvDist p q = tvDist q p := by unfold tvDist; congr 1 exact Finset.sum_congr rfl (fun x _ => abs_sub_comm _ _) lemma tvDist_equiv {α β : Type*} [Fintype α] [Fintype β] (e : α ≃ β) (p q : β → ℝ) : tvDist (p ∘ e) (q ∘ e) = tvDist p q := by unfold tvDist; congr 1 exact Fintype.sum_equiv e (fun x => |p (e x) - q (e x)|) (fun y => |p y - q y|) (fun _ => rfl) /-- Exact overlap identity: for probability distributions `p, q`, `TV(p, q) = 1 - ∑_x min(p x, q x)`. -/ theorem tvDist_eq_one_sub_sum_min {α : Type*} [Fintype α] {p q : α → ℝ} (hp : IsProbDist p) (hq : IsProbDist q) : tvDist p q = 1 - ∑ x : α, min (p x) (q x) := by unfold tvDist have hpt : ∀ x : α, |p x - q x| = p x + q x - 2 * min (p x) (q x) := fun x => by rcases le_total (p x) (q x) with h | h · rw [abs_of_nonpos (sub_nonpos.mpr h), min_eq_left h]; ring · rw [abs_of_nonneg (sub_nonneg.mpr h), min_eq_right h]; ring rw [Finset.sum_congr rfl (fun x _ => hpt x), Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, hp.2, hq.2] ring lemma tvDist_le_one {α : Type*} [Fintype α] {p q : α → ℝ} (hp : IsProbDist p) (hq : IsProbDist q) : tvDist p q ≤ 1 := by rw [tvDist_eq_one_sub_sum_min hp hq] have hnn : 0 ≤ ∑ x : α, min (p x) (q x) := Finset.sum_nonneg (fun x _ => le_min (hp.1 x) (hq.1 x)) linarith /-- Data-processing marginal lower bounds on product total variation distance. -/ theorem tvDist_prod_ge_left {α β : Type*} [Fintype α] [Fintype β] {p₁ p₂ : α → ℝ} {q₁ q₂ : β → ℝ} (hq₁ : IsProbDist q₁) (hq₂ : IsProbDist q₂) : tvDist p₁ p₂ ≤ tvDist (prodDist p₁ q₁) (prodDist p₂ q₂) := by unfold tvDist prodDist refine div_le_div_of_nonneg_right ?_ (by norm_num) rw [Fintype.sum_prod_type] refine Finset.sum_le_sum (fun x _ => ?_) have hmarg : p₁ x - p₂ x = ∑ y : β, (p₁ x * q₁ y - p₂ x * q₂ y) := by rw [Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.mul_sum, hq₁.2, hq₂.2, mul_one, mul_one] rw [hmarg] exact Finset.abs_sum_le_sum_abs _ _ theorem tvDist_prod_ge_right {α β : Type*} [Fintype α] [Fintype β] {p₁ p₂ : α → ℝ} {q₁ q₂ : β → ℝ} (hp₁ : IsProbDist p₁) (hp₂ : IsProbDist p₂) : tvDist q₁ q₂ ≤ tvDist (prodDist p₁ q₁) (prodDist p₂ q₂) := by unfold tvDist prodDist refine div_le_div_of_nonneg_right ?_ (by norm_num) rw [Fintype.sum_prod_type, Finset.sum_comm] refine Finset.sum_le_sum (fun y _ => ?_) have hmarg : q₁ y - q₂ y = ∑ x : α, (p₁ x * q₁ y - p₂ x * q₂ y) := by rw [Finset.sum_sub_distrib, ← Finset.sum_mul, ← Finset.sum_mul, hp₁.2, hp₂.2, one_mul, one_mul] rw [hmarg] exact Finset.abs_sum_le_sum_abs _ _ /-- **Exact Submultiplicative Product-TV Upper Bound** (strictly sharper than triangle inequality!): `TV(p₁ ⊗ q₁, p₂ ⊗ q₂) ≤ 1 - (1 - TV(p₁, p₂)) (1 - TV(q₁, q₂))`. -/ theorem tvDist_prod_le_submult {α β : Type*} [Fintype α] [Fintype β] {p₁ p₂ : α → ℝ} {q₁ q₂ : β → ℝ} (hp₁ : IsProbDist p₁) (hp₂ : IsProbDist p₂) (hq₁ : IsProbDist q₁) (hq₂ : IsProbDist q₂) : tvDist (prodDist p₁ q₁) (prodDist p₂ q₂) ≤ 1 - (1 - tvDist p₁ p₂) * (1 - tvDist q₁ q₂) := by rw [tvDist_eq_one_sub_sum_min (isProbDist_prodDist hp₁ hq₁) (isProbDist_prodDist hp₂ hq₂), tvDist_eq_one_sub_sum_min hp₁ hp₂, tvDist_eq_one_sub_sum_min hq₁ hq₂] have hmin : (∑ x : α, min (p₁ x) (p₂ x)) * (∑ y : β, min (q₁ y) (q₂ y)) ≤ ∑ xy : α × β, min (prodDist p₁ q₁ xy) (prodDist p₂ q₂ xy) := by rw [Fintype.sum_prod_type, Finset.sum_mul] refine Finset.sum_le_sum (fun x _ => ?_) rw [Finset.mul_sum] refine Finset.sum_le_sum (fun y _ => ?_) unfold prodDist refine le_min ?_ ?_ · exact mul_le_mul (min_le_left _ _) (min_le_left _ _) (le_min (hq₁.1 y) (hq₂.1 y)) (hp₁.1 x) · exact mul_le_mul (min_le_right _ _) (min_le_right _ _) (le_min (hq₁.1 y) (hq₂.1 y)) (hp₂.1 x) linarith /-- Strict sharpening of submultiplicative product-TV over the standard triangle inequality. -/ theorem tvDist_submult_lt_add {α β : Type*} [Fintype α] [Fintype β] {p₁ p₂ : α → ℝ} {q₁ q₂ : β → ℝ} (h1 : 0 < tvDist p₁ p₂) (h2 : 0 < tvDist q₁ q₂) : 1 - (1 - tvDist p₁ p₂) * (1 - tvDist q₁ q₂) < tvDist p₁ p₂ + tvDist q₁ q₂ := by nlinarith /-- Exact TV distance between subset-uniform `subsetUnif B` and full `unifDist α`. -/ theorem tvDist_subsetUnif_unif {α : Type*} [Fintype α] [DecidableEq α] [Nonempty α] {B : Finset α} (hB : B.Nonempty) : tvDist (subsetUnif B) (unifDist α) = 1 - (B.card : ℝ) / (Fintype.card α : ℝ) := by rw [tvDist_eq_one_sub_sum_min (isProbDist_subsetUnif hB) isProbDist_unifDist] congr 1 have hBpos : (0 : ℝ) < B.card := by exact_mod_cast hB.card_pos have hApos : (0 : ℝ) < Fintype.card α := by exact_mod_cast Fintype.card_pos (α := α) have hle : (B.card : ℝ) ≤ Fintype.card α := by exact_mod_cast B.card_le_univ have hinv_le : 1 / (Fintype.card α : ℝ) ≤ 1 / (B.card : ℝ) := one_div_le_one_div_of_le hBpos hle have hpt : ∀ x : α, min (subsetUnif B x) (unifDist α x) = if x ∈ B then 1 / (Fintype.card α : ℝ) else 0 := by intro x; unfold subsetUnif unifDist by_cases hx : x ∈ B · rw [if_pos hx, if_pos hx, min_eq_right hinv_le] · rw [if_neg hx, if_neg hx, min_eq_left (by positivity)] rw [Finset.sum_congr rfl (fun x _ => hpt x), ← Finset.sum_filter] have hfilt : Finset.univ.filter (fun x : α => x ∈ B) = B := by ext x; simp rw [hfilt]; simp [div_eq_mul_inv] /-! ### Abstract Σ-Protocols, k-Special Soundness & Challenge-Entropy Knowledge Extraction -/ /-- Abstract 3-move Σ-protocol for an NP relation `rel ⊆ X × W`. -/ structure SigmaProtocol (X W A C Z : Type*) where rel : X → W → Prop verify : X → A → C → Z → Prop /-- `k`-special soundness: any `k` accepting transcripts with the same commitment and distinct challenges guarantee existence of a valid witness `w` with `rel x w`. -/ def HasKSpecialSoundness {X W A C Z : Type*} (proto : SigmaProtocol X W A C Z) (k : ℕ) : Prop := ∀ (x : X) (a : A) (S : Finset C) (resp : C → Z), k ≤ S.card → (∀ c ∈ S, proto.verify x a c (resp c)) → ∃ w : W, proto.rel x w /-- **Theorem 3.1 (Exact Non-Uniform Challenge-Entropy Knowledge Error)**: In ANY `k`-special-sound Σ-protocol under ANY challenge distribution `μ` with max probability `p_max = 2^{-H_∞(μ)}`, any cheating prover on a false statement `x` (`¬ ∃ w, rel x w`) has at most `k - 1` accepting challenges per commitment `a` and acceptance probability at most `κ_k^*(μ) ≤ (k - 1) · p_max`. -/ theorem kSpecialSound_nonuniform_knowledge_error {X W A C Z : Type*} [Fintype C] [DecidableEq C] (proto : SigmaProtocol X W A C Z) {k : ℕ} (hk : 1 ≤ k) (hss : HasKSpecialSoundness proto k) {x : X} (hno : ¬ ∃ w : W, proto.rel x w) (a : A) (resp : C → Z) [DecidablePred (fun c => proto.verify x a c (resp c))] {μ : C → ℝ} (hμ : IsProbDist μ) {p_max : ℝ} (hpmax : ∀ c, μ c ≤ p_max) : let S_acc := Finset.univ.filter (fun c : C => proto.verify x a c (resp c)) S_acc.card ≤ k - 1 ∧ ∑ c ∈ S_acc, μ c ≤ ((k - 1 : ℕ) : ℝ) * p_max := by intro S_acc have hlt : S_acc.card < k := by by_contra hge have hcard : k ≤ S_acc.card := not_lt.mp hge exact hno (hss x a S_acc resp hcard (fun c hc => (Finset.mem_filter.mp hc).2)) have hle : S_acc.card ≤ k - 1 := by omega refine ⟨hle, ?_⟩ have hpmax_nn : 0 ≤ p_max := by have hne : Nonempty C := by by_contra hempty have h0 : ∑ c : C, μ c = 0 := by have hEmp : IsEmpty C := not_nonempty_iff.mp hempty exact Finset.sum_eq_zero (fun c _ => hEmp.elim c) linarith [hμ.2] exact (hμ.1 (Classical.arbitrary C)).trans (hpmax (Classical.arbitrary C)) calc ∑ c ∈ S_acc, μ c ≤ ∑ _c ∈ S_acc, p_max := Finset.sum_le_sum (fun c _ => hpmax c) _ = (S_acc.card : ℝ) * p_max := by simp _ ≤ ((k - 1 : ℕ) : ℝ) * p_max := mul_le_mul_of_nonneg_right (by exact_mod_cast hle) hpmax_nn /-- **Theorem 3.2 (Exact 2-Run Rewinding Knowledge Extraction under Degraded Challenge Entropy)**: For ANY randomized prover `(ν, S_a)` and ANY non-uniform challenge distribution `μ` with min-entropy peak `p_max = 2^{-H_∞(μ)}` and Rényi-2 collision probability `C₂ = ∑_c μ(c)²`, the exact 2-run independent distinct-accepting extraction probability obeys BOTH: 1. `ε̄ (ε̄ - p_max) ≤ Pr[extract]` (Min-Entropy Bound), AND 2. `ε̄² - C₂ ≤ Pr[extract]` (Rényi-2 Collision-Entropy Bound). -/ theorem twoRun_rewinding_nonuniform_entropy {A C : Type*} [Fintype A] [Fintype C] {ν : A → ℝ} (hν : IsProbDist ν) {μ : C → ℝ} (hμ : IsProbDist μ) (S_a : A → Finset C) {p_max : ℝ} (hpmax : ∀ c, μ c ≤ p_max) : let ε : A → ℝ := fun a => ∑ c ∈ S_a a, μ c let ε_bar : ℝ := ∑ a : A, ν a * ε a let C₂ : ℝ := ∑ c : C, (μ c) ^ 2 let extProb : ℝ := ∑ a : A, ν a * ((ε a) ^ 2 - ∑ c ∈ S_a a, (μ c) ^ 2) ε_bar * (ε_bar - p_max) ≤ extProb ∧ ε_bar ^ 2 - C₂ ≤ extProb := by intro ε ε_bar C₂ extProb -- Jensen / Cauchy-Schwarz: ε_bar² ≤ ∑ a, ν a * (ε a)² have hjensen : ε_bar ^ 2 ≤ ∑ a : A, ν a * (ε a) ^ 2 := by have hcs := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset A) (fun a => Real.sqrt (ν a)) (fun a => Real.sqrt (ν a) * ε a) have h1 : ∑ a : A, Real.sqrt (ν a) * (Real.sqrt (ν a) * ε a) = ε_bar := by refine Finset.sum_congr rfl (fun a _ => ?_) rw [← mul_assoc, Real.mul_self_sqrt (hν.1 a)] have h2 : ∑ a : A, (Real.sqrt (ν a)) ^ 2 = 1 := by rw [Finset.sum_congr rfl (fun a _ => Real.sq_sqrt (hν.1 a)), hν.2] have h3 : ∑ a : A, (Real.sqrt (ν a) * ε a) ^ 2 = ∑ a : A, ν a * (ε a) ^ 2 := Finset.sum_congr rfl (fun a _ => by rw [mul_pow, Real.sq_sqrt (hν.1 a)]) rw [h1, h2, h3, one_mul] at hcs exact hcs constructor · have hstep : ∑ a : A, ν a * ((ε a) ^ 2 - p_max * ε a) ≤ extProb := by refine Finset.sum_le_sum (fun a _ => mul_le_mul_of_nonneg_left ?_ (hν.1 a)) have hcoll : ∑ c ∈ S_a a, (μ c) ^ 2 ≤ p_max * ε a := by calc ∑ c ∈ S_a a, (μ c) ^ 2 = ∑ c ∈ S_a a, μ c * μ c := Finset.sum_congr rfl (fun c _ => sq (μ c)) _ ≤ ∑ c ∈ S_a a, p_max * μ c := Finset.sum_le_sum (fun c _ => mul_le_mul_of_nonneg_right (hpmax c) (hμ.1 c)) _ = p_max * ε a := (Finset.mul_sum _ _ _).symm linarith have hlin : ∑ a : A, ν a * ((ε a) ^ 2 - p_max * ε a) = (∑ a : A, ν a * (ε a) ^ 2) - p_max * ε_bar := by simp only [mul_sub, Finset.sum_sub_distrib] congr 1 calc ∑ a : A, ν a * (p_max * ε a) = ∑ a : A, p_max * (ν a * ε a) := Finset.sum_congr rfl (fun a _ => by ring) _ = p_max * ε_bar := (Finset.mul_sum _ _ _).symm nlinarith · have hstep : ∑ a : A, ν a * ((ε a) ^ 2 - C₂) ≤ extProb := by refine Finset.sum_le_sum (fun a _ => mul_le_mul_of_nonneg_left ?_ (hν.1 a)) have hcoll : ∑ c ∈ S_a a, (μ c) ^ 2 ≤ C₂ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun _ _ _ => sq_nonneg _) linarith have hlin : ∑ a : A, ν a * ((ε a) ^ 2 - C₂) = (∑ a : A, ν a * (ε a) ^ 2) - C₂ := by simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hν.2, one_mul] linarith /-- Clamped falling-factorial extraction kernel `φ_k(N; t) = ∏_{j=0}^{k-1} max(0, t - j / N)`. -/ noncomputable def fallingKernel (k N : ℕ) (t : ℝ) : ℝ := ∏ j : Fin k, max 0 (t - (j.val : ℝ) / (N : ℝ)) /-- Pure-algebraic convexity of products of nonnegative nondecreasing convex functions (no calculus!). -/ lemma convex_mul_nonneg_mono {f g : ℝ → ℝ} (hf0 : ∀ x, 0 ≤ f x) (hg0 : ∀ x, 0 ≤ g x) (hfm : Monotone f) (hgm : Monotone g) (hfc : ∀ x y lam : ℝ, 0 ≤ lam → lam ≤ 1 → f (lam * x + (1 - lam) * y) ≤ lam * f x + (1 - lam) * f y) (hgc : ∀ x y lam : ℝ, 0 ≤ lam → lam ≤ 1 → g (lam * x + (1 - lam) * y) ≤ lam * g x + (1 - lam) * g y) : ∀ x y lam : ℝ, 0 ≤ lam → lam ≤ 1 → f (lam * x + (1 - lam) * y) * g (lam * x + (1 - lam) * y) ≤ lam * (f x * g x) + (1 - lam) * (f y * g y) := by intro x y lam h0 h1 have hf_le := hfc x y lam h0 h1 have hg_le := hgc x y lam h0 h1 have hprod : f (lam * x + (1 - lam) * y) * g (lam * x + (1 - lam) * y) ≤ (lam * f x + (1 - lam) * f y) * (lam * g x + (1 - lam) * g y) := mul_le_mul hf_le hg_le (hg0 _) (add_nonneg (mul_nonneg h0 (hf0 x)) (mul_nonneg (by linarith) (hf0 y))) have hmono_prod : 0 ≤ (f x - f y) * (g x - g y) := by rcases le_total x y with hxy | hyx · exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr (hfm hxy)) (sub_nonpos.mpr (hgm hxy)) · exact mul_nonneg (sub_nonneg.mpr (hfm hyx)) (sub_nonneg.mpr (hgm hyx)) have halg : lam * (f x * g x) + (1 - lam) * (f y * g y) - (lam * f x + (1 - lam) * f y) * (lam * g x + (1 - lam) * g y) = lam * (1 - lam) * ((f x - f y) * (g x - g y)) := by ring have hnn : 0 ≤ lam * (1 - lam) * ((f x - f y) * (g x - g y)) := mul_nonneg (mul_nonneg h0 (by linarith)) hmono_prod linarith lemma fallingKernel_props (k N : ℕ) : (∀ t, 0 ≤ fallingKernel k N t) ∧ Monotone (fallingKernel k N) ∧ (∀ x y lam : ℝ, 0 ≤ lam → lam ≤ 1 → fallingKernel k N (lam * x + (1 - lam) * y) ≤ lam * fallingKernel k N x + (1 - lam) * fallingKernel k N y) := by induction k with | zero => refine ⟨fun _ => by simp [fallingKernel], fun _ _ _ => by simp [fallingKernel], fun _ _ lam _ _ => by simp [fallingKernel]⟩ | succ k ih => have hrew : ∀ t, fallingKernel (k + 1) N t = fallingKernel k N t * max 0 (t - (k : ℝ) / (N : ℝ)) := by intro t; unfold fallingKernel rw [Fin.prod_univ_castSucc]; rfl have hg0 : ∀ t, 0 ≤ max (0 : ℝ) (t - (k : ℝ) / (N : ℝ)) := fun _ => le_max_left _ _ have hgm : Monotone (fun t : ℝ => max (0 : ℝ) (t - (k : ℝ) / (N : ℝ))) := fun x y hxy => max_le_max_left 0 (by linarith) have hgc : ∀ x y lam : ℝ, 0 ≤ lam → lam ≤ 1 → max (0 : ℝ) (lam * x + (1 - lam) * y - (k : ℝ) / (N : ℝ)) ≤ lam * max (0 : ℝ) (x - (k : ℝ) / (N : ℝ)) + (1 - lam) * max (0 : ℝ) (y - (k : ℝ) / (N : ℝ)) := by intro x y lam h0 h1 refine max_le (add_nonneg (mul_nonneg h0 (le_max_left _ _)) (mul_nonneg (by linarith) (le_max_left _ _))) ?_ have h1' : lam * (x - (k : ℝ) / (N : ℝ)) ≤ lam * max 0 (x - (k : ℝ) / (N : ℝ)) := mul_le_mul_of_nonneg_left (le_max_right _ _) h0 have h2' : (1 - lam) * (y - (k : ℝ) / (N : ℝ)) ≤ (1 - lam) * max 0 (y - (k : ℝ) / (N : ℝ)) := mul_le_mul_of_nonneg_left (le_max_right _ _) (by linarith) linarith refine ⟨fun t => by rw [hrew]; exact mul_nonneg (ih.1 t) (hg0 t), fun x y hxy => by rw [hrew, hrew]; exact mul_le_mul (ih.2.1 hxy) (hgm hxy) (hg0 x) (ih.1 y), fun x y lam h0 h1 => by rw [hrew, hrew, hrew] exact convex_mul_nonneg_mono ih.1 hg0 ih.2.1 hgm ih.2.2 hgc x y lam h0 h1⟩ /-- Finite Jensen inequality for any convex function `φ : ℝ → ℝ`. -/ lemma finite_jensen {α : Type*} (s : Finset α) {φ : ℝ → ℝ} (hconv : ∀ x y lam : ℝ, 0 ≤ lam → lam ≤ 1 → φ (lam * x + (1 - lam) * y) ≤ lam * φ x + (1 - lam) * φ y) {w x : α → ℝ} (hw0 : ∀ a ∈ s, 0 ≤ w a) (hw1 : ∑ a ∈ s, w a = 1) : φ (∑ a ∈ s, w a * x a) ≤ ∑ a ∈ s, w a * φ (x a) := by classical induction s using Finset.induction_on generalizing w with | empty => simp at hw1 | @insert a s ha ih => rw [Finset.sum_insert ha] at hw1 ⊢ rw [Finset.sum_insert ha] have hwa : 0 ≤ w a := hw0 a (Finset.mem_insert_self a s) have hrest_nn : 0 ≤ ∑ b ∈ s, w b := Finset.sum_nonneg (fun b hb => hw0 b (Finset.mem_insert_of_mem hb)) by_cases hrem : ∑ b ∈ s, w b = 0 · have hwa1 : w a = 1 := by linarith have hall0 : ∀ b ∈ s, w b = 0 := (Finset.sum_eq_zero_iff_of_nonneg (fun b hb => hw0 b (Finset.mem_insert_of_mem hb))).mp hrem have hsx : ∑ b ∈ s, w b * x b = 0 := Finset.sum_eq_zero (fun b hb => by rw [hall0 b hb, zero_mul]) have hsφ : ∑ b ∈ s, w b * φ (x b) = 0 := Finset.sum_eq_zero (fun b hb => by rw [hall0 b hb, zero_mul]) rw [hwa1, hsx, hsφ, one_mul, add_zero, one_mul, add_zero] · have hrem_pos : 0 < ∑ b ∈ s, w b := lt_of_le_of_ne hrest_nn (Ne.symm hrem) have hwa_le1 : w a ≤ 1 := by linarith set W := ∑ b ∈ s, w b let w' : α → ℝ := fun b => w b / W have hw'0 : ∀ b ∈ s, 0 ≤ w' b := fun b hb => div_nonneg (hw0 b (Finset.mem_insert_of_mem hb)) (le_of_lt hrem_pos) have hw'1 : ∑ b ∈ s, w' b = 1 := by unfold w'; rw [← Finset.sum_div]; exact div_self (ne_of_gt hrem_pos) have hih := ih hw'0 hw'1 have hcomb : w a * x a + ∑ b ∈ s, w b * x b = w a * x a + (1 - w a) * (∑ b ∈ s, w' b * x b) := by congr 1 have h1m : 1 - w a = W := by linarith rw [h1m, Finset.mul_sum] refine Finset.sum_congr rfl (fun b _ => ?_) dsimp only [w']; field_simp [ne_of_gt hrem_pos] rw [hcomb] refine (hconv (x a) (∑ b ∈ s, w' b * x b) (w a) hwa hwa_le1).trans ?_ have h1m : 1 - w a = W := by linarith have hmul : (1 - w a) * φ (∑ b ∈ s, w' b * x b) ≤ (1 - w a) * ∑ b ∈ s, w' b * φ (x b) := mul_le_mul_of_nonneg_left hih (by linarith) have hrhs : (1 - w a) * ∑ b ∈ s, w' b * φ (x b) = ∑ b ∈ s, w b * φ (x b) := by rw [h1m, Finset.mul_sum] refine Finset.sum_congr rfl (fun b _ => ?_) dsimp only [w']; field_simp [ne_of_gt hrem_pos] linarith /-- **Theorem 3.3 (Exact `k`-Special Soundness Convex Falling-Factorial Rewinding Bound)**: For ANY `k ≥ 1`, uniform challenge space of size `N ≥ 1`, and ANY randomized prover `(ν, s)` whose average acceptance probability `ε = ∑_a ν(a) (s(a)/N)` exceeds `(k - 1)/N`, the exact `k`-run independent distinct-accepting extraction probability obeys: `∏_{j=0}^{k-1} (ε - j / N) ≤ ∑_a ν(a) · ∏_{j=0}^{k-1} max(0, (s(a) - j) / N)`. -/ theorem kRun_rewinding_falling_factorial_jensen {A : Type*} [Fintype A] (k N : ℕ) (hN : 1 ≤ N) {ν : A → ℝ} (hν : IsProbDist ν) (s : A → ℕ) (hε_ge : ∀ j : Fin k, (j.val : ℝ) / (N : ℝ) ≤ ∑ a : A, ν a * ((s a : ℝ) / (N : ℝ))) : ∏ j : Fin k, ((∑ a : A, ν a * ((s a : ℝ) / (N : ℝ))) - (j.val : ℝ) / (N : ℝ)) ≤ ∑ a : A, ν a * ∏ j : Fin k, (max 0 ((s a : ℝ) - (j.val : ℝ)) / (N : ℝ)) := by have hNpos : (0 : ℝ) < N := by exact_mod_cast hN have hjen := finite_jensen (Finset.univ : Finset A) (fallingKernel_props k N).2.2 (fun a _ => hν.1 a) hν.2 (x := fun a => (s a : ℝ) / (N : ℝ)) have hlhs : fallingKernel k N (∑ a : A, ν a * ((s a : ℝ) / (N : ℝ))) = ∏ j : Fin k, ((∑ a : A, ν a * ((s a : ℝ) / (N : ℝ))) - (j.val : ℝ) / (N : ℝ)) := by unfold fallingKernel refine Finset.prod_congr rfl (fun j _ => max_eq_right (sub_nonneg.mpr (hε_ge j))) have hrhs : ∑ a : A, ν a * fallingKernel k N ((s a : ℝ) / (N : ℝ)) = ∑ a : A, ν a * ∏ j : Fin k, (max 0 ((s a : ℝ) - (j.val : ℝ)) / (N : ℝ)) := by refine Finset.sum_congr rfl (fun a _ => ?_) congr 1; unfold fallingKernel refine Finset.prod_congr rfl (fun j _ => ?_) rw [← sub_div] rcases le_total 0 ((s a : ℝ) - (j.val : ℝ)) with h | h · rw [max_eq_right (div_nonneg h (le_of_lt hNpos)), max_eq_right h] · rw [max_eq_left (div_nonpos_of_nonpos_of_nonneg h (le_of_lt hNpos)), max_eq_left h, zero_div] rw [← hlhs, ← hrhs] exact hjen /-- **Theorem 3.4 (Without-Replacement Extraction Dominance)**: Sampling `k` distinct challenges without replacement dominates `k` independent runs: `∏_{j=0}^{k-1} ((s - j) / N) ≤ C(s, k) / C(N, k)` for all `k ≤ s ≤ N` (`1 ≤ N`). -/ theorem without_replacement_dominates_with_replacement {k s N : ℕ} (hks : k ≤ s) (hsN : s ≤ N) (hN : 1 ≤ N) : ∏ j : Fin k, (((s : ℝ) - (j.val : ℝ)) / (N : ℝ)) ≤ (s.choose k : ℝ) / (N.choose k : ℝ) := by have hNpos : (0 : ℝ) < N := by exact_mod_cast hN have hdesc_eq : ∀ n : ℕ, k ≤ n → (n.choose k : ℝ) * (Nat.factorial k : ℝ) = ∏ j : Fin k, ((n : ℝ) - (j.val : ℝ)) := by intro n hkn have hnat : n.choose k * Nat.factorial k = n.descFactorial k := by rw [Nat.descFactorial_eq_factorial_mul_choose, mul_comm] have hcast : (n.choose k : ℝ) * (Nat.factorial k : ℝ) = (n.descFactorial k : ℝ) := by exact_mod_cast hnat rw [hcast] clear hnat hcast induction k with | zero => simp | succ m ih => rw [Nat.descFactorial_succ, Fin.prod_univ_castSucc] simp only [Fin.val_castSucc, Fin.val_last] push_cast rw [← ih (by omega) (by omega), Nat.cast_sub (by omega)] ring have hfact_pos : (0 : ℝ) < Nat.factorial k := by exact_mod_cast Nat.factorial_pos k have hchooseN_pos : (0 : ℝ) < N.choose k := by exact_mod_cast Nat.choose_pos (hks.trans hsN) have hratio : (s.choose k : ℝ) / (N.choose k : ℝ) = ∏ j : Fin k, (((s : ℝ) - (j.val : ℝ)) / ((N : ℝ) - (j.val : ℝ))) := by rw [Finset.prod_div_distrib, ← hdesc_eq s hks, ← hdesc_eq N (hks.trans hsN)] field_simp [ne_of_gt hfact_pos, ne_of_gt hchooseN_pos] rw [hratio] refine Finset.prod_le_prod (fun j _ => div_nonneg (by have : j.val ≤ s := (le_of_lt j.isLt).trans hks have : (j.val : ℝ) ≤ s := by exact_mod_cast this linarith) (le_of_lt hNpos)) (fun j _ => ?_) have hNj_pos : (0 : ℝ) < (N : ℝ) - (j.val : ℝ) := by have : j.val < N := lt_of_lt_of_le j.isLt (hks.trans hsN) have : (j.val : ℝ) < N := by exact_mod_cast this linarith have hsj_nn : 0 ≤ (s : ℝ) - (j.val : ℝ) := by have : j.val ≤ s := (le_of_lt j.isLt).trans hks have : (j.val : ℝ) ≤ s := by exact_mod_cast this linarith exact div_le_div_of_nonneg_left hsj_nn hNj_pos (by linarith [Nat.cast_nonneg (α := ℝ) j.val]) /-- **Theorem 3.5 (Exact `t`-Fold Parallel Repetition Soundness)**: Under independent challenge distributions `μ i`, if each coordinate `i` has acceptance probability `≤ κ i` on a false statement, the joint acceptance probability across all `t` parallel copies is at most `∏ i, κ i`. -/ theorem parallel_repetition_soundness_exact {t : ℕ} {C : Type*} [Fintype C] [DecidableEq C] (μ : Fin t → C → ℝ) (hμ : ∀ i, IsProbDist (μ i)) (S : Fin t → Finset C) (κ : Fin t → ℝ) (hκ : ∀ i, ∑ c ∈ S i, μ i c ≤ κ i) : ∑ v ∈ Fintype.piFinset S, ∏ i : Fin t, μ i (v i) ≤ ∏ i : Fin t, κ i := by have hprod : ∀ {m : ℕ} (f : Fin m → C → ℝ) (T : Fin m → Finset C), ∑ v ∈ Fintype.piFinset T, ∏ i : Fin m, f i (v i) = ∏ i : Fin m, ∑ c ∈ T i, f i c := by intro m induction m with | zero => intro f T; rw [piFinset_fin0_eq_singleton]; simp | succ m ih => intro f T rw [sum_piFinset_succ, Fin.prod_univ_succ] have hinner : ∀ a ∈ T 0, ∑ tail ∈ Fintype.piFinset (fun i : Fin m => T i.succ), ∏ i : Fin (m + 1), f i ((Fin.cons a tail : Fin (m + 1) → C) i) = f 0 a * ∏ i : Fin m, ∑ c ∈ T i.succ, f i.succ c := by intro a _ have hstep : ∀ tail : Fin m → C, ∏ i : Fin (m + 1), f i ((Fin.cons a tail : Fin (m + 1) → C) i) = f 0 a * ∏ i : Fin m, f i.succ (tail i) := fun tail => by rw [Fin.prod_univ_succ]; simp simp_rw [hstep, ← Finset.mul_sum, ih] rw [Finset.sum_congr rfl hinner, ← Finset.sum_mul] rw [hprod] refine Finset.prod_le_prod (fun i _ => Finset.sum_nonneg (fun c _ => (hμ i).1 c)) (fun i _ => hκ i) /-! ### Maurer Universal Group-Homomorphism Σ-Protocol (Schnorr / Okamoto / Chaum–Pedersen) -/ section MaurerSigma section Algebraic variable {K H G : Type*} [Field K] [AddCommGroup H] [AddCommGroup G] [Module K H] [Module K G] /-- Verifier check for Maurer's universal linear-homomorphism Σ-protocol `ψ : H →ₗ[K] G`: on statement `y : G`, commitment `a : G`, challenge `c : K`, response `z : H`, accept iff `ψ z = a + c • y`. -/ def maurerVerify (ψ : H →ₗ[K] G) (y a : G) (c : K) (z : H) : Prop := ψ z = a + c • y /-- **Theorem 3.6a (Perfect Completeness of Maurer's Universal Σ-Protocol)**. -/ theorem maurer_sigma_completeness (ψ : H →ₗ[K] G) {w : H} {y : G} (hrel : ψ w = y) (r : H) (c : K) : maurerVerify ψ y (ψ r) c (r + c • w) := by unfold maurerVerify rw [map_add, map_smul, hrel] /-- **Theorem 3.6b (Exact 2-Special Soundness & Explicit Algebraic Extractor)**: From ANY two accepting transcripts `(a, c₁, z₁)` and `(a, c₂, z₂)` with `c₁ ≠ c₂`, the explicit extractor `w_ext = (c₁ - c₂)⁻¹ • (z₁ - z₂)` satisfies `ψ w_ext = y`. -/ theorem maurer_sigma_two_special_soundness (ψ : H →ₗ[K] G) {y a : G} {c₁ c₂ : K} {z₁ z₂ : H} (hne : c₁ ≠ c₂) (h1 : maurerVerify ψ y a c₁ z₁) (h2 : maurerVerify ψ y a c₂ z₂) : ψ ((c₁ - c₂)⁻¹ • (z₁ - z₂)) = y := by unfold maurerVerify at h1 h2 have hsub : ψ (z₁ - z₂) = (c₁ - c₂) • y := by rw [map_sub, h1, h2, sub_smul]; abel rw [map_smul, hsub, smul_smul, inv_mul_cancel₀ (sub_ne_zero.mpr hne), one_smul] /-- **Theorem 3.6c (Exact Nonce-Reuse Witness Recovery Duality)**: If the prover reuses the same nonce `r` across two distinct challenges `c₁ ≠ c₂`, the exact special-soundness extractor deterministically recovers the secret witness `w`. -/ theorem maurer_sigma_nonce_reuse_witness_recovery (w r : H) {c₁ c₂ : K} (hne : c₁ ≠ c₂) : (c₁ - c₂)⁻¹ • ((r + c₁ • w) - (r + c₂ • w)) = w := by have hsub : (r + c₁ • w) - (r + c₂ • w) = (c₁ - c₂) • w := by rw [sub_smul]; abel rw [hsub, smul_smul, inv_mul_cancel₀ (sub_ne_zero.mpr hne), one_smul] end Algebraic section Transcripts variable {K H C : Type*} [Field K] [AddCommGroup H] [Module K H] [Fintype H] [Fintype C] /-- Real transcript distribution on `(c, z) ∈ C × H` (since `a = ψ z - c • y` is uniquely determined by `(c, z)` on every accepting transcript) for witness `w`, nonce distribution `ν`, challenge map `emb : C → K`, and verifier challenge distribution `μ'`. -/ def realTranscriptDist (emb : C → K) (w : H) (ν : H → ℝ) (μ' : C → ℝ) : C × H → ℝ := fun cz => μ' cz.1 * ν (cz.2 - emb cz.1 • w) /-- Simulator transcript distribution on `(c, z) ∈ C × H`: samples `c ∼ μ` and `z ∼ Unif(H)`. -/ noncomputable def simTranscriptDist (μ : C → ℝ) : C × H → ℝ := fun cz => μ cz.1 * unifDist H cz.2 /-- **Theorem 3.7 (Exact Product-Measure Transcript Isomorphism for Maurer Σ-Protocols)**: For ANY witness `w`, ANY nonce distribution `ν`, ANY real challenge distribution `μ'`, and ANY simulator challenge distribution `μ`: `TV(P_real(w; ν, μ'), P_sim(μ)) = TV(μ' ⊗ ν, μ ⊗ Unif(H))`. -/ theorem maurer_sigma_exact_product_tv_isomorphism (emb : C → K) (w : H) (ν : H → ℝ) (μ' μ : C → ℝ) : tvDist (realTranscriptDist emb w ν μ') (simTranscriptDist (H := H) μ) = tvDist (prodDist μ' ν) (prodDist μ (unifDist H)) := by -- Bijection (c, r) ↦ (c, r + emb c • w) on C × H let e : C × H ≃ C × H := { toFun := fun cr => (cr.1, cr.2 + emb cr.1 • w) invFun := fun cz => (cz.1, cz.2 - emb cz.1 • w) left_inv := fun cr => Prod.ext rfl (by dsimp; abel) right_inv := fun cz => Prod.ext rfl (by dsimp; abel) } have hcomp_real : realTranscriptDist emb w ν μ' ∘ e = prodDist μ' ν := by ext cr; simp only [Function.comp_apply, realTranscriptDist, prodDist, e, Equiv.coe_fn_mk] congr 2; abel have hcomp_sim : simTranscriptDist (H := H) μ ∘ e = prodDist μ (unifDist H) := by ext cr; rfl rw [← tvDist_equiv e, hcomp_real, hcomp_sim] /-- **Theorem 3.8a (Perfect HVZK for Arbitrary Challenge Distributions)**: With a uniform nonce `ν = Unif(H)`, statistical distance is identically `0` for EVERY challenge distribution `μ` (even adversarially biased!). -/ theorem maurer_sigma_perfect_hvzk (emb : C → K) (w : H) (μ : C → ℝ) : tvDist (realTranscriptDist emb w (unifDist H) μ) (simTranscriptDist (H := H) μ) = 0 := by rw [maurer_sigma_exact_product_tv_isomorphism, tvDist_self] /-- **Theorem 3.8b (Exact Degraded-HVZK Two-Sided Submultiplicative Sandwich)**: When nonce randomness degrades (`ν ≠ Unif(H)`) and/or verifier challenges mismatch (`μ' ≠ μ`), the exact transcript statistical distance obeys: `max(TV(μ', μ), TV(ν, Unif)) ≤ TV(P_real, P_sim) ≤ 1 - (1 - TV(μ', μ))(1 - TV(ν, Unif))`. -/ theorem maurer_sigma_degraded_hvzk_sandwich [Nonempty H] (emb : C → K) (w : H) {ν : H → ℝ} {μ' μ : C → ℝ} (hν : IsProbDist ν) (hμ' : IsProbDist μ') (hμ : IsProbDist μ) : max (tvDist μ' μ) (tvDist ν (unifDist H)) ≤ tvDist (realTranscriptDist emb w ν μ') (simTranscriptDist (H := H) μ) ∧ tvDist (realTranscriptDist emb w ν μ') (simTranscriptDist (H := H) μ) ≤ 1 - (1 - tvDist μ' μ) * (1 - tvDist ν (unifDist H)) := by rw [maurer_sigma_exact_product_tv_isomorphism] exact ⟨max_le (tvDist_prod_ge_left hν isProbDist_unifDist) (tvDist_prod_ge_right hμ' hμ), tvDist_prod_le_submult hμ' hμ hν isProbDist_unifDist⟩ /-- **Corollary (Exact Nonce-Bias Equality)**: When verifier challenges match (`μ' = μ`), the HVZK statistical distance equals `TV(ν, Unif(H))` EXACTLY. -/ theorem maurer_sigma_exact_nonce_bias_tv [Nonempty H] (emb : C → K) (w : H) {ν : H → ℝ} {μ : C → ℝ} (hν : IsProbDist ν) (hμ : IsProbDist μ) : tvDist (realTranscriptDist emb w ν μ) (simTranscriptDist (H := H) μ) = tvDist ν (unifDist H) := by have hs := maurer_sigma_degraded_hvzk_sandwich emb w hν hμ hμ rw [tvDist_self] at hs have hnn := tvDist_nonneg ν (unifDist H) linarith [le_max_right (0 : ℝ) (tvDist ν (unifDist H)), hs.1, hs.2] /-- **Theorem 3.9 (Exact Witness-Distinguishing Leakage under Biased Nonces)**: For any two witnesses `w₁, w₂ : H` (e.g. `ψ w₁ = ψ w₂ = y` in Okamoto/Pedersen), `TV(P_real(w₁; ν, μ), P_real(w₂; ν, μ)) = ∑_c μ(c) · TV(ν, ν shifted by c•(w₁ - w₂))`. In particular, for uniform nonces `ν = Unif(H)`, witness indistinguishability is PERFECT (`= 0`)! -/ theorem maurer_sigma_witness_indistinguishability_exact (emb : C → K) (w₁ w₂ : H) (ν : H → ℝ) {μ : C → ℝ} (hμ0 : ∀ c, 0 ≤ μ c) : tvDist (realTranscriptDist emb w₁ ν μ) (realTranscriptDist emb w₂ ν μ) = ∑ c : C, μ c * tvDist ν (fun r => ν (r + emb c • (w₁ - w₂))) := by unfold tvDist realTranscriptDist rw [Fintype.sum_prod_type, Finset.sum_div] refine Finset.sum_congr rfl (fun c _ => ?_) have hshift : ∑ z : H, |μ c * ν (z - emb c • w₁) - μ c * ν (z - emb c • w₂)| = μ c * ∑ r : H, |ν r - ν (r + emb c • (w₁ - w₂))| := by have hfac : ∀ z : H, |μ c * ν (z - emb c • w₁) - μ c * ν (z - emb c • w₂)| = μ c * |ν (z - emb c • w₁) - ν (z - emb c • w₂)| := fun z => by rw [← mul_sub, abs_mul, abs_of_nonneg (hμ0 c)] rw [Finset.sum_congr rfl (fun z _ => hfac z), ← Finset.mul_sum] congr 1 let eH : H ≃ H := { toFun := fun z => z - emb c • w₁ invFun := fun r => r + emb c • w₁ left_inv := fun z => by dsimp; abel right_inv := fun r => by dsimp; abel } refine Fintype.sum_equiv eH _ _ (fun z => ?_) have hdiff : z - emb c • w₂ = (z - emb c • w₁) + emb c • (w₁ - w₂) := by rw [smul_sub]; abel simp only [eH, Equiv.coe_fn_mk, hdiff] rw [hshift]; ring theorem maurer_sigma_perfect_witness_indistinguishability (emb : C → K) (w₁ w₂ : H) {μ : C → ℝ} (hμ0 : ∀ c, 0 ≤ μ c) : tvDist (realTranscriptDist emb w₁ (unifDist H) μ) (realTranscriptDist emb w₂ (unifDist H) μ) = 0 := by rw [maurer_sigma_witness_indistinguishability_exact emb w₁ w₂ (unifDist H) hμ0] refine Finset.sum_eq_zero (fun c _ => ?_) have h0 : tvDist (unifDist H) (fun _ => unifDist H (0 : H)) = 0 := by simp [tvDist, unifDist] have heq : (fun r => unifDist H (r + emb c • (w₁ - w₂))) = unifDist H := rfl rw [heq, tvDist_self, mul_zero] end Transcripts end MaurerSigma end Pillar3 end ZkPcpSumcheck /-! ============================================================================ AXIOM HYGIENE AUDIT — ALL 65 THEOREMS ============================================================================ -/ -- Pillar 1: Exact Sum-Check, Optimal Cheating Provers, Subgroup Obstruction & Schwartz-Zippel #print axioms ZkPcpSumcheck.prodComplement_le_sum #print axioms ZkPcpSumcheck.prodComplement_lt_sum #print axioms ZkPcpSumcheck.sumCheck_honest_accept #print axioms ZkPcpSumcheck.sumCheck_honest_completeness #print axioms ZkPcpSumcheck.sumCheck_exact_product_soundness #print axioms ZkPcpSumcheck.sumCheck_lfkn_union_bound #print axioms ZkPcpSumcheck.sumCheck_subset_refined_soundness #print axioms ZkPcpSumcheck.optimalCheatingProver_accept_iff #print axioms ZkPcpSumcheck.sumCheck_optimal_cheating_prover_exact #print axioms ZkPcpSumcheck.sumCheck_universal_sharpness #print axioms ZkPcpSumcheck.subgroup_poly_sum_eq_card_mul_eval_zero #print axioms ZkPcpSumcheck.subgroup_zero_challenge_obstruction #print axioms ZkPcpSumcheck.subgroup_rootWeight_vanishPoly #print axioms ZkPcpSumcheck.schwartz_zippel_individual_degree #print axioms ZkPcpSumcheck.schwartz_zippel_individual_degree_sharp #print axioms ZkPcpSumcheck.round_by_round_product_composition -- Pillar 2: Exact BLR, BCHKS Phase Transitions, Finite-n Gowers-U2/U3 & RM2 Testing #print axioms ZkPcpSumcheck.walsh_inversion #print axioms ZkPcpSumcheck.walsh_parseval #print axioms ZkPcpSumcheck.anti_linear_rigidity #print axioms ZkPcpSumcheck.blrReject_eq_fourier #print axioms ZkPcpSumcheck.blrReject_ge_linDist #print axioms ZkPcpSumcheck.blrReject_exact_sumFree_identity #print axioms ZkPcpSumcheck.blrReject_ge_three_sub_six_sq #print axioms ZkPcpSumcheck.blrReject_le_three_sub_two_sq #print axioms ZkPcpSumcheck.blr_finite_n_gowersU2_sq #print axioms ZkPcpSumcheck.blr_finite_n_gowersU2_sharp #print axioms ZkPcpSumcheck.blr_finite_n_strictly_dominates_classical #print axioms ZkPcpSumcheck.plurality_eq_nearest_linear_below_quarter #print axioms ZkPcpSumcheck.bchks_lemma_4_1 #print axioms ZkPcpSumcheck.bchks_lemma_4_2 #print axioms ZkPcpSumcheck.bchks_linear_plurality_three_eighths #print axioms ZkPcpSumcheck.blrReject_ge_plurality_var #print axioms ZkPcpSumcheck.coppersmith_two_ninths_plurality_linear #print axioms ZkPcpSumcheck.sumFree_hyperplane_witness_exact #print axioms ZkPcpSumcheck.bchks_45_128_witness_all_n #print axioms ZkPcpSumcheck.bchks4_hits_finite_n_gowersU2_equality #print axioms ZkPcpSumcheck.walsh_bentFn #print axioms ZkPcpSumcheck.maiorana_mcfarland_bent_exact #print axioms ZkPcpSumcheck.rm2Reject_eq_gowersU3 #print axioms ZkPcpSumcheck.gowers_u2_le_u3 #print axioms ZkPcpSumcheck.gowersU3_sharp_finite_n_floor #print axioms ZkPcpSumcheck.rm2Reject_sharp_ceiling #print axioms ZkPcpSumcheck.bentFn_rm2_complete #print axioms ZkPcpSumcheck.cubic_witness_rm2_exact_ceiling #print axioms ZkPcpSumcheck.rm2Reject_quadratic_lower_cubic_upper -- Pillar 3: Algebraic Zero-Knowledge, k-Special Soundness, Rewinding & Product-TV HVZK #print axioms ZkPcpSumcheck.tvDist_eq_one_sub_sum_min #print axioms ZkPcpSumcheck.tvDist_prod_ge_left #print axioms ZkPcpSumcheck.tvDist_prod_ge_right #print axioms ZkPcpSumcheck.tvDist_prod_le_submult #print axioms ZkPcpSumcheck.tvDist_submult_lt_add #print axioms ZkPcpSumcheck.tvDist_subsetUnif_unif #print axioms ZkPcpSumcheck.kSpecialSound_nonuniform_knowledge_error #print axioms ZkPcpSumcheck.twoRun_rewinding_nonuniform_entropy #print axioms ZkPcpSumcheck.kRun_rewinding_falling_factorial_jensen #print axioms ZkPcpSumcheck.without_replacement_dominates_with_replacement #print axioms ZkPcpSumcheck.parallel_repetition_soundness_exact #print axioms ZkPcpSumcheck.maurer_sigma_completeness #print axioms ZkPcpSumcheck.maurer_sigma_two_special_soundness #print axioms ZkPcpSumcheck.maurer_sigma_nonce_reuse_witness_recovery #print axioms ZkPcpSumcheck.maurer_sigma_exact_product_tv_isomorphism #print axioms ZkPcpSumcheck.maurer_sigma_perfect_hvzk #print axioms ZkPcpSumcheck.maurer_sigma_degraded_hvzk_sandwich #print axioms ZkPcpSumcheck.maurer_sigma_exact_nonce_bias_tv #print axioms ZkPcpSumcheck.maurer_sigma_witness_indistinguishability_exact #print axioms ZkPcpSumcheck.maurer_sigma_perfect_witness_indistinguishability