Documentation

Cslib.Computability.Machines.Turing.MultiTape.Configuration

Configurations of Multi-Tape Turing Machines #

Configurations of a multi-tape Turing machine with a read-only input tape, k work tapes and one write-only output tape, together with what a single transition does to one and the space measure read off a list of them.

Design #

Nothing here mentions a machine. A step is described in two parts: an Action, recording which way the input head moves, what is written and where the work heads move, which symbol is emitted and which state follows; and Action.apply, which carries it out on a configuration.

The output tape is part of the configuration, so the string emitted along a run can be read off the configuration the run ends in.

Important Declarations #

structure Turing.Action (k : ) (Symbol : Type u_3) (State : Type u_4) :
Type (max u_3 u_4)

What a machine does in one step.

  • inputTape : SignType

    The movement (attempt) of the input head.

  • workTapes : Fin kOption (Option Symbol) × SignType

    Actions on the work tapes: optionally a symbol to write and the head movement.

  • output : Option Symbol

    An optional symbol to output.

  • state : Option State

    The successor state or none to halt.

Instances For
    structure Turing.Cfg (k : ) (Symbol : Type u_3) (State : Type u_4) (input : List Symbol) :
    Type (max u_3 u_4)

    The configurations of a Turing machine is relative to the input of the machine and consist of:

    • an Optional state (or none for the halting state),
    • the position of the input head (shifted by one),
    • the contents of the work tape,
    • the positions of the work tape heads,
    • the contents of the write-only output tape
    • state : Option State

      the state of the TM (or none for the halting state)

    • inputPos : Fin (input.length + 2)

      the position of the input head, shifted by one

    • workTapes : Fin kOption Symbol

      the work tapes

    • workTapePos : Fin k

      the positions of the heads on the work tapes

    • output : List Symbol

      the contents of the write-only output tape

    Instances For
      theorem Turing.Cfg.ext {k : } {Symbol : Type u_3} {State : Type u_4} {input : List Symbol} {x y : Cfg k Symbol State input} (state : x.state = y.state) (inputPos : x.inputPos = y.inputPos) (workTapes : x.workTapes = y.workTapes) (workTapePos : x.workTapePos = y.workTapePos) (output : x.output = y.output) :
      x = y
      theorem Turing.Cfg.ext_iff {k : } {Symbol : Type u_3} {State : Type u_4} {input : List Symbol} {x y : Cfg k Symbol State input} :
      @[instance_reducible]
      instance Turing.instInhabitedCfg {a✝ : } {a✝¹ : Type u_3} {a✝² : Type u_4} {a✝³ : List a✝¹} :
      Inhabited (Cfg a✝ a✝¹ a✝² a✝³)
      Equations
      theorem Turing.Cfg.ext_zero_tapes {Symbol : Type u_3} {State : Type u_4} {input : List Symbol} {cfg₁ cfg₂ : Cfg 0 Symbol State input} (state : cfg₁.state = cfg₂.state) (inputPos : cfg₁.inputPos = cfg₂.inputPos) (output : cfg₁.output = cfg₂.output) :
      cfg₁ = cfg₂

      Two configurations of a machine without work tapes are equal if their states, input head positions and outputs are equal.

      def Turing.moveInputPos {n : } (pos : Fin (n + 2)) (m : SignType) :
      Fin (n + 2)

      Attempt to move the input tape head. The machine can only read one empty cell outside of the input, any attempted movement beyond that results in no movement.

      The addition is performed in before clamping. Performing it in Fin (n + 2) would wrap an outward boundary move to the opposite end of the input.

      Equations
      Instances For
        @[simp]
        theorem Turing.moveInputPos_zero {n : } (pos : Fin (n + 2)) :
        moveInputPos pos 0 = pos
        @[simp]
        theorem Turing.moveInputPos_neg_of_ne_left {n : } (p : Fin (n + 2)) (h : p 0) :

        A left move away from the left input boundary decrements the native input position.

        theorem Turing.moveInputPos_pos_of_ne_right {n : } (p : Fin (n + 2)) (h : p n + 1) :

        A right move away from the right input boundary increments the native input position.

        def Turing.Cfg.inputSymbol {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) :
        Option Symbol

        The symbol currently under the input tape head.

        Equations
        Instances For
          @[simp]
          theorem Turing.inputSymbolInner {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} {cfg : Cfg k Symbol State input} (p : ) (h₁ : cfg.inputPos = 1 + p) (h₂ : p < input.length) :
          cfg.inputSymbol = some input[p]
          def Turing.Cfg.workTapeSymbols {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) (i : Fin k) :
          Option Symbol

          The symbol read by work tape i.

          Equations
          Instances For
            @[reducible, inline]
            abbrev Turing.Cfg.Halted {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) :

            A configuration is halted when it has no state to continue from.

            Equations
            Instances For
              def Turing.Cfg.withState {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) {State' : Type u_3} (q : Option State') :
              Cfg k Symbol State' input

              The same configuration in a different control state, possibly of a different state type.

              Equations
              Instances For
                @[simp]
                theorem Turing.Cfg.withState_output {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) {State' : Type u_3} (q : Option State') :
                (cfg.withState q).output = cfg.output
                @[simp]
                theorem Turing.Cfg.withState_state {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) {State' : Type u_3} (q : Option State') :
                (cfg.withState q).state = q
                @[simp]
                theorem Turing.Cfg.withState_workTapes {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) {State' : Type u_3} (q : Option State') (a✝ : Fin k) (a✝¹ : ) :
                (cfg.withState q).workTapes a✝ a✝¹ = cfg.workTapes a✝ a✝¹
                @[simp]
                theorem Turing.Cfg.withState_inputPos {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) {State' : Type u_3} (q : Option State') :
                @[simp]
                theorem Turing.Cfg.withState_workTapePos {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfg : Cfg k Symbol State input) {State' : Type u_3} (q : Option State') (a✝ : Fin k) :
                (cfg.withState q).workTapePos a✝ = cfg.workTapePos a✝
                def Turing.Cfg.mapState {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} {State' : Type u_3} (φ : Option StateOption State') (c : Cfg k Symbol State input) :
                Cfg k Symbol State' input

                Remap the (optional) state of a configuration through φ, leaving the input head, the work tapes, the work-tape heads and the output alone. This is the shape of embedding used to place a sub-machine's configurations into a larger machine built from it.

                Equations
                Instances For
                  @[simp]
                  theorem Turing.Cfg.mapState_workTapes {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} {State' : Type u_3} (φ : Option StateOption State') (c : Cfg k Symbol State input) (a✝ : Fin k) (a✝¹ : ) :
                  (mapState φ c).workTapes a✝ a✝¹ = c.workTapes a✝ a✝¹
                  @[simp]
                  theorem Turing.Cfg.mapState_state {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} {State' : Type u_3} (φ : Option StateOption State') (c : Cfg k Symbol State input) :
                  (mapState φ c).state = φ c.state
                  @[simp]
                  theorem Turing.Cfg.mapState_output {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} {State' : Type u_3} (φ : Option StateOption State') (c : Cfg k Symbol State input) :
                  @[simp]
                  theorem Turing.Cfg.mapState_inputPos {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} {State' : Type u_3} (φ : Option StateOption State') (c : Cfg k Symbol State input) :
                  @[simp]
                  theorem Turing.Cfg.mapState_workTapePos {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} {State' : Type u_3} (φ : Option StateOption State') (c : Cfg k Symbol State input) (a✝ : Fin k) :
                  (mapState φ c).workTapePos a✝ = c.workTapePos a✝
                  def Turing.Cfg.init {k : } {State : Type u_1} {Symbol : Type u_2} (q₀ : State) (input : List Symbol) :
                  Cfg k Symbol State input

                  The initial configuration for a starting state and an input string.

                  Equations
                  Instances For
                    def Turing.Action.apply {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (action : Action k Symbol State) (cfg : Cfg k Symbol State input) :
                    Cfg k Symbol State input

                    The effect of an action on a configuration: move the input head, write and move on the work tapes, append the emitted symbol to the output tape, and go to the successor state. This is the part of a step that does not depend on how the action was chosen.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem Turing.workTapePos_apply_le {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (action : Action k Symbol State) (cfg : Cfg k Symbol State input) (i : Fin k) :
                      |(action.apply cfg).workTapePos i - cfg.workTapePos i| 1

                      A work tape head moves by at most one cell when an action is applied.

                      def Turing.visitedOfCfgs {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfgs : List (Cfg k Symbol State input)) (i : Fin k) :

                      The work tape cells visited by the head of tape i along a list of configurations.

                      Equations
                      Instances For
                        def Turing.spaceUsedOfCfgs {k : } {State : Type u_1} {Symbol : Type u_2} {input : List Symbol} (cfgs : List (Cfg k Symbol State input)) :

                        The number of work tape cells touched by the heads along a list of configurations.

                        Equations
                        Instances For