@@ -16,11 +16,11 @@ import Data.IntMap (IntMap)
16
16
import qualified Data.IntMap as IM
17
17
import qualified Data.List as List
18
18
19
- -- Hopcroft's Algorithm for DFA minimization (cut/pasted from Wikipedia):
20
- -- X refines Y into Y1 and Y2 means
21
- -- Y1 := Y ∩ X
22
- -- Y2 := Y \ X
23
- -- where both Y1 and Y2 are nonempty
19
+ -- % Hopcroft's Algorithm for DFA minimization (cut/pasted from Wikipedia):
20
+ -- % X refines Y into Y1 and Y2 means
21
+ -- % Y1 := Y ∩ X
22
+ -- % Y2 := Y \ X
23
+ -- % where both Y1 and Y2 are nonempty
24
24
--
25
25
-- P := {{all accepting states}, {all nonaccepting states}};
26
26
-- Q := {{all accepting states}};
@@ -37,9 +37,11 @@ import qualified Data.List as List
37
37
-- end;
38
38
-- end;
39
39
-- end;
40
+ --
41
+ -- % X is a preimage of A under transition function.
40
42
41
- -- observation : Q is always subset of P
42
- -- let R = P \ Q. then following algorithm is the equivalent of the Hopcroft's Algorithm
43
+ -- % observation : Q is always subset of P
44
+ -- % let R = P \ Q. then following algorithm is the equivalent of the Hopcroft's Algorithm
43
45
--
44
46
-- R := {{all nonaccepting states}};
45
47
-- Q := {{all accepting states}};
@@ -57,6 +59,10 @@ import qualified Data.List as List
57
59
-- end;
58
60
-- end;
59
61
-- end;
62
+ --
63
+ -- % The second for loop that iterates over R mutates Q,
64
+ -- % but it does not affect the third for loop that iterates over Q.
65
+ -- % Because once X refines Y into Y1 and Y2, Y1 and Y2 can't be more refined by X.
60
66
61
67
minimizeDFA :: forall a . Ord a => DFA Int a -> DFA Int a
62
68
minimizeDFA dfa@ (DFA { dfa_start_states = starts,
0 commit comments