Algorithm Search⌘K

Proofs: Brzozowski's minimization algorithm

These are the human proofs of Brzozowski's minimization algorithm, at full length.

Brzozowski's algorithm outputs the minimal DFA full

This proof shows: correctness, termination.

Let N=(Q,Σ,δ,I,F)N = (Q, \Sigma, \delta, I, F) be an NFA with a set II of start states and no ε\varepsilon-moves. For a set S⊆QS \subseteq Q and a string ww, let δ^(S,w)\hat\delta(S, w) be the set of states reachable from SS by a path labelled ww: δ^(S,ε)=S\hat\delta(S, \varepsilon) = S and δ^(S,wa)=⋃q∈δ^(S,w)δ(q,a)\hat\delta(S, wa) = \bigcup_{q \in \hat\delta(S, w)} \delta(q, a). NN accepts ww when δ^(I,w)∩F≠∅\hat\delta(I, w) \cap F \neq \emptyset.

Part 1: the subset construction

Lemma 1. DETERMINIZE (lines L6 to L13) stops, and returns a complete DFA det⁡(N)\det(N) that accepts L(N)L(N), whose states are exactly the sets δ^(I,w)\hat\delta(I, w) for w∈Σ∗w \in \Sigma^*, with the state reached on ww equal to δ^(I,w)\hat\delta(I, w).

Proof. Each subset gets a number at most once (line L10), and there are at most 2∣Q∣2^{|Q|} subsets, so the loop of line L7 runs at most 2∣Q∣2^{|Q|} times and stops. Line L9 sets δ′(S,a)=δ^(S,a)\delta'(S, a) = \hat\delta(S, a), and every numbered subset is processed, so δ′\delta' is total. By induction on ∣w∣|w|, the state reached on ww is δ^(I,w)\hat\delta(I, w): for w=εw = \varepsilon it is S0=IS_0 = I, and if it is δ^(I,w)\hat\delta(I, w) for ww, then on wawa it is δ^(δ^(I,w),a)=δ^(I,wa)\hat\delta(\hat\delta(I, w), a) = \hat\delta(I, wa). Every numbered subset was found from S0S_0 by a sequence of moves, so it is δ^(I,w)\hat\delta(I, w) for some ww, and each such set is numbered because the search follows every move of every numbered subset. Line L12 makes the state of ww accepting if and only if δ^(I,w)∩F≠∅\hat\delta(I, w) \cap F \neq \emptyset, that is, if and only if w∈L(N)w \in L(N). □\square

Part 2: reversal

Lemma 2. rev(N)=(Q,Σ,δR,F,I)\mathrm{rev}(N) = (Q, \Sigma, \delta^R, F, I), with δR(q,a)={p:q∈δ(p,a)}\delta^R(q, a) = \{ p : q \in \delta(p, a) \}, accepts L(N)RL(N)^R. More precisely, p∈δ^R(S,w)p \in \hat\delta^R(S, w) if and only if δ^({p},wR)∩S≠∅\hat\delta(\{p\}, w^R) \cap S \neq \emptyset.

Proof. A path q0→a1q1⋯→amqmq_0 \xrightarrow{a_1} q_1 \cdots \xrightarrow{a_m} q_m in NN is the same as a path qm→am⋯→a1q0q_m \xrightarrow{a_m} \cdots \xrightarrow{a_1} q_0 in rev(N)\mathrm{rev}(N), by the definition of δR\delta^R. So rev(N)\mathrm{rev}(N) has a path labelled ww from some state of SS to pp if and only if NN has a path labelled wRw^R from pp to some state of SS. With S=FS = F and p∈Ip \in I this says that rev(N)\mathrm{rev}(N) accepts ww if and only if NN accepts wRw^R. □\square

Part 3: determinizing the reverse of a reachable DFA

Theorem. Let D=(P,Σ,η,p0,G)D = (P, \Sigma, \eta, p_0, G) be a deterministic automaton, where η\eta may be partial, in which every state is reachable from p0p_0. Then det⁡(rev(D))\det(\mathrm{rev}(D)) is the minimal complete DFA for L(D)RL(D)^R.

Proof. Write η∗(p,x)\eta^*(p, x) for the state reached from pp on xx, when it is defined. By Lemma 1, the state of det⁡(rev(D))\det(\mathrm{rev}(D)) reached on ww is Sw=η^R(G,w)S_w = \hat\eta^R(G, w), and by Lemma 2,

Sw={p∈P:η∗(p,wR) is defined and lies in G}.S_w = \{ p \in P : \eta^*(p, w^R) \text{ is defined and lies in } G \}.

By Lemma 1 and Lemma 2, det⁡(rev(D))\det(\mathrm{rev}(D)) accepts L(D)RL(D)^R, and all its states are reachable.

Let Su≠SvS_u \neq S_v be two of its states, and take pp in one of them and not in the other, say p∈Su∖Svp \in S_u \setminus S_v. Since pp is reachable in DD, there is xx with η∗(p0,x)=p\eta^*(p_0, x) = p. Since DD is deterministic, η∗(p0,xy)\eta^*(p_0, x y) is defined if and only if η∗(p,y)\eta^*(p, y) is, and then they are equal. Now

p0∈SuxR  ⟺  η∗(p0,(uxR)R)∈G  ⟺  η∗(p0,xuR)∈G  ⟺  η∗(p,uR)∈G  ⟺  p∈Su,p_0 \in S_{u x^R} \iff \eta^*(p_0, (u x^R)^R) \in G \iff \eta^*(p_0, x u^R) \in G \iff \eta^*(p, u^R) \in G \iff p \in S_u,

and the same holds for vv. The state SuxRS_{u x^R} is the state reached from SuS_u on xRx^R, and it is accepting if and only if it contains p0p_0, because the accepting states of rev(D)\mathrm{rev}(D) form the set {p0}\{p_0\}. So xRx^R is accepted from SuS_u and rejected from SvS_v, and the two states are not equivalent.

So det⁡(rev(D))\det(\mathrm{rev}(D)) is a complete DFA for L(D)RL(D)^R whose states are all reachable and pairwise inequivalent. By Part 3 of the uniqueness theorem for minimal DFAs, it is the minimal complete DFA for L(D)RL(D)^R. □\square

Part 4: the algorithm

Lines L1 and L2 compute D1=det⁡(rev(N))D_1 = \det(\mathrm{rev}(N)). By Lemmas 1 and 2, D1D_1 is a complete DFA for L(N)RL(N)^R with all states reachable. Line L3 computes rev(D1)\mathrm{rev}(D_1), an NFA with the single start set F1F_1 (the accepting states of D1D_1) and the single accepting state, the start state of D1D_1. Line L4 computes det⁡(rev(D1))\det(\mathrm{rev}(D_1)). By the theorem of Part 3 with D=D1D = D_1, this is the minimal complete DFA for L(D1)R=(L(N)R)R=L(N)L(D_1)^R = (L(N)^R)^R = L(N). Both calls of DETERMINIZE stop by Lemma 1, and lines L1 and L3 are single passes over the transitions, so the algorithm stops and line L5 returns the minimal complete DFA for L(N)L(N). ■\blacksquare

Back to Brzozowski's minimization algorithm