Buckets:
| import Mathlib | |
| import OAI.Combinatorics.IndependentSets.Machines.PushWord | |
| import OAI.Combinatorics.IndependentSets.Machines.MachineTableRows | |
| namespace OAI | |
| namespace IndependentSetsGames.Foundations.Complexity.MachineDummyRows | |
| open Turing | |
| open PCP.GraphTables | |
| open Reduction.MachineSubstitution (pushWord stepAux_pushWord) | |
| def trueRelation : RelationTable := Vector.replicate 4096 true | |
| def trueBits : List Bool := encodeWords (relationWords trueRelation) | |
| theorem trueBits_length : trueBits.length = 8192 := by | |
| simp only [trueBits, encodeWords_length, relationWords, trueRelation, | |
| Vector.toList_replicate, List.map_replicate, List.sum_replicate_nat, | |
| List.length_replicate] | |
| rfl | |
| def rowBits (v e : Nat) : List Bool := encodeWord v ++ encodeWord e ++ trueBits | |
| theorem rowBits_length (v e : Nat) : (rowBits v e).length = v + e + 8194 := by | |
| simp [rowBits, trueBits_length, encodeWord_length] | |
| omega | |
| theorem rowBits_eq_graph_row {n m : Nat} (v : Fin n) (e : Fin m) : | |
| rowBits v.val e.val = encodeWords (rowWords (⟨v, e, trueRelation⟩ : DartRow n m)) := by | |
| rw [MachineTableRows.rowBits_eq] | |
| rfl | |
| def rowsBits (v e : Nat) : Nat → List Bool | |
| | 0 => [] | |
| | count + 1 => rowBits v e ++ rowsBits v (e + 1) count | |
| abbrev Label (d : Nat) := Unit ⊕ (Fin d × (MachineTableRows.Label ⊕ Unit)) | |
| def start (d : Nat) : Label d := .inl () | |
| def rowLabel {d : Nat} (p : Fin d) (stage : MachineTableRows.Label) : Label d := | |
| .inr (p, .inl stage) | |
| def bumpLabel {d : Nat} (p : Fin d) : Label d := .inr (p, .inr ()) | |
| def fields : Fin 3 → Fin 6 := fun i => i.castLE (by decide) | |
| def afterPort {d : Nat} (p : Fin d) : Option (Label d) := | |
| if h : p.val + 1 < d then some (rowLabel ⟨p.val + 1, h⟩ .relationRead) else none | |
| def entry (d : Nat) : Option (Label d) := | |
| if h : 0 < d then some (rowLabel ⟨0, h⟩ .relationRead) else none | |
| variable {σ : Type} | |
| abbrev Alphabet (_ : Fin 6) := Bool | |
| def continueAt {d : Nat} (exit : Option (Label d)) : | |
| TM2.Stmt Alphabet (Label d) (σ × Option Bool) := | |
| match exit with | |
| | none => .halt | |
| | some label => .goto fun _ => label | |
| theorem stepAux_continueAt {d : Nat} (exit : Option (Label d)) | |
| (state : σ × Option Bool) (tapes : Fin 6 → List Bool) : | |
| TM2.stepAux (continueAt exit) state tapes = ⟨exit, state, tapes⟩ := by | |
| cases exit <;> rfl | |
| def program (d : Nat) : Label d → TM2.Stmt Alphabet (Label d) (σ × Option Bool) | |
| | .inl () => pushWord 2 trueBits.reverse | |
| (.load (fun state => (state.1, none)) (continueAt (entry d))) | |
| | .inr (p, .inl stage) => MachineTableRows.routine fields 3 4 5 | |
| (rowLabel p) (some (bumpLabel p)) stage | |
| | .inr (p, .inr ()) => .push 1 (fun _ => true) (continueAt (afterPort p)) | |
| def fieldTapes (v e : Nat) (output : List Bool) : Fin 6 → List Bool := | |
| ![encodeWord v, encodeWord e, trueBits, [], output, []] | |
| def initialTapes (v e : Nat) (output : List Bool) : Fin 6 → List Bool := | |
| Function.update (fieldTapes v e output) 2 [] | |
| theorem initializeStep (d v e : Nat) (output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| TM2.step (program d) ⟨some (start d), (ambient, register), initialTapes v e output⟩ = | |
| some ⟨entry d, (ambient, none), fieldTapes v e output⟩ := by | |
| change some (TM2.stepAux (program d (start d)) (ambient, register) | |
| (initialTapes v e output)) = _ | |
| simp only [start, program, stepAux_pushWord, List.reverse_reverse, TM2.stepAux, | |
| initialTapes, Function.update_self, List.append_nil, Function.update_idem] | |
| have ht : Function.update (fieldTapes v e output) 2 trueBits = fieldTapes v e output := by | |
| funext i | |
| fin_cases i <;> simp [fieldTapes] | |
| rw [ht, stepAux_continueAt] | |
| theorem rowTrace {d : Nat} (p : Fin d) (v e : Nat) (output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| (MachineComposition.advance (TM2.step (program d)))^[ | |
| 4 * (v + e + 8194) + 2 * output.length + 9] | |
| (some ⟨some (rowLabel p .relationRead), (ambient, register), fieldTapes v e output⟩) = | |
| some ⟨some (bumpLabel p), (ambient, none), fieldTapes v e (output ++ rowBits v e)⟩ := by | |
| have hfields (i : Fin 3) : fields i ≠ (3 : Fin 6) ∧ fields i ≠ (5 : Fin 6) := by | |
| fin_cases i <;> decide | |
| have h := MachineTableRows.appendTrace fields (3 : Fin 6) 4 5 hfields | |
| (by decide) (by decide) (by decide) (rowLabel p) (some (bumpLabel p)) | |
| (program d) (fun _ => rfl) (fieldTapes v e output) rfl rfl ambient register | |
| have hbits : MachineTableRows.fieldBits fields (fieldTapes v e output) = rowBits v e := by | |
| rfl | |
| have hsize : MachineTableRows.fieldSize fields (fieldTapes v e output) = v + e + 8194 := by | |
| rw [← MachineTableRows.fieldBits_length, hbits, rowBits_length] | |
| have ht : Function.update (fieldTapes v e output) 4 (output ++ rowBits v e) = | |
| fieldTapes v e (output ++ rowBits v e) := by | |
| funext i | |
| fin_cases i <;> simp [fieldTapes] | |
| simpa only [hsize, hbits, show fieldTapes v e output 4 = output from rfl, ht] using h | |
| theorem bumpStep {d : Nat} (p : Fin d) (v e : Nat) (output : List Bool) (ambient : σ) : | |
| TM2.step (program d) ⟨some (bumpLabel p), (ambient, none), fieldTapes v e output⟩ = | |
| some ⟨afterPort p, (ambient, none), fieldTapes v (e + 1) output⟩ := by | |
| change some (TM2.stepAux (program d (bumpLabel p)) (ambient, none) | |
| (fieldTapes v e output)) = _ | |
| simp only [bumpLabel, program, TM2.stepAux] | |
| rw [stepAux_continueAt] | |
| congr 2 | |
| funext i | |
| fin_cases i <;> simp [fieldTapes, encodeWord, List.replicate_succ] | |
| theorem rowAndBumpTrace {d : Nat} (p : Fin d) (v e : Nat) (output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| (MachineComposition.advance (TM2.step (program d)))^[ | |
| 4 * (v + e + 8194) + 2 * output.length + 10] | |
| (some ⟨some (rowLabel p .relationRead), (ambient, register), fieldTapes v e output⟩) = | |
| some ⟨afterPort p, (ambient, none), fieldTapes v (e + 1) (output ++ rowBits v e)⟩ := by | |
| rw [show 4 * (v + e + 8194) + 2 * output.length + 10 = | |
| (4 * (v + e + 8194) + 2 * output.length + 9) + 1 by omega, | |
| Function.iterate_succ_apply', rowTrace, MachineComposition.advance_some] | |
| exact bumpStep p v e (output ++ rowBits v e) ambient | |
| def steps (v e : Nat) (output : List Bool) : Nat → Nat | |
| | 0 => 0 | |
| | count + 1 => (4 * (v + e + 8194) + 2 * output.length + 10) + | |
| steps v (e + 1) (output ++ rowBits v e) count | |
| theorem suffixTrace {d : Nat} (count : Nat) (p : Fin d) (hp : p.val + count = d) | |
| (v e : Nat) (output : List Bool) (ambient : σ) (register : Option Bool) : | |
| (MachineComposition.advance (TM2.step (program d)))^[steps v e output count] | |
| (some ⟨some (rowLabel p .relationRead), (ambient, register), fieldTapes v e output⟩) = | |
| some ⟨none, (ambient, none), fieldTapes v (e + count) (output ++ rowsBits v e count)⟩ := by | |
| induction count generalizing p v e output register with | |
| | zero => | |
| have hlt := p.isLt | |
| omega | |
| | succ count ih => | |
| rw [steps, Nat.add_comm (4 * (v + e + 8194) + 2 * output.length + 10), | |
| Function.iterate_add_apply, rowAndBumpTrace] | |
| by_cases hc : count = 0 | |
| · subst count | |
| have hlast : ¬ p.val + 1 < d := by omega | |
| simp [afterPort, hlast, steps, rowsBits] | |
| · have hnext : p.val + 1 < d := by omega | |
| rw [afterPort, dite_eq_left hnext] | |
| have hh := ih ⟨p.val + 1, hnext⟩ (by change (p.val + 1) + count = d; omega) | |
| v (e + 1) (output ++ rowBits v e) none | |
| have he : (e + 1) + count = e + (count + 1) := by omega | |
| simpa only [rowsBits, List.append_assoc, he] using hh | |
| theorem allTrace (d v e : Nat) (output : List Bool) (ambient : σ) (register : Option Bool) : | |
| (MachineComposition.advance (TM2.step (program d)))^[steps v e output d + 1] | |
| (some ⟨some (start d), (ambient, register), initialTapes v e output⟩) = | |
| some ⟨none, (ambient, none), fieldTapes v (e + d) (output ++ rowsBits v e d)⟩ := by | |
| rw [Function.iterate_succ_apply] | |
| change (MachineComposition.advance (TM2.step (program d)))^[steps v e output d] | |
| (TM2.step (program d) ⟨some (start d), (ambient, register), initialTapes v e output⟩) = _ | |
| rw [initializeStep] | |
| by_cases hd : 0 < d | |
| · rw [entry, dite_eq_left hd] | |
| exact suffixTrace d ⟨0, hd⟩ (by simp) v e output ambient none | |
| · have hz : d = 0 := by omega | |
| subst d | |
| simp [entry, steps, rowsBits] | |
| def graphRows {n m : Nat} (v : Fin n) (e : Nat) : | |
| (count : Nat) → e + count ≤ m → List (DartRow n m) | |
| | 0, _ => [] | |
| | count + 1, h => | |
| ⟨v, ⟨e, by omega⟩, trueRelation⟩ :: | |
| graphRows v (e + 1) count (by omega) | |
| theorem graphRows_length {n m : Nat} (v : Fin n) (e count : Nat) (h : e + count ≤ m) : | |
| (graphRows v e count h).length = count := by | |
| induction count generalizing e with | |
| | zero => rfl | |
| | succ count ih => simp [graphRows, ih] | |
| theorem rowsBits_eq_graphRows {n m : Nat} (v : Fin n) (e count : Nat) | |
| (h : e + count ≤ m) : | |
| rowsBits v.val e count = encodeWords ((graphRows v e count h).flatMap rowWords) := by | |
| induction count generalizing e with | |
| | zero => rfl | |
| | succ count ih => | |
| simp [rowsBits, graphRows, encodeWords_append, MachineTableRows.rowBits_eq, | |
| rowBits, trueBits] | |
| exact ih (e + 1) (by omega) | |
| def dummyRows {n : Nat} (d : Nat) (v : Fin n) : List (DartRow n (n * d)) := | |
| graphRows v (d * v.val) d (by | |
| have h := Nat.mul_le_mul_right d (Nat.succ_le_of_lt v.isLt) | |
| simpa only [Nat.succ_mul, Nat.mul_comm] using h) | |
| theorem dummyRows_length {n : Nat} (d : Nat) (v : Fin n) : | |
| (dummyRows d v).length = d := graphRows_length _ _ _ _ | |
| theorem dummyRowsTrace {n : Nat} (d : Nat) (v : Fin n) (output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| (MachineComposition.advance (TM2.step (program d)))^[steps v.val (d * v.val) output d + 1] | |
| (some ⟨some (start d), (ambient, register), initialTapes v.val (d * v.val) output⟩) = | |
| some ⟨none, (ambient, none), fieldTapes v.val (d * v.val + d) | |
| (output ++ encodeWords ((dummyRows d v).flatMap rowWords))⟩ := by | |
| have h := allTrace d v.val (d * v.val) output ambient register | |
| rw [rowsBits_eq_graphRows v (d * v.val) d (by | |
| have h := Nat.mul_le_mul_right d (Nat.succ_le_of_lt v.isLt) | |
| simpa only [Nat.succ_mul, Nat.mul_comm] using h)] at h | |
| exact h | |
| theorem steps_le_bound (v e : Nat) (output : List Bool) (count : Nat) : | |
| steps v e output count ≤ count * | |
| (4 * (v + e + count + 8194) + | |
| 2 * (output.length + count * (v + e + count + 8194)) + 10) := by | |
| induction count generalizing e output with | |
| | zero => simp [steps] | |
| | succ count ih => | |
| let B := v + e + (count + 1) + 8194 | |
| let C := 4 * B + 2 * (output.length + (count + 1) * B) + 10 | |
| have hb : v + (e + 1) + count + 8194 = B := by dsimp [B]; omega | |
| have hi := ih (e + 1) (output ++ rowBits v e) | |
| rw [List.length_append, rowBits_length, hb] at hi | |
| have hrow : v + e + 8194 ≤ B := by dsimp [B]; omega | |
| have hout : output.length + (v + e + 8194) + count * B ≤ | |
| output.length + (count + 1) * B := by | |
| calc | |
| _ ≤ output.length + B + count * B := | |
| Nat.add_le_add_right (Nat.add_le_add_left hrow output.length) _ | |
| _ = _ := by simp only [Nat.add_mul, Nat.one_mul]; omega | |
| have hconstant : 4 * B + 2 * (output.length + (v + e + 8194) + count * B) + 10 ≤ C := by | |
| exact Nat.add_le_add_right | |
| (Nat.add_le_add_left (Nat.mul_le_mul_left 2 hout) (4 * B)) 10 | |
| have hremaining := hi.trans (Nat.mul_le_mul_left count hconstant) | |
| have hbody : 4 * (v + e + 8194) + 2 * output.length + 10 ≤ C := by | |
| exact Nat.add_le_add_right (Nat.add_le_add (Nat.mul_le_mul_left 4 hrow) | |
| (Nat.mul_le_mul_left 2 (Nat.le_add_right output.length ((count + 1) * B)))) 10 | |
| change (4 * (v + e + 8194) + 2 * output.length + 10) + | |
| steps v (e + 1) (output ++ rowBits v e) count ≤ (count + 1) * C | |
| calc | |
| _ ≤ C + count * C := Nat.add_le_add hbody hremaining | |
| _ = (count + 1) * C := by rw [Nat.add_mul, Nat.one_mul]; omega | |
| def inputSize (v e : Nat) (output : List Bool) : Nat := | |
| (encodeWord v).length + (encodeWord e).length + output.length | |
| noncomputable def timePolynomial (d : Nat) : Polynomial Nat := | |
| Polynomial.C d * | |
| (Polynomial.C 4 * (Polynomial.X + Polynomial.C (d + 8192)) + | |
| Polynomial.C 2 * (Polynomial.X + Polynomial.C d * | |
| (Polynomial.X + Polynomial.C (d + 8192))) + Polynomial.C 10) + 1 | |
| theorem timePolynomial_bounds (d v e : Nat) (output : List Bool) : | |
| steps v e output d + 1 ≤ (timePolynomial d).eval (inputSize v e output) := by | |
| have h := steps_le_bound v e output d | |
| have hB : v + e + d + 8194 ≤ inputSize v e output + d + 8192 := by | |
| simp only [inputSize, encodeWord_length] | |
| omega | |
| have hO : output.length ≤ inputSize v e output := by | |
| simp only [inputSize, encodeWord_length] | |
| omega | |
| have hm := Nat.mul_le_mul_left d hB | |
| have hinner : | |
| 4 * (v + e + d + 8194) + 2 * (output.length + d * (v + e + d + 8194)) + 10 ≤ | |
| 4 * (inputSize v e output + d + 8192) + | |
| 2 * (inputSize v e output + d * (inputSize v e output + d + 8192)) + 10 := by | |
| exact Nat.add_le_add_right (Nat.add_le_add (Nat.mul_le_mul_left 4 hB) | |
| (Nat.mul_le_mul_left 2 (Nat.add_le_add hO hm))) 10 | |
| have htotal := h.trans (Nat.mul_le_mul_left d hinner) | |
| simp only [timePolynomial, Polynomial.eval_add, Polynomial.eval_mul, | |
| Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_one] | |
| simpa only [Nat.add_assoc] using Nat.add_le_add_right htotal 1 | |
| def machine (d : Nat) : FinTM2 where | |
| K := Fin 6 | |
| k₀ := 0 | |
| k₁ := 4 | |
| Γ _ := Bool | |
| Λ := Label d | |
| main := start d | |
| σ := Unit × Option Bool | |
| initialState := ((), none) | |
| m := program d | |
| def machineInTime (d v e : Nat) (output : List Bool) (register : Option Bool) : | |
| StateTransition.EvalsToInTime (machine d).step | |
| ⟨some (start d), ((), register), initialTapes v e output⟩ | |
| (some ⟨none, ((), none), fieldTapes v (e + d) (output ++ rowsBits v e d)⟩) | |
| ((timePolynomial d).eval (inputSize v e output)) where | |
| steps := steps v e output d + 1 | |
| evals_in_steps := by | |
| convert allTrace d v e output () register using 1 | |
| rfl | |
| steps_le_m := timePolynomial_bounds d v e output | |
| def machineDummyInTime {n : Nat} (d : Nat) (v : Fin n) | |
| (output : List Bool) (register : Option Bool) : | |
| StateTransition.EvalsToInTime (machine d).step | |
| ⟨some (start d), ((), register), initialTapes v.val (d * v.val) output⟩ | |
| (some ⟨none, ((), none), fieldTapes v.val (d * v.val + d) | |
| (output ++ encodeWords ((dummyRows d v).flatMap rowWords))⟩) | |
| ((timePolynomial d).eval (inputSize v.val (d * v.val) output)) where | |
| steps := steps v.val (d * v.val) output d + 1 | |
| evals_in_steps := by | |
| convert dummyRowsTrace d v output () register using 1 | |
| rfl | |
| steps_le_m := timePolynomial_bounds d v.val (d * v.val) output | |
| theorem finalFrame (v e : Nat) (output : List Bool) : | |
| fieldTapes v e output 0 = encodeWord v ∧ | |
| fieldTapes v e output 2 = trueBits ∧ | |
| fieldTapes v e output 3 = [] ∧ fieldTapes v e output 5 = [] := | |
| ⟨rfl, rfl, rfl, rfl⟩ | |
| end IndependentSetsGames.Foundations.Complexity.MachineDummyRows | |
| end OAI | |
Xet Storage Details
- Size:
- 15.2 kB
- Xet hash:
- 1c265342f192902fed091699c1113aa248673517df7ac97ccc4644b2529b2a03
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.