Finite Turing machines with a read-only input tape

Lax434930.SpaceMachines · concepts/Lax434930/SpaceMachines.lean · lax-434930

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

    A machine has finitely many control states, a finite work alphabet with a blank symbol, a read-only binary input tape between distinct endmarkers, and one initially blank, semi-infinite work tape. Both heads start at position zero, which is the input's left endmarker and the work tape's leftmost cell. One transition reads the two scanned symbols, writes one work symbol, changes state, and moves each head by at most one cell. An outward move at a tape boundary leaves that head in place.

    The finite transition table gives a finite set of possible actions for each state and pair of scanned symbols. A deterministic machine has at most one action in every such set. A configuration with no successor is terminal, and its control state supplies an accept/reject bit. Acceptance means that some computation branch reaches an accepting terminal configuration. A decider has a finite bound on the lengths of all branches for each input, and accepts exactly the strings in its language. This bound need not be computable or satisfy any specified time bound.

    Only the work tape is charged as space. Bounding its head below ss at every reachable configuration bounds every visited cell to the prefix 0,…,s−10,\ldots,s-1, including blank cells and cells later erased. The input head is confined to ∣x∣+2|x|+2 positions and cannot act as an unbounded free counter. The transition table sees neither head position nor the input length; it sees only the control state and scanned symbols.

    Concept map
    2 concepts
    100%
    DefinitionThis conceptRelated conceptA → B: B builds on ADescendants are omitted for concepts with more than 10 descendants.

    In the paper

    • page 2 of this submission's paper

    Lean source view on GitHub

    1import Lax434930.PolynomialTime
    2import Mathlib.Data.Finset.Basic
    3
    4set_option backward.isDefEq.respectTransparency false
    5
    6/-!
    7---
    8title: Finite Turing machines with a read-only input tape
    9type: definition
    10---
    11A machine has finitely many control states, a finite work alphabet with a
    12blank symbol, a read-only binary input tape between distinct endmarkers,
    13and one initially blank, semi-infinite work tape. Both heads start at
    14position zero, which is the input's left endmarker and the work tape's
    15leftmost cell. One transition reads the two scanned symbols, writes one
    16work symbol, changes state, and moves each head by at most one cell.
    17An outward move at a tape boundary leaves that head in place.
    18
    19The finite transition table gives a finite set of possible actions for
    20each state and pair of scanned symbols. A deterministic machine has at
    21most one action in every such set. A configuration with no successor is
    22terminal, and its control state supplies an accept/reject bit. Acceptance
    23means that some computation branch reaches an accepting terminal
    24configuration. A decider has a finite bound on the lengths of all branches
    25for each input, and accepts exactly the strings in its language. This
    26bound need not be computable or satisfy any specified time bound.
    27
    28Only the work tape is charged as space. Bounding its head below ss at
    29every reachable configuration bounds every visited cell to the prefix
    300,…,s−10,\ldots,s-1, including blank cells and cells later erased. The input
    31head is confined to ∣x∣+2|x|+2 positions and cannot act as an unbounded free
    32counter. The transition table sees neither head position nor the input
    33length; it sees only the control state and scanned symbols.
    34-/
    35
    36namespace Lax434930.SpaceMachines
    37
    38open PolynomialTime
    39
    40/-- The input alphabet, with two distinct endmarkers. -/
    41inductive InputSymbol
    42 | leftEnd
    43 | bit (value : Bool)
    44 | rightEnd
    45 deriving DecidableEq, Fintype
    46
    47/-- An elementary head movement, including staying in place. -/
    48inductive Move
    49 | left
    50 | stay
    51 | right
    52 deriving DecidableEq, Fintype
    53
    54/-- Move a head on a semi-infinite tape, keeping it at zero on a leftward exit. -/
    55def Move.apply : Move → ℕ → ℕ
    56 | .left, i => i - 1
    57 | .stay, i => i
    58 | .right, i => i + 1
    59
    60/-- Read the immutable input at a head position, including its endmarkers. -/
    61def readInput (w : Word) : ℕ → InputSymbol
    62 | 0 => .leftEnd
    63 | i + 1 => match w[i]? with
    64 | some b => .bit b
    65 | none => .rightEnd
    66
    67/-- One local transition: change state, write a work symbol, and move the heads. -/
    68structure Action (Γ Q : Type) where
    69 state : Q
    70 write : Γ
    71 inputMove : Move
    72 workMove : Move
    73
    74/-- The complete finite description of a possibly nondeterministic machine. -/
    75structure Machine where
    76 Γ : Type
    77 Q : Type
    78 [alphabet : Fintype Γ]
    79 [control : Fintype Q]
    80 blank : Γ
    81 start : Q
    82 transition : Q → InputSymbol → Γ → Finset (Action Γ Q)
    83 accept : Q → Bool
    84
    85attribute [instance] Machine.alphabet Machine.control
    86
    87/-- The two head positions, control state, and work-tape contents. -/
    88structure Configuration (Γ Q : Type) where
    89 state : Q
    90 inputHead : ℕ
    91 workHead : ℕ
    92 tape : ℕ → Γ
    93
    94/-- Configurations for a fixed machine. Only reachable configurations are used. -/
    95abbrev Machine.Config (M : Machine) := Configuration M.Γ M.Q
    96
    97/-- The work tape is blank; the input is supplied separately to the step relation. -/
    98def Machine.initial (M : Machine) : M.Config :=
    99 ⟨M.start, 0, 0, fun _ => M.blank⟩
    100
    101/-- Execute one action. The input head is clipped to the two endmarkers. -/
    102def Machine.execute (M : Machine) (w : Word) (c : M.Config)
    103 (a : Action M.Γ M.Q) : M.Config :=
    104 ⟨a.state, min (a.inputMove.apply c.inputHead) (w.length + 1),
    105 a.workMove.apply c.workHead, Function.update c.tape c.workHead a.write⟩
    106
    107/-- One legal transition consults only the state and the two scanned symbols. -/
    108def Machine.Step (M : Machine) (w : Word) (c d : M.Config) : Prop :=
    109 ∃ a ∈ M.transition c.state (readInput w c.inputHead) (c.tape c.workHead),
    110 d = M.execute w c a
    111
    112/-- A computation prefix consisting of exactly the indicated number of transitions. -/
    113inductive Machine.Run (M : Machine) (w : Word) : ℕ → M.Config → Prop
    114 | zero : M.Run w 0 M.initial
    115 | succ {n : ℕ} {c d : M.Config} :
    116 M.Run w n c → M.Step w c d → M.Run w (n + 1) d
    117
    118/-- No choice of action is available at a terminal configuration. -/
    119def Machine.Terminal (M : Machine) (w : Word) (c : M.Config) : Prop :=
    120 ∀ d : M.Config, ¬ M.Step w c d
    121
    122/-- All computation branches on this input have bounded finite length. -/
    123def Machine.HaltsOn (M : Machine) (w : Word) : Prop :=
    124 ∃ t : ℕ, ∀ (n : ℕ) (c : M.Config), M.Run w n c → n ≤ t
    125
    126/-- Existential acceptance at a terminal configuration. -/
    127def Machine.Accepts (M : Machine) (w : Word) : Prop :=
    128 ∃ (n : ℕ) (c : M.Config), M.Run w n c ∧ M.Terminal w c ∧ M.accept c.state = true
    129
    130/-- A decider halts on every branch and accepts exactly its language. -/
    131def Machine.Decides (M : Machine) (A : Language) : Prop :=
    132 ∀ w : Word, M.HaltsOn w ∧ (M.Accepts w ↔ w ∈ A)
    133
    134/-- The transition table has at most one action for each local observation. -/
    135def Machine.Deterministic (M : Machine) : Prop :=
    136 ∀ (q : M.Q) (i : InputSymbol) (b : M.Γ),
    137 ∀ a ∈ M.transition q i b, ∀ a' ∈ M.transition q i b, a = a'
    138
    139/-- Every branch stays within the first `s` work cells, whether blank or nonblank. -/
    140def Machine.UsesSpace (M : Machine) (w : Word) (s : ℕ) : Prop :=
    141 ∀ (n : ℕ) (c : M.Config), M.Run w n c → c.workHead < s
    142
    143end Lax434930.SpaceMachines
    144

    Discussion

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

    Loading discussion…