Reading a string out of an encoded tape — proof internals #
The completeness direction ends by reading the simulated machine's output off
its encoded output tape. Once the output head has been driven back to cell 0
(see Complexitylib.Classes.P.Cobham.Internal.StepAlgebra), that tape's right
half-block is the whole tape in order, two bits per cell: the first bit of a
cell says whether it holds data, the second is the data bit.
So the output is recovered by two short recursions on notation, both collected here:
Complexity.cellBits— every second bit of a string, from a fixed offset; used twice, once for the "is data" bits and once for the data bits;Complexity.runTrue— the leading run oftrues, as a ruler; its length is where the first blank cell is, hence the output's length.
Main results #
Complexity.Cobham.cellBitsFn,Complexity.Cobham.runTrueFn— both are in the algebraComplexity.runTrue_length— the run's length is where the firstfalseis, clamped by the ruler
Reading a single bit #
Every second bit #
cellBits o z m lists the bits of z at positions o, o + 2, …, o + 2(m-1).
With z a run of two-bit symbol codes, offset o picks out one bit of each
symbol — which is how both halves of a coded cell are read.
The bits of z at positions 2i + o for i < m.
Equations
- Complexity.cellBits o z 0 = []
- Complexity.cellBits o z m.succ = Complexity.cellBits o z m ++ [Complexity.bitOf z (2 * m + o)]
Instances For
The leading run of trues #
The output tape's "is data" bits are true on the output and false at the
first blank past it, so the output's length is the length of the leading run of
trues. The recursion below computes it as a ruler, clamped at the width it is
run to: the guard m ≤ |previous| is what stops the run at the first false
rather than restarting after it.
The leading run of trues of z, clamped to m bits, as a ruler.
Equations
- Complexity.runTrue z 0 = []
- Complexity.runTrue z m.succ = Complexity.runTrue z m ++ if m ≤ (Complexity.runTrue z m).length ∧ Complexity.bitOf z m = true then [true] else []
Instances For
The run's length is where the first false is. The guard in runTrue
stops the run at the first false rather than restarting after it, so the run's
length is the position of the first false, clamped by the width.
Both recursions are in the algebra #
Every second bit is in the algebra. One limited recursion on notation:
each peeled bit of the ruler appends one more bit of z, read at twice the
remaining ruler's length plus the offset.
The leading run of trues is in the algebra. One limited recursion on
notation: the run grows by one only while it has kept pace with the ruler, which
is the length comparison nonemptyFn/notFn performs.