# Minimizing finite state automata

September 18, 2013 11 Comments

Computer science is a strange mix of engineering, science, and math. This is captured well by the historic roots of deterministic finite state automata (DFAs). The first ideas that can be recognized as a precursor to DFAs can be found with Gilberth & Gilberth (1921) introducing flow process charts into mechanical and industrial engineering. Independently, McCullock & Pitts (1943) used nerve-nets as a model of neural activity. This preceded Turing’s 1948 entry into brain science with B-type neural networks, and Rosenblatt’s perceptrons (1957). Unlike Turing and Rosenblatt, McCullock & Pitts model did not incorporate learning. However, the nerve nets went on to have a more profound effect on ratiocination because — as Kleene (1951) recognized — they became the modern form of DFAs. Although DFAs are now in less vogue than they were a few decades ago, they are an essential part of a standard computer science curriculum due to their centrality in computer science. Yesterday, I had the privilege of familiarizing students with the importance of DFAs by giving a lecture of Prakash Panangaden’s COMP 330 course. Since Prakash already introduced the students to the theory of DFAs, regular expressions, and languages, I was tasked with explaining the more practical task of DFA minimization.

Consider the two DFAs above, they both recognize the same language and yet the first has three states, and the second has four. Can we tell from just examining the left machine that it has some redundant states? Well, consider states in the right machine, no matter what happens in the future, they will have the same output. If the future has no more letters, i.e. is $\latex \epsilon$ then both states accept, and if the future has any non-zero string then they both transition to state where the machine will remain forever and reject. We could easily merge the two states into a single state and still recognize the same language. Let’s formalize this insight into an equivalence relationship on states:

This can be used to design a quotient automaton on equivalence classes . If we start with a DFA then the quotient automaton is where , , and . To prove that this quotient machine recognizes the same languages, we need three lemmas. The first checks that is well defined and in-fact a function:

Lemma 1:

*Proof:*

Lemma 2:

*Proof:* By induction on length of with Lemma 1 as base case.

Lemma 3:

*Proof:* $(\Rightarrow)$ by definition of , and $(\Leftarrow)$ by definition of with set to .

This allows us to prove that the quotient automaton recognizes the same language as the original automaton.

Theorem 1:

*Proof:*

Now, we just need an algorithm to find the equivalence classes. The most straightforward way is to assume that all states are mergeable, and then mark the ones we can’t merge, progressing backwards from states that differ in output on to preceding states that need to be distinct to preserve determinism. More formally, this gives us the algorithm:

- Write down a table of all pairs ; initialize all as unmarked.
- Mark if and (or vice versa).
- Repeat until a whole pass through the table of pairs without a new marking. For each unmarked , if there is some such that $\latex {\delta(p,a), \delta(q,a)\}$ are marked then mark .
- If is not marked then .

I encourage you to use induction to prove that this algorithm is correct. More formally:

Theorem 2:is marked if and only if $\exists x \in \Sigma^*$ such that and (or vice versa).

### References

Gilbreth, F.B., & Gilbreth, L.M. (1921) Process Charts. *American Society of Mechanical Engineers*.

Kleene, S. C. (1951). Representation of events in nerve nets and finite automata. *Project RAND Research Memorandum RM-704*.

McCulloch, Warren S., & Pitts, Walter (1943). A logical calculus of the ideas immanent in nervous activity. Bulletin of Mathematical Biophysics, 5, 115-133 DOI: 10.1007/BF02478259

Rosenblatt, F. (1957). The Perceptron — a perceiving and recognizing automaton. Report 85-460-1, *Cornell Aeronautical Laboratory*.

“Computer science is a strange mix of engineering, science, and math.” …and turning things off and on again until they work.

Pingback: How teachers help us learn deterministic finite automata | Theory, Evolution, and Games Group

Pingback: Limits on efficient minimization and the helpfulness of teachers. | Theory, Evolution, and Games Group

I’m not sure if this is a typo, but in the fourth paragraph (just above Lemma 1), should it be Q’ = { [q] | q \in Q} instead of Q’ = { [p] | q \in Q}?

Also, in the first line of proof of Lemma 1, I think it should be .

You are correct on both counts, thank you! I’ve fixed the typos.

No problem. Thanks so much for writing up all of these!

for Lemma 2, should we be proving the statement for and not ? The statement as it is doesn’t “type check” since operates on states in and not on the states in .

Yup! The one on the left should be primed, I will fix it up shortly. Thank you :D.

Pingback: Cataloging a year of blogging: the algorithmic world | Theory, Evolution, and Games Group

Pingback: Evolution is a special kind of (machine) learning | Theory, Evolution, and Games Group