Documentation

Cslib.Computability.Machines.SingleTapeTuring.Basic

Single-Tape Turing Machines #

Defines a single-tape Turing machine for computing functions on List Symbol for finite alphabet Symbol.

Design #

Here are some design choices made in this file:

These machines have access to a single bidirectionally-infinite tape (BiTape) which uses symbols from Option Symbol.

The transition function of the machine takes a state and a tape alphabet character under the read-head (i.e. an Option Symbol) and returns a Stmt describing the tape action to take, as well as an optional new state to transition to (where none means halt).

We do not make the "halting state" a member of the state type for a few reasons:

We also include the possibility for non-movement actions, for convenience in composition of machines.

Important Declarations #

We define a number of structures related to Turing machine computation:

We also provide ways of constructing polynomial-runtime TMs

TODOs #

structure Turing.SingleTapeTM.Stmt (Symbol : Type) :

A Turing machine "statement" is just a Optional command to move left or right, and write a symbol (i.e. an Option Symbol, where none is the blank symbol) on the BiTape

  • symbol : Option Symbol

    The symbol to write at the current head position

  • movement : Option Dir

    The direction to move the tape head

Instances For
    Equations
    Instances For
      structure Turing.SingleTapeTM (Symbol : Type) [Inhabited Symbol] [Fintype Symbol] :

      A single-tape Turing machine over the alphabet of Option Symbol (where none is the blank BiTape symbol).

      • State : Type

        type of state labels

      • stateFintype : Fintype self.State

        finiteness of the state type

      • qโ‚€ : self.State

        Initial state

      • tr : self.State โ†’ Option Symbol โ†’ Stmt Symbol ร— Option self.State

        Transition function, mapping a state and a head symbol to a Stmt to invoke, and optionally the new state to transition to afterwards (none for halt)

      Instances For

        Configurations of a Turing Machine #

        This section defines the configurations of a Turing machine, the step function that lets the machine transition from one configuration to the next, and the intended initial and final configurations.

        @[implicit_reducible]
        instance Turing.SingleTapeTM.instInhabitedState {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) :
        Inhabited tm.State
        Equations
        @[implicit_reducible]
        instance Turing.SingleTapeTM.instFintypeState {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) :
        Fintype tm.State
        Equations
        @[implicit_reducible]
        instance Turing.SingleTapeTM.inhabitedStmt {Symbol : Type} :
        Inhabited (Stmt Symbol)
        Equations
        structure Turing.SingleTapeTM.Cfg {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) :

        The configurations of a Turing machine consist of: an Optional state (or none for the halting state), and a BiTape representing the tape contents.

        • state : Option tm.State

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

        • BiTape : Turing.BiTape Symbol

          the BiTape contents

        Instances For
          def Turing.SingleTapeTM.instInhabitedCfg.default {aโœ : Type} {aโœยน : Inhabited aโœ} {aโœยฒ : Fintype aโœ} {aโœยณ : SingleTapeTM aโœ} :
          aโœยณ.Cfg
          Equations
          Instances For
            @[implicit_reducible]
            instance Turing.SingleTapeTM.instInhabitedCfg {aโœ : Type} {aโœยน : Inhabited aโœ} {aโœยฒ : Fintype aโœ} {aโœยณ : SingleTapeTM aโœ} :
            Inhabited aโœยณ.Cfg
            Equations
            def Turing.SingleTapeTM.step {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) :
            tm.Cfg โ†’ Option tm.Cfg

            The step function corresponding to a SingleTapeTM.

            Equations
            • tm.step { state := none, BiTape := BiTape } = none
            • tm.step { state := some q', BiTape := t } = match tm.tr q' t.head with | ({ symbol := wr, movement := dir }, q'') => some { state := q'', BiTape := (t.write wr).optionMove dir }
            Instances For
              def Turing.SingleTapeTM.initCfg {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (s : List Symbol) :
              tm.Cfg

              The initial configuration corresponding to a list in the input alphabet. Note that the entries of the tape constructed by BiTape.mkโ‚ are all some values. This is to ensure that distinct lists map to distinct initial configurations.

              Equations
              Instances For
                def Turing.SingleTapeTM.haltCfg {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (s : List Symbol) :
                tm.Cfg

                The final configuration corresponding to a list in the output alphabet. (We demand that the head halts at the leftmost position of the output.)

                Equations
                Instances For
                  def Turing.SingleTapeTM.Cfg.space_used {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (cfg : tm.Cfg) :
                  โ„•

                  The space used by a configuration is the space used by its tape.

                  Equations
                  Instances For
                    theorem Turing.SingleTapeTM.Cfg.space_used_initCfg {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (s : List Symbol) :
                    space_used tm (tm.initCfg s) = max 1 s.length
                    theorem Turing.SingleTapeTM.Cfg.space_used_haltCfg {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (s : List Symbol) :
                    space_used tm (tm.haltCfg s) = max 1 s.length
                    theorem Turing.SingleTapeTM.Cfg.space_used_step {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] {tm : SingleTapeTM Symbol} (cfg cfg' : tm.Cfg) (hstep : tm.step cfg = some cfg') :
                    space_used tm cfg' โ‰ค space_used tm cfg + 1
                    def Turing.SingleTapeTM.TransitionRelation {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (cโ‚ cโ‚‚ : tm.Cfg) :

                    The TransitionRelation corresponding to a SingleTapeTM Symbol is defined by the step function, which maps a configuration to its next configuration, if it exists.

                    Equations
                    Instances For
                      def Turing.SingleTapeTM.Outputs {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (l l' : List Symbol) :

                      A proof of tm outputting l' on input l.

                      Equations
                      Instances For
                        def Turing.SingleTapeTM.OutputsWithinTime {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (l l' : List Symbol) (m : โ„•) :

                        A proof of tm outputting l' on input l in at most m steps.

                        Equations
                        Instances For
                          theorem Turing.SingleTapeTM.output_length_le_input_length_add_time {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm : SingleTapeTM Symbol) (l l' : List Symbol) (t : โ„•) (h : tm.OutputsWithinTime l l' t) :
                          l'.length โ‰ค max 1 l.length + t

                          This lemma bounds the size blow-up of the output of a Turing machine. It states that the increase in length of the output over the input is bounded by the runtime. This is important for guaranteeing that composition of polynomial time Turing machines remains polynomial time, as the input to the second machine is bounded by the output length of the first machine.

                          def Turing.SingleTapeTM.idComputer {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] :

                          A Turing machine computing the identity.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            def Turing.SingleTapeTM.compComputer {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm1 tm2 : SingleTapeTM Symbol) :

                            A Turing machine computing the composition of two other Turing machines.

                            If f and g are computed by Turing machines tm1 and tm2 then we can construct a Turing machine which computes g โˆ˜ f by first running tm1 and then, when tm1 halts, transitioning to the start state of tm2 and running tm2.

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

                              Composition Computer Lemmas #

                              theorem Turing.SingleTapeTM.compComputer_qโ‚€_eq {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (tm1 tm2 : SingleTapeTM Symbol) :
                              (tm1.compComputer tm2).qโ‚€ = Sum.inl tm1.qโ‚€

                              Time Computability #

                              This section defines the notion of time-bounded Turing Machines

                              structure Turing.SingleTapeTM.TimeComputable {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (f : List Symbol โ†’ List Symbol) :

                              A Turing machine + a time function + a proof it outputs f in at most time(input.length) steps.

                              • tm : SingleTapeTM Symbol

                                the underlying bundled SingleTapeTM

                              • time_bound : โ„• โ†’ โ„•

                                a bound on runtime

                              • outputsFunInTime (a : List Symbol) : self.tm.OutputsWithinTime a (f a) (self.time_bound a.length)

                                proof this machine outputs f in at most time_bound(input.length) steps

                              Instances For
                                def Turing.SingleTapeTM.TimeComputable.id {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] :
                                TimeComputable _root_.id

                                The identity map on Symbol is computable in constant time.

                                Equations
                                Instances For
                                  def Turing.SingleTapeTM.TimeComputable.comp {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] {f g : List Symbol โ†’ List Symbol} (hf : TimeComputable f) (hg : TimeComputable g) (h_mono : Monotone hg.time_bound) :
                                  TimeComputable (g โˆ˜ f)

                                  Time bounds for compComputer.

                                  The compComputer of two machines which have time bounds is bounded by

                                  • The time taken by the first machine on the input size
                                  • added to the time taken by the second machine on the output size of the first machine (which is itself bounded by the time taken by the first machine)

                                  Note that we require the time function of the second machine to be monotone; this is to ensure that if the first machine returns an output which is shorter than the maximum possible length of output for that input size, then the time bound for the second machine still holds for that shorter input to the second machine.

                                  Equations
                                  Instances For

                                    Polynomial Time Computability #

                                    This section defines polynomial time computable functions on Turing machines, and proves that:

                                    structure Turing.SingleTapeTM.PolyTimeComputable {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] (f : List Symbol โ†’ List Symbol) extends Turing.SingleTapeTM.TimeComputable f :

                                    A Turing machine + a polynomial time function + a proof it outputs f in at most time(input.length) steps.

                                    Instances For
                                      noncomputable def Turing.SingleTapeTM.PolyTimeComputable.id {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] :

                                      A proof that the identity map on Symbol is computable in polytime.

                                      Equations
                                      Instances For
                                        noncomputable def Turing.SingleTapeTM.PolyTimeComputable.comp {Symbol : Type} [Inhabited Symbol] [Fintype Symbol] {f g : List Symbol โ†’ List Symbol} (hf : PolyTimeComputable f) (hg : PolyTimeComputable g) (h_mono : Monotone hg.time_bound) :
                                        PolyTimeComputable (g โˆ˜ f)

                                        A proof that the composition of two polytime computable functions is polytime computable.

                                        Equations
                                        Instances For