Professional Documents
Culture Documents
Regular languages are recognized by nite automata, context free languages are recognized by non-deterministic pushdown automata.
Models of Computation
(We mostly follow the denitions in Kozens Automata and Computability.) A (non-deterministic) pushdown automaton is like an NFA, except it has a stack (pushdown store) for recording a potentially unbounded amount of information, in a last-in-rst-out (LIFO) fashion.
input string
stack head (push/pop)
(pushdown) stack
nite control
Models of Computation
In each step, the NPDA pops the top symbol off the stack; based on (1) this symbol, (2) the input symbol currently reading, and (3) its current state, it can 1. push a sequence of symbols (possibly ) onto the stack 2. move its read head one cell to the right, and 3. enter a new state according to the transition rule
of the machine.
We allow -transition: an NPDA can pop and push without reading the next input symbol or moving its read head. Note: an NPDA can only access the top of stack symbol in each step.
Models of Computation
Intuitive description of an NPDA: 1. WHILE <input symbol is [> DO <push [ onto the stack>. 2. WHILE <input symbol is ]> and <top of stack is [> DO <pop>. 3. IF <all of input read> and <top of stack is > THEN <accept>. ( is initial stack symbol.)
4
Example: input is [ [ ] [ ] ] Think of an NPDA as (representing) an algorithm (for a decision problem) with memory access in the form of a stack.
Models of Computation
Denition of an NPDA
and
X#YNZ7[\^].!_0
is the start state
`A#Q
! .
Note: An NPDA is strictly more powerful than a deterministic PDA. We shall not consider the latter specically here.
Models of Computation 5
Conguration
A conguration of
is an element of
!"
state, (2) the portion of the input yet unread (i.e. under and to the right of the input head) and (3) the current stack contents. The start conguration is
#%$'&)(+*,(-/. 0
. I.e.
its input head scanning the leftmost input symbol and the stack containing only The next-conguration relation describes how
If
#%$2(435.678#:9;(=<>(+?/. <
#:9;(=<@>(G?BCH.I0
(The input symbol pushed, and the new state is $ .)
#%$J(+@>(43>CH.
was popped and 3 was
If
#%$2(435.678#:9;(
'(G?.
#L9M(+@>(G?BCH.N0
gAhGi
0 k l 0
, written
0
, as follows:
& 0 l krqts\u 0 l
and dene from
mRn mRn k 0 q l
kpo vxwcf 0
q w
wz0 k
l 0 l
iff
0 l
just if
follows
#%$ & (+de(-/. 0 where $,6EV and 3K6 are called accepting. 3~6E"
, we have The language of by
, written
S#%z.
Models of Computation
$,6
#Q$J(
'(
.-f
Models of Computation
\JO
2. Non-deterministically guess that the middle of the string has been reached at some point during 1, and then change into popping off the stack for each symbol read, checking to see if they (i.e. symbols just popped and just read) are the same. 3. If they are always the same symbols, and the stack empties at the same time as the input is nished, accept.
Models of Computation
\JO
#[$ u (=$ & (=$]( [}8 ( [}8(' ) (' \] (-N] (=(=$ & (
([$e].
where
,W
where
}8('
Models of Computation
10
\JO
X X
push
=+N
pop
#%$%(43M.67#%$2(=<O(-.
to
$ .
Models of Computation
11
#%$ & ( 0 0 0 0 0 0 0 0 #%$ & ( #%$ & ( #%$ & ( #%$ u ( #%$u( #%$u( #%$u( #%$(
X X =
push
=+X
pop
Models of Computation
12
Implementation-level description:
Transition diagram:
(T. 0 0 0
[ [
[( [. ]( [.
[ [
[#%$2().O] [#%$ (
.]
#%$2(t8(T.
Models of Computation
13
A major result in automata theory is: Theorem. A language is context-free iff some NPDA accepts it. Proof overview We are breaking down the proof into the following steps: A Given a CFG
. generating S#_. .
B Given an NPDA
1 Every NPDA can be simulated by an NPDA with one state 2 Every NPDA with one state has an equivalent CFG.
Models of Computation
14
informally:
1. Place the start variable symbol on the stack. 2. Repeat forever: Pop top-of-stack d . Cases of: (a)
d *
is a variable
and replace
by the string *
(say) on the rhs of the rule (so that the leftmost symbol of
(b)
d d
is a terminal < : Read the next input symbol and compare it with < . If they
do not match, then exit (and reject this branch of the nondeterminism). (c) Claim:
accepts S#Y. .
Models of Computation
15
>
Implementation-level description:
Transition diagram:
is given by
2 U
; = = = -
Models of Computation
16
#%$U&t( 0 0 0 0 0 0 0 0 0 0 0 #%$u( #%$ u ( #%$ u ( #%$u( #%$u( #%$ u ( #%$u( #%$ u ( #%$ u ( #%$ u ( #%$ (
<x<x( <x<x( <x<x( <x( <x( <x( <x( ( ( U( U( U( X0
/. /. <8F/. F/. U"<8F/. "<8F/. <8F/. F/. /. /. /.
. <8FN0 <xUH<"UN0 <x<8FUI0 <x<xX0 <x<x
17
(1)
(2)
J4 J4 J4 2
; = = =
(3)
(3)
(3)
Leftmost derivation:
Models of Computation
We do this in two steps: 1. Every NPDA can be simulated by an NPDA with one state 2. Every NPDA with one state has an equivalent CFG. For 2: Take a one-state NPDA empty stack. Dene
o o
#[$T](-S(+(=(=$2(-,(
t. #T(-S(G(-/. ^u''/
where
that accepts by
where
contains a rule
?
for every transition have
S#%z.
#%$2(=,u''/.678#%$2(=(G?. S#Y . .
6KIZ[\^]
. Then we
Models of Computation
18
Idea: maintain all state information on the stack. W.l.o.g. we assume form
is of the
#QR(-S(+T(=(-)(-,([M>]. , and can empty its stack after entering nal state . o Set e aAN! (elements are written L9?_$ ). We construct a new NPDA o #["]J(-S(+ (= (J(Q+-(
t.
#%$U&)(=u''/.67#L9M(=(G?.
where
6KIZ7[H]
, include in
the transition
$ u ('''(=$
.
19
Intuitively
simulates
will be
in at certain future points in the computation, saving those guesses on the stack, and then verifying later that the guesses were correct. Lemma.
9B?~$
q #L9M(+de(+?/. 0
It then follows that
#%$J(
'(
. S#%z. o
mRn S#%.
.
q #J(+d5(9?_$+. 0 R #J(
U(
-.
Models of Computation
20
o # u(-S(u(-u-. and # (-( (- . be context o free grammars with Tu\ . Consider the following context free grammars o UU
#Tu\ZA Z7[H](-S(u\Z Z7[HN0 u(-N0 ](-. o
#Tu\ZA Z7[H](-S(u\Z Z7[HN0 u ]J(-F. o Q+ #Tu\Z7[H]J(
(7u\Z[HN0 u\(-N0 ](-.
Proof idea. Let
,u
where
S#YUU
. S#Y
. S#YQ++.
Models of Computation
o o o