TM State Normalization and Binary Encoding #
This file provides two pieces of general infrastructure for working with Turing machines:
State normalization: Convert any
TM nwith finite state typeQto an equivalent machine using statesFin (Fintype.card Q). This is needed whenever states must be represented as binary numbers (e.g., for encoding a TM description).Binary encoding primitives: Fixed-width encodings for tape symbols, write symbols, directions, and natural numbers, with roundtrip correctness proofs.
Main definitions #
State normalization #
TM.stateEquiv— canonical equivalenceQ ≃ Fin (Fintype.card Q)TM.normalize— normalize state type toFin (Fintype.card Q)TM.normalizeCfg— embed a config into the normalized state spaceTM.normalize_decidesInTime— behavioral equivalence
Binary encoding #
Γ.encode/Γ.decode— tape symbol ↔ 2 bitsΓw.encode— write symbol → 2 bitsDir3.encode— direction → 2 bitsNat.toBits/Nat.fromBits— fixed-width big-endian binary
Enumeration #
The canonical equivalence between a TM's states and Fin (Fintype.card Q).
Equations
- tm.stateEquiv = Fintype.equivFin tm.Q
Instances For
The canonical equivalence cast to Fin k given k = Fintype.card Q.
Equations
- tm.stateEquivOfCardEq hk = ⋯ ▸ tm.stateEquiv
Instances For
stateEquivOfCardEq agrees with stateEquiv on values.
Normalize a TM's state type to Fin (Fintype.card Q) via the canonical
equivalence. This preserves all computational behavior.
Noncomputable because Fintype.equivFin uses choice.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Configuration embedding: map a config with original states to normalized states.
Equations
- tm.normalizeCfg c = { state := tm.stateEquiv c.state, input := c.input, work := c.work, output := c.output }
Instances For
Stepping the normalized TM commutes with the state equivalence.
Multi-step simulation: normalized TM mirrors original TM.
Output is preserved by normalization.
Normalized TM decides the same language in the same time.
Decode 2 bits back to a tape symbol.
Equations
Instances For
All 4 tape symbols in canonical order.