introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
54.4 kB
import Mathlib.Algebra.BigOperators.Expect import Mathlib.Algebra.Order.BigOperators.Expect import Mathlib.Algebra.Ring.GeomSum import Mathlib.Algebra.Ring.Parity import Mathlib.Basic.Real.Basic import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring import OAI.Computability.BinPacking.Games.Reindexing import OAI.Computability.BinPacking.PCP.BinaryFormula namespace OAI noncomputable section namespace BinPackingGames.Foundations.Hastad section open scoped BigOperators open Finset abbrev Cube (I : Type*) := I β†’ Bool def bitSign (b : Bool) : ℝ := if b then -1 else 1 @[simp] theorem bitSign_sq (b : Bool) : bitSign b ^ 2 = 1 := by cases b <;> norm_num [bitSign] theorem bitSign_xor (b c : Bool) : bitSign (b ^^ c) = bitSign b * bitSign c := by cases b <;> cases c <;> norm_num [bitSign] def cubeXor {I : Type*} (x y : Cube I) : Cube I := fun i => x i ^^ y i def walsh {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) : ℝ := ∏ i, bitSign (s i && x i) theorem walsh_symm {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) : walsh s x = walsh x s := by simp [walsh, Bool.and_comm] @[simp] theorem walsh_sq {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) : walsh s x ^ 2 = 1 := by simp [walsh, ← Finset.prod_pow] theorem walsh_xor {I : Type*} [Fintype I] [DecidableEq I] (s x y : Cube I) : walsh s (cubeXor x y) = walsh s x * walsh s y := by simp only [walsh, ← Finset.prod_mul_distrib] apply Finset.prod_congr rfl intro i _ simp only [cubeXor] cases s i <;> cases x i <;> cases y i <;> norm_num [bitSign] theorem coordinate_orthogonality (s t : Bool) : (βˆ‘ x : Bool, bitSign (s && x) * bitSign (t && x)) = if s = t then 2 else 0 := by cases s <;> cases t <;> norm_num [bitSign, Fintype.sum_bool] theorem walsh_sum_orthogonality {I : Type*} [Fintype I] [DecidableEq I] (s t : Cube I) : (βˆ‘ x, walsh s x * walsh t x) = if s = t then (Fintype.card (Cube I) : ℝ) else 0 := by classical simp only [walsh, ← Finset.prod_mul_distrib] rw [← Fintype.prod_sum (fun (i : I) (b : Bool) => bitSign (s i && b) * bitSign (t i && b))] simp only [coordinate_orthogonality] by_cases h : s = t Β· subst t simp Β· rw [ite_eq_right h] obtain ⟨i, hi⟩ := Function.ne_iff.mp h apply Finset.prod_eq_zero (Finset.mem_univ i) exact ite_eq_right hi theorem walsh_orthogonality {I : Type*} [Fintype I] [DecidableEq I] (s t : Cube I) : (𝔼 x, walsh s x * walsh t x) = if s = t then 1 else 0 := by classical rw [Fintype.expect_eq_sum_div_card, walsh_sum_orthogonality] split_ifs <;> simp def coefficient {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β†’ ℝ) (s : Cube I) : ℝ := 𝔼 x, f x * walsh s x theorem walsh_inversion {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β†’ ℝ) (x : Cube I) : (βˆ‘ s, coefficient f s * walsh s x) = f x := by classical unfold coefficient simp_rw [Finset.expect_mul] rw [← Finset.expect_sum_comm] have h (y : Cube I) : (βˆ‘ s, (f y * walsh s y) * walsh s x) = f y * (if y = x then (Fintype.card (Cube I) : ℝ) else 0) := by simp only [mul_assoc, ← Finset.mul_sum] congr 1 simp_rw [walsh_symm (x := y), walsh_symm (x := x)] exact walsh_sum_orthogonality y x simp_rw [h] rw [Fintype.expect_eq_sum_div_card] simp theorem walsh_inner {I : Type*} [Fintype I] [DecidableEq I] (f g : Cube I β†’ ℝ) : (βˆ‘ s, coefficient f s * coefficient g s) = 𝔼 x, f x * g x := by classical unfold coefficient simp_rw [Finset.mul_expect] rw [← Finset.expect_sum_comm] apply Finset.expect_congr rfl intro x _ have h : (βˆ‘ s, (𝔼 y, f y * walsh s y) * (g x * walsh s x)) = g x * (βˆ‘ s, coefficient f s * walsh s x) := by simp only [Finset.mul_sum, coefficient] apply Finset.sum_congr rfl intro s _ ring rw [h, walsh_inversion] ring theorem walsh_parseval {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β†’ ℝ) : (βˆ‘ s, coefficient f s ^ 2) = 𝔼 x, f x ^ 2 := by simpa [pow_two] using walsh_inner f f theorem sign_parseval {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β†’ Bool) : (βˆ‘ s, coefficient (fun x => bitSign (f x)) s ^ 2) = 1 := by rw [walsh_parseval] simp open scoped BigOperators open Finset variable {I J : Type*} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] def support (s : Cube I) : Finset I := Finset.univ.filter fun i => s i = true def noiseWeight (Ξ΅ : ℝ) (ΞΌ : Cube I) : ℝ := ∏ i, if ΞΌ i then Ξ΅ else 1 - Ξ΅ omit [DecidableEq I] in theorem noiseWeight_nonneg {Ξ΅ : ℝ} (hΞ΅ : 0 ≀ Ξ΅) (hΞ΅' : Ξ΅ ≀ 1) (ΞΌ : Cube I) : 0 ≀ noiseWeight Ξ΅ ΞΌ := by apply Finset.prod_nonneg intro i _ split <;> linarith theorem noiseWeight_sum (Ξ΅ : ℝ) : (βˆ‘ ΞΌ : Cube I, noiseWeight Ξ΅ ΞΌ) = 1 := by unfold noiseWeight rw [← Fintype.prod_sum (fun (_ : I) (b : Bool) => if b then Ξ΅ else 1 - Ξ΅)] simp theorem noise_walsh (Ξ΅ : ℝ) (s : Cube I) : (βˆ‘ ΞΌ, noiseWeight Ξ΅ ΞΌ * walsh s ΞΌ) = (1 - 2 * Ξ΅) ^ (support s).card := by unfold noiseWeight walsh simp only [← Finset.prod_mul_distrib] rw [← Fintype.prod_sum (fun i b => (if b then Ξ΅ else 1 - Ξ΅) * bitSign (s i && b))] have hc (i : I) : (βˆ‘ b : Bool, (if b then Ξ΅ else 1 - Ξ΅) * bitSign (s i && b)) = if s i then 1 - 2 * Ξ΅ else 1 := by cases s i <;> simp [bitSign]; ring simp_rw [hc] simp [support, Finset.prod_ite] def thirdQuery (Ο€ : J β†’ I) (f : Cube I) (g ΞΌ : Cube J) : Cube J := cubeXor g (cubeXor (fun y => f (Ο€ y)) ΞΌ) theorem walsh_autocorrelation (B : Cube J β†’ ℝ) (h : Cube J) : (𝔼 g, B g * B (cubeXor g h)) = βˆ‘ s, coefficient B s ^ 2 * walsh s h := by conv_lhs => enter [2, g, 2] rw [← walsh_inversion B (cubeXor g h)] simp_rw [Finset.mul_sum, walsh_xor] rw [Finset.expect_sum_comm] apply Finset.sum_congr rfl intro s _ have hterm : (fun g => B g * (coefficient B s * (walsh s g * walsh s h))) = (fun g => (coefficient B s * walsh s h) * (B g * walsh s g)) := by funext g ring rw [hterm, ← Finset.mul_expect] change (coefficient B s * walsh s h) * coefficient B s = _ ring def projectedCoefficient (Ο€ : J β†’ I) (A : Cube I β†’ ℝ) (s : Cube J) : ℝ := 𝔼 f, A f * walsh s (fun y => f (Ο€ y)) def testBias (Ξ΅ : ℝ) (Ο€ : J β†’ I) (A : Cube I β†’ ℝ) (B : Cube J β†’ ℝ) : ℝ := 𝔼 f, βˆ‘ ΞΌ, noiseWeight Ξ΅ ΞΌ * A f * (𝔼 g, B g * B (thirdQuery Ο€ f g ΞΌ)) theorem testBias_fourier (Ξ΅ : ℝ) (Ο€ : J β†’ I) (A : Cube I β†’ ℝ) (B : Cube J β†’ ℝ) : testBias Ξ΅ Ο€ A B = βˆ‘ s, projectedCoefficient Ο€ A s * coefficient B s ^ 2 * (1 - 2 * Ξ΅) ^ (support s).card := by unfold testBias thirdQuery simp_rw [walsh_autocorrelation, Finset.mul_sum] conv_lhs => enter [2, f] rw [Finset.sum_comm] rw [Finset.expect_sum_comm] apply Finset.sum_congr rfl intro s _ have hterm (f : Cube I) : (βˆ‘ ΞΌ, noiseWeight Ξ΅ ΞΌ * A f * (coefficient B s ^ 2 * walsh s (cubeXor (fun y => f (Ο€ y)) ΞΌ))) = (A f * walsh s (fun y => f (Ο€ y))) * coefficient B s ^ 2 * (1 - 2 * Ξ΅) ^ (support s).card := by simp_rw [walsh_xor] have heq (ΞΌ : Cube J) : noiseWeight Ξ΅ ΞΌ * A f * (coefficient B s ^ 2 * (walsh s (fun y => f (Ο€ y)) * walsh s ΞΌ)) = ((A f * walsh s (fun y => f (Ο€ y))) * coefficient B s ^ 2) * (noiseWeight Ξ΅ ΞΌ * walsh s ΞΌ) := by ring simp_rw [heq] rw [← Finset.mul_sum, noise_walsh] simp_rw [hterm, ← Finset.expect_mul] rfl def testAcceptance (Ξ΅ : ℝ) (Ο€ : J β†’ I) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) : ℝ := 𝔼 f, βˆ‘ ΞΌ, noiseWeight Ξ΅ ΞΌ * (𝔼 g, if A f ^^ B g ^^ B (thirdQuery Ο€ f g ΞΌ) then 0 else 1) theorem threeBit_indicator (a b c : Bool) : (if a ^^ b ^^ c then (0 : ℝ) else 1) = (1 + bitSign a * bitSign b * bitSign c) / 2 := by cases a <;> cases b <;> cases c <;> norm_num [bitSign] theorem testAcceptance_eq (Ξ΅ : ℝ) (Ο€ : J β†’ I) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) : testAcceptance Ξ΅ Ο€ A B = (1 + testBias Ξ΅ Ο€ (fun f => bitSign (A f)) (fun g => bitSign (B g))) / 2 := by unfold testAcceptance testBias simp_rw [threeBit_indicator, div_eq_mul_inv, ← Finset.expect_mul, Finset.expect_add_distrib] simp only [Fintype.expect_const] have hterm (f : Cube I) (ΞΌ : Cube J) : noiseWeight Ξ΅ ΞΌ * ((1 + 𝔼 g, bitSign (A f) * bitSign (B g) * bitSign (B (thirdQuery Ο€ f g ΞΌ))) * 2⁻¹) = (noiseWeight Ξ΅ ΞΌ + noiseWeight Ξ΅ ΞΌ * bitSign (A f) * (𝔼 g, bitSign (B g) * bitSign (B (thirdQuery Ο€ f g ΞΌ)))) * 2⁻¹ := by simp_rw [mul_assoc (bitSign (A f)), ← Finset.mul_expect] ring simp_rw [hterm, ← Finset.sum_mul, Finset.sum_add_distrib, noiseWeight_sum, ← Finset.expect_mul, Finset.expect_add_distrib] simp end section open scoped BigOperators open Finset variable {I : Type*} [Fintype I] [DecidableEq I] def cubeFlip (f : Cube I) : Cube I := fun i => !(f i) omit [Fintype I] [DecidableEq I] in @[simp] theorem cubeFlip_cubeFlip (f : Cube I) : cubeFlip (cubeFlip f) = f := by funext i simp [cubeFlip] @[simp] theorem bitSign_not (b : Bool) : bitSign (!b) = -bitSign b := by cases b <;> norm_num [bitSign] theorem sum_cubeFlip (F : Cube I β†’ ℝ) : (βˆ‘ f, F (cubeFlip f)) = βˆ‘ f, F f := by refine Finset.sum_bij (fun f _ => cubeFlip f) ?_ ?_ ?_ ?_ Β· intro f _ exact Finset.mem_univ _ Β· intro f _ g _ h have h' := congrArg cubeFlip h simpa only [cubeFlip_cubeFlip] using h' Β· intro g _ exact ⟨cubeFlip g, Finset.mem_univ _, cubeFlip_cubeFlip g⟩ Β· intro f _ rfl theorem coefficient_zero_of_odd (F : Cube I β†’ ℝ) (hF : βˆ€ f, F (cubeFlip f) = -F f) : coefficient F (fun _ => false) = 0 := by have hs : (βˆ‘ f, F f) = 0 := by have h := sum_cubeFlip F simp_rw [hF, Finset.sum_neg_distrib] at h linarith simp [coefficient, walsh, bitSign, Fintype.expect_eq_sum_div_card, hs] theorem coefficient_sign_zero_of_folded (A : Cube I β†’ Bool) (hA : βˆ€ f, A (cubeFlip f) = !(A f)) : coefficient (fun f => bitSign (A f)) (fun _ => false) = 0 := by apply coefficient_zero_of_odd intro f rw [hA, bitSign_not] def representative (iβ‚€ : I) (f : Cube I) : Cube I := if f iβ‚€ then cubeFlip f else f omit [Fintype I] [DecidableEq I] in theorem representative_at (iβ‚€ : I) (f : Cube I) : representative iβ‚€ f iβ‚€ = false := by cases hf : f iβ‚€ <;> simp [representative, cubeFlip, hf] omit [Fintype I] [DecidableEq I] in theorem representative_flip (iβ‚€ : I) (f : Cube I) : representative iβ‚€ (cubeFlip f) = representative iβ‚€ f := by cases hf : f iβ‚€ <;> simp [representative, cubeFlip, hf] abbrev HalfCube (iβ‚€ : I) := {f : Cube I // f iβ‚€ = false} def canonicalInput (iβ‚€ : I) (f : Cube I) : HalfCube iβ‚€ := ⟨representative iβ‚€ f, representative_at iβ‚€ f⟩ omit [Fintype I] [DecidableEq I] in theorem canonicalInput_flip (iβ‚€ : I) (f : Cube I) : canonicalInput iβ‚€ (cubeFlip f) = canonicalInput iβ‚€ f := by apply Subtype.ext exact representative_flip iβ‚€ f def foldedAnswer (iβ‚€ : I) (table : HalfCube iβ‚€ β†’ Bool) (f : Cube I) : Bool := table (canonicalInput iβ‚€ f) ^^ f iβ‚€ omit [Fintype I] [DecidableEq I] in theorem foldedAnswer_flip (iβ‚€ : I) (table : HalfCube iβ‚€ β†’ Bool) (f : Cube I) : foldedAnswer iβ‚€ table (cubeFlip f) = !(foldedAnswer iβ‚€ table f) := by unfold foldedAnswer rw [canonicalInput_flip] change (table (canonicalInput iβ‚€ f) ^^ !(f iβ‚€)) = !(table (canonicalInput iβ‚€ f) ^^ f iβ‚€) cases table (canonicalInput iβ‚€ f) <;> cases f iβ‚€ <;> rfl theorem foldedAnswer_zero_coefficient (iβ‚€ : I) (table : HalfCube iβ‚€ β†’ Bool) : coefficient (fun f => bitSign (foldedAnswer iβ‚€ table f)) (fun _ => false) = 0 := coefficient_sign_zero_of_folded _ (foldedAnswer_flip iβ‚€ table) omit [Fintype I] [DecidableEq I] in theorem foldedAnswer_dictator (iβ‚€ i : I) (f : Cube I) : foldedAnswer iβ‚€ (fun h => h.val i) f = f i := by cases hf : f iβ‚€ <;> cases hi : f i <;> simp [foldedAnswer, canonicalInput, representative, cubeFlip, hf, hi] def coordinateMask (i : I) : Cube I := fun j => decide (j = i) def cubeToggle (i : I) (f : Cube I) : Cube I := cubeXor f (coordinateMask i) omit [Fintype I] in @[simp] theorem cubeToggle_twice (i : I) (f : Cube I) : cubeToggle i (cubeToggle i f) = f := by funext j change ((f j ^^ coordinateMask i j) ^^ coordinateMask i j) = f j cases f j <;> cases coordinateMask i j <;> rfl theorem walsh_coordinateMask (s : Cube I) (i : I) : walsh s (coordinateMask i) = bitSign (s i) := by unfold walsh rw [Finset.prod_eq_single i] Β· simp [coordinateMask] Β· intro j _ hj simp [coordinateMask, hj, bitSign] Β· intro h exact False.elim (h (Finset.mem_univ _)) theorem walsh_cubeToggle (s : Cube I) (i : I) (f : Cube I) (hs : s i = true) : walsh s (cubeToggle i f) = -walsh s f := by rw [cubeToggle, walsh_xor, walsh_coordinateMask, hs] simp [bitSign] theorem sum_cubeToggle (i : I) (F : Cube I β†’ ℝ) : (βˆ‘ f, F (cubeToggle i f)) = βˆ‘ f, F f := by refine Finset.sum_bij (fun f _ => cubeToggle i f) ?_ ?_ ?_ ?_ Β· intro f _ exact Finset.mem_univ _ Β· intro f _ g _ h have h' := congrArg (cubeToggle i) h simpa only [cubeToggle_twice] using h' Β· intro g _ exact ⟨cubeToggle i g, Finset.mem_univ _, cubeToggle_twice i g⟩ Β· intro f _ rfl def restrictQuery (valid : I β†’ Bool) (f : Cube I) : Cube {i : I // valid i = true} := fun i => f i.val omit [Fintype I] in theorem restrictQuery_cubeToggle (valid : I β†’ Bool) (i : I) (hi : valid i = false) (f : Cube I) : restrictQuery valid (cubeToggle i f) = restrictQuery valid f := by funext j have hj : j.val β‰  i := by intro heq have hp := j.property rw [heq, hi] at hp contradiction simp [restrictQuery, cubeToggle, cubeXor, coordinateMask, hj] theorem conditioned_coefficient_zero_invalid (valid : I β†’ Bool) (B : Cube {i : I // valid i = true} β†’ ℝ) (s : Cube I) (i : I) (hi : valid i = false) (hs : s i = true) : coefficient (fun f => B (restrictQuery valid f)) s = 0 := by have hsum := sum_cubeToggle i (fun f => B (restrictQuery valid f) * walsh s f) simp_rw [restrictQuery_cubeToggle valid i hi, walsh_cubeToggle s i _ hs, mul_neg, Finset.sum_neg_distrib] at hsum have hz : (βˆ‘ f, B (restrictQuery valid f) * walsh s f) = 0 := by linarith simp [coefficient, Fintype.expect_eq_sum_div_card, hz] theorem conditioned_coefficient_support (valid : I β†’ Bool) (B : Cube {i : I // valid i = true} β†’ ℝ) (s : Cube I) (hne : coefficient (fun f => B (restrictQuery valid f)) s β‰  0) : βˆ€ i ∈ support s, valid i = true := by intro i hi have hs := (Finset.mem_filter.mp hi).2 cases hv : valid i Β· exact False.elim (hne (conditioned_coefficient_zero_invalid valid B s i hv hs)) Β· rfl def conditionedFoldedAnswer (valid : I β†’ Bool) (iβ‚€ : {i : I // valid i = true}) (table : HalfCube iβ‚€ β†’ Bool) (f : Cube I) : Bool := foldedAnswer iβ‚€ table (restrictQuery valid f) omit [Fintype I] [DecidableEq I] in theorem conditionedFoldedAnswer_flip (valid : I β†’ Bool) (iβ‚€ : {i : I // valid i = true}) (table : HalfCube iβ‚€ β†’ Bool) (f : Cube I) : conditionedFoldedAnswer valid iβ‚€ table (cubeFlip f) = !(conditionedFoldedAnswer valid iβ‚€ table f) := by change foldedAnswer iβ‚€ table (cubeFlip (restrictQuery valid f)) = _ exact foldedAnswer_flip iβ‚€ table (restrictQuery valid f) theorem conditionedFoldedAnswer_zero_coefficient (valid : I β†’ Bool) (iβ‚€ : {i : I // valid i = true}) (table : HalfCube iβ‚€ β†’ Bool) : coefficient (fun f => bitSign (conditionedFoldedAnswer valid iβ‚€ table f)) (fun _ => false) = 0 := coefficient_sign_zero_of_folded _ (conditionedFoldedAnswer_flip valid iβ‚€ table) omit [Fintype I] [DecidableEq I] in theorem conditionedFoldedAnswer_dictator (valid : I β†’ Bool) (iβ‚€ i : {i : I // valid i = true}) (f : Cube I) : conditionedFoldedAnswer valid iβ‚€ (fun h => h.val i) f = f i.val := by exact foldedAnswer_dictator iβ‚€ i (restrictQuery valid f) end open scoped BigOperators open Finset variable {I J : Type*} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] def parityProjection (Ο€ : J β†’ I) (s : Cube J) : Cube I := fun i => decide (Odd ((support s).filter fun y => Ο€ y = i).card) theorem walsh_support (s x : Cube I) : walsh s x = ∏ i ∈ support s, bitSign (x i) := by unfold walsh support rw [Finset.prod_filter] apply Finset.prod_congr rfl intro i _ cases s i <;> simp [bitSign] theorem sign_power_parity (b : Bool) (n : Nat) : bitSign b ^ n = bitSign (decide (Odd n) && b) := by cases b Β· simp [bitSign] Β· simp only [Bool.and_true, bitSign, ite_true, decide_eq_true_eq] rw [neg_one_pow_eq_ite] by_cases h : Even n Β· simp [h, Nat.not_odd_iff_even.mpr h] Β· simp [h, Nat.not_even_iff_odd.mp h] theorem walsh_pullback (Ο€ : J β†’ I) (s : Cube J) (f : Cube I) : walsh s (fun y => f (Ο€ y)) = walsh (parityProjection Ο€ s) f := by rw [walsh_support] rw [← Finset.prod_fiberwise' (support s) Ο€ (fun i => bitSign (f i))] unfold walsh parityProjection apply Finset.prod_congr rfl intro i _ simp only [Finset.prod_const] exact sign_power_parity (f i) _ theorem projectedCoefficient_eq (Ο€ : J β†’ I) (A : Cube I β†’ ℝ) (s : Cube J) : projectedCoefficient Ο€ A s = coefficient A (parityProjection Ο€ s) := by simp only [projectedCoefficient, coefficient, walsh_pullback] omit [DecidableEq J] in theorem projection_has_preimage (Ο€ : J β†’ I) (s : Cube J) (i : I) (hi : i ∈ support (parityProjection Ο€ s)) : βˆƒ y ∈ support s, Ο€ y = i := by have hodd : Odd ((support s).filter fun y => Ο€ y = i).card := by have hbit := (Finset.mem_filter.mp hi).2 simpa only [parityProjection, decide_eq_true_eq] using hbit have hp : 0 < ((support s).filter fun y => Ο€ y = i).card := by obtain ⟨n, hn⟩ := hodd omega obtain ⟨y, hy⟩ := Finset.card_pos.mp hp exact ⟨y, (Finset.mem_filter.mp hy).1, (Finset.mem_filter.mp hy).2⟩ theorem scaled_geometric_power_le_one {t : ℝ} (ht : 0 ≀ t) (ht' : t ≀ 1) (n : Nat) : (n : ℝ) * (1 - t) * t ^ n ≀ 1 := by have hsum : (n : ℝ) * t ^ n ≀ βˆ‘ j ∈ Finset.range n, t ^ j := by calc (n : ℝ) * t ^ n = βˆ‘ _j ∈ Finset.range n, t ^ n := by simp _ ≀ βˆ‘ j ∈ Finset.range n, t ^ j := by apply Finset.sum_le_sum intro j hj exact pow_le_pow_of_le_one ht ht' (Nat.le_of_lt (Finset.mem_range.mp hj)) have hm := mul_le_mul_of_nonneg_right hsum (sub_nonneg.mpr ht') rw [geom_sum_mul_neg] at hm have hp : 0 ≀ t ^ n := pow_nonneg ht _ nlinarith theorem noise_decay_bound {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) {k : Nat} (hk : 0 < k) : 4 * Ξ΅ * ((1 - 2 * Ξ΅) ^ k) ^ 2 ≀ 1 / (k : ℝ) := by have h := scaled_geometric_power_le_one (t := 1 - 2 * Ξ΅) (by linarith) (by linarith) (2 * k) have hkp : (0 : ℝ) < k := Nat.cast_pos.mpr hk apply (le_div_iffβ‚€ hkp).mpr have hpow : (1 - 2 * Ξ΅) ^ (2 * k) = ((1 - 2 * Ξ΅) ^ k) ^ 2 := by rw [Nat.mul_comm, pow_mul] rw [hpow] at h norm_num only [Nat.cast_mul, Nat.cast_ofNat] at h nlinarith def zeroMask : Cube I := fun _ => false omit [DecidableEq I] in theorem support_eq_empty_iff (s : Cube I) : support s = βˆ… ↔ s = zeroMask := by constructor Β· intro h funext i have hi : i βˆ‰ support s := by rw [h]; simp have : s i β‰  true := by simpa [support] using hi cases hs : s i <;> simp_all [zeroMask] Β· intro h subst s simp [zeroMask, support] omit [Fintype I] [DecidableEq J] in theorem parityProjection_zero (Ο€ : J β†’ I) : parityProjection Ο€ (zeroMask : Cube J) = zeroMask := by funext i simp [parityProjection, support, zeroMask] def agreementProbability (Ο€ : J β†’ I) (a : Cube I) (b : Cube J) : ℝ := (βˆ‘ i ∈ support a, (((support b).filter fun y => Ο€ y = i).card : ℝ)) / ((support a).card * (support b).card : ℝ) omit [DecidableEq J] in theorem agreementProbability_nonneg (Ο€ : J β†’ I) (a : Cube I) (b : Cube J) : 0 ≀ agreementProbability Ο€ a b := by unfold agreementProbability apply div_nonneg Β· exact Finset.sum_nonneg (fun _ _ => Nat.cast_nonneg _) Β· exact mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) omit [DecidableEq J] in theorem agreementProbability_projection (Ο€ : J β†’ I) (b : Cube J) (ha : (support (parityProjection Ο€ b)).Nonempty) : 1 / ((support b).card : ℝ) ≀ agreementProbability Ο€ (parityProjection Ο€ b) b := by have hca : (0 : ℝ) < (support (parityProjection Ο€ b)).card := Nat.cast_pos.mpr (Finset.card_pos.mpr ha) have hb : (support b).Nonempty := by obtain ⟨i, hi⟩ := ha obtain ⟨y, hy, _⟩ := projection_has_preimage Ο€ b i hi exact ⟨y, hy⟩ have hcb : (0 : ℝ) < (support b).card := Nat.cast_pos.mpr (Finset.card_pos.mpr hb) have hsum : ((support (parityProjection Ο€ b)).card : ℝ) ≀ βˆ‘ i ∈ support (parityProjection Ο€ b), (((support b).filter fun y => Ο€ y = i).card : ℝ) := by calc _ = βˆ‘ _i ∈ support (parityProjection Ο€ b), (1 : ℝ) := by simp _ ≀ _ := by apply Finset.sum_le_sum intro i hi obtain ⟨y, hy, hΟ€βŸ© := projection_has_preimage Ο€ b i hi have hp : 0 < ((support b).filter fun y => Ο€ y = i).card := Finset.card_pos.mpr ⟨y, Finset.mem_filter.mpr ⟨hy, hΟ€βŸ©βŸ© exact_mod_cast hp unfold agreementProbability apply (div_le_div_iffβ‚€ hcb (mul_pos hca hcb)).mpr nlinarith def decoderSuccess (Ο€ : J β†’ I) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) : ℝ := βˆ‘ b, coefficient (fun g => bitSign (B g)) b ^ 2 * (βˆ‘ a, coefficient (fun f => bitSign (A f)) a ^ 2 * agreementProbability Ο€ a b) def decodingEnergy (Ο€ : J β†’ I) (A : Cube I β†’ ℝ) (B : Cube J β†’ ℝ) : ℝ := βˆ‘ b, projectedCoefficient Ο€ A b ^ 2 * coefficient B b ^ 2 / (support b).card theorem decodingEnergy_le_success (Ο€ : J β†’ I) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) (hzero : coefficient (fun f => bitSign (A f)) zeroMask = 0) : decodingEnergy Ο€ (fun f => bitSign (A f)) (fun g => bitSign (B g)) ≀ decoderSuccess Ο€ A B := by unfold decodingEnergy decoderSuccess apply Finset.sum_le_sum intro b _ rw [projectedCoefficient_eq] have hsum : coefficient (fun f => bitSign (A f)) (parityProjection Ο€ b) ^ 2 * agreementProbability Ο€ (parityProjection Ο€ b) b ≀ βˆ‘ a, coefficient (fun f => bitSign (A f)) a ^ 2 * agreementProbability Ο€ a b := by apply Finset.single_le_sum (s := Finset.univ) (f := fun a => coefficient (fun f => bitSign (A f)) a ^ 2 * agreementProbability Ο€ a b) Β· intro a _ exact mul_nonneg (sq_nonneg _) (agreementProbability_nonneg Ο€ a b) Β· exact Finset.mem_univ _ have hm := mul_le_mul_of_nonneg_left hsum (sq_nonneg (coefficient (fun g => bitSign (B g)) b)) by_cases ha : (support (parityProjection Ο€ b)).Nonempty Β· have hagree := agreementProbability_projection Ο€ b ha have ht := mul_le_mul_of_nonneg_left hagree (mul_nonneg (sq_nonneg (coefficient (fun f => bitSign (A f)) (parityProjection Ο€ b))) (sq_nonneg (coefficient (fun g => bitSign (B g)) b))) have heq : coefficient (fun f => bitSign (A f)) (parityProjection Ο€ b) ^ 2 * coefficient (fun g => bitSign (B g)) b ^ 2 / (support b).card = (coefficient (fun f => bitSign (A f)) (parityProjection Ο€ b) ^ 2 * coefficient (fun g => bitSign (B g)) b ^ 2) * (1 / (support b).card) := by ring rw [heq] exact ht.trans (by convert hm using 1; ring) Β· have hempty : support (parityProjection Ο€ b) = βˆ… := Finset.not_nonempty_iff_eq_empty.mp ha have hz := (support_eq_empty_iff _).mp hempty simpa [hz, hzero] using hm theorem bias_sq_le_weighted_energy (Ξ΅ : ℝ) (Ο€ : J β†’ I) (A : Cube I β†’ ℝ) (B : Cube J β†’ Bool) : testBias Ξ΅ Ο€ A (fun g => bitSign (B g)) ^ 2 ≀ βˆ‘ b, (projectedCoefficient Ο€ A b * coefficient (fun g => bitSign (B g)) b * (1 - 2 * Ξ΅) ^ (support b).card) ^ 2 := by rw [testBias_fourier] have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun b => projectedCoefficient Ο€ A b * coefficient (fun g => bitSign (B g)) b * (1 - 2 * Ξ΅) ^ (support b).card) (fun b => coefficient (fun g => bitSign (B g)) b) rw [sign_parseval, mul_one] at h convert h using 1 congr 1 apply Finset.sum_congr rfl intro b _ ring theorem decoder_four_epsilon_bias_sq (Ξ΅ : ℝ) (Ο€ : J β†’ I) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) (hzero : coefficient (fun f => bitSign (A f)) zeroMask = 0) : 4 * Ξ΅ * testBias Ξ΅ Ο€ (fun f => bitSign (A f)) (fun g => bitSign (B g)) ^ 2 ≀ decoderSuccess Ο€ A B := by apply le_trans _ (decodingEnergy_le_success Ο€ A B hzero) have hcs := mul_le_mul_of_nonneg_left (bias_sq_le_weighted_energy Ξ΅ Ο€ (fun f => bitSign (A f)) B) (by linarith : 0 ≀ 4 * Ξ΅) apply hcs.trans rw [Finset.mul_sum] unfold decodingEnergy apply Finset.sum_le_sum intro b _ by_cases hk : 0 < (support b).card Β· have hd := noise_decay_bound hΞ΅ hΞ΅' hk have hm := mul_le_mul_of_nonneg_left hd (mul_nonneg (sq_nonneg (projectedCoefficient Ο€ (fun f => bitSign (A f)) b)) (sq_nonneg (coefficient (fun g => bitSign (B g)) b))) convert hm using 1 <;> ring Β· have hb : support b = βˆ… := Finset.card_eq_zero.mp (by omega) have hbzero := (support_eq_empty_iff b).mp hb subst b simp [projectedCoefficient_eq, parityProjection_zero, hzero, support, zeroMask] theorem folded_decoder_bound (Ξ΅ : ℝ) (Ο€ : J β†’ I) (iβ‚€ : I) (table : HalfCube iβ‚€ β†’ Bool) (B : Cube J β†’ Bool) (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) : 4 * Ξ΅ * testBias Ξ΅ Ο€ (fun f => bitSign (foldedAnswer iβ‚€ table f)) (fun g => bitSign (B g)) ^ 2 ≀ decoderSuccess Ο€ (foldedAnswer iβ‚€ table) B := by exact decoder_four_epsilon_bias_sq Ξ΅ Ο€ (foldedAnswer iβ‚€ table) B hΞ΅ hΞ΅' (foldedAnswer_zero_coefficient iβ‚€ table) def validAgreementProbability (valid : J β†’ Bool) (Ο€ : J β†’ I) (a : Cube I) (b : Cube J) : ℝ := (βˆ‘ i ∈ support a, (((support b).filter fun y => Ο€ y = i ∧ valid y = true).card : ℝ)) / ((support a).card * (support b).card : ℝ) omit [DecidableEq J] in theorem validAgreementProbability_eq (valid : J β†’ Bool) (Ο€ : J β†’ I) (a : Cube I) (b : Cube J) (hb : βˆ€ y ∈ support b, valid y = true) : validAgreementProbability valid Ο€ a b = agreementProbability Ο€ a b := by unfold validAgreementProbability agreementProbability congr 1 apply Finset.sum_congr rfl intro i _ congr 1 apply congrArg Finset.card apply Finset.filter_congr intro y hy simp [hb y hy] def validDecoderSuccess (valid : J β†’ Bool) (Ο€ : J β†’ I) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) : ℝ := βˆ‘ b, coefficient (fun g => bitSign (B g)) b ^ 2 * (βˆ‘ a, coefficient (fun f => bitSign (A f)) a ^ 2 * validAgreementProbability valid Ο€ a b) theorem conditioned_validDecoderSuccess (valid : J β†’ Bool) (Ο€ : J β†’ I) (A : Cube I β†’ Bool) (jβ‚€ : {j : J // valid j = true}) (table : HalfCube jβ‚€ β†’ Bool) : validDecoderSuccess valid Ο€ A (conditionedFoldedAnswer valid jβ‚€ table) = decoderSuccess Ο€ A (conditionedFoldedAnswer valid jβ‚€ table) := by unfold validDecoderSuccess decoderSuccess apply Finset.sum_congr rfl intro b _ by_cases hc : coefficient (fun g => bitSign (conditionedFoldedAnswer valid jβ‚€ table g)) b = 0 Β· simp [hc] Β· have hb : βˆ€ y ∈ support b, valid y = true := by apply conditioned_coefficient_support valid (fun g => bitSign (foldedAnswer jβ‚€ table g)) b exact hc congr 1 apply Finset.sum_congr rfl intro a _ rw [validAgreementProbability_eq valid Ο€ a b hb] theorem conditioned_folded_decoder_bound (Ξ΅ : ℝ) (Ο€ : J β†’ I) (valid : J β†’ Bool) (iβ‚€ : I) (tableA : HalfCube iβ‚€ β†’ Bool) (jβ‚€ : {j : J // valid j = true}) (tableB : HalfCube jβ‚€ β†’ Bool) (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) : 4 * Ξ΅ * testBias Ξ΅ Ο€ (fun f => bitSign (foldedAnswer iβ‚€ tableA f)) (fun g => bitSign (conditionedFoldedAnswer valid jβ‚€ tableB g)) ^ 2 ≀ validDecoderSuccess valid Ο€ (foldedAnswer iβ‚€ tableA) (conditionedFoldedAnswer valid jβ‚€ tableB) := by rw [conditioned_validDecoderSuccess] exact folded_decoder_bound Ξ΅ Ο€ iβ‚€ tableA (conditionedFoldedAnswer valid jβ‚€ tableB) hΞ΅ hΞ΅' end BinPackingGames.Foundations.Hastad namespace BinPackingGames.Foundations.Hastad.SourceContexts open Target PCP def clauseAnswerEquiv : ClauseAnswer ≃ Bool Γ— Bool Γ— Bool where toFun a := (a.first, a.second, a.third) invFun a := ⟨a.1, a.2.1, a.2.2⟩ left_inv a := by cases a; rfl right_inv a := by rcases a with ⟨a, b, c⟩; rfl def clauseAnswerFinEquiv : ClauseAnswer ≃ Fin 8 := clauseAnswerEquiv.trans ((Equiv.prodCongr finTwoEquiv.symm (Equiv.prodCongr finTwoEquiv.symm finTwoEquiv.symm)).trans ((Equiv.prodCongr (Equiv.refl (Fin 2)) finProdFinEquiv).trans finProdFinEquiv)) instance clauseAnswerFintype : Fintype ClauseAnswer := Fintype.ofEquiv (Bool Γ— Bool Γ— Bool) clauseAnswerEquiv.symm instance clauseAnswerInhabited : Inhabited ClauseAnswer := ⟨⟨false, false, false⟩⟩ instance slotFintype : Fintype Slot where elems := {.first, .second, .third} complete s := by cases s <;> simp instance slotInhabited : Inhabited Slot := ⟨.first⟩ @[simp] theorem card_clauseAnswer : Fintype.card ClauseAnswer = 8 := by rw [Fintype.card_congr clauseAnswerFinEquiv] rfl @[simp] theorem card_slot : Fintype.card Slot = 3 := by decide abbrev I (u : β„•) := Fin u β†’ Bool abbrev J (u : β„•) := Fin u β†’ ClauseAnswer abbrev ClauseContext (F : Formula) (u : β„•) := Fin u β†’ Fin F.clauses.length abbrev VariableContext (F : Formula) (u : β„•) := Fin u β†’ Fin F.variables abbrev SlotContext (u : β„•) := Fin u β†’ Slot @[simp] theorem card_I (u : β„•) : Fintype.card (I u) = 2 ^ u := by simp [I] @[simp] theorem card_J (u : β„•) : Fintype.card (J u) = 8 ^ u := by simp [J] @[simp] theorem card_ClauseContext (F : Formula) (u : β„•) : Fintype.card (ClauseContext F u) = F.clauses.length ^ u := by simp [ClauseContext] @[simp] theorem card_VariableContext (F : Formula) (u : β„•) : Fintype.card (VariableContext F u) = F.variables ^ u := by simp [VariableContext] @[simp] theorem card_SlotContext (u : β„•) : Fintype.card (SlotContext u) = 3 ^ u := by simp [SlotContext] def localConsistent {n : β„•} (clause : Clause n) (answer : ClauseAnswer) : Bool := decide (βˆ€ s s' : Slot, nameAt clause s = nameAt clause s' β†’ answerAt answer s = answerAt answer s') @[simp] theorem localConsistent_eq_true_iff {n : β„•} (clause : Clause n) (answer : ClauseAnswer) : localConsistent clause answer = true ↔ βˆ€ s s' : Slot, nameAt clause s = nameAt clause s' β†’ answerAt answer s = answerAt answer s' := by simp [localConsistent] def validJ (F : Formula) {u : β„•} (c : ClauseContext F u) (j : J u) : Bool := decide ((βˆ€ t, localSatisfies (clauseAt F (c t)) (j t) = true) ∧ βˆ€ t t' s s', nameAt (clauseAt F (c t)) s = nameAt (clauseAt F (c t')) s' β†’ answerAt (j t) s = answerAt (j t') s') @[simp] theorem validJ_eq_true_iff (F : Formula) {u : β„•} (c : ClauseContext F u) (j : J u) : validJ F c j = true ↔ (βˆ€ t, localSatisfies (clauseAt F (c t)) (j t) = true) ∧ βˆ€ t t' s s', nameAt (clauseAt F (c t)) s = nameAt (clauseAt F (c t')) s' β†’ answerAt (j t) s = answerAt (j t') s' := by simp [validJ] theorem validJ_satisfies (F : Formula) {u : β„•} (c : ClauseContext F u) (j : J u) (hj : validJ F c j = true) (t : Fin u) : localSatisfies (clauseAt F (c t)) (j t) = true := ((validJ_eq_true_iff F c j).mp hj).1 t theorem validJ_consistent (F : Formula) {u : β„•} (c : ClauseContext F u) (j : J u) (hj : validJ F c j = true) (t : Fin u) (s : Slot) (t' : Fin u) (s' : Slot) (hname : nameAt (clauseAt F (c t)) s = nameAt (clauseAt F (c t')) s') : answerAt (j t) s = answerAt (j t') s' := ((validJ_eq_true_iff F c j).mp hj).2 t t' s s' hname theorem validJ_localConsistent (F : Formula) {u : β„•} (c : ClauseContext F u) (j : J u) (hj : validJ F c j = true) (t : Fin u) : localConsistent (clauseAt F (c t)) (j t) = true := by apply (localConsistent_eq_true_iff _ _).mpr intro s s' hs exact validJ_consistent F c j hj t s t s' hs def canonicalSlot {n : β„•} (clause : Clause n) (v : Fin n) : Slot := if nameAt clause .first = v then .first else if nameAt clause .second = v then .second else .third theorem canonicalSlot_name {n : β„•} (clause : Clause n) (v : Fin n) (hv : βˆƒ s, nameAt clause s = v) : nameAt clause (canonicalSlot clause v) = v := by by_cases hfirst : nameAt clause .first = v Β· simp [canonicalSlot, hfirst] by_cases hsecond : nameAt clause .second = v Β· simp [canonicalSlot, hfirst, hsecond] obtain ⟨s, hs⟩ := hv cases s with | first => exact False.elim (hfirst hs) | second => exact False.elim (hsecond hs) | third => simpa [canonicalSlot, hfirst, hsecond] using hs def pi (F : Formula) {u : β„•} (c : ClauseContext F u) (v : VariableContext F u) (j : J u) : I u := fun t => answerAt (j t) (canonicalSlot (clauseAt F (c t)) (v t)) def sampledVariables (F : Formula) {u : β„•} (c : ClauseContext F u) (s : SlotContext u) : VariableContext F u := fun t => nameAt (clauseAt F (c t)) (s t) theorem sampledVariables_supported (F : Formula) {u : β„•} (c : ClauseContext F u) (s : SlotContext u) : βˆ€ t, βˆƒ slot, nameAt (clauseAt F (c t)) slot = sampledVariables F c s t := fun t => ⟨s t, rfl⟩ theorem sampled_eq_pi (F : Formula) {u : β„•} (c : ClauseContext F u) (v : VariableContext F u) (j : J u) (hj : validJ F c j = true) (t : Fin u) (s : Slot) (hs : nameAt (clauseAt F (c t)) s = v t) : answerAt (j t) s = pi F c v j t := by exact validJ_consistent F c j hj t s t (canonicalSlot (clauseAt F (c t)) (v t)) (hs.trans (canonicalSlot_name _ _ ⟨s, hs⟩).symm) theorem sampled_answers_eq_of_visible_eq (F : Formula) {u : β„•} (c : ClauseContext F u) (s s' : SlotContext u) (j : J u) (hj : validJ F c j = true) (hvisible : sampledVariables F c s = sampledVariables F c s') : (fun t => answerAt (j t) (s t)) = fun t => answerAt (j t) (s' t) := by funext t exact validJ_consistent F c j hj t (s t) t (s' t) (congrFun hvisible t) def honestJ (F : Formula) {u : β„•} (c : ClauseContext F u) (assignment : Fin F.variables β†’ Bool) : J u := fun t => honestAnswer (clauseAt F (c t)) assignment def honestI (F : Formula) {u : β„•} (v : VariableContext F u) (assignment : Fin F.variables β†’ Bool) : I u := fun t => assignment (v t) theorem honestJ_valid (F : Formula) {u : β„•} (c : ClauseContext F u) (assignment : Fin F.variables β†’ Bool) (hs : βˆ€ clause ∈ F.clauses, clause.eval assignment = true) : validJ F c (honestJ F c assignment) = true := by apply (validJ_eq_true_iff F c _).mpr constructor Β· intro t exact (honest_satisfies _ assignment).trans (hs _ (List.getElem_mem _)) Β· intro t t' s s' hname simp only [honestJ, honest_answerAt] exact congrArg assignment hname theorem pi_honest (F : Formula) {u : β„•} (c : ClauseContext F u) (v : VariableContext F u) (assignment : Fin F.variables β†’ Bool) (hsupport : βˆ€ t, βˆƒ s, nameAt (clauseAt F (c t)) s = v t) : pi F c v (honestJ F c assignment) = honestI F v assignment := by funext t exact (honest_answerAt _ assignment _).trans (congrArg assignment (canonicalSlot_name _ _ (hsupport t))) theorem pi_honest_sampled (F : Formula) {u : β„•} (c : ClauseContext F u) (s : SlotContext u) (assignment : Fin F.variables β†’ Bool) : pi F c (sampledVariables F c s) (honestJ F c assignment) = honestI F (sampledVariables F c s) assignment := pi_honest F c _ assignment (sampledVariables_supported F c s) def baseAccepts (F : Formula) (v : Fin F.variables) (c : Fin F.clauses.length) (i : Bool) (j : ClauseAnswer) : Bool := decide (localSatisfies (clauseAt F c) j = true ∧ localConsistent (clauseAt F c) j = true ∧ answerAt j (canonicalSlot (clauseAt F c) v) = i) @[simp] theorem baseAccepts_eq_true_iff (F : Formula) (v : Fin F.variables) (c : Fin F.clauses.length) (i : Bool) (j : ClauseAnswer) : baseAccepts F v c i j = true ↔ localSatisfies (clauseAt F c) j = true ∧ localConsistent (clauseAt F c) j = true ∧ answerAt j (canonicalSlot (clauseAt F c) v) = i := by simp [baseAccepts] theorem projection_implies_coordinate_accepts (F : Formula) {u : β„•} (c : ClauseContext F u) (v : VariableContext F u) (i : I u) (j : J u) (hj : validJ F c j = true) (hpi : pi F c v j = i) (t : Fin u) : baseAccepts F (v t) (c t) (i t) (j t) = true := by exact (baseAccepts_eq_true_iff F _ _ _ _).mpr ⟨validJ_satisfies F c j hj t, validJ_localConsistent F c j hj t, congrFun hpi t⟩ theorem baseAccepts_implies_sampled (F : Formula) (c : Fin F.clauses.length) (s : Slot) (i : Bool) (j : ClauseAnswer) (h : baseAccepts F (nameAt (clauseAt F c) s) c i j = true) : (localSatisfies (clauseAt F c) j && decide (answerAt j s = i)) = true := by obtain ⟨hsat, hcons, heq⟩ := (baseAccepts_eq_true_iff F _ _ _ _).mp h have hname := canonicalSlot_name (clauseAt F c) (nameAt (clauseAt F c) s) ⟨s, rfl⟩ have hans := (localConsistent_eq_true_iff _ _).mp hcons s (canonicalSlot (clauseAt F c) (nameAt (clauseAt F c) s)) hname.symm simp [hsat, hans.trans heq] theorem projection_implies_sampled_accepts (F : Formula) {u : β„•} (c : ClauseContext F u) (s : SlotContext u) (i : I u) (j : J u) (hj : validJ F c j = true) (hpi : pi F c (sampledVariables F c s) j = i) : βˆ€ t, (localSatisfies (clauseAt F (c t)) (j t) && decide (answerAt (j t) (s t) = i t)) = true := by intro t exact baseAccepts_implies_sampled F (c t) (s t) (i t) (j t) (projection_implies_coordinate_accepts F c _ i j hj hpi t) end BinPackingGames.Foundations.Hastad.SourceContexts namespace BinPackingGames.Foundations.Hastad section open scoped BigOperators open Finset open BinPackingGames.Foundations.Games variable {I J : Type*} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] def supportResponse (fallback : I) (s : Cube I) : FiniteDistribution I where weight i := if (support s).Nonempty then if i ∈ support s then 1 / ((support s).card : ℝ) else 0 else if i = fallback then 1 else 0 nonnegative i := by split_ifs <;> positivity normalized := by by_cases hs : (support s).Nonempty Β· have hc : ((support s).card : ℝ) β‰  0 := ne_of_gt (Nat.cast_pos.mpr (Finset.card_pos.mpr hs)) simp [hs, hc] Β· simp [hs] theorem supportResponse_expectation (fallback : I) (s : Cube I) (H : I β†’ ℝ) (hs : (support s).Nonempty) : (supportResponse fallback s).expectation H = (βˆ‘ i ∈ support s, H i) / ((support s).card : ℝ) := by simp only [FiniteDistribution.expectation, supportResponse, hs, ite_true] simp_rw [ite_mul, zero_mul] rw [Finset.sum_ite_mem] simp only [div_eq_mul_inv, one_mul, Finset.univ_inter] rw [← Finset.mul_sum] ring def fourierResponse (fallback : I) (F : Cube I β†’ Bool) : FiniteDistribution I where weight i := βˆ‘ s, coefficient (fun f => bitSign (F f)) s ^ 2 * (supportResponse fallback s).weight i nonnegative i := Finset.sum_nonneg fun s _ => mul_nonneg (sq_nonneg _) ((supportResponse fallback s).nonnegative i) normalized := by rw [Finset.sum_comm] simp_rw [← Finset.mul_sum, FiniteDistribution.normalized, mul_one] exact sign_parseval F theorem fourierResponse_expectation (fallback : I) (F : Cube I β†’ Bool) (H : I β†’ ℝ) : (fourierResponse fallback F).expectation H = βˆ‘ s, coefficient (fun f => bitSign (F f)) s ^ 2 * (supportResponse fallback s).expectation H := by unfold FiniteDistribution.expectation fourierResponse simp_rw [Finset.sum_mul] rw [Finset.sum_comm] apply Finset.sum_congr rfl intro s _ rw [Finset.mul_sum] apply Finset.sum_congr rfl intro i _ ring theorem response_expectation_nonnegative {K : Type*} [Fintype K] (law : FiniteDistribution K) (H : K β†’ ℝ) (hH : βˆ€ k, 0 ≀ H k) : 0 ≀ law.expectation H := Finset.sum_nonneg fun k _ => mul_nonneg (law.nonnegative k) (hH k) def responseAgreement (Ο€ : J β†’ I) (fallbackI : I) (fallbackJ : J) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) : ℝ := (fourierResponse fallbackI A).expectation fun i => (fourierResponse fallbackJ B).expectation fun j => if Ο€ j = i then 1 else 0 def validResponseAgreement (valid : J β†’ Bool) (Ο€ : J β†’ I) (fallbackI : I) (fallbackJ : J) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) : ℝ := (fourierResponse fallbackI A).expectation fun i => (fourierResponse fallbackJ B).expectation fun j => if Ο€ j = i ∧ valid j = true then 1 else 0 theorem supportResponse_validAgreement (valid : J β†’ Bool) (Ο€ : J β†’ I) (fallbackI : I) (fallbackJ : J) (a : Cube I) (b : Cube J) (ha : (support a).Nonempty) (hb : (support b).Nonempty) : (supportResponse fallbackI a).expectation (fun i => (supportResponse fallbackJ b).expectation (fun j => if Ο€ j = i ∧ valid j = true then 1 else 0)) = validAgreementProbability valid Ο€ a b := by rw [supportResponse_expectation fallbackI a _ ha] simp_rw [supportResponse_expectation fallbackJ b _ hb, Finset.sum_boole] unfold validAgreementProbability simp only [div_eq_mul_inv] rw [← Finset.sum_mul] ring theorem validAgreement_le_supportResponses (valid : J β†’ Bool) (Ο€ : J β†’ I) (fallbackI : I) (fallbackJ : J) (a : Cube I) (b : Cube J) : validAgreementProbability valid Ο€ a b ≀ (supportResponse fallbackI a).expectation (fun i => (supportResponse fallbackJ b).expectation (fun j => if Ο€ j = i ∧ valid j = true then 1 else 0)) := by by_cases ha : (support a).Nonempty Β· by_cases hb : (support b).Nonempty Β· exact le_of_eq (supportResponse_validAgreement valid Ο€ fallbackI fallbackJ a b ha hb).symm Β· have he : support b = βˆ… := Finset.not_nonempty_iff_eq_empty.mp hb simp only [validAgreementProbability, he, Finset.card_empty, Nat.cast_zero, mul_zero, div_zero] apply response_expectation_nonnegative intro i apply response_expectation_nonnegative intro j split_ifs <;> norm_num Β· have he : support a = βˆ… := Finset.not_nonempty_iff_eq_empty.mp ha simp only [validAgreementProbability, he, Finset.sum_empty, Finset.card_empty, Nat.cast_zero, zero_mul, div_zero] apply response_expectation_nonnegative intro i apply response_expectation_nonnegative intro j split_ifs <;> norm_num theorem validDecoderSuccess_le_response (valid : J β†’ Bool) (Ο€ : J β†’ I) (fallbackI : I) (fallbackJ : J) (A : Cube I β†’ Bool) (B : Cube J β†’ Bool) : validDecoderSuccess valid Ο€ A B ≀ validResponseAgreement valid Ο€ fallbackI fallbackJ A B := by unfold validDecoderSuccess validResponseAgreement rw [FiniteDistribution.expectation_comm] rw [fourierResponse_expectation fallbackJ B] apply Finset.sum_le_sum intro b _ apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) rw [FiniteDistribution.expectation_comm] rw [fourierResponse_expectation fallbackI A] apply Finset.sum_le_sum intro a _ apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) exact validAgreement_le_supportResponses valid Ο€ fallbackI fallbackJ a b theorem conditioned_folded_response_bound (Ξ΅ : ℝ) (Ο€ : J β†’ I) (valid : J β†’ Bool) (iβ‚€ : I) (tableA : HalfCube iβ‚€ β†’ Bool) (jβ‚€ : {j : J // valid j = true}) (tableB : HalfCube jβ‚€ β†’ Bool) (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) : 4 * Ξ΅ * testBias Ξ΅ Ο€ (fun f => bitSign (foldedAnswer iβ‚€ tableA f)) (fun g => bitSign (conditionedFoldedAnswer valid jβ‚€ tableB g)) ^ 2 ≀ validResponseAgreement valid Ο€ iβ‚€ jβ‚€.val (foldedAnswer iβ‚€ tableA) (conditionedFoldedAnswer valid jβ‚€ tableB) := (conditioned_folded_decoder_bound Ξ΅ Ο€ valid iβ‚€ tableA jβ‚€ tableB hΞ΅ hΞ΅').trans (validDecoderSuccess_le_response valid Ο€ iβ‚€ jβ‚€.val _ _) end open scoped BigOperators open Finset open BinPackingGames.Foundations.Games theorem distribution_sq_expectation_le {Ξ© : Type*} [Fintype Ξ©] (law : FiniteDistribution Ξ©) (F : Ξ© β†’ ℝ) : law.expectation F ^ 2 ≀ law.expectation (fun x => F x ^ 2) := by let m := law.expectation F have h := response_expectation_nonnegative law (fun x => (F x - m) ^ 2) (fun x => sq_nonneg _) have he : law.expectation (fun x => (F x - m) ^ 2) = law.expectation (fun x => F x ^ 2) - m ^ 2 := by unfold FiniteDistribution.expectation calc _ = βˆ‘ x, ((law.weight x * F x ^ 2 - 2 * m * (law.weight x * F x)) + law.weight x * m ^ 2) := by apply Finset.sum_congr rfl intro x _ ring _ = _ := by rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.sum_mul, law.normalized] change (law.expectation (fun x => F x ^ 2) - 2 * m * m) + 1 * m ^ 2 = _ simp only [FiniteDistribution.expectation] ring rw [he] at h dsimp [m] at h linarith variable {Q₁ Qβ‚‚ I J : Type*} [Fintype Q₁] [DecidableEq Q₁] [Fintype Qβ‚‚] [DecidableEq Qβ‚‚] [Fintype I] [DecidableEq I] [Nonempty I] [Fintype J] [DecidableEq J] [Nonempty J] def projectionGame (questions : FiniteDistribution (Q₁ Γ— Qβ‚‚)) (Ο€ : Q₁ β†’ Qβ‚‚ β†’ J β†’ I) (valid : Qβ‚‚ β†’ J β†’ Bool) : Game Q₁ Qβ‚‚ I J where questions := questions accepts q₁ qβ‚‚ i j := decide (Ο€ q₁ qβ‚‚ j = i ∧ valid qβ‚‚ j = true) def questionBias (Ξ΅ : ℝ) (Ο€ : Q₁ β†’ Qβ‚‚ β†’ J β†’ I) (A : Q₁ β†’ Cube I β†’ Bool) (B : Qβ‚‚ β†’ Cube J β†’ Bool) (q : Q₁ Γ— Qβ‚‚) : ℝ := testBias Ξ΅ (Ο€ q.1 q.2) (fun f => bitSign (A q.1 f)) (fun g => bitSign (B q.2 g)) def questionAcceptance (Ξ΅ : ℝ) (Ο€ : Q₁ β†’ Qβ‚‚ β†’ J β†’ I) (A : Q₁ β†’ Cube I β†’ Bool) (B : Qβ‚‚ β†’ Cube J β†’ Bool) (q : Q₁ Γ— Qβ‚‚) : ℝ := testAcceptance Ξ΅ (Ο€ q.1 q.2) (A q.1) (B q.2) omit [DecidableEq Q₁] [DecidableEq Qβ‚‚] [Nonempty I] [Nonempty J] in theorem questionAcceptance_eq (questions : FiniteDistribution (Q₁ Γ— Qβ‚‚)) (Ξ΅ : ℝ) (Ο€ : Q₁ β†’ Qβ‚‚ β†’ J β†’ I) (A : Q₁ β†’ Cube I β†’ Bool) (B : Qβ‚‚ β†’ Cube J β†’ Bool) : questions.expectation (questionAcceptance Ξ΅ Ο€ A B) = (1 + questions.expectation (questionBias Ξ΅ Ο€ A B)) / 2 := by unfold questionAcceptance simp_rw [testAcceptance_eq] unfold questionBias FiniteDistribution.expectation simp only [div_eq_mul_inv, mul_add, mul_one, ← mul_assoc, Finset.sum_add_distrib, ← Finset.sum_mul, questions.normalized] inductive ConditionedOracle (valid : J β†’ Bool) where | empty (noLegal : βˆ€ j, valid j = false) | stored (jβ‚€ : {j : J // valid j = true}) (table : HalfCube jβ‚€ β†’ Bool) def ConditionedOracle.answer {valid : J β†’ Bool} : ConditionedOracle valid β†’ Cube J β†’ Bool | .empty _ => fun _ => false | .stored jβ‚€ table => conditionedFoldedAnswer valid jβ‚€ table def ConditionedOracle.fallback {valid : J β†’ Bool} (default : J) : ConditionedOracle valid β†’ J | .empty _ => default | .stored jβ‚€ _ => jβ‚€.val omit [Nonempty I] [Nonempty J] in theorem testBias_constant_right (Ξ΅ : ℝ) (Ο€ : J β†’ I) (A : Cube I β†’ ℝ) : testBias Ξ΅ Ο€ A (fun _ => 1) = 𝔼 f, A f := by unfold testBias simp only [mul_one, Fintype.expect_const] simp_rw [← Finset.sum_mul, noiseWeight_sum, one_mul] omit [Nonempty I] [Nonempty J] in theorem empty_conditioned_bias (Ξ΅ : ℝ) (Ο€ : J β†’ I) (iβ‚€ : I) (tableA : HalfCube iβ‚€ β†’ Bool) : testBias Ξ΅ Ο€ (fun f => bitSign (foldedAnswer iβ‚€ tableA f)) (fun _ => bitSign false) = 0 := by simp only [bitSign, Bool.false_eq_true, ite_false] rw [testBias_constant_right] have hz := foldedAnswer_zero_coefficient iβ‚€ tableA simpa [coefficient, walsh, bitSign] using hz omit [Nonempty I] [Nonempty J] in theorem conditionedOracle_response_bound (Ξ΅ : ℝ) (Ο€ : J β†’ I) (valid : J β†’ Bool) (iβ‚€ : I) (tableA : HalfCube iβ‚€ β†’ Bool) (default : J) (right : ConditionedOracle valid) (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) : 4 * Ξ΅ * testBias Ξ΅ Ο€ (fun f => bitSign (foldedAnswer iβ‚€ tableA f)) (fun g => bitSign (right.answer g)) ^ 2 ≀ validResponseAgreement valid Ο€ iβ‚€ (right.fallback default) (foldedAnswer iβ‚€ tableA) right.answer := by cases right with | empty noLegal => simp only [ConditionedOracle.answer, ConditionedOracle.fallback, empty_conditioned_bias, pow_two, mul_zero] unfold validResponseAgreement apply response_expectation_nonnegative intro i apply response_expectation_nonnegative intro j split_ifs <;> norm_num | stored jβ‚€ table => exact conditioned_folded_response_bound Ξ΅ Ο€ valid iβ‚€ tableA jβ‚€ table hΞ΅ hΞ΅' theorem folded_game_decoder_bound (questions : FiniteDistribution (Q₁ Γ— Qβ‚‚)) (Ξ΅ : ℝ) (Ο€ : Q₁ β†’ Qβ‚‚ β†’ J β†’ I) (valid : Qβ‚‚ β†’ J β†’ Bool) (iβ‚€ : Q₁ β†’ I) (tableA : βˆ€ q, HalfCube (iβ‚€ q) β†’ Bool) (jβ‚€ : βˆ€ q, {j : J // valid q j = true}) (tableB : βˆ€ q, HalfCube (jβ‚€ q) β†’ Bool) (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) : 4 * Ξ΅ * questions.expectation (questionBias Ξ΅ Ο€ (fun q => foldedAnswer (iβ‚€ q) (tableA q)) (fun q => conditionedFoldedAnswer (valid q) (jβ‚€ q) (tableB q))) ^ 2 ≀ (projectionGame questions Ο€ valid).value := by let A := fun q => foldedAnswer (iβ‚€ q) (tableA q) let B := fun q => conditionedFoldedAnswer (valid q) (jβ‚€ q) (tableB q) let bias := questionBias Ξ΅ Ο€ A B calc _ ≀ 4 * Ξ΅ * questions.expectation (fun q => bias q ^ 2) := mul_le_mul_of_nonneg_left (distribution_sq_expectation_le questions bias) (by linarith) _ = questions.expectation (fun q => 4 * Ξ΅ * bias q ^ 2) := by unfold FiniteDistribution.expectation rw [Finset.mul_sum] apply Finset.sum_congr rfl intro q _ ring _ ≀ questions.expectation (fun q => validResponseAgreement (valid q.2) (Ο€ q.1 q.2) (iβ‚€ q.1) (jβ‚€ q.2).val (A q.1) (B q.2)) := by unfold FiniteDistribution.expectation apply Finset.sum_le_sum intro q _ apply mul_le_mul_of_nonneg_left _ (questions.nonnegative q) exact conditioned_folded_response_bound Ξ΅ (Ο€ q.1 q.2) (valid q.2) (iβ‚€ q.1) (tableA q.1) (jβ‚€ q.2) (tableB q.2) hΞ΅ hΞ΅' _ = (projectionGame questions Ο€ valid).stochasticSuccess (fun q => fourierResponse (iβ‚€ q) (A q)) (fun q => fourierResponse (jβ‚€ q).val (B q)) := by simp [Game.stochasticSuccess, projectionGame, validResponseAgreement] _ ≀ _ := Game.stochasticSuccess_le_value _ _ _ theorem conditionedOracle_game_decoder_bound (questions : FiniteDistribution (Q₁ Γ— Qβ‚‚)) (Ξ΅ : ℝ) (Ο€ : Q₁ β†’ Qβ‚‚ β†’ J β†’ I) (valid : Qβ‚‚ β†’ J β†’ Bool) (iβ‚€ : Q₁ β†’ I) (tableA : βˆ€ q, HalfCube (iβ‚€ q) β†’ Bool) (default : J) (right : βˆ€ q, ConditionedOracle (valid q)) (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) : 4 * Ξ΅ * questions.expectation (questionBias Ξ΅ Ο€ (fun q => foldedAnswer (iβ‚€ q) (tableA q)) (fun q => (right q).answer)) ^ 2 ≀ (projectionGame questions Ο€ valid).value := by let A := fun q => foldedAnswer (iβ‚€ q) (tableA q) let B := fun q => (right q).answer let bias := questionBias Ξ΅ Ο€ A B calc _ ≀ 4 * Ξ΅ * questions.expectation (fun q => bias q ^ 2) := mul_le_mul_of_nonneg_left (distribution_sq_expectation_le questions bias) (by linarith) _ = questions.expectation (fun q => 4 * Ξ΅ * bias q ^ 2) := by unfold FiniteDistribution.expectation rw [Finset.mul_sum] apply Finset.sum_congr rfl intro q _ ring _ ≀ questions.expectation (fun q => validResponseAgreement (valid q.2) (Ο€ q.1 q.2) (iβ‚€ q.1) ((right q.2).fallback default) (A q.1) (B q.2)) := by unfold FiniteDistribution.expectation apply Finset.sum_le_sum intro q _ apply mul_le_mul_of_nonneg_left _ (questions.nonnegative q) exact conditionedOracle_response_bound Ξ΅ (Ο€ q.1 q.2) (valid q.2) (iβ‚€ q.1) (tableA q.1) default (right q.2) hΞ΅ hΞ΅' _ = (projectionGame questions Ο€ valid).stochasticSuccess (fun q => fourierResponse (iβ‚€ q) (A q)) (fun q => fourierResponse ((right q).fallback default) (B q)) := by simp [Game.stochasticSuccess, projectionGame, validResponseAgreement] _ ≀ _ := Game.stochasticSuccess_le_value _ _ _ theorem conditionedOracle_acceptance_bound (questions : FiniteDistribution (Q₁ Γ— Qβ‚‚)) (Ξ΅ Ξ΄ : ℝ) (Ο€ : Q₁ β†’ Qβ‚‚ β†’ J β†’ I) (valid : Qβ‚‚ β†’ J β†’ Bool) (iβ‚€ : Q₁ β†’ I) (tableA : βˆ€ q, HalfCube (iβ‚€ q) β†’ Bool) (default : J) (right : βˆ€ q, ConditionedOracle (valid q)) (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ ≀ 1 / 2) (hΞ΄ : 0 ≀ Ξ΄) (hvalue : (projectionGame questions Ο€ valid).value ≀ 4 * Ξ΅ * Ξ΄ ^ 2) : questions.expectation (questionAcceptance Ξ΅ Ο€ (fun q => foldedAnswer (iβ‚€ q) (tableA q)) (fun q => (right q).answer)) ≀ (1 + Ξ΄) / 2 := by have hd := conditionedOracle_game_decoder_bound questions Ξ΅ Ο€ valid iβ‚€ tableA default right hΞ΅ hΞ΅' have hpos : 0 < 4 * Ξ΅ := by positivity have hs := le_of_mul_le_mul_left (hd.trans hvalue) hpos rw [questionAcceptance_eq] nlinarith end BinPackingGames.Foundations.Hastad end end OAI
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Algebra.Order.BigOperators.Expect
import Mathlib.Algebra.Ring.GeomSum
import Mathlib.Algebra.Ring.Parity
import Mathlib.Basic.Real.Basic
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import OAI.Computability.BinPacking.Games.Reindexing
import OAI.Computability.BinPacking.PCP.BinaryFormula
namespace OAI
noncomputable section
namespace BinPackingGames.Foundations.Hastad
section
open scoped BigOperators
open Finset
abbrev Cube (I : Type*) := I β†’ Bool
def bitSign (b : Bool) : ℝ := if b then -1 else 1
@[simp] theorem bitSign_sq (b : Bool) : bitSign b ^ 2 = 1 := by
cases b <;> norm_num [bitSign]
theorem bitSign_xor (b c : Bool) :
bitSign (b ^^ c) = bitSign b * bitSign c := by
cases b <;> cases c <;> norm_num [bitSign]
def cubeXor {I : Type*} (x y : Cube I) : Cube I := fun i => x i ^^ y i
def walsh {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) : ℝ :=
∏ i, bitSign (s i && x i)
theorem walsh_symm {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) :
walsh s x = walsh x s := by
simp [walsh, Bool.and_comm]
@[simp] theorem walsh_sq {I : Type*} [Fintype I] [DecidableEq I] (s x : Cube I) :
walsh s x ^ 2 = 1 := by
simp [walsh, ← Finset.prod_pow]
theorem walsh_xor {I : Type*} [Fintype I] [DecidableEq I] (s x y : Cube I) :
walsh s (cubeXor x y) = walsh s x * walsh s y := by
simp only [walsh, ← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro i _
simp only [cubeXor]
cases s i <;> cases x i <;> cases y i <;> norm_num [bitSign]
theorem coordinate_orthogonality (s t : Bool) :
(βˆ‘ x : Bool, bitSign (s && x) * bitSign (t && x)) =
if s = t then 2 else 0 := by
cases s <;> cases t <;> norm_num [bitSign, Fintype.sum_bool]
theorem walsh_sum_orthogonality {I : Type*} [Fintype I] [DecidableEq I]
(s t : Cube I) :
(βˆ‘ x, walsh s x * walsh t x) =
if s = t then (Fintype.card (Cube I) : ℝ) else 0 := by
classical
simp only [walsh, ← Finset.prod_mul_distrib]
rw [← Fintype.prod_sum (fun (i : I) (b : Bool) =>
bitSign (s i && b) * bitSign (t i && b))]
simp only [coordinate_orthogonality]
by_cases h : s = t
Β· subst t
simp
Β· rw [ite_eq_right h]
obtain ⟨i, hi⟩ := Function.ne_iff.mp h
apply Finset.prod_eq_zero (Finset.mem_univ i)
exact ite_eq_right hi
theorem walsh_orthogonality {I : Type*} [Fintype I] [DecidableEq I]
(s t : Cube I) :
(𝔼 x, walsh s x * walsh t x) = if s = t then 1 else 0 := by
classical
rw [Fintype.expect_eq_sum_div_card, walsh_sum_orthogonality]
split_ifs <;> simp
def coefficient {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β†’ ℝ) (s : Cube I) : ℝ :=
𝔼 x, f x * walsh s x
theorem walsh_inversion {I : Type*} [Fintype I] [DecidableEq I] (f : Cube I β†’ ℝ) (x : Cube I) :
(βˆ‘ s, coefficient f s * walsh s x) = f x := by
classical
unfold coefficient
simp_rw [Finset.expect_mul]
rw [← Finset.expect_sum_comm]
have h (y : Cube I) :
(βˆ‘ s, (f y * walsh s y) * walsh s x) =
f y * (if y = x then (Fintype.card (Cube I) : ℝ) else 0) := by
simp only [mul_assoc, ← Finset.mul_sum]
congr 1
simp_rw [walsh_symm (x := y), walsh_symm (x := x)]
exact walsh_sum_orthogonality y x