Context-free languages are closed under intersection with regular languages #
The intersection of a context-free language with a regular language is context-free
([BHPS61]). The construction is the triple product: the nonterminals of
the product grammar are the nonterminals of G annotated with an entry and an exit state of the
automaton M, and a rule of G yields one product rule for every way of threading the states
of M through its right-hand side. A fresh start symbol rewrites to the start nonterminal of G
between the start state and each accepting state of M.
Main definitions #
ContextFreeGrammar.Annotates:Annotates M p l out qsays that the sentential formlof the product grammar isoutwith its nonterminals annotated so that the states ofMthread fromptoq.ContextFreeGrammar.product: the product of a grammar with a finite automaton.
Main results #
ContextFreeGrammar.product_language: the product generates the intersection.Language.IsContextFree.inter_isRegular: closure under intersection with a regular language, and its contrapositivesLanguage.not_isContextFree_of_inter_regular_notand the proof schemaLanguage.not_isContextFree_via_witnessof [Shi85], which first pushes the language through a string homomorphism.
References #
The nonterminals of the product grammar: a nonterminal of G between an entry and an exit
state of the automaton, or the fresh start symbol none.
Equations
- G.ProductNT σ = Option (σ × G.NT × σ)
Instances For
Annotates M p l out q: the sentential form l of the product grammar is out with every
nonterminal A replaced by some some (p', A, q'), the states threading from p to q: a
terminal advances the automaton, and an annotated nonterminal jumps from its entry state to its
exit state.
- nil {T : Type u_1} {σ : Type} {G : ContextFreeGrammar T} {M : DFA T σ} (p : σ) : Annotates M p [] [] p
- terminal {T : Type u_1} {σ : Type} {G : ContextFreeGrammar T} {M : DFA T σ} {p q : σ} (a : T) {l : List (Symbol T (G.ProductNT σ))} {out : List (Symbol T G.NT)} (h : Annotates M (M.step p a) l out q) : Annotates M p (Symbol.terminal a :: l) (Symbol.terminal a :: out) q
- nonterminal {T : Type u_1} {σ : Type} {G : ContextFreeGrammar T} {M : DFA T σ} {p p' q : σ} (A : G.NT) {l : List (Symbol T (G.ProductNT σ))} {out : List (Symbol T G.NT)} (h : Annotates M p' l out q) : Annotates M p (Symbol.nonterminal (some (p, A, p')) :: l) (Symbol.nonterminal A :: out) q
Instances For
An annotation of a concatenation splits at the concatenation.
An annotation that is a concatenation annotates a concatenation.
A word annotates only itself, and ends where the automaton ends.
A word is annotated only by itself, and ends where the automaton ends.
The annotations of out from state p, each with its exit state.
Equations
- One or more equations did not get rendered due to their size.
- ContextFreeGrammar.annotations M x✝ [] = {(x✝, [])}
Instances For
The start rule of the product for an accepting state q.
Equations
- ContextFreeGrammar.startRule M G q = { input := none, output := [Symbol.nonterminal (some (M.start, G.initial, q))] }
Instances For
The rules of the product: a start rule for each accepting state, and each rule of G in
every annotation of its right-hand side.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The product of a grammar with a finite automaton: the nonterminals are annotated with entry
and exit states, each rule of G appears in every annotation of its right-hand side, and the
fresh start symbol rewrites to the start nonterminal of G between the start state and each
accepting state.
Equations
- G.product M = { NT := G.ProductNT σ, initial := none, rules := ContextFreeGrammar.productRules M G }
Instances For
The product generates the intersection #
A step of the product on an annotated form is a step of G on the form it annotates.
A derivation of the product from an annotated form is a derivation of G from the form it
annotates.
Every derivation of G of a word is the projection of a derivation of the product from an
annotation of its start, for any entry state.
Bar-Hillel: the product generates the intersection.
Context-free languages are closed under intersection with regular languages.
If L ∩ R is not context-free for a regular R, then L is not context-free.
The proof schema of [Shi85]: if the image of L under a string homomorphism,
intersected with a regular language, is not context-free, then L is not context-free.