Uploaded by NIKHIL YADAV

Unit IV PUSHDOWN AUTOMATA AND POST MACHINES

advertisement
Unit IV
PUSHDOWN AUTOMATA AND
POST MACHINES
Jagadish K Kamble (M.Tech, IIT Kharagpur)
Assistant Professor,
Dept. of Information Technology,
Pune Institute of Computer Technology, Pune.
1
FA +Stack =Pushdown Automaton -- PDA
Input String
Stack
States
What is?
◼
FA to Reg Lang, PDA is to CFL
Formal Definition
Pushdown Automaton (PDA)
M = (Q, Σ, Γ, δ, q0 , z , F )
States
Input
alphabet
Transition Initial
Stack
function
state
alphabet
Accept
states
Stack
start
symbol
Transition Function: δ
Deterministic PDA:
δ(Q x {∑ U ε} x Г)=Q x Г*
Non-Deterministic PDA:
Q x Г*
δ(Q x {∑ U ε} x Г)=2
δ(Q
Г)=Q
Q x {∑
∑ U ε}
ε xГ
Q x Г*
Pop
symbol
Input
symbol
input

a

q1
a, b → c
stack
States
b
h
e
$
Push
symbol
q2
stack
top
c
h
e
$
Initial Stack Symbol
stack
head
Stack
Stack
$
z
bottom special symbol
Appears at time 0
top
The States
Pop
symbol
Input
symbol
q1
a, b → c
Push
symbol
q2
q1
a, b → c
q2
input

a


a
stack
b
h
e
$
top
Replace
c
h
e
$

q1
a, b → 
q2
input

a


a
stack
b
h
e
$
top
Pop
h
e
$

q1
a,  → 
q2
input

a


a
stack
b
h
e
$
top
No Change
b
h
e
$

Pop from Empty Stack
q1
input

a
a, b → c
q2

Pop
stack
Automaton halts!
top
If the automaton attempts to pop from
empty stack then it halts and rejects input
Non-Determinism
PDAs are non-deterministic
Allowed non-deterministic transitions
a, b → c
q2
q1
a, b → c
q1
, b → c
 − transition
q3
q2
Example PDA
PDA
M
L( M ) = {a b : n  1}
n n
:
a, a → aa
a,$ → a$
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
L( M ) = {a b : n  0}
n n
Basic Idea:
1. Push the a’s
on the stack
a, a → aa
a,$ → a$
2. Match the b’s on input
with a’s on stack
b, a → 
3. Match
found
b,
a
→


,
$
→
$
q3
q2
q1
a, a → aa
a,$ → a$
b, a → 
Transition
Diagram
b,
a
→


,
$
→
$
q3
q2
q1
Transition
function
δ( q1x ax $)=(q1,a$)
δ( q1x ax a)=(q1,aa)
δ( q1x bx a)=(q2,ε)
δ( q2x bx a)=(q2,ε)
δ( q2x ε x $)=(q3,$)
PDA Acceptance by Final State
a, a → aa
a,$ → a$
b, a → 
b,
a
→

q2
q1
Transition
function
Transition
Diagram
 ,$ → 
δ( q1x ax $)=(q1,a$)
δ( q1x ax a)=(q1,aa)
δ( q1x bx a)=(q2,ε)
δ( q2x bx a)=(q2,ε)
δ( q2x ε x $)=(q2,ε)
PDA Acceptance by Empty Stack
Final State
PDA
ACCEPTANCE
Empty Stack
Execution Example: Time 0
Input
a
a
a
b
b
b
$
Stack
a, a → aa
a,$ → a$
Current/
initial
state
b, a → 
b, a →  q , $ → $ q
q1
3
2
Time 1
Input
a a a b
b b
a
$
Stack
a, a → aa
a,$ → a$
b, a → 
b, a →  q , $ → $ q
q1
3
2
Time 2
Input
a a a b
a
a
$
b b
Stack
a, a → aa
a,$ → a$
b, a → 
b, a →  q , $ → $ q
q1
3
2
Time 3
a
a
a
$
Input
a a a b
b b
Stack
a, a → aa
a,$ → a$
b, a → 
b, a →  q , $ → $ q
q1
3
2
Time 4
Input
a a a b
b b
a
a
a
$
Stack
a, a → aa
a,$ → a$
b, a → 
q1 b, a → 

,
$
→
$
q2
q3
Time 5
Input
a a a b
a
a
$
b b
Stack
a, a → aa
a,$ → a$
b, a → 
q1 b, a → 

,
$
→
$
q2
q3
Time 6
Input
a a a b
a
$
b b
Stack
a, a → aa
a,$ → a$
b, a → 
q1 b, a → 

,
$
→
$
q2
q3
Time 7
Input
a a a b
b b
$
Stack
a, a → aa
a,$ → a$
b, a → 
q1 b, a → 
q2 , $ → $
q3
A string is accepted if there is
a computation such that:
All the input is consumed
AND
The last state is an accepting state
we do not care about the stack contents
at the end of the accepting computation
Rejection Example:
Time 0
Input
a
a b
$
Stack
a, a → aa
a,$ → a$
Current State
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
Rejection Example:
Time 2
Input
a
a
a b
$
Stack
a, a → aa
a,$ → a$
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
Rejection Example:
Time 3
Input
a
a
a b
a
$
Stack
a, a → aa
a,$ → a$
current
state
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
Rejection Example:
Time 4
Input
a
a
a
a b
$
Stack
a, a → aa
a,$ → a$
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
Rejection Example:
Time 4
Input
a
a
a
a b
$
Stack
a, a → aa
a,$ → a$
reject
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
There is no accepting computation for
The string
aab
aab is rejected by the PDA
a, a → aa
a,$ → a$
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
Example PDA
PDA M :L(M) such that na(w)=nb(w),w€(a,b)*
a, a → aa
a,$ → a$
q1 , $ → $
b, b → bb
b,$ → b$
b, a → 
a,b → 
q2
Example PDA
PDA M :L(M) such that anbncm| n, m>=1
a, a → aa
a,$ → a$
b, a → 
b,
a
→

q2
q1
c,$ → $
c,$ → $
q3
, $ → $
Review
•
•
•
•
•
•
•
•
PDA
Formal Definition of PDA
Transition Function
Transition Diagram
Design of PDA
Examples
Acceptance by Final State
Acceptance by Empty Stack
Example PDA
PDA M :L(M) such that anbncm| n, m>=1
a, a → aa
a,$ → a$
b, a → 
b,
a
→

q2
q1
c,$ → $
Acceptance by final state
c,$ → $
, $ → $ q
q3
4
Example PDA
PDA M :L(M) such that anbncm| n, m>=1
a, a → aa
a,$ → a$
b, a → 
b,
a
→

q2
q1
c,$ → $
Acceptance by final state
c,$ → $
q3
, $ → $
Example PDA
PDA M :L(M) such that anbncm| n, m>=1
a, a → aa
a,$ → a$
b, a → 
b,
a
→

q2
q1
c,$ → $
Acceptance by Empty
stack
c,$ → $
q3
 ,$ → 
Example PDA
PDA
M
L( M ) = {a b : n  1}
n n
:
a, → a
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
Problems
1. Construct PDA that accepts language
L = { an bm cn | m, n > 1}
(Nov-2017 EndSem 8 Marks)
2.Design a PDA for the language
L = {an bm cn | m, n > =l} by empty stack.
(Nov-2016 EndSem 8 Marks)
Example PDA
PDA M :L(M) such that anbmcn| n, m>=1
a, a → aa
a,$ → a$
b,a → a
c,a → 
b
,
a
→
a
q2 c,a →  q3 , $ → $ q3
q1
Acceptance by final state
Example PDA
PDA M :L(M) such that anbmcn| n, m>=1
a, a → aa
c,a → 
a,$ → a$
b,a → a
b
,
a
→
a
q2 c,a →  q3
q1
 ,$ → 
Acceptance by Empty Stack
Example PDA
2.Construct PDA to check for well formedness
of paranthesis.
(Nov-2017 EndSem 8 Marks)
(, (→ ((
(,$ → ($
, $ → $ q
q1
3
),(→ 
Acceptance by
final state
Construct a PDA for the language described as “The set of
all strings over ∑= {a, b} with equal no. of a’s and b’s.
(Nov-2017 EndSem 8 Marks)
a, a → aa
a,$ → a$
q1 , $ → $
b, b → bb
b,$ → b$
b, a → 
a,b → 
q2
Example PDA
PDA M :L(M) such that anb2n| n>=1
(Nov-2017 EndSem 8 Marks)
a, a → aaa
a,$ → aa$
b,a → 

,
$
→
$
b,
a
→

q3
q2
q1
Review
• PDA Examples
• Acceptance by Final State
• Acceptance by Empty Stack
Another PDA example
L( M ) = {w  {a, b} : na ( w) = nb ( w)}
*
PDA
a, $ → 0$
a, 0 → 00
a, 1→ 
M
b, $ →1$
b, 1 → 11
b, 0 → 
q1
, $ → $
q2
Example PDA
PDA M :L(M) such that na(w)>nb(w),w€(a,b)*
a, a → aa
a,$ → $
a,$ → a$
q1
b, b → bb
b,$ → b$
a,$ → $
b, a → 
a,b → 
q2
, $ → $ q
3
Example PDA
PDA M :L(M) such that na(w)<nb(w),w€(a,b)*
a, a → aa
b,$ → $
a,$ → a$
q1
b, b → bb
b,$ → b$
b,$ → $
b, a → 
a,b → 
q2
, $ → $ q
3
Example PDA
PDA M :L(M) such that anbm+ncn| n, m>=1
a, a → aa
c,b → 
a,$ → a$
b,a → 
b,
a
→

c,
b
→


,
$
→
$
q
q2
q1
q3
3
b,$ → b$
b, b → bb
Another PDA example
PDA
M
:

L( M ) = {vcv : v  {a, b} }
R
a,$ → a b,$ → b
a,a → aa b,b → bb
a,b → ab b,a → ba
a,  → a
a, a → 
b,  → b
b, b → 
q0
c,a → a
c,b → b
q1
, $ → $
q2
Formalities for PDAs
q1
a , w1 → w 2
q2
Transition function:
 (q1 , a ,w 1 ) = {(q2 ,w 2 )}
a , w1 → w 2
q2
q1
a , w1 → w 3
q3
Transition function:
 (q1 , a ,w 1 ) = {(q2 ,w 2 ), (q3,w 3 )}
DPDA and NDPDA
• The main (and only) difference between DPDA and NPDA is
that DPDAs are deterministic, whereas NPDAs are nondeterministic.
• With some of notation, we can say that NPDAs are a
generalization of DPDAs: every DPDA can be simulated by
an NPDA, but the converse doesn't hold (there are some
context-free languages which cannot be accepted by a
DPDA).
• Every DPDA contain equivalent NPDA,
• but, every NPDA may not
sometimes.
contain equivalent DPDA
NPDA example
L( M ) = {w  {a, b} : aibjckdm |i=k or j=m }
*
L(M) ={anbjcndm }U {aibnckdn}
a,$|a$
q1
q2
, $ → $ q
3
q4
q5
, $ → $
q0
a,$|$
q6
PDA
M
L( M ) = {vv : v  {a, b} }
:
a,$ → a
a,a → aa
a,b → ab
q0

R
a, a → 
b, b → 
a, a → 
b, b → 
b,$ → b
b,b → bb
b,a → ba
q1
, $ → $
q2
PDA
M
L(M ) = {vv : v  {a, b} }
:
1. Push v
on stack
a,$ → a
a,a → aa
a,b → ab
q0

R
2. Guess
middle
of input
a, a → 
a, a → 
b, b → 
b,$ → b
b,b → bb
b,a → ba
3. Match v R on input
with v on stack
b, b → 
q1
4. Match
found
, $ → $
q2
Execution Example:
Input
a b
b
a
a,$ → a
a,a → aa
a,b → ab
q0
a, a → 
b, b → 
b,$ → b
b,b → bb
b,a → ba
Time 0
$
a, a → 
b, b → 
q1
, $ → $
q2
Time 1
Input
a b
b
a
a,$ → a
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
a
$
a, a → 
Stack
b, b → 
a, a → 
b, b → 
q1
, $ → $
q2
Time 2
Input
a b
b
a,$ → a
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
b
a
$
a
a, a → 
b, b → 
q1
, $ → $
Stack
q2
Time 3
Input
a b
b
a
a,$ → a
a,a → aa
a,b → ab
q0
a, a → 
b, b → 
b,$ → b
b,b → bb
b,a → ba
Guess the middle
of string
a, a → 
Stack
b, b → 
q1
, $ → $
b
a
$
q2
Time 4
Input
a b
b
a,$ → a
a,a → aa
a,b → ab
q0
a, a → 
b, b → 
b,$ → b
b,b → bb
b,a → ba
b
a
$
a
a, a → 
b, b → 
q1
, $ → $
Stack
q2
Time 5
Input
a b
b
a
a,$ → a
a,a → aa
a,b → ab
q0
a, a → 
b, b → 
b,$ → b
b,b → bb
b,a → ba
a
$
a, a → 
Stack
b, b → 
q1
, $ → $
q2
Time 6
Input
a b
b
a
a,$ → a
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
$
a, a → 
b, b → 
q1
, $ → $
Stack
q2
accept
Rejection Example:
Time 0
Input
a b
b
b
a,$ → a
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
$
a, a → 
Stack
b, b → 
a, a → 
b, b → 
q1
, $ → $
q2
accept
Time 1
Input
a b
b
b
a,$ → a
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
a
$
a, a → 
b, b → 
q1
, $ → $
Stack
q2
Time 2
Input
a b
b
b
a,$ → a
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
b
a
$
a, a → 
Stack
b, b → 
a, a → 
b, b → 
q1
, $ → $
q2
Time 3
Input
a b
b
a,$ → a
b Guess the middle
of string
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
b
a
$
a, a → 
b, b → 
q1
, $ → $
Stack
q2
Time 4
There is no possible transition.
Input
a b
b
b
a,$ → a
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
a
$
Input is not
consumed
Stack
a, a → 
b, b → 
a, a → 
b, b → 
q1
, $ → $
q2
Another computation on same string:
Input
a b
Time 0
b
b
a,$ → a
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
$
a, a → 
b, b → 
q1
, $ → $
Stack
q2
Time 1
Input
a b
b
b
a,$ → a
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
a
$
a, a → 
Stack
b, b → 
a, a → 
b, b → 
q1
, $ → $
q2
Time 2
Input
a b
b
b
a,$ → a
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
b
a
$
a, a → 
b, b → 
q1
, $ → $
Stack
q2
Time 3
b
b
a
$
Input
a b
b
b
a,$ → a
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
a, a → 
b, b → 
q1
, $ → $
Stack
q2
Time 4
b
b
b
a
$
Input
a b
b
b
a,$ → a
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
a, a → 
b, b → 
q1
, $ → $
Stack
q2
Time 5
Input
a b
There is no possible transition.
b
b
a,$ → a
a, a → 
b, b → 
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
No accept state
is reached
a, a → 
b, b → 
q1
, $ → $
b
b
b
a
$
Stack
q2
There is no computation
that accepts string abbb
a,$ → a
a,a → aa
a,b → ab
q0
b,$ → b
b,b → bb
b,a → ba
abbb  L(M )
a, a → 
b, b → 
a, a → 
b, b → 
q1
, $ → $
q2
PDA for Lwwr: Transition Diagram
Grow stack
0, Z0/0Z0
1, Z0/1Z0
0, 0/00
0, 1/01
1, 0/10
1, 1/11
q0
Pop stack for
matching
symbols
0, 0/ 
1, 1/ 
, Z0/Z0
, 0/0
, 1/1
q1
Switch to
popping mode
This would be a non-deterministic PDA
, Z0/Z0
∑ = {0, 1}
= {Z0, 0, 1}
Q = {q0,q1,q2}
q2
Go to acceptance
How does the PDA for Lwwr
work on input “1111”?
All moves made by the non-deterministic PDA
(q0,1111,Z0)
(q0,111,1Z0)
(q0,11,11Z0)
(q0,1,111Z0)
(q1,1111,Z0)
(q1,111,1Z0)
Path dies…
Path dies…
(q1,11,11Z0)
(q1,1,111Z0)
(q1,1,1Z0)
(q1, ,1111Z0)
(q1, ,11Z0)
(q1, ,Z0)
Path dies…
Path dies…
(q0,,1111Z0)
(q2, ,Z0)
Acceptance by
final state:
= empty input
AND
final state
79
Instantaneous Description
( q, u , s )
Current
state
Remaining
input
Current
stack
contents
PDA’s Instantaneous Description (ID)
A PDA has a configuration at any given instance:
(q,w,y)
◼
◼
◼
q - current state
w - remainder of the input (i.e., unconsumed part)
y - current stack contents as a string from top to bottom of
stack
If δ(q,a, X)={(p, A)} is a transition, then the following are also true:
◼ (q, a, X ) |--- (p,,A)
◼ (q, aw, XB ) |--- (p,w,AB)
|--- sign is called a “turnstile notation” and represents one
move
|---* sign represents a sequence of moves
81
Then the following move is possible:
(q1, aW, xZ) |--- (q2, W, yZ)
where W indicates the rest of the string following the a, and
Z indicates the rest of the stack contents underneath the x.
This notation says that in moving from state q1 to state q2, an
a is consumed from the input string aW, and the x at the top
(left) of the stack xZ is replaced with y, leaving yZ on the
stack.
Example:
Instantaneous Description
(q1, bbb, aaa$)
Time 4:
a
Input
a
a
a
b
b
b
a,a → aa
a,$ → a$
b, a → 
a
a
$
Stack
b,
a
→


,
$
→
$
q3
q2
q1
Example:
Instantaneous Description
(q2 , bb, aa$)
Time 5:
a
Input
a
a
a
b
b
b
a,a → aa
a,$ → a$
b, a → 
a
a
$
Stack
b,
a
→


,
$
→
$
q3
q2
q1
We write:
(q1, bbb, aaa$)  (q2 , bb, aa$)
Time 4
Time 5
A computation:
(q0 , aaabbb,$)  (q1, aaabbb,$) 
(q1, aabbb, a$)  (q1, abbb, aa$)  (q1, bbb, aaa$) 
(q2 , bb, aa$)  (q2 , b, a$)  (q2 ,  ,$)  (q3 ,  ,$)
a,a → aa
a,$ → a$
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
(q0 , aaabbb,$)  (q1, aaabbb,$) 
(q1, aabbb, a$)  (q1, abbb, aa$)  (q1, bbb, aaa$) 
(q2 , bb, aa$)  (q2 , b, a$)  (q2 ,  ,$)  (q3 ,  ,$)
For convenience we write:

(q0 , aaabbb,$)  (q3 ,  ,$)
Language of PDA
Language
L(M )
accepted by PDA M :

L( M ) = {w : (q 0 , w,$)  (q f ,  ,$)}
Initial state
Accept state
Example:

(q0 , aaabbb,$)  (q3 ,  ,$)
aaabbb  L(M )
PDA M :
a,a → aa
a,$ → a$
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1

(q0 , a b ,$)  (q3 ,  ,$)
n n
a b  L(M )
n n
PDA M :
a,a → aa
a,$ → a$
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
Therefore:
PDA M :
L( M ) = {a b : n  0}
n n
a,a → aa
a,$ → a$
b, a → 
b,
a
→


,
$
→
$
q3
q2
q1
Review
• DPDA and NPDA
• Instantaneous Description (IDs)
1) am+nbmcn|n,m>1
DCFL
CFL
2) ambm+ncn|n,m>1
DCFL
CFL
3) anbmcm+n|n,m>1
DCFL
CFL
4) ambmcndn|n,m>1
DCFL
CFL
5) ambncmdn|n,m>1
Not DCFL Not CFL
6) ambncndm|n,m>1
DCFL
CFL
7) ambicmdk|n,m>1
DCFL
CFL
8) ambn|m>n
DCFL
CFL
9) amb2m|m>1
DCFL
CFL
1) anbn2|m,n>1
2) amb2n |n,m>1
Not DCFL
Not DCFL
Not CFL
Not CFL
3) wwR|w€(a,b)*
NDCFL
4) ww| w€(a,b)*
Not DCFL
5) anbncm|n>m
Not DCFL Not CFL
6) anbncndn|n<1010
DCFL
7) amb2mc3m|m>1
8) xcy| x,y€(a,b)*
9) ambn|m#n
CFL
Not CFL
CFL
Not CFL
RL
DCFL
DCFL CFL
CFL
Review
• Examples on PDA
• Equivalence of Context free language and PDA
PDAs Accept
Context-Free Languages
Theorem:
Context-Free
Languages
(Grammars)
=
Languages
Accepted by
PDAs
Proof - Step 1:
Context-Free
Languages
(Grammars)

Languages
Accepted by
PDAs
Convert any context-free grammar G
to a PDA M with: L(G ) = L( M )
Proof - Step 2:
Context-Free
Languages
(Grammars)

Languages
Accepted by
PDAs
Convert any PDA M to a context-free
grammar G with: L(G ) = L( M )
Proof - step 1
Convert
Context-Free Grammars
to
PDAs
Take an arbitrary context-free grammar
We will convert
G
G
to a PDA M such that:
L(G ) = L( M )
Procedure to Convert CFG to PDA
• G = (V, ∑, S, P)
• NT(G)=(Q, ∑, Г,q0,$,A, δ)
Q = {q0, q1, q2}
A = {q2}
Г = V ∪ ∑ ∪ {$}
• On initial state, δ(q0,λ, λ) = {(q1, S)}
• The moves from q1 are the following:
For every A ∈ V ,
δ(q1,λ,A) = {(q1, α) | A → α is a production in G}
For every terminal a∈ ∑,
δ(q1, a, a) = {(q1, λ)}
• For accepting state
δ(q1, λ,$) = {(q2,$)}
S→bAb
A→aA|a
Conversion Procedure:
For each
Variable/production in G
A→a
A → aA
S → bAb
q0
G
a
Add transitions
, A → a
 , A → aA
 , S → bAb
,  → S
For each
terminal in
q1
b
a, a → 
b, b → 
, $ → $
q2
Formal construction of PDA
Note: Initial stack symbol (S)
from CFG
same as the start variable
in the grammar
◼
◼
◼
Before:
Given: G= (V,T,P,S)
Output: PN = ({q}, T, V U T, δ, q, S)
δ:
◼
A
◼
Before:
a
◼
δ(q,  ,A) = { (q, ) | “A ==> ”  P}
◼
δ(q,a,a)= { (q,  ) }

After:
a…
a pop
…
…
For all a  T, add the following
transition(s) in the PDA:
After:
…
…
For all A  V , add the following
transition(s) in the PDA:
Example
Grammar
S → aSTb
S →b
T → Ta
T →
q0
PDA
 , S → aSTb
, S → b
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Example:
Input
Time 0
q0
a b
a
b
 , S → aSTb
$
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S
Input
Time 1
q0
a b
a
b
S
$
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb
Input
Time 2
q0
a b
a
a
S
T
b
$
b
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb
Input
Time 3
q0
a b
a
a
S
T
b
$
b
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb  abTb
Input
Time 4
q0
a b
a
b
T
b
$
b
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb  abTb
Input
Time 5
q0
a b
a
b
T
b
$
b
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb  abTb  abTab
Input
Time 6
q0
a b
a
T
a
b
$
b
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb  abTb  abTab  abab
Input
Time 7
q0
a b
a
T
a
b
$
b
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb  abTb  abTab  abab
Input
Time 8
q0
a b
a
b
a
b
$
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb  abTb  abTab  abab
Input
Time 9
q0
a b
a
b
b
$
 , S → aSTb
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
,  → S
q1
, $ → $
q2
Derivation: S  aSTb  abTb  abTab  abab
Input
a b
Time 10
a
b
 , S → aSTb
$
, S → b
Stack
a, a → 
 , T → Ta
b, b → 
, T → 
accept
q0
,  → S
q1
, $ → $
q2
Grammar
Leftmost Derivation
S
 aSTb
 abTb
 abTab
 abab
PDA Computation
(q0 , abab,$)
 (q1 , abab, S $)
 (q1 , bab, STb$)
 (q1 , bab, bTb$)
 (q1 , ab, Tb$)
 (q1 , ab, Tab$)
 (q1 , ab, ab$)
 (q1 , b, b$)
 (q1 ,  ,$)
 (q2 ,  ,$)
Example: CFG to PDA
◼
◼
G = ( {S,A}, {0,1}, P, S)
P:
◼
◼
◼
◼
1,1 / 
0,0 / 
,A / 01
,A / A1
,A / 0A1
,S / 
,S / AS
S ==> AS | 
A ==> 0A1 | A1 | 01
,  / S
q0
PDA = ({q0,q,p}, {0,1}, {0,1,A,S}, δ, q0, S)
δ:
◼ δ(q0,  , )=(q,S)
δ(q,  , S) = { (q, AS), (q,  )}
◼ δ(q,  , A) = { (q,0A1), (q,A1), (q,01) }
◼ δ(q, 0, 0) = { (q,  ) }
◼ δ(q, 1, 1) = { (q,  ) }
◼ δ(q,  , $) = { (P, $ ) }
◼
How will this new PDA work?
Lets simulate string 0011
q
,$ / $
p
Simulating string 0011 on the
new PDA …
Leftmost deriv.:
1,1 / 
0,0 / 
,A / 01
,A / A1
,A / 0A1
,S / 
,S / AS
PDA (δ):
δ(q0 , , )=(q,S)
δ(q,  , S) = { (q, AS), (q,  )}
δ(q,  , A) = { (q,0A1), (q,A1), (q,01) }
δ(q, 0, 0) = { (q,  ) }
δ(q, 1, 1) = { (q,  ) }
,S / S
q0
q
,S / S
p
S => AS
=> 0A1S
=> 0011S
=> 0011
Stack moves (shows only the successful path):
S
A
S
0
A
1
S
A
1
S
0
1
1
S
0
S
=>AS =>0A1S
=>0011S
1
1
S
1
S
S
0
1
1

=> 0011
Accept by
final state
In general, it can be shown that:
Grammar
generates
string
w
G
If and
Only if
*
Sw
Therefore
PDA M
accepts
w
(q0 , w,$)  (q2 ,  ,$)
L(G ) = L( M )
Construct PDA equivalent to the following CFG.
S->0A1 | 0BA
(May-2017 EndSem 8 Marks)
A->S01 | 0
 , S → 0 A1
B->1B | 1
 , S → 0 BA
 , A → S 01
, A → 0
1
,
1
→

 , B → 1B
0,0 → 
, B → 1
q0
,  → S
q1
, $ → $
q2
There are two types of PDAs that one can design:
those that accept by final state or by empty stack
Acceptance by…
◼
PDAs that accept by final state:
◼
For a PDA P, the language accepted by P,
denoted by L(P) by final state, is: Checklist:
◼
◼
{w | (q0,w,Z0) |---* (q,, A) }, s.t., q  F
- input exhausted?
- in a final state?
PDAs that accept by empty stack:
◼
For a PDA P, the language accepted by P,
denoted by N(P) by empty stack, is:
◼
{w | (q0,w,Z0) |---* (q, , ) }, for any q  Q.
Q) Does a PDA that accepts by empty stack
need any final state specified in the design?
Checklist:
- input exhausted?
- is the stack empty?
Example: L of balanced
parenthesis
PDA that accepts by final state
PF:
start
,Z0/ Z 0
(,Z0/ ( Z
(,( / ( (
), ( / 
(,Z0 / ( Z0
(, ( / ( (
), ( / 
,Z0 / 
PN:
0
,Z0/ Z0
q0
An equivalent PDA that
accepts by empty stack
start
q1
,Z0/ Z0
q0
How will these two PDAs work on the input: ( ( ( ) ) ( ) ) ( )
PDA- Acceptance by final state
Let
P = (Q,Σ,Γ,δ,q0,Z0,F)
be a PDA. The language accepted by P by final state is:
∗
L(P) = {w| (q0,w,Z0) ⊢(q,ǫ,α),q∈F}
for some state qin F and any input stack string α.
Starting in the initial ID with w waiting on the input, P consumes w
from the input and enters an accepting state. The contents of the
stack at that time is irrelevant.
PDA- Acceptance by empty stack
Let
P = (Q,Σ,Γ,δ,q0,Z0,F)
be a PDA. The language accepted by P by empty stack is:
∗
N(P) = {w| (q0,w,Z0) ⊢(q,ǫ,ǫ)}
where qis any state
N (P ) is the set of inputs wthat P can consume an at the same
time empty the stack.
Attendance TE-9
24/08/2018 absent
student
1,2,8,13,14,22,26,27,28,45,46,52,57,58,61,62,63,64,68,71,73,76,77
Review
• Equivalence of Context free language and PDA
From Empty stack to Final State
Let PN be a PDA by empty stack.
Let PF be a PDA by final state.
Theorem:
If L = N(PN ) for some PDA PN , then there exist a PDA PF , such
that
L = L(PF )
From Empty Stack to Final State
The specification of Pf is as follows:
Qf = Qn ∪ {p0, pf }.
Γf = Γn ∪ {X0}.
Ff = {pf }.
δf is defined by
1.δf (p0, ε, X 0) = {(q0, Z0X0)}. In its start state, Pf makes a
spontaneous transition to the start state of Pn, pushing its start
symbol Z0 onto the stack.
2.For all state q ∈ Qn, inputs a ∈ Σ n or a = ε, and stack symbol Y ∈
Γn, δf (q, a, Y ) contains all the pairs in δn(q, a, Y ).
3.In addition to rule (2), δf (q, ε, X 0) contains (pf , ε) for every
state q ∈ Qn.
From Final State to Empty Stack
Pn=(Q U {P0,P},∑,Г U X0,δN,P0,X0)
δN is defined by
1.δN (p0, ε, X 0) = {(q0, Z0X0)}. In its start state, PN makes a
spontaneous transition to the start state of Pf, pushing its start
symbol Z0 onto the stack.
2.For all state q ∈ Qf, inputs a ∈ Σ f or a = ε, and stack symbol Y ∈
Γn, δN (q, a, Y ) contains all the pairs in δf(q, a, Y ).
3.For all accepting States q in F and stack symbols Y in Г or Y=X0,
δN (q, ε, Y) = {(P, ε)}. By this rule whenever Pf accepts PN can
start emptying its stack without consuming any more input.
4.For all stack symbols Y in Γ or Y=X0, δN (p, ε, Y) = {(P, ε)}.
Once in state p, which only occurs when pf has accepted, PN
pops every symbol on its stack, until stack is empty. No further
input is consumed.
Problems
Q)Convert the following CFG into CNF &
construct PDA for the same.
S → 0A1 | 0BA
A → S01 | 0
B → 1B | 1
Nov-2017 8 Marks
Question : The language L = { 0i12i | i ≥ 0 } over the alphabet {0, 1, 2} is :
A. Not recursive
B. deterministic CFL
C. Is regular
D. Is CFL bot not deterministic CFL.
Question : Consider the following languages:
L1 = { 0n1n| n≥0 }
L2 = { wcwr | w ɛ {a,b}* }
L3 = { wwr | w ɛ {a,b}* }
Which of these languages are deterministic context-free languages?
A. None of the languages
B. Only L1
C. Only L1 and L2
D. All three languages
Question : Consider the language L1,L2,L3 as given below.
L1 = { ambn | m, n >= 0 }
L2 = { anbn | n >= 0 }
L3 = { anbncn | n >= 0 }
Which of the following statements is NOT TRUE?
A. Push Down Automata (PDA) can be used to recognize L1 and L2
B. L1 is a regular language
C. All the three languages are context free
Closure Properties
of
Context-Free languages
Closure Property
◼
CFLs are closed under:
◼
◼
◼
◼
◼
◼
◼
Union
Concatenation
Kleene closure operator
Substitution
Homomorphism, inverse homomorphism
reversal
CFLs are not closed under:
◼
◼
◼
Intersection
Difference
Complementation
Note: Reg languages
are closed
under
these
operators
Union
Context-free languages
are closed under:
Union
L1
is context free
L2
is context free
L1  L2
is context-free
Example
Language
Grammar
L1 = {a b }
S1 → aS1b | 
L2 = {ww }
S 2 → aS 2 a | bS 2b | 
n n
R
Union
L = {a b }  {ww }
n n
R
S → S1 | S 2
In general:
For context-free languages
with context-free grammars
and start variables
The grammar of the union
has new start variable
and additional production
L1,
G1,
S1,
L2
G2
S2
L1  L2
S
S → S1 | S 2
Concatenation
Context-free languages
Concatenation
are closed under:
L1
is context free
L1L2
L2 is context free
is context-free
Example
Language
Grammar
L1 = {a b }
S1 → aS1b | 
L2 = {ww }
S 2 → aS 2 a | bS 2b | 
n n
R
Concatenation
L = {a b }{ww }
n n
R
S → S1S 2
In general:
For context-free languages
with context-free grammars
and start variables
L1, L2
G1, G2
S1, S 2
The grammar of the concatenation L1L2
S
has new start variable
and additional production S → S1S 2
Star Operation
Context-free languages
Star-operation
are closed under:
L
is context free
*
L
is context-free
Example
Language
Grammar
L = {a b }
S → aSb | 
n n
Star Operation
L = {a b } *
n n
S1 → SS1 | 
In general:
For context-free language
with context-free grammar
and start variable
L
G
S
The grammar of the star operation L *
S1
has new start variable
and additional production S1 → SS1 | 
Negative Properties
of
Context-Free Languages
Intersection
Context-free languages
intersection
are not closed under:
L1 is context free
L2
is context free
L1  L2
not necessarily
context-free
Example
L1 = {a b c }
L2 = {a b c }
Context-free:
Context-free:
n n m
n m m
S → AC
S → AB
A → aAb | 
A → aA | 
C → cC | 
B → bBc | 
Intersection
L1  L2 = {a b c } NOT context-free
n n n
Complement
Context-free languages
complement
are not closed under:
L
is context free
L
not necessarily
context-free
Example
L1 = {a b c }
L2 = {a b c }
Context-free:
Context-free:
n n m
n m m
S → AC
S → AB
A → aAb | 
A → aA | 
C → cC | 
B → bBc | 
Complement
L1  L2 = L1  L2 = {a b c }
n n n
NOT context-free
Review
• Acceptance by Empty stack to Final State
• Acceptance by final state to empty stack
Design a PDA which accepts only odd number
of a’s over Σ = {a, b}.
Simulate PDA for the string “aabab”.
(9 Marks Nov-2015)
Pumping Lemma
for
Context-free Languages
Return of the Pumping Lemma !!
Think of languages that cannot be CFL
== think of languages for which a stack will not be enough
e.g., the language of strings of the form ww
154
Why pumping lemma?
A result that will be useful in proving
languages that are not CFLs
(just like we did for regular languages)
But before we prove the pumping lemma for
CFLs ….
Let us first prove an important property about
parse trees
155
Take an infinite context-free language
Generates an infinite number
of different strings
Example:
S → ABE | bBd
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
In a derivation of a “long” enough
string, variables are repeated
aabbccddee
A possible derivation:
S  ABE  AaBE  aaBE
 aabSDE  aabbBdDE 
 aaabbccdDE  aabbccddE
 aabbccddeE  aabbccddee
Derivation Tree
S
B
A
A
aabbccddee
a
a
b
S
b
e
D
B
c
Repeated
variable
E
d
c
d
E
e
S → ABE | bBd
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
Derivation Tree
S
B
A
A
aabbccddee
a
a
b
S
b
e
D
B
c
Repeated
variable
E
d
c
d
E
e
S → ABE | bBd
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
B  bSD  bbBdD  bbBdd
B
b
S
D
b
B
d
d
S → ABE | bBd
*
B  bbBdd
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
S  ABE  AaBE  aaBE  aaBeE  aaBee
S
B
A
A
E
e
a
E
e
a
*
S  aaBee
S → ABE | bBd
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
B
c
c
B  cc
S → ABE | bBd
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
S → ABE | bBd
Putting all together
A → Aa | a
B → bSD | cc
S
D → Dd | d
E → eE | e
B
A
A
a
a
b
S
b
S  aaBee
*
e
D
B
c
*
E
d
d
E
e
c
B  bbBdd
B  cc
We can remove the middle part
S
B
A
A
a
c
E
e
c
E
e
a
*
S → ABE | bBd
0
0
S  aa (bb) cc(dd ) ee
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
*
*
S  aaBee
*
B  bbBdd
*
S  aaBee  aaccee
B  cc
0
0
= aa (bb) cc(dd ) ee
S → ABE | bBd
0
0
A → Aa | a
aa (bb) cc(dd ) ee  L(G ) B → bSD | cc
D → Dd | d
E → eE | e
We can repeated middle part two times
S
B
A
A
b
a
1
a
2
E
S
e
D
b
B
d
b
S
D
b
B
d
E
e
d
d
S → ABE | bBd
c
*
A → Aa | a
c
B → bSD | cc
2
2
S  aa (bb) cc(dd ) ee
D → Dd | d
E → eE | e
*
*
S  aaBee
*
B  cc
B  bbBdd
*
S  aaBee  aabbBddee
*
2
2
*
2
2
 aa (bb) B (dd ) ee  aa (bb) cc(dd ) ee
S → ABE | bBd
A → Aa | a
2
2
aa (bb) cc(dd ) ee  L(G )D → Dd | d
B → bSD | cc
E → eE | e
We can repeat middle part three times
S
B
A
b
a
A
1
a
2
3
S
e
D
b
B
d
b
S
D
b
B
d
b
S
D
b
B
d
c
*
E
d
E
e
d
S → ABE | bBd
d
A → Aa | a
c
B → bSD | cc
3
3
S  aa (bb) cc(dd ) ee
D → Dd | d
E → eE | e
*
S  aaBee
*
*
B  bbBdd
3
B  cc
3
S  aa (bb) cc(dd ) ee  L(G )
S → ABE | bBd
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
Repeat middle part
i times
S
B
A
a
A
1
a
b
S
b
B
E
e
D
d
E
e
d
B
i
b
S
D
b
B
d
c
*
S → ABE | bBd
d
A → Aa | a
c
i
B → bSD | cc
i
S  aa (bb) cc(dd ) ee
D → Dd | d
E → eE | e
*
*
S  aaBee
*
B  bbBdd
i
i
For any
i0
B  cc
S  aa (bb) cc(dd ) ee  L(G )
S → ABE | bBd
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
From Grammar
and given string
S → ABE | bBd
aabbccddee  L(G )
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
We inferred that a family of strings is in L(G )
*
i
i
S  aa(bb) cc(dd ) ee  L(G )
for any
i0
We can write
S
w = uvxyz
yield
u
yield
v
H
H
u , v, x, y , z :
Strings of terminals
x
yield
z
yield
y
yield
Example:
S
A
B
A
u = aa
v = bb
x = cc
y = dd
z = ee
a
u
b
a
v
E
S
b
B
c
e
D
d
d
y
E
e
z
c
x
S → ABE | bBd
B corresponds to H A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
Possible derivations

S
S  uHz
u

H
z
H  vHy
v
H

Hx
x
y
Example:
S
B
A
A
a
a
b
S  uHz

S  aaBee
E
S
b
d
c

H  vHy

e
D
B
c

u = aa
v = bb
x = cc
B  bbBdd
d
y = dd
z = ee
E
e
B correspond s to H

H x
S → ABE | bBd
A → Aa | a
B → bSD | cc
B  cc D → Dd | d
E → eE | e
Remove Middle Part

S
S  uHz
u
z
H

Hx
x
Yield:

*
S  uHz  uxz
uxz = uv xy z
0
= uv xy z
0
0
0
 L(G )
Repeat Middle part two times
S

S  uHz
u
H
z

1
H  vHy
v
H
y

H  vHy

H x
Yield:
v
H
x
2
y
uvvxyyz = uv xy z
2
2


S  uHz

H  vHy
*
Hx
*
S  uHz  uvHyz  uvvHyyz
*
 uvvxyyz
2
2

= uv xy z  L(G )
Repeat Middle part

i
times
S
S  uHz
u

H
z
H  vHy
v

H x
1
y
i
H

H  vHy
H
y
v
H
x
Yield: uv xy z
i
i


S  uHz
H  vHy




H x

S  uHz  uvHyz  uvvHyyz 




 uv Hy z  uv xy z  L(G)
i
i
i
i
Therefore,
If we know that:
| w | n
w = uvxyz  L(G )
then we also know:
uv xy z  L(G )
For all i  0
i
i
since
L(G ) = L − {}
i
i
uv xy z  L
Observation 1:
S
| vy |  1
Since G has no
unit and
-productions

u
v
z
H
y
H
x
At least one of v
or y is not

Observation 2:
S
| vxy |  n
since in subtree
only variable H
is repeated
u
v
H
H
z
y
x
subtree of H
The Pumping Lemma:
For any infinite context-free language
there exists an integer
for any string
m
w  L,
L
such that
| w | m
we can write
w = uvxyz
with lengths
| vxy | m and | vy | 1
and it must be that:
i i
uv xy z  L,
for all i  0
Applications
of
The Pumping Lemma
Non-context free languages
{a b c : n  0}
n n n
Context-free languages
{a b : n  0}
n n
Theorem: The language
n n n
L = {a b c : n  0}
is not context free
Proof:
Use the Pumping Lemma
for context-free languages
L = {a b c : n  0}
n n n
Assume for contradiction that
L
is context-free
Since L is context-free and infinite
we can apply the pumping lemma
L = {a b c : n  0}
n n n
Let m be the critical length
of the pumping lemma
Pick any string
We pick:
w L with length | w | m
w=a b c
m m m
L = {a b c : n  0}
n n n
w=a b c
m m m
From pumping lemma:
we can write:
w = uvxyz
with lengths
| vxy | m
and
| vy | 1
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
| vxy | m
| vy | 1
Pumping Lemma says:
uv xy z  L
i
i
for all
i0
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
| vxy | m
| vy | 1
We examine all the possible locations
S → ABE | bBd
of string vxy in w
A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Case 1:
m
vxy
| vxy | m
is in
a
m
| vy | 1
m
m
a ...aa ...aa ...a bbb ...bbb ccc ...ccc
u vxy
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
v =a
| vxy | m
y =a
k1
m
k2
| vy | 1
k1 + k2  1
m
m
a ...aa ...aa ...aa ...aa ...a bbb ...bbb ccc ...ccc
u v
x
y
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
v =a
| vxy | m
y =a
k1
k2
| vy | 1
k1 + k2  1
m
m
m + k1 + k2
a ...aa ...aa ...aa ...aa ...a bbb ...bbb ccc ...ccc
u v2 x
y
2
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
| vxy | m
From Pumping Lemma:
| vy | 1
uv xy z  L
2
2
k1 + k2  1
However:
uv xy z = a
2
2
m +k1 +k2
b c L
m
m
Contradiction!!!
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Case 2:
vxy
| vxy | m
is in
b
| vy | 1
m
Similar to case 1
m
m
m
aaa ...aaa b ...bb ...bb ...b ccc ...ccc
u
vxy
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Case 3:
vxy
| vxy | m
is in
c
| vy | 1
m
Similar to case 1
m
m
m
aaa ...aaa bbb ...bbb c ...cc ...cc ...c
u
vxy z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Case 4:
vxy
| vxy | m
overlaps
a
m
| vy | 1
and
b
m
m
m
a ...aa ...aa b ...bb ...bbb ccc ...ccc
u
vxy
z
m
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Sub-case 1:
v
y
| vxy | m
contains only
contains only
| vy | 1
a
b
m
m
m
a ...aa ...aa ...a b ...bb ...bb ...b ccc ...ccc
u v
x
y
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
v =a
k1
| vxy | m
y =a
| vy | 1
k1 + k2  1
k2
m
m
m
a ...aa ...aa ...a b ...bb ...bb ...b ccc ...ccc
u v
x
y
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
v =a
k1
| vxy | m
y =a
| vy | 1
k1 + k2  1
k2
m + k2
m
m + k1
a ...aa ...aa ...a b ...bb ...bb ...b ccc ...ccc
u v2
x
y
2
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
| vxy | m
From Pumping Lemma:
| vy | 1
uv xy z  L
2
2
k1 + k 2  1
However:
uv xy z = a
2
2
m + k1 m + k2 m
b
c L
Contradiction!!!
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Sub-case 2:
v
y
| vxy | m
contains a and
contains only b
| vy | 1
b
m
m
m
a ...aa ...a b ...bb ...bb ...bb ...b ccc ...ccc
u
v
x
y
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
| vxy | m
| vy | 1
By assumption
v =a b
k1
m
y =a
k2
k1
k1 , k2  1
k3
m
k2
m
k3
a ...aa ...a b ...bb ...bb ...bb ...b ccc ...ccc
u
v
x
y
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
v =a b
k1
k2
| vxy | m
y =a
k1 , k2  1
k3
m + k3
m
| vy | 1
m
2k3
k1 k2 k1 k2
a ...aa ...ab ...ba ...ab ...bb ...bb ...bb ...b ccc ...ccc
u
v
2
x
y
2
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
| vxy | m
From Pumping Lemma:
| vy | 1
uv xy z  L
2
2
k1 , k2  1
However:
uv xy z = a b a b
2
2
m
k2
Contradiction!!!
k1
m +k3
c L
m
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Sub-case 3:
v
y
| vxy | m
contains only a
contains a and
| vy | 1
b
Similar to sub-case 2
m
m
m
a ...aa ...aa ...aa ...a b ...bb ...b ccc ...ccc
u
v
x
y
z
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Case 5:
| vxy | m
vxy overlaps b
m
| vy | 1
and
Similar to case 4
m
m
m
aaa...aaa bbb...bbb ccc...ccc
z
vxy
u
c
m
L = {a b c : n  0}
n n n
w=a b c
w = uvxyz
m m m
Case 6:
vxy
| vxy | m
overlaps
a
| vy | 1
m
,
b
m and
Impossible!
m
m
m
aaa...aaa bbb...bbb ccc...ccc
z
vxy
u
c
m
In all cases we obtained a contradiction
Therefore: the original assumption that
L = {a b c : n  0}
n n n
is context-free must be wrong
Conclusion:
L
is not context-free
Theory of Automata
Post Machine
Contents
◼
◼
◼
◼
Post Machine
Examples
Simulating PM on TM
Simulating TM on PM
❑
SHIFT-RIGHT CYCLICALLY.
Recall
• Pumping Lemma for CFL
• Introduction to Post Machine
POST Machine
◼
A Post machine denoted by PM is a collection of five things
1.
2.
3.
The alphabet Σ plus the special symbol #. We generally use Σ
= { a, b}.
A linear storage location (a place where a string of symbols is
kept called the STORE or QUEUE, which initially contains the
input string. This location can be read by which we mean the
leftmost character can be removed for inspection. The STORE
can also be added to, which means a new character can be
concatenated onto the right of whatever is there already. We
allow for the possibility that characters not in Σ can be used in
the STORE, characters from an alphabet Γ called the store
alphabet.
More Powerful than FA,PDA
◼
◼
◼
◼
◼
A Post machine does not have a separate input store like
FA, PDA have.
PM has a Queue.
While Processing a string it is assumed that the string is
initially loaded into the queue.
PM has start execution at Start State.
If post machine halt at ACCEPT state, the input string is said
to be accepted else rejected.
Formal Definition
◼
A Post machine =(Input alphabet,start state, Accept state,
◼
Reject State, Branching state Read, Queue/Tape alphabet,
Transition function,)
OR
◼
(Q, Σ, qo, A, δ,┌,z0)
a
b
b
a
#
В
Tape/QUEUE
В
В
…
….
R/W Head
Current State
End of I/P
Bounded to Left side
Blank Symbols
UnBounded to Right side
Example
◼
Design a post machine that accepts the
following language which end by a.
a, 
b, 
a, 
q0
#,  q
q1
2
b, 
a
b
b
a
#
В
В
В
…
….
Example
◼
Design a post machine that accepts the
following language which end by a.
a, 
b, 
a, 
q0
#,  q
q1
2
b, 
a
b
b
a
#
В
В
В
…
….
Example
◼
Design a post machine that accepts the
following language which end by a.
a, 
b, 
a, 
q0
#,  q
q1
2
b, 
a
b
b
a
#
В
В
В
…
….
Example
◼
Design a post machine that accepts the
following language which end by a.
a, 
b, 
a, 
q0
#,  q
q1
2
b, 
a
b
b
a
#
В
В
В
…
….
Example
◼
Design a post machine that accepts the
following language which end by a.
a, 
b, 
a, 
q0
#,  q
q1
2
b, 
a
b
b
a
#
В
В
В
…
….
Example
◼
Design a post machine that accepts the
following language which end by a.
a, 
b, 
a, 
q0
#,  q
q1
2
b, 
a
b
b
a
#
В
В
В
…
….
String is accepted..
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
.
.
.
…
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
.
.
…
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
.
.
…
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
.
.
…
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
b
.
…
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
b
#
…
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
b
#
…
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
b
#
…
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
b
#
#
….
Example
◼
Design a post machine that accepts the following
language. L={anbn|n >=0}
(8 marks Nov-15)
a, a
q3
#, #
a, 
q0
q1
b,b
b, 
q2
#, #
a
a
b
b
#
a
b
#
#
….
String is accepted..
POST Machine Contd.
3.
READ states, for example,
PMs are deterministic, so no two edges from the
READ have the same label
4. ADD states:
POST Machine Contd.
5.
A START state (un-enterable) and some halt states
called ACCEPT and REJECT
Example
◼
Design a post machine that accepts the
following language.
(8 marks Nov-15)
L={anbn|n >=0}
Another POST Machine
◼
Design a post machine that accepts the
following language.
(8 marks Nov-16)
L={anbncn|n >=0}
Recall
• Post Machine
Construct Post Machine which accepts the string
over Σ = {a, b} containing odd length & the
element at the centre as 'a'.
Write simulation for the string “abbabba”
q7
#, #
#, #
a, 
b, 
a, 
q0
#, #
q6
q4
q1
a, 
b, 
q2
#, #
q8
b, 
b, a
a, b
q3
#, #
a, a
b,b
Construct Post Machine which accepts the string
over Σ = {a, b} containing numbers of ‘a’ and ‘b’
same.
Write simulation for the string “abbaabba”
q3
#, #
#, #
q1
a, 
q0
#, #
q6
b, 
q5
b, 
q2
a, 
#, #
q4
#, #
a, a
b, b
Construct Post Machine which accepts the
Language over Σ = {a, b} is
L = {an b2n | n >= 0}
a, a
#, #
q0
#, #
q6
a, 
q1 b, 
b, b
q2
b, 
q3
RECALL
•Post Machine
•Examples
Thank You!!!!!!!!!!!!!
Download