openAI-math-dataset / lean /OAI /Computability /DirectedFeedback /Machines /MachineExpanderRowLookup.lean
Download lean/OAI/Computability/DirectedFeedback/Machines/MachineExpanderRowLookup.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 39.1 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/DirectedFeedback/Machines/MachineExpanderRowLookup.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/DirectedFeedback/Machines/MachineExpanderRowLookup.lean
-
curl -L -o MachineExpanderRowLookup.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/DirectedFeedback/Machines/MachineExpanderRowLookup.lean
39.1 kB
| import Mathlib | |
| import OAI.Computability.DirectedFeedback.Machines.MachineExpanderFamilyTapes | |
| namespace OAI | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| namespace DFVSGames.Foundations.Complexity.MachineExpanderRow | |
| open Turing | |
| open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords | |
| open MachineComposition | |
| def lookupPhaseLabel {d : Nat} (second : Bool) | |
| (l : MachinePreservingLookupClean.Label) : Label d := | |
| if second then .secondLookup l else .firstLookup l | |
| def scanPhaseLabel {d : Nat} (second : Bool) : Label d := | |
| if second then .secondScan else .firstScan | |
| def reversePhaseLabel {d : Nat} (second : Bool) : Label d := | |
| if second then .secondReverse else .firstReverse | |
| def lookupPhasePort {d : Nat} (second : Bool) (control : Control d) : Fin (degree d) := | |
| if second then secondOffset control else firstOffset control | |
| def lookupPhaseAddress {d : Nat} (second : Bool) (vertex : Nat) (control : Control d) : Nat := | |
| if second then secondAddress vertex control else firstAddress vertex control | |
| theorem lookupPhaseAddress_eq_rowIndex {v d : Nat} (second : Bool) | |
| (vertex : Fin v) (control : Control d) : | |
| lookupPhaseAddress second vertex.val control = | |
| (rowIndex v (degree d) (vertex, lookupPhasePort second control)).val := by | |
| cases second | |
| · exact firstAddress_eq_rowIndex vertex control | |
| · exact secondAddress_eq_rowIndex vertex control | |
| theorem lookupTape_injective : Function.Injective lookupTape := by decide | |
| variable {K Λ ρ : Type} [DecidableEq K] [Fintype ρ] | |
| def lookupResultTapes (ports : Tape → K) (base : K → List Bool) | |
| (value : Nat) (indexSuffix : List Bool) : K → List Bool := | |
| MachinePreservingLookup.initialTapes (ports ∘ lookupTape) base 0 indexSuffix [] | |
| (encodeWord value ++ base (ports .lookupOutput)) | |
| theorem lookupResultTapes_index (ports : Tape → K) (distinct : Function.Injective ports) | |
| (base : K → List Bool) (value : Nat) (indexSuffix : List Bool) : | |
| lookupResultTapes ports base value indexSuffix (ports .queryIndex) = | |
| encodeWord 0 ++ indexSuffix := by | |
| apply MachineLookup.tapes_index | |
| · exact fun h => (by decide : Tape.queryIndex ≠ .lookupWork) (distinct h) | |
| · exact fun h => (by decide : Tape.queryIndex ≠ .lookupOutput) (distinct h) | |
| theorem lookupResultTapes_work (ports : Tape → K) (distinct : Function.Injective ports) | |
| (base : K → List Bool) (value : Nat) (indexSuffix : List Bool) : | |
| lookupResultTapes ports base value indexSuffix (ports .lookupWork) = [] := by | |
| apply MachineLookup.tapes_source | |
| exact fun h => (by decide : Tape.lookupWork ≠ .lookupOutput) (distinct h) | |
| theorem lookupResultTapes_output (ports : Tape → K) | |
| (base : K → List Bool) (value : Nat) (indexSuffix : List Bool) : | |
| lookupResultTapes ports base value indexSuffix (ports .lookupOutput) = | |
| encodeWord value ++ base (ports .lookupOutput) := by | |
| apply MachineLookup.tapes_destination | |
| theorem lookupResultTapes_other (ports : Tape → K) (base : K → List Bool) | |
| (value : Nat) (indexSuffix : List Bool) (p : K) | |
| (hi : p ≠ ports .queryIndex) (hw : p ≠ ports .lookupWork) | |
| (ho : p ≠ ports .lookupOutput) : | |
| lookupResultTapes ports base value indexSuffix p = base p := by | |
| exact MachineLookup.tapes_other _ _ _ p hi hw ho _ _ _ _ | |
| theorem lookupResultTapes_table (ports : Tape → K) (distinct : Function.Injective ports) | |
| (base : K → List Bool) (value : Nat) (indexSuffix : List Bool) : | |
| lookupResultTapes ports base value indexSuffix (ports .table) = base (ports .table) := by | |
| apply lookupResultTapes_other | |
| all_goals intro h; have := distinct h; cases this | |
| theorem lookupResultTapes_restore (ports : Tape → K) (distinct : Function.Injective ports) | |
| (base : K → List Bool) (value : Nat) (indexSuffix : List Bool) : | |
| lookupResultTapes ports base value indexSuffix (ports .lookupRestore) = | |
| base (ports .lookupRestore) := by | |
| apply lookupResultTapes_other | |
| all_goals intro h; have := distinct h; cases this | |
| section Lookup | |
| variable {v d : Nat} (second : Bool) (positive : 0 < d) | |
| (H : Table (cloudSize d) d) (ports : Tape → K) | |
| (distinct : Function.Injective ports) (labels : Label d → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d)) | |
| (code : ∀ l, target (labels l) = statement positive H ports labels exit l) | |
| (base : K → List Bool) (G : Table v (degree d)) | |
| (tableWord : base (ports .table) = encodeWords (rotationWords G)) | |
| (scratchEmpty : base (ports .lookupRestore) = []) | |
| (x : Fin v × Fin (degree d)) (indexSuffix : List Bool) | |
| (counterWord : base (ports .queryIndex) = | |
| encodeWord (rowIndex v (degree d) x).val ++ indexSuffix) | |
| (workEmpty : base (ports .lookupWork) = []) | |
| (ambient : (Ambient ρ d × Fin (degree d)) × Unit) (register : Option Bool) | |
| include positive H distinct exit code tableWord scratchEmpty counterWord workEmpty | |
| theorem lookupPhaseTrace : | |
| (advance (TM2.step target))^[MachinePreservingLookupClean.steps | |
| (rotationWords G) (rowIndex v (degree d) x).val] | |
| (some ⟨some (labels (lookupPhaseLabel second (.run .copyFirst))), | |
| (ambient, register), base⟩) = | |
| some ⟨some (labels (scanPhaseLabel second)), (ambient, none), | |
| lookupResultTapes ports base (reverseIndex G (rowIndex v (degree d) x)).val | |
| indexSuffix⟩ := by | |
| apply MachinePreservingLookupClean.traceAt_fromTapes (ports ∘ lookupTape) | |
| (distinct.comp lookupTape_injective) | |
| (fun l => labels (lookupPhaseLabel second l)) (some (labels (scanPhaseLabel second))) | |
| target | |
| · intro l | |
| cases second | |
| · exact code (.firstLookup l) | |
| · exact code (.secondLookup l) | |
| · exact tableWord | |
| · exact scratchEmpty | |
| · exact rotationWords_getElem? G (rowIndex v (degree d) x) | |
| · exact counterWord | |
| · exact workEmpty | |
| def lookupPhaseInTime : | |
| StateTransition.EvalsToInTime (TM2.step target) | |
| ⟨some (labels (lookupPhaseLabel second (.run .copyFirst))), | |
| (ambient, register), base⟩ | |
| (some ⟨some (labels (scanPhaseLabel second)), (ambient, none), | |
| lookupResultTapes ports base (reverseIndex G (rowIndex v (degree d) x)).val | |
| indexSuffix⟩) | |
| (6 * (encodeWords (rotationWords G)).length + 4) where | |
| steps := MachinePreservingLookupClean.steps (rotationWords G) (rowIndex v (degree d) x).val | |
| evals_in_steps := lookupPhaseTrace second positive H ports distinct labels exit target code | |
| base G tableWord scratchEmpty x indexSuffix counterWord workEmpty ambient register | |
| steps_le_m := MachinePreservingLookupClean.steps_le (rotationWords G) _ _ | |
| (rotationWords_getElem? G (rowIndex v (degree d) x)) | |
| end Lookup | |
| section Reverse | |
| variable {d : Nat} (second : Bool) (positive : 0 < d) | |
| (H : Table (cloudSize d) d) (ports : Tape → K) | |
| (distinct : Function.Injective ports) (labels : Label d → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d)) | |
| (code : ∀ l, target (labels l) = statement positive H ports labels exit l) | |
| (base : K → List Bool) | |
| (ambient : (Ambient ρ d × Fin (degree d)) × Unit) (register : Option Bool) | |
| include positive H distinct exit code | |
| theorem reversePhaseTrace : | |
| (advance (TM2.step target))^[(base (ports .queryReverse)).length + 1] | |
| (some ⟨some (labels (reversePhaseLabel second)), (ambient, register), base⟩) = | |
| some ⟨some (labels (lookupPhaseLabel second (.run .copyFirst))), (ambient, none), | |
| Reduction.MachineTransfer.tapesAt (ports .queryReverse) (ports .queryIndex) base [] | |
| ((base (ports .queryReverse)).reverse ++ base (ports .queryIndex))⟩ := by | |
| have h := Reduction.MachineTransfer.transferAt_fromTapes | |
| (ports .queryReverse) (ports .queryIndex) | |
| (fun h => (by decide : Tape.queryReverse ≠ .queryIndex) (distinct h)) | |
| id false (labels (reversePhaseLabel second)) | |
| (some (labels (lookupPhaseLabel second (.run .copyFirst)))) target | |
| (by cases second <;> exact code _) base ambient register | |
| unfold Reduction.MachineTransfer.nextAt at h | |
| unfold advance | |
| simpa only [List.map_id] using h | |
| def reversePhaseInTime : | |
| StateTransition.EvalsToInTime (TM2.step target) | |
| ⟨some (labels (reversePhaseLabel second)), (ambient, register), base⟩ | |
| (some ⟨some (labels (lookupPhaseLabel second (.run .copyFirst))), (ambient, none), | |
| Reduction.MachineTransfer.tapesAt (ports .queryReverse) (ports .queryIndex) base [] | |
| ((base (ports .queryReverse)).reverse ++ base (ports .queryIndex))⟩) | |
| ((base (ports .queryReverse)).length + 1) where | |
| steps := (base (ports .queryReverse)).length + 1 | |
| evals_in_steps := reversePhaseTrace second positive H ports distinct labels exit target code | |
| base ambient register | |
| steps_le_m := Nat.le_refl _ | |
| theorem reversePhaseTrace_unary (index : Nat) (suffix : List Bool) | |
| (queryWord : base (ports .queryReverse) = (encodeWord index).reverse) | |
| (indexWord : base (ports .queryIndex) = suffix) : | |
| (advance (TM2.step target))^[index + 2] | |
| (some ⟨some (labels (reversePhaseLabel second)), (ambient, register), base⟩) = | |
| some ⟨some (labels (lookupPhaseLabel second (.run .copyFirst))), (ambient, none), | |
| Reduction.MachineTransfer.tapesAt (ports .queryReverse) (ports .queryIndex) base [] | |
| (encodeWord index ++ suffix)⟩ := by | |
| have h := reversePhaseTrace second positive H ports distinct labels exit target code | |
| base ambient register | |
| simpa only [queryWord, indexWord, List.length_reverse, encodeWord_length, | |
| List.reverse_reverse, Nat.add_assoc] using h | |
| end Reverse | |
| end DFVSGames.Foundations.Complexity.MachineExpanderRow | |
| end | |
| section | |
| namespace DFVSGames.Foundations.Complexity.MachineExpanderRow | |
| open Turing MachineComposition | |
| open PCP.ExpanderTables PCP.ExpanderRowControl | |
| @[simp] private theorem dirtyTape_zero : dirtyTape 0 = .queryIndex := rfl | |
| @[simp] private theorem dirtyTape_one : dirtyTape 1 = .lookupOutput := rfl | |
| @[simp] private theorem dirtyTape_two : dirtyTape 2 = .quotientFirst := rfl | |
| @[simp] private theorem dirtyTape_three : dirtyTape 3 = .quotientSecond := rfl | |
| @[simp] private theorem dirtyTape_four : dirtyTape 4 = .remainderFirst := rfl | |
| @[simp] private theorem dirtyTape_five : dirtyTape 5 = .remainderSecond := rfl | |
| variable {K Λ ρ : Type} [DecidableEq K] | |
| def cleanupTapes (ports : Tape → K) (base : K → List Bool) : K → List Bool := | |
| Function.update | |
| (Function.update | |
| (Function.update | |
| (Function.update | |
| (Function.update | |
| (Function.update base (ports .queryIndex) []) | |
| (ports .lookupOutput) []) | |
| (ports .quotientFirst) []) | |
| (ports .quotientSecond) []) | |
| (ports .remainderFirst) []) | |
| (ports .remainderSecond) [] | |
| def cleanupSteps (ports : Tape → K) (base : K → List Bool) : Nat := | |
| ((base (ports .queryIndex)).length + 1) + | |
| ((base (ports .lookupOutput)).length + 1) + | |
| ((base (ports .quotientFirst)).length + 1) + | |
| ((base (ports .quotientSecond)).length + 1) + | |
| ((base (ports .remainderFirst)).length + 1) + | |
| ((base (ports .remainderSecond)).length + 1) | |
| omit [DecidableEq K] in | |
| theorem cleanupSteps_eq_sum (ports : Tape → K) (base : K → List Bool) : | |
| cleanupSteps ports base = ∑ i : Fin 6, ((base (ports (dirtyTape i))).length + 1) := by | |
| simp [cleanupSteps, Fin.sum_univ_succ, Nat.add_assoc] | |
| @[simp] theorem cleanupTapes_dirty (ports : Tape → K) (distinct : Function.Injective ports) | |
| (base : K → List Bool) (i : Fin 6) : | |
| cleanupTapes ports base (ports (dirtyTape i)) = [] := by | |
| fin_cases i <;> | |
| simp [cleanupTapes, distinct.eq_iff] | |
| theorem cleanupTapes_other (ports : Tape → K) (base : K → List Bool) (k : K) | |
| (outside : ∀ i : Fin 6, k ≠ ports (dirtyTape i)) : | |
| cleanupTapes ports base k = base k := by | |
| have h0 := outside 0 | |
| have h1 := outside 1 | |
| have h2 := outside 2 | |
| have h3 := outside 3 | |
| have h4 := outside 4 | |
| have h5 := outside 5 | |
| change k ≠ ports .queryIndex at h0 | |
| change k ≠ ports .lookupOutput at h1 | |
| change k ≠ ports .quotientFirst at h2 | |
| change k ≠ ports .quotientSecond at h3 | |
| change k ≠ ports .remainderFirst at h4 | |
| change k ≠ ports .remainderSecond at h5 | |
| simp [cleanupTapes, h0, h1, h2, h3, h4, h5] | |
| @[simp] theorem cleanupTapes_table (ports : Tape → K) (distinct : Function.Injective ports) | |
| (base : K → List Bool) : | |
| cleanupTapes ports base (ports .table) = base (ports .table) := by | |
| simp [cleanupTapes, distinct.eq_iff] | |
| @[simp] theorem cleanupTapes_inputVertex (ports : Tape → K) | |
| (distinct : Function.Injective ports) (base : K → List Bool) : | |
| cleanupTapes ports base (ports .inputVertex) = base (ports .inputVertex) := by | |
| simp [cleanupTapes, distinct.eq_iff] | |
| @[simp] theorem cleanupTapes_output (ports : Tape → K) (distinct : Function.Injective ports) | |
| (base : K → List Bool) : | |
| cleanupTapes ports base (ports .output) = base (ports .output) := by | |
| simp [cleanupTapes, distinct.eq_iff] | |
| private theorem join_trace_inline_MachineExpanderRowCleanup {A : Type*} {f : A → A} {m n : Nat} {a b c : A} | |
| (first : f^[m] a = b) (second : f^[n] b = c) : f^[m + n] a = c := by | |
| rw [Nat.add_comm m n, Function.iterate_add_apply, first, second] | |
| variable [Fintype ρ] {d : Nat} | |
| theorem cleanupOneTraceAt (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ports : Tape → K) (labels : Label d → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d)) | |
| (code : ∀ label, target (labels label) = statement positive H ports labels exit label) | |
| (i : Fin 6) (base : K → List Bool) (state : State ρ d) : | |
| (advance (TM2.step target))^[((base (ports (dirtyTape i))).length + 1)] | |
| (some ⟨some (labels (.cleanup i)), state, base⟩) = | |
| some ⟨some (if hi : i.val + 1 < 6 then labels (.cleanup ⟨i.val + 1, hi⟩) | |
| else labels .done), | |
| (state.1, none), Function.update base (ports (dirtyTape i)) []⟩ := by | |
| have run := MachineDrain.drainTrace (ports (dirtyTape i)) (labels (.cleanup i)) | |
| (some (if hi : i.val + 1 < 6 then labels (.cleanup ⟨i.val + 1, hi⟩) | |
| else labels .done)) target | |
| (by simpa only [statement] using code (.cleanup i)) | |
| base (base (ports (dirtyTape i))) state.1 state.2 | |
| simpa only [Function.update_eq_self] using run | |
| theorem cleanupTraceAt (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ports : Tape → K) (distinct : Function.Injective ports) | |
| (labels : Label d → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d)) | |
| (code : ∀ label, target (labels label) = statement positive H ports labels exit label) | |
| (base : K → List Bool) (state : State ρ d) : | |
| (advance (TM2.step target))^[cleanupSteps ports base] | |
| (some ⟨some (labels (.cleanup 0)), state, base⟩) = | |
| some ⟨some (labels .done), (state.1, none), cleanupTapes ports base⟩ := by | |
| let t1 := Function.update base (ports .queryIndex) [] | |
| let t2 := Function.update t1 (ports .lookupOutput) [] | |
| let t3 := Function.update t2 (ports .quotientFirst) [] | |
| let t4 := Function.update t3 (ports .quotientSecond) [] | |
| let t5 := Function.update t4 (ports .remainderFirst) [] | |
| have h0 := cleanupOneTraceAt positive H ports labels exit target code 0 base state | |
| have h1 := cleanupOneTraceAt positive H ports labels exit target code 1 t1 (state.1, none) | |
| have h2 := cleanupOneTraceAt positive H ports labels exit target code 2 t2 (state.1, none) | |
| have h3 := cleanupOneTraceAt positive H ports labels exit target code 3 t3 (state.1, none) | |
| have h4 := cleanupOneTraceAt positive H ports labels exit target code 4 t4 (state.1, none) | |
| have h5 := cleanupOneTraceAt positive H ports labels exit target code 5 t5 (state.1, none) | |
| simp [t1, t2, t3, t4, t5, distinct.eq_iff, | |
| -Function.iterate_succ] at h0 h1 h2 h3 h4 h5 | |
| have finished := join_trace_inline_MachineExpanderRowCleanup (join_trace_inline_MachineExpanderRowCleanup (join_trace_inline_MachineExpanderRowCleanup (join_trace_inline_MachineExpanderRowCleanup (join_trace_inline_MachineExpanderRowCleanup h0 h1) h2) h3) h4) h5 | |
| simpa only [cleanupSteps, cleanupTapes] using finished | |
| theorem doneStepAt (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ports : Tape → K) (labels : Label d → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d)) | |
| (code : ∀ label, target (labels label) = statement positive H ports labels exit label) | |
| (base : K → List Bool) (state : State ρ d) : | |
| TM2.step target ⟨some (labels .done), state, base⟩ = some ⟨exit, state, base⟩ := by | |
| change some (TM2.stepAux (target (labels .done)) state base) = _ | |
| rw [code] | |
| cases exit <;> rfl | |
| theorem cleanupExitTraceAt (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ports : Tape → K) (distinct : Function.Injective ports) | |
| (labels : Label d → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d)) | |
| (code : ∀ label, target (labels label) = statement positive H ports labels exit label) | |
| (base : K → List Bool) (state : State ρ d) : | |
| (advance (TM2.step target))^[cleanupSteps ports base + 1] | |
| (some ⟨some (labels (.cleanup 0)), state, base⟩) = | |
| some ⟨exit, (state.1, none), cleanupTapes ports base⟩ := by | |
| have cleaned := cleanupTraceAt positive H ports distinct labels exit target code base state | |
| have done : (advance (TM2.step target))^[1] | |
| (some ⟨some (labels .done), (state.1, none), cleanupTapes ports base⟩) = | |
| some ⟨exit, (state.1, none), cleanupTapes ports base⟩ := by | |
| simpa only [Function.iterate_one, advance_some] using | |
| doneStepAt positive H ports labels exit target code (cleanupTapes ports base) (state.1, none) | |
| exact join_trace_inline_MachineExpanderRowCleanup cleaned done | |
| def initializedTapes (ports : Tape → K) (base : K → List Bool) : K → List Bool := | |
| Function.update | |
| (Function.update | |
| (Function.update | |
| (Function.update base (ports .quotientFirst) (false :: base (ports .quotientFirst))) | |
| (ports .quotientSecond) (false :: base (ports .quotientSecond))) | |
| (ports .remainderFirst) (false :: base (ports .remainderFirst))) | |
| (ports .remainderSecond) (false :: base (ports .remainderSecond)) | |
| theorem initializeStepAt (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ports : Tape → K) (distinct : Function.Injective ports) | |
| (labels : Label d → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d)) | |
| (code : ∀ label, target (labels label) = statement positive H ports labels exit label) | |
| (base : K → List Bool) (state : State ρ d) : | |
| TM2.step target ⟨some (labels .initialize), state, base⟩ = | |
| some ⟨some (labels (.firstEmit (PCP.AlphabetTable.Emitter.labelAt 3 _ 0 .entry))), | |
| (state.1, none), initializedTapes ports base⟩ := by | |
| change some (TM2.stepAux (target (labels .initialize)) state base) = _ | |
| rw [code] | |
| simp [statement, TM2.stepAux, initializedTapes, distinct.eq_iff] | |
| def clearedQueryTapes (ports : Tape → K) (base : K → List Bool) : K → List Bool := | |
| Function.update | |
| (Function.update base (ports .queryIndex) (base (ports .queryIndex)).tail) | |
| (ports .lookupOutput) (base (ports .lookupOutput)).tail | |
| theorem clearQueryStepAt (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ports : Tape → K) (distinct : Function.Injective ports) | |
| (labels : Label d → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d)) | |
| (code : ∀ label, target (labels label) = statement positive H ports labels exit label) | |
| (base : K → List Bool) (state : State ρ d) : | |
| TM2.step target ⟨some (labels .clearQuery), state, base⟩ = | |
| some ⟨some (labels (.secondEmit (PCP.AlphabetTable.Emitter.labelAt 3 _ 0 .entry))), | |
| state, clearedQueryTapes ports base⟩ := by | |
| change some (TM2.stepAux (target (labels .clearQuery)) state base) = _ | |
| rw [code] | |
| simp [statement, TM2.stepAux, clearedQueryTapes, distinct.eq_iff] | |
| end DFVSGames.Foundations.Complexity.MachineExpanderRow | |
| end | |
| section | |
| namespace DFVSGames.Foundations.Complexity.MachineExpanderRow | |
| open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords | |
| structure RowData (v d : Nat) where | |
| oldTable : Table v (degree d) | |
| smallTable : Table (cloudSize d) d | |
| inputVertex : Fin v | |
| inputCloud : Fin (cloudSize d) | |
| inputPort : Fin (degree d) | |
| def rowData {v d : Nat} (G : Table v (degree d)) (H : Table (cloudSize d) d) | |
| (vertex : Fin v) (cloud : Fin (cloudSize d)) (port : Fin (degree d)) : RowData v d := | |
| ⟨G, H, vertex, cloud, port⟩ | |
| namespace RowData | |
| variable {v d : Nat} (r : RowData v d) | |
| def control0 : Control d := start r.smallTable r.inputCloud r.inputPort | |
| def firstRow : Fin (v * degree d) := rowIndex v (degree d) (r.inputVertex, firstOffset r.control0) | |
| def firstValue : Nat := (reverseIndex r.oldTable r.firstRow).val | |
| def firstPair : Fin v × Fin (degree d) := lookup r.oldTable (r.inputVertex, firstOffset r.control0) | |
| def firstVertex : Fin v := r.firstPair.1 | |
| def firstReturn : Fin (degree d) := r.firstPair.2 | |
| def control1 : Control d := receiveFirst r.control0 r.firstReturn | |
| def secondRow : Fin (v * degree d) := rowIndex v (degree d) (r.firstVertex, secondOffset r.control1) | |
| def secondValue : Nat := (reverseIndex r.oldTable r.secondRow).val | |
| def secondPair : Fin v × Fin (degree d) := lookup r.oldTable (r.firstVertex, secondOffset r.control1) | |
| def secondVertex : Fin v := r.secondPair.1 | |
| def secondReturn : Fin (degree d) := r.secondPair.2 | |
| def control2 : Control d := receiveSecond r.smallTable r.control1 r.secondReturn | |
| def query1 : Nat := firstAddress r.inputVertex.val r.control0 | |
| def query2 : Nat := secondAddress r.firstVertex.val r.control1 | |
| def finalValue : Nat := outputAddress r.secondVertex.val r.control2 | |
| def tableLength : Nat := (encodeWords (rotationWords r.oldTable)).length | |
| theorem query1_eq_firstRow : r.query1 = r.firstRow.val := | |
| firstAddress_eq_rowIndex r.inputVertex r.control0 | |
| theorem query2_eq_secondRow : r.query2 = r.secondRow.val := | |
| secondAddress_eq_rowIndex r.firstVertex r.control1 | |
| @[simp] theorem firstValue_div_degree : r.firstValue / degree d = r.firstVertex.val := rfl | |
| @[simp] theorem firstValue_mod_degree : r.firstValue % degree d = r.firstReturn.val := rfl | |
| @[simp] theorem secondValue_div_degree : r.secondValue / degree d = r.secondVertex.val := rfl | |
| @[simp] theorem secondValue_mod_degree : r.secondValue % degree d = r.secondReturn.val := rfl | |
| theorem firstReturn_eq_residue (positive : 0 < d) : | |
| r.firstReturn = MachineFixedDivMod.residue (degree d) (Nat.mul_pos positive positive) | |
| r.firstValue := Fin.ext rfl | |
| theorem secondReturn_eq_residue (positive : 0 < d) : | |
| r.secondReturn = MachineFixedDivMod.residue (degree d) (Nat.mul_pos positive positive) | |
| r.secondValue := Fin.ext rfl | |
| theorem receiveFirst_residue_eq_control1 (positive : 0 < d) : | |
| receiveFirst r.control0 (MachineFixedDivMod.residue (degree d) | |
| (Nat.mul_pos positive positive) r.firstValue) = r.control1 := by | |
| rw [← r.firstReturn_eq_residue positive] | |
| rfl | |
| theorem receiveSecond_residue_eq_control2 (positive : 0 < d) : | |
| receiveSecond r.smallTable r.control1 (MachineFixedDivMod.residue (degree d) | |
| (Nat.mul_pos positive positive) r.secondValue) = r.control2 := by | |
| rw [← r.secondReturn_eq_residue positive] | |
| rfl | |
| theorem firstSelected : (rotationWords r.oldTable)[r.query1]? = some r.firstValue := by | |
| rw [query1_eq_firstRow] | |
| exact rotationWords_getElem? r.oldTable r.firstRow | |
| theorem secondSelected : (rotationWords r.oldTable)[r.query2]? = some r.secondValue := by | |
| rw [query2_eq_secondRow] | |
| exact rotationWords_getElem? r.oldTable r.secondRow | |
| theorem evaluateRow_eq : evaluateRow r.oldTable r.smallTable r.inputVertex r.inputCloud r.inputPort = | |
| (r.secondVertex, r.control2) := rfl | |
| theorem finalValue_eq_step_reverseIndex : | |
| r.finalValue = (reverseIndex (step r.oldTable r.smallTable) | |
| (rowIndex (v * cloudSize d) (degree d) | |
| (rowIndex v (cloudSize d) (r.inputVertex, r.inputCloud), r.inputPort))).val := by | |
| simpa only [evaluateRow_eq, finalValue] using outputAddress_eq_step_reverseIndex | |
| r.oldTable r.smallTable r.inputVertex r.inputCloud r.inputPort | |
| theorem rows_le_tableLength : v * degree d ≤ r.tableLength := by | |
| simp only [tableLength, encodeWords_length, rotationWords_length] | |
| omega | |
| theorem query1_le_tableLength : r.query1 ≤ r.tableLength := by | |
| rw [query1_eq_firstRow] | |
| exact r.firstRow.isLt.le.trans r.rows_le_tableLength | |
| theorem query2_le_tableLength : r.query2 ≤ r.tableLength := by | |
| rw [query2_eq_secondRow] | |
| exact r.secondRow.isLt.le.trans r.rows_le_tableLength | |
| theorem firstValue_le_tableLength : r.firstValue ≤ r.tableLength := | |
| (reverseIndex r.oldTable r.firstRow).isLt.le.trans r.rows_le_tableLength | |
| theorem secondValue_le_tableLength : r.secondValue ≤ r.tableLength := | |
| (reverseIndex r.oldTable r.secondRow).isLt.le.trans r.rows_le_tableLength | |
| theorem inputVertex_le_tableLength : r.inputVertex.val ≤ r.tableLength := by | |
| have hq : 1 ≤ degree d := Nat.zero_lt_of_lt r.inputPort.isLt | |
| have hv : v ≤ v * degree d := by simpa using Nat.mul_le_mul_left v hq | |
| exact r.inputVertex.isLt.le.trans (hv.trans r.rows_le_tableLength) | |
| theorem firstVertex_le_tableLength : r.firstVertex.val ≤ r.tableLength := by | |
| rw [← firstValue_div_degree] | |
| exact (Nat.div_le_self r.firstValue (degree d)).trans r.firstValue_le_tableLength | |
| theorem secondVertex_le_tableLength : r.secondVertex.val ≤ r.tableLength := by | |
| rw [← secondValue_div_degree] | |
| exact (Nat.div_le_self r.secondValue (degree d)).trans r.secondValue_le_tableLength | |
| theorem firstReturn_le_tableLength : r.firstReturn.val ≤ r.tableLength := by | |
| rw [← firstValue_mod_degree] | |
| exact (Nat.mod_le r.firstValue (degree d)).trans r.firstValue_le_tableLength | |
| theorem secondReturn_le_tableLength : r.secondReturn.val ≤ r.tableLength := by | |
| rw [← secondValue_mod_degree] | |
| exact (Nat.mod_le r.secondValue (degree d)).trans r.secondValue_le_tableLength | |
| end RowData | |
| variable {v d : Nat} | |
| def frameContents (r : RowData v d) (output : List Bool) | |
| (qr qi lo q1 q2 r1 r2 : List Bool) : Tape → List Bool | |
| | .inputVertex => encodeWord r.inputVertex.val | |
| | .table => encodeWords (rotationWords r.oldTable) | |
| | .output => output | |
| | .queryReverse => qr | |
| | .queryIndex => qi | |
| | .lookupOutput => lo | |
| | .quotientFirst => q1 | |
| | .quotientSecond => q2 | |
| | .remainderFirst => r1 | |
| | .remainderSecond => r2 | |
| | _ => [] | |
| def frame0 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| frameContents r output [] [] [] [] [] [] [] | |
| def frame1 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| initializedTapes id (frame0 r output) | |
| def frame2 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| emittedWord .queryReverse (frame1 r output) r.query1 | |
| def frame3 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| Reduction.MachineTransfer.tapesAt .queryReverse .queryIndex (frame2 r output) [] | |
| (encodeWord r.query1) | |
| def frame4 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| lookupResultTapes id (frame3 r output) r.firstValue [] | |
| def frame5 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| divisionOutput d id .quotientFirst .remainderFirst (frame4 r output) r.firstValue [] [] [] | |
| def frame6 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| clearedQueryTapes id (frame5 r output) | |
| def frame7 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| emittedWord .queryReverse (frame6 r output) r.query2 | |
| def frame8 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| Reduction.MachineTransfer.tapesAt .queryReverse .queryIndex (frame7 r output) [] | |
| (encodeWord r.query2) | |
| def frame9 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| lookupResultTapes id (frame8 r output) r.secondValue [] | |
| def frame10 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| divisionOutput d id .quotientSecond .remainderSecond (frame9 r output) r.secondValue [] [] [] | |
| def frame11 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| emittedWord .output (frame10 r output) r.finalValue | |
| def frame12 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| cleanupTapes id (frame11 r output) | |
| private theorem lookupResultTapes_id_eq_inline_MachineExpanderRowFrames (base : Tape → List Bool) | |
| (value : Nat) (suffix : List Bool) : | |
| lookupResultTapes id base value suffix = | |
| Function.update | |
| (Function.update (Function.update base .queryIndex (encodeWord 0 ++ suffix)) | |
| .lookupWork []) | |
| .lookupOutput (encodeWord value ++ base .lookupOutput) := rfl | |
| @[simp] theorem frame1_eq (r : RowData v d) (output : List Bool) : | |
| frame1 r output = frameContents r output [] [] [] | |
| (encodeWord 0) (encodeWord 0) (encodeWord 0) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame1, frame0, frameContents, initializedTapes, encodeWord] | |
| @[simp] theorem frame2_eq (r : RowData v d) (output : List Bool) : | |
| frame2 r output = frameContents r output (encodeWord r.query1).reverse [] [] | |
| (encodeWord 0) (encodeWord 0) (encodeWord 0) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame2, frameContents, emittedWord] | |
| @[simp] theorem frame3_eq (r : RowData v d) (output : List Bool) : | |
| frame3 r output = frameContents r output [] (encodeWord r.query1) [] | |
| (encodeWord 0) (encodeWord 0) (encodeWord 0) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame3, frameContents, Reduction.MachineTransfer.tapesAt] | |
| @[simp] theorem frame4_eq (r : RowData v d) (output : List Bool) : | |
| frame4 r output = frameContents r output [] (encodeWord 0) (encodeWord r.firstValue) | |
| (encodeWord 0) (encodeWord 0) (encodeWord 0) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame4, lookupResultTapes_id_eq_inline_MachineExpanderRowFrames, frameContents] | |
| @[simp] theorem frame5_eq (r : RowData v d) (output : List Bool) : | |
| frame5 r output = frameContents r output [] (encodeWord 0) (encodeWord 0) | |
| (encodeWord r.firstVertex.val) (encodeWord 0) | |
| (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame5, divisionOutput, MachineFixedDivMod.unaryTapes, MachineFixedDivMod.tapes, MachineCopy.forkTapes, frameContents] | |
| @[simp] theorem frame6_eq (r : RowData v d) (output : List Bool) : | |
| frame6 r output = frameContents r output [] [] [] (encodeWord r.firstVertex.val) | |
| (encodeWord 0) (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame6, clearedQueryTapes, frameContents, encodeWord] | |
| @[simp] theorem frame7_eq (r : RowData v d) (output : List Bool) : | |
| frame7 r output = frameContents r output (encodeWord r.query2).reverse [] [] | |
| (encodeWord r.firstVertex.val) (encodeWord 0) | |
| (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame7, emittedWord, frameContents] | |
| @[simp] theorem frame8_eq (r : RowData v d) (output : List Bool) : | |
| frame8 r output = frameContents r output [] (encodeWord r.query2) [] | |
| (encodeWord r.firstVertex.val) (encodeWord 0) | |
| (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame8, Reduction.MachineTransfer.tapesAt, frameContents] | |
| @[simp] theorem frame9_eq (r : RowData v d) (output : List Bool) : | |
| frame9 r output = frameContents r output [] (encodeWord 0) (encodeWord r.secondValue) | |
| (encodeWord r.firstVertex.val) (encodeWord 0) | |
| (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame9, lookupResultTapes_id_eq_inline_MachineExpanderRowFrames, frameContents] | |
| @[simp] theorem frame10_eq (r : RowData v d) (output : List Bool) : | |
| frame10 r output = frameContents r output [] (encodeWord 0) (encodeWord 0) | |
| (encodeWord r.firstVertex.val) (encodeWord r.secondVertex.val) | |
| (encodeWord r.firstReturn.val) (encodeWord r.secondReturn.val) := by | |
| funext tape | |
| cases tape <;> simp [frame10, divisionOutput, MachineFixedDivMod.unaryTapes, MachineFixedDivMod.tapes, MachineCopy.forkTapes, frameContents] | |
| @[simp] theorem frame11_eq (r : RowData v d) (output : List Bool) : | |
| frame11 r output = frameContents r ((encodeWord r.finalValue).reverse ++ output) | |
| [] (encodeWord 0) (encodeWord 0) | |
| (encodeWord r.firstVertex.val) (encodeWord r.secondVertex.val) | |
| (encodeWord r.firstReturn.val) (encodeWord r.secondReturn.val) := by | |
| funext tape | |
| cases tape <;> simp [frame11, emittedWord, frameContents] | |
| @[simp] theorem frame12_eq (r : RowData v d) (output : List Bool) : | |
| frame12 r output = frameContents r ((encodeWord r.finalValue).reverse ++ output) | |
| [] [] [] [] [] [] [] := by | |
| funext tape | |
| cases tape <;> simp [frame12, cleanupTapes, frameContents] | |
| theorem final_frame_eq (r : RowData v d) (output : List Bool) : | |
| frame12 r output = emittedWord .output (frame0 r output) r.finalValue := by | |
| funext tape | |
| cases tape <;> simp [frame0, emittedWord, frameContents] | |
| @[simp] theorem frame0_inputVertex (r : RowData v d) (output : List Bool) : | |
| frame0 r output .inputVertex = encodeWord r.inputVertex.val := rfl | |
| @[simp] theorem frame0_table (r : RowData v d) (output : List Bool) : | |
| frame0 r output .table = encodeWords (rotationWords r.oldTable) := rfl | |
| @[simp] theorem frame0_output (r : RowData v d) (output : List Bool) : | |
| frame0 r output .output = output := rfl | |
| @[simp] theorem frame1_inputVertex (r : RowData v d) (output : List Bool) : | |
| frame1 r output .inputVertex = encodeWord r.inputVertex.val := by simp [frameContents] | |
| @[simp] theorem frame1_emitScratch (r : RowData v d) (output : List Bool) : | |
| frame1 r output .emitScratch = [] := by simp [frameContents] | |
| @[simp] theorem frame2_queryReverse (r : RowData v d) (output : List Bool) : | |
| frame2 r output .queryReverse = (encodeWord r.query1).reverse := by simp [frameContents] | |
| @[simp] theorem frame2_queryIndex (r : RowData v d) (output : List Bool) : | |
| frame2 r output .queryIndex = [] := by simp [frameContents] | |
| @[simp] theorem frame3_table (r : RowData v d) (output : List Bool) : | |
| frame3 r output .table = encodeWords (rotationWords r.oldTable) := by simp [frameContents] | |
| @[simp] theorem frame3_lookupRestore (r : RowData v d) (output : List Bool) : | |
| frame3 r output .lookupRestore = [] := by simp [frameContents] | |
| @[simp] theorem frame3_lookupWork (r : RowData v d) (output : List Bool) : | |
| frame3 r output .lookupWork = [] := by simp [frameContents] | |
| @[simp] theorem frame3_lookupOutput (r : RowData v d) (output : List Bool) : | |
| frame3 r output .lookupOutput = [] := by simp [frameContents] | |
| @[simp] theorem frame3_queryIndex (r : RowData v d) (output : List Bool) : | |
| frame3 r output .queryIndex = encodeWord r.query1 := by simp [frameContents] | |
| @[simp] theorem frame4_lookupOutput (r : RowData v d) (output : List Bool) : | |
| frame4 r output .lookupOutput = encodeWord r.firstValue := by simp [frameContents] | |
| @[simp] theorem frame4_quotientFirst (r : RowData v d) (output : List Bool) : | |
| frame4 r output .quotientFirst = encodeWord 0 := by simp [frameContents] | |
| @[simp] theorem frame4_remainderFirst (r : RowData v d) (output : List Bool) : | |
| frame4 r output .remainderFirst = encodeWord 0 := by simp [frameContents] | |
| @[simp] theorem frame6_quotientFirst (r : RowData v d) (output : List Bool) : | |
| frame6 r output .quotientFirst = encodeWord r.firstVertex.val := by simp [frameContents] | |
| @[simp] theorem frame6_emitScratch (r : RowData v d) (output : List Bool) : | |
| frame6 r output .emitScratch = [] := by simp [frameContents] | |
| @[simp] theorem frame7_queryReverse (r : RowData v d) (output : List Bool) : | |
| frame7 r output .queryReverse = (encodeWord r.query2).reverse := by simp [frameContents] | |
| @[simp] theorem frame7_queryIndex (r : RowData v d) (output : List Bool) : | |
| frame7 r output .queryIndex = [] := by simp [frameContents] | |
| @[simp] theorem frame8_table (r : RowData v d) (output : List Bool) : | |
| frame8 r output .table = encodeWords (rotationWords r.oldTable) := by simp [frameContents] | |
| @[simp] theorem frame8_lookupRestore (r : RowData v d) (output : List Bool) : | |
| frame8 r output .lookupRestore = [] := by simp [frameContents] | |
| @[simp] theorem frame8_lookupWork (r : RowData v d) (output : List Bool) : | |
| frame8 r output .lookupWork = [] := by simp [frameContents] | |
| @[simp] theorem frame8_lookupOutput (r : RowData v d) (output : List Bool) : | |
| frame8 r output .lookupOutput = [] := by simp [frameContents] | |
| @[simp] theorem frame8_queryIndex (r : RowData v d) (output : List Bool) : | |
| frame8 r output .queryIndex = encodeWord r.query2 := by simp [frameContents] | |
| @[simp] theorem frame9_lookupOutput (r : RowData v d) (output : List Bool) : | |
| frame9 r output .lookupOutput = encodeWord r.secondValue := by simp [frameContents] | |
| @[simp] theorem frame9_quotientSecond (r : RowData v d) (output : List Bool) : | |
| frame9 r output .quotientSecond = encodeWord 0 := by simp [frameContents] | |
| @[simp] theorem frame9_remainderSecond (r : RowData v d) (output : List Bool) : | |
| frame9 r output .remainderSecond = encodeWord 0 := by simp [frameContents] | |
| @[simp] theorem frame10_quotientSecond (r : RowData v d) (output : List Bool) : | |
| frame10 r output .quotientSecond = encodeWord r.secondVertex.val := by simp [frameContents] | |
| @[simp] theorem frame10_emitScratch (r : RowData v d) (output : List Bool) : | |
| frame10 r output .emitScratch = [] := by simp [frameContents] | |
| @[simp] theorem frame10_output (r : RowData v d) (output : List Bool) : | |
| frame10 r output .output = output := by simp [frameContents] | |
| theorem final_dirty_word_length_le (r : RowData v d) (output : List Bool) (i : Fin 6) : | |
| ((frame11 r output) (dirtyTape i)).length ≤ r.tableLength + 1 := by | |
| have h1 := r.firstVertex_le_tableLength | |
| have h2 := r.secondVertex_le_tableLength | |
| have h3 := r.firstReturn_le_tableLength | |
| have h4 := r.secondReturn_le_tableLength | |
| fin_cases i <;> simp only [frame11_eq, dirtyTape, frameContents, encodeWord_length] <;> omega | |
| theorem cleanupSteps_le_tableLength (r : RowData v d) (output : List Bool) : | |
| cleanupSteps id (frame11 r output) ≤ 6 * (r.tableLength + 1) + 6 := by | |
| have h1 := r.firstVertex_le_tableLength | |
| have h2 := r.secondVertex_le_tableLength | |
| have h3 := r.firstReturn_le_tableLength | |
| have h4 := r.secondReturn_le_tableLength | |
| simp only [cleanupSteps, frame11_eq, id_eq, frameContents, encodeWord_length] | |
| omega | |
| end DFVSGames.Foundations.Complexity.MachineExpanderRow | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end OAI | |