Documentation

CslibFrontier.Computability.Automata.MPDA.HoleDerivation

Hole derivations #

A hole derivation builds a sequence of transitions from three kinds of blocks, keeping track of the open holes as chains of pending pushes: a well-nested block, a new hole made of atomic hole segments ↓ws ↓ws ⋯ of one stack (each a push followed by a well-nested sequence), and a pop that matches the newest push of the last open hole of its stack. These are the steps of the search of Algorithm 1 of [AGKR20] (AddHole, AddPop and the well-nested continuations through WR).

Every sequence built with at most K open holes is K-hole-bounded (MPDA.HoleDerivation.holeBounded): at each position, the first pending pushes of open holes in the sense of Definition 1 map injectively to the open chains.

Main definitions #

Main results #

References #

Pending pushes #

theorem Cslib.Automata.MPDA.pendingAt_append_iff {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w v : List (α × Op n Γ)} {p x : ℕ} (hx : x < w.length) :
PendingAt (w ++ v) p x ↔ PendingAt w p x

Whether a push is pending at a position only depends on the sequence up to that position.

theorem Cslib.Automata.MPDA.PendingAt.anti {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {p x y : ℕ} (h : PendingAt w p x) (hpy : p ≤ y) (hyx : y ≤ x) :
PendingAt w p y

A push pending at a position is pending at every earlier position from the push on.

theorem Cslib.Automata.MPDA.PendingAt.extend {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {p x y : ℕ} (h : PendingAt w p x) (hxy : x ≤ y) (hy : y < w.length) (hk : ∀ (i : Fin n), (∃ (a : α) (γ : Γ), w[p]? = some (a, Op.push i γ)) → ∀ (k : ℕ), 0 ≤ net i (List.take k (w.extract (x + 1) (y + 1)))) :
PendingAt w p y

A push pending at x stays pending at y ≥ x if no prefix of the factor after x pops below its initial height on the stack of the push.

theorem Cslib.Automata.MPDA.not_pendingAt_of_matches {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {q x m : ℕ} (h : Matches w q m) (hmx : m ≤ x) :

A push matched at m is no longer pending from m on.

theorem Cslib.Automata.MPDA.exists_matches_of_wellNested {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {q a b : ℕ} {i : Fin n} (hwn : WellNested (w.extract a b)) (hb : b ≤ w.length) (haq : a ≤ q) (hqb : q < b) (hq : IsPushOn w i q) :
∃ (m : ℕ), Matches w q m ∧ m < b ∧ WellMatched w q

A push inside a well-nested factor is closed by a well-nested continuation inside that factor.

Chains of pending pushes #

structure Cslib.Automata.MPDA.HoleChain (n : ℕ) (Γ : Type u_3) :
Type u_3

An open hole as a chain of pushes on one stack: their positions and pushed symbols, newest first.

  • stack : Fin n

    The stack of the hole.

  • pushes : List (ℕ × Γ)

    The positions and symbols of the pushes, newest first.

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

Consecutive pushes of a chain are separated by a well-nested factor, newest first.

def Cslib.Automata.MPDA.Snapshot {n : ℕ} {Γ : Type u_1} {α : Type u_2} (K : ℕ) (w : List (α × Op n Γ)) (x : ℕ) (C : List (HoleChain n Γ)) :

A snapshot of the open holes at position x of w: at most K chains of pending pushes, consecutive pushes of a chain separated by well-nested factors, and every other push pending at x inside a well-nested factor of w.

theorem Cslib.Automata.MPDA.Chained.pairwise {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {ps : List (ℕ × Γ)} (h : Chained w ps) :
List.Pairwise (fun (e e' : ℕ × Γ) => e'.1 < e.1) ps
theorem Cslib.Automata.MPDA.Snapshot.openHoles_le {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w : List (α × Op n Γ)} {x K : ℕ} {C : List (HoleChain n Γ)} (h : Snapshot K w x C) :

Counting holes: the open holes at x, in the sense of Definition 1, are at most the chains of a snapshot at x.

Hole derivations #

inductive Cslib.Automata.MPDA.HoleBlock {n : ℕ} {Γ : Type u_1} {α : Type u_2} (i : Fin n) (L : ℕ) :
List (α × Op n Γ) → List (ℕ × Γ) → Prop

A block of atomic hole segments of stack i starting at position L: pushes on stack i, each followed by a well-nested sequence. ps lists the positions and symbols of the pushes, newest first.

inductive Cslib.Automata.MPDA.HoleDerivation {n : ℕ} {Γ : Type u_1} {α : Type u_2} (K : ℕ) :
List (HoleChain n Γ) → List (α × Op n Γ) → Prop

Hole derivations with at most K open holes: a well-nested block, a new hole as a block of atomic hole segments while fewer than K holes are open, a pop matching the newest push of the last open hole of its stack, or closing a hole without pending pushes. These are the steps of the search of Algorithm 1 of [AGKR20].

def Cslib.Automata.MPDA.HoleBoundary {n : ℕ} {Γ : Type u_1} {α : Type u_2} (K : ℕ) (w : List (α × Op n Γ)) (C : List (HoleChain n Γ)) :

The open chains at the end of w: at most K chains of pushes pending at the last position, with no other pending push, consecutive pushes of a chain separated by well-nested factors, and the pushes of earlier chains before those of later ones.

theorem Cslib.Automata.MPDA.chained_append {n : ℕ} {Γ : Type u_1} {α : Type u_2} {w v : List (α × Op n Γ)} {ps : List (ℕ × Γ)} (h : Chained w ps) (hps : ∀ e ∈ ps, e.1 < w.length) :
Chained (w ++ v) ps
theorem Cslib.Automata.MPDA.Snapshot.append {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {w v : List (α × Op n Γ)} {C : List (HoleChain n Γ)} {x : ℕ} (h : Snapshot K w x C) (hx : x < w.length) :
Snapshot K (w ++ v) x C
theorem Cslib.Automata.MPDA.HoleBoundary.snapshot {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {w : List (α × Op n Γ)} {C : List (HoleChain n Γ)} (h : HoleBoundary K w C) :
Snapshot K w (w.length - 1) C
theorem Cslib.Automata.MPDA.HoleBoundary.lt_length {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {w : List (α × Op n Γ)} {C : List (HoleChain n Γ)} (h : HoleBoundary K w C) {c : HoleChain n Γ} (hc : c ∈ C) {e : ℕ × Γ} (he : e ∈ c.pushes) :
e.1 < w.length

The pushes of the chains lie in w.

theorem Cslib.Automata.MPDA.HoleBoundary.append_wellNested {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {w v : List (α × Op n Γ)} {C : List (HoleChain n Γ)} (h : HoleBoundary K w C) (hv : WellNested v) :
HoleBoundary K (w ++ v) C ∧ ∀ (x : ℕ), w.length ≤ x → x < (w ++ v).length → Snapshot K (w ++ v) x C
theorem Cslib.Automata.MPDA.HoleBoundary.append_push {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {w : List (α × Op n Γ)} {C : List (HoleChain n Γ)} {i : Fin n} {ps : List (ℕ × Γ)} {a : α} {γ : Γ} (h : HoleBoundary K w (C ++ [{ stack := i, pushes := ps }])) (hlink : ∀ e ∈ ps.head?, WellNested (w.extract (e.1 + 1))) :
HoleBoundary K (w ++ [(a, Op.push i γ)]) (C ++ [{ stack := i, pushes := (w.length, γ) :: ps }])

A push on stack i at the last position joins the newest chain.

theorem Cslib.Automata.MPDA.HoleBoundary.append_pop {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {w : List (α × Op n Γ)} {pre post : List (HoleChain n Γ)} {i : Fin n} {p : ℕ} {γ : Γ} {ps : List (ℕ × Γ)} {b : α} (h : HoleBoundary K w (pre ++ { stack := i, pushes := (p, γ) :: ps } :: post)) (hpost : ∀ c ∈ post, c.stack ≠ i) :
HoleBoundary K (w ++ [(b, Op.pop i γ)]) (pre ++ { stack := i, pushes := ps } :: post)

A pop on stack i matches the newest push of the last open hole of stack i.

theorem Cslib.Automata.MPDA.HoleBoundary.close {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {w : List (α × Op n Γ)} {pre post : List (HoleChain n Γ)} {i : Fin n} (h : HoleBoundary K w (pre ++ { stack := i, pushes := [] } :: post)) :
HoleBoundary K w (pre ++ post)

Closing a hole without pending pushes.

theorem Cslib.Automata.MPDA.HoleBlock.boundary {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {i : Fin n} {L : ℕ} {v : List (α × Op n Γ)} {ps : List (ℕ × Γ)} (hb : HoleBlock i L v ps) {w : List (α × Op n Γ)} {C : List (HoleChain n Γ)} :
w.length = L → C.length < K → HoleBoundary K w C → (∀ x < w.length, ∃ (Cx : List (HoleChain n Γ)), Snapshot K w x Cx) → HoleBoundary K (w ++ v) (C ++ [{ stack := i, pushes := ps }]) ∧ (∀ x < (w ++ v).length, ∃ (Cx : List (HoleChain n Γ)), Snapshot K (w ++ v) x Cx) ∧ ∀ e ∈ ps.head?, WellNested ((w ++ v).extract (e.1 + 1))

A hole block opens a new chain.

theorem Cslib.Automata.MPDA.HoleDerivation.invariant {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {C : List (HoleChain n Γ)} {w : List (α × Op n Γ)} (h : HoleDerivation K C w) :
HoleBoundary K w C ∧ ∀ x < w.length, ∃ (Cx : List (HoleChain n Γ)), Snapshot K w x Cx

The invariant of hole derivations: the open chains at the end, and a snapshot at every position.

theorem Cslib.Automata.MPDA.HoleDerivation.holeBounded {n : ℕ} {Γ : Type u_1} {α : Type u_2} {K : ℕ} {C : List (HoleChain n Γ)} {w : List (α × Op n Γ)} (h : HoleDerivation K C w) :

Words built by hole derivations are hole-bounded: a hole derivation with at most K open holes builds a K-hole-bounded sequence.