Presentation is loading. Please wait.

Presentation is loading. Please wait.

Context Free Pumping Lemma Zeph Grunschlag. Agenda Context Free Pumping Motivation Theorem Proof Proving non-Context Freeness Examples on slides Examples.

Similar presentations


Presentation on theme: "Context Free Pumping Lemma Zeph Grunschlag. Agenda Context Free Pumping Motivation Theorem Proof Proving non-Context Freeness Examples on slides Examples."— Presentation transcript:

1 Context Free Pumping Lemma Zeph Grunschlag

2 Agenda Context Free Pumping Motivation Theorem Proof Proving non-Context Freeness Examples on slides Examples on blackboard

3 Pumping FA’s Strings of length 3 or more in DFA above can be pumped because such strings correspond to paths of length  3, so visit  4 vertices. Hence, pigeonhole principle guarantees some vertex visited twice, and hence a pumpable cycle. 0 1 0 0 1 1 xy z

4 Pumping PDA’s However, regular pumping lemma fails in this example. Q: Give an example of a pattern that cannot be pumped. r s   $ q  $     X  X  

5 Pumping PDA’s A: ( n ) n can’t be pumped in the first half. However, could pump two substrings at once. I.e. could take k left parens if take k right parens. I.e. can “tandem pump”. r s   $ q  $     X  X  

6 Tandem Pumping DEF: A string s in L is said to be tandem pumpable if can break s up into s = uvxyz such that for all i  0 we have that s = uv i xy i z  L with at least one of v,y nonempty. Q1: Is 00111 tandem pumpable in 0*111 ? Q2: Is 00100 tandem pumpable in {0 n 10 n } ? Q3: Is 00100100 tandem pumpable in {0 n 10 n 10 n } ?

7 Tandem Pumping A1: Yes. Any pumpable string is automatically tandem pumpable by letting y = . In our case, let u = , v = 00, x = y =  z = 111. uv i xy i z =(00) i 111 is indeed in 0*111. A2: Yes. Let u = , v = 00, x = 1, y = 11 and z =  uv i xy i z =(00) i 1(00) i is indeed in {0 n 10 n } A3: NO! Tandem pumping 00100100 leads either to too many 1’s, or would increase two of the 0-streaks, without ability to increase the remaining 0-streak.

8 Tandem Pumping In general, since pumping automatically implies tandem pumping, all (infinite) regular languages are tandem pumpable. Turns out, that all (infinite) context free languages are as well. But Q3 can be generalized to show that {0 n 10 n 10 n } does not admit tandem pumping of strings which are past a certain length. This will end up proving that {0 n 10 n 10 n } is not context free:

9 Context Free Pumping Lemma THM: Given a context free language L, there is a number p (tandem-pumping number) such that any string in L of length  p is tandem- pumpable within a substring of length p. In other words, for all s  L with |s|  p we we can write: s = uvxyz |vy |  1(some pumpable stuff non-empty) |vxy |  p (pumping inside length-p portion) uv i xy i z  L for all i  0 (tandem-pump v and y)

10 CFPL – Intuition Intuitively s = uvxyz is found as follows: Only finitely many stack changes possible at cycles in the graph of length  n (the number of states). Thus if s is long enough, there will have to be some states q,r such that the same string is pushed at q as is popped at r and such that the path from q to r starts and ends with same stack configuration. With these assumption, can then pump up v and y in tandem as v pushes same stuff that y pops off. q r -x  p s -v  -y  -z  -u  t k … t 2 t 1 s k … s 2 s 1

11 CFPL - Proof The previous can actually be formalized and used to prove the Context Free Pumping Lemma. However, this is actually quite painful compared to very simple grammar- theoretic proof: Proof of CFPL: We may assume that the language is in CNF. This is not an essential assumption but it makes the proof a little easier. Consider a derivation tree in which some occurring variable node has itself as an ancestor:

12 CFPL – Proof Could replace last appearance of A by its first appearance. I.e., in tree replace A  * “and a” by A  * “chuga and a choo” to get the following: chuga foryou S aA A andachoo

13 chuga foryou S aA choo chuga A A andachoo And again: CFPL – Proof

14 chuga foryou S aA choo chuga A choo chuga A A andachoo

15 Or could replace A  * “chuga and a choo” by A  * “and a” This is called tandem-pumping down: chuga foryou S aA A andachoo

16 CFPL – Proof foryou S aA anda

17 In our particular case, we were able to create any string of the form a (chuga) i and a (choo) i for you In general, any branch down the derivation tree with a repeated variable gives rise to strings of the form uv i xy i z all of which are in L. The end of the proof is just a counting argument to see when a repeated variable is guaranteed to occur.

18 CFPL – Proof Q: If n is the number of variables in the grammar, what tree-height guarantees that a variable is repeated? (Recall: the height of the trivial tree –just a root– is 0)

19 CFPL – Proof A: If n is the number of variables in the grammar, any subtree of height h = n+1 will have a repeated variable. This is because the bottom row of a derivation tree is composed of terminals, so height n+1 (= n+2 levels) guarantees n+1 levels of variables, at least on one branch from the root. Pigeonhole principle guarantees that some variable will be encountered twice!

20 CFPL – Proof Q: If the grammar is in CNF, what kind of tree is any derivation tree?

21 CFPL – Proof A: A binary tree! Q: What is the maximum number of leaves that a binary tree of height n may have?

22 CFPL – Proof A: 2 n Q: What the maximum number of leaves that a CNF derivation-tree of height n+1 may have?

23 CFPL – Proof A: Still 2 n ! This is because the only way to get a terminal is through rule of the form A  a so there is no branching at the final level. Q: What string length will guarantee a derivation tree of height  n+1 ?

24 CFPL – Proof A: 2 n. This is because no tree with height < n+1 could generated this many leaves, or terminal letters. This leads to setting the tandem-pumping number to be p=2 n. The rest of the theorem follows from the above considerations. Only fact that need to verify is that the pumping can happened within a substring of length p. This just follows from finding a repeating variable in the last n+2 levels of tree. 

25 Proving Non-Context Freeness Standard method for applying pumping lemma. Only no. 3 changes from example to example: 1. Suppose that the language is context free. 2. Then it would have a pumping no. p. 3. Find a string s which isn’t tandem-pumpable within a substring of length p. 4. 2 and 3 contradict, so 1 must have been false and the language is not context free.

26 Proving Non-Context Freeness Example 1 L ={ 1 n 0 n 1 n 0 n | n is non-negative }

27 Proving Non-Context Freeness Example 1 The hard part is number 3!!! Try s = 1 p 0 p 1 p 0 p There are three cases of where the “sliding window” vxy could be.

28 Proving Non-Context Freeness Example 1 Case I. Pumping up (or down) would change the number of 0’s and or 1’s in the first half of the string without affecting the second half. This would violate the language definition.

29 Proving Non-Context Freeness Example 1 Cases II and III. Same argument works as in Case I. (Case III would cause the second half to change without affecting the first half. Case II would cause the middle to change without the first 1 p nor the last changing.) This completes the pf. of no.3.

30 Proving Non-Context Freeness Example 2 ADD = { x=y+z | x, y, and z are bit- strings which satisfy the equation }

31 Proving Non-Context Freeness Example 2 The hard part is number 3! Define s by: 1 p+1 =1 p +10 p There are two cases of where the substring vxy could be. (Sliding p- window approach)

32 Proving Non-Context Freeness Example 2 Case I. v must occur to the left of “=” while y must occur to the right as otherwise, pumping would give too many =‘s, or would affect one side of the equation, and not the other. Let k be the length of v and l be the length of y. Pumping down results in supposed equation: 1 p+1-k =1 p-l +10 p. This is impossible because the RHS is then much greater than LHS.

33 Proving Non-Context Freeness Example 2 Case II. Pumping must occur to the right of “=”: The RHS is affected without affecting the LHS. This is impossible since we want the equation to hold in binary. This finishes the proof that ADD is not context free.

34 Blackboard Exercises {1 n | n is prime} {0 n 1 n 0 n 1 n } {int x; x = 3; | x is an alphabetic string} Therefore, claim that Java is context free is a lie. (If x = 3 occurred, must have declared x somewhere in past!) UNIX regex (not regexp): ( a*)b\1b\1 “ \n ” construct refers to n’ t h parenthesized sub-expression


Download ppt "Context Free Pumping Lemma Zeph Grunschlag. Agenda Context Free Pumping Motivation Theorem Proof Proving non-Context Freeness Examples on slides Examples."

Similar presentations


Ads by Google