Skip to content

Commit f4ca6db

Browse files
committed
more precise documentation
1 parent fc9a6b9 commit f4ca6db

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/DFAMin.hs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import Data.IntMap (IntMap)
1616
import qualified Data.IntMap as IM
1717
import qualified Data.List as List
1818

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
2424
--
2525
-- P := {{all accepting states}, {all nonaccepting states}};
2626
-- Q := {{all accepting states}};
@@ -37,9 +37,11 @@ import qualified Data.List as List
3737
-- end;
3838
-- end;
3939
-- end;
40+
--
41+
-- % X is a preimage of A under transition function.
4042

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
4345
--
4446
-- R := {{all nonaccepting states}};
4547
-- Q := {{all accepting states}};
@@ -57,6 +59,10 @@ import qualified Data.List as List
5759
-- end;
5860
-- end;
5961
-- 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.
6066

6167
minimizeDFA :: forall a. Ord a => DFA Int a -> DFA Int a
6268
minimizeDFA dfa@(DFA { dfa_start_states = starts,

0 commit comments

Comments
 (0)