The encoded machine step, inside the algebra — proof internals #
Complexitylib.Classes.P.Cobham.Internal.Encoding shows that one machine step
acts on an encoded configuration blockwise, via tapeStepBlocks. This module
shows the other half: that tapeStepBlocks is in Cobham's algebra once the
written symbol and the direction are fixed constants — which they are inside one
branch of Cobham.tableFn, since the branch is selected by the (state,
read-symbols) key.
Each half-block of the successor is a short composition of toolkit members:
Cobham.takeFn and Cobham.dropFn at width two, Cobham.appendFn,
Cobham.const, and one Cobham.padFn to restore the block width.
Main results #
Complexity.Cobham.tapeStepBlocksFst,Complexity.Cobham.tapeStepBlocksSnd— both half-blocks of a stepped tape are in the algebra
The left half-block after a step is in the algebra. For a fixed direction and written symbol it is one of: the old left block unchanged (stay), the symbol prepended (right), or two bits dropped (left).
The right half-block after a step is in the algebra. For a fixed direction and written symbol it is the old right block with its leading symbol replaced (stay), consumed (right), or pushed back together with the nearest left symbol (left).
Tape j's two half-blocks, read out of an encoded configuration. Block
0 is the state, so tape j occupies blocks 2j+1 and 2j+2 — exactly the
indices tapesStepFn addresses with Cobham.blockFn.
The transition key #
The key is the state together with the symbol under every head. Reading it out of
an encoding is one takeFn per field: the state block truncated to |Q| bits,
then the first two bits of each tape's right half-block.
The read symbols of the tapes from index j on, m of them.
Equations
- Complexity.Cobham.readsFn R 0 j z = []
- Complexity.Cobham.readsFn R m_2.succ j z = List.take 2 (Complexity.blockAt R z (2 * j + 2)) ++ Complexity.Cobham.readsFn R m_2 (j + 1) z
Instances For
The transition key, read out of an encoded configuration.
Equations
- Complexity.Cobham.keyFn R q m z = List.take q (Complexity.blockAt R z 0) ++ Complexity.Cobham.readsFn R m 0 z
Instances For
The whole key, read out of an encoded configuration.
Lifting across all the tapes #
A machine has a fixed number of tapes, so stepping all of them is a finite
composition — the recursion below is at the meta level, over the list of
per-tape actions, not inside the algebra. Tape j occupies blocks 2j+1 and
2j+2 (block 0 is the state), which Cobham.blockFn addresses.
The algebra-side tape step computes the machine-side one. Reading the
half-blocks out of the encoding (blockAt) gives exactly the tapes' own
half-blocks, so tapesStepFn reproduces the blockwise map of
tapesBlocks_tapesStep.
One whole branch of the transition table: the new state block (a constant) followed by every tape stepped.
Equations
- Complexity.Cobham.branchFn R q' acts z = Complexity.padTo R q' ++ Complexity.Cobham.tapesStepFn R acts 0 z
Instances For
A transition-table branch is in the algebra. With the branch fixed, the new state code and every tape's write and direction are constants, so the whole successor configuration is a finite composition of toolkit members.
The join. For a fixed transition-table branch, the algebra-side successor
branchFn — built purely from takeFn/dropFn/appendFn/padFn/const — is
the encoding of the machine's successor configuration.
This is the point where the two halves of the development meet: the machine side
(cfgBlocks_step, from the six write-and-move lemmas) and the algebra side
(tapesStepFn, in the class by branchFn_mem).
The whole transition table #
A machine has finitely many (state, read-symbols) keys, so the transition
function is a finite table: one branchFn per key, selected by matching the key
read out of the encoding against the key's constant pattern.
The transition table's index set: every (state, read-symbols) pair.
Equations
Instances For
The branch a transition key selects. A halting key stands still: the machine has stopped, but the simulation runs for a fixed polynomial number of steps, so the encoding has to be a fixed point from then on.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The table selects the configuration's own branch. The key read out of the
encoding is the configuration's key, and by keyPattern_injective no other
entry's pattern matches it.
The encoded step computes the machine step.
Length bounds #
Cobham.iterFn needs one polynomial bound covering every iterate, including
the ones reached from junk inputs. Both simulated steps keep an encoding inside a
fixed number of blocks, which is all the bound needs.
Rewinding the output head #
The encoding splits a tape at its head, so reading a tape off an encoding is
easy only when the head sits at cell 0 — then the left half is empty and the
right half is the whole tape, in order. Driving the head back to cell 0 is a
separate iteration, of a step that moves one cell left and writes nothing.
It is stated on one tape's pair of half-blocks rather than on a whole
configuration: after the simulation only the output tape matters, and a pair of
blocks splits with one takeFn/dropFn.
One rewind step. The head moves one cell left, except at cell 0 — where
it reads ▷ and stays put, which is also what the machine model does. The symbol
written back is the one just read, so nothing changes but the head.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The rewind step computes a left move. Away from cell 0 the symbol
written back is the one read, so tapeStepBlocks_eq applies with
Tape.write_read_self; at cell 0 the head reads ▷ and both sides stand
still.
The initial encoding #
At the start every tape but the input is blank and every head is at cell 0, so
the encoding is a constant apart from the input tape's right half-block — which
is the input string at two bits per cell. Zero padding is blank padding, which
is why symCode Γ.blank = [0,0].
A bitstring as tape cells, two bits each.
Equations
- Complexity.Cobham.encodeBits x = List.flatMap (fun (b : Bool) => Complexity.Cobham.symCode (Complexity.Γ.ofBool b)) x