CFG Properties
CFG Properties
Languages
By,
Mr.R.Karunamoorthi, AP / CSE
1
Closure Property Results
CFLs are closed under:
Union
Concatenation
Kleene closure operator
Substitution
Homomorphism, inverse homomorphism
reversal
CFLs are not closed under:
Note: Reg languages
Intersection are closed
Difference under
Complementation these
operators
2
Strategy for Closure Property
Proofs
First prove “closure under substitution”
Using the above result, prove other closure properties
CFLs are closed under:
Union
Concatenation
Kleene closure operator
Prove Substitution
this first Homomorphism, inverse homomorphism
Reversal
3
Note: s(L) can use
a different alphabet
4
CFLs are closed under
Substitution
IF L is a CFL and a substititution defined
on L, s(L), is s.t., s(a) is a CFL for every
symbol a, THEN:
s(L) is also a CFL
What is s(L)?
L s(L)
w1 s(w1) Note: each s(w)
w2 s(L) s(w2) is itself a set of strings
w3 s(w3)
w4 s(w4)
5
CFLs are closed under
Substitution
G=(V,T,P,S) : CFG for L
Because every s(a) is a CFL, there is a CFG for each s(a)
Let Ga = (Va,Ta,Pa,Sa)
Construct G’=(V’,T’,P’,S) for s(L);
V’ has V and all V for a ∑; T’ has T and all a ∑
P’ consists of:
The productions of P, but with every occurrence of terminal “a” in
their bodies replaced by Sa.
All productions in any Pa, for any a ∑
Parse tree for G’: S
S=> S0SS0 | S1 S S1 |
S0=> aS0b | ab
S1=> xx | yy 7
CFLs are closed under union
Let L1 and L2 be CFLs
To show: L2 U L2 is also a CFL
Let us show by using the result of Substitution
Make a new language:
Lnew = {a,b} s.t., s(a) = L1 and s(b) = L2
==> s(Lnew) == same as == L1 U L2
8
CFLs are closed under
concatenation
Let L1 and L2 be CFLs
Let us show by using the result of Substitution
Make Lnew= {ab} s.t.,
s(a) = L1 and s(b)= L2
==> L1 L2 = s(Lnew)
9
CFLs are closed under
Kleene Closure
Let L be a CFL
Then, L* = s(Lnew)
10
We won’t use substitution to prove this result
12
Some negative closure results
2’s)
But L1 L2 cannot be a CFL
Why? same no of 0,1,2 not CFL
13
Some negative closure results
L1 L2 = L1 U L2
Logic: if CFLs were to be closed under complementation
the whole right hand side becomes a CFL (because
CFL is closed for union)
the left hand side (intersection) is also a CFL
but we just showed CFLs are
NOT closed under intersection!
CFLs cannot be closed under complementation.
14
Some negative closure results
15