Documentation

MIPRE.TM.Code.Evaluator

The reference evaluator for coded machines #

Milestone D (planning/tm-infrastructure.md): the specification-side evaluator against which the universal machine (Milestones E–G) will be verified, independent of its eventual construction language. Everything is definitional over Code.toTM — this file re-implements nothing:

The three views agree (decision D12): evalWithin_eq_halted_iff and evalWithin_eq_timeout_iff characterize the budgeted evaluator by configurations, evalWithin_halted_mono makes budgeted results stable, and produces_iff_exists_evalWithin ties the relational semantics to the executable one — via the bit-level bridge outputString_isBit/map_bitEmbedding_decodeBitOutput (coded machines only ever emit the two reserved bit symbols, so decoding loses nothing). Produces.unique records that outputs are deterministic.

The BoundedResult bit codec is deliberately deferred to the Milestone F interface.

The step-indexed run #

def Turing.Code.runFor {i : } (c : Code i) (x : Fin iList Bool) (t : ) :

The configuration reached by the coded machine c on bit inputs x after t steps.

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

    The bits emitted by c on bit inputs x during the first t steps.

    Equations
    Instances For
      @[simp]
      theorem Turing.Code.runFor_zero {i : } (c : Code i) (x : Fin iList Bool) :
      theorem Turing.Code.runFor_succ {i : } (c : Code i) (x : Fin iList Bool) (t : ) :
      c.runFor x (t + 1) = MultiInputTM.step (c.runFor x t)
      theorem Turing.Code.runFor_add {i : } (c : Code i) (x : Fin iList Bool) (a b : ) :
      c.runFor x (a + b) = MultiInputTM.configs (c.runFor x a) b
      theorem Turing.Code.runFor_of_halt {i : } {c : Code i} {x : Fin iList Bool} {t : } (h : (c.runFor x t).state = none) (d : ) :
      c.runFor x (t + d) = c.runFor x t

      Once halted, the run is frozen.

      @[simp]
      theorem Turing.Code.outputFor_zero {i : } (c : Code i) (x : Fin iList Bool) :
      c.outputFor x 0 = []
      theorem Turing.Code.outputFor_of_halt {i : } {c : Code i} {x : Fin iList Bool} {t t' : } (hle : t t') (h : (c.runFor x t).state = none) :
      c.outputFor x t' = c.outputFor x t

      The output is frozen once the machine has halted.

      Budgeted evaluation #

      The result of running a coded machine under a step budget. Its canonical bit codec is deferred to the universal-machine interface (Milestone F).

      • timeout : BoundedResult

        The machine was still running when the budget ran out.

      • halted (output : List Bool) : BoundedResult

        The machine halted within the budget, with the given output bits.

      Instances For
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def Turing.Code.evalWithin {i : } (c : Code i) (x : Fin iList Bool) (T : ) :

          Budgeted evaluation: run for T steps; report the output if the machine has halted by then, and timeout otherwise. Total and executable.

          Equations
          Instances For
            theorem Turing.Code.evalWithin_eq_halted_iff {i : } {c : Code i} {x : Fin iList Bool} {T : } {y : List Bool} :
            theorem Turing.Code.evalWithin_halted_mono {i : } {c : Code i} {x : Fin iList Bool} {T T' : } {y : List Bool} (hle : T T') (h : c.evalWithin x T = BoundedResult.halted y) :

            Budgeted results are stable under enlarging the budget.

            The relational semantics #

            def Turing.Code.Produces {i : } (c : Code i) (x : Fin iList Bool) (y : List Bool) :

            The relational input/output semantics: c on bit inputs x halts with output bits y, in some time and space.

            Equations
            Instances For

              The bit-level bridge #

              @[simp]
              theorem Turing.Code.bitEmbedding_val_beq_one {i : } (c : Code i) (b : Bool) :
              ((c.bitEmbedding b) == 1) = b
              @[simp]
              theorem Turing.Code.decodeBitOutput_cons {i : } (c : Code i) (s : c.Symbol) (l : List c.Symbol) :
              c.decodeBitOutput (s :: l) = (s == 1) :: c.decodeBitOutput l
              theorem Turing.Code.outputString_isBit {i : } (c : Code i) {input : Fin iList c.Symbol} (cfg : MultiInputTM.Cfg i c.workTapeCount c.Symbol c.State input) (t : ) (s : c.Symbol) :
              s c.toTM.outputString cfg t∃ (b : Bool), s = c.bitEmbedding b

              Coded machines only ever emit the two reserved bit symbols.

              theorem Turing.Code.map_bitEmbedding_decodeBitOutput {i : } (c : Code i) {l : List c.Symbol} (h : sl, ∃ (b : Bool), s = c.bitEmbedding b) :
              List.map (fun (b : Bool) => c.bitEmbedding b) (c.decodeBitOutput l) = l

              Decoding is a section on strings of bit symbols.

              theorem Turing.Code.produces_iff_exists_evalWithin {i : } (c : Code i) (x : Fin iList Bool) (y : List Bool) :
              c.Produces x y ∃ (T : ), c.evalWithin x T = BoundedResult.halted y

              The relational and the budgeted views agree: c produces y exactly when some budget suffices to observe it.

              theorem Turing.Code.Produces.unique {i : } {c : Code i} {x : Fin iList Bool} {y y' : List Bool} (h : c.Produces x y) (h' : c.Produces x y') :
              y = y'

              Outputs are deterministic.

              Executable pins (Milestone B machines) #