Documentation

CslibFrontier.Computability.Automata.MPDA.EmptinessComplete

Completeness of the emptiness procedure #

If an MPDA has a K-hole-bounded accepting run, repaired Algorithm 1 of [AGKR20] (MPDA.isEmpty) answers false. With soundness, this is Theorem 1 for repaired Algorithm 1 (MPDA.isEmpty_iff), for every K; the source states Theorem 1 for positive K. Starting the search from the initial state alone, as printed, is not complete (CslibFrontierTests.MPDA.Emptiness).

The run is cut at its events: the positions after a maximal well-nested factor, where the next transition is a pop or a push that is not closed by a well-nested continuation (MPDA.wnEnd). A hole push opens a chain, which extends greedily by the least later hole push of the same stack behind a well-nested factor; the chain is one AddHole step. A pop matches the newest push of the last chain of its stack and is one AddPop step. When a chain opens, Definition 1 counts at least one more open hole than there are open chains, so a K-hole-bounded run never needs more than K of them.

Main results #

References #

The next event #

noncomputable def Cslib.Automata.MPDA.wnEnd {n : ℕ} {Γ : Type u_1} {α : Type u_2} (w : List (α × Op n Γ)) (p : ℕ) :

The end of the longest well-nested factor of w starting at p.

theorem Cslib.Automata.MPDA.wnEnd_spec {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {p : ℕ} (hp : p ≤ w.length) :
theorem Cslib.Automata.MPDA.le_wnEnd {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {p r : ℕ} (hr : r ≤ w.length) (hpr : p ≤ r) (hwn : WellNested (w.extract p r)) :
r ≤ wnEnd w p
theorem Cslib.Automata.MPDA.wnEnd_event {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {p : ℕ} (hp : p ≤ w.length) (hlt : wnEnd w p < w.length) :
(¬∃ (a : α), w[wnEnd w p]? = some (a, Op.nop)) ∧ ¬WellMatched w (wnEnd w p)

After the longest well-nested factor comes an event: not a nop, and not a push closed by a well-nested continuation.

Greedy chains #

def Cslib.Automata.MPDA.IsHolePushOn {n : ℕ} {Γ : Type u_1} {α : Type u_2} (w : List (α × Op n Γ)) (i : Fin n) (r : ℕ) :

A push on stack i that is not closed by a well-nested continuation.

def Cslib.Automata.MPDA.Ext {n : ℕ} {Γ : Type u_1} {α : Type u_2} (w : List (α × Op n Γ)) (i : Fin n) (q r : ℕ) :

The hole push at r extends a chain ending in the push at q: same stack, separated by a well-nested factor.

theorem Cslib.Automata.MPDA.IsPushOn.lt_length {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} {r : ℕ} (h : IsPushOn w i r) :
r < w.length
theorem Cslib.Automata.MPDA.Ext.eq_of_le {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} {q r r' : ℕ} (h : Ext w i q r) (h' : Ext w i q r') (hle : r ≤ r') :
r = r'

Only the least extension of a push is an extension: a later one would enclose it in a well-nested factor.

@[irreducible]
noncomputable def Cslib.Automata.MPDA.chainFrom {n : ℕ} {Γ : Type u_1} {α : Type u_2} (w : List (α × Op n Γ)) (i : Fin n) (q : ℕ) :

The greedy chain from position q, oldest first: q, then the least extension, and so on.

theorem Cslib.Automata.MPDA.chainFrom_eq {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} {q : ℕ} :
chainFrom w i q = if h : ∃ (r : ℕ), Ext w i q r then q :: chainFrom w i (Nat.find h) else [q]
theorem Cslib.Automata.MPDA.mem_chainFrom_self {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} {q : ℕ} :
q ∈ chainFrom w i q
theorem Cslib.Automata.MPDA.chainFrom_spec {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} (q r : ℕ) :
r ∈ chainFrom w i q → q ≤ r ∧ (r ≠ q → IsHolePushOn w i r)

Every element of the greedy chain after q is a hole push of stack i, and the elements increase.

theorem Cslib.Automata.MPDA.mem_chainFrom_of_ext {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} (q p : ℕ) :
p ∈ chainFrom w i q → ∀ (r : ℕ), Ext w i p r → r ∈ chainFrom w i q

Greedy chains are closed under extension: an extension of an element of the chain is in the chain.

The counting guard #

theorem Cslib.Automata.MPDA.pendingAt_self {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} {t : ℕ} (h : IsPushOn w i t) :
PendingAt w t t
theorem Cslib.Automata.MPDA.chains_ne {n : ℕ} {Γ : Type u_1} {C : List (HoleChain n Γ)} (horder : List.Pairwise (fun (c c' : HoleChain n Γ) => ∀ e ∈ c.pushes, ∀ e' ∈ c'.pushes, e.1 < e'.1) C) {c c' : HoleChain n Γ} (hc : c ∈ C) (hc' : c' ∈ C) (hne : c ≠ c') (e : ℕ × Γ) :
e ∈ c.pushes → ∀ e' ∈ c'.pushes, e.1 ≠ e'.1

Pushes of different chains are at different positions.

theorem Cslib.Automata.MPDA.card_add_one_le_openHoles {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {C : List (HoleChain n Γ)} {t : ℕ} {i : Fin n} (ht : IsHolePushOn w i t) (hne : ∀ c ∈ C, c.pushes ≠ []) (helem : ∀ c ∈ C, ∀ e ∈ c.pushes, IsHolePushOn w c.stack e.1 ∧ PendingAt w e.1 t ∧ e.1 < t) (hcover : ∀ q < t, PendingAt w q t → ∃ c ∈ C, ∃ e ∈ c.pushes, e.1 = q) (horder : List.Pairwise (fun (c c' : HoleChain n Γ) => ∀ e ∈ c.pushes, ∀ e' ∈ c'.pushes, e.1 < e'.1) C) (hchain : ∀ c ∈ C, List.Pairwise (fun (e e' : ℕ × Γ) => e'.1 < e.1) c.pushes) (hclosed : ∀ c ∈ C, ∀ e ∈ c.pushes, ∀ (r : ℕ), Ext w c.stack e.1 r → r < t ∧ (PendingAt w r t → ∃ e' ∈ c.pushes, e'.1 = r)) :

The counting guard: a new hole push at t comes with at least one more open hole, in the sense of Definition 1, than there are open chains.

Helper lemmas #

theorem Cslib.Automata.MPDA.splitLastHole_eq_none {n : ℕ} {State : Type u_3} {i : Fin n} {l : List (HoleTriple n State)} :
(∀ h ∈ l, h.stack ≠ i) → splitLastHole i l = none
theorem Cslib.Automata.MPDA.splitLastHole_eq_some_of {n : ℕ} {State : Type u_3} {i : Fin n} {post : List (HoleTriple n State)} {s s' : State} (hpost : ∀ h ∈ post, h.stack ≠ i) (pre : List (HoleTriple n State)) :
splitLastHole i (pre ++ { stack := i, src := s, dst := s' } :: post) = some (pre, (s, s'), post)

The converse of splitLastHole_eq_some.

theorem Cslib.Automata.MPDA.stacksOf_eq_cons {n : ℕ} {Γ : Type u_1} {C : List (HoleChain n Γ)} (hne : ∀ c ∈ C, c.pushes ≠ []) {i : Fin n} {γ : Γ} {rest : List Γ} (h : stacksOf C i = γ :: rest) :
∃ (pre : List (HoleChain n Γ)) (post : List (HoleChain n Γ)) (p : ℕ) (ps : List (ℕ × Γ)), C = pre ++ { stack := i, pushes := (p, γ) :: ps } :: post ∧ ∀ d ∈ post, d.stack ≠ i

The top of a stack holding open chains is the newest push of the last chain of that stack.

theorem Cslib.Automata.MPDA.HoleBlock.prepend {n : ℕ} {Γ : Type u_1} {α : Type u_2} {i : Fin n} {L : ℕ} {v ws : List (α × Op n Γ)} {ps : List (ℕ × Γ)} {a : α} {γ : Γ} (hb : HoleBlock i (L + 1 + ws.length) v ps) (hws : WellNested ws) :
HoleBlock i L ((a, Op.push i γ) :: ws ++ v) (ps ++ [(L, γ)])

Prepend an atomic hole segment to a hole block.

Blocks of greedy chains along a run #

@[irreducible]
noncomputable def Cslib.Automata.MPDA.blockEnd {n : ℕ} {Γ : Type u_1} {α : Type u_2} (w : List (α × Op n Γ)) (i : Fin n) (q : ℕ) :

The end of the hole block of the greedy chain from q: after its last push, the longest well-nested factor.

theorem Cslib.Automata.MPDA.Realizes.prepend {n : ℕ} {Γ : Type u_1} {State : Type u_3} {Symbol : Type u_4} [Fintype State] [DecidableEq State] [Fintype Symbol] [Fintype Γ] {M : MPDA n State Symbol Γ} [(s : State) → (μ : Symbol × Op n Γ) → (s' : State) → Decidable (M.Tr s μ s')] {i : Fin n} {s s₁ t : State} {γ : Γ} {r : List (Γ × State)} (hγ : { src := s, sym := γ, dst := s₁ } ∈ M.atomicHoles i) (hr : M.Realizes i s₁ t r) :
M.Realizes i s t (r ++ [(γ, s₁)])

Prepend an atomic hole segment to a realization.

theorem Cslib.Automata.MPDA.exists_block_run {n : ℕ} {Γ : Type u_1} {State : Type u_3} {Symbol : Type u_4} [Fintype State] [DecidableEq State] [Fintype Symbol] [Fintype Γ] {M : MPDA n State Symbol Γ} [(s : State) → (μ : Symbol × Op n Γ) → (s' : State) → Decidable (M.Tr s μ s')] {w : List (Symbol × Op n Γ)} {i : Fin n} (q : ℕ) :
IsPushOn w i q → ∀ (c cf : Config n State Γ), M.configLTS.MTr c (List.drop q w) cf → ∃ (c' : Config n State Γ) (r : List (Γ × State)) (ps : List (ℕ × Γ)), HoleBlock i q (w.extract q (blockEnd w i q)) ps ∧ List.map Prod.fst ps = (chainFrom w i q).reverse ∧ List.map Prod.snd ps = List.map Prod.fst r ∧ M.Realizes i c.state c'.state r ∧ c'.contents = Function.update c.contents i (List.map Prod.fst r ++ c.contents i) ∧ M.configLTS.MTr c' (List.drop (blockEnd w i q) w) cf ∧ q < blockEnd w i q ∧ blockEnd w i q ≤ w.length

The block of a greedy chain along a run: from a push at q, the greedy chain is a hole block, the run through it realizes the hole triple from the state at q to the state at the end of the block, and pushes the chain's symbols on stack i.

The completeness invariant #

theorem Cslib.Automata.MPDA.chainFrom_lt_blockEnd {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} (q : ℕ) :
q < w.length → ∀ r ∈ chainFrom w i q, r < blockEnd w i q
theorem Cslib.Automata.MPDA.blockEnd_event {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} (q : ℕ) :
q < w.length → blockEnd w i q < w.length → (¬∃ (a : α), w[blockEnd w i q]? = some (a, Op.nop)) ∧ ¬WellMatched w (blockEnd w i q)
theorem Cslib.Automata.MPDA.eq_nil_of_stacksOf_eq_empty {n : ℕ} {Γ : Type u_1} {C : List (HoleChain n Γ)} (hne : ∀ c ∈ C, c.pushes ≠ []) (h : stacksOf C = Stacks.empty) :
C = []
theorem Cslib.Automata.MPDA.update_cons_injective {n : ℕ} {Γ : Type u_1} {σ σ' : Stacks n Γ} {i : Fin n} {γ : Γ} (h : Function.update σ i (γ :: σ i) = Function.update σ' i (γ :: σ' i)) :
σ = σ'
theorem Cslib.Automata.MPDA.reverse_take_eq_cons {β : Type u_3} {L : List β} {m : ℕ} (hm₁ : 1 ≤ m) (hm₂ : m ≤ L.length) :
(List.take m L).reverse = L[m - 1] :: (List.take (m - 1) L).reverse

The pop step #

The hole step #

theorem Cslib.Automata.MPDA.pendingAt_of_push {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {p t : ℕ} {a : α} {i : Fin n} {γ : Γ} (h : PendingAt w p (t - 1)) (hpt : p < t) (hwt : w[t]? = some (a, Op.push i γ)) :
PendingAt w p t

A push pending before a push stays pending across it.

Completeness #

theorem Cslib.Automata.MPDA.blockEnd_le_length {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {i : Fin n} (q : ℕ) :
q < w.length → blockEnd w i q ≤ w.length
theorem Cslib.Automata.MPDA.isEmpty_eq_false_of_mem_boundedLanguage {n : ℕ} {Γ : Type u_1} {State : Type u_3} {Symbol : Type u_4} [Fintype State] [DecidableEq State] [Fintype Symbol] [Fintype Γ] [DecidableEq Γ] {M : MPDA n State Symbol Γ} [(s : State) → (μ : Symbol × Op n Γ) → (s' : State) → Decidable (M.Tr s μ s')] [DecidablePred fun (x : State) => x ∈ M.start] [DecidablePred fun (x : State) => x ∈ M.accept] {K : ℕ} {x : List Symbol} (hx : x ∈ M.boundedLanguage (HoleBounded K)) :

Completeness of repaired Algorithm 1 of [AGKR20]: if some word has a K-hole-bounded accepting run, the search answers false.

theorem Cslib.Automata.MPDA.isEmpty_iff {n : ℕ} {Γ : Type u_1} {State : Type u_3} {Symbol : Type u_4} [Fintype State] [DecidableEq State] [Fintype Symbol] [Fintype Γ] [DecidableEq Γ] {M : MPDA n State Symbol Γ} [(s : State) → (μ : Symbol × Op n Γ) → (s' : State) → Decidable (M.Tr s μ s')] [DecidablePred fun (x : State) => x ∈ M.start] [DecidablePred fun (x : State) => x ∈ M.accept] {K : ℕ} :

Theorem 1 of [AGKR20], for repaired Algorithm 1: the search answers true exactly when no word has a K-hole-bounded accepting run. It holds for every K, including K = 0; the source states Theorem 1 for positive K.