RLCFL
5.2 Push Down Automata
59
• In this lecture we introduce Pushdown Automata, a computational model equivalent to context free lan guages
• A pushdown automata is an NFA augmented with a n infinitely large stack
• The additional memory enables recognition of som e non regular languages
Introduction and Motivation
60
Schematic of a Finite Automaton
Finite control
a a b a c
input
61
z
Schematic of a Pushdown Automaton
Finite control
b c c a a x
y
stack
input
62
• A Pushdown Automata (PDA) can write an unbound ed number of Stack Symbols on the stack and read these symbols later.
• Writing a symbol onto the stack is called pushing an d it pushes all symbols on the stack one stack cell d own.
Informal Description
63
• Removing a symbol off the stack is called popping a nd every symbol on the stack moves one stack cell up.
• Note: A PDA can access only the stack’s topmost sy mbol (LIFO).
Informal Description
64
• This PDA reads symbols from the input.
• As each 0 is read, it is pushed onto the stack.
• As each 1 is read, a 0 is popped from the stack.
• If the stack becomes empty exactly when the last 1 is read – accept.
Otherwise – reject.
A PDA Recognizing_________
65
n nL 0 1
• The definition of a PDA does not give a special way to check emptiness.
• One way to do it is to augment the stack alphabet wit h a special “emptiness” marker, the symbol $. (Note: T here is nothing special about $ any other symbol not i n the original can do.)
Checking Stack Emptiness
66
• The computation is started by an transition in which
$ is pushed on the stack.
• If the end marker $ is found on the stack at the end of the computation, it is popped by a single additional transition after which the automaton “knows” that th e stack is empty.
Checking Stack Emptiness
67
The label of each transition represents the input (left of arrow) and pushed stack symbol (right of the a rrow).
A PDA Recognizing_________
68
, $
1
q
q4 q3
n nL 0 1
q2 0, 0
0
, 1
0
, 1
,$
The $ symbol, pushed onto the stack at the beginning of the computation, is used as an “empty” marke r.
A PDA Recognizing_________
69
,e $
1
q
q4 q3
n nL 0 1
q2 0, 0
0
, 1
0
, 1
,$
The PDA accepts either if the input is empty, or if sca nning the input is completed and the PDA is at
A PDA Recognizing_________
70
,e $
1
q
q4 q3
n nL 0 1
q2 0, 0
0
, 1
0
, 1
,$
q
4• A Nondeterministic PDA allows nondeterministic tra nsitions.
• Nondeterministic PDA-s are strictly stronger then d eterministic PDA-s
• In this respect, the situation is not similar to the sit uation of DFA-s and NFA-s.
• Nondeterministic PDA-s are equivalent to CFL-s.
Nondeterministic PDAs
71
A pushdown automaton is a 6-tupple where:
1. is a finite set called the states.
2. is the input alphabet.
3. is the stack alphabet.
4. is the transition function.
5. is the start state, and
6. is the set of accepting states.
PDA – A Formal Definition
72
Q , , , , q
0, F
Q
: Q P Q, Qq0
Q F
• Consider the expression :
• Recall that , and that .
• Assume that the PDA is in state , the next input s ymbol is , and the top stack symbol is
PDA - The Transition Function
73
: Q P Q,
Q
q
• The next transition may either depend on the input sy mbol and the stack symbol , or only on the input symbol , or only on the stack symbol , or on none of them.
• This choice is formally expressed by the argument of t he transition function as detailed in the next slides.
PDA - The Transition Function
74
• Each step of the automaton is atomic, meaning it is ex ecuted in a single indivisible time unit.
• For descriptive purposes only, each step is divided int o two separate sub-steps:
• Sub-step1: A symbol may be read from the input, a symbol may be read and popped off the stack.
• Sub-step2: A state transition is carried out and a stack sym bol may be pushed on the stack.
Transition Function Sub-steps
75
• If the transition depends both on and we write
. In this case is consumed and is remove d from the stack.
• If the transition depends only on we write
, is consumed and the stack does not chang e.
Transition Function – 1
stSub-step
76
q, ,
q, ,
• If the transition depends only on , we write
. In this case is not consumed and is removed from the stack.
• Finally, If the transition depends neither on , nor o n , we write . In this case is not consume d and the stack is not changed.
Transition Function – 1
stSub-step
77
q, ,
q, ,
• The range of the transition function is :
The power set of the Cartesian product of the set of P DA states and the stack alphabet.
• Using pairs means that determines:
1. The new state to which the PDA moves.
2. The new stack symbol pushed on the stack.
PDA - The Transition Function
78
Q,
P
• Using the power set means that the PDA is nondeter ministic: At any given situation, it may make a nondet erministic transition.
• Finally, the use of means that at each tran sition the PDA may either push a stack symbol onto th e stack or not (if the value is ).
PDA - The Transition Function
79
Theorem:
A language is CFL if and only if there exists a PDA acc epting it.
Lemma->
For any CFL L, there exists a PDA P such that .
CFLG-s and PDA-s are Equivalent
80
PL L
• Since L is a CFL there exists a CFG G such that
. We will present a PDA P, that recognizes L.
• The PDA P starts with a word on its input.
• In order to decide whether , P simulates th e derivation of w.
Proof Idea
81
*
w
GL L
GL w
• Recall that a derivation is a sequence of strings, wh ere each string contains variables and terminals. Th e first string is always the start symbol of G and eac h string is obtained from the previous one by a singl e activation of some rule.
Proof Idea (cont.)
82
• A string may allow activation of several rules and th e PDA P non deterministically guesses the next rul e to be activated.
• The initial idea for the simulation is to store each in termediate string on the stack. Upon each producti on, the string on the stack before production is tran sformed to the string after production.
Proof Idea (cont.)
83
• Unfortunately, this idea does not quite work since a t any given moment, P can only access the top sym bol on the stack.
• To overcome this problem, the stack holds only a su ffix of each intermediate string where the top symb ol is the variable to be substituted during the next p roduction.
Proof Idea (cont.)
84
The Intermediate String aaSbb
Finite control
a a a b b
input
S b
stack
$
b b
85
Push the marker $ and the start symbol S on the stac k.
Repeat
If the top symbol is a variable V – Replace V by the ri ght hand side of some non deterministically chos en rule whose left hand side is V .
…..
Informal Description of P
86
Push the marker $ and the start symbol S on the stac k.
Repeat
…..
If the top symbol is a terminal compare it with the ne xt symbol on the input. If equal – advance the inp ut and pop the variable else – reject.
Informal Description of P
87