Encoded Context-Free Grammars and Uniform Computability of Emptiness #
Shows a computability theorem for CFG emptiness where the grammar itself is the argument.
Main results #
encoded_cf_emptiness_decidable— constructiveDecidableinstance for emptiness of the language of an encoded grammarencoded_cf_emptiness_computable—ComputablePredfor emptiness, where the grammar is the argument (uniform over all encoded grammars)
Part 1: Productive Nonterminals Algorithm #
Initialize the productive nonterminals set: all nonterminals with leaf rules.
Equations
- g.productiveInit = g.rules.biUnion fun (r : ChomskyNormalFormRule T g.NT) => match r with | ChomskyNormalFormRule.leaf n t => {n} | ChomskyNormalFormRule.node n l r => ∅
Instances For
One step of the productive nonterminals fixpoint: add nonterminals whose
node rule has both children already in S.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The set of productive nonterminals, computed by iterating productiveStep
g.rules.card times.
Equations
Instances For
The set of all nonterminals that appear as inputs of rules.
Equations
- g.ruleInputs = Finset.image (fun (r : ChomskyNormalFormRule T g.NT) => r.input) g.rules
Instances For
Part 2: Monotonicity #
Part 3: Range bound – productive nonterminals are rule inputs #
Part 4: Fixpoint property #
Part 5: Soundness #
Part 6: Completeness #
Part 7: Main Correctness #
Part 8: Constructive Decidability #
Emptiness of a CNF grammar's language is decidable (constructively,
without Classical.propDecidable).
Equations
- g.cnf_emptiness_dec = if h : g.initial ∈ g.productiveNTs then isFalse ⋯ else isTrue ⋯
Instances For
Part 9: Context-Free Languages – General CFG #
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decidability and Computability #
Equations
Instances For
Direct Emptiness Check #
All nonterminal indices are normalized modulo ntCount to ensure the
algorithm correctly identifies productive nonterminals regardless of
the raw index values used in the encoding.
Check whether all nonterminal indices (mod nc) in a rule's RHS appear
in the set S (a list of ℕ). Terminals always pass.
Equations
Instances For
Check whether the encoded CFG has an empty language.
Instances For
Correctness #
Equations
- IsProductive g nt = ∃ (w : List T), CF_derives g [symbol.nonterminal nt] (List.map symbol.terminal w)
Instances For
For a fixpoint S, if all nonterminals in a sentential form that derives some terminal string have their indices in S, and a rule (nt, rhs) with rhs = that form is in the grammar, then nt's index is in S.
Computability #
Context-free emptiness is uniformly computable for encoded CFGs (raw ComputablePred
decider; the packaged ComputableEmptiness over the CF class lives in
ContextFree/Decidability/Characterization.lean).
Emptiness is uniformly computable for the context-free languages: encoded
context-free grammars are an adequate, effective presentation
(contextFreeLanguageOf_characterizes) with uniformly decidable emptiness
(ComputableEmptiness).