Lecture 15UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.

Slides:



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

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
CS 3240: Languages and Computation Properties of Context-Free Languages.
1 Introduction to Computability Theory Lecture7: The Pumping Lemma for Context Free Languages Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
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
1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings.
Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
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.
Lecture 7UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7.
CS 3240 – Chapter 8.  Is a n b n c n context-free? CS Properties of Context-Free Languages2.
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
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.
1 Applications of Regular Closure. 2 The intersection of a context-free language and a regular language is a context-free language context free regular.
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.
Lecture 10UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 10.
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.
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.
Non-Context-Free Languages Section 2.3 CSC 4170 Theory of Computation.
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.
CSCI 2670 Introduction to Theory of Computing September 23, 2004.
Costas Busch - LSU1 Pumping Lemma for 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.
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.
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.
Lecture 8UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 8.
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.
COSC 3340: Introduction to Theory of Computation
Chapter Fourteen: The Context-Free Frontier
COSC 3340: Introduction to Theory of Computation
Definition: Let G = (V, T, P, S) be a CFL
COSC 3340: Introduction to Theory of Computation
Pumping Lemma for Context-free Languages
Properties of Context-Free Languages
Bottom-up parsing Pumping Theorem for CFLs
COSC 3340: Introduction to Theory of Computation
CS21 Decidability and Tractability
Chapter 2 Context-Free Language - 02
CS21 Decidability and Tractability
COSC 3340: Introduction to Theory of Computation
Pumping Theorem for CFLs
COSC 3340: Introduction to Theory of Computation
Presentation transcript:

Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15

UofH - COSC Dr. Verma 2 Are all languages context-free? Ans: No. How do we know this? – Ans: Cardinality arguments. Let C(CFG) = {G | G is a CFG}. C(CFG) is a countable set. Why? Let AL = { L | L is a subset of  *}. AL is uncountable.

Lecture 15UofH - COSC Dr. Verma 3 Pumping Lemma First technique to show that specific given languages are not context-free. Cardinality arguments show existence of languages that are not context-free. There is a big difference between the two!

Lecture 15UofH - COSC Dr. Verma 4 Statement of Pumping Lemma If A is an infinite context-free language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divided into five pieces s = uvxyz satisfying the conditions. 1. For each i  0, uv i xy i z ε A, 2. |vy| > 0, and 3. |vxy| <= p.

Lecture 15UofH - COSC Dr. Verma 5 Statement of Pumping Lemma (contd.) When s is divided into uvxyz, cond. 2 says - either v or y is not the empty string. Otherwise the theorem would be trivially true. Cond. 3 say - the pieces v, x, and y together have length at most p. This condition is useful in proving that certain languages are not context free.

Lecture 15UofH - COSC Dr. Verma 6 Proof of pumping lemma Idea: If a sufficiently long string s is derived by a CFG, then there is a repeated nonterminal on a path in the parse tree. One such repeated nonterminal must have a nonempty yield “on the sides” – v, y. This nonterminal can be used to build infinitely many longer strings (and one shorter string, i = 0 case) derived by the CFG. Uses: Pigeon-hole principle

Lecture 15UofH - COSC Dr. Verma 7 Details of Proof of Pumping Lemma. Let A be a CFL and let G be a CFG that generates it. We must show how any sufficiently long string s in A can be pumped and remain in A. Let s be a very long string in A. Since s is in A, it is derivable from G and so has a parse tree. The parse tree for s must be very tall because s is very long.

Lecture 15UofH - COSC Dr. Verma 8 Details of Proof of Pumping Lemma (contd). How long does s have to be? – Let b be the maximum number of symbols in the right-hand side of a rule. – Assume b  2. A parse tree using this grammar can have no more than b children. At least b leaves are 1 step from the start variable; at most b 2 leaves are at most 2 steps from the start variable; at most b h leaves are at most h steps from the start variable.

Lecture 15UofH - COSC Dr. Verma 9 Details of Proof of Pumping Lemma (contd). – So, if the height of the parse tree is at most h, the length of the string generated is at most b h – Let |V | = number of nonterminals in G – Set p = b |V|+2 – Because b  2, we know that p > b |V|+1, so a parse tree for any string in A of length at least p requires height at least |V | + 2. Therefore, let s in A be of length at least p.

Lecture 15UofH - COSC Dr. Verma 10 Details of Proof of Pumping Lemma (contd). The parse tree must contain some long path from the start variable at the root of the tree to one of the terminal symbol at a leaf. On this long path some variable symbol R must repeat because of the pigeonhole principle. T R R uxvyz We start with a smallest parse tree with yield s

Lecture 15UofH - COSC Dr. Verma 11 Details of Proof of Pumping Lemma (contd). This repetition of R allows us to replace the subtree under the 2 nd occurrence of R with the subtree under the 1 st occurrence of R and still get a legal parse tree. Therefore we may cut s into 5 pieces uvxyz as the figure indicates and we may repeat the 2 nd and 4 th pieces and obtain a sting in the language. T R R uR vy z xvy

Lecture 15UofH - COSC Dr. Verma 12 Details of Proof of Pumping Lemma (contd). In other words, uv i xy i z is in A for any i  0. even if i = 0. T R.... uz x

Lecture 15UofH - COSC Dr. Verma 13 Some Applications of Pumping Lemma The following languages are not context-free. 1. {a n b n c n | n  0 }. 2. {a {n 2 } | n  0}. 3. {w in {a,b,c} * | w has equal a’s, b’s and c’s}.

Lecture 15UofH - COSC Dr. Verma 14 Example: CFL L = {a n b n c n | n  0 }. L is not context free. To show this, assume L is a CFL. L is infinite. Let w = a p b p c p, p is the pumping length a … a b … b c … c ppp |w| = 3p  p |vy|  0 |vxy|  p

Lecture 15UofH - COSC Dr. Verma 15 Example (contd.) Case 1: – Both v and y contain only one type of alphabet symbols, v does not contain both a’s and b’s or both b’s and c’s and the same holds for y. Two possibilities are shown below. – In this case the string uv 2 xy 2 z cannot contain equal number of a’s, b’s and c’s. Therefore, uv 2 xy 2 z  L a … a b … b c … c vy/vy

Lecture 15UofH - COSC Dr. Verma 16 Example (contd.) Case 2: – Either v or y contain more than one type of alphabet symbols. Two possibilities are shown below. – In this case the string uv 2 xy 2 z may contain equal number of the three alphabet symbols but won’t contain them in the correct order. – Therefore, uv 2 xy 2 z  L a…a … a b b b… b c … c vy/vy

Lecture 15UofH - COSC Dr. Verma 17 CFL’s not closed under intersection and complement Let Σ = {a,b,c}. L = {w over Σ | w has equal a’s and b’s}. L’ = {w over Σ | w has equal b’s and c’s}. L, L’ are CFLs. L intersect L’ = {w over Σ | w has equal a’s, b’s and c’s}, which is not a CFL. Because of closure under Union and DeMorgan’s law, CFLs are not closed under complement also. CFLs are closed under intersection with regular languages.

Lecture 15UofH - COSC Dr. Verma 18 Tips of the trade -- Do not forget! Closure properties can be used effectively for: (1)Shortening cumbersome Pumping lemma arguments. Example: {w in {a, b, c}* | w has equal a's, b's, and c's}. (2)For showing that certain languages are context-free. Example: {w in {a, b, c}* | w has equal a's and b's or equal b's and c's }.