Sub topic 15
Closure Properties of CFLs and Deterministic CFLs
Assume you know alphabets, strings, regular languages, finite automata, context-free grammars (CFGs), and proof by contradiction. This chapter focuses on closure properties. A language family is closed under an operation if applying that operation to languages in the family always produces another language in the same family.
Closure properties of context-free languages
Context-free languages (CFLs) are closed under these operations:
- Union: if \(L1\) and \(L2\) are CFLs, then \(L1 \cup L2\) is a CFL.
- Concatenation: \(L1L2\) is a CFL.
- Kleene star: \(L_1^*\) is a CFL.
- Reversal: \(L_1^R\) is a CFL.
- Homomorphism and inverse homomorphism.
- Intersection with a regular language.
- Difference with a regular language.
The last two are useful in constructions. If \(L\) is context-free and \(R\) is regular, then \(L \cap R\) and \(L-R\) are context-free.
However, CFLs are not closed under arbitrary intersection, complement, or difference between two CFLs.
A standard counterexample uses:
\[ L_1=\{a^i b^i c^j\mid i,j\geq 0\} \]
and
\[ L_2=\{a^i b^j c^j\mid i,j\geq 0\}. \]
Both languages are context-free, but:
\[ L1\cap L2=\{a^n b^n c^n\mid n\geq 0\}, \]
which is not context-free. Therefore CFLs are not closed under intersection.
Deterministic CFLs
A deterministic context-free language (DCFL) is accepted by a deterministic pushdown automaton. Determinism gives useful closure properties, but it does not make the class equal to the CFLs.
DCFLs are closed under:
- Complement.
- Intersection with a regular language.
- Inverse homomorphism.
DCFLs are not generally closed under union, intersection, concatenation, Kleene star, homomorphism, or reversal.
The complement result is an important difference:
| Language family | Complement | Intersection |
|---|---|---|
| CFL | Not closed | Not closed |
| DCFL | Closed | Not closed in general |
Although DCFLs are closed under complement, they are not closed under intersection of two DCFLs. If they were, closure under complement and De Morgan's law would imply closure under union as well, which is known to fail.
A decision strategy
Use this sequence for a closure question:
- Identify the language family: CFL or DCFL.
- Identify the operation.
- Check whether the other language is regular.
- Apply a known closure rule.
- If the operation is not closed, use a counterexample or reduction.
Exercise
Let L be a CFL and R be regular. Is L - R necessarily context-free? What about the complement of L?
Show answer
L - R is context-free because L - R = L ∩ complement(R), and regular languages are closed under complement while CFLs are closed under intersection with regular languages. The complement of L is not necessarily context-free.