CS 3240: Languages and Computation Properties of Context-Free Languages.

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.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
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.
CS5371 Theory of Computation
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
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.
Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
Homework 4 Solutions.
Normal forms for Context-Free Grammars
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 1: RE = Regular Languages, nonregular languages RL pumping lemma Chapter 2: Context-Free Languages (CFLs)
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.
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
Context-free Languages Chapter 2. Ambiguity.
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.
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.
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.
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.
Lecture # 31 Theory Of Automata By Dr. MM Alam 1.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
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.
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.
7. Properties of Context-Free Languages
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Definition: Let G = (V, T, P, S) be a CFL
COSC 3340: Introduction to Theory of Computation
Properties of Context-Free Languages
COSC 3340: Introduction to Theory of Computation
Applications of Regular Closure
Intro to Theory of Computation
Presentation transcript:

CS 3240: Languages and Computation Properties of Context-Free Languages

Properties of CFGs

Chomsky Normal Form

In Summary

Conversion to Chomsky Normal Form

Recall: Pumping Lemma for Regular Languages q1q1 qkqk qjqj For every regular language L, there is a finite pumping length p, such that for any string s  L and |s|  p, we can write s=xyz with: 1) x y i z  L for every i  {0,1,2,…} 2) |y|  1 3) |xy|  p

Pumping Lemma for CFL Theorem: For every context-free language L, there is a pumping length p, such that for any string s  L and |s|  p, we can write s=uvxyz with 1) u v i x y i z  L for every i  {0,1,2,…} 2) |vy|  1 3) |vxy|  p Note that 1) implies that uxz  L (take i=0), requirement 2) says that v,y cannot be the empty strings ε and condition 3) is useful in proving non-CFL.

Pumping a Parse Tree A A uvxyz 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

uvxyz  L A A uvxyz 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

Using Pumping Lemma “Proof by contradiction. Assume that L is context free. Let p be the pumping length of L and take s  L. By the pumping lemma it is possible to write s=uvxyz (with |vy|  1 and |vxy|  p) such that uv i xy i z  L for all i  0. However… Thus the pumping lemma does not hold for s. Contradiction. The language L is not context-free.” Show that pumping up or down s gives strings that are not in L. Be careful to consider all v,x,y possibilities. Here you have to be clever in picking the right s.

Example I: Pumping a n b n c n Proof by contradiction; assume L = {a n b n c n | n  0} is CF. According to the pumping lemma there is a pumping length p such that for s = a p b p c p  L, we can write s = uvxyz = a p b p c p, with uv i xy i z  L for all i  0. Two options for 1  |vxy|  p: 1) vxy = a*b*, then the string uv 2 xy 2 z has not enough letters c, hence uv 2 xy 2 z  L 2) vxy = b*c*, then the string uv 2 xy 2 z has not enough letters a, hence uv 2 xy 2 z  L Contradiction: the pumping lemma does not hold, hence L is not context free.

Example II: (Pumping down) Prove 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. Pumping lemma: s = uvxyz, such that uv i xy i z  C for every i  0. Two options for 1  |vxy|  p: 1) vxy = a*b*, then the string uv 2 xy 2 z has not enough letters c, hence uv 2 xy 2 z  C 2) vxy = b*c*, then the string uv 0 xy 0 z = uxz has too many letters a, hence uv 0 xy 0 z  C Contradiction: The pumping lemma does not hold for this string a p b p c p, hence C is not context-free.

Example III: ww Prove that the language D = { ww : w  {0,1}* } is not CF. You must be careful when picking the strings s  D… Let p be the pumping length, take s=0 p 1 p 0 p 1 p. Options for s=uvxyz with 1  |vxy|  p: 1. If vxy is to the left of the middle of 0 p 1 p 0 p 1 p, then second half of uv 2 xy 2 z starts with a “1”. 2. If vxy is to the right of the middle of 0 p 1 p 0 p 1 p, then first half of hence uv 2 xy 2 z ends with a “0”. 3. If x is in the middle of 0 p 1 p 0 p 1 p, then pumped down uxz equals 0 p 1 i 0 j 1 p  D (because i or j < p)

Additional Notes on CFL Let A 1 and A 2 be two context-free languages, then the union A 1  A 2 is also context free. However, the intersection A 1  A 2 is not necessarily context free The complement Ā 1 =  *–A 1 are not necessarily context free either

Closure properties of CFLs

Closure under reversal

CFL not closed under intersection!

Decision Problems for CFL

Make a chain of everywhere a variable occurs From each production send a link to a counter counting how many variables in the prod have not yet been found to produce When a variable is found to be generating decrement Counter accordingly When counter reaches 0 the head variable is generating

Undecidable problems for CFL