Minimization: Removing Unreachable States
Two correct automata for the same language, one larger than the other: equivalent automata, states that cannot be reached, removing them without changing the language, and finding them by a search in the graph.
Last updated:
In this lesson we learn to make a deterministic finite automaton (DFA) smaller without changing its language:
when two automata are equivalent, that is, recognize the same language; how to find the states that cannot be reached, by a search in the graph step by step; and why removing them does not change the language.
Two validators for the same rule
A form field accepts codes over , and its validity rule is the language
that is, the words that contain or contain : words with two equal adjacent letters.
Each of the two parts already has a validator, built by following progress in a pattern.
The validator for “contains ” remembers how much of the end of the word already matches:
(start, or the last letter is ), (the last letter is ) and ( found; an accepting trap state).
The validator for “contains ” is built the same way, with , as in the section Combine simple machines.
Think: build the transition table of the product automaton of and , with the set of accepting states for “or”.
How many states does it have, and how many of them accept?
Hint
Each letter moves each coordinate by its own automaton only:
advances () and returns to (except , which is a trap state), and acts symmetrically.
A pair accepts for “or” when at least one coordinate accepts.
Answer
There are pairs. The arrow marks the start state and the star the accepting states, the five in which or is one of the coordinates:
| State | on | on |
|---|---|---|
Transitions of the diagram:
- δ((q_0,p_0), a) = (q_a,p_0)
- δ((q_0,p_0), b) = (q_0,p_b)
- δ((q_0,p_b), a) = (q_a,p_0)
- δ((q_0,p_b), b) = (q_0,p_bb)
- δ((q_0,p_bb), a) = (q_a,p_bb)
- δ((q_0,p_bb), b) = (q_0,p_bb)
- δ((q_a,p_0), a) = (q_aa,p_0)
- δ((q_a,p_0), b) = (q_0,p_b)
- δ((q_a,p_b), a) = (q_aa,p_0)
- δ((q_a,p_b), b) = (q_0,p_bb)
- δ((q_a,p_bb), a) = (q_aa,p_bb)
- δ((q_a,p_bb), b) = (q_0,p_bb)
- δ((q_aa,p_0), a) = (q_aa,p_0)
- δ((q_aa,p_0), b) = (q_aa,p_b)
- δ((q_aa,p_b), a) = (q_aa,p_0)
- δ((q_aa,p_b), b) = (q_aa,p_bb)
- δ((q_aa,p_bb), a) = (q_aa,p_bb)
- δ((q_aa,p_bb), b) = (q_aa,p_bb)
We can also design a validator for the same language directly, by what it must remember:
the last letter, and whether two equal adjacent letters have already been found.
This is a third machine on the same page, so its states use the letter :
(start, no letter read), and (the last letter, and no pair found yet), and (a pair found; an accepting trap state).
| State | on | on |
|---|---|---|
Transitions of the diagram:
- δ(r_0, a) = r_a
- δ(r_0, b) = r_b
- δ(r_a, a) = r_pair
- δ(r_a, b) = r_b
- δ(r_b, a) = r_a
- δ(r_b, b) = r_pair
- δ(r_pair, a) = r_pair
- δ(r_pair, b) = r_pair
Both validators are correct: both recognize exactly . Two automata over the same alphabet are equivalent automata if they recognize the same language, and we write :
that is, on every word they give the same answer. The product and the validator are equivalent, but one has 9 states and the other 4.
The product is a general method that gives a correct validator without designing again, and it grows fast:
each additional validator multiplies the number of states, and every state is one more row in the transition table that the computer stores.
The question of this lesson: how do we get from the large automaton to a small equivalent one by a method, without designing again?
Check: is the validator for “contains ” equivalent to the product automaton?
If not, give a word on which their answers differ.
Answer
No. The word contains , so the product accepts it, but it has no , so rejects it.
Every word that contains without shows that .
States that cannot be reached
Question 1. Which state of the product does no run starting at pass through?
Explain without searching the table, by what each coordinate remembers.
Hint
What does the coordinate say about the last letter? What does the coordinate say?
Answer
The state . The coordinate says that the last letter read is , and the coordinate says that it is ; the two cannot hold together.
In the table: no row leads to , and it is not the start state either.
A state of a DFA (here is the start state) is a reachable state if there is a word such that , that is, the run on ends in it.
We write for the set of reachable states:
Removing the states that are not in , together with the arrows that leave them, gives the DFA
where for every and : the same transitions, only from the states that remain.
A function is a set of pairs of an input and an output, and here the input is a pair of a state and a letter, as in the formal definition of a DFA; so can also be written as a set:
That is, keeps exactly the pairs of whose input state is in , and it is the restriction of to .
Also : this is part (a) of the proof that is a complete DFA.
The removal does not change the language, that is : the run on every word passes only through states in , so it is the same in both automata.
Claim and proof: removing the states that are not reachable
Claim. is a complete DFA, and .
(a) returns a state in . Let and . Since there is a word such that , and by the definition of on the last letter .
So , and is a function from to : the automaton is complete.
(b) The run on a word. We prove by induction on the length of :
.
- Base, : both sides equal .
- Induction hypothesis: the claim holds for every word of length .
- Step, with and :
The first and last equalities are the definition of , the second is the induction hypothesis, and the third is the definition of , because .
Conclusion. if and only if , if and only if (by (b)) , if and only if (because by the definition of ), if and only if .
We find by a search in the graph: start from the start state, and add every state that an arrow leads to from a state already found, until no state is added:
By induction on , is the set of the states of the words of length at most .
When , all the following sets are equal to it too, so .
There is no need to continue forever: the search stops by at the latest, where .
As long as , the set is larger than by at least one state.
Since , if the sets grew at every step up to , then ; and since always , they can grow at most times.
So : every reachable state is reached by a word of length at most .
In the product 8 states remain.
Question 2. In the validator designed directly, which word reaches each of the four states?
Does it have a state that is not reachable?
Answer
, , and . All four states are reachable.
Back to the question of this lesson: removing made the product smaller, from 9 states to 8, and the validator designed directly has 4 states, all of them reachable.
The gap closes only when we merge states of the product that “do the same thing”.
Removing the unreachable states and merging such states are together called the minimization of the automaton, and merging is taught in the lesson on merging states.
Practice
1. Over a DFA has six states , start state and accepting states and :
| State | on $a$ | on $b$ |
|---|---|---|
Write until the search stops, and build . Which accepting states remain, and what is the language of the automaton?
Hint
Which states lead to , to and to ? Is any of them already in some ?
Answer
, (since and ), (since ), and , since and lead from to and to .
So ; the search stops at , well before the bound .
Arrows into come only from themselves.
has three states, with the same transitions from , and the single accepting state :
the accepting state was removed, because no word reaches it.
In the state says that the last letter is , and the state that the last two letters are ; so the language of , and by the claim also of the given automaton, is the words that end in .
2. Prove or disprove: if all the states of a DFA and all the states of a DFA are reachable, then all the states of their product automaton are reachable.
Hint
Do the validators and for “contains ” and “contains ” have a state that is not reachable?
Answer
The claim is false. In all the states are reachable ( reaches , reaches and reaches ), and so are those of (, , ).
But in their product the state is not reachable (Question 1):
a word on which the run of ends in ends in , and a word on which the run of ends in ends in .
3. The search for stops by at the latest. Show that the bound cannot be improved:
for every find a DFA over with states in which .
Hint
For the search to take steps, each step must add exactly one state.
Answer
A chain: the states , start state , the letter leads from to (and from to itself), and the letter keeps the state.
Any set of accepting states will do, for example . By induction on , for every , so while also contains .
The shortest word that reaches is , of length exactly .
Continue with the lesson on merging states, go back to Combining Automata, or see the glossary.