Single-tape simulation — encoding internals #
Foundations for NTM.singleTapeSim (see docs/A4-SingleTapeSimulation.md):
the binary symbol codec and the block-index arithmetic for laying k work
tapes onto one. These are path-independent: any single-work-tape encoding
over the fixed alphabet Γ = {0,1,□,▷} needs a binary code (so that literal
□ can serve as the end-of-used-region sentinel) and a per-position block
layout. Proof internals only — correctness of the full simulation is
established downstream.
Binary symbol codec #
A writable symbol Γw = {0,1,□} is stored in two cells over {0,1} (never
□), so that a literal □ inside the used region is impossible and can mark
its end. Code: □ ↦ 00, 0 ↦ 01, 1 ↦ 10.
Encode a writable symbol as a 2-cell binary code.
Equations
Instances For
Encode a writable symbol into a 2-cell writable code (for SCATTER's
symbol writes; agrees with encSym under Γw.toΓ, see encSymW_toΓ).
Equations
Instances For
Decode a 2-cell code back to a writable symbol (any non-code pair ↦ □).
Equations
Instances For
Codec on the full read alphabet Γ, used by the invariant (which ranges
over work-tape cells of type Γ). ▷ ↦ 00 is junk: ▷ never occurs at a
work-tape position ≥ 1, so the round-trip below excludes it.
Equations
- Complexity.NTM.SingleTape.encSymΓ Complexity.Γ.blank = (Complexity.Γ.zero, Complexity.Γ.zero)
- Complexity.NTM.SingleTape.encSymΓ Complexity.Γ.zero = (Complexity.Γ.zero, Complexity.Γ.one)
- Complexity.NTM.SingleTape.encSymΓ Complexity.Γ.one = (Complexity.Γ.one, Complexity.Γ.zero)
- Complexity.NTM.SingleTape.encSymΓ Complexity.Γ.start = (Complexity.Γ.zero, Complexity.Γ.zero)
Instances For
Decode a 2-cell code over Γ (any non-code pair ↦ □).
Equations
Instances For
Block layout #
Position-major: super-position p ≥ 1 occupies a block of blockWidth k = 3*k
cells starting at blockStart k p = 1 + (p-1)*3k. Within a block, tape j
uses offsets 3j, 3j+1 (symbol code) and 3j+2 (head-present bit). Cell 0 is
the global ▷.
Cells per super-position block: 2 symbol cells + 1 head bit, per tape.
Equations
Instances For
First cell of the block for super-position p ≥ 1.
Equations
- Complexity.NTM.SingleTape.blockStart k p = 1 + (p - 1) * Complexity.NTM.SingleTape.blockWidth k
Instances For
The first super-position's block starts at cell 1, directly after the ▷.
Consecutive blocks are exactly blockWidth k apart.
Blocks start at or after cell 1 (never the ▷ cell 0).
The cell holding tape j's head-present bit within block p (offset 0 of
the triple: head-bit-first, so a sweep learns "head here" before passing
the symbol cells).
Equations
- Complexity.NTM.SingleTape.headBitCell k p j = Complexity.NTM.SingleTape.blockStart k p + 3 * ↑j
Instances For
The first (high) symbol cell of tape j within block p (offset 1; the low
symbol cell is symCell + 1 at offset 2).
Equations
- Complexity.NTM.SingleTape.symCell k p j = Complexity.NTM.SingleTape.blockStart k p + 3 * ↑j + 1
Instances For
Within a block, tape j's three cells stay inside [blockStart, blockStart+3k).
Block starts are monotone (non-strict) in the position.
Tape j's whole triple fits strictly before the next block:
headBitCell + 3 ≤ blockStart (p+1) (the +2 cell is the last of the triple).
The simulation invariant #
SimInvAt k t w M asserts that the single work tape t encodes the k
work tapes w, with the used region materialized up to super-position M
(the maximum position any head has reached). This is the relation preserved by
one simulated macro-step; the two behavioural lemmas of singleTapeSim follow
from base case + preservation + iteration. See docs/A4-SingleTapeSimulation.md.
The single tape t encodes the k work tapes w, materialized up to M.
Cell 0 is the global start marker
▷.Each encoded work tape has
▷at its own cell 0.No encoded work tape has
▷at a position≥ 1(writes useΓw).Every head is within the materialized region.
- headBit (p : ℕ) : 1 ≤ p → p ≤ M → ∀ (j : Fin k), t.cells (headBitCell k p j) = if (w j).head = p then Γ.one else Γ.zero
Head-present bit at
(p, j)is set iff tapej's head is at positionp. - sym (p : ℕ) : 1 ≤ p → p ≤ M → ∀ (j : Fin k), t.cells (symCell k p j) = (encSymΓ ((w j).cells p)).1 ∧ t.cells (symCell k p j + 1) = (encSymΓ ((w j).cells p)).2
The two symbol cells at
(p, j)hold the code of tapej's symbol atp. Everything from block
M+1onward is blank — the□sentinel region.
Instances For
Base case. The initial single tape Tape.init [] encodes the initial
k-tape configuration (all heads at 0, all blank), materialized to M = 0
(empty used region — the sentinel □ starts right at cell 1).
SimInvAt depends on the encoding tape only through its cells (never its
head), so it transfers along any cell-preserving change (e.g. a head move).
GATHER decode kernel (head off cell 0). When tape j's head is in the
materialized region, decoding its two symbol cells recovers exactly the
symbol under that head — what the sweep accumulates.
No □ inside the materialized region. Every cell strictly between the
▷ (cell 0) and the sentinel block is a code or head-bit cell, hence in
{0,1} — so the first □ a rightward sweep meets is exactly the sentinel
at blockStart k (M+1). (Holds vacuously for k = 0.)
No ▷ inside the materialized region. Every cell strictly between the
▷ (cell 0) and the sentinel block is a code or head-bit cell (in {0,1}),
hence never ▷ — so ▷ uniquely marks cell 0. The REWIND sweep's precondition.