Documentation

Complexity.Computability.Machines.Turing.MultiTape.Halting.Partrec

Partial recursiveness of MultiTapeTM and bridges to Mathlib computability #

This file proves that the universal multi-tape simulator Turing.MultiTapeTM.Universal.simulate is primitive recursive (Primrec) and bridges multi-tape Turing machine computability, decidability, and mapping reductions with Mathlib's Partrec, Computable, ComputablePred, and ManyOneReducible.

Main definitions #

Main results #

References #

Primcodable instances for Universal types #

Equivalence between ℤ and ℕ ⊕ ℕ.

Instances For

    Equivalence between Key and its tuple of fields.

    Instances For

      Equivalence between Act and its tuple of fields.

      Instances For

        Equivalence between Desc and its tuple of fields.

        Instances For

          Equivalence between Universal.Tape and its tuple of fields (with ℤ encoded as ℕ ⊕ ℕ).

          Instances For

            Equivalence between SCfg and its tuple of fields.

            Instances For

              Primrec for Universal.simulate #

              theorem Turing.MultiTapeTM.Universal.primrec_tape_mk {α : Type u_1} [Primcodable α] {h : α → ℕ ⊕ ℕ} {l r : α → List (Option ℕ)} (hh : Primrec h) (hl : Primrec l) (hr : Primrec r) :
              Primrec fun (a : α) => { head := intEquivNatSumNat.symm (h a), left := l a, right := r a }
              theorem Turing.MultiTapeTM.Universal.applyTapes_eq_map_range (ts : List Tape) (as : List (Option (Option ℕ) × SignType)) :
              applyTapes ts as = List.map (fun (i : ℕ) => match ts[i]?, as[i]? with | some t, some a => t.apply a | some t, none => t | none, x => default) (List.range ts.length)
              theorem Turing.MultiTapeTM.Universal.primrec_scfg_mk {α : Type u_1} [Primcodable α] {s : α → Option ℕ} {i : α → ℕ} {w : α → List Tape} (hs : Primrec s) (hi : Primrec i) (hw : Primrec w) :
              Primrec fun (a : α) => { state := s a, inputPos := i a, workTapes := w a }
              theorem Turing.MultiTapeTM.Universal.primrec_find_table :
              Primrec₂ fun (table : List (Key × Act)) (k : Key) => List.find? (fun (x : Key × Act) => decide (x.1 = k)) table

              The universal simulator Universal.simulate is primitive recursive.

              Partial recursive evaluation of Desc #

              theorem Turing.MultiTapeTM.Universal.stepOut_of_state_none (d : Desc) (x : List ℕ) (c : SCfg) (out : List ℕ) (h : c.state = none) :
              stepOut d x (c, out) = (c, out)
              theorem Turing.MultiTapeTM.Universal.stepOut_iterate_of_state_none (d : Desc) (x : List ℕ) (c : SCfg) (out : List ℕ) (h : c.state = none) (k : ℕ) :
              (stepOut d x)^[k] (c, out) = (c, out)
              theorem Turing.MultiTapeTM.Universal.simulate_eq_of_halted {d : Desc} {x out : List ℕ} {t₁ t₂ : ℕ} (ht : t₁ ≤ t₂) (h : simulate d x t₁ = (out, true)) :
              simulate d x t₂ = (out, true)

              Clocked evaluation of a machine description d on input x after t steps.

              Instances For
                theorem Turing.MultiTapeTM.Universal.Desc.runFor_mono (d : Desc) (x : List ℕ) {t₁ t₂ : ℕ} (ht : t₁ ≤ t₂) {out : List ℕ} (h : out ∈ d.runFor x t₁) :
                out ∈ d.runFor x t₂

                Partial evaluation of a machine description d on input x.

                Instances For

                  Evaluating a machine description (d, x) ↦ d.eval x is partial recursive.

                  Partial recursiveness of MultiTapeTM and bridges to Computable #

                  noncomputable def Turing.MultiTapeTM.runFor {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (tm : MultiTapeTM k Symbol State) (x : List Symbol) (t : ℕ) :
                  Option (List Symbol)

                  Clocked run of a MultiTapeTM: returns some output if tm has halted after t steps on x, and none otherwise.

                  Instances For
                    theorem Turing.MultiTapeTM.mem_runFor_iff {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (tm : MultiTapeTM k Symbol State) {x y : List Symbol} {t : ℕ} :
                    y ∈ tm.runFor x t ↔ (runFrom (tm.initCfg x) t).Halted ∧ (runFrom (tm.initCfg x) t).output = y
                    theorem Turing.MultiTapeTM.runFor_mono {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (tm : MultiTapeTM k Symbol State) (x : List Symbol) {t₁ t₂ : ℕ} (ht : t₁ ≤ t₂) {y : List Symbol} (h : y ∈ tm.runFor x t₁) :
                    y ∈ tm.runFor x t₂
                    noncomputable def Turing.MultiTapeTM.eval {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (tm : MultiTapeTM k Symbol State) (x : List Symbol) :
                    Part (List Symbol)

                    Partial evaluation of a MultiTapeTM: tm.eval x evaluates to y iff tm.Computes x y.

                    Instances For
                      @[simp]
                      theorem Turing.MultiTapeTM.mem_eval_iff_computes {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (tm : MultiTapeTM k Symbol State) {x y : List Symbol} :
                      y ∈ tm.eval x ↔ tm.Computes x y
                      @[simp]
                      theorem Turing.MultiTapeTM.dom_eval_iff_halts {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (tm : MultiTapeTM k Symbol State) {x : List Symbol} :
                      (tm.eval x).Dom ↔ tm.Halts x
                      theorem Turing.MultiTapeTM.runFor_eq_simulate {k : ℕ} {State : Type} (tm : MultiTapeTM k Bool State) [Fintype State] (eS : State ↪ ℕ) (x : List Bool) (t : ℕ) :
                      tm.runFor x t = have r := Universal.simulate (Universal.desc eS Universal.eBit tm) (List.map (⇑Universal.eBit) x) t; if r.2 = true then some (List.map (fun (x : ℕ) => x != 0) r.1) else none
                      theorem Turing.MultiTapeTM.primrec_runFor {k : ℕ} {State : Type} [Finite State] (tm : MultiTapeTM k Bool State) :

                      For every finite-state binary MultiTapeTM, its clocked run tm.runFor is primitive recursive.

                      theorem Turing.MultiTapeTM.partrec_eval {k : ℕ} {State : Type} [Finite State] (tm : MultiTapeTM k Bool State) :

                      For every finite-state binary MultiTapeTM, its partial evaluation tm.eval is partial recursive.

                      Bridges from IsComputable, IsDecidable, and MappingReducible to Mathlib #

                      theorem Turing.MultiTapeTM.IsComputable.computable_enc {α : Type u_1} {β : Type u_2} [Primcodable α] {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} (hf : IsComputable f encIn encOut) (hIn : Computable ⇑encIn) :
                      Computable fun (a : α) => encOut (f a)

                      If IsComputable f encIn encOut and encIn is Computable, then fun a => encOut (f a) is Computable in Mathlib's sense.

                      theorem Turing.MultiTapeTM.IsComputable.computable {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {f : α → β} {encIn : α ↪ List Bool} {encOut : β ↪ List Bool} {decOut : List Bool → β} (hf : IsComputable f encIn encOut) (hIn : Computable ⇑encIn) (hOut : Computable decOut) (hdec : ∀ (b : β), decOut (encOut b) = b) :

                      If IsComputable f encIn encOut, encIn is Computable, and decOut is a computable left inverse of encOut, then f is Computable in Mathlib's sense.

                      Any function f : List Bool → List Bool that is MultiTapeTM.IsComputable under the identity encoding encBits is Computable in Mathlib's sense.

                      theorem Turing.MultiTapeTM.IsComputable.computable_bool {α : Type u_1} [Primcodable α] {f : α → Bool} {encIn : α ↪ List Bool} (hf : IsComputable f encIn encBool) (hIn : Computable ⇑encIn) :

                      Any Boolean-valued function f : α → Bool that is MultiTapeTM.IsComputable with respect to a computable input encoding encIn and encBool is Computable in Mathlib's sense.

                      theorem Turing.MultiTapeTM.IsDecidable.computablePred {α : Type u_1} [Primcodable α] {L : Set α} {enc : α ↪ List Bool} (hL : IsDecidable L enc) (henc : Computable ⇑enc) :
                      ComputablePred fun (x : α) => x ∈ L

                      Any set L : Set α that is MultiTapeTM.IsDecidable with respect to a computable encoding enc satisfies Mathlib's ComputablePred (· ∈ L).

                      Any language L : Set (List Bool) that is MultiTapeTM.IsDecidable under encBits satisfies Mathlib's ComputablePred (· ∈ L).

                      theorem Turing.MultiTapeTM.MappingReducible.manyOneReducible {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {encA : α ↪ List Bool} {encB : β ↪ List Bool} {decB : List Bool → β} {A : Set α} {B : Set β} (h : MappingReducible encA encB A B) (hA : Computable ⇑encA) (hB : Computable decB) (hdec : ∀ (b : β), decB (encB b) = b) :
                      (fun (x : α) => x ∈ A) ≤₀ fun (x : β) => x ∈ B

                      Any MultiTapeTM.MappingReducible reduction between Primcodable types with computable encoding encA and left-invertible encB yields a Mathlib ManyOneReducible (≤₀) reduction.

                      Any MultiTapeTM.MappingReducible reduction on bit strings under encBits yields a Mathlib ManyOneReducible (≤₀) reduction.