Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit IV PUSHDOWN AUTOMATA AND POST MACHINES

Download as pdf or txt
Download as pdf or txt
You are on page 1of 247
At a glance
Powered by AI
The document discusses pushdown automata and post machines, including their definitions, transition functions, and examples.

A pushdown automaton (PDA) is a type of automaton that extends a finite automaton with a stack. A PDA can recognize context-free languages.

A pushdown automaton is defined as a 7-tuple (Q, Σ, Γ, δ, q0, Z, F) where Q is a finite set of states, Σ is the input alphabet, Γ is the stack alphabet, δ is the transition function, q0 is the initial state, Z is the initial stack symbol, and F is the set of accept states.

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 )
Accept
States states

Input Stack
alphabet Transition Initial start
Stack
function state symbol
alphabet
Transition Function: δ
Deterministic PDA:
δ(Q x {∑ U ε} x Г)=Q x Г*

Non-Deterministic PDA:
Q x Г*
δ(Q x {∑ U ε} x Г)=2
δ(Q
Q x {∑
∑ U ε}
ε xГ
Г)=Q
Q x Г*

Input Pop Push


symbol symbol symbol

input a, b → c
q1 q2
 a 
stack stack
States b top c
h h
e e
$ $
Initial Stack Symbol

Stack Stack

stack
$ z top
head

bottom special symbol


Appears at time 0
The States

Input Pop Push


symbol symbol symbol

a, b → c
q1 q2
a, b → c
q1 q2

input
 a   a 

stack
b top c
h Replace h
e e
$ $
a, b → 
q1 q2

input
 a   a 

stack
b top
h Pop h
e e
$ $
a,  → 
q1 q2

input
 a   a 

stack
b top b
h No Change h
e e
$ $
Pop from Empty Stack
a, b → c
q1 q2
input
 a 
stack Pop 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

, b → c
q1 q1 q2

a, b → c
 − transition
q3
Example PDA

PDA M : L( M ) = {a b : n  1}
n n

a, a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
L( M ) = {a b : n  0}
n n

Basic Idea:

1. Push the a’s 2. Match the b’s on input


on the stack with a’s on stack

3. Match
a, a → aa found
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
a, a → aa Transition
a,$ → a$ b, a →  Diagram

q1 b, a →  q2  , $ → $ q3
δ( q1x ax $)=(q1,a$)
δ( q1x ax a)=(q1,aa)
Transition
δ( q1x bx a)=(q2,ε)
function
δ( q2x bx a)=(q2,ε)
δ( q2x ε x $)=(q3,$)
PDA Acceptance by Final State
a, a → aa Transition
a,$ → a$ b, a →  Diagram

q1 b, a →  q2  ,$ → 

δ( q1x ax $)=(q1,a$)
δ( q1x ax a)=(q1,aa)
Transition
δ( q1x bx a)=(q2,ε)
function
δ( q2x bx a)=(q2,ε)
δ( q2x ε x $)=(q2,ε)
PDA Acceptance by Empty Stack
Final State

ACCEPTANCE
PDA

Empty Stack
Execution Example: Time 0
Input
a a a b b b
$
Stack
a, a → aa
a,$ → a$ b, a → 
Current/
initial b, a →  q , $ → $ q
q1 2 3
state
Time 1
Input
a a a b b b a
$
Stack
a, a → aa
a,$ → a$ b, a → 

b, a →  q , $ → $ q
q1 2 3
Time 2
Input a
a a a b b b a
$
Stack

a, a → aa
a,$ → a$ b, a → 

b, a →  q , $ → $ q
q1 2 3
Time 3
a
Input
a
a a a b b b a
$
Stack
a, a → aa
a,$ → a$ b, a → 

b, a →  q , $ → $ q
q1 2 3
Time 4
a
Input
a
a a a b b b a
$
Stack
a, a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
Time 5
Input a
a a a b b b a
$
Stack

a, a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
Time 6
Input
a a a b b b a
$
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$ b, a → 

Current State
q1 b, a →  q2  , $ → $ q3
Rejection Example: Time 2
Input
a
a a b
$
Stack

a, a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
Rejection Example: Time 3
Input a
a
a a b
$
Stack

a, a → aa
a,$ → a$ b, a → 
current
state b, a →   , $ → $
q1 q2 q3
Rejection Example: Time 4
Input a
a
a a b
$
Stack

a, a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
Rejection Example: Time 4
Input a
a
a a b
$
Stack
reject
a, a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
There is no accepting computation for aab
The string aab is rejected by the PDA

a, a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
Example PDA

PDA M :L(M) such that na(w)=nb(w),w€(a,b)*


a, a → aa
a,$ → a$

q1 , $ → $ q2

b, b → bb b, a → 
b,$ → b$ a,b → 
Example PDA

PDA M :L(M) such that anbncm| n, m>=1

a, a → aa
a,$ → a$ b, a →  c,$ → $

q1 b, a →  q2
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 →  c,$ → $

b, a →  c,$ → $ , $ → $ q
q1 q2 q3 4

Acceptance by final state


Example PDA

PDA M :L(M) such that anbncm| n, m>=1

a, a → aa
a,$ → a$ b, a →  c,$ → $

q1 b, a →  q2
c,$ → $
q3

Acceptance by final state , $ → $


Example PDA

PDA M :L(M) such that anbncm| n, m>=1

a, a → aa
a,$ → a$ b, a →  c,$ → $

q1 b, a →  q2
c,$ → $
q3

Acceptance by Empty  ,$ → 
stack
Example PDA

PDA M : L( M ) = {a b : n  1}
n n

a, → a b, a → 

q1 b, a →  q2  , $ → $ q3
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$ c,a → 
b,a → a

q1 b,a → a q2 c,a →  q3 , $ → $ q3

Acceptance by final state


Example PDA

PDA M :L(M) such that anbmcn| n, m>=1


a, a → aa
a,$ → a$ c,a → 
b,a → a

q1 b,a → a q2 c,a →  q3

 ,$ → 
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 , $ → $ q2

b, b → bb b, a → 
b,$ → b$ a,b → 
Example PDA
PDA M :L(M) such that anb2n| n>=1
(Nov-2017 EndSem 8 Marks)

a, a → aaa
a,$ → aa$ b,a → 

q1 b,a →  q2  , $ → $ q3
Review

• PDA Examples
• Acceptance by Final State
• Acceptance by Empty Stack
Another PDA example
L( M ) = {w  {a, b} : na ( w) = nb ( w)}
*

PDA M

a, $ → 0$ b, $ →1$
a, 0 → 00 b, 1 → 11
a, 1→  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 a,$ → $ q2 , $ → $ q
3

b, b → bb b, a → 
b,$ → b$ a,b → 
Example PDA

PDA M :L(M) such that na(w)<nb(w),w€(a,b)*


a, a → aa
a,$ → a$ b,$ → $

q1 b,$ → $ q2 , $ → $ q
3

b, b → bb b, a → 
b,$ → b$ a,b → 
Example PDA

PDA M :L(M) such that anbm+ncn| n, m>=1


a, a → aa
a,$ → a$ c,b → 
b,a → 

q1 b,a →  q2 c,b →  q  , $ → $ 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 q1 , $ → $ q2
c,b → b
Formalities for PDAs
a , w1 → w 2
q1 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 non-
deterministic.
• 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 contain equivalent DPDA
sometimes.
NPDA example
L( M ) = {w  {a, b} : aibjckdm |i=k or j=m }
*

L(M) ={anbjcndm }U {aibnckdn}

q1 q2 , $ → $ q
a,$|a$ 3
q0
a,$|$
q4 q5 , $ → $ q6

PDA M : L( M ) = {vv : v  {a, b} }
R

a,$ → a
a,a → aa a, a → 
a,b → ab b, b → 

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba

PDA M : L(M ) = {vv : v  {a, b} }
R

1. Push v 2. Guess 3. Match v R on input


on stack middle with v on stack
a,$ → a of input
a,a → aa a, a →  4. Match
a,b → ab b, b →  found

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Execution Example: Time 0
Input
a b b a

a,$ → a $
a,a → aa a, a → 
a,b → ab b, b → 

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 1
Input
a b b a
a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 2
Input
a b b a b
a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 3
Input
Guess the middle
a b b a b
of string
a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 4
Input
a b b a b
a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $ q2
q0 q1
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 5
Input
a b b a
a
a,$ → a
$
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 6
Input
a b b a

a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2 accept
b, b → 

b,$ → b
b,b → bb
b,a → ba
Rejection Example: Time 0
Input
a b b b
a,$ → a
$
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2 accept
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 1
Input
a b b b a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 2
Input
b
a b b b a
a,$ → a
$
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 3
Input
b
a b b b Guess the middle a
a,$ → a of string $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 4
Input There is no possible transition.
a
a b b b Input is not
$
a,$ → a consumed
a,a → aa a, a →  Stack
a,b → ab b, b → 

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Another computation on same string:
Input Time 0
a b b b
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 1
Input
a b b b a
a,$ → a
$
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 2
Input
b
a b b b a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 3
Input b
b
a b b b a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 4 b
Input b
b
a b b b a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
Time 5 b
Input There is no possible transition. b
No accept state b
a b b b is reached a
a,$ → a $
a,a → aa a, a → 
a,b → ab b, b →  Stack

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
There is no computation
that accepts string abbb

abbb  L(M )
a,$ → a
a,a → aa a, a → 
a,b → ab b, b → 

a, a →  , $ → $
q0 q1 q2
b, b → 

b,$ → b
b,b → bb
b,a → ba
PDA for Lwwr: Transition Diagram

Grow stack
Pop stack for
0, Z0/0Z0 ∑ = {0, 1}
1, Z0/1Z0 matching
= {Z0, 0, 1}
0, 0/00 symbols
Q = {q0,q1,q2}
0, 1/01 0, 0/ 
1, 0/10 1, 1/ 
1, 1/11

, Z0/Z0
q0 , 0/0 q1 , Z0/Z0 q2
, 1/1
Switch to
Go to acceptance
popping mode

This would be a non-deterministic PDA


How does the PDA for Lwwr
work on input “1111”?
All moves made by the non-deterministic PDA
(q0,1111,Z0)

(q1,1111,Z0) Path dies…


(q0,111,1Z0)

(q0,11,11Z0) (q1,111,1Z0) Path dies…

(q0,1,111Z0) (q1,11,11Z0)

(q0,,1111Z0) (q1,1,111Z0) (q1,1,1Z0) Acceptance by


final state:

(q1, ,1111Z0) (q1, ,11Z0) (q1, ,Z0) = empty input


Path dies… AND
Path dies…
(q2, ,Z0) final state
79
Instantaneous Description

( q, u , s )

Current Current
Remaining
state stack
input
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$)
a
Time 4: Input a
a a a b b b a
$
a,a → aa
Stack
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
Example: Instantaneous Description
(q2 , bb, aa$)
a
Time 5: Input a
a a a b b b a
$
a,a → aa
Stack
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
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 → 

q1 b, a →  q2  , $ → $ q3
(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 → 

q1 b, a →  q2  , $ → $ q3

(q0 , a b ,$)  (q3 ,  ,$)
n n

a b  L(M )
n n

PDA M :
a,a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
Therefore: L( M ) = {a b : n  0}
n n

PDA M :
a,a → aa
a,$ → a$ b, a → 

q1 b, a →  q2  , $ → $ q3
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 Not DCFL Not CFL
2) amb2n |n,m>1 Not DCFL Not CFL
3) wwR|w€(a,b)* NDCFL CFL
4) ww| w€(a,b)* Not DCFL Not CFL

5) anbncm|n>m Not DCFL Not CFL

6) anbncndn|n<1010 DCFL CFL


7) amb2mc3m|m>1 Not CFL
8) xcy| x,y€(a,b)* RL DCFL CFL
9) ambn|m#n DCFL 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 G

We will convert 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
Conversion Procedure: A→aA|a
For each For each
Variable/production in G terminal in G
A→a a
A → aA
Add transitions
S → bAb b
, A → a
 , A → aA
a, a → 
 , S → bAb
b, b → 

q0 ,  → S q1 , $ → $ q2
Formal construction of PDA
from CFG Note: Initial stack symbol (S)
same as the start variable
in the grammar
◼ Given: G= (V,T,P,S)
◼ Output: PN = ({q}, T, V U T, δ, q, S)
◼ δ:
For all A  V , add the following
Before: After:

A 
transition(s) in the PDA:


◼ δ(q,  ,A) = { (q, ) | “A ==> ”  P}
Before:
◼ For all a  T, add the following After: a…
a transition(s) in the PDA: a pop

δ(q,a,a)= { (q,  ) }



Example
Grammar
S → aSTb
PDA
S →b
T → Ta  , S → aSTb
T → , S → b
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Example:

Input a b a b

 , S → aSTb $
Time 0
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

,  → S , $ → $
q0 q1 q2
Derivation: S

Input a b a b
S
 , S → aSTb $
Time 1
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb a
S
Input a b a b T
b
 , S → aSTb $
Time 2
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb a
S
Input a b a b T
b
 , S → aSTb $
Time 3
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb  abTb
b
Input a b a b T
b
 , S → aSTb $
Time 4
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb  abTb
b
Input a b a b T
b
 , S → aSTb $
Time 5
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb  abTb  abTab
T
Input a b a b a
b
 , S → aSTb $
Time 6
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb  abTb  abTab  abab
T
Input a b a b a
b
 , S → aSTb $
Time 7
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb  abTb  abTab  abab

Input a b a b a
b
 , S → aSTb $
Time 8
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb  abTb  abTab  abab

Input a b a b
b
 , S → aSTb $
Time 9
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 

q0 ,  → S q1 , $ → $ q2
Derivation: S  aSTb  abTb  abTab  abab

Input a b a b

 , S → aSTb $
Time 10
, S → b Stack
 , T → Ta a, a → 
, T →  b, b → 
accept

q0 ,  → S q1 , $ → $ q2
Grammar PDA Computation
Leftmost Derivation
(q0 , abab,$)
S  (q1 , abab, S $)
 aSTb  (q1 , bab, STb$)
 (q1 , bab, bTb$)
 abTb
 (q1 , ab, Tb$)
 abTab  (q1 , ab, Tab$)
 abab  (q1 , ab, ab$)
 (q1 , b, b$)
 (q1 ,  ,$)
 (q2 ,  ,$)
Example: CFG to PDA
1,1 / 
0,0 / 
,A / 01
◼ G = ( {S,A}, {0,1}, P, S) ,A / A1
,A / 0A1
,S / 
◼ P: ,S / AS

◼ S ==> AS |  ,  / S
,$ / $
◼ A ==> 0A1 | A1 | 01
q0 q p
◼ 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
Simulating string 0011 on the
new PDA … Leftmost deriv.:
1,1 / 
0,0 / 
,A / 01
,A / A1
,A / 0A1 S => AS
PDA (δ): ,S / 
δ(q0 , , )=(q,S) ,S / AS => 0A1S
δ(q,  , S) = { (q, AS), (q,  )}
,S / S
=> 0011S
δ(q,  , A) = { (q,0A1), (q,A1), (q,01) }
,S / S => 0011
δ(q, 0, 0) = { (q,  ) } q0 q p
δ(q, 1, 1) = { (q,  ) }

Stack moves (shows only the successful path):

0 0
A A 1 1
A 1 1 1 1 1
Accept by
S S S S S S S S
final state
0 0 1 1 

S =>AS =>0A1S =>0011S => 0011


In general, it can be shown that:

Grammar G
generates PDA M
string If and accepts w
w Only if
* (q0 , w,$)  (q2 ,  ,$)
Sw

Therefore L(G ) = L( M )
Construct PDA equivalent to the following CFG.
S->0A1 | 0BA (May-2017 EndSem 8 Marks)
A->S01 | 0
B->1B | 1  , S → 0 A1
 , S → 0 BA
 , A → S 01
, A → 0
 , B → 1B 1 ,1 → 
, B → 1 0,0 → 

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 Checklist:
need any final state specified in the design? - input exhausted?
- is the stack empty?
Example: L of balanced
parenthesis
An equivalent PDA that
PDA that accepts by final state accepts by empty stack
(,Z0 / ( Z0
PF: (,Z0/ ( Z
PN: (, ( / ( (
0 ), ( / 
(,( / ( ( ,Z0 / 
), ( / 

,Z0/ Z0 start
start
q0 q1 q0
,Z0/ Z 0 ,Z0/ Z0

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: Note: Reg languages
are closed
◼ Intersection under
◼ Difference these
◼ Complementation operators
Union

Context-free languages
are closed under: Union

L1 is context free
L1  L2
L2 is context free is context-free
Example
Language Grammar

L1 = {a b }
n n
S1 → aS1b | 

L2 = {ww } R
S 2 → aS 2 a | bS 2b | 

Union

L = {a b }  {ww }
n n R S → S1 | S 2
In general:
For context-free languages L1, L2
with context-free grammars G1, G2
and start variables S1, S2

The grammar of the union L1  L2


has new start variable S
and additional production S → S1 | S 2
Concatenation

Context-free languages
are closed under: Concatenation

L1 is context free
L1L2
L2 is context free is context-free
Example
Language Grammar

L1 = {a b }
n n
S1 → aS1b | 

L2 = {ww } R
S 2 → aS 2 a | bS 2b | 

Concatenation

L = {a b }{ww }
n n R S → S1S 2
In general:

For context-free languages L1, L2


with context-free grammars G1, G2
and start variables S1, S 2

The grammar of the concatenation L1L2


has new start variable S
and additional production S → S1S 2
Star Operation

Context-free languages
are closed under: Star-operation

*
L is context free L is context-free
Example

Language Grammar

L = {a b }
n n
S → aSb | 

Star Operation

L = {a b } *
n n
S1 → SS1 | 
In general:

For context-free language L


with context-free grammar G
and start variable
S

The grammar of the star operation L *


has new start variable S1
and additional production S1 → SS1 | 
Negative Properties
of
Context-Free Languages
Intersection

Context-free languages
are not closed under: intersection

L1 is context free
L1  L2
L2 is context free not necessarily
context-free
Example

L1 = {a b c }
n n m
L2 = {a b c }
n m m

Context-free: Context-free:
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
are not closed under: complement

L is context free L not necessarily


context-free
Example

L1 = {a b c }
n n m
L2 = {a b c }
n m m

Context-free: Context-free:
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 aabbccddee
S

A B E

b e E
A a S D

a e
b B d d

S → ABE | bBd
c c
A → Aa | a
Repeated B → bSD | cc
D → Dd | d
variable E → eE | e
Derivation Tree aabbccddee
S

A B E

b e E
A a S D

a e
b B d d

S → ABE | bBd
c c
A → Aa | a
Repeated B → bSD | cc
D → Dd | d
variable E → eE | e
B  bSD  bbBdD  bbBdd

b S D

b B d d

S → ABE | bBd
* A → Aa | a

B  bbBdd B → bSD | cc
D → Dd | d
E → eE | e
S  ABE  AaBE  aaBE  aaBeE  aaBee

A B E

e E
A a
a e
* S → ABE | bBd

S  aaBee 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
A → Aa | a Putting all together
B → bSD | cc S
D → Dd | d
E → eE | e
A B E

e E
A a b S D

a e
b B d d

c c

* *
S  aaBee B  bbBdd B  cc
We can remove the middle part

A B E

c c e E
A a
a e

S → ABE | bBd
* A → Aa | a
0 0
S  aa (bb) cc(dd ) ee B → bSD | cc
D → Dd | d
E → eE | e
* *
S  aaBee B  bbBdd B  cc

* *
0 0
S  aaBee  aaccee = aa (bb) cc(dd ) ee

S → ABE | bBd
A → Aa | a
0 0
aa (bb) cc(dd ) ee  L(G ) B → bSD | cc
D → Dd | d
E → eE | e
We can repeated middle part two times
S

A B E

b e E
A a S D

a 1 b B d d
e

b S D

2 b B d d
S → ABE | bBd
c c A → Aa | a
B → bSD | cc
*
2 2
S  aa (bb) cc(dd ) ee D → Dd | d
E → eE | e
* *
S  aaBee B  bbBdd B  cc

* *
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

A B E

b e E
A a S D

a 1 b B d d
e

b S D

2 b B d d

b S D

3 b B d d
S → ABE | bBd
c c A → Aa | a
B → bSD | cc
*
3 3
S  aa (bb) cc(dd ) ee D → Dd | d
E → eE | e
* *
S  aaBee B  bbBdd B  cc

*
3 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

A B E

b e E
A a S D

a 1 b B d d
e

b S D
i b B d d S → ABE | bBd
A → Aa | a
c c
B → bSD | cc
*
i i
S  aa (bb) cc(dd ) ee D → Dd | d
E → eE | e
* *
S  aaBee B  bbBdd B  cc

*
i i
S  aa (bb) cc(dd ) ee  L(G )

For any i0 S → ABE | bBd


A → Aa | a
B → bSD | cc
D → Dd | d
E → eE | e
From Grammar
and given string
S → ABE | bBd
A → Aa | a aabbccddee  L(G )
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 z yield
H

yield v y yield
H

u , v, x, y , z :
Strings of terminals x yield
Example: S

A B E

b e E
A a S D

u = aa a b B d d
e

u v y z
v = bb c c
x = cc x S → ABE | bBd
y = dd B corresponds to H A → Aa | a
B → bSD | cc
z = ee D → Dd | d
E → eE | e
Possible derivations S

S  uHz
u z
H

H  vHy
v y
H

Hx
x
Example: u = aa
v = bb
S

A B E x = cc
e E
y = dd
A a b S D
z = ee
a e
b B d d

c c B correspond s to H
   S → ABE | bBd
S  uHz H  vHy H x A → Aa | a

B → bSD | cc

S  aaBee B  bbBdd B  cc D → Dd | d
E → eE | e
Remove Middle Part S

S  uHz
u z
H

Hx
x
Yield: uxz = uv xy z0 0

 *
S  uHz  uxz = uv xy z
0 0
 L(G )
Repeat Middle part two times
 S
S  uHz
u z
H

H  vHy 1
v y
H


H  vHy v y
2
H

H x
x
Yield: uvvxyyz = uv xy z
2 2
  
S  uHz H  vHy Hx

 * *
S  uHz  uvHyz  uvvHyyz
*
2 2
 uvvxyyz = uv xy z  L(G )
Repeat Middle part i times
 S
S  uHz
u z
H

H  vHy 1
v H
y

H

H  vHy v y i
H

H x 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,
| w | n
If we know that: w = uvxyz  L(G )

then we also know: uv xy z  L(G )


i i

For all i  0
since
L(G ) = L − {}

i i
uv xy z  L
Observation 1: S

| vy |  1
Since G has no u
H
z
unit and
-productions
v H y
x

At least one of v or y is not 


Observation 2: S

| vxy |  n
u z
since in subtree H

only variable H
is repeated v y
H

subtree of H
The Pumping Lemma:
For any infinite context-free language L
there exists an integer m such that

for any string w  L, | w | m


we can write w = uvxyz
with lengths | vxy | m and | vy | 1
and it must be that:

uv xy z  L,
i i
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

L = {a b c : n  0}
n n n

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 w L with length | w | m

We pick: w=a b cm 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 m m m

w = uvxyz | 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
m m m

w = uvxyz | 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 m m m

w = uvxyz | vxy | m | vy | 1

m
Case 1: vxy is in a

m 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 m m m

w = uvxyz | vxy | m | vy | 1

v =a k1
y =a k2
k1 + k2  1

m 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 m m m

w = uvxyz | vxy | m | vy | 1

v =a k1
y =a k2
k1 + k2  1

m + k1 + k2 m m
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
m m m

w = uvxyz | vxy | m | vy | 1

From Pumping Lemma: 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 m m m

w = uvxyz | vxy | m | vy | 1

Case 2: vxy is in b 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 m m m

w = uvxyz | vxy | m | vy | 1

m
Case 3: vxy is in c
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 m m m

w = uvxyz | vxy | m | vy | 1

m m
Case 4: vxy overlaps a and b

m m m
a ...aa ...aa b ...bb ...bbb ccc ...ccc
u vxy z
L = {a b c : n  0}
n n n

w=a b cm m m

w = uvxyz | vxy | m | vy | 1

Sub-case 1: v contains only a


y contains only 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
m m m

w = uvxyz | vxy | m | vy | 1

v =a k1
y =a k2
k1 + k2  1

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
m m m

w = uvxyz | vxy | m | vy | 1

v =a k1
y =a k2
k1 + k2  1

m + k1 m + k2 m
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
m m m

w = uvxyz | vxy | m | vy | 1

From Pumping Lemma: uv xy z  L


2 2

k1 + k 2  1
m + k1 m + k2 m
However: uv xy z = a
2 2
b c L
Contradiction!!!
L = {a b c : n  0}
n n n

w=a b cm m m

w = uvxyz | vxy | m | vy | 1

Sub-case 2: v contains a and b


y contains only 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
m m m

w = uvxyz | vxy | m | vy | 1
By assumption
v =a b k1 k2
y =a k3
k1 , k2  1
m m m
k1 k2 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 cm m m

w = uvxyz | vxy | m | vy | 1

v =a b k1 k2
y =a k3
k1 , k2  1
m m + k3 m
k1 k2 k1 k2 2k3
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 m m m

w = uvxyz | vxy | m | vy | 1

From Pumping Lemma: uv xy z  L


2 2

k1 , k2  1
However: uv xy z = a b a b
2 2 m k2 k1 m +k3
c L
m

Contradiction!!!
L = {a b c : n  0}
n n n

w=a b cm m m

w = uvxyz | vxy | m | vy | 1
Sub-case 3: v contains only a
y contains a and 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 m m m

w = uvxyz | vxy | m | vy | 1

m m
Case 5: vxy overlaps b and c
Similar to case 4
m m m
aaa...aaa bbb...bbb ccc...ccc
u vxy z
L = {a b c : n  0}
n n n

w=a b c m m m

w = uvxyz | vxy | m | vy | 1

Case 6: vxy overlaps a m


, b m and
c m

Impossible!
m m m
aaa...aaa bbb...bbb ccc...ccc
u vxy z
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. The alphabet Σ plus the special symbol #. We generally use Σ
= { a, b}.
2. 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.
3. 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)


Tape/QUEUE
a b b a # В В В … ….
R/W Head

Current State End of I/P Blank Symbols

Bounded to Left side UnBounded to Right side


Example
◼ Design a post machine that accepts the
following language which end by a.

b,  a, 

q0 a,  q1 #,  q 2

b, 
a b b a # В В В … ….
Example
◼ Design a post machine that accepts the
following language which end by a.

b,  a, 

q0 a,  q1 #,  q 2

b, 
a b b a # В В В … ….
Example
◼ Design a post machine that accepts the
following language which end by a.

b,  a, 

q0 a,  q1 #,  q 2

b, 
a b b a # В В В … ….
Example
◼ Design a post machine that accepts the
following language which end by a.

b,  a, 

q0 a,  q1 #,  q 2

b, 
a b b a # В В В … ….
Example
◼ Design a post machine that accepts the
following language which end by a.

b,  a, 

q0 a,  q1 #,  q 2

b, 
a b b a # В В В … ….
Example
◼ Design a post machine that accepts the
following language which end by a.

b,  a, 

q0 a,  q1 #,  q 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)

q3
a, a b,b
#, #
q0 a,  q1
b,  q2

#, #

a a b b # . . . … ….
Example
◼ Design a post machine that accepts the following
language. L={anbn|n >=0} (8 marks Nov-15)

q3
a, a b,b
#, #
q0 a,  q1
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)

q3
a, a b,b
#, #
q0 a,  q1
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)

q3
a, a b,b
#, #
q0 a,  q1
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)

q3
a, a b,b
#, #
q0 a,  q1
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)

q3
a, a b,b
#, #
q0 a,  q1
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)

q3
a, a b,b
#, #
q0 a,  q1
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)

q3
a, a b,b
#, #
q0 a,  q1
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)

q3
a, a b,b
#, #
q0 a,  q1
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)

q3
a, a b,b
#, #
q0 a,  q1
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

#, #

#, #
q1 q4 a, a
a, 
a, 
b, 
q0 a, b b, a
b,  a, 
#, # q2
b,  q3 b,b
#, #
q6
#, #
q8
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,  b, 
q5 a, a
q0 b, b
b,  a, 
#, # q2

q6
#, #
q4 #, #
Construct Post Machine which accepts the
Language over Σ = {a, b} is
L = {an b2n | n >= 0}
#, # a, a
b, b
q0
a,  q1 b,  q2 b,  q3

#, #
q6
RECALL
•Post Machine
•Examples
Thank You!!!!!!!!!!!!!

You might also like