theory of computation (fall 2014): equivalence relations, language- and dfa-based equivalence...

18
Theory of Computation www.vkedco.blogspot.com Myhill-Nerode Theorem & DFA Minimization Vladimir Kulyukin

Upload: vladimir-kulyukin

Post on 20-Jun-2015

141 views

Category:

Science


0 download

TRANSCRIPT

Page 2: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Outline

● Equivalence Relations

● Language- and DFA-Based Equivalence Relations

● Myhill-Nerode Theorem

● DFA Minimization

Page 3: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Reflexivity, Transitivity, Symmetry

. :Symmetry 3.

. and :tyTransitivi 2.

.in a allfor :yReflexivit 1.

set. a andrelation a be Let

bRaaRb

aRcbRcaRb

SaRa

SR

Page 4: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Equivalence Relations

false. is then ,, and If 3.

true.is then , and If 2.

., 2.

... 1.

: thatso classes eequivalencdisjoint into set a splits symmetric. and

e, transitivreflexive, isit ifrelation eequivalencan is relation A

321

aRbjiSbSa

aRbSbSa

jiSS

SSSS

SR

R

ji

ii

ji

Page 5: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Example: ≡5(Congruence Modulo 5)

.

.

. 45 40 35 30 25 20 15 10 5 0

.

.

. 46 41 36 31 26 21 16 11 6 1

.

.

. 47 42 37 32 27 22 17 12 7 2

.

.

. 48 43 38 33 28 23 18 13 8 3

.

.

. 49 44 39 34 29 24 19 14 9 4

≡5 splits N into 5 disjoint equivalence classes:

C0 (remainder 0), C1 (remainder 1), C2 (remainder 2),

C3 (remainder 3), C4(remainder 4)

C0 C1 C2 C3 C4

Page 6: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Example: Mod 5

5). modulo remaindersdifferent have

and ( false is then ,, and If 3.

5). moduloremainder same

thehave and ( trueis then , and If 2.

., 2.

. 1.

:on relation

eequivalencan is 5) modulo e(congruenc relation A

5

5

43210

5

babajiCbCa

babaCbCa

jiCC

CCCCCN

N

ji

ii

ji

Page 7: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Language-Based Equivalence Relations

. splits

whichinto classes eequivalenc ofnumber theisindex The

. Σ

Σ,

if on relation

eequivalencan is Then Σ.over language a be Let

LR

Lyz LxzLyzLxzz

yxRyx

L

RL

L

*

L

*

L

Page 8: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

DFA-Based Equivalence Relations

. from reachable in stateeach for one

:classes eequivalenc ofset finite a into divides

.,, Σ,

such that relation eequivalenc

an be Then DFA. a be ,,,,Let

0

*

0

*

0

*

0

qQ

R

yqxqyxRyx

RFqQM

M

M

*

M

Page 9: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Right Invariance of RM

.,,,,,,

because , ,Σany for Then, .

,Σ,for and,DFA a be ,,,,Let

0

*

0

**

0

**

0

*

0

yzqzyqzxqxzq

yzxzRzyxR

yxFqQM

M

*

M

*

Page 10: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Myhill-Nerode Theorem

index. finite a has Then .

enexactly wh ,Σ iff Σ,

such that relation eequivalencan be Let 3)

index. finite ofrelation eequivalencinvariant right

a of classes eequivalenc theof some ofunion theis 2)

.,,,,

DFA somefor i.e., regular, is Σset The 1)

:equivalent are statements threefollowing The

0

L

*

L

*

L

*

RLyz

LxzzyxRyx

R

L

FqQM

MLLL

Page 11: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Application of Myhill-Nerode Theorem

● The Myhill-Nerode Theorem makes it possible to

minimize DFAs by using right-invariant equivalence

relations.

● In particular, if L is a regular language, then there is a

unique DFA M having the smallest number of states such

that L(M) = L.

● M can be effectively computed, i.e., there is an

algorithm that minimizes DFAs.

Page 12: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Procedure refine_partition

}

}

}

}

}

of subsetsdifferent in are and

{ else

}

ofsubset same in the are and

{''',', if

{ in s symboleach for

{ , where, states ofpair each for

{ set each for

{ ,titionrefine_par procedure

. ofpartition a be Let DFA. a be ,,,,Let 0

Sqp

Sqp

ParRRqRpqsqpsp

Sqpqp

ParS

QPar

QParFqQM

Page 13: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Example: DFA M

q q1

q2 q3

q4 q5

0 1

1

0 0, 1 0 0

1

1

Page 14: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Example: refine_partition(Par, M)

● Suppose Par = {{q2, q3, q4}, {q1, q5}}, where S1 = {q2, q3, q4} and

S2 = {q1, q5}.

● Then refine_partition(Par, M) = {{q2}, {q3}, {q4}, {q1, q5}.

● Here is why:

– 𝛿 𝑞1,0 = 𝑞3 ∈ 𝑆1; 𝛿 𝑞5,0 = 𝑞3 ∈ 𝑆1; 𝛿 𝑞1,1 = 𝑞2 ∈ 𝑆1;

𝛿 𝑞5,1 = 𝑞2 ∈ 𝑆1; So q1 and q2 cannot be split into separate

subsets

– 𝛿 𝑞2,0 = 𝑞4 ∈ 𝑆1; 𝛿 𝑞3,0 = 𝑞5 ∈ 𝑆2; So q2 and q3 can be split

into separate subsets

– 𝛿 𝑞3,0 = 𝑞5 ∈ 𝑆2; 𝛿 𝑞4,0 = 𝑞4 ∈ 𝑆1; So q3 and q4 can be split

into separate subsets

Page 15: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

DFA Minimization Algorithm

Let M be a DFA.

Remove from M all states unreachable from the start state q0

(there is no need to keep track of them).

OldPar = {Q-F, F};

NewPar = refine_partition(OldPar, M);

while ( NewPar != OldPar ) {

OldPar = NewPar;

NewPar = refine_partition(OldPar, M);

}

Page 16: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

Example

● Let us apply the minimization algorithm to M

● The 1st partition is {{q1, q5}, {q2, q3, q4}}

● The 2nd partition is {{q1, q5}, {q2}, {q3}, {q4}}

● The 3rd partition is {{q1, q5}, {q2}, {q3}, {q4}},

which is the same as the second partition, so

where the algorithm stops

Page 17: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

qq

qq

Example: DFA M Minimized

q q1

q2

q3

q5

0

1

qq q4

1

0

1

0

0,1

Page 18: Theory of Computation (Fall 2014): Equivalence Relations, Language- and DFA-Based Equivalence Relations, Myhill-Nerode Theorems, DFA Minimization

References

● J. E. Hopcroft & J. D. Ullman. “Introduction to Automata Theory,

Languages, and Computation”