math / data /lean /OAI /Computability /BinPacking /PCP /Queries.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
56.5 kB
import Mathlib.Algebra.BigOperators.Expect import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.BigOperators.Expect import Mathlib.Data.Finset.Max import Mathlib.Data.Fintype.Pi import Mathlib.Data.Fintype.Prod import Mathlib.Basic.Real.Basic import Mathlib.Logic.Equiv.Prod import OAI.Computability.BinPacking.Information.GameDecoder import OAI.Computability.BinPacking.PCP.AlphabetRetraction namespace OAI noncomputable section namespace BinPackingGames.Foundations.PCP.UniformRestriction open scoped BigOperators variable {B : Type*} (p : B β†’ Prop) def restrict (f : B β†’ Bool) : {b // p b} β†’ Bool := fun b => f b.1 variable [DecidablePred p] def extend (g : {b // p b} β†’ Bool) : B β†’ Bool := fun b => if hb : p b then g ⟨b, hb⟩ else false def canonicalize (f : B β†’ Bool) : B β†’ Bool := extend p (restrict p f) omit [DecidablePred p] in @[simp] theorem restrict_apply (f : B β†’ Bool) (b : {b // p b}) : restrict p f b = f b.1 := rfl @[simp] theorem extend_apply_of_mem (g : {b // p b} β†’ Bool) (b : B) (hb : p b) : extend p g b = g ⟨b, hb⟩ := by simp [extend, hb] @[simp] theorem extend_apply_of_not_mem (g : {b // p b} β†’ Bool) (b : B) (hb : Β¬ p b) : extend p g b = false := by simp [extend, hb] @[simp] theorem restrict_extend (g : {b // p b} β†’ Bool) : restrict p (extend p g) = g := by funext b simp [restrict, extend, b.property] @[simp] theorem canonicalize_apply_of_mem (f : B β†’ Bool) (b : B) (hb : p b) : canonicalize p f b = f b := by simp [canonicalize, hb] @[simp] theorem canonicalize_apply_of_not_mem (f : B β†’ Bool) (b : B) (hb : Β¬ p b) : canonicalize p f b = false := by simp [canonicalize, hb] @[simp] theorem restrict_canonicalize (f : B β†’ Bool) : restrict p (canonicalize p f) = restrict p f := by exact restrict_extend p (restrict p f) @[simp] theorem canonicalize_idempotent (f : B β†’ Bool) : canonicalize p (canonicalize p f) = canonicalize p f := by simp only [canonicalize, restrict_extend] theorem canonicalize_eq_iff (f g : B β†’ Bool) : canonicalize p f = canonicalize p g ↔ restrict p f = restrict p g := by constructor Β· intro h simpa only [restrict_canonicalize] using congrArg (restrict p) h Β· intro h exact congrArg (extend p) h variable [Fintype B] [DecidableEq B] theorem expect_restrict (h : ({b // p b} β†’ Bool) β†’ ℝ) : (𝔼 f : B β†’ Bool, h (restrict p f)) = 𝔼 g : {b // p b} β†’ Bool, h g := by calc (𝔼 f : B β†’ Bool, h (restrict p f)) = 𝔼 g : ({b // p b} β†’ Bool) Γ— ({b // Β¬ p b} β†’ Bool), h g.1 := Fintype.expect_equiv (Equiv.piEquivPiSubtypeProd p (fun _ => Bool)) _ _ (fun _ => rfl) _ = 𝔼 g : {b // p b} β†’ Bool, 𝔼 _k : {b // Β¬ p b} β†’ Bool, h g := by simpa only [Finset.univ_product_univ] using Finset.expect_product (Finset.univ : Finset ({b // p b} β†’ Bool)) (Finset.univ : Finset ({b // Β¬ p b} β†’ Bool)) (fun g : ({b // p b} β†’ Bool) Γ— ({b // Β¬ p b} β†’ Bool) => h g.1) _ = 𝔼 g : {b // p b} β†’ Bool, h g := by simp only [Fintype.expect_const] theorem expect_canonicalize (h : (B β†’ Bool) β†’ ℝ) : (𝔼 f : B β†’ Bool, h (canonicalize p f)) = 𝔼 g : {b // p b} β†’ Bool, h (extend p g) := expect_restrict p (fun g => h (extend p g)) theorem expect_restrict_pair (h : ({b // p b} β†’ Bool) β†’ ({b // p b} β†’ Bool) β†’ ℝ) : (𝔼 f : B β†’ Bool, 𝔼 g : B β†’ Bool, h (restrict p f) (restrict p g)) = 𝔼 f : {b // p b} β†’ Bool, 𝔼 g : {b // p b} β†’ Bool, h f g := by calc _ = 𝔼 f : B β†’ Bool, 𝔼 g : {b // p b} β†’ Bool, h (restrict p f) g := by apply Finset.expect_congr rfl intro f _ exact expect_restrict p (h (restrict p f)) _ = _ := expect_restrict p (fun f => 𝔼 g : {b // p b} β†’ Bool, h f g) end BinPackingGames.Foundations.PCP.UniformRestriction namespace BinPackingGames.Foundations.PCP.CodeComposition open scoped BigOperators open BinPackingGames.Foundations.Hastad def disagreement (a b : Bool) : ℝ := if a = b then 0 else 1 @[simp] theorem disagreement_self (a : Bool) : disagreement a a = 0 := by simp [disagreement] theorem disagreement_nonnegative (a b : Bool) : 0 ≀ disagreement a b := by cases a <;> cases b <;> norm_num [disagreement] theorem disagreement_le_one (a b : Bool) : disagreement a b ≀ 1 := by cases a <;> cases b <;> norm_num [disagreement] theorem disagreement_comm (a b : Bool) : disagreement a b = disagreement b a := by simp [disagreement, eq_comm] theorem disagreement_triangle (a b c : Bool) : disagreement a c ≀ disagreement a b + disagreement b c := by cases a <;> cases b <;> cases c <;> norm_num [disagreement] theorem disagreement_eq_sign (a b : Bool) : disagreement a b = (1 - bitSign a * bitSign b) / 2 := by cases a <;> cases b <;> norm_num [disagreement, bitSign] def relativeDistance {X : Type*} [Fintype X] (f g : X β†’ Bool) : ℝ := 𝔼 x, disagreement (f x) (g x) @[simp] theorem relativeDistance_self {X : Type*} [Fintype X] (f : X β†’ Bool) : relativeDistance f f = 0 := by simp [relativeDistance] theorem relativeDistance_nonnegative {X : Type*} [Fintype X] (f g : X β†’ Bool) : 0 ≀ relativeDistance f g := Finset.expect_nonneg (fun _ _ => disagreement_nonnegative _ _) theorem relativeDistance_comm {X : Type*} [Fintype X] (f g : X β†’ Bool) : relativeDistance f g = relativeDistance g f := by simp only [relativeDistance, disagreement_comm] theorem relativeDistance_triangle {X : Type*} [Fintype X] (f g h : X β†’ Bool) : relativeDistance f h ≀ relativeDistance f g + relativeDistance g h := by rw [relativeDistance, relativeDistance, relativeDistance, ← Finset.expect_add_distrib] exact Finset.expect_le_expect (fun _ _ => disagreement_triangle _ _ _) theorem relativeDistance_eq_sign {X : Type*} [Fintype X] [Nonempty X] (f g : X β†’ Bool) : relativeDistance f g = (1 - 𝔼 x, bitSign (f x) * bitSign (g x)) / 2 := by simp only [relativeDistance, disagreement_eq_sign] rw [← Finset.expect_div, Finset.expect_sub_distrib] simp def codeword {A : Type*} (a : A) : Cube A β†’ Bool := fun x => x a private def singletonMask {A : Type*} [DecidableEq A] (a : A) : Cube A := fun i => decide (i = a) private theorem walsh_singletonMask {A : Type*} [Fintype A] [DecidableEq A] (a : A) (x : Cube A) : walsh (singletonMask a) x = bitSign (x a) := by classical unfold walsh singletonMask rw [Finset.prod_eq_single a] Β· simp Β· intro b _ hba simp [hba, bitSign] Β· simp private theorem singletonMask_ne {A : Type*} [DecidableEq A] {a b : A} (hab : a β‰  b) : singletonMask a β‰  singletonMask b := by intro h have he := congrFun h a simp [singletonMask, hab] at he theorem codeword_distance {A : Type*} [Fintype A] [DecidableEq A] {a b : A} (hab : a β‰  b) : relativeDistance (codeword a) (codeword b) = 1 / 2 := by rw [relativeDistance_eq_sign] have horth := walsh_orthogonality (singletonMask a) (singletonMask b) rw [ite_eq_right (singletonMask_ne hab)] at horth simp_rw [walsh_singletonMask] at horth change (1 - 𝔼 x : Cube A, bitSign (x a) * bitSign (x b)) / 2 = 1 / 2 rw [horth] norm_num theorem exists_nearest {A : Type*} [Fintype A] [DecidableEq A] [Nonempty A] (f : Cube A β†’ Bool) : βˆƒ a : A, βˆ€ b : A, relativeDistance f (codeword a) ≀ relativeDistance f (codeword b) := by classical obtain ⟨a, _, ha⟩ := Finset.exists_min_image Finset.univ (fun a : A => relativeDistance f (codeword a)) Finset.univ_nonempty exact ⟨a, fun b => ha b (Finset.mem_univ b)⟩ def nearest {A : Type*} [Fintype A] [DecidableEq A] [Nonempty A] (f : Cube A β†’ Bool) : A := Classical.choose (exists_nearest f) theorem nearest_minimal {A : Type*} [Fintype A] [DecidableEq A] [Nonempty A] (f : Cube A β†’ Bool) (a : A) : relativeDistance f (codeword (nearest f)) ≀ relativeDistance f (codeword a) := Classical.choose_spec (exists_nearest f) a theorem distance_from_other_codeword {A : Type*} [Fintype A] [DecidableEq A] [Nonempty A] (f : Cube A β†’ Bool) {a : A} (ha : a β‰  nearest f) : 1 / 4 ≀ relativeDistance f (codeword a) := by have htri := relativeDistance_triangle (codeword (nearest f)) f (codeword a) rw [codeword_distance (Ne.symm ha), relativeDistance_comm (codeword (nearest f)) f] at htri have hmin := nearest_minimal f a linarith def pairWord {X : Type*} (left right : X β†’ Bool) : Bool Γ— X β†’ Bool := fun p => if p.1 then right p.2 else left p.2 theorem pairWord_distance {X : Type*} [Fintype X] [Nonempty X] (left right left' right' : X β†’ Bool) : relativeDistance (pairWord left right) (pairWord left' right') = (relativeDistance left left' + relativeDistance right right') / 2 := by classical simp [relativeDistance, Fintype.expect_eq_sum_div_card, Fintype.card_prod, Fintype.sum_prod_type, pairWord] ring theorem rejected_pair_far {A : Type*} [Fintype A] [DecidableEq A] [Nonempty A] (accepts : A β†’ A β†’ Bool) (left right : Cube A β†’ Bool) (hbad : accepts (nearest left) (nearest right) = false) (a b : A) (hgood : accepts a b = true) : 1 / 8 ≀ relativeDistance (pairWord left right) (pairWord (codeword a) (codeword b)) := by rw [pairWord_distance] have hleft := relativeDistance_nonnegative left (codeword a) have hright := relativeDistance_nonnegative right (codeword b) by_cases ha : a = nearest left Β· have hb : b β‰  nearest right := by intro hb rw [ha, hb, hbad] at hgood cases hgood have hsep := distance_from_other_codeword right hb linarith Β· have hsep := distance_from_other_codeword left ha linarith end BinPackingGames.Foundations.PCP.CodeComposition namespace BinPackingGames.Foundations.PCP.AssignmentTester open BinPackingGames.Foundations.Hastad open scoped BigOperators open Finset variable {A : Type*} [Fintype A] [DecidableEq A] def truth (b : Bool) : ℝ := if b then 1 else 0 def disagree (a b : Bool) : ℝ := if a = b then 0 else 1 theorem truth_nonneg (b : Bool) : 0 ≀ truth b := by cases b <;> norm_num [truth] theorem disagree_nonneg (a b : Bool) : 0 ≀ disagree a b := by cases a <;> cases b <;> norm_num [disagree] theorem disagree_eq (a b : Bool) : disagree a b = (1 - bitSign a * bitSign b) / 2 := by cases a <;> cases b <;> norm_num [disagree, bitSign] theorem disagree_xor_le (a b c d : Bool) : disagree (a ^^ b) (c ^^ d) ≀ disagree a c + disagree b d := by cases a <;> cases b <;> cases c <;> cases d <;> norm_num [disagree] def parity (s f : Cube A) : Bool := decide (Odd ((Finset.univ.filter fun a => s a && f a = true).card)) theorem bitSign_parity (s f : Cube A) : bitSign (parity s f) = walsh s f := by have hw : walsh s f = (-1 : ℝ) ^ (Finset.univ.filter fun a => s a && f a = true).card := by simp [walsh, bitSign, Finset.prod_ite] rw [hw] simpa [parity, bitSign] using (sign_power_parity true (Finset.univ.filter fun a => s a && f a = true).card).symm theorem bitSign_injective : Function.Injective bitSign := by intro a b h cases a <;> cases b <;> simp_all [bitSign] <;> linarith theorem parity_xor (s f g : Cube A) : parity s (cubeXor f g) = (parity s f ^^ parity s g) := by apply bitSign_injective rw [bitSign_parity, bitSign_xor, bitSign_parity, bitSign_parity, walsh_xor] omit [Fintype A] [DecidableEq A] in theorem cubeXor_comm (f g : Cube A) : cubeXor f g = cubeXor g f := by funext a simp [cubeXor, Bool.xor_comm] omit [Fintype A] [DecidableEq A] in @[simp] theorem cubeXor_right_twice (f g : Cube A) : cubeXor (cubeXor f g) g = f := by funext a change ((f a ^^ g a) ^^ g a) = f a cases f a <;> cases g a <;> rfl theorem expect_cubeXor (F : Cube A β†’ ℝ) (g : Cube A) : (𝔼 f, F (cubeXor f g)) = 𝔼 f, F f := by rw [Fintype.expect_eq_sum_div_card, Fintype.expect_eq_sum_div_card] congr 1 refine Finset.sum_bij (fun f _ => cubeXor f g) ?_ ?_ ?_ ?_ Β· intro f _ exact Finset.mem_univ _ Β· intro f _ h _ heq have hh := congrArg (fun x => cubeXor x g) heq simpa only [cubeXor_right_twice] using hh Β· intro f _ exact ⟨cubeXor f g, Finset.mem_univ _, cubeXor_right_twice f g⟩ Β· intro f _ rfl def distance {K : Type*} [Fintype K] (f g : K β†’ Bool) : ℝ := 𝔼 k, disagree (f k) (g k) theorem distance_nonneg {K : Type*} [Fintype K] (f g : K β†’ Bool) : 0 ≀ distance f g := by apply Finset.expect_nonneg intro k _ exact disagree_nonneg _ _ theorem distance_parity (F : Cube A β†’ Bool) (s : Cube A) : distance F (parity s) = (1 - coefficient (fun f => bitSign (F f)) s) / 2 := by unfold distance simp_rw [disagree_eq, bitSign_parity, div_eq_mul_inv, ← Finset.expect_mul, Finset.expect_sub_distrib] simp only [Fintype.expect_const] rfl def blrReject (F : Cube A β†’ Bool) : ℝ := 𝔼 f, 𝔼 g, disagree (F f ^^ F g) (F (cubeXor f g)) theorem blrReject_nonneg (F : Cube A β†’ Bool) : 0 ≀ blrReject F := by apply Finset.expect_nonneg intro f _ apply Finset.expect_nonneg intro g _ exact disagree_nonneg _ _ theorem blr_correlation (F : Cube A β†’ Bool) : (𝔼 f, 𝔼 g, bitSign (F f) * bitSign (F g) * bitSign (F (cubeXor f g))) = βˆ‘ s, coefficient (fun f => bitSign (F f)) s ^ 3 := by simp_rw [mul_assoc, ← Finset.mul_expect] conv_lhs => enter [2, f, 2, 2, g, 2, 1] rw [cubeXor_comm] simp_rw [walsh_autocorrelation, Finset.mul_sum] rw [Finset.expect_sum_comm] apply Finset.sum_congr rfl intro s _ have heq (f : Cube A) : bitSign (F f) * (coefficient (fun f => bitSign (F f)) s ^ 2 * walsh s f) = coefficient (fun f => bitSign (F f)) s ^ 2 * (bitSign (F f) * walsh s f) := by ring simp_rw [heq, ← Finset.mul_expect] change coefficient (fun f => bitSign (F f)) s ^ 2 * coefficient (fun f => bitSign (F f)) s = _ ring theorem blrReject_fourier (F : Cube A β†’ Bool) : blrReject F = (1 - βˆ‘ s, coefficient (fun f => bitSign (F f)) s ^ 3) / 2 := by unfold blrReject simp_rw [disagree_eq, bitSign_xor, div_eq_mul_inv, ← Finset.expect_mul, Finset.expect_sub_distrib] simp only [Fintype.expect_const] rw [blr_correlation] theorem blr_near_parity (F : Cube A β†’ Bool) : βˆƒ s : Cube A, distance F (parity s) ≀ blrReject F := by classical let c := coefficient (fun f => bitSign (F f)) have hmass : (βˆ‘ s, c s ^ 2) = 1 := sign_parseval F have hlarge : βˆƒ s, (βˆ‘ t, c t ^ 3) ≀ c s := by by_contra hn push Not at hn have hpos : βˆƒ s, 0 < c s ^ 2 := by by_contra hh push Not at hh have hz := Finset.sum_nonpos (s := Finset.univ) (fun s _ => hh s) linarith obtain ⟨sβ‚€, hsβ‚€βŸ© := hpos have hle (s : Cube A) (_ : s ∈ Finset.univ) : c s ^ 3 ≀ (βˆ‘ t, c t ^ 3) * c s ^ 2 := by have h := mul_le_mul_of_nonneg_right (hn s).le (sq_nonneg (c s)) nlinarith have hlt : c sβ‚€ ^ 3 < (βˆ‘ t, c t ^ 3) * c sβ‚€ ^ 2 := by have h := mul_lt_mul_of_pos_right (hn sβ‚€) hsβ‚€ nlinarith have hsum := Finset.sum_lt_sum hle ⟨sβ‚€, Finset.mem_univ _, hlt⟩ rw [← Finset.mul_sum, hmass, mul_one] at hsum exact (lt_irrefl _ hsum) obtain ⟨s, hs⟩ := hlarge refine ⟨s, ?_⟩ rw [distance_parity, blrReject_fourier] dsimp [c] at hs linarith def selfCorrect (F : Cube A β†’ Bool) (x r : Cube A) : Bool := F r ^^ F (cubeXor r x) theorem parity_selfCorrect (s x r : Cube A) : (parity s r ^^ parity s (cubeXor r x)) = parity s x := by rw [parity_xor] cases parity s r <;> cases parity s x <;> rfl theorem selfCorrect_error (F : Cube A β†’ Bool) (s x : Cube A) : (𝔼 r, disagree (selfCorrect F x r) (parity s x)) ≀ 2 * distance F (parity s) := by have hle (r : Cube A) : disagree (selfCorrect F x r) (parity s x) ≀ disagree (F r) (parity s r) + disagree (F (cubeXor r x)) (parity s (cubeXor r x)) := by rw [← parity_selfCorrect s x r] exact disagree_xor_le _ _ _ _ have h := Finset.expect_le_expect (s := Finset.univ) (fun r _ => hle r) rw [Finset.expect_add_distrib, expect_cubeXor (fun r => disagree (F r) (parity s r)) x] at h change _ ≀ distance F (parity s) + distance F (parity s) at h linarith def singleMask (i : A) : Cube A := fun j => decide (j = i) def flipAt (i : A) (f : Cube A) : Cube A := fun j => if j = i then !(f j) else f j omit [Fintype A] in @[simp] theorem flipAt_twice (i : A) (f : Cube A) : flipAt i (flipAt i f) = f := by funext j by_cases h : j = i <;> simp [flipAt, h] omit [Fintype A] in theorem flipAt_eq_xor (i : A) (f : Cube A) : flipAt i f = cubeXor f (singleMask i) := by funext j by_cases h : j = i <;> simp [flipAt, cubeXor, singleMask, h] theorem expect_flipAt (F : Cube A β†’ ℝ) (i : A) : (𝔼 f, F (flipAt i f)) = 𝔼 f, F f := by simp_rw [flipAt_eq_xor] exact expect_cubeXor F _ theorem walsh_singleMask (s : Cube A) (i : A) : walsh s (singleMask i) = bitSign (s i) := by unfold walsh rw [Finset.prod_eq_single i] Β· simp [singleMask] Β· intro j _ hj simp [singleMask, hj, bitSign] Β· intro h exact False.elim (h (Finset.mem_univ _)) theorem parity_singleMask (s : Cube A) (i : A) : parity s (singleMask i) = s i := by apply bitSign_injective rw [bitSign_parity, walsh_singleMask] theorem parity_flipAt (s : Cube A) (i : A) (f : Cube A) (hs : s i = true) : parity s (flipAt i f) = !(parity s f) := by rw [flipAt_eq_xor, parity_xor, parity_singleMask, hs] cases parity s f <;> rfl def cubeAnd (f g : Cube A) : Cube A := fun a => f a && g a def andLawFailure (s f g : Cube A) : Bool := parity s (cubeAnd f g) ^^ (parity s f && parity s g) theorem andLawFailure_flipAt_second (s : Cube A) (i : A) (f g : Cube A) (hi : s i = true) : andLawFailure s f (flipAt i g) = (andLawFailure s f g ^^ (parity s f ^^ f i)) := by have hAnd : cubeAnd f (flipAt i g) = (if f i then flipAt i (cubeAnd f g) else cubeAnd f g) := by funext a by_cases ha : a = i Β· subst a cases hfi : f i <;> simp [cubeAnd, flipAt, hfi] Β· cases f i <;> simp [cubeAnd, flipAt, ha] have hg := parity_flipAt s i g hi have hfg := parity_flipAt s i (cubeAnd f g) hi cases hfi : f i <;> cases hf : parity s f <;> cases hgβ‚€ : parity s g <;> cases ha : parity s (cubeAnd f g) <;> simp [andLawFailure, hAnd, hg, hfg, hfi, hf, hgβ‚€, ha] private theorem four_truth_lower (eβ‚€ e₁ d : Bool) : (1 : ℝ) ≀ truth eβ‚€ + truth (eβ‚€ ^^ d) + truth e₁ + truth (e₁ ^^ (!d)) := by cases eβ‚€ <;> cases e₁ <;> cases d <;> norm_num [truth] theorem parity_and_rejection (s : Cube A) (i j : A) (hi : s i = true) (hj : s j = true) (hij : i β‰  j) : (1 : ℝ) / 4 ≀ 𝔼 f, 𝔼 g, truth (andLawFailure s f g) := by have hpoint (f g : Cube A) : (1 : ℝ) ≀ truth (andLawFailure s f g) + truth (andLawFailure s f (flipAt i g)) + truth (andLawFailure s (flipAt j f) g) + truth (andLawFailure s (flipAt j f) (flipAt i g)) := by rw [andLawFailure_flipAt_second s i f g hi, andLawFailure_flipAt_second s i (flipAt j f) g hi] have hD : (parity s (flipAt j f) ^^ (flipAt j f) i) = !(parity s f ^^ f i) := by rw [parity_flipAt s j f hj] simp only [flipAt, ite_eq_right hij] cases parity s f <;> cases f i <;> simp rw [hD] exact four_truth_lower _ _ _ have havg := Finset.expect_le_expect (s := Finset.univ) (fun f _ => Finset.expect_le_expect (s := Finset.univ) (fun g _ => hpoint f g)) simp only [Finset.expect_add_distrib, Fintype.expect_const] at havg have hinner (f : Cube A) : (𝔼 g, truth (andLawFailure s f (flipAt i g))) = 𝔼 g, truth (andLawFailure s f g) := expect_flipAt (fun g => truth (andLawFailure s f g)) i have houter : (𝔼 f, 𝔼 g, truth (andLawFailure s (flipAt j f) g)) = 𝔼 f, 𝔼 g, truth (andLawFailure s f g) := expect_flipAt (fun f => 𝔼 g, truth (andLawFailure s f g)) j simp only [hinner, houter] at havg linarith theorem truth_xor (a b : Bool) : truth (a ^^ b) = disagree a b := by cases a <;> cases b <;> norm_num [truth, disagree] theorem disagree_triangle (a b c : Bool) : disagree a c ≀ disagree a b + disagree b c := by cases a <;> cases b <;> cases c <;> norm_num [disagree] theorem and_disagree_transfer (pβ‚€ p₁ pβ‚‚ qβ‚€ q₁ qβ‚‚ : Bool) : disagree pβ‚€ (p₁ && pβ‚‚) ≀ disagree qβ‚€ (q₁ && qβ‚‚) + disagree qβ‚€ pβ‚€ + disagree q₁ p₁ + disagree qβ‚‚ pβ‚‚ := by cases pβ‚€ <;> cases p₁ <;> cases pβ‚‚ <;> cases qβ‚€ <;> cases q₁ <;> cases qβ‚‚ <;> norm_num [disagree] def andReject (F : Cube A β†’ Bool) : ℝ := 𝔼 f, 𝔼 g, 𝔼 rβ‚€, 𝔼 r₁, 𝔼 rβ‚‚, disagree (selfCorrect F (cubeAnd f g) rβ‚€) (selfCorrect F f r₁ && selfCorrect F g rβ‚‚) def unitReject (F : Cube A β†’ Bool) : ℝ := 𝔼 r, disagree (selfCorrect F (fun _ => true) r) true variable {K : Type*} [Fintype K] [Nonempty K] def inputReject (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) : ℝ := 𝔼 k, 𝔼 r, disagree (Οƒ k) (selfCorrect F (fun a => label a k) r) def testerReject (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) : ℝ := (blrReject F + andReject F + unitReject F + inputReject label Οƒ F) / 4 theorem andReject_nonneg (F : Cube A β†’ Bool) : 0 ≀ andReject F := by apply Finset.expect_nonneg intro f _ apply Finset.expect_nonneg intro g _ apply Finset.expect_nonneg intro rβ‚€ _ apply Finset.expect_nonneg intro r₁ _ apply Finset.expect_nonneg intro rβ‚‚ _ exact disagree_nonneg _ _ theorem unitReject_nonneg (F : Cube A β†’ Bool) : 0 ≀ unitReject F := by apply Finset.expect_nonneg intro r _ exact disagree_nonneg _ _ omit [Nonempty K] in theorem inputReject_nonneg (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) : 0 ≀ inputReject label Οƒ F := by apply Finset.expect_nonneg intro k _ apply Finset.expect_nonneg intro r _ exact disagree_nonneg _ _ theorem andReject_transfer (F : Cube A β†’ Bool) (s : Cube A) : (𝔼 f, 𝔼 g, truth (andLawFailure s f g)) ≀ andReject F + 6 * distance F (parity s) := by have hlocal (f g : Cube A) : truth (andLawFailure s f g) ≀ (𝔼 rβ‚€, 𝔼 r₁, 𝔼 rβ‚‚, disagree (selfCorrect F (cubeAnd f g) rβ‚€) (selfCorrect F f r₁ && selfCorrect F g rβ‚‚)) + 6 * distance F (parity s) := by have hp (rβ‚€ r₁ rβ‚‚ : Cube A) := and_disagree_transfer (parity s (cubeAnd f g)) (parity s f) (parity s g) (selfCorrect F (cubeAnd f g) rβ‚€) (selfCorrect F f r₁) (selfCorrect F g rβ‚‚) have havg := Finset.expect_le_expect (s := Finset.univ) (fun rβ‚€ _ => Finset.expect_le_expect (s := Finset.univ) (fun r₁ _ => Finset.expect_le_expect (s := Finset.univ) (fun rβ‚‚ _ => hp rβ‚€ r₁ rβ‚‚))) simp only [Finset.expect_add_distrib, Fintype.expect_const] at havg have hβ‚€ := selfCorrect_error F s (cubeAnd f g) have h₁ := selfCorrect_error F s f have hβ‚‚ := selfCorrect_error F s g rw [andLawFailure, truth_xor] linarith have h := Finset.expect_le_expect (s := Finset.univ) (fun f _ => Finset.expect_le_expect (s := Finset.univ) (fun g _ => hlocal f g)) simpa only [Finset.expect_add_distrib, Fintype.expect_const, andReject] using h theorem parity_zero (f : Cube A) : parity (fun _ => false) f = false := by apply bitSign_injective rw [bitSign_parity] simp [walsh, bitSign] theorem unitReject_zero_parity (F : Cube A β†’ Bool) : 1 - 2 * distance F (parity (fun _ => false)) ≀ unitReject F := by have herr := selfCorrect_error F (fun _ => false) (fun _ => true) simp only [parity_zero] at herr have heq : unitReject F + (𝔼 r, disagree (selfCorrect F (fun _ => true) r) false) = 1 := by unfold unitReject rw [← Finset.expect_add_distrib] have hp (b : Bool) : disagree b true + disagree b false = 1 := by cases b <;> norm_num [disagree] simp only [hp, Fintype.expect_const] linarith theorem parity_singleMask_eval (a : A) (f : Cube A) : parity (singleMask a) f = f a := by apply bitSign_injective rw [bitSign_parity, walsh_symm, walsh_singleMask] theorem inputReject_transfer (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) (a : A) : distance Οƒ (label a) ≀ inputReject label Οƒ F + 2 * distance F (parity (singleMask a)) := by have hlocal (k : K) : disagree (Οƒ k) (label a k) ≀ (𝔼 r, disagree (Οƒ k) (selfCorrect F (fun a => label a k) r)) + 2 * distance F (parity (singleMask a)) := by have hp (r : Cube A) := disagree_triangle (Οƒ k) (selfCorrect F (fun a => label a k) r) (label a k) have havg := Finset.expect_le_expect (s := Finset.univ) (fun r _ => hp r) simp only [Fintype.expect_const, Finset.expect_add_distrib] at havg have herr := selfCorrect_error F (singleMask a) (fun a => label a k) simp only [parity_singleMask_eval] at herr linarith have h := Finset.expect_le_expect (s := Finset.univ) (fun k _ => hlocal k) simpa only [Finset.expect_add_distrib, Fintype.expect_const, inputReject, distance] using h theorem tester_proximity_soundness (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) {Ξ΄ : ℝ} (hΞ΄ : 0 < Ξ΄) (hΞ΄' : Ξ΄ ≀ 1 / 4) (hfar : βˆ€ a, Ξ΄ ≀ distance Οƒ (label a)) : Ξ΄ / 256 ≀ testerReject label Οƒ F := by have hblr := blrReject_nonneg F have hand := andReject_nonneg F have hunit := unitReject_nonneg F have hin := inputReject_nonneg label Οƒ F by_cases hb : Ξ΄ / 64 ≀ blrReject F Β· unfold testerReject linarith obtain ⟨s, hs⟩ := blr_near_parity F by_cases hz : s = fun _ => false Β· subst s have hu := unitReject_zero_parity F unfold testerReject linarith have hsome : βˆƒ i, s i = true := by by_contra hh push Not at hh apply hz funext i have h := hh i cases hi : s i <;> simp_all obtain ⟨i, hi⟩ := hsome by_cases htwo : βˆƒ j, i β‰  j ∧ s j = true Β· obtain ⟨j, hij, hj⟩ := htwo have ha := parity_and_rejection s i j hi hj hij have ht := andReject_transfer F s unfold testerReject linarith Β· have heq : s = singleMask i := by funext j by_cases hji : j = i Β· subst j simp [singleMask, hi] Β· have hj : s j = false := by cases hv : s j Β· rfl Β· exact False.elim (htwo ⟨j, Ne.symm hji, hv⟩) simp [singleMask, hji, hj] subst s have ht := inputReject_transfer label Οƒ F i have hf := hfar i unfold testerReject linarith omit [Fintype A] [DecidableEq A] in theorem selfCorrect_dictator (a : A) (x r : Cube A) : selfCorrect (fun f => f a) x r = x a := by change (r a ^^ (r a ^^ x a)) = x a cases r a <;> cases x a <;> rfl omit [Nonempty K] in theorem tester_perfect_completeness (label : A β†’ K β†’ Bool) (a : A) : testerReject label (label a) (fun f => f a) = 0 := by have hb : blrReject (fun f : Cube A => f a) = 0 := by simp [blrReject, cubeXor, disagree] have ha : andReject (fun f : Cube A => f a) = 0 := by simp [andReject, selfCorrect_dictator, cubeAnd, disagree] have hu : unitReject (fun f : Cube A => f a) = 0 := by simp [unitReject, selfCorrect_dictator, disagree] have hi : inputReject label (label a) (fun f => f a) = 0 := by simp [inputReject, selfCorrect_dictator, disagree] simp [testerReject, hb, ha, hu, hi] def eventQueries (label : A β†’ K β†’ Bool) (kind : Fin 4) (k : K) (f g rβ‚€ r₁ rβ‚‚ : Cube A) (slot : Fin 6) : K βŠ• Cube A := if kind = 0 then if slot = 0 then .inr f else if slot = 1 then .inr g else .inr (cubeXor f g) else if kind = 1 then if slot = 0 then .inr rβ‚€ else if slot = 1 then .inr (cubeXor rβ‚€ (cubeAnd f g)) else if slot = 2 then .inr r₁ else if slot = 3 then .inr (cubeXor r₁ f) else if slot = 4 then .inr rβ‚‚ else .inr (cubeXor rβ‚‚ g) else if kind = 2 then if slot = 0 then .inr rβ‚€ else .inr (cubeXor rβ‚€ (fun _ => true)) else if slot = 0 then .inl k else if slot = 1 then .inr rβ‚€ else .inr (cubeXor rβ‚€ (fun a => label a k)) def eventAccepts (kind : Fin 4) (b : Fin 6 β†’ Bool) : Bool := if kind = 0 then decide ((b 0 ^^ b 1) = b 2) else if kind = 1 then decide ((b 0 ^^ b 1) = ((b 2 ^^ b 3) && (b 4 ^^ b 5))) else if kind = 2 then (b 0 ^^ b 1) else decide (b 0 = (b 1 ^^ b 2)) def oracleAnswer (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) : K βŠ• Cube A β†’ Bool := Sum.elim Οƒ F def eventReject (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) (kind : Fin 4) (k : K) (f g rβ‚€ r₁ rβ‚‚ : Cube A) : ℝ := truth (!(eventAccepts kind (fun slot => oracleAnswer Οƒ F (eventQueries label kind k f g rβ‚€ r₁ rβ‚‚ slot)))) theorem truth_not_decide_eq (a b : Bool) : truth (!(decide (a = b))) = disagree a b := by cases a <;> cases b <;> norm_num [truth, disagree] omit [Fintype A] [DecidableEq A] [Fintype K] [Nonempty K] in theorem eventReject_blr (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) (k : K) (f g rβ‚€ r₁ rβ‚‚ : Cube A) : eventReject label Οƒ F 0 k f g rβ‚€ r₁ rβ‚‚ = disagree (F f ^^ F g) (F (cubeXor f g)) := by simp [eventReject, eventAccepts, eventQueries, oracleAnswer, truth_not_decide_eq] omit [Fintype A] [DecidableEq A] [Fintype K] [Nonempty K] in theorem eventReject_and (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) (k : K) (f g rβ‚€ r₁ rβ‚‚ : Cube A) : eventReject label Οƒ F 1 k f g rβ‚€ r₁ rβ‚‚ = disagree (selfCorrect F (cubeAnd f g) rβ‚€) (selfCorrect F f r₁ && selfCorrect F g rβ‚‚) := by simp [eventReject, eventAccepts, eventQueries, oracleAnswer, truth_not_decide_eq, selfCorrect] omit [Fintype A] [DecidableEq A] [Fintype K] [Nonempty K] in theorem eventReject_unit (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) (k : K) (f g rβ‚€ r₁ rβ‚‚ : Cube A) : eventReject label Οƒ F 2 k f g rβ‚€ r₁ rβ‚‚ = disagree (selfCorrect F (fun _ => true) rβ‚€) true := by simp only [eventReject, eventAccepts, eventQueries, oracleAnswer] norm_num change truth (!(selfCorrect F (fun _ => true) rβ‚€)) = disagree (selfCorrect F (fun _ => true) rβ‚€) true cases selfCorrect F (fun _ => true) rβ‚€ <;> norm_num [truth, disagree] omit [Fintype A] [DecidableEq A] [Fintype K] [Nonempty K] in theorem eventReject_input (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) (k : K) (f g rβ‚€ r₁ rβ‚‚ : Cube A) : eventReject label Οƒ F 3 k f g rβ‚€ r₁ rβ‚‚ = disagree (Οƒ k) (selfCorrect F (fun a => label a k) rβ‚€) := by simp [eventReject, eventAccepts, eventQueries, oracleAnswer, truth_not_decide_eq, selfCorrect] omit [Fintype A] [DecidableEq A] [Fintype K] [Nonempty K] in theorem event_perfect_completeness (label : A β†’ K β†’ Bool) (a : A) (kind : Fin 4) (k : K) (f g rβ‚€ r₁ rβ‚‚ : Cube A) : eventAccepts kind (fun slot => oracleAnswer (label a) (fun x => x a) (eventQueries label kind k f g rβ‚€ r₁ rβ‚‚ slot)) = true := by have hkind : kind = 0 ∨ kind = 1 ∨ kind = 2 ∨ kind = 3 := by omega have hreject : eventReject label (label a) (fun x => x a) kind k f g rβ‚€ r₁ rβ‚‚ = 0 := by rcases hkind with h | h | h | h <;> subst kind Β· simp [eventReject_blr, cubeXor, disagree] Β· simp [eventReject_and, selfCorrect_dictator, cubeAnd, disagree] Β· simp [eventReject_unit, selfCorrect_dictator, disagree] Β· simp [eventReject_input, selfCorrect_dictator, disagree] unfold eventReject at hreject cases h : eventAccepts kind (fun slot => oracleAnswer (label a) (fun x => x a) (eventQueries label kind k f g rβ‚€ r₁ rβ‚‚ slot)) <;> simp_all [truth] def explicitTesterReject (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) : ℝ := 𝔼 kind : Fin 4, 𝔼 k, 𝔼 f, 𝔼 g, 𝔼 rβ‚€, 𝔼 r₁, 𝔼 rβ‚‚, eventReject label Οƒ F kind k f g rβ‚€ r₁ rβ‚‚ theorem explicitTesterReject_eq (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) : explicitTesterReject label Οƒ F = testerReject label Οƒ F := by unfold explicitTesterReject rw [Fintype.expect_eq_sum_div_card] simp [Fin.sum_univ_succ, eventReject_blr, eventReject_and, eventReject_unit, eventReject_input, testerReject, blrReject, andReject, unitReject, inputReject, add_assoc] theorem explicit_proximity_soundness (label : A β†’ K β†’ Bool) (Οƒ : K β†’ Bool) (F : Cube A β†’ Bool) {Ξ΄ : ℝ} (hΞ΄ : 0 < Ξ΄) (hΞ΄' : Ξ΄ ≀ 1 / 4) (hfar : βˆ€ a, Ξ΄ ≀ distance Οƒ (label a)) : Ξ΄ / 256 ≀ explicitTesterReject label Οƒ F := by rw [explicitTesterReject_eq] exact tester_proximity_soundness label Οƒ F hΞ΄ hΞ΄' hfar end BinPackingGames.Foundations.PCP.AssignmentTester namespace BinPackingGames.Foundations.PCP.AlphabetReduction open BinPackingGames.Foundations.Hastad open CodeComposition variable {A : Type*} [Fintype A] [DecidableEq A] [Nonempty A] abbrev LegalPair (accepts : A β†’ A β†’ Bool) := {p : A Γ— A // accepts p.1 p.2 = true} abbrev InputCoordinate (A : Type*) := Bool Γ— Cube A def pairEncoding (accepts : A β†’ A β†’ Bool) (p : LegalPair accepts) : InputCoordinate A β†’ Bool := pairWord (codeword p.1.1) (codeword p.1.2) def edgeTesterReject (accepts : A β†’ A β†’ Bool) (left right : Cube A β†’ Bool) (F : Cube (LegalPair accepts) β†’ Bool) : ℝ := AssignmentTester.explicitTesterReject (pairEncoding accepts) (pairWord left right) F theorem rejected_edge_tester_bound (accepts : A β†’ A β†’ Bool) (left right : Cube A β†’ Bool) (F : Cube (LegalPair accepts) β†’ Bool) (hbad : accepts (nearest left) (nearest right) = false) : 1 / 2048 ≀ edgeTesterReject accepts left right F := by have hfar (p : LegalPair accepts) : (1 / 8 : ℝ) ≀ AssignmentTester.distance (pairWord left right) (pairEncoding accepts p) := by have h := rejected_pair_far accepts left right hbad p.1.1 p.1.2 p.2 convert h using 1 rfl have h := AssignmentTester.explicit_proximity_soundness (pairEncoding accepts) (pairWord left right) F (Ξ΄ := 1 / 8) (by norm_num) (by norm_num) hfar norm_num at h exact h omit [Nonempty A] in theorem honest_edge_tester (accepts : A β†’ A β†’ Bool) (a b : A) (hab : accepts a b = true) : edgeTesterReject accepts (codeword a) (codeword b) (fun f => f ⟨(a, b), hab⟩) = 0 := by unfold edgeTesterReject rw [AssignmentTester.explicitTesterReject_eq] exact AssignmentTester.tester_perfect_completeness (pairEncoding accepts) ⟨(a, b), hab⟩ end BinPackingGames.Foundations.PCP.AlphabetReduction namespace BinPackingGames.Foundations.PCP.AlphabetGraph open BinPackingGames.Foundations.Hastad open scoped BigOperators abbrev Address (V E A : Type*) := (V Γ— Cube A) βŠ• (E Γ— Cube (A Γ— A)) abbrev LocalEvent (A : Type*) := Fin 4 Γ— AlphabetReduction.InputCoordinate A Γ— Cube (A Γ— A) Γ— Cube (A Γ— A) Γ— Cube (A Γ— A) Γ— Cube (A Γ— A) Γ— Cube (A Γ— A) abbrev Event (E A : Type*) := E Γ— LocalEvent A variable {V E A : Type*} [Fintype A] [DecidableEq A] [Nonempty A] abbrev legal (G : ConstraintGraph V E A) (e : E) (p : A Γ— A) : Prop := G.accepts e p.1 p.2 = true instance legalDecidable (G : ConstraintGraph V E A) (e : E) : DecidablePred (legal G e) := fun p => inferInstanceAs (Decidable (G.accepts e p.1 p.2 = true)) def restrictTape (G : ConstraintGraph V E A) (e : E) (f : Cube (A Γ— A)) : Cube (AlphabetReduction.LegalPair (G.accepts e)) := UniformRestriction.restrict (legal G e) f def extendTape (G : ConstraintGraph V E A) (e : E) (f : Cube (AlphabetReduction.LegalPair (G.accepts e))) : Cube (A Γ— A) := UniformRestriction.extend (legal G e) f def globalizeQuery (G : ConstraintGraph V E A) (e : E) : AlphabetReduction.InputCoordinate A βŠ• Cube (AlphabetReduction.LegalPair (G.accepts e)) β†’ Address V E A | .inl (side, tape) => .inl ((if side then G.head e else G.tail e), tape) | .inr tape => .inr (e, extendTape G e tape) def verifier (G : ConstraintGraph V E A) : QueryIncidence.Verifier (Event E A) (Address V E A) 6 where query := fun (e, kind, k, f, g, rβ‚€, r₁, rβ‚‚) slot => globalizeQuery G e (AssignmentTester.eventQueries (AlphabetReduction.pairEncoding (G.accepts e)) kind k (restrictTape G e f) (restrictTape G e g) (restrictTape G e rβ‚€) (restrictTape G e r₁) (restrictTape G e rβ‚‚) slot) accepts := fun (_, kind, _, _, _, _, _, _) b => AssignmentTester.eventAccepts kind b def vertexBlock (assignment : Address V E A β†’ Bool) (v : V) : Cube A β†’ Bool := fun tape => assignment (.inl (v, tape)) def edgeOracle (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) (e : E) : Cube (AlphabetReduction.LegalPair (G.accepts e)) β†’ Bool := fun tape => assignment (.inr (e, extendTape G e tape)) omit [Fintype A] [DecidableEq A] [Nonempty A] in theorem oracleAnswer_globalize (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) (e : E) (x : AlphabetReduction.InputCoordinate A βŠ• Cube (AlphabetReduction.LegalPair (G.accepts e))) : assignment (globalizeQuery G e x) = AssignmentTester.oracleAnswer (CodeComposition.pairWord (vertexBlock assignment (G.tail e)) (vertexBlock assignment (G.head e))) (edgeOracle G assignment e) x := by rcases x with ⟨side, tape⟩ | tape Β· cases side <;> rfl Β· rfl omit [Fintype A] [DecidableEq A] [Nonempty A] in theorem response_eq_local (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) (e : E) (kind : Fin 4) (k : AlphabetReduction.InputCoordinate A) (f g rβ‚€ r₁ rβ‚‚ : Cube (A Γ— A)) : QueryIncidence.response (verifier G) assignment (e, kind, k, f, g, rβ‚€, r₁, rβ‚‚) = fun slot => AssignmentTester.oracleAnswer (CodeComposition.pairWord (vertexBlock assignment (G.tail e)) (vertexBlock assignment (G.head e))) (edgeOracle G assignment e) (AssignmentTester.eventQueries (AlphabetReduction.pairEncoding (G.accepts e)) kind k (restrictTape G e f) (restrictTape G e g) (restrictTape G e rβ‚€) (restrictTape G e r₁) (restrictTape G e rβ‚‚) slot) := by funext slot exact oracleAnswer_globalize G assignment e _ def eventReject (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) (event : Event E A) : ℝ := AssignmentTester.truth (!((verifier G).accepts event (QueryIncidence.response (verifier G) assignment event))) omit [Fintype A] [DecidableEq A] [Nonempty A] in theorem eventReject_eq_local (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) (e : E) (kind : Fin 4) (k : AlphabetReduction.InputCoordinate A) (f g rβ‚€ r₁ rβ‚‚ : Cube (A Γ— A)) : eventReject G assignment (e, kind, k, f, g, rβ‚€, r₁, rβ‚‚) = AssignmentTester.eventReject (AlphabetReduction.pairEncoding (G.accepts e)) (CodeComposition.pairWord (vertexBlock assignment (G.tail e)) (vertexBlock assignment (G.head e))) (edgeOracle G assignment e) kind k (restrictTape G e f) (restrictTape G e g) (restrictTape G e rβ‚€) (restrictTape G e r₁) (restrictTape G e rβ‚‚) := by unfold eventReject rw [response_eq_local] rfl theorem expect_prod {I J : Type*} [Fintype I] [Fintype J] (f : I Γ— J β†’ ℝ) : (𝔼 z : I Γ— J, f z) = 𝔼 i : I, 𝔼 j : J, f (i, j) := by simpa only [Finset.univ_product_univ] using Finset.expect_product (Finset.univ : Finset I) (Finset.univ : Finset J) f def localAverage (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) (e : E) : ℝ := 𝔼 sample : LocalEvent A, eventReject G assignment (e, sample) theorem expect_restrict_five {B : Type*} [Fintype B] [DecidableEq B] (p : B β†’ Prop) [DecidablePred p] (h : ({b // p b} β†’ Bool) β†’ ({b // p b} β†’ Bool) β†’ ({b // p b} β†’ Bool) β†’ ({b // p b} β†’ Bool) β†’ ({b // p b} β†’ Bool) β†’ ℝ) : (𝔼 f : B β†’ Bool, 𝔼 g : B β†’ Bool, 𝔼 rβ‚€ : B β†’ Bool, 𝔼 r₁ : B β†’ Bool, 𝔼 rβ‚‚ : B β†’ Bool, h (UniformRestriction.restrict p f) (UniformRestriction.restrict p g) (UniformRestriction.restrict p rβ‚€) (UniformRestriction.restrict p r₁) (UniformRestriction.restrict p rβ‚‚)) = 𝔼 f : {b // p b} β†’ Bool, 𝔼 g : {b // p b} β†’ Bool, 𝔼 rβ‚€ : {b // p b} β†’ Bool, 𝔼 r₁ : {b // p b} β†’ Bool, 𝔼 rβ‚‚ : {b // p b} β†’ Bool, h f g rβ‚€ r₁ rβ‚‚ := by rw [UniformRestriction.expect_restrict p (fun f => 𝔼 g : B β†’ Bool, 𝔼 rβ‚€ : B β†’ Bool, 𝔼 r₁ : B β†’ Bool, 𝔼 rβ‚‚ : B β†’ Bool, h f (UniformRestriction.restrict p g) (UniformRestriction.restrict p rβ‚€) (UniformRestriction.restrict p r₁) (UniformRestriction.restrict p rβ‚‚))] apply Finset.expect_congr rfl intro f _ rw [UniformRestriction.expect_restrict p (fun g => 𝔼 rβ‚€ : B β†’ Bool, 𝔼 r₁ : B β†’ Bool, 𝔼 rβ‚‚ : B β†’ Bool, h f g (UniformRestriction.restrict p rβ‚€) (UniformRestriction.restrict p r₁) (UniformRestriction.restrict p rβ‚‚))] apply Finset.expect_congr rfl intro g _ rw [UniformRestriction.expect_restrict p (fun rβ‚€ => 𝔼 r₁ : B β†’ Bool, 𝔼 rβ‚‚ : B β†’ Bool, h f g rβ‚€ (UniformRestriction.restrict p r₁) (UniformRestriction.restrict p rβ‚‚))] apply Finset.expect_congr rfl intro rβ‚€ _ rw [UniformRestriction.expect_restrict p (fun r₁ => 𝔼 rβ‚‚ : B β†’ Bool, h f g rβ‚€ r₁ (UniformRestriction.restrict p rβ‚‚))] apply Finset.expect_congr rfl intro r₁ _ exact UniformRestriction.expect_restrict p (h f g rβ‚€ r₁) omit [Nonempty A] in theorem localAverage_eq_tester (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) (e : E) : localAverage G assignment e = AlphabetReduction.edgeTesterReject (G.accepts e) (vertexBlock assignment (G.tail e)) (vertexBlock assignment (G.head e)) (edgeOracle G assignment e) := by unfold localAverage AlphabetReduction.edgeTesterReject AssignmentTester.explicitTesterReject simp only [LocalEvent, expect_prod, eventReject_eq_local, restrictTape] apply Finset.expect_congr rfl intro kind _ apply Finset.expect_congr rfl intro side _ apply Finset.expect_congr rfl intro tape _ exact expect_restrict_five (legal G e) (AssignmentTester.eventReject (AlphabetReduction.pairEncoding (G.accepts e)) (CodeComposition.pairWord (vertexBlock assignment (G.tail e)) (vertexBlock assignment (G.head e))) (edgeOracle G assignment e) kind (side, tape)) def average [Fintype E] (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) : ℝ := 𝔼 event : Event E A, eventReject G assignment event omit [Nonempty A] in theorem average_eq_testers [Fintype E] (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) : average G assignment = 𝔼 e : E, AlphabetReduction.edgeTesterReject (G.accepts e) (vertexBlock assignment (G.tail e)) (vertexBlock assignment (G.head e)) (edgeOracle G assignment e) := by unfold average rw [expect_prod] exact Finset.expect_congr rfl (fun e _ => localAverage_eq_tester G assignment e) def decodedLabeling (assignment : Address V E A β†’ Bool) : V β†’ A := fun v => CodeComposition.nearest (vertexBlock assignment v) theorem local_gap (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) (e : E) : AssignmentTester.truth (!(G.edgeSatisfied (decodedLabeling assignment) e)) / 2048 ≀ localAverage G assignment e := by cases h : G.edgeSatisfied (decodedLabeling assignment) e with | false => rw [localAverage_eq_tester] simpa [AssignmentTester.truth] using AlphabetReduction.rejected_edge_tester_bound (G.accepts e) (vertexBlock assignment (G.tail e)) (vertexBlock assignment (G.head e)) (edgeOracle G assignment e) h | true => simp only [Bool.not_true, AssignmentTester.truth, Bool.false_eq_true, ite_false, zero_div] apply Finset.expect_nonneg intro sample _ exact AssignmentTester.truth_nonneg _ theorem average_gap [Fintype E] (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) : (𝔼 e : E, AssignmentTester.truth (!(G.edgeSatisfied (decodedLabeling assignment) e))) / 2048 ≀ average G assignment := by unfold average rw [expect_prod, Finset.expect_div] exact Finset.expect_le_expect (fun e _ => local_gap G assignment e) theorem expect_rejection_eq_count {I : Type*} [Fintype I] (b : I β†’ Bool) : (𝔼 i : I, AssignmentTester.truth (!(b i))) = ((Finset.univ.filter (fun i => b i = false)).card : ℝ) / Fintype.card I := by rw [Fintype.expect_eq_sum_div_card] congr 1 calc (βˆ‘ i : I, AssignmentTester.truth (!(b i))) = βˆ‘ i : I, if b i = false then (1 : ℝ) else 0 := by apply Finset.sum_congr rfl intro i _ cases b i <;> norm_num [AssignmentTester.truth] _ = _ := Finset.sum_boole _ _ omit [Nonempty A] in theorem average_eq_count [Fintype E] (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) : average G assignment = (QueryIncidence.verifierRejectionCount (verifier G) assignment : ℝ) / Fintype.card (Event E A) := expect_rejection_eq_count _ omit [Nonempty A] in @[simp] theorem card_event [Fintype E] : Fintype.card (Event E A) = Fintype.card E * Fintype.card (LocalEvent A) := Fintype.card_prod _ _ omit [Nonempty A] in theorem card_localEvent : Fintype.card (LocalEvent A) = 4 * (2 * 2 ^ Fintype.card A) * (2 ^ (Fintype.card A * Fintype.card A)) ^ 5 := by simp [LocalEvent, AlphabetReduction.InputCoordinate, Cube, Fintype.card_prod, pow_succ, Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] omit [Nonempty A] in theorem card_address [Fintype V] [Fintype E] : Fintype.card (Address V E A) = Fintype.card V * 2 ^ Fintype.card A + Fintype.card E * 2 ^ (Fintype.card A * Fintype.card A) := by simp [Address, Cube, Fintype.card_sum, Fintype.card_prod] theorem rejection_count_bound [Fintype E] (G : ConstraintGraph V E A) (assignment : Address V E A β†’ Bool) : Fintype.card (LocalEvent A) * G.rejectionCount (decodedLabeling assignment) ≀ 2048 * QueryIncidence.verifierRejectionCount (verifier G) assignment := by classical cases isEmpty_or_nonempty E with | inl empty => let := empty simp [ConstraintGraph.rejectionCount, ConstraintGraph.rejectedDarts] | inr inhabited => let := inhabited have h := average_gap G assignment rw [average_eq_count, expect_rejection_eq_count, card_event, Nat.cast_mul, div_div] at h have he : (0 : ℝ) < Fintype.card E := by exact_mod_cast Fintype.card_pos have hl : (0 : ℝ) < Fintype.card (LocalEvent A) := by exact_mod_cast Fintype.card_pos have hc := (div_le_div_iffβ‚€ (mul_pos he (by norm_num)) (mul_pos he hl)).mp h have hc' : ((Fintype.card (LocalEvent A) : ℝ) * (G.rejectionCount (decodedLabeling assignment) : ℝ)) * Fintype.card E ≀ (2048 * (QueryIncidence.verifierRejectionCount (verifier G) assignment : ℝ)) * Fintype.card E := by simpa only [ConstraintGraph.rejectionCount, ConstraintGraph.rejectedDarts, mul_assoc, mul_comm, mul_left_comm] using hc have result := (mul_le_mul_iff_leftβ‚€ he).mp hc' exact_mod_cast result def honestAssignment (G : ConstraintGraph V E A) (labeling : V β†’ A) : Address V E A β†’ Bool | .inl (v, tape) => tape (labeling v) | .inr (e, tape) => tape (labeling (G.tail e), labeling (G.head e)) omit [Fintype A] [DecidableEq A] [Nonempty A] in @[simp] theorem honest_vertexBlock (G : ConstraintGraph V E A) (labeling : V β†’ A) (v : V) : vertexBlock (honestAssignment G labeling) v = CodeComposition.codeword (labeling v) := rfl omit [Fintype A] [DecidableEq A] [Nonempty A] in theorem honest_edgeOracle (G : ConstraintGraph V E A) (labeling : V β†’ A) (e : E) (h : G.edgeSatisfied labeling e = true) : edgeOracle G (honestAssignment G labeling) e = fun tape => tape ⟨(labeling (G.tail e), labeling (G.head e)), h⟩ := by funext tape exact UniformRestriction.extend_apply_of_mem (legal G e) tape (labeling (G.tail e), labeling (G.head e)) h omit [Fintype A] [DecidableEq A] [Nonempty A] in theorem honest_event (G : ConstraintGraph V E A) (labeling : V β†’ A) (satisfied : βˆ€ e, G.edgeSatisfied labeling e = true) (event : Event E A) : (verifier G).accepts event (QueryIncidence.response (verifier G) (honestAssignment G labeling) event) = true := by rcases event with ⟨e, kind, k, f, g, rβ‚€, r₁, rβ‚‚βŸ© rw [response_eq_local, honest_edgeOracle G labeling e (satisfied e)] simp only [honest_vertexBlock] exact AssignmentTester.event_perfect_completeness (AlphabetReduction.pairEncoding (G.accepts e)) ⟨(labeling (G.tail e), labeling (G.head e)), satisfied e⟩ kind k (restrictTape G e f) (restrictTape G e g) (restrictTape G e rβ‚€) (restrictTape G e r₁) (restrictTape G e rβ‚‚) def graph [DecidableEq V] [DecidableEq E] (G : ConstraintGraph V E A) : ConstraintGraph (QueryIncidence.Vertex (Event E A) (Address V E A)) (QueryIncidence.Dart (Event E A) 6) (QueryIncidence.Label 6) := QueryIncidence.graph (verifier G) (by omega) omit [DecidableEq A] [Nonempty A] in theorem perfect_completeness [DecidableEq V] [DecidableEq E] (G : ConstraintGraph V E A) (satisfied : G.Satisfiable) : (graph G).Satisfiable := by obtain ⟨labeling, h⟩ := satisfied exact QueryIncidence.satisfiable_of_verifier_satisfiable (verifier G) (by omega) ⟨honestAssignment G labeling, honest_event G labeling h⟩ theorem gap_transfer [Fintype E] [DecidableEq V] [DecidableEq E] (G : ConstraintGraph V E A) (a b : Nat) (source : βˆ€ labeling : V β†’ A, a * Fintype.card E ≀ b * G.rejectionCount labeling) (labeling : QueryIncidence.Vertex (Event E A) (Address V E A) β†’ QueryIncidence.Label 6) : a * Fintype.card (QueryIncidence.Dart (Event E A) 6) ≀ (b * 12288) * (graph G).rejectionCount labeling := by have verifierGap (assignment : Address V E A β†’ Bool) : a * Fintype.card (Event E A) ≀ (b * 2048) * QueryIncidence.verifierRejectionCount (verifier G) assignment := by rw [card_event] calc a * (Fintype.card E * Fintype.card (LocalEvent A)) = Fintype.card (LocalEvent A) * (a * Fintype.card E) := by ac_rfl _ ≀ Fintype.card (LocalEvent A) * (b * G.rejectionCount (decodedLabeling assignment)) := Nat.mul_le_mul_left _ (source (decodedLabeling assignment)) _ = b * (Fintype.card (LocalEvent A) * G.rejectionCount (decodedLabeling assignment)) := by ac_rfl _ ≀ b * (2048 * QueryIncidence.verifierRejectionCount (verifier G) assignment) := Nat.mul_le_mul_left _ (rejection_count_bound G assignment) _ = (b * 2048) * QueryIncidence.verifierRejectionCount (verifier G) assignment := by ac_rfl have h := QueryIncidence.gap_transfer (verifier G) (by omega) a (b * 2048) verifierGap labeling have hcoef : b * 2048 * 6 = b * 12288 := by omega rw [hcoef] at h exact h theorem alphabet_card : Fintype.card (QueryIncidence.Label 6) = 64 := QueryIncidence.six_query_alphabet end BinPackingGames.Foundations.PCP.AlphabetGraph namespace BinPackingGames.Foundations.PCP.AlphabetTable.Queries open BinPackingGames.Foundations.Hastad abbrev RawQuery (q : Nat) := (Bool Γ— Cube (Fin q)) βŠ• Cube (Fin q Γ— Fin q) abbrev LocalEvent (q : Nat) := AlphabetGraph.LocalEvent (Fin q) def mask {q : Nat} (P : Fin q β†’ Fin q β†’ Bool) (f : Cube (Fin q Γ— Fin q)) : Cube (Fin q Γ— Fin q) := fun p => if P p.1 p.2 then f p else false def xorTape {A : Type*} (f g : Cube A) : Cube A := fun a => f a ^^ g a def andTape {A : Type*} (f g : Cube A) : Cube A := fun a => f a && g a def inputPairTape {q : Nat} (k : Bool Γ— Cube (Fin q)) : Cube (Fin q Γ— Fin q) := fun p => if k.1 then k.2 p.2 else k.2 p.1 def query {q : Nat} (P : Fin q β†’ Fin q β†’ Bool) (event : LocalEvent q) (slot : Fin 6) : RawQuery q := match event with | (kind, k, f, g, rβ‚€, r₁, rβ‚‚) => if kind = 0 then if slot = 0 then .inr (mask P f) else if slot = 1 then .inr (mask P g) else .inr (mask P (xorTape f g)) else if kind = 1 then if slot = 0 then .inr (mask P rβ‚€) else if slot = 1 then .inr (mask P (xorTape rβ‚€ (andTape f g))) else if slot = 2 then .inr (mask P r₁) else if slot = 3 then .inr (mask P (xorTape r₁ f)) else if slot = 4 then .inr (mask P rβ‚‚) else .inr (mask P (xorTape rβ‚‚ g)) else if kind = 2 then if slot = 0 then .inr (mask P rβ‚€) else .inr (mask P (xorTape rβ‚€ (fun _ => true))) else if slot = 0 then .inl k else if slot = 1 then .inr (mask P rβ‚€) else .inr (mask P (xorTape rβ‚€ (inputPairTape k))) def globalize {q : Nat} {V E : Type*} (tail head : V) (edge : E) : RawQuery q β†’ AlphabetGraph.Address V E (Fin q) | .inl (side, tape) => .inl ((if side then head else tail), tape) | .inr tape => .inr (edge, tape) @[simp] theorem mask_idempotent {q : Nat} (P : Fin q β†’ Fin q β†’ Bool) (f : Cube (Fin q Γ— Fin q)) : mask P (mask P f) = mask P f := by funext p cases hp : P p.1 p.2 <;> simp [mask, hp] theorem mask_of_empty {q : Nat} (P : Fin q β†’ Fin q β†’ Bool) (empty : βˆ€ a b, P a b = false) (f : Cube (Fin q Γ— Fin q)) : mask P f = fun _ => false := by funext p simp [mask, empty] theorem query_is_masked {q : Nat} (P : Fin q β†’ Fin q β†’ Bool) (event : LocalEvent q) (slot : Fin 6) : match query P event slot with | .inl _ => True | .inr tape => mask P tape = tape := by rcases event with ⟨kind, k, f, g, rβ‚€, r₁, rβ‚‚βŸ© by_cases hkβ‚€ : kind = 0 <;> by_cases hk₁ : kind = 1 <;> by_cases hkβ‚‚ : kind = 2 <;> simp only [query, hkβ‚€, hk₁, hkβ‚‚, ite_true, ite_false] <;> split_ifs <;> simp def extendQuery {q : Nat} (P : Fin q β†’ Fin q β†’ Bool) : AlphabetReduction.InputCoordinate (Fin q) βŠ• Cube (AlphabetReduction.LegalPair P) β†’ RawQuery q | .inl k => .inl k | .inr tape => .inr (UniformRestriction.extend (fun p : Fin q Γ— Fin q => P p.1 p.2 = true) tape) theorem query_eq_extend_eventQueries {q : Nat} (P : Fin q β†’ Fin q β†’ Bool) (kind : Fin 4) (k : AlphabetReduction.InputCoordinate (Fin q)) (f g rβ‚€ r₁ rβ‚‚ : Cube (Fin q Γ— Fin q)) (slot : Fin 6) : query P (kind, k, f, g, rβ‚€, r₁, rβ‚‚) slot = extendQuery P (AssignmentTester.eventQueries (AlphabetReduction.pairEncoding P) kind k (UniformRestriction.restrict (fun p : Fin q Γ— Fin q => P p.1 p.2 = true) f) (UniformRestriction.restrict (fun p : Fin q Γ— Fin q => P p.1 p.2 = true) g) (UniformRestriction.restrict (fun p : Fin q Γ— Fin q => P p.1 p.2 = true) rβ‚€) (UniformRestriction.restrict (fun p : Fin q Γ— Fin q => P p.1 p.2 = true) r₁) (UniformRestriction.restrict (fun p : Fin q Γ— Fin q => P p.1 p.2 = true) rβ‚‚) slot) := by by_cases hkβ‚€ : kind = 0 <;> by_cases hk₁ : kind = 1 <;> by_cases hkβ‚‚ : kind = 2 <;> simp only [query, AssignmentTester.eventQueries, hkβ‚€, hk₁, hkβ‚‚, ite_true, ite_false] all_goals split_ifs <;> simp_all only [extendQuery] all_goals rfl theorem globalize_extendQuery {q : Nat} {V E : Type*} (G : ConstraintGraph V E (Fin q)) (e : E) (x : AlphabetReduction.InputCoordinate (Fin q) βŠ• Cube (AlphabetReduction.LegalPair (G.accepts e))) : globalize (G.tail e) (G.head e) e (extendQuery (G.accepts e) x) = AlphabetGraph.globalizeQuery G e x := by cases x with | inl k => cases k; rfl | inr tape => rfl theorem globalize_query {q : Nat} {V E : Type*} (G : ConstraintGraph V E (Fin q)) (e : E) (event : LocalEvent q) (slot : Fin 6) : globalize (G.tail e) (G.head e) e (query (G.accepts e) event slot) = (AlphabetGraph.verifier G).query (e, event) slot := by rcases event with ⟨kind, k, f, g, rβ‚€, r₁, rβ‚‚βŸ© rw [query_eq_extend_eventQueries] exact globalize_extendQuery G e _ end BinPackingGames.Foundations.PCP.AlphabetTable.Queries end end OAI
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.BigOperators.Expect
import Mathlib.Data.Finset.Max
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.Fintype.Prod
import Mathlib.Basic.Real.Basic
import Mathlib.Logic.Equiv.Prod
import OAI.Computability.BinPacking.Information.GameDecoder
import OAI.Computability.BinPacking.PCP.AlphabetRetraction
namespace OAI
noncomputable section
namespace BinPackingGames.Foundations.PCP.UniformRestriction
open scoped BigOperators
variable {B : Type*} (p : B β†’ Prop)
def restrict (f : B β†’ Bool) : {b // p b} β†’ Bool := fun b => f b.1
variable [DecidablePred p]
def extend (g : {b // p b} β†’ Bool) : B β†’ Bool :=
fun b => if hb : p b then g ⟨b, hb⟩ else false
def canonicalize (f : B β†’ Bool) : B β†’ Bool := extend p (restrict p f)
omit [DecidablePred p] in
@[simp] theorem restrict_apply (f : B β†’ Bool) (b : {b // p b}) :
restrict p f b = f b.1 := rfl
@[simp] theorem extend_apply_of_mem (g : {b // p b} β†’ Bool) (b : B) (hb : p b) :
extend p g b = g ⟨b, hb⟩ := by
simp [extend, hb]
@[simp] theorem extend_apply_of_not_mem (g : {b // p b} β†’ Bool) (b : B)
(hb : Β¬ p b) : extend p g b = false := by
simp [extend, hb]
@[simp] theorem restrict_extend (g : {b // p b} β†’ Bool) :
restrict p (extend p g) = g := by
funext b
simp [restrict, extend, b.property]
@[simp] theorem canonicalize_apply_of_mem (f : B β†’ Bool) (b : B) (hb : p b) :
canonicalize p f b = f b := by
simp [canonicalize, hb]
@[simp] theorem canonicalize_apply_of_not_mem (f : B β†’ Bool) (b : B)
(hb : Β¬ p b) : canonicalize p f b = false := by
simp [canonicalize, hb]
@[simp] theorem restrict_canonicalize (f : B β†’ Bool) :
restrict p (canonicalize p f) = restrict p f := by
exact restrict_extend p (restrict p f)
@[simp] theorem canonicalize_idempotent (f : B β†’ Bool) :
canonicalize p (canonicalize p f) = canonicalize p f := by
simp only [canonicalize, restrict_extend]
theorem canonicalize_eq_iff (f g : B β†’ Bool) :
canonicalize p f = canonicalize p g ↔ restrict p f = restrict p g := by
constructor
Β· intro h
simpa only [restrict_canonicalize] using congrArg (restrict p) h
Β· intro h
exact congrArg (extend p) h
variable [Fintype B] [DecidableEq B]
theorem expect_restrict (h : ({b // p b} β†’ Bool) β†’ ℝ) :
(𝔼 f : B β†’ Bool, h (restrict p f)) = 𝔼 g : {b // p b} β†’ Bool, h g := by
calc
(𝔼 f : B β†’ Bool, h (restrict p f)) =
𝔼 g : ({b // p b} β†’ Bool) Γ— ({b // Β¬ p b} β†’ Bool), h g.1 :=
Fintype.expect_equiv (Equiv.piEquivPiSubtypeProd p (fun _ => Bool))
_ _ (fun _ => rfl)
_ = 𝔼 g : {b // p b} β†’ Bool, 𝔼 _k : {b // Β¬ p b} β†’ Bool, h g := by
simpa only [Finset.univ_product_univ] using
Finset.expect_product
(Finset.univ : Finset ({b // p b} β†’ Bool))
(Finset.univ : Finset ({b // Β¬ p b} β†’ Bool))
(fun g : ({b // p b} β†’ Bool) Γ— ({b // Β¬ p b} β†’ Bool) => h g.1)
_ = 𝔼 g : {b // p b} β†’ Bool, h g := by
simp only [Fintype.expect_const]
theorem expect_canonicalize (h : (B β†’ Bool) β†’ ℝ) :
(𝔼 f : B β†’ Bool, h (canonicalize p f)) =
𝔼 g : {b // p b} β†’ Bool, h (extend p g) :=
expect_restrict p (fun g => h (extend p g))
theorem expect_restrict_pair (h : ({b // p b} β†’ Bool) β†’ ({b // p b} β†’ Bool) β†’ ℝ) :
(𝔼 f : B β†’ Bool, 𝔼 g : B β†’ Bool, h (restrict p f) (restrict p g)) =
𝔼 f : {b // p b} β†’ Bool, 𝔼 g : {b // p b} β†’ Bool, h f g := by
calc
_ = 𝔼 f : B β†’ Bool, 𝔼 g : {b // p b} β†’ Bool, h (restrict p f) g := by