Top Banner
Finite Automata and Non Determinism http://cis.k.hosei.ac.jp/ ~yukita/
46

Finite Automata and Non Determinism yukita

Dec 19, 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: Finite Automata and Non Determinism yukita/

Finite Automata andNon Determinism

http://cis.k.hosei.ac.jp/~yukita/

Page 2: Finite Automata and Non Determinism yukita/

2

Definition 1.1: Finite Automaton

. theis 5.

and , theis 4.

, theis : 3.

, thecalledset finite a is 2.

, thecalledset finite a is 1.

where),,,,,( tupple-5 a is A

0

0

states accept of set

state start

function transition

alphabet

states

automatonfinite

QF

Qq

QQ

Q

FqQ

Page 3: Finite Automata and Non Determinism yukita/

3

State Diagram for M1

q3q1 q2

0 1

10

0, 1

Page 4: Finite Automata and Non Determinism yukita/

4

Data Representation for M1

.}{ 5.

and state,start theis 4.

,

10

as described is 3.

{0,1} 2.

},,{ 1.

2

1

223

232

211

321

qF

q

qqq

qqq

qqq

qqqQ

Page 5: Finite Automata and Non Determinism yukita/

5

Task 01DFA

1. Implement M1 with your favorite programming language.

2. GUI• Two buttons for input 0 and 1• State chart with the current state highlighted

Page 6: Finite Automata and Non Determinism yukita/

6

Language of M1

}1last thefollow 0s ofnumber even an

and 1 oneleast at contains |{)(

. say that can We

accepts. machine that strings all ofset theis

),( as written , The

1 wwML

AM

M

MLM

recognizes

machine oflanguage

Page 7: Finite Automata and Non Determinism yukita/

7

State Diagram for M5

q2

q1

q0

0

1

12

2, <RESET>

1, <RESET>

2

0, <RESET> 0

Page 8: Finite Automata and Non Determinism yukita/

8

Data Representation for M5

.}{ 5.

and state,start theis 4.

,

210

as described is 3.

,0,1,2}RESET{ 2.

},,{ 1.

0

0

10202

02101

21000

210

qF

q

qqqqq

qqqqq

qqqqq

R

qqqQ

Page 9: Finite Automata and Non Determinism yukita/

9

Informal Description of M5

• M5 keeps a running count of the sum of the numerical symbols it reads, modulo 3.

• Every time it receives the <RESET> symbol it resets the count to 0.

• M5 accepts if the sum is 0, modulo 3.

Page 10: Finite Automata and Non Determinism yukita/

10

Definition 1.7: Regular Language

• A language is called a regular language if some finite automaton recognizes it.

Page 11: Finite Automata and Non Determinism yukita/

11

Example 1.9: A finite automaton E2

• E2 recognizes the regular language of all strings that contain the string 001 as a substring.

• 0010, 1001, 001, and 1111110011110 are all accepted,

• but 11 and 0000 are not.

Page 12: Finite Automata and Non Determinism yukita/

12

Find a set of states of E2

You

1. haven’t just seen any symbols of the pattern,

2. have just seen a 0,

3. have just seen 00 or,

4. have just seen the entire pattern 001.

Assign the states q,q0,q00, and q001 to these possibilities.

Page 13: Finite Automata and Non Determinism yukita/

13

Draw a State Diagram for E2

q00 q001

0 0, 1

1

1

0q0

0

q

1

Page 14: Finite Automata and Non Determinism yukita/

14

Regular Operations on Languages

operation. a onelast theand

,operations are operations first two The

}.each and 0|{ :

}. and |{ :

}.or |{ :

languages. be and Let

21*

unary

binary

AxkxxxA

ByAxxyBA

BxAxxBA

BA

ik

Star

ionConcatenat

Union

Page 15: Finite Automata and Non Determinism yukita/

15

Example 1.11

}. ,goodbadbad

d,goodbadgoo goodbad, good od,goodgoodgo

badbad, goodbad, goodgood, bad, good, ,{

and },badgirl badboy, goodgirl, goodboy,{

},girl boy, bad, good,{

have weThen, }.girl boy,{ and }bad good,{Let

}.z,,ba,{ be alphabet Let the

*

A

BA

BA

BA

Page 16: Finite Automata and Non Determinism yukita/

16

Theorem 1.12 Closedness for Union

. is so

languages,regular are and if s,other wordIn

operation.union the

under closed is languagesregular of class The

21

21

AA

AA

Page 17: Finite Automata and Non Determinism yukita/

Proof of Th 1.12 17

Proof of Theorem 1.12

on.constructi theof scorrectnes check the Then,

.),,,,( where

, recognize toConstruct

.),,,,( where, recognize and

),,,,,( where, recognize Let

21

2222222

1111111

FqQM

AAM

FqQMAM

FqQMAM

Page 18: Finite Automata and Non Determinism yukita/

Proof of Th 1.12 18

Construction of M

}.or |),{()()( 5.

).,( 4.

)),(),,(()),,((;,),( 3.

(Why?) .alphabet

same thehave and that assumecan We2.

}. and |),{( 1.

2211212121

210

22112121

21

22112121

FrFrrrFQQFF

qqq

arararraQrr

MM

QrQrrrQQQ

Page 19: Finite Automata and Non Determinism yukita/

Proof of Th 1.12 19

Correctness

You should check the following.

1. For any string recognized by M1 is recognized by M.

2. For any string recognized by M2 is recognized by M.

3. For any string recognized by M is recognized by M1 or M2.

Page 20: Finite Automata and Non Determinism yukita/

20

Theorem 1.13 Closedness for concatenation

. is so

languages,regular are and if s,other wordIn operation.

ionconcatenatunder closed is languagesregular of class The

21

21

AA

AA

Page 21: Finite Automata and Non Determinism yukita/

21

Nondeterminism

• To prove Theorem 1.13, we need nondeterminism.

• Nondeterminism is a generalization of determinism. So, every deterministic automaton is automatically a nondeterministic automaton.

Page 22: Finite Automata and Non Determinism yukita/

22

Nondetermistic Finite Automata

• A nondeterministic finite automaton can be different from a deterministic one in that– for any input symbol, nondeterministic one

can transit to more than one states.– epsilon transition

• NFA and DFA stand for nondeterministic finite automaton and deterministic finite automaton, respectively.

Page 23: Finite Automata and Non Determinism yukita/

23

NFA N1

q3q1 q2

0,1

1 0, q4

0,1

1

Page 24: Finite Automata and Non Determinism yukita/

24

Parallel world and NFA

... ...accept

Page 25: Finite Automata and Non Determinism yukita/

25

Example 1.14 NFA N2

q3q1 q2

0,1

1 0, q4

0,1

Let language A consist of all strings over {0,1} containing a 1 in the third position from the end. N2 recognizes A.

Page 26: Finite Automata and Non Determinism yukita/

26

A DFA equivalent to N2

q010q000 q100

0

0 0 q110

q011q001 q101

q111

1

0

1

00

10

11

01

1

Page 27: Finite Automata and Non Determinism yukita/

27

Example 1.15 NFA N3

0

Let language A consist of all strings 0k , where k is a multiple of 2 or 3. N3 recognizes A.

0

0

0

0

Page 28: Finite Automata and Non Determinism yukita/

28

A DFA equivalent to N3

0q 2q 1 q3

q50

q0

0 0 0 q4

0

q-1

11

1 1 1

1

0, 1

Page 29: Finite Automata and Non Determinism yukita/

29

Example 1.16 NFA N4

q1

q2q3

a

b

a,b

a

N4 accepts , a, baba, and baa. N4 does not accept b, nor babba.

Page 30: Finite Automata and Non Determinism yukita/

30

Definition 1.17: NFA

. theis 5.

and , theis 4.

, theis 2: 3.

, thecalledset finite a is 2.

, thecalledset finite a is 1.

where),,,,,( tupple-5 a is A

0

0

states accept of set

state start

function transition

alphabet

states

automatonfinite nistic nondetermi

QF

Qq

Q

Q

FqQ

Q

Page 31: Finite Automata and Non Determinism yukita/

31

Example 1.18 NFA N1

}.{ 5.

state.start theis 4.

}{}{

}{

}{}{

},{}{

10

asgiven is 3.

}1,0{ 2.

},,,,{ 1.

4

1

444

43

332

2111

4321

qF

q

qqq

qq

qqq

qqqq

qqqqQ

q3q1 q2

0,1

1 0,q4

0,1

1

Page 32: Finite Automata and Non Determinism yukita/

32

In what situation is Non Determinism relevant?

• Von Neumann machines are deterministic.

• However, there are many cases where machine specification is all we need.

Page 33: Finite Automata and Non Determinism yukita/

33

Theorem 1.19

• Every nondeterministic finite automaton has an equivalent deterministic finite automaton.– Def. The two machines are equivalent is they

recognize the same language.

Page 34: Finite Automata and Non Determinism yukita/

Proof of Th 1.19 34

Proof of Th. 1.19

}.|{ 4.

and },{ 3.

,),(),( 2.

,2 1.

such that ),,,,(Construct

arrows. no has first that assume usLet

. language some grecognizinNFA thebe ),,,,(Let

00

0

0

FRQRF

qq

araR

Q

FqQM

N

AFqQN

Rr

Q

Page 35: Finite Automata and Non Determinism yukita/

Proof of Th 1.19 35

Incorporate arrows

0

0 0

( ) { | can be reached from by traveling along zero or

more arrows.}

We modify as follows.

( , ) { | ( ( , )) for some }.

We modify as follows.

({ }).

We omit the correctness p

E R q q R

R a q Q q E r a r R

q

q E q

roof.

Page 36: Finite Automata and Non Determinism yukita/

36

Corollary 1.20

• A language is regular if and only if some nondeterministic finite automaton recognizes it.

Page 37: Finite Automata and Non Determinism yukita/

37

Example 1.21 NFA N4 to DFA

1

2 3a

b

a,b

a

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

as takesbemay set state s' The .DFA equivalentan

construct want to we,}}3{,1,},,{},3,2,1{{Given

}3,2,1{

4

DD

baN

Page 38: Finite Automata and Non Determinism yukita/

38

Task 02Parallel World

1. Write a program that simulates N4.

2. GUI– Three buttons for input 0, 1, and epsion.– State chart that reflect the branching of the

world.

Page 39: Finite Automata and Non Determinism yukita/

39

Start and Accept states

follows. asgiven is diagram state The

}}.3,2,1{},3,2{},3,1{},3{{ is statesaccept ofset The

}.3,1{})1({ is statestart The E

Page 40: Finite Automata and Non Determinism yukita/

40

The state diagram of D

{1} {2} {1,2}

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

a,b

a,b

a

aa

a

a

a

b

b bb

b

b

Page 41: Finite Automata and Non Determinism yukita/

41

Theorem 1.22 The class of regular languages is closed under the union operation.

N1

N2

N

Page 42: Finite Automata and Non Determinism yukita/

42

Proof of Th. 1.22

. and for

and for },{

for ),(

for ),(

),( 4.

3.

of statestart theis state The 2.

}{ 1.

. recognize to),,,,{ Construct

. recognize ),,,,(

and , recognize ),,,,(Let

0

021

22

11

21

0

210

210

222222

111111

aqq

aqqqq

Qqaq

Qqaq

aq

FFF

N.q

QQqQ

AAFqQN

AFqQN

AFqQN

Page 43: Finite Automata and Non Determinism yukita/

43

Theorem 1.23 The class of regular languages is closed under the concatenation operation.

N1N2

N

Page 44: Finite Automata and Non Determinism yukita/

44

Proof of Th. 1.23

.for ),(

and for }{),(

and for ),(

and for ),(

),( 4.

of that as same theis statesaccept ofset The 3.

. of that as same theis statestart The 2.

1.

. recognize to),,,,{ Construct

. recognize ),,,,(

and , recognize ),,,,(Let

22

121

11

111

2

11

21

2121

222222

111111

Qqaq

aFqqaq

aFqaq

FqQqaq

aq

N

Nq

QQQ

AAFqQN

AFqQN

AFqQN

Page 45: Finite Automata and Non Determinism yukita/

45

Theorem 1.24 The class of regular languages is closed under the star operation.

N1

N

Page 46: Finite Automata and Non Determinism yukita/

46

Proof of Th. 1.24

. and for

and for }{

and for }{),(

and for ),(

and for ),(

),( 4.

}{ 3.

state.start new theis statestart The 2.

}{ 1.

. recognize to),,,,{ Construct

. recognize ),,,,(Let

0

01

111

11

111

10

0

10

*10

111111

aqq

aqqq

aFqqaq

aFqaq

FqQqaq

aq

FqF

q

QqQ

AFqQN

AFqQN