1 Introduction to Computability Theory Lecture9: The Pumping Lemma for Context Free Languages Prof. Amos Israeli
Feb 25, 2016
1
Introduction to Computability Theory
Lecture9: The Pumping Lemma for Context Free Languages
Prof. Amos Israeli
In this lecture we present the Pumping Lemma for Context Free Languages.
This lemma enables us to prove that some languages are not CFL and hence are not recognizable by any PDA.
Introduction and Motivation
2
Let A be a context free language. There exists a number p such that for every , if then w may be divided into five parts, satisfying:
1. for each , it holds that .2. .3. .Note: Without req. 2 the Theorem is trivial.
The Pumping Lemma
3
Awpw ||
uvxyzw
0i Azxyuv ii
0|| vy
pvxy ||
If w is “long enough” (to be precisely defined later) it has a large parse tree which has a “long enough” path from its root to one of its leaves.
Under these conditions, some variable on should appear twice. This enables pumping of w as demonstrated in the next slide:
Proof Idea
4
Proof Idea
5
R
R
zyxvu zyvu
R
R
R
R
yxv
2 i 0 iR
zu x
Pumping up Pumping down
Let T be a binary tree.
The 0 - th level of T has nodes.
The 1 - th level of T has at most nodes.
…
The i - th level of T has at most nodes.
If T’ is a b-ari tree then its i-th level has at most nodes.
122
Reminder
6
021
i2
ib
Let G be a grammar for the language L. Let b be the maximum number of symbols (variables and constants) in the right hand side of a rule of G. (Assume ). In any parse tree, T, for generating w from G, a node of T may have no more than b children.
If the height of T is h then .
The Proof
7
2b
hbw ||
If the height of T is h then . Conversely,
If then the height of T is at least .
Assume that G has variables. Then we set .
Conclusion: For any , if , then the
height of any parse tree of w is at least .
The Proof (cont.)
8
1|| Vbp
hbw ||hbw || 1h
||V
pw ||Lw
1|| V
To see how pumping works let be the parse tree of with a minimal number of nodes. The height of the tree , is at least , so it has a path, with at least nodes, from its root until some leaf. The path has at least variables and a single terminal.
The Proof (cont.)
9
1|| V
w
2|| V
1|| V
Since G has variables and has at least variables, there exists a variable, R ,that repeats itself among the lowest variables of , as depictedin the following picture:
The Proof (cont.)
10
||V1|| V
1|| V
R
R
zyxvu
Each occurrence of R has a sub-tree rooted at it:Let be the word generated by the upper occurrence of R and letx be the word generated by the lower occurrence of R .
The Proof (cont.)
11
R
R
zyxvu
vxy
Since both sub-trees are generated by the same variable, each of thesesub-trees can be replaced by another . This tree is obtained from by substituting the upper sub-tree at the lower occurrence of R.
The Proof (cont.)
12
zyvu
R
R
R
R
yxv
The word generated is , and since It is generated by a parse tree of Gwe get . Additionalsubstitutions of the upper sub-tree at the lower occurrence of , yield the conclusion for each
The Proof (cont.)
13
zyvu
R
R
R
R
yxv. 0i
R
zxyuv 22
Azxyuv ii
Azxyuv 22
Substitution of the lower sub-tree atthe upper occurrence of Ryields this pars tree whose generated word is .Since once again this is a legitimate parse tree weget .
The Proof (cont.)
14
Auxz
uxzzxyuv 00
R
zu x
To see that , assume that this isthe situation. In this case, thistree is a parse tree for w with less nodes then , incontradiction with the choice of as a parse treefor w with a minimal number of nodes.
The Proof (cont.)
15
R
zu x
0|| vy
In order to show that recall that we chose R so that both its occurrences fall within the bottom nodes of the path , where is the longest path of the tree so the height of the red sub-tree is at most and thenumber of its leaves is at most
The Proof (cont.)
16
1|| V
. 1|| pbV
R
R
zyxvu
pvxy ||
1|| V
Now we use the pumping lemma for CFL to show that the language is not CFL.
Assume towards a contradiction that L is CFL and let p be the pumping constant. Consider . Obviously .
Using the Pumping Lemma
17
0| ncbaL nnn
ppp cbaw Lw
By the pumping lemma, there exist a partition where , and for each , it holds that .
Case 1: Both v and y contain one symbol each:Together they may hold 2 symbols, so in , the third symbol appears less than the other two.
Using the Pumping Lemma
18
pvxy ||uvxyzw 0|| vy
i Lzxyuv ii
zxyuv 22
Case 2: Either v or y contain two symbols:In this case, the word has more than three blocks of identical letters: In other words: , Q.E.D.
Using the Pumping Lemma
19
zxyuv 22
cbazxyuv 22
quod erat demonstrandum (Wiktionary)which was to be proved; which was to be demonstrated. Abbreviation: QED
Some weeks ago we started our quest to find out “What can be computed and what cannot?”
So far we identified two classes: RL-s and CFL-s and found some examples which do not belong in neither class
Discussion
20
This is what we got so far:
CFL-s Ex: 0| nba nn
RL-s Ex: 0| nan
Discussion
21
Non CFL-s Ex: 0| ncba nnn
???
Moreover: Our most complex example, namely, the language is easily recognizable by your everyday computer, so we did not get so far yet.Our next attempt to grasp the essence of “What’s Computable?” are Turing Machines.
Some surprises are awaiting…
Discussion
22
0| ncbaL nnn
In this lecture we introduced and proved the Pumping Lemma for CFL-s
Using this lemma we managed to prove that the fairly simple language , is not CFL.
The next step is to define Turing Machines.
Recap
23
0| ncbaL nnn