Lecture 11: Properties of CFL's

- The context-free languages are closed under the following operations:
- substitution
- Let Σ be an alphabet and let
*L*_{a}be a language for each symbol*a*in Σ. These languages define a substitution*s*on Σ. - If
*w*=*a*_{1}*a*_{2}...*a*_{n}is a string in Σ*, then*s*(*w*) = {*x*_{1}*x*_{2}...*x*_{n}|*x*_{i}is a string in*s*(*a*_{i}) for 1 ≤*i*≤*n*}. - If
*L*is a language,*s*(*L*) = {*s*(*w*) |*w*is in*L*}. - If
*L*is a CFL over Σ and*s*(*a*) is a CFL for each*a*in Σ, then*s*(*L*) is a CFL. - union
- concatenation
- Kleene star
- homomorphism
- reversal
- intersection with a regular set
- inverse homomorphism

- The context-free languages are not closed under the following operations:
- intersection
*L*_{1}= {*a*|^{n}b^{n}c^{i}*n, i*≥ 0 } and L_{2}= {*a*|^{i}b^{n}c^{n}*n, i*≥ 0 } are CFL's. But*L*=*L*_{1}∩*L*_{2}= {*a*|^{n}b^{n}c^{n}*n*≥ 0 } is not a CFL.- complement
- Suppose comp(
*L*) is context free if*L*is context free. Since*L*_{1}∩*L*_{2}= comp(comp(*L*_{1}) ∪ comp(*L*_{2})), this would imply the CFL's are closed under intersection. - difference
- Suppose
*L*_{1}–*L*_{2}is a context free if*L*_{1}and*L*_{2}are context free. If*L*is a CFL over Σ, then comp(*L*) = Σ* -*L*would be context free.

- Problem: Given a CFG
*G*, is L(*G*) empty? - Emptiness problem is decidable: determine whether the
start symbol of
*G*is generating. - Naive algorithm has O(
*n*^{2}) time complexity where*n*is the size of*G*(sum of the lengths of the productions). - With a more sophisticated list-processing algorithm, emptiness problem can be solved in linear time. See HMU, p. 302.

- We say a problem that cannot be solved by any Turing machine is
*undecidable*. There is no algorithm that can solve an undecidable problem. - We shall see that several fundamental questions about context-free grammars and languages are undecidable, such as:
- Is a given CFG ambiguous?
- Given a CFG, is there another equivalent CFG that is unambiguous?
- Do two given CFG's generate the same language?
- Is the intersection of the languages generated by two CFG's empty?
- Given a CFG
*G*= (*V*,*T*,*P*,*S*), is L(*G*) =*T**?

- Prove the CFL's are closed under the operations in Section 1 above.
- Let min(
*L*) = {*w*|*w*is in*L*but no proper prefix of*w*is in*L*}. Are the CFL's closed under the min operation? - Let max(
*L*) = {*w*|*w*is in*L*but for no string*x*other than ε is*wx*is in*L*}. Are the CFL's closed under the max operation? - Let init(
*L*) = {*w*|*wx*is in*L*for some string*x*(possibly the empty string) }. Are the CFL's closed under the init operation? - Let cycle(
*L*) = {*w*| we can write*w*as*xy*where*yx*is in*L*}. Are the CFL's closed under the cycle operation? - Let half(L) = {
*w*| there exists a string*x*such that |*w*| = |*x*| and*wx*is in*L*}. Are the CFL's closed under the half operation? - Let
*L*= {*a*|^{n}b^{n}c^{n}*n*≥ 1 }. Show that the complement of*L*is context free. - Let
*L*= {*ww*|*w*is a strings of*a*'s and*b*'s }. Show that the complement of*L*is context free.

- HMU: Ch. 7

aho@cs.columbia.edu verma@cs.columbia.edu