Documentation

MIPRE.TM.Code.Semantics

Interpretation of machine codes #

Code.toTM interprets a well-formed machine code as an operational multi-input Turing machine (MIPRE.TM.MultiInput.Deterministic) over the alphabet Fin alphabetSize and state set Fin stateCount: the transition function looks up the dense table at the canonical position (Code.actionAt) and converts the raw entry into a transition output (Code.interpretAction), with every range fact supplied by well-formedness through the Code.actionAt_* lemmas. Code.toTM_tr records that this is definitional.

The machine code is the primary object and toTM its interpretation — never the other way around. Everything here is executable: no Fintype.elems, no choice, no noncomputable (planning/tm-infrastructure.md, decision D5 and Milestone B).

Bit-level input/output: coded machines read and write the reserved symbols 0/1 (Code.bitEmbedding, Code.bitInputs); every symbol they emit is one of the two bit symbols (Code.outputSymbol_isBit), so decoding outputs as bit strings (Code.decodeBitOutput) is total and faithful (Code.decodeBitOutput_map_bitEmbedding).

@[reducible, inline]
abbrev Turing.Code.Symbol {i : } (c : Code i) :

The alphabet of a coded machine.

Equations
Instances For
    @[reducible, inline]
    abbrev Turing.Code.State {i : } (c : Code i) :

    The state set of a coded machine.

    Equations
    Instances For

      The two reserved I/O symbols of a coded machine: false ↦ 0, true ↦ 1 (the alphabet has size at least two by well-formedness).

      Equations
      Instances For
        def Turing.Code.bitInputs {i : } (c : Code i) (x : Fin iList Bool) :
        Fin iList c.Symbol

        Present a tuple of bit strings as input strings over the machine alphabet.

        Equations
        Instances For
          def Turing.Code.interpretAction {i : } (c : Code i) (a : RawAction) (hmoves : a.inputMoves.size = i) (hworks : a.workActions.size = c.workTapeCount) (hwrite : waa.workActions, ∀ (s : ), wa.write = RawWrite.symbol ss < c.alphabetSize) (hnext : q'a.nextState, q' < c.stateCount) :

          Interpret one table entry as a transition output, given the well-formedness facts for that entry: input moves and work actions are read off positionally, written symbols and successor states are cast into Fin using their range facts, and the output bit is embedded as a reserved I/O symbol.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            The operational machine denoted by a code: start in the coded start state, and transition by looking up the dense table at the canonical position.

            Equations
            Instances For
              @[simp]
              theorem Turing.Code.toTM_q₀ {i : } (c : Code i) :
              theorem Turing.Code.toTM_tr {i : } (c : Code i) (q : c.State) (as : Fin iOption c.Symbol) (bs : Fin c.workTapeCountOption c.Symbol) :
              c.toTM.tr q as bs = c.interpretAction (c.actionAt q as bs)

              The transition function of Code.toTM is, definitionally, the interpretation of the canonical table entry.

              @[simp]
              theorem Turing.Code.interpretAction_outS {i : } (c : Code i) (a : RawAction) (h₁ : a.inputMoves.size = i) (h₂ : a.workActions.size = c.workTapeCount) (h₃ : waa.workActions, ∀ (s : ), wa.write = RawWrite.symbol ss < c.alphabetSize) (h₄ : q'a.nextState, q' < c.stateCount) :
              (c.interpretAction a h₁ h₂ h₃ h₄).outS = Option.map (fun (b : Bool) => c.bitEmbedding b) a.output
              @[simp]
              theorem Turing.Code.toTM_tr_outS {i : } (c : Code i) (q : c.State) (as : Fin iOption c.Symbol) (bs : Fin c.workTapeCountOption c.Symbol) :
              (c.toTM.tr q as bs).outS = Option.map (fun (b : Bool) => c.bitEmbedding b) (c.actionAt q as bs).output

              The emitted symbol of a coded transition, at the level of raw data.

              theorem Turing.Code.interpretAction_q'_map_val {i : } (c : Code i) (a : RawAction) (h₁ : a.inputMoves.size = i) (h₂ : a.workActions.size = c.workTapeCount) (h₃ : waa.workActions, ∀ (s : ), wa.write = RawWrite.symbol ss < c.alphabetSize) (h₄ : q'a.nextState, q' < c.stateCount) :
              Option.map Fin.val (c.interpretAction a h₁ h₂ h₃ h₄).q' = a.nextState

              The successor state of a coded transition, at the level of raw data.

              theorem Turing.Code.toTM_tr_q'_map_val {i : } (c : Code i) (q : c.State) (as : Fin iOption c.Symbol) (bs : Fin c.workTapeCountOption c.Symbol) :
              Option.map Fin.val (c.toTM.tr q as bs).q' = (c.actionAt q as bs).nextState

              The successor state of Code.toTM, at the level of raw data.

              theorem Turing.Code.toTM_tr_q'_eq_none_iff {i : } (c : Code i) (q : c.State) (as : Fin iOption c.Symbol) (bs : Fin c.workTapeCountOption c.Symbol) :
              (c.toTM.tr q as bs).q' = none (c.actionAt q as bs).nextState = none

              A coded machine halts on an observation exactly when the table entry says to.

              Every symbol a coded machine emits is one of the two reserved bit symbols.

              Decode a machine-alphabet string as a bit string: symbol 1 is true, every other symbol is false. On outputs of coded machines this is faithful, because only the two bit symbols are ever emitted (Code.outputSymbol_isBit).

              Equations
              Instances For
                @[simp]