While this submission is a draft, it cannot be used by other submissions.

The number written by a deterministic Turing machine

Lax366625.MachineNumbers · concepts/Lax366625/MachineNumbers.lean · lax-366625

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    An instance is a machine instance of the NP core, extended by two marks: the output cells of the tape, and the symbols read as the digit 11. The output cells are ordered by the order of the tape, and the rank of an output cell is the number of output cells before it. If the instance describes a well-formed deterministic machine, the number it writes is ∑2r(p)\sum 2^{r(p)} over the output cells pp holding a symbol read as 11 in the configuration where the machine halts in an accepting state, r(p)r(p) being the rank of pp; otherwise it is 00. The machine halts in a configuration when that configuration is reached from an initial one within the bound of the instance and no step leaves it.

    Concept map
    8 concepts; 13 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.Algebra.BigOperators.Finprod
    2import Mathlib.Data.Set.Finite.Lemmas
    3import Mathlib.Data.Fintype.EquivFin
    4import Mathlib.Data.Set.Card
    5import Mathlib.SetTheory.Cardinal.Finite
    6import Mathlib.Logic.Equiv.Prod
    7import Mathlib.ModelTheory.Syntax
    8import Mathlib.ModelTheory.Semantics
    9import Mathlib.Order.PiLex
    10import Mathlib.Data.Prod.Lex
    11import Mathlib.ModelTheory.Order
    12import Mathlib.ModelTheory.Complexity
    13import Mathlib.Tactic.FinCases
    14import Mathlib.Logic.Equiv.Fin.Basic
    15import Mathlib.Data.Finite.Sigma
    16import Mathlib.Data.Fintype.Lattice
    17import Mathlib.Order.Lattice.Nat
    18import Mathlib.Data.Fintype.Pigeonhole
    19import Mathlib.Dynamics.FixedPoints.Basic
    20import Lax904597.Machines
    21import Lax535992.DeterministicMachines
    22import Lax366625.CountingProblems
    23
    24/-!
    25---
    26title: The number written by a deterministic Turing machine
    27type: definition
    28---
    29An instance is a machine instance of the NP core, extended by two marks: the
    30output cells of the tape, and the symbols read as the digit 11. The output
    31cells are ordered by the order of the tape, and the rank of an output cell
    32is the number of output cells before it. If the instance describes a
    33well-formed deterministic machine, the number it writes is
    34∑2r(p)\sum 2^{r(p)} over the output cells pp holding a symbol read as 11 in
    35the configuration where the machine halts in an accepting state, r(p)r(p)
    36being the rank of pp; otherwise it is 00. The machine halts in a
    37configuration when that configuration is reached from an initial one within
    38the bound of the instance and no step leaves it.
    39-/
    40
    41namespace Lax366625.MachineNumbers
    42
    43open Lax904597.Machines
    44
    45section Ripple
    46
    47variable {A : Type} [Finite A] {Le : A → A → Prop} {Posn : A → Prop}
    48
    49/-- `p` is a highest position. -/
    50def MaxPos (Le : A → A → Prop) (Posn : A → Prop) (p : A) : Prop :=
    51 Posn p ∧ ∀ q, Posn q → Le q p
    52
    53end Ripple
    54
    55open FirstOrder
    56
    57open FirstOrder.Language
    58
    59/-- The relation symbols of the language. -/
    60inductive tapeOutRel : ℕ → Type where
    61/-- `out p`: the cell `p` is an output cell, holding one digit. -/
    62 | out : tapeOutRel 1
    63/-- `one a`: the symbol `a` is read as the digit `1`. -/
    64 | one : tapeOutRel 1
    65 deriving DecidableEq
    66
    67/-- The symbols reading a number off the tape of a machine. -/
    68def tapeOut : FirstOrder.Language :=
    69 ⟨fun _ => Empty, tapeOutRel⟩
    70
    71instance instIsRelationalTapeOut : FirstOrder.Language.IsRelational tapeOut := fun _ =>
    72 (inferInstance : IsEmpty Empty)
    73
    74/-- `out p`: the cell `p` is an output cell, holding one digit. -/
    75abbrev tpOut : tapeOut.Relations 1 :=
    76 .out
    77
    78/-- `one a`: the symbol `a` is read as the digit `1`. -/
    79abbrev tpOne : tapeOut.Relations 1 :=
    80 .one
    81
    82/-- The relational language of machines writing a number. -/
    83abbrev turingOut : Language.{0, 0} := turing.sum tapeOut
    84
    85open FirstOrder
    86
    87open Language Structure
    88
    89namespace TMData
    90
    91variable {A : Type} (M : TMData A)
    92
    93/-- **The machine halts in the configuration `c`**: `c` is reached from an
    94initial configuration within the clock, and no step is possible from it. -/
    95def Halts (c : Config A) : Prop :=
    96 ∃ (c₀ : Config A) (n : ℕ), M.IsInit c₀ ∧ n < Nat.card {p : A // M.Posn p} ∧
    97 M.StepsIn n c₀ c ∧ ∀ e, ¬M.Step c e
    98
    99end TMData
    100
    101/-- “Is an output cell”, in the vocabulary of machines writing a number. -/
    102abbrev mnOut : turingOut.Relations 1 := Sum.inr tpOut
    103
    104/-- “Is read as the digit `1`”, in the vocabulary of machines writing a
    105number. -/
    106abbrev mnOne : turingOut.Relations 1 := Sum.inr tpOne
    107
    108/-- The order of the tape, in the vocabulary of machines writing a number. -/
    109abbrev mnLe : turingOut.Relations 2 := Sum.inl tmLe
    110
    111/-- A machine writing a number is a machine. -/
    112instance turingOutStructure (A : Type) [turingOut.Structure A] :
    113 turing.Structure A :=
    114 (LHom.sumInl : turing →ᴸ turingOut).reduct A
    115
    116section Semantics
    117
    118variable {A : Type} [turingOut.Structure A]
    119
    120/-- The output cell `p` holds the digit `1` when the machine halts, in an
    121accepting state. -/
    122def OutDigit (p : A) : Prop :=
    123 RelMap mnOut ![p] ∧ ∃ c : Config A, TMData.Halts (tmData A) c ∧ (tmData A).Acc c.state ∧
    124 RelMap mnOne ![c.tape p]
    125
    126/-- `q` is an output cell strictly before `p` on the tape. -/
    127def LowerCell (p q : A) : Prop :=
    128 RelMap mnOut ![q] ∧ q ≠ p ∧ RelMap mnLe ![q, p]
    129
    130/-- The rank of a cell among the output cells: the number of output cells
    131strictly before it on the tape. -/
    132noncomputable def cellRank (p : A) : ℕ :=
    133 Nat.card {q : A // LowerCell p q}
    134
    135variable (A) in
    136open Classical in
    137/-- **The number written by a machine**: each output cell holding the digit
    138`1` when the machine halts and accepts contributes two to the power of its
    139rank among the output cells. Instances that are not well-formed deterministic
    140machines write `0`. -/
    141noncomputable def machineNumber : ℕ :=
    142 if (tmData A).WellFormed ∧ Lax535992.DeterministicMachines.TMData.Deterministic (tmData A) then
    143 ∑ᶠ p : A, if OutDigit p then 2 ^ cellRank p else 0
    144 else 0
    145
    146end Semantics
    147
    148open Lax366625.CountingProblems
    149
    150/-- **The number written by a deterministic machine**, as a counting problem. -/
    151noncomputable def DTMNumber : CountingProblem turingOut :=
    152 CountingProblem.ofFun fun A _ => machineNumber A
    153
    154end Lax366625.MachineNumbers
    155

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…