Top Banner
cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans
27

Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Jan 02, 2016

Download

Documents

Neil Hunt
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

cs3102: Theory of Computation

Class 6: Pushdown Automata

Spring 2010University of VirginiaDavid Evans

Page 2: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Menu

• Revisiting and Reversing the Pumping Lemma• Recognizing Non-Regular Languages• Pushdown Automata

Page 3: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Revisiting the Pumping Lemma

q0

qz

x

y

z

If input string is longer than |Q|, some state must repeat.

qi

If A is a regular language, then there is some number p (the pumping length) where for any string sA and |s| p, s may be divided into three pieces, s = xyz, such that |y|> 0, |xy| p, and for any i 0, xyizA.

Page 4: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Pumping Game for Language A1. Player 1: picks p2. Player 2: picks sA and |s| p3. Player 1: picks x, y, z, |y|> 0, |xy| p, s = xyz4. Player 2: picks i 0

Player 1 wins if xyiz A, Player 2 wins if xyizAIf Player 1 can always win: A is regularIf Player 2 can always win: A is not regular

q0

qz

x

y

z

qi

What if Player 2 picks an sA?

Page 5: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Pump-Priming Game for Language A1. Player 1: picks p2. Player 2: picks sA and |s| p3. Player 1: picks x, y, z, |y|> 0, |xy| p, s = xyz4. Player 2: picks i 0

Player 1 wins if xyiz A, Player 2 wins if xyiz AIf Player 1 can always win: A is regularIf Player 2 can always win: A is not regular

q0

qz

x

y

z

qi

Page 6: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

A = { w | w has more 0s than 1s }

Pump-Priming Game for Language A1. Player 1: picks p2. Player 2: picks sA and |s| p3. Player 1: picks x, y, z, |y|> 0, |xy| p, s = xyz4. Player 2: picks i 0

Player 1 wins if xyiz A, Player 2 wins if xyiz AIf Player 1 can always win: A is regularIf Player 2 can always win: A is not regular

Page 7: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

A Complementary View

• Regular Languages are closed under complement: if A is regular, then Ā is regularProof sketch:

DFA M = (Q, , , q0, F) recognizes A.

DFA M = (Q, , , q0, Q F) recognizes Ā.

• Thus, Player 2 wins by showing either A or Ā is non-regular.

Page 8: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

s

All Languages

RegularLanguages

Can be recognized by some DFA

Finite Languages

anbn

wwR

What do we need to add to a DFA to recognize some non-regular languages?

Page 9: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

DFA + Counter?A = anbn

Page 10: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

DFA + Counter?

count = 0

A = anbn

a, count = count + 1 b, count = count 1

b, count = count 1

Accept if count == 0.

Page 11: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

DFA + Stack = Deterministic Pushdown Automaton

A = anbn

Page 12: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

DFA + Stack = Deterministic Pushdown Automaton

a, push a b, pop a

b, pop a

Accept if stack is empty.

A = anbn

Page 13: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Formalizing DPDA

(Q;§ ;¡ ;±;q0;F )(Q;§ ;¡ ;±;q0;F )

Note: Sipser only defines Nondeterministic PDA and calls it PDA.

Page 14: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

DPDA Transitions

Inputs: state, alphabet symbol or ε, popped stack symbol or εOutputs: state, stack symbol to push or ε

It is a deterministic machine: must always follow possible ε-input transition.

a, ε Aq1 q2

Page 15: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Deterministic Pushdown Automaton

q1 q2

a, ε +

b, + ε

A = anbn

Bottom of stack marker

q0 b, + ε

ε, ε $

q3

ε, $ ε

This looks like nondeterminism, but is not: must always take possible ε-transitions a state with an (ε, h) transitions cannot have any other (a, h) transitions; a state with a (a, ε) transition, cannot have any other (a, h) transitions

Page 16: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

A = { w | w has more 0s than 1s }

Page 17: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Computing Model for DPDA

First, we need to model the stack!

$

+

+

+

push +

$

+

+

+

+

pop +

$

+

+

+

Page 18: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Modeling the Stack

Page 19: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Modeling the Stack

This would be a normalway to define a stack, but not what we use!

Page 20: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

DPDA Computation Model

±¤ : Q £ § ¤ £ ¡ ¤² ! Q £ ¡ ¤²

±¤(q;²;°) = (q;°)

8q2 Q;8a 2 § ;x 2 § ¤;° 2 ¡ ¤ :

Page 21: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

±¤ : Q £ § ¤ £ ¡ ¤² ! Q £ ¡ ¤²8q2 Q;8a 2 § ;x 2 § ¤;° 2 ¡ ¤;h 2 ¡ :

±(q;a;²) ! (qt; ²) ) ±¤(q;ax;°) = ±¤(qt;x;°)

±(q;a;²) ! (qt;hp) ) ±¤(q;ax;°) = ±¤(qt;x;hp°)

±(q;a;ht) ! (qt;hp) ) ±¤(q;ax;ht°) =±¤(qt;x;hp°)

±(q;a;ht) ! (qt;²) ) ±¤(q;ax;ht°) =±¤(qt;x;°)

No push or pop:

Push only:

Pop only:

Push and pop:

This rule actually covers all four cases if we make h 2 ¡ ²

Page 22: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Dealing with -transitionsRemember the NFA DFA proof?

Page 23: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

DPDA Computing Model

±(q;a;ht) ! (qt;hp) ) ±¤(q;ax;ht°) =±¤(qr ;x;°r )

±¤(q;²;°) = E (q;°)

Where E is the forced-follow -transitions function defined by:

E : Q £ ¡ ¤ ! Q £ ¡ ¤

E (q;°) = (q;°)±(q;²;°) = ; :

E (q;ht°) = E (qt;hp°)

±(q;²;ht°) = (qt;hp°) :

(qr ;°r ) = E (qt;hp°)where

Page 24: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Acceptance: PDA accepts w when:Accepting State Model

±¤(q0;w;²) ! (qf ;s) ^qf 2 F

Empty Stack Model

±¤(q0;w;²) ! (q;²)Is the set of languages accepted by DPDAs with each model the same?

A good, original proof is worth a challenge bonus. (Finding a published proof is not.)

Page 25: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Power of DPDAsL(DPDA) L(DFA) ?

1. Prove there is some DPDA that recognizes every regular language.

2. Prove there is some language that can be recognized by a DPDA that cannot be recognized by any PDA.

Construct DPDA from DFA by addingempty stack transitions:

±DP DA (q;a;²) = (±D F A (q;a);²)

A = fanbn jn ¸ 0g

Henceforth: assume DPDA is Accepting-State DPDA

Page 26: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

s

All Languages

RegularLanguages

Can be recognized by some DFA

Finite Languages

anbn

DPDA Languages(Accepting State)

Page 27: Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

Charge

• Thursday:– Non-equivalence of NPDA and DPDA– Context-Free Grammars

• Next Tuesday:– PS2 Due– Languages that cannot be recognized by NPDA