7.1. Pumping Lemma for CFL¶
7.1.1. Which of these is a CFL?¶
Which of the following languages are CFL?L={anbncj∣0<n≤j}L={anbjanbj∣n>0,j>0}L={anbjakbp∣n+j≤k+p,n>0,j>0,k>0,p>0}L={anbjajbn∣n>0,j>0}
7.1.2. Pumping Lemma: Regular Languages¶
Let L be an infinite regular language.Then there exists a constant m>0 such that any w∈L with |w|≥m can be decomposed into three parts as w=xyz with:|xy|≤m|y|≥1xyiz∈L for all i≥0With this pumping lemma, we were able to show that anbn is not a regular language.
7.1.3. Pumping Lemma for CFLs: Intuition¶
Suppose a variable repeats, such as: A∗⇒vAy, with A∗⇒x.
The derived string will then contain the substring vxy. There will also be strings in the language that contain substrings x,vvxyy,vvvxyyy...
A little more complicated because there can be two “pumped” parts (in equal measure of pumped-ness).
Of course, the production is not required to have both v and y.
7.1.4. Pumping Lemma for CFLs¶
Let L be any infinite CFL.Then there exists a constant m (depending only on L), such that for every string w∈L, with |w|≥m, we may partition w=uvxyz such that:|vxy|≤m, (limit on size of substring)|vy|≥1, (v and y not both empty)for all i≥0,uvixyiz∈L
7.1.5. Proof Sketch (1)¶
7.1.6. Proof Sketch (2)¶
7.1.7. Proof Example Problem¶
Consider L={anbncn:n≥1}.
Why would we want to recognize the language {anbncn:n≥1}?
Recognize underlined words:
word_ is stored as wordββββ _ _ _ _ where β represents a backspace.
Unfortunately, L is not a CFL.
7.1.8. Proof (1)¶
Assume L is a CFL and apply the pumping lemma.Let m be the constant in the pumping lemma and consider w=ambmcm. Note |w|≥m.Show there is no division of w into uvxyz such that |vy|≥1, |vxy|≤m, and uvixyiz∈L for i=0,1,2,….Case 1: Neither v nor y may contain 2 or more distinct symbols. If, for example, v contains a’s and b’s, then uv2xy2z∉L since there will be b’s before a’s. Likewise for y.Thus, v and y each can be only a’s, b’s, or c’s (not mixed).
7.1.9. Proof (2)¶
Case 2: v=at1, then y=at2 or bt3 (since |vxy|≤m)If y=at2, then uv2xy2z=am+t1+t2bmcm∉L since t1+t2>0,n(a)>n(b) (number of a’s is greater than number of b’s)If y=bt3, then uv2xy2z=am+t1bm+t3cm∉L since t1+t3>0, either n(a)>n(c) or n(b)>n(c).Case 3: v=bt1, then y=bt2 or ct3.If y=bt2, then uv2xy2z=ambm+t1+t2cm∉L since t1+t2>0,n(b)>n(a).If y=ct3, then uv2xy2z=ambm+t1cm+t3∉L since t1+t3>0, either n(b)>n(a) or n(c)>n(a).
7.1.10. Proof (3)¶
Case 4: v=ct1, then y=ct2.Then, uv2xy2z=ambmcm+t1+t2∉L since t1+t2>0,n(c)>n(a).Thus, there is no breakdown of w into uvxyz such that |vy|≥1, |vxy|≤m and for all i≥0, uvixyiz is in L.This is a contradiction, thus, L is not a CFL.
7.1.11. Adversary Version (1)¶
Adversary picks some value for m.We pick the string w=ambmcm.Adversary picks the breakdown for w=uvxyz. Adversary has (bad) choices:vxy are all a’s, or all b’s, or all c’s.This cannot be pumped.vxy has either v or y a mix of lettersThis cannot be pumped.vy has between them an equal number of a’s, b’s, and c’s.This is too long.
7.1.12. Adversary Version (2)¶
Note that both v and y are pumped the same number of times.If the adversary could pick them with this in mind, then the string might be pumpable.For example, if v=ak and y=bkck.But the length restriction kicks in to prevent that(too many b’s between the a’s and c’s in w=ambmcm).
7.1.13. (Try to) Prove a CFL not a CFL¶
What if we try to prove that L=anbn is not context free, by using the pumping lemma?
Pick w=ambm.
Adversary picks v=ak and y=bk. (This is pumpable!)
Of course, this does not prove that L is context free. Just that we failed to disprove this with the pumping lemma (that is a good thing).
7.1.14. Example¶
Prove that L={ww∣w∈{a,b}∗} is not a CFL.
Consider the string w=ambmambm.
No matter how the adversary picks vxy, it is not pumpable.
7.1.15. Example¶
Prove that L{an!∣n≥0} is not a CFL.
We pick w=am!.Obviously, any decomposition is of the form v=ak, y=al.This is not pumpable.