Documentation

Complexitylib.Models.TuringMachine.Registers.ForReg

forRegTM: the register-fueled loop combinator #

forRegTM body r runs body once per mark of register r. The fuel is the head position on r: the register's cells are never written; the test reads the cell under the head — a mark means "iterate" (consume = move right, run the body), the first blank means "exit" (rewind r to cell 1 and halt). The body must leave r untouched (our ghost-style specs guarantee this for free, since bodies preserve every non-target tape literally).

This is the only loop mechanism of the reduction emitter (docs/A5-ReductionEmitter.md): unlike loopTM, its test reads a work tape, so the output tape remains an append-only accumulator throughout.

The Hoare rule forRegTM_hoareTime threads an iteration-indexed family of ghost work-tape functions and output words through the loop.

Driver phases of forRegTM: test reads the fuel register's cell (mark = iterate, blank = exit), rewind returns the register head to cell 1, done is the halt state.

Instances For
    @[implicit_reducible]
    Equations
    @[implicit_reducible]

    ForPhase is a finite type (it has exactly three constructors).

    Equations
    • One or more equations did not get rendered due to their size.
    def Complexity.TM.forRegTM {n : } (body : TM n) (r : Fin n) :
    TM n

    Register-fueled loop: run body once per mark of register r. States: the driver phases on the left, the body's states on the right.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Complexity.TM.forRegTM_hoareTime {n : } (body : TM n) (r : Fin n) (v : ) (inp₀ : Tape) (w : Fin nTape) (ys : List Bool) (b_iter : ) (hinp₀ : Parked inp₀) (hwreg : ∀ (i : ), w i r = regTape v) (hwP : ∀ (i : ) (j : Fin n), j rParked (w i j)) (hbody : i < v, body.HoareTime (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = inp₀ work = Function.update (w i) r { head := i + 2, cells := regCells v } OutAcc (ys i) out) (fun (inp : Tape) (work : Fin nTape) (out : Tape) => inp = inp₀ work = Function.update (w (i + 1)) r { head := i + 2, cells := regCells v } OutAcc (ys (i + 1)) out) b_iter) :
      (body.forRegTM r).HoareTime (EmitPred inp₀ (w 0) (ys 0)) (EmitPred inp₀ (w v) (ys v)) (v * (b_iter + 2) + (v + 2))

      forRegTM Hoare rule. Given a fuel register holding v (whose tape the iteration-indexed ghost family w never changes) and a body spec carrying w i / ys i to w (i+1) / ys (i+1), the loop carries w 0 / ys 0 to w v / ys v in at most v·(b_iter + 2) + v + 3 steps.