Documentation

Complexitylib.Models.TuringMachine.UTM.Encoding

TM State Normalization and Binary Encoding #

This file provides two pieces of general infrastructure for working with Turing machines:

  1. State normalization: Convert any TM n with finite state type Q to an equivalent machine using states Fin (Fintype.card Q). This is needed whenever states must be represented as binary numbers (e.g., for encoding a TM description).

  2. Binary encoding primitives: Fixed-width encodings for tape symbols, write symbols, directions, and natural numbers, with roundtrip correctness proofs.

Main definitions #

State normalization #

Binary encoding #

Enumeration #

noncomputable def Complexity.TM.stateEquiv {n : } (tm : TM n) :

The canonical equivalence between a TM's states and Fin (Fintype.card Q).

Equations
Instances For
    noncomputable def Complexity.TM.stateEquivOfCardEq {n k : } (tm : TM n) (hk : k = Fintype.card tm.Q) :
    tm.Q Fin k

    The canonical equivalence cast to Fin k given k = Fintype.card Q.

    Equations
    Instances For
      theorem Complexity.TM.stateEquivOfCardEq_val {n k : } (tm : TM n) (hk : k = Fintype.card tm.Q) (q : tm.Q) :
      ((tm.stateEquivOfCardEq hk) q) = (tm.stateEquiv q)

      stateEquivOfCardEq agrees with stateEquiv on values.

      noncomputable def Complexity.TM.normalize {n : } (tm : TM n) :
      TM n

      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
        noncomputable def Complexity.TM.normalizeCfg {n : } (tm : TM n) (c : Cfg n tm.Q) :

        Configuration embedding: map a config with original states to normalized states.

        Equations
        Instances For
          theorem Complexity.TM.normalize_step_comm {n : } (tm : TM n) (c : Cfg n tm.Q) :

          Stepping the normalized TM commutes with the state equivalence.

          theorem Complexity.TM.normalize_reachesIn {n : } (tm : TM n) {t : } {c c' : Cfg n tm.Q} (h : tm.reachesIn t c c') :

          Multi-step simulation: normalized TM mirrors original TM.

          theorem Complexity.TM.normalize_halted {n : } (tm : TM n) (c : Cfg n tm.Q) :

          Halting is preserved by normalization.

          theorem Complexity.TM.normalize_output {n : } (tm : TM n) (c : Cfg n tm.Q) :

          Output is preserved by normalization.

          theorem Complexity.TM.normalize_initCfg {n : } (tm : TM n) (x : List Bool) :

          The initial config normalizes correctly.

          theorem Complexity.TM.normalize_decidesInTime {n : } (tm : TM n) {L : Language} {T : } (h : tm.DecidesInTime L T) :

          Normalized TM decides the same language in the same time.

          Encode a write symbol as 2 bits: 0→00, 1→01, □→10.

          Equations
          Instances For

            Roundtrip: decode ∘ encode = some.

            theorem Complexity.mem_allΓ (g : Γ) :

            Every tape symbol appears in allΓ.

            allΓ contains no duplicates.

            allΓ has exactly 4 elements (one per Γ constructor).

            def Complexity.allΓFuncs (n : ) :
            List (Fin nΓ)

            Enumerate all functions Fin n → Γ in canonical (lexicographic) order.

            Equations
            Instances For
              theorem Complexity.mem_allΓFuncs (n : ) (f : Fin nΓ) :

              Every function Fin n → Γ appears in allΓFuncs n.