# Are there algorithms to exactly minimize NFAs which are sometimes efficient?

I'm doing some research with NFAs, and I'm wondering there are algorithms which quasi-efficiently minimize them. I realize that this problem is $PSPACE$ hard, so I'm not looking for a polynomial time algorithm.

What I mean by this is an algorithm which may run in exponential time in the worst cases, but which uses some sort of heuristic to speed up the process, albiet not enough to make it exponential.

I'm only using this to try to get a better idea of what the minimal NFAs of certain languages look like. I'm not using it in any production code, so it doesn't need to be blazingly fast.

For example, the Antichains algorithm for NFAs does equivalence testing which is usually fast but sometimes has exponential explosion. I'm looking for something similar, but for minimization.

Note that I'm NOT looking for things like equivalences, etc. which run efficiently but don't produce a minimal NFA.

Bonus points to anyone who find one with an implementation, and quadruple bonus points if it's in Prolog or Python. If the tool I'm looking for doesn't exist, I'd be happy if anyone gave any old implementation of NFA minimization.

• this is basically a question on average case complexity. it depends on the "distribution" of inputs. hence an empirical study/survey would be useful. unf there seems to be little empirical study in the area. also, the question seems not so clear on whether an approximation or an exact solution is required. heuristics almost always are associated with approximations. – vzn Sep 25 '13 at 15:12

SAT solvers have been pretty good at this. See [1] for more; the method produces a minimal automaton in almost all cases. Following some references, Tsyganov [2] combined the Kameda-Weiner with local search methods.

I don't know if there are readily available implementations out there, but at least [1] describes the reduction to SAT. One can then use any available SAT solver.

I've implemented the Kameda-Weiner algorithm; see the source on Github. Note, however, that a minimal NFA is not generally unique (there may be multiple solutions), so I don't know if I'd say it's "exact" as in your question.

• I'm not worried about it being unique, I'm worried about it being exact in the sense that there is 0 probability that the output is not one of the minimal NFAs for the given regular language. – jmite Aug 25 '13 at 5:44
• In that case, it is exact. It will always give a minimal NFA. – Brent Aug 25 '13 at 15:53
• Source code alone is not considered an answer on this site. What is the idea of the algorithm? Is it sometimes fast? Can you quantify this? – Raphael Aug 26 '13 at 7:20
• I guess I should have just made a comment then. ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=1671587 – Brent Aug 26 '13 at 14:32
• if its an implementation of a standard or published algorithm (which it is, as brent stated in answer), seems like reasonable/fair answer. as for jmites defn of "exact" in the above comment, it doesnt make sense to me, can someone explain it? it seems opposite ie think that an exact solution would be one of the minimal NFAs of the language acc to some defn of "minimal" (eg # of states)... – vzn Sep 25 '13 at 15:15

The title of the question insists on an exact algorithm, but then you say it would "use some sort of heuristic to speed up the process". Generally, heuristics are associated with inexact solutions. This following paper is more focused on an inexact solution i.e. heuristics, but has some discussion and further references on the general minimization problem.

• For heuristics, what I mean is, say there are several paths to search, the heuristic would try to speed up the search by guessing which path we should search first. For example, A* is exact, but beat's Dijkstra's in terms of speed because of a heuristic. – jmite Sep 26 '13 at 3:22
• generally a heuristic can only improve performance in average case for a particular input distribution, and then other distributions exist that push heuristics away from that improved performance. (in other words, like greedy algorithms seeking out local optima.) – vzn Sep 26 '13 at 21:23