View
216
Download
1
Category
Preview:
Citation preview
1
Module 32
• Pushdown Automata (PDA’s)– definition– example
2
Pushdown Automata
Definition and Motivating Example
3
PDA’s
• In this presentation we introduce the PDA model of computation (programming language).– We first begin with an example NFA
– We augment this NFA with external memory in the form of a counter
– We then transform the counter into a stack to produce a PDA
• We define configurations and computations of these new computational models
• We define L(M) for these new computational models
4
NFA for {ambn | m,n >= 0} *
• What strings end up in each state of the above NFA?– A:
– 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
A B C
5
NFA+ for {anbn | n >=0 }
/\ /\
a b
A B C
NFA
a;add 1
A B C
b;substract 1
/\
/\;only if count 0Initialize count 0
NFA+
Imagine we now have memory in the form of a counter which we can increment or decrement every time we see an input character.
When we see an a in state A, we do the following two actions:1) We increment the counter value by 1.2) We stay in state A.
When we see a b in state B, we do the following two actions:1) We decrement the counter value by 1.2) We stay in state B.
From state B, we allow a /\-transition to state C only if1) The counter has value 0.
Finally, when we begin, the counter should have value 0.
6
Defining Configurations of NFA+
a;add 1
A B C
b;substract 1
/\
/\;only if count 0Initialize count 0
NFA+
The following information needs to be recorded in a configuration of a computation of an NFA+ M on an input string x.
1) Current state2) Remaining input to be processed3) Current counter value
• Note, the counter is NOT part of the input.• It is part of the computational model.• Its current value needs to be recorded in a configuration.
7
Computation Graph of NFA+
a;add 1
A B C
b;substract 1
/\
/\;only if count 0Initialize count 0
NFA+
Computation graph for this NFA+ on the input string aabb
(A,aabb,0)
(C,aabb,0)
(B,bb,2)
(B,abb,1)(A,bb,2)
(B,aabb,0)(A,abb,1)
(B,b,1)
(B,/\,0)
(C,/\,0)
8
Questions about NFA+ *
a;add 1
A B C
b;substract 1
/\
/\;only if count 0Initialize count 0
NFA+
1) Why can this NFA+ accept {anbn | n >= 0}? That is, how do we get around the Myhill-Nerode Theorem?
2) What happens if the counter has a finite capacity? For example, it can only go up to 10. Can some NFA+ still accept {anbn | n >= 0}?
3) Suppose that we have a stack data structure instead of a counter. Can we do anything we could with the counter?
9
PDA for {anbn | n >= 0}
a;add 1
A B C
b;substract 1
/\
/\;only if count 0Initialize count 0
NFA+
Here is a pushdown automaton (PDA) for this language.
A PDA is essentially an NFA augmented with an infinitecapacity stack.
The “pushdown” part of the name supposedlycomes from the stacks trays in cafeterias whereyou have to pushdown on the stack to add atray to it.
In this example, only one character a is ever pushed ontothe stack.
A B C
b;popa;push a
/\;only if stack is empty
PDA
/\
Initialize stack to empty
10
Defining Configurations of PDA
The following information needs to be recorded in a configurationof a computation of an PDA M on an input string x.
1) Current state2) Remaining input to be processed3) Current stack contents.
Note again, the stack is NOT part of the input.It is part of the computational model.However, its current value needs to be recorded in a configuration.
We will represent the stack contents by a string of characters.The leftmost character is on top of the stack.The rightmost character is at the bottom of the stack.
We will represent an empty stack with the string /\.
A B C
b;popa;push a
/\;only if stack is empty
PDA
/\
Initialize stack to empty
11
Computation Graph of PDA
Computation graph for this PDA on the input string aabb
(A,aabb,/\)
(C,aabb,/\)
(B,bb,aa)
(B,abb,a)(A,bb,aa)
(B,aabb,/\)(A,abb,a)
(B,b,a)
(B,/\,/\)
(C,/\,/\)
A B C
b;popa;push a
/\;only if stack is empty
PDA
/\
Initialize stack to empty
12
PDA for {anbn | n >= 0}
1) The first black character is the current input symbol.2) The second red character is the current top stack symbol.3) The third string of characters is the stack update action.
The stack character Z is a special character which we willalways keep on the bottom of the stack. Note it is part of , though,so it may be used other places as well.
A B C
b;popa;push a
/\;only if stack is empty
PDA
/\
Initialize stack to empty
A B C
b;a;popa;a;push aa;Z; push a
/\;Z;-/\;a;- /\;Z;-
Our actual PDA
Initialize stack to empty(only contains Z)
13
Computation Graph of PDA
Computation graph for this PDA on the input string aabb
(A,aabb,Z)
(C,aabb,Z)
(B,bb,aaZ)
(B,abb,aZ)(A,bb,aaZ)
(A,abb,aZ) (B,aabb,Z)
(B,b,aZ)
(B,/\,Z)
(C,/\,Z)
A B C
b;a;popa;a;push aa;Z; push a
/\;Z;-/\;a;- /\;Z;-
Our actual PDA
Initialize stack to empty(only contains Z)
14
Formal Definition of PDAA PDA M = (Q, , , q0, Z, A, )
Items common to NFAsQ is the set of states is the input alphabetq0 is the initial stateA is the set of accepting states
Modified/New items is the stack alphabet
- Z is a special character in - The stack always begins containing 1 Z
: modified as follows:pops/reads top stack symbol as well as
current input characterdescribes how to update stack
note push /\ results in pop!
Q = {I, B, C} = {a,b} = {Z, a}q0 = IZ is the initial stack characterA = {C}:
state input top stack next state 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
I B C
b;a;/\a;a; aaa;Z; aZ
/\;Z;Z/\;a;a /\;Z;Z
Our actual PDA
Initialize stack to empty(only contains Z)
15
L(M) for a PDA
Computation graph for this PDA on the input string aabb
(A,aabb,Z)
(A,abb,aZ) (B,aabb,)
(C,aabb,)(B,abb,aZ)(A,bb,aaZ)
(B,bb,aaZ)
(B,b,aZ)
(B,,Z)
(C)
A string x is in L(M) if and only if it there exists an accepting configuration (q, /\, anything) in the computation graph of Mon x .
An accepting configuration satisfies the following two conditions :
1) The PDA must be in an accepting state2) The input string must be completely processed
Note, the stack contents is unimportant.
This is known as acceptance by final state. An accepting configuration.
Not an accepting configurationbecause the remaining inputstring is not /\.
Not an accepting configurationbecause the state B is not anaccepting state.
A B C
b;a;-a;a;aaa;Z;aZ
/\;Z;Z/\;a;a /\;Z;Z
Our actual PDA
Initialize stack to empty(only contains Z)
16
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
17
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 which is a proper superset of DCFL
18
PDA Comments
• Note, we can use the stack for much more than just a counter
• See examples in section 6.1 for some details
Recommended