Documentation

Complexitylib.Models.TuringMachine.UTM.Internal.Desc

Machine descriptions for the universal Turing machine #

A TMDesc describes a single-work-tape deterministic Turing machine as finite data: a state bit-width w (states are numbers below 2^w), start and halt states, and a transition table (List DescEntry, first match wins).

Encoding #

A description is laid out as a string over the writable alphabet Γw = {0, 1, □}, with acting as a field/entry separator:

qstart(w bits) □ qhalt(w bits) □ entry₀ □ entry₁ □ ⋯ □ entryₘ □ □

Each entry is 2w + 16 bit-symbols with no internal separators (field widths are determined by w): key q(w) si(2) sw(2) so(2), action q'(w) ww(2) wo(2) di(2) dw(2) dOut(2). The state width w is defined by the length of the leading qstart field. The table ends at the first empty segment (□□), so trailing junk is ignored — every description has infinitely many encodings (decodeDesc_encodeDesc_append), which the hierarchy-theorem diagonalization relies on.

The binary encoding encodeDesc : TMDescList Bool maps each Γw symbol to 2 bits via Γw.encode; decodeDesc : List BoolTMDesc is total (unparseable segments are skipped, missing fields default), so every binary string denotes some machine.

Main definitions #

Main results #

The action part of a transition-table entry: next state, writes for the work and output tapes, and directions for the input, work, and output heads (matching the component order of TM.δ).

  • q' :

    The next state (as a number below 2^w).

  • ww : Γw

    The symbol written to the work tape.

  • wo : Γw

    The symbol written to the output tape.

  • di : Dir3

    The input-head direction.

  • dw : Dir3

    The work-head direction.

  • dOut : Dir3

    The output-head direction.

Instances For
    def Complexity.instDecidableEqDescAct.decEq (x✝ x✝¹ : DescAct) :
    Decidable (x✝ = x✝¹)
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      One transition-table row for a single-work-tape machine: the key (state and the three symbols under the input/work/output heads) together with the action to take.

      • q :

        The state this row fires in.

      • si : Γ

        The symbol under the input head.

      • sw : Γ

        The symbol under the work head.

      • so : Γ

        The symbol under the output head.

      • act : DescAct

        The action to take when the key matches.

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

          A description of a single-work-tape deterministic TM: state bit-width w (states are numbers below 2^w), start and halt states, and a transition table with first-match-wins semantics (TMDesc.lookup).

          • w :

            The state bit-width: states are numbers below 2^w.

          • qstart :

            The start state.

          • qhalt :

            The halt state.

          • entries : List DescEntry

            The transition table, first match wins.

          Instances For
            def Complexity.instDecidableEqTMDesc.decEq (x✝ x✝¹ : TMDesc) :
            Decidable (x✝ = x✝¹)
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Identity write-back: the Γw symbol that leaves a read symbol unchanged when written. maps to , which is harmless: occurs only at cell 0, where writes are structural no-ops.

              Equations
              Instances For

                The default action taken when no table entry matches: go to the halt state, write back what was read, and keep all heads in place.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def Complexity.TMDesc.lookup (d : TMDesc) (q : ) (si sw so : Γ) :

                  First-match transition lookup; missing keys take the default action.

                  Equations
                  Instances For

                    A description is well-formed when every state field is below 2^w, so the fixed-width binary encoding is faithful.

                    Instances For

                      A bit as a desc-tape symbol.

                      Equations
                      Instances For

                        A bit string as desc-tape symbols.

                        Equations
                        Instances For

                          The desc-tape symbols of one table entry (given state width w): q(w) si(2) sw(2) so(2) q'(w) ww(2) wo(2) di(2) dw(2) dOut(2), 2w + 16 symbols with no separators.

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

                            The desc-tape symbols of a description: qstart(w) □ qhalt(w) □ entry₀ □ ⋯ □ entryₘ □ □.

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

                              The canonical binary encoding of a description: each desc-tape symbol becomes 2 bits via Γw.encode.

                              Equations
                              Instances For

                                Total 2-bit-group decoding: 00 → 0, 01 → 1, and both remaining patterns (10, 11) map to the separator . Left inverse of Γw.encode on the three encodable patterns.

                                Equations
                                Instances For

                                  Group a bit string into consecutive pairs and decode each; a trailing odd bit is dropped.

                                  Equations
                                  Instances For

                                    Decoding pairs is a left inverse of symbol-wise binary encoding.

                                    groupPairs distributes over appending at an even boundary.

                                    Every symbol-wise binary encoding has even length.

                                    Split off the first field: the symbols before the first , and the rest after it. An empty first field means the input started with a separator (or was empty).

                                    Equations
                                    Instances For
                                      theorem Complexity.takeField_cons_rest_length (s : Γw) (rest : List Γw) :
                                      (takeField (s :: rest)).2.length rest.length

                                      On a nonempty input the remainder after the first field is strictly shorter — the parse loop terminates.

                                      theorem Complexity.takeField_append {f : List Γw} (hf : sf, s Γw.blank) (r : List Γw) :

                                      takeField recovers a blank-free field followed by a separator.

                                      The number denoted by a field (its bit symbols, read big-endian).

                                      Equations
                                      Instances For
                                        @[simp]
                                        @[simp]

                                        Parse one table entry from a (blank-free) segment: reject if shorter than 2w + 16, otherwise decode the fixed-width fields sequentially from the prefix and ignore any excess.

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

                                          Parse the table: segments are separated by ; parseable segments become entries, unparseable (too short) segments are skipped, and the first empty segment (a □□ or end of input) terminates the table.

                                          Equations
                                          Instances For

                                            Decode a desc-tape symbol string into a description. The state width is the length of the leading qstart field; a qhalt field of any other length denotes the out-of-range sentinel 2^w (a machine that never halts), matching the universal machine's symbol-wise comparison.

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

                                              Total decoding of a binary string into a machine description.

                                              Equations
                                              Instances For
                                                theorem Complexity.parseEntry_syms {w : } {e : DescEntry} (hq : e.q < 2 ^ w) (hq' : e.act.q' < 2 ^ w) :

                                                Parsing one encoded entry recovers it (when its state fields fit in width w).

                                                A leading separator (empty segment) terminates the table parse.

                                                theorem Complexity.parseEntries_cons_of_ne_blank {s : Γw} (hs : s Γw.blank) (w : ) (rest : List Γw) :
                                                parseEntries w (s :: rest) = match parseEntry w (takeField (s :: rest)).1 with | some e => e :: parseEntries w (takeField (s :: rest)).2 | none => parseEntries w (takeField (s :: rest)).2

                                                One-step unfolding of the table parse on a segment-headed input.

                                                theorem Complexity.parseEntries_syms {w : } {es : List DescEntry} (hq : ees, e.q < 2 ^ w) (hq' : ees, e.act.q' < 2 ^ w) (junk : List Γw) :

                                                Parsing the encoded table recovers it, ignoring anything after the terminating empty segment.

                                                theorem Complexity.decodeDesc_encodeDesc_append {d : TMDesc} (hd : d.WF) (junk : List Bool) :

                                                Roundtrip with padding: decoding an encoded well-formed description recovers it exactly, no matter what junk follows the encoding. This gives every description infinitely many encodings — the padding fact the hierarchy-theorem diagonalization relies on.

                                                Roundtrip: decoding an encoded well-formed description recovers it.