Documentation

CslibFrontier.Computability.Automata.MPDA.Basic

Multistack pushdown automata #

A multistack pushdown automaton (MPDA) with n stacks is a finite control equipped with n stacks over a common stack alphabet. Every transition carries an input symbol and performs at most one stack operation: it either leaves all stacks untouched (nop), pushes a symbol onto one stack, or pops a given symbol from the top of one stack.

Following the conventions of NA, an MPDA extends an LTS over its control states, whose labels pair an input symbol with a stack operation. We do not impose any finiteness assumption. The configuration semantics is itself an LTS (MPDA.configLTS), so that the generic LTS API for multistep transitions applies directly to runs of the automaton.

A word is accepted when some run starts in an initial state with all stacks empty and ends in an accepting state with all stacks empty, as in Section 2 of [AGKR20]. The paper has a single initial state; we allow a set of initial states, as NA does.

Main definitions #

Main results #

References #

inductive Cslib.Automata.MPDA.Op (n : ℕ) (Γ : Type u_1) :
Type u_1

The stack operations of a multistack pushdown automaton with n stacks over the stack alphabet Γ.

  • nop {n : ℕ} {Γ : Type u_1} : Op n Γ

    Leave all stacks unchanged.

  • push {n : ℕ} {Γ : Type u_1} (i : Fin n) (γ : Γ) : Op n Γ

    Push γ onto stack i.

  • pop {n : ℕ} {Γ : Type u_1} (i : Fin n) (γ : Γ) : Op n Γ

    Pop γ from the top of stack i.

def Cslib.Automata.MPDA.instDecidableEqOp.decEq {n✝ : ℕ} {Γ✝ : Type u_1} [DecidableEq Γ✝] (x✝ x✝¹ : Op n✝ Γ✝) :
Decidable (x✝ = x✝¹)
@[instance_reducible]
instance Cslib.Automata.MPDA.instDecidableEqOp {n✝ : ℕ} {Γ✝ : Type u_1} [DecidableEq Γ✝] :
DecidableEq (Op n✝ Γ✝)
structure Cslib.Automata.MPDA (n : ℕ) (State : Type u_1) (Symbol : Type u_2) (Γ : Type u_3) extends Cslib.LTS State (Symbol × Cslib.Automata.MPDA.Op n Γ) :
Type (max (max u_1 u_2) u_3)

A multistack pushdown automaton with n stacks, control states State, input alphabet Symbol and stack alphabet Γ. Its transition relation is an LTS over control states, whose labels pair an input symbol with a stack operation.

  • Tr : State → Symbol × Automata.MPDA.Op n Γ → State → Prop
  • start : Set State

    The set of initial states.

  • accept : Set State

    The set of accepting states.

Instances For
    @[reducible, inline]
    abbrev Cslib.Automata.MPDA.Stacks (n : ℕ) (Γ : Type u_4) :
    Type u_4

    The contents of n stacks. The head of each list is the top of the stack.

    def Cslib.Automata.MPDA.Stacks.empty {n : ℕ} {Γ : Type u_3} :
    Stacks n Γ

    All stacks are empty.

    def Cslib.Automata.MPDA.Op.Apply {n : ℕ} {Γ : Type u_3} :
    Op n Γ → Stacks n Γ → Stacks n Γ → Prop

    op.Apply σ σ' holds when performing op on the stacks σ yields σ'. A pop of γ from stack i is enabled only when γ is on top of stack i.

    @[simp]
    theorem Cslib.Automata.MPDA.Op.apply_nop {n : ℕ} {Γ : Type u_3} {σ σ' : Stacks n Γ} :
    nop.Apply σ σ' ↔ σ' = σ
    @[simp]
    theorem Cslib.Automata.MPDA.Op.apply_push {n : ℕ} {Γ : Type u_3} {i : Fin n} {γ : Γ} {σ σ' : Stacks n Γ} :
    (push i γ).Apply σ σ' ↔ σ' = Function.update σ i (γ :: σ i)
    @[simp]
    theorem Cslib.Automata.MPDA.Op.apply_pop {n : ℕ} {Γ : Type u_3} {i : Fin n} {γ : Γ} {σ σ' : Stacks n Γ} :
    (pop i γ).Apply σ σ' ↔ σ = Function.update σ' i (γ :: σ' i)

    Two stacks #

    def Cslib.Automata.MPDA.Stacks.pair {Γ : Type u_3} (s₀ s₁ : List Γ) :
    Stacks 2 Γ

    Two stacks with contents s₀ and s₁.

    theorem Cslib.Automata.MPDA.Stacks.eq_pair_iff {Γ : Type u_3} {σ : Stacks 2 Γ} {s₀ s₁ : List Γ} :
    σ = pair s₀ s₁ ↔ σ 0 = s₀ ∧ σ 1 = s₁
    theorem Cslib.Automata.MPDA.Op.apply_push_zero_pair {Γ : Type u_3} {γ : Γ} {s₀ s₁ : List Γ} {σ : Stacks 2 Γ} :
    (push 0 γ).Apply (Stacks.pair s₀ s₁) σ ↔ σ = Stacks.pair (γ :: s₀) s₁
    theorem Cslib.Automata.MPDA.Op.apply_push_one_pair {Γ : Type u_3} {γ : Γ} {s₀ s₁ : List Γ} {σ : Stacks 2 Γ} :
    (push 1 γ).Apply (Stacks.pair s₀ s₁) σ ↔ σ = Stacks.pair s₀ (γ :: s₁)
    theorem Cslib.Automata.MPDA.Op.apply_pop_zero_pair {Γ : Type u_3} {γ : Γ} {s₀ s₁ : List Γ} {σ : Stacks 2 Γ} :
    (pop 0 γ).Apply (Stacks.pair s₀ s₁) σ ↔ ∃ (t : List Γ), s₀ = γ :: t ∧ σ = Stacks.pair t s₁
    theorem Cslib.Automata.MPDA.Op.apply_pop_one_pair {Γ : Type u_3} {γ : Γ} {s₀ s₁ : List Γ} {σ : Stacks 2 Γ} :
    (pop 1 γ).Apply (Stacks.pair s₀ s₁) σ ↔ ∃ (t : List Γ), s₁ = γ :: t ∧ σ = Stacks.pair s₀ t

    The kind of a stack operation: a push on stack i, a pop from stack i, or no stack operation. A visibly pushdown alphabet assigns a kind to each letter.

    def Cslib.Automata.MPDA.instDecidableEqOpKind.decEq {n✝ : ℕ} (x✝ x✝¹ : OpKind n✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    def Cslib.Automata.MPDA.Op.kind {n : ℕ} {Γ : Type u_3} :
    Op n Γ → OpKind n

    The kind of an operation, forgetting its stack symbol.

    theorem Cslib.Automata.MPDA.Op.kind_eq_push {n : ℕ} {Γ : Type u_3} {op : Op n Γ} {i : Fin n} :
    op.kind = OpKind.push i ↔ ∃ (γ : Γ), op = push i γ
    theorem Cslib.Automata.MPDA.Op.kind_eq_pop {n : ℕ} {Γ : Type u_3} {op : Op n Γ} {i : Fin n} :
    op.kind = OpKind.pop i ↔ ∃ (γ : Γ), op = pop i γ
    structure Cslib.Automata.MPDA.Config (n : ℕ) (State : Type u_4) (Γ : Type u_5) :
    Type (max u_4 u_5)

    A configuration of an MPDA: a control state and the contents of all stacks.

    • state : State

      The control state.

    • contents : Stacks n Γ

      The contents of the stacks.

    theorem Cslib.Automata.MPDA.Config.ext {n : ℕ} {State : Type u_4} {Γ : Type u_5} {x y : Config n State Γ} (state : x.state = y.state) (contents : x.contents = y.contents) :
    x = y
    theorem Cslib.Automata.MPDA.Config.ext_iff {n : ℕ} {State : Type u_4} {Γ : Type u_5} {x y : Config n State Γ} :
    def Cslib.Automata.MPDA.configLTS {n : ℕ} {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} (M : MPDA n State Symbol Γ) :
    LTS (Config n State Γ) (Symbol × Op n Γ)

    The transition system on configurations of an MPDA. A configuration c moves to c' with label μ when the control moves along μ and the stack operation of μ turns the stacks of c into those of c'.

    @[simp]
    theorem Cslib.Automata.MPDA.configLTS_tr {n : ℕ} {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA n State Symbol Γ} {c c' : Config n State Γ} {μ : Symbol × Op n Γ} :
    M.configLTS.Tr c μ c' ↔ M.Tr c.state μ c'.state ∧ μ.2.Apply c.contents c'.contents
    theorem Cslib.Automata.MPDA.configLTS_mTr_state {n : ℕ} {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA n State Symbol Γ} {c c' : Config n State Γ} {μs : List (Symbol × Op n Γ)} (h : M.configLTS.MTr c μs c') :
    M.MTr c.state μs c'.state

    Every run on configurations projects to a run of the control.

    Repeating a transition #

    theorem Cslib.Automata.MPDA.configLTS_mTr_replicate_push {n : ℕ} {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA n State Symbol Γ} {q : State} {x : Symbol} {i : Fin n} {γ : Γ} (h : M.Tr q (x, Op.push i γ) q) (k : ℕ) (σ : Stacks n Γ) :
    M.configLTS.MTr { state := q, contents := σ } (List.replicate k (x, Op.push i γ)) { state := q, contents := Function.update σ i (List.replicate k γ ++ σ i) }

    Repeating k times a transition that pushes γ on stack i and stays in its state.

    theorem Cslib.Automata.MPDA.configLTS_mTr_replicate_pop {n : ℕ} {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA n State Symbol Γ} {q : State} {x : Symbol} {i : Fin n} {γ : Γ} (h : M.Tr q (x, Op.pop i γ) q) (k : ℕ) (σ : Stacks n Γ) :
    M.configLTS.MTr { state := q, contents := Function.update σ i (List.replicate k γ ++ σ i) } (List.replicate k (x, Op.pop i γ)) { state := q, contents := σ }

    Repeating k times a transition that pops γ from stack i and stays in its state.

    Repeating a transition on two stacks #

    theorem Cslib.Automata.MPDA.configLTS_mTr_replicate_push_zero {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA 2 State Symbol Γ} {q : State} {x : Symbol} {γ : Γ} (h : M.Tr q (x, Op.push 0 γ) q) (s₁ : List Γ) (k : ℕ) (s₀ : List Γ) :
    M.configLTS.MTr { state := q, contents := Stacks.pair s₀ s₁ } (List.replicate k (x, Op.push 0 γ)) { state := q, contents := Stacks.pair (List.replicate k γ ++ s₀) s₁ }
    theorem Cslib.Automata.MPDA.configLTS_mTr_replicate_push_one {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA 2 State Symbol Γ} {q : State} {x : Symbol} {γ : Γ} (h : M.Tr q (x, Op.push 1 γ) q) (s₀ : List Γ) (k : ℕ) (s₁ : List Γ) :
    M.configLTS.MTr { state := q, contents := Stacks.pair s₀ s₁ } (List.replicate k (x, Op.push 1 γ)) { state := q, contents := Stacks.pair s₀ (List.replicate k γ ++ s₁) }
    theorem Cslib.Automata.MPDA.configLTS_mTr_replicate_pop_zero {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA 2 State Symbol Γ} {q : State} {x : Symbol} {γ : Γ} (h : M.Tr q (x, Op.pop 0 γ) q) (s₁ : List Γ) (k : ℕ) (s₀ : List Γ) :
    M.configLTS.MTr { state := q, contents := Stacks.pair (List.replicate k γ ++ s₀) s₁ } (List.replicate k (x, Op.pop 0 γ)) { state := q, contents := Stacks.pair s₀ s₁ }
    theorem Cslib.Automata.MPDA.configLTS_mTr_replicate_pop_one {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA 2 State Symbol Γ} {q : State} {x : Symbol} {γ : Γ} (h : M.Tr q (x, Op.pop 1 γ) q) (s₀ : List Γ) (k : ℕ) (s₁ : List Γ) :
    M.configLTS.MTr { state := q, contents := Stacks.pair s₀ (List.replicate k γ ++ s₁) } (List.replicate k (x, Op.pop 1 γ)) { state := q, contents := Stacks.pair s₀ s₁ }
    theorem Cslib.Automata.MPDA.exists_inv_pair_of_configLTS_mTr {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA 2 State Symbol Γ} (Inv : State → List Γ → List Γ → List Symbol → Prop) (hstep : ∀ {q q' : State} {s₀ s₁ : List Γ} {u : List Symbol} {μ : Symbol × Op 2 Γ} {σ : Stacks 2 Γ}, Inv q s₀ s₁ u → M.configLTS.Tr { state := q, contents := Stacks.pair s₀ s₁ } μ { state := q', contents := σ } → ∃ (t₀ : List Γ) (t₁ : List Γ), σ = Stacks.pair t₀ t₁ ∧ Inv q' t₀ t₁ (u ++ [μ.1])) {q : State} {s₀ s₁ : List Γ} {μs : List (Symbol × Op 2 Γ)} {c : Config 2 State Γ} (h : M.configLTS.MTr { state := q, contents := Stacks.pair s₀ s₁ } μs c) (h₀ : Inv q s₀ s₁ []) :
    ∃ (t₀ : List Γ) (t₁ : List Γ), c.contents = Stacks.pair t₀ t₁ ∧ Inv c.state t₀ t₁ (List.map Prod.fst μs)

    An invariant of the control state, the contents of two stacks and the input read so far that holds at the start of a run and is preserved by every transition holds at its end.

    def Cslib.Automata.MPDA.IsVisibly {n : ℕ} {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} (M : MPDA n State Symbol Γ) (κ : Symbol → OpKind n) :

    An MPDA reads the letters visibly for κ if every transition on a letter a performs an operation of kind κ a.

    theorem Cslib.Automata.MPDA.IsVisibly.kind_eq {n : ℕ} {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} {M : MPDA n State Symbol Γ} {κ : Symbol → OpKind n} (hM : M.IsVisibly κ) {c c' : Config n State Γ} {w : List (Symbol × Op n Γ)} (h : M.configLTS.MTr c w c') (μ : Symbol × Op n Γ) :
    μ ∈ w → μ.2.kind = κ μ.1

    Every operation of a run of a visibly MPDA has the kind of its letter.

    @[instance_reducible]
    instance Cslib.Automata.MPDA.instAcceptor {n : ℕ} {State : Type u_1} {Symbol : Type u_2} {Γ : Type u_3} :
    Acceptor (MPDA n State Symbol Γ) Symbol

    An MPDA accepts a word if it has a run labelled by that word that starts in an initial state with all stacks empty and ends in an accepting state with all stacks empty.