Algorithm Search⌘K

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 M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F) be a complete DFA, δ:Q×Σ→Q\delta : Q \times \Sigma \to Q, and let RR be the set of states reachable from q0q_0. For p,q∈Rp, q \in R, a string zz distinguishes pp and qq if exactly one of δ∗(p,z)\delta^*(p, z) and δ∗(q,z)\delta^*(q, z) is in FF. The states are equivalent, p≈qp \approx q, if no string distinguishes them. Pairs are unordered pairs {p,q}\{p, q\} of distinct states of RR.

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 (∣R∣2)\binom{|R|}{2} passes. □\square

Lemma 2 (the waiting lists). For pairs {p,q}\{p, q\} and {r,s}\{r, s\}, {p,q}\{p, q\} is in the list S[r,s]S[r, s] if and only if {δ(p,a),δ(q,a)}={r,s}\{\delta(p, a), \delta(q, a)\} = \{r, s\} for some a∈Σa \in \Sigma.

Proof. Line L5 appends {p,q}\{p, q\} to S[δ(p,a),δ(q,a)]S[\delta(p, a), \delta(q, a)] for each aa with δ(p,a)≠δ(q,a)\delta(p, a) \ne \delta(q, a), and nothing else appends to the lists. □\square

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 FF, so ε\varepsilon distinguishes it. A pair {p,q}\{p, q\} marked at line L9 is in S[r,s]S[r, s] for a pair {r,s}\{r, s\} that was marked earlier, since it was pushed when marked. By Lemma 2 there is aa with {δ(p,a),δ(q,a)}={r,s}\{\delta(p, a), \delta(q, a)\} = \{r, s\}, and by induction some zz distinguishes rr and ss. Then azaz distinguishes pp and qq. □\square

Lemma 4 (completeness). Each distinguishable pair is marked when the loop stops.

Proof. By induction on the length of a shortest distinguishing string zz of the pair {p,q}\{p, q\}. If z=εz = \varepsilon, exactly one of p,qp, q is in FF, and line L4 marks the pair. If z=az′z = az', then r=δ(p,a)r = \delta(p, a) and s=δ(q,a)s = \delta(q, a) are distinguished by the shorter string z′z', so r≠sr \ne s, and by induction {r,s}\{r, s\} is marked. Each marked pair is pushed once and, by the loop condition, popped before the loop stops. When {r,s}\{r, s\} is popped at line L7, line L8 reads the list S[r,s]S[r, s], which contains {p,q}\{p, q\} by Lemma 2. So {p,q}\{p, q\} is marked then, if it was not marked before. □\square

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). ≈\approx is an equivalence relation on RR. If p≈qp \approx q, then δ(p,a)≈δ(q,a)\delta(p, a) \approx \delta(q, a) for each aa, and p∈F⇔q∈Fp \in F \Leftrightarrow q \in F.

Proof. "Same membership in FF after zz" is reflexive, symmetric and transitive for each fixed zz, so ≈\approx is an equivalence relation. If zz distinguished δ(p,a)\delta(p, a) and δ(q,a)\delta(q, a), then azaz would distinguish pp and qq. With z=εz = \varepsilon, pp and qq agree on FF. □\square

Lemma 6 (the quotient). Lines L10 to L12 make the DFA M′=(R/≈,Σ,δ′,[q0],F′)M' = (R / {\approx}, \Sigma, \delta', [q_0], F') with δ′([p],a)=[δ(p,a)]\delta'([p], a) = [\delta(p, a)] and F′={[p]:p∈F∩R}F' = \{[p] : p \in F \cap R\}, and L(M′)=L(M)L(M') = L(M).

Proof. Line L10 gives each state the least state of RR, 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, δ′\delta' and F′F' do not depend on the choice of pp in its class. By induction on ∣w∣|w|, δ′∗([q0],w)=[δ∗(q0,w)]\delta'^*([q_0], w) = [\delta^*(q_0, w)], and by Lemma 5 again, [δ∗(q0,w)]∈F′[\delta^*(q_0, w)] \in F' if and only if δ∗(q0,w)∈F\delta^*(q_0, w) \in F. □\square

Theorem. TABLE-FILLING(M)(M) stops and returns a DFA with the language of MM and with the least number of states among all complete DFAs for L(M)L(M).

Proof. It stops by Lemma 1 and the finiteness of the other loops, and L(M′)=L(M)L(M') = L(M) by Lemma 6. Each state of M′M' is [δ∗(q0,x)][\delta^*(q_0, x)] for some xx, since RR is the set of reachable states. Two different states [δ∗(q0,x)][\delta^*(q_0, x)] and [δ∗(q0,y)][\delta^*(q_0, y)] are distinguished by some zz, and then exactly one of xzxz and yzyz is in L(M)L(M), so x̸≡Lyx \not\equiv_L y for the Myhill-Nerode relation of L=L(M)L = L(M). So LL has at least ∣R/≈∣|R / {\approx}| classes, and by the Myhill-Nerode theorem each complete DFA for LL has at least that many states. ■\blacksquare

Running time. Let n=∣R∣n = |R| and σ=∣Σ∣\sigma = |\Sigma|. The search of line L1 costs O(∣Q∣σ)O(|Q| \sigma) in the worst case and O(nσ)O(n \sigma) on the reachable part. Lines L2 to L5 touch each of the (n2)\binom{n}{2} pairs O(σ)O(\sigma) times, and the lists hold at most σ(n2)\sigma \binom{n}{2} entries in total. By Lemma 1 each list is read at most once in lines L6 to L9, so the loop costs O(σn2)O(\sigma n^2). Lines L10 to L12 cost O(n2+nσ)O(n^2 + n\sigma). The total is O(σn2)O(\sigma n^2) time and O(σn2)O(\sigma n^2) space.

Back to Table-filling DFA minimization