Counting Derivation Steps for CFGs #
This file refines context-free derivations by tracking the number of production steps.
Main declarations #
Given a context-free grammar g, strings u and v, and number n
g.DerivesIn u v n means that g can transform u to v in n rewriting steps.
- refl
{T : Type uT}
{g : ContextFreeGrammar T}
(w : List (Symbol T g.NT))
: g.DerivesIn w w 0
0 steps entail no transformation
- tail
{T : Type uT}
{g : ContextFreeGrammar T}
(u v w : List (Symbol T g.NT))
(n : ℕ)
: g.DerivesIn u v n → g.Produces v w → g.DerivesIn u w n.succ
n + 1 steps, if transforms
utovin n steps, andvtowin 1 step
Instances For
theorem
ContextFreeGrammar.mem_language_iff_derivesIn
{T : Type uT}
(g : ContextFreeGrammar T)
(w : List T)
:
theorem
ContextFreeGrammar.DerivesIn.zero_steps
{T : Type uT}
{g : ContextFreeGrammar T}
(w : List (Symbol T g.NT))
:
g.DerivesIn w w 0
theorem
ContextFreeGrammar.Produces.single_step
{T : Type uT}
{g : ContextFreeGrammar T}
{v w : List (Symbol T g.NT)}
(hvw : g.Produces v w)
:
g.DerivesIn v w 1
@[irreducible]
theorem
ContextFreeGrammar.DerivesIn.append_split
{T : Type uT}
{g : ContextFreeGrammar T}
{p q w : List (Symbol T g.NT)}
{n : ℕ}
(hpqw : g.DerivesIn (p ++ q) w n)
:
theorem
ContextFreeGrammar.DerivesIn.three_split
{T : Type uT}
{g : ContextFreeGrammar T}
{p q r w : List (Symbol T g.NT)}
{n : ℕ}
(hg : g.DerivesIn (p ++ q ++ r) w n)
:
theorem
ContextFreeGrammar.DerivesIn.head_induction_on
{T : Type uT}
{g : ContextFreeGrammar T}
{n : ℕ}
{b : List (Symbol T g.NT)}
{P : (n : ℕ) → (a : List (Symbol T g.NT)) → g.DerivesIn a b n → Prop}
(refl : P 0 b ⋯)
(head :
∀ {n : ℕ} {a c : List (Symbol T g.NT)} (hac : g.Produces a c) (hcb : g.DerivesIn c b n), P n c hcb → P n.succ a ⋯)
{a : List (Symbol T g.NT)}
(hab : g.DerivesIn a b n)
:
P n a hab