Theory of Computation
www.vkedco.blogspot.com
Myhill-Nerode Theorem & DFA Minimization
Vladimir Kulyukin
Outline
● Equivalence Relations
● Language- and DFA-Based Equivalence Relations
● Myhill-Nerode Theorem
● 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
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
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
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
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
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
R
yqxqyxRyx
RFqQM
M
M
*
M
Right Invariance of RM
.,,,,,,
because , ,Σany for Then, .
,Σ,for and,DFA a be ,,,,Let
0
*
0
**
0
**
0
*
0
yzqzyqzxqxzq
yzxzRzyxR
yxFqQM
M
*
M
*
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
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.
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
Example: DFA M
q q1
q2 q3
q4 q5
0 1
1
0 0, 1 0 0
1
1
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
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);
}
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
Example: DFA M Minimized
q q1
q2
q3
q5
0
1
qq q4
1
0
1
0
0,1
References
● J. E. Hopcroft & J. D. Ullman. “Introduction to Automata Theory,
Languages, and Computation”