Documentation

Complexitylib.Models.TuringMachine.UTM.Internal.SimLoop

Universal machine: the simulate/halt-test loop #

The headline correctness theorem for the UTM's main loop loopTM bodyTM haltTestTM: if the interpreted machine (decodeDesc α).toTM halts on x in T steps at the configuration mcF, then from any tapes realizing the standing invariant SimInv at the interpreted machine's initial configuration (output tape cleared, head parked at cell 1), the loop halts within (T + 1) * utmStepTime α steps with SimInv re-established at mcF and the halt verdict Γ.one at output cell 1.

Proof structure #

One loop iteration = one interpreted step:

The outer induction (loop_sim_aux) is a strong induction on the remaining fuel T - t' rather than an instance of loopTM_hoareTime: the loop variant would have to be a function of the tapes, while here it is determined only through the existentially quantified prefix run of the interpreted machine. Determinism of reachesIn plus the halted-configurations-don't-step principle (TM.reachesIn_le_halt) identify the loop's exit configuration with mcF.

Per-α time cost of one iteration of the UTM's simulate/halt-test loop: one body pass, the two combinator transitions, the halt test, and the loop's rewind/check bookkeeping.

Equations
Instances For
    theorem Complexity.TM.UTMBody.utm_loop_simulates (α x : List Bool) (hterm : TerminatedRegion α) (T : ) (mcF : Cfg 1 (decodeDesc α).toTM.Q) (hrun : (decodeDesc α).toTM.reachesIn T ((decodeDesc α).toTM.initCfg x) mcF) (hhalt : (decodeDesc α).toTM.halted mcF) (inp : Tape) (work : Fin 6Tape) (out : Tape) (hinv : SimInv α ((decodeDesc α).toTM.initCfg x) inp work out) (hout0 : out.cells 0 = Γ.start) (houtns : ∀ (j : ), 1 jout.cells j Γ.start) (houth : out.head = 1) :
    ∃ (c' : Cfg 6 (bodyTM.loopTM haltTestTM).Q), t ≤ (T + 1) * utmStepTime α, (bodyTM.loopTM haltTestTM).reachesIn t { state := (bodyTM.loopTM haltTestTM).qstart, input := inp, work := work, output := out } c' (bodyTM.loopTM haltTestTM).halted c' SimInv α mcF c'.input c'.work c'.output c'.output.cells 0 = Γ.start (∀ (j : ), 1 jc'.output.cells j Γ.start) c'.output.head = 1 c'.output.cells 1 = Γ.one

    The UTM loop simulates the interpreted machine. Suppose (decodeDesc α).toTM halts on x in T steps at mcF. Then from any tapes realizing SimInv at the interpreted machine's initial configuration — with the output tape -clean and parked at cell 1 — the loop loopTM bodyTM haltTestTM halts within (T + 1) * utmStepTime α steps, with SimInv re-established at mcF (so the virtual output tape shadows the simulated output) and the halt verdict Γ.one at output cell 1.

    theorem Complexity.TM.UTMBody.utm_loop_hoareTime (α x : List Bool) (hterm : TerminatedRegion α) (T : ) (mcF : Cfg 1 (decodeDesc α).toTM.Q) (hrun : (decodeDesc α).toTM.reachesIn T ((decodeDesc α).toTM.initCfg x) mcF) (hhalt : (decodeDesc α).toTM.halted mcF) :
    (bodyTM.loopTM haltTestTM).HoareTime (fun (inp : Tape) (work : Fin 6Tape) (out : Tape) => SimInv α ((decodeDesc α).toTM.initCfg x) inp work out out.cells 0 = Γ.start (∀ (j : ), 1 jout.cells j Γ.start) out.head = 1) (fun (inp : Tape) (work : Fin 6Tape) (out : Tape) => SimInv α mcF inp work out out.cells 0 = Γ.start (∀ (j : ), 1 jout.cells j Γ.start) out.head = 1 out.cells 1 = Γ.one) ((T + 1) * utmStepTime α)

    Hoare-style packaging of utm_loop_simulates, ready for seqTM composition with the init and extract phases.

    theorem Complexity.TM.UTMBody.utm_loop_extract_hoareTime (α x : List Bool) (hterm : TerminatedRegion α) (T : ) (mcF : Cfg 1 (decodeDesc α).toTM.Q) (hrun : (decodeDesc α).toTM.reachesIn T ((decodeDesc α).toTM.initCfg x) mcF) (hhalt : (decodeDesc α).toTM.halted mcF) :
    ((bodyTM.loopTM haltTestTM).seqTM extractTM).HoareTime (fun (inp : Tape) (work : Fin 6Tape) (out : Tape) => SimInv α ((decodeDesc α).toTM.initCfg x) inp work out out.cells 0 = Γ.start (∀ (j : ), 1 jout.cells j Γ.start) out.head = 1) (fun (x : Tape) (x_1 : Fin 6Tape) (out : Tape) => mT, mcF.output.cells (m + 1) = Γ.blank (∀ j < m, mcF.output.cells (j + 1) Γ.blank) jm, out.cells (j + 1) = mcF.output.cells (j + 1)) ((T + 1) * utmStepTime α + 1 + (2 * T + 9))

    Loop + extraction: after the simulate/halt-test loop, extractTM copies the virtual output tape onto the real output tape. The combined machine turns the loop's precondition into the final output guarantee: the real output tape agrees with the simulated machine's final output tape (cells 1, …, m + 1) through the latter's first blank.

    theorem Complexity.TM.UTMBody.utmTM_hoareTime (α x : List Bool) (hterm : TerminatedRegion α) (T : ) (mcF : Cfg 1 (decodeDesc α).toTM.Q) (hrun : (decodeDesc α).toTM.reachesIn T ((decodeDesc α).toTM.initCfg x) mcF) (hhalt : (decodeDesc α).toTM.halted mcF) :
    utmTM.HoareTime (fun (inp : Tape) (work : Fin 6Tape) (out : Tape) => inp = Tape.init (List.map Γ.ofBool (pair α x)) (∀ (i : Fin 6), work i = Tape.init []) out = Tape.init []) (fun (x : Tape) (x_1 : Fin 6Tape) (out : Tape) => mT, mcF.output.cells (m + 1) = Γ.blank (∀ j < m, mcF.output.cells (j + 1) Γ.blank) jm, out.cells (j + 1) = mcF.output.cells (j + 1)) (4 * (pair α x).length + 4 * (groupPairs α).length + 24 + 1 + ((T + 1) * utmStepTime α + 1 + (2 * T + 9)))

    The universal machine's end-to-end specification. On the standard initial tapes for input pair α x, if the interpreted machine (decodeDesc α).toTM halts on x at mcF within T steps, then utmTM halts within 4·|pair α x| + 4·|groupPairs α| + 26 + (T + 1)·utmStepTime α + 2T + 9 steps with its real output tape agreeing with the simulated machine's final output tape through the latter's first blank — i.e. the UTM computes exactly the simulated machine's output.