1 Module 31 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union, concatenation.

Slides:



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

Closure Properties of CFL's
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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 19 LNFA subset of LFSA –Theorem 4.1 on page 131 of Martin textbook –Compare with set closure proofs Main idea –A state in FSA represents a set.
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.
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.
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.
Normal forms for Context-Free Grammars
1 Lecture 19 Closure Properties for LFSA using NFA’s –union second proof –concatenation –Kleene closure.
1 Lecture 20 LNFA subset of LFSA –Theorem 4.1 on page 105 of Martin textbook –Compare with set closure proofs Main idea –A state in FSA represents a set.
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.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
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.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
1 Dr. torng CFG → PDA construction Shows that for any CFL L, there exists a PDA M such that L(M) = L The reverse is true, but we skip the proof Parsing.
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?
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.
Context-Free and Noncontext-Free Languages Chapter 13 1.
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.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
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,
Transparency No. 1 Formal Language and Automata Theory Homework 5.
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
1 Closure E.g., we understand number systems partly by understanding closure properties: Naturals are closed under +, , but not -, . Integers are closed.
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.
Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION.
Formal Language & Automata Theory
Definition: Let G = (V, T, P, S) be a CFL
Properties of Context-Free Languages
Closure Properties of Regular Languages
Closure Properties of Regular Languages
CFGs: Formal Definition
COSC 3340: Introduction to Theory of Computation
CSCE 355 Foundations of Computation
Presentation transcript:

1 Module 31 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 ) = 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 ??

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 = –  = {a,b} –Start symbol is –P: 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 --> ST | }

9 Input grammar: –V = {S, T} –  = {a,b} –Start symbol is T –P: T --> ST | S --> aa | ab | ba | bb Output grammar –V = –  = {a,b} –Start symbol is –P: 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 --> ST | }

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 –Examining G 2, what is the only string x such that T ==> 1 G 2 x ? –Prove this string is in (L(G 1 )) *

14 Inductive Case Inductive Hypothesis: –For 1 ≤ j ≤ n, if T ==> 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 –Examining G 2, what are the two possible first derivation steps? Case 1: T ==> G 2  ==> n G 2 x Case 2: T ==> G 2 ==> n G 2 x

15 Case Analysis Case 1: T ==> G 2  n x is not possible –Why not? Case 2: T ==> G 2 ==> n G 2 x –This means x has the form uv where What can we say about u (no IH)? What can we say about v (no IH)? –Applying the inductive hypothesis, what can we conclude?

16 Concluding Case 2: T ==> G 2 ==> n G 2 x –Concluding string u belongs to L(G 1 ) Follows from S ==> * G 2 u and Our construction insures that all strings derived from S in L(G 2 ) are also in L(G 1 ) –How do we conclude that x 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 –What is the only string x in (L(G 1 )) 0 ? –Show this string belongs to L(G 2 )

19 Inductive Case Inductive Hypothesis: –For n ≥ 0, if x is in (L(G 1 )) j, then T ==> * G 2 x Note, this is a “normal” induction hypothesis Statement to be Proven in Inductive Case: –For n ≥ 0, 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 in L(G 1 ) What can we say about v?

20 Deriving x –x = uv where u is a string in L(G 1 ) v is a string in –Justify all the steps in the following derivation –T ==> G 2 ST ==> * G 2 Sv ==> * G 2 uv = x First step: Second step: Third step: –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 =

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 =

23 CFL’s and regular languages

24 CFL Closure Properties What have we just proven –CFL’s are closed under Kleene closure –CFL’s are closed under set union –CFL’s are closed under set concatenation 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 1 and L 2 are are regular languages, then L 1 *, L 1 L 2, L 1 union L 2 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 ?