Two-way multihead automata on ordered structures

Lax485149.HeadAutomata · concepts/Lax485149/HeadAutomata.lean · lax-485149

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 two-way kk-head automaton over a vocabulary LL has a finite set of control states with an initial state and accepting states, a finite family of tests, each a quantifier-free formula over L∪{≤}L \cup \{\le\} in the kk head positions, and a transition table: for each state and each outcome of the tests, a finite list of transitions, each a new state together with one move per head. A move leaves the head where it is, sends it to the least or to the greatest element, to the position of another head, or to the immediate successor or predecessor of the position of another head; the last two are disabled at the ends of the order. There is no work tape.

    On a linearly ordered LL-structure AA, a configuration is a state and a kk-tuple of elements; a step applies one of the transitions listed for the current state and the truth values of the tests at the current positions. The automaton accepts AA when a configuration in an accepting state is reachable from an initial configuration, in the initial state with every head on the least element. It is deterministic when every entry of its transition table lists at most one transition.

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

    Lean source view on GitHub

    1import Mathlib.ModelTheory.Order
    2import Mathlib.ModelTheory.Semantics
    3import Mathlib.ModelTheory.Complexity
    4import Mathlib.Logic.Relation
    5import Lax904597.Interpretations
    6
    7/-!
    8---
    9title: Two-way multihead automata on ordered structures
    10type: definition
    11---
    12A two-way kk-head automaton over a vocabulary LL has a finite set of
    13control states with an initial state and accepting states, a finite family
    14of tests, each a quantifier-free formula over L∪{≤}L \cup \{\le\} in the kk
    15head positions, and a transition table: for each state and each outcome of
    16the tests, a finite list of transitions, each a new state together with one
    17move per head. A move leaves the head where it is, sends it to the least or
    18to the greatest element, to the position of another head, or to the
    19immediate successor or predecessor of the position of another head; the last
    20two are disabled at the ends of the order. There is no work tape.
    21
    22On a linearly ordered LL-structure AA, a configuration is a state and a
    23kk-tuple of elements; a step applies one of the transitions listed for the
    24current state and the truth values of the tests at the current positions.
    25The automaton accepts AA when a configuration in an accepting state is
    26reachable from an initial configuration, in the initial state with every
    27head on the least element. It is deterministic when every entry of its
    28transition table lists at most one transition.
    29-/
    30
    31namespace Lax485149.HeadAutomata
    32
    33open FirstOrder
    34
    35open Language Structure
    36
    37/-- What a head may do in one step: stay where it is, jump to an end of the
    38order, copy another head, or step to the immediate successor or predecessor of
    39another head. All of it is definable from the order, which is what lets a
    40transition become a first-order formula. -/
    41inductive HeadMove (k : ℕ) where
    42 /-- Stay on the current element. -/
    43 | stay : HeadMove k
    44 /-- Jump to the least element. -/
    45 | toMin : HeadMove k
    46 /-- Jump to the greatest element. -/
    47 | toMax : HeadMove k
    48 /-- Copy the position of head `i`. -/
    49 | copy (i : Fin k) : HeadMove k
    50 /-- Move to the immediate successor of head `i` (disabled at the greatest
    51 element, which is how a head runs off the end). -/
    52 | succ (i : Fin k) : HeadMove k
    53 /-- Move to the immediate predecessor of head `i` (disabled at the least
    54 element). -/
    55 | pred (i : Fin k) : HeadMove k
    56 deriving DecidableEq
    57
    58namespace HeadMove
    59
    60variable {k : ℕ} {A : Type} [LinearOrder A]
    61
    62/-- The semantics of a move: where head `j` may be after it, the current heads
    63being `x`. -/
    64def Holds (mv : HeadMove k) (x : Fin k → A) (j : Fin k) (y : A) : Prop :=
    65 match mv with
    66 | .stay => y = x j
    67 | .toMin => ∀ b : A, y ≤ b
    68 | .toMax => ∀ b : A, b ≤ y
    69 | .copy i => y = x i
    70 | .succ i => x i < y ∧ ∀ a : A, ¬(x i < a ∧ a < y)
    71 | .pred i => y < x i ∧ ∀ a : A, ¬(y < a ∧ a < x i)
    72
    73end HeadMove
    74
    75/-- **A two-way `k`-head automaton over `L`-structures**: a finite control, a
    76finite list of quantifier-free tests of the head positions, and, per state and
    77per outcome of those tests, a list of possible transitions – a new state and one
    78move per head. No work tape: all the storage is in the `k` heads. -/
    79structure HeadAutomaton (L : Language.{0, 0}) (k : ℕ) where
    80 /-- The control states. -/
    81 State : Type
    82 /-- The control is finite: that is what makes this a machine. -/
    83 [stateFinite : Finite State]
    84 /-- The initial state. -/
    85 start : State
    86 /-- The accepting states. -/
    87 accept : State → Bool
    88 /-- What the control reads at each step, indexed by a finite type. -/
    89 TestIx : Type
    90 /-- Finitely many tests: a control that could read unboundedly many facts
    91 would not be a finite control. -/
    92 [testFinite : Finite TestIx]
    93 /-- The tests: what the control sees of the current head positions. -/
    94 test : TestIx → (L.sum Language.order).Formula (Fin k)
    95 /-- **The tests are quantifier-free.** The control may compare its heads and
    96 look at the relations holding between them, and nothing else; a quantified
    97 test would make the model first-order logic in disguise. -/
    98 test_qf : ∀ i, (test i).IsQF
    99 /-- The transitions available in a state, at a given outcome of the tests:
    100 a new state and a move for each head. Nondeterminism is the length of this
    101 list. -/
    102 trans : State → (TestIx → Bool) → List (State × (Fin k → HeadMove k))
    103
    104attribute [instance] HeadAutomaton.stateFinite HeadAutomaton.testFinite
    105
    106namespace HeadAutomaton
    107
    108variable {L : Language.{0, 0}} {k : ℕ} (M : HeadAutomaton L k) {A : Type} [L.Structure A]
    109 [LinearOrder A]
    110
    111/-- A configuration: a control state together with the positions of the heads. -/
    112abbrev Config (A : Type) : Type := M.State × (Fin k → A)
    113
    114open Classical in
    115/-- What the control reads at a configuration: the truth values of its tests. -/
    116noncomputable def reading (x : Fin k → A) : M.TestIx → Bool :=
    117 fun i => decide ((M.test i).Realize x)
    118
    119/-- One step of the automaton: some transition available at the current state
    120and reading leads to the new state, each head moving as it prescribes. -/
    121def Step (a b : M.Config A) : Prop :=
    122 ∃ p ∈ M.trans a.1 (M.reading a.2), p.1 = b.1 ∧ ∀ j, (p.2 j).Holds a.2 j (b.2 j)
    123
    124/-- The automaton accepts the structure when an accepting state is reachable
    125from an initial configuration – the initial state with every head on the least
    126element. -/
    127def Accepts (A : Type) [L.Structure A] [LinearOrder A] : Prop :=
    128 ∃ c₀ c : M.Config A, (c₀.1 = M.start ∧ ∀ j, ∀ b : A, c₀.2 j ≤ b) ∧
    129 Relation.ReflTransGen M.Step c₀ c ∧ M.accept c.1 = true
    130
    131/-- **The automaton is deterministic**: at most one transition per state and
    132reading. -/
    133def IsDeterministic : Prop :=
    134 ∀ (s : M.State) (r : M.TestIx → Bool), (M.trans s r).length ≤ 1
    135
    136end HeadAutomaton
    137
    138end Lax485149.HeadAutomata
    139

    Discussion

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

    Loading discussion…