module 31 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Module 31 PowerPoint Presentation
Download Presentation
Module 31

Loading in 2 Seconds...

play fullscreen
1 / 27

Module 31 - PowerPoint PPT Presentation


  • 130 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Module 31' - maxim


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
module 31
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
cfl closed under kleene closure
CFL closed under Kleene Closure
  • Let L be an arbitrary CFL
  • Let G1 be a CFG s.t. L(G1) = L
    • G1 exists by definition of L1 in CFL
  • Construct CFG G2 from CFG G1
  • Argue L(G2) = L*
  • There exists CFG G2 s.t. L(G2) = L*
  • L* is a CFL
visualization

L

L*

G1

G2

CFG’s

Visualization
  • Let L be an arbitrary CFL
  • Let G1 be a CFG s.t. L(G1) = L
    • G1 exists by definition of L1 in CFL
  • Construct CFG G2 from CFG G1
  • Argue L(G2) = L*
  • There exists CFG G2 s.t. L(G2) = L*
  • L* is a CFL

CFL

algorithm specification

A

Algorithm Specification
  • Input
    • CFG G1
  • Output
    • CFG G2 such that L(G2) = (L(G1))*

CFG G1

CFG G2

construction
Construction
  • Input
    • CFG G1 = (V1, S, S1, P1)
  • Output
    • CFG G2 = (V2, S, S2, P2)
      • V2 = V1 union {T}
        • T is a new symbol not in V1 or S
      • S2 = T
      • P2 = P1 union ??
closure properties for cfl s1

Closure Properties for CFL’s

Kleene Closure Examples

example 1
Input grammar:

V = {S}

S = {a,b}

S = S

P:

S --> aa | ab | ba | bb

Output grammar

V = {S, T}

S = {a,b}

Start symbol is

P:

Example 1

V2 = V1 union {T} T is a new symbol not in V1 or SS2 = TP2 = P1 union {T --> ST | l}

example 2
Input grammar:

V = {S, T}

S = {a,b}

Start symbol is T

P:

T --> ST | l

S --> aa | ab | ba | bb

Output grammar

V = {S, T, U}

S = {a,b}

Start symbol is

P:

Example 2

V2 = V1 union {T} T is a new symbol not in V1 or SS2 = TP2 = P1 union {T --> ST | l}

closure properties for cfl s2

Closure Properties for CFL’s

Kleene Closure Proof of Correctness

is our construction correct
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 G2 belongs to (L(G1))*
        • That is, show L(G2) is a subset of (L(G1))*
      • Second, show every string in (L(G1))* can be derived by G2
        • That is, show (L(G1))* is a subset of L(G2)
      • Both proofs will be inductive proofs
        • Inductive proofs and recursive algorithms go well together
l g 2 is a subset of l g 1
L(G2) is a subset of (L(G1))*
  • We want to prove the following
    • If x in L(G2), then x is in (L(G1))*
  • This is equivalent to the following
    • If T ==>*G2 x, then x is in (L(G1))*
    • The two statements are equivalent because
      • x in L(G2) means that T ==>*G2 x
  • We break the second statement down as follows:
    • If T ==>1G2 x, then x is in (L(G1))*
    • If T ==>2G2 x, then x is in (L(G1))*
    • If T ==>3G2 x, then x is in (L(G1))*
    • ...
l g 2 is a subset of l g 11
L(G2) is a subset of (L(G1))*
  • Statement to be proven:
    • For all n >= 1, if T ==>nG2 x, then x is in (L(G1))*
    • Prove this by induction on n
  • Base Case:
    • n = 1
    • Examining G2, what is the only string x such that T ==>1G2 x ?
    • Prove this string is in (L(G1))*
inductive case
Inductive Case
  • Inductive Hypothesis:
    • For 1 <= j <= n, if T ==>jG2 x, then x is in (L(G1))*
      • Note, this is a “strong” induction hypothesis
  • Statement to be Proven in Inductive Case:
    • For n above, if T ==>n+1G2 x, then x is in (L(G1))*
  • Proving this statement
    • Let x be an arbitrary string such that T ==>n+1G2 x
    • Examining G2, what are the two possible first derivation steps?
      • Case 1: T ==>G2 ==>nG2 x
      • Case 2: T ==>G2 ==>nG2 x
case analysis
Case Analysis
  • Case 1: T ==>G2 ==>n x is not possible
    • Why not?
  • Case 2: T ==>G2 ==>nG2 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?
concluding case 2 t g 2 n g 2 x
Concluding Case 2: T ==>G2 ==>nG2 x
    • Concluding string u belongs to L(G1)
      • Follows from S ==>* G2 u and
      • Our construction insures that all strings derived from S in L(G2) are also in L(G1)
    • How do we conclude that x belongs to (L(G1))*
  • Wrapping up inductive case
    • In all possible derivations of x, we have shown that x belongs to (L(G1))*
    • Thus, we have proven the inductive case
  • Conclusion
    • By the principle of mathematical induction, we have shown that L(G2) is a subset of (L(G1))*
l g 1 is a subset of l g 2
(L(G1))* is a subset of L(G2)
  • We want to prove the following
    • If x is in (L(G1))*, then x is in L(G2)
  • This is equivalent to the following
    • If x is in (L(G1))*, then T ==>*G2 x
    • The two statements are equivalent because
      • x in L(G2) means that T ==>*G2 x
  • We break the second statement down as follows:
    • If x is in (L(G1))0, then T ==>*G2 x
    • If x is in (L(G1))1, then T ==>*G2 x
    • If x is in (L(G1))2, then T ==>*G2 x
    • ...
l g 1 is a subset of l g 21
(L(G1))* is a subset of L(G2)
  • Statement to be proven:
    • For all n >= 0, if x is in (L(G1))n, then x is in L(G2)
    • Prove this by induction on n
  • Base Case:
    • n = 0
    • What is the only string x in (L(G1))0?
    • Show this string belongs to L(G2)
inductive case1
Inductive Case
  • Inductive Hypothesis:
    • For n>=0, if x is in (L(G1))j, thenT ==>*G2 x
      • Note, this is a “normal” induction hypothesis
  • Statement to be Proven in Inductive Case:
    • For n>=0, if x is in (L(G1))n+1, thenT ==>*G2 x
  • Proving this statement
    • Let x be an arbitrary string in (L(G1))n+1
    • This means x = uv where
      • u in L(G1)
      • What can we say about v?
deriving x
Deriving x
    • x = uv where
      • u is a string in L(G1)
      • v is a string in
    • Justify all the steps in the following derivation
    • T ==> G2 ST ==>* G2 Sv ==>* G2 uv = x
      • First step:
      • Second step:
      • Third step:
    • Thus T ==>* G2 x
  • The inductive case follows
  • The result is proven by the principle of mathematical induction
construction for set union
Construction for Set Union
  • Input
    • CFG G1 = (V1, S, S1, P1)
    • CFG G2 = (V2, S, S2, P2)
  • Output
    • CFG G3 = (V3, S, S3, P3)
      • V3 = V1 union V2 union {T}
        • Variable renaming to insure no names shared between V1 and V2
        • T is a new symbol not in V1 or V2 or S
      • S3 = T
      • P3 = P1 union P2 union {T --> }
construction for set concatenation
Construction for Set Concatenation
  • Input
    • CFG G1 = (V1, S, S1, P1)
    • CFG G2 = (V2, S, S2, P2)
  • Output
    • CFG G3 = (V3, S, S3, P3)
      • V3 = V1 union V2 union {T}
        • Variable renaming to insure no names shared between V1 and V2
        • T is a new symbol not in V1 or V2 or S
      • S3 = T
      • P3 = P1 union P2 union {T --> }
cfl closure properties
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
regular languages subset of cfl
Regular languages subset of CFL
  • Recursive definition of regular languages
    • Base Case:
      • {}, {l}, {a}, {b} are regular languages over {a,b}
      • P={}, P={S --> l}, P={S --> a}, P={S --> b}
    • Inductive Case:
      • If L1 and L2 are are regular languages, then L1*, L1L2, L1 union L2 are regular languages
      • Use previous constructions to see that these resulting languages are also context-free
other cfl closure properties
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
language class hierarchy

H

Equal

?

CFL

REC

RE

All languages over alphabet S

H

Language class hierarchy

REG