Pushdown Automata - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Pushdown Automata

Description:

Pushdown Automata – PowerPoint PPT presentation

Number of Views:338
Avg rating:3.0/5.0
Slides: 32
Provided by: juancarl
Category:

less

Transcript and Presenter's Notes

Title: Pushdown Automata


1
Pushdown Automata
  • Juan Carlos Guzmán
  • CS 6413 Theory of Computation
  • Southern Polytechnic State University

2
Summary
  • Definitions
  • Languages recognized
  • Equivalence to Context-Free Grammars
  • Deterministic PDAs

3
Pushdown Automaton
  • A pushdown automaton is
  • e-NFA
  • States
  • Transitions
  • Tape
  • Read-only
  • Read-once
  • Finite
  • Plus a stack
  • LIFO

4
Pushdown Automaton
  • A pushdown automaton P is a seven-element tuple
  • P (Q,S,G,d,q0,Z0,F )
  • where
  • Q is the set of states
  • S is the alphabet of the input tape
  • G is the alphabet of the stack
  • d is the transition function
  • q0 is the initial state
  • Z0 is the initial stack symbol
  • F is the set of final states

5
Pushdown Automaton
  • L 0n1n
  • P (q0,q1,q2,0,1,Z0,0,1,d,q0,Z0,q2),
    where
  • d(q0,0,Z0) (q0,0Z0)
  • d(q0,0,0) (q0,00)
  • d(q0,1,0) (q1,e)
  • d(q0,e,Z0) (q2,e)
  • d(q1,1,0) (q1,e)
  • d(q1,e,Z0) (q2,e)

6
Instantaneous Descriptions
  • The instantaneous description of a PDA is the
    triple (q, w, ?), where
  • q is a state
  • w is the remaining input
  • ? is the stack contents

7
Movement Relation
  • Establishes the relation between different
    instantaneous descriptions
  • (q,aw,X?) (p,w,??)
  • if (p,?) ? d(q,a,X )

8
Languages of a PDA
  • Remember that languages are sets of strings that
    satisfy a property
  • For a phrase, the automaton, started in its
    initial state, lands in a final state with the
    input tape completely consumed
  • Acceptance by final state
  • L(P ) w (q0,w,Z0) (q,e,?), q?F
  • For a phrase, the automaton, started in its
    initial state, consumes all stack symbols as the
    input tape completely consumed
  • Acceptance by empty stack
  • N(P ) w (q0,w,Z0) (q,e,e)

9
L(P ) vs. N(P ) vs. CFL
  • For a particular PDA P, L(P) and N(P) may be
    different
  • Take the families of languages implied by L(P)
    and N(P) over all PDAs P
  • Do they refer to the same family?, or
  • Is there a language in one of these families and
    not in the other?
  • Is one of them more powerful than the other?
  • How do these families relate to the Context-Free
    Languages?

10
Equivalences
  • These families of languages are equal
  • Context-Free Languages
  • Languages accepted by final state of a PDA
  • Languages accepted by empty stack of a PDA

11
From Acceptance by Empty Stack to Final State
  • For any L, if there exists PN such that LN(PN),
    then there is PF such that LL(PF)
  • If a language is accepted by empty stack by a
    PDA, then construct a new PDA with an augmented
    stack
  • A new initial stack symbol (X0)
  • A new initial state (p0)
  • A new final state (pf)
  • Augment the transitions as follows
  • The initial state should insert Z0 (old initial
    stack symbol into the stack)
  • All old states should have a transition to move
    to the new final state if X0 is visible

12
From Acceptance by Empty Stack to Final State
  • PN (Q,S,G,d,q0,Z0,?)
  • PF (Q ?p0,pf,S,G?X0,d,p0,X0,pf), where
  • d(p0,e,X0) (q0,Z0X0)
  • d(q,e,X0) (pf , e), for q ?Q
  • d(q,a,X) d(q,a,X), otherwise

13
From Acceptance by Final State to Empty Stack
  • For any L, if there exists PF such that LL(PF),
    then there is PN such that LN(PN)

14
From Acceptance by Final State to Empty Stack
  • PF (Q,S,G,d,q0,Z0,F)
  • PF (Q ?p0,p,S,G?X0,d,p0,X0,?), where
  • d(p0,e,X0) (q0,Z0X0)
  • d(q,e,X) (p,e), for all q ?F ?p, all X ?
    GUX0
  • d(q,a,X) d(q,a,X), otherwise

15
From Grammars to PDAs
  • Given G, construct a PDA P that simulates
    leftmost derivations of G
  • A sentential form can be characterized as xA?,
    where A is the leftmost variable
  • We will call A? as its tail
  • We want to make sure that
  • S ? xA? ? xy, iff
  • (q,xy,S) (q,y,A?) (q,e,e)

16
From Grammars to PDA
  • Let G (V,T,Q,S )
  • P (q,T,V ?T, d,q,S ), where
  • d(q,e,A) (q,ß) A ? ß ? Q (derive)
  • d(q,a,a) (q,e) (match)
  • Note that there is not a one-to-one
    correspondence between the leftmost derivation in
    the grammar and the movements of the automaton
  • Nice automaton but, does it recognize the same
    language as the grammar? Prove by induction (on
    the number of derivations taken to obtain the
    phrase

17
Example
  • Let G (A,C,0,1,R,A), where
  • R A ? 0 C e,
  • C ? 0 C 1 1
  • The PDA is P (q,0,1,0,1,A,C,d,q,A), where
  • d(q,e,A) (q,0C ),(q,e)
  • d(q,e,C) (q,0C 1),(q,1)
  • d(q,0,0) (q,e)
  • d(q,1,1) (q,e)

18
Grammar vs. PDA
  • (q,000111,A)
  • (q,000111,0C)
  • (q,00111,C)
  • (q,00111,0C 1)
  • (q,0111,C 1)
  • (q,0111,0C 11)
  • (q,111,C 11)
  • (q,111,111)
  • (q,11,11)
  • (q,1,1)
  • (q,e,e)

A
0
C
C
0
1
C
0
1
1
19
Correctness
  • L(G) L(P)
  • Vw, S gtw iff (q,w,S) -(q,eps,eps)
  • By induction on the number of derivations

20
From PDAs to Grammars
  • This is a more complex construction, since we
    have to deal with different states

21
From PDAs to Grammars
  • Let P (Q, S,G,d,q0,Z0) be a PDA
  • Let G (V, S,R,S ), such that
  • S?V
  • For all p,q ? Q, X ? G, pXq ? V
  • For all p ? Q, S?q0Z0p ? R
  • If (r,Y1Y2Yk) in d(q,a,X)
  • then, for all states ri
  • qXrk ? arY1r1r1Y2r2rk-1Ykrk

22
Example
  • Recall sample automaton

23
Grammar Variables
  • S
  • q01q0
  • q01q1
  • q01q2
  • q11q0
  • q11q1
  • q11q2
  • q21q0
  • q21q1
  • q21q2
  • q00q0
  • q00q1
  • q00q2
  • q10q0
  • q10q1
  • q10q2
  • q20q0
  • q20q1
  • q20q2
  • q0Z0q0
  • q0Z0q1
  • q0Z0q2
  • q1Z0q0
  • q1Z0q1
  • q1Z0q2
  • q2Z0q0
  • q2Z0q1
  • q2Z0q2

24
Grammar Productions
  • S
  • S ? q0Z0q0
  • S ? q0Z0q1
  • S ? q0Z0q2
  • d(q0,0,Z0) (q0,0Z0)
  • q0Z0q0 ? 0q00q0q0Z0q0
  • q0Z0q0 ? 0q00q1q1Z0q0
  • q0Z0q0 ? 0q00q2q2Z0q0
  • q0Z0q1 ? 0q00q0q0Z0q1
  • q0Z0q1 ? 0q00q1q1Z0q1
  • q0Z0q1 ? 0q00q2q2Z0q1
  • q0Z0q2 ? 0q00q0q0Z0q2
  • q0Z0q2 ? 0q00q1q1Z0q2
  • q0Z0q2 ? 0q00q2q2Z0q2
  • d(q0,0,0) (q0,00)
  • q00q0 ? 0q00q0q00q0
  • q00q0 ? 0q00q1q10q0
  • q00q0 ? 0q00q2q20q0
  • q00q1 ? 0q00q0q00q1
  • q00q1 ? 0q00q1q10q1
  • q00q1 ? 0q00q2q20q1
  • q00q2 ? 0q00q0q00q2
  • q00q2 ? 0q00q1q10q2
  • q00q2 ? 0q00q2q20q2

25
Grammar Productions
  • d(q0,1,0) (q1,e)
  • q00q1 ? 1
  • d(q0,e,Z0) (q2,e)
  • q0Z0q2 ? e
  • d(q1,1,0) (q1,e)
  • q10q1 ? 1
  • d(q1,e,Z0) (q2,e)
  • q1Z0q2 ? e

26
Grammar Notes
  • The generated grammar has
  • 28 variables
  • 25 productions
  • However, most of them are useless
  • The highlighted variables and productions are not
    useless
  • Variables
  • q0Z0q2
  • q1Z0q2
  • q00q1
  • q10q1
  • Productions
  • S?q0Z0q2
  • q0Z0q2 ? 0q00q1q1Z0q2
  • q00q1 ? 0q00q1q10q1
  • q00q1 ? 1
  • q0Z0q2 ? e
  • q10q1 ? 1
  • q1Z0q2 ? e

27
PDA vs. Grammar
S
  • (q0,000111,Z0)
  • (q0,00111,0Z0)
  • (q0,0111,00Z0)
  • (q0,111,000Z0)
  • (q1,11,00Z0)
  • (q1,1,0Z0)
  • (q1,e,Z0)
  • (q2,e,e)

q0Z0q2
0
q00q1
q1Z0q2
q00q1
0
e
q10q1
q00q1
0
q10q1
1
1
1
28
PDA vs. Grammar
8 1
S
  • (q0,000111,Z0)
  • (q0,00111,0Z0)
  • (q0,0111,00Z0)
  • (q0,111,000Z0)
  • (q1,11,00Z0)
  • (q1,1,0Z0)
  • (q1,e,Z0)
  • (q2,e,e)

8 1
q0Z0q2
7 2
8 7
0
q00q1
q1Z0q2
6 3
7 6
q00q1
0
e
q10q1
5 4
6 5
q00q1
0
q10q1
1
1
1
29
Grammar Notes
S
  • Lets rename the variables
  • q0Z0q2 ? A
  • q1Z0q2 ? B
  • q00q1 ? C
  • q10q1 ? D
  • Productions
  • S ? A
  • A ? 0 C B e
  • C ? 0 C D 1
  • D ? 1
  • B ? e
  • Equivalent Grammar
  • A ? 0 C e
  • C ? 0 C 1 1

A
0
C
B
C
0
e
D
C
0
D
1
1
1
30
Deterministic PDA
  • There is never a choice of movement in any
    situation
  • d(q,a,X) does not contain more than one entry
  • If some d(q,a,X) is nonempty, then d(q,e,X) must
    be empty

31
Deterministic PDA
  • Recognize some CFLs
  • Recognize some languages that are not regular
  • Do not recognize all CFLs

PDAs
DPDAs
FAs
Write a Comment
User Comments (0)
About PowerShow.com