CS 3240 – Chapter 8.  Is a n b n c n context-free? CS 3240 - Properties of Context-Free Languages2.

Slides:



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

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.
Context Free Grammars.
CS 3240: Languages and Computation Properties of Context-Free Languages.
CS 3240 – Chapter 6.  6.1: Simplifying Grammars  Substitution  Removing useless variables  Removing λ  Removing unit productions  6.2: Normal Forms.
1 Introduction to Computability Theory Lecture12: Decidable Languages 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
Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
104 Closure Properties of Regular Languages Regular languages are closed under many set operations. Let L 1 and L 2 be regular languages. (1) L 1  L 2.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
Normal forms for Context-Free Grammars
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.
Context-Free Grammars Chapter 3. 2 Context-Free Grammars and Languages n Defn A context-free grammar is a quadruple (V, , P, S), where  V is.
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.
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.
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
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 21, 2004.
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
1 Properties of Context-Free Languages Is a certain language context-free? Is the family of CFLs closed under a certain operation?
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
Grammars CPSC 5135.
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL.
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.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
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.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
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.
CS 203: Introduction to Formal Languages and Automata
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 Chapter 6 Simplification of CFGs and Normal Forms.
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.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
Lecture 6: Context-Free Languages
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.
Context-Free and Noncontext-Free Languages Chapter 13.
7. Properties of Context-Free Languages
PDAs Accept Context-Free Languages
Chapter Fourteen: The Context-Free Frontier
Definition: Let G = (V, T, P, S) be a CFL
7. Properties of Context-Free Languages
COSC 3340: Introduction to Theory of Computation
Deterministic PDAs - DPDAs
COSC 3340: Introduction to Theory of Computation
Presentation transcript:

CS 3240 – Chapter 8

 Is a n b n c n context-free? CS Properties of Context-Free Languages2

 a n b n c n is not context-free  Neither is ww  although ww R is!  We will develop a pumping lemma for context-free languages  (oh joy! :-)  as before, can only be used to show that a language is not CF CS Properties of Context-Free Languages3

 How can you tell by looking at a CFG whether its language is infinite or not? CS Properties of Context-Free Languages4

 S → aaB  A → bBb | λ  B → Aa  Consider the derivation: S ⇒ aaB ⇒ aaAa ⇒ aabBba ⇒ aabAaba ⇒ aabbBbaba ⇒ aabbAababa … CS Properties of Context-Free Languages5

 Grammars for infinite CFL must reuse a variable in some derivation  S ⇒ * uAz ⇒ * uvAyz  That is, A ⇒ * vAy  u,v,y,z,are derivable strings of characters and variables  We can repeat the same choices for A again:  S ⇒ * uAz ⇒ * uvAyz ⇒ * uvvAyyz  And again and again… (finally stopping with x)  S ⇒ * uv n Ay n z ⇒ * uv n xy n z  So for any sufficiently long string, s, we have  s = uv n xy n z CS Properties of Context-Free Languages6 ⇒

 Hint: think of derivation trees, and the relationship between the depth and the number of leaves in a tree CS Properties of Context-Free Languages7

 If a complete binary has depth d, how many leaves does it have? CS Properties of Context-Free Languages8

 Consider a path from the root of a tree (S) to a leaf.  It is all variables, except for the leaf  The longer the string, the deeper the path  Eventually a variable must be repeated! CS Properties of Context-Free Languages9

 Based on a repeated variable (a type of loop)  For sufficiently-long strings (≥ p = 2 v ), some variable will be a descendant of itself in the parse  Every string of sufficient length from an infinite CFL can be written as uvxyz, and pumped as uv i xy i z, i ≥ 0:  |v| + |y| > 0  |vxy| <= p

 Intuitively: We’ve already used up the stack to coordinate the a n b n prefix  Must consider all cases for a proof  CFLPL-8.PDF CFLPL-8.PDF

 Use the pumping lemma with a p b p a p b p

 (N)CFLs are closed under:  Union  Concatenation  Kleene Star  “Regular Intersection” (CF ∩ R = CF)  (N)CFLs are not closed under:  intersection  complement CS Properties of Context-Free Languages13

 Let S 1 be the start symbol for L 1, and S 2 for L 2  Just have a new start symbol point to the OR of the old ones:  S => S 1 | S 2 S 1 => … S 2 => …

 S => S 1 S 2 S 1 => … S 2 => …

 Rename the old start variable to S 1  S => S 1 S | λ S 1 => …

 Let L 1 = a n b n c m  The concatenation of a n b n and c m  Let L 2 = a n b m c m  The concatenation of a n and b m c m  These are both context-free  L 1 ∩ L 2 = a n b n c n  We already showed this is not context free

 Let R be a regular language and L a context- free language  The R ∩ L is context-free  Why? CS Properties of Context-Free Languages18

CS Properties of Context-Free Languages19 a,λb,X ± ss/Xf/λ + fΦf/λ ab ± ABC BAD CDA DCB

CS Properties of Context-Free Languages20 a,λb,X ± sAs/X; Bf/λ; C sBs/X; Af/λ; D fC; Df/λ; A fD; Cf/λ; B + fA; Bf/λ; C fB; Af/λ; D

CS Properties of Context-Free Languages21 jail

 Proof by contradiction, derived from the formula for intersection: L 1 ∩ L 2 = (L 1 ' + L 2 ')' Since the intersection is not closed, but union is, then the complement cannot be.  (Otherwise we could compute the intersection, which in general is not CF)

 Non-determinism is the problem  Remember NFAs?  To find the complement, we needed to first convert to a DFA, then flip the states  Since some CFLs are inherently non- deterministic, they have no deterministic equivalent to “flip”  But… what does this say about deterministic CFLs? CS Properties of Context-Free Languages23

 DCFLs are closed under:  Complement!  Concatenation  Kleene Star  “Regular Intersection” (CF ∩ R = CF)  DCFLs are not closed under:  Intersection  Union! CS Properties of Context-Free Languages24

 Consider: L 1 = {a i b j c k | i = j} L 2 = {a i b j c k | j = k}  Each of these is DCF  (Easy to show – your 7.1 homework was similar)  The union is not!  It requires non-determinism  It’s still context-free, but not Deterministic CF

 DCFLs always have an associated CFG that is unambiguous

 Closed under Union, Concatenation, Kleene Star  Not closed under intersection, complement  CFL ∩ Regular = CFL  DCFLs are closed under complement  But not union!  Swap those two

 Unanswerable questions  Answerable questions

 Do 2 arbitrary CFGs generate the same language?  Is a CFG ambiguous?  Is a given NCFL’s complement also CF?  Is the intersection of 2 given CFLs CF?  Do 2 CFLs have a common word?

 Is a non-terminal ever used in a productive derivation?  Draw the connectivity graph ✔  Does a CFG generate any words?  Substitute each “terminating production” (RHS is all terminals) throughout and see what happens ▪ “back substitution method”  Is a CFL finite or infinite?  Procedure to detect useful, repeated variables

CS Properties of Context-Free Languages31 S → aA | bB | λ A → a | aCA | bDA | bBa | aAa B → b | aAb | aCB | bDB | bBb C → aCC | bDC D → aCD | bDD First remove useless variables…

CS Properties of Context-Free Languages32 S → aA | bB | λ A → a | bBa | aAa B → b | aAb | bBb Pick a non-empty, terminal rule: A → a Back-substitute that rule: S → aa | bB | λ A → a | bBa | aaa B → b | aab | bBb Keep going until we have S →, or we can’t continue. We have S → aa. STOP.

CS Properties of Context-Free Languages33 S → aA | bB | λ A → a | bBa | aAa B → b | aAb | bBb All variables are useful. Let’s see if A is repeated, for instance. First, mark all A’s on the right: S → aA | bB | λ A → a | bBa | aAa B → b | aAb | bBb Now mark all variables affected on the left: S → aA | bB | λ A → a | bBa | aAa B → b | aAb | bBb Since A was marked on the left, it is repeated.

CS Properties of Context-Free Languages34 S ➞ aA | SBMark on left: A ➞ baB | λ B ➞ bB | bAS ➞ aA | SB A ➞ baB | λ Mark A’s on right:B ➞ bB | bA S ➞ aA | SBA was marked on left. DONE. A ➞ baB | λ B ➞ bB | bA Now mark corresponding variables on left: S ➞ aA | SB A ➞ baB | λ B ➞ bB | bA Repeat marking on right: S ➞ aA | SB A ➞ baB | λ B ➞ bB | bA