COMS W3261
Computer Science Theory
Lecture 15: October 28, 2009
Pumping Lemma and Closure Properties for CFL's
1. Outline
- Midterm 2 will be in class Wednesday, November 11, 2009.
It will be closed book and will cover context-free languages.
- Pumping lemma for CFL's
- Closure properties for CFL's
2. Review
- Eliminating useless symbols
- Eliminating ε-productions
- Eliminating unit productions
- Chomsky normal form
3. Pumping Lemma for CFL's
- For every nonfinite context-free language L,
there exists a constant n that depends on L such that
for all z in L with |z| ≥ n, we can write
z as uvwxy where
- vx ≠ ε,
- |vwx| ≤ n, and
- for all i ≥ 0, the string uviwxiy is in L.
- Proof: See HMU, pp. 281-282.
4. Applications of the Pumping Lemma
- One important use of the pumping lemma is to prove certain
languages are not context free.
- Example: The language L = { ss | s is a string of
a's and b's } is not context free.
- The proof will be by contradiction. Assume L is context free.
Then by the pumping lemma there is a constant n associated with L
such that for all z in L with |z| ≥ n,
z can be written as uvwxy
such that
- vx ≠ ε,
- |vwx| ≤ n, and
- for all i ≥ 0, the string
uviwxiy is in L.
- Consider the string z =
anbnanbn.
- Setting i = 0, condition (3) of the pumping lemma
says uwy must also be in L.
- But we can argue uwy cannot be in L, yielding a contradiction.
The details can be found in HMU, p. 285.
5. Closure Properties of CFL's
- The context-free languages are closed under
- substitution
- Let Σ be an alphabet and La a language
for each symbol a in Σ. These languages are
called a substitution s on Σ.
- If w =
a1a2 ... an
is a string in Σ*, then s(w) =
{ x1x2 ... xn |
xi is a string in
s(ai)
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
- reversal
- intersection with a regular set
- inverse homomorphism
6. Nonclosure Properties of CFL's
- The context-free languages are not closed under
- intersection
- L1 =
{ anbnci | n, i ≥ 0 }
and L2 =
{ aibncn | n, i ≥ 0 }
are CFL's. But
L = L1 ∩ L2 =
{ anbncn | n ≥ 0 }
is not a CFL.
- complement
- Suppose comp(L) is context free if L is context free.
Since L1 ∩ L2 =
comp(comp(L1) ∪ comp(L2)),
this would imply the CFL's are closed under intersection.
- difference
- Suppose L1 – L2 is a context free if
L1 and L2 are context free.
If L is a CFL over Σ, then comp(L) = Σ* - L
would be context free.
7. Practice Problems
- Show that { anbncn | n ≥ 0 }
is not context free.
- Show that { anbnci | i ≤ n }
is not context free.
- Show that { ssRs | s is a string
of a's and b's } is not context free.
- (Hard) Show that the complement of { ss | ss is a string
of a's and b's } is context free.
8. Reading Assignment
aho@cs.columbia.edu