def brzozowski(nfa):
return reachable(subset(reverse(reachable(subset(reverse(nfa))))))
The auxilliary procedures are:
- reachable: Return only the states and transitions reachable from the start states.
- subset: The subset construction to turn an NFA into a DFA.
- reverse: Reverse all of the transitions and swap the start and final state sets. (Eg, if the NFA has a transition (1, 'a') -> 4, it would become (4, 'a') -> 1.)
We can write a 1-liner for calculating the optimal DFA. Isn't it pretty?
P.S.: I know I'm hopeless. Deal. :)