Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Module 31 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union, concatenation."— Presentation transcript:

1 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 2 Closure Properties for CFL’s Kleene Closure

3 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 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 5 Algorithm Specification Input –CFG G 1 Output –CFG G 2 such that L(G 2 ) = CFG G 1 CFG G 2 A

6 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 7 Closure Properties for CFL’s Kleene Closure Examples

8 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 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 10 Closure Properties for CFL’s Kleene Closure Proof of Correctness

11 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 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 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 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 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 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 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 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 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 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 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 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 23 CFL’s and regular languages

24 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 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 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 27 Language class hierarchy All languages over alphabet  RE REG H H Equal CFL REC ?


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

Similar presentations


Ads by Google