Canonical observation indexing for coded machines #
An observation of an i-input machine with w work tapes over the alphabet Fin σ is
a triple (q, as, bs) of a state q : Fin Q, the tuple as of symbols under the input
heads, and the tuple bs of symbols under the work heads (each an Option (Fin σ),
none being the blank). This file fixes, once and for all, the bijection between
observations and positions in a dense transition table.
Normative order #
This order is normative: the serialization format (Milestone C) and the universal machine's table lookup (Milestones E–G) cite it, and it must never change.
transitionIndex q as bs = q * (σ + 1) ^ (i + w) + obs, whereobsis the Horner evaluation (Turing.encodeDigits), in radixσ + 1, of the digit string consisting of the input-tape symbols in ascending tape order followed by the work-tape symbols in ascending tape order — input tape0is the most significant digit;- the digit of the blank
noneis0, and the digit of the symbola : Fin σisa + 1(Turing.encodeSymbol?).
Nothing here depends on Fintype.elems, hash or enumeration order, a chosen basis, or
choice: the order is fixed by the explicit recursions below (decision D5 of
planning/tm-infrastructure.md; deliberately not finFunctionFinEquiv, whose digit
order is owned by Mathlib). Both inverse laws are proved for symbols, observations, and
transition indices; the decode direction is consumed by the Milestone C parser and by the
universal machine.
Digit strings #
Horner evaluation of a digit string in radix r + 1; the first digit is the most
significant one.
Equations
- Turing.encodeDigits [] = 0
- Turing.encodeDigits (a :: l) = ↑a * (r + 1) ^ l.length + Turing.encodeDigits l
Instances For
Decode len digits (most significant first) from a natural number.
Equations
Instances For
Decoding inverts encoding on digit strings.
Encoding inverts decoding on numbers below (r + 1) ^ len.
Symbol digits #
The digit of an optional symbol: blank none is 0, symbol a is a + 1.
Equations
Instances For
Observations #
The digit string of an observation: input symbols then work symbols, both in
ascending tape order, input tape 0 most significant.
Equations
- Turing.observationDigits as bs = (List.ofFn fun (j : Fin i) => Turing.encodeSymbol? (as j)) ++ List.ofFn fun (d : Fin w) => Turing.encodeSymbol? (bs d)
Instances For
The canonical position of an observation's symbol part, below (σ + 1) ^ (i + w).
Equations
- Turing.encodeObservation as bs = ⟨Turing.encodeDigits (Turing.observationDigits as bs), ⋯⟩
Instances For
Recover the symbol tuples from an observation position.
Equations
- Turing.decodeObservation n = (fun (j : Fin i) => Turing.decodeSymbol? (Turing.decodeDigits σ (i + w) ↑n)[↑j], fun (d : Fin w) => Turing.decodeSymbol? (Turing.decodeDigits σ (i + w) ↑n)[i + ↑d])
Instances For
Transition indices #
The canonical position of an observation in a dense transition table:
q * (σ + 1) ^ (i + w) + obs. This order is normative (see the module docstring).
Equations
- Turing.transitionIndex q as bs = ⟨↑q * (σ + 1) ^ (i + w) + ↑(Turing.encodeObservation as bs), ⋯⟩
Instances For
Encoding inverts decoding on transition-table positions.