Understanding the closure properties of different classes of formal languages is fundamental in theoretical computer science. Closure properties describe how language classes behave under various operations such as union, intersection, concatenation, etc. Below, we explore the closure properties for five fundamental language classes:
- Deterministic Context-Free Languages (DCFL)
- Context-Free Languages (CFL)
- Context-Sensitive Languages (CSL)
- Recursive (Decidable) Languages (REC)
- Recursively Enumerable (Turing Recognizable) Languages (RE)
For each language class, we'll examine whether it is closed under the following operations and provide examples to illustrate these properties.
1. Deterministic Context-Free Languages (DCFL)
Definition: DCFLs are a subset of context-free languages that can be recognized by deterministic pushdown automata.
Closure Properties:
-
Union
- Closed? No
- Example:
Let ( L_1 = { a^n b^n \mid n \geq 0 } ) and ( L_2 = { a^n c^n \mid n \geq 0 } ). Both ( L_1 ) and ( L_2 ) are DCFLs.
( L = L_1 \cup L_2 = { a^n b^n } \cup { a^n c^n } ) is not a DCFL.
-
Intersection
- Closed? No (except with regular languages)
- Example:
Let ( L_1 = { a^n b^n \mid n \geq 0 } ) and ( L_2 = { a^n b^m \mid m = 2n } ). ( L_1 ) and ( L_2 ) are DCFLs, but ( L_1 \cap L_2 = { a^n b^{2n} \mid n \geq 0 } ) is not a DCFL.
-
Set Difference
- Closed? No
- Example:
Using the same ( L_1 ) and ( L_2 ) as above, ( L_1 \setminus L_2 = { a^n b^n \mid n \geq 0 } ) which is DCFL, but in general, DCFLs are not closed under set difference.
-
Complementation
- Closed? No
- Example:
Let ( L = { a^n b^n \mid n \geq 0 } ). The complement ( \overline{L} ) contains all strings not of the form ( a^n b^n ), which is not a DCFL.
-
Intersection with Regular Language
- Closed? Yes
- Example:
Let ( L = { a^n b^n \mid n \geq 0 } ) (DCFL) and ( R = a^* b^* ) (regular).
( L \cap R = { a^n b^n \mid n \geq 0 } ) is DCFL.
-
Concatenation
- Closed? No
- Example:
Let ( L_1 = { a^n b^n \mid n \geq 0 } ) and ( L_2 = { b^n c^n \mid n \geq 0 } ). Both are DCFLs.
( L = L_1 L_2 = { a^n b^{2n} c^n \mid n \geq 0 } ) is not a DCFL.
-
Kleene Closure (*)
- Closed? No
- Example:
Let ( L = { a^n b^n \mid n \geq 0 } ) (DCFL).
( L^* = { a^{n_1} b^{n_1} a^{n_2} b^{n_2} \dots a^{n_k} b^{n_k} \mid k \geq 0, n_i \geq 0 } ) is not a DCFL.
-
Kleene Plus (+)
- Closed? No
- Example:
Similar to Kleene star, ( L^+ = { a^{n_1} b^{n_1} \dots a^{n_k} b^{n_k} \mid k \geq 1, n_i \geq 0 } ) is not a DCFL.
-
Reversal
- Closed? Yes
- Example:
Let ( L = { a^n b^n \mid n \geq 0 } ) (DCFL).
( L^R = { b^n a^n \mid n \geq 0 } ) is also a DCFL.
-
Homomorphism
- Closed? No
- Example:
Let ( h(a) = ab ) and ( h(b) = bc ).
( h(L) = { (ab)^n (bc)^n \mid n \geq 0 } = { a^n b^{2n} c^n \mid n \geq 0 } ) is not a DCFL.
-
Epsilon-free Homomorphism
- Closed? No
- Example:
Same as above; even without epsilon mappings, DCFLs are not closed under homomorphism.
-
Inverse Homomorphism
- Closed? Yes
- Example:
Let ( h(a) = ab ), ( h(b) = bc ), and ( L' = { a^n b^{2n} c^n \mid n \geq 0 } ) (not DCFL).
( h^{-1}(L') = { a^n b^n \mid n \geq 0 } ) which is DCFL.
-
Substitution
- Closed? No
- Example:
Substitute ( a ) with ( ab ) in ( L = { a^n b^n \mid n \geq 0 } ), resulting in ( { (ab)^n b^n \mid n \geq 0 } = { a^n b^{2n} \mid n \geq 0 } ), which is not DCFL.
-
Epsilon-free Substitution
- Closed? No
- Example:
Similar to substitution; closure does not hold even without epsilon.
-
Right Quotient with a Regular Language
- Closed? Yes
- Example:
Let ( L = { a^n b^n \mid n \geq 0 } ) (DCFL) and ( R = b^* ) (regular).
( L / R = { a^n \mid n \geq 0 } ), which is regular and hence DCFL.
-
Left Quotient with a Regular Language
- Closed? Yes
- Example:
Let ( L = { a^n b^n \mid n \geq 0 } ) (DCFL) and ( R = a^* ) (regular).
( R \setminus L = { b^n \mid n \geq 0 } ), which is regular and hence DCFL.
2. Context-Free Languages (CFL)
Definition: CFLs are languages that can be generated by context-free grammars or recognized by pushdown automata.
Closure Properties:
-
Union
- Closed? Yes
- Example:
( L_1 = { a^n b^n \mid n \geq 0 } ) and ( L_2 = { a^n c^n \mid n \geq 0 } ) are CFLs.
( L = L_1 \cup L_2 ) is also a CFL.
-
Intersection
- Closed? No
- Example:
( L_1 = { a^n b^n c^m \mid n, m \geq 0 } ) and ( L_2 = { a^m b^n c^n \mid m, n \geq 0 } ).
( L_1 \cap L_2 = { a^n b^n c^n \mid n \geq 0 } ), which is not a CFL.
-
Set Difference
- Closed? No
- Example:
Using ( L_1 ) and ( L_2 ) from the intersection example, ( L_1 \setminus L_2 = { a^n b^n c^m \mid n \geq 0, m \neq n } ) is not a CFL.
-
Complementation
- Closed? No
- Example:
Let ( L = { a^n b^n \mid n \geq 0 } ). Its complement ( \overline{L} ) is not a CFL.
-
Intersection with Regular Language
- Closed? Yes
- Example:
( L = { a^n b^n \mid n \geq 0 } ) (CFL) and ( R = a^* b^* ) (regular).
( L \cap R = { a^n b^n \mid n \geq 0 } ), which is CFL.
-
Concatenation
- Closed? Yes
- Example:
( L_1 = { a^n b^n \mid n \geq 0 } ) and ( L_2 = { b^n c^n \mid n \geq 0 } ) are CFLs.
( L = L_1 L_2 = { a^n b^{m} c^m \mid n, m \geq 0 } ), which is CFL.
-
Kleene Closure (*)
- Closed? Yes
- Example:
( L = { a^n b^n \mid n \geq 0 } ).
( L^* = { a^{n_1} b^{n_1} \dots a^{n_k} b^{n_k} \mid k \geq 0, n_i \geq 0 } ) is CFL.
-
Kleene Plus (+)
- Closed? Yes
- Example:
( L^+ = { a^{n_1} b^{n_1} \dots a^{n_k} b^{n_k} \mid k \geq 1, n_i \geq 0 } ), which is CFL.
-
Reversal
3. Context-Sensitive Languages (CSL)
Definition: CSLs are languages that can be recognized by linear bounded automata. They are more powerful than CFLs and DCFLs.
Closure Properties:
Context-sensitive languages possess robust closure properties, often mirroring those of recursive languages.
-
Union
- Closed? Yes
- Example:
( L_1 = { a^n b^n c^n \mid n \geq 0 } ) and ( L_2 = { a^m b^m d^m \mid m \geq 0 } ) are CSLs.
( L = L_1 \cup L_2 ) is also a CSL.
-
Intersection
- Closed? Yes
- Example:
( L_1 = { a^n b^n c^* \mid n \geq 0 } ) and ( L_2 = { a^* b^n c^n \mid n \geq 0 } ) are CSLs.
( L_1 \cap L_2 = { a^n b^n c^n \mid n \geq 0 } ), which is a CSL.
-
Set Difference
- Closed? Yes
- Example:
Using ( L_1 ) and ( L_2 ) from the intersection example, ( L_1 \setminus L_2 = { a^n b^n c^m \mid n \geq 0, m \neq n } ) is a CSL.
-
Complementation
- Closed? Yes
- Example:
Let ( L = { a^n b^n c^n \mid n \geq 0 } ), a CSL.
( \overline{L} ), which consists of all strings not in ( L ), is also a CSL.
-
Intersection with Regular Language
- Closed? Yes
- Example:
( L = { a^n b^n c^n \mid n \geq 0 } ) (CSL) and ( R = a^* b^* c^* ) (regular).
( L \cap R = L ) is CSL.
-
Concatenation
- Closed? Yes
- Example:
( L_1 = { a^n b^n } ) and ( L_2 = { b^n c^n } ) are CSLs.
( L = L_1 L_2 = { a^n b^{2n} c^n } ) is a CSL.
-
Kleene Closure (*)
- Closed? Yes
- Example:
( L = { a^n b^n c^n \mid n \geq 1 } ).
( L^* ) is a CSL.
-
Kleene Plus (+)
- Closed? Yes
- Example:
( L^+ ), similar to ( L^* ), is a CSL.
-
Reversal
- Closed? Yes
- Example:
( L = { a^n b^n c^n } ).
( L^R = { c^n b^n a^n } ) is a CSL.
-
Homomorphism
4. Recursive (Decidable) Languages (REC)
Definition: Recursive languages are those for which a Turing machine exists that will halt and accept for strings in the language and halt and reject for strings not in the language.
Closure Properties:
Recursive languages are robustly closed under virtually all standard operations.
-
Union
- Closed? Yes
- Example:
If ( L_1 ) and ( L_2 ) are recursive, then ( L_1 \cup L_2 ) is recursive.
-
Intersection
- Closed? Yes
- Example:
( L_1 \cap L_2 ) is recursive.
-
Set Difference
- Closed? Yes
- Example:
( L_1 \setminus L_2 ) is recursive.
-
Complementation
- Closed? Yes
- Example:
If ( L ) is recursive, then ( \overline{L} ) is also recursive.
-
Intersection with Regular Language
- Closed? Yes
- Example:
( L \cap R ), where ( R ) is regular, is recursive.
-
Concatenation
- Closed? Yes
- Example:
( L_1 L_2 ) is recursive.
-
Kleene Closure (*)
- Closed? Yes
- Example:
( L^* ) is recursive.
-
Kleene Plus (+)
- Closed? Yes
- Example:
( L^+ ) is recursive.
-
Reversal
- Closed? Yes
- Example:
( L^R ) is recursive.
-
Homomorphism
- Closed? Yes
- Example:
Applying any homomorphism ( h ) to ( L ), ( h(L) ) is recursive.
-
Epsilon-free Homomorphism
- Closed? Yes
- Example:
Similar to homomorphism without introducing epsilon.
-
Inverse Homomorphism
5. Recursively Enumerable (Turing Recognizable) Languages (RE)
Definition: RE languages are those for which a Turing machine exists that will halt and accept for strings in the language but may not halt for strings not in the language.
Closure Properties:
RE languages are closed under several operations but not all.
-
Union
- Closed? Yes
- Example:
If ( L_1 ) and ( L_2 ) are RE, then ( L_1 \cup L_2 ) is RE.
-
Intersection
- Closed? No
- Example:
Let ( L_1 ) be the Halting Problem and ( L_2 ) be its complement. While ( L_1 ) is RE, ( L_2 ) is not. ( L_1 \cap L_2 ) is empty (which is RE), but more nuanced examples show that intersection can lead to non-RE languages.
-
Set Difference
- Closed? No
- Example:
Similar to intersection, set difference ( L_1 \setminus L_2 ) can result in non-RE languages.
-
Complementation
- Closed? No
- Example:
The complement of the Halting Problem is not RE.
-
Intersection with Regular Language
- Closed? Yes
- Example:
( L \cap R ) is RE if ( L ) is RE and ( R ) is regular.
-
Concatenation
- Closed? Yes
- Example:
If ( L_1 ) and ( L_2 ) are RE, then ( L_1 L_2 ) is RE.
-
Kleene Closure (*)
- Closed? Yes
- Example:
( L^* ) is RE if ( L ) is RE.
-
Kleene Plus (+)
- Closed? Yes
- Example:
( L^+ ) is RE if ( L ) is RE.
-
Reversal
- Closed? Yes
- Example:
If ( L ) is RE, then ( L^R ) is RE.
-
Homomorphism
- Closed? Yes
- Example:
Applying any homomorphism ( h ) to ( L ), ( h(L) ) is RE.
-
Epsilon-free Homomorphism
Summary Table
| Operation | DCFL | CFL | CSL | REC | RE |
|---|
| Union | No | Yes | Yes | Yes | Yes |
| Intersection | No* | No | Yes | Yes | No |
| Set Difference | No | No | Yes | Yes | No |
| Complementation | No | No | Yes | Yes | No |
| Intersection with Regular | Yes | Yes | Yes | Yes | Yes |
| Concatenation | No | Yes | Yes | Yes | Yes |
| Kleene Closure (*) | No | Yes | Yes | Yes | Yes |
| Kleene Plus (+) | No | Yes | Yes | Yes | Yes |
| Reversal | Yes | Yes | Yes | Yes | Yes |
| Homomorphism | No | Yes | Yes | Yes | Yes |
| Epsilon-free Homomorphism | No | Yes | Yes | Yes | Yes |
| Inverse Homomorphism | Yes | Yes | Yes | Yes | Yes |
| Substitution | No | Yes | Yes | Yes | Yes |
| Epsilon-free Substitution | No | Yes | Yes | Yes | Yes |
| Right Quotient with Reg. | Yes | Yes | Yes | Yes | Yes |
| Left Quotient with Reg. | Yes | Yes |
Note: "No" under DCFL intersection indicates that DCFLs are not closed under general intersection but are closed when intersected with regular languages.
Key Takeaways
-
DCFLs have limited closure properties. They are not closed under union, general intersection, set difference, complementation, concatenation, etc., but are closed under reversal, intersection with regular languages, homomorphism inverse, etc.
-
CFLs are more flexible than DCFLs, being closed under union, concatenation, Kleene star/plus, reversal, homomorphism operations, and intersection with regular languages, but not under general intersection, set difference, or complementation.
-
CSLs enjoy strong closure properties, including all operations listed. They are closed under union, intersection, set difference, complementation, concatenation, Kleene operations, reversal, homomorphism, substitution, and quotient with regular languages.
-
REC languages are the most robust concerning closure. They are closed under all standard operations, including union, intersection, set difference, complementation, concatenation, Kleene operations, reversal, homomorphism, substitution, and quotient with regular languages.
-
RE languages are closed under many operations but lack closure under intersection, set difference, and complementation. They are, however, closed under union, concatenation, Kleene operations, reversal, homomorphism, substitution, and quotient with regular languages.
Understanding these closure properties is crucial when designing grammars, parsers, and automata for various computational problems, as well as in proving properties about different language classes.