CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.

Slides:



Advertisements
Similar presentations
Pumping Lemma Problem: Solution:
Advertisements

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
4.5 Inherently Ambiguous Context-free Language For some context-free languages, such as arithmetic expressions, may have many different CFG’s to generate.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
THE PUMPING LEMMA PROVING A LANGUAGE IS NOT REGULAR Dr. Cynthia Lee - UCSD - Spring 2011 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia.
CS 3240: Languages and Computation Properties of Context-Free Languages.
CS21 Decidability and Tractability
Turing machines Sipser 2.3 and 3.1 (pages )
Turing machines Sipser 2.3 and 3.1 (pages )
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
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.
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 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.
1 More Applications of the Pumping Lemma. 2 The Pumping Lemma: Given a infinite regular language there exists an integer for any string with length we.
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.
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.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
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?
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
Context-Free and Noncontext-Free Languages Chapter 13 1.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
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.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
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.
Non-Context-Free Languages Section 2.3 CSC 4170 Theory of Computation.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
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.
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.
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.
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 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.
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.
Context-Free and Noncontext-Free Languages Chapter 13.
Intro to Theory of Computation
COSC 3340: Introduction to Theory of Computation
COSC 3340: Introduction to Theory of Computation
Intro to Theory of Computation
Presentation transcript:

CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at Permissions beyond the scope of this license may be available at

CONTEXT-FREE LANGUAGES: CLOSURE PROPERTIES From last time

Closure properties: union Last class: CFL’s are closed under union. – If L1 and L2 are context-free languages, then L1 U L2 is a context-free language.

Closure properties: intersection How could you prove that CFL’s are closed under intersection? a)Pick two CFL’s L1 and L2, and construct a CFG for L1 ∩ L2 b)Show that for any two CFL’s L1 and L2, you can combine CFG’s to make a CFG for L1 ∩ L2 c)Show that any CFL L can be written as L1 ∩ L2 for two CFL’s L1, L2 d)Use the pumping lemma for CFL’s

Closure properties: intersection How could you prove that CFL’s are NOT closed under intersection? a)Show that there are CFL’s L1, L2 such that L1 ∩ L2 is not context-free b)Show that for any two CFL’s L1 and L2, the intersection L1 ∩ L2 is regular c)Show that there are CFL’s L1, L2 such that L1 ∩ L2 is context-free, but either L1 or L2 is not d)Use the pumping lemma for CFL’s

CONTEXT-FREE PUMPING LEMMA Proving that languages that are NOT context-free

Limits of Context-Free Languages What are the limitations of Context-Free languages What are the limitations of PDA? – Stack size has no limit (infinite stack) – ….BUT, there’s only one of them – Stack can only be accessed at the top What does that mean intuitively? When would you need more than one stack? Regular Context-Free Not Context-Free

PDA Language is 0 n 1 2n Can we change this so it is 0 n 1 2n 0 n ?

Classic Not-Context-Free Language a n b n c n for some n ≥ 0 INTUITIVELY, the problem is that a PDA recognizing this language would try to: – Push on the stack to count the ‘a’ section, then – Pop off the stack to match the ‘b’ section, then – You’ve “forgotten” n, now you can’t count the ‘c’ section Aside: what could you do with a second stack? THIS IS NOT A PROOF!! – Maybe there is a completely different way to approach this problem using PDA, which we just didn’t think of yet – But, turns out, there is no way to do this, and we can actually prove that

CFL Pumping Lemma: why it works

Proving {a j b k c l | 0 ≤ j ≤ k ≤ l} is not Context-Free s = a p b p c p i = ??? – Can’t solve it with just one i! – For the case analysis in this proof, we need to use i=0 for some cases, and i=2 for other cases – Is that legal??? Yes. The Pumping Lemma Game shows us why…

The REGULAR LANGUAGES Pumping Lemma Game Your Script “I’m giving you a language L that I’m assuming is regular.” “Excellent. I’m giving you this string s that I made using your p. It is in L and |s| ≥ p. I think you’ll really like it.” “Hm. I followed your directions for xyz, but when I [copy y N times or delete y], the new string is NOT is L! What happened?” Pumping Lemma’s Script “Thanks. For the language L that you’ve given me, I pick this nice pumping length I call p.” “Great string, thanks. I’ve cut s up into parts xyz for you. I won’t tell you what they are exactly, but I will say this: |y| > 0 and |xy| ≤ p. Also, you can remove y, or copy it as many times as you like (as in xy i z), and the new string will still be in L, I guarantee!” “Well, then L wasn’t a regular language. Thanks for playing.”

The CONTEXT-FREE LANGUAGES Pumping Lemma Game Your Script “I’m giving you a language L that I’m assuming is context-free.” “Excellent. I’m giving you this string s that I made using your p. It is in L and |s| ≥ p. I think you’ll really like it.” “Hm. I followed your directions for uvxyz, but when I [copy vy N times or delete vy], the new string is NOT is L! What happened?” Pumping Lemma’s Script “Thanks. For the language L that you’ve given me, I pick this nice pumping length I call p.” “Great string, thanks. I’ve cut s up into parts uvxyz for you. I won’t tell you what they are exactly, but I will say this: |vy| > 0 and |vxy| ≤ p. Also, you can remove v and y, or copy them as many times as you like (as in uv i xy i z), and the new string will still be in L, I guarantee!” “Well, then L wasn’t a context-free language. Thanks for playing.”

Case Analysis Let s = a p b p c p, and suppose s is split into uvxyz with |vy| > 0 and |vxy| ≤ p. Which of the following can describe vy? a)vy contains no symbols b)vy contains 1 type of symbol c)vy contains 2 types of symbols d)vy contains all 3 types of symbols e)None or more than 1 of the above e. b and c

Pumping Lemma Practice Thm. L = {a n b n c n | n ≥ 0} is not context-free. Proof (by contradiction): Assume (towards contradiction) that L is context-free. Then the pumping lemma applies to L. Let p be the pumping length. Choose s to be the string a p b p c p. The pumping lemma guarantees s can be divided into parts uvxyz s.t. for any i ≥ 0, uv i xy i z is in L, and that |vy|> 0 and |vxy| ≤ p. But if we let i = ____, we get the string XXXX, which is not in L, a contradiction. Therefore the assumption is false, and L is not context-free. Q.E.D. Which of the following choices for i will work? a)i = 0 b)i = 1 c)i = 2 d)None or more than 1 of the above d. a and c

So, are CFL’s closed under intersection? We just proved that {a n b n c n | n ≥ 0} is not a CFL. Are CFL’s closed under intersection? a)Yes b)No

Are CFL’s closed under complement? We just proved CFL’s are not closed under intersection, and we know they are closed under union. For two CFL’s L1, L2, it is possible to write their intersection as: L1 ∩ L2 = (L1’ U L2’)’ Are CFL’s closed under complement? a)Yes b)No

Pumping Lemma Practice Thm. L = {a j b k c l | 0 ≤ j ≤ k ≤ l } is not context-free. Proof (by contradiction): Assume (towards contradiction) that L is context-free. Then the pumping lemma applies to L. Let p be the pumping length. Choose s to be the string ______. The pumping lemma guarantees s can be divided into parts uvxyz s.t. for any i ≥ 0, uv i xy i z is in L, and that |vy|> 0 and |vxy| ≤ p. But if we let i = ____, we get the string XXXX, which is not in L, a contradiction. Therefore the assumption is false, and L is not context-free. Q.E.D. Will the same string (s = a p b p c p ) work for this proof? a)Yes b)No

Pumping Lemma Practice Thm. L = {a j b k c l | 0 ≤ j ≤ k ≤ l } is not context-free. Proof (by contradiction): Assume (towards contradiction) that L is context-free. Then the pumping lemma applies to L. Let p be the pumping length. Choose s to be the string a p b p c p. The pumping lemma guarantees s can be divided into parts uvxyz s.t. for any i ≥ 0, uv i xy i z is in L, and that |vy|> 0 and |vxy| ≤ p. But if we let i = ____, we get the string XXXX, which is not in L, a contradiction. Therefore the assumption is false, and L is not context-free. Q.E.D. Which value of i will work for this proof? a)i = 0c) i = 2 b)i = 1d) No value of i works in all cases d

Pumping Lemma Practice Thm. L = {a j b k c l | 0 ≤ j ≤ k ≤ l } is not context-free. Proof (by contradiction): Assume (towards contradiction) that L is context-free. Then the pumping lemma applies to L. Let p be the pumping length. Choose s to be the string a p b p c p. The pumping lemma guarantees s can be divided into parts uvxyz s.t. for any i ≥ 0, uv i xy i z is in L, and that |vy|> 0 and |vxy| ≤ p. But if we let i = ____, we get the string XXXX, which is not in L, a contradiction. Therefore the assumption is false, and L is not context-free. Q.E.D. Suppose vy consists of only a’s or only a’s and b’s. Which value of i will work for this proof? a)i = 0c) i = 2 b)i = 1d) a or c c. a doesn’t work b/c you can take the same amt of a’s and b’s out

Pumping Lemma Practice Thm. L = {a j b k c l | 0 ≤ j ≤ k ≤ l } is not context-free. Proof (by contradiction): Assume (towards contradiction) that L is context-free. Then the pumping lemma applies to L. Let p be the pumping length. Choose s to be the string a p b p c p. The pumping lemma guarantees s can be divided into parts uvxyz s.t. for any i ≥ 0, uv i xy i z is in L, and that |vy|> 0 and |vxy| ≤ p. But if we let i = ____, we get the string XXXX, which is not in L, a contradiction. Therefore the assumption is false, and L is not context-free. Q.E.D. Suppose vy consists of only c’s or only b’s and c’s. Which value of i will work for this proof? a)i = 0c) i = 2 b)i = 1d) a or c a

Pumping Lemma Practice Thm. L = {a j b k c l | 0 ≤ j ≤ k ≤ l } is not context-free. Proof (by contradiction): Assume (towards contradiction) that L is context-free. Then the pumping lemma applies to L. Let p be the pumping length. Choose s to be the string a p b p c p. The pumping lemma guarantees s can be divided into parts uvxyz s.t. for any i ≥ 0, uv i xy i z is in L, and that |vy|> 0 and |vxy| ≤ p. But if we let i = ____, we get the string XXXX, which is not in L, a contradiction. Therefore the assumption is false, and L is not context-free. Q.E.D. Suppose vy consists of only b’s. Which value of i will work for this proof? a)i = 0c) i = 2 b)i = 1d) a or c d