Buckets:
cfahlgren1/math / lean /OAI /Combinatorics /IndependentSets /Machines /MachinePreservingLookupClean.lean
| import Mathlib | |
| import OAI.Combinatorics.IndependentSets.Machines.MachineDrain | |
| import OAI.Combinatorics.IndependentSets.Machines.MachineSubroutine | |
| namespace OAI | |
| namespace IndependentSetsGames.Foundations.Complexity.MachinePreservingLookupClean | |
| open Turing | |
| open MachineComposition | |
| variable {K Λ σ : Type} [DecidableEq K] | |
| abbrev Alphabet (_ : K) := Bool | |
| inductive Label | |
| | run (label : MachinePreservingLookup.Label) | |
| | cleanup | |
| deriving DecidableEq, Fintype | |
| def statement (tape : Fin 5 → K) (labels : Label → Λ) (exit : Option Λ) : | |
| Label → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool) | |
| | .run label => MachineSubroutine.statement (fun label => labels (.run label)) | |
| (some (labels .cleanup)) (MachinePreservingLookup.program tape label) | |
| | .cleanup => MachineDrain.drain (tape 2) (labels .cleanup) exit | |
| def program (tape : Fin 5 → K) : | |
| Label → TM2.Stmt (Alphabet (K := K)) Label (σ × Option Bool) := | |
| statement tape id none | |
| def steps (values : List Nat) (index : Nat) : Nat := | |
| (2 * ((encodeWords values).length + 1) + MachineLookupSpec.steps values index + 1) + | |
| ((encodeWords (values.drop (index + 1))).length + 1) | |
| theorem remaining_length_le (values : List Nat) (index : Nat) : | |
| (encodeWords (values.drop (index + 1))).length ≤ (encodeWords values).length := by | |
| have h := congrArg (fun words : List Nat => (encodeWords words).length) | |
| (List.take_append_drop (index + 1) values) | |
| simp only [encodeWords_append, List.length_append] at h | |
| omega | |
| theorem steps_le (values : List Nat) (index value : Nat) | |
| (selected : values[index]? = some value) : | |
| steps values index ≤ 6 * (encodeWords values).length + 4 := by | |
| have hc := MachinePreservingLookup.preservingLookup_steps_le values index value selected | |
| have hd := remaining_length_le values index | |
| unfold steps | |
| omega | |
| noncomputable def timePolynomial : Polynomial Nat := 6 * Polynomial.X + 4 | |
| theorem steps_le_timePolynomial (values : List Nat) (index value : Nat) | |
| (selected : values[index]? = some value) : | |
| steps values index ≤ timePolynomial.eval (encodeWords values).length := by | |
| simpa only [timePolynomial, Polynomial.eval_add, Polynomial.eval_mul, | |
| Polynomial.eval_ofNat, Polynomial.eval_X] using steps_le values index value selected | |
| theorem traceAt (tape : Fin 5 → K) (distinct : Function.Injective tape) | |
| (labels : Label → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (code : ∀ label, target (labels label) = statement tape labels exit label) | |
| (base : K → List Bool) (values : List Nat) | |
| (tableWord : base (tape 0) = encodeWords values) | |
| (scratchEmpty : base (tape 4) = []) | |
| (index value : Nat) (selected : values[index]? = some value) | |
| (indexSuffix output : List Bool) (ambient : σ) (register : Option Bool) : | |
| (advance (TM2.step target))^[steps values index] | |
| (some ⟨some (labels (.run .copyFirst)), (ambient, register), | |
| MachinePreservingLookup.initialTapes tape base index indexSuffix [] output⟩) = | |
| some ⟨exit, (ambient, none), | |
| MachinePreservingLookup.initialTapes tape base 0 indexSuffix [] | |
| (encodeWord value ++ output)⟩ := by | |
| have hd (a b : Fin 5) (hne : a ≠ b) : tape a ≠ tape b := | |
| fun h => hne (distinct h) | |
| have raw := MachinePreservingLookup.preservingLookupTrace tape distinct | |
| MachinePreservingLookup.Label.copyFirst MachinePreservingLookup.Label.copySecond | |
| MachinePreservingLookup.Label.lookup none (MachinePreservingLookup.program tape) | |
| rfl rfl (fun _ => rfl) base values tableWord scratchEmpty index value selected | |
| indexSuffix [] output ambient register | |
| have run := MachineSubroutine.trace (fun label => labels (.run label)) | |
| (some (labels .cleanup)) (MachinePreservingLookup.program tape) target | |
| (fun label => code (.run label)) | |
| (2 * ((encodeWords values).length + 1) + MachineLookupSpec.steps values index + 1) | |
| _ _ raw | |
| simp only [MachineSubroutine.configuration, MachineSubroutine.label] at run | |
| have cleanup := MachineDrain.drainTrace (tape 2) (labels .cleanup) exit target | |
| (code .cleanup) | |
| (MachinePreservingLookup.finalTapes tape base values index value indexSuffix [] output) | |
| (encodeWords (values.drop (index + 1))) ambient none | |
| have word : MachinePreservingLookup.finalTapes tape base values index value | |
| indexSuffix [] output (tape 2) = encodeWords (values.drop (index + 1)) := by | |
| simp only [MachinePreservingLookup.finalTapes, | |
| MachineLookup.tapes_source _ _ _ (hd 2 3 (by decide)), List.append_nil] | |
| have start : Function.update | |
| (MachinePreservingLookup.finalTapes tape base values index value indexSuffix [] output) | |
| (tape 2) (encodeWords (values.drop (index + 1))) = | |
| MachinePreservingLookup.finalTapes tape base values index value indexSuffix [] output := by | |
| rw [← word, Function.update_eq_self] | |
| have finish : Function.update | |
| (MachinePreservingLookup.finalTapes tape base values index value indexSuffix [] output) | |
| (tape 2) [] = MachinePreservingLookup.initialTapes tape base 0 indexSuffix [] | |
| (encodeWord value ++ output) := by | |
| unfold MachinePreservingLookup.finalTapes MachinePreservingLookup.initialTapes | |
| rw [MachineLookup.update_source _ _ _ (hd 2 3 (by decide))] | |
| rw [start, finish] at cleanup | |
| rw [show steps values index = | |
| ((encodeWords (values.drop (index + 1))).length + 1) + | |
| (2 * ((encodeWords values).length + 1) + MachineLookupSpec.steps values index + 1) by | |
| unfold steps | |
| omega, | |
| Function.iterate_add_apply, run] | |
| exact cleanup | |
| def inTimeAt (tape : Fin 5 → K) (distinct : Function.Injective tape) | |
| (labels : Label → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (code : ∀ label, target (labels label) = statement tape labels exit label) | |
| (base : K → List Bool) (values : List Nat) | |
| (tableWord : base (tape 0) = encodeWords values) | |
| (scratchEmpty : base (tape 4) = []) | |
| (index value : Nat) (selected : values[index]? = some value) | |
| (indexSuffix output : List Bool) (ambient : σ) (register : Option Bool) : | |
| StateTransition.EvalsToInTime (TM2.step target) | |
| ⟨some (labels (.run .copyFirst)), (ambient, register), | |
| MachinePreservingLookup.initialTapes tape base index indexSuffix [] output⟩ | |
| (some ⟨exit, (ambient, none), | |
| MachinePreservingLookup.initialTapes tape base 0 indexSuffix [] | |
| (encodeWord value ++ output)⟩) | |
| (timePolynomial.eval (encodeWords values).length) where | |
| steps := steps values index | |
| evals_in_steps := traceAt tape distinct labels exit target code base values tableWord | |
| scratchEmpty index value selected indexSuffix output ambient register | |
| steps_le_m := steps_le_timePolynomial values index value selected | |
| theorem initialTapes_eq (tape : Fin 5 → K) (base : K → List Bool) | |
| (index : Nat) (indexSuffix : List Bool) | |
| (counterWord : base (tape 1) = encodeWord index ++ indexSuffix) | |
| (workEmpty : base (tape 2) = []) : | |
| MachinePreservingLookup.initialTapes tape base index indexSuffix [] (base (tape 3)) = | |
| base := by | |
| simp only [MachinePreservingLookup.initialTapes, MachineLookup.tapes, | |
| ← counterWord, ← workEmpty, Function.update_eq_self] | |
| theorem traceAt_fromTapes (tape : Fin 5 → K) (distinct : Function.Injective tape) | |
| (labels : Label → Λ) (exit : Option Λ) | |
| (target : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (code : ∀ label, target (labels label) = statement tape labels exit label) | |
| (base : K → List Bool) (values : List Nat) | |
| (tableWord : base (tape 0) = encodeWords values) | |
| (scratchEmpty : base (tape 4) = []) | |
| (index value : Nat) (selected : values[index]? = some value) | |
| (indexSuffix : List Bool) | |
| (counterWord : base (tape 1) = encodeWord index ++ indexSuffix) | |
| (workEmpty : base (tape 2) = []) (ambient : σ) (register : Option Bool) : | |
| (advance (TM2.step target))^[steps values index] | |
| (some ⟨some (labels (.run .copyFirst)), (ambient, register), base⟩) = | |
| some ⟨exit, (ambient, none), | |
| MachinePreservingLookup.initialTapes tape base 0 indexSuffix [] | |
| (encodeWord value ++ base (tape 3))⟩ := by | |
| have h := traceAt tape distinct labels exit target code base values tableWord scratchEmpty | |
| index value selected indexSuffix (base (tape 3)) ambient register | |
| rw [initialTapes_eq tape base index indexSuffix counterWord workEmpty] at h | |
| exact h | |
| def machine : FinTM2 where | |
| K := Fin 5 | |
| k₀ := 0 | |
| k₁ := 3 | |
| Γ _ := Bool | |
| Λ := Label | |
| main := .run .copyFirst | |
| σ := Unit × Option Bool | |
| initialState := ((), none) | |
| m := program id | |
| def machineInTime (base : Fin 5 → List Bool) (values : List Nat) | |
| (tableWord : base 0 = encodeWords values) (scratchEmpty : base 4 = []) | |
| (index value : Nat) (selected : values[index]? = some value) | |
| (indexSuffix output : List Bool) (register : Option Bool) : | |
| StateTransition.EvalsToInTime machine.step | |
| ⟨some (.run .copyFirst), ((), register), | |
| MachinePreservingLookup.initialTapes id base index indexSuffix [] output⟩ | |
| (some ⟨none, ((), none), | |
| MachinePreservingLookup.initialTapes id base 0 indexSuffix [] | |
| (encodeWord value ++ output)⟩) | |
| (timePolynomial.eval (encodeWords values).length) := | |
| inTimeAt id (fun _ _ h => h) id none (program id) (fun _ => rfl) | |
| base values tableWord scratchEmpty index value selected indexSuffix output () register | |
| end IndependentSetsGames.Foundations.Complexity.MachinePreservingLookupClean | |
| end OAI | |
Xet Storage Details
- Size:
- 9.62 kB
- Xet hash:
- c3f2cdc2f515c1210e2b7f4d21e305fc6781d0ef7863b9402548216739b58ead
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.