Context-Free Languages and Non-Closure Under Specified Operations
Context-free languages (CFLs) have several closure properties, but they are not closed under intersection and (as a consequence) not closed under complement. Standard results also show that CFLs are closed under union, concatenation, and Kleene star—so if you are told “CFLs are NOT closed under (i) Union (ii) Concatenation (iii) Intersection (iv) Kleene star”, that statement is only correct for (iii) Intersection. We will prove/justify this precisely by giving:
- what is closed (i, ii, iv), and
- why intersection fails (iii), using a classic counterexample. 3
Mermaid intuition (why intersection is the problematic one):
In short: intersection can force constraints that require “correlated” counting across multiple regions in a way that a single PDA cannot simulate.
Key terms: Context-free language , Closure property , Intersection , Kleene star.
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
Closure Properties of Context Free Languages (GeeksforGeeks) https://www.geeksforgeeks.org/theory-of-computation/closure-properties-of-context-free-languages - States and outlines closure under concatenation and Kleene closure/star (with constructions) and discusses intersection/complement non-closure. ↩
-
[PDF] Lecture 10 - Closure Properties for Context-Free Languages (University of Waterloo) https://cs.uwaterloo.ca/~s4bendav/files/CS360S22Lec10.pdf - Mentions regular operations closure (union/concatenation/star) and non-closure under intersection/complement. ↩
CFL Closure Properties: which operations preserve context-freeness?
The correct closure status for CFLs (high-level)
Let be CFLs. Then:
| Operation on languages | Closed for CFLs? | Status |
|---|---|---|
| (i) Union | Yes | CFLs are closed under union 2 |
| (ii) Concatenation | Yes | CFLs are closed under concatenation 2 |
| (iii) Intersection | No (not necessarily) | Intersection of CFLs need not be CFL 2 |
| (iv) Kleene star | Yes | CFLs are closed under Kleene star 2 |
So the only “NOT closed” item in your list is (iii) Intersection. 2
Key terms: Context-free grammar , Pushdown automaton (PDA) , Regular language , De Morgan’s laws.
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩ ↩2 ↩3 ↩4 ↩5
-
Closure Properties of Context Free Languages (GeeksforGeeks) https://www.geeksforgeeks.org/theory-of-computation/closure-properties-of-context-free-languages - States and outlines closure under concatenation and Kleene closure/star (with constructions) and discusses intersection/complement non-closure. ↩ ↩2 ↩3
-
4.5: Non-context-free Languages - Engineering LibreTexts https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Foundations_of_Computation_(Critchlow_and_Eck)/04%3A_Grammars/4.05%3A_Non-context-free_Languages - Provides the CFL intersection non-closure theorem and explicit counterexample languages; also notes intersection with regular languages is CFL. ↩ ↩2
Why CFLs ARE closed under union, concatenation, and Kleene star (grammar constructions)
- 1Step 1
Given CFGs for and , create a new start symbol with rules and ; the resulting CFG generates exactly .
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
- 2Step 2
Given CFGs for and , build a new CFG with start symbol and rule (after renaming nonterminals to avoid clashes). Then every derivation yields a string from followed by a string from .
Footnotes
-
Closure Properties of Context Free Languages (GeeksforGeeks) https://www.geeksforgeeks.org/theory-of-computation/closure-properties-of-context-free-languages - States and outlines closure under concatenation and Kleene closure/star (with constructions) and discusses intersection/complement non-closure. ↩
-
- 3Step 3
Given CFG for , add a new start symbol and productions that allow either (zero copies) or concatenation of one or more copies of the old start symbol. This ensures is generated. 2
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
Closure Properties of Context Free Languages (GeeksforGeeks) https://www.geeksforgeeks.org/theory-of-computation/closure-properties-of-context-free-languages - States and outlines closure under concatenation and Kleene closure/star (with constructions) and discusses intersection/complement non-closure. ↩
-
- 4Step 4
Since each operation has a CFG construction, the corresponding closure property holds for CFLs. 2
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
Closure Properties of Context Free Languages (GeeksforGeeks) https://www.geeksforgeeks.org/theory-of-computation/closure-properties-of-context-free-languages - States and outlines closure under concatenation and Kleene closure/star (with constructions) and discusses intersection/complement non-closure. ↩
-
(iii) CFLs are NOT closed under intersection: the classic counterexample
Consider the alphabet . Define two languages:
Each of and is context-free (they each enforce equality in exactly one region: number of ’s vs ’s in , and number of ’s vs ’s in ).
Now compute the intersection:
- A string is in iff it satisfies both constraints simultaneously.
- From : number of ’s equals number of ’s.
- From : number of ’s equals number of ’s. Therefore, for strings in the intersection, \\#a=\\#b=\\#c=n, giving:
The crucial fact: is not context-free (proved using the pumping lemma for CFLs / standard non-CFL results). 2
Hence, CFLs are not closed under intersection.
Mermaid “constraint stacking”:
Key terms: Pumping lemma for CFLs , Counterexample , Non-context-free language.
Footnotes
-
4.5: Non-context-free Languages - Engineering LibreTexts https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Foundations_of_Computation_(Critchlow_and_Eck)/04%3A_Grammars/4.05%3A_Non-context-free_Languages - Provides the CFL intersection non-closure theorem and explicit counterexample languages; also notes intersection with regular languages is CFL. ↩ ↩2
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
type="warning" title="Important correction about your list" content="CFLs are actually closed under Union, Concatenation, and Kleene Star; the only operation in your list that CFLs are not closed under (in general) is Intersection. 2"
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
Closure Properties of Context Free Languages (GeeksforGeeks) https://www.geeksforgeeks.org/theory-of-computation/closure-properties-of-context-free-languages - States and outlines closure under concatenation and Kleene closure/star (with constructions) and discusses intersection/complement non-closure. ↩
type="tip" title="Common exam strategy for non-closure under intersection" content="To show CFLs are not closed under intersection, pick two CFLs whose intersection forces a known non-CFL pattern—often —and then cite a standard non-CFL proof (e.g., pumping lemma). 2"
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
4.5: Non-context-free Languages - Engineering LibreTexts https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Foundations_of_Computation_(Critchlow_and_Eck)/04%3A_Grammars/4.05%3A_Non-context-free_Languages - Provides the CFL intersection non-closure theorem and explicit counterexample languages; also notes intersection with regular languages is CFL. ↩
FAQs and related closure facts
Learning roadmap (what to know to solve closure questions)
Know the closure theorem
Step 1Union, concatenation, and star for CFLs can be shown by explicit CFG constructions. 2"
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
Closure Properties of Context Free Languages (GeeksforGeeks) https://www.geeksforgeeks.org/theory-of-computation/closure-properties-of-context-free-languages - States and outlines closure under concatenation and Kleene closure/star (with constructions) and discusses intersection/complement non-closure. ↩
Recognize the typical failure mode
Step 2Intersection can enforce multiple independent equalities that push beyond PDA capabilities. 2"
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
4.5: Non-context-free Languages - Engineering LibreTexts https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Foundations_of_Computation_(Critchlow_and_Eck)/04%3A_Grammars/4.05%3A_Non-context-free_Languages - Provides the CFL intersection non-closure theorem and explicit counterexample languages; also notes intersection with regular languages is CFL. ↩
Use a standard non-CFL target
Step 3Common target: , known not to be CFL (e.g., pumping lemma). 2"
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
4.5: Non-context-free Languages - Engineering LibreTexts https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Foundations_of_Computation_(Critchlow_and_Eck)/04%3A_Grammars/4.05%3A_Non-context-free_Languages - Provides the CFL intersection non-closure theorem and explicit counterexample languages; also notes intersection with regular languages is CFL. ↩
Conclude non-closure via counterexample
Step 4Show both are CFL but is not, so closure fails. 2"
Footnotes
-
[PDF] 1 Closure Properties of Context-Free Languages (University of North Carolina) https://www.cs.unc.edu/~plaisted/comp455/slides/cfl3.5.pdf - Notes showing union/concatenation/star closure and non-closure under intersection (and complement) with a standard argument. ↩
-
4.5: Non-context-free Languages - Engineering LibreTexts https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Foundations_of_Computation_(Critchlow_and_Eck)/04%3A_Grammars/4.05%3A_Non-context-free_Languages - Provides the CFL intersection non-closure theorem and explicit counterexample languages; also notes intersection with regular languages is CFL. ↩
Knowledge Check
Which of the following operations are context-free languages (CFLs) always closed under?