The universal machine's loop body #
One simulated step of the interpreted description: own halt check, peek
(capture the at-origin flags of the three virtual tapes), seek to the entry
region, first-match key scan, action copy to scratch, apply, or the
no-match default; then cleanup. See docs/UTM-design.md (appendix) for the
full state-machine design and the correspondence tricks (q'-length sync via
the state tape, uniform mismatch path, sanitized default moves).
Tape layout: 0 vInput, 1 vWork, 2 vOut (virtual tapes, +1-shift
representation, VTape.lean), 3 state, 4 desc, 5 scratch. The real input
and output tapes are untouched (the loop verdict on the output tape is
written by the halt-test machine, not the body).
This file defines the machine only; its HoareTime spec and the
correspondence with TMDesc.toTM.step live in BodyInternal.lean (M3).
At-origin flags for the three virtual tapes (input, work, output):
true = the simulated head is at position 0 (reading ▷), captured by
the peek phase and threaded through the match/apply phases.
Instances For
Control states of the body machine. See the design appendix.
- hc0 : BodyQ
Halt check: skip desc field 1 (qstart).
- hc1 : BodyQ
Halt check: lockstep-compare state tape vs desc field 2 (qhalt).
- haltRewS : BodyQ
Machine already halted: rewind state, then desc, exit as no-op.
- haltRewD : BodyQ
- preRewS : BodyQ
Not halted: rewind state, then desc, proceed to peek.
- preRewD : BodyQ
- peek1 : BodyQ
Peek: virtual heads step left, read (▷ ⟺ at sim-origin), step back.
- peek2 : BodyQ
- seek1
(f : VFlags)
: BodyQ
Seek desc head past two
□s to the entry region. - seek2 (f : VFlags) : BodyQ
- cmpQ
(f : VFlags)
: BodyQ
Key scan: state field (lockstep with state tape).
- cmpS
(f : VFlags)
(idx : Fin 6)
: BodyQ
Key scan: the six symbol cells (vs live virtual reads).
- skipSeg
(f : VFlags)
: BodyQ
Mismatch: skip desc to the cell after the next
□. - segCheck
(f : VFlags)
: BodyQ
After a
□: another□means no-match (default); else next segment. - mmScr
(f : VFlags)
: BodyQ
Mismatch cleanup: blank-rewind scratch.
- rewindSt
(f : VFlags)
: BodyQ
Mismatch cleanup: rewind state head, then resume the key scan.
- copyQ'
(f : VFlags)
: BodyQ
Copy the q' field to scratch, state head counting down (trick 1).
- copyAct
(f : VFlags)
(j : Fin 10)
: BodyQ
Copy the ten action cells to scratch.
- appRewScr
(f : VFlags)
: BodyQ
Apply: rewind scratch.
- appQ'
(f : VFlags)
: BodyQ
Apply: overwrite the state tape with the new state (trick 2).
- appAct
(f : VFlags)
(g : Fin 5)
(pending : Option Bool)
: BodyQ
Apply: decode five 2-cell action groups and act (trick 6).
- dfScr : BodyQ
Default path: blank-rewind scratch, blank state, copy qhalt field.
- dfStRew : BodyQ
- dfBlank : BodyQ
- dfStRew2 : BodyQ
- dfDescRew : BodyQ
- dfSkip : BodyQ
- dfCopy : BodyQ
- dfStRew3 : BodyQ
- dfDescRew2 : BodyQ
- clScr : BodyQ
Cleanup after apply: blank-rewind scratch, rewind state and desc.
- clSt : BodyQ
- clDesc : BodyQ
- bodyDone : BodyQ
Body halt state.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Tape indices, for readability (0 vInput, 1 vWork, 2 vOut, 3 state, 4 desc, 5 scratch).
Equations
Instances For
Work-tape index of the simulated work tape.
Equations
Instances For
Work-tape index of the simulated output tape.
Equations
Instances For
Work-tape index of the state tape.
Equations
Instances For
Work-tape index of the description tape.
Equations
Instances For
Work-tape index of the scratch tape.
Equations
Instances For
The simulated read of a virtual tape: ▷ at the origin, else the live
cell under the (stationary) shadow head.
Equations
- Complexity.TM.UTMBody.simRead flag live = if flag = true then Complexity.Γ.start else live
Instances For
Bit value of a desc-tape cell (Γ.one ↦ true, all else false).
Equations
Instances For
A bit as the Γ symbol a desc-tape cell should hold.
Equations
Instances For
Decode a 2-bit group as a write symbol (must match decΓw):
00→0, 01→1, 10→□, 11→□.
Equations
Instances For
Decode a 2-bit group as a direction (must match decDir):
00→left, 01→right, 10→stay, 11→stay.
Equations
Instances For
The expected desc cell at key-symbol index idx (0,1 = input symbol's
two encoding bits; 2,3 = work; 4,5 = output), given the flags and live
virtual reads.
Equations
- Complexity.TM.UTMBody.keyCell f v0 v1 v2 0 = Complexity.TM.UTMBody.bitCell (Complexity.TM.UTMBody.simRead f.1 v0).encode[0]!
- Complexity.TM.UTMBody.keyCell f v0 v1 v2 1 = Complexity.TM.UTMBody.bitCell (Complexity.TM.UTMBody.simRead f.1 v0).encode[1]!
- Complexity.TM.UTMBody.keyCell f v0 v1 v2 2 = Complexity.TM.UTMBody.bitCell (Complexity.TM.UTMBody.simRead f.2.1 v1).encode[0]!
- Complexity.TM.UTMBody.keyCell f v0 v1 v2 3 = Complexity.TM.UTMBody.bitCell (Complexity.TM.UTMBody.simRead f.2.1 v1).encode[1]!
- Complexity.TM.UTMBody.keyCell f v0 v1 v2 4 = Complexity.TM.UTMBody.bitCell (Complexity.TM.UTMBody.simRead f.2.2 v2).encode[0]!
- Complexity.TM.UTMBody.keyCell f v0 v1 v2 5 = Complexity.TM.UTMBody.bitCell (Complexity.TM.UTMBody.simRead f.2.2 v2).encode[1]!
Instances For
A per-tape action: write this symbol and move this way (direction is
sanitized against ▷ by the builder). none = idle.
Equations
Instances For
Build a full δ output from per-work-tape actions; the real input and
output tapes always idle. Directions are sanitized (▷ ⇒ right), so
δ_right_of_start holds by construction.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The body machine's transition function.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.TM.UTMBody.bodyδ Complexity.TM.UTMBody.BodyQ.bodyDone iH wH oH = Complexity.TM.UTMBody.idle Complexity.TM.UTMBody.BodyQ.bodyDone iH wH oH
Instances For
The body machine.
Equations
- One or more equations did not get rendered due to their size.