LBA → CS: configuration encoding and the run-induction skeleton #
This file develops the completeness half of myhill_language_eq
(Automata/LinearBounded/Equivalence/ContextSensitive.lean): an accepting LBA run on w
is mirrored by a derivation start ⇒* map terminal w of the Myhill grammar.
The plan factors the derivation as
start ⇒* encode w₀ (initial cfg) -- start_setup
⇒* encode w₀ cfg' -- CS_derives_of_reaches + step_sim
⇒* map terminal w -- cleanup
where encode reifies an LBA configuration as a list of cell nonterminals (defined here),
and CS_derives_of_reaches (proved here) lifts the single-step simulation over an entire
reachable run by induction on Relation.ReflTransGen.
This file pins down the encoding and the glue, and proves the three content lemmas
start_setup, step_sim, cleanup that assemble into completeness (the soundness direction is
in LBAToCSG/Soundness.lean).
Encoding of an LBA configuration as a Myhill sentential form: one cell per tape
position, recording the boundary flags (i = 0, i = n), whether the head — and its
state — sits at that cell, the current tape symbol, and the frozen original terminal
worig i.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run induction. If a single LBA step is mirrored by a context-sensitive derivation of
the encodings, then so is any reachable run. Pure ReflTransGen induction — the engine that
turns the per-step simulation step_sim into the full start ⇒* accepting derivation.
Rewriting a single nonterminal A at position k to the output [out] of a
context-free-shaped rule A → out is one context-sensitive step (List.set). The engine
for the head-stationary cases of the step simulation.
Rewriting nonterminal A at position k to [out] with the right neighbour L[k+1]
as context is one context-sensitive step (= L.set k out). Drives interior step 1.
Rewriting nonterminal A at position k+1 to [out] with the left neighbour L[k]
as context is one context-sensitive step (= L.set (k+1) out). Drives interior step 2.
Two-sided context rewrite at position j+1 (= L.set (j+1) out).
Two-sided context rewrite at position k ≥ 1 (= L.set k out); avoids j+1 mismatch.
Start phase: the startAux nonterminal lays down the non-head cells #
The interior/last cells produced by the startAux rules for an input list: every cell
carries lb = false and q = none; only the final cell carries rb = true.
Equations
- MyhillConstruction.auxCells embed [] = []
- MyhillConstruction.auxCells embed [t] = [MyhillConstruction.cellSym false true none (embed t) t]
- MyhillConstruction.auxCells embed (t :: t' :: rest) = MyhillConstruction.cellSym false false none (embed t) t :: MyhillConstruction.auxCells embed (t' :: rest)
Instances For
Right-to-left middle build. Starting from startAux :: tail, repeatedly applying the
middle-cell rule (startAux → [startAux, cell]) lays the none cells for mids immediately to
the right of startAux, in order. Applying the inductive hypothesis first (building ts to
the right) and the head step last keeps the cells in position order with no reversal.
auxCells splits as the none-cells for all but the last input, followed by the single
rb = true cell for the last input. This is the shape produced by the right-to-left build:
the rightmost cell comes from the start rule, the middles from preRow.
The full initial sentential form: the head cell (lb = true, state M.initial) at
position 0, followed by auxCells for the rest of the input.
Equations
- MyhillConstruction.startCells M embed [] = []
- MyhillConstruction.startCells M embed [t] = [MyhillConstruction.cellSym true true (some M.initial) (embed t) t]
- MyhillConstruction.startCells M embed (t :: t' :: rest) = MyhillConstruction.cellSym true false (some M.initial) (embed t) t :: MyhillConstruction.auxCells embed (t' :: rest)
Instances For
Start phase. start ⇒* startCells ts for any non-empty input list ts; this is the
initial sentential form encoding the LBA's initial configuration on ts.
Unfolding startCells on a cons whose tail is non-empty (a :: l matches clause 3).
Start-phase bridge. The cons-list startCells equals the positional encode of the
initial configuration (head at 0, state M.initial, tape embed ∘ worig). This connects
start_phase to the encode-based run simulation.
Step simulation: the stay case #
step_sim, stay case. A stay transition of the LBA is mirrored by a single
context-sensitive derivation step on the encodings (rewrite the head cell in place).
Moving right at the right boundary is clamped (no movement).
Moving left at the left boundary is clamped (no movement).
A stay move leaves the tape unchanged.
moveHead never changes the tape contents.
An interior right move increments the head position.
An interior left move decrements the head position.
An interior right step changes exactly the head cell (head leaves, symbol a' written)
and its right neighbour (head arrives with state q').
An interior left step changes exactly the head cell (at m+1; head leaves, symbol a'
written) and its left neighbour (at m; head arrives with state q'). Stated with
head = m + 1 so the indices m, m+1 match the three-step assembly.
step_sim, right-interior case. An interior right transition is mirrored by the
three-step cellPending protocol: park the head as a cellPending, place the new state on
the right neighbour, then resolve the pending cell.
step_sim, left-interior case. Mirror of the right-interior case.
step_sim, right-boundary case. A right transition with the head at the right end
is clamped, so it is mirrored by a single in-place rewrite (using the boundary rule).
step_sim, left-boundary case. A left transition with the head at the left end is
clamped, so it is mirrored by a single in-place rewrite (using the boundary rule).
Step simulation. Every single LBA step is mirrored by a context-sensitive derivation of the cell encodings — combining the stay, boundary, and interior cases.
Cleanup: an accepting configuration's encoding derives the terminal word #
A list of (head-free) cells, as grammar symbols, given their (lb, rb, a, t) data.
Equations
- MyhillConstruction.cleanupCells cs = List.map (fun (c : Bool × Bool × Γ × T) => MyhillConstruction.cellSym c.1 c.2.1 none c.2.2.1 c.2.2.2) cs
Instances For
Rightward propagation. A terminal followed by head-free cells derives to all terminals (each cell is converted by the left-propagation rule using the terminal on its left).
Leftward propagation. Head-free cells followed by a terminal derive to all terminals (each cell is converted by the right-propagation rule using the terminal on its right).
Two-sided propagation. A terminal flanked by head-free cells derives to all terminals.
Cleanup (list form). A list of head-free cells with one accepting (some q) cell at
position k derives to the list of terminals.
Cleanup. The encoding of an accepting configuration derives the terminal word.
Completeness (Fin-indexed). If the LBA, started on the configuration encoding worig,
reaches an accepting configuration, then the Myhill grammar derives the terminal word
map terminal worig. Assembles the start phase, the run simulation, and the cleanup.
Completeness. Every word accepted by the LBA is generated by the Myhill grammar.