Download lean/OAI/Computability/DirectedFeedback/Games/InitialGraph.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 32.1 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/DirectedFeedback/Games/InitialGraph.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/DirectedFeedback/Games/InitialGraph.lean
-
curl -L -o InitialGraph.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/DirectedFeedback/Games/InitialGraph.lean
32.1 kB
| import Mathlib | |
| import OAI.Computability.DirectedFeedback.Encoding.Queries | |
| namespace OAI | |
| namespace DFVSGames.Foundations.PCP.InitialGraph | |
| open Target | |
| abbrev Label := Bool × Bool × Bool | |
| abbrev Vertex (F : Formula) := (Fin F.«variables» ⊕ Fin F.clauses.length) ⊕ Unit | |
| abbrev Dart (F : Formula) := (RandomEvent F × Bool) ⊕ Unit | |
| instance slotFintype : Fintype Slot where | |
| elems := {Slot.first, Slot.second, Slot.third} | |
| complete := by intro s; cases s <;> simp | |
| @[simp] theorem card_slot : Fintype.card Slot = 3 := by decide | |
| @[simp] theorem card_label : Fintype.card Label = 8 := by | |
| simp [Label, Fintype.card_prod] | |
| def variableVertex (F : Formula) (v : Fin F.«variables») : Vertex F := .inl (.inl v) | |
| def clauseVertex (F : Formula) (i : Fin F.clauses.length) : Vertex F := .inl (.inr i) | |
| def dummyVertex (F : Formula) : Vertex F := .inr () | |
| def dummyDart (F : Formula) : Dart F := .inr () | |
| instance vertexNonempty (F : Formula) : Nonempty (Vertex F) := ⟨dummyVertex F⟩ | |
| instance dartNonempty (F : Formula) : Nonempty (Dart F) := ⟨dummyDart F⟩ | |
| def reverse (F : Formula) : Dart F → Dart F | |
| | .inl (event, orientation) => .inl (event, !orientation) | |
| | .inr _ => .inr () | |
| theorem reverse_involutive (F : Formula) : Function.Involutive (reverse F) := by | |
| intro d | |
| cases d with | |
| | inl pair => rcases pair with ⟨e, b⟩; cases b <;> rfl | |
| | inr u => cases u; rfl | |
| def reverseEquiv (F : Formula) : Dart F ≃ Dart F where | |
| toFun := reverse F | |
| invFun := reverse F | |
| left_inv := reverse_involutive F | |
| right_inv := reverse_involutive F | |
| def tail (F : Formula) : Dart F → Vertex F | |
| | .inl (event, false) => clauseVertex F event.1 | |
| | .inl (event, true) => variableVertex F (nameAt (clauseAt F event.1) event.2) | |
| | .inr _ => dummyVertex F | |
| def toClauseAnswer (label : Label) : ClauseAnswer := ⟨label.1, label.2.1, label.2.2⟩ | |
| def fromClauseAnswer (answer : ClauseAnswer) : Label := (answer.first, answer.second, answer.third) | |
| def variableLabel (value : Bool) : Label := (value, false, false) | |
| @[simp] theorem to_fromClauseAnswer (answer : ClauseAnswer) : | |
| toClauseAnswer (fromClauseAnswer answer) = answer := by | |
| cases answer; rfl | |
| def variableValid (label : Label) : Bool := | |
| decide (label.2.1 = false ∧ label.2.2 = false) | |
| def incidenceAccept (F : Formula) (event : RandomEvent F) | |
| (clauseLabel variableAnswer : Label) : Bool := | |
| variableValid variableAnswer && | |
| (localSatisfies (clauseAt F event.1) (toClauseAnswer clauseLabel) && | |
| decide (answerAt (toClauseAnswer clauseLabel) event.2 = variableAnswer.1)) | |
| def predicate (F : Formula) : Dart F → Label → Label → Bool | |
| | .inl (event, false), a, b => incidenceAccept F event a b | |
| | .inl (event, true), a, b => incidenceAccept F event b a | |
| | .inr _, _, _ => true | |
| def raw (F : Formula) : ConstraintGraph (Vertex F) (Dart F) Label where | |
| reverse := reverseEquiv F | |
| reverse_involutive := reverse_involutive F | |
| tail := tail F | |
| accepts := predicate F | |
| reverse_accepts := by | |
| intro d a b | |
| cases d with | |
| | inl pair => rcases pair with ⟨event, orientation⟩; cases orientation <;> rfl | |
| | inr u => rfl | |
| theorem raw_forward (F : Formula) (labeling : Vertex F → Label) (event : RandomEvent F) : | |
| (raw F).edgeSatisfied labeling (.inl (event, false)) = | |
| incidenceAccept F event (labeling (clauseVertex F event.1)) | |
| (labeling (variableVertex F (nameAt (clauseAt F event.1) event.2))) := rfl | |
| theorem incidenceAccept_true (F : Formula) (event : RandomEvent F) (a b : Label) | |
| (h : incidenceAccept F event a b = true) : | |
| localSatisfies (clauseAt F event.1) (toClauseAnswer a) = true ∧ | |
| answerAt (toClauseAnswer a) event.2 = b.1 := by | |
| simp only [incidenceAccept, Bool.and_eq_true, decide_eq_true_eq] at h | |
| exact h.2 | |
| def honestLabeling (F : Formula) (A : Fin F.«variables» → Bool) : Vertex F → Label | |
| | .inl (.inl v) => variableLabel (A v) | |
| | .inl (.inr i) => fromClauseAnswer (honestAnswer (clauseAt F i) A) | |
| | .inr _ => variableLabel false | |
| theorem incidence_honest (F : Formula) (A : Fin F.«variables» → Bool) | |
| (sat : ∀ c ∈ F.clauses, c.eval A = true) (event : RandomEvent F) : | |
| incidenceAccept F event (honestLabeling F A (clauseVertex F event.1)) | |
| (honestLabeling F A (variableVertex F (nameAt (clauseAt F event.1) event.2))) = true := by | |
| have hc : (clauseAt F event.1).eval A = true := sat _ (List.getElem_mem _) | |
| simp [incidenceAccept, honestLabeling, clauseVertex, variableVertex, variableLabel, | |
| variableValid, honest_satisfies, honest_answerAt, hc] | |
| theorem raw_completeness (F : Formula) (sat : F.Satisfiable) : (raw F).Satisfiable := by | |
| rcases sat with ⟨A, hA⟩ | |
| refine ⟨honestLabeling F A, fun d => ?_⟩ | |
| cases d with | |
| | inl pair => | |
| rcases pair with ⟨event, orientation⟩ | |
| cases orientation <;> exact incidence_honest F A hA event | |
| | inr u => rfl | |
| theorem clauseAnswer_eq_of_slots (a b : ClauseAnswer) | |
| (h : ∀ s, answerAt a s = answerAt b s) : a = b := by | |
| rcases a with ⟨a₀, a₁, a₂⟩ | |
| rcases b with ⟨b₀, b₁, b₂⟩ | |
| have h₀ : a₀ = b₀ := h .first | |
| have h₁ : a₁ = b₁ := h .second | |
| have h₂ : a₂ = b₂ := h .third | |
| cases h₀; cases h₁; cases h₂; rfl | |
| theorem raw_reflects (F : Formula) (sat : (raw F).Satisfiable) : F.Satisfiable := by | |
| rcases sat with ⟨labeling, hlabeling⟩ | |
| let A : Fin F.«variables» → Bool := fun v => (labeling (variableVertex F v)).1 | |
| have slot_correct (i : Fin F.clauses.length) (s : Slot) : | |
| localSatisfies (clauseAt F i) (toClauseAnswer (labeling (clauseVertex F i))) = true ∧ | |
| answerAt (toClauseAnswer (labeling (clauseVertex F i))) s = | |
| A (nameAt (clauseAt F i) s) := by | |
| exact incidenceAccept_true F (i, s) _ _ (hlabeling (.inl ((i, s), false))) | |
| have clause_correct (i : Fin F.clauses.length) : (clauseAt F i).eval A = true := by | |
| have equal : toClauseAnswer (labeling (clauseVertex F i)) = honestAnswer (clauseAt F i) A := | |
| clauseAnswer_eq_of_slots _ _ (fun s => by | |
| simpa only [honest_answerAt] using (slot_correct i s).2) | |
| have satisfied := (slot_correct i .first).1 | |
| rw [equal, honest_satisfies] at satisfied | |
| exact satisfied | |
| refine ⟨A, fun c hc => ?_⟩ | |
| obtain ⟨i, hi, heq⟩ := List.getElem_of_mem hc | |
| simpa only [clauseAt, heq] using clause_correct ⟨i, hi⟩ | |
| theorem raw_satisfiable_iff (F : Formula) : (raw F).Satisfiable ↔ F.Satisfiable := | |
| ⟨raw_reflects F, raw_completeness F⟩ | |
| @[simp] theorem card_vertex (F : Formula) : | |
| Fintype.card (Vertex F) = F.«variables» + F.clauses.length + 1 := by | |
| simp [Vertex, Fintype.card_sum] | |
| @[simp] theorem card_dart (F : Formula) : | |
| Fintype.card (Dart F) = 6 * F.clauses.length + 1 := by | |
| simp [Dart, RandomEvent, Fintype.card_sum, Fintype.card_prod] | |
| omega | |
| abbrev CompactVertex (F : Formula) := Vertex (NameCompaction.compact F) | |
| abbrev CompactDart (F : Formula) := Dart (NameCompaction.compact F) | |
| def build (F : Formula) : ConstraintGraph (CompactVertex F) (CompactDart F) Label := | |
| raw (NameCompaction.compact F) | |
| theorem build_satisfiable_iff (F : Formula) : (build F).Satisfiable ↔ F.Satisfiable := by | |
| exact (raw_satisfiable_iff (NameCompaction.compact F)).trans | |
| (NameCompaction.compact_satisfiable_iff F) | |
| theorem build_vertex_bound (F : Formula) : | |
| Fintype.card (CompactVertex F) ≤ 4 * F.clauses.length + 1 := by | |
| have h := NameCompaction.compact_active_bound F | |
| simp only [CompactVertex, card_vertex, NameCompaction.compact_clause_count] | |
| omega | |
| theorem build_dart_count (F : Formula) : | |
| Fintype.card (CompactDart F) = 6 * F.clauses.length + 1 := by | |
| simp only [CompactDart, card_dart, NameCompaction.compact_clause_count] | |
| theorem build_initial_gap (F : Formula) (unsat : ¬ F.Satisfiable) | |
| (labeling : CompactVertex F → Label) : 1 ≤ (build F).rejectionCount labeling := by | |
| apply ConstraintGraph.rejectionCount_positive | |
| intro h | |
| exact unsat ((build_satisfiable_iff F).mp h) | |
| theorem build_inverse_size_gap (F : Formula) (unsat : ¬ F.Satisfiable) | |
| (labeling : CompactVertex F → Label) : | |
| Fintype.card (CompactDart F) ≤ | |
| (6 * F.clauses.length + 1) * (build F).rejectionCount labeling := by | |
| rw [build_dart_count] | |
| simpa only [Nat.mul_one] using | |
| Nat.mul_le_mul_left (6 * F.clauses.length + 1) (build_initial_gap F unsat labeling) | |
| end DFVSGames.Foundations.PCP.InitialGraph | |
| namespace DFVSGames.Foundations.PCP.AlphabetRetraction | |
| variable {V E A B : Type*} | |
| def pullback (G : ConstraintGraph V E A) (decode : B → A) : ConstraintGraph V E B where | |
| reverse := G.reverse | |
| reverse_involutive := G.reverse_involutive | |
| tail := G.tail | |
| accepts := fun e b c => G.accepts e (decode b) (decode c) | |
| reverse_accepts := fun e b c => G.reverse_accepts e (decode b) (decode c) | |
| @[simp] theorem edgeSatisfied_pullback (G : ConstraintGraph V E A) | |
| (decode : B → A) (labeling : V → B) (e : E) : | |
| (pullback G decode).edgeSatisfied labeling e = | |
| G.edgeSatisfied (decode ∘ labeling) e := rfl | |
| @[simp] theorem rejectionCount_pullback [Fintype E] (G : ConstraintGraph V E A) | |
| (decode : B → A) (labeling : V → B) : | |
| (pullback G decode).rejectionCount labeling = | |
| G.rejectionCount (decode ∘ labeling) := rfl | |
| theorem satisfiable_pullback_iff (G : ConstraintGraph V E A) | |
| (decode : B → A) (encode : A → B) (sectionLaw : ∀ a, decode (encode a) = a) : | |
| (pullback G decode).Satisfiable ↔ G.Satisfiable := by | |
| constructor | |
| · rintro ⟨labeling, h⟩ | |
| exact ⟨decode ∘ labeling, h⟩ | |
| · rintro ⟨labeling, h⟩ | |
| refine ⟨encode ∘ labeling, fun e => ?_⟩ | |
| change G.accepts e (decode (encode (labeling (G.tail e)))) | |
| (decode (encode (labeling (G.head e)))) = true | |
| simpa only [ConstraintGraph.edgeSatisfied, sectionLaw] using h e | |
| abbrev Label64 := QueryIncidence.Label 6 | |
| def decode64 (label : Label64) : InitialGraph.Label := (label 0, label 1, label 2) | |
| def encode64 (label : InitialGraph.Label) : Label64 := | |
| fun i => if i = 0 then label.1 else if i = 1 then label.2.1 else label.2.2 | |
| @[simp] theorem decode_encode64 (label : InitialGraph.Label) : | |
| decode64 (encode64 label) = label := by | |
| rcases label with ⟨a, b, c⟩ | |
| rfl | |
| def initial64 (F : DFVSGames.Foundations.Target.Formula) : | |
| ConstraintGraph (InitialGraph.CompactVertex F) (InitialGraph.CompactDart F) Label64 := | |
| pullback (InitialGraph.build F) decode64 | |
| theorem initial64_satisfiable_iff (F : DFVSGames.Foundations.Target.Formula) : | |
| (initial64 F).Satisfiable ↔ F.Satisfiable := | |
| (satisfiable_pullback_iff (InitialGraph.build F) decode64 encode64 decode_encode64).trans | |
| (InitialGraph.build_satisfiable_iff F) | |
| theorem initial64_alphabet : Fintype.card Label64 = 64 := | |
| QueryIncidence.six_query_alphabet | |
| theorem initial64_inverse_size_gap (F : DFVSGames.Foundations.Target.Formula) | |
| (unsat : ¬ F.Satisfiable) (labeling : InitialGraph.CompactVertex F → Label64) : | |
| Fintype.card (InitialGraph.CompactDart F) ≤ | |
| (6 * F.clauses.length + 1) * (initial64 F).rejectionCount labeling := | |
| InitialGraph.build_inverse_size_gap F unsat (decode64 ∘ labeling) | |
| end DFVSGames.Foundations.PCP.AlphabetRetraction | |
| namespace DFVSGames.Foundations.PCP.RawInitialTables | |
| open Target GraphTables | |
| def unitOrder : Unit ≃ Fin 1 where | |
| toFun _ := 0 | |
| invFun _ := () | |
| left_inv _ := rfl | |
| right_inv i := by fin_cases i; rfl | |
| def slotOrder : Slot ≃ Fin 3 where | |
| toFun | |
| | .first => 0 | |
| | .second => 1 | |
| | .third => 2 | |
| invFun i := if i = 0 then .first else if i = 1 then .second else .third | |
| left_inv s := by cases s <;> rfl | |
| right_inv i := by fin_cases i <;> rfl | |
| def binaryOrder (n : Nat) : (Fin n → Bool) ≃ Fin (2 ^ n) where | |
| toFun bits := (DFVSGames.Integration.BinaryCoordinates.pack bits).toFin | |
| invFun index := DFVSGames.Integration.BinaryCoordinates.unpack (BitVec.ofFin index) | |
| left_inv bits := DFVSGames.Integration.BinaryCoordinates.unpack_pack bits | |
| right_inv index := by | |
| change (DFVSGames.Integration.BinaryCoordinates.pack | |
| (DFVSGames.Integration.BinaryCoordinates.unpack (BitVec.ofFin index))).toFin = index | |
| rw [DFVSGames.Integration.BinaryCoordinates.pack_unpack] | |
| def labelOrder : AlphabetRetraction.Label64 ≃ GraphTables.Label := binaryOrder 6 | |
| def vertexOrder (F : Formula) : | |
| InitialGraph.Vertex F ≃ Fin (F.«variables» + F.clauses.length + 1) := | |
| ((finSumFinEquiv.sumCongr unitOrder).trans finSumFinEquiv) | |
| def eventOrder (F : Formula) : RandomEvent F ≃ Fin (F.clauses.length * 3) := | |
| ((Equiv.refl (Fin F.clauses.length)).prodCongr slotOrder).trans finProdFinEquiv | |
| def dartOrder (F : Formula) : InitialGraph.Dart F ≃ Fin (6 * F.clauses.length + 1) := | |
| (((((eventOrder F).prodCongr finTwoEquiv.symm).trans finProdFinEquiv).sumCongr | |
| unitOrder).trans finSumFinEquiv).trans (finCongr (by omega)) | |
| def raw64 (F : Formula) : ConstraintGraph (InitialGraph.Vertex F) | |
| (InitialGraph.Dart F) AlphabetRetraction.Label64 := | |
| AlphabetRetraction.pullback (InitialGraph.raw F) AlphabetRetraction.decode64 | |
| def table (F : Formula) : GraphTables.Table := | |
| GraphTables.ofEnumeratedGraph (raw64 F) (vertexOrder F) (dartOrder F) labelOrder | |
| @[simp] theorem table_vertices (F : Formula) : | |
| (table F).vertices = F.«variables» + F.clauses.length + 1 := rfl | |
| @[simp] theorem table_darts (F : Formula) : (table F).darts = 6 * F.clauses.length + 1 := rfl | |
| theorem table_vertices_positive (F : Formula) : 0 < (table F).vertices := by | |
| rw [table_vertices]; omega | |
| theorem table_darts_positive (F : Formula) : 0 < (table F).darts := by | |
| rw [table_darts]; omega | |
| theorem raw64_satisfiable_iff (F : Formula) : (raw64 F).Satisfiable ↔ F.Satisfiable := | |
| (AlphabetRetraction.satisfiable_pullback_iff (InitialGraph.raw F) | |
| AlphabetRetraction.decode64 AlphabetRetraction.encode64 | |
| AlphabetRetraction.decode_encode64).trans (InitialGraph.raw_satisfiable_iff F) | |
| theorem table_semantics (F : Formula) : | |
| GraphTables.semantics (table F) = | |
| (raw64 F).reindex (vertexOrder F) (dartOrder F) labelOrder := by | |
| change GraphTables.semantics (GraphTables.ofGraph | |
| (GraphTables.enumeratedGraph (raw64 F) (vertexOrder F) (dartOrder F) labelOrder)) = _ | |
| rw [GraphTables.semantics_ofGraph] | |
| rfl | |
| theorem table_satisfiable_iff (F : Formula) : | |
| (GraphTables.semantics (table F)).Satisfiable ↔ F.Satisfiable := by | |
| rw [table_semantics] | |
| exact ((raw64 F).satisfiable_reindex (vertexOrder F) (dartOrder F) labelOrder).trans | |
| (raw64_satisfiable_iff F) | |
| theorem initial_rejection (F : Formula) (unsat : ¬ F.Satisfiable) | |
| (labeling : Fin (table F).vertices → GraphTables.Label) : | |
| 1 ≤ (GraphTables.semantics (table F)).rejectionCount labeling := | |
| ConstraintGraph.rejectionCount_positive _ | |
| (fun h => unsat ((table_satisfiable_iff F).mp h)) labeling | |
| theorem initial_size (F : Formula) : | |
| (table F).vertices + (table F).darts = F.«variables» + 7 * F.clauses.length + 2 := by | |
| rw [table_vertices, table_darts] | |
| omega | |
| end DFVSGames.Foundations.PCP.RawInitialTables | |
| noncomputable section | |
| namespace DFVSGames.Foundations.PCP.FiniteGraph | |
| structure Bundle (A : Type) where | |
| Vertex : Type | |
| Dart : Type | |
| vertexFintype : Fintype Vertex | |
| dartFintype : Fintype Dart | |
| vertexDecidableEq : DecidableEq Vertex | |
| dartDecidableEq : DecidableEq Dart | |
| dartNonempty : Nonempty Dart | |
| graph : ConstraintGraph Vertex Dart A | |
| namespace Bundle | |
| variable {A : Type} | |
| instance instFintypeVertex (G : Bundle A) : Fintype G.Vertex := G.vertexFintype | |
| instance instFintypeDart (G : Bundle A) : Fintype G.Dart := G.dartFintype | |
| instance instDecidableEqVertex (G : Bundle A) : DecidableEq G.Vertex := G.vertexDecidableEq | |
| instance instDecidableEqDart (G : Bundle A) : DecidableEq G.Dart := G.dartDecidableEq | |
| instance instNonemptyDart (G : Bundle A) : Nonempty G.Dart := G.dartNonempty | |
| instance instNonemptyVertex (G : Bundle A) : Nonempty G.Vertex := by | |
| obtain ⟨d⟩ := G.dartNonempty | |
| exact ⟨G.graph.tail d⟩ | |
| def ofGraph {V E : Type} [Fintype V] [Fintype E] | |
| [DecidableEq V] [DecidableEq E] [Nonempty E] | |
| (G : ConstraintGraph V E A) : Bundle A where | |
| Vertex := V | |
| Dart := E | |
| vertexFintype := inferInstance | |
| dartFintype := inferInstance | |
| vertexDecidableEq := inferInstance | |
| dartDecidableEq := inferInstance | |
| dartNonempty := inferInstance | |
| graph := G | |
| def size (G : Bundle A) : Nat := Fintype.card G.Vertex + Fintype.card G.Dart | |
| def Satisfiable (G : Bundle A) : Prop := G.graph.Satisfiable | |
| def rejectionCount (G : Bundle A) (labeling : G.Vertex → A) : Nat := | |
| G.graph.rejectionCount labeling | |
| theorem size_positive (G : Bundle A) : 0 < G.size := | |
| lt_of_lt_of_le (Fintype.card_pos : 0 < Fintype.card G.Dart) (Nat.le_add_left _ _) | |
| theorem dartCard_le_size (G : Bundle A) : Fintype.card G.Dart ≤ G.size := | |
| Nat.le_add_left _ _ | |
| @[simp] theorem ofGraph_graph {V E : Type} [Fintype V] [Fintype E] | |
| [DecidableEq V] [DecidableEq E] [Nonempty E] (G : ConstraintGraph V E A) : | |
| (ofGraph G).graph = G := rfl | |
| @[simp] theorem ofGraph_size {V E : Type} [Fintype V] [Fintype E] | |
| [DecidableEq V] [DecidableEq E] [Nonempty E] (G : ConstraintGraph V E A) : | |
| (ofGraph G).size = Fintype.card V + Fintype.card E := rfl | |
| @[simp] theorem ofGraph_satisfiable {V E : Type} [Fintype V] [Fintype E] | |
| [DecidableEq V] [DecidableEq E] [Nonempty E] (G : ConstraintGraph V E A) : | |
| (ofGraph G).Satisfiable ↔ G.Satisfiable := Iff.rfl | |
| @[simp] theorem ofGraph_rejectionCount {V E : Type} [Fintype V] [Fintype E] | |
| [DecidableEq V] [DecidableEq E] [Nonempty E] | |
| (G : ConstraintGraph V E A) (labeling : V → A) : | |
| (ofGraph G).rejectionCount labeling = G.rejectionCount labeling := rfl | |
| variable [Fintype A] [Nonempty A] | |
| def minimumRejections (G : Bundle A) : Nat := G.graph.minimumRejections | |
| def gap (G : Bundle A) : ℝ := G.graph.gap | |
| theorem exists_minimizer (G : Bundle A) : | |
| ∃ labeling : G.Vertex → A, G.rejectionCount labeling = G.minimumRejections := | |
| G.graph.exists_minimizer | |
| theorem gap_nonnegative (G : Bundle A) : 0 ≤ G.gap := G.graph.gap_nonnegative | |
| theorem gap_le_one (G : Bundle A) : G.gap ≤ 1 := G.graph.gap_le_one | |
| theorem gap_eq_zero_iff (G : Bundle A) : G.gap = 0 ↔ G.Satisfiable := | |
| G.graph.gap_eq_zero_iff | |
| theorem le_gap_iff (G : Bundle A) (ε : ℝ) : | |
| ε ≤ G.gap ↔ ∀ labeling : G.Vertex → A, | |
| ε * Fintype.card G.Dart ≤ (G.rejectionCount labeling : ℝ) := | |
| G.graph.le_gap_iff ε | |
| theorem inverse_card_le_gap_of_unsatisfiable (G : Bundle A) (unsat : ¬ G.Satisfiable) : | |
| 1 / (Fintype.card G.Dart : ℝ) ≤ G.gap := | |
| G.graph.inverse_card_le_gap_of_unsatisfiable unsat | |
| theorem one_le_dartCard_mul_gap (G : Bundle A) (unsat : ¬ G.Satisfiable) : | |
| 1 ≤ (Fintype.card G.Dart : ℝ) * G.gap := by | |
| have he : (0 : ℝ) < Fintype.card G.Dart := by exact_mod_cast Fintype.card_pos | |
| have h := (div_le_iff₀ he).mp (G.inverse_card_le_gap_of_unsatisfiable unsat) | |
| simpa only [mul_comm] using h | |
| theorem one_le_size_mul_gap (G : Bundle A) (unsat : ¬ G.Satisfiable) : | |
| 1 ≤ (G.size : ℝ) * G.gap := by | |
| have hsize : (Fintype.card G.Dart : ℝ) ≤ (G.size : ℝ) := by | |
| exact_mod_cast G.dartCard_le_size | |
| exact (G.one_le_dartCard_mul_gap unsat).trans | |
| (mul_le_mul_of_nonneg_right hsize G.gap_nonnegative) | |
| @[simp] theorem ofGraph_minimumRejections {V E : Type} [Fintype V] [Fintype E] | |
| [DecidableEq V] [DecidableEq E] [Nonempty E] (G : ConstraintGraph V E A) : | |
| (ofGraph G).minimumRejections = G.minimumRejections := rfl | |
| @[simp] theorem ofGraph_gap {V E : Type} [Fintype V] [Fintype E] | |
| [DecidableEq V] [DecidableEq E] [Nonempty E] (G : ConstraintGraph V E A) : | |
| (ofGraph G).gap = G.gap := rfl | |
| end Bundle | |
| end DFVSGames.Foundations.PCP.FiniteGraph | |
| end | |
| namespace DFVSGames.Foundations.PCP.FinalConstants | |
| def alphabet : Nat := 64 | |
| def compositionLoss : Nat := 12288 | |
| def denominator : Nat := 16 * alphabet ^ 4 * 66 * compositionLoss | |
| def windowHalf : Nat := denominator * Preprocessing.sizeFactor | |
| def windowSize : Nat := 2 * windowHalf + 1 | |
| def smoothingScale : Nat := 4 * alphabet * windowHalf | |
| def endpointLength : Nat := smoothingScale ^ 2 | |
| def walkLength : Nat := 2 * endpointLength + 1 | |
| noncomputable def gain : ℝ := (windowSize : ℝ) / denominator | |
| noncomputable def cap : ℝ := 1 / (walkLength : ℝ) | |
| theorem denominator_positive : 0 < denominator := by | |
| norm_num [denominator, alphabet, compositionLoss] | |
| theorem windowHalf_positive : 0 < windowHalf := | |
| Nat.mul_pos denominator_positive Preprocessing.sizeFactor_positive | |
| theorem walkLength_positive : 0 < walkLength := by | |
| simp [walkLength] | |
| theorem gain_large : 2 * (Preprocessing.sizeFactor : ℝ) ≤ gain := by | |
| have hd : (0 : ℝ) < denominator := by exact_mod_cast denominator_positive | |
| apply (le_div_iff₀ hd).2 | |
| simp only [windowSize, windowHalf, Nat.cast_add, Nat.cast_mul, | |
| Nat.cast_ofNat] | |
| nlinarith | |
| theorem cap_positive : 0 < cap := by | |
| exact one_div_pos.mpr (by exact_mod_cast walkLength_positive) | |
| theorem cap_le_one : cap ≤ 1 := by | |
| apply (div_le_one (by exact_mod_cast walkLength_positive)).2 | |
| exact_mod_cast walkLength_positive | |
| theorem composed_gap (epsilon : ℝ) (he : 0 ≤ epsilon) : | |
| min (2 * epsilon) cap ≤ | |
| gain * min (epsilon / (Preprocessing.sizeFactor : ℝ)) | |
| (1 / (walkLength : ℝ)) := by | |
| have hs : (0 : ℝ) < Preprocessing.sizeFactor := by | |
| exact_mod_cast Preprocessing.sizeFactor_positive | |
| have hs1 : (1 : ℝ) ≤ Preprocessing.sizeFactor := by | |
| exact_mod_cast Preprocessing.sizeFactor_positive | |
| have hg : 0 ≤ gain := le_trans (by positivity) gain_large | |
| rw [mul_min_of_nonneg _ _ hg] | |
| apply min_le_min | |
| · calc | |
| 2 * epsilon = (2 * (Preprocessing.sizeFactor : ℝ)) * | |
| (epsilon / (Preprocessing.sizeFactor : ℝ)) := by field_simp | |
| _ ≤ gain * (epsilon / (Preprocessing.sizeFactor : ℝ)) := | |
| mul_le_mul_of_nonneg_right gain_large (div_nonneg he hs.le) | |
| · change cap ≤ gain * cap | |
| have hgain : 1 ≤ gain := by linarith [gain_large] | |
| simpa only [one_mul] using mul_le_mul_of_nonneg_right hgain cap_positive.le | |
| end DFVSGames.Foundations.PCP.FinalConstants | |
| namespace DFVSGames.Foundations.PCP.RoundTables | |
| abbrev BaseTable := PreprocessingTables.BaseTable | |
| opaque fixedWalkParameter : {n : Nat // n = 2 * FinalConstants.endpointLength} := | |
| ⟨2 * FinalConstants.endpointLength, rfl⟩ | |
| def walkParameter : Nat := fixedWalkParameter.val | |
| theorem walkParameter_eq : walkParameter = 2 * FinalConstants.endpointLength := | |
| fixedWalkParameter.property | |
| def alphabet : Nat := PoweringTables.labelCount PreprocessingTables.degree walkParameter | |
| theorem alphabet_positive : 0 < alphabet := by | |
| unfold alphabet PoweringTables.labelCount | |
| exact Nat.pow_pos (by decide) | |
| def powered (H : BaseTable) (table : GraphTables.Table) : GenericGraphTables.Table alphabet := | |
| PoweringTables.table (PreprocessingTables.preprocess H table) walkParameter | |
| def build (H : BaseTable) (table : GraphTables.Table) : GraphTables.Table := | |
| AlphabetTable.Table.build (powered H table) | |
| def sizeFactor : Nat := AlphabetGraphBounds.sizeFactor alphabet * | |
| (ExpanderFamily.growth ^ 2 * (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1))) | |
| theorem degree_positive : 0 < PreprocessingTables.degree := by | |
| unfold PreprocessingTables.degree | |
| omega | |
| theorem dartFactor_positive (q : Nat) : 0 < AlphabetGraphBounds.dartFactor q := by | |
| unfold AlphabetGraphBounds.dartFactor AlphabetGraphBounds.localEventFactor | |
| positivity | |
| theorem sizeFactor_positive : 0 < sizeFactor := by | |
| unfold sizeFactor | |
| apply Nat.mul_pos (AlphabetGraphBounds.sizeFactor_positive alphabet) | |
| apply Nat.mul_pos | |
| · exact Nat.pow_pos (Nat.zero_lt_one.trans ExpanderFamily.growth_gt_one) | |
| · omega | |
| theorem powered_vertices (H : BaseTable) (table : GraphTables.Table) : | |
| (powered H table).vertices = PreprocessingTables.vertices table := rfl | |
| theorem powered_darts (H : BaseTable) (table : GraphTables.Table) : | |
| (powered H table).darts = 2 * PreprocessingTables.vertices table * | |
| PreprocessingTables.degree ^ (walkParameter + 1) := rfl | |
| theorem build_darts_positive (H : BaseTable) (table : GraphTables.Table) : | |
| 0 < (build H table).darts := by | |
| change 0 < (AlphabetTable.Table.build (powered H table)).darts | |
| rw [AlphabetTableBounds.build_darts, powered_darts] | |
| exact Nat.mul_pos (Nat.mul_pos | |
| (Nat.mul_pos (by decide) (PreprocessingTables.vertices_positive table)) | |
| (Nat.pow_pos degree_positive)) (dartFactor_positive alphabet) | |
| theorem build_size_le (H : BaseTable) (table : GraphTables.Table) | |
| (ht : 0 < table.darts) : | |
| (build H table).vertices + (build H table).darts ≤ | |
| sizeFactor * (table.vertices + table.darts) := by | |
| have hv := PreprocessingTables.vertices_le_of_positive table ht | |
| have he : (powered H table).vertices + (powered H table).darts = | |
| PreprocessingTables.vertices table * | |
| (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1)) := by | |
| rw [powered_vertices, powered_darts] | |
| ring | |
| have hp := Nat.mul_le_mul_right | |
| (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1)) hv | |
| calc | |
| _ ≤ AlphabetGraphBounds.sizeFactor alphabet * | |
| ((powered H table).vertices + (powered H table).darts) := | |
| AlphabetTableBounds.build_total_le (powered H table) | |
| _ = AlphabetGraphBounds.sizeFactor alphabet * | |
| (PreprocessingTables.vertices table * | |
| (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1))) := by rw [he] | |
| _ ≤ AlphabetGraphBounds.sizeFactor alphabet * | |
| ((ExpanderFamily.growth ^ 2 * table.darts) * | |
| (1 + 2 * PreprocessingTables.degree ^ (walkParameter + 1))) := | |
| Nat.mul_le_mul_left _ hp | |
| _ = sizeFactor * table.darts := by unfold sizeFactor; ring | |
| _ ≤ sizeFactor * (table.vertices + table.darts) := | |
| Nat.mul_le_mul_left _ (Nat.le_add_left _ _) | |
| theorem build_completeness (H : BaseTable) (table : GraphTables.Table) | |
| (sat : (GraphTables.semantics table).Satisfiable) : | |
| (GraphTables.semantics (build H table)).Satisfiable := by | |
| let : Nonempty (Fin alphabet) := ⟨⟨0, alphabet_positive⟩⟩ | |
| exact AlphabetTable.Table.perfect_completeness (powered H table) | |
| (PoweringTableSemantics.preserves_satisfiability | |
| (PreprocessingTables.preprocess H table) walkParameter | |
| (PreprocessingGuarantees.completeness H table sat)) | |
| abbrev Input := {table : GraphTables.Table // 0 < table.darts} | |
| instance (input : Input) : Nonempty (Fin input.val.darts) := ⟨⟨0, input.property⟩⟩ | |
| def step (H : BaseTable) (input : Input) : Input := | |
| ⟨build H input.val, build_darts_positive H input.val⟩ | |
| def initial (F : Target.Formula) : Input := | |
| ⟨RawInitialTables.table F, RawInitialTables.table_darts_positive F⟩ | |
| def size (input : Input) : Nat := input.val.vertices + input.val.darts | |
| def Satisfiable (input : Input) : Prop := (GraphTables.semantics input.val).Satisfiable | |
| noncomputable def gap (input : Input) : ℝ := (GraphTables.semantics input.val).gap | |
| theorem size_positive (input : Input) : 0 < size input := | |
| input.property.trans_le (Nat.le_add_left _ _) | |
| theorem gap_nonnegative (input : Input) : 0 ≤ gap input := | |
| (GraphTables.semantics input.val).gap_nonnegative | |
| theorem gap_eq_zero_iff (input : Input) : gap input = 0 ↔ Satisfiable input := | |
| (GraphTables.semantics input.val).gap_eq_zero_iff | |
| theorem one_le_size_mul_gap (input : Input) (unsat : ¬ Satisfiable input) : | |
| 1 ≤ (size input : ℝ) * gap input := by | |
| have h := (GraphTables.semantics input.val).inverse_card_le_gap_of_unsatisfiable unsat | |
| have hp : (0 : ℝ) < input.val.darts := Nat.cast_pos.mpr input.property | |
| simp only [Fintype.card_fin] at h | |
| have hd := (div_le_iff₀ hp).mp h | |
| have hsize : (input.val.darts : ℝ) ≤ (size input : ℝ) := by | |
| exact_mod_cast (Nat.le_add_left input.val.darts input.val.vertices) | |
| exact (show 1 ≤ (input.val.darts : ℝ) * gap input by | |
| simpa only [gap, mul_comm] using hd).trans | |
| (mul_le_mul_of_nonneg_right hsize (gap_nonnegative input)) | |
| theorem initial_satisfiable_iff (F : Target.Formula) : Satisfiable (initial F) ↔ F.Satisfiable := | |
| RawInitialTables.table_satisfiable_iff F | |
| theorem step_completeness (H : BaseTable) (input : Input) : | |
| Satisfiable input → Satisfiable (step H input) := build_completeness H input.val | |
| theorem step_size (H : BaseTable) (input : Input) : | |
| size (step H input) ≤ sizeFactor * size input := build_size_le H input.val input.property | |
| end DFVSGames.Foundations.PCP.RoundTables | |
| namespace DFVSGames.Foundations.PCP.AmplificationIteration | |
| def run {X : Type*} (step : X → X) : Nat → X → X | |
| | 0, x => x | |
| | n + 1, x => step (run step n x) | |
| private theorem min_double_min_inline_AmplificationIteration (u cap : ℝ) (hc : 0 ≤ cap) : | |
| min (2 * min u cap) cap = min (2 * u) cap := by | |
| by_cases hu : u ≤ cap | |
| · rw [min_eq_left hu] | |
| · have hcu : cap ≤ u := le_of_not_ge hu | |
| rw [min_eq_right hcu, min_eq_right (by linarith : cap ≤ 2 * cap), | |
| min_eq_right (by linarith : cap ≤ 2 * u)] | |
| theorem run_gap {X : Type*} (step : X → X) (gap : X → ℝ) | |
| (cap : ℝ) (hc : 0 ≤ cap) | |
| (amplifies : ∀ x, min (2 * gap x) cap ≤ gap (step x)) | |
| (n : Nat) (x : X) : | |
| min (2 ^ n * gap x) cap ≤ gap (run step n x) := by | |
| induction n with | |
| | zero => simp [run] | |
| | succ n ih => | |
| have hm : min (2 * min (2 ^ n * gap x) cap) cap ≤ | |
| min (2 * gap (run step n x)) cap := | |
| min_le_min (mul_le_mul_of_nonneg_left ih (by norm_num)) le_rfl | |
| rw [min_double_min_inline_AmplificationIteration _ _ hc] at hm | |
| have h := hm.trans (amplifies (run step n x)) | |
| simpa [run, pow_succ, mul_assoc, mul_left_comm, mul_comm] using h | |
| theorem run_preserves {X : Type*} (step : X → X) (P : X → Prop) | |
| (preserves : ∀ x, P x → P (step x)) (n : Nat) (x : X) (hx : P x) : | |
| P (run step n x) := by | |
| induction n with | |
| | zero => exact hx | |
| | succ n ih => exact preserves _ ih | |
| theorem run_size {X : Type*} (step : X → X) (size : X → Nat) (C : Nat) | |
| (blowup : ∀ x, size (step x) ≤ C * size x) (n : Nat) (x : X) : | |
| size (run step n x) ≤ C ^ n * size x := by | |
| induction n with | |
| | zero => simp [run] | |
| | succ n ih => | |
| have h := (blowup (run step n x)).trans (Nat.mul_le_mul_left C ih) | |
| simpa [run, pow_succ, Nat.mul_assoc, Nat.mul_left_comm, Nat.mul_comm] using h | |
| def rounds (n : Nat) : Nat := Nat.log2 n + 1 | |
| theorem rounds_large (n : Nat) : n < 2 ^ rounds n := by | |
| simpa [rounds, Nat.log2_eq_log_two] using | |
| (Nat.lt_pow_succ_log_self (by decide : 1 < 2) n) | |
| theorem rounds_power_le {n : Nat} (hn : 0 < n) : 2 ^ rounds n ≤ 2 * n := by | |
| have h := Nat.pow_log_le_self 2 (Nat.ne_of_gt hn) | |
| simpa [rounds, Nat.log2_eq_log_two, pow_succ, Nat.mul_comm] using | |
| (Nat.mul_le_mul_right 2 h) | |
| theorem blowup_rounds_le {C degree n : Nat} (hn : 0 < n) (hC : C ≤ 2 ^ degree) : | |
| C ^ rounds n ≤ (2 * n) ^ degree := by | |
| calc | |
| C ^ rounds n ≤ (2 ^ degree) ^ rounds n := Nat.pow_le_pow_left hC _ | |
| _ = (2 ^ rounds n) ^ degree := by | |
| rw [← pow_mul, ← pow_mul, Nat.mul_comm degree (rounds n)] | |
| _ ≤ (2 * n) ^ degree := Nat.pow_le_pow_left (rounds_power_le hn) _ | |
| theorem run_size_polynomial {X : Type*} (step : X → X) (size : X → Nat) | |
| {C degree n : Nat} (hn : 0 < n) (hC : C ≤ 2 ^ degree) | |
| (blowup : ∀ x, size (step x) ≤ C * size x) (x : X) : | |
| size (run step (rounds n) x) ≤ (2 * n) ^ degree * size x := | |
| (run_size step size C blowup (rounds n) x).trans | |
| (Nat.mul_le_mul_right _ (blowup_rounds_le hn hC)) | |
| theorem run_reaches_cap {X : Type*} (step : X → X) (gap : X → ℝ) | |
| (cap : ℝ) (hc : 0 ≤ cap) (hc1 : cap ≤ 1) | |
| (amplifies : ∀ x, min (2 * gap x) cap ≤ gap (step x)) | |
| (n : Nat) (x : X) (hg : 0 ≤ gap x) (hstart : 1 ≤ (n : ℝ) * gap x) : | |
| cap ≤ gap (run step (rounds n) x) := by | |
| have hp : (n : ℝ) ≤ (2 : ℝ) ^ rounds n := by | |
| exact_mod_cast (Nat.le_of_lt (rounds_large n)) | |
| have hcap : cap ≤ (2 : ℝ) ^ rounds n * gap x := | |
| hc1.trans (hstart.trans (mul_le_mul_of_nonneg_right hp hg)) | |
| have h := run_gap step gap cap hc amplifies (rounds n) x | |
| rwa [min_eq_right hcap] at h | |
| end DFVSGames.Foundations.PCP.AmplificationIteration | |
| end OAI | |