Chomsky Normal Form Grammars #
This file defines Chomsky-normal-form grammars and their derivation semantics.
Main declarations #
Rule that rewrites a single nonterminal to a single terminal or a pair of nonterminals.
- leaf
{T : Type uT}
{N : Type uN}
(n : N)
(t : T)
: ChomskyNormalFormRule T N
First kind of rule, rewriting a nonterminal
nto a single terminalt. - node
{T : Type uT}
{N : Type uN}
(n l r : N)
: ChomskyNormalFormRule T N
Second kind of rule, rewriting a nonterminal
nto a pair of nonterminallr.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- instDecidableEqChomskyNormalFormRule.decEq (ChomskyNormalFormRule.leaf n t) (ChomskyNormalFormRule.node n_1 l r) = isFalse ⋯
- instDecidableEqChomskyNormalFormRule.decEq (ChomskyNormalFormRule.node n l r) (ChomskyNormalFormRule.leaf n_1 t) = isFalse ⋯
Instances For
- NT : Type uN
Type of nonterminals.
- initial : self.NT
Initial nonterminal.
- rules : Finset (ChomskyNormalFormRule T self.NT)
Rewrite rules.
Instances For
The input of a CNF rule, similar to ContextFreeRule.input
Equations
- (ChomskyNormalFormRule.leaf n t).input = n
- (ChomskyNormalFormRule.node n l r_2).input = n
Instances For
The output of a CNF rule, similar to ContextFreeRule.output
Equations
- (ChomskyNormalFormRule.leaf n t).output = [Symbol.terminal t]
- (ChomskyNormalFormRule.node n l r_2).output = [Symbol.nonterminal l, Symbol.nonterminal r_2]
Instances For
Inductive definition of a single application of a given cnf rule r to a string u;
r.Rewrites u v means that the r sends u to v (there may be multiple such strings v).
- head_leaf
{T : Type uT}
{N : Type uN}
(n : N)
(t : T)
(s : List (Symbol T N))
: (leaf n t).Rewrites (Symbol.nonterminal n :: s) (Symbol.terminal t :: s)
The replacement is at the start of the remaining string and the rule is a leaf rule.
- head_node
{T : Type uT}
{N : Type uN}
(nᵢ n₁ n₂ : N)
(s : List (Symbol T N))
: (node nᵢ n₁ n₂).Rewrites (Symbol.nonterminal nᵢ :: s) (Symbol.nonterminal n₁ :: Symbol.nonterminal n₂ :: s)
The replacement is at the start of the remaining string and the rule is a node rule.
- cons
{T : Type uT}
{N : Type uN}
(r : ChomskyNormalFormRule T N)
(s : Symbol T N)
{u₁ u₂ : List (Symbol T N)}
(hru : r.Rewrites u₁ u₂)
: r.Rewrites (s :: u₁) (s :: u₂)
The replacement is at the start of the remaining string.
Instances For
Rule r rewrites string u to string v iff they share both a prefix p and postfix q
such that the remaining middle part of u is the input of r and the remaining middle part
of v is the output of r.
Given a cnf grammar g and strings u and v
g.Produces u v means that one step of a cnf transformation by a rule from g sends
u to v.
Instances For
Given a cnf grammar g and strings u and v
g.Derives u v means that g can transform u to v in some number of rewriting steps.
Equations
Instances For
Given a cnf grammar g and a string s
g.Generates s means that g can transform its initial nonterminal to s in some number of
rewriting steps.
Instances For
The language (set of words) that can be generated by a given cnf grammar g.
Instances For
A given word w belongs to the language generated by a given cnf grammar g iff
g can derive the word w (wrapped as a string) from the initial nonterminal of g in some
number of steps.