import Mathlib import OAI.Combinatorics.IndependentSets.Expansion.PoweringTables namespace OAI namespace IndependentSetsGames.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 IndependentSetsGames.Foundations.PCP.PoweringTableSemantics end OAI