Length Restriction for CFGs #
This file transforms wellformed grammars so that every rule has Chomsky-normal-form length.
Main declarations #
Wellformed r holds if the rule's output is not a single nonterminal (UnitRule), not empty,
or if the output is more than one symbol, it is only nonterminals
- terminal
{T : Type uT}
{N : Type u_1}
{n : N}
(t : T)
: { input := n, output := [Symbol.terminal t] }.Wellformed
Rule rewriting to a single terminal is wellformed
- nonterminals
{T : Type uT}
{N : Type u_1}
{n : N}
(u : List (Symbol T N))
(h2 : 2 ≤ u.length)
(hu :
∀ s ∈ u,
match s with
| Symbol.nonterminal n => True
| x => False)
: { input := n, output := u }.Wellformed
Rule rewriting to mulitple nonterminals is wellformed
Instances For
Shorthand for the new type of nonterminals.
Equations
- ContextFreeGrammar.NT' = (g.NT ⊕ (r : ContextFreeRule T g.NT) × Fin (r.output.length - 2))
Instances For
Computes a cascade of rules generating r.output if it only contains nonterminals. For a rule
r : n -> n₁n₂n₃n₄, generates rules n -> n₁m₂, m₂ -> n₂m₃, and m₃ -> n₃n₄. The type of of NT',
encodes the correspondence between rules and the new nonterminals.
Equations
- One or more equations did not get rendered due to their size.
Instances For
We assume all rules' output is either a pair of nonterminals, a single terminal or a string of
at least 3 nonterminals. In the first two cases we can directly translate them, otherwise we generate
new rules using compute_rules_rec.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compute all ChomskyNormalFormRules corresponding to the original ContextFreeRules
Equations
Instances For
Construct a ChomskyNormalGrammar corresponding to the original ContextFreeGrammar
Equations
- g.restrictLength = { NT := ContextFreeGrammar.NT', initial := Sum.inl g.initial, rules := ContextFreeGrammar.restrictLengthRules g.rules.toList }
Instances For
A grammar is Wellformed if all rules are ContextFreeRule.Wellformed
Equations
- g.Wellformed = ∀ r ∈ g.rules, r.Wellformed
Instances For
Intuitive embedding of symbols of the original grammar into symbols of the new grammar's type
Equations
Instances For
Intuitive embedding of strings of the original grammar into strings of the new grammar's type
Instances For
Projection from symbols of the new grammars type into symbols of the original grammar
Equations
Instances For
Projection from strings of the new grammars type into strings of the original grammar