Download lean/OAI/Computability/DirectedFeedback/Encoding/PoweringTables.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 36.7 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/DirectedFeedback/Encoding/PoweringTables.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/DirectedFeedback/Encoding/PoweringTables.lean
-
curl -L -o PoweringTables.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/DirectedFeedback/Encoding/PoweringTables.lean
36.7 kB
| import Mathlib | |
| import OAI.Computability.DirectedFeedback.Games.PoweringReach | |
| namespace OAI | |
| namespace DFVSGames.Foundations.PCP.PoweringTables | |
| open PoweringWalks PoweringLabels PoweringAddresses PoweringEnumeration | |
| def labelCount (d n : Nat) : Nat := 64 ^ addressCount d (n + 1) | |
| def dartCount (vertices d n : Nat) : Nat := 2 * vertices * d ^ (n + 1) | |
| def mathematicalGraph {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) : | |
| ConstraintGraph (Fin vertices) (PoweringTest.Dart (Fin vertices) (Fin d) n) | |
| (PaddedLabel (Fin d) (n + 1) (Fin 64)) := | |
| PoweringTest.poweredGraph (PortTables.portGraph input) (PortTables.accepts input) n | |
| (finitePortSelector (PortTables.portGraph input) (n + 1)) | |
| def rowAccepts {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) | |
| (e : PoweringTest.Dart (Fin vertices) (Fin d) n) | |
| (a b : Fin (labelCount d n)) : Bool := | |
| let rows := PoweringOpinionTables.walkRows (PortTables.portGraph input) n e.2 | |
| let left := PoweringOpinionTables.labelTable (decodeLabel d (n + 1) 64 a) | |
| let right := PoweringOpinionTables.labelTable (decodeLabel d (n + 1) 64 b) | |
| if e.1 then PoweringOpinionTables.rowsAccepts (PortTables.accepts input) rows right left | |
| else PoweringOpinionTables.rowsAccepts (PortTables.accepts input) rows left right | |
| theorem rowAccepts_eq {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) | |
| (e : PoweringTest.Dart (Fin vertices) (Fin d) n) | |
| (a b : Fin (labelCount d n)) : | |
| rowAccepts input n e a b = (mathematicalGraph input n).accepts e | |
| (decodeLabel d (n + 1) 64 a) (decodeLabel d (n + 1) 64 b) := by | |
| rcases e with ⟨direction, w⟩ | |
| cases direction <;> | |
| simp only [rowAccepts, mathematicalGraph, PoweringTest.poweredGraph, Bool.false_eq_true, | |
| ite_false, ite_true, PoweringOpinionTables.rowsAccepts_walkRows] | |
| def table {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) : | |
| GenericGraphTables.Table (labelCount d n) := | |
| GenericGraphTables.ofEnumeratedGraph (mathematicalGraph input n) (Equiv.refl _) | |
| (dartEquiv vertices d n) (paddedLabelEquiv d (n + 1) 64) | |
| @[simp] theorem table_vertices {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) : (table input n).vertices = vertices := rfl | |
| @[simp] theorem table_darts {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) : (table input n).darts = dartCount vertices d n := rfl | |
| theorem semantics_table {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) : | |
| GenericGraphTables.semantics (table input n) = | |
| GenericGraphTables.enumeratedGraph (mathematicalGraph input n) (Equiv.refl _) | |
| (dartEquiv vertices d n) (paddedLabelEquiv d (n + 1) 64) := | |
| GenericGraphTables.semantics_ofGraph _ | |
| theorem table_accepts {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) | |
| (i : Fin (dartCount vertices d n)) (a b : Fin (labelCount d n)) : | |
| GenericGraphTables.acceptsAt (table input n).rows i a b = | |
| rowAccepts input n (decodeDart vertices d n i) a b := by | |
| change (GenericGraphTables.semantics (table input n)).accepts i a b = _ | |
| rw [semantics_table] | |
| exact (rowAccepts_eq input n (decodeDart vertices d n i) a b).symm | |
| theorem table_reverse {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) | |
| (direction : Bool) (w : Walk (Fin vertices) (Fin d) (n + 1)) : | |
| GenericGraphTables.reverseAt (table input n).rows (encodeDart vertices d n (direction, w)) = | |
| encodeDart vertices d n (!direction, w) := by | |
| change (GenericGraphTables.semantics (table input n)).reverse _ = _ | |
| rw [semantics_table] | |
| change dartEquiv vertices d n ((mathematicalGraph input n).reverse | |
| ((dartEquiv vertices d n).symm (dartEquiv vertices d n (direction, w)))) = | |
| dartEquiv vertices d n (!direction, w) | |
| rw [(dartEquiv vertices d n).symm_apply_apply] | |
| rfl | |
| def outputBits {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) : List Bool := | |
| GenericGraphTables.tableBits (table input n) | |
| def transform (d n : Nat) (input : PortTables.Input d) : GenericGraphTables.Table (labelCount d n) := | |
| table input.2 n | |
| end DFVSGames.Foundations.PCP.PoweringTables | |
| namespace DFVSGames.Foundations.PCP.PoweringCounting | |
| open PoweringWalks PoweringLabels PoweringTest | |
| open scoped BigOperators | |
| variable {V D A E : Type*} | |
| theorem constraint_rejection_mean_eq_count [Fintype E] | |
| (H : ConstraintGraph V E A) (labels : V → A) : | |
| SpectralReturn.mean (fun e : E => PoweringMoment.bit | |
| (H.edgeSatisfied labels e = false)) = | |
| (H.rejectionCount labels : ℝ) / (Fintype.card E : ℝ) := by | |
| classical | |
| rw [SpectralReturn.mean_eq_sum_div_card] | |
| simp only [PoweringMoment.bit, ConstraintGraph.rejectionCount, ConstraintGraph.rejectedDarts] | |
| apply congrArg (fun x : ℝ => x / (Fintype.card E : ℝ)) | |
| convert (Finset.sum_boole (R := ℝ) | |
| (fun e => H.edgeSatisfied labels e = false) Finset.univ) using 1 ; try rfl | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| by_cases h : H.edgeSatisfied labels e = false <;> simp [h] | |
| theorem constraint_rejection_lower_iff [Fintype E] | |
| (H : ConstraintGraph V E A) (labels : V → A) | |
| (hcard : 0 < Fintype.card E) (ε : ℝ) : | |
| ε ≤ SpectralReturn.mean (fun e : E => PoweringMoment.bit | |
| (H.edgeSatisfied labels e = false)) ↔ | |
| ε * (Fintype.card E : ℝ) ≤ (H.rejectionCount labels : ℝ) := by | |
| rw [constraint_rejection_mean_eq_count] | |
| exact le_div_iff₀ (Nat.cast_pos.mpr hcard) | |
| theorem edgeDensity_eq_bit_mean [Fintype V] [Fintype D] | |
| (bad : Edge V D → Bool) : | |
| SpectralReturn.edgeDensity bad = | |
| SpectralReturn.mean (fun e : Edge V D => PoweringMoment.bit (bad e = true)) := by | |
| convert (SpectralReturn.mean_prod | |
| (fun e : Edge V D => PoweringMoment.bit (bad e = true))).symm using 1 ; try rfl | |
| change SpectralReturn.mean (fun v => SpectralReturn.mean | |
| (fun d => if bad (v, d) then (1 : ℝ) else 0)) = _ | |
| apply congrArg SpectralReturn.mean | |
| funext v | |
| apply congrArg SpectralReturn.mean | |
| funext d | |
| cases h : bad (v, d) <;> simp [PoweringMoment.bit] | |
| theorem base_edgeDensity_eq_rejection_count [Fintype V] [Fintype D] | |
| (G : PortGraph V D) (accepts : Edge V D → A → A → Bool) | |
| (reverse_accepts : ∀ e a b, accepts (G.rot e) b a = accepts e a b) | |
| (assignment : V → A) : | |
| SpectralReturn.edgeDensity (decodedBad G accepts assignment) = | |
| ((baseGraph G accepts reverse_accepts).rejectionCount assignment : ℝ) / | |
| (Fintype.card (Edge V D) : ℝ) := by | |
| calc | |
| _ = SpectralReturn.mean (fun e : Edge V D => PoweringMoment.bit | |
| (decodedBad G accepts assignment e = true)) := edgeDensity_eq_bit_mean _ | |
| _ = SpectralReturn.mean (fun e : Edge V D => PoweringMoment.bit | |
| ((baseGraph G accepts reverse_accepts).edgeSatisfied assignment e = false)) := by | |
| apply congrArg SpectralReturn.mean | |
| funext e | |
| exact congrArg PoweringMoment.bit | |
| (propext (decodedBad_eq_true_iff G accepts assignment e)) | |
| _ = _ := constraint_rejection_mean_eq_count _ _ | |
| theorem base_count_lower_to_density [Fintype V] [Fintype D] | |
| (G : PortGraph V D) (accepts : Edge V D → A → A → Bool) | |
| (reverse_accepts : ∀ e a b, accepts (G.rot e) b a = accepts e a b) | |
| (assignment : V → A) (hcard : 0 < Fintype.card (Edge V D)) (ε : ℝ) | |
| (hcount : ε * (Fintype.card (Edge V D) : ℝ) ≤ | |
| ((baseGraph G accepts reverse_accepts).rejectionCount assignment : ℝ)) : | |
| ε ≤ SpectralReturn.edgeDensity (decodedBad G accepts assignment) := by | |
| rw [base_edgeDensity_eq_rejection_count G accepts reverse_accepts assignment] | |
| exact (le_div_iff₀ (Nat.cast_pos.mpr hcard)).2 hcount | |
| theorem powered_rejection_mean_eq_count [Fintype V] [Fintype D] | |
| (G : PortGraph V D) (accepts : Edge V D → A → A → Bool) (n : Nat) | |
| (selectors : ∀ v, AddressSelector G (n + 1) v) | |
| (labels : V → PaddedLabel D (n + 1) A) : | |
| SpectralReturn.mean (fun d : Dart V D n => PoweringMoment.bit | |
| ((poweredGraph G accepts n selectors).edgeSatisfied labels d = false)) = | |
| ((poweredGraph G accepts n selectors).rejectionCount labels : ℝ) / | |
| (Fintype.card (Dart V D n) : ℝ) := | |
| constraint_rejection_mean_eq_count _ _ | |
| theorem path_rejection_mean_eq_count [Fintype V] [Fintype D] | |
| (G : PortGraph V D) (accepts : Edge V D → A → A → Bool) (n : Nat) | |
| (selectors : ∀ v, AddressSelector G (n + 1) v) | |
| (labels : V → PaddedLabel D (n + 1) A) : | |
| SpectralReturn.mean (fun w : Walk V D (n + 1) => PoweringMoment.bit | |
| (pathAccepts G accepts n selectors w (labels w.1) (labels (endpoint G w)) = false)) = | |
| ((poweredGraph G accepts n selectors).rejectionCount labels : ℝ) / | |
| (Fintype.card (Dart V D n) : ℝ) := by | |
| rw [← rejection_mean_eq_path_mean G accepts n selectors labels] | |
| exact powered_rejection_mean_eq_count G accepts n selectors labels | |
| theorem powered_density_lower_to_count [Fintype V] [Fintype D] | |
| (G : PortGraph V D) (accepts : Edge V D → A → A → Bool) (n : Nat) | |
| (selectors : ∀ v, AddressSelector G (n + 1) v) | |
| (labels : V → PaddedLabel D (n + 1) A) | |
| (hcard : 0 < Fintype.card (Dart V D n)) (ε : ℝ) | |
| (hlower : ε ≤ SpectralReturn.mean (fun w : Walk V D (n + 1) => PoweringMoment.bit | |
| (pathAccepts G accepts n selectors w (labels w.1) (labels (endpoint G w)) = false))) : | |
| ε * (Fintype.card (Dart V D n) : ℝ) ≤ | |
| ((poweredGraph G accepts n selectors).rejectionCount labels : ℝ) := by | |
| rw [path_rejection_mean_eq_count G accepts n selectors labels] at hlower | |
| exact (le_div_iff₀ (Nat.cast_pos.mpr hcard)).1 hlower | |
| theorem natCard_dart [Finite V] [Finite D] (n : Nat) : | |
| Nat.card (Dart V D n) = 2 * Nat.card V * Nat.card D ^ (n + 1) := by | |
| simp [Dart, Walk, Nat.card_prod, Nat.card_fun, Nat.mul_assoc] | |
| theorem fintypeCard_dart [Fintype V] [Fintype D] (n : Nat) : | |
| Fintype.card (Dart V D n) = | |
| 2 * Fintype.card V * Fintype.card D ^ (n + 1) := by | |
| simpa only [Nat.card_eq_fintype_card] using (natCard_dart (V := V) (D := D) n) | |
| theorem natCard_poweredAlphabet [Finite D] [Finite A] (n : Nat) : | |
| Nat.card (PaddedLabel D (n + 1) A) = | |
| Nat.card A ^ (∑ j : Fin (n + 2), Nat.card D ^ j.val) := | |
| PoweringLabels.card_paddedLabel (n + 1) | |
| theorem natCard_finitePortAlphabet [Finite A] (d n : Nat) : | |
| Nat.card (PaddedLabel (Fin d) (n + 1) A) = | |
| Nat.card A ^ (PoweringAddresses.allAddresses d (n + 1)).length := by | |
| rw [PoweringLabels.card_paddedLabel, PoweringAddresses.length_allAddresses] | |
| simp only [Nat.card_fin] | |
| end DFVSGames.Foundations.PCP.PoweringCounting | |
| namespace DFVSGames.Foundations.PCP.PoweringTableSemantics | |
| open PoweringWalks PoweringLabels PoweringAddresses PoweringEnumeration PoweringTables | |
| abbrev RawLabeling (vertices d n : Nat) := | |
| Fin vertices → PaddedLabel (Fin d) (n + 1) (Fin 64) | |
| abbrev EncodedLabeling (vertices d n : Nat) := | |
| Fin vertices → Fin (labelCount d n) | |
| def encodeLabeling {vertices : Nat} (d n : Nat) (labels : RawLabeling vertices d n) : | |
| EncodedLabeling vertices d n := | |
| fun v => encodeLabel d (n + 1) 64 (labels v) | |
| def decodeLabeling {vertices : Nat} (d n : Nat) (labels : EncodedLabeling vertices d n) : | |
| RawLabeling vertices d n := | |
| fun v => decodeLabel d (n + 1) 64 (labels v) | |
| @[simp] theorem decodeLabeling_encodeLabeling {vertices : Nat} (d n : Nat) | |
| (labels : RawLabeling vertices d n) : | |
| decodeLabeling d n (encodeLabeling d n labels) = labels := by | |
| funext v | |
| exact decodeLabel_encodeLabel d (n + 1) 64 (labels v) | |
| @[simp] theorem encodeLabeling_decodeLabeling {vertices : Nat} (d n : Nat) | |
| (labels : EncodedLabeling vertices d n) : | |
| encodeLabeling d n (decodeLabeling d n labels) = labels := by | |
| funext v | |
| exact encodeLabel_decodeLabel d (n + 1) 64 (labels v) | |
| theorem edgeSatisfied_encoded {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) (labels : RawLabeling vertices d n) | |
| (e : PoweringTest.Dart (Fin vertices) (Fin d) n) : | |
| (GenericGraphTables.semantics (table input n)).edgeSatisfied | |
| (encodeLabeling (vertices := vertices) d n labels) (encodeDart vertices d n e) = | |
| (mathematicalGraph input n).edgeSatisfied labels e := by | |
| rw [semantics_table] | |
| unfold encodeLabeling encodeLabel encodeDart | |
| exact GenericGraphTables.enumeratedGraph_edgeSatisfied (mathematicalGraph input n) | |
| (Equiv.refl _) (dartEquiv vertices d n) (paddedLabelEquiv d (n + 1) 64) labels e | |
| theorem edgeSatisfied_decoded {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) (labels : EncodedLabeling vertices d n) (i : Fin (dartCount vertices d n)) : | |
| (GenericGraphTables.semantics (table input n)).edgeSatisfied labels i = | |
| (mathematicalGraph input n).edgeSatisfied (decodeLabeling d n labels) | |
| (decodeDart vertices d n i) := by | |
| simpa only [encodeLabeling_decodeLabeling d n labels, | |
| encodeDart_decodeDart vertices d n i] using | |
| edgeSatisfied_encoded input n (decodeLabeling d n labels) (decodeDart vertices d n i) | |
| theorem edgeSatisfied_eq_path {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) (labels : EncodedLabeling vertices d n) (direction : Bool) | |
| (w : Walk (Fin vertices) (Fin d) (n + 1)) : | |
| (GenericGraphTables.semantics (table input n)).edgeSatisfied labels | |
| (encodeDart vertices d n (direction, w)) = | |
| PoweringTest.pathAccepts (PortTables.portGraph input) (PortTables.accepts input) n | |
| (finitePortSelector (PortTables.portGraph input) (n + 1)) w | |
| (decodeLabeling d n labels w.1) | |
| (decodeLabeling d n labels (endpoint (PortTables.portGraph input) w)) := by | |
| rw [edgeSatisfied_decoded input n labels (encodeDart vertices d n (direction, w)), | |
| decodeDart_encodeDart vertices d n (direction, w)] | |
| exact PoweringTest.poweredGraph_edgeSatisfied (PortTables.portGraph input) | |
| (PortTables.accepts input) n (finitePortSelector (PortTables.portGraph input) (n + 1)) | |
| (decodeLabeling d n labels) direction w | |
| theorem rejectionCount_encoded {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) (labels : RawLabeling vertices d n) : | |
| (GenericGraphTables.semantics (table input n)).rejectionCount | |
| (encodeLabeling (vertices := vertices) d n labels) = | |
| (mathematicalGraph input n).rejectionCount labels := by | |
| rw [semantics_table] | |
| unfold encodeLabeling encodeLabel | |
| exact GenericGraphTables.enumeratedGraph_rejectionCount (mathematicalGraph input n) | |
| (Equiv.refl _) (dartEquiv vertices d n) (paddedLabelEquiv d (n + 1) 64) labels | |
| theorem rejectionCount_decoded {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) (labels : EncodedLabeling vertices d n) : | |
| (GenericGraphTables.semantics (table input n)).rejectionCount labels = | |
| (mathematicalGraph input n).rejectionCount (decodeLabeling d n labels) := by | |
| simpa only [encodeLabeling_decodeLabeling d n labels] using | |
| rejectionCount_encoded input n (decodeLabeling d n labels) | |
| theorem card_darts_eq_table {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) : | |
| Fintype.card (PoweringTest.Dart (Fin vertices) (Fin d) n) = (table input n).darts := by | |
| change Fintype.card (PoweringTest.Dart (Fin vertices) (Fin d) n) = | |
| 2 * vertices * d ^ (n + 1) | |
| simpa only [Fintype.card_fin] using Fintype.card_congr (dartEquiv vertices d n) | |
| theorem satisfiable_iff {vertices d : Nat} (input : PortTables.Table vertices d) (n : Nat) : | |
| (GenericGraphTables.semantics (table input n)).Satisfiable ↔ | |
| (mathematicalGraph input n).Satisfiable := by | |
| constructor | |
| · rintro ⟨labels, satisfies⟩ | |
| refine ⟨decodeLabeling d n labels, ?_⟩ | |
| intro e | |
| have h := edgeSatisfied_encoded input n (decodeLabeling d n labels) e | |
| rw [encodeLabeling_decodeLabeling (vertices := vertices) d n labels] at h | |
| exact h.symm.trans (satisfies (encodeDart vertices d n e)) | |
| · rintro ⟨labels, satisfies⟩ | |
| refine ⟨encodeLabeling d n labels, ?_⟩ | |
| intro i | |
| have h := edgeSatisfied_encoded input n labels (decodeDart vertices d n i) | |
| rw [encodeDart_decodeDart vertices d n i] at h | |
| exact h.trans (satisfies (decodeDart vertices d n i)) | |
| theorem preserves_satisfiability {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) (h : (PortTables.baseGraph input).Satisfiable) : | |
| (GenericGraphTables.semantics (table input n)).Satisfiable := by | |
| apply (satisfiable_iff input n).mpr | |
| exact PoweringTest.preserves_satisfiability (PortTables.portGraph input) | |
| (PortTables.accepts input) (PortTables.accepts_rotation input) n | |
| (finitePortSelector (PortTables.portGraph input) (n + 1)) h | |
| theorem path_rejection_mean_eq_table_fraction {vertices d : Nat} | |
| (input : PortTables.Table vertices d) (n : Nat) (labels : EncodedLabeling vertices d n) : | |
| SpectralReturn.mean (fun w : Walk (Fin vertices) (Fin d) (n + 1) => | |
| PoweringMoment.bit | |
| (PoweringTest.pathAccepts (PortTables.portGraph input) (PortTables.accepts input) n | |
| (finitePortSelector (PortTables.portGraph input) (n + 1)) w | |
| (decodeLabeling d n labels w.1) | |
| (decodeLabeling d n labels (endpoint (PortTables.portGraph input) w)) = false)) = | |
| ((GenericGraphTables.semantics (table input n)).rejectionCount labels : ℝ) / | |
| ((table input n).darts : ℝ) := by | |
| rw [rejectionCount_decoded input n labels, ← card_darts_eq_table input n] | |
| exact PoweringCounting.path_rejection_mean_eq_count (PortTables.portGraph input) | |
| (PortTables.accepts input) n (finitePortSelector (PortTables.portGraph input) (n + 1)) | |
| (decodeLabeling d n labels) | |
| theorem uniform_count_gap_iff {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) (epsilon : ℝ) : | |
| (∀ labels : EncodedLabeling vertices d n, | |
| epsilon * ((table input n).darts : ℝ) ≤ | |
| ((GenericGraphTables.semantics (table input n)).rejectionCount labels : ℝ)) ↔ | |
| (∀ labels : RawLabeling vertices d n, | |
| epsilon * (Fintype.card (PoweringTest.Dart (Fin vertices) (Fin d) n) : ℝ) ≤ | |
| ((mathematicalGraph input n).rejectionCount labels : ℝ)) := by | |
| constructor | |
| · intro h labels | |
| have hlabels := h (encodeLabeling d n labels) | |
| rw [rejectionCount_encoded input n labels, ← card_darts_eq_table input n] at hlabels | |
| exact hlabels | |
| · intro h labels | |
| rw [rejectionCount_decoded input n labels] | |
| have hlabels := h (decodeLabeling d n labels) | |
| rw [card_darts_eq_table input n] at hlabels | |
| exact hlabels | |
| theorem uniform_count_gap {vertices d : Nat} (input : PortTables.Table vertices d) | |
| (n : Nat) (epsilon : ℝ) | |
| (hgap : ∀ labels : RawLabeling vertices d n, | |
| epsilon * (Fintype.card (PoweringTest.Dart (Fin vertices) (Fin d) n) : ℝ) ≤ | |
| ((mathematicalGraph input n).rejectionCount labels : ℝ)) : | |
| ∀ labels : EncodedLabeling vertices d n, | |
| epsilon * ((table input n).darts : ℝ) ≤ | |
| ((GenericGraphTables.semantics (table input n)).rejectionCount labels : ℝ) := | |
| (uniform_count_gap_iff input n epsilon).mpr hgap | |
| end DFVSGames.Foundations.PCP.PoweringTableSemantics | |
| namespace DFVSGames.Foundations.PCP.QueryIncidence | |
| structure Verifier (E X : Type*) (q : Nat) where | |
| query : E → Fin q → X | |
| accepts : E → (Fin q → Bool) → Bool | |
| abbrev Label (q : Nat) := Fin q → Bool | |
| abbrev Vertex (E X : Type*) := E ⊕ X | |
| abbrev Dart (E : Type*) (q : Nat) := (E × Fin q) × Bool | |
| variable {E X : Type*} {q : Nat} | |
| def response (T : Verifier E X q) (assignment : X → Bool) (event : E) : Label q := | |
| fun i => assignment (T.query event i) | |
| def zeroSlot (positive : 0 < q) : Fin q := ⟨0, positive⟩ | |
| def decodeRight (positive : 0 < q) (label : Label q) : Bool := label (zeroSlot positive) | |
| def encodeRight (bit : Bool) : Label q := fun _ => bit | |
| @[simp] theorem decode_encodeRight (positive : 0 < q) (bit : Bool) : | |
| decodeRight positive (encodeRight bit) = bit := rfl | |
| def canonicalSlot [DecidableEq X] (T : Verifier E X q) (event : E) (i : Fin q) : Fin q := | |
| Fin.find (fun j => T.query event j = T.query event i) ⟨i, rfl⟩ | |
| theorem canonicalSlot_query [DecidableEq X] (T : Verifier E X q) (event : E) (i : Fin q) : | |
| T.query event (canonicalSlot T event i) = T.query event i := | |
| Fin.find_spec (p := fun j => T.query event j = T.query event i) ⟨i, rfl⟩ | |
| def RepeatedConsistent (T : Verifier E X q) (event : E) (label : Label q) : Prop := | |
| ∀ i j, T.query event i = T.query event j → label i = label j | |
| instance repeatedConsistentDecidable [DecidableEq X] | |
| (T : Verifier E X q) (event : E) (label : Label q) : | |
| Decidable (RepeatedConsistent T event label) := by | |
| unfold RepeatedConsistent | |
| infer_instance | |
| def LeftValid (T : Verifier E X q) (event : E) (label : Label q) : Prop := | |
| T.accepts event label = true ∧ RepeatedConsistent T event label | |
| instance leftValidDecidable [DecidableEq X] | |
| (T : Verifier E X q) (event : E) (label : Label q) : | |
| Decidable (LeftValid T event label) := by | |
| unfold LeftValid | |
| infer_instance | |
| def incidenceAccept [DecidableEq X] (T : Verifier E X q) (positive : 0 < q) | |
| (event : E) (slot : Fin q) (left right : Label q) : Bool := | |
| decide (LeftValid T event left) && | |
| decide (left (canonicalSlot T event slot) = decodeRight positive right) | |
| def reverse : Dart E q → Dart E q := fun d => (d.1, !d.2) | |
| theorem reverse_involutive : Function.Involutive (reverse : Dart E q → Dart E q) := by | |
| rintro ⟨⟨event, slot⟩, orientation⟩ | |
| cases orientation <;> rfl | |
| def reverseEquiv : Dart E q ≃ Dart E q where | |
| toFun := reverse | |
| invFun := reverse | |
| left_inv := reverse_involutive | |
| right_inv := reverse_involutive | |
| def tail (T : Verifier E X q) : Dart E q → Vertex E X | |
| | ((event, _), false) => .inl event | |
| | ((event, slot), true) => .inr (T.query event slot) | |
| def predicate [DecidableEq X] (T : Verifier E X q) (positive : 0 < q) : | |
| Dart E q → Label q → Label q → Bool | |
| | ((event, slot), false), a, b => incidenceAccept T positive event slot a b | |
| | ((event, slot), true), a, b => incidenceAccept T positive event slot b a | |
| def graph [DecidableEq X] (T : Verifier E X q) (positive : 0 < q) : | |
| ConstraintGraph (Vertex E X) (Dart E q) (Label q) where | |
| reverse := reverseEquiv | |
| reverse_involutive := reverse_involutive | |
| tail := tail T | |
| accepts := predicate T positive | |
| reverse_accepts := by | |
| rintro ⟨⟨event, slot⟩, orientation⟩ a b | |
| cases orientation <;> rfl | |
| theorem edgeSatisfied_eq_incidence [DecidableEq X] (T : Verifier E X q) | |
| (positive : 0 < q) (labeling : Vertex E X → Label q) | |
| (event : E) (slot : Fin q) (orientation : Bool) : | |
| (graph T positive).edgeSatisfied labeling ((event, slot), orientation) = | |
| incidenceAccept T positive event slot (labeling (.inl event)) | |
| (labeling (.inr (T.query event slot))) := by | |
| cases orientation <;> rfl | |
| def honestLabeling (T : Verifier E X q) (assignment : X → Bool) : Vertex E X → Label q | |
| | .inl event => response T assignment event | |
| | .inr address => encodeRight (assignment address) | |
| theorem honest_leftValid (T : Verifier E X q) (assignment : X → Bool) (event : E) | |
| (accepted : T.accepts event (response T assignment event) = true) : | |
| LeftValid T event (response T assignment event) := by | |
| refine ⟨accepted, ?_⟩ | |
| intro i j hij | |
| exact congrArg assignment hij | |
| theorem honest_incidence [DecidableEq X] (T : Verifier E X q) (positive : 0 < q) | |
| (assignment : X → Bool) (event : E) | |
| (accepted : T.accepts event (response T assignment event) = true) (slot : Fin q) : | |
| incidenceAccept T positive event slot | |
| (honestLabeling T assignment (.inl event)) | |
| (honestLabeling T assignment (.inr (T.query event slot))) = true := by | |
| simp only [incidenceAccept, Bool.and_eq_true, honestLabeling, | |
| decode_encodeRight] | |
| refine ⟨_root_.decide_eq_true (honest_leftValid T assignment event accepted), ?_⟩ | |
| exact _root_.decide_eq_true (congrArg assignment (canonicalSlot_query T event slot)) | |
| theorem perfect_completeness [DecidableEq X] (T : Verifier E X q) (positive : 0 < q) | |
| (assignment : X → Bool) | |
| (accepted : ∀ event, T.accepts event (response T assignment event) = true) : | |
| ∀ dart, (graph T positive).edgeSatisfied (honestLabeling T assignment) dart = true := by | |
| rintro ⟨⟨event, slot⟩, orientation⟩ | |
| rw [edgeSatisfied_eq_incidence] | |
| exact honest_incidence T positive assignment event (accepted event) slot | |
| theorem satisfiable_of_verifier_satisfiable [DecidableEq X] (T : Verifier E X q) | |
| (positive : 0 < q) | |
| (sat : ∃ assignment : X → Bool, | |
| ∀ event, T.accepts event (response T assignment event) = true) : | |
| (graph T positive).Satisfiable := by | |
| obtain ⟨assignment, h⟩ := sat | |
| exact ⟨honestLabeling T assignment, perfect_completeness T positive assignment h⟩ | |
| def decodedAssignment (positive : 0 < q) (labeling : Vertex E X → Label q) : X → Bool := | |
| fun address => decodeRight positive (labeling (.inr address)) | |
| theorem incidenceAccept_true [DecidableEq X] (T : Verifier E X q) (positive : 0 < q) | |
| (event : E) (slot : Fin q) (left right : Label q) | |
| (accepted : incidenceAccept T positive event slot left right = true) : | |
| T.accepts event left = true ∧ RepeatedConsistent T event left ∧ | |
| left (canonicalSlot T event slot) = decodeRight positive right := by | |
| simp only [incidenceAccept, Bool.and_eq_true] at accepted | |
| have hvalid : LeftValid T event left := _root_.of_decide_eq_true accepted.1 | |
| exact ⟨hvalid.1, hvalid.2, _root_.of_decide_eq_true accepted.2⟩ | |
| theorem all_incidences_imply_event [DecidableEq X] (T : Verifier E X q) | |
| (positive : 0 < q) (labeling : Vertex E X → Label q) (event : E) | |
| (accepted : ∀ slot, incidenceAccept T positive event slot (labeling (.inl event)) | |
| (labeling (.inr (T.query event slot))) = true) : | |
| T.accepts event (response T (decodedAssignment positive labeling) event) = true := by | |
| have first := incidenceAccept_true T positive event (zeroSlot positive) _ _ | |
| (accepted (zeroSlot positive)) | |
| have labels_equal : labeling (.inl event) = response T (decodedAssignment positive labeling) event := by | |
| funext slot | |
| have info := incidenceAccept_true T positive event slot _ _ (accepted slot) | |
| exact (first.2.1 slot (canonicalSlot T event slot) | |
| (canonicalSlot_query T event slot).symm).trans info.2.2 | |
| rw [← labels_equal] | |
| exact first.1 | |
| theorem rejected_event_forces_slot [DecidableEq X] (T : Verifier E X q) | |
| (positive : 0 < q) (labeling : Vertex E X → Label q) (event : E) | |
| (rejected : T.accepts event (response T (decodedAssignment positive labeling) event) = false) : | |
| ∃ slot, incidenceAccept T positive event slot (labeling (.inl event)) | |
| (labeling (.inr (T.query event slot))) = false := by | |
| classical | |
| by_contra none | |
| have all : ∀ slot, incidenceAccept T positive event slot (labeling (.inl event)) | |
| (labeling (.inr (T.query event slot))) = true := by | |
| intro slot | |
| cases h : incidenceAccept T positive event slot (labeling (.inl event)) | |
| (labeling (.inr (T.query event slot))) with | |
| | false => exact False.elim (none ⟨slot, h⟩) | |
| | true => rfl | |
| have h := all_incidences_imply_event T positive labeling event all | |
| rw [rejected] at h | |
| cases h | |
| def rejectedEvents [Fintype E] (T : Verifier E X q) (assignment : X → Bool) : Finset E := | |
| Finset.univ.filter (fun event => T.accepts event (response T assignment event) = false) | |
| def verifierRejectionCount [Fintype E] (T : Verifier E X q) (assignment : X → Bool) : Nat := | |
| (rejectedEvents T assignment).card | |
| theorem rejection_count_bound [Fintype E] [DecidableEq X] | |
| (T : Verifier E X q) (positive : 0 < q) (labeling : Vertex E X → Label q) : | |
| 2 * verifierRejectionCount T (decodedAssignment positive labeling) ≤ | |
| (graph T positive).rejectionCount labeling := by | |
| classical | |
| let failed := rejectedEvents T (decodedAssignment positive labeling) | |
| have witnesses : ∀ event, event ∈ failed → | |
| ∃ slot, incidenceAccept T positive event slot (labeling (.inl event)) | |
| (labeling (.inr (T.query event slot))) = false := by | |
| intro event he | |
| apply rejected_event_forces_slot T positive labeling event | |
| simpa [failed, rejectedEvents] using he | |
| let chosen := fun event he => Classical.choose (witnesses event he) | |
| let inject : (failed.product (Finset.univ : Finset Bool)) → | |
| (graph T positive).rejectedDarts labeling := fun p => | |
| ⟨((p.val.1, chosen p.val.1 (Finset.mem_product.mp p.property).1), p.val.2), by | |
| apply (ConstraintGraph.mem_rejectedDarts _ _ _).mpr | |
| rw [edgeSatisfied_eq_incidence] | |
| exact Classical.choose_spec (witnesses p.val.1 (Finset.mem_product.mp p.property).1)⟩ | |
| have injective : Function.Injective inject := by | |
| intro a b h | |
| apply Subtype.ext | |
| apply Prod.ext | |
| · exact congrArg (fun d => d.val.1.1) h | |
| · exact congrArg (fun d => d.val.2) h | |
| have bound := Finset.card_le_card_of_injective injective | |
| simpa [failed, verifierRejectionCount, ConstraintGraph.rejectionCount, | |
| Finset.card_product, Nat.mul_comm] using bound | |
| @[simp] theorem card_label (q : Nat) : Fintype.card (Label q) = 2 ^ q := by | |
| simp [Label] | |
| @[simp] theorem card_vertex [Fintype E] [Fintype X] : | |
| Fintype.card (Vertex E X) = Fintype.card E + Fintype.card X := by | |
| simp [Vertex, Fintype.card_sum] | |
| @[simp] theorem card_dart [Fintype E] : | |
| Fintype.card (Dart E q) = 2 * q * Fintype.card E := by | |
| simp [Dart, Fintype.card_prod, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] | |
| theorem gap_transfer [Fintype E] [DecidableEq X] (T : Verifier E X q) | |
| (positive : 0 < q) (a b : Nat) | |
| (sourceGap : ∀ assignment : X → Bool, | |
| a * Fintype.card E ≤ b * verifierRejectionCount T assignment) | |
| (labeling : Vertex E X → Label q) : | |
| a * Fintype.card (Dart E q) ≤ (b * q) * (graph T positive).rejectionCount labeling := by | |
| have source := Nat.mul_le_mul_left (2 * q) (sourceGap (decodedAssignment positive labeling)) | |
| have incidences := Nat.mul_le_mul_left (b * q) (rejection_count_bound T positive labeling) | |
| rw [card_dart] | |
| calc | |
| a * (2 * q * Fintype.card E) = (2 * q) * (a * Fintype.card E) := by ac_rfl | |
| _ ≤ (2 * q) * (b * verifierRejectionCount T (decodedAssignment positive labeling)) := source | |
| _ = (b * q) * (2 * verifierRejectionCount T (decodedAssignment positive labeling)) := by ac_rfl | |
| _ ≤ (b * q) * (graph T positive).rejectionCount labeling := incidences | |
| theorem six_query_alphabet : Fintype.card (Label 6) = 64 := by | |
| simp [] | |
| end DFVSGames.Foundations.PCP.QueryIncidence | |
| noncomputable section | |
| namespace DFVSGames.Foundations.PCP.CodeComposition | |
| open scoped BigOperators | |
| open DFVSGames.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_inline_CodeComposition {A : Type*} [DecidableEq A] (a : A) : Cube A := | |
| fun i => decide (i = a) | |
| private theorem walsh_singletonMask_inline_CodeComposition {A : Type*} [Fintype A] [DecidableEq A] | |
| (a : A) (x : Cube A) : walsh (singletonMask_inline_CodeComposition a) x = bitSign (x a) := by | |
| classical | |
| unfold walsh singletonMask_inline_CodeComposition | |
| rw [Finset.prod_eq_single a] | |
| · simp | |
| · intro b _ hba | |
| simp [hba, bitSign] | |
| · simp | |
| private theorem singletonMask_ne_inline_CodeComposition {A : Type*} [DecidableEq A] {a b : A} (hab : a ≠ b) : | |
| singletonMask_inline_CodeComposition a ≠ singletonMask_inline_CodeComposition b := by | |
| intro h | |
| have he := congrFun h a | |
| simp [singletonMask_inline_CodeComposition, 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_inline_CodeComposition a) (singletonMask_inline_CodeComposition b) | |
| rw [ite_eq_right (singletonMask_ne_inline_CodeComposition hab)] at horth | |
| simp_rw [walsh_singletonMask_inline_CodeComposition] 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 DFVSGames.Foundations.PCP.CodeComposition | |
| end | |
| end OAI | |