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
CSCI 3130: Formal languages and automata theory Tutorial 5
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.
CS5371 Theory of Computation
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.
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.
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.
Context-Free Grammars Chapter 3. 2 Context-Free Grammars and Languages n Defn A context-free grammar is a quadruple (V, , P, S), where  V is.
Homework #7 Solutions. #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping.
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?
Context-Free and Noncontext-Free Languages Chapter 13 1.
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.
Context-Free and Noncontext-Free Languages Chapter 13 1.
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.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
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 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.
Context-Free Languages
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.
January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016.
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.
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.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Lecture 6: Context-Free Languages
CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
 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.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
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
Finite Automata and Formal 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
CS21 Decidability and Tractability
Chapter 2 Context-Free Language - 02
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 a language: we have a pumping lemma that utilizes the “finite-state” property of finite automata and can be used to show that a language is not regular. 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 with corresponding parse tree T D with height n, where A  N and    *. Then |  |  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 n.

Pumping lemma and closure properties of CFLs Transparency No. P2C5-4 Shallow trees cannot have many leaves Basis: n = 1 (not 0 why ?) Then D : A --> G a (or S --> G e). ==> h(T D ) = 1  Inductive case: n = k + 1 > 1. Then  B, C, D 1, D 2 s.t. D : A --> G BC -->* G w and D 1 : B -->* G w 1, D 2 : C-->* G w 2 s.t. w = w 1 w 2 and T D = (A T D1 T D2 ) and max(h(T D1 ), h(T D2 )) = k. By ind. hyp., |w 1 |  2 h(T D1 ) -1  2 k -1 and |w 2 |  2 h(T D2 ) -1  2 k -1 Hence w = |w 1 | + |w 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 ( k > 0 /\  z ((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 ( k > 0 /\  z ((z  L /\ |z|  k) =>  u  v  w  x  y (( z = uvxyz) /\ (1) /\ (2) /\ (3)) )). Then ~ Q =  k (k  0 \/  z ((z  L /\ |z|  k) /\  u  v  w  x  y ( (z = uvxyz)/\(1)/\(2)) =>~(3)) )). =  k (k > 0 =>  z ((z  L /\ |z|  k) /\  u  v  w  x  y ( (z = uvxyz)/\(1)/\(2)) =>  i (i  0 /\ uv i wx i y  L) )) =  k>0  z  L |z|  k /\  uvwxy=z (1)/\(2) =>  i (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 numer 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 values 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 > max (k,2) ( 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 > 0 if v+x > 1 and i = 0 if v+ x = 1. Now a u a vi a w a xi a y = a u + w + y a (v+x) i case1: (v+x) = 1 => a u a vi a w a xi a y = a u + w + y =a p-1  PRIME. case2: (v+x) > 1 => 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)(i+1) since (i+1) > 1, a (v+x)(i+1)  PRIME. ==> In both cases Y win. Since Y always win the game no matter what k and z are picked by Demo at step 1 & 3, by the game-theoretical argument of the pumping lemma, 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 = 2 ==> who wins ? case1: v (or x) contains distinct symbols (a&b or b&c) ==> uv 2 wx 2 y is not of the form:a*b*c* ==> uv 2 wx 2 y  A case2: v and x each consist of the same symbol. (i.e., each is of the form a* or b* or c* ). ==> uv 2 wx 2 y increase only a’s or b’s or c’s but not all ==> 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 = X J = 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) 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 XmXm w u vxy T TITI TJTJ h(T I )  n+1 h(T I )  n+1

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 ---( ** ). 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 case2: vwx = a J b I (or b I a J), 1  I + J  k, I > 0, J > 0 ==> in all cases (1&2 &3, see next slide) only either the first half or the last half or the middle of u v 2 wx 2 y is increased ==> u v 2 wx 2 y  B This shows that the statement (**) 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. ==> 1. L 1 U L 2 = L(G’) where G’ has rules: P’ = P 1 U P 2 U {S’ --> S 1 ; S’ --> S 2 } 2. L 1 L 2 =L(G’’) where G’’ has rules: P’’ = P 1 U P 2 U {S’’ --> S 1 S 2 } 3. L 1 * = L(G’’’) where G’’’ has rules: P’’’= P 1 U P 2 U {S’’’ -->  | S 1 S’’’ }