Buckets:
| import OAI.Computability.UniqueGames.Machines.MachineCanonicalOutputLemmas | |
| import OAI.Computability.UniqueGames.Machines.MachineControlLemmas | |
| namespace OAI | |
| namespace UniqueGamesTheorem.Foundations.Complexity.MachinePaddingRows | |
| open Turing MachineComposition | |
| inductive Control | |
| | initialize | guard | bump | |
| deriving DecidableEq | |
| protected abbrev Control.enumList : List Control := [.initialize, .guard, .bump] | |
| protected theorem Control.enumList_getElem?_ctorIdx_eq (x : Control) : | |
| Control.enumList[x.ctorIdx]? = some x := by | |
| cases x <;> rfl | |
| protected theorem Control.enumList_nodup : Control.enumList.Nodup := by decide | |
| instance : Fintype Control where | |
| elems := ⟨Control.enumList, Control.enumList_nodup⟩ | |
| complete x := by cases x <;> decide | |
| abbrev Tape := Fin 6 ⊕ Unit | |
| abbrev Label (d : Nat) := MachineDummyRows.Label d ⊕ Control | |
| abbrev Alphabet : Tape → Type := MachineEmbedding.Alphabet | |
| (fun _ : Fin 6 => Bool) (fun _ : Unit => Bool) | |
| abbrev State := (Unit × Option Bool) × Unit | |
| def bodyEntry (d : Nat) (hd : 0 < d) : Label d := | |
| .inl (MachineDummyRows.rowLabel ⟨0, hd⟩ .relationRead) | |
| def extra (d : Nat) (hd : 0 < d) : Control → TM2.Stmt Alphabet (Label d) State | |
| | .initialize => Reduction.MachineSubstitution.pushWord (.inl 2) | |
| MachineDummyRows.trueBits.reverse | |
| (.load (fun _ => (((), none), ())) (.goto (fun _ => .inr .guard))) | |
| | .guard => .pop (.inr ()) (fun _ bit => (((), bit), ())) | |
| (.branch (fun s => s.1.2.getD false) | |
| (.load (fun _ => (((), none), ())) (.goto (fun _ => bodyEntry d hd))) | |
| (.push (.inr ()) (fun _ => false) | |
| (.load (fun _ => (((), none), ())) .halt))) | |
| | .bump => .push (.inl 0) (fun _ => true) (.goto (fun _ => .inr .guard)) | |
| def program (d : Nat) (hd : 0 < d) : Label d → TM2.Stmt Alphabet (Label d) State := | |
| MachineEmbedding.program (some (.inr .bump)) (MachineDummyRows.program d) (extra d hd) | |
| def tapes (v e fuel : Nat) (output : List Bool) : ∀ k, List (Alphabet k) := | |
| MachineEmbedding.tapes (MachineDummyRows.fieldTapes v e output) | |
| (fun _ : Unit => encodeWord fuel) | |
| def cfg (d : Nat) (label : Option (Label d)) (v e fuel : Nat) | |
| (output : List Bool) : TM2.Cfg Alphabet (Label d) State := | |
| ⟨label, (((), none), ()), tapes v e fuel output⟩ | |
| theorem bodyTrace (d : Nat) (hd : 0 < d) (v e fuel : Nat) (output : List Bool) : | |
| (advance (TM2.step (program d hd)))^[MachineDummyRows.steps v e output d] | |
| (some (cfg d (some (bodyEntry d hd)) v e fuel output)) = | |
| some (cfg d (some (.inr .bump)) v (e + d) fuel | |
| (output ++ MachineDummyRows.rowsBits v e d)) := by | |
| have run := MachineDummyRows.suffixTrace d ⟨0, hd⟩ (by simp) | |
| v e output () none | |
| have lifted := liftSuccessfulTrace | |
| (TM2.step (MachineDummyRows.program d)) (TM2.step (program d hd)) | |
| (MachineEmbedding.configuration (some (.inr .bump)) () | |
| (fun _ : Unit => encodeWord fuel)) | |
| (by | |
| intro a b h | |
| exact MachineEmbedding.step_simulation (some (.inr Control.bump)) () | |
| (fun _ : Unit => encodeWord fuel) (MachineDummyRows.program d) (extra d hd) a b h) | |
| (MachineDummyRows.steps v e output d) _ _ run | |
| exact lifted | |
| theorem guard_succ (d : Nat) (hd : 0 < d) (v e fuel : Nat) (output : List Bool) : | |
| TM2.step (program d hd) (cfg d (some (.inr .guard)) v e (fuel + 1) output) = | |
| some (cfg d (some (bodyEntry d hd)) v e fuel output) := by | |
| change some (TM2.stepAux (extra d hd .guard) _ _) = _ | |
| simp only [extra, TM2.stepAux, tapes, MachineEmbedding.tapes_inr, | |
| encodeWord, List.replicate_succ, List.cons_append, List.head?_cons, | |
| List.tail_cons, Option.getD_some, Bool.cond_true] | |
| congr 2 | |
| funext k | |
| cases k <;> simp [tapes, MachineEmbedding.tapes, Function.update, encodeWord] | |
| theorem guard_zero (d : Nat) (hd : 0 < d) (v e : Nat) (output : List Bool) : | |
| TM2.step (program d hd) (cfg d (some (.inr .guard)) v e 0 output) = | |
| some (cfg d none v e 0 output) := by | |
| change some (TM2.stepAux (extra d hd .guard) _ _) = _ | |
| simp only [extra, TM2.stepAux, tapes, MachineEmbedding.tapes_inr, | |
| encodeWord, List.replicate_zero, List.nil_append, List.head?_cons, | |
| List.tail_cons, Option.getD_some, Bool.cond_false] | |
| congr 2 | |
| funext k | |
| cases k <;> simp [tapes, MachineEmbedding.tapes, Function.update, encodeWord] | |
| theorem bump_step (d : Nat) (hd : 0 < d) (v e fuel : Nat) (output : List Bool) : | |
| TM2.step (program d hd) (cfg d (some (.inr .bump)) v e fuel output) = | |
| some (cfg d (some (.inr .guard)) (v + 1) e fuel output) := by | |
| change some (TM2.stepAux (extra d hd .bump) _ _) = _ | |
| simp only [extra, TM2.stepAux] | |
| congr 2 | |
| funext k | |
| cases k with | |
| | inl k => fin_cases k <;> simp [tapes, MachineEmbedding.tapes, | |
| MachineDummyRows.fieldTapes, encodeWord, List.replicate_succ] | |
| | inr k => simp [tapes, MachineEmbedding.tapes] | |
| def paddingBits (d v e : Nat) : Nat → List Bool | |
| | 0 => [] | |
| | count + 1 => MachineDummyRows.rowsBits v e d ++ paddingBits d (v + 1) (e + d) count | |
| def steps (d v e : Nat) (output : List Bool) : Nat → Nat | |
| | 0 => 1 | |
| | count + 1 => (MachineDummyRows.steps v e output d + 2) + | |
| steps d (v + 1) (e + d) (output ++ MachineDummyRows.rowsBits v e d) count | |
| /-- The entire varying-length padding loop is proved from its actual guards, | |
| actual row bodies and actual vertex increments. -/ | |
| theorem loopTrace (d : Nat) (hd : 0 < d) (count v e : Nat) (output : List Bool) : | |
| (advance (TM2.step (program d hd)))^[steps d v e output count] | |
| (some (cfg d (some (.inr .guard)) v e count output)) = | |
| some (cfg d none (v + count) (e + count * d) 0 | |
| (output ++ paddingBits d v e count)) := by | |
| induction count generalizing v e output with | |
| | zero => simpa [steps, paddingBits] using guard_zero d hd v e output | |
| | succ count ih => | |
| rw [steps, Nat.add_comm (MachineDummyRows.steps v e output d + 2), | |
| Function.iterate_add_apply] | |
| have hb : (advance (TM2.step (program d hd)))^[MachineDummyRows.steps v e output d + 2] | |
| (some (cfg d (some (.inr .guard)) v e (count + 1) output)) = | |
| some (cfg d (some (.inr .guard)) (v + 1) (e + d) count | |
| (output ++ MachineDummyRows.rowsBits v e d)) := by | |
| rw [show MachineDummyRows.steps v e output d + 2 = | |
| (MachineDummyRows.steps v e output d + 1) + 1 by omega, | |
| Function.iterate_succ_apply, advance_some, guard_succ, | |
| Function.iterate_succ_apply', bodyTrace, advance_some, bump_step] | |
| rw [hb, ih] | |
| simp only [paddingBits, List.append_assoc, Nat.succ_mul] | |
| congr 2 <;> omega | |
| def initialTapes (v e fuel : Nat) (output : List Bool) : ∀ k, List (Alphabet k) := | |
| Function.update (tapes v e fuel output) (.inl 2) [] | |
| theorem initialize_step (d : Nat) (hd : 0 < d) (v e fuel : Nat) (output : List Bool) : | |
| TM2.step (program d hd) | |
| ⟨some (.inr .initialize), (((), none), ()), initialTapes v e fuel output⟩ = | |
| some (cfg d (some (.inr .guard)) v e fuel output) := by | |
| change some (TM2.stepAux (extra d hd .initialize) _ _) = _ | |
| simp only [extra, Reduction.MachineSubstitution.stepAux_pushWord, | |
| List.reverse_reverse, initialTapes, Function.update_self, List.append_nil, | |
| Function.update_idem, TM2.stepAux] | |
| congr 2 | |
| funext k | |
| cases k with | |
| | inl k => fin_cases k <;> simp [tapes, MachineEmbedding.tapes, | |
| MachineDummyRows.fieldTapes] | |
| | inr k => simp [tapes, MachineEmbedding.tapes] | |
| theorem paddingTrace (d : Nat) (hd : 0 < d) (count v e : Nat) (output : List Bool) : | |
| (advance (TM2.step (program d hd)))^[steps d v e output count + 1] | |
| (some ⟨some (.inr .initialize), (((), none), ()), initialTapes v e count output⟩) = | |
| some (cfg d none (v + count) (e + count * d) 0 | |
| (output ++ paddingBits d v e count)) := by | |
| rw [Function.iterate_succ_apply, advance_some, initialize_step, loopTrace] | |
| def machine (d : Nat) (hd : 0 < d) : FinTM2 where | |
| K := Tape | |
| k₀ := .inl 0 | |
| k₁ := .inl 4 | |
| Γ := Alphabet | |
| Λ := Label d | |
| main := .inr .initialize | |
| σ := State | |
| initialState := (((), none), ()) | |
| m := program d hd | |
| /-- The exact time count is the sum of the physically executed row loops. | |
| Its polynomial bound is derived separately from this recurrence. -/ | |
| def execution (d : Nat) (hd : 0 < d) (count v e : Nat) (output : List Bool) : | |
| StateTransition.EvalsToInTime (machine d hd).step | |
| ⟨some (.inr .initialize), (((), none), ()), initialTapes v e count output⟩ | |
| (some (cfg d none (v + count) (e + count * d) 0 | |
| (output ++ paddingBits d v e count))) | |
| (steps d v e output count + 1) where | |
| steps := steps d v e output count + 1 | |
| evals_in_steps := by | |
| convert paddingTrace d hd count v e output using 1 | |
| rfl | |
| steps_le_m := le_rfl | |
| end UniqueGamesTheorem.Foundations.Complexity.MachinePaddingRows | |
| /-! Polynomial bounds for the actual outer padding-loop recurrence. No | |
| execution or cost premise is introduced: the recurrence is the one matched | |
| to the concrete machine by `MachinePaddingRows.loopTrace`. -/ | |
| namespace UniqueGamesTheorem.Foundations.Complexity.MachinePaddingBounds | |
| /-- All rows in a fixed block are bounded by its last possible index. -/ | |
| theorem rowsBits_length_le (v e count : Nat) : | |
| (MachineDummyRows.rowsBits v e count).length ≤ count * (v + e + count + 8194) := by | |
| induction count generalizing e with | |
| | zero => simp [MachineDummyRows.rowsBits] | |
| | succ count ih => | |
| have hi := ih (e + 1) | |
| have hb : v + (e + 1) + count + 8194 = v + e + (count + 1) + 8194 := by omega | |
| rw [hb] at hi | |
| have hr : v + e + 8194 ≤ v + e + (count + 1) + 8194 := by omega | |
| simp only [MachineDummyRows.rowsBits, List.length_append, MachineDummyRows.rowBits_length] | |
| calc | |
| _ ≤ (v + e + (count + 1) + 8194) + | |
| count * (v + e + (count + 1) + 8194) := Nat.add_le_add hr hi | |
| _ = _ := by rw [Nat.add_mul, Nat.one_mul]; omega | |
| /-- A common row-size bound for all remaining vertices and ports. -/ | |
| def rowBound (d v e count : Nat) : Nat := v + count + e + (count + 1) * d + 8194 | |
| /-- This bound is invariant when one vertex and its `d` reverse indices | |
| have been consumed from the remaining outer-loop count. -/ | |
| theorem rowBound_next (d v e count : Nat) : | |
| rowBound d (v + 1) (e + d) count = rowBound d v e (count + 1) := by | |
| simp only [rowBound, Nat.add_mul, Nat.one_mul] | |
| omega | |
| theorem blockRow_le_rowBound (d v e count : Nat) : | |
| v + e + d + 8194 ≤ rowBound d v e (count + 1) := by | |
| simp only [rowBound, Nat.add_mul, Nat.one_mul] | |
| omega | |
| /-- The actual outer-loop cost is bounded by the number of vertices times | |
| a uniform bound on its actual row bodies and two control transitions. -/ | |
| theorem steps_le_bound (d v e : Nat) (output : List Bool) (count : Nat) : | |
| MachinePaddingRows.steps d v e output count ≤ | |
| count * (d * (4 * rowBound d v e count + | |
| 2 * (output.length + count * d * rowBound d v e count) + 10) + 2) + 1 := by | |
| induction count generalizing v e output with | |
| | zero => simp [MachinePaddingRows.steps] | |
| | succ count ih => | |
| let B := rowBound d v e (count + 1) | |
| let C := d * (4 * B + 2 * (output.length + (count + 1) * d * B) + 10) + 2 | |
| have hb : rowBound d (v + 1) (e + d) count = B := rowBound_next d v e count | |
| have hr : v + e + d + 8194 ≤ B := blockRow_le_rowBound d v e count | |
| have hlen : (MachineDummyRows.rowsBits v e d).length ≤ d * B := | |
| (rowsBits_length_le v e d).trans (Nat.mul_le_mul_left d hr) | |
| have hout : (output ++ MachineDummyRows.rowsBits v e d).length + count * d * B ≤ | |
| output.length + (count + 1) * d * B := by | |
| rw [List.length_append] | |
| calc | |
| _ ≤ output.length + d * B + count * d * B := | |
| Nat.add_le_add_right (Nat.add_le_add_left hlen output.length) _ | |
| _ = _ := by simp only [Nat.add_mul, Nat.one_mul]; omega | |
| have hi := ih (v + 1) (e + d) (output ++ MachineDummyRows.rowsBits v e d) | |
| rw [hb] at hi | |
| have hconstant : | |
| d * (4 * B + 2 * ((output ++ MachineDummyRows.rowsBits v e d).length + | |
| count * d * B) + 10) + 2 ≤ C := by | |
| exact Nat.add_le_add_right (Nat.mul_le_mul_left d | |
| (Nat.add_le_add_right (Nat.add_le_add_left (Nat.mul_le_mul_left 2 hout) (4 * B)) 10)) 2 | |
| have hremaining := hi.trans | |
| (Nat.add_le_add_right (Nat.mul_le_mul_left count hconstant) 1) | |
| have hcount : d * B ≤ (count + 1) * d * B := by | |
| simpa only [Nat.one_mul, Nat.mul_assoc] using | |
| Nat.mul_le_mul_right (d * B) (Nat.succ_le_succ (Nat.zero_le count)) | |
| have hbodyOutput : output.length + d * (v + e + d + 8194) ≤ | |
| output.length + (count + 1) * d * B := | |
| Nat.add_le_add_left ((Nat.mul_le_mul_left d hr).trans hcount) output.length | |
| have hbodyInner : 4 * (v + e + d + 8194) + | |
| 2 * (output.length + d * (v + e + d + 8194)) + 10 ≤ | |
| 4 * B + 2 * (output.length + (count + 1) * d * B) + 10 := by | |
| exact Nat.add_le_add_right (Nat.add_le_add (Nat.mul_le_mul_left 4 hr) | |
| (Nat.mul_le_mul_left 2 hbodyOutput)) 10 | |
| have hbody : MachineDummyRows.steps v e output d + 2 ≤ C := | |
| Nat.add_le_add_right ((MachineDummyRows.steps_le_bound v e output d).trans | |
| (Nat.mul_le_mul_left d hbodyInner)) 2 | |
| change (MachineDummyRows.steps v e output d + 2) + | |
| MachinePaddingRows.steps d (v + 1) (e + d) | |
| (output ++ MachineDummyRows.rowsBits v e d) count ≤ (count + 1) * C + 1 | |
| calc | |
| _ ≤ C + (count * C + 1) := Nat.add_le_add hbody hremaining | |
| _ = _ := by rw [Nat.add_mul, Nat.one_mul]; omega | |
| /-- Exact variable-size input: two unary fields, unary fuel, and old output. -/ | |
| def inputSize (v e count : Nat) (output : List Bool) : Nat := | |
| (encodeWord v).length + (encodeWord e).length + (encodeWord count).length + output.length | |
| def rowCap (d size : Nat) : Nat := size + (size + 1) * d + 8194 | |
| theorem rowBound_le_cap (d v e count : Nat) (output : List Bool) : | |
| rowBound d v e count ≤ rowCap d (inputSize v e count output) := by | |
| have hbase : v + e + count ≤ inputSize v e count output := by | |
| simp only [inputSize, encodeWord_length] | |
| omega | |
| have hcount : count ≤ inputSize v e count output := by | |
| simp only [inputSize, encodeWord_length] | |
| omega | |
| have hmul := Nat.mul_le_mul_right d (Nat.succ_le_succ hcount) | |
| have h := Nat.add_le_add_right (Nat.add_le_add hbase hmul) 8194 | |
| simpa only [rowBound, rowCap, Nat.succ_eq_add_one, Nat.add_assoc, | |
| Nat.add_comm, Nat.add_left_comm] using h | |
| noncomputable def rowPolynomial (d : Nat) : Polynomial Nat := | |
| Polynomial.X + (Polynomial.X + 1) * Polynomial.C d + Polynomial.C 8194 | |
| /-- A cubic polynomial for fixed degree, including the final zero-fuel | |
| guard. The one-time relation initializer can be accounted for separately. -/ | |
| noncomputable def timePolynomial (d : Nat) : Polynomial Nat := | |
| Polynomial.X * (Polynomial.C d * | |
| (Polynomial.C 4 * rowPolynomial d + | |
| Polynomial.C 2 * (Polynomial.X + Polynomial.X * Polynomial.C d * rowPolynomial d) + | |
| Polynomial.C 10) + Polynomial.C 2) + 1 | |
| theorem timePolynomial_bounds (d v e count : Nat) (output : List Bool) : | |
| MachinePaddingRows.steps d v e output count ≤ | |
| (timePolynomial d).eval (inputSize v e count output) := by | |
| have hc : count ≤ inputSize v e count output := by | |
| simp only [inputSize, encodeWord_length] | |
| omega | |
| have ho : output.length ≤ inputSize v e count output := by | |
| simp only [inputSize, encodeWord_length] | |
| omega | |
| have hb := rowBound_le_cap d v e count output | |
| have hp := Nat.mul_le_mul (Nat.mul_le_mul_right d hc) hb | |
| have hout := Nat.add_le_add ho hp | |
| have hinner := Nat.add_le_add_right | |
| (Nat.add_le_add (Nat.mul_le_mul_left 4 hb) (Nat.mul_le_mul_left 2 hout)) 10 | |
| have hbody := Nat.add_le_add_right (Nat.mul_le_mul_left d hinner) 2 | |
| have h := (steps_le_bound d v e output count).trans | |
| (Nat.add_le_add_right (Nat.mul_le_mul hc hbody) 1) | |
| simpa only [timePolynomial, rowPolynomial, rowCap, Polynomial.eval_add, | |
| Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_one] using h | |
| end UniqueGamesTheorem.Foundations.Complexity.MachinePaddingBounds | |
| /-! Polynomial-time certificate for the actual varying-length padding loop, | |
| including its one-time relation initialization. The input vertex, reverse | |
| index, fuel, and accumulated output are all measured as physically stored | |
| bits. This is a reusable stage of the graph-table transformation. -/ | |
| namespace UniqueGamesTheorem.Foundations.Complexity.MachinePaddingCertificate | |
| open MachinePaddingRows | |
| noncomputable def timePolynomial (d : Nat) : Polynomial Nat := | |
| MachinePaddingBounds.timePolynomial d + 1 | |
| def execution (d : Nat) (hd : 0 < d) (count v e : Nat) (output : List Bool) : | |
| StateTransition.EvalsToInTime (machine d hd).step | |
| ⟨some (.inr .initialize), (((), none), ()), initialTapes v e count output⟩ | |
| (some (cfg d none (v + count) (e + count * d) 0 | |
| (output ++ paddingBits d v e count))) | |
| ((timePolynomial d).eval (MachinePaddingBounds.inputSize v e count output)) where | |
| steps := steps d v e output count + 1 | |
| evals_in_steps := by | |
| convert paddingTrace d hd count v e output using 1 | |
| rfl | |
| steps_le_m := by | |
| simp only [timePolynomial, Polynomial.eval_add, Polynomial.eval_one] | |
| exact Nat.add_le_add_right | |
| (MachinePaddingBounds.timePolynomial_bounds d v e count output) 1 | |
| end UniqueGamesTheorem.Foundations.Complexity.MachinePaddingCertificate | |
| end OAI | |
Xet Storage Details
- Size:
- 17.3 kB
- Xet hash:
- b56474897d9b47bab4b62d889e376ba12a2fb44a63e747160ac31a3acce76e3b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.