Documentation

MIPRE.TM.Code.WellFormed

Well-formed machine codes #

RawCode.WellFormed pins down when a raw description denotes a machine: alphabet of size at least two (symbols 0/1 are the I/O bits), a nonempty state set containing the start state, a dense transition table of exactly the canonical size stateCount * (alphabetSize + 1) ^ (i + workTapeCount) (Turing.transitionIndex), and per-entry arity and range constraints.

The predicate comes with an executable checker RawCode.wellFormedB and the equivalence RawCode.wellFormedB_iff (decision D3 of planning/tm-infrastructure.md); through it, WellFormed is decidable, so concrete literals can be certified by decide. The Milestone C parser will run the same checker.

Code i bundles a raw code with its well-formedness proof; by proof irrelevance it is just as first-order as RawCode i (Code.ext, DecidableEq). Code.actionAt is the canonical table lookup, and the Code.actionAt_* lemmas expose the well-formedness facts about the entry it returns — every later consumer of table entries (the interpretation of Milestone B, the serialization of Milestone C, the universal machine of Milestones E–G) goes through this single, dependency-free access point.

The well-formedness predicate #

Executable check that a write action only writes symbols below the alphabet size.

Equations
Instances For
    theorem Turing.RawWrite.checkB_eq_true_iff {w : RawWrite} {σ : } :
    w.checkB σ = true ∀ (s : ), w = symbol ss < σ

    Executable check that a successor state, if any, is below the state count.

    Equations
    Instances For

      A raw code denotes a machine: the alphabet has at least the two I/O symbols, there is at least one state, the start state is in range, the transition table has exactly the canonical dense size, and every entry has the right arities and only in-range symbols and successor states.

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

        The executable well-formedness checker; RawCode.wellFormedB_iff proves it decides RawCode.WellFormed. The Milestone C parser accepts exactly the descriptions passing this check.

        The table loops run over toList with List.all (not Array.all) deliberately: List.all is structurally recursive, so the kernel can evaluate this checker and concrete literals can be certified by decide; Array.all does not kernel-reduce on this toolchain.

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

          The executable checker decides well-formedness.

          Named accessors for the conjuncts #

          theorem Turing.RawCode.WellFormed.write_lt {i : } {c : RawCode i} {a : RawAction} (h : c.WellFormed) (ha : a c.table) {wa : RawWorkAction} (hwa : wa a.workActions) {s : } (hs : wa.write = RawWrite.symbol s) :
          theorem Turing.RawCode.WellFormed.nextState_lt {i : } {c : RawCode i} {a : RawAction} (h : c.WellFormed) (ha : a c.table) {q : } (hq : q a.nextState) :

          The type of well-formed codes #

          structure Turing.Code (i : ) :

          A well-formed machine code: a raw description together with its well-formedness proof. By proof irrelevance, Code i is as first-order as RawCode i itself.

          • raw : RawCode i

            The underlying raw description.

          • wf : self.raw.WellFormed

            The well-formedness certificate.

          Instances For
            theorem Turing.Code.ext {i : } {c₁ c₂ : Code i} :
            c₁.raw = c₂.rawc₁ = c₂

            Codes with equal raw descriptions are equal (proof irrelevance).

            theorem Turing.Code.ext_iff {i : } {c₁ c₂ : Code i} :
            c₁ = c₂ c₁.raw = c₂.raw
            @[instance_reducible]
            Equations
            @[reducible, inline]
            abbrev Turing.Code.workTapeCount {i : } (c : Code i) :

            The number of work tapes of a coded machine.

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

              The alphabet size of a coded machine (at least 2).

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

                The number of states of a coded machine (at least 1).

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

                  The start state of a coded machine (in range by well-formedness).

                  Equations
                  Instances For
                    def Turing.Code.actionAt {i : } (c : Code i) (q : Fin c.stateCount) (as : Fin iOption (Fin c.alphabetSize)) (bs : Fin c.workTapeCountOption (Fin c.alphabetSize)) :

                    The canonical table lookup: the entry of the dense transition table at the normative position transitionIndex q as bs. All later consumers of table entries go through this single access point.

                    Equations
                    Instances For
                      theorem Turing.Code.actionAt_mem {i : } (c : Code i) (q : Fin c.stateCount) (as : Fin iOption (Fin c.alphabetSize)) (bs : Fin c.workTapeCountOption (Fin c.alphabetSize)) :
                      c.actionAt q as bs c.raw.table
                      theorem Turing.Code.actionAt_write_lt {i : } {c : Code i} {q : Fin c.stateCount} {as : Fin iOption (Fin c.alphabetSize)} {bs : Fin c.workTapeCountOption (Fin c.alphabetSize)} {wa : RawWorkAction} (hwa : wa (c.actionAt q as bs).workActions) {s : } (hs : wa.write = RawWrite.symbol s) :
                      theorem Turing.Code.actionAt_nextState_lt {i : } {c : Code i} {q : Fin c.stateCount} {as : Fin iOption (Fin c.alphabetSize)} {bs : Fin c.workTapeCountOption (Fin c.alphabetSize)} {q' : } (hq' : q' (c.actionAt q as bs).nextState) :