Body machine: peek, default-move, and apply phases #
Phase lemmas for the body machine's interaction with the three virtual
tapes (the +1-shift shadows of the simulated input/work/output tapes,
VTape.lean):
peek_correct— the two-step peek captures the at-origin flags and restores all tapes exactly;segCheck_default_step/segCheck_continue_step— the no-match branch's sanitized default moves (trick 4) and the ordinary continue step;appQ'_loop— the overwrite copy of the new state from scratch onto the state tape (trick 2);appAct_all— the ten-step decode of the five 2-cell action groups (trick 6), transforming the three virtual tapes exactly as one sanitized simulated action.
grpΓw_eq_decΓw / grpDir_eq_decDir bridge the machine's 2-bit group
decoders to the description decoders in Desc.lean.
The peek phase (peek1 → peek2 → seek1 f): in two steps the
body machine captures the at-origin flags of the three virtual tapes and
restores every tape exactly. The flags are honest: the machine proceeds
to seek1 (decide (sim0.head = 0), decide (sim1.head = 0), decide (sim2.head = 0)).
The no-match default step (segCheck f reading □ → dfScr,
trick 4): one step applies the default action's sanitized moves to the
three virtual tapes — right where the at-origin flag is set, stay
otherwise — matching the interpreted machine's sanitized stay
directions. All writes are read-backs; every other tape is preserved
exactly.
The segCheck continue step (segCheck f reading non-□ → mmScr f):
a pure control-state change — every tape is preserved exactly.
The apply-phase state overwrite (appQ' f, trick 2): with the state
head at a (old cells S, blank at distance n) and the scratch head
at e (cells E, ▷-free), the machine copies n scratch symbols
over the old state — reading the old state cell to know when to stop —
then idles once on the □ into appAct f 0 none. Total n + 1 steps;
the scratch tape and every other tape are exactly preserved.
The full apply-phase action decode (appAct f 0 none → … → clScr,
trick 6): ten steps consume the ten scratch action cells E e .. E (e+9)
in five 2-cell groups — write ww on vWork (g0), write wo on vOut
(g1), move vInput (g2), move vWork (g3), move vOut (g4) — each write
suppressed to □ and each move forced right where the corresponding
at-origin flag is set, matching the interpreted machine's sanitized
action exactly (note sim.write at the origin is itself a structural
no-op, so the stated sim-side write is unconditional). The scratch tape
ends at head e + 10 with cells unchanged; the state, desc, input, and
output tapes are preserved exactly.