Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.

Slides:



Advertisements
Similar presentations
Context-Free and Noncontext-Free Languages
Advertisements

The Pumping Lemma for CFL’s
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
CS 3240: Languages and Computation Properties of Context-Free Languages.
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
Transparency No. 2-1 Formal Language and Automata Theory Chapter 2 Deterministic Finite Automata (DFA) (include Lecture 3 and 4)
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
127 The Chomsky Hierarchy(review) Recursively Enumerable Sets Turing Machines Post System Markov Algorithms,  -recursive Functions Regular Expression.
Transparency No. P2C4-1 Formal Language and Automata Theory Part II Chapter 4 Parse Trees and Parsing.
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
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
Transparency No. 7-1 Formal Language and Automata Theory Chapter 7 Limitations of Finite Automata (lecture 11 and 12)
Normal forms for Context-Free Grammars
Transparency No. P2C1-1 Formal Language and Automata Theory Part II Pushdown Automata and Context-Free Languages.
Context Free Pumping Lemma Zeph Grunschlag. Agenda Context Free Pumping Motivation Theorem Proof Proving non-Context Freeness Examples on slides Examples.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.3: Non-Context-Free Languages) David Martin With.
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.
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.
1 Properties of Context-free Languages Reading: Chapter 7.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
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?
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
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.
Class Discussion Can you draw a DFA that accepts the language {a k b k | k = 0,1,2,…} over the alphabet  ={a,b}?
Context-Free and Noncontext-Free Languages Chapter 13 1.
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.
Chapter 6 Properties of Regular Languages. 2 Regular Sets and Languages  Claim(1). The family of languages accepted by FSAs consists of precisely the.
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.
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
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.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
C SC 473 Automata, Grammars & Languages Automata, Grammars and Languages Discourse 04 Context-Free Grammars and Pushdown Automata.
1 Alphabets: An Alphabet is a finite set of symbols. We will usually use  to denote the alphabet of input symbols or “terminal characters.” String: A.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Lecture 6: Context-Free Languages
 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.
Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein.
Context-Free and Noncontext-Free Languages Chapter 13.
Lecture 15 Pumping Lemma.
7. Properties of Context-Free Languages
Chapter Fourteen: The Context-Free Frontier
Definition: Let G = (V, T, P, S) be a CFL
7. Properties of Context-Free Languages
COSC 3340: Introduction to Theory of Computation
Properties of Context-Free Languages
The Pumping Lemma for CFL’s
Bottom-up parsing Pumping Theorem for CFLs
COSC 3340: Introduction to Theory of Computation
Pumping Theorem for CFLs
Presentation transcript:

Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages

Pumping lemma and closure properties of CFLs Transparency No. P2C5-2 The pumping Lemma for CFLs Issue: Is there any language not representable by CFGs ? Ans: yes! Ex: {a n b n c n | n > 0 }. But how to show it ? For regular languages: we use the pumping lemma that utilizes the “finite-state” property of finite automata to show the non-regularity of a language. For CFLs: can we have analogous result for CFLs ? ==> Yes! But this time uses the property of parse tree instead of the machine (i.e., PDAs ) recognizing them.

Pumping lemma and closure properties of CFLs Transparency No. P2C5-3 Minimum height of parse trees for an input string Definition: Given a (parse) tree T, h(T) = def the height of T, is defined to be the distance of the longest path from the root to its leaves. Ex: a single node tree has height 0, h(T 1 ) = m and h(T 2 ) = n ==> h( (root T 1 T 2 ) ) = max(m,n) +1. Lemma 5.1: G: a CFG in Chomsky Normal Form ; D = A -->* G  a derivation whose parse tree T D has height n, where A  N and    *. Then |  |  2 n-1. [i.e, height = n (or  n) => width ≤ 2 n-1. ] Note: since G is in cnf, every node of T D has at most two children, hence T D is a binary tree. Pf: By ind. on the height n.

Pumping lemma and closure properties of CFLs Transparency No. P2C5-4 Shallow trees cannot have many leaves Basis: n = 1 (not 0 since A   ) Then D : A --> G a (or S --> G  ). ==> h(T D ) = 1 and |a|  Inductive case: n = k + 1 > 1. Then  B, C, D 1, D 2 s.t. D : A --> G BC -->* G , D 1 : B -->* G  1, D 2 : C-->* G  2 s.t.  =  1  2, and T D = (A T D1 T D2 ) and max(h(T D1 ), h(T D2 )) = k. By ind. hyp., |  1 |  2 h(T D1 ) -1  2 k-1 and |  2 |  2 h(T D2 ) -1  2 k -1 Hence  = |  1 | + |  2 |  (2 k k -1 ) = 2 n-1. QED Lemma 5.2: G: a CFG in cnf; S -->* G w in  *: a derivation with parse tree T. If |w|  2 n ==> h(T)  n + 1. Pf: Assume h(T)  n ==> |w|  2 n-1 < 2 n --- by lemma 5.1 ==> a contradiction !! QED

Pumping lemma and closure properties of CFLs Transparency No. P2C5-5 The pumping lemma for CFLs Theorem: 5.3: L : a CFL. Then  k > 0 s.t. for all member z of L of length  k, there must exist a decomposition of z into uvwxy (i.e., z = uvwxy) s.t. (1). |vwx|  k, (2). |v| + |x| > 0 and (3). uv i wx i y  L for any i  0. Formal rephrase of Theorem 5.3: (L  CFL) =>  k>0  z  L ( |z|  k =>  u  v  w  x  y (( z = uvxyz) /\ (1) /\ (2) /\ (3)) )).

Pumping lemma and closure properties of CFLs Transparency No. P2C5-6 Contrapositive form of the pumping lamma Contrapositive form of Theorem 5.3: (Recall that ~q => ~ p is the contrapositive of p => q) Let Q = def  k>0  z  L ( |z|  k =>  u  v  w  x  y (( z = uvxyz) /\ (1) /\ (2) /\ (3)) )). Then ~ Q =  k>0  z  L ( |z|  k /\  u  v  w  x  y ( (z = uvxyz)/\(1)/\(2)) =>~(3)) )). =  k>0  z  L ( |z|  k /\  u  v  w  x  y ( (z = uvxyz)/\(1)/\(2)) =>  i  0 uv i wx i y  L )) =  k>0  z  L ( |z|  k /\  uvwxy=z ( (1)/\(2) =>  i  0 uv i wx i y  L) ). i.e., for all k > 0 there exists a member z of L with length  k s.t. for any decomposition of z into uvwxy s.t. (1) /\ (2) hold, then there must exist i  0 s.t. uv i wx i y  L. The contrapotive form of Theorem 5.3 : Given a language L, If ~Q then L is not context free.

Pumping lemma and closure properties of CFLs Transparency No. P2C5-7 Game-theoretical form of the pumping lamma: ~ Q:Game-theoretical argument: (to show ~Q true)  k>0 1. D picks any k > 0  z  L |z|  k /\2. Y pick a z  L with length  k  uvwxy=z (1)/\(2) =>3. D decompose z into uvwxy with |vwx|  k /\ |v| + |x| > 0  i (i  0 /\ uv i wx i y  L). 4. Y pick a number i  0 5. Y win iff (uv i wx i y  L or D fails to pick k or decompose z at step1&3) Notes: 0. If Y has a strategy according to which he always win the game, then ~Q is true, otherwise ~Q is false. 1. To show that “  x P” is true, it is Your responsibility to give a witness c s.t. P is indeed true for that individual c. if Your opponent, who always tries to win you, cannot show that P(c) is false then You wins. 2. On the contrary, to show that “  x P” is true, for any value c given by your opponent, who always tries to win you and hence would never give you value that is true for P provided he knows some value is false for P, You must show that P(c) is true.

Pumping lemma and closure properties of CFLs Transparency No. P2C5-8 The set of prime numbers is not context-free Ex5.1:PRIME = def {a k | k is a prime number } is not context-free. Pf: The following is a winning strategy for Y: 1. Suppose D picks k > 0 // for any k picked by D 2. Y picks z = a p where p is any prime number >k+2 (note p>3) ( obviously z  PRIME and |z|  k ). 3. Suppose D decompose z into a u a v a w a x a y with v + x > 0 /\ v + w + x  k 4. Y pick i = u + w + y // = p-(v+x) > k+2 –k =2 Now a u a vi a w a xi a y = a u+w+y a (v+x)i = a i a (v+x)i = a (v+x+1)i. Since i>2 and v+x+1  2, a (v+x+1)i  PRIME. ==> Y win. Since Y always win the game no matter what k is chosen and how z is decomposed at step 1&3, by the game-theoretical argument, PRIME is not context-free. QED

Pumping lemma and closure properties of CFLs Transparency No. P2C5-9 Additional example Ex 5.2: Let A = {a n b n c n | n > 0 } is not context-free. Pf: Consider the following strategy of Y in the game: 1. D picks k > 0 2. Y pick z = a k b k c k // obviously z  A and |z|  k 3. Suppose D decompose z into uvwxy with |vx| > 0 /\ |vwx|  k 4. Y pick i = 0 ==> who wins ? case1: vwx = a J (or b J or c J ) where J = |vwx| ==> in  = uv 0 wx 0 y, #a(  ) uv 0 wx 0 y  A The other two cases (b J or c J )are similar. case2: vwx = a I b J (or b I c J ) with I + J = |vwx|. ==> uv 0 wx 0 y decreases only occurrences of (a or b) or (b or c) but not c (or a) ==> uv 2 wx 2 y  A In all cases uv 2 wx 2 y  A So Y always win and A  CFL. QED

Pumping lemma and closure properties of CFLs Transparency No. P2C5-10 Proof of the pumping lemma pf: Let G = (N,S,P,S) be any CFG in cnf s.t. L= L(G). Suppose |N| = n and let k = 2 n. Now for any z  L(G) if |z|  k, by Lem 5.2,  a parse tree T for z with h(T) = m  n+1. Now let P = X 0 X 1 …. X m be any longest path from the root of T to a leaf of T. Hence 1. X 0 = S is the start symbol 2. X 0,X 1,…. X m-1 are nonterminal symbols and 3. X m is a terminal symbol. Since X 0 X 1 …. X m-1 has m > n nodes, by the pigeon-hole principle, there must exist i  j s.t. X i = X j Now let I < m-1 be the largest number s.t. X I+1,…. X m-1 consist of distinct symbols and X I = X J for some I<J< m. Let X I (and X J ) be the nonterminal A.

Pumping lemma and closure properties of CFLs Transparency No. P2C5-11 Proof of the pumping lemma (cont’d) Let T I be the subtree of T with root X I and T J the subtree of T with root X J Let yield(T J ) = w (hence X J  + G w or A  + G w --- (1) ) Since T J is a subtree of T I, X I  + G v X J x for some v,x in  *. hence A  + G vAx --- (2) Also note that since G is in cnf form it is impossible that v = x = . (o/w X I  + X I implies existence of unit rule or  -rule. Since T I is a subtree of T, S= X 0 -->* G u X I y = u A y for some u,y in  *. -->* G u v i A x i y ---- apply (2) i times -->* G u v i w x i y ---- apply (1). Hence u v i w x i y  L for any i  0. Also note that since X I …. X m is the longest path in subtree T I and has length  n+1, h(T I ) = length of its longest path  n+1. ==> (by lem 5.1) |vwx| = |yield(T I )|  2 h(T I ) -1 = 2 n = k. QED

Pumping lemma and closure properties of CFLs Transparency No. P2C5-12 S=X 0 X I =A X J =A X m-1 w u vxy T TITI TJTJ h(T I )  n+1 h(T)  n+1 XmXm |z| ≥ k = 2 n |uvw| ≤ k

Pumping lemma and closure properties of CFLs Transparency No. P2C5-13 Example: Ex5.3: B = {a i b j a i b j | i,j > 0 } is not context free. Pf: Assume B is context-free. Then by the pumping lemma:  k > 0 s.t.  z  B of length  k,  uvxyz = z s.t. |vwx|  k /\ |vx| > 0 /\ uv i wx i y  B for any i  0. Now for any given k > 0, let z = a k b k a k b k ---( ** step1,2 **). Let z = uvwxy be any decomposition with |vwx|  k /\ |vx| > 0. case1: vwx = a J (or b J ), 1  J  k ==> a J u v 2 wx 2 y  B --- (Step 3,4: i = 2) case2: vwx = a J b I (or b I a J ), 1  I + J  k, I > 0, J > 0 ==> For the string uv 2 wx 2 y,in all cases (1&2 &3, see next slide) only the first a k b k or the last a k b k or the middle b k a k of z = a k b k a k b k is increased ==> u v 2 wx 2 y  B This shows that the statement of pumping lemma is not true for B. Hence by the pumping lemma, B is not context free. QED

Pumping lemma and closure properties of CFLs Transparency No. P2C5-14 aa...aa bb...bb vwx (2) vwx (1) vwx (3)

Pumping lemma and closure properties of CFLs Transparency No. P2C5-15 Closure properties of CFLs Theorem 5.2: CFLs are closed under union, concatenation and Kleene’s star operation. Pf: Let L 1 = L(G 1 ), L 2 = L(G 2 ) : two CFLs generated by CFG G 1 and G 2, respectively, where G 1 = (N 1,  1, S 1, P 1 ) and G 2 = (N 2,  2, S 2, P 2 ). ==> Then 1. L 1 U L 2 = L(G’) where G’ =(N 1 UN 2,  1 U  2, S’, P’) has rules: P’ = P 1 U P 2 U {S’ --> S 1 ; S’ --> S 2 } 2. L 1 L 2 =L(G’’) where G’’ =(N 1 UN 2,  1 U  2, S’’, P’’) has rules: P’’ = P 1 U P 2 U {S’’ --> S 1 S 2 } 3. L 1 * = L(G’’’) where G’’’ =(N 1,  1, S’’’, P’’’) has rules: P’’’= P 1 U {S’’’ -->  | S 1 S’’’ }

Pumping lemma and closure properties of CFLs Transparency No. P2C5-16 Non-closure properties of CFLs are CFLs closed under complementation ? i.e., L is context free =>  * - L is context free ? Ans : No. The set L 1 = {a,b}* - {ww | w  {a,b}*} is context free but its complement {ww | w  {a,b}*} is known to be not Context- free. Exercise: Design a CFG for L 1. Hint: x  L 1 iff (1) |x| is odd or (2) x = yazybz’ or ybzyaz’ for some y,z,z’  {a,b}* with |z|=|z’|, which also means x = yay’ubu’ or yby’uau’ for some y,y’,u,u’  {a,b}* with |y|=|y’| and |u|=|u’|.

Pumping lemma and closure properties of CFLs Transparency No. P2C5-17 Non-closure properties of CFLs are CFLs closed under intersection ? i.e., L 1 and L 2 context free => L 1  L 2 is context free ? Ans : No. Ex: Let L 1 = {a i b + a i b + | i > 0} and L 2 = { a + b j a + b j | j > 0 }. L 1 and L 2 are two CFLs. But L 1  L 2 = B = { a i b j a i b j | i,j >0 } is not context free.

Pumping lemma and closure properties of CFLs Transparency No. P2C5-18 CFL Language is not closed under intersection. But how about CFL and RL ? Exercise: Let L be a CFL and R a Regular Language. Then L  R is context free. Hint: Let M 1 be a PDA accept L by final state and M 2 a FA accepting R, then the product machine M 1 XM 2 can be used to accept L  R by final state. The definition of the product PDA M 1 XM 2 is similar to that of the product of two FAs.