Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.Space.Decode

Decoding finite configurations in polynomial time #

Turing.MultiTapeTM.decodeFiniteCfg reads a finite configuration from any word, inverting Turing.MultiTapeTM.encFiniteCfg, in polynomial time; a malformed word decodes to some configuration. The fields are read off the frames of the encoding by unframe and dropFrame, counts are clamped into range, and the cells of a stack tape are read by a finite transducer and folded into a canonical tape by StackTape.cons, last cell first.

Main definitions #

Main results #

Implementation notes #

Only unframe, dropFrame, list folds and finite transducers from the main development are used. The cell transducer Turing.MultiTapeTM.cellsTransducer splits a framed list of cells, a special case of splitting a word into its framed words; a general splitter with list decoders, once available, could replace it, and Turing.MultiTapeTM.decodeState is a decoder of a finite encoding from its length.

Cells #

The bits of a cell: whether it is occupied, then its symbol, false when it is blank.

Instances For

    The bits of a framed cell, from a summary of its framed word: blank while the word is empty, otherwise occupied, with the second bit of the word as its symbol.

    Instances For

      Record a bit of a framed word in its summary: only the first two bits matter.

      Instances For

        The transducer emitting the bits of every framed cell. Its state is the summary of the framed word read so far, and whether a bit of that word is expected next.

        Instances For

          The transducer emits the bits of a framed cell and continues after its frame.

          On an encoded list of cells, the transducer emits the bits of every cell.

          Stack tapes #

          Read the reversed bits of cells into a tape, last cell first: a symbol bit is held until the occupancy bit before it.

          Instances For

            Decode a stack tape from any word, inverting encStackTape encBool.

            Instances For

              The fold over the reversed bits of cells prepends the cells, last first.

              theorem Cslib.Turing.StackTape.foldr_cons_toList {Symbol : Type u_1} (tape : StackTape Symbol) :

              Prepending the stored cells of a stack tape to the empty tape rebuilds it.

              A word encoding a list of cells decodes to the tape of the cells, without the blank cells at its end.

              Decoding inverts the encoding of stack tapes.

              Two-sided tapes and configurations #

              Decode a cell encoded by encOption encBool.

              Instances For
                @[simp]

                Decoding inverts the encoding of cells.

                Decode a two-sided tape from any word, inverting encBiTape encBool.

                Instances For

                  Decoding inverts the encoding of two-sided tapes.

                  theorem Turing.MultiTapeTM.dropFrame_iterate_encList {α : Type u_1} (enc : α ↪ List Bool) (values : List α) (n : ℕ) :
                  dropFrame^[n] ((encList enc) values) = (encList enc) (List.drop n values)

                  Dropping n frames from an encoded list drops its first n elements.

                  noncomputable def Turing.MultiTapeTM.decodeTapes (k : ℕ) (word : List Bool) :

                  Decode a family of k tapes from any word, inverting encPi (encBiTape encBool).

                  Instances For

                    Decoding inverts the encoding of families of tapes.

                    noncomputable def Turing.MultiTapeTM.decodeState {State : Type} [Finite State] (n : ℕ) :
                    Option State

                    Decode a control state from the length of its encoding by encFinite, clamped into range.

                    Instances For
                      theorem Turing.MultiTapeTM.encFinite_decodeState {State : Type} [Finite State] (n : ℕ) :
                      (encFinite (Option State)) (decodeState n) = encUnary (min n (Nat.card (Option State) - 1))

                      A decoded control state is encoded by the clamped count.

                      @[simp]
                      theorem Turing.MultiTapeTM.decodeState_length_encFinite {State : Type} [Finite State] (state : Option State) :
                      decodeState ((encFinite (Option State)) state).length = state

                      Decoding inverts the encoding of control states.

                      noncomputable def Turing.MultiTapeTM.decodeFiniteCfg {k : ℕ} {State : Type} [Finite State] (word : List Bool) :
                      FiniteCfg k Bool State

                      Decode a finite configuration from any word, inverting encFiniteCfg.

                      Instances For
                        theorem Turing.MultiTapeTM.decodeFiniteCfg_encFiniteCfg {k : ℕ} {State : Type} [Finite State] (finite : FiniteCfg k Bool State) :

                        Decoding inverts the encoding of finite configurations.

                        Decoding in polynomial time #

                        Decoding a fixed finite family of tapes is polynomial-time.