Uniform Membership Check for Encoded Context-Free Grammars #
Saturation Algorithm Definitions #
def
matchRHS
{T : Type}
[DecidableEq T]
(w : List T)
(nc : ℕ)
(S : List (ℕ × ℕ × ℕ))
(rhs : List (ℕ ⊕ T))
(startPos : ℕ)
:
Match a rule's RHS against a substring of word w, starting from position startPos.
Returns all possible end positions after matching the full RHS.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check membership of word w in the language of encoded CFG G.
Equations
Instances For
Monotonicity #
Soundness Lemmas #
Property that a triple represents a valid derivation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
theorem
matchRHS_sound
{T : Type}
[DecidableEq T]
(G : EncodedCFG T)
(w : List T)
(S : List (ℕ × ℕ × ℕ))
(hS : AllSound G w S)
(rhs : List (ℕ ⊕ T))
(startPos endPos : ℕ)
(hstart : startPos ≤ w.length)
(hmatch : endPos ∈ matchRHS w G.ntCount S rhs startPos)
:
startPos ≤ endPos ∧ endPos ≤ w.length ∧ CF_derives G.toCFGrammar (List.map G.toSymbol rhs)
(List.map symbol.terminal (List.take (endPos - startPos) (List.drop startPos w)))
theorem
satFixpoint_sound
{T : Type}
[DecidableEq T]
(G : EncodedCFG T)
(w : List T)
(steps : ℕ)
:
AllSound G w (satFixpoint G.ntCount G.rawRules w steps)
matchRHS structural lemmas #
theorem
matchRHS_foldl_append
{T : Type}
[DecidableEq T]
(w : List T)
(nc : ℕ)
(S : List (ℕ × ℕ × ℕ))
(rhs : List (ℕ ⊕ T))
(p1 p2 : List ℕ)
:
List.foldl (fun (positions : List ℕ) (sym : ℕ ⊕ T) => List.flatMap (matchOneSym w nc S sym) positions) (p1 ++ p2) rhs = List.foldl (fun (positions : List ℕ) (sym : ℕ ⊕ T) => List.flatMap (matchOneSym w nc S sym) positions) p1 rhs ++ List.foldl (fun (positions : List ℕ) (sym : ℕ ⊕ T) => List.flatMap (matchOneSym w nc S sym) positions) p2 rhs
Completeness Lemmas #
theorem
mem_satStep_of_matchRHS
{T : Type}
[DecidableEq T]
(nc : ℕ)
(rules : List (ℕ × List (ℕ ⊕ T)))
(w : List T)
(S : List (ℕ × ℕ × ℕ))
(lhs : ℕ)
(rhs : List (ℕ ⊕ T))
(hrule : (lhs, rhs) ∈ rules)
(startPos endPos : ℕ)
(hstart : startPos ≤ w.length)
(hmatch : endPos ∈ matchRHS w nc S rhs startPos)
:
Monotonicity of matchRHS in S #
Additional splitting lemmas #
theorem
terminal_derives_in_self
{T : Type}
(g : CF_grammar T)
(t : T)
(n : ℕ)
(w : List T)
(h : CF_derives_in g n [symbol.terminal t] (List.map symbol.terminal w))
:
theorem
rawRule_of_toCFGrammar_rule
{T : Type}
(G : EncodedCFG T)
(nt : Fin G.ntCount)
(rhs : List (symbol T (Fin G.ntCount)))
(hrule : (nt, rhs) ∈ G.toCFGrammar.rules)
:
theorem
matchRHS_in_satFixpoint
{T : Type}
[DecidableEq T]
(G : EncodedCFG T)
(w : List T)
(n : ℕ)
(ih_outer :
∀ m < n + 1,
∀ (nt : Fin G.ntCount) (i j : ℕ),
i ≤ j →
j ≤ w.length →
CF_derives_in G.toCFGrammar m [symbol.nonterminal nt]
(List.map symbol.terminal (List.take (j - i) (List.drop i w))) →
∃ (bound : ℕ), (↑nt, i, j) ∈ satFixpoint G.ntCount G.rawRules w bound)
(rhs : List (ℕ ⊕ T))
(startPos endPos : ℕ)
(hstart : startPos ≤ endPos)
(hend : endPos ≤ w.length)
(nder : ℕ)
(hnder : nder ≤ n)
(hder :
CF_derives_in G.toCFGrammar nder (List.map G.toSymbol rhs)
(List.map symbol.terminal (List.take (endPos - startPos) (List.drop startPos w))))
:
theorem
satFixpoint_complete
{T : Type}
[DecidableEq T]
(G : EncodedCFG T)
(w : List T)
(nt : Fin G.ntCount)
(i j : ℕ)
(hij : i ≤ j)
(hj : j ≤ w.length)
(hder : CF_derives G.toCFGrammar [symbol.nonterminal nt] (List.map symbol.terminal (List.take (j - i) (List.drop i w))))
:
Saturation Stabilization #
theorem
satFixpoint_nodup
{T : Type}
[DecidableEq T]
(nc : ℕ)
(rules : List (ℕ × List (ℕ ⊕ T)))
(w : List T)
(n : ℕ)
:
(satFixpoint nc rules w n).Nodup
theorem
satFixpoint_stable_after
{T : Type}
[DecidableEq T]
(nc : ℕ)
(rules : List (ℕ × List (ℕ ⊕ T)))
(w : List T)
(k : ℕ)
(hk : satFixpoint nc rules w k = satFixpoint nc rules w (k + 1))
(m : ℕ)
:
m ≥ k → satFixpoint nc rules w m = satFixpoint nc rules w k
Main Correctness #
theorem
checkMembershipEncoded_correct
{T : Type}
[DecidableEq T]
[Fintype T]
(G : EncodedCFG T)
(w : List T)
: