Top Banner
cs3102: Theory of Computation Class 4: Nondeterminism Spring 2010 University of Virginia David Evans PS1 is due now!
31

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

Dec 30, 2015

Download

Documents

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 4: Nondeterminism Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.

cs3102: Theory of Computation

Class 4: Nondeterminism

Spring 2010University of VirginiaDavid Evans

PS1 is due now!

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

Adding Nondeterminism

1 2

Deterministic machine: at every step, there is only one choice

Nondeterministic machine: at some steps, there may be more than one choice.

a

a, b

b

b

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

Nondeterminism in Practice

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

Nondeterminism in Theory

Omnipotent: Machine splits into a new machine for each choice; if any machine accepts, accept.

Omniscient: Whenever it has to make a choice, machine always guesses right.

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

Example NFA

1 2 3

a b

a, b

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

Defining DFAs

A deterministic finite automaton is a 5-tuple:Q finite set (“states”)S finite set (“alphabet”) d : Q Q transition functionq0 Q start state

F Q set of accepting states

How do we need to change this to support nondeterminism?

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

Defining NFAs

A nondeterministic finite automaton is a 5-tuple:Q finite set (“states”)S finite set (“alphabet”) transition

functionq0 Q start state

F Q set of accepting statesOutput of transition function is a set of states, not just one state.

±: Q £ (§ [ f ²g) ! P (Q)

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

Computation Model of NFA

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

Computation Model of NFA

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

Is an NFA more powerful than a DFA?

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

Power of Machines

Languages that can be recognized

by an A

Languages that can be recognized

by a B

A and B are non-comparable.

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

Power of Machines

Languages that can be recognized

by an A

Languages that can be recognized

by a B

B is less powerful than A:(1) Some A can recognize

every language a B can recognize.

(2) There is some language that can be recognized by an A but not by any B.

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

Power of Machines

Languages that can be recognized

by an A

Languages that can be recognized

by a B

A and B are equal: (1) every language that can

be recognized by an A can be recognized by some B

(2) every language that can be recognized by a B can be recognized by some A

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

Power of NFA/DFA

Easy part: is there any language a DFA can recognize that cannot be recognized by an NFA?

Hard part: is there any language an NFA can recognized that cannot be recognized by a DFA?

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

L(NFA) L(DFA)A nondeterministic finite automaton is a 5-tuple:Q finite set (“states”)S finite set (“alphabet”) q0 Q start state

F Q set of accepting states

±: Q £ (§ [ f ²g) ! P (Q)

Proof by construction:Construct the NFA N corresponding to any DFA A = (Q, , , q0,F):

N = (Q, , ’, q0,F) where q Q, ’(q, ) = reject a , ’(q, a) = { (q, a) }

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

Power of NFA/DFA

Easy part: is there any language a DFA can recognize that cannot be recognized by an NFA?

Hard part: is there any language an NFA can recognized that cannot be recognized by a DFA?

No: NFAs are at least as powerful as DFAs.

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

L(DFA) L(NFA)

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

L(DFA) L(NFA)

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

Example Conversion

1 2 3

a b

a, b

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

1 2 3

a b

a, b

{1} {2} {1, 2} {1, 3}

{2, 3} {1,2, 3}{3}{}

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

1 2 3

a b

a, b

{1} {2} {1, 2} {1, 3}

{2, 3} {1,2, 3}{3}{}

a

a

b

b

b

a

b

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

Converting NFAs to DFAs

How many states may be needed for the DFA corresponding to and NFA with N states?

How much bigger is the transition function for the DFA corresponding to and NFA with N states?

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

Regu

lar E

xpre

ssio

ns

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

“something formatted like an [email] address”

address@domain

[A-Za-z0-9]*@[A-Za-z0-9]*(. [A-Za-z0-9]*)*

This matches most email addresses. Matching the full spec of all possible email addresses is left as exercise.

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

Regular Expression

Base: Language a { a }

{ } { }

Induction: R1, R2 are regular expressions

R1 R2 L(R1) L(R2)

R1 R2 { xy | xL(R1) and yL(R2) }

R1* { xn | xL(R1) and n ≥ 0 }

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

How powerful are Regular Expressions?

Is there a Regular Expression that describes the same language as any NFA?

Is there some NFA that describes the same language as any Regular Expression?

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

L(RE) L(NFA)

Base: Language a { a }

{ } { }

Induction: R1, R2 are regular expressions

R1 R2 L(R1) L(R2)

R1 R2 { xy | xL(R1) and yL(R2) }

R1* { xn | xL(R1) and n ≥ 0 }

Proof by construction.Trivial to draw NFAs forEach of these languages.

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

L(RE) L(NFA)

Base: Language a { a }

{ } { }

Proof by construction.Trivial to draw NFAs forEach of these languages.

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

L(RE) L(NFA)

Induction: R1, R2 are regular expressions

R1 R2 L(R1) L(R2)

R1 R2 { xy | xL(R1) and yL(R2) }

R1* { xn | xL(R1) and n ≥ 0 }

Proof by induction and construction.Assume there are NFAs A1 and A2 that recognize the languages L(R1) and L(R2). Show how to construct an NFA that recognizes the produced language for each part.

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

Proving: R1 R2

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

Charge

• PS2 will be posted by tomorrow• Finish reading Chapter 1• Thursday: how to prove a language is non-

regular