There is something

46
Finite A utomata and Non Determinism http://cis.k.hosei.ac.jp/~yukita/

Transcript of There is something

Page 1: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 1/46

Finite Automata and

Non Determinism

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

Page 2: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 2/46

  2

Definition 1.1: Finite Automaton

.theis 5.and,theis 4.

,theis :3.

,thecalledsetfiniteais2.,thecalledsetfiniteais1.

 where),,,,,(tupple-5aisA

0

0

statesaccept of set statestart 

 functiontransition

alphabet states

automaton finite

Q F Qq

QQ

Q

 F qQ

⊆∈

→Σ×

Σ

Σ

δ 

δ 

Page 3: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 3/46

  3

State Diaram for M 1

!3!1 !2

" 1

1"

"# 1

Page 4: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 4/46

  $

Data %epresentation for &1

.}{5.

andstate,starttheis 4.

10

 asdescriedis3.

{0,1}2.},,{1.

2

1

223

232

211

321

q F 

q

qqq

qqq

qqq

qqqQ

=

=Σ=

δ 

Page 5: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 5/46

  '

(ask "1

DFA

1. )mp*ement &1 +ith your fa,orite

prorammin *anuae.

2. -) (+o 0uttons for input " and 1

State chart +ith the current state hih*ihted

Page 6: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 6/46

 

anuae of &1

}1lastthef!ll!w0s!f nu"ere#enan

and1!neleastatc!ntains${)(

.sa% thatcan&eaccepts."achinethatstrin'sall!f settheis

 ),(aswritten,he

1   ww M  L

 A M  M 

 M  L M 

=

recognizes

machineof language

Page 7: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 7/46

 

State Diaram for &'

!2

!1

!"

"

1

12

  2#  4  %  5  S

  5  (  6

1# 4%5S5(6

2

"# 4%5S5(6 "

Page 8: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 8/46

  7

Data %epresentation for &'

.}{5.

andstate,starttheis 4.

210

 asdescriedis3.

,0,1,2}*+*{2.

},,{1.

0

0

10202

02101

21000

210

q F 

qqqqqq

qqqqq

qqqqq R

qqqQ

=

=

δ 

Page 9: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 9/46

  8

)nforma* Description of M '

 M ' keeps a runnin count of the sum of

the numerica* sym0o*s it reads# modu*o 3.

5,ery time it recei,es the 4%5S5(6sym0o* it resets the count to ".

 M ' accepts if the sum is "# modu*o 3.

Page 10: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 10/46

  1"

Definition 1.: %eu*ar anuae

 A *anuae is ca**ed a regular language if

some finite automaton reconi9es it.

Page 11: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 11/46

  11

5amp*e 1.8: A finite automaton E 2

 E 2 reconi9es the reu*ar *anuae of a**

strins that contain the strin ""1 as a

su0strin.

""1"# 1""1# ""1# and 111111""1111" are

a** accepted#

0ut 11 and """" are not.

Page 12: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 12/46

  12

Find a set of states of E 2

;ou

1. ha,en<t just seen any sym0o*s of the

pattern#

2. ha,e just seen a "#

3. ha,e just seen "" or#

$. ha,e just seen the entire pattern ""1. Assin the states q#q"#q""# and q""1 to these

possi0i*ities.

Page 13: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 13/46

  13

 Dra+ a State Diaram for E 2

!"" !""1

" "# 1

1

1

"!"

"

!

1

Page 14: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 14/46

  1$

%eu*ar =perations on anuaes

!perati!n.a!nelasttheand

,!perati!nsare!perati!nsfirst tw!he

}.eachand0${:

}.and${:

}.!r${ :

lan'ua'es. eandet

21

unary

binary

 A xk  x x x A

 B y A x xy B A

 B x A x x B A

 B A

ik    ∈≥=

∈∈=

∈∈=∪

Star

ionConcatenat

Union

Page 15: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 15/46

  1'

5amp*e 1.11

}.,'!!dadad

 d,'!!dad'!!'!!dad,'!!d!d,'!!d'!!d'!

 adad,'!!dad,'!!d'!!d, ad,'!!d,,{

and}, ad'irl ad!%,'!!d'irl,'!!d!%,{

},'irl !%, ad,'!!d,{

ha#ewehen,}.'irl !%,{ and} ad'!!d,{et

}.,, a,{ ealphaetet the

ε =

==∪

==

Σ

 A

 B A

 B A

 B A

Page 16: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 16/46

  1

(heorem 1.12 >*osedness for nion

.iss!

 lan'ua'es,re'ularareandif s,!ther w!rd/n

!perati!n.uni!nthe

under cl!sedislan'ua'esre'ular!f classhe

21

21

 A A

 A A

Page 17: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 17/46

  ?roof of (h 1.12 1

?roof of (heorem 1.12

!n.c!nstructithe!f sc!rrectneschec thehen,

.),,,,(where

 ,rec!'niet!!nstruct

.),,,,(where,rec!'nieand

 ),,,,,(where,rec!'nieet

21

2222222

1111111

 F qQ M 

 A A M 

 F qQ M  A M 

 F qQ M  A M 

δ 

δ 

δ 

Σ=

Σ=

Σ=

Page 18: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 18/46

  ?roof of (h 1.12 17

>onstruction of M 

}.!r$),{()()( 5.).,( 4.

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

(&h%) .alphaetsa"etheha#eandthatassu"ecan&e2.

}.and$),{( 1.

2211212121

210

22112121

21

22112121

 F r  F r r r  F QQ F  F qqq

ar ar ar r aQr r 

 M  M 

Qr Qr r r QQQ

∈∈=×∪×==

=Σ∈∀∈∀

Σ

∈∈=×=

δ δ δ 

Page 19: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 19/46

  ?roof of (h 1.12 18

>orrectness

;ou shou*d check the fo**o+in.

1. For any strin reconi9ed 0y M 1 is

reconi9ed 0yM 

.2. For any strin reconi9ed 0y M 2 is

reconi9ed 0y M .

3. For any strin reconi9ed 0y M  isreconi9ed 0y M 1 or M 2.

Page 20: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 20/46

  2"

(heorem 1.13 >*osedness for

concatenation

.iss!

lan'ua'es,re'ularareandif s,!ther w!rd/n!perati!n.

i!nc!ncatenatundercl!sedislan'ua'esre'ular!f classhe

21

21

 A A

 A A

Page 21: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 21/46

  21

Nondeterminism

(o pro,e (heorem 1.13# +e need

nondeterminism.

Nondeterminism is a enera*i9ation of

determinism. So# e,ery deterministic

automaton is automatica**y a

nondeterministic automaton.

Page 22: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 22/46

  22

Nondetermistic Finite Automata

 A nondeterministic finite automaton can 0e

different from a deterministic one in that

 @ for any input sym0o*# nondeterministic one

can transit to more than one states.

 @ epsi*on transition

NFA and DFA stand for nondeterministic

finite automaton and deterministic finiteautomaton# respecti,e*y.

Page 23: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 23/46

  23

NFA N 1

!3!1 !2

"#1

1 "#ε !$

"#1

1

Page 24: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 24/46

  2$

?ara**e* +or*d and NFA

...   ...

accept

Page 25: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 25/46

  2'

5amp*e 1.1$ NFA N 2

!3!1 !2

"#1

1 "#1 !$"#1

et *anuae A consist of a** strins o,er "#1B containin a 1 in the thirdposition from the end. N 2 reconi9es A.

Page 26: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 26/46

  2

 A DFA e!ui,a*ent to N 2

!"1"!""" !1""

"

" " !11"

!"11!""1 !1"1

1 !111

1

"

1

""

1

"1

1"1

1

Page 27: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 27/46

  2

5amp*e 1.1' NFA N 3

ε

"

et *anuae A consist of a** strins "k  # +here k  is a mu*tip*e of 2 or 3. N 3 

reconi9es A.

ε

"

"

"

"

Page 28: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 28/46

  27

 A DFA e!ui,a*ent to N 3

"!2

!1

!3!'

"!"

" " " !$

"

!C1

1 11 1 1

1

"# 1

Page 29: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 29/46

  28

5amp*e 1.1 NFA N $

!1

!2 !3

a

0

a#0

εa

N $ accepts , a, baba# and baa. N $ does not accept b, nor babba.

Page 30: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 30/46

  3"

Definition 1.1: NFA

.theis 5.

and,theis 4.

,theis 2:3.

,thecalledsetfiniteais2.,thecalledsetfiniteais1.

 where),,,,,(tupple-5aisA

0

0

statesaccept of set 

statestart 

 functiontransition

alphabet states

automaton finitenisticnondetermi 

Q F 

Qq

Q

Q

 F qQ

Q

→Σ×

Σ

Σ

ε δ 

δ 

Page 31: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 31/46

  31

5amp*e 1.17 NFA N 1

}.{ 5.

state.starttheis 4.

}{}{

}{

}{}{

},{}{10

 as'i#enis 3.

}1,0{ 2.

},,,,{ 1.

4

1

444

43

332

2111

4321

q F 

q

qqq

qq

qqq

qqqq

qqqqQ

=

∅∅

=

ε 

δ 

!3!1 !2

"#1

1 "#ε!$

"#1

1

Page 32: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 32/46

  32

)n +hat situation is Non

Determinism re*e,ant

Eon Neumann machines are deterministic.

o+e,er# there are many cases +here

machine specification is a** +e need.

Page 33: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 33/46

  33

(heorem 1.18

5,ery nondeterministic finite automaton

has an e!ui,a*ent deterministic finite

automaton.

 @ Def. (he t+o machines are equivalent  is they

reconi9e the same *anuae.

Page 34: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 34/46

  ?roof of (h 1.18 3$

?roof of (h. 1.18

}.${ 4.

and },{ 3.

,),(),( 2.

,2 1.

such that),,,,(!nstruct

arr!ws.n!hasfirst thatassu"euset

.lan'ua'es!"e'rec!'niin Athe e),,,,(et

00

0

0

∅≠∩′∈=′=′

=′

=′′′′Σ′=

Σ=

 F  RQ R F 

qq

ar a R

Q

 F qQ M 

 N 

 A F qQ N 

 Rr 

Q

δ δ 

δ 

ε 

δ 

Page 35: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 35/46

  ?roof of (h 1.18 3'

)ncorporate ε arro+s

0

0 0

( ) { $ can e reached fr!" % tra#elin' al!n' er! !r 

"!re arr!ws.}

&e "!dif% as f!ll!ws.( , ) { $ ( ( , )) f!r s!"e }.

&e "!dif% as f!ll!ws.

({ }).

&e !"it the c!rrectness p

 E R q q R

 R a q Q q E r a r R

q

q E q

ε 

δ δ δ 

=

′   = ∈ ∈ ∈

′ =

r!!f.

Page 36: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 36/46

  3

>oro**ary 1.2"

 A *anuae is reu*ar if and on*y if some

nondeterministic finite automaton

reconi9es it.

Page 37: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 37/46

  3

5amp*e 1.21 NFA N $ to DFA

1

2 3a

0

a#0

εa

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

astaes e"a%setstates6he .7Ae8ui#alentan

c!nstructwant t! we,}}3{,1,},,{},3,2,1{{9i#en

}3,2,1{

4

∅=

=

 D D

ba N    δ 

Page 38: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 38/46

  37

(ask "2

?ara**e* Gor*d

1. Grite a proram that simu*ates N$.

2. -)

 @ (hree 0uttons for input "# 1# and epsion.

 @ State chart that ref*ect the 0ranchin of the

+or*d.

Page 39: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 39/46

  38

Start and Accept states

f!ll!ws.as'i#enisdia'ra"statehe

}}.3,2,1{},3,2{},3,1{},3{{isstatesaccept!f sethe}.3,1{})1({ isstatestarthe   = E 

Page 40: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 40/46

  $"

(he state diaram of D

φ  1B 2B 1#2B

3B 1#3B 2#3B 1#2#3B

a#0

a#0

a

a

a

a

a

a

0

0 00

0

0

Page 41: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 41/46

  $1

(heorem 1.22 (he c*ass of reu*ar *anuaes is

c*osed under the union operation.

N 1

N 2

ε 

ε 

Page 42: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 42/46

  $2

?roof of (h. 1.22

≠=∅

==

∈∈=

=

=

Σ=

Σ=

Σ=

.and f!r

and f!r},{

f!r),(f!r),(

),( 4.

 3.

 !f statestarttheis statehe 2.

}{ 1.

.rec!'niet!),,,,{!nstruct

.rec!'nie ),,,,(

and,rec!'nie ),,,,(et

0

021

22

11

21

0

210

210

222222

111111

ε 

ε 

δ δ 

δ 

δ 

δ 

δ 

aqq

aqqqq

QqaqQqaq

aq

 F  F  F 

 N.q

QQqQ

 A A F qQ N 

 A F qQ N 

 A F qQ N 

Page 43: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 43/46

  $3

(heorem 1.23 (he c*ass of reu*ar *anuaes is

c*osed under the concatenation operation.

N 1N 2

N    ε 

ε 

Page 44: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 44/46

  $$

?roof of (h. 1.23

=∈

≠∈

∉∈

=

=

Σ=

Σ=

Σ=

.f!r),(

 and f!r}{),(

 and f!r),( and f!r),(

),( 4.

 !f thatassa"etheisstatesaccept!f sethe 3.

.!f thatassa"etheis statestarthe 2.

 1.

.rec!'niet!),,,,{!nstruct

.rec!'nie ),,,,(

and,rec!'nie ),,,,(et

22

121

11

111

2

11

21

2121

222222

111111

Qqaq

a F qqaq

a F qaq F qQqaq

aq

 N 

 N q

QQQ

 A A F qQ N 

 A F qQ N 

 A F qQ N 

δ 

ε δ 

ε δ δ 

δ 

δ 

δ 

δ 

Page 45: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 45/46

  $'

(heorem 1.2$ (he c*ass of reu*ar *anuaes is

c*osed under the star operation.

N 1

ε  ε 

ε 

Page 46: There is something

7/23/2019 There is something

http://slidepdf.com/reader/full/there-is-something 46/46

?roof of (h. 1.2$

≠=∅

==

=∈

≠∈

∉∈

=

=

=

Σ=

Σ=

.and f!r

and f!r}{

 and f!r}{),( and f!r),(

 and f!r),(

),( 4.

}{ 3.state.startnewtheis statestarthe 2.

}{ 1.

.rec!'niet!),,,,{!nstruct

.rec!'nie ),,,,(et

01

111

11

111

10

0

10

10

111111

ε 

ε 

ε δ ε δ 

δ 

δ 

δ 

δ 

aqq

aqqq

a F qqaqa F qaq

 F qQqaq

aq

 F q F q

QqQ

 A F qQ N 

 A F qQ N