1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union,

Slides:



Advertisements
Similar presentations
Closure Properties of CFL's
Advertisements

1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
Lecture 9 Recursive and r.e. language classes
1 Lecture 14 Language class LFSA –Study limits of what can be done with FSA’s –Closure Properties –Comparing to other language classes.
1 Module 9 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.
Lecture 8 Recursively enumerable (r.e.) languages
1 Lecture 21 Regular languages review –Several ways to define regular languages –Two main types of proofs/algorithms Relative power of two computational.
1 Module 21 Closure Properties for LFSA using NFA’s –From now on, when I say NFA, I mean any NFA including an NFA- unless I add a specific restriction.
1 Lecture 31 EQUAL language –Designing a CFG –Proving the CFG is correct.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL.
1 Lecture 20 Regular languages are a subset of LFSA –algorithm for converting any regular expression into an equivalent NFA –Builds on existing algorithms.
1 Module 37 Showing CFL’s not closed under set intersection and set complement.
CS 310 – Fall 2006 Pacific University CS310 Strings, String Operators, and Languages Sections: August 30, 2006.
1 Module 30 EQUAL language –Designing a CFG –Proving the CFG is correct.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
1 Module 34 CFG --> PDA construction –Shows that for any CFL L, there exists a PDA M such that L(M) = L –The reverse is true as well, but we do not prove.
1 Languages and Finite Automata or how to talk to machines...
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
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.
1 Lecture 5 Topics –Closure Properties for REC Proofs –2 examples Applications.
1 Lecture 18 Closure Properties of Language class LFSA –Remember ideas used in solvable languages unit –Set complement –Set intersection, union, difference,
1 Lecture 32 CFG --> PDA construction –Shows that for any CFL L, there exists a PDA M such that L(M) = L –The reverse is true as well, but we do not prove.
1 Lecture 36 Attempt to prove that CFL’s are closed under intersection –Review previous constructions –Translate previous constructions to current setting.
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
1 Lecture 19 Closure Properties for LFSA using NFA’s –union second proof –concatenation –Kleene closure.
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.
1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.
1 Regular Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Introduction to CS Theory Lecture 1 – Introduction Piotr Faliszewski
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
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.
1 Strings and Languages. 2 Review Sets and sequences Functions and relations Graphs Boolean logic:      Proof techniques: – Construction, Contradiction,
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
TM Design Universal TM MA/CSSE 474 Theory of Computation.
1 Let L= { w= u v : u  {a, b}*, v  {c, d}* and |u|= |v|} 1.Design a context-free grammar that generates L. 2.Use your grammar and the construction from.
1 Properties of Context-Free Languages Is a certain language context-free? Is the family of CFLs closed under a certain operation?
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
1 Module 14 Regular languages –Inductive definitions –Regular expressions syntax semantics.
1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL.
Lecture 10UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 10.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
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.
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.
Grammars A grammar is a 4-tuple G = (V, T, P, S) where 1)V is a set of nonterminal symbols (also called variables or syntactic categories) 2)T is a finite.
Classifications LanguageGrammarAutomaton Regular, right- linear Right-linear, left-linear DFA, NFA Context-free PDA Context- sensitive LBA Recursively.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
Formal Languages and Grammars
Lecture 2 Overview Topics What I forgot from last lecture Proof techniques continued Alphabets, strings, languages Automata June 2, 2015 CSCE 355 Foundations.
Strings and Languages Denning, Section 2.7. Alphabet An alphabet V is a finite nonempty set of symbols. Each symbol is a non- divisible or atomic object.
1 Module 17 Closure Properties of Language class LFSA –Remember ideas used in solvable languages unit –Set complement –Set intersection, union, difference,
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Lecture 6: Context-Free Languages
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
Chapter 2. Formal Languages Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Closed book, closed notes
Formal Language & Automata Theory
Definition: Let G = (V, T, P, S) be a CFL
Properties of Context-Free Languages
Closure Properties of Regular Languages
CSCE 355 Foundations of Computation
Presentation transcript:

1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union, concatenation CFL’s versus regular languages –regular languages subset of CFL

2 Closure Properties for CFL’s Kleene Closure

3 CFL closed under Kleene Closure Let L be an arbitrary CFL Let G 1 be a CFG s.t. L(G 1 ) = L –G 1 exists by definition of L 1 in CFL Construct CFG G 2 from CFG G 1 Argue L(G 2 ) = L * There exists CFG G 2 s.t. L(G 2 ) = L * L * is a CFL

4 Visualization L*L* L CFL CFG’s Let L be an arbitrary CFL Let G 1 be a CFG s.t. L(G 1 ) = L –G 1 exists by definition of L 1 in CFL Construct CFG G 2 from CFG G 1 Argue L(G 2 ) = L * There exists CFG G 2 s.t. L(G 2 ) = L * L * is a CFL G1G1 G2G2

5 Algorithm Specification Input –CFG G 1 Output –CFG G 2 such that L(G 2 ) = (L(G 1 )) * CFG G 1 CFG G 2 A

6 Construction Input –CFG G 1 = (V 1, , S 1, P 1 ) Output –CFG G 2 = (V 2, , S 2, P 2 ) V 2 = V 1 union {T} – T is a new symbol not in V 1 or  S 2 = T P 2 = P 1 union {T --> TS 1 | }

7 Closure Properties for CFL’s Kleene Closure Examples

8 Input grammar: –V = {S} –  = {a,b} –S = S –P: S --> aa | ab | ba | bb Output grammar –V = {S, T} –  = {a,b} –Start symbol is T –P: T --> TS | S --> aa | ab | ba | bb Example 1 V 2 = V 1 union {T} T is a new symbol not in V 1 or  S 2 = T P 2 = P 1 union {T --> TS | }

9 Input grammar: –V = {S, T} –  = {a,b} –Start symbol is T –P: T --> TS | S --> aa | ab | ba | bb Output grammar –V = {S, T, U} –  = {a,b} –Start symbol is U –P: U --> UT | T --> TS | S --> aa | ab | ba | bb Example 2 V 2 = V 1 union {T} T is a new symbol not in V 1 or  S 2 = T P 2 = P 1 union {T --> TS | }

10 Closure Properties for CFL’s Kleene Closure Proof of Correctness

11 Is our construction correct? How do we prove our construction is correct? –Informal Test some strings Review logic behind construction –Formal First, show every string derived by G 2 belongs to (L(G 1 )) * –That is, show L(G 2 ) is a subset of (L(G 1 )) * Second, show every string in (L(G 1 )) * can be derived by G 2 –That is, show (L(G 1 )) * is a subset of L(G 2 ) Both proofs will be inductive proofs –Inductive proofs and recursive algorithms go well together

12 L(G 2 ) is a subset of (L(G 1 )) * We want to prove the following –If x in L(G 2 ), then x is in (L(G 1 )) * This is equivalent to the following –If T ==> * G 2 x, then x is in (L(G 1 )) * –The two statements are equivalent because x in L(G 2 ) means that T ==> * G 2 x We break the second statement down as follows: –If T ==> 1 G 2 x, then x is in (L(G 1 )) * –If T ==> 2 G 2 x, then x is in (L(G 1 )) * –If T ==> 3 G 2 x, then x is in (L(G 1 )) * –...

13 L(G 2 ) is a subset of (L(G 1 )) * Statement to be proven: –For all n >= 1, if T ==> n G 2 x, then x is in (L(G 1 )) * –Prove this by induction on n Base Case: –n = 1 –The only string x such that T ==> 1 G 2 x is the string Follows from inspection of G 2 –The string belongs to (L(G 1 )) * Follows from definition of Kleene Closure

14 Inductive Case Inductive Hypothesis: –For 1 j G 2 x, then x is in (L(G 1 )) * Note, this is a “strong” induction hypothesis Statement to be Proven in Inductive Case: –For n above, if T ==> n+1 G 2 x, then x is in (L(G 1 )) * Proving this statement –Let x be an arbitrary string such that T ==> n+1 G 2 x –There are two possible first derivation steps Case 1: T ==> G 2 ==> n G 2 x Case 2: T ==> G 2 TS ==> n G 2 x –These 2 cases follow from looking at grammar G 2

15 Case Analysis Case 1: T ==> G 2 is not possible –n >= 1 which means n+1 >= 2 Case 2: T ==> G 2 TS ==> n G 2 x –This means x has the form uv where T ==> <n u S ==> <n v –This follows because in n steps, we go from TS to x –Thus, T can take at most n-1 steps to generate u –Likewise for S generating v –String u belongs to (L(G 1 )) * Follows from the inductive hypothesis

16 Concluding Case 2: T ==> G 2 TS ==> n G 2 x –String v belongs to L(G 1 ) Follows from S ==> * G 2 v and Our construction insures that all strings derived from S in L(G 2 ) are also in L(G 1 ) –Conclude x belongs to (L(G 1 )) * x = uv where u belongs to (L(G 1 )) * and v belongs to L(G 1 ) By definition of Kleene closure, this means x=uv belongs to (L(G 1 )) * Wrapping up inductive case –In all possible derivations of x, we have shown that x belongs to (L(G 1 )) * –Thus, we have proven the inductive case Conclusion –By the principle of mathematical induction, we have shown that L(G 2 ) is a subset of (L(G 1 )) *

17 (L(G 1 )) * is a subset of L(G 2 ) We want to prove the following –If x is in (L(G 1 )) *, then x is in L(G 2 ) This is equivalent to the following –If x is in (L(G 1 )) *, then T ==> * G 2 x –The two statements are equivalent because x in L(G 2 ) means that T ==> * G 2 x We break the second statement down as follows: –If x is in (L(G 1 )) 0, then T ==> * G 2 x –If x is in (L(G 1 )) 1, then T ==> * G 2 x –If x is in (L(G 1 )) 2, then T ==> * G 2 x –...

18 (L(G 1 )) * is a subset of L(G 2 ) Statement to be proven: –For all n >= 0, if x is in (L(G 1 )) n, then x is in L(G 2 ) –Prove this by induction on n Base Case: –n = 0 –The only string x such that x is in (L(G 1 )) 0 is the string Follows from definition of (L(G 1 )) 0 –The string belongs to L(G 2 ) Follows from production T -->

19 Inductive Case Inductive Hypothesis: –For 0 * G 2 x Note, this is a “strong” induction hypothesis Statement to be Proven in Inductive Case: –For n above, if x is in (L(G 1 )) n+1, then T ==> * G 2 x Proving this statement –Let x be an arbitrary string in (L(G 1 )) n+1 –This means x = uv where u is a string in (L(G 1 )) n v is a string in L(G 1 ) –This follows from definition of (L(G 1 )) n+1 and that n>=0

20 Deriving x –x = uv where u is a string in (L(G 1 )) n v is a string in L(G 1 ) –T ==> G 2 TS ==> * G 2 uS ==> * G 2 uv = x The first derivation step is possible from our grammar The second sequence of derivation steps follows from T ==> * G 2 u –This follows from applying the induction hypothesis Third sequence of derivation steps follows from S ==> * G 2 v –This follows from the fact that v is in L(G 1 ) and –Our construction includes all productions from G 1 –Thus T ==> * G 2 x The inductive case follows The result is proven by the principle of mathematical induction

21 Construction for Set Union Input –CFG G 1 = (V 1, , S 1, P 1 ) –CFG G 2 = (V 2, , S 2, P 2 ) Output –CFG G 3 = (V 3, , S 3, P 3 ) V 3 = V 1 union V 2 union {T} –Variable renaming to insure no names shared between V 1 and V 2 – T is a new symbol not in V 1 or V 2 or  S 3 = T P 3 = P 1 union P 2 union {T --> S 1 | S 2 }

22 Construction for Set Concatenation Input –CFG G 1 = (V 1, , S 1, P 1 ) –CFG G 2 = (V 2, , S 2, P 2 ) Output –CFG G 3 = (V 3, , S 3, P 3 ) V 3 = V 1 union V 2 union {T} –Variable renaming to insure no names shared between V 1 and V 2 – T is a new symbol not in V 1 or V 2 or  S 3 = T P 3 = P 1 union P 2 union {T --> S 1 S 2 }

23 CFL’s and regular languages

24 CFL Closure Properties CFL’s are closed under Kleene closure –Just proven, proof also in book CFL’s are closed under set union –Proof in book CFL’s are closed under set concatenation –Proof in book What can we conclude from these 3 results? –It follows that regular languages are a subset of CFL’s

25 Regular languages subset of CFL Recursive definition of regular languages –Base Case: {}, { }, {a}, {b} are regular languages over {a,b} P={}, P={S --> }, P={S --> a}, P={S --> b} –Inductive Case: If L and L’ are are regular languages, then L*, LL’, L union L’ are regular languages Use previous constructions to see that these resulting languages are also context-free

26 Other CFL Closure Properties We will show that CFL’s are NOT closed under many other set operations Examples include –set complement –set intersection –set difference

27 Language class hierarchy All languages over alphabet  RE REG H H Equal CFL REC ?