Buckets:
| import Mathlib | |
| import OAI.Computability.DirectedFeedback.Encoding.PoweringAddresses | |
| namespace OAI | |
| namespace DFVSGames.Foundations.PCP.PoweringReach | |
| open PoweringWalks PoweringLabels | |
| variable {V D : Type*} | |
| def ReachLE (G : PortGraph V D) (t : Nat) (u v : V) : Prop := | |
| ∃ l, l ≤ t ∧ ∃ p : Fin l → D, wordEnd G l u p = v | |
| theorem reach_refl (G : PortGraph V D) (t : Nat) (u : V) : ReachLE G t u u := | |
| ⟨0, Nat.zero_le t, Fin.elim0, rfl⟩ | |
| theorem reach_mono {G : PortGraph V D} {s t : Nat} {u v : V} | |
| (hst : s ≤ t) (h : ReachLE G s u v) : ReachLE G t u v := by | |
| obtain ⟨l, hl, p, hp⟩ := h | |
| exact ⟨l, hl.trans hst, p, hp⟩ | |
| theorem reach_prepend (G : PortGraph V D) {t : Nat} (u : V) (d : D) {v : V} | |
| (h : ReachLE G t (next G u d) v) : ReachLE G (t + 1) u v := by | |
| obtain ⟨l, hl, p, hp⟩ := h | |
| refine ⟨l + 1, Nat.succ_le_succ hl, | |
| (fun i : Fin (l + 1) => Fin.cases d p i), ?_⟩ | |
| simpa only [wordEnd, Fin.cases_zero, Fin.cases_succ] using hp | |
| def reversePorts (G : PortGraph V D) : V → List D → List D | |
| | _, [] => [] | |
| | v, d :: ds => reversePorts G (next G v d) ds ++ [(G.rot (v, d)).2] | |
| theorem reversePorts_length (G : PortGraph V D) (v : V) (ds : List D) : | |
| (reversePorts G v ds).length = ds.length := by | |
| induction ds generalizing v with | |
| | nil => rfl | |
| | cons d ds ih => simp [reversePorts, ih] | |
| theorem walkEnd_reversePorts (G : PortGraph V D) (v : V) (ds : List D) : | |
| walkEnd G (walkEnd G v ds) (reversePorts G v ds) = v := by | |
| induction ds generalizing v with | |
| | nil => rfl | |
| | cons d ds ih => | |
| change walkEnd G (walkEnd G (next G v d) ds) | |
| (reversePorts G (next G v d) ds ++ [(G.rot (v, d)).2]) = v | |
| rw [walkEnd_append, ih] | |
| change (G.rot (G.rot (v, d))).1 = v | |
| exact congrArg Prod.fst (G.rot_involutive (v, d)) | |
| theorem wordEnd_eq_walkEnd_ofFn (G : PortGraph V D) : | |
| ∀ n v (p : Fin n → D), wordEnd G n v p = walkEnd G v (List.ofFn p) := by | |
| intro n | |
| induction n with | |
| | zero => intro v p; rfl | |
| | succ n ih => | |
| intro v p | |
| rw [List.ofFn_succ, walkEnd_cons] | |
| exact ih (next G v (p 0)) (fun j => p j.succ) | |
| theorem reach_reverse {G : PortGraph V D} {t : Nat} {u v : V} | |
| (h : ReachLE G t u v) : ReachLE G t v u := by | |
| obtain ⟨l, hl, p, hp⟩ := h | |
| refine ⟨(reversePorts G u (List.ofFn p)).length, ?_, | |
| (reversePorts G u (List.ofFn p)).get, ?_⟩ | |
| · simpa only [reversePorts_length, List.length_ofFn] using hl | |
| · rw [wordEnd_eq_walkEnd_ofFn, List.ofFn_get] | |
| have hlist : walkEnd G u (List.ofFn p) = v := by | |
| rw [← wordEnd_eq_walkEnd_ofFn] | |
| exact hp | |
| rw [← hlist, walkEnd_reversePorts] | |
| theorem tail_reach (G : PortGraph V D) : | |
| ∀ (n : Nat) (w : Walk V D (n + 1)) (k : Fin (n + 1)), | |
| ReachLE G (n + 1) w.1 (edgeAt G n w k).1 := by | |
| intro n | |
| induction n with | |
| | zero => | |
| intro w k | |
| exact reach_refl G 1 w.1 | |
| | succ n ih => | |
| intro w k | |
| refine Fin.cases ?_ (fun j => ?_) k | |
| · exact reach_refl G (n + 2) w.1 | |
| · exact reach_prepend G w.1 (w.2 0) (ih (advanceTail G w) j) | |
| theorem head_reach_endpoint (G : PortGraph V D) : | |
| ∀ (n : Nat) (w : Walk V D (n + 1)) (k : Fin (n + 1)), | |
| ReachLE G (n + 1) (G.rot (edgeAt G n w k)).1 (endpoint G w) := by | |
| intro n | |
| induction n with | |
| | zero => | |
| intro w k | |
| exact reach_refl G 1 (G.rot (w.1, w.2 0)).1 | |
| | succ n ih => | |
| intro w k | |
| refine Fin.cases ?_ (fun j => ?_) k | |
| · exact ⟨n + 1, Nat.le_succ (n + 1), (fun j => w.2 j.succ), rfl⟩ | |
| · exact reach_mono (Nat.le_succ (n + 1)) (ih (advanceTail G w) j) | |
| def tailFromStart (G : PortGraph V D) (n : Nat) (w : Walk V D (n + 1)) | |
| (k : Fin (n + 1)) : Ball G (n + 1) w.1 := | |
| ⟨(edgeAt G n w k).1, tail_reach G n w k⟩ | |
| def headFromEnd (G : PortGraph V D) (n : Nat) (w : Walk V D (n + 1)) | |
| (k : Fin (n + 1)) : Ball G (n + 1) (endpoint G w) := | |
| ⟨(G.rot (edgeAt G n w k)).1, reach_reverse (head_reach_endpoint G n w k)⟩ | |
| @[simp] theorem tailFromStart_val (G : PortGraph V D) (n : Nat) | |
| (w : Walk V D (n + 1)) (k : Fin (n + 1)) : | |
| (tailFromStart G n w k).val = (edgeAt G n w k).1 := rfl | |
| @[simp] theorem headFromEnd_val (G : PortGraph V D) (n : Nat) | |
| (w : Walk V D (n + 1)) (k : Fin (n + 1)) : | |
| (headFromEnd G n w k).val = (G.rot (edgeAt G n w k)).1 := rfl | |
| end DFVSGames.Foundations.PCP.PoweringReach | |
| namespace DFVSGames.Foundations.PCP.PoweringTest | |
| open PoweringWalks PoweringLabels PoweringReach PoweringOpinions | |
| variable {V D A : Type*} | |
| def baseGraph (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) : | |
| ConstraintGraph V (Edge V D) A where | |
| reverse := G.rot | |
| reverse_involutive := G.rot_involutive | |
| tail := Prod.fst | |
| accepts := accepts | |
| reverse_accepts := reverse_accepts | |
| def pathAccepts (G : PortGraph V D) (accepts : Edge V D → A → A → Bool) | |
| (n : Nat) (selectors : ∀ v, AddressSelector G (n + 1) v) | |
| (w : Walk V D (n + 1)) (a b : PaddedLabel D (n + 1) A) : Bool := | |
| decide (∀ k : Fin (n + 1), | |
| accepts (edgeAt G n w k) | |
| (decode (selectors w.1) a (tailFromStart G n w k)) | |
| (decode (selectors (endpoint G w)) b (headFromEnd G n w k)) = true) | |
| theorem pathAccepts_eq_true_iff (G : PortGraph V D) | |
| (accepts : Edge V D → A → A → Bool) | |
| (n : Nat) (selectors : ∀ v, AddressSelector G (n + 1) v) | |
| (w : Walk V D (n + 1)) (a b : PaddedLabel D (n + 1) A) : | |
| pathAccepts G accepts n selectors w a b = true ↔ | |
| ∀ k : Fin (n + 1), | |
| accepts (edgeAt G n w k) | |
| (decode (selectors w.1) a (tailFromStart G n w k)) | |
| (decode (selectors (endpoint G w)) b (headFromEnd G n w k)) = true := by | |
| simp [pathAccepts] | |
| abbrev Dart (V D : Type*) (n : Nat) := Bool × Walk V D (n + 1) | |
| def reverseDart (V D : Type*) (n : Nat) : Dart V D n ≃ Dart V D n where | |
| toFun d := (!d.1, d.2) | |
| invFun d := (!d.1, d.2) | |
| left_inv := by | |
| rintro ⟨b, w⟩ | |
| cases b <;> rfl | |
| right_inv := by | |
| rintro ⟨b, w⟩ | |
| cases b <;> rfl | |
| theorem reverseDart_involutive (V D : Type*) (n : Nat) : | |
| Function.Involutive (reverseDart V D n) := by | |
| rintro ⟨b, w⟩ | |
| cases b <;> rfl | |
| def poweredGraph (G : PortGraph V D) (accepts : Edge V D → A → A → Bool) | |
| (n : Nat) (selectors : ∀ v, AddressSelector G (n + 1) v) : | |
| ConstraintGraph V (Dart V D n) (PaddedLabel D (n + 1) A) where | |
| reverse := reverseDart V D n | |
| reverse_involutive := reverseDart_involutive V D n | |
| tail d := if d.1 then endpoint G d.2 else d.2.1 | |
| accepts d a b := if d.1 then pathAccepts G accepts n selectors d.2 b a | |
| else pathAccepts G accepts n selectors d.2 a b | |
| reverse_accepts := by | |
| rintro ⟨direction, w⟩ a b | |
| cases direction <;> rfl | |
| @[simp] theorem poweredGraph_tail_false (G : PortGraph V D) | |
| (accepts : Edge V D → A → A → Bool) (n : Nat) | |
| (selectors : ∀ v, AddressSelector G (n + 1) v) (w : Walk V D (n + 1)) : | |
| (poweredGraph G accepts n selectors).tail (false, w) = w.1 := rfl | |
| @[simp] theorem poweredGraph_tail_true (G : PortGraph V D) | |
| (accepts : Edge V D → A → A → Bool) (n : Nat) | |
| (selectors : ∀ v, AddressSelector G (n + 1) v) (w : Walk V D (n + 1)) : | |
| (poweredGraph G accepts n selectors).tail (true, w) = endpoint G w := rfl | |
| theorem poweredGraph_edgeSatisfied (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) | |
| (direction : Bool) (w : Walk V D (n + 1)) : | |
| (poweredGraph G accepts n selectors).edgeSatisfied labels (direction, w) = | |
| pathAccepts G accepts n selectors w (labels w.1) (labels (endpoint G w)) := by | |
| cases direction <;> rfl | |
| theorem rejection_mean_eq_path_mean [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)) = | |
| 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)) := by | |
| rw [SpectralReturn.mean_prod] | |
| simp only [poweredGraph_edgeSatisfied, SpectralReturn.mean_const] | |
| theorem pathAccepts_honest (G : PortGraph V D) | |
| (accepts : Edge V D → A → A → Bool) (n : Nat) | |
| (selectors : ∀ v, AddressSelector G (n + 1) v) | |
| (assignment : V → A) | |
| (satisfies : ∀ e, accepts e (assignment e.1) (assignment (G.rot e).1) = true) | |
| (w : Walk V D (n + 1)) : | |
| pathAccepts G accepts n selectors w | |
| (honestLabels G (n + 1) assignment w.1) | |
| (honestLabels G (n + 1) assignment (endpoint G w)) = true := by | |
| apply (pathAccepts_eq_true_iff G accepts n selectors w _ _).2 | |
| intro k | |
| simpa only [honestLabels, decode_encode, tailFromStart_val, headFromEnd_val] using | |
| satisfies (edgeAt G n w k) | |
| theorem perfect_completeness (G : PortGraph V D) | |
| (accepts : Edge V D → A → A → Bool) (n : Nat) | |
| (selectors : ∀ v, AddressSelector G (n + 1) v) | |
| (assignment : V → A) | |
| (satisfies : ∀ e, accepts e (assignment e.1) (assignment (G.rot e).1) = true) : | |
| ∀ d, (poweredGraph G accepts n selectors).edgeSatisfied | |
| (honestLabels G (n + 1) assignment) d = true := by | |
| rintro ⟨direction, w⟩ | |
| rw [poweredGraph_edgeSatisfied] | |
| exact pathAccepts_honest G accepts n selectors assignment satisfies w | |
| theorem preserves_satisfiability (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) | |
| (n : Nat) (selectors : ∀ v, AddressSelector G (n + 1) v) | |
| (h : (baseGraph G accepts reverse_accepts).Satisfiable) : | |
| (poweredGraph G accepts n selectors).Satisfiable := by | |
| obtain ⟨assignment, satisfies⟩ := h | |
| refine ⟨honestLabels G (n + 1) assignment, ?_⟩ | |
| apply perfect_completeness G accepts n selectors assignment | |
| intro e | |
| exact satisfies e | |
| def decodedBad (G : PortGraph V D) (accepts : Edge V D → A → A → Bool) | |
| (assignment : V → A) (e : Edge V D) : Bool := | |
| !(accepts e (assignment e.1) (assignment (G.rot e).1)) | |
| theorem decodedBad_eq_true_iff (G : PortGraph V D) | |
| (accepts : Edge V D → A → A → Bool) (assignment : V → A) (e : Edge V D) : | |
| decodedBad G accepts assignment e = true ↔ | |
| accepts e (assignment e.1) (assignment (G.rot e).1) = false := by | |
| simp [decodedBad] | |
| theorem decodedBad_rot (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) (e : Edge V D) : | |
| decodedBad G accepts assignment (G.rot e) = decodedBad G accepts assignment e := by | |
| have h := congrArg Bool.not | |
| (reverse_accepts e (assignment e.1) (assignment (G.rot e).1)) | |
| simpa only [decodedBad, G.rot_involutive e] using h | |
| noncomputable def witness (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) (fallback : A) | |
| (assignment : V → A) (w : Walk V D (n + 1)) (k : Fin (n + 1)) : Prop := | |
| decodedBad G accepts assignment (edgeAt G n w k) = true ∧ | |
| opinionAt G (n + 1) selectors labels fallback (edgeAt G n w k).1 w.1 = | |
| assignment (edgeAt G n w k).1 ∧ | |
| opinionAt G (n + 1) selectors labels fallback | |
| (G.rot (edgeAt G n w k)).1 (endpoint G w) = | |
| assignment (G.rot (edgeAt G n w k)).1 | |
| theorem witness_bad (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) (fallback : A) | |
| (assignment : V → A) (w : Walk V D (n + 1)) (k : Fin (n + 1)) | |
| (h : witness G accepts n selectors labels fallback assignment w k) : | |
| decodedBad G accepts assignment (edgeAt G n w k) = true := h.1 | |
| theorem witness_implies_path_rejection (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) (fallback : A) | |
| (assignment : V → A) (w : Walk V D (n + 1)) (k : Fin (n + 1)) | |
| (h : witness G accepts n selectors labels fallback assignment w k) : | |
| pathAccepts G accepts n selectors w (labels w.1) (labels (endpoint G w)) = false := by | |
| obtain ⟨hBad, hTail, hHead⟩ := h | |
| have hTailDecode : | |
| decode (selectors w.1) (labels w.1) (tailFromStart G n w k) = | |
| assignment (edgeAt G n w k).1 := | |
| (opinionAt_eq_decode G (n + 1) selectors labels fallback w.1 | |
| (tailFromStart G n w k)).symm.trans hTail | |
| have hHeadDecode : | |
| decode (selectors (endpoint G w)) (labels (endpoint G w)) | |
| (headFromEnd G n w k) = assignment (G.rot (edgeAt G n w k)).1 := | |
| (opinionAt_eq_decode G (n + 1) selectors labels fallback (endpoint G w) | |
| (headFromEnd G n w k)).symm.trans hHead | |
| have hFalse := (decodedBad_eq_true_iff G accepts assignment (edgeAt G n w k)).1 hBad | |
| cases hPath : pathAccepts G accepts n selectors w | |
| (labels w.1) (labels (endpoint G w)) with | |
| | false => rfl | |
| | true => | |
| have hChecked := (pathAccepts_eq_true_iff G accepts n selectors w _ _).1 hPath k | |
| rw [hTailDecode, hHeadDecode, hFalse] at hChecked | |
| exact False.elim (Bool.noConfusion hChecked) | |
| theorem witness_implies_rejection (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) (fallback : A) | |
| (assignment : V → A) (w : Walk V D (n + 1)) (k : Fin (n + 1)) | |
| (h : witness G accepts n selectors labels fallback assignment w k) | |
| (direction : Bool) : | |
| (poweredGraph G accepts n selectors).edgeSatisfied labels (direction, w) = false := by | |
| rw [poweredGraph_edgeSatisfied] | |
| exact witness_implies_path_rejection G accepts n selectors labels fallback assignment w k h | |
| end DFVSGames.Foundations.PCP.PoweringTest | |
| namespace DFVSGames.Foundations.PCP.PoweringOpinionTables | |
| open PoweringWalks PoweringLabels PoweringAddresses PoweringReach | |
| open scoped BigOperators | |
| variable {X A : Type*} | |
| private theorem match_in_tail_inline_PoweringOpinionTables (p : X → Prop) {a : X} {xs : List X} | |
| (h : ∃ b ∈ a :: xs, p b) (ha : ¬p a) : ∃ b ∈ xs, p b := by | |
| obtain ⟨b, hb, hp⟩ := h | |
| rcases List.mem_cons.mp hb with he | hm | |
| · exact False.elim (ha (he ▸ hp)) | |
| · exact ⟨b, hm, hp⟩ | |
| def firstIndex (p : X → Prop) [DecidablePred p] : | |
| (xs : List X) → (∃ a ∈ xs, p a) → Fin xs.length | |
| | [], h => False.elim (by simp at h) | |
| | a :: xs, h => | |
| if ha : p a then ⟨0, Nat.zero_lt_succ xs.length⟩ else | |
| (firstIndex p xs (match_in_tail_inline_PoweringOpinionTables p h ha)).succ | |
| theorem get_firstIndex (p : X → Prop) [DecidablePred p] : | |
| ∀ (xs : List X) (h : ∃ a ∈ xs, p a), | |
| xs.get (firstIndex p xs h) = (scanWitness p xs h).val := by | |
| intro xs | |
| induction xs with | |
| | nil => intro h; simp at h | |
| | cons a xs ih => | |
| intro h | |
| by_cases ha : p a | |
| · simp [firstIndex, scanWitness, ha] | |
| · simpa only [firstIndex, scanWitness, ha, dite_false, List.get_cons_succ'] using | |
| ih (match_in_tail_inline_PoweringOpinionTables p h ha) | |
| theorem firstIndex_matches (p : X → Prop) [DecidablePred p] | |
| (xs : List X) (h : ∃ a ∈ xs, p a) : p (xs.get (firstIndex p xs h)) := by | |
| rw [get_firstIndex] | |
| exact (scanWitness p xs h).property | |
| theorem firstIndex_is_first (p : X → Prop) [DecidablePred p] : | |
| ∀ (xs : List X) (h : ∃ a ∈ xs, p a) (j : Fin xs.length), | |
| j.val < (firstIndex p xs h).val → ¬p (xs.get j) := by | |
| intro xs | |
| induction xs with | |
| | nil => intro h; simp at h | |
| | cons a xs ih => | |
| intro h j | |
| by_cases ha : p a | |
| · simp [firstIndex, ha] | |
| · refine Fin.cases (by intro _; exact ha) (fun i => ?_) j | |
| intro hi | |
| apply ih (match_in_tail_inline_PoweringOpinionTables p h ha) i | |
| exact Nat.lt_of_succ_lt_succ (by | |
| simpa only [firstIndex, ha, dite_false, Fin.val_succ] using hi) | |
| abbrev AddressIndex (d t : Nat) := Fin (allAddresses d t).length | |
| variable {vertices d : Nat} | |
| def addressIndex (G : PortGraph (Fin vertices) (Fin d)) (t : Nat) | |
| (center : Fin vertices) (u : Ball G t center) : AddressIndex d t := | |
| firstIndex (fun w => (wordToBall G t center w).val = u.val) | |
| (allAddresses d t) (by | |
| obtain ⟨w, hw⟩ := wordToBall_surjective G t center u | |
| exact ⟨w, mem_allAddresses d t w, congrArg Subtype.val hw⟩) | |
| theorem addressIndex_get (G : PortGraph (Fin vertices) (Fin d)) (t : Nat) | |
| (center : Fin vertices) (u : Ball G t center) : | |
| (allAddresses d t).get (addressIndex G t center u) = | |
| (finitePortSelector G t center).address u := by | |
| change (allAddresses d t).get (firstIndex | |
| (fun w => (wordToBall G t center w).val = u.val) (allAddresses d t) _) = | |
| (scanWitness _ _ _).val | |
| exact get_firstIndex _ _ _ | |
| theorem addressIndex_matches (G : PortGraph (Fin vertices) (Fin d)) (t : Nat) | |
| (center : Fin vertices) (u : Ball G t center) : | |
| wordToBall G t center ((allAddresses d t).get (addressIndex G t center u)) = u := by | |
| rw [addressIndex_get] | |
| exact (finitePortSelector G t center).correct u | |
| theorem addressIndex_is_first (G : PortGraph (Fin vertices) (Fin d)) (t : Nat) | |
| (center : Fin vertices) (u : Ball G t center) (j : AddressIndex d t) | |
| (hj : j.val < (addressIndex G t center u).val) : | |
| (wordToBall G t center ((allAddresses d t).get j)).val ≠ u.val := by | |
| exact firstIndex_is_first _ _ _ j hj | |
| theorem addressIndex_lt (G : PortGraph (Fin vertices) (Fin d)) (t : Nat) | |
| (center : Fin vertices) (u : Ball G t center) : | |
| (addressIndex G t center u).val < ∑ n : Fin (t + 1), d ^ n.val := by | |
| rw [← length_allAddresses] | |
| exact (addressIndex G t center u).isLt | |
| abbrev LabelTable (d t : Nat) (A : Type*) := Vector A (allAddresses d t).length | |
| def labelTable {t : Nat} (a : PaddedLabel (Fin d) t A) : LabelTable d t A := | |
| Vector.ofFn fun i => a ((allAddresses d t).get i) | |
| @[simp] theorem labelTable_get {t : Nat} (a : PaddedLabel (Fin d) t A) | |
| (i : AddressIndex d t) : | |
| (labelTable a)[i] = a ((allAddresses d t).get i) := by | |
| simp [labelTable] | |
| theorem labelTable_addressIndex (G : PortGraph (Fin vertices) (Fin d)) (t : Nat) | |
| (center : Fin vertices) (u : Ball G t center) (a : PaddedLabel (Fin d) t A) : | |
| (labelTable a)[addressIndex G t center u] = | |
| decode (finitePortSelector G t center) a u := by | |
| rw [labelTable_get, addressIndex_get] | |
| rfl | |
| structure WalkOpinionRow (vertices d t : Nat) where | |
| edge : Edge (Fin vertices) (Fin d) | |
| tailIndex : AddressIndex d t | |
| headIndex : AddressIndex d t | |
| abbrev WalkRows (vertices d n : Nat) := Vector (WalkOpinionRow vertices d (n + 1)) (n + 1) | |
| def walkRows (G : PortGraph (Fin vertices) (Fin d)) (n : Nat) | |
| (w : Walk (Fin vertices) (Fin d) (n + 1)) : WalkRows vertices d n := | |
| Vector.ofFn fun k => | |
| { edge := edgeAt G n w k | |
| tailIndex := addressIndex G (n + 1) w.1 (tailFromStart G n w k) | |
| headIndex := addressIndex G (n + 1) (endpoint G w) (headFromEnd G n w k) } | |
| @[simp] theorem walkRows_edge (G : PortGraph (Fin vertices) (Fin d)) (n : Nat) | |
| (w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1)) : | |
| (walkRows G n w)[k].edge = edgeAt G n w k := by | |
| simp [walkRows] | |
| @[simp] theorem walkRows_tail_value (G : PortGraph (Fin vertices) (Fin d)) (n : Nat) | |
| (w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1)) | |
| (a : PaddedLabel (Fin d) (n + 1) A) : | |
| (labelTable a)[(walkRows G n w)[k].tailIndex] = | |
| decode (finitePortSelector G (n + 1) w.1) a (tailFromStart G n w k) := by | |
| simpa only [walkRows, Fin.getElem_fin, Vector.getElem_ofFn] using | |
| labelTable_addressIndex G (n + 1) w.1 (tailFromStart G n w k) a | |
| @[simp] theorem walkRows_head_value (G : PortGraph (Fin vertices) (Fin d)) (n : Nat) | |
| (w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1)) | |
| (b : PaddedLabel (Fin d) (n + 1) A) : | |
| (labelTable b)[(walkRows G n w)[k].headIndex] = | |
| decode (finitePortSelector G (n + 1) (endpoint G w)) b (headFromEnd G n w k) := by | |
| simpa only [walkRows, Fin.getElem_fin, Vector.getElem_ofFn] using | |
| labelTable_addressIndex G (n + 1) (endpoint G w) (headFromEnd G n w k) b | |
| theorem walkRows_length (G : PortGraph (Fin vertices) (Fin d)) (n : Nat) | |
| (w : Walk (Fin vertices) (Fin d) (n + 1)) : | |
| (walkRows G n w).toList.length = n + 1 := by | |
| simp | |
| def rowsAccepts {n : Nat} (accepts : Edge (Fin vertices) (Fin d) → A → A → Bool) | |
| (rows : WalkRows vertices d n) (a b : LabelTable d (n + 1) A) : Bool := | |
| decide (∀ k : Fin (n + 1), accepts rows[k].edge a[rows[k].tailIndex] | |
| b[rows[k].headIndex] = true) | |
| theorem rowsAccepts_walkRows (G : PortGraph (Fin vertices) (Fin d)) | |
| (accepts : Edge (Fin vertices) (Fin d) → A → A → Bool) (n : Nat) | |
| (w : Walk (Fin vertices) (Fin d) (n + 1)) | |
| (a b : PaddedLabel (Fin d) (n + 1) A) : | |
| rowsAccepts accepts (walkRows G n w) (labelTable a) (labelTable b) = | |
| PoweringTest.pathAccepts G accepts n (finitePortSelector G (n + 1)) w a b := by | |
| apply Bool.eq_iff_iff.mpr | |
| simp only [rowsAccepts, decide_eq_true_iff, PoweringTest.pathAccepts_eq_true_iff, | |
| walkRows_edge, walkRows_tail_value, walkRows_head_value] | |
| end DFVSGames.Foundations.PCP.PoweringOpinionTables | |
| namespace DFVSGames.Foundations.PCP.GenericGraphTables | |
| open DFVSGames.Foundations.Complexity | |
| abbrev Label (q : Nat) := Fin q | |
| abbrev RelationTable (q : Nat) := Vector Bool (q * q) | |
| variable {q : Nat} | |
| def relationIndex (q : Nat) : (Label q) × (Label q) ≃ Fin (q * q) := finProdFinEquiv | |
| theorem relationIndex_val (a b : (Label q)) : | |
| ((relationIndex q) (a, b)).val = b.val + q * a.val := rfl | |
| def relationAt (table : (RelationTable q)) (a b : (Label q)) : Bool := | |
| table[(relationIndex q) (a, b)] | |
| def relationOf (predicate : (Label q) → (Label q) → Bool) : (RelationTable q) := | |
| Vector.ofFn (fun i => predicate ((relationIndex q).symm i).1 ((relationIndex q).symm i).2) | |
| @[simp] theorem relationAt_relationOf (predicate : (Label q) → (Label q) → Bool) (a b : (Label q)) : | |
| relationAt (relationOf predicate) a b = predicate a b := by | |
| simp [relationAt, relationOf] | |
| structure DartRow (q vertices darts : Nat) where | |
| tail : Fin vertices | |
| reverseIndex : Fin darts | |
| relation : (RelationTable q) | |
| abbrev Rows (q vertices darts : Nat) := Vector (DartRow q vertices darts) darts | |
| def reverseAt {n m : Nat} (rows : Rows q n m) (e : Fin m) : Fin m := | |
| rows[e].reverseIndex | |
| def acceptsAt {n m : Nat} (rows : Rows q n m) (e : Fin m) (a b : (Label q)) : Bool := | |
| relationAt rows[e].relation a b | |
| def Valid {n m : Nat} (rows : Rows q n m) : Prop := | |
| (∀ e, reverseAt rows (reverseAt rows e) = e) ∧ | |
| (∀ e a b, acceptsAt rows (reverseAt rows e) b a = acceptsAt rows e a b) | |
| instance {n m : Nat} (rows : Rows q n m) : Decidable (Valid rows) := by | |
| unfold Valid | |
| infer_instance | |
| structure Table (q : Nat) where | |
| vertices : Nat | |
| darts : Nat | |
| rows : Rows q vertices darts | |
| valid : Valid rows | |
| def rowList (table : (Table q)) : List (DartRow q table.vertices table.darts) := table.rows.toList | |
| @[simp] theorem rowList_length (table : (Table q)) : (rowList table).length = table.darts := by | |
| simp [rowList] | |
| def semantics (table : (Table q)) : ConstraintGraph (Fin table.vertices) (Fin table.darts) (Label q) where | |
| reverse := | |
| { toFun := reverseAt table.rows | |
| invFun := reverseAt table.rows | |
| left_inv := table.valid.1 | |
| right_inv := table.valid.1 } | |
| reverse_involutive := table.valid.1 | |
| tail e := table.rows[e].tail | |
| accepts := acceptsAt table.rows | |
| reverse_accepts := table.valid.2 | |
| @[simp] theorem semantics_reverse (table : (Table q)) (e : Fin table.darts) : | |
| (semantics table).reverse e = table.rows[e].reverseIndex := rfl | |
| @[simp] theorem semantics_tail (table : (Table q)) (e : Fin table.darts) : | |
| (semantics table).tail e = table.rows[e].tail := rfl | |
| @[simp] theorem semantics_accepts (table : (Table q)) (e : Fin table.darts) (a b : (Label q)) : | |
| (semantics table).accepts e a b = relationAt table.rows[e].relation a b := rfl | |
| def graphRows {n m : Nat} (G : ConstraintGraph (Fin n) (Fin m) (Label q)) : Rows q n m := | |
| Vector.ofFn (fun e => ⟨G.tail e, G.reverse e, relationOf (G.accepts e)⟩) | |
| @[simp] theorem reverseAt_graphRows {n m : Nat} | |
| (G : ConstraintGraph (Fin n) (Fin m) (Label q)) (e : Fin m) : | |
| reverseAt (graphRows G) e = G.reverse e := by | |
| simp [reverseAt, graphRows] | |
| @[simp] theorem acceptsAt_graphRows {n m : Nat} | |
| (G : ConstraintGraph (Fin n) (Fin m) (Label q)) (e : Fin m) (a b : (Label q)) : | |
| acceptsAt (graphRows G) e a b = G.accepts e a b := by | |
| simp [acceptsAt, graphRows] | |
| theorem graphRows_valid {n m : Nat} (G : ConstraintGraph (Fin n) (Fin m) (Label q)) : | |
| Valid (graphRows G) := by | |
| constructor | |
| · intro e | |
| simpa using G.reverse_involutive e | |
| · intro e a b | |
| simpa using G.reverse_accepts e a b | |
| def ofGraph {n m : Nat} (G : ConstraintGraph (Fin n) (Fin m) (Label q)) : (Table q) := | |
| ⟨n, m, graphRows G, graphRows_valid G⟩ | |
| @[simp] theorem semantics_ofGraph_reverse {n m : Nat} | |
| (G : ConstraintGraph (Fin n) (Fin m) (Label q)) (e : Fin m) : | |
| (semantics (ofGraph G)).reverse e = G.reverse e := by | |
| exact reverseAt_graphRows G e | |
| @[simp] theorem semantics_ofGraph_tail {n m : Nat} | |
| (G : ConstraintGraph (Fin n) (Fin m) (Label q)) (e : Fin m) : | |
| (semantics (ofGraph G)).tail e = G.tail e := by | |
| change (graphRows G)[e.val].tail = G.tail e | |
| simp only [graphRows, Vector.getElem_ofFn] | |
| @[simp] theorem semantics_ofGraph_accepts {n m : Nat} | |
| (G : ConstraintGraph (Fin n) (Fin m) (Label q)) (e : Fin m) (a b : (Label q)) : | |
| (semantics (ofGraph G)).accepts e a b = G.accepts e a b := by | |
| exact acceptsAt_graphRows G e a b | |
| @[simp] theorem semantics_ofGraph_edgeSatisfied {n m : Nat} | |
| (G : ConstraintGraph (Fin n) (Fin m) (Label q)) (labeling : Fin n → (Label q)) (e : Fin m) : | |
| (semantics (ofGraph G)).edgeSatisfied labeling e = G.edgeSatisfied labeling e := by | |
| simp [ConstraintGraph.edgeSatisfied, ConstraintGraph.head] | |
| private theorem constraintGraph_ext_inline_GenericGraphTables {V E A : Type*} {G H : ConstraintGraph V E A} | |
| (hr : ∀ e, G.reverse e = H.reverse e) (ht : G.tail = H.tail) | |
| (hp : G.accepts = H.accepts) : G = H := by | |
| cases G with | |
| | mk reverse hinv tail accepts htranspose => | |
| cases H with | |
| | mk reverse' hinv' tail' accepts' htranspose' => | |
| dsimp only at hr ht hp | |
| have he : reverse = reverse' := Equiv.ext hr | |
| cases he | |
| cases ht | |
| cases hp | |
| rfl | |
| @[simp] theorem semantics_ofGraph {n m : Nat} | |
| (G : ConstraintGraph (Fin n) (Fin m) (Label q)) : semantics (ofGraph G) = G := by | |
| apply constraintGraph_ext_inline_GenericGraphTables | |
| · exact semantics_ofGraph_reverse G | |
| · funext e | |
| exact semantics_ofGraph_tail G e | |
| · funext e a b | |
| exact semantics_ofGraph_accepts G e a b | |
| @[simp] theorem semantics_ofGraph_rejectionCount {n m : Nat} | |
| (G : ConstraintGraph (Fin n) (Fin m) (Label q)) (labeling : Fin n → (Label q)) : | |
| (semantics (ofGraph G)).rejectionCount labeling = G.rejectionCount labeling := by | |
| rw [semantics_ofGraph] | |
| rfl | |
| def enumeratedGraph {V E A : Type*} {n m : Nat} (G : ConstraintGraph V E A) | |
| (vertexOrder : V ≃ Fin n) (dartOrder : E ≃ Fin m) (labelOrder : A ≃ (Label q)) : | |
| ConstraintGraph (Fin n) (Fin m) (Label q) where | |
| reverse := (dartOrder.symm.trans G.reverse).trans dartOrder | |
| reverse_involutive e := by | |
| change dartOrder (G.reverse (dartOrder.symm | |
| (dartOrder (G.reverse (dartOrder.symm e))))) = e | |
| rw [dartOrder.symm_apply_apply, G.reverse_involutive, dartOrder.apply_symm_apply] | |
| tail e := vertexOrder (G.tail (dartOrder.symm e)) | |
| accepts e a b := G.accepts (dartOrder.symm e) (labelOrder.symm a) (labelOrder.symm b) | |
| reverse_accepts e a b := by | |
| change G.accepts (dartOrder.symm (dartOrder (G.reverse (dartOrder.symm e)))) | |
| (labelOrder.symm b) (labelOrder.symm a) = _ | |
| rw [dartOrder.symm_apply_apply] | |
| exact G.reverse_accepts _ _ _ | |
| theorem enumeratedGraph_edgeSatisfied {V E A : Type*} {n m : Nat} | |
| (G : ConstraintGraph V E A) (vertexOrder : V ≃ Fin n) (dartOrder : E ≃ Fin m) | |
| (labelOrder : A ≃ (Label q)) (labeling : V → A) (e : E) : | |
| (enumeratedGraph G vertexOrder dartOrder labelOrder).edgeSatisfied | |
| (fun v => labelOrder (labeling (vertexOrder.symm v))) (dartOrder e) = | |
| G.edgeSatisfied labeling e := by | |
| simp [ConstraintGraph.edgeSatisfied, ConstraintGraph.head, enumeratedGraph] | |
| theorem enumeratedGraph_rejectionCount {V E A : Type*} [Fintype E] {n m : Nat} | |
| (G : ConstraintGraph V E A) (vertexOrder : V ≃ Fin n) (dartOrder : E ≃ Fin m) | |
| (labelOrder : A ≃ (Label q)) (labeling : V → A) : | |
| (enumeratedGraph G vertexOrder dartOrder labelOrder).rejectionCount | |
| (fun v => labelOrder (labeling (vertexOrder.symm v))) = G.rejectionCount labeling := by | |
| classical | |
| unfold ConstraintGraph.rejectionCount | |
| symm | |
| apply Finset.card_equiv dartOrder | |
| intro e | |
| simp only [ConstraintGraph.mem_rejectedDarts, enumeratedGraph_edgeSatisfied] | |
| def ofEnumeratedGraph {V E A : Type*} {n m : Nat} (G : ConstraintGraph V E A) | |
| (vertexOrder : V ≃ Fin n) (dartOrder : E ≃ Fin m) (labelOrder : A ≃ (Label q)) : (Table q) := | |
| ofGraph (enumeratedGraph G vertexOrder dartOrder labelOrder) | |
| def bitWord (b : Bool) : Nat := if b then 1 else 0 | |
| def parseBit : Nat → Option Bool | |
| | 0 => some false | |
| | 1 => some true | |
| | _ => none | |
| @[simp] theorem parseBit_bitWord (b : Bool) : parseBit (bitWord b) = some b := by | |
| cases b <;> rfl | |
| @[simp] theorem parseBits_bitWords (bits : List Bool) : | |
| (bits.map bitWord).mapM parseBit = some bits := by | |
| induction bits with | |
| | nil => rfl | |
| | cons bit bits ih => simp [ih] | |
| def relationWords (relation : (RelationTable q)) : List Nat := relation.toList.map bitWord | |
| @[simp] theorem relationWords_length (relation : (RelationTable q)) : | |
| (relationWords relation).length = (q * q) := by simp [relationWords] | |
| def parseRelation (q : Nat) (words : List Nat) : Option (RelationTable q) := do | |
| let bits ← words.mapM parseBit | |
| if length_ok : bits.length = (q * q) then | |
| some ⟨bits.toArray, by simpa using length_ok⟩ | |
| else none | |
| @[simp] theorem parseRelation_encoded (relation : (RelationTable q)) : | |
| (parseRelation q) (relationWords relation) = some relation := by | |
| unfold parseRelation relationWords | |
| rw [parseBits_bitWords] | |
| simp | |
| exact Vector.toArray_toList | |
| def rowWords {n m : Nat} (row : DartRow q n m) : List Nat := | |
| [row.tail.val, row.reverseIndex.val] ++ relationWords row.relation | |
| def parseRow (q : Nat) (vertices darts : Nat) : List Nat → Option (DartRow q vertices darts × List Nat) | |
| | tail :: reverseIndex :: words => do | |
| let tail ← parseLabel vertices tail | |
| let reverseIndex ← parseLabel darts reverseIndex | |
| let relation ← (parseRelation q) (words.take (q * q)) | |
| return (⟨tail, reverseIndex, relation⟩, words.drop (q * q)) | |
| | _ => none | |
| @[simp] theorem parseRow_encoded {n m : Nat} (row : DartRow q n m) (rest : List Nat) : | |
| (parseRow q) n m (rowWords row ++ rest) = some (row, rest) := by | |
| cases row with | |
| | mk tail reverseIndex relation => | |
| have taken := List.take_left' (l₂ := rest) (relationWords_length relation) | |
| have dropped := List.drop_left' (l₂ := rest) (relationWords_length relation) | |
| simp [rowWords, parseRow, taken, dropped] | |
| def parseRows (q : Nat) (vertices darts : Nat) : | |
| Nat → List Nat → Option (List (DartRow q vertices darts) × List Nat) | |
| | 0, words => some ([], words) | |
| | count + 1, words => do | |
| let (row, words) ← (parseRow q) vertices darts words | |
| let (rows, words) ← (parseRows q) vertices darts count words | |
| return (row :: rows, words) | |
| @[simp] theorem parseRows_encoded {n m : Nat} (rows : List (DartRow q n m)) (rest : List Nat) : | |
| (parseRows q) n m rows.length (rows.flatMap rowWords ++ rest) = some (rows, rest) := by | |
| induction rows with | |
| | nil => rfl | |
| | cons row rows ih => simp [parseRows, List.append_assoc, ih] | |
| def tableWords (table : (Table q)) : List Nat := | |
| [table.vertices, table.darts] ++ (rowList table).flatMap rowWords | |
| def tableBits (table : (Table q)) : List Bool := encodeWords (tableWords table) | |
| def decodeTableWords (q : Nat) : List Nat → Option (Table q) | |
| | vertices :: darts :: words => do | |
| let (parsed, trailing) ← (parseRows q) vertices darts darts words | |
| if trailing = [] then | |
| if length_ok : parsed.length = darts then | |
| let rows : Rows q vertices darts := ⟨parsed.toArray, by simpa using length_ok⟩ | |
| if valid : Valid rows then some ⟨vertices, darts, rows, valid⟩ else none | |
| else none | |
| else none | |
| | _ => none | |
| @[simp] theorem decodeTableWords_encoded (table : (Table q)) : | |
| (decodeTableWords q) (tableWords table) = some table := by | |
| cases table with | |
| | mk vertices darts rows valid => | |
| have parsed := parseRows_encoded rows.toList [] | |
| simp only [Vector.length_toList, List.append_nil] at parsed | |
| simp [tableWords, rowList, decodeTableWords, parsed, valid, Vector.toArray_toList] | |
| def decodeTableBits (q : Nat) (bits : List Bool) : Option (Table q) := | |
| decodeWords bits >>= (decodeTableWords q) | |
| @[simp] theorem decodeTableBits_encoded (table : (Table q)) : | |
| (decodeTableBits q) (tableBits table) = some table := by | |
| simp [decodeTableBits, tableBits] | |
| def encoding (q : Nat) : Computability.Encoding (Table q) Bool where | |
| encode := tableBits | |
| decode := (decodeTableBits q) | |
| decode_encode := decodeTableBits_encoded | |
| theorem tableBits_injective : Function.Injective (tableBits (q := q)) := (encoding q).encode_injective | |
| @[simp] theorem rowWords_length {n m : Nat} (row : DartRow q n m) : | |
| (rowWords row).length = (q * q + 2) := by | |
| simp only [rowWords, List.length_append, List.length_cons, List.length_nil, | |
| relationWords_length] | |
| omega | |
| theorem rowsWords_length {n m : Nat} (rows : List (DartRow q n m)) : | |
| (rows.flatMap rowWords).length = (q * q + 2) * rows.length := by | |
| induction rows with | |
| | nil => rfl | |
| | cons row rows ih => simp [ih, Nat.mul_add, Nat.add_comm] | |
| @[simp] theorem tableWords_length (table : (Table q)) : | |
| (tableWords table).length = 2 + (q * q + 2) * table.darts := by | |
| simp only [tableWords, List.length_append, List.length_cons, List.length_nil, | |
| rowsWords_length, rowList_length] | |
| theorem tableWords_length_le_bits (table : (Table q)) : | |
| 2 + (q * q + 2) * table.darts ≤ (tableBits table).length := by | |
| rw [tableBits, encodeWords_length, ← tableWords_length] | |
| omega | |
| theorem relationBits_length_le (relation : (RelationTable q)) : | |
| (encodeWords (relationWords relation)).length ≤ (2 * (q * q)) := by | |
| have h := encodeWords_length_le (relationWords relation) 1 (by | |
| intro word hword | |
| obtain ⟨bit, _, rfl⟩ := List.mem_map.mp hword | |
| cases bit <;> decide) | |
| simpa only [relationWords_length, Nat.mul_comm] using h | |
| theorem rowBits_length_le {n m : Nat} (row : DartRow q n m) : | |
| (encodeWords (rowWords row)).length ≤ n + m + (2 * (q * q)) := by | |
| have ht := row.tail.isLt | |
| have hr := row.reverseIndex.isLt | |
| have hp := relationBits_length_le row.relation | |
| simp only [rowWords, encodeWords_append, List.length_append, encodeWords, | |
| encodeWord_length, List.length_nil] at ⊢ | |
| omega | |
| theorem rowsBits_length_le {n m : Nat} (rows : List (DartRow q n m)) : | |
| (encodeWords (rows.flatMap rowWords)).length ≤ rows.length * (n + m + (2 * (q * q))) := by | |
| induction rows with | |
| | nil => simp [encodeWords] | |
| | cons row rows ih => | |
| have hrow := rowBits_length_le row | |
| simp only [List.flatMap_cons, encodeWords_append, List.length_append, | |
| List.length_cons, Nat.add_mul, Nat.one_mul] | |
| omega | |
| theorem tableBits_length_le (table : (Table q)) : | |
| (tableBits table).length ≤ table.vertices + table.darts + 2 + | |
| table.darts * (table.vertices + table.darts + (2 * (q * q))) := by | |
| have hrows := rowsBits_length_le (rowList table) | |
| rw [rowList_length] at hrows | |
| simp only [tableBits, tableWords, encodeWords_append, List.length_append, | |
| encodeWords, encodeWord_length, List.length_nil] | |
| omega | |
| theorem vertices_le_tableBits_length (table : (Table q)) : | |
| table.vertices ≤ (tableBits table).length := by | |
| simp only [tableBits, tableWords, encodeWords_append, List.length_append, | |
| encodeWords, encodeWord_length, List.length_nil] | |
| omega | |
| theorem darts_le_tableBits_length (table : (Table q)) : | |
| table.darts ≤ (tableBits table).length := by | |
| simp only [tableBits, tableWords, encodeWords_append, List.length_append, | |
| encodeWords, encodeWord_length, List.length_nil] | |
| omega | |
| end DFVSGames.Foundations.PCP.GenericGraphTables | |
| end OAI | |
Xet Storage Details
- Size:
- 36.8 kB
- Xet hash:
- 4b9354dcfe53e751aa3a50bf369539dae5e1ce10f7ac30f0d098638f9758603f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.