import Mathlib import OAI.Computability.VertexCover.Fourier.Folding import OAI.Computability.VertexCover.Reduction.FiniteNoise namespace OAI section section section section section section section section section section section section section section section section section section section section section section section section section section noncomputable section namespace UniqueGames.Foundations.Hastad open scoped BigOperators open UniqueGames.Reduction.FiniteNoise variable {I J : Type*} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] omit [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] in theorem dictator_test_parity (π : J → I) (i : I) (j : J) (hπ : π j = i) (f : Cube I) (g μ : Cube J) : (f i ^^ g j ^^ (thirdQuery π f g μ) j) = μ j := by simp only [thirdQuery, cubeXor, hπ] cases f i <;> cases g j <;> cases μ j <;> rfl theorem noise_coordinate_sign (ε : ℝ) (j : J) : (∑ μ : Cube J, noiseWeight ε μ * bitSign (μ j)) = 1 - 2 * ε := by have hs : support (coordinateMask j) = {j} := by ext k simp [support, coordinateMask] have h := noise_walsh ε (coordinateMask j) simp_rw [walsh_symm (coordinateMask j), walsh_coordinateMask] at h simpa only [hs, Finset.card_singleton, pow_one] using h theorem noise_coordinate_false (ε : ℝ) (j : J) : (∑ μ : Cube J, noiseWeight ε μ * if μ j then (0 : ℝ) else 1) = 1 - ε := by have hind (b : Bool) : (if b then (0 : ℝ) else 1) = (1 + bitSign b) * (2 : ℝ)⁻¹ := by cases b <;> norm_num [bitSign] have ht (μ : Cube J) : noiseWeight ε μ * (if μ j then (0 : ℝ) else 1) = (noiseWeight ε μ + noiseWeight ε μ * bitSign (μ j)) * (2 : ℝ)⁻¹ := by rw [hind] ring simp_rw [ht] rw [← Finset.sum_mul, Finset.sum_add_distrib, noiseWeight_sum, noise_coordinate_sign] ring theorem testAcceptance_dictator (ε : ℝ) (π : J → I) (i : I) (j : J) (hπ : π j = i) : testAcceptance ε π (fun f => f i) (fun g => g j) = 1 - ε := by have hg (f : Cube I) (μ : Cube J) : (𝔼 g : Cube J, if f i ^^ g j ^^ (thirdQuery π f g μ) j then (0 : ℝ) else 1) = if μ j then 0 else 1 := by calc _ = 𝔼 _g : Cube J, if μ j then (0 : ℝ) else 1 := by apply Finset.expect_congr rfl intro g _ rw [dictator_test_parity π i j hπ f g μ] _ = _ := Fintype.expect_const _ change (𝔼 f : Cube I, ∑ μ : Cube J, noiseWeight ε μ * (𝔼 g : Cube J, if f i ^^ g j ^^ (thirdQuery π f g μ) j then (0 : ℝ) else 1)) = _ simp_rw [hg] rw [Fintype.expect_const] exact noise_coordinate_false ε j theorem testAcceptance_folded_dictators (ε : ℝ) (π : J → I) (i₀ i : I) (j₀ j : J) (hπ : π j = i) : testAcceptance ε π (foldedAnswer i₀ (fun h => h.val i)) (foldedAnswer j₀ (fun h => h.val j)) = 1 - ε := by have hA : foldedAnswer i₀ (fun h => h.val i) = (fun f : Cube I => f i) := funext (foldedAnswer_dictator i₀ i) have hB : foldedAnswer j₀ (fun h => h.val j) = (fun g : Cube J => g j) := funext (foldedAnswer_dictator j₀ j) rw [hA, hB] exact testAcceptance_dictator ε π i j hπ theorem testAcceptance_conditioned_dictators (ε : ℝ) (π : J → I) (validI : I → Bool) (validJ : J → Bool) (i₀ i : {i : I // validI i = true}) (j₀ j : {j : J // validJ j = true}) (hπ : π j.val = i.val) : testAcceptance ε π (conditionedFoldedAnswer validI i₀ (fun h => h.val i)) (conditionedFoldedAnswer validJ j₀ (fun h => h.val j)) = 1 - ε := by have hA : conditionedFoldedAnswer validI i₀ (fun h => h.val i) = (fun f : Cube I => f i.val) := funext (conditionedFoldedAnswer_dictator validI i₀ i) have hB : conditionedFoldedAnswer validJ j₀ (fun h => h.val j) = (fun g : Cube J => g j.val) := funext (conditionedFoldedAnswer_dictator validJ j₀ j) rw [hA, hB] exact testAcceptance_dictator ε π i.val j.val hπ theorem testAcceptance_folded_conditioned_dictators (ε : ℝ) (π : J → I) (i₀ i : I) (valid : J → Bool) (j₀ j : {j : J // valid j = true}) (hπ : π j.val = i) : testAcceptance ε π (foldedAnswer i₀ (fun h => h.val i)) (conditionedFoldedAnswer valid j₀ (fun h => h.val j)) = 1 - ε := by have hA : foldedAnswer i₀ (fun h => h.val i) = (fun f : Cube I => f i) := funext (foldedAnswer_dictator i₀ i) have hB : conditionedFoldedAnswer valid j₀ (fun h => h.val j) = (fun g : Cube J => g j.val) := funext (conditionedFoldedAnswer_dictator valid j₀ j) rw [hA, hB] exact testAcceptance_dictator ε π i j.val hπ def realizedTestAcceptance (D : Nat) (π : J → I) (A : Cube I → Bool) (B : Cube J → Bool) : ℝ := 𝔼 f : Cube I, 𝔼 z : J → Fin D, 𝔼 g : Cube J, if A f ^^ B g ^^ B (thirdQuery π f g (realizedNoise z)) then 0 else 1 theorem realizedTestAcceptance_eq_testAcceptance {D : Nat} (positive : 0 < D) (π : J → I) (A : Cube I → Bool) (B : Cube J → Bool) : realizedTestAcceptance D π A B = testAcceptance ((D : ℝ)⁻¹) π A B := by unfold realizedTestAcceptance testAcceptance apply Finset.expect_congr rfl intro f _ exact expect_realizedNoise positive (fun μ => 𝔼 g : Cube J, if A f ^^ B g ^^ B (thirdQuery π f g μ) then 0 else 1) theorem realizedTestAcceptance_dictator {D : Nat} (positive : 0 < D) (π : J → I) (i : I) (j : J) (hπ : π j = i) : realizedTestAcceptance D π (fun f => f i) (fun g => g j) = 1 - (D : ℝ)⁻¹ := by rw [realizedTestAcceptance_eq_testAcceptance positive] exact testAcceptance_dictator _ π i j hπ theorem realizedTestAcceptance_folded_dictators {D : Nat} (positive : 0 < D) (π : J → I) (i₀ i : I) (j₀ j : J) (hπ : π j = i) : realizedTestAcceptance D π (foldedAnswer i₀ (fun h => h.val i)) (foldedAnswer j₀ (fun h => h.val j)) = 1 - (D : ℝ)⁻¹ := by rw [realizedTestAcceptance_eq_testAcceptance positive] exact testAcceptance_folded_dictators _ π i₀ i j₀ j hπ theorem realizedTestAcceptance_conditioned_dictators {D : Nat} (positive : 0 < D) (π : J → I) (validI : I → Bool) (validJ : J → Bool) (i₀ i : {i : I // validI i = true}) (j₀ j : {j : J // validJ j = true}) (hπ : π j.val = i.val) : realizedTestAcceptance D π (conditionedFoldedAnswer validI i₀ (fun h => h.val i)) (conditionedFoldedAnswer validJ j₀ (fun h => h.val j)) = 1 - (D : ℝ)⁻¹ := by rw [realizedTestAcceptance_eq_testAcceptance positive] exact testAcceptance_conditioned_dictators _ π validI validJ i₀ i j₀ j hπ theorem realizedTestAcceptance_folded_conditioned_dictators {D : Nat} (positive : 0 < D) (π : J → I) (i₀ i : I) (valid : J → Bool) (j₀ j : {j : J // valid j = true}) (hπ : π j.val = i) : realizedTestAcceptance D π (foldedAnswer i₀ (fun h => h.val i)) (conditionedFoldedAnswer valid j₀ (fun h => h.val j)) = 1 - (D : ℝ)⁻¹ := by rw [realizedTestAcceptance_eq_testAcceptance positive] exact testAcceptance_folded_conditioned_dictators _ π i₀ i valid j₀ j hπ end UniqueGames.Foundations.Hastad end end end end end end end end end end end end end end end end end end end end end end end end end end end end OAI