Unit 4
Unit 4
Course Instructor
Dr. Umadevi V
Department of CSE, BMSCE
Webpage:https://sites.google.com/site/drvumadevi/
Pushdown Automata
Definition of the Pushdown Automaton, The Languages of a PDA,
Equivalence of PDA’s and CFG’s , Deterministic Pushdown
Automata,
The Pumping Lemma for Context Free Languages, Closure
Properties of Context Free Languages
Input a a b b 𝞮
z0
Stack
𝞮 Input a a b b b 𝞮
Input a a b b
a
a
z0 z0
Stack Stack
𝞮 Input a a b b b 𝞮
Input a a b b
a a
a a
z0 z0
Stack Stack
Note: Unlike Finite Automata, DPDA and NPDA are not equivalent. For example,
the language
L={WWR, W ∈(a+b)*) } is accepted by NPDA but not by any DPDA
Construct PDA ( or DPDA) to recognize the language L={anbn, n>=1} by empty stack
method. Show the moves made by PDA for the string aabb and aaabb
a
q1 z0
a
Construct PDA ( or DPDA) to recognize the language L={anbn, n>=1} by empty stack
method. Show the moves made by PDA for the string aabb and aaabb
a, z0 | az0 b, a | 𝞮
b, a | 𝞮
q0 q1
a, a | aa 𝞮, Z0 | 𝞮
January 1, 2024 CSE, BMSCE 14
Construct PDA ( or DPDA) to recognize the language L={anbn, n>=1} by empty stack
method.
Q = { q 0 , q1 }
∑ = {a, b}
Γ ={a, Z0}
q0 = q0
Z0 = Z0
F={}
Push Operation
δ(q0 , a, z0) =(q0 , az0)
δ(q0 , a, a) =(q0 , aa)
δ(q0 , b, a) =(q1 , 𝞮) Pop Operation
δ(q1 , b, a) =(q1 , 𝞮)
δ(q1 , 𝞮, z0) =(q1 , 𝞮)
The current configuration of PDA at any given instant can be described by Instantaneous
Description (ID).
An ID gives current state of PDA, the remaining string to be processed and the entire contents of
stack.
Instantaneous Description for the string "aabb"
˫ (q , bb, aaz )
0 0
˫ (q , b, az )
1 0
˫ (q , 𝞮, z )
1 0
˫ (q , 𝞮, 𝞮)
1
˫ (q , abb, aaz )
0 0
˫ (q , bb, aaaz )
1 0
˫ (q , b, aaz )
1 0
˫ (q , 𝞮, az )
1 0
a
q1 z0
a
b, a | 𝞮
q0 q1
a, a | aaa 𝞮, Z0 | 𝞮
January 1, 2024 CSE, BMSCE 22
Construct PDA ( or DPDA) to recognize the language L={anb2n, n>=1} by empty stack
method.
Q = { q 0 , q1 }
∑ = {a, b}
Γ ={a, Z0}
q0 = q0
Z0 = Z0
F={}
˫ (q , bbbb, aaaaz )
0 0
˫ (q , bbb, aaaz )
1 0
˫ (q , bb, aaz )
1 0
˫ (q , b, az )
1 0
˫ (q , 𝞮, z )
1 0
˫ (q , 𝞮, 𝞮)
1
All the Input symbols
are read and Stack is
empty, therefore the string
“aabbbb” is accepted.
˫ (q , bbb, aaaaz )
0 0
˫ (q , bb, aaaz )
1 0
˫ (q , b, aaz )
1 0
˫ (q , 𝞮, az )
1 0
Solution:
Logic
Initial
a a a a b b 𝞮
State q0
a
q1 z0
a
q2 z0
a
b, a | 𝞮
b, a | 𝞮
a, z0 | z0 q2
q0 q1
a, a | a
a, z0 | az0 𝞮, Z0 | 𝞮
a, a | aa
Example Strings:
c , aca , bcb , aacaa , abcba , abbcbba
Logic: Push w on to stack, when c is seen switch to different state, for wr do the
Popping operation
q0 z0
a
b
q1 Z0
a
b
c, z0 | z0
q0 z0 Push a Push b q1
q0 q0 X c, a | a
c, b | b
a Push a Push b q1 q0 q1
q0 q0 X
b Push a Push b q1
q0 q0 X a,
b,
z0
z0
| az0
| bz0
a, a | 𝞮
b, b | 𝞮
q1 Z0 Pop Z0 a, a | aa 𝞮, Z0 | 𝞮
X X X q1 a, b | ab
b, b | bb
a Pop a
q1 X X X b, a | ba
b Pop b
X q1 X X
January 1, 2024 CSE, BMSCE 43
Design DPDA for the language L={WcWR, W ∈ (a+b)*} by empty stack.
Formal definition of PDA
P=(Q, ∑ , Γ , q0, Z0, δ, F)
Q = { q 0 , q1 }
∑ = {a, b, c}
Γ ={a, b, Z0}
q0 = q0
Z0 = Z0
F={}
δ(q0 , a, z0) =(q0 ,az0)
δ(q0 , b, z0) =(q0 ,bz0) Push Operation
δ(q0 , a, a) =(q0 ,aa)
δ(q0 , a, b) =(q0 ,ab)
δ(q0 , b, b) =(q0 ,bb)
δ(q0 , b, a) =(q0 ,ba)
No action
δ(q0 , c, z0) =(q1 ,z0)
δ(q0 , c, a) =(q1 ,a)
δ(q0 , c, b) =(q1 ,b)
Pop Operation
δ(q1 , a, a) =(q1 , 𝞮)
January 1, 2024 δ(q1 , b, b) =(q1 , 𝞮)
CSE, BMSCE 44
δ(q , 𝞮, z ) =(q , 𝞮)
Design DPDA for the language L={WcWR, W ∈ (a+b)*} by empty stack.
Rough Slide
˫ (q , bcbaa, aaz )
0 0
˫ (q , cbaa, baaz )
0 0
˫ (q , baa, baaz )
1 0
˫ (q , aa, aaz )
1 0
˫ (q , a, az )
1 0
˫ (q , 𝞮, z )
1 0
˫ (q , 𝞮, 𝞮)
1
All the Input symbols
are read and Stack is
empty, therefore the string
“aabcbaa” is accepted.
a Z0 Push a
b Z0 Push b
a a Push a
b a Pop a
a b Pop b
b b Push b
q0 z0
a
b
q1 Z0
a
b
q0 z0 Push a Push b q1
q0 q0
a Push a Pop a
q0 q0 X
b Pop b Push b
q0 q0 X
q1 Z0 Pop Z0
X X q1
a
X X X
b
January 1, 2024
X X X
CSE, BMSCE 49
Design DPDA for the language L={W, W ∈ (a+b)* and na(w)==nb(w)} by empty
stack.
˫ (q , babb, aaz )
0 0
˫ (q , abb, az )
0 0
˫ (q , bb, aaz )
0 0
˫ (q , b, az )
0 0
˫ (q , 𝞮, z )
0 0
˫ (q , 𝞮, z )
1 0
˫ (q , 𝞮, 𝞮)
1
All the Input symbols
are read and Stack is
empty, therefore the string
“aababb” is accepted.
a Z0 Push a
b Z0 Push b
a a Push a
b a Pop a
a b Pop b
b b Push b
𝞮 b Move to Final State
q0 z0 Push a Push b
q0 q0 X q0
𝞮, b | b
q1
a Push a Pop a
q0 q0 X
b Pop b Push b q1 a, z0 | az0 𝞮, b | b
q0 q0 b, z0 | bz0
a, a | aa
q1 Z0
X X X a,
b,
b
b
|𝞮
| bb
a
X X X b, a |𝞮
b q1
X X
January 1, 2024 CSE, BMSCE 52
Design Deterministic Push Down Automata for the language L={W, W ∈ (a+b)*
and na(w) < nb(w)} by final state.
Formal definition of PDA
P=(Q, ∑ , Γ , q0, Z0, δ, F)
Q = { q 0 , q1 }
∑ = {a, b}
Γ ={a, b, Z0}
q0 = q0
Z0 = Z0
F = {q1}
δ(q0 , a, z0) =(q0 ,az0)
δ(q0 , b, z0) =(q0 ,bz0) Push Operation
δ(q0 , a, a) =(q0 ,aa)
δ(q0 , b, b) =(q0 ,bb)
Pop Operation
δ(q0 , a, b) =(q0 , 𝞮)
δ(q0 , b, a) =(q0 , 𝞮)
No action
δ(q0 , 𝞮, b) =(q1 ,b)
δ(q 1 , for
Note: 𝞮, b) =(q
na(w) ,b)
>1 n b(w)
δ(q0 , 𝞮, a) =(q1 ,a)
δ(q1 , 𝞮, a) =(q1 ,a)
January 1, 2024 CSE, BMSCE 53
Design Deterministic Push Down Automata for the language L={W, W ∈ (a+b)*
and na(w) < nb(w)} by final state.
˫ (q , bab, z )
0 0
˫ (q , ab, bz )
0 0
˫ (q , b, z )
0 0
˫ (q , 𝞮, bz )
0 0
˫ (q , 𝞮, bz )
1 0
˫ (q , 𝞮, bz )
1 0
All the Input symbols
are read and reached to
Final state, therefore the string
“abbab” is accepted.
1 1 2 abbc
1 0 1 ab
0 1 1 bc
2 2 4 aabbbbcc
2 1 3 aabbbc
1 2 3 abbbcc
aibJck
Logic:
aibibkck
ai bi bk ck 𝞮
q0 z0
a
q1 Z0
q2 Z0
q3 Z0
q0 z0 Push a , q0 Push b, q1 X q3
a Push a , q0 Pop a, q1 X X
b X X X X
q1 Z0 X Push b, q1 X X
a X Pop a, q1 X X
b X Push b, q1 Pop b, q2 X
q2 Z0 X X X q3
a X X X X
b X X Pop b, q2 X
q3 Z0 X X X Pop z0, q3
a X X X X
b X X X X
January 1, 2024 CSE, BMSCE 58
Design Deterministic Push Down Automata for the language L={aibJck ,
J=i+k ,i,k≥0} by empty stack.
˫ (q , bbcc, z )
0 0
˫ (q , bcc, bz )
1 0
˫ (q , cc, bbz )
1 0
˫ (q , c, bz )
2 0
˫ (q , 𝞮, z )
2 0
˫ (q , 𝞮, z )
3 0
˫ (q , 𝞮, 𝞮)
3
a
q1 z0
a
q2 z0
a
or
b Z0 Push b, q0
a a Push a, q0 ; Pop a , q1
b a Push b, q0
a b Push a, q0
b b Push b, q0 ; Pop b, q1
Logic
Instantaneous Description for the string "abba" Input Stack Operation
Top
(q0, abba, z0)
a Z0 Push a, q0
b Z0 Push b, q0
a a Push a, q0 ; Pop a , q1
b a Push b, q0
a b Push a, q0
b b Push b, q0 ; Pop b, q1
𝞮 Z0 Change state to q2
𝞮 Z0 Pop Z0 , q2
˫ (q , ba,baz )
0 0
b Z0 Push b, q0
a a Push a, q0 ; Pop a , q1
(q0, a, bbaz0) (q1, a, az0) b a Push b, q0
a b Push a, q0
(q0, 𝞮, abbaz0)
(q1, 𝞮, z0) b b Push b, q0 ; Pop b, q1
Rejected
(q1, 𝞮, 𝞮)
Accepted
q0 z0
q1 Z0
a
b
q2 Z0
a
b
q0 z0 Push a , q0 Push b , q0 q2
a Push a , q0 Push b , q0 X
Pop a , q1
b Push a , q0 Push b , q0 X
Pop b , q1
q1 Z0 X X q2
a Pop a , q1 X X
b X Pop b , q1 X
q2 Z0 X X Pop Z0 , q2
a X X X
b X X X
January 1, 2024 CSE, BMSCE 69
Design NPDA for the language L={WWR, W ∈ (a+b)*} by empty stack.
δ(q1 , a, a) =(q1 , 𝞮)
δ(q1 , b, b) =(q1 , 𝞮)
a, z | AZ
b, A | AA
January 1, 2024 CSE, BMSCE 73
Question
Obtain CFG that generates the language accepted by the PDA M=({q0 , q1 }, {a,
b}, {A, Z}, q0 , Z , {q1} ,
{ δ(q0 , a, Z)=(q0, AZ),
δ(q0 , b, A)=(q0, AA),
δ(q0 , a, A)=(q1, 𝞮))
Solution:
For δ of the form Resulting Production
δ(qi , a, Z) = (qj, ε ) (qiZqj) → a
Solution (Contd…):
For δ of the form Resulting Production
δ(qi , a, Z) = (qj, AB) (qiZqk) → a(qjAql)(qlBqk)
where qk and ql will take all possible
values from Q
δ(q0 , a, Z)=(q0, AZ) (q0Zq0) → a(q0Aq0)(q0Zq0) | a(q0Aq1)(q1Zq0)
75
Solution (Contd…):
For δ of the form Resulting Production
δ(qi , a, Z) = (qj, AB) (qiZqk) → a(qjAql)(qlBqk)
where qk and ql will take all possible
values from Q
δ(q0 , a, Z)=(q0, AZ) (q0Zq0) → a(q0Aq0)(q0Zq0) | a(q0Aq1)(q1Zq0)
76
Solution (Contd…):
G=(V, T, P, S)
V= {(q0Zq1) , (q0Aq1) , (q0Zq0), (q0Aq0) ,
(q1Zq0) , (q1Zq1) , (q1Aq0) , (q1Aq1) }
T={a, b}
P={
(q0Aq1) → a
(q0Zq0) → a(q0Aq0)(q0Zq0) | a(q0Aq1)(q1Zq0)
(q0Zq1) → a(q0Aq0)(q0Zq1) | a(q0Aq1)(q1Zq1)
(q0Aq0) → b(q0Aq0)(q0Aq0) | b(q0Aq1)(q1Aq0)
(q0Aq1) → b(q0Aq0)(q0Aq1) | b(q0Aq1)(q1Aq1)
}
S=(q0Zq1)
Solution:
To obtain CFG from the PDA, all transitions should be of the form
δ(qi , a, Z) = (qj, AB)
or
δ(qi , a, Z) = (qj, ε )
In the given transitions except the second transition, all transitions are in the required form. So, let us
take the second transition
δ(q0 , a, A)=(q0, A)
This transition indicates that when input symbol a is encountered and top stack symbol is A, the PDA
remains in the state q0 and contents of the stack are not altered. This can be interpreted as delete A
from stack and insert A onto the stack. So once A is deleted from the stack we enter into a new state
q3. But in state q3 without consuming any input we add A onto the stack. The corresponding
transitions are
δ(q0 , a, A)=(q3, 𝞮)
δ(q3 , 𝞮, Z)=(q0, AZ)
Solution (Contd…):
So the given PDA can be written using the following transitions
δ(q0 , a, Z)=(q0, AZ)
δ(q0 , a, A)=(q3, 𝞮)
δ(q3 , 𝞮, Z)=(q0, AZ)
δ(q0 , b, A)=(q1, 𝞮)
δ(q1 , 𝞮, Z)=(q2, 𝞮)
Solution (Contd…):
So the given PDA can be written using the following transitions
δ(q0 , a, Z)=(q0, AZ) , δ(q0 , a, A)=(q3, 𝞮), δ(q3 , 𝞮, Z)=(q0, AZ)
δ(q0 , b, A)=(q1, 𝞮) , δ(q1 , 𝞮, Z)=(q2, 𝞮)
For δ of the form Resulting Production
δ(qi , a, Z) = (qj, AB) (qiZqk) → a(qjAql)(qlBqk)
where qk and ql will take all possible
values from Q
δ(q0 , a, Z)=(q0, AZ) (q0Zq0) → a(q0Aq0)(q0Zq0) | a(q0Aq1)(q1Zq0) |
a(q0Aq2)(q2Zq0) | a(q0Aq3)(q3Zq0)
Solution (Contd…):
So the given PDA can be written using the following transitions
δ(q0 , a, Z)=(q0, AZ) , δ(q0 , a, A)=(q3, 𝞮), δ(q3 , 𝞮, Z)=(q0, AZ)
δ(q0 , b, A)=(q1, 𝞮) , δ(q1 , 𝞮, Z)=(q2, 𝞮)
For δ of the form Resulting Production
δ(qi , a, Z) = (qj, AB) (qiZqk) → a(qjAql)(qlBqk)
where qk and ql will take all possible values from Q
δ(q3 , 𝞮, Z)=(q0, AZ) (q3Zq0) → (q0Aq0)(q0Zq0) | (q0Aq1)(q1Zq0) |
(q0Aq2)(q2Zq0) | (q0Aq3)(q3Zq0)
The steps to be followed to convert a grammar G=(V,T,P,S) to its equivalent PDA are
1. Convert the grammar to GNF
2. Let q0 be the start state and z0 is initial symbol on stack. Without consuming any input,
push the start symbol S onto the stack and change state to q1
The transition for this can be δ(q0, ε, z0)=(q1,Sz0)
3. For each production of the form A -> aβ introduce the transition
δ(q1 , a, A)=(q1, β)
4. Finally, in state q1 , without consuming any input change the state to qf which is an
accepting state. The transition can be of the form δ(q1 , ε, z0)=(qf, z0)
Solution:
Step1: Convert the grammar to GNF
The given grammar is in GNF
Step2: Let q0 be the start state and z0 is initial symbol on stack. Without consuming any
input, push the start symbol S onto the stack and change state to q1
The transition for this can be δ(q0, ε, z0)=(q1,Sz0)
Solution (Contd…):
Step3: For each production of the form A -> aβ introduce the transition δ(q1 , a, A)=(q1,
β)
Production Transition
S → aABC
A → aB
A →a
B → bA
B →b
C →a
Solution (Contd…):
Step3: For each production of the form A -> aβ introduce the transition δ(q1 , a, A)=(q1,
β)
Production Transition
S → aABC δ(q1 , a, S)=(q1, ABC)
A → aB δ(q1 , a, A)=(q1, B)
A →a δ(q1 , a, A)=(q1, 𝞮)
B → bA δ(q1 , b, B)=(q1, A)
B →b δ(q1 , b, B)=(q1, 𝞮)
C →a δ(q1 , a, C)=(q1, 𝞮)
Step4:Finally, in state q1 , without consuming any input change the state to qf which is an
accepting state. The transition can be of the form δ(q1 , ε, z0)=(qf, z0)
δ(q0, ε, z0)=(q1,Sz0)
δ(q1 , a, S)=(q1, ABC)
δ(q1 , a, A)=(q1, B)
δ(q1 , a, A)=(q1, 𝞮)
δ(q1 , b, B)=(q1, A)
δ(q1 , b, B)=(q1, 𝞮)
δ(q1 , a, C)=(q1, 𝞮)
δ(q1 , ε, z0)=(qf, z0)
Transitions of PDA
δ(q0, ε, z0)=(q1,Sz0)
δ(q1 , a, A)=(q1, B)
δ(q1 , a, A)=(q1, 𝞮)
δ(q1 , b, B)=(q1, A)
δ(q1 , b, B)=(q1, 𝞮)
δ(q1 , a, C)=(q1, 𝞮)
˫ (q , abba, ABCz )
1 0
δ(q0, ε, z0)=(q1,Sz0)
The general strategy used to prove that a given language is not CFL
is shown below:
1. Assume that the language L is infinite and it is context free
2. Select string say z and break it into sub strings u, v, w, x and y
such that |z|>=n,
z=uvwxy where |vwx| <= n , |vx| >=1
3. Find any i such that uviwxiy ∉ L . According to pumping lemma
uviwxiy ∈ L . So, the result is a contradiction to the assumption
that the language is context free. Therefore, the given language L
is not context free.
|vwx| =|ajakal|=(j+k+ l) ≤ n
January 1, 2024 CSE, BMSCE 103
Question
Show that the language L={anbncn, n≥0} is not Context Free Language (CFL).
Solution (Contd…):
Step3: For all i, uviwxiy ∈ L.
Solution:
Step1: Let L be CFL and Let z= anbnanbn ∈ L
Step2: Note that |z|=| anbnanbn |=4n >= n
Split z into uvwxy such that |vwx| ≤ n and |vx| ≥ 1
Solution:
Step1: Let L be CFL and Let z= 0n2 ∈ L
Step2: Note that |z|=| 0n2|=n2 ≥ n
Split z into uvwxy such that |vwx| ≤ n and |vx| ≥ 1
Step 3: For all i, uviwxiy ∈ L.
Solution:
Step1: Let L be CFL and Let z= 0n2 ∈ L
Step2: Note that |z|=| 0n2|=n2 ≥ n
Split z into uvwxy such that |vwx| ≤ n and |vx| ≥ 1
Step 3: For all i, uviwxiy ∈ L.
Let |vx| = m , m ≤ n.
But for i=2,
n2 < |uv2wx2y| = n2+m ≤ (n2 + n) < (n+1)2
And hence the length is nit a perfect square and therefore string is not in L. This
contradiction allows us to conclude that our assumption was wrong and L is not CFL.
an!-(j+k+l)a2jaka2l = an!+j+l
|an!+j+l|= n!+j+l ≤ n!+n
< n!+n!(n)
< n!(n+1)
119
CFLs are closed under Union Operation
Let L1 and L2 be two CFL’s generated by CFGs G1=(V1, T1, S1, P1) and G2
=(V2, T2, S2, P2)
120
CFLs are closed under Union Operation
Let L1 and L2 be two CFL’s generated by CFGs G1=(V1, T1, S1, P1) and G2
=(V2, T2, S2, P2)
To get grammar for L1 L2 ?
Add new start symbol S and rules S S1 | S2
We get grammar G = (V, T, P, S) where
V = V1 V2 { S }, where S V1 V2
P = P 1 P2 { S S1 | S 2 }
121
CFLs are closed under Union Operation
Let L1 and L2 be two CFL’s generated by CFGs G1=(V1, T1, S1, P1) and G2
=(V2, T2, S2, P2)
To get grammar for L1 L2 ?
Add new start symbol S and rules S S1 | S2
We get grammar G = (V, T, P, S) where
V = V1 V2 { S }, where S V1 V2
P = P 1 P2 { S S1 | S 2 }
Example:
L 1 = { a n b n | n 0 } , L 2 = { b n an | n 0 }
G1 : S1 aS1b | G2 : S2 bS2a |
L1 L2 is G = ({S1, S2 , S}, {a, b}, P, S) where
P = {P1 P2 {S S1 | S2 }}
Union of two CFLs results in CFL.
122
CFLs are closed under Concatenation Operation
Let L1 and L2 be two CFL’s generated by CFGs G1=(V1, T1, S1, P1) and G2
=(V2, T2, S2, P2)
To get grammar for L1L2 ?
Add new start symbol S and rule S S1S2
We get G = (V, T, P, S) where
V = V1 V2 { S }, where S V1 V2
P = P 1 P 2 { S S 1 S2 }
Example:
L1 = { anbn | n 0 } with G1: S1 aS1b |
L2 = { bmam | m 0 } with G2 : S2 bS2a |
L1L2 = { anb{n+m}am | n, m 0 } with G = ({S, S1, S2}, {a, b},
{S S1S2, S1 aS1b | , S2 bS2a}, S)
Concatenation of Two CFLs results in a CFL
123
CFLs are closed under Kleene’s-Closure or Star-
Closure Operation
124
Context-free languages are not closed under Intersection
126
Context-free languages are not closed under Complement
If the family of CFL’s were closed under Complementation then the right side
of the above expression would be a CFL for any L1 and L2. But this contradicts
what we have just shown in previous slide that the intersection of two CFLs is
not necessarily Context free.
Consequently, the family of CFL is not closed under Complementation
128
Reversal
The CFL’s are closed under reversal
This means then if L is a CFL, so LR is a CFL
It is enough to reverse each production of a CFL for L, i.e.,
substitute A by AR
Example:
L = { anbn | n 0 } with P : S aSb |
LR = {bnan | n 0 } with PR : S bSa |
129
Homomorphism
Closure under homomorphism of CFL L for every a
Suppose L is a CFL over alphabet and h is a homomorphism
on .
Let s be a substitution that replaces every a , by h(a). i.e., s(a)
= {h(a)}.
Then h(L) = s(L).
h(L) ={h(a1)…h(ak) | k 0} where h(ak) is a homomorphism for
every ak .
130
Inverse homomorphism
To recall: If h is a homomorphism, and L is any language, then h -
1
(L), called an inverse homomorphism, is the set of all strings w
such that h(w)L
The CFL’s are closed under inverse homomorphism.
Theorem: If L is a CFL and h is a homomorphism, then h-1(L) is a
CFL
131
Inverse homomorphism – proof
Buffer
a h(a)
Input h
Accept/
PDA
Reject
Stack
132
Proof Contd...
After input a is read, h(a) is placed in a buffer.
Symbols of h(a) are used one at a time and fed to PDA being
simulated.
Only when the buffer is empty does the PDA read another of its
input symbol and apply homomorphism to it.
133
Proof Contd...
Suppose h applies to symbols of alphabet Σ and produces
strings in T*.
Let PDA P = (Q, T, Γ, δ, q0, Z0, F) that accept CFL L by
final state.
Construct a new PDA P = (Q, Σ, Γ, δ, (q0, ), Z0, F X {})
to simulate language of h-1(L), where
Q is the set of pairs (q, x) such that
q is a state in Q
x is a suffix of some string h(a) for some input string a in Σ
134
Proof Contd...
δ is defined by
δ((q, ), a, X) = {((q, h(a)),a,X)}
If δ(q, b, X) = {(p, )} where bT or b = then δ((q, bx), , X) = {((p, x), )}
The start state of P’ is (q0, )
The accepting state of P is (q, ), where q is an accepting state of P.
(q0,h(w),Z0)|-*P (p,,) iff ((q0,),w,Z0) |-*P ((p, ), , )
P accepts h(w) if and only if P accepts w, because of the way the accepting states of
P are defined.
Thus L(P)=h-1(L(P))
135
Intersection with RL
FA Accept/
AND Reject
PDA
Stack
136
Intersection with RL Proof
P=(QP, , , P, qP, Z0, FP) be PDA to accept CFL by final
state
A=(QA, , A, qA, FA) be a DFA for RL
Construct PDA P = (Q, , , , qo, Z0, F) where
Q = Qp X QA
qo= (qp, qA)
F = (FP X FA)
is in the form ((q, p), a, X) = ((r, s), ) such that
1. s = A(p, a)
2. (r, ) is in P(q, a, X)
137
Proof Contd…
For each move of PDA P, we make the same move in PDA P and
also we carry along the state of DFA A in a second component of
P.
P accepts a string w iff both P and A accept w.
w is in L R.
The moves ((qp, qA), w, Z) |-*P ((q, p), , ) are possible iff (qp,
w, Z) |-*P (q, , ) moves and p = *(qA, w) transitions are
possible.
138
Set Difference with RL
For a CFL’s L, and a regular language R.
L - R is a CFL.
Proof:
R is regular and RC is also regular
L - R = L RC
Complement of Regular Language (RC ) is regular
Intersection of a CFL and a regular language is CFL
CFL and Regular language are closed under intersection.
139
Complementation
LC is not necessarily a CFL
Proof:
Assume that CFLs were closed under complement.
If L is a CFL then LC is a CFL
Since CFLs are closed under union, L1C L2C is a CFL
And by our assumption (L1C L2C) C is a CFL
But (L1C L2C) C = L1 L2 which we just showed isn’t
necessarily a CFL.
Contradiction!
140
Substitution
141
Substitution
Theorem: If a substitution s assigns a CFL to every symbol in the alphabet
of a CFL L, then s(L) is a CFL.
Proof
Let G = (V, , P, S) be grammar for L
Let Ga= (Va, Ta, Pa, Sa) be the grammar for each a with VVa
=
G= (V, T, P, S) for s(L) where
V = V Va
T = union of Ta for all a
P consists of
All productions in any Pa for a
In productions of P, each terminal a is replaced by S a
A detailed proof that this construction works is in the reader.
Intuition: this replacement allows any string in La to take the place
of any occurrence of a in any string of L.
142
Example (1)
143
Example(1) Contd...
In the first grammar replace 0 by S0 and 1 by S1. The combined
grammar:
144
Application of Substitution
Closure under union of CFL’s L1 and L2
Closure under concatenation of CFL’s L1 and L2
Closure under Kleene’s star (closure * and positive
closure +) of CFL’s L1
Closure under homomorphism of CFL Li for every
ai
145
Thanks for Listening