View
217
Download
0
Embed Size (px)
Citation preview
1
Module 32
• Pushdown Automata (PDA’s)– definition– Example
• We define configurations and computations of PDA’s
• We define L(M) for PDA’s
2
Pushdown Automata
Definition and Motivating Example
3
Pushdown Automata (PDA)
• In this presentation we introduce the PDA model of computation (programming language).– The key addition to a PDA (from an NFA-/\) is
the addition of external memory in the form of an infinite capacity stack
• The word “pushdown” comes from the stacks of trays in cafeterias where you have to pushdown on the stack to add a tray to it.
4
NFA for {ambn | m,n >= 0}
• What strings end up in each state of the above NFA?– I:
– B:
– C:
• Consider the language {anbn | n >= 0}.
• This NFA can recognize strings which have the correct form, – a’s followed by b’s.
• However, the NFA cannot remember the relative number of a’s and b’s seen at any point in time.
/\ /\
a b
I B C
5
PDA for {anbn | n >=0 } *
/\ /\
a b
I B C
NFA
Imagine we now have memory in the form of a stack which we can use to help remember how many a’s we have seen by pushing onto and popping from the stack
When we see an a in state I, we do the following two actions:1) We push an a on the stack.2) We stay in state I.
When we see a b in state B, we do the following two actions:1) We pop an a from the stack.2) We stay in state B.
From state B, we allow a /\-transition to state C only if1) The stack is empty.
Finally, when we begin, the stack should be empty.
I B C
b;popa;push a
/\;only if stack is empty
PDA
/\
Initialize stack to empty
6
Formal PDA definition
• PDA M = (Q, , , q0, Z, A, )
• Modified elements– is the stack alphabet
• Z is a special character that is initially on the stack
• Often used to represent an empty stack
– is modified as follows• Pop to read the top character on the stack
• Stack update action– What to push back on the stack
– If we push /\, then the net result of the action is a pop
7
Example PDAQ = {I, B, C} = {a,b} = {Z, a}q0 = IZ is the initial stack characterA = {C}:
S a TopSt NS stack update
I a a I push aaI a Z I push aZI /\ a B push aI /\ Z B push ZB b a B push /\B /\ Z C push Z
I B C
b;a;/\a;a; aaa;Z; aZ
/\;Z;Z/\;a;a /\;Z;Z
Example PDA
Initialize stack toonly contain Z
8
Computing with PDA’s *
• Configurations change compared with NFA-/\’s– Configuration components:
• current state• remaining input to be processed• stack contents
• Computations are essentially the same as with NFA-/\’s given the modified configurations– Determining which transitions of a PDA can be
applied to a given configuration is more complicated though
9
Computation Graph of PDA
Computation graph for this PDA on the input string aabb
(I,aabb,Z)
(C,aabb,Z)
(B,bb,aaZ)
(B,abb,aZ)(I,bb,aaZ)
(I,abb,aZ) (B,aabb,Z)
(B,b,aZ)
(B,/\,Z)
(C,/\,Z)
Q = {I, B, C} = {a,b} = {Z, a}q0 = IZ is the initial stack characterA = {C}:
S a TopSt NS stack updateI a a I push aaI a Z I push aZI /\ a B push aI /\ Z B push ZB b a B push /\B /\ Z C push Z
10
Definition of |- Input string aabb
(I, aabb, Z) |- (I,abb,aZ)
(I, aabb, Z) |- (B, aabb, Z)
(I, aabb, Z) |-2 (C, aabb, Z)
(I, aabb, Z) |-3 (B, bb, aaZ)
(I, aabb, Z) |-* (B, abb, aZ)
(I, aabb, Z) |-* (B, /\, Z)
(I, aabb, Z) |-* (C, /\, Z)
I B C
b;a;/\a;a; aaa;Z; aZ
/\;Z;Z/\;a;a /\;Z;Z
(I,aabb,Z)
(C,aabb,Z)
(B,bb,aaZ)
(B,abb,aZ)(I,bb,aaZ)
(I,abb,aZ) (B,aabb,Z)
(B,b,aZ)
(B,/\,Z)
(C,/\,Z)
11
Acceptance and Rejection
M accepts string x if one of the configurations reached is an accepting configuration
(q0, x, Z) |-* (f, /\),f in A, in *
Stack contents can be anything
M rejects string x if all configurations reached are either not halting configurations or are rejecting configurations
I B C
b;a;/\a;a; aaa;Z; aZ
/\;Z;Z/\;a;a /\;Z;Z
Input string aabb
(I,aabb,Z)
(C,aabb,Z)
(B,bb,aaZ)
(B,abb,aZ)(I,bb,aaZ)
(I,abb,aZ) (B,aabb,Z)
(B,b,aZ)
(B,/\,Z)
(C,/\,Z)
Not an accepting configuration since input not completely processed
Not an accepting configuration since state is not accepting
An accepting configuration
12
Defining L(M) and LPDA
• L(M) (or Y(M)) – The set of strings ?
• N(M)– The set of strings ?
• LPDA– Language L is in language
class LPDA iff ?
M accepts string x if one of the configurations reached is an accepting configuration
(q0, x, Z) |-* (f, /\),f in A, in *
Stack contents can be anything
M rejects string x if all configurations reached are either not halting configurations or are rejecting configurations
13
Deterministic PDA’s
• A PDA is deterministic if its transition function satisfies both of the following properties– For all q in Q, a in union {/\}, and X in ,
• the set (q,a,X) has at most one element
– For all q in Q and X in G,• if (q, /\, X) < > { }, then (q,a,X) = { } for all a in
• A computation graph is now just a path again• Our default assumption is that PDA’s are
nondeterministic
14
Two forms of nondeterminism
Trans Current Input Top of Next Stack# State Char. Stack State Update-------------------------------------------------------1 q0 a Z q0 aZ2 q0 a Z q0 aa
3 q0 /\ Z q0 aZ4 q0 a Z q0 aa
15
LPDA and DCFL
• A language L is in language class LPDA if and only if there exists a PDA M such that L(M) = L
• A language L is in language class DCFL (Deterministic Context-Free Languages) if and only if there exists a deterministic PDA M such that L(M) = L
• To be proven– LPDA = CFL – CFL is a proper superset of DCFL
16
PDA Comments
• Note, we can use the stack for much more than just a counter
• See examples in chapter 7 for some details