Professional Documents
Culture Documents
Lec 09
Lec 09
163
Smallest DFA
Theorem: For any regular language L there is a unique (upto isomorphism) DFA that has minimum number of states.
Proof: Let M L = (QL , , L , q0 L , F L ) be the machine whose states are the equivalence classes of L . Let M = (Q, , , q0 , F ) be any other DFA recognizing L.
M is right invariant equivalence of nite index such that L is the union of some of its equivalence classes. By Myhill-Nerode theorem, M is a renement of L Number of equivalence classes of M (= the number of states in M ) number of equivalence classes of L (= the number of states in M L ) If |Q| > |QL | then done. If |Q| = |QL | then M L and M are isomorphic
164
Proof (continued)
Recall that the states of M L are x1 , x2 , . . . xk where these are the representatives of each equivalence class of L Dene f : QL Q as follows: f (xi ) = (q0 , xi ) In other words, f maps state xi to the state in M that xi goes to. Note, f is well-dened as each xi leads to some state in M To show f is one-to-one. That f is onto will follow from the fact that |QL | = |Q| f satises the properties of an isomorphism
165
f is one-to-one
To show that p, r QL if f (p) = f (r) then p = r We will show that u, v if f (u) = f (v) then u L v. Now since x1 . . . xk are representatives of dierent equivalence classes of L , this proves that f is one-to one. Suppose f (u) = f (v) = q Q. Then (q0 , u) = (q0 , v) = q Thus, (q0 , uz) = (q, z) = (q0 , vz) Hence, uz L i vz L. Or u L v
166
= f () = (q0 , ) = q0
2. Final states map to nal states xi F xi L (q0 , xi ) F f (xi ) F (by denition) (M recognizes L) (denition of f )
3. Transition are preserved xi , a (f (xi ), a) = = = = ((q0 , xi ), a) (q0 , xi a) f (xi a) f ( L (xi , a)) (defn. of f ) (xi a L L (xi , a)) (defn. of f )
167
0 1 0 1 1
168
Potential Problem
0 q1 q2
q3
q4
This cannot happen! Let x1 lead to q1 an x2 lead to q2 . We know (from the gure) that x1 L x2 In addition, because q3 L q4 , x1 0 L x2 0. But L is right invariant! Contradiction.
169
Merging States
How do we decide which states must be merged? Distinguishability: States p, q are distinguishable if there is some z such that (p, z) F and (q, z) F (or vice versa). We write this as p q In other words, states p, q are indistinguishable if for every z, (p, z) F i (q, z) F . We write this as p q indistinguishability is an equivalence relation
170
Example
1
1 a 1 0 0 c 1 0 0 0 1 e 0 0, 1 g 0, 1 1 0 f 0, 1 1 d 1 0 b
Correctness Condition
Need to show that when we merge states then they correspond to the same state in M L p q xy. (q0 , x) = p and (q0 , y) = q x L y In other words, p q i every pair of strings that lead to them are equivalent according to L
172
Proof of Correctness
Let p q, (q0 , x) = p and (q0 , y) = q. To show that x L y z. (q0 , xz) = (p, z) F
z. (q0 , yz)
(q, z) F
So xz L i yz L and thus x L y Let p q, (q0 , x) = p and (q0 , y) = q. To show x L y Since p q there is z such that (p, z) F and (q, z) F Then (q0 , xz) = (p, z) F and (q0 , yz) = (q, z) F Hence xz L and yz L and so x L y
173
174
Minimization Algorithm
Essentially we need to discover all the distinguishable pairs of states. First eliminate from M all unreachable states. distinguish = { p, q | p F and q F } oldDistinguish = while (distinguish = oldDistinguish) oldDistinguish = distinguish for every symbol a and for every p, q distinguish do if (p, a), (q, a) distinguish distinguish = distinguish { p, q } The above algorithm corectly computes all the pairs of states that can be distinguished. The minimized DFA has the indistingushed states grouped together and the transitions appropriately changed.
175
An Example
1 0 1 0 A B 0 1 0 0 E H 1 1 0 G 0 1 F 1 C 1 State is unreachable 0 D
B C D E F G H
2 1 2 2 3 2 A B 1 2 2 2 2 1 1 1 1 1 C 2 2 D 2 2 2 2 E 2 2 F 2 G
Step 1: Make p, q in distinguish if p F and q F (or vice versa) Step 2: If p, q are not in distinguish and if (p, a) and (q, a) are in distinguish then put p, q in distinguish Step 3: Repeat the above process 176
177