CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.

Slides:



Advertisements
Similar presentations
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Advertisements

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.
CS21 Decidability and Tractability
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free.
Courtesy Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
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)
Normal forms for Context-Free Grammars
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
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.
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.
1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
1 Let L= { w= u v : u  {a, b}*, v  {c, d}* and |u|= |v|} 1.Design a context-free grammar that generates L. 2.Use your grammar and the construction from.
1 Properties of Context-Free Languages Is a certain language context-free? Is the family of CFLs closed under a certain operation?
TK PrasadPumping Lemma1 Nonregularity Proofs. TK PrasadPumping Lemma2 Grand Unification Regular Languages: Grand Unification (Parallel Simulation) (Rabin.
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.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
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.
CS355 - Theory of Computation Regular Expressions.
CS 203: Introduction to Formal Languages and Automata
Non-Context-Free Languages Section 2.3 CSC 4170 Theory of Computation.
Context-Free and Noncontext-Free Languages Chapter 13.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
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,
CS 154 Formal Languages and Computability February 4 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
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 February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability March 8 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.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability May 12 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability April 28 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
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.
CS 154 Formal Languages and Computability March 22 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
1 Use the pumping theorem for context-free languages to prove that L= { a n b a n b a p : n, p ≥ 0, p ≥ n } is not context-free. Hint: For the pumping.
Context-Free and Noncontext-Free Languages Chapter 13.
PROPERTIES OF REGULAR LANGUAGES
PDAs Accept Context-Free Languages
COSC 3340: Introduction to Theory of Computation
Deterministic PDAs - DPDAs
Closure Properties of Context-Free languages
Chapter 4 Properties of Regular Languages
COSC 3340: Introduction to Theory of Computation
Applications of Regular Closure
Intro to Theory of Computation
Presentation transcript:

CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Pumping Lemma for Context-Free Languages  Yes, there is one for context-free languages, too.  Like the one for regular languages, use the pumping lemma to prove that a language is not context-free.  Unfortunately, it’s even harder to use than the one for regular languages. 2

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Context-Free Pumping Lemma, cont’d  If L is an infinite context-free language, then there exists some positive integer m such that for any string w in L with |w| ≥ m We can decompose w = uvxyz with |vxy| ≤ m and |vy| ≥ 1 (i.e., vy is nonempty) such that uv i xy i z is also in L, with i = 0, 1, 2, …  In other words, strings in a context-free language can be pumped, and the pumped strings are also in the language. 3

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Context-Free Pumping Lemma, cont’d  S and A are variables in context-free grammar L.  Variable A can be repeated i times during the derivation of a sufficiently long string in L, i = 0, 1, 2, …, we pump substrings v and y. Example: 4 S A A uv x yz Note that |v| and |y| are not necessarily equal. S A A A uv x yzvy

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Context-Free Pumping Lemma, cont’d  Again, by using proof by contradiction, the pumping lemma for context-free languages enables us to prove that a given language is not context-free.  We only have to find one string that violates the pumping lemma. This can be harder to do than the regular language pumping lemma. We only have a bound on the length of substring vxy. We don’t know the length of the prefix substring u. 5

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Example Pumping Lemma Proof #1  Prove that is not context-free.  Choose the string w = a m b m a m b m which is in L.  The substring vxy can lie anywhere in w. Example:  In all cases, choose i = 0 to remove v and y.  The resulting string is not in L. 6 If L is a regular language, then for any w in L with |w| ≥ m, we can decompose w = uvxyz with |vxy| ≤ m and |vy| ≥ 1 such that uv i xy i z is also in L. b Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Example Pumping Lemma Proof #2  Prove that is not context-free.  Choose the string w = a m! which is in L.  Therefore, no matter what the decomposition is, v = a j and y = a k.  When i = 0, w 0 = uxz has length m! – (j + k).  But since j + k ≤ m m! – (j + k) ≥ m! – m = m[(m – 1)! – 1] > (m – 1)!  Therefore, m! – (j + k) is between (m – 1)! and m! and so w cannot be in L. 7 If L is a regular language, then for any w in L with |w| ≥ m, we can decompose w = uvxyz with |vxy| ≤ m and |vy| ≥ 1 such that uv i xy i z is also in L. In order for w 0 to be in L, its length m! – (j + k) must equal some factorial.

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Example Pumping Lemma Proof #3  Prove that, r is a substring of s, is a string symbol} is not context-free.  Choose string w = a m b m b m which is in L.  If either v or y then when i = 0, uxz would not and thus cannot be in L.  If both v and y are left of uv 2 xy 2 z cannot be in L because the left side would have a longer length and can’t be a substring of the right side. 8 If L is a regular language, then for any w in L with |w| ≥ m, we can decompose w = uvxyz with |vxy| ≤ m and |vy| ≥ 1 such that uv i xy i z is also in L.

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Example Pumping Lemma Proof #3, cont’d  If both v and y are right of uv 0 xy 0 z cannot be in L again because the left side would have a longer length and can’t be a substring of the right side.  If v and y straddle then v consists of b ’s and y consists of a ’s since |vwy| ≤ m. But then pumping would increase the number of b ’s to the left and increase the number of a ’s to the right and the resulting string cannot be in L. 9 If L is a regular language, then for any w in L with |w| ≥ m, we can decompose w = uvxyz with |vxy| ≤ m and |vy| ≥ 1 such that uv i xy i z is also in L.

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Assignment #5  Use the pumping lemma for context-free languages to prove that each of the following languages is not context-free. L 1 = {a n b 2n a n : n ≥ 0} L 2 = {a n : n is a perfect square} L 3 = {a n : n is prime}  Submit into Canvas: Assignment #5  Due Wednesday, March

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Context-Free Closure Properties  The family of context-free languages is closed under union, concatenation, and star-closure.  The family of context-free languages is not closed under intersection and complementation.  If L 1 is a context-free language and L 2 is a regular language, then is context-free. Closure under regular intersection. 11

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Regular Intersection Example  Show that is context-free.  Let which is context-free.  Let L 2 = {a 100 b 100 } which is finite and regular.  Then, is regular because regular languages are closed under complementation.  Then is context free by regular intersection. 12

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Context-Free Decidable Properties  There is an algorithm to decide whether or not a given string w can be derived from a context- free grammar G. Membership Is w in L(G) ?  There is an algorithm to decide whether or not L(G) is empty for a context-free grammar G.  There is an algorithm to decide whether or not L(G) is infinite for a context-free grammar G. 13

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Assignment #4: JavaCC for Super Calculator 14 TOKEN : { | | | > | | "> | ="> |

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Assignment #4, cont’d 15 | )+> | )+ "." ( )+> | )+ ( )? ( )+> | )+ "." ( )+ ( )? ( )+> | }

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Assignment #4, cont’d 16 double expression() throws NumberFormatException : { double v, value; } { value = simpleExpr() ( v = simpleExpr() { value = value == v ? 1 : 0; } | v = simpleExpr() { value = value != v ? 1 : 0; } | v = simpleExpr() { value = value < v ? 1 : 0; } | v = simpleExpr() { value = value <= v ? 1 : 0; } | v = simpleExpr() { value = value > v ? 1 : 0; } | v = simpleExpr() { value = value >= v ? 1 : 0; } )? { return value; } }

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Assignment #4, cont’d 17 double simpleExpr() throws NumberFormatException : { double v, value; } { value = term() ( v = term() { value += v; } | v = term() { value -= v; } | v = term() { value = (value != 0) || (v != 0) ? 1 : 0; } )* { return value; } } double term() throws NumberFormatException : { double v, value; } { value = power() ( v = power() { value *= v; } | v = power() { value /= v; } | v = power() { value = (value != 0) && (v != 0) ? 1 : 0; } )* { return value; } }

Computer Science Dept. Spring 2016: March 17 CS 154: Formal Languages and Computability © R. Mak Assignment #4, cont’d 18 double power() throws NumberFormatException : { double v, value; } { value = factor() ( v = factor() { value = Math.pow(value, v); } )* { return value; } } double factor() throws NumberFormatException : { double value; } { value = primary() { return value; } | value = factor() { return -value; } | value = factor() { return value != 0 ? 0 : 1; } | value = expression() { return value; } }