Linear bounded automata
InductiveBoundary tag of a linear bounded automaton head#✓fully proved
Where the head sits relative to the tape boundaries: strictly inside the tape, on the first cell, on the last cell, or on the only cell of a one-cell tape. The transition function observes this tag, so the machine can tell the two ends of its tape apart from interior cells.
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
Used by 53
DefinitionBoundary tag of a head position#✓fully proved
The boundary tag of head position h on a tape of length n.
def LBABoundary.ofHead (h n : ℕ) : LBABoundary :=
if h = 0 then (if n = 1 then .both else .left)
else if h + 1 = n then .right else .middle
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
Uses 1 · Used by 16
TheoremBoundary tag on a one-cell tape#✓fully proved
The boundary tag at the head of a one-cell tape.
theorem LBABoundary.ofHead_eq_both {h n : ℕ} (h0 : h = 0) (hn : n = 1) :
LBABoundary.ofHead h n = .both
def LBABoundary.ofHead (h n : ℕ) : LBABoundary :=
if h = 0 then (if n = 1 then .both else .left)
else if h + 1 = n then .right else .middle
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:139
Uses 2 · Used by 1
TheoremBoundary tag on the first cell of a longer tape#✓fully proved
The boundary tag at the head of the first cell of a longer tape.
theorem LBABoundary.ofHead_eq_left {h n : ℕ} (h0 : h = 0) (hn : n ≠ 1) :
LBABoundary.ofHead h n = .left
def LBABoundary.ofHead (h n : ℕ) : LBABoundary :=
if h = 0 then (if n = 1 then .both else .left)
else if h + 1 = n then .right else .middle
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:139
Uses 2
TheoremBoundary tag on the last cell of a longer tape#✓fully proved
The boundary tag at the head of the last cell of a longer tape.
theorem LBABoundary.ofHead_eq_right {h n : ℕ} (h0 : h ≠ 0) (hn : h + 1 = n) :
LBABoundary.ofHead h n = .right
def LBABoundary.ofHead (h n : ℕ) : LBABoundary :=
if h = 0 then (if n = 1 then .both else .left)
else if h + 1 = n then .right else .middle
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:139
Uses 2 · Used by 1
TheoremBoundary tag at an interior head position#✓fully proved
The boundary tag at an interior head position.
theorem LBABoundary.ofHead_eq_middle {h n : ℕ} (h0 : h ≠ 0) (hn : h + 1 ≠ n) :
LBABoundary.ofHead h n = .middle
def LBABoundary.ofHead (h n : ℕ) : LBABoundary :=
if h = 0 then (if n = 1 then .both else .left)
else if h + 1 = n then .right else .middle
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:139
Uses 2 · Used by 1
InductiveHead move of a linear bounded automaton#✓fully proved
A head move of a linear bounded automaton: left, stay, or right.
inductive LBAMove where
/-- Move the head one cell to the left. -/
| left : LBAMove
/-- Leave the head on the same cell. -/
| stay : LBAMove
/-- Move the head one cell to the right. -/
| right : LBAMove
deriving DecidableEq
Used by 14
DefinitionHead position after a move#✓fully proved
The head position after a move: left decrements, stay keeps, right increments.
def LBAMove.moveHead (mv : LBAMove) (h : ℕ) : ℕ :=
match mv with
| .left => h - 1
| .stay => h
| .right => h + 1
inductive LBAMove where
/-- Move the head one cell to the left. -/
| left : LBAMove
/-- Leave the head on the same cell. -/
| stay : LBAMove
/-- Move the head one cell to the right. -/
| right : LBAMove
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:164
Uses 1 · Used by 4
DefinitionLegal head move of a linear bounded automaton#✓fully proved
A move is legal from the head position h on a tape of length n when
the source head is on the tape and the new head position is still on the
tape. In particular a left move from an out-of-bounds head is illegal,
even though the truncated new head h - 1 would still be out of bounds:
legality requires h < n for left moves as well.
def LBAMove.legal (mv : LBAMove) (h n : ℕ) : Prop :=
match mv with
| .left => 0 < h ∧ h < n
| .stay => h < n
| .right => h + 1 < n
inductive LBAMove where
/-- Move the head one cell to the left. -/
| left : LBAMove
/-- Leave the head on the same cell. -/
| stay : LBAMove
/-- Move the head one cell to the right. -/
| right : LBAMove
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:164
Uses 1 · Used by 4
StructureLinear bounded automaton#✓fully proved
A linear bounded automaton: a nondeterministic Turing machine whose
tape is the input word. The transition function gives, for a state, the
symbol under the head (none for a blank cell), and the boundary tag of
the head position, the finite set of possible next states, symbols to
write (none for a blank), and head moves. The boundary tag is what lets
the machine detect the ends of its tape: without it the model could not
recognize general context-sensitive languages. A move that would take
the head off the tape is not a step.
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
inductive LBAMove where
/-- Move the head one cell to the left. -/
| left : LBAMove
/-- Leave the head on the same cell. -/
| stay : LBAMove
/-- Move the head one cell to the right. -/
| right : LBAMove
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:164
Uses 2 · Used by 53
StructureConfiguration of a linear bounded automaton#✓fully proved
A configuration of a linear bounded automaton: the state, the tape
(a list of cells, one per input cell; none is a blank), and the head
position.
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
Used by 13
DefinitionInitial configuration of a linear bounded automaton#✓fully proved
The initial configuration on the input w: the initial state, the tape
w itself (no blanks), the head on the first cell.
def initCfg (w : List Γ) : LBAConfig Q Γ :=
⟨M.q₀, w.map some, 0⟩
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
Uses 2 · Used by 5
DefinitionOne step of a linear bounded automaton#✓fully proved
One step of the machine: choose a transition for the current state, the symbol under the head, and its boundary tag, write the symbol, move the head legally. A step from a configuration whose head is off the tape is impossible: legality requires the source head to be on the tape.
def Step (c c' : LBAConfig Q Γ) : Prop :=
∃ (q' : Q) (b' : Option Γ) (mv : LBAMove),
(q', b', mv) ∈
M.delta c.state (c.tape[c.head]?).join
(LBABoundary.ofHead c.head c.tape.length) ∧
c' = ⟨q', c.tape.set c.head b', mv.moveHead c.head⟩ ∧
mv.legal c.head c.tape.length
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
inductive LBAMove where
/-- Move the head one cell to the left. -/
| left : LBAMove
/-- Leave the head on the same cell. -/
| stay : LBAMove
/-- Move the head one cell to the right. -/
| right : LBAMove
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:164
def LBABoundary.ofHead (h n : ℕ) : LBABoundary :=
if h = 0 then (if n = 1 then .both else .left)
else if h + 1 = n then .right else .middle
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:139
Uses 7 · Used by 7
DefinitionAcceptance by a linear bounded automaton#✓fully proved
M accepts w when some run from the initial configuration on w
reaches a configuration in the accepting state.
def Accepts (w : List Γ) : Prop :=
∃ c : LBAConfig Q Γ, Relation.ReflTransGen M.Step (M.initCfg w) c ∧
c.state = M.qAcc
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
Uses 4 · Used by 2
DefinitionLanguage of a linear bounded automaton#✓fully proved
The language of M: the words it accepts.
Uses 2
InductiveNonterminals of the grammar of a linear bounded automaton#✓fully proved
The nonterminals of the grammar of an LBA: a cell, a generator, and the start symbol. A cell records the original input symbol, the current tape symbol, the head state if the head is on the cell, whether the cell is active (simulation acts only on active cells), and the boundary tag of its position (so simulation can apply the boundary-aware transitions).
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
Uses 1 · Used by 52
AbbreviationCell symbol of the LBA grammar#✓fully proved
A grammar symbol for the LBA grammar: a cell as a nonterminal.
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
Uses 2 · Used by 27
AbbreviationStart symbol of the LBA grammar#✓fully proved
The start symbol as a grammar symbol.
abbrev startSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .start
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
Uses 1 · Used by 9
AbbreviationGenerator symbol of the LBA grammar#✓fully proved
The generator as a grammar symbol.
abbrev genSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .gen
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
Uses 1 · Used by 10
AbbreviationTerminal symbol of the LBA grammar#✓fully proved
A terminal symbol of the grammar.
abbrev termSym (a : Γ) : Symbol Γ (LBANT Γ Q) :=
.terminal a
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
Uses 1 · Used by 7
DefinitionGeneration rules of the LBA grammar#✓fully proved
The generation rules: the start symbol produces the first cell and the
generator (or, for a one-cell word, the first cell alone, tagged both);
the generator produces a middle non-head cell and itself, or a final
right non-head cell. The first cell of a longer word is tagged left.
noncomputable def genRules (M : LinearBoundedAutomaton Q Γ) : List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList : List Γ).flatMap fun a ↦
[([startSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) (some M.q₀) false .left, genSym]),
([startSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) (some M.q₀) false .both]),
([genSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) none false .middle, genSym]),
([genSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) none false .right])]
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
abbrev startSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .start
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:285
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
abbrev genSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .gen
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:289
Uses 6 · Used by 13
DefinitionActivation rules of the LBA grammar#✓fully proved
The activation rules: an inactive cell becomes active, keeping its original, current, head state, and boundary tag.
noncomputable def activateRules :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList : List (Γ × Option Γ × Option Q × LBABoundary)).flatMap
fun ⟨a, cur, st, bnd⟩ ↦
[([cellSym a cur st false bnd], [cellSym a cur st true bnd])]
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 3 · Used by 12
DefinitionSimulation rules for a stay move#✓fully proved
The simulation rules for a stay move: the head cell rewrites its current symbol and state, staying active, keeping its boundary tag.
noncomputable def simStayRules (M : LinearBoundedAutomaton Q Γ) :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList : List (Q × Option Γ × Γ × LBABoundary)).flatMap
fun ⟨q, read, orig, bnd⟩ ↦
((M.delta q read bnd).toList).flatMap fun ⟨q', write, mv⟩ ↦
match mv with
| .stay => [([cellSym orig read (some q) true bnd],
[cellSym orig write (some q') true bnd])]
| _ => []
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 5 · Used by 12
DefinitionSimulation rules for a right move#✓fully proved
The simulation rules for a right move: the head cell rewrites its current symbol and loses the head; the neighbouring cell gains the head. Both cells keep their boundary tags.
noncomputable def simRightRules (M : LinearBoundedAutomaton Q Γ) :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList :
List (Q × Option Γ × Γ × Γ × Option Γ × LBABoundary × LBABoundary)).flatMap
fun ⟨q, read, orig, orig₂, cur₂, bnd, bnd₂⟩ ↦
((M.delta q read bnd).toList).flatMap fun ⟨q', write, mv⟩ ↦
match mv with
| .right => [([cellSym orig read (some q) true bnd,
cellSym orig₂ cur₂ none true bnd₂],
[cellSym orig write none true bnd,
cellSym orig₂ cur₂ (some q') true bnd₂])]
| _ => []
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 5 · Used by 12
DefinitionSimulation rules for a left move#✓fully proved
The simulation rules for a left move: the neighbouring cell gains the head; the head cell rewrites its current symbol and loses the head. Both cells keep their boundary tags.
noncomputable def simLeftRules (M : LinearBoundedAutomaton Q Γ) :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList :
List (Q × Option Γ × Γ × Γ × Option Γ × LBABoundary × LBABoundary)).flatMap
fun ⟨q, read, orig, orig₂, cur₂, bnd, bnd₂⟩ ↦
((M.delta q read bnd).toList).flatMap fun ⟨q', write, mv⟩ ↦
match mv with
| .left => [([cellSym orig₂ cur₂ none true bnd₂,
cellSym orig read (some q) true bnd],
[cellSym orig₂ cur₂ (some q') true bnd₂,
cellSym orig write none true bnd])]
| _ => []
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 5 · Used by 12
DefinitionConversion rules of the LBA grammar#✓fully proved
The conversion rules: an active cell becomes its original terminal. The head cell converts only in the accepting state, so a terminal word is produced only from an accepting configuration. The boundary tag is discarded on conversion.
noncomputable def convRules (M : LinearBoundedAutomaton Q Γ) :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList : List (Γ × Option Γ × LBABoundary)).flatMap
fun ⟨a, cur, bnd⟩ ↦
[([cellSym a cur (some M.qAcc) true bnd], [termSym a]),
([cellSym a cur none true bnd], [termSym a])]
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
abbrev termSym (a : Γ) : Symbol Γ (LBANT Γ Q) :=
.terminal a
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:293
Uses 5 · Used by 10
DefinitionAll rules of the LBA grammar#✓fully proved
All the rules of the grammar.
noncomputable def allRules (M : LinearBoundedAutomaton Q Γ) : List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
genRules M ++ activateRules ++ simStayRules M ++ simRightRules M ++
simLeftRules M ++ convRules M
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
noncomputable def genRules (M : LinearBoundedAutomaton Q Γ) : List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList : List Γ).flatMap fun a ↦
[([startSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) (some M.q₀) false .left, genSym]),
([startSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) (some M.q₀) false .both]),
([genSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) none false .middle, genSym]),
([genSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) none false .right])]
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:302
noncomputable def activateRules :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList : List (Γ × Option Γ × Option Q × LBABoundary)).flatMap
fun ⟨a, cur, st, bnd⟩ ↦
[([cellSym a cur st false bnd], [cellSym a cur st true bnd])]
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:315
noncomputable def simStayRules (M : LinearBoundedAutomaton Q Γ) :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList : List (Q × Option Γ × Γ × LBABoundary)).flatMap
fun ⟨q, read, orig, bnd⟩ ↦
((M.delta q read bnd).toList).flatMap fun ⟨q', write, mv⟩ ↦
match mv with
| .stay => [([cellSym orig read (some q) true bnd],
[cellSym orig write (some q') true bnd])]
| _ => []
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:323
noncomputable def simRightRules (M : LinearBoundedAutomaton Q Γ) :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList :
List (Q × Option Γ × Γ × Γ × Option Γ × LBABoundary × LBABoundary)).flatMap
fun ⟨q, read, orig, orig₂, cur₂, bnd, bnd₂⟩ ↦
((M.delta q read bnd).toList).flatMap fun ⟨q', write, mv⟩ ↦
match mv with
| .right => [([cellSym orig read (some q) true bnd,
cellSym orig₂ cur₂ none true bnd₂],
[cellSym orig write none true bnd,
cellSym orig₂ cur₂ (some q') true bnd₂])]
| _ => []
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:336
noncomputable def simLeftRules (M : LinearBoundedAutomaton Q Γ) :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList :
List (Q × Option Γ × Γ × Γ × Option Γ × LBABoundary × LBABoundary)).flatMap
fun ⟨q, read, orig, orig₂, cur₂, bnd, bnd₂⟩ ↦
((M.delta q read bnd).toList).flatMap fun ⟨q', write, mv⟩ ↦
match mv with
| .left => [([cellSym orig₂ cur₂ none true bnd₂,
cellSym orig read (some q) true bnd],
[cellSym orig₂ cur₂ (some q') true bnd₂,
cellSym orig write none true bnd])]
| _ => []
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:352
noncomputable def convRules (M : LinearBoundedAutomaton Q Γ) :
List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
(Finset.univ.toList : List (Γ × Option Γ × LBABoundary)).flatMap
fun ⟨a, cur, bnd⟩ ↦
[([cellSym a cur (some M.qAcc) true bnd], [termSym a]),
([cellSym a cur none true bnd], [termSym a])]
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:369
Uses 8 · Used by 9
DefinitionThe grammar of an LBA#✓fully proved
The grammar whose rules are the generation, activation, simulation, and conversion rules above, starting from the start symbol.
noncomputable def lbaGrammar (M : LinearBoundedAutomaton Q Γ) : CSGrammar Γ (LBANT Γ Q) where
rules := allRules M
initial := .start
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
structure CSGrammar (T N : Type*) where
/-- The finite list of productions, each a pair of symbol lists. -/
rules : List (List (Symbol T N) × List (Symbol T N))
/-- The initial nonterminal. -/
initial : N
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:54
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
noncomputable def allRules (M : LinearBoundedAutomaton Q Γ) : List (List (Symbol Γ (LBANT Γ Q)) × List (Symbol Γ (LBANT Γ Q))) :=
genRules M ++ activateRules ++ simStayRules M ++ simRightRules M ++
simLeftRules M ++ convRules M
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:377
Uses 4 · Used by 31
TheoremThe start rule is a generation rule of the LBA grammar#✓fully proved
The first generation rule is a rule of the grammar.
theorem mem_genRules_start (a : Γ) :
([startSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) (some M.q₀) false .left, genSym (Γ := Γ) (Q := Q)]) ∈
M.genRules
abbrev startSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .start
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:285
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
abbrev genSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .gen
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:289
TheoremThe grammar of an LBA is context-sensitive#✓fully proved
Every production has a nonterminal on its left side and does not shrink.
theorem lbaGrammar_contextSensitive : IsContextSensitive M.lbaGrammar
def IsContextSensitive {T N : Type*} (g : CSGrammar T N) : Prop :=
∀ r ∈ g.rules, r.1.any (·.isNonterminal) = true ∧ r.1.length ≤ r.2.length
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:80
Uses 19
DefinitionCell tuples of an LBA configuration from an offset#✓fully proved
The cells of a configuration, as a list of cell tuples: original symbol,
current symbol, head state, active, boundary tag. The head is given as
some i for the head position, or none once it has been passed. The
start index is the position of the first cell in the whole word and
total is the whole word's length, so the boundary tag of the cell at
offset j is ofHead (start + j) total.
def encodeCellsAux : List Γ → List (Option Γ) → Option ℕ → Q → ℕ → ℕ →
List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [], _, _, _, _, _ => []
| _ :: _, [], _, _, _, _ => []
| a :: w, cur :: tape, some 0, q, i, total =>
(a, cur, some q, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
| a :: w, cur :: tape, some (k + 1), q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape (some k) q (i + 1) total
| a :: w, cur :: tape, none, q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
def LBABoundary.ofHead (h n : ℕ) : LBABoundary :=
if h = 0 then (if n = 1 then .both else .left)
else if h + 1 = n then .right else .middle
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:139
Uses 2 · Used by 11
DefinitionCell tuple as a grammar symbol#✓fully proved
A cell tuple as a grammar symbol.
def cellTupleSym : Γ × Option Γ × Option Q × Bool × LBABoundary →
Symbol Γ (LBANT Γ Q)
| ⟨orig, cur, st, active, bnd⟩ => cellSym orig cur st active bnd
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 3 · Used by 13
DefinitionConfiguration encoded as a sentential form#✓fully proved
A configuration as a sentential form: the cells of its tape, with the
original symbols taken from the input word w.
def encodeCfg (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) (cfg : LBAConfig Q Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(encodeCellsAux w cfg.tape (if cfg.head < w.length then some cfg.head else none)
cfg.state 0 w.length).map cellTupleSym
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def encodeCellsAux : List Γ → List (Option Γ) → Option ℕ → Q → ℕ → ℕ →
List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [], _, _, _, _, _ => []
| _ :: _, [], _, _, _, _ => []
| a :: w, cur :: tape, some 0, q, i, total =>
(a, cur, some q, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
| a :: w, cur :: tape, some (k + 1), q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape (some k) q (i + 1) total
| a :: w, cur :: tape, none, q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
⋯
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:462
def cellTupleSym : Γ × Option Γ × Option Q × Bool × LBABoundary →
Symbol Γ (LBANT Γ Q)
| ⟨orig, cur, st, active, bnd⟩ => cellSym orig cur st active bnd
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:477
DefinitionMiddle generated cells of a word#✓fully proved
The middle non-head generated cells of a word, inactive: the cells the generator produces while the generator remains.
def tailCellsMid : List Γ → List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [] => []
| a :: w => (a, some a, none, false, .middle) :: tailCellsMid w
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
Uses 1 · Used by 2
DefinitionTail generated cells of a word#✓fully proved
The non-head generated cells of a word, inactive, as the tail of a generated word: middle cells and a final right cell.
def tailCells : List Γ → List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [] => []
| [a] => [(a, some a, none, false, .right)]
| a :: b :: w => (a, some a, none, false, .middle) :: tailCells (b :: w)
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
Uses 1 · Used by 6
DefinitionGenerated cells of a word#✓fully proved
The generated cells of a word, inactive, with the head state on the first
cell: the sentential form generation produces. The first cell is tagged
both for a one-cell word and left otherwise; the tail is tailCells.
def genCells (M : LinearBoundedAutomaton Q Γ) :
List Γ → List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [] => []
| [a] => [(a, some a, some M.q₀, false, .both)]
| a :: b :: w => (a, some a, some M.q₀, false, .left) :: tailCells (b :: w)
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
def tailCells : List Γ → List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [] => []
| [a] => [(a, some a, none, false, .right)]
| a :: b :: w => (a, some a, none, false, .middle) :: tailCells (b :: w)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:496
Uses 3 · Used by 1
DefinitionGenerated sentential form of a word#✓fully proved
The generated sentential form of a word.
def genEncode (M : LinearBoundedAutomaton Q Γ) (w : List Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(genCells (M := M) w).map cellTupleSym
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def genCells (M : LinearBoundedAutomaton Q Γ) :
List Γ → List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [] => []
| [a] => [(a, some a, some M.q₀, false, .both)]
| a :: b :: w => (a, some a, some M.q₀, false, .left) :: tailCells (b :: w)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:504
def cellTupleSym : Γ × Option Γ × Option Q × Bool × LBABoundary →
Symbol Γ (LBANT Γ Q)
| ⟨orig, cur, st, active, bnd⟩ => cellSym orig cur st active bnd
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:477
DefinitionTail generated sentential form of a word#✓fully proved
The non-head generated sentential form of a word.
def tailEncode (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(tailCells w).map cellTupleSym
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def tailCells : List Γ → List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [] => []
| [a] => [(a, some a, none, false, .right)]
| a :: b :: w => (a, some a, none, false, .middle) :: tailCells (b :: w)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:496
def cellTupleSym : Γ × Option Γ × Option Q × Bool × LBABoundary →
Symbol Γ (LBANT Γ Q)
| ⟨orig, cur, st, active, bnd⟩ => cellSym orig cur st active bnd
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:477
DefinitionMiddle generated sentential form of a word#✓fully proved
The middle non-head generated sentential form of a word: every cell
tagged middle, for the generator's intermediate stage.
def tailEncodeMid (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(tailCellsMid w).map cellTupleSym
structure LinearBoundedAutomaton (Q Γ : Type*) where
/-- The initial state. -/
q₀ : Q
/-- The accepting state. -/
qAcc : Q
/-- The transition function: from a state, the symbol under the head,
and the boundary tag of the head position, the finite set of possible
(next state, written symbol, head move) triples. -/
delta : Q → Option Γ → LBABoundary → Finset (Q × Option Γ × LBAMove)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:200
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def tailCellsMid : List Γ → List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [] => []
| a :: w => (a, some a, none, false, .middle) :: tailCellsMid w
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:490
def cellTupleSym : Γ × Option Γ × Option Q × Bool × LBABoundary →
Symbol Γ (LBANT Γ Q)
| ⟨orig, cur, st, active, bnd⟩ => cellSym orig cur st active bnd
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:477
TheoremLength of the cell-tuple encoding#✓fully proved
The encoding has as many cells as the input word, when the tape has the same length.
theorem length_encodeCellsAux {w : List Γ} {tape : List (Option Γ)} {h : Option ℕ} {q : Q}
{start total : ℕ} (hl : w.length = tape.length) :
(encodeCellsAux w tape h q start total).length = w.length
def encodeCellsAux : List Γ → List (Option Γ) → Option ℕ → Q → ℕ → ℕ →
List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [], _, _, _, _, _ => []
| _ :: _, [], _, _, _, _ => []
| a :: w, cur :: tape, some 0, q, i, total =>
(a, cur, some q, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
| a :: w, cur :: tape, some (k + 1), q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape (some k) q (i + 1) total
| a :: w, cur :: tape, none, q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
⋯
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:462
Uses 2 · Used by 3
TheoremEntries of the cell-tuple encoding#✓fully proved
The i-th cell of the encoding: original w[i], current tape[i],
head state exactly at the head position, boundary tag of position
start + i in a word of length total.
theorem getElem_encodeCellsAux {w : List Γ} {tape : List (Option Γ)} {h : Option ℕ} {q : Q}
{start total i : ℕ} (hl : w.length = tape.length) (hi : i < w.length) :
(encodeCellsAux w tape h q start total)[i]'
(by rw [length_encodeCellsAux hl]; exact hi) =
(w[i]'hi, (tape[i]?).join, if h = some i then some q else none, true,
LBABoundary.ofHead (start + i) total)
def encodeCellsAux : List Γ → List (Option Γ) → Option ℕ → Q → ℕ → ℕ →
List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [], _, _, _, _, _ => []
| _ :: _, [], _, _, _, _ => []
| a :: w, cur :: tape, some 0, q, i, total =>
(a, cur, some q, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
| a :: w, cur :: tape, some (k + 1), q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape (some k) q (i + 1) total
| a :: w, cur :: tape, none, q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
⋯
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:462
Uses 4 · Used by 1
TheoremReplacing a block by a rule is a derivation step#✓fully proved
One grammar step replacing a block: if u splits as p ++ lhs ++ q
and (lhs, rhs) is a rule, then u derives p ++ rhs ++ q.
theorem derives_replace_list {u p q lhs rhs : List (Symbol Γ (LBANT Γ Q))}
(hu : u = p ++ lhs ++ q) (hrule : (lhs, rhs) ∈ M.lbaGrammar.rules) :
Derives M.lbaGrammar u (p ++ rhs ++ q)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
Uses 8 · Used by 8
TheoremReplacing a single cell is a derivation step#✓fully proved
One grammar step replacing a single cell by a single cell.
theorem derives_single_cell {u p q : List (Symbol Γ (LBANT Γ Q))}
{x y : Symbol Γ (LBANT Γ Q)} (hu : u = p ++ [x] ++ q)
(hrule : ([x], [y]) ∈ M.lbaGrammar.rules) :
Derives M.lbaGrammar u (p ++ [y] ++ q)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
TheoremReplacing two consecutive cells is a derivation step#✓fully proved
One grammar step replacing two consecutive cells.
theorem derives_two_cells {u p q : List (Symbol Γ (LBANT Γ Q))}
{x₁ x₂ y₁ y₂ : Symbol Γ (LBANT Γ Q)} (hu : u = p ++ [x₁, x₂] ++ q)
(hrule : ([x₁, x₂], [y₁, y₂]) ∈ M.lbaGrammar.rules) :
Derives M.lbaGrammar u (p ++ [y₁, y₂] ++ q)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
TheoremSingleton-to-singleton productions are derivation steps#✓fully proved
A singleton-to-singleton production is a derivation step.
theorem derives_singleton_cell {x y : Symbol Γ (LBANT Γ Q)}
(hrule : ([x], [y]) ∈ M.lbaGrammar.rules) :
Derives M.lbaGrammar [x] [y]
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
Uses 6 · Used by 5
TheoremDerivations extend by a left context#✓fully proved
A derivation may be appended on the left.
theorem derives_append_left {u v : List (Symbol Γ (LBANT Γ Q))}
(p : List (Symbol Γ (LBANT Γ Q))) (h : Derives M.lbaGrammar u v) :
Derives M.lbaGrammar (p ++ u) (p ++ v)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
Uses 8 · Used by 3
TheoremDerivations extend by a right context#✓fully proved
A derivation may be appended on the right.
theorem derives_append_right {u v : List (Symbol Γ (LBANT Γ Q))}
(p : List (Symbol Γ (LBANT Γ Q))) (h : Derives M.lbaGrammar u v) :
Derives M.lbaGrammar (u ++ p) (v ++ p)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
TheoremDerivations compose under concatenation#✓fully proved
Derivations compose under append.
theorem derives_append {a b c d : List (Symbol Γ (LBANT Γ Q))}
(h₁ : Derives M.lbaGrammar a b) (h₂ : Derives M.lbaGrammar c d) :
Derives M.lbaGrammar (a ++ c) (b ++ d)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
Uses 8 · Used by 3
TheoremTransitivity of grammar derivations#✓fully proved
Derivations are transitive.
theorem derives_trans {a b c : List (Symbol Γ (LBANT Γ Q))}
(h₁ : Derives M.lbaGrammar a b) (h₂ : Derives M.lbaGrammar b c) :
Derives M.lbaGrammar a c
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
Uses 8 · Used by 5
TheoremThe first generation rule belongs to the LBA grammar#✓fully proved
The first generation rule is a rule of the grammar.
theorem mem_rule_gen_start (a : Γ) :
([startSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) (some M.q₀) false .left, genSym (Γ := Γ) (Q := Q)]) ∈
M.lbaGrammar.rules
abbrev startSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .start
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:285
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
abbrev genSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .gen
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:289
Uses 15 · Used by 1
TheoremThe one-cell generation rule belongs to the LBA grammar#✓fully proved
The one-cell generation rule is a rule of the grammar.
theorem mem_rule_gen_single (a : Γ) :
([startSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) (some M.q₀) false .both]) ∈
M.lbaGrammar.rules
abbrev startSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .start
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:285
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 15 · Used by 1
TheoremThe generator step rule belongs to the LBA grammar#✓fully proved
The generator step rule is a rule of the grammar.
theorem mem_rule_gen_step (a : Γ) :
([genSym (Γ := Γ) (Q := Q)],
[cellSym a (some a) none false .middle, genSym (Γ := Γ) (Q := Q)]) ∈
M.lbaGrammar.rules
abbrev genSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .gen
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:289
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 15 · Used by 2
TheoremThe final generation rule belongs to the LBA grammar#✓fully proved
The final generation rule is a rule of the grammar.
theorem mem_rule_gen_last (a : Γ) :
([genSym (Γ := Γ) (Q := Q)], [cellSym a (some a) none false .right]) ∈
M.lbaGrammar.rules
abbrev genSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .gen
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:289
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 15 · Used by 1
TheoremThe activation rule belongs to the LBA grammar#✓fully proved
The activation rule is a rule of the grammar.
theorem mem_rule_activate (a : Γ) (cur : Option Γ) (st : Option Q)
(bnd : LBABoundary) :
([cellSym a cur st false bnd], [cellSym a cur st true bnd]) ∈
M.lbaGrammar.rules
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 13 · Used by 2
TheoremStay transitions give simulation rules#✓fully proved
A stay transition gives a simulation rule.
theorem mem_rule_sim_stay {q q' : Q} {read write : Option Γ} {orig : Γ}
{bnd : LBABoundary}
(h : (q', write, LBAMove.stay) ∈ M.delta q read bnd) :
([cellSym orig read (some q) true bnd],
[cellSym orig write (some q') true bnd]) ∈
M.lbaGrammar.rules
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
inductive LBAMove where
/-- Move the head one cell to the left. -/
| left : LBAMove
/-- Leave the head on the same cell. -/
| stay : LBAMove
/-- Move the head one cell to the right. -/
| right : LBAMove
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:164
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 13 · Used by 1
TheoremRight transitions give simulation rules#✓fully proved
A right transition gives a simulation rule.
theorem mem_rule_sim_right {q q' : Q} {read write : Option Γ} {orig orig₂ : Γ}
{cur₂ : Option Γ} {bnd bnd₂ : LBABoundary}
(h : (q', write, LBAMove.right) ∈ M.delta q read bnd) :
([cellSym orig read (some q) true bnd, cellSym orig₂ cur₂ none true bnd₂],
[cellSym orig write none true bnd, cellSym orig₂ cur₂ (some q') true bnd₂]) ∈
M.lbaGrammar.rules
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
inductive LBAMove where
/-- Move the head one cell to the left. -/
| left : LBAMove
/-- Leave the head on the same cell. -/
| stay : LBAMove
/-- Move the head one cell to the right. -/
| right : LBAMove
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:164
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 13 · Used by 1
TheoremLeft transitions give simulation rules#✓fully proved
A left transition gives a simulation rule.
theorem mem_rule_sim_left {q q' : Q} {read write : Option Γ} {orig orig₂ : Γ}
{cur₂ : Option Γ} {bnd bnd₂ : LBABoundary}
(h : (q', write, LBAMove.left) ∈ M.delta q read bnd) :
([cellSym orig₂ cur₂ none true bnd₂, cellSym orig read (some q) true bnd],
[cellSym orig₂ cur₂ (some q') true bnd₂, cellSym orig write none true bnd]) ∈
M.lbaGrammar.rules
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
inductive LBAMove where
/-- Move the head one cell to the left. -/
| left : LBAMove
/-- Leave the head on the same cell. -/
| stay : LBAMove
/-- Move the head one cell to the right. -/
| right : LBAMove
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:164
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
Uses 13 · Used by 1
TheoremThe accepting conversion rule belongs to the LBA grammar#✓fully proved
The accepting conversion rule is a rule of the grammar.
theorem mem_rule_conv_acc (a : Γ) (cur : Option Γ) (bnd : LBABoundary) :
([cellSym a cur (some M.qAcc) true bnd], [termSym a]) ∈ M.lbaGrammar.rules
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
abbrev termSym (a : Γ) : Symbol Γ (LBANT Γ Q) :=
.terminal a
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:293
Uses 13 · Used by 1
TheoremThe non-head conversion rule belongs to the LBA grammar#✓fully proved
The non-head conversion rule is a rule of the grammar.
theorem mem_rule_conv_none (a : Γ) (cur : Option Γ) (bnd : LBABoundary) :
([cellSym a cur none true bnd], [termSym a]) ∈ M.lbaGrammar.rules
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
abbrev cellSym (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : Symbol Γ (LBANT Γ Q) :=
.nonterminal (.cell orig cur st active bnd)
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:280
abbrev termSym (a : Γ) : Symbol Γ (LBANT Γ Q) :=
.terminal a
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:293
Uses 13 · Used by 1
TheoremThe generator derives the middle cells and itself#✓fully proved
The generator derives the middle tail cells followed by itself.
theorem derives_gen_tail : ∀ w : List Γ,
Derives M.lbaGrammar [genSym (Γ := Γ) (Q := Q)]
(tailEncodeMid M w ++ [genSym])
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
abbrev genSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .gen
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:289
def tailEncodeMid (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(tailCellsMid w).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:522
Uses 18
TheoremThe generator derives the full tail of cells#✓fully proved
The generator derives the tail cells, ending the generation.
theorem derives_gen_tail_last : ∀ w : List Γ, w ≠ [] →
Derives M.lbaGrammar [genSym (Γ := Γ) (Q := Q)] (tailEncode M w)
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
abbrev genSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .gen
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:289
def tailEncode (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(tailCells w).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:516
Uses 16 · Used by 1
TheoremThe start symbol derives the generated form of a word#✓fully proved
The start symbol derives the generated sentential form of a word.
theorem derives_start_genEncode : ∀ w : List Γ, w ≠ [] →
Derives M.lbaGrammar [startSym (Γ := Γ) (Q := Q)] (genEncode M w)
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
abbrev startSym : Symbol Γ (LBANT Γ Q) :=
.nonterminal .start
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:285
def genEncode (M : LinearBoundedAutomaton Q Γ) (w : List Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(genCells (M := M) w).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:511
Uses 19 · Used by 1
TheoremTail cells derive their activated encoding#✓fully proved
The tail cells, sitting at offset start ≥ 1 in a word of total length
start + w.length, derive their activated encoding. The offset stays
≥ 1 in the induction step, so the first tail cell is never tagged
left: it is right when it is the last cell and middle otherwise.
theorem derives_tail_activate : ∀ (w : List Γ) (start : ℕ), 1 ≤ start →
Derives M.lbaGrammar (tailEncode M w)
((encodeCellsAux w (w.map some) none M.q₀ start (w.length + start)).map
cellTupleSym)
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
def tailEncode (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(tailCells w).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:516
def encodeCellsAux : List Γ → List (Option Γ) → Option ℕ → Q → ℕ → ℕ →
List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [], _, _, _, _, _ => []
| _ :: _, [], _, _, _, _ => []
| a :: w, cur :: tape, some 0, q, i, total =>
(a, cur, some q, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
| a :: w, cur :: tape, some (k + 1), q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape (some k) q (i + 1) total
| a :: w, cur :: tape, none, q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
⋯
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:462
def cellTupleSym : Γ × Option Γ × Option Q × Bool × LBABoundary →
Symbol Γ (LBANT Γ Q)
| ⟨orig, cur, st, active, bnd⟩ => cellSym orig cur st active bnd
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:477
Uses 20 · Used by 1
TheoremGenerated form derives the initial configuration encoding#✓fully proved
The generated form derives the encoding of the initial configuration.
theorem derives_gen_activate : ∀ w : List Γ,
Derives M.lbaGrammar (genEncode M w) (encodeCfg M w (M.initCfg w))
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
def genEncode (M : LinearBoundedAutomaton Q Γ) (w : List Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(genCells (M := M) w).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:511
def encodeCfg (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) (cfg : LBAConfig Q Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(encodeCellsAux w cfg.tape (if cfg.head < w.length then some cfg.head else none)
cfg.state 0 w.length).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:483
Uses 24 · Used by 1
TheoremSplitting a list at two consecutive positions#✓fully proved
A list splits at two consecutive positions.
TheoremSetting one list position by a production is a derivation step#✓fully proved
A single-cell replacement that is a production is a derivation step.
theorem derives_set_single {u : List (Symbol Γ (LBANT Γ Q))} {i : ℕ}
{y : Symbol Γ (LBANT Γ Q)} (hi : i < u.length)
(hrule : ([u[i]'hi], [y]) ∈ M.lbaGrammar.rules) :
Derives M.lbaGrammar u (u.set i y)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
Uses 6 · Used by 1
TheoremDropping past an updated list position#✓fully proved
Dropping past a set position is unaffected by the set.
TheoremTaking past an updated list position#✓fully proved
Taking past a set position keeps the new value at that position.
TheoremSetting two adjacent list positions by a production is a derivation step#✓fully proved
A two-cell replacement that is a production is a derivation step.
theorem derives_set_two {u : List (Symbol Γ (LBANT Γ Q))} {i : ℕ}
{y₁ y₂ : Symbol Γ (LBANT Γ Q)} (hi : i + 1 < u.length)
(hrule : ([u[i]'(by omega), u[i + 1]'hi], [y₁, y₂]) ∈ M.lbaGrammar.rules) :
Derives M.lbaGrammar u ((u.set i y₁).set (i + 1) y₂)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
Uses 9 · Used by 2
TheoremTwo-cell replacement at indices \(i\) and \(j = i + 1\)#✓fully proved
A two-cell replacement at positions i and j = i + 1.
theorem derives_set_two' {u : List (Symbol Γ (LBANT Γ Q))} {i j : ℕ}
{y₁ y₂ : Symbol Γ (LBANT Γ Q)} (hi : i + 1 < u.length) (hj : j = i + 1)
(hrule : ([u[i]'(by omega), u[j]'(by omega)], [y₁, y₂]) ∈ M.lbaGrammar.rules) :
Derives M.lbaGrammar u ((u.set i y₁).set j y₂)
inductive LBANT (Γ Q : Type*) where
/-- A tape cell: original symbol, current symbol, head state, active,
boundary tag. -/
| cell (orig : Γ) (cur : Option Γ) (st : Option Q) (active : Bool)
(bnd : LBABoundary) : LBANT Γ Q
/-- The generator: it produces the remaining cells, then disappears. -/
| gen : LBANT Γ Q
/-- The start symbol: the initial nonterminal of the grammar. -/
| start : LBANT Γ Q
deriving DecidableEq, Fintype
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:262
Uses 6 · Used by 1
TheoremLength of a configuration encoding#✓fully proved
The encoding of a configuration has as many cells as the input word.
theorem length_encodeCfg {w : List Γ} {cfg : LBAConfig Q Γ}
(hl : cfg.tape.length = w.length) : (encodeCfg M w cfg).length = w.length
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
def encodeCfg (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) (cfg : LBAConfig Q Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(encodeCellsAux w cfg.tape (if cfg.head < w.length then some cfg.head else none)
cfg.state 0 w.length).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:483
Uses 8 · Used by 2
TheoremEntries of a configuration encoding#✓fully proved
The i-th cell of the encoding.
theorem getElem_encodeCfg {w : List Γ} {cfg : LBAConfig Q Γ} {i : ℕ}
(hl : cfg.tape.length = w.length) (hhead : cfg.head < w.length)
(hi : i < w.length) :
(encodeCfg M w cfg)[i]'(by rw [length_encodeCfg hl]; exact hi) =
cellSym (w[i]'hi) ((cfg.tape[i]?).join)
(if i = cfg.head then some cfg.state else none) true
(LBABoundary.ofHead i w.length)
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
def encodeCfg (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) (cfg : LBAConfig Q Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(encodeCellsAux w cfg.tape (if cfg.head < w.length then some cfg.head else none)
cfg.state 0 w.length).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:483
Uses 12 · Used by 1
TheoremLBA steps preserve tape length#✓fully proved
One step preserves the tape length.
theorem step_tape_length {c c' : LBAConfig Q Γ} (h : M.Step c c') :
c'.tape.length = c.tape.length
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
Uses 8 · Used by 2
TheoremLBA steps keep the head on the tape#✓fully proved
One step keeps the head on the tape, when the source head is on the tape.
theorem step_head_lt {c c' : LBAConfig Q Γ} (h : M.Step c c')
(hhead : c.head < c.tape.length) : c'.head < c'.tape.length
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
Uses 8 · Used by 2
TheoremReachable LBA configurations keep the tape length and the head on the tape#✓fully proved
Reachable configurations have the input tape length and the head on the tape, for a nonempty input word.
theorem reachable_tape_length {w : List Γ} {c : LBAConfig Q Γ} (hw : w ≠ [])
(h : Relation.ReflTransGen M.Step (M.initCfg w) c) :
c.tape.length = w.length ∧ c.head < c.tape.length
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
TheoremAn LBA step is a grammar derivation step on encodings#✓fully proved
One machine step is one grammar derivation step on encodings.
theorem derives_encodeCfg_step {w : List Γ} {c c' : LBAConfig Q Γ}
(_hw : w ≠ []) (hstep : M.Step c c')
(hl : c.tape.length = w.length) (hhead : c.head < c.tape.length) :
Derives M.lbaGrammar (encodeCfg M w c) (encodeCfg M w c')
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
def encodeCfg (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) (cfg : LBAConfig Q Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(encodeCellsAux w cfg.tape (if cfg.head < w.length then some cfg.head else none)
cfg.state 0 w.length).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:483
Uses 22 · Used by 1
TheoremHead states in a configuration encoding#✓fully proved
Every cell of an encoding has head state none or the given state.
theorem encodeCellsAux_state {w : List Γ} {tape : List (Option Γ)} {h : Option ℕ} {q : Q}
{start total : ℕ}
{cell : Γ × Option Γ × Option Q × Bool × LBABoundary}
(hmem : cell ∈ encodeCellsAux w tape h q start total) :
cell.2.2.1 = none ∨ cell.2.2.1 = some q
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
def encodeCellsAux : List Γ → List (Option Γ) → Option ℕ → Q → ℕ → ℕ →
List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [], _, _, _, _, _ => []
| _ :: _, [], _, _, _, _ => []
| a :: w, cur :: tape, some 0, q, i, total =>
(a, cur, some q, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
| a :: w, cur :: tape, some (k + 1), q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape (some k) q (i + 1) total
| a :: w, cur :: tape, none, q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
⋯
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:462
Uses 3 · Used by 1
TheoremEvery cell of a configuration encoding is active#✓fully proved
Every cell of an encoding is active.
theorem encodeCellsAux_active {w : List Γ} {tape : List (Option Γ)} {h : Option ℕ} {q : Q}
{start total : ℕ}
{cell : Γ × Option Γ × Option Q × Bool × LBABoundary}
(hmem : cell ∈ encodeCellsAux w tape h q start total) :
cell.2.2.2.1 = true
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
def encodeCellsAux : List Γ → List (Option Γ) → Option ℕ → Q → ℕ → ℕ →
List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [], _, _, _, _, _ => []
| _ :: _, [], _, _, _, _ => []
| a :: w, cur :: tape, some 0, q, i, total =>
(a, cur, some q, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
| a :: w, cur :: tape, some (k + 1), q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape (some k) q (i + 1) total
| a :: w, cur :: tape, none, q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
⋯
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:462
Uses 3 · Used by 1
TheoremOriginal symbols of an encoding are the input word#✓fully proved
The original symbols of an encoding are the input word.
theorem map_orig_encodeCellsAux {w : List Γ} {tape : List (Option Γ)} {h : Option ℕ} {q : Q}
{start total : ℕ} (hl : w.length = tape.length) :
(encodeCellsAux w tape h q start total).map (fun cell ↦ termSym (Q := Q) cell.1) =
w.map (termSym (Q := Q))
def encodeCellsAux : List Γ → List (Option Γ) → Option ℕ → Q → ℕ → ℕ →
List (Γ × Option Γ × Option Q × Bool × LBABoundary)
| [], _, _, _, _, _ => []
| _ :: _, [], _, _, _, _ => []
| a :: w, cur :: tape, some 0, q, i, total =>
(a, cur, some q, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape none q (i + 1) total
| a :: w, cur :: tape, some (k + 1), q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
encodeCellsAux w tape (some k) q (i + 1) total
| a :: w, cur :: tape, none, q, i, total =>
(a, cur, none, true, LBABoundary.ofHead i total) ::
⋯
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:462
abbrev termSym (a : Γ) : Symbol Γ (LBANT Γ Q) :=
.terminal a
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:293
TheoremNon-head or accepting cells convert to terminals#✓fully proved
A list of cells, each non-head or accepting, converts to its original terminals.
theorem derives_convert_cells :
∀ (cells : List (Γ × Option Γ × Option Q × Bool × LBABoundary)),
(∀ cell ∈ cells, (cell.2.2.1 = none ∨ cell.2.2.1 = some M.qAcc) ∧
cell.2.2.2.1 = true) →
Derives M.lbaGrammar (cells.map cellTupleSym)
(cells.map fun cell ↦ termSym (Q := Q) cell.1)
inductive LBABoundary where
/-- Strictly inside the tape: not the first and not the last cell. -/
| middle : LBABoundary
/-- On the first cell of a tape of length at least two. -/
| left : LBABoundary
/-- On the last cell of a tape of length at least two. -/
| right : LBABoundary
/-- On the only cell of a one-cell tape. -/
| both : LBABoundary
deriving DecidableEq
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:122
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
def cellTupleSym : Γ × Option Γ × Option Q × Bool × LBABoundary →
Symbol Γ (LBANT Γ Q)
| ⟨orig, cur, st, active, bnd⟩ => cellSym orig cur st active bnd
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:477
abbrev termSym (a : Γ) : Symbol Γ (LBANT Γ Q) :=
.terminal a
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:293
Uses 16 · Used by 1
TheoremRuns of an LBA give grammar derivations#✓fully proved
Derivations along a run, keeping the tape length and head on the tape.
theorem derives_encodeCfg_reflTransGen {w : List Γ} {c : LBAConfig Q Γ} (hw : w ≠ [])
(h : Relation.ReflTransGen M.Step (M.initCfg w) c) :
c.tape.length = w.length ∧ c.head < c.tape.length ∧
Derives M.lbaGrammar (encodeCfg M w (M.initCfg w)) (encodeCfg M w c)
structure LBAConfig (Q Γ : Type*) where
/-- The current state. -/
state : Q
/-- The tape: one cell per input cell. -/
tape : List (Option Γ)
/-- The head position, an index into the tape. -/
head : ℕ
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:213
def Derives {T N : Type*} (g : CSGrammar T N) (u v : List (Symbol T N)) : Prop :=
Cslib.Decidability.Rewriting.Derives g.rules u v
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:68
def encodeCfg (_M : LinearBoundedAutomaton Q Γ) (w : List Γ) (cfg : LBAConfig Q Γ) :
List (Symbol Γ (LBANT Γ Q)) :=
(encodeCellsAux w cfg.tape (if cfg.head < w.length then some cfg.head else none)
cfg.state 0 w.length).map cellTupleSym
CSLibExt/Computability/Languages/ContextSensitive/LBA.lean:483
Uses 16 · Used by 1
TheoremIf the LBA accepts a nonempty word, the grammar derives it#✓fully proved
This is one inclusion of the LBA-to-grammar direction.
theorem lba_accepts_implies_grammar_derives {w : List Γ} (hw : w ≠ [])
(h : M.Accepts w) : w ∈ Cslib.Language.language M.lbaGrammar
def language {T N : Type*} (g : CSGrammar T N) : Set (List T) :=
{w | Derives g [Symbol.nonterminal g.initial] (w.map Symbol.terminal)}
CSLibExt/Computability/Languages/ContextSensitive/Basic.lean:73
Uses 24
DefinitionSpace-bounded single-tape machines#✓fully proved
Let \(s : \mathbb{N} \to \mathbb{N}\). A single-tape Turing machine \(M\) runs in space \(s\) when, for every input word \(l\) of length \(|l|\), every configuration reachable from the initial configuration of \(M\) on \(l\) uses at most \(s(|l|)\) cells, whether or not the run halts. The cells used by a configuration are the head cell together with the cells on each side of it up to the outermost non-blank cell.
def SpaceBoundedBy (s : ℕ → ℕ) : Prop :=
∀ (l : List Symbol) (c : tm.Cfg), ReflTransGen tm.TransitionRelation (tm.initCfg l) c →
c.spaceUsed ≤ s l.length
DefinitionLinear bounded automaton#✓fully proved
A single-tape machine is a linear bounded automaton when it runs in space \(n + 1\) on inputs of length \(n\): every configuration of its run on an input of length \(n\) uses at most \(n + 1\) cells, whether or not the run halts.
The input itself uses \(\max(1, n)\) cells, and the extra cell lets the head step onto a blank cell next to the input, the analogue of Sipser's endmarkers. With the bound \(n\) instead, no machine would qualify, since the empty input already uses one cell.
def IsLBA : Prop :=
tm.SpaceBoundedBy (· + 1)
Uses 1 · Used by 6
TheoremSpace bounds can be weakened#✓fully proved
If a single-tape machine runs in space \(s : \mathbb{N} \to \mathbb{N}\) and \(s' : \mathbb{N} \to \mathbb{N}\) satisfies \(s(n) \le s'(n)\) for every \(n \in \mathbb{N}\), then it runs in space \(s'\).
theorem SpaceBoundedBy.mono {s s' : ℕ → ℕ} (h : tm.SpaceBoundedBy s) (hs : ∀ n, s n ≤ s' n) :
tm.SpaceBoundedBy s'
Uses 1
TheoremA space bound is at least the space of the input#✓fully proved
If a single-tape machine runs in space \(s : \mathbb{N} \to \mathbb{N}\), then \(\max(1, n) \le s(n)\) for the length \(n\) of every input word, since the initial configuration on an input of length \(n\) uses \(\max(1, n)\) cells.
theorem SpaceBoundedBy.max_one_le {s : ℕ → ℕ} (h : tm.SpaceBoundedBy s) (l : List Symbol) :
max 1 l.length ≤ s l.length
Uses 1
TheoremA machine that, on a blank cell, writes a blank and does not move is a linear bounded automaton#✓fully proved
A machine that, on a blank cell, writes a blank and does not move is a linear bounded automaton. Its head never leaves a blank cell, so it stays on the input or on the two blank cells next to it, and it writes non-blank symbols only on the input. The machine may change state on a blank cell, or halt there.
Uses 3 · Used by 1
DefinitionConfiguration bound#✓fully proved
For a single-tape machine with state set \(Q\) over a finite alphabet \(\Sigma\) and \(k \in \mathbb{N}\), the configuration bound at \(k\) is the number \((|Q| + 1)(|\Sigma| + 1)(|\Sigma| + 2)^{2k}\).
A configuration that uses at most \(k\) cells is determined by a state or the halting state, the symbol or blank under the head, and the first \(k\) cells to either side of the head, each a symbol, a blank, or past the last non-blank cell; so this number bounds how many such configurations there are.
def cfgBound (k : ℕ) : ℕ :=
(Fintype.card tm.State + 1) * (Fintype.card Symbol + 1) * (Fintype.card Symbol + 2) ^ (2 * k)
TheoremConfigurations of bounded space are finitely many#✓fully proved
Let \(M\) be a single-tape machine with state set \(Q\) over a finite alphabet \(\Sigma\), where a configuration uses the cell under the head and the cells on either side of it up to the last non-blank one. For every \(k \in \mathbb{N}\), at most \((|Q| + 1)(|\Sigma| + 1)(|\Sigma| + 2)^{2k}\) configurations of \(M\) use at most \(k\) cells.
theorem encard_le_cfgBound (k : ℕ) : {c : tm.Cfg | c.spaceUsed ≤ k}.encard ≤ tm.cfgBound k
Uses 1 · Used by 1
TheoremSpace-bounded machines halt within the configuration bound#✓fully proved
Let \(M\) be a single-tape machine with state set \(Q\) over a finite alphabet \(\Sigma\) that runs in space \(s : \mathbb{N} \to \mathbb{N}\). If \(M\) halts on an input word \(w\) of length \(n\), then from the initial configuration on \(w\) it reaches a configuration in the halting state in at most \((|Q| + 1)(|\Sigma| + 1)(|\Sigma| + 2)^{2 s(n)}\) steps.
Its run visits only configurations of space at most \(s(n)\), and does not repeat one before halting.
theorem SpaceBoundedBy.exists_halted_relatesWithinSteps {s : ℕ → ℕ} (h : tm.SpaceBoundedBy s)
{l : List Symbol} (hl : tm.HaltsOn l) :
∃ c : tm.Cfg, RelatesWithinSteps tm.TransitionRelation (tm.initCfg l) c
(tm.cfgBound (s l.length)) ∧ c.state = none
Uses 4 · Used by 1
TheoremHalting of a machine running in computable space is computable#✓fully proved
Let \(M\) be a single-tape machine with state set \(Q\) over a finite alphabet \(\Sigma\), fix any primitive recursive coding of \(\Sigma\), and let \(s : \mathbb{N} \to \mathbb{N}\) be computable. If \(M\) runs in space \(s\), then the set of input words over \(\Sigma\) on which \(M\) halts is computable.
The decision procedure runs \(M\) for \((|Q| + 1)(|\Sigma| + 1)(|\Sigma| + 2)^{2 s(n)}\) steps on an input of length \(n\) and checks whether it has halted.
theorem SpaceBoundedBy.computablePred_haltsOn [Primcodable Symbol] {s : ℕ → ℕ}
(hs : Computable s) (h : tm.SpaceBoundedBy s) : ComputablePred tm.HaltsOn
Uses 10 · Used by 1
TheoremHalting of a linear bounded automaton is decidable#✓fully proved
Let \(M\) be a single-tape machine over a finite alphabet \(\Sigma\), and fix any primitive recursive coding of \(\Sigma\). If \(M\) is a linear bounded automaton, then the set of input words over \(\Sigma\) on which \(M\) halts is computable.
theorem IsLBA.computablePred_haltsOn [Primcodable Symbol] (h : tm.IsLBA) :
ComputablePred tm.HaltsOn
Sources
- Sipser, Introduction to the Theory of Computation, Theorem 5.9, of which this is a fixed-machine halting analogue: Sipser decides acceptance uniformly over machine descriptions, which needs a code type for CSLib machines.
Uses 3 · Used by 1
TheoremHalting of a linear bounded automaton on binary codes is decidable#✓fully proved
Let \(M\) be a single-tape machine over a finite alphabet \(\Sigma\) that is a linear bounded automaton, let \(\alpha\) be a primitive recursively coded type, and let \(\iota : \{0, 1\} \to \Sigma\) be any map. For \(a \in \alpha\), let \(w_a\) be the word over \(\Sigma\) obtained by applying \(\iota\) to each bit of the binary expansion, least significant bit first and without leading zeros, of the natural-number code of \(a\); so \(w_a\) is empty when that code is \(0\). Then the set of \(a \in \alpha\) such that \(M\) halts on \(w_a\) is computable.
theorem IsLBA.computablePred_haltsOn_encodeNat {α : Type*} [Primcodable α] (h : tm.IsLBA)
(ι : Bool → Symbol) : ComputablePred fun a : α ↦ tm.HaltsOn ((encodeNat (encode a)).map ι)
Uses 4 · Used by 1
TheoremA single-tape machine decides the halting problem of a linear bounded automaton#✓fully proved
Let \(M\) be a linear bounded automaton over a finite tape alphabet \(\Sigma\), let \(\iota\) be any map from the Booleans to \(\Sigma\), and let \(\alpha\) be a primitively encodable type. For \(a \in \alpha\), let \(w_a\) be the word obtained by writing, letter by letter through \(\iota\), the binary expansion (least significant bit first) of the natural-number code of \(a\). Then the predicate on \(\alpha\) that holds at \(a\) exactly when \(M\) halts on the input \(w_a\) is decidable by a single-tape machine.
theorem IsLBA.singleTapeDecidable_haltsOn_encodeNat {α : Type*} [Primcodable α] (h : tm.IsLBA)
(ι : Bool → Symbol) :
Decidability.SingleTapeDecidable fun a : α ↦ tm.HaltsOn ((encodeNat (encode a)).map ι)
def SingleTapeDecidable (p : α → Prop) : Prop :=
∃ (Symbol : Type) (_ : Inhabited Symbol) (_ : Fintype Symbol) (ι : Bool → Symbol),
Function.Injective ι ∧ ∃ tm : SingleTapeTM Symbol, ∀ a, ∃ b : Bool,
tm.Outputs ((encodeNat (encode a)).map ι) [ι b] ∧ (b = true ↔ p a)
CSLibExt/Computability/Machines/Turing/SingleTape/Classes.lean:196
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.