Data-carrying normal-form indexed parse certificates #
IndexedGrammar.NFYield is intentionally proposition-valued. Aho's marked simulation must,
however, follow individual pushed flag occurrences through one chosen parse. Proof irrelevance
means that this information cannot soundly be indexed by an NFYield proof itself, so this file
introduces the parallel Type-valued certificate NFParse.
Every NFYield proposition has a nonempty NFParse type, and every NFParse erases back to an
NFYield proof. We then define whether one root-stack occurrence is consumed in that concrete
parse and prove that an occurrence which is not consumed can be erased throughout the tree.
A data-carrying version of NFYield. Its constructors have exactly the four normal-form
rule shapes, but the result lives in Type so later algorithms may inspect the chosen tree.
- binary {T : Type} {g : IndexedGrammar T} {A B C : g.nt} {σ : List g.flag} {u v : List T} {r : IRule T g.nt g.flag} (hr : r ∈ g.rules) (hlhs : r.lhs = A) (hc : r.consume = none) (hrhs : r.rhs = [IRhsSymbol.nonterminal B none, IRhsSymbol.nonterminal C none]) (left : g.NFParse B σ u) (right : g.NFParse C σ v) : g.NFParse A σ (u ++ v)
- pop {T : Type} {g : IndexedGrammar T} {A B : g.nt} {f : g.flag} {ρ : List g.flag} {w : List T} {r : IRule T g.nt g.flag} (hr : r ∈ g.rules) (hlhs : r.lhs = A) (hc : r.consume = some f) (hrhs : r.rhs = [IRhsSymbol.nonterminal B none]) (rest : g.NFParse B ρ w) : g.NFParse A (f :: ρ) w
- push {T : Type} {g : IndexedGrammar T} {A B : g.nt} {f : g.flag} {σ : List g.flag} {w : List T} {r : IRule T g.nt g.flag} (hr : r ∈ g.rules) (hlhs : r.lhs = A) (hc : r.consume = none) (hrhs : r.rhs = [IRhsSymbol.nonterminal B (some f)]) (rest : g.NFParse B (f :: σ) w) : g.NFParse A σ w
- terminal {T : Type} {g : IndexedGrammar T} {A : g.nt} {σ : List g.flag} {a : T} {r : IRule T g.nt g.flag} (hr : r ∈ g.rules) (hlhs : r.lhs = A) (hc : r.consume = none) (hrhs : r.rhs = [IRhsSymbol.terminal a]) : g.NFParse A σ [a]
Instances For
Choose a concrete data-carrying representative of an NFYield proof.
Equations
Instances For
At the initial nonterminal, concrete parse trees characterize normal-form generation.
ConsumesAt p k says that some pop in the concrete parse p consumes the occurrence
initially at root-stack position k (positions start at zero).
Equations
- (IndexedGrammar.NFParse.binary hr hlhs hc hrhs left right).ConsumesAt k = (left.ConsumesAt k ∨ right.ConsumesAt k)
- (IndexedGrammar.NFParse.pop hr hlhs hc hrhs rest).ConsumesAt k = (k = 0 ∨ rest.ConsumesAt (k - 1))
- (IndexedGrammar.NFParse.push hr hlhs hc hrhs rest).ConsumesAt k = rest.ConsumesAt (k + 1)
- (IndexedGrammar.NFParse.terminal hr hlhs hc hrhs).ConsumesAt k = False
Instances For
Erase an inherited occurrence which is never consumed in a concrete parse.
Equations
- One or more equations did not get rendered due to their size.
- (IndexedGrammar.NFParse.pop hr hlhs hc hrhs rest).eraseIdxOfNotConsumesAt 0 unused_3 = ⋯.elim
- (IndexedGrammar.NFParse.pop hr hlhs hc hrhs rest).eraseIdxOfNotConsumesAt k_2.succ unused_3 = IndexedGrammar.NFParse.pop hr hlhs hc hrhs (rest.eraseIdxOfNotConsumesAt k_2 ⋯)
- (IndexedGrammar.NFParse.push hr hlhs hc hrhs rest).eraseIdxOfNotConsumesAt k unused_2 = IndexedGrammar.NFParse.push hr hlhs hc hrhs (rest.eraseIdxOfNotConsumesAt (k + 1) unused_2)
- (IndexedGrammar.NFParse.terminal hr hlhs hc hrhs).eraseIdxOfNotConsumesAt k unused_2 = IndexedGrammar.NFParse.terminal hr hlhs hc hrhs
Instances For
Proposition-level corollary of eraseIdxOfNotConsumesAt.
Productive-node accounting #
The number of terminal leaves in a concrete normal-form parse.
Equations
- (IndexedGrammar.NFParse.binary hr hlhs hc hrhs left right).terminalCount = left.terminalCount + right.terminalCount
- (IndexedGrammar.NFParse.pop hr hlhs hc hrhs rest).terminalCount = rest.terminalCount
- (IndexedGrammar.NFParse.push hr hlhs hc hrhs rest).terminalCount = rest.terminalCount
- (IndexedGrammar.NFParse.terminal hr hlhs hc hrhs).terminalCount = 1
Instances For
The number of binary nodes in a concrete normal-form parse.
Equations
- (IndexedGrammar.NFParse.binary hr hlhs hc hrhs left right).binaryCount = left.binaryCount + right.binaryCount + 1
- (IndexedGrammar.NFParse.pop hr hlhs hc hrhs rest).binaryCount = rest.binaryCount
- (IndexedGrammar.NFParse.push hr hlhs hc hrhs rest).binaryCount = rest.binaryCount
- (IndexedGrammar.NFParse.terminal hr hlhs hc hrhs).binaryCount = 0
Instances For
Productive events are binary expansions and terminal emissions.
Equations
Instances For
Terminal leaves count the length of the yield exactly.
A nonempty full binary parse has one fewer binary nodes than terminal leaves.
The number of productive events is at most twice the terminal yield length.