1 Module 33 Non-context free languages –Intuition and Examples CFL Pumping Lemma –Comparison to regular language pumping lemma –What it means –Proof overview.

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

CSCI 3130: Formal languages and automata theory Tutorial 5
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.
1 Pumping Lemma –A technique for proving a language L is NOT regular –What does the Pumping Lemma mean? –Proof of Pumping Lemma.
CS 3240: Languages and Computation Properties of Context-Free Languages.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Mount Holyoke College 2 Nonregular languages? We now know: –Regular languages may be specified either.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Fall Nonregular languages? We now know: –Regular languages may be specified either by regular.
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
CS5371 Theory of Computation
CS 310 – Fall 2006 Pacific University CS310 Pumping Lemma Sections:1.4 page 77 September 27, 2006.
127 The Chomsky Hierarchy(review) Recursively Enumerable Sets Turing Machines Post System Markov Algorithms,  -recursive Functions Regular Expression.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
Courtesy Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
The Pumping Lemma for CFL’s
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
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.
1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.
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.
Normal forms for Context-Free Grammars
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.
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.
1 Computer Language Theory Chapter 2: Context-Free Languages.
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 Homework #7 (Models of Computation, Spring, 2001) Due: Section 1; April 16 (Monday) Section 2; April 17 (Tuesday) 2. Covert the following context-free.
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.
TK PrasadPumping Lemma1 Nonregularity Proofs. TK PrasadPumping Lemma2 Grand Unification Regular Languages: Grand Unification (Parallel Simulation) (Rabin.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
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.
Context Free Pumping Lemma. CFL Pumping Lemma A CFL pump consists of two non-overlapping substrings that can be pumped simultaneously while staying in.
CS 203: Introduction to Formal Languages and Automata
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.
1 Applications of pumping lemma(Dr. Torng) Applications of Pumping Lemma –General proof template What is the same in every proof What changes in every.
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.
Lecture # 31 Theory Of Automata By Dr. MM Alam 1.
Cs466(Prasad)L11PLEG1 Examples Applying Pumping Lemma.
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:
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.
Lecture 15 Pumping Lemma.
Context Free Pumping Lemma Some languages are not context free!
Definition: Let G = (V, T, P, S) be a CFL
COSC 3340: Introduction to Theory of Computation
The Pumping Lemma for CFL’s
Properties of Context-Free Languages
Chapter 4 Properties of Regular Languages
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
The Pumping Lemma for CFL’s
Intro to Theory of Computation
Presentation transcript:

1 Module 33 Non-context free languages –Intuition and Examples CFL Pumping Lemma –Comparison to regular language pumping lemma –What it means –Proof overview –Applications

2 Examples and Intuition

3 Examples What are some examples of nonregular languages? Can we build on any of these languages to create a non context-free language?

4 Intuition Try and prove that these languages are CFL’s and identify the stumbling blocks –Why can’t we construct a CFG to generate this language? –Compare to similar CFL languages to try and identify differences.

5 Comparison to regular language pumping lemma/condition

6 What’s different about CFL’s than regular languages? * In regular languages, a single substring “pumps” –Consider the language of even length strings over {a,b} –We can identify a single substring which can be pumped In CFL’s, multiple substrings can “pump” –Consider the language {a n b n | n > 0} –No single substring can be pumped and allow us to stay in the language –However, there do exist pairs of substrings which can be pumped resulting in strings which stay in the language This results in a modified pumping condition

7 Modified Pumping Condition A language L satisfies the regular language pumping condition if: –there exists an integer n > 0 such that –for all strings x in L of length at least n –there exist strings u, v, w such that x = uvw and |uv| ≤ n and |v| ≥ 1 and For all k ≥ 0, uv k w is in L A language L satisfies the CFL pumping condition if: –there exists an integer n > 0 such that –for all strings x in L of length at least n –there exist strings u, v, w, y, z such that x = uvw yz and | v w y | ≤ n and | vy | ≥ 1 and For all k ≥ 0, u v k w y k z is in L

8 Pumping Lemma All CFL’s satisfy the CFL pumping condition All languages over {a,b} CFL’s “Pumping Languages”

9 Implications We can use the pumping lemma to prove a language L is not a CFL –Show L does not satisfy the CFL pumping condition We cannot use the pumping lemma to prove a language is context-free –Showing L satisfies the pumping condition does not guarantee that L is context-free CFL Pumping

10 Pumping Lemma What does it mean?

11 Pumping Condition A language L satisfies the CFL pumping condition if: –there exists an integer n > 0 such that –for all strings x in L of length at least n –there exist strings u, v, w, y, z such that x = uvwyz and |vwy| ≤ n and |vy| ≥ 1 and For all k ≥ 0, u v k w y k z is in L

12 v and y can be pumped Let x = abcdefg be in L Then there exist 2 substrings v and y in x such that v and y can be repeated (pumped) in place any number of times and the resulting string is still in L –uv k wy k z is in L for all k ≥ 0 For example –v = cd and y = f uv 0 wy 0 z = uwz = abeg is in L uv 1 wy 1 z = uvwyz = abcdefg is in L uv 2 wy 2 z = uvvwyyz = abcdcdeffg is in L uv 3 wy 3 z = uvvvwyyyz = abcdcdcdefffg is in L … 1) x in L 2) x = uvwyz 3) For all k ≥ 0, uv k wy k z is in L

13 What the other parts mean A language L satisfies the CFL pumping condition if: –there exists an integer n > 0 such that related to number of variables in CNF grammar G –for all strings x in L of length at least n x must be in L and have sufficient length –there exist strings u, v, w, y, z such that x = uvwyz and |vwy| ≤ n and –v and y are contained within n characters of x –these are NOT necessarily the first n characters of x |vy| ≥ 1 and –v and y cannot both be  –One of them might be, but not both For all k ≥ 0, uv k wy k z is in L

14 Example Let L be the set of palindromes over {a,b} –Let x = aabaa –Let n = 3 –What are the possibilities for v and y ignoring the pumping constraint? –Which ones satisfy the pumping lemma?

15 Pumping Lemma Proof

16 Proof For any CFL L, consider a CNF grammar G with m variables s.t. L(G) = L – {λ} Let n = 2 m Consider any string x in L of length at least n, and let T be a parse tree for x How short can the longest path of T be? –Must have length at least m+1. From the last m+1 variables in the longest path of T, identify two variables that are identical. Formulate u, v, w, y, and z based on these choice.

17 Illustration: k=2 uvwyz S A Auvyz S A A uvyz S A A vwy A slide originally from Chris Umans, Cal Tech

18 Illustration: k=0 uvwyz S A Auz S A uz S A x slide originally from Chris Umans, Cal Tech

19 Pumping Lemma Applying it to prove a specific language L is not context-free

20 How we use the Pumping Lemma We choose a specific language L –For example, {a j b j c j | j > 0} We show that L does not satisfy the pumping condition We conclude that L is not context-free

21 Showing L “does not pump” A language L satisfies the CFL pumping condition if: –there exists an integer n > 0 such that –for all strings x in L of length at least n –there exist strings u, v, w, y, z such that x = uvw yz and | v w y | ≤ n and | vy | ≥ 1 and For all k ≥ 0, u v k w y k z is in L A language L does not satisfy the CFL pumping condition if: –for all integers n of sufficient size –there exists a string x in L of length at least n such that –for all strings u, v, w, y, z such that x = uvwyz and |vwy| ≤ n and |vy| ≥ 1 –There exists a k ≥ 0 such that uv k wy k z is not in L

22 Example Proof A language L does not satisfy the CFL pumping condition if: –for all integers n of sufficient size –there exists a string x in L of length at least n such that –for all strings u, v, w, y, z such that x = uvwyz and |vwy| ≤ n and |vy| ≥ 1 –There exists a k ≥ 0 such that uv k wy k z is not in L Proof that L = {a i b i c i | i>0} does not satisfy the CFL pumping condition Let n be the integer from the pumping lemma Choose x = a n b n c n Consider all strings u, v, w, y, z s.t. x = uvwyz and |vwy| ≤ n and |vy| ≥ 1 Argue that uv k wy k z is not in L for some k ≥ 0 –Argument must apply to all possible u,v,w,y,z –Continued on next slide

23 Example Proof Continued Proof that L = {a i b i c i | i>0} does not satisfy the CFL pumping condition Let n be the integer from the pumping lemma Choose x = a n b n c n Consider all strings u, v, w, y, z s.t. x = uvwyz and |vwy| ≤ n and |vy| ≥ 1 Argue that uv k wy k z is not in L for some k ≥ 0 –Argument must apply to all possible u,v,w,y,z –Continued next column Identify possible cases for vwy What is impossible for vwy? Case 1 –vwy contains no a’s Case 2 –vwy contains no c’s Must argue uv k wy k z is not in L for both cases described above –Can use different values of k –Continued on next slide

24 Example Proof Continued Identify possible cases for vwy What is impossible for vwy? Case 1 –vwy contains no a’s Case 2 –vwy contains no c’s Must argue uv k wy k z is not in L for both cases described above –Can use different values of k –Continued next column Case 1: vwy contains no a’s –vy contains at least 1 b or c follows from –vwy contains no a’s and –|vy| ≥ 1 –uwz is not in L uwz has n a’s –follows from fact vwy contains no a’s and x originally had n a’s uwz has fewer than n b’s or fewer than n c’s –follows from vy contains at least 1 b or c and x originally only had n b’s and n c’s Continued next slide

25 Example Proof Continued Case 1: vwy contains no a’s –vy contains at least 1 b or c follows from –vwy contains no a’s and –|vy| ≥ 1 –uwz is not in L uwz has n a’s –follows from fact vwy contains no a’s and x originally had n a’s uwz has fewer than n b’s or fewer than n c’s –follows from vy contains at least 1 b or c and x originally only had n b’s and n c’s Continued next column Case 2: vwy contains no c’s –vy contains at least –uv 2 wy 2 z is not in L uv 2 wy 2 z has n c’s –follows from fact vwy contains no c’s and x originally had n c’s uv 2 wy 2 z has more than n a’s or more than n b’s –follows from vy contains at least 1 a or b and x originally has n a’s and n b’s Continued next slide

26 Example Proof Completed For all possible u, v, w, y, z, we have shown there exists a k ≥ 0 such that –uv k wy k z is not in L Note, we used a different value of k for each case (though we didn’t have to) Therefore L does not satisfy the CFL pumping condition There L is not a CFL Case 2: vwy contains no c’s –vy contains at least –uv 2 wy 2 z is not in L uv 2 wy 2 z has n c’s –follows from fact vwy contains no c’s and x originally had n c’s uv 2 wy 2 z has more than n a’s or more than n b’s –follows from vy contains at least 1 a or b and x originally has n a’s and n b’s Continued next column

27 Other example languages TWOCOPIES = {ww | w is in {a,b} * } –abbabb is in TWOCOPIES but abaabb is not EQUAL3 = the set of strings over {a, b, c} such that the number of a’s equals the number of b’s equals the number of c’s {a i b j c k | i < j < k}

28 Pumping Lemma Two rules of thumb

29 Two Rules of Thumb Try to use blocks of at least n characters in x –For TWOCOPIES, choose x = a n b n a n b n rather than a n ba n b Guarantees v and y cannot be in more than 2 blocks of x Try k=0 or k=2 –k=0 This reduces number of occurrences of v and y –k=2 This increases number of occurrences of v and y

30 Summary Examples of some non-CFL’s We use the Pumping Lemma to prove a language is not a CFL –Note, does not work for all non CFL languages –Can be strengthened to Ogden’s Lemma (in book) Choosing a good string x is first key step Choosing a good k is second key step Typically have several cases for v, w, y