Closure Properties - University of Arizona
Transcript of Closure Properties - University of Arizona
CSC 473 Automata, Grammars & Languages 10/26/10
1
C SC 473 Automata, Grammars & Languages 56
Closure Properties Regular Ops. The CFLs are closed under ∪, ⋅, ∗ Pf: Homework �
Intersection. The CFLs are not closed under intersection. Example: Consider the two CFLs
Then We will later see (CF Pumping Lemma) that this last is
not a CFL. �
However, if is regular and is CF, then is CF.
1 2{ | 0}, { | 0}
n n n nL a b c n L a b n c
! != " # = # "
1 2{ | 0}.
n n nL L a b c n! = "
1L
2L
1 2L L!
!
C SC 473 Automata, Grammars & Languages 57
Closure Properties (contʼd)• Thm: The class of CFLs is closed under intersection with
regular languages. Pf: Assume and
Construction. Construct a “cross-product pda” M asfollows:
where the transition function is defined by:
provided and
Machine M simulates the two given machines “in parallel”, keeping each machine state in one component of the
compound state [ , ]. �
1 1 1 1 1 1 1( ), ( , , , , , )L L P P Q s F!= = " #
2 2 2 2 2 2 2( ), ( , , , , )R L M M Q s F!= = "
1 2 1 2 1, 2 1 2( , , , ,[ ], )M Q Q s s F F!= " # $ # % "
1 2 1 2([ , ], ) ([ , ], , )p p Y q q a X!"
!
1 1 1( , ) ( , , )p Y q a X!" 2 2 2
( , )p q a!=
C SC 473 Automata, Grammars & Languages 58
What is Not Context-Free?• PDA have a limited computing ability. They cannot, for
example, recognize repeated strings like w#w or stringsthat “count” in more than 2 places, such as .
• We will show that some languages are not CF using a CFPumping Lemma, which gives a property that all CFLsmust have. Then, to show that a language L is not CF, wesomehow argue that it lacks this pumping property.
• Closure properties of CFLs can sometimes be used tosimplify non-CFLs and make a pumping argument easier.
n n na b c
CSC 473 Automata, Grammars & Languages 10/26/10
2
C SC 473 Automata, Grammars & Languages 59
CF Pumping Lemma• Thm [Pumping Lemma for CFLs]. Suppose that L is an
infinite CF language. Then
• For comparison, here is the Regular P.L.:
( )( )[
( , , , , )(
( 0) )]i i
p w w L w p
u v x y z w uvxyz vy
vxy p i uv xy z L
!
" # $ % & '
" = % (
% ) % # & $
( )( )[
( , , )(
( 0) )]i
p w w L w p
x y z w xyz y
xy p i xy z L
!
" # $ % & '
" = % (
% ) % # & $
C SC 473 Automata, Grammars & Languages 60
CF Pumping Lemma (contʼd)• Pf: Let where CFG G is a CFG in
Chomsky Normal Form (Text, Theorem 2.9), i.e. a CFG inwhich all rules are of the (schematic) forms A→BC or A→a(a ≠ ε). If is “sufficiently long”, then anyderivation tree T for w must contain a “long” path—moreprecisely:
• Claim 1: If the derivation tree T for has no path longerthan h then
Pf: Induction on h. Base: h = 1. Only possible tree is and Step: Assume Let T have all paths and be of form (in CNF)
( )w L G!
1| | 2 .
h
w!
"
1.h > h!
{ } ( )L L G!" =
w
0| | 2.a =
S
a
C SC 473 Automata, Grammars & Languages 61
CF Pumping Lemma (contʼd)
• Then have all paths of length By IH, which implies �. Conversely, if a generated string is at least long, then its parse tree must be at least high.
G has variables. Choose If and then Claim 1 ⇒ any parse tree T for w has a path of length at least Such a path has at
least nodes. ∴ some variable appears twice on the path (note the leaf node is a terminal).
2 2| | 2 ,| | 2
h h
s t! !
" "
S
1T
2T
T =
s t w st=
1 2,T T 1.h! "
1| | 2
h
w!
"
2h
1h+
V1
2 .V
p+
= w L!
w p!
2.V +
3V +
CSC 473 Automata, Grammars & Languages 10/26/10
3
C SC 473 Automata, Grammars & Languages 62
CF Pumping Lemma (contʼd)• Picture:
1
2V
w p+
! =
T =
R
R
height nodes
variables repeat
2 3
2
V V
V
! + " ! +
" ! + "
R
RR
u v x y zw =
a
ht 2V! +
1
2V
p+
! =
ChooseBottom
variables1V +
vxy p! "
1T
2T
C SC 473 Automata, Grammars & Languages 63
CF Pumping Lemma (contʼd)(1) Center portion is not too long:(2) Pumped portion not empty: cannot both = ε.
1T
2T
vxy p!
,v y
=
R
B C
2T
v x y
x !"
R
B C
2T
v x y
x!"
or
In CNF, no variablegenerates ε
C SC 473 Automata, Grammars & Languages 64
CF Pumping Lemma (contʼd)(3) Pumped strings in L : the following are all parse trees
R
R
( 0)i i
i uv xy z L! " # $ !
R
R
R
R
R
R
R
u v x y z
u vv x yy z
u vvv x yyy z
…
R
u x z
and:
CSC 473 Automata, Grammars & Languages 10/26/10
4
C SC 473 Automata, Grammars & Languages 65
CF Pumping: Applications• Ex: is not a CFL. Pf: Suppose it is CF. Then the Pumping Lemma ⇒ ∃p ∀ w∈L, |w|≥p ⇒ ∃ uvxyz =w & vy ≠ ε & ∀i≥0 u vi x yi z ∈L. Pick p as the constant guaranteed and choose n ≥ p/3 and Where is Cases: Assume first that
{ | 0}n n n
L a b c n= !
, .n n n
w a b c uvxyz vy != = " ?vxy
.v !"
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
a ab bc c
u v x y z
u v x y z
u v xyz
u v x y z
u v xyz
u v xyz
……… ……… ………
C SC 473 Automata, Grammars & Languages 66
CF Pumping: Applications• In cases 1-3 has an imbalance. In case 4 it has a b before a. In case 5 it has a c before b. In case 6 it has an a after a c. In any case, there is a contradiction to the pumped word being in L. The case where is symmetric. Contradiction. � Cor. The CFLs are not closed under complementation. Pf: is a CFL. But is not a CFL. Therefore cannot be CF. � Ex: is not CF. Proof similar to regular case. � Ex: is not CF. �
y !"
2 2uv xy z
{ | }p q r
L a b c p q q r p r= ! " ! " !
{ | 0}i i i
L a b c a b c i! ! !
" = #
L
{ | prime}i
L a i=
2
{ | 0}i
L a i= !
C SC 473 Automata, Grammars & Languages 67
Pumping: Applications (contʼd) Ex: is not CF. Pf: Intersection with is not a CFL. Therefore cannot be CF. � Ex: is not CF. Pf: By pumping on the word Similar to Text, Example 2.38. � Ex: is not CF. Pf:
Pump on the latter language in a way similar to the previousexample to show it is not CF. �
L
a b c{ { , , } | = = }L w a b c w w w
!= "
a b c! ! !
{ |i 1,j 1}i j i j
L a b c d= ! !n n n n
w a b c d=
{ | {0,1}}L ww w= !
10 10 110 10 1 {10 10 110 10 1| , 1}n m n m
L m n+ + + +
! = "