Professional Documents
Culture Documents
Formal Languages, Automata and Computability
Formal Languages, Automata and Computability
FORMAL LANGUAGES,
AUTOMATA AND
COMPUTABILITY
MINIMIZING DFAs
THURSDAY Jan 24
IS THIS MINIMAL?
NO
0
1
1 1 0
1 0
0
IS THIS MINIMAL?
0
1
0
THEOREM
For every regular language L, there exists
a UNIQUE (up to re-labeling of the states)
minimal DFA M such that L = L(M)
NOT TRUE FOR NFAs
0
0
EXTENDING
Given DFA M = (Q, Σ, , q0, F) extend to
^ : Q Σ* → Q as follows:
^ ε) = q
(q,
^ ) = (q, )
(q,
^
^ … ) = ( (q,
(q, 1 k+1 1 …k ), k+1 )
^ , w) F M accepts w
Note: (q0
p is indistinguishable from q
iff
p is not distinguishable from q
iff
^
for all w Σ*, (p, w) F ^(q, w) F
q1 1
0
0,1
1
q0 q2
0 0
1
q3
Define relation ~ :
p ~ q iff p is indistinguishable from q
p ~/ q iff p is distinguishable from q
1
1 1 0
1 0
0
Algorithm MINIMIZE
Input: DFA M
Output: DFA MMIN such that:
MMMIN (that is, L(M) = L(MMIN))
MMIN has no inaccessible states
MMIN is irreducible
||
all states of MMIN are pairwise distinguishable
IDEA:
• We know how to find those pairs of
states that ε distinguishes…
• Use this and recursion to find those
pairs distinguishable with longer strings
• Pairs left over will be indistinguishable
TABLE-FILLING ALGORITHM
Input: DFA M = (Q, Σ, , q0, F)
Output: (1) DM = { (p,q) | p,q Q and p ~/ q }
(2) EM = { [q] | q Q }
q0
q1 Base Case: p accepts
and q rejects p ~/ q
qi
qn
q0 q1 qi qn
TABLE-FILLING ALGORITHM
Input: DFA M = (Q, Σ, , q0, F)
Output: (1) DM = { (p,q) | p,q Q and p ~/ q }
(2) EM = { [q] | q Q }
q0
q1 Base Case: p accepts
and q rejects p ~/ q
Recursion: if there is σ Σ
qi D D and states p, q satisfying
(p, ) = p
qn D ~/ p ~/ q
q0 q1 qi qn (q, ) = q
Repeat until no more new D’s
q0
q1 D
q2 D D
q3 D D D
q0 q1 q2 q3
0,1
1 0
0 0 1
q0 q1 q2 q3
1
0
q0 q1
1
1 1 0
1 0
q0
q3 q2
q1 D 0
q2 D
q3 D D
q0 q1 q2 q3
Claim: If p, q are distinguished by Table-
Filling algorithm, then p ~/ q
Proof: By induction on the length of the string
distinguishing them.
If (p, q) is marked D at the start, then one’s in
F and one isn’t, so ε distinguishes p and q
Suppose (p, q) is marked D at a later point.
Then there are states p, q, and string w such that:
1. (p, q) are marked D p ~ / q (by induction)
(p,
^ w) F and ^(q, w) F
2. p = (p,) and q = (q,), where Σ
The string w distinguishes p and q!
Claim: If p, q are not distinguished by Table-
Filling algorithm, then p ~ q
Proof (by contradiction):
Suppose the pair (p, q) is not marked D by the
/ q (a “bad pair”)
algorithm, yet p ~
Then there is a string w such that:
^ w) F and (q,
(p, ^ w) F (Why is |w| >0 ?)
So, w
Of all such bad= w, let p, q
where
pairs, beΣa pair with
the = (p,)wand q = (q,)
shortest
Let p
Then (p, q) is also a bad pair,
but with a SHORTER w !
Algorithm MINIMIZE
Input: DFA M
Output: DFA MMIN
(1) Remove all inaccessible states from M
(2) Apply Table-Filling algorithm to get:
EM = { [q] | q is an accessible state of M }
MIN( [q], ) = [ ( q, ) ]
Must show MIN is well defined!
Algorithm MINIMIZE
Input: DFA M
Output: DFA MMIN
(1) Remove all inaccessible states from M
(2) Apply Table-Filling algorithm to get:
EM = { [q] | q is an accessible state of M }
MIN( [q], ) = [ ( q, ) ]
Claim: MMIN M
MINIMIZE
0
q0 q1 0
1
0 1 0
1
q2
0
1
1
1 0 0,1
0
q0 q1 q4
1 1
0,1 0 0 q5
q0
q1 q2 1
D q3
q3 D D
q4 D D
q5 D D D D
q0 q1 q3 q4 q5
1 0 0,1
0
q0 q1 q4
1 1
0 0 q5
q0
q1 D q3
q3 D D
q4 D D
q5 D D D D
q0 q1 q3 q4 q5
*MMIN is the unique minimal DFA equivalent to M
Claim: Suppose MMMIN, and M has no
inaccessible states and is irreducible. Then
there is a bijection that preserves transitions
between M and MMIN
*MMIN is the unique minimal DFA equivalent to M
Claim: Suppose MMMIN, and M has no
inaccessible states and is irreducible. Then
there is a bijection that preserves transitions
between M and MMIN
MMIN M
Accept
Accept
u w u w
q0 MIN q q0 q
Contradiction!
v w v w
Reject
Reject
MMIN M
Accept
Accept
u w u w
q0 MIN p q0 q
Contradiction!
v w v w
Reject
Reject
q0 MIN q q0 q
How can we prove that two
regular expressions are
equivalent?
WWW.FLAC.WS
Finish reviewing Chapter 1 of the book and
read 2.1 & 2.2 for next time