Documentation

MIPRE.TM.Code.Encoding.MachineCode

Binary serialization of machine codes #

The normative description format (planning/tm-infrastructure.md, Milestone C):

encodeCode c = encodeNat 0 (version) · workTapeCount · alphabetSize · stateCount · startState · table entries in transitionIndex order

with every natural in the self-delimiting code of MIPRE.TM.Code.Encoding.Nat, and per entry: the i input moves (stay = 0, right = 10, left = 11), the w work actions (write keep = 0, blank = 10, symbol s = 11·encodeNat s, then the move), the output (none = 0, some b = 1·b), and the successor (none = 0, some q = 1·encodeNat q). The arity i is external, matching the paper's [α]_i.

decodeCodeExact parses, demands full consumption, and gates on the executable well-formedness checker; the three theorems at the end are Milestone C's exact-codec package: decodeCodeExact_encodeCode (round trip), encodeCode_injective, and decodeCodeExact_sound (canonicality: every accepted string is the canonical encoding of its parse). Every parser is paired with a prefix lemma and a soundness lemma, so soundness composes field by field (decision D11); everything is structurally recursive (decision D10).

Field codecs #

@[simp]
theorem Turing.parseMove_encodeMove (m : Move) (rest : List Bool) :
parseMove (encodeMove m ++ rest) = some (m, rest)
theorem Turing.parseMove_sound {s : List Bool} {m : Move} {rest : List Bool} :
parseMove s = some (m, rest)s = encodeMove m ++ rest
@[simp]
theorem Turing.parseWrite_sound {s : List Bool} {w : RawWrite} {rest : List Bool} :
parseWrite s = some (w, rest)s = encodeWrite w ++ rest

Encode an optional output bit: none = 0, some b = 1·b.

Equations
Instances For

    Parse an optional output bit.

    Equations
    Instances For
      theorem Turing.parseOutput_sound {s : List Bool} {o : Option Bool} {rest : List Bool} :
      parseOutput s = some (o, rest)s = encodeOutput o ++ rest

      Encode an optional successor state: none = 0, some q = 1·encodeNat q.

      Equations
      Instances For

        Parse an optional successor state.

        Equations
        Instances For

          Encode one work-tape action: the write, then the move.

          Equations
          Instances For

            Parse one work-tape action.

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

              Fixed-count sequences #

              def Turing.encodeListWith {α : Type u_1} (enc : αList Bool) (l : List α) :

              Concatenate elementwise encodings; the element count is protocol context (the parser is told how many to read), not part of the string.

              Equations
              Instances For
                @[simp]
                theorem Turing.encodeListWith_nil {α : Type u_1} (enc : αList Bool) :
                @[simp]
                theorem Turing.encodeListWith_cons {α : Type u_1} (enc : αList Bool) (a : α) (l : List α) :
                encodeListWith enc (a :: l) = enc a ++ encodeListWith enc l
                def Turing.parseCount {α : Type u_1} (p : List BoolOption (α × List Bool)) :

                Parse exactly k elements.

                Equations
                Instances For
                  theorem Turing.parseCount_encodeListWith {α : Type u_1} {p : List BoolOption (α × List Bool)} {enc : αList Bool} (l : List α) (henc : al, ∀ (rest : List Bool), p (enc a ++ rest) = some (a, rest)) (rest : List Bool) :
                  parseCount p l.length (encodeListWith enc l ++ rest) = some (l, rest)

                  Prefix property for fixed-count sequences; the elementwise prefix property is only required on the members of the encoded list.

                  theorem Turing.parseCount_encodeListWith' {α : Type u_1} {p : List BoolOption (α × List Bool)} {enc : αList Bool} (henc : ∀ (a : α) (rest : List Bool), p (enc a ++ rest) = some (a, rest)) (l : List α) (rest : List Bool) :
                  parseCount p l.length (encodeListWith enc l ++ rest) = some (l, rest)

                  Uniform-codec version of parseCount_encodeListWith.

                  theorem Turing.parseCount_sound {α : Type u_1} {p : List BoolOption (α × List Bool)} {enc : αList Bool} (hp : ∀ {s : List Bool} {a : α} {rest : List Bool}, p s = some (a, rest)s = enc a ++ rest) {k : } {s : List Bool} {l : List α} {rest : List Bool} :
                  parseCount p k s = some (l, rest)s = encodeListWith enc l ++ rest l.length = k

                  Soundness for fixed-count sequences.

                  Actions #

                  Encode one transition-table entry.

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

                    Parse one transition-table entry of an i-input, w-work-tape machine.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      @[simp]
                      theorem Turing.parseAction_encodeAction {i w : } (a : RawAction) (hmoves : a.inputMoves.size = i) (hworks : a.workActions.size = w) (rest : List Bool) :
                      parseAction i w (encodeAction a ++ rest) = some (a, rest)
                      theorem Turing.parseAction_sound {i w : } {s : List Bool} {a : RawAction} {rest : List Bool} (h : parseAction i w s = some (a, rest)) :

                      Machine codes #

                      Encode a raw machine description (version 0, header, dense table in canonical order).

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        def Turing.encodeCode {i : } (c : Code i) :

                        The canonical binary description of a machine code — the paper's α.

                        Equations
                        Instances For

                          Parse a raw machine description: version, header, then exactly the canonical number of table entries.

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

                            Exact decoding: parse, demand full consumption, and check well-formedness.

                            Equations
                            Instances For
                              theorem Turing.parseRawCode_encodeRawCode {i : } (c : RawCode i) (hwf : c.WellFormed) (rest : List Bool) :

                              Prefix property at the raw level (for well-formed codes, whose entries have the arities the parser expects).

                              theorem Turing.parseRawCode_sound {i : } {s : List Bool} {c : RawCode i} {rest : List Bool} (h : parseRawCode i s = some (c, rest)) :
                              s = encodeRawCode c ++ rest

                              Soundness at the raw level: every accepted prefix is the canonical encoding.

                              @[simp]

                              Round trip: exact decoding inverts encoding.

                              theorem Turing.decodeCodeExact_sound {i : } {s : List Bool} {c : Code i} (h : decodeCodeExact i s = some c) :

                              Canonicality: every accepted description is exactly the canonical encoding of the code it parses to.

                              Canonical descriptions are unique.