Documentation

Mathlib.Computability.TuringMachine.Computable

Computable functions #

This file contains the definition of a Turing machine with some finiteness conditions (bundling the definition of TM2 in StackTuringMachine.lean), a definition of when a TM gives a certain output (in a certain time), and the definition of computability (in polynomial time or any time function) of a function between two types that have an encoding (as in Encoding.lean).

Main theorems #

Implementation notes #

To count the execution time of a Turing machine, we have decided to count the number of times the step function is used. Each step executes a statement (of type Stmt); this is a function, and generally contains multiple "fundamental" steps (pushing, popping, and so on). However, as functions only contain a finite number of executions and each one is executed at most once, this execution time is up to multiplication by a constant the amount of fundamental steps.

structure Turing.FinTM2 :

A bundled TM2 (an equivalent of the classical Turing machine, defined starting from the namespace Turing.TM2 in StackTuringMachine.lean), with an input and output stack, a main function, an initial state and some finiteness guarantees.

  • K : Type

    index type of stacks

  • kDecidableEq : DecidableEq self.K
  • kFin : Fintype self.K

    A TM2 machine has finitely many stacks.

  • k₀ : self.K

    input resp. output stack

  • k₁ : self.K

    input resp. output stack

  • Γ : self.KType

    type of stack elements

  • Λ : Type

    type of function labels

  • main : self.Λ

    a main function: the initial function that is executed, given by its label

  • ΛFin : Fintype self.Λ

    A TM2 machine has finitely many function labels.

  • σ : Type

    type of states of the machine

  • initialState : self.σ

    the initial state of the machine

  • σFin : Fintype self.σ

    a TM2 machine has finitely many internal states.

  • Γk₀Fin : Fintype (self.Γ self.k₀)

    Each internal stack is finite.

  • m : self.ΛTM2.Stmt self.Γ self.Λ self.σ

    the program itself, i.e. one function for every function label

Instances For
    @[implicit_reducible]
    Equations
    @[implicit_reducible]
    Equations

    The type of statements (functions) corresponding to this TM.

    Equations
    Instances For
      @[implicit_reducible]
      Equations

      The type of configurations (functions) corresponding to this TM.

      Equations
      Instances For
        @[implicit_reducible]
        Equations
        def Turing.FinTM2.step (tm : FinTM2) :
        tm.CfgOption tm.Cfg

        The step function corresponding to this TM.

        Equations
        Instances For
          def Turing.initList (tm : FinTM2) (s : List (tm.Γ tm.k₀)) :
          tm.Cfg

          The initial configuration corresponding to a list in the input alphabet.

          Equations
          Instances For
            def Turing.haltList (tm : FinTM2) (s : List (tm.Γ tm.k₁)) :
            tm.Cfg

            The final configuration corresponding to a list in the output alphabet.

            Equations
            Instances For
              @[deprecated StateTransition.EvalsTo (since := "2026-03-06")]
              def Turing.EvalsTo {σ : Type u_1} (f : σOption σ) (a : σ) (b : Option σ) :

              Alias of StateTransition.EvalsTo.

              Equations
              Instances For
                @[deprecated StateTransition.EvalsToInTime (since := "2026-03-06")]
                def Turing.EvalsToInTime {σ : Type u_1} (f : σOption σ) (a : σ) (b : Option σ) (m : ) :

                Alias of StateTransition.EvalsToInTime.

                Equations
                Instances For
                  def Turing.TM2Outputs (tm : FinTM2) (l : List (tm.Γ tm.k₀)) (l' : Option (List (tm.Γ tm.k₁))) :

                  A proof of tm outputting l' when given l.

                  Equations
                  Instances For
                    def Turing.TM2OutputsInTime (tm : FinTM2) (l : List (tm.Γ tm.k₀)) (l' : Option (List (tm.Γ tm.k₁))) (m : ) :

                    A proof of tm outputting l' when given l in at most m steps.

                    Equations
                    Instances For
                      def Turing.TM2OutputsInTime.toTM2Outputs {tm : FinTM2} {l : List (tm.Γ tm.k₀)} {l' : Option (List (tm.Γ tm.k₁))} {m : } (h : TM2OutputsInTime tm l l' m) :
                      TM2Outputs tm l l'

                      The forgetful map, forgetting the upper bound on the number of steps.

                      Equations
                      Instances For
                        structure Turing.TM2ComputableAux (Γ₀ Γ₁ : Type) :

                        A (bundled TM2) Turing machine with input alphabet equivalent to Γ₀ and output alphabet equivalent to Γ₁.

                        • tm : FinTM2

                          the underlying bundled TM2

                        • inputAlphabet : self.tm.Γ self.tm.k₀ Γ₀

                          the input alphabet is equivalent to Γ₀

                        • outputAlphabet : self.tm.Γ self.tm.k₁ Γ₁

                          the output alphabet is equivalent to Γ₁

                        Instances For
                          structure Turing.TM2Computable {α β αΓ βΓ : Type} (ea : αList αΓ) (eb : βList βΓ) (f : αβ) extends Turing.TM2ComputableAux αΓ βΓ :

                          A Turing machine + a proof it outputs f.

                          Instances For
                            structure Turing.TM2ComputableInTime {α β αΓ βΓ : Type} (ea : αList αΓ) (eb : βList βΓ) (f : αβ) extends Turing.TM2ComputableAux αΓ βΓ :

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

                            Instances For
                              structure Turing.TM2ComputableInPolyTime {α β αΓ βΓ : Type} (ea : αList αΓ) (eb : βList βΓ) (f : αβ) extends Turing.TM2ComputableAux αΓ βΓ :

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

                              Instances For
                                def Turing.TM2ComputableInTime.toTM2Computable {α β αΓ βΓ : Type} {ea : αList αΓ} {eb : βList βΓ} {f : αβ} (h : TM2ComputableInTime ea eb f) :

                                A forgetful map, forgetting the time bound on the number of steps.

                                Equations
                                Instances For
                                  def Turing.TM2ComputableInPolyTime.toTM2ComputableInTime {α β αΓ βΓ : Type} {ea : αList αΓ} {eb : βList βΓ} {f : αβ} (h : TM2ComputableInPolyTime ea eb f) :

                                  A forgetful map, forgetting that the time function is polynomial.

                                  Equations
                                  Instances For
                                    def Turing.idComputer (αΓ : Type) [Fintype αΓ] :

                                    A Turing machine computing the identity on α.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      noncomputable def Turing.idComputableInPolyTime {α αΓ : Type} [Fintype αΓ] (ea : αList αΓ) :

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

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        noncomputable def Turing.idComputableInTime {α αΓ : Type} [Fintype αΓ] (ea : αList αΓ) :

                                        A proof that the identity map on α is computable in time.

                                        Equations
                                        Instances For
                                          noncomputable def Turing.idComputable {α αΓ : Type} [Fintype αΓ] (ea : αList αΓ) :

                                          A proof that the identity map on α is computable.

                                          Equations
                                          Instances For