cfahlgren1's picture
download
raw
50.7 kB
import Mathlib import OAI.Computability.DirectedFeedback.Machines.MachinePortReindex 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.MachineLazyRows open Turing MachineComposition PCP.GraphTables open PCP.PreprocessingLazyWords (reverseMap moveRow moveRow_words) variable {K Λ A : Type} [DecidableEq K] abbrev VertexLabel (d : Nat) := Fin (d + 1) × Option (StreamLabel d) def vertexInstruction (d : Nat) (positive : 0 < d) (c b : Nat) (tape : Fin 10 → K) (labels : VertexLabel d → Λ) (exit : Option Λ) : VertexLabel d → TM2.Stmt (fun _ : K => Bool) Λ (StreamState A d) | (i, none) => if i.val < d then .goto fun _ => labels (i, some .tailStart) else MachinePortReindex.exitAt exit | (i, some stage) => if h : i.val < d then streamInstruction d positive c b tape (fun stage => labels (i, some stage)) (some (labels (⟨i.val + 1, by omega⟩, none))) stage else MachinePortReindex.exitAt exit def recordsInput {n m : Nat} (rows : List (DartRow n m)) : List Bool := rows.flatMap (fun r => inputRowBits r.tail.val r.reverseIndex.val r.relation) def recordsOutput {n m : Nat} (d c b : Nat) (rows : List (DartRow n m)) : List Bool := rows.flatMap (fun r => reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation) def streamFrame {n m : Nat} (tape : Fin 10 → K) (base : K → List Bool) (rows : List (DartRow n m)) (output : List Bool) : K → List Bool := Function.update (Function.update base (tape 9) (recordsInput rows ++ base (tape 9))) (tape 7) output def vertexSteps {n m : Nat} (d c b : Nat) : List (DartRow n m) → List Bool → Nat | [], _ => 1 | r :: rows, output => 1 + streamRowSteps d c b r.tail.val r.reverseIndex.val r.relation output + vertexSteps d c b rows (output ++ reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation) theorem recordsInput_eq_codec {n m : Nat} (rows : List (DartRow n m)) : recordsInput rows = encodeWords (rows.flatMap rowWords) := by induction rows with | nil => rfl | cons r rows ih => simp only [recordsInput, List.flatMap_cons, encodeWords_append, MachineTableRows.rowBits_eq, inputRowBits] at ih ⊢ rw [ih] private theorem streamFrame_afterRow_inline_MachineLazyRows {n m : Nat} (d c b : Nat) (r : DartRow n m) (tape : Fin 10 → K) (distinct : Function.Injective tape) (base : K → List Bool) (rows : List (DartRow n m)) (output : List Bool) : streamResultTapes d c b r.tail.val r.reverseIndex.val r.relation tape (streamFrame tape base (r :: rows) output) (recordsInput rows ++ base (tape 9)) = streamFrame tape base rows (output ++ reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation) := by have h79 : tape 7 ≠ tape 9 := fun h => (by decide : (7 : Fin 10) ≠ 9) (distinct h) funext k by_cases h7 : k = tape 7 · subst k simp [streamResultTapes, streamFrame] · by_cases h9 : k = tape 9 · subst k simp [streamResultTapes, streamFrame, Ne.symm h79] · simp [streamResultTapes, streamFrame, h7, h9] theorem vertexSuffixTrace {n m : Nat} (d : Nat) (positive : 0 < d) (c b : Nat) (tape : Fin 10 → K) (distinct : Function.Injective tape) (labels : VertexLabel d → Λ) (exit : Option Λ) (program : Λ → TM2.Stmt (fun _ : K => Bool) Λ (StreamState A d)) (atLabels : ∀ l, program (labels l) = vertexInstruction d positive c b tape labels exit l) (base : K → List Bool) (rows : Fin d → DartRow n m) (empty : ∀ i : Fin 10, i ≠ 7 → i ≠ 9 → base (tape i) = []) (ambient : A) (remaining : Nat) (i : Fin (d + 1)) (count : i.val + remaining = d) (output : List Bool) : (advance (TM2.step program))^[vertexSteps d c b ((List.ofFn rows).drop i.val) output] (some ⟨some (labels (i, none)), streamClean d positive ambient, streamFrame tape base ((List.ofFn rows).drop i.val) output⟩) = some ⟨exit, streamClean d positive ambient, streamFrame (n := n) (m := m) tape base [] (output ++ recordsOutput d c b ((List.ofFn rows).drop i.val))⟩ := by have hd (a k : Fin 10) (h : a ≠ k) : tape a ≠ tape k := fun x => h (distinct x) induction remaining generalizing i output with | zero => have hi : i.val = d := by omega have hdrop : (List.ofFn rows).drop i.val = [] := by apply List.drop_eq_nil_of_le simp only [List.length_ofFn, hi, le_refl] rw [hdrop] simp only [vertexSteps, recordsOutput, List.flatMap_nil, List.append_nil] change some (TM2.stepAux (program (labels (i, none))) _ _) = _ rw [atLabels] cases exit <;> simp [vertexInstruction, hi, MachinePortReindex.exitAt, TM2.stepAux] | succ remaining ih => have hi : i.val < d := by omega let port : Fin d := ⟨i.val, hi⟩ let next : Fin (d + 1) := ⟨i.val + 1, by omega⟩ let rest := (List.ofFn rows).drop (i.val + 1) have split : (List.ofFn rows).drop i.val = rows port :: rest := by have h := List.getElem_cons_drop (as := List.ofFn rows) (i := i.val) (by simpa only [List.length_ofFn] using hi) simpa only [List.getElem_ofFn, port, rest] using h.symm let initial := streamFrame tape base (rows port :: rest) output have boundary : (advance (TM2.step program))^[1] (some ⟨some (labels (i, none)), streamClean d positive ambient, initial⟩) = some ⟨some (labels (i, some .tailStart)), streamClean d positive ambient, initial⟩ := by change some (TM2.stepAux (program (labels (i, none))) _ _) = _ rw [atLabels] simp [vertexInstruction, hi, TM2.stepAux] have body := streamRowTrace d positive c b tape distinct (fun stage => labels (i, some stage)) (some (labels (next, none))) program (by intro stage simpa only [vertexInstruction, hi, dite_true, next] using (atLabels (i, some stage))) initial (rows port).tail.val (rows port).reverseIndex.val (rows port).relation (recordsInput rest ++ base (tape 9)) (by simp [initial, streamFrame, hd 9 7 (by decide), recordsInput, List.append_assoc]) (by intro k hk7 hk9 simp [initial, streamFrame, hd k 7 hk7, hd k 9 hk9, empty k hk7 hk9]) ambient have initialOutput : initial (tape 7) = output := by simp [initial, streamFrame] rw [initialOutput] at body change (advance (TM2.step program))^[streamRowSteps d c b (rows port).tail.val (rows port).reverseIndex.val (rows port).relation output] (some ⟨some (labels (i, some .tailStart)), streamClean d positive ambient, initial⟩) = some ⟨some (labels (next, none)), streamClean d positive ambient, streamResultTapes d c b (rows port).tail.val (rows port).reverseIndex.val (rows port).relation tape initial (recordsInput rest ++ base (tape 9))⟩ at body rw [show streamResultTapes d c b (rows port).tail.val (rows port).reverseIndex.val (rows port).relation tape initial (recordsInput rest ++ base (tape 9)) = streamFrame tape base rest (output ++ reindexRowBits d c b (rows port).tail.val (rows port).reverseIndex.val (rows port).relation) from streamFrame_afterRow_inline_MachineLazyRows d c b (rows port) tape distinct base rest output] at body have nextCount : next.val + remaining = d := by dsimp [next]; omega have tail := ih next nextCount (output ++ reindexRowBits d c b (rows port).tail.val (rows port).reverseIndex.val (rows port).relation) change (advance (TM2.step program))^[vertexSteps d c b rest (output ++ reindexRowBits d c b (rows port).tail.val (rows port).reverseIndex.val (rows port).relation)] (some ⟨some (labels (next, none)), streamClean d positive ambient, streamFrame tape base rest (output ++ reindexRowBits d c b (rows port).tail.val (rows port).reverseIndex.val (rows port).relation)⟩) = some ⟨exit, streamClean d positive ambient, streamFrame (n := n) (m := m) tape base [] ((output ++ reindexRowBits d c b (rows port).tail.val (rows port).reverseIndex.val (rows port).relation) ++ recordsOutput d c b rest)⟩ at tail rw [split] have all := joinTrace_inline_MachineLazyRows (joinTrace_inline_MachineLazyRows boundary body) tail simpa only [vertexSteps, initial, recordsOutput, List.flatMap_cons, List.append_assoc] using all theorem vertexTrace {n m : Nat} (d : Nat) (positive : 0 < d) (c b : Nat) (tape : Fin 10 → K) (distinct : Function.Injective tape) (labels : VertexLabel d → Λ) (exit : Option Λ) (program : Λ → TM2.Stmt (fun _ : K => Bool) Λ (StreamState A d)) (atLabels : ∀ l, program (labels l) = vertexInstruction d positive c b tape labels exit l) (base : K → List Bool) (rows : Fin d → DartRow n m) (empty : ∀ i : Fin 10, i ≠ 7 → i ≠ 9 → base (tape i) = []) (ambient : A) (output : List Bool) : (advance (TM2.step program))^[vertexSteps d c b (List.ofFn rows) output] (some ⟨some (labels (0, none)), streamClean d positive ambient, streamFrame tape base (List.ofFn rows) output⟩) = some ⟨exit, streamClean d positive ambient, streamFrame (n := n) (m := m) tape base [] (output ++ recordsOutput d c b (List.ofFn rows))⟩ := by simpa only [Fin.val_zero, List.drop_zero] using vertexSuffixTrace d positive c b tape distinct labels exit program atLabels base rows empty ambient d 0 (by simp) output private theorem encodeWords_flatMap_inline_MachineLazyRows {α : Type*} (items : List α) (words : α → List Nat) : encodeWords (items.flatMap words) = items.flatMap (fun x => encodeWords (words x)) := by induction items with | nil => rfl | cons item items ih => simp only [List.flatMap_cons, encodeWords_append, ih] theorem recordsOutput_lazy {n d : Nat} (table : PCP.PortTables.Table n d) (v : Fin n) : recordsOutput d (2 * d) d (List.ofFn (PCP.PreprocessingLazyWords.row table v)) = encodeWords ((List.ofFn (moveRow table v)).flatMap rowWords) := by rw [encodeWords_flatMap_inline_MachineLazyRows] simp only [recordsOutput, List.flatMap_def, List.map_ofFn] apply congrArg List.flatten apply congrArg List.ofFn funext p change reindexRowBits d (2 * d) d v.val (PCP.PreprocessingLazyWords.row table v p).reverseIndex.val (PCP.PreprocessingLazyWords.row table v p).relation = encodeWords (rowWords (moveRow table v p)) have h := rowBits_eq_moveRow table v p simpa only [rowBits, reindexRowBits, MachinePortReindex.lazy_value, reverseMap] using h def valueBound (c b m : Nat) : Nat := c * m + m + b def rowSizeBound (c b n m : Nat) : Nat := n + valueBound c b m + 8194 def rowCostBound (c b n m : Nat) : Nat := 2 * n + 8 * m + valueBound c b m + 4 * rowSizeBound c b n m + 8224 theorem reindexValue_le {n m : Nat} (d c b : Nat) (r : DartRow n m) : MachinePortReindex.value d c b r.reverseIndex.val ≤ valueBound c b m := by have hj := r.reverseIndex.isLt.le have hdiv := (Nat.div_le_self r.reverseIndex.val d).trans hj have hmod := (Nat.mod_le r.reverseIndex.val d).trans hj have hmul := Nat.mul_le_mul_left c hdiv unfold MachinePortReindex.value valueBound omega theorem reindexRowBits_length_le {n m : Nat} (d c b : Nat) (r : DartRow n m) : (reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation).length ≤ rowSizeBound c b n m := by have htail := r.tail.isLt.le have hvalue := reindexValue_le d c b r have hrelation := relationBits_length_le r.relation simp only [reindexRowBits, List.length_append, encodeWord_length] unfold rowSizeBound omega theorem streamRowSteps_le {n m : Nat} (d c b : Nat) (r : DartRow n m) (output : List Bool) : streamRowSteps d c b r.tail.val r.reverseIndex.val r.relation output ≤ rowCostBound c b n m + 2 * output.length := by have htail := r.tail.isLt.le have hj := r.reverseIndex.isLt.le have hdiv := (Nat.div_le_self r.reverseIndex.val d).trans hj have hvalue := reindexValue_le d c b r have hrelation := relationBits_length_le r.relation have hsize := reindexRowBits_length_le d c b r unfold streamRowSteps reindexSteps MachinePortReindex.steps rowCostBound omega private theorem vertexSteps_le_capacity_inline_MachineLazyRows {n m : Nat} (d c b capacity : Nat) (rows : List (DartRow n m)) (output : List Bool) (room : output.length + rows.length * rowSizeBound c b n m ≤ capacity) : vertexSteps d c b rows output ≤ rows.length * (rowCostBound c b n m + 2 * capacity + 1) + 1 := by induction rows generalizing output with | nil => simp [vertexSteps] | cons r rows ih => have hsize := reindexRowBits_length_le d c b r have hcost := streamRowSteps_le d c b r output have hout : output.length ≤ capacity := by omega have hroom : (output ++ reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation).length + rows.length * rowSizeBound c b n m ≤ capacity := by rw [List.length_append] simp only [List.length_cons, Nat.succ_mul] at room omega have htail := ih (output ++ reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation) hroom change 1 + streamRowSteps d c b r.tail.val r.reverseIndex.val r.relation output + vertexSteps d c b rows (output ++ reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation) ≤ (rows.length + 1) * (rowCostBound c b n m + 2 * capacity + 1) + 1 rw [Nat.add_mul, Nat.one_mul] omega theorem vertexSteps_le {n m : Nat} (d c b : Nat) (rows : List (DartRow n m)) (output : List Bool) : vertexSteps d c b rows output ≤ rows.length * (rowCostBound c b n m + 2 * (output.length + rows.length * rowSizeBound c b n m) + 1) + 1 := vertexSteps_le_capacity_inline_MachineLazyRows d c b _ rows output (Nat.le_refl _) def vertexInTime {n m : Nat} (d : Nat) (positive : 0 < d) (c b : Nat) (tape : Fin 10 → K) (distinct : Function.Injective tape) (labels : VertexLabel d → Λ) (exit : Option Λ) (program : Λ → TM2.Stmt (fun _ : K => Bool) Λ (StreamState A d)) (atLabels : ∀ l, program (labels l) = vertexInstruction d positive c b tape labels exit l) (base : K → List Bool) (rows : Fin d → DartRow n m) (empty : ∀ i : Fin 10, i ≠ 7 → i ≠ 9 → base (tape i) = []) (ambient : A) (output : List Bool) : StateTransition.EvalsToInTime (TM2.step program) ⟨some (labels (0, none)), streamClean d positive ambient, streamFrame tape base (List.ofFn rows) output⟩ (some ⟨exit, streamClean d positive ambient, streamFrame (n := n) (m := m) tape base [] (output ++ recordsOutput d c b (List.ofFn rows))⟩) (d * (rowCostBound c b n m + 2 * (output.length + d * rowSizeBound c b n m) + 1) + 1) where steps := vertexSteps d c b (List.ofFn rows) output evals_in_steps := vertexTrace d positive c b tape distinct labels exit program atLabels base rows empty ambient output steps_le_m := by simpa only [List.length_ofFn] using vertexSteps_le d c b (List.ofFn rows) output def vertexMachine (d : Nat) (positive : 0 < d) (c b : Nat) : FinTM2 where K := Fin 10 k₀ := 9 k₁ := 7 Γ _ := Bool Λ := VertexLabel d main := (0, none) σ := StreamState Unit d initialState := streamClean d positive () m := vertexInstruction d positive c b id id none end DFVSGames.Foundations.Complexity.MachineLazyRows end section namespace DFVSGames.Foundations.PCP.PreprocessingOverlayWords open PortTables GraphTables PreprocessingOverlayTables open Complexity variable {n d e : Nat} abbrev row := @PreprocessingLazyWords.row abbrev trueRelation := PreprocessingLazyWords.trueRelation def oldReverseMap (d e j : Nat) : Nat := (d + e) * (j / d) + j % d def expanderReverseMap (d e j : Nat) : Nat := (d + e) * (j / e) + d + j % e def oldRow (G : PortTables.Table n d) (e : Nat) (v : Fin n) (p : Fin d) : DartRow n (n * (d + e)) := ⟨v, rowIndex n (d + e) ((rotation G (v, p)).1, overlayPorts d e (.inl (rotation G (v, p)).2)), G.relations[rowIndex n d (v, p)]⟩ def expanderRow (d : Nat) (H : ExpanderTables.Table n e) (v : Fin n) (p : Fin e) : DartRow n (n * (d + e)) := ⟨v, rowIndex n (d + e) ((ExpanderTables.lookup H (v, p)).1, overlayPorts d e (.inr (ExpanderTables.lookup H (v, p)).2)), trueRelation⟩ private theorem relation_ext_inline_PreprocessingOverlayWords {r s : RelationTable} (h : ∀ a b, relationAt r a b = relationAt s a b) : r = s := by apply Vector.ext intro i hi simpa only [relationAt, Prod.eta, Equiv.apply_symm_apply, Fin.getElem_fin] using h (relationIndex.symm ⟨i, hi⟩).1 (relationIndex.symm ⟨i, hi⟩).2 theorem row_overlay_old (G : PortTables.Table n d) (H : ExpanderTables.Table n e) (v : Fin n) (p : Fin d) : row (overlay G H) v (overlayPorts d e (.inl p)) = oldRow G e v p := by have hr : (overlay G H).reverseIndex[rowIndex n (d + e) (v, overlayPorts d e (.inl p))] = rowIndex n (d + e) ((rotation G (v, p)).1, overlayPorts d e (.inl (rotation G (v, p)).2)) := by rw [← rowIndex_rotation, overlay_rotation_old] have hp : (overlay G H).relations[rowIndex n (d + e) (v, overlayPorts d e (.inl p))] = G.relations[rowIndex n d (v, p)] := by apply relation_ext_inline_PreprocessingOverlayWords exact overlay_accepts_old G H v p exact congrArg₂ (DartRow.mk v) hr hp theorem row_overlay_expander (G : PortTables.Table n d) (H : ExpanderTables.Table n e) (v : Fin n) (p : Fin e) : row (overlay G H) v (overlayPorts d e (.inr p)) = expanderRow d H v p := by have hr : (overlay G H).reverseIndex[rowIndex n (d + e) (v, overlayPorts d e (.inr p))] = rowIndex n (d + e) ((ExpanderTables.lookup H (v, p)).1, overlayPorts d e (.inr (ExpanderTables.lookup H (v, p)).2)) := by rw [← rowIndex_rotation, overlay_rotation_expander] have hp : (overlay G H).relations[rowIndex n (d + e) (v, overlayPorts d e (.inr p))] = trueRelation := by apply relation_ext_inline_PreprocessingOverlayWords intro a b simpa only [PortTables.accepts, relationAt, trueRelation, PreprocessingLazyWords.trueRelation, Fin.getElem_fin, Vector.getElem_replicate] using overlay_accepts_expander G H v p a b exact congrArg₂ (DartRow.mk v) hr hp theorem oldRow_reverse_val (G : PortTables.Table n d) (v : Fin n) (p : Fin d) : (oldRow G e v p).reverseIndex.val = oldReverseMap d e (row G v p).reverseIndex.val := by simp only [oldRow, rowIndex_val, overlayPorts_inl_val, oldReverseMap, row, PreprocessingLazyWords.row] change (G.reverseIndex[rowIndex n d (v, p)]).val % d + (d + e) * ((G.reverseIndex[rowIndex n d (v, p)]).val / d) = _ omega theorem expanderRow_reverse_val (H : ExpanderTables.Table n e) (v : Fin n) (p : Fin e) : (expanderRow d H v p).reverseIndex.val = expanderReverseMap d e (ExpanderTables.reverseIndex H (ExpanderTables.rowIndex n e (v, p))).val := by simp only [expanderRow, rowIndex_val, overlayPorts_inr_val, expanderReverseMap] change d + (ExpanderTables.reverseIndex H (ExpanderTables.rowIndex n e (v, p))).val % e + (d + e) * ((ExpanderTables.reverseIndex H (ExpanderTables.rowIndex n e (v, p))).val / e) = _ omega theorem oldRow_words (G : PortTables.Table n d) (v : Fin n) (p : Fin d) : rowWords (oldRow G e v p) = [v.val, oldReverseMap d e (row G v p).reverseIndex.val] ++ relationWords (row G v p).relation := by rw [rowWords, oldRow_reverse_val] rfl theorem expanderRow_words (H : ExpanderTables.Table n e) (v : Fin n) (p : Fin e) : rowWords (expanderRow d H v p) = [v.val, expanderReverseMap d e (ExpanderTables.reverseIndex H (ExpanderTables.rowIndex n e (v, p))).val] ++ List.replicate 4096 1 := by rw [rowWords, expanderRow_reverse_val] exact congrArg (fun rs => [v.val, expanderReverseMap d e (ExpanderTables.reverseIndex H (ExpanderTables.rowIndex n e (v, p))).val] ++ rs) PreprocessingLazyWords.relationWords_true theorem ofFn_overlayPorts {α : Type*} (f : Fin (d + e) → α) : List.ofFn f = List.ofFn (fun p => f (overlayPorts d e (.inl p))) ++ List.ofFn (fun p => f (overlayPorts d e (.inr p))) := by rw [List.ofFn_add] rfl def vertexRows (G : PortTables.Table n d) (H : ExpanderTables.Table n e) (v : Fin n) : List (DartRow n (n * (d + e))) := List.ofFn (oldRow G e v) ++ List.ofFn (expanderRow d H v) theorem vertexRows_length (G : PortTables.Table n d) (H : ExpanderTables.Table n e) (v : Fin n) : (vertexRows G H v).length = d + e := by simp only [vertexRows, List.length_append, List.length_ofFn] theorem flatRows_overlay (G : PortTables.Table n d) (H : ExpanderTables.Table n e) : (flatRows (overlay G H)).toList = (List.ofFn (vertexRows G H)).flatten := by rw [PreprocessingLazyWords.flatRows_list] apply congrArg List.flatten congr 1 funext v rw [ofFn_overlayPorts] simp only [row_overlay_old, row_overlay_expander] rfl theorem vertexRows_words (G : PortTables.Table n d) (H : ExpanderTables.Table n e) (v : Fin n) : (vertexRows G H v).flatMap rowWords = (List.ofFn fun p : Fin d => [v.val, oldReverseMap d e (row G v p).reverseIndex.val] ++ relationWords (row G v p).relation).flatten ++ (List.ofFn fun p : Fin e => [v.val, expanderReverseMap d e (ExpanderTables.reverseIndex H (ExpanderTables.rowIndex n e (v, p))).val] ++ List.replicate 4096 1).flatten := by have ho : rowWords ∘ oldRow G e v = fun p : Fin d => [v.val, oldReverseMap d e (row G v p).reverseIndex.val] ++ relationWords (row G v p).relation := by funext p exact oldRow_words G v p have he : rowWords ∘ expanderRow d H v = fun p : Fin e => [v.val, expanderReverseMap d e (ExpanderTables.reverseIndex H (ExpanderTables.rowIndex n e (v, p))).val] ++ List.replicate 4096 1 := by funext p exact expanderRow_words H v p simp only [vertexRows, List.flatMap_def, List.map_append, List.map_ofFn, List.flatten_append] rw [ho, he] theorem tableWords_overlay (G : PortTables.Table n d) (H : ExpanderTables.Table n e) : PortTables.tableWords (overlay G H) = [n, n * (d + e)] ++ (List.ofFn (vertexRows G H)).flatten.flatMap rowWords := by rw [PortTables.tableWords_eq, flatRows_overlay] theorem tableBits_overlay (G : PortTables.Table n d) (H : ExpanderTables.Table n e) : PortTables.tableBits (overlay G H) = encodeWords ([n, n * (d + e)] ++ (List.ofFn (vertexRows G H)).flatten.flatMap rowWords) := by change encodeWords (PortTables.tableWords (overlay G H)) = _ rw [tableWords_overlay] theorem rotationWords_vertices (H : ExpanderTables.Table n e) : ExpanderTableWords.rotationWords H = (List.ofFn fun v : Fin n => List.ofFn fun p : Fin e => (ExpanderTables.reverseIndex H (ExpanderTables.rowIndex n e (v, p))).val).flatten := by have hflat : ExpanderTableWords.rotationWords H = List.ofFn (fun i : Fin (n * e) => (ExpanderTables.reverseIndex H i).val) := by apply List.ext_getElem · simp [ExpanderTableWords.rotationWords_length] · intro i hi hj rw [ExpanderTableWords.rotationWords_getElem H i (by simpa using hi)] simp only [List.getElem_ofFn] rw [hflat, PreprocessingLazyWords.ofFn_rowIndex] rfl end DFVSGames.Foundations.PCP.PreprocessingOverlayWords end section namespace DFVSGames.Foundations.Complexity.MachineOverlayRows open Turing MachineComposition open PCP.GraphTables PCP.PreprocessingOverlayWords open Reduction.MachineSubstitution (pushWord stepAux_pushWord) variable {K Λ A : Type} [DecidableEq K] abbrev State (A : Type) (e : Nat) := MachinePortReindex.State A e inductive Label (e : Nat) | loadStart | loadLoop | seedRelation | row (stage : MachineLazyRows.Label e) | drainOld | drainNew | drainRelation deriving DecidableEq, Fintype def bodyIndex (i : Fin 9) : Fin 10 := i.castSucc theorem bodyIndex_injective : Function.Injective bodyIndex := by intro i j h exact Fin.castSucc_injective 9 h def trueBits : List Bool := encodeWords (relationWords trueRelation) def instruction (d e : Nat) (positive : 0 < e) (tape : Fin 10 → K) (labels : Label e → Λ) (exit : Option Λ) : Label e → TM2.Stmt (fun _ : K => Bool) Λ (State A e) | .loadStart => Hastad.SourceMachine.fieldStart (tape 1) (labels .loadLoop) | .loadLoop => Hastad.SourceMachine.fieldLoop (tape 9) (tape 1) (labels .loadLoop) (some (labels .seedRelation)) | .seedRelation => pushWord (tape 2) trueBits.reverse (.goto fun _ => labels (.row (.inl .copySeed))) | .row stage => MachineLazyRows.reindexInstruction e positive (d + e) d (tape ∘ bodyIndex) (fun stage => labels (.row stage)) (some (labels .drainOld)) stage | .drainOld => MachineDrain.drain (tape 1) (labels .drainOld) (some (labels .drainNew)) | .drainNew => MachineDrain.drain (tape 6) (labels .drainNew) (some (labels .drainRelation)) | .drainRelation => MachineDrain.drain (tape 2) (labels .drainRelation) exit def rowBits (d e v j : Nat) : List Bool := MachineLazyRows.reindexRowBits e (d + e) d v j trueRelation def rowSteps (d e v j : Nat) (output : List Bool) : Nat := (j + 2) + 1 + MachineLazyRows.reindexSteps e (d + e) d v j trueRelation output + (j + 2) + (MachinePortReindex.value e (d + e) d j + 2) + (trueBits.length + 1) def resultTapes (d e v j : Nat) (tape : Fin 10 → K) (base : K → List Bool) (suffix : List Bool) : K → List Bool := Function.update (Function.update base (tape 9) suffix) (tape 7) (base (tape 7) ++ rowBits d e v j) private theorem joinTrace_inline_MachineOverlayRows {X : Type*} {f : X → X} {a b c : X} {n m : Nat} (first : f^[n] a = b) (second : f^[m] b = c) : f^[n + m] a = c := by rw [Nat.add_comm, Function.iterate_add_apply, first, second] theorem rowTrace (d e : Nat) (positive : 0 < e) (tape : Fin 10 → K) (distinct : Function.Injective tape) (labels : Label e → Λ) (exit : Option Λ) (program : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State A e)) (atLabels : ∀ l, program (labels l) = instruction d e positive tape labels exit l) (base : K → List Bool) (v j : Nat) (suffix : List Bool) (tailWord : base (tape 0) = encodeWord v) (inputWord : base (tape 9) = encodeWord j ++ suffix) (empty : ∀ i : Fin 10, i ≠ 0 → i ≠ 7 → i ≠ 9 → base (tape i) = []) (ambient : A) : (advance (TM2.step program))^[rowSteps d e v j (base (tape 7))] (some ⟨some (labels .loadStart), MachinePortReindex.clean e positive ambient, base⟩) = some ⟨exit, MachinePortReindex.clean e positive ambient, resultTapes d e v j tape base suffix⟩ := by have hd (i k : Fin 10) (h : i ≠ k) : tape i ≠ tape k := fun x => h (distinct x) have h₁ := empty 1 (by decide) (by decide) (by decide) have h₂ := empty 2 (by decide) (by decide) (by decide) have h₃ := empty 3 (by decide) (by decide) (by decide) have h₄ := empty 4 (by decide) (by decide) (by decide) have h₅ := empty 5 (by decide) (by decide) (by decide) have h₆ := empty 6 (by decide) (by decide) (by decide) have h₈ := empty 8 (by decide) (by decide) (by decide) have hi0 : bodyIndex 0 = 0 := rfl have hi3 : bodyIndex 3 = 3 := rfl have hi4 : bodyIndex 4 = 4 := rfl have hi5 : bodyIndex 5 = 5 := rfl have hi6 : bodyIndex 6 = 6 := rfl have hi8 : bodyIndex 8 = 8 := rfl let loaded := Function.update (Function.update base (tape 9) suffix) (tape 1) (encodeWord j) let seeded := Function.update loaded (tape 2) trueBits let rowed := MachineLazyRows.reindexResultTapes e (d + e) d v j trueRelation (tape ∘ bodyIndex) seeded let oldCleared := Function.update rowed (tape 1) [] let newCleared := Function.update oldCleared (tape 6) [] have loadRun : (advance (TM2.step program))^[j + 2] (some ⟨some (labels .loadStart), MachinePortReindex.clean e positive ambient, base⟩) = some ⟨some (labels .seedRelation), MachinePortReindex.clean e positive ambient, loaded⟩ := by have h := (Hastad.SourceMachine.fieldInTime (tape 9) (tape 1) (hd 9 1 (by decide)) (labels .loadStart) (labels .loadLoop) (some (labels .seedRelation)) program (atLabels .loadStart) (atLabels .loadLoop) base j suffix inputWord (ambient, MachineFixedDivMod.residue e positive 0) none).evals_in_steps change (advance (TM2.step program))^[j + 2] (some ⟨some (labels .loadStart), MachinePortReindex.clean e positive ambient, base⟩) = some ⟨some (labels .seedRelation), MachinePortReindex.clean e positive ambient, Hastad.SourceMachine.fieldTapes (tape 9) (tape 1) base suffix (encodeWord j ++ base (tape 1))⟩ at h simpa only [Hastad.SourceMachine.fieldTapes, h₁, List.append_nil, MachinePortReindex.clean, loaded] using h have seedRun : (advance (TM2.step program))^[1] (some ⟨some (labels .seedRelation), MachinePortReindex.clean e positive ambient, loaded⟩) = some ⟨some (labels (.row (.inl .copySeed))), MachinePortReindex.clean e positive ambient, seeded⟩ := by change some (TM2.stepAux (program (labels .seedRelation)) _ _) = _ rw [atLabels] simp [instruction, stepAux_pushWord, TM2.stepAux, seeded, loaded, hd 2 1 (by decide), hd 2 9 (by decide), h₂] have hs (i : Fin 10) (hi : i ≠ 1) (hi' : i ≠ 2) (hi'' : i ≠ 9) : seeded (tape i) = base (tape i) := by simp [seeded, loaded, hd i 1 hi, hd i 2 hi', hd i 9 hi''] have bodyRun := MachineLazyRows.reindexRowTrace e positive (d + e) d (tape ∘ bodyIndex) (distinct.comp bodyIndex_injective) (fun s => labels (.row s)) (some (labels .drainOld)) program (fun s => atLabels (.row s)) seeded v j trueRelation (by simpa only [Function.comp_apply, hi0] using (hs 0 (by decide) (by decide) (by decide)).trans tailWord) (by simp [seeded, loaded, Function.comp_apply, bodyIndex, hd 1 2 (by decide)]) (by simp [seeded, Function.comp_apply, bodyIndex, trueBits]) (by simpa only [Function.comp_apply, hi3] using (hs 3 (by decide) (by decide) (by decide)).trans h₃) (by simpa only [Function.comp_apply, hi4] using (hs 4 (by decide) (by decide) (by decide)).trans h₄) (by simpa only [Function.comp_apply, hi5] using (hs 5 (by decide) (by decide) (by decide)).trans h₅) (by simpa only [Function.comp_apply, hi6] using (hs 6 (by decide) (by decide) (by decide)).trans h₆) (by simpa only [Function.comp_apply, hi8] using (hs 8 (by decide) (by decide) (by decide)).trans h₈) ambient have hout : seeded ((tape ∘ bodyIndex) 7) = base (tape 7) := hs 7 (by decide) (by decide) (by decide) rw [hout] at bodyRun change (advance (TM2.step program))^[MachineLazyRows.reindexSteps e (d + e) d v j trueRelation (base (tape 7))] (some ⟨some (labels (.row (.inl .copySeed))), MachinePortReindex.clean e positive ambient, seeded⟩) = some ⟨some (labels .drainOld), MachinePortReindex.clean e positive ambient, rowed⟩ at bodyRun have rowedOld : rowed (tape 1) = encodeWord j := by simp [rowed, MachineLazyRows.reindexResultTapes, MachineLazyRows.reindexMappedTapes, Function.comp_apply, bodyIndex, seeded, loaded, hd 1 7 (by decide), hd 1 6 (by decide), hd 1 2 (by decide)] have rowedNew : oldCleared (tape 6) = encodeWord (MachinePortReindex.value e (d + e) d j) := by simp [oldCleared, rowed, MachineLazyRows.reindexResultTapes, MachineLazyRows.reindexMappedTapes, Function.comp_apply, bodyIndex, hd 6 1 (by decide), hd 6 7 (by decide)] have rowedRelation : newCleared (tape 2) = trueBits := by simp [newCleared, oldCleared, rowed, MachineLazyRows.reindexResultTapes, MachineLazyRows.reindexMappedTapes, Function.comp_apply, bodyIndex, seeded, hd 2 6 (by decide), hd 2 1 (by decide), hd 2 7 (by decide)] have drainOld := (MachineDrain.drainInTime (tape 1) (labels .drainOld) (some (labels .drainNew)) program (atLabels .drainOld) rowed (ambient, MachineFixedDivMod.residue e positive 0) none).evals_in_steps change (advance (TM2.step program))^[(rowed (tape 1)).length + 1] (some ⟨some (labels .drainOld), MachinePortReindex.clean e positive ambient, rowed⟩) = some ⟨some (labels .drainNew), MachinePortReindex.clean e positive ambient, oldCleared⟩ at drainOld rw [rowedOld, encodeWord_length] at drainOld have drainNew := (MachineDrain.drainInTime (tape 6) (labels .drainNew) (some (labels .drainRelation)) program (atLabels .drainNew) oldCleared (ambient, MachineFixedDivMod.residue e positive 0) none).evals_in_steps change (advance (TM2.step program))^[(oldCleared (tape 6)).length + 1] (some ⟨some (labels .drainNew), MachinePortReindex.clean e positive ambient, oldCleared⟩) = some ⟨some (labels .drainRelation), MachinePortReindex.clean e positive ambient, newCleared⟩ at drainNew rw [rowedNew, encodeWord_length] at drainNew have drainRelation := (MachineDrain.drainInTime (tape 2) (labels .drainRelation) exit program (atLabels .drainRelation) newCleared (ambient, MachineFixedDivMod.residue e positive 0) none).evals_in_steps change (advance (TM2.step program))^[(newCleared (tape 2)).length + 1] (some ⟨some (labels .drainRelation), MachinePortReindex.clean e positive ambient, newCleared⟩) = some ⟨exit, MachinePortReindex.clean e positive ambient, Function.update newCleared (tape 2) []⟩ at drainRelation rw [rowedRelation] at drainRelation have finalFrame : Function.update newCleared (tape 2) [] = resultTapes d e v j tape base suffix := by funext k by_cases h2 : k = tape 2 · subst k simp [resultTapes, hd 2 7 (by decide), hd 2 9 (by decide), h₂] · by_cases h6 : k = tape 6 · subst k simp [newCleared, resultTapes, hd 6 2 (by decide), hd 6 7 (by decide), hd 6 9 (by decide), h₆] · by_cases h1 : k = tape 1 · subst k simp [newCleared, oldCleared, resultTapes, hd 1 2 (by decide), hd 1 6 (by decide), hd 1 7 (by decide), hd 1 9 (by decide), h₁] · by_cases h7 : k = tape 7 · subst k simp [newCleared, oldCleared, rowed, MachineLazyRows.reindexResultTapes, MachineLazyRows.reindexMappedTapes, Function.comp_apply, bodyIndex, resultTapes, rowBits, seeded, loaded, hd 7 2 (by decide), hd 7 6 (by decide), hd 7 1 (by decide), hd 7 9 (by decide)] · simp [newCleared, oldCleared, rowed, MachineLazyRows.reindexResultTapes, MachineLazyRows.reindexMappedTapes, Function.comp_apply, bodyIndex, seeded, loaded, resultTapes, h2, h6, h1, h7] rw [finalFrame] at drainRelation exact joinTrace_inline_MachineOverlayRows (joinTrace_inline_MachineOverlayRows (joinTrace_inline_MachineOverlayRows (joinTrace_inline_MachineOverlayRows (joinTrace_inline_MachineOverlayRows loadRun seedRun) bodyRun) drainOld) drainNew) drainRelation theorem rowBits_eq_expanderRow {n e : Nat} (d : Nat) (H : PCP.ExpanderTables.Table n e) (v : Fin n) (p : Fin e) : rowBits d e v.val (PCP.ExpanderTables.reverseIndex H (PCP.ExpanderTables.rowIndex n e (v, p))).val = encodeWords (rowWords (expanderRow d H v p)) := by rw [expanderRow_words] have h (j : Nat) : MachinePortReindex.value e (d + e) d j = expanderReverseMap d e j := by unfold MachinePortReindex.value expanderReverseMap omega simp only [rowBits, MachineLazyRows.reindexRowBits, h, PCP.PreprocessingLazyWords.relationWords_true, List.cons_append, List.nil_append, encodeWords, List.append_assoc] def machine (d e : Nat) (positive : 0 < e) : FinTM2 where K := Fin 10 k₀ := 9 k₁ := 7 Γ _ := Bool Λ := Label e main := .loadStart σ := State Unit e initialState := MachinePortReindex.clean e positive () m := instruction d e positive id id none abbrev VertexLabel (e : Nat) := Fin (e + 1) × Option (Label e) def vertexInstruction (d e : Nat) (positive : 0 < e) (tape : Fin 10 → K) (labels : VertexLabel e → Λ) (exit : Option Λ) : VertexLabel e → TM2.Stmt (fun _ : K => Bool) Λ (State A e) | (i, none) => if i.val < e then .goto fun _ => labels (i, some .loadStart) else MachinePortReindex.exitAt exit | (i, some stage) => if h : i.val < e then instruction d e positive tape (fun stage => labels (i, some stage)) (some (labels (⟨i.val + 1, by omega⟩, none))) stage else MachinePortReindex.exitAt exit def streamFrame (tape : Fin 10 → K) (base : K → List Bool) (words : List Nat) (output : List Bool) : K → List Bool := Function.update (Function.update base (tape 9) (encodeWords words ++ base (tape 9))) (tape 7) output def streamOutput (d e v : Nat) (words : List Nat) : List Bool := words.flatMap (rowBits d e v) def vertexSteps (d e v : Nat) : List Nat → List Bool → Nat | [], _ => 1 | j :: words, output => 1 + rowSteps d e v j output + vertexSteps d e v words (output ++ rowBits d e v j) def valueBound (d e B : Nat) : Nat := (d + e) * B + B + d def rowSizeBound (d e v B : Nat) : Nat := v + valueBound d e B + trueBits.length + 2 def rowCostBound (d e v B : Nat) : Nat := 8 * B + 4 * rowSizeBound d e v B + valueBound d e B + trueBits.length + 28 theorem value_le (d e j B : Nat) (hj : j ≤ B) : MachinePortReindex.value e (d + e) d j ≤ valueBound d e B := by have hdiv := (Nat.div_le_self j e).trans hj have hmod := (Nat.mod_le j e).trans hj have hmul := Nat.mul_le_mul_left (d + e) hdiv unfold MachinePortReindex.value valueBound omega theorem rowBits_length (d e v j : Nat) : (rowBits d e v j).length = v + MachinePortReindex.value e (d + e) d j + trueBits.length + 2 := by simp only [rowBits, MachineLazyRows.reindexRowBits, List.length_append, encodeWord_length, trueBits] omega theorem rowBits_length_le (d e v j B : Nat) (hj : j ≤ B) : (rowBits d e v j).length ≤ rowSizeBound d e v B := by rw [rowBits_length] have h := value_le d e j B hj unfold rowSizeBound omega theorem rowSteps_le (d e v j B : Nat) (hj : j ≤ B) (output : List Bool) : rowSteps d e v j output ≤ rowCostBound d e v B + 2 * output.length := by have hdiv := (Nat.div_le_self j e).trans hj have hval := value_le d e j B hj have hsize := rowBits_length_le d e v j B hj change (MachineLazyRows.reindexRowBits e (d + e) d v j trueRelation).length ≤ rowSizeBound d e v B at hsize unfold rowSteps MachineLazyRows.reindexSteps MachinePortReindex.steps rowCostBound omega private theorem vertexSteps_le_capacity_inline_MachineOverlayRows (d e v B capacity : Nat) (words : List Nat) (bounded : ∀ j ∈ words, j ≤ B) (output : List Bool) (room : output.length + words.length * rowSizeBound d e v B ≤ capacity) : vertexSteps d e v words output ≤ words.length * (rowCostBound d e v B + 2 * capacity + 1) + 1 := by induction words generalizing output with | nil => simp [vertexSteps] | cons j words ih => have hj := bounded j (by simp) have hb : ∀ k ∈ words, k ≤ B := fun k hk => bounded k (by simp [hk]) have hsize := rowBits_length_le d e v j B hj have hcost := rowSteps_le d e v j B hj output have hout : output.length ≤ capacity := by omega have hroom : (output ++ rowBits d e v j).length + words.length * rowSizeBound d e v B ≤ capacity := by rw [List.length_append] simp only [List.length_cons, Nat.succ_mul] at room omega have htail := ih hb (output ++ rowBits d e v j) hroom change 1 + rowSteps d e v j output + vertexSteps d e v words (output ++ rowBits d e v j) ≤ (words.length + 1) * (rowCostBound d e v B + 2 * capacity + 1) + 1 rw [Nat.add_mul, Nat.one_mul] omega theorem vertexSteps_le (d e v B : Nat) (words : List Nat) (bounded : ∀ j ∈ words, j ≤ B) (output : List Bool) : vertexSteps d e v words output ≤ words.length * (rowCostBound d e v B + 2 * (output.length + words.length * rowSizeBound d e v B) + 1) + 1 := vertexSteps_le_capacity_inline_MachineOverlayRows d e v B _ words bounded output (Nat.le_refl _) private theorem streamFrame_afterRow_inline_MachineOverlayRows (d e v j : Nat) (tape : Fin 10 → K) (distinct : Function.Injective tape) (base : K → List Bool) (words : List Nat) (output : List Bool) : resultTapes d e v j tape (streamFrame tape base (j :: words) output) (encodeWords words ++ base (tape 9)) = streamFrame tape base words (output ++ rowBits d e v j) := by have h79 : tape 7 ≠ tape 9 := fun h => (by decide : (7 : Fin 10) ≠ 9) (distinct h) funext k by_cases h7 : k = tape 7 · subst k simp [resultTapes, streamFrame] · by_cases h9 : k = tape 9 · subst k simp [resultTapes, streamFrame, Ne.symm h79] · simp [resultTapes, streamFrame, h7, h9] theorem vertexSuffixTrace (d e : Nat) (positive : 0 < e) (tape : Fin 10 → K) (distinct : Function.Injective tape) (labels : VertexLabel e → Λ) (exit : Option Λ) (program : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State A e)) (atLabels : ∀ l, program (labels l) = vertexInstruction d e positive tape labels exit l) (base : K → List Bool) (v : Nat) (values : Fin e → Nat) (tailWord : base (tape 0) = encodeWord v) (empty : ∀ i : Fin 10, i ≠ 0 → i ≠ 7 → i ≠ 9 → base (tape i) = []) (ambient : A) (remaining : Nat) (i : Fin (e + 1)) (count : i.val + remaining = e) (output : List Bool) : (advance (TM2.step program))^[vertexSteps d e v ((List.ofFn values).drop i.val) output] (some ⟨some (labels (i, none)), MachinePortReindex.clean e positive ambient, streamFrame tape base ((List.ofFn values).drop i.val) output⟩) = some ⟨exit, MachinePortReindex.clean e positive ambient, streamFrame tape base [] (output ++ streamOutput d e v ((List.ofFn values).drop i.val))⟩ := by have hd (a b : Fin 10) (h : a ≠ b) : tape a ≠ tape b := fun x => h (distinct x) induction remaining generalizing i output with | zero => have hi : i.val = e := by omega have hdrop : (List.ofFn values).drop i.val = [] := by apply List.drop_eq_nil_of_le simp only [List.length_ofFn, hi, le_refl] rw [hdrop] simp only [vertexSteps, streamOutput, List.flatMap_nil, List.append_nil] change some (TM2.stepAux (program (labels (i, none))) _ _) = _ rw [atLabels] cases exit <;> simp [vertexInstruction, hi, MachinePortReindex.exitAt, TM2.stepAux] | succ remaining ih => have hi : i.val < e := by omega let port : Fin e := ⟨i.val, hi⟩ let next : Fin (e + 1) := ⟨i.val + 1, by omega⟩ let rest := (List.ofFn values).drop (i.val + 1) have split : (List.ofFn values).drop i.val = values port :: rest := by have h := List.getElem_cons_drop (as := List.ofFn values) (i := i.val) (by simpa only [List.length_ofFn] using hi) simpa only [List.getElem_ofFn, port, rest] using h.symm let initial := streamFrame tape base (values port :: rest) output have boundary : (advance (TM2.step program))^[1] (some ⟨some (labels (i, none)), MachinePortReindex.clean e positive ambient, initial⟩) = some ⟨some (labels (i, some .loadStart)), MachinePortReindex.clean e positive ambient, initial⟩ := by change some (TM2.stepAux (program (labels (i, none))) _ _) = _ rw [atLabels] simp [vertexInstruction, hi, TM2.stepAux] have body := rowTrace d e positive tape distinct (fun stage => labels (i, some stage)) (some (labels (next, none))) program (by intro stage simpa only [vertexInstruction, hi, dite_true, next] using (atLabels (i, some stage))) initial v (values port) (encodeWords rest ++ base (tape 9)) (by simp [initial, streamFrame, hd 0 7 (by decide), hd 0 9 (by decide), tailWord]) (by simp [initial, streamFrame, hd 9 7 (by decide), encodeWords, List.append_assoc]) (by intro k hk0 hk7 hk9 simp [initial, streamFrame, hd k 7 hk7, hd k 9 hk9, empty k hk0 hk7 hk9]) ambient have initialOutput : initial (tape 7) = output := by simp [initial, streamFrame] rw [initialOutput] at body change (advance (TM2.step program))^[rowSteps d e v (values port) output] (some ⟨some (labels (i, some .loadStart)), MachinePortReindex.clean e positive ambient, initial⟩) = some ⟨some (labels (next, none)), MachinePortReindex.clean e positive ambient, resultTapes d e v (values port) tape initial (encodeWords rest ++ base (tape 9))⟩ at body rw [show resultTapes d e v (values port) tape initial (encodeWords rest ++ base (tape 9)) = streamFrame tape base rest (output ++ rowBits d e v (values port)) from streamFrame_afterRow_inline_MachineOverlayRows d e v (values port) tape distinct base rest output] at body have nextCount : next.val + remaining = e := by dsimp [next]; omega have tail := ih next nextCount (output ++ rowBits d e v (values port)) change (advance (TM2.step program))^[vertexSteps d e v rest (output ++ rowBits d e v (values port))] (some ⟨some (labels (next, none)), MachinePortReindex.clean e positive ambient, streamFrame tape base rest (output ++ rowBits d e v (values port))⟩) = some ⟨exit, MachinePortReindex.clean e positive ambient, streamFrame tape base [] ((output ++ rowBits d e v (values port)) ++ streamOutput d e v rest)⟩ at tail rw [split] have all := joinTrace_inline_MachineOverlayRows (joinTrace_inline_MachineOverlayRows boundary body) tail simpa only [vertexSteps, initial, streamOutput, List.flatMap_cons, List.append_assoc] using all theorem vertexTrace (d e : Nat) (positive : 0 < e) (tape : Fin 10 → K) (distinct : Function.Injective tape) (labels : VertexLabel e → Λ) (exit : Option Λ) (program : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State A e)) (atLabels : ∀ l, program (labels l) = vertexInstruction d e positive tape labels exit l) (base : K → List Bool) (v : Nat) (values : Fin e → Nat) (tailWord : base (tape 0) = encodeWord v) (empty : ∀ i : Fin 10, i ≠ 0 → i ≠ 7 → i ≠ 9 → base (tape i) = []) (ambient : A) (output : List Bool) : (advance (TM2.step program))^[vertexSteps d e v (List.ofFn values) output] (some ⟨some (labels (0, none)), MachinePortReindex.clean e positive ambient, streamFrame tape base (List.ofFn values) output⟩) = some ⟨exit, MachinePortReindex.clean e positive ambient, streamFrame tape base [] (output ++ streamOutput d e v (List.ofFn values))⟩ := by simpa only [Fin.val_zero, List.drop_zero] using vertexSuffixTrace d e positive tape distinct labels exit program atLabels base v values tailWord empty ambient e 0 (by simp) output def vertexInTime (d e : Nat) (positive : 0 < e) (tape : Fin 10 → K) (distinct : Function.Injective tape) (labels : VertexLabel e → Λ) (exit : Option Λ) (program : Λ → TM2.Stmt (fun _ : K => Bool) Λ (State A e)) (atLabels : ∀ l, program (labels l) = vertexInstruction d e positive tape labels exit l) (base : K → List Bool) (v B : Nat) (values : Fin e → Nat) (bounded : ∀ p, values p ≤ B) (tailWord : base (tape 0) = encodeWord v) (empty : ∀ i : Fin 10, i ≠ 0 → i ≠ 7 → i ≠ 9 → base (tape i) = []) (ambient : A) (output : List Bool) : StateTransition.EvalsToInTime (TM2.step program) ⟨some (labels (0, none)), MachinePortReindex.clean e positive ambient, streamFrame tape base (List.ofFn values) output⟩ (some ⟨exit, MachinePortReindex.clean e positive ambient, streamFrame tape base [] (output ++ streamOutput d e v (List.ofFn values))⟩) (e * (rowCostBound d e v B + 2 * (output.length + e * rowSizeBound d e v B) + 1) + 1) where steps := vertexSteps d e v (List.ofFn values) output evals_in_steps := vertexTrace d e positive tape distinct labels exit program atLabels base v values tailWord empty ambient output steps_le_m := by simpa only [List.length_ofFn] using vertexSteps_le d e v B (List.ofFn values) (by intro j hj; obtain ⟨p, rfl⟩ := List.mem_ofFn.mp hj; exact bounded p) output private theorem encodeWords_flatMap_inline_MachineOverlayRows {α : Type*} (items : List α) (words : α → List Nat) : encodeWords (items.flatMap words) = items.flatMap (fun x => encodeWords (words x)) := by induction items with | nil => rfl | cons item items ih => simp only [List.flatMap_cons, encodeWords_append, ih] theorem streamOutput_expanderRows {n e : Nat} (d : Nat) (H : PCP.ExpanderTables.Table n e) (v : Fin n) : streamOutput d e v.val (List.ofFn fun p : Fin e => (PCP.ExpanderTables.reverseIndex H (PCP.ExpanderTables.rowIndex n e (v, p))).val) = encodeWords ((List.ofFn (expanderRow d H v)).flatMap rowWords) := by rw [encodeWords_flatMap_inline_MachineOverlayRows] simp only [streamOutput, List.flatMap_def, List.map_ofFn] apply congrArg List.flatten apply congrArg List.ofFn funext p exact rowBits_eq_expanderRow d H v p theorem expanderValues_bounded {n e : Nat} (H : PCP.ExpanderTables.Table n e) (v : Fin n) (p : Fin e) : (PCP.ExpanderTables.reverseIndex H (PCP.ExpanderTables.rowIndex n e (v, p))).val ≤ n * e := (PCP.ExpanderTables.reverseIndex H (PCP.ExpanderTables.rowIndex n e (v, p))).isLt.le def vertexMachine (d e : Nat) (positive : 0 < e) : FinTM2 where K := Fin 10 k₀ := 9 k₁ := 7 Γ _ := Bool Λ := VertexLabel e main := (0, none) σ := State Unit e initialState := MachinePortReindex.clean e positive () m := vertexInstruction d e positive id id none end DFVSGames.Foundations.Complexity.MachineOverlayRows 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
import Mathlib
import OAI.Computability.DirectedFeedback.Machines.MachinePortReindex
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.MachineLazyRows
open Turing MachineComposition PCP.GraphTables
open PCP.PreprocessingLazyWords (reverseMap moveRow moveRow_words)
variable {K Λ A : Type} [DecidableEq K]
abbrev VertexLabel (d : Nat) := Fin (d + 1) × Option (StreamLabel d)
def vertexInstruction (d : Nat) (positive : 0 < d) (c b : Nat) (tape : Fin 10 → K)
(labels : VertexLabel d → Λ) (exit : Option Λ) :
VertexLabel d → TM2.Stmt (fun _ : K => Bool) Λ (StreamState A d)
| (i, none) => if i.val < d then .goto fun _ => labels (i, some .tailStart)
else MachinePortReindex.exitAt exit
| (i, some stage) => if h : i.val < d then
streamInstruction d positive c b tape (fun stage => labels (i, some stage))
(some (labels (⟨i.val + 1, by omega⟩, none))) stage
else MachinePortReindex.exitAt exit
def recordsInput {n m : Nat} (rows : List (DartRow n m)) : List Bool :=
rows.flatMap (fun r => inputRowBits r.tail.val r.reverseIndex.val r.relation)
def recordsOutput {n m : Nat} (d c b : Nat) (rows : List (DartRow n m)) : List Bool :=
rows.flatMap (fun r => reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation)
def streamFrame {n m : Nat} (tape : Fin 10 → K) (base : K → List Bool)
(rows : List (DartRow n m)) (output : List Bool) : K → List Bool :=
Function.update (Function.update base (tape 9) (recordsInput rows ++ base (tape 9)))
(tape 7) output
def vertexSteps {n m : Nat} (d c b : Nat) : List (DartRow n m) → List Bool → Nat
| [], _ => 1
| r :: rows, output => 1 + streamRowSteps d c b r.tail.val r.reverseIndex.val r.relation output +
vertexSteps d c b rows
(output ++ reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation)
theorem recordsInput_eq_codec {n m : Nat} (rows : List (DartRow n m)) :
recordsInput rows = encodeWords (rows.flatMap rowWords) := by
induction rows with
| nil => rfl
| cons r rows ih =>
simp only [recordsInput, List.flatMap_cons, encodeWords_append,
MachineTableRows.rowBits_eq, inputRowBits] at ih ⊢
rw [ih]
private theorem streamFrame_afterRow_inline_MachineLazyRows {n m : Nat} (d c b : Nat) (r : DartRow n m)
(tape : Fin 10 → K) (distinct : Function.Injective tape) (base : K → List Bool)
(rows : List (DartRow n m)) (output : List Bool) :
streamResultTapes d c b r.tail.val r.reverseIndex.val r.relation tape
(streamFrame tape base (r :: rows) output) (recordsInput rows ++ base (tape 9)) =
streamFrame tape base rows
(output ++ reindexRowBits d c b r.tail.val r.reverseIndex.val r.relation) := by
have h79 : tape 7 ≠ tape 9 := fun h => (by decide : (7 : Fin 10) ≠ 9) (distinct h)
funext k

Xet Storage Details

Size:
50.7 kB
·
Xet hash:
e8f0fa5a1d3e892d1bcd1a742f4f2862c2da9420e7a0f1dcbd6e09ead5b6f3cf

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.