1 91.304 Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.3: Non-Context-Free Languages) David Martin With.

Slides:



Advertisements
Similar presentations
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Advertisements

CS 3240: Languages and Computation Properties of Context-Free Languages.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture7: The Pumping Lemma for Context Free Languages Prof. Amos Israeli.
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
CS5371 Theory of Computation
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (more on Section 1.4) David Martin This work is licensed under.
1 Module 33 Non-context free languages –Intuition and Examples CFL Pumping Lemma –Comparison to regular language pumping lemma –What it means –Proof overview.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Foundations of (Theoretical) Computer Science Chapter 4 Lecture Notes (Section 4.1: Decidable Languages) David Martin With modifications.
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.1: DFA’s) David Martin With some modifications.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
Normal forms for Context-Free Grammars
Context Free Pumping Lemma Zeph Grunschlag. Agenda Context Free Pumping Motivation Theorem Proof Proving non-Context Freeness Examples on slides Examples.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
1 Background Information for the Pumping Lemma for Context-Free Languages Definition: Let G = (V, T, P, S) be a CFL. If every production in P is of the.
Prof. Busch - LSU1 Pumping Lemma for Context-free Languages.
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.4: Nonregular Languages) David Martin With some.
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.2: NFA’s) David Martin With some modifications.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
1 Properties of Context-Free Languages Is a certain language context-free? Is the family of CFLs closed under a certain operation?
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
Context-Free and Noncontext-Free Languages Chapter 13 1.
1 L= { w c w R : w  {a, b}* } is accepted by the PDA below. Use a construction like the one for intersection for regular languages to design a PDA that.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
Test # 2 Friday, November 2 nd Covers all of Chapter 2 Test # 2 will be 20% of final score (same as Test #1) Final Exam will be 40% of the final score.
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
Non-CF Languages The language L = { a n b n c n | n  0 } does not appear to be context-free. Informal: A PDA can compare #a’s with #b’s. But by the time.
Context Free Pumping Lemma. CFL Pumping Lemma A CFL pump consists of two non-overlapping substrings that can be pumped simultaneously while staying in.
Non-Context-Free Languages Section 2.3 CSC 4170 Theory of Computation.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Context-Free and Noncontext-Free Languages Chapter 13.
Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path.
Critique this PDA for L= { u u R v v R : u ∈ {0,1}* and v ∈ {0,1}+ } u0εu0 u1εu1 uεεvε v00vε v11vε vεεfε sεεtε t0εt0 t1εt1 t00tε t11tε tεεuε After you.
CSCI 2670 Introduction to Theory of Computing September 23, 2004.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
Lecture # 31 Theory Of Automata By Dr. MM Alam 1.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
 2004 SDU Lecture8 NON-Context-free languages.  2004 SDU 2 Are all languages context free? Ans: No. # of PDAs on  < # of languages on  Pumping lemma:
Bottom-up parsing Pumping Theorem for CFLs MA/CSSE 474 Theory of Computation.
CS 461 – Oct. 5 Pumping lemma #2 –Understanding –Use to show a language is not a CFL Next: Applications of CFLs –Expression grammars and Compiling.
Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
Context-Free and Noncontext-Free Languages Chapter 13.
CSE 105 theory of computation
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Definition: Let G = (V, T, P, S) be a CFL
COSC 3340: Introduction to Theory of Computation
Properties of Context-Free Languages
COSC 3340: Introduction to Theory of Computation
CS21 Decidability and Tractability
Chapter 2 Context-Free Language - 02
CS21 Decidability and Tractability
Pumping Theorem for CFLs
Intro to Theory of Computation
Presentation transcript:

Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.3: Non-Context-Free Languages) David Martin With some modifications by Prof. Karen Daniels, Fall 2009 This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

2 Picture so far ALL FIN Each point is a language in this Venn diagram REG RPP B = { 0 n 1 n | n ¸ 0 } { 0101,  } 0 * (101)* F = { a i b j c k | i1 or j=k } CFL Does this exist?

3 Strategy for finding a non-CFL  Just as we produced non-regular languages with the assistance of RPP, we'll produce non-context-free languages with the assistance of the context-free pumping property First we show that CFL µ CFPP And then show that a particular language L is not in CFPP Hence L can not be in CFL either

4 The Context-Free Pumping Property, CFPP Definition L is a member of CFPP if  There exists p ¸ 0 such that For every s 2 L satisfying |s| ¸ p,  There exist u,v,x,y,z 2  * such that 1.s=uvxyz 2.|vy|>0 3.|vxy| · p 4.For all i ¸ 0, u v i x y i z 2 L bold, red text shows differences from RPP

5 The non-CFPP Rephrasing L is not in CFPP if  For every p ¸ 0 There exists some s 2 L satisfying |s| ¸ p such that  For every u,v,x,y,z 2  * satisfying 1-3: 1.s=uvxyz, 2.|vy|>0, and 3.|vxy| · p  There exists some i ¸ 0 for which u v i x y i z L 2

6 Game theory formulation  The direct (non-contradiction) proof of non-context-freeness can be formulated as a two-player game You are the player who wants to establish that L is not CF-pumpable Your opponent wants to make it difficult for you to succeed Both of you have to play by the rules Same setup as with regular pumping (RPP)

7 Game theory continued The game has just four steps. 1.Your opponent picks p ¸ 0 2. You pick s 2 L such that |s| ¸ p 3.Your opponent chooses u,v,x,y,z 2  * such that s=uvxyz, |vy|>0, and |vxy| · p 4. You produce some i ¸ 0 such that uv i xy i z L 2

8 Game theory continued  If you are able to succeed through step 4, then you have won only one round of the game  To show that a language is not in CFPP you must show that you can always win, regardless of your opponent's legal moves Realize that the opponent is free to choose the most inconvenient or difficult p and u,v,x,y,z imaginable that are consistent with the rules

9 Game theory continued  So you have to present a strategy for always winning — and convincingly argue that it will always win So your choices in steps 2 & 4 have to depend on the opponent's choices in steps 1 & 3 And you don't know what the opponent will choose So your choices need to be framed in terms of the variables p, u, v, x, y, z

10 Towards proving CFL µ CFPP  To prove the claim that CFL µ CFPP we'll simplify things by using Chomsky Normal Form (CNF)  Recall: a CFG G=(V,,R,S 0 ) is in Chomsky Normal Form if each rule is of one of these forms: A ! BC, where A, B and C 2 V, and BS 0 and CS 0 (neither B nor C is the start symbol) A ! c, where A 2 V and c 2  S 0 ! , where S 0 is the grammar's start symbol (this is the only  production allowed)  Recall: Every context-free language L has a grammar G that is in Chomsky Normal Form

11 Towards proving CFL µ CFPP: Length constraints We will use some handy facts about CNF grammars. Definition. Suppose s is some string generated by a CNF grammar G. Then let minheight(s) be the height ( number of levels - 1 ) in the shortest parse tree for s in the grammar G. Example: minheight() ¸ 1 for every G

12 Towards proving CFL µ CFPP: Length constraints  Lemma Suppose G is in Chomsky Normal Form. Then 1.For all n ¸ 1, if minheight(s) · n then |s| · 2 n. In other words, constraining the height of a parse tree also constrains the length of the string. 1.Recall length of string = # terminals = # leaves of parse tree. 2.For all n ¸ 0, if |s|>2 n, then minheight(s)> n. In other words, large strings come from tall trees.  (The 2 in 2 x comes from the fact that each node in a parse tree for s has at most two children, because the grammar is in CNF.)

13 The Context-Free Pumping Property, CFPP (repeat) Definition L is a member of CFPP if  There exists p ¸ 0 such that For every s 2 L satisfying |s| ¸ p,  There exist u,v,x,y,z 2  * such that 1.s=uvxyz 2.|vy|>0 3.|vxy| · p 4.For all i ¸ 0, u v i x y i z 2 L

14 Theorem 2.19: CFL µ CFPP: Proof Idea Let: A be a CFL and G be a CFG generating A s be a “very” long string in A  s has a parse tree for its derivation Parse tree is “very” long and contains a “long” path. Pigeon-hole principle:  “Long” path contains repetition of some variable R.  Repetition of R allows substitution of first occurrence of R’s subtree where second occurrence of R’s subtree occurs. Result is a legal parse tree for language A. Due to substitution we can cut s into 5 pieces uvxyz.  Occurrences of v and y can be “pumped” to yield uv i xy i z.

15 Theorem 2.19: CFL µ CFPP: Proof Idea Source: Sipser textbook

16 Theorem 2.19: CFL µ CFPP Proof. Suppose L 2 CFL and let G=(V,,R,S 0 ) be any CNF grammar that generates it.  We set p=2 |V|+1.  Now suppose s 2 L where |s| ¸ p. We must show how to produce u,v,x,y,z etc.  Since |s| ¸ 2 |V|+1 > 2 |V|, we can apply the length fact to conclude that minheight(s)> |V|. But there are only |V| variables in the grammar. So looking at the parse tree for |s|, some variable R must be used more than once. For convenience later, pick R to be a variable that repeats on the bottom |V| +1 internal nodes (corresponding to variables) of that path of the tree.

17 CFL µ CFPP continued  We know that S 0 ) * s and that R appears within this derivation twice  So let u,v,x,y,z be strings satisfying uvxyz=s S 0 ) * uRz (first appearance) R ) * vRy (second appearance) R ) * x (then turning into x)  So S 0 ) * uRz ) * uvRyz ) * uvxyz = s (we knew that S 0 ) * s already)  But the grammar is context free, so we can apply any of the R substitutions at any point  Thus S 0 ) * uRz ) * uxz = u v 0 x y 0 z  And S 0 ) * uvRyz ) * uvvRyyz ) * uvvxyyz = uv 2 xy 2 z and so on. Hence, the pumping property holds.

18 CFL µ CFPP continued  We still have to see the length constraints |vy|>0 and |vxy| · p though.  Recall s = uvxyz.  Suppose that |vy|=0 (to get a contradiction). Then the parse tree has to include S 0 ) * uRz ) ¸ 1 uRz ) * uxz ( z ) ( ¸ 1 meaning "at least one substitution") This is because we know that R is actually repeated in the tree.  But CNF rules always add to the string. The only exception is the optional rule S 0 ! , but we've already assumed that |s| is long, so it isn't . Thus line ( z ) above can't be true, and hence |vy|=0 is impossible.

19 CFL µ CFPP continued  We still have to see the length constraint |vxy| · p.  We know that R repeats somewhere within the bottom |V|+1 internal nodes (representing variables) of the tree while producing the vxy part of s. Let h be the actual height of this subtree. Then minheight(vxy) · h · |V|+1 (length of longest branch) ) |vxy| · 2 |V|+1 = p (by lemma (1.0 on slide 12).  Q.E.D.

20 Game theory (repeat) The game has just four steps. 1.Your opponent picks p ¸ 0 2. You pick s 2 L such that |s| ¸ p 3.Your opponent chooses u,v,x,y,z 2  * such that s=uvxyz, |vy|>0, and |vxy| · p 4. You produce some i ¸ 0 such that uv i xy i z L 2

21 Example 2.36  L = {a n b n c n | n ¸ 0} is not a CFL  To see this: let opponent choose p, then we set s = a p b p c p. Clearly |s|>p and s 2 L.  So opponent breaks it up into u,v,x,y,z subject to the length constraints |vy|>0 and |vxy| · p.  We need to show that some i exists for which uv i xy i z is not in L. Note: the first character of v must be no more than p chars away from the last character of y, because |vxy| · p. So in the string uv 0 xy 0 z, we have removed at least one char and at most p chars — but we have removed at most 2 types of characters: that is, some "a"s & "b"s, or some "b"s & "c"s. It's impossible to remove 3 types ("a"s & "b"s & "c"s) this way. So the resulting string isn't in L. i=0 is our exponent.

22 Closure properties of CFL  Reminder: closure properties can help us measure whether a computation model is reasonable or not  CFL is closed under Union, concatenation  Thus, exponentiation and *  CFL is not closed under Intersection Complement  Weak intersection: If A 2 CFL and R 2 REG, then A Å R 2 CFL