 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:

Slides:



Advertisements
Similar presentations
Pumping Lemma Problem: Solution:
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.
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.
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.
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)
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.
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.
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.
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.
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.
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.
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.
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.
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.
Bottom-up parsing Pumping Theorem for CFLs MA/CSSE 474 Theory of Computation.
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.
Lecture5 Non-regular languages
Non-Context-Free Languages
Definition: Let G = (V, T, P, S) be a CFL
Context-Free Grammars
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
The Pumping Lemma for CFL’s
Applications of Regular Closure
Pumping Theorem for CFLs
The Pumping Lemma for CFL’s
Intro to Theory of Computation
Presentation transcript:

 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: A technique to show that specific given languages are not context free.

 2004 SDU 3 Statement of Pumping Lemma Pumping lemma for context-free languages: If A is a 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. uvxyzuvxyz uxzuxz uvvxyyz uvvvxyyyz uvvvvxyyyyz uvvvvvxyyyyyz

 2004 SDU 4 Proof of pumping lemma Idea: If a sufficiently long string s is derived by a CFG, then there is a repeated variable on a path in the parse tree. We can substitute the smaller sub-tree rooted at the lower occurrence for the larger sub-tree rooted at the higher occurrence to build infinitely many longer strings (and one shorter string, i = 0 case) derived by the CFG. Think: why not use PDA to prove? T R R uxvyz

The pumping lemma in work: example S  “R” is a regular expression R  0 | ( R )* “0” is a regular expression “(0)*” is a regular expression “((0)*)*” is a regular expression “(((0)*)*)*” is a regular expression … “((0)*)*” is a regular expression u = “( v = ( x = 0 y = )* z = )*” is a regular expression uv 0 xy 0 z: “(0)*” is a regular expression uv 1 xy 1 z: “((0)*)*” is a regular expression uv 2 xy 2 z: “(((0)*)*)*” is a regular expression uv 3 xy 3 z: “((((0)*)*)*)*” is a regular expression s R R R 0 “ is a regular expression ” ( ) * ( ) *

The pumping lemma in work: example S  “R” is a regular expression R  0 | ( R )* “((0)*)*” is a regular expression u = “( v = ( x = 0 y = )* z = )*” is a regular expression s R R R 0 “ is a regular expression ” ( ) * () * ( R ) * uv 2 xy 2 z

The pumping lemma in work: example S  “R” is a regular expression R  0 | ( R )* “((0)*)*” is a regular expression u = “( v = ( x = 0 y = )* z = )*” is a regular expression s R 0 “ is a regular expression ” ( ) * R uxz

 2004 SDU 8 Details of Proof of Pumping Lemma 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. //why? –Each node in a parse tree using this grammar can have no more than b children. –At most 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.

 2004 SDU 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 variables in G Set p = b |V|+1  Because b  2, so a parse tree for any string in A of length at least p requires height at least |V | + 1. Therefore, let s in A be of length at least p.

 2004 SDU 10 Details of Proof of Pumping Lemma (contd.) Choose a parse tree T of s with smallest number of nodes. The longest path of T must have length  |V| +1 Consider the lowest |V|+1 variables on this path. On this sub-path some variable R must repeat. T R R uxvyz We start with a smallest parse tree that derives s

 2004 SDU 11 Details of Proof of Pumping Lemma (contd.) Replace the sub-tree under the 2 nd occurrence of R with the sub-tree 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 to obtain longer stings in the language. T R R uR vy z xvy

 2004 SDU 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. For i=0, replace the sub-tree under the 1 st occurrence of R with the sub-tree under the 2 nd occurrence of R u z T R.... x

 2004 SDU 13 Details of Proof of Pumping Lemma (contd.) |vy|>0? T R R u xvyz R u x z T TT’ T’ has fewer nodes than T and also derives s

 2004 SDU 14 Details of Proof of Pumping Lemma (contd.) |vxy|  p? Note that the sub-tree rooted at first R has height at most |V|+1, so, the string vxy has length at most p = b |V|+1.

 2004 SDU 15 Application of pumping lemma A = {0 n 1 n 2 n | n  0} is not context free. Proof. Assume, on the contrary, that A is context free. By pumping lemma, there exists a constant p such that every w  A of length  p can be divided into w = uvxyz such that 1.|vxy|  p 2.|vy| > 0 3.For every i  0, uv i xy i z  A. Let w = 0 p 1 p 2 p. Since |vxy|  p, vxy is either in 0*1* or 1*2*. So, it is not the case that uv 2 xy 2 z has the same number of 0’s, 1’s as 2’s.

 2004 SDU 16 Application of pumping lemma B = {ww | w  {0,1}*}is not context free. Proof. Assume B is context free. Let p be the constant from the pumping lemma for B. Let w = 0 p 1 p 0 p 1 p, which is in B. Then w can be written as w = uvxyz such that 1.|vxy|  p 2.|vy| > 0 3.For every i  0, uv i xy i z  B. If v contains a symbol from the first 0 p, then y cannot contain one from the second 0 p, so pumping does not work. If v contains a symbol from the first 1 p, then y cannot contain one from the second 1 p, so, pumping lemma does not work. If v contains only symbols from the second 0 p 1 p, then pumping lemma does not work.

 2004 SDU 17 C={0 n 1 n 0 n 1 n | n  0} is not context free. The proof is similar to that of B. Does this contradict that Context free languages are closed under concatenation?  C 1 = {0 n 1 n | n  0}, C 2 = {0 n 1 n | n  0},  Is C = C 1  C 2 ? What happens if we change the stack to be first- in-first-out? Or use two first-in-last-out stacks?