Decidable Grammar Membership Test #
This file shows that the basic operations of unrestricted grammars are decidable / computable, which is needed to express grammar membership as a search procedure.
Main results #
applyRuleAt— computable function that applies a rule at a positionapplyRuleSeq— computable function that applies a sequence of rulesextractTerminals— extract the terminal word from a terminal sentential formgrammarTest— the decidable test for grammar membershipgrammarTest_sound/grammarTest_complete— correctness of the test
Computable rule application #
Given a grammar, a sentential form, a rule index, and a position,
attempt to apply the rule at that position. Returns none if the rule
doesn't match at that position.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply a sequence of (rule_index, position) pairs to a sentential form,
starting from a given initial form. Returns none if any step fails.
This is the core "derivation simulator": given a sequence of instructions
[(r₀, p₀), (r₁, p₁), ...], it:
- Starts with
init - Applies rule
rules[rᵢ]at positionpᵢ - Returns the final sentential form (or
noneif any step fails)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Terminal checking #
The Grammar Test Function #
The key function: given a derivation sequence (encoded as a List (ℕ × ℕ))
and an input word w, check whether the derivation produces w.
The grammar membership test.
Given a grammar g, a derivation sequence seq, and a target word w:
- Apply the rule sequence starting from
[nonterminal g.initial] - Check if the result is exactly
w.map symbol.terminal
Returns true iff the derivation sequence witnesses w ∈ grammar_language g.
Equations
- grammarTest g seq w = match applyRuleSeq g.rules [symbol.nonterminal g.initial] seq with | none => false | some sf => extractTerminals sf == some w