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.

Slides:



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

Pumping Lemma Problem: Solution:
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union,
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 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
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 9: Automata Theory VII (Pumping Lemma, Non-CFL)
1 Module 31 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union, concatenation.
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.
CS 3240 – Chapter 8.  Is a n b n c n context-free? CS Properties of Context-Free Languages2.
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.
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.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
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?
Context-free Languages
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
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.
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.
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.
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.
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.
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.
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.
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.
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Definition: Let G = (V, T, P, S) be a CFL
فصل دوم Context-Free Languages
COSC 3340: Introduction to Theory of Computation
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
Applications of Regular Closure
Pumping Theorem for CFLs
Intro to Theory of Computation
Presentation transcript:

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 b’s are processed, the stack is empty. Not possible to count a’s with c’s. The problem of A  * vAy : If S  * uAz  * uvAyz  * uvxyz  L, then S  * uAz  * uvAyz  * …  * uv i Ay i z  * uv i xy i z  L as well, for all i=0,1,2,…

Pumping Lemma for CFLs Idea: If we can prove the existence of derivations for elements of the CFL L that use the step A  * vAy, then a new form of ‘v-y pumping’ holds: A  * vAy  * v 2 Ay 2  * v 3 Ay 3  * …) Observation: We can prove this existence if the parse- tree is tall enough.

Recall Parse Trees Parse tree for S  AbbcBa  * cbbccccaBca  cbbccccacca S b b ac A c c ca A c c c B B

Pumping a Parse Tree A A u vxy z If s = uvxyz  L is long, then its parse-tree is tall. Hence, there is a path on which a variable A repeats itself. We can pump this A–A part. S

A Tree Tall Enough Let L be a context-free language, and let G be its grammar with maximal b symbols on the right side of the rules: A  X 1 …X b A parse tree of depth h produces a string with maximum length of b h. Long strings implies tall trees. Let |V| be the number of variables of G. If h = |V|+2 or bigger, then there is a variable on a ‘top-down path’ that occurs more than once.

uvxyz  L A A u vxy z By repeating the A–A part we get… S

uv 2 xy 2 z  L A u v x y z R A A v x y … while removing the A–-A gives… S

uxz  L A uz In general uv i xy i z  L for all i=0,1,2,… S x

Pumping Lemma for CFL For every context-free language L, there is a pumping length p, such that for every string s  L and |s|  p, we can write s = uvxyz with 1) uv i xy i z  L for every i  {0,1,2,…} 2) |vy|  1 3) |vxy|  p Note that 1) implies that uxz  L 2) says that v and y cannot be both empty strings  Condition 3) is not always used. (It is not crucial part of pumping lemma, but helps to reduce the number of cases.)

Formal Proof of Pumping Lemma Let G=(V, ,R,S) be the grammar of a CFL. Maximum size of rules is b  2: A  X 1 …X b A string s requires a minimum tree-depth  log b |s|. If |s|  p=b |V|+2, then tree-depth  |V|+2, hence there is a path and variable A where A repeats itself: S  * uAz  * uvAyz  * uvxyz It follows that uv i xy i z  L for all i=0,1,2,… Furthermore: |vy|  1 because tree is minimal |vxy|  p because bottom tree with  p leaves has a ‘repeating path’

Pumping lemma for {a n b n c n | n >= 0} Assume that B = {a n b n c n | n  0} is CFL Let p be the pumping length, and s = a p b p c p  B P.L.: s = uvxyz = a p b p c p, with uv i xy i z  B for all i  0 Options for vxy: 1) The strings v and y are uniform (v=a…a and y=c…c, for example). Then uv 2 xy 2 z will not contain the same number of a’s, b’s and c’s, hence uv 2 xy 2 z  B 2) At least one of v or y is not uniform. (i.e., it has at least two different symbols occurring in it). Then uv 2 xy 2 z will not be a…ab…bc…c Hence uv 2 xy 2 z  B

Pumping lemma applied to {a n b n c n } continued Assume that B = {a n b n c n | n  0} is CFL Let p be the pumping length, and s = a p b p c p  B P.L.: s = uvxyz = a p b p c p, with uv i xy i z  B for all i  0 We showed: For every way of partitioning s into uvxyz, there is an i such that uv i xy i z is not in B. Contradiction. B is not a context-free language.

Another example Proof that C = {a i b j c k | 0  i  j  k } is not context-free. Let p be the pumping length, and s = a p b p c p  C P.L.: s = uvxyz, such that uv i xy i z  C for every i  0 vxy can’t have a’s and c’s. Why? So only two options for vxy: 1) vxy belongs to a*b*, then the string uv 2 xy 2 z has not enough c’s, hence uv 2 xy 2 z  C 2) vxy belongs to b*c*, then the string uv 0 xy 0 z = uxz has too many a’s, hence uv 0 xy 0 z  C Contradiction: C is not a context-free language.

D = { ww | w  {0,1}* } (Ex. 2.22) Carefully take the strings s  D. Let p be the pumping length, take s=0 p 1 p 0 p 1 p. Three options for s=uvxyz with 1  |vxy|  p: 1)If a part of y is to the left of | in 0 p 1 p |0 p 1 p, then second half of uv 2 xy 2 z starts with “1” 2) Same reasoning if a part of v is to the right of middle of 0 p 1 p |0 p 1 p, hence uv 2 xy 2 z  D 3) If x is in the middle of 0 p 1 p |0 p 1 p, then uxz equals 0 p 1 i 0 j 1 p  D (because i or j < p) Contradiction: D is not context-free.

Pumping lemma for CFG - remarks Using the CFL pumping lemma is more difficult than the pumping lemma for regular languages. You have to choose the string s carefully, and divide the options efficiently. Additional CFL properties would be helpful (like we had for regular languages). What about closure under standard operations?

Union 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 G 1 =(V 1, ,R 1,S 1 ) and G 2 =(V 2, ,R 2,S 2 ). Construct a third grammar G 3 =(V 3, ,R 3,S 3 ) by: V 3 = V 1  V 2  { S 3 } (new start variable) with R 3 = R 1  R 2  { S 3  S 1 | S 2 }. It follows that L(G 3 ) = L(G 1 )  L(G 2 ).

Intersection, Complement? Let again A 1 and A 2 be two CF languages. One can prove that, in general, the intersection A 1  A 2, and the complement Ā 1 =  * \ A 1 are not context free languages.

Intersection, Complement? Proof for complement: Recall that a problem in HW 5 shows that L = { x#y | x, y are in {a, b}*, x != y} IS context-free. Complement of this language is L’ = { w | w has no # symbol} U { w | w has two or more # symbols} U { w#w | w is in {a,b}* }. We can show that L’ is NOT context-free.

Context-free languages are NOT closed under intersection Proof by counterexample: Recall that in an earlier slide in this lecture, we showed that L = {a n b n c n | n >= 0} is NOT context-free. Let A = {a n b n c m | n, m >= 0} and B = L = {a n b m c m | n, m >= 0}. It is easy to see that both A and B are context-free. (Design CFG’s.) This shows that CFG’s are not closed under intersection.