2 . finite automata - softcomputing lab, …sclab.yonsei.ac.kr/courses/07am/chap02.pdf제2장....

27
2. Finite Automata 학습목표 가장 단순한 Finite Automata를 통해 DFANFA이해하고 그 둘의 능력이 같음을 확인한다. No temporary storage 닭머리 기계 (기억용량에 제약) CU내의 finite한 분량의 상태를 저장하여 처리

Upload: tranthuy

Post on 26-Aug-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

제 2장. Finite Automata

학습목표

가장단순한 Finite Automata를통해 DFA와 NFA를이해하고그둘의능력이같음을확인한다.

No temporary storage

닭머리기계 (기억용량에제약)

CU내의 finite한분량의상태를저장하여처리

Page 2: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

뭘배우나?

G

Maaba acb

aaaba . . . .

언어발생모델: 문법(Models of Language

Generation: Grammars)

언어인식모델:계산기(Models of Language

Recognition: Machines)

Page 3: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

개요

Deterministic Finite Accepters (DFA)

DFA의정의와 transition graph

DFA가 accept하는언어 regular language

Nondeterministic Finite Accepters (NFA)

NFA의정의와 nondeterminism의필요성

Equivalence of DFA & NFA

Reduction of Number of States in FA

mark & reduce algorithm

Page 4: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

Deterministic Accepters

statesfinal:stateinitial:

functiontransition:alphabetinput:

statesinternal:),,,,(DFA.

0

0

QFQq

QQ

QFqQMDef

⊆∈

→∑×∑

∑=⋅

δ

δ

⎪⎪⎩

⎪⎪⎨

=→∑∈

→∗

10

10

),(input1

stringofend

qaq

w

qq

δ

L⎩⎨⎧ ∈

rejectedFqifacceptedw i

DFA의 formal한정의와작동과정을이해하자

Page 5: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

DFA : Transition Graph

2.1 Ex.

: states finalstate initial

) symbolinput : label (on transiti: edge

states :vertex

⋅⋅

q1q0a

iq|Q|

a

- Extended transition function δ* : Q x Σ* Q

0 1 2

00 1

0

1 1

01?

00 ?

DFA를시각적으로쉽게볼수있도록하는그래프표현방법이해

Page 6: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

DFA : Languages

}),(:{)( 0 FwqwML ∈∑∈=⋅ ∗∗ δ

- Nonacceptance?- Ex 2.2 : multiply labeled edges

Trap state

anb

- Thm : M = (Q, Σ, δ, q0, F) GM

0 1 2

a

b a, b

a, b

δ*(qi, w) = qj iff qi qjw induction on |w|

- 구현 : simple table-lookup, sequence of “if” statements

DFA가 accept하는언어의정의와Transition graph와의관계이해

L(M) = {w | M은 input string w를모두읽고accepting state에들어간다}

Page 7: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

DFA : 예들- Ex 2.3 : ab로시작하는모든 string의집합을 accept하는 DFA 설계

0 1 2a b

a, b

3

a,b

ab

- Ex 2.4 : 001을포함하지않는모든 string을 accept하는 DFA 설계

λ 00

11

0

0

0 0011

0,1

0

주어진언어를 accept하는 DFA의설계방법을여러가지연습을통해이해할것

Page 8: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

DFA : Regular Languages

- L : regular iff there exists some DFA M such that L = L(M)- To show L = regular find a DFA for it

- Ex 2.5 : L = {awa : w in {a, b}*} is regular?•Point : no explicit way of testing the end of string

두번째 a가나올때마다일단 final state로가본다

2

bb

3

a

a

0a

1

a,b

b

- Ex 2.6 : L2 is regular Point : aa가나오면두번째 DFA로그림 2.7 L=regular -> L2, L3, … is regular

DFA가 accept하는언어Family를정규언어라함

Page 9: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

실전연습 : 다음 언어 L을 인식하는 DFA를 설계하시오 . L = {x | x 는 binary 수이며 ( 즉, x ∈ {0, 1}+), x mod 3 = 0}

힌트: 이 DFA의 idea는입력으로주어진 string을한 bit 씩우측으로차례로읽으며 지금까지 읽은 수에 대한 나머지를 계산해 두는 방법이다.Graph에서 state 상의 수는 지금까지 읽은 수를 3으로 나눈 나머지이다. 지금까지 읽은 수에 대한 나머지를 i 라 하자. 다음 읽은 bit가 j∈ {0,1}이면, 나머지는 (2i + j) mod 3 이다. 따라서 현 상태 i 상에서 j∈ {0,1} 를읽으면, 상태 (2i + j) mod 3 로가도록하면된다.

0

1

20

1

1

1

0

0

10

start

Page 10: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

DFA : Exercises (2.1)

-2 : grammar와오토메타에대한기초이해문제

-7 : DFA에의한modular counting 연습 (참고: 1.2절의 Exercise 14)

-11, 12 : regular 언어란 해당 DFA 구축하기!!

-22 (20) : 정규언어의특성(4장) 중중요한 closure property에대한문제

Page 11: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA: 정의

있음수일empty가),(있음수일이symbolinput

},{),()exstatesofsubset:)2(range의

차이점

2}){(:

동일와DFA:,,,),,,,(

201

0

0

aq

qqaq

Q

FqQFqQM

i

Q

Q

δλ

δδ

λδ

δ

=−

→∑×−

∑−

∑=⋅

U

statefinalatomovespossibleofsequenceifstringaacceptstatespossibleofsetamoveunique

∃⇒→⇒

Unique move대신에 set of possible move 허용

q0

q1

q2

a

a

a

a,bb

q0

q1

q2

a

b

q0

q0

q1

q1

Xb

b

b b

a

Page 12: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA: 예

}1|{}{ 23 ≥naa nU

}0|)10{( ≥nnq1q0

0

1

λ

0,1 q2

q0

q2

q5

a q3a

a

aa

a

q4

q1

Page 13: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA : Extended Transition Function

wqq

aiffqwq

ji

ji

labeledtofrom

graphtransitioninwalkcontains),(정의

⋅∗δ

λaq0 q2q1

λ

=

=

=

),(

),(

),(

2

2

1

aaq

q

aq

δ

λδ

δ },,{ 210 qqq

},{ 20 qq},,{ 210 qqq

Page 14: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA : Language Acceptance

wvw

wq

FwqwML

i

i

labeledthemfromselectatgoriginatin||)1(mostatlengthofwalksallevaluate

),(computingformethodA

}),(|{)(정의

0

Λ++Λ⋅

≠∑∈=

∗∗

δ

φδ I

Page 15: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA: Nondeterminism?

easilyproblemssolvinginhelpful이유

searchexhaustivewithoutbacktrackandsearch:

−⋅

−−⋅방법

q0

q2

q5

a q3a

a

aa

a

q4

q1

lemmatheorem,ex)존재사실설명가능한쉽게로NFA보다DFA

|)ex표현간결하게언어를복잡한

→−

λaSbS

conclusionofgeneralitytheaffectingwithoutargumentsformalSimplify⇒

왜굳이 NFA를사용하려하는지에대한이해필요

Page 16: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA: Exercises (2.2)

-2 : DFA와 NFA의 equivalence에대한사전이해

-12~15 (11~14) : NFA와언어에대한기초적인이해

-16 (15) : 약간어려운문제일까? 뒤의해답을참조하여이해할것

Page 17: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

Equivalence of DFA & NFA

.)

)()(.

2}){(::

),,,,(),,,,(

2121

00

Ex

MLMLiffMMDef

QQQ

FqQMFqQMQ

ND

NNNNDDDD

=≡⋅

→∑×→∑×

∑=∑=

λδδ

δδ

U

q1q0

0

1

λ

0,1 q2

0

1

0

1

0,1

q0 q1 q2

)(),(:sspowerfulne

DDN MLwMMLw ∈∋∃∈∀⋅

}0:)10{( ≥nn

Page 18: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA DFA

)12.2

2|Q|DFANFA

||

Ex

Q→

→⋅

ø

a

a,b

b

b

a q1 q2q0λ

a

a

b

q0 q2q1

기본아이디어는 NFA의상태수가아무리많아도 2|Q|개의유한수임을이용한다

Page 19: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

Theorem for NFA DFA (1)

)()( : Thm DDN MLLMMLL =∋∃→=⋅

edges||2mostathas : terminate-

statefinal:}{)(

state final : in }{

}{}{

}{)()()(

for of }{repeat

state initial :}{dfanfa.)

||0

state

0

→∈

⎯→⎯

∑∈

NQD

N

Dnf

nmla

kji

nmlkji

Dkji

G

qML

GFq

, q,, qq, q,, qq

, q, , qq, aqδ*, aqδ*, aqδ*

aG, q, , qq

qpf

λ

LL

LULUU

L

알고리즘과종료함의증명

Page 20: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

Theorem for NFA DFA (2)

⎜⎜⎝

⎛⎯→⎯⎯→⎯⇒⎯→⎯⎯→⎯=

⎯→⎯⇒⎯→⎯≤∀

∈→∈

=

},,{}{in }{}{in ||

)ii

),(),( true1)i

|stringinput|oninduction-

00

00

0*D0

*N

laivlaiv

DivNiv

qQqqqqvawGqqGqqnv

FwqFwqn

LL

δδQi

동일함의증명by induction (8:2☺)

Page 21: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA DFA : 예

0,1 0,1

0 1

q0 q2q1

0,1

q0 q1 q2

0

1

q0 q1 q1

q0

0,1q1 q2 q2

ø

0,11

1

1

0

00

Ex 2.13 :

• L(MN) : regular

NFA로 accept되는언어도 regular임!

Page 22: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

NFA DFA : Exercises (2.3)

-1 : 진짜연습문제

-5 : 이럴경우, 8:2 rule에의하면…?

- 13 : 주어진언어가무엇인지먼저파악할것.

Page 23: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

Reduction of Number of States

),(),(),(relationeequivalenc) versaor vice,),(),( habledistinguis)

),(),(),(),(

ifishableindistingu:),(:

**

**

**

rprqqpcfFwqFwpcf

FwqFwpFwqFwp

wqpDef *

→∉→∈

⎜⎜⎝

∉→∉∈→∈

∑∈∀⋅

δδ

δδδδ

•Simplicity, Storage efficiency

Ex 2.14 : p.63⎩⎨⎧ Inaccessible

reachable

Page 24: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

Mark Algorithm

),(habledistinguis:),(),(,),(&),(repeat

states habledistinguis),(&),(leinaccessiballremove

states ishableindistingu combining & finding :Idea

qpmarkqpqaqpapaqp

qpmarkFqFpqp

aaaa →==∑∈∀

→∉∈∋∀

δδ

mark distinguishable pairs

•Thm : mark terminates & determines all distinguishable states

증명 : 8:2☺

Distinguishable states를모두찾아내는알고리즘

Page 25: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

Reduce Algorithm

FqF

qq

qqqqqqMnlmakij

Mqaqqqqq

mark

i

nlp

kir

pr

nlki

∈∈→=

=

containingstatesfinal

includingstateinitial

},,{},,{in),(

in),(},,{},,,{statesishableindistingufind

algorithm withstatehabledistinguisofpairsallfind

00)

)L

L)

LL)

LL

δ

δ

• reduce indistinguishable state

),,,,(),,,,( 00 FqQMFqQM D

))))))δδ ∑=→∑=

a state

구별이안되는 states를모아서State의수를줄이는알고리즘

Page 26: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

State Reduction : 예

),(),(),(),(),(),(),(

pairshabledistinguis

43

3042

2041

1040

qqqqqqqqqqqqqq ⎜⎜

⎛==

30

41

)1,()1,(

qqqq

δδ

Q

}{},,,{},{ishableindistingu:

),(),(),(pairsishableindistingu

43210

321

323121

qqqqqqqq

qqqqqq

⇒⇒

Ex)

p.67minimal:

)()(yields,GivenThm ⎜

⎜⎝

⎛ =∋⋅

M

MLMLMreduceM)

))

q0 q2

q1

q4

0,1

01

q3

0

0

0

1

1

1

0 41230,1

0,1

1

0

증명 : 1) 동일한가? 8:2☺ by induction2) Minimal? 이제슬슬 8:2☺면?

Page 27: 2 . Finite Automata - Softcomputing Lab, …sclab.yonsei.ac.kr/courses/07AM/chap02.pdf제2장. Finite Automata 학습목표 가장단순한Finite Automata를통해DFA와NFA를 이해하고그둘의능력이같음을확인한다

State Reduction : Exercises (2.4)

-2 : 골라서 2문제정도는연습할것

-4 : 뒤의힌트를참고하면…