Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein.

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
1 Introduction to Computability Theory Lecture7: The Pumping Lemma for Context Free Languages Prof. Amos Israeli.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
CS5371 Theory of Computation
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
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.
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.
CS 3240 – Chapter 8.  Is a n b n c n context-free? CS Properties of Context-Free Languages2.
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 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
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.
Tutorial CSC3130 : Formal Languages and Automata Theory Haifeng Wan ( )
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.
Pushdown Automata (PDAs)
1 Properties of Context-Free Languages Is a certain language context-free? Is the family of CFLs closed under a certain operation?
Context-free Languages
Complexity and Computability Theory I Lecture #9 Instructor: Rina Zviel-Girshin Lea Epstein.
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.
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.
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.
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein.
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.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
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.
Context-Free and Noncontext-Free Languages Chapter 13.
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,
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.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Context-Free and Noncontext-Free Languages Chapter 13.
Complexity and Computability Theory I
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Definition: Let G = (V, T, P, S) be a CFL
Context-Free Grammars
فصل دوم Context-Free Languages
COSC 3340: Introduction to Theory of Computation
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
Pumping Theorem for CFLs
Intro to Theory of Computation
Presentation transcript:

Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Overview Push-down automata - examples The pumping lemma for CFL Examples Interesting facts

Rina L = {a i b j | j>i  0} Construct a PDA to recognize: L = {a i b j | j>i  0} We will use the final states model. The basic idea: write each a to the stack for each b pop from the stack and check that the number of b’s greater than the number of a’s

Rina L = {a i b j | j>i  0}

Rina L = {a i b j | j>i  0} Construct a PDA to recognize: L = {a i b j | j>i  0} We will use the empty stack model. The basic idea: write each a to the stack for each b, pop from the stack until reaching Z and then for each b give two possibilities – to pop Z and stop – or to do nothing

Rina Example

Rina L = {a i b i c j d j |i,j  0} Construct a PDA to recognize: L = {a i b i c j d j |i,j  0} We will use the empty stack model. The basic idea: write each a to the stack and for each b pop write each c to the stack and for each d pop

Rina L = {a i b i c j d j |i,j  0}

Rina Context-Free Languages Languages decided by PDA called –context-free languages. Not all languages are context-free.

Rina Non-Context-Free Languages Consider L={a i b i c i |i  0}. We try to build a push-down automata that recognizes (decides) it. If we manage to build a PDA for L then the language is context-free. We cannot build a push-down automaton that recognizes L.

Rina L={a i b i c i |i  0} WHY? We can compare a number of a-'s with b-'s or c-'s but not both. If we compared the number of a-'s to the number of b-'s then we can't compare c-'s with any of them. Stack (or counter) is empty.

Rina Non-Context-Free Languages So some languages are not CFL. The question is which? We will answer this question later – pumping lemma for context-free languages.

Rina Recursive grammar Back to grammars. Grammar is recursive if it has: - direct recursion (A  wAu) or - indirect recursion (A  wBu,B  zA)

Rina Direct recursion The following rule is called a direct recursion rule: A  wAu where –w,u  (VU  )* and –A derives A in one step and –either w or u is not empty Why? – Unite rule.

Rina Indirect recursion A grammar having the following rules is called an indirect recursion grammar: A  wBu B  zA where –w,u,z  (VU  )* –either w or u is not empty –z is not empty –A derives A in two steps

Rina Recursive grammar Grammar is recursive if it has direct or indirect recursion. Example: S  aS | b S  aA A  cS

Rina Infinite Language If a context-free language (CFL) has an infinite number of words then its grammar is recursive one. This means that there must be at least one production rule that is recursive (directly or indirectly). Recursive rules are used to generate strings of arbitrary length. (infinite)

Rina Formal proof Proof by contradiction: We assume that L(G) is infinite and G is a grammar with no recursive rules. Let n be a number of rules in G. The longest string in G can be parsed in at most n steps - (no recursion means there is no reuse of the same production rule, so after using n rules all rules are used). n 1

Rina Formal proof (cont) Each step should be a different rule. Now we can “play” with sequences of rules. We have n! different sequences. That means – number of strings produced by non recursive grammar is bounded by n!. The language L(G) is finite. Contradiction to the assumption L(G) is infinite. n 1

Rina Infinite Language Example S  uAz A  vAy | x where either v or y is not empty. If we do not use the recursive rule we derived a language that consist of only one string - uxz. If we use the recursive rule than the grammar allows us to derive infinitely many strings having the same construction (pattern).

Rina Example (cont.) For example w = uv 2 xy 2 z can be derived as follows: S  uAz  uvAyz  uvvAyyz  uvvxyyz The same pattern can be used to derive all words of the form w = uv k xy k z for all k  0.

Rina Pumping length That means that every CFL has a special value called the pumping length such that all strings longer than the pumping length can be "pumped". The string can be divided into 5 parts w=uvxyz. The second and fourth can be pumped. w = uv k xy k z for all k  0

Rina Pumping Lemma for CFL Let L be an infinite context-free language. There is a positive integer p (the pumping length) such that for all strings w  L with |w|  p, w can be divided into five pieces w=uvxyz satisfying the following conditions: 1. |vy|>0 2. |vxy|  p 3. for each i  0, uv i xy i z  L

Rina Proof - value of p Let G be a CFG for CFL L. First we find out the value of p. Let n be the maximum number of symbols in the right side of some rule in G. So we know that in any parse tree of G a node can't have more than n children. So if the height of the tree is h then the length of the string its generate is at most n h.

Rina Proof - value of p Let |V| be the number of variables in G. We set p to be n |V|+2. p= n |V|+2 Because n  2 (no unite rules) then for any string of length p the parse tree requires height at least |V|+2. Lets call this string w: |w|  p.

Rina Proof Since G has only |V| variables that means that at least one of the production rules have to be repeated (height |V|+2). Lets call this variable R. For convenience later, we select R to be a variable that repeats among the lowest |V|+1 variables.

Rina Proof We divide w into uvxyz accordingly to the parse tree. Each occurrence of R has a subtree under it.

Rina Proof The upper occurrence of R has a larger subtree and generates vxy. The lower occurrence of R has a smaller subtree and generates only x. Both subtrees are generated by the same variable R. That means if we substitute one for the other we will still obtain valid parse trees.

Rina Replacing the smaller by the larger repeatedly generates the string uv i xy i z at each i>0. Replacing the larger by the smaller generates the string uxz or uv i xy i z where i=0. That establishes condition 3 of lemma.

Rina Proof To prove condition 1 (|vy|>0) we must be sure that both v and y are not . We use a grammar without union rules. So if v and y are both  we have a rule R  R – unite rule. Contradiction. So condition 1 is satisfied.

Rina Proof To prove condition 2 (|vxy|  p) we will check the height of the subtree rooted in first R - subtree that generates vxy. It’s height is at most |V|+2. So it can generate a string of length at most n |V|+2. But p= n |V|+2. Condition 2 is satisfied. Q.E.D

Rina Usage of lemma We use pumping lemma to prove that a language is not context-free. To prove that language L is context-free you have: – to build a CFG for L or – to build PDA that recognizes the words of L.

Rina L={a i b i c i |i  0} We will use the pumping lemma to prove that L={a i b i c i |i  0} is not CFL. Proof: We assume that L is CFL and obtain a contradiction. Let p be the pumping length for L. We select a string w= a p b p c p. w  L and |w|>p, so it can be pumped.

Rina L={a i b i c i |i  0} Lets divide w into five parts uvxyz such that |vy|>0 and |vxy|  p. We have two cases: 1. v and y contain only one type of alphabet symbol. So if we choose i=2 then we have uv 2 xy 2 z and it cannot contain the same number of a's, b's and c's. So w  L.

Rina L={a i b i c i |i  0} 2. v and y contain only two type of alphabet symbol. (Can't have three because condition 2 holds). So if we choose i=2 then we have uv 2 xy 2 z and it cannot contain the same number of a's, b's and c's, because we pumped only two alphabet symbols. So w  L.

Rina L={a i b i c i |i  0} One of these cases must occur. In both cases we have a contradiction to lemma. So the assumption that L is CFL must be false. L={a i b i c i |i  0} is not CFL.

Rina Intersection CFL are not closed under intersection. Example: L1={a n b n c k |n,k>0} L2={a k b n c n | n,k>0} Both L1 and L2 are CFL L1  L2 = {a j b j c j | j>0} -not CFL

Rina Complement CFL are not closed under complement. Proof by contradiction: Lets take two CFL L1 and L2 and assume that L1' and L2‘ are CFL. By union of L1' and L2' we obtain another CFL. (Since CFL closed under union operation).

Rina Complement If we take the compliment of this union we again obtain CFL. (L1'  L2')'=L1  L2 - is CFL. But we know that {a n b n c k |n,k>0}  {a k b n cn | n,k>0} = {a n b n c n | n>0} -not CFL

Rina Any Questions?