Upload
russell-harrington
View
230
Download
3
Embed Size (px)
Citation preview
Recall: Pumping Lemma for Regular Languages
q1
qk
qj
For every regular language L, there is a finite pumping length p, such that for any string sL and |s|p, we can write s=xyz with:
1) x yi z L for every i{0,1,2,…}2) |y| 13) |xy| p
Pumping Lemma for CFLTheorem: For every context-free language L, there is a pumping length p, such that for any string sL and |s|p, we can write s=uvxyz with
1) u vi x yi z L for every i{0,1,2,…}2) |vy| 13) |vxy| p
Note that 1) implies that uxz L (take i=0), requirement2) says that v,y cannot be the empty strings ε and condition 3) is useful in proving non-CFL.
Pumping a Parse Tree
A
A
u v x y zIf s = uvxyz L is long, then its parse-tree is tall.Hence, there is a path on which a variable A repeats itself. We can pump this A–A part.
S
Using Pumping Lemma“Proof by contradiction. Assume that L is context free.Let p be the pumping length of L and take sL.
By the pumping lemma it is possible to write s=uvxyz(with |vy| 1 and |vxy| p) such that uvixyiz L for all i0.
However…
Thus the pumping lemma does not hold for s. Contradiction. The language L is not context-free.”
Show that pumping up or down s gives strings that are not in L. Be careful to consider all v,x,y possibilities.
Here you have to be clever in picking the right s.
Example I: Pumping anbncn
Proof by contradiction; assume L = {anbncn | n0} is CF.According to the pumping lemma there is a pumping length p such that
for s = apbpcp L, we can write s = uvxyz = apbpcp, with uvixyiz L for all i0.
Two options for 1 |vxy| p:1) vxy = a*b*, then the string uv2xy2z has not enough letters c, hence
uv2xy2zL2) vxy = b*c*, then the string uv2xy2z has not enough letters a, hence
uv2xy2zL
Contradiction: the pumping lemma does not hold, hence L is not context free.
Example II: (Pumping down)
Prove that C = {aibjck | 0ijk } is not context-free.
Let p be the pumping length, and s = apbpcp C.Pumping lemma: s = uvxyz, such that uv ixyiz C
for every i0. Two options for 1 |vxy| p:1) vxy = a*b*, then the string uv2xy2z has not enough letters c,
hence uv2xy2zC2) vxy = b*c*, then the string uv0xy0z = uxz has too many letters a,
hence uv0xy0zC
Contradiction: The pumping lemma does not hold forthis string apbpcp, hence C is not context-free.
Example III: ww
Prove that the language D = { ww : w{0,1}* } is not CF.
You must be careful when picking the strings sD… Let p be the pumping length, take s=0p1p0p1p.
Options for s=uvxyz with 1 |vxy| p:
• If vxy is to the left of the middle of 0p1p 0p1p,then second half of uv2xy2z starts with a “1”.
• If vxy is to the right of the middle of 0p1p 0p1p, then first half of hence uv2xy2z ends with a “0”.
• If x is in the middle of 0p1p 0p1p, then pumped down uxz equals 0p1i 0j1p D (because i or j < p)
Additional Notes on CFL
Let A1 and A2 be two context-free languages,then the union A1 A2 is also context free.
However, the intersection A1 A2 is not necessarily context free
The complement Ā1= *–A1 are not necessarily context free either
Make a chain of everywhere a variable occurs
From each production send a link to a counter counting how many variables in the prod havenot yet been found to produce
When a variable is found to be generating decrementCounter accordingly
When counter reaches 0 the head variable is generating