Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax434930.SpaceMachines

Finite Turing machines with a read-only input tape

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.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    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,,s10,\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.

    Lean source view on GitHub

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

    Community review

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.

    0 comments

    Loading discussion…