Two-way multihead automata on ordered structures
Lax485149.HeadAutomata · concepts/Lax485149/HeadAutomata.lean · lax-485149
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
A two-way -head automaton over a vocabulary 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 in the 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 -structure , a configuration is a state and a -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 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
Lean source view on GitHub
| 1 | import Mathlib.ModelTheory.Order |
| 2 | import Mathlib.ModelTheory.Semantics |
| 3 | import Mathlib.ModelTheory.Complexity |
| 4 | import Mathlib.Logic.Relation |
| 5 | import Lax904597.Interpretations |
| 6 | |
| 7 | /-! |
| 8 | --- |
| 9 | title: Two-way multihead automata on ordered structures |
| 10 | type: definition |
| 11 | --- |
| 12 | A two-way -head automaton over a vocabulary has a finite set of |
| 13 | control states with an initial state and accepting states, a finite family |
| 14 | of tests, each a quantifier-free formula over in the |
| 15 | head positions, and a transition table: for each state and each outcome of |
| 16 | the tests, a finite list of transitions, each a new state together with one |
| 17 | move per head. A move leaves the head where it is, sends it to the least or |
| 18 | to the greatest element, to the position of another head, or to the |
| 19 | immediate successor or predecessor of the position of another head; the last |
| 20 | two are disabled at the ends of the order. There is no work tape. |
| 21 | |
| 22 | On a linearly ordered -structure , a configuration is a state and a |
| 23 | -tuple of elements; a step applies one of the transitions listed for the |
| 24 | current state and the truth values of the tests at the current positions. |
| 25 | The automaton accepts when a configuration in an accepting state is |
| 26 | reachable from an initial configuration, in the initial state with every |
| 27 | head on the least element. It is deterministic when every entry of its |
| 28 | transition table lists at most one transition. |
| 29 | -/ |
| 30 | |
| 31 | namespace Lax485149.HeadAutomata |
| 32 | |
| 33 | open FirstOrder |
| 34 | |
| 35 | open Language Structure |
| 36 | |
| 37 | /-- What a head may do in one step: stay where it is, jump to an end of the |
| 38 | order, copy another head, or step to the immediate successor or predecessor of |
| 39 | another head. All of it is definable from the order, which is what lets a |
| 40 | transition become a first-order formula. -/ |
| 41 | inductive 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 | |
| 58 | namespace HeadMove |
| 59 | |
| 60 | variable {k : ℕ} {A : Type} [LinearOrder A] |
| 61 | |
| 62 | /-- The semantics of a move: where head `j` may be after it, the current heads |
| 63 | being `x`. -/ |
| 64 | def 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 | |
| 73 | end HeadMove |
| 74 | |
| 75 | /-- **A two-way `k`-head automaton over `L`-structures**: a finite control, a |
| 76 | finite list of quantifier-free tests of the head positions, and, per state and |
| 77 | per outcome of those tests, a list of possible transitions – a new state and one |
| 78 | move per head. No work tape: all the storage is in the `k` heads. -/ |
| 79 | structure 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 | |
| 104 | attribute [instance] HeadAutomaton.stateFinite HeadAutomaton.testFinite |
| 105 | |
| 106 | namespace HeadAutomaton |
| 107 | |
| 108 | variable {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. -/ |
| 112 | abbrev Config (A : Type) : Type := M.State × (Fin k → A) |
| 113 | |
| 114 | open Classical in |
| 115 | /-- What the control reads at a configuration: the truth values of its tests. -/ |
| 116 | noncomputable 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 |
| 120 | and reading leads to the new state, each head moving as it prescribes. -/ |
| 121 | def 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 |
| 125 | from an initial configuration – the initial state with every head on the least |
| 126 | element. -/ |
| 127 | def 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 |
| 132 | reading. -/ |
| 133 | def IsDeterministic : Prop := |
| 134 | ∀ (s : M.State) (r : M.TestIx → Bool), (M.trans s r).length ≤ 1 |
| 135 | |
| 136 | end HeadAutomaton |
| 137 | |
| 138 | end Lax485149.HeadAutomata |
| 139 |
Builds on
Used by
Lax485149.DeterministicReachabilityInvarianceLax485149.FirstOrderInTransitiveClosureLax485149.ImmermanSzelepcsenyiLax485149.KromAndTransitiveClosureLax485149.LByAutomataLax485149.LClosureLax485149.LEqCoLLax485149.LSubsetNLLax485149.NLByAutomataLax485149.NLClosureLax485149.NLEqCoNLLax485149.NLIsTransitiveClosureLax485149.NLSubsetNPLax485149.ReachabilityInvarianceLax485149.ReachdLCompleteLax485149.ReachNLCompleteLax485149.TransitiveClosureClosureLax485149.TwoSatInvarianceLax485149.TwoSatNLCompleteLax485149.UnreachdLCompleteLax485149.UnreachNLComplete
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments