Download data/lean/OAI/Computability/DirectedFeedback/Encoding/PoweringAddresses.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 31.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DirectedFeedback/Encoding/PoweringAddresses.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/DirectedFeedback/Encoding/PoweringAddresses.lean
-
curl -L -o PoweringAddresses.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DirectedFeedback/Encoding/PoweringAddresses.lean
31.4 kB
| import Mathlib | |
| import OAI.Computability.DirectedFeedback.Games.Preprocessing | |
| namespace OAI | |
| namespace DFVSGames.Foundations.PCP.PoweringAddresses | |
| open PoweringWalks PoweringLabels | |
| open scoped BigOperators | |
| variable {V : Type*} | |
| def allWords (d : Nat) : (n : Nat) β List (Fin n β Fin d) | |
| | 0 => [Fin.elim0] | |
| | n + 1 => (List.finRange d).flatMap fun a => | |
| (allWords d n).map fun p => Fin.cases a p | |
| theorem mem_allWords (d : Nat) : | |
| β n (p : Fin n β Fin d), p β allWords d n := by | |
| intro n | |
| induction n with | |
| | zero => | |
| intro p | |
| simp only [allWords, List.mem_singleton] | |
| funext i | |
| exact Fin.elim0 i | |
| | succ n ih => | |
| intro p | |
| simp only [allWords, List.mem_flatMap, List.mem_map] | |
| refine β¨p 0, List.mem_finRange (p 0), (fun j => p j.succ), ih _, ?_β© | |
| funext j | |
| exact Fin.cases rfl (fun _ => rfl) j | |
| def allAddresses (d t : Nat) : List (PortWords (Fin d) t) := | |
| (List.finRange (t + 1)).flatMap fun n => | |
| (allWords d n.val).map fun p => Sigma.mk n p | |
| theorem mem_allAddresses (d t : Nat) (w : PortWords (Fin d) t) : | |
| w β allAddresses d t := by | |
| rcases w with β¨n, pβ© | |
| unfold allAddresses | |
| apply List.mem_flatMap.mpr | |
| refine β¨n, List.mem_finRange n, ?_β© | |
| exact List.mem_map.mpr β¨p, mem_allWords d n.val p, rflβ© | |
| theorem length_allWords (d : Nat) : | |
| β n, (allWords d n).length = d ^ n := by | |
| intro n | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| simp only [allWords, List.length_flatMap, List.length_map, ih, | |
| List.map_const', List.length_finRange, List.sum_replicate_nat] | |
| exact (Nat.mul_comm d (d ^ n)).trans (Nat.pow_succ d n).symm | |
| theorem length_allAddresses (d t : Nat) : | |
| (allAddresses d t).length = β n : Fin (t + 1), d ^ n.val := by | |
| unfold allAddresses | |
| simp only [List.length_flatMap, List.length_map, length_allWords] | |
| exact (Fin.sum_univ_def (fun n : Fin (t + 1) => d ^ n.val)).symm | |
| def finitePortSelector {d : Nat} [DecidableEq V] (G : PortGraph V (Fin d)) | |
| (t : Nat) (v : V) : AddressSelector G t v := | |
| listSelector G t v (allAddresses d t) (mem_allAddresses d t) | |
| end DFVSGames.Foundations.PCP.PoweringAddresses | |
| namespace DFVSGames.Foundations.PCP.PoweringEnumeration | |
| open PoweringLabels | |
| open scoped BigOperators | |
| def addressCount (d t : Nat) : Nat := β i : Fin (t + 1), d ^ i.val | |
| def reverseWordEquiv (d n : Nat) : (Fin n β Fin d) β (Fin n β Fin d) where | |
| toFun p i := p i.rev | |
| invFun p i := p i.rev | |
| left_inv p := by funext i; simp only [Fin.rev_rev] | |
| right_inv p := by funext i; simp only [Fin.rev_rev] | |
| def wordEquiv (d n : Nat) : (Fin n β Fin d) β Fin (d ^ n) := | |
| (reverseWordEquiv d n).trans finFunctionFinEquiv | |
| theorem wordEquiv_val (d n : Nat) (p : Fin n β Fin d) : | |
| (wordEquiv d n p).val = β i : Fin n, (p i.rev).val * d ^ i.val := rfl | |
| def addressEquiv (d t : Nat) : PortWords (Fin d) t β Fin (addressCount d t) := | |
| (Equiv.sigmaCongrRight (fun i : Fin (t + 1) => wordEquiv d i.val)).trans | |
| finSigmaFinEquiv | |
| theorem addressEquiv_val (d t : Nat) (w : PortWords (Fin d) t) : | |
| (addressEquiv d t w).val = | |
| (β i : Fin w.1.val, d ^ i.val) + (wordEquiv d w.1.val w.2).val := by | |
| change (finSigmaFinEquiv | |
| (β¨w.1, wordEquiv d w.1.val w.2β© : (i : Fin (t + 1)) Γ Fin (d ^ i.val))).val = _ | |
| rw [finSigmaFinEquiv_apply] | |
| rfl | |
| def paddedLabelEquiv (d t q : Nat) : | |
| PaddedLabel (Fin d) t (Fin q) β Fin (q ^ addressCount d t) := | |
| ((addressEquiv d t).arrowCongr (Equiv.refl (Fin q))).trans | |
| (wordEquiv q (addressCount d t)) | |
| theorem paddedLabelEquiv_val (d t q : Nat) (a : PaddedLabel (Fin d) t (Fin q)) : | |
| (paddedLabelEquiv d t q a).val = | |
| β i : Fin (addressCount d t), | |
| (a ((addressEquiv d t).symm i.rev)).val * q ^ i.val := rfl | |
| def orientationEquiv : Bool β Fin 2 := finTwoEquiv.symm | |
| @[simp] theorem orientationEquiv_false : orientationEquiv false = 0 := rfl | |
| @[simp] theorem orientationEquiv_true : orientationEquiv true = 1 := rfl | |
| def dartBlockEquiv (d n : Nat) : | |
| ((Fin (n + 1) β Fin d) Γ Bool) β Fin (2 * d ^ (n + 1)) := | |
| ((wordEquiv d (n + 1)).prodCongr orientationEquiv).trans | |
| (finProdFinEquiv.trans (finCongr (Nat.mul_comm (d ^ (n + 1)) 2))) | |
| theorem dartBlockEquiv_val (d n : Nat) (p : Fin (n + 1) β Fin d) (b : Bool) : | |
| (dartBlockEquiv d n (p, b)).val = | |
| 2 * (wordEquiv d (n + 1) p).val + (orientationEquiv b).val := by | |
| change (orientationEquiv b).val + 2 * (wordEquiv d (n + 1) p).val = _ | |
| exact Nat.add_comm _ _ | |
| def dartVertexEquiv (vertices d n : Nat) : | |
| (Bool Γ (Fin vertices Γ (Fin (n + 1) β Fin d))) β | |
| (Fin vertices Γ ((Fin (n + 1) β Fin d) Γ Bool)) where | |
| toFun x := (x.2.1, (x.2.2, x.1)) | |
| invFun x := (x.2.2, (x.1, x.2.1)) | |
| left_inv x := by rcases x with β¨b, v, pβ©; rfl | |
| right_inv x := by rcases x with β¨v, p, bβ©; rfl | |
| def dartEquiv (vertices d n : Nat) : | |
| (Bool Γ (Fin vertices Γ (Fin (n + 1) β Fin d))) β | |
| Fin (2 * vertices * d ^ (n + 1)) := | |
| (dartVertexEquiv vertices d n).trans | |
| (((Equiv.refl (Fin vertices)).prodCongr (dartBlockEquiv d n)).trans | |
| (finProdFinEquiv.trans | |
| (finCongr (show vertices * (2 * d ^ (n + 1)) = | |
| 2 * vertices * d ^ (n + 1) by ac_rfl)))) | |
| theorem dartEquiv_val (vertices d n : Nat) (b : Bool) (v : Fin vertices) | |
| (p : Fin (n + 1) β Fin d) : | |
| (dartEquiv vertices d n (b, (v, p))).val = | |
| (2 * d ^ (n + 1)) * v.val + | |
| 2 * (wordEquiv d (n + 1) p).val + (orientationEquiv b).val := by | |
| change (dartBlockEquiv d n (p, b)).val + (2 * d ^ (n + 1)) * v.val = _ | |
| rw [dartBlockEquiv_val] | |
| omega | |
| theorem dartEquiv_true_eq_false_add_one (vertices d n : Nat) (v : Fin vertices) | |
| (p : Fin (n + 1) β Fin d) : | |
| (dartEquiv vertices d n (true, (v, p))).val = | |
| (dartEquiv vertices d n (false, (v, p))).val + 1 := by | |
| rw [dartEquiv_val, dartEquiv_val, orientationEquiv_true, orientationEquiv_false] | |
| rfl | |
| def encodeWord (d n : Nat) : (Fin n β Fin d) β Fin (d ^ n) := wordEquiv d n | |
| def decodeWord (d n : Nat) : Fin (d ^ n) β (Fin n β Fin d) := (wordEquiv d n).symm | |
| @[simp] theorem decodeWord_encodeWord (d n : Nat) (p : Fin n β Fin d) : | |
| decodeWord d n (encodeWord d n p) = p := (wordEquiv d n).symm_apply_apply p | |
| @[simp] theorem encodeWord_decodeWord (d n : Nat) (i : Fin (d ^ n)) : | |
| encodeWord d n (decodeWord d n i) = i := (wordEquiv d n).apply_symm_apply i | |
| def encodeAddress (d t : Nat) : PortWords (Fin d) t β Fin (addressCount d t) := | |
| addressEquiv d t | |
| def decodeAddress (d t : Nat) : Fin (addressCount d t) β PortWords (Fin d) t := | |
| (addressEquiv d t).symm | |
| @[simp] theorem decodeAddress_encodeAddress (d t : Nat) (w : PortWords (Fin d) t) : | |
| decodeAddress d t (encodeAddress d t w) = w := (addressEquiv d t).symm_apply_apply w | |
| @[simp] theorem encodeAddress_decodeAddress (d t : Nat) (i : Fin (addressCount d t)) : | |
| encodeAddress d t (decodeAddress d t i) = i := (addressEquiv d t).apply_symm_apply i | |
| def encodeLabel (d t q : Nat) : | |
| PaddedLabel (Fin d) t (Fin q) β Fin (q ^ addressCount d t) := paddedLabelEquiv d t q | |
| def decodeLabel (d t q : Nat) : | |
| Fin (q ^ addressCount d t) β PaddedLabel (Fin d) t (Fin q) := | |
| (paddedLabelEquiv d t q).symm | |
| @[simp] theorem decodeLabel_encodeLabel (d t q : Nat) (a : PaddedLabel (Fin d) t (Fin q)) : | |
| decodeLabel d t q (encodeLabel d t q a) = a := (paddedLabelEquiv d t q).symm_apply_apply a | |
| @[simp] theorem encodeLabel_decodeLabel (d t q : Nat) (i : Fin (q ^ addressCount d t)) : | |
| encodeLabel d t q (decodeLabel d t q i) = i := (paddedLabelEquiv d t q).apply_symm_apply i | |
| @[simp] theorem decodeLabel_apply (d t q : Nat) (i : Fin (q ^ addressCount d t)) | |
| (w : PortWords (Fin d) t) : | |
| decodeLabel d t q i w = decodeWord q (addressCount d t) i (encodeAddress d t w) := rfl | |
| def encodeDart (vertices d n : Nat) : | |
| (Bool Γ (Fin vertices Γ (Fin (n + 1) β Fin d))) β | |
| Fin (2 * vertices * d ^ (n + 1)) := dartEquiv vertices d n | |
| def decodeDart (vertices d n : Nat) : | |
| Fin (2 * vertices * d ^ (n + 1)) β | |
| (Bool Γ (Fin vertices Γ (Fin (n + 1) β Fin d))) := (dartEquiv vertices d n).symm | |
| @[simp] theorem decodeDart_encodeDart (vertices d n : Nat) | |
| (e : Bool Γ (Fin vertices Γ (Fin (n + 1) β Fin d))) : | |
| decodeDart vertices d n (encodeDart vertices d n e) = e := | |
| (dartEquiv vertices d n).symm_apply_apply e | |
| @[simp] theorem encodeDart_decodeDart (vertices d n : Nat) | |
| (i : Fin (2 * vertices * d ^ (n + 1))) : | |
| encodeDart vertices d n (decodeDart vertices d n i) = i := | |
| (dartEquiv vertices d n).apply_symm_apply i | |
| theorem card_words (d n : Nat) : Nat.card (Fin n β Fin d) = d ^ n := by | |
| simpa only [Nat.card_fin] using Nat.card_congr (wordEquiv d n) | |
| theorem card_addresses (d t : Nat) : | |
| Nat.card (PortWords (Fin d) t) = addressCount d t := by | |
| simpa only [Nat.card_fin] using Nat.card_congr (addressEquiv d t) | |
| theorem card_labels (d t q : Nat) : | |
| Nat.card (PaddedLabel (Fin d) t (Fin q)) = q ^ addressCount d t := by | |
| simpa only [Nat.card_fin] using Nat.card_congr (paddedLabelEquiv d t q) | |
| theorem card_darts (vertices d n : Nat) : | |
| Nat.card (Bool Γ (Fin vertices Γ (Fin (n + 1) β Fin d))) = | |
| 2 * vertices * d ^ (n + 1) := by | |
| simpa only [Nat.card_fin] using Nat.card_congr (dartEquiv vertices d n) | |
| theorem length_allAddresses (d t : Nat) : | |
| (PoweringAddresses.allAddresses d t).length = addressCount d t := | |
| PoweringAddresses.length_allAddresses d t | |
| end DFVSGames.Foundations.PCP.PoweringEnumeration | |
| namespace DFVSGames.Foundations.PCP.PoweringDecoding | |
| open scoped BigOperators | |
| variable {Ξ© A : Type*} [Fintype Ξ©] [Nonempty Ξ©] [Fintype A] [Nonempty A] | |
| noncomputable def mass (opinion : Ξ© β A) (a : A) : β := by | |
| classical | |
| exact Finset.univ.expect (fun Ο => if opinion Ο = a then 1 else 0) | |
| omit [Nonempty A] in | |
| theorem mass_sum (opinion : Ξ© β A) : (β a, mass opinion a) = 1 := by | |
| classical | |
| calc | |
| (β a, mass opinion a) = | |
| (Finset.univ : Finset Ξ©).expect | |
| (fun Ο => β a : A, if opinion Ο = a then (1 : β) else 0) := | |
| (Finset.expect_sum_comm (Finset.univ : Finset Ξ©) (Finset.univ : Finset A) | |
| (fun Ο a => if opinion Ο = a then (1 : β) else 0)).symm | |
| _ = (Finset.univ : Finset Ξ©).expect (fun _ => (1 : β)) := by | |
| apply Finset.expect_congr rfl | |
| intro Ο _ | |
| simp | |
| _ = 1 := Finset.expect_const Finset.univ_nonempty 1 | |
| omit [Nonempty Ξ©] in | |
| theorem exists_mode (opinion : Ξ© β A) : | |
| β a : A, β b : A, mass opinion b β€ mass opinion a := by | |
| obtain β¨a, _, haβ© := Finset.exists_max_image (Finset.univ : Finset A) | |
| (mass opinion) Finset.univ_nonempty | |
| exact β¨a, fun b => ha b (Finset.mem_univ b)β© | |
| noncomputable def mode (opinion : Ξ© β A) : A := Classical.choose (exists_mode opinion) | |
| omit [Nonempty Ξ©] in | |
| theorem mode_max (opinion : Ξ© β A) (b : A) : | |
| mass opinion b β€ mass opinion (mode opinion) := | |
| Classical.choose_spec (exists_mode opinion) b | |
| theorem mode_mass_lower (opinion : Ξ© β A) : | |
| 1 / (Fintype.card A : β) β€ mass opinion (mode opinion) := by | |
| have hk : 0 < (Fintype.card A : β) := Nat.cast_pos.mpr Fintype.card_pos | |
| have hsum : (1 : β) β€ mass opinion (mode opinion) * (Fintype.card A : β) := by | |
| calc | |
| (1 : β) = β a : A, mass opinion a := (mass_sum opinion).symm | |
| _ β€ β _a : A, mass opinion (mode opinion) := | |
| Finset.sum_le_sum (fun a _ => mode_max opinion a) | |
| _ = mass opinion (mode opinion) * (Fintype.card A : β) := by simp [mul_comm] | |
| exact (div_le_iffβ hk).2 hsum | |
| theorem exists_letter_mass_lower (opinion : Ξ© β A) : | |
| β a : A, 1 / (Fintype.card A : β) β€ mass opinion a := | |
| β¨mode opinion, mode_mass_lower opinionβ© | |
| end DFVSGames.Foundations.PCP.PoweringDecoding | |
| noncomputable section | |
| namespace DFVSGames.Foundations.PCP.PoweringMoment | |
| open scoped BigOperators | |
| def bit (p : Prop) : β := by | |
| classical | |
| exact if p then 1 else 0 | |
| def hits {I Ξ© : Type*} [Fintype I] (E : I β Ξ© β Prop) (Ο : Ξ©) : β := | |
| β i, bit (E i Ο) | |
| def mean {Ξ© : Type*} [Fintype Ξ©] (f : Ξ© β β) : β := Finset.univ.expect f | |
| theorem bit_nonneg (p : Prop) : 0 β€ bit p := by | |
| classical | |
| by_cases hp : p <;> simp [bit, hp] | |
| theorem bit_sq (p : Prop) : bit p ^ 2 = bit p := by | |
| classical | |
| by_cases hp : p <;> simp [bit, hp] | |
| theorem bit_mul (p q : Prop) : bit p * bit q = bit (p β§ q) := by | |
| classical | |
| by_cases hp : p <;> by_cases hq : q <;> simp [bit, hp, hq] | |
| theorem bit_mono {p q : Prop} (hpq : p β q) : bit p β€ bit q := by | |
| classical | |
| by_cases hp : p | |
| Β· simp [bit, hp, hpq hp] | |
| Β· have hz : bit p = 0 := by simp [bit, hp] | |
| rw [hz] | |
| exact bit_nonneg q | |
| theorem hits_nonneg {I Ξ© : Type*} [Fintype I] (E : I β Ξ© β Prop) (Ο : Ξ©) : | |
| 0 β€ hits E Ο := Finset.sum_nonneg (fun i _ => bit_nonneg (E i Ο)) | |
| theorem mean_nonneg {Ξ© : Type*} [Fintype Ξ©] (f : Ξ© β β) (hf : β Ο, 0 β€ f Ο) : | |
| 0 β€ mean f := Finset.expect_nonneg (fun Ο _ => hf Ο) | |
| theorem mean_hits {I Ξ© : Type*} [Fintype I] [Fintype Ξ©] (E : I β Ξ© β Prop) : | |
| mean (hits E) = β i, mean (fun Ο => bit (E i Ο)) := by | |
| exact Finset.expect_sum_comm _ _ _ | |
| theorem second_moment_eq {I Ξ© : Type*} [Fintype I] [Fintype Ξ©] | |
| (E : I β Ξ© β Prop) : | |
| mean (fun Ο => hits E Ο ^ 2) = | |
| β i, β j, mean (fun Ο => bit (E i Ο β§ E j Ο)) := by | |
| simp only [hits, pow_two, Finset.sum_mul, Finset.mul_sum, bit_mul, | |
| mean, Finset.expect_sum_comm] | |
| exact Finset.sum_comm | |
| theorem mean_witness_sq_le {I Ξ© : Type*} [Fintype I] [Fintype Ξ©] | |
| (E W : I β Ξ© β Prop) (reject : Ξ© β Prop) | |
| (hWE : β i Ο, W i Ο β E i Ο) | |
| (hWR : β i Ο, W i Ο β reject Ο) : | |
| mean (hits W) ^ 2 β€ | |
| mean (fun Ο => bit (reject Ο)) * mean (fun Ο => hits E Ο ^ 2) := by | |
| classical | |
| have hNH (Ο : Ξ©) : hits W Ο β€ hits E Ο := | |
| Finset.sum_le_sum (fun i _ => bit_mono (hWE i Ο)) | |
| have hzero (Ο : Ξ©) (hr : Β¬ reject Ο) : hits W Ο = 0 := by | |
| apply Finset.sum_eq_zero | |
| intro i _ | |
| have hw : Β¬ W i Ο := fun h => hr (hWR i Ο h) | |
| simp [bit, hw] | |
| have hsupport (Ο : Ξ©) : bit (reject Ο) * hits W Ο = hits W Ο := by | |
| by_cases hr : reject Ο | |
| Β· simp [bit, hr] | |
| Β· rw [hzero Ο hr] | |
| simp | |
| have hCS := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ | |
| (fun Ο => bit (reject Ο)) (hits W) | |
| have hsquares : mean (fun Ο => hits W Ο ^ 2) β€ mean (fun Ο => hits E Ο ^ 2) := by | |
| apply Finset.expect_le_expect | |
| intro Ο _ | |
| simpa only [pow_two] using | |
| (mul_le_mul (hNH Ο) (hNH Ο) (hits_nonneg W Ο) (hits_nonneg E Ο)) | |
| calc | |
| _ β€ mean (fun Ο => bit (reject Ο)) * mean (fun Ο => hits W Ο ^ 2) := by | |
| simpa only [mean, hsupport, bit_sq] using hCS | |
| _ β€ _ := mul_le_mul_of_nonneg_left hsquares | |
| (mean_nonneg _ (fun Ο => bit_nonneg (reject Ο))) | |
| theorem rejection_lower_bound {I Ξ© : Type*} [Fintype I] [Fintype Ξ©] | |
| (E W : I β Ξ© β Prop) (reject : Ξ© β Prop) | |
| (hWE : β i Ο, W i Ο β E i Ο) | |
| (hWR : β i Ο, W i Ο β reject Ο) | |
| (a b : β) (ha : 0 < a) (hb : 0 < b) | |
| (hfirst : a β€ mean (hits W)) | |
| (hsecond : mean (fun Ο => hits E Ο ^ 2) β€ b) : | |
| a ^ 2 / b β€ mean (fun Ο => bit (reject Ο)) := by | |
| have hN : 0 β€ mean (hits W) := mean_nonneg _ (hits_nonneg W) | |
| have hΟ : 0 β€ mean (fun Ο => bit (reject Ο)) := | |
| mean_nonneg _ (fun Ο => bit_nonneg (reject Ο)) | |
| have haSq : a ^ 2 β€ mean (hits W) ^ 2 := by | |
| simpa only [pow_two] using mul_le_mul hfirst hfirst ha.le hN | |
| have hCS := mean_witness_sq_le E W reject hWE hWR | |
| apply (div_le_iffβ hb).2 | |
| exact haSq.trans (hCS.trans (mul_le_mul_of_nonneg_left hsecond hΟ)) | |
| end DFVSGames.Foundations.PCP.PoweringMoment | |
| end | |
| namespace DFVSGames.Foundations.PCP.PoweringReturn | |
| open PoweringWalks SpectralReturn | |
| open PoweringMoment (bit) | |
| variable {V D : Type*} | |
| def portConsEquiv (D : Type*) (n : Nat) : | |
| (D Γ (Fin n β D)) β (Fin (n + 1) β D) where | |
| toFun z := Fin.cases z.1 z.2 | |
| invFun r := (r 0, fun j => r j.succ) | |
| left_inv z := by | |
| apply Prod.ext | |
| Β· rfl | |
| Β· funext j | |
| rfl | |
| right_inv r := by | |
| funext j | |
| exact Fin.cases rfl (fun _ => rfl) j | |
| theorem mean_word_cons_head [Fintype D] (n : Nat) | |
| (F : (Fin (n + 1) β D) β β) : | |
| mean F = mean (fun d : D => mean (fun r : Fin n β D => F (Fin.cases d r))) := by | |
| calc | |
| mean F = mean (fun z : D Γ (Fin n β D) => F (Fin.cases z.1 z.2)) := | |
| (mean_equiv (portConsEquiv D n) F).symm | |
| _ = _ := mean_prod _ | |
| theorem mean_word_cons_tail [Fintype D] (n : Nat) | |
| (F : (Fin (n + 1) β D) β β) : | |
| mean F = mean (fun r : Fin n β D => mean (fun d : D => F (Fin.cases d r))) := by | |
| calc | |
| mean F = mean (fun z : (Fin n β D) Γ D => F (Fin.cases z.2 z.1)) := | |
| (mean_equiv ((Equiv.prodComm (Fin n β D) D).trans (portConsEquiv D n)) F).symm | |
| _ = _ := mean_prod _ | |
| theorem iterateOperator_succ_right [Fintype D] (G : PortGraph V D) | |
| (n : Nat) (f : V β β) : | |
| iterateOperator G n (averagingOperator G f) = iterateOperator G (n + 1) f := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => exact congrArg (averagingOperator G) ih | |
| theorem mean_wordEnd [Fintype D] [Nonempty D] (G : PortGraph V D) : | |
| β (n : Nat) (v : V) (f : V β β), | |
| mean (fun r : Fin n β D => f (wordEnd G n v r)) = iterateOperator G n f v := by | |
| intro n | |
| induction n with | |
| | zero => | |
| intro v f | |
| change mean (fun _ : Fin 0 β D => f v) = f v | |
| exact mean_const _ | |
| | succ n ih => | |
| intro v f | |
| rw [mean_word_cons_head] | |
| change mean (fun d : D => mean (fun r : Fin n β D => | |
| f (wordEnd G n (next G v d) r))) = _ | |
| calc | |
| _ = mean (fun d : D => iterateOperator G n f (next G v d)) := by | |
| congr 1 | |
| funext d | |
| exact ih (next G v d) f | |
| _ = iterateOperator G (n + 1) f v := rfl | |
| theorem mean_pivot_endpoints [Fintype D] [Nonempty D] (G : PortGraph V D) : | |
| β (n : Nat) (k : Fin (n + 1)) (e : Edge V D) (Ο Ο : V β β), | |
| mean (fun r : Fin n β D => | |
| Ο (leftFromPivot G n k e.1 r) * Ο (rightFromPivot G n k e r)) = | |
| iterateOperator G k.val Ο e.1 * | |
| iterateOperator G (n - k.val) Ο (next G e.1 e.2) := by | |
| intro n | |
| induction n with | |
| | zero => | |
| intro k e Ο Ο | |
| have hk : k = 0 := Fin.eq_zero k | |
| subst k | |
| change mean (fun _ : Fin 0 β D => Ο e.1 * Ο (next G e.1 e.2)) = | |
| Ο e.1 * Ο (next G e.1 e.2) | |
| exact mean_const _ | |
| | succ n ih => | |
| intro k e Ο Ο | |
| refine Fin.cases ?_ (fun j => ?_) k | |
| Β· change mean (fun r : Fin (n + 1) β D => | |
| Ο e.1 * Ο (wordEnd G (n + 1) (next G e.1 e.2) r)) = | |
| Ο e.1 * iterateOperator G (n + 1) Ο (next G e.1 e.2) | |
| rw [mean_mul_left, mean_wordEnd] | |
| Β· simp only [Fin.val_succ, Nat.add_sub_add_right] | |
| rw [mean_word_cons_tail] | |
| change mean (fun r : Fin n β D => mean (fun d : D => | |
| Ο (next G (leftFromPivot G n j e.1 r) d) * | |
| Ο (rightFromPivot G n j e r))) = | |
| iterateOperator G (j.val + 1) Ο e.1 * | |
| iterateOperator G (n - j.val) Ο (next G e.1 e.2) | |
| calc | |
| _ = mean (fun r : Fin n β D => | |
| averagingOperator G Ο (leftFromPivot G n j e.1 r) * | |
| Ο (rightFromPivot G n j e r)) := by | |
| congr 1 | |
| funext r | |
| rw [mean_mul_right] | |
| rfl | |
| _ = iterateOperator G j.val (averagingOperator G Ο) e.1 * | |
| iterateOperator G (n - j.val) Ο (next G e.1 e.2) := | |
| ih j e (averagingOperator G Ο) Ο | |
| _ = _ := by rw [iterateOperator_succ_right] | |
| theorem mean_edge_endpoints [Fintype V] [Fintype D] [Nonempty D] | |
| (G : PortGraph V D) (n : Nat) (k : Fin (n + 1)) (Ο Ο : Edge V D β V β β) : | |
| mean (fun w : Walk V D (n + 1) => | |
| Ο (edgeAt G n w k) w.1 * Ο (edgeAt G n w k) (endpoint G w)) = | |
| mean (fun e : Edge V D => | |
| iterateOperator G k.val (Ο e) e.1 * | |
| iterateOperator G (n - k.val) (Ο e) (next G e.1 e.2)) := by | |
| let F : Edge V D Γ (Fin n β D) β β := fun z => | |
| Ο z.1 (leftFromPivot G n k z.1.1 z.2) * | |
| Ο z.1 (rightFromPivot G n k z.1 z.2) | |
| calc | |
| _ = mean (fun w => F (pivotEquiv G n k w)) := by | |
| congr 1 | |
| funext w | |
| dsimp [F] | |
| rw [leftFromPivot_actual, rightFromPivot_actual, pivotEquiv_fst] | |
| _ = mean F := mean_equiv (pivotEquiv G n k) F | |
| _ = mean (fun e : Edge V D => mean (fun r : Fin n β D => | |
| Ο e (leftFromPivot G n k e.1 r) * Ο e (rightFromPivot G n k e r))) := mean_prod F | |
| _ = _ := by | |
| congr 1 | |
| funext e | |
| exact mean_pivot_endpoints G n k e (Ο e) (Ο e) | |
| theorem bit_bool (b : Bool) : bit (b = true) = (if b then 1 else 0 : β) := by | |
| cases b <;> simp [bit] | |
| theorem mean_edge_bit [Fintype D] (bad : V Γ D β Bool) (v : V) : | |
| mean (fun d : D => bit (bad (v, d) = true)) = edgeProfile bad v := by | |
| simp only [bit_bool, mean, edgeProfile] | |
| theorem mean_marked_bit [Fintype D] (G : PortGraph V D) | |
| (bad : V Γ D β Bool) (f : V β β) (v : V) : | |
| mean (fun d : D => bit (bad (v, d) = true) * f (next G v d)) = | |
| markedStep G bad f v := by | |
| change mean (fun d : D => bit (bad (v, d) = true) * f (next G v d)) = | |
| mean (fun d : D => if bad (v, d) then f (next G v d) else 0) | |
| congr 1 | |
| funext d | |
| cases bad (v, d) <;> simp [bit] | |
| theorem edgeAt_zero (G : PortGraph V D) (n : Nat) (w : Walk V D (n + 1)) : | |
| edgeAt G n w 0 = (w.1, w.2 0) := by | |
| cases n <;> rfl | |
| theorem word_first_hit_mean [Fintype D] [Nonempty D] | |
| (G : PortGraph V D) (bad : V Γ D β Bool) (n : Nat) (v : V) : | |
| mean (fun p : Fin (n + 1) β D => bit (bad (edgeAt G n (v, p) 0) = true)) = | |
| edgeProfile bad v := by | |
| rw [mean_word_cons_head] | |
| simp_rw [edgeAt_zero] | |
| change mean (fun d : D => mean (fun _ : Fin n β D => bit (bad (v, d) = true))) = _ | |
| calc | |
| _ = mean (fun d : D => bit (bad (v, d) = true)) := by simp only [mean_const] | |
| _ = edgeProfile bad v := mean_edge_bit bad v | |
| theorem word_hit_mean [Fintype D] [Nonempty D] | |
| (G : PortGraph V D) (bad : V Γ D β Bool) : | |
| β (n : Nat) (v : V) (k : Fin (n + 1)), | |
| mean (fun p : Fin (n + 1) β D => bit (bad (edgeAt G n (v, p) k) = true)) = | |
| iterateOperator G k.val (edgeProfile bad) v := by | |
| intro n | |
| induction n with | |
| | zero => | |
| intro v k | |
| have hk : k = 0 := Fin.eq_zero k | |
| subst k | |
| exact word_first_hit_mean G bad 0 v | |
| | succ n ih => | |
| intro v k | |
| refine Fin.cases ?_ (fun j => ?_) k | |
| Β· exact word_first_hit_mean G bad (n + 1) v | |
| Β· rw [mean_word_cons_head] | |
| change mean (fun d : D => mean (fun p : Fin (n + 1) β D => | |
| bit (bad (edgeAt G n (next G v d, p) j) = true))) = | |
| averagingOperator G (iterateOperator G j.val (edgeProfile bad)) v | |
| calc | |
| _ = mean (fun d : D => iterateOperator G j.val (edgeProfile bad) (next G v d)) := by | |
| congr 1 | |
| funext d | |
| exact ih (next G v d) j | |
| _ = _ := rfl | |
| theorem word_pair_hit_mean [Fintype D] [Nonempty D] | |
| (G : PortGraph V D) (bad : V Γ D β Bool) : | |
| β (n : Nat) (v : V) (i j : Fin (n + 1)), i < j β | |
| mean (fun p : Fin (n + 1) β D => | |
| bit (bad (edgeAt G n (v, p) i) = true) * | |
| bit (bad (edgeAt G n (v, p) j) = true)) = | |
| iterateOperator G i.val (markedStep G bad | |
| (iterateOperator G (j.val - i.val - 1) (edgeProfile bad))) v := by | |
| intro n | |
| induction n with | |
| | zero => | |
| intro v i j hij | |
| have hi : i = 0 := Fin.eq_zero i | |
| have hj : j = 0 := Fin.eq_zero j | |
| subst i | |
| subst j | |
| exact ((lt_irrefl _) hij).elim | |
| | succ n ih => | |
| intro v i | |
| refine Fin.cases ?_ (fun a => ?_) i | |
| Β· intro j | |
| refine Fin.cases ?_ (fun b => ?_) j | |
| Β· intro hij | |
| exact ((lt_irrefl _) hij).elim | |
| Β· intro _hij | |
| simp only [Fin.val_zero, Fin.val_succ, Nat.sub_zero, Nat.add_sub_cancel] | |
| rw [mean_word_cons_head] | |
| change mean (fun d : D => mean (fun p : Fin (n + 1) β D => | |
| bit (bad (v, d) = true) * bit (bad (edgeAt G n (next G v d, p) b) = true))) = | |
| markedStep G bad (iterateOperator G b.val (edgeProfile bad)) v | |
| calc | |
| _ = mean (fun d : D => bit (bad (v, d) = true) * | |
| iterateOperator G b.val (edgeProfile bad) (next G v d)) := by | |
| congr 1 | |
| funext d | |
| rw [mean_mul_left, word_hit_mean] | |
| _ = _ := mean_marked_bit G bad _ v | |
| Β· intro j | |
| refine Fin.cases ?_ (fun b => ?_) j | |
| Β· intro hij | |
| exact (Nat.not_lt_zero _ hij).elim | |
| Β· intro hij | |
| have hab : a < b := Nat.lt_of_succ_lt_succ hij | |
| simp only [Fin.val_succ, Nat.add_sub_add_right] | |
| rw [mean_word_cons_head] | |
| change mean (fun d : D => mean (fun p : Fin (n + 1) β D => | |
| bit (bad (edgeAt G n (next G v d, p) a) = true) * | |
| bit (bad (edgeAt G n (next G v d, p) b) = true))) = | |
| averagingOperator G (iterateOperator G a.val (markedStep G bad | |
| (iterateOperator G (b.val - a.val - 1) (edgeProfile bad)))) v | |
| calc | |
| _ = mean (fun d : D => iterateOperator G a.val (markedStep G bad | |
| (iterateOperator G (b.val - a.val - 1) (edgeProfile bad))) (next G v d)) := by | |
| congr 1 | |
| funext d | |
| exact ih (next G v d) a b hab | |
| _ = _ := rfl | |
| theorem hit_mean [Fintype V] [Fintype D] [Nonempty V] [Nonempty D] | |
| (G : PortGraph V D) (bad : V Γ D β Bool) (n : Nat) (k : Fin (n + 1)) : | |
| mean (fun w : Walk V D (n + 1) => bit (bad (edgeAt G n w k) = true)) = | |
| edgeDensity bad := by | |
| calc | |
| _ = mean (fun v : V => mean (fun p : Fin (n + 1) β D => | |
| bit (bad (edgeAt G n (v, p) k) = true))) := | |
| mean_prod (A := V) (B := Fin (n + 1) β D) | |
| (fun w => bit (bad (edgeAt G n w k) = true)) | |
| _ = mean (iterateOperator G k.val (edgeProfile bad)) := by | |
| congr 1 | |
| funext v | |
| exact word_hit_mean G bad n v k | |
| _ = mean (edgeProfile bad) := mean_iterate G k.val _ | |
| _ = _ := rfl | |
| theorem pair_hit_mean [Fintype V] [Fintype D] [Nonempty V] [Nonempty D] | |
| (G : PortGraph V D) (bad : V Γ D β Bool) (n : Nat) | |
| (i j : Fin (n + 1)) (hij : i < j) : | |
| mean (fun w : Walk V D (n + 1) => bit (bad (edgeAt G n w i) = true) * | |
| bit (bad (edgeAt G n w j) = true)) = returnMass G bad (j.val - i.val - 1) := by | |
| calc | |
| _ = mean (fun v : V => mean (fun p : Fin (n + 1) β D => | |
| bit (bad (edgeAt G n (v, p) i) = true) * | |
| bit (bad (edgeAt G n (v, p) j) = true))) := | |
| mean_prod (A := V) (B := Fin (n + 1) β D) | |
| (fun w => bit (bad (edgeAt G n w i) = true) * | |
| bit (bad (edgeAt G n w j) = true)) | |
| _ = mean (iterateOperator G i.val (markedStep G bad | |
| (iterateOperator G (j.val - i.val - 1) (edgeProfile bad)))) := by | |
| congr 1 | |
| funext v | |
| exact word_pair_hit_mean G bad n v i j hij | |
| _ = mean (markedStep G bad | |
| (iterateOperator G (j.val - i.val - 1) (edgeProfile bad))) := mean_iterate G i.val _ | |
| _ = _ := rfl | |
| theorem pair_event_mean [Fintype V] [Fintype D] [Nonempty V] [Nonempty D] | |
| (G : PortGraph V D) (bad : V Γ D β Bool) (n : Nat) | |
| (i j : Fin (n + 1)) (hij : i < j) : | |
| mean (fun w : Walk V D (n + 1) => | |
| bit (bad (edgeAt G n w i) = true β§ bad (edgeAt G n w j) = true)) = | |
| returnMass G bad (j.val - i.val - 1) := by | |
| simpa only [PoweringMoment.bit_mul] using pair_hit_mean G bad n i j hij | |
| end DFVSGames.Foundations.PCP.PoweringReturn | |
| noncomputable section | |
| namespace DFVSGames.Foundations.PCP.PoweringOpinions | |
| open PoweringWalks PoweringLabels SpectralReturn | |
| open PoweringMoment (bit) | |
| variable {V D A : Type*} | |
| def opinionAt (G : PortGraph V D) (t : Nat) | |
| (selectors : β v, AddressSelector G t v) (labels : V β PaddedLabel D t A) | |
| (fallback : A) (u v : V) : A := by | |
| classical | |
| exact if h : β n, n β€ t β§ β p : Fin n β D, wordEnd G n v p = u then | |
| decode (selectors v) (labels v) β¨u, hβ© else fallback | |
| theorem opinionAt_eq_decode (G : PortGraph V D) (t : Nat) | |
| (selectors : β v, AddressSelector G t v) (labels : V β PaddedLabel D t A) | |
| (fallback : A) (v : V) (u : Ball G t v) : | |
| opinionAt G t selectors labels fallback u.val v = decode (selectors v) (labels v) u := by | |
| classical | |
| simp [opinionAt, u.property] | |
| rfl | |
| def honestLabels (G : PortGraph V D) (t : Nat) (assignment : V β A) : | |
| V β PaddedLabel D t A := fun v => encode G t v (fun u => assignment u.val) | |
| theorem opinionAt_honest (G : PortGraph V D) (t : Nat) | |
| (selectors : β v, AddressSelector G t v) (assignment : V β A) | |
| (fallback : A) (v : V) (u : Ball G t v) : | |
| opinionAt G t selectors (honestLabels G t assignment) fallback u.val v = | |
| assignment u.val := by | |
| rw [opinionAt_eq_decode] | |
| exact congrFun (decode_encode (selectors v) (fun u => assignment u.val)) u | |
| variable [Fintype D] [Nonempty D] [Fintype A] [Nonempty A] | |
| def sampleOpinion (G : PortGraph V D) (t N : Nat) | |
| (selectors : β v, AddressSelector G t v) (labels : V β PaddedLabel D t A) | |
| (fallback : A) (u : V) (p : Fin N β D) : A := | |
| opinionAt G t selectors labels fallback u (wordEnd G N u p) | |
| def decoded (G : PortGraph V D) (t N : Nat) | |
| (selectors : β v, AddressSelector G t v) (labels : V β PaddedLabel D t A) | |
| (fallback : A) (u : V) : A := | |
| PoweringDecoding.mode (sampleOpinion G t N selectors labels fallback u) | |
| def matchFn (G : PortGraph V D) (t N : Nat) | |
| (selectors : β v, AddressSelector G t v) (labels : V β PaddedLabel D t A) | |
| (fallback : A) (u v : V) : β := | |
| bit (opinionAt G t selectors labels fallback u v = decoded G t N selectors labels fallback u) | |
| omit [Nonempty D] in | |
| theorem matchFn_mem_Icc (G : PortGraph V D) (t N : Nat) | |
| (selectors : β v, AddressSelector G t v) (labels : V β PaddedLabel D t A) | |
| (fallback : A) (u v : V) : | |
| matchFn G t N selectors labels fallback u v β Set.Icc (0 : β) 1 := by | |
| classical | |
| constructor | |
| Β· exact PoweringMoment.bit_nonneg _ | |
| Β· unfold matchFn bit | |
| split <;> simp | |
| theorem decoded_modal_baseline (G : PortGraph V D) (t N : Nat) | |
| (selectors : β v, AddressSelector G t v) (labels : V β PaddedLabel D t A) | |
| (fallback : A) (u : V) : | |
| 1 / (Fintype.card A : β) β€ | |
| iterateOperator G N (matchFn G t N selectors labels fallback u) u := by | |
| have h := PoweringDecoding.mode_mass_lower (sampleOpinion G t N selectors labels fallback u) | |
| change 1 / (Fintype.card A : β) β€ mean (fun p : Fin N β D => | |
| matchFn G t N selectors labels fallback u (wordEnd G N u p)) at h | |
| rwa [PoweringReturn.mean_wordEnd] at h | |
| theorem decoded_modal_near (G : PortGraph V D) (t M m : Nat) | |
| (selectors : β v, AddressSelector (lazyGraph G) t v) | |
| (labels : V β PaddedLabel (Bool Γ D) t A) (fallback : A) | |
| (hM : 1 β€ M) | |
| (hlo : (4 * Fintype.card A * M) ^ 2 - M β€ m) | |
| (hhi : m β€ (4 * Fintype.card A * M) ^ 2 + M) (u : V) : | |
| 1 / (2 * (Fintype.card A : β)) β€ | |
| iterateOperator (lazyGraph G) m | |
| (matchFn (lazyGraph G) t ((4 * Fintype.card A * M) ^ 2) | |
| selectors labels fallback u) u := by | |
| exact PoweringLazy.lazy_endpoint_modal_transfer G (Fintype.card A) M m | |
| Fintype.card_pos hM hlo hhi _ | |
| (matchFn_mem_Icc (lazyGraph G) t ((4 * Fintype.card A * M) ^ 2) | |
| selectors labels fallback u) u | |
| (decoded_modal_baseline (lazyGraph G) t ((4 * Fintype.card A * M) ^ 2) | |
| selectors labels fallback u) | |
| end DFVSGames.Foundations.PCP.PoweringOpinions | |
| end | |
| end OAI | |