Imports
/-
Copyright (c) 2026 Terence Rokop. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Terence Rokop
-/
module
public import Geb.Prototypes.Computability.BitTree.Elias.Execution
public import Geb.Prototypes.Computability.BitTree.Elias.ScannerCorrect
public import Cslib.Computability.Machines.Turing.MultiTape.TapeLemmasset_option doc.verso trueResource bounds for the Elias-length recognizer
Work space counts all visited cells, including blank cells and marked origins. The input tape is read-only and excluded from CSLib's work-space measure.
Main statements
-
computableInTimeAndSpace_validBoolproves simultaneous quadratic time and linear space. -
spaceUsed_le_of_headBoundconverts the four head intervals to a work-space bound.
Implementation notes
The machine consumes each input bit once. Binary countdowns sweep their entire fixed-width words, including leading zeros, between input reads. Length fields are kept in binary, so malformed inputs advertising enormous payloads still halt within the same polynomial bound.
Tags
Elias delta code, Turing machine, running time, work space
@[expose] public sectionnamespace Geb.BitTree.Elias.Machineopen Turing MultiTapeTMFour heads confined to the same interval visit at most four times its number of cells.
theorem spaceUsed_le_of_headBound {input : List (Fin 3)}
(cfg : Cfg 4 (Fin 3) Control input) (width t : ℕ)
(h : ∀ u ≤ t, HeadBound width (machine.configs cfg u)) :
machine.spaceUsed cfg t ≤ 4 * (width + 1) := input:List (Fin 3)cfg:Cfg 4 (Fin 3) Control inputwidth:ℕt:ℕh:∀ u ≤ t, HeadBound width (configs cfg u)⊢ spaceUsed cfg t ≤ 4 * (width + 1)
input:List (Fin 3)cfg:Cfg 4 (Fin 3) Control inputwidth:ℕt:ℕh:∀ u ≤ t, HeadBound width (configs cfg u)hsub:∀ (i : Fin 4), visitedByTapeHead cfg t i ⊆ Finset.image (fun n ↦ ↑n) (Finset.range (width + 1))⊢ spaceUsed cfg t ≤ 4 * (width + 1)
have hi (i : Fin 4) : machine.spaceUsedByTape cfg t i ≤ width + 1 :=
(Finset.card_le_card (hsub i)).trans (Finset.card_image_le.trans (by input:List (Fin 3)cfg:Cfg 4 (Fin 3) Control inputwidth:ℕt:ℕh:∀ u ≤ t, HeadBound width (configs cfg u)hsub:∀ (i : Fin 4), visitedByTapeHead cfg t i ⊆ Finset.image (fun n ↦ ↑n) (Finset.range (width + 1))i:Fin 4⊢ (Finset.range (width + 1)).card ≤ width + 1 simp All goals completed! 🐙)) input:List (Fin 3)cfg:Cfg 4 (Fin 3) Control inputwidth:ℕt:ℕh:∀ u ≤ t, HeadBound width (configs cfg u)hsub:∀ (i : Fin 4), visitedByTapeHead cfg t i ⊆ Finset.image (fun n ↦ ↑n) (Finset.range (width + 1))hi:∀ (i : Fin 4), spaceUsedByTape cfg t i ≤ width + 1⊢ spaceUsed cfg t ≤ 4 * (width + 1)
calc
machine.spaceUsed cfg t ≤ ∑ _i : Fin 4, (width + 1) :=
Finset.sum_le_sum (fun i _ ↦ hi i)
_ = 4 * (width + 1) := by input:List (Fin 3)cfg:Cfg 4 (Fin 3) Control inputwidth:ℕt:ℕh:∀ u ≤ t, HeadBound width (configs cfg u)hsub:∀ (i : Fin 4), visitedByTapeHead cfg t i ⊆ Finset.image (fun n ↦ ↑n) (Finset.range (width + 1))hi:∀ (i : Fin 4), spaceUsedByTape cfg t i ≤ width + 1⊢ ∑ _i, (width + 1) = 4 * (width + 1) simp All goals completed! 🐙After all input bits, one final transition halts.
theorem halts_at (w : List Bool) :
(machine.configs (machine.initCfg (w.map boolEmb)) (1 + runCost w + 1)).state = none := by w:List Bool⊢ (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1)).state = none
have h := configs_account w w.length (Nat.le_refl _) w:List Boolh:have cost := 1 + runCost (List.take w.length w);
have a := account (List.take w.length w);
configs (initCfg (List.map (⇑boolEmb) w)) cost = modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ a.1 a.2.1 a.2.2 ∧
machine.outputString (initCfg (List.map (⇑boolEmb) w)) cost = [] ∧
∀ u ≤ cost, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1)).state = none
simp only [List.take_length] at h w:List Boolh:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2 ∧
machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = [] ∧
∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1)).state = none
obtain ⟨hc, _, _⟩ := h w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1)).state = none
rw [configs_succ_eq_step', w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ (MultiTapeTM.step (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w))).state = none hc w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ (MultiTapeTM.step
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)).state =
none] w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ (MultiTapeTM.step
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)).state =
none
rw [step_end _ (account w).1.1 rfl (inputSymbol_end _ (by w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ ↑(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2).inputPos =
(List.map (⇑boolEmb) w).length + 1
simp only [modelCfg, scanCfg, List.length_map] All goals completed! 🐙))] All goals completed! 🐙The only output is the decision of the Elias tree decoder.
theorem outputString_eq (w : List Bool) :
machine.outputString (machine.initCfg (w.map boolEmb)) (1 + runCost w + 1) =
[boolEmb (Elias.validBool w)] := by w:List Bool⊢ machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1) = [boolEmb (validBool w)]
have h := configs_account w w.length (Nat.le_refl _) w:List Boolh:have cost := 1 + runCost (List.take w.length w);
have a := account (List.take w.length w);
configs (initCfg (List.map (⇑boolEmb) w)) cost = modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ a.1 a.2.1 a.2.2 ∧
machine.outputString (initCfg (List.map (⇑boolEmb) w)) cost = [] ∧
∀ u ≤ cost, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1) = [boolEmb (validBool w)]
simp only [List.take_length] at h w:List Boolh:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2 ∧
machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = [] ∧
∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1) = [boolEmb (validBool w)]
obtain ⟨hc, ho, _⟩ := h w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1) = [boolEmb (validBool w)]
rw [outputString_succ, w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) ++
(outputSymbol (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w))).toList =
[boolEmb (validBool w)] ho, w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ [] ++ (outputSymbol (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w))).toList = [boolEmb (validBool w)] hc, w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ [] ++
(outputSymbol
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)).toList =
[boolEmb (validBool w)]
outputSymbol_end _ (account w).1.1 rfl (inputSymbol_end _ (by w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ ↑(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2).inputPos =
(List.map (⇑boolEmb) w).length + 1
simp only [modelCfg, scanCfg, List.length_map] All goals completed! 🐙)), account_project w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ [] ++ (some (boolEmb (decide ((Scanner.scan w).1 = Scanner.Mode.done)))).toList = [boolEmb (validBool w)]] w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ [] ++ (some (boolEmb (decide ((Scanner.scan w).1 = Scanner.Mode.done)))).toList = [boolEmb (validBool w)]
change [boolEmb (Scanner.validBool w)] = _ w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ [boolEmb (Scanner.validBool w)] = [boolEmb (validBool w)]
rw [Scanner.validBool_eq w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2ho:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []right✝:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ [boolEmb (validBool w)] = [boolEmb (validBool w)]] All goals completed! 🐙The final halting transition preserves the work-head interval.
theorem headBound_run (w : List Bool) :
∀ u ≤ 1 + runCost w + 1, HeadBound (w.length + 1)
(machine.configs (machine.initCfg (w.map boolEmb)) u) := by w:List Bool⊢ ∀ u ≤ 1 + runCost w + 1, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)
have h := configs_account w w.length (Nat.le_refl _) w:List Boolh:have cost := 1 + runCost (List.take w.length w);
have a := account (List.take w.length w);
configs (initCfg (List.map (⇑boolEmb) w)) cost = modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ a.1 a.2.1 a.2.2 ∧
machine.outputString (initCfg (List.map (⇑boolEmb) w)) cost = [] ∧
∀ u ≤ cost, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ ∀ u ≤ 1 + runCost w + 1, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)
simp only [List.take_length] at h w:List Boolh:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2 ∧
machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = [] ∧
∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ ∀ u ≤ 1 + runCost w + 1, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)
obtain ⟨hc, _, hh⟩ := h w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)⊢ ∀ u ≤ 1 + runCost w + 1, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)
intro u hu w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)u:ℕhu:u ≤ 1 + runCost w + 1⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)
by_cases he : u ≤ 1 + runCost w pos w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)u:ℕhu:u ≤ 1 + runCost w + 1he:u ≤ 1 + runCost w⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)u:ℕhu:u ≤ 1 + runCost w + 1he:¬u ≤ 1 + runCost w⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)
· pos w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)u:ℕhu:u ≤ 1 + runCost w + 1he:u ≤ 1 + runCost w⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u) exact hh u he All goals completed! 🐙
· neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)u:ℕhu:u ≤ 1 + runCost w + 1he:¬u ≤ 1 + runCost w⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u) have hu' : u = 1 + runCost w + 1 := by w:List Bool⊢ ∀ u ≤ 1 + runCost w + 1, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u) omega neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)u:ℕhu:u ≤ 1 + runCost w + 1he:¬u ≤ 1 + runCost whu':u = 1 + runCost w + 1⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)
subst u neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)hu:1 + runCost w + 1 ≤ 1 + runCost w + 1he:¬1 + runCost w + 1 ≤ 1 + runCost w⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1))
have hlast := hh (1 + runCost w) (Nat.le_refl _) neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)hu:1 + runCost w + 1 ≤ 1 + runCost w + 1he:¬1 + runCost w + 1 ≤ 1 + runCost whlast:HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w))⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1))
rw [hc neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)hu:1 + runCost w + 1 ≤ 1 + runCost w + 1he:¬1 + runCost w + 1 ≤ 1 + runCost whlast:HeadBound (w.length + 1)
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1))] at hlast neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)hu:1 + runCost w + 1 ≤ 1 + runCost w + 1he:¬1 + runCost w + 1 ≤ 1 + runCost whlast:HeadBound (w.length + 1)
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)⊢ HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w + 1))
rw [configs_succ_eq_step', neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)hu:1 + runCost w + 1 ≤ 1 + runCost w + 1he:¬1 + runCost w + 1 ≤ 1 + runCost whlast:HeadBound (w.length + 1)
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)⊢ HeadBound (w.length + 1) (MultiTapeTM.step (configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w))) hc, neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)hu:1 + runCost w + 1 ≤ 1 + runCost w + 1he:¬1 + runCost w + 1 ≤ 1 + runCost whlast:HeadBound (w.length + 1)
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)⊢ HeadBound (w.length + 1)
(MultiTapeTM.step (modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2))
step_end _ (account w).1.1 rfl (inputSymbol_end _ (by w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)hu:1 + runCost w + 1 ≤ 1 + runCost w + 1he:¬1 + runCost w + 1 ≤ 1 + runCost whlast:HeadBound (w.length + 1)
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)⊢ ↑(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2).inputPos =
(List.map (⇑boolEmb) w).length + 1
simp only [modelCfg, scanCfg, List.length_map] All goals completed! 🐙))] neg w:List Boolhc:configs (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) =
modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2left✝:machine.outputString (initCfg (List.map (⇑boolEmb) w)) (1 + runCost w) = []hh:∀ u ≤ 1 + runCost w, HeadBound (w.length + 1) (configs (initCfg (List.map (⇑boolEmb) w)) u)hu:1 + runCost w + 1 ≤ 1 + runCost w + 1he:¬1 + runCost w + 1 ≤ 1 + runCost whlast:HeadBound (w.length + 1)
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2)⊢ HeadBound (w.length + 1)
{ state := none,
inputPos :=
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2).inputPos,
workTapes :=
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2).workTapes,
workTapePos :=
(modelCfg (List.map (⇑boolEmb) w) ⟨w.length + 1, ⋯⟩ (account w).1 (account w).2.1 (account w).2.2).workTapePos }
exact hlast All goals completed! 🐙The one-pass Elias recognizer has simultaneous quadratic-time and linear-space bounds.
theorem computableInTimeAndSpace_validBool :
ComputableInTimeAndSpace (fun w : List Bool ↦ [Elias.validBool w])
(fun n ↦ 5 * n ^ 2 + 16 * n + 2) (fun n ↦ 4 * (n + 2)) := by ⊢ ComputableInTimeAndSpace (fun w ↦ [validBool w]) (fun n ↦ 5 * n ^ 2 + 16 * n + 2) fun n ↦ 4 * (n + 2)
refine ⟨4, 3, 25, boolEmb, machine, fun w ↦ ?_⟩ w:List Bool⊢ ∃ t' ≤ (fun n ↦ 5 * n ^ 2 + 16 * n + 2) w.length,
∃ s' ≤ (fun n ↦ 4 * (n + 2)) w.length,
machine.ComputesInTimeAndSpace (List.map (⇑boolEmb) w) (List.map (⇑boolEmb) ((fun w ↦ [validBool w]) w)) t' s'
refine ⟨1 + runCost w + 1, ?_,
machine.spaceUsed (machine.initCfg (w.map boolEmb)) (1 + runCost w + 1),
spaceUsed_le_of_headBound _ _ _ (headBound_run w),
halts_at w, outputString_eq w, rfl⟩ w:List Bool⊢ 1 + runCost w + 1 ≤ (fun n ↦ 5 * n ^ 2 + 16 * n + 2) w.length
change 1 + runCost w + 1 ≤ 5 * w.length ^ 2 + 16 * w.length + 2 w:List Bool⊢ 1 + runCost w + 1 ≤ 5 * w.length ^ 2 + 16 * w.length + 2
have h := runCost_le w w:List Boolh:runCost w ≤ 5 * w.length ^ 2 + 16 * w.length⊢ 1 + runCost w + 1 ≤ 5 * w.length ^ 2 + 16 * w.length + 2
omega All goals completed! 🐙end Geb.BitTree.Elias.Machine