Proofs: Table-filling DFA minimization
These are the human proofs of Table-filling DFA minimization, at full length.
The table-filling algorithm marks exactly the distinguishable pairs and returns the minimal DFA full
This proof shows: correctness, termination.
Let be a complete DFA, , and let be the set of states reachable from . For , a string distinguishes and if exactly one of and is in . The states are equivalent, , if no string distinguishes them. Pairs are unordered pairs of distinct states of .
Lemma 1 (termination). The loop of lines L6 to L9 stops, and each pair is pushed at most once.
Proof. A pair is pushed only at the moment it is marked, at line L4 or line L9, and a marked pair is never unmarked. Line L9 marks only unmarked pairs. So each pair is pushed at most once, and the loop makes at most passes.
Lemma 2 (the waiting lists). For pairs and , is in the list if and only if for some .
Proof. Line L5 appends to for each with , and nothing else appends to the lists.
Lemma 3 (soundness). Each marked pair is distinguishable.
Proof. By induction on the order in which pairs are marked. A pair marked at line L4 has exactly one state in , so distinguishes it. A pair marked at line L9 is in for a pair that was marked earlier, since it was pushed when marked. By Lemma 2 there is with , and by induction some distinguishes and . Then distinguishes and .
Lemma 4 (completeness). Each distinguishable pair is marked when the loop stops.
Proof. By induction on the length of a shortest distinguishing string of the pair . If , exactly one of is in , and line L4 marks the pair. If , then and are distinguished by the shorter string , so , and by induction is marked. Each marked pair is pushed once and, by the loop condition, popped before the loop stops. When is popped at line L7, line L8 reads the list , which contains by Lemma 2. So is marked then, if it was not marked before.
So, when the loop stops, an unordered pair of distinct reachable states is unmarked if and only if its states are equivalent.
Lemma 5 (the classes). is an equivalence relation on . If , then for each , and .
Proof. "Same membership in after " is reflexive, symmetric and transitive for each fixed , so is an equivalence relation. If distinguished and , then would distinguish and . With , and agree on .
Lemma 6 (the quotient). Lines L10 to L12 make the DFA with and , and .
Proof. Line L10 gives each state the least state of , in the fixed order, that is unmarked with it, which by Lemmas 3 to 5 is the least element of its class. So two states get the same representative if and only if they are equivalent. By Lemma 5, and do not depend on the choice of in its class. By induction on , , and by Lemma 5 again, if and only if .
Theorem. TABLE-FILLING stops and returns a DFA with the language of and with the least number of states among all complete DFAs for .
Proof. It stops by Lemma 1 and the finiteness of the other loops, and by Lemma 6. Each state of is for some , since is the set of reachable states. Two different states and are distinguished by some , and then exactly one of and is in , so for the Myhill-Nerode relation of . So has at least classes, and by the Myhill-Nerode theorem each complete DFA for has at least that many states.
Running time. Let and . The search of line L1 costs in the worst case and on the reachable part. Lines L2 to L5 touch each of the pairs times, and the lists hold at most entries in total. By Lemma 1 each list is read at most once in lines L6 to L9, so the loop costs . Lines L10 to L12 cost . The total is time and space.