Encoded Context-Free Grammars and Uniform Computability of Emptiness #
This file introduces a concrete encoded representation of context-free grammars
(EncodedCFG) that is Primcodable, enabling a genuine uniform computability
theorem for CFG emptiness where the grammar itself is the argument.
Encoding #
An EncodedCFG T is a triple (numNT, initial, rules) where:
numNT : ℕ— the number of nonterminals minus one (the actual nonterminal type isFin (numNT + 1), ensuring it is always nonempty)initial : ℕ— index of the initial nonterminal (taken modnumNT + 1)rules : List (ℕ × List (ℕ ⊕ T))— production rules, whereSum.inl krepresents nonterminalk % (numNT + 1)andSum.inr trepresents terminalt
The underlying type is ℕ × ℕ × List (ℕ × List (ℕ ⊕ T)), which inherits Primcodable
from the standard Mathlib instances for products, sums, lists, and ℕ (plus
Primcodable T). It is Primcodable because each component is: ℕ has
Primcodable.nat, ⊕ has Primcodable.sum, List has Primcodable.list,
and × has Primcodable.prod.
Main results #
EncodedCFG— the encoded grammar typeEncodedCFG.toCFGrammar— translation to the project'sCF_grammar T
The Encoded Grammar Type #
Equations
- EncodedCFG.instPrimcodable = inferInstanceAs (Primcodable (ℕ × ℕ × List (ℕ × List (ℕ ⊕ T))))
Equations
- G.initialIdx = G.2.1
Instances For
Instances For
Equations
- G.toSymbol (Sum.inl k) = symbol.nonterminal (G.toNT k)
- G.toSymbol (Sum.inr t) = symbol.terminal t
Instances For
Equations
- One or more equations did not get rendered due to their size.