> 9U(
H/0DTimes New Romanp5'D,0DWo
0DTahomaew Romanp5'D,0DWo
0D" DMonotype Sortsp5'D,0DWo
00DLucida Sans Unicode,0DWo
0D"@DSymbolSans Unicode,0DWo
0Da.
@n?" dd@ @@``x<N.H
!"#$%&'()*+,/.0132457689:;<=>;@ABCDEGFHc$ f3f33ff̙@g4FdFd08ppp@uʚ;2Nʚ;<4!d!ddЁ
0P<4dddddЁ
0P<4BdBddЁ
0P&___PPT9/08H?O=H$Properties of ContextFree Languages&Decision Properties
Closure PropertiesSummary of Decision PropertiesAs usual, when we talk about a CFL we really mean a representation for the CFL, e.g., a CFG or a PDA accepting by final state or empty stack.
There are algorithms to decide if:
String w is in CFL L.
CFL L is empty.
CFL L is infinite.,9u9
NonDecision PropertiesMany questions that can be decided for regular sets cannot be decided for CFL s.
Example: Are two CFL s the same?
Example: Are two CFL s disjoint?
How would you do that for regular languages?
Need theory of Turing machines and decidability to prove no algorithm exists.^NQ3333NPJZ
Testing EmptinessWe already did this.
We learned to eliminate variables that generate no terminal string.
If the start symbol is one of these, then the CFL is empty; otherwise not.Testing MembershipWant to know if string w is in L(G).
Assume G is in CNF.
Or convert the given grammar to CNF.
w = is a special case, solved by testing if the start symbol is nullable.
Algorithm (CYK ) is a good example of dynamic programming and runs in time O(n3), where n = w.9qa9)Gf33c
CYK AlgorithmLet w = a1& an.
We construct an nbyn triangular array of sets of variables.
Xij = {variables A  A =>* ai& aj}.
Induction on j i+1.
The length of the derived string.
Finally, ask if S is in X1n." A">MV&CYK Algorithm (2)3fBasis: Xii = {A  A > ai is a production}.
Induction: Xij = {A  there is a production A > BC and an integer k, with i < k < j, such that B is in Xik and C is in Xk+1,j.3f 3f?PYExample: CYK Algorithm33 Example: CYK Algorithm33
Example: CYK Algorithm33Example: CYK Algorithm33Example: CYK Algorithm33Testing InfinitenessThe idea is essentially the same as for regular languages.
Use the pumping lemma constant n.
If there is a string in the language of length between n and 2n1, then the language is infinite; otherwise not.
Let s work this out in class.33!
6Closure Properties of CFL sRCFL s are closed under union, concatenation, and Kleene closure.
Also, under reversal, homomorphisms and inverse homomorphisms.
But not under intersection or difference.H+
,#8Closure of CFL s Under Union
Let L and M be CFL s with grammars G and H, respectively.
Assume G and H have no variables in common.
Names of variables do not affect the language.
Let S1 and S2 be the start symbols of G and H.Zf//f/"$2Closure Under Union (2)&Form a new grammar for L M by combining all the symbols and productions of G and H.
Then, add a new start symbol S.
Add productions S > S1  S2.Hq&2Closure Under Union (3)In the new grammar, all derivations start with S.
The first step replaces S by either S1 or S2.
In the first case, the result must be a string in L(G) = L, and in the second case a string in L(H) = M.6Wk(HClosure of CFL s Under Concatenation(Let L and M be CFL s with grammars G and H, respectively.
Assume G and H have no variables in common.
Let S1 and S2 be the start symbols of G and H.6k"+BClosure Under Concatenation (2)Form a new grammar for LM by starting with all symbols and productions of G and H.
Add a new start symbol S.
Add production S > S1S2.
Every derivation from S results in a string in L followed by one in M.6I,Closure Under StarLet L have grammar G, with start symbol S1.
Form a new grammar for L* by introducing to G a new start symbol S and the productions S > S1S  .
A rightmost derivation from S generates a sequence of zero or more S1 s, each of which generates some string in L.Z)_F./>Closure of CFL s Under ReversalIf L is a CFL with grammar G, form a grammar for LR by reversing the right side of every production.
Example: Let G have S > 0S1  01.
The reversal of L(G) has grammar S > 1S0  10. 82233S0FClosure of CFL s Under HomomorphismLet L be a CFL with grammar G.
Let h be a homomorphism on the terminal symbols of G.
Construct a grammar for h(L) by replacing each terminal symbol a by h(a).$1#Example: Closure Under Homomorphism$33G has productions S > 0S1  01.
h is defined by h(0) = ab, h(1) = .
h(L(G)) has the grammar with productions S > abS  ab.$~C:>8:3VClosure of CFL s Under Inverse Homomorphism*Here, grammars don t help us.
But a PDA construction serves nicely.
Intuition: Let L = L(P) for some PDA P.
Construct PDA P to accept h1(L).
P simulates P, but keeps, as one component of a twocomponent state a buffer that holds the result of applying h to one input symbol.8D ̙;4$Architecture of P 92Formal Construction of P States are pairs [q, b], where:
q is a state of P.
b is a suffix of h(a) for some symbol a.
Thus, only a finite number of possible values for b.
Stack symbols of P are those of P.
Start state of P is [q0 ,]. <u5uB 95;:0Construction of P (2)Input symbols of P are the symbols to which h applies.
Final states of P are the states [q, ] such that q is a final state of P.$^%="Transitions of P ( ([q, ], a, X) = {([q, h(a)], X)} for any input symbol a of P and any stack symbol X.
When the buffer is empty, P can reload it.
([q, bw], , X) contains ([p, w], a) if (q, b, X) contains (p, a), where b is either an input symbol of P or .
Simulate P from the buffer.Zu,usuu1 ,?2Proving Correctness of P We need to show that L(P ) = h1(L(P)).
Key argument: P makes the transition ([q0, ], w, Z0)"*([q, x], , a) if and only if P makes transition (q0, y, Z0) "*(q, , a), h(w) = yx, and x is a suffix of the last symbol of w.
Proof in both directions is an induction on the number of moves made.D̙
D93fAsANonclosure Under Intersection4Unlike the regular languages, the class of CFL s is not closed under .
We know that L1 = {0n1n2n  n > 1} is not a CFL (use the pumping lemma).
However, L2 = {0n1n2i  n > 1, i > 1} is.
CFG: S > AB, A > 0A1  01, B > 2B  2.
So is L3 = {0i1n2n  n > 1, i > 1}.
But L1 = L2 L3.*6E4*
+CNonclosure Under DifferenceWe can prove something more general:
Any class of languages that is closed under difference is closed under intersection.
Proof: L M = L (L M).
Thus, if CFL s were closed under difference, they would be closed under intersection, but they are not.T%U%U3fzYE$Intersection with a Regular LanguageIntersection of two CFL s need not be context free.
But the intersection of a CFL with a regular language is always a CFL.
Proof involves running a DFA in parallel with a PDA, and noting that the combination is a PDA.
PDA s accept by final state.:{3fZF DFA and PDA in ParallelI!Formal Construction4Let the DFA A have transition function A.
Let the PDA P have transition function P.
States of combined PDA are [q,p], where q is a state of A and p a state of P.
([q,p], a, X) contains ([A(q,a),r], a) if P(p, a, X) contains (r, a).
Note a could be e, in which case A(q,a) = q..')P
J"2Formal Construction (2)Accepting states of combined PDA are those [q,p] such that q is an accepting state of A and p is an accepting state of P.
Easy induction: ([q0,p0], w, Z0)"* ([q,p], e, a) if and only if A(q0,w) = q and in P: (p0, w, Z0)"*(p, e, a).zf/
"
%')*.25678;<>@BDGH K!L" ` ̙33` ` ff3333f` 333MMM` f` f` 3>?" dd@,?udd@ w " @ ` n?" dd@ @@``PR @ ` `p>>6.(
6n' P'
T Click to edit Master title style!
!
0q' '
RClick to edit Master text styles
Second level
Third level
Fourth level
Fifth level!
S
0v' ``'
X*
0{' ` '
Z*
0Ȁ' ` '
Z*Z
Byh@ ? ̙33 Default Design
0zrP
(
01u P
u
P*
06u u
R*
d
c$ ?
u
02u
@u
RClick to edit Master text styles
Second level
Third level
Fourth level
Fifth level!
S
6 AB, A > BC  a, B > AC  b, C > a  b
String w = ababa,K .fE
\
<uUu
:
\
<u`k
,$D
0
!=X11={A,C} X22={B,C} X33={A,C} X44={B,C} X55={A,C}> >
\
<`u
`),$D
0
O X12={B,S}*
h
\
<u
q,$D
0
"X23={A} X34={B,S} X45={A}V# ,
Dl
\,$D
0`B
\
0D3f8c0`B
\
0D3f8c`Dl
\,$D
0`B
\
0D8c`B
\
0D8cH
\0h ? ̙33
H
@
@` (
`x
` c$uP
u
T
`
<uPV,$D
0
JGrammar: S > AB, A > BC  a, B > AC  b, C > a  b
String w = ababa,K .fE
`
<uUu
:
`
<u`k
,$D
0
!=X11={A,C} X22={B,C} X33={A,C} X44={B,C} X55={A,C}> >
`
<0u
`),$D
0
O X12={B,S}*
h
`
<
q,$D
0
"X23={A} X34={B,S} X45={A}V# ,
`
<` ,$D
0
LX13={}* l P0
`0 P,$D
0ZB
`
s*DP PZB
`
s*D
`
<0 P
>Yields nothingH
`0h ? ̙33
w
`d
(
dx
d c$P
T
d
<tPV,$D
0
JGrammar: S > AB, A > BC  a, B > AC  b, C > a  b
String w = ababa,K .fE
d
<#Uu
:
d
<L&`k
,$D
0
!=X11={A,C} X22={B,C} X33={A,C} X44={B,C} X55={A,C}> >
d
<1
`),$D
0
O X12={B,S}*
h
d
<d6
q,$D
0
"X23={A} X34={B,S} X45={A}V# ,
d
<H` ,$D
0
MX13={A}* 8
d `B
d
0D8c
`B
d
0D8c
d
<C ,$D
0
pX24={B,S} X35={A}@ H
d0h ? ̙33F
t(
tx
t c$DQP
T
t
<RPV,$D
0
JGrammar: S > AB, A > BC  a, B > AC  b, C > a  b
String w = ababa,K .fE
t
<`YUu
:
t
<\`k
,$D
0
!=X11={A,C} X22={B,C} X33={A,C} X44={B,C} X55={A,C}> >
t
<(h
`),$D
0
O X12={B,S}*
h
t
<m
q,$D
0
"X23={A} X34={B,S} X45={A}V# ,
t
<u` ,$D
0
MX13={A}*
t
<z ,$D
0
pX24={B,S} X35={A}@
t
< `)@,$D
0
O X14={B,S}*
Dl
t,$D
0`B
t
0D8c``B
t
0D8c@Dl P
tP,$D
0`B
t
0D3f8c`B
t
0D3f8c@PH
t0h ? ̙33
$
(
x
 c$P
T

<PV,$D
0
JGrammar: S > AB, A > BC  a, B > AC  b, C > a  b
String w = ababa,K .fE

<Uu
:

<(`k
,$D
0
!=X11={A,C} X22={B,C} X33={A,C} X44={B,C} X55={A,C}> >

<
`),$D
0
O X12={B,S}*
h

<
q,$D
0
"X23={A} X34={B,S} X45={A}V# ,

<` ,$D
0
MX13={A}*

<4 ,$D
0
pX24={B,S} X35={A}@

< `)@,$D
0
O X14={B,S}*

<< @,$D
0
MX25={A}*

<4p,$D
0
MX15={A}* Dl `
`,$D
0`B

0D8c` `B

0D8cH
0h ? ̙33
8$(
8r
8 S\qrP
r
r
8 Srrr
H
80h ? ̙33
$(
r
SP
r
S
H
0h ? ̙33
$(
r
SP
r
S<
H
0h ? ̙33
$(
r
SP
r
S
H
0h ? ̙33
0$(
r
SP
r
S
H
0h ? ̙33
P0(
x
c$
P
x
c$
@
H
0h ? ̙33
p$(
r
Sh
P
r
S
H
0h ? ̙33
$(
r
S!
P
r
SX"
H
0h ? ̙33
$(
r
S
P
r
S4.
pp
H
0h ? ̙33
$(
r
S3
P
r
S:
H
0h ? ̙33
$(
r
SF
P
r
StG
0p
H
0h ? ̙33
$(
r
SQ
r
S0R
H
0h ? ̙33
NF0(
r
S\]
P
X
0`
<L
p
8Buffer
<`
@@
<
State of P^
6
<d
V
?Input: 0 0 1 1l ` `
`` ,$D
0ZB
s*D` {
<h
`
4h(0)
<k
5
3;
:
Stack
of PRB
s*D
l
,$D
0ZB
s*D {
<p
o?Read first remaining
symbol in buffer as
if it were input to P.@@H
0h ? ̙33
P:(
r
S
P
SĀ
"p`PpH
0h ? ̙33
p$(
r
S
P
r
S
H
0h ? ̙33
:(
r
S
P
S4
0`
"p`PpH
0h ? ̙33
$(
r
S
P
r
S
H
0h ? ̙33
$(
r
S4
P
r
S
`
H
0h ? ̙33
$(
r
S
P
r
S
H
0h ? ̙33
$(
r
S
P
r
S8
@
H
0h ? ̙33
0 L(
r
Sp
P
B
@
5DFA
<
̙p @
5PDA
<
; S
t
a
c
k
RB
s*D
P
P
RB
s*D
P
P
<<
5U
5InputRB
s*D RB
s*D `
<4
X
EAccept
if both
acceptRB
s*D@
RB
s*D@p
` l @$
@$
,$D
0`
0@0
<hr
$
OLooks like the
state of one PDA fB
6D8c0
H
0h ? ̙33
!P($(
(r
( SDP
r
( SP`
H
(0h ? ̙33
"p,$(
,r
, SP
r
, St
H
,0h ? ̙33
0@ (
X
C
u
SMu
@u
H
0h ? ̙33
0p,(
,X
, C
u
, Spu
@u
H
,0h ? ̙33
00(
0X
0 C
u
0 Sd~u
@u
H
00h ? ̙33
0<(
<X
< C
u
< Su
@u
H
<0h ? ̙33
0@(
@X
@ C
@ S
@
H
@0h ? ̙33
0H(
HX
H C
u
H Su
@u
H
H0h ? ̙33
0P(
PX
P C
u
P S̫u
@u
H
P0h ? ̙33
0X(
XX
X C
u
X Slu
@u
H
X0h ? ̙33
00h(
hX
h C
u
h Su
@u
H
h0h ? ̙33
0Pl(
lX
l C
l SX
@
H
l0h ? ̙33
0pp(
pX
p C
p SF
@
H
p0h ? ̙33
0x((
x^
x S
x c$
@
H
x0h ? ̙33
0((
^
S
c$d
@
H
0h ? ̙33
0(
X
C
S
@
H
0h ? ̙33
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$5C$CQ!$!Q_/$/_m=$=m{K$K{Y$Yg$gu$u$$$$$$$$#$#1$1?$?M$M[+$+[i9$9iwG$GwU$Uc$cq$q$$$$$$$$$$;$;I$IW'$'We5$5erB$BrP$P^$^l$lz$z$$$$$$$$($(6$6D$DR"$"R`0$0`n>$>nL$LZ$Zh$hv$v$$$&
&&&y&/v`vL
F8v`vf @Times New Romanv`vf . 2
f1 .iyH @"TahomavL
F8v`vf .'2
Properties of Context! !
# !. . 2
. .2
Free . .2
fU Languages!!!!.Q1 @"Tahomavi
HF8v`vf .$2
,Decision Propertiesx
. ."2
5Closure Properties
."Systemf
G&TNPP &՜.+,0$
(Onscreen ShowStanford University, CS Dept. \(## )Times New RomanTahomaMonotype SortsLucida Sans UnicodeSymbolDefault Design%Properties of ContextFree LanguagesSummary of Decision PropertiesNonDecision PropertiesTesting EmptinessTesting MembershipCYK AlgorithmCYK Algorithm (2)Example: CYK AlgorithmExample: CYK AlgorithmExample: CYK AlgorithmExample: CYK AlgorithmExample: CYK AlgorithmTesting InfinitenessClosure Properties of CFLsClosure of CFLs Under UnionClosure Under Union (2)Closure Under Union (3)%Closure of CFLs Under Concatenation"Closure Under Concatenation (2)Closure Under Star Closure of CFLs Under Reversal$Closure of CFLs Under Homomorphism$Example: Closure Under Homomorphism,Closure of CFLs Under Inverse HomomorphismArchitecture of PFormal Construction of PConstruction of P (2)Transitions of PProving Correctness of PNonclosure Under IntersectionNonclosure Under Difference%Intersection with a Regular LanguageDFA and PDA in ParallelFormal ConstructionFormal Construction (2)Fonts UsedDesign Template
Slide Titles#_8('JeffJeff
!"#$%&'()*+,./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{}~Root EntrydO)Current UserSummaryInformation(80PowerPoint Document(\(DocumentSummaryInformation8Root EntrydO)7W^~<Current UserPSummaryInformation(80PowerPoint Document(\((_8('Michael GoodrichMichael Goodrich