Minimization: Merging Equivalent States
Two correct automata for the same language, one larger than the other: distinguishing words and equivalent states, table filling in rounds, and the quotient automaton that recognizes the same language.
Last updated:
In this lesson we learn to make a deterministic finite automaton (DFA) smaller without changing its language by merging states:
to decide when two states can be merged, using a distinguishing word; to fill a table of pairs in rounds that finds all the equivalent states; and to build from them the quotient automaton and prove that it recognizes the same language.
The language
of the words that contain or contain has two validators.
One is the product automaton of the validator for “contains ” (the states ) and the validator for “contains ” (the states ), with 9 states.
The other was designed directly, with 4 states: (start), and (the last letter, and no two equal adjacent letters found yet) and (such a pair found).
The two automata are equivalent, that is, they recognize the same language, and we write when .
The transition table of the validator designed directly; the arrow marks the start state and the star the accepting state:
| State | on | on |
|---|---|---|
In a DFA , where is the start state, a state is reachable if there is a word such that .
In the product the state is not reachable, and after removing it 8 states remain, twice as many as in the validator designed directly.
The construction of the two validators and the removal of the states that are not reachable are in Minimization: Removing Unreachable States.
Figure: the product automaton
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)
Which states can be merged?
Think: which of the 8 remaining states “do the same thing” and can be merged into one state without changing the language?
Suggest groups, and give reasons.
Hint
What happens to the run after it reaches one of the five accepting states?
Can it leave them?
Answer
The five accepting states: every letter leads from an accepting state to an accepting state (in each of them or is a coordinate, and both are trap states), so from each of them every continuation of the word is accepted.
We answer for the three states that do not accept, , and , right below.
Let us check whether we can also merge and . From the letter leads to , which accepts, and from it leads to , which does not.
If we merge the two states, we will not know where to continue on :
the word must be accepted and the word must not.
Such a word, which leads from one of the states to an accepting state and from the other to a state that does not accept, is a distinguishing word for the pair.
Formulate: when are two states and of a DFA “the same”, so that we can merge them without changing the language?
Write a condition using and .
Hint
Candidate definitions: (1) and both accept or both do not; (2) for every letter , ; (3) the pair has no distinguishing word.
Which of them is right in the example of and , and which fits the five accepting states here?
The formal definition
Let be a DFA. A word is a distinguishing word for the pair of states if exactly one of the states and belongs to .
The states and are equivalent states, and we write , if they have no distinguishing word:
The empty word distinguishes every accepting state from every state that does not accept, because .
Candidate (1) is only the case , and candidate (2) is too strict:
from and from the letter leads to different states, but they have no distinguishing word.
The sign here is the same sign as for equivalent automata, and not by chance:
exactly when the automaton , which starts at , is equivalent to the automaton , which starts at .
The language of the first is and of the second , and the condition in the definition says that these languages are equal.
Question 1. Find a distinguishing word for the pair and for the pair .
Figure: the product automaton (from the start of the lesson)
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)
Answer
For the first pair : from it leads to , which accepts, and from to , which does not.
For the second pair : from to , which accepts, and from to , which does not.
Equivalence behaves like equality: every state is equivalent to itself; if then ; and if and then , because for every word we have .
So the states split into disjoint groups, in each of which every two states are equivalent, while states from different groups are not equivalent.
The set of all the states equivalent to a state is the class of , and we denote it .
Question 2. Is ? How many classes are there among the five accepting states of the product?
Figure: the product automaton (from the start of the lesson)
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)
Hint
Prove by induction on the length of the word that from every accepting state of the product, every word ends in an accepting state.
Answer
Yes. We prove by induction on the length of that for every accepting state of the product, accepts.
Base: accepts. Step: if accepts, then , and every letter leads from an accepting state to an accepting state (the coordinate or is a trap state).
So no two accepting states have a distinguishing word, and all five form one class.
Table filling in rounds
With the eight states of the product it is already tedious to check every pair separately.
We merged the five accepting states with one argument, because from each of them every letter leads to an accepting state; an automaton without such a structure has no general argument that covers many pairs at once.
We need a method that finds all the pairs that have a distinguishing word.
The idea: a distinguishing word that starts with the letter is , and distinguishes the two states that leads to.
For this we need to read a word in two parts, the first letter and then the rest, while is defined by the last letter.
Claim and proof: reading a word in two parts
Claim. For every state and every two words : .
In particular, for a letter : .
Proof by induction on the length of , with and fixed.
- Base, : , by the definition of on the empty word.
- Induction hypothesis: the claim holds for every word of length .
- Step, with and :
The first and third equalities are the definition of on the last letter, and the second is the induction hypothesis.
The case gives the conclusion, because .
So long distinguishing words are built from short ones:
- Round 0: mark every pair of an accepting state and a state that does not accept (the distinguishing word ).
- Round : mark a pair not yet marked if there is a letter that leads it to a pair marked in an earlier round. The distinguishing word is followed by the word of that pair.
- Stop: when a whole round marks no pair. The pairs that were not marked are equivalent, and we merge them. In a DFA with states this happens by round at the latest (the proof is in part (3) below).
The pairs are written in a triangular table, one cell per pair.
Half a table is enough: a word distinguishes from exactly when it distinguishes from , so the cell of would repeat the cell of ; and the diagonal cells are not needed, because no word distinguishes a state from itself.
In every cell we mark we write the distinguishing word. The word written in round has length :
the pair that the letter leads to was marked exactly in round , because if it had been marked earlier, the current pair would already have been marked in the round after that.
The method is called table filling.
Example. We are given a DFA over with six states , start state and a single accepting state .
The names are numbered, because we do not yet know what each state remembers.
| State | on | on |
|---|---|---|
Transitions of the diagram:
- δ(q_0, a) = q_5
- δ(q_0, b) = q_1
- δ(q_5, a) = q_2
- δ(q_5, b) = q_3
- δ(q_2, a) = q_5
- δ(q_2, b) = q_3
- δ(q_3, a) = q_2
- δ(q_3, b) = q_3
- δ(q_1, a) = q_4
- δ(q_1, b) = q_1
- δ(q_4, a) = q_4
- δ(q_4, b) = q_4
Question 3. All the states are reachable. Fill in the table round by round, and before each round predict which pairs it will mark.
In each cell write a distinguishing word, or if the pair was not marked by the time the algorithm stops.
The word you write in round has length , so its length tells in which round the pair was marked.
What is the language of the automaton?
?(round 2) | |||||
?(round 1) | ?(round 1) | ||||
?(round 0) | ?(round 0) | ?(round 0) | |||
?(round 2) | ? | ?(round 1) | ?(round 0) | ||
?(round 1) | ?(round 1) | ? | ?(round 0) | ?(round 1) |
Answer: the rounds and the language
Round 0: the five pairs of with another state. Round 1: the letter leads and to , and to ; so the six pairs of a state from and a state from are marked, by the word .
The letter leads no state to , so it marks nothing in this round.
Round 2: leads to and to , and these two pairs were marked in round 1; so and are marked by the word .
The pair goes on to and on to , and the pair goes on to and on to ; neither reaches a marked pair.
Round 3: no new pair, and we stop.
The classes: , , , . Now we can say what each class remembers:
is “the word started with ” (a rejecting trap state), is “started with and the last letter is ”, and is “started with and the last letter is ”.
The language: the words that start with and end with .
Why we can rely on the table. We need two directions: every marked pair is not equivalent, and every pair not marked when the algorithm stops is equivalent.
Proof: a pair is marked if and only if it has a distinguishing word
(1) The main claim: after round , a pair is marked if and only if it has a distinguishing word of length at most . By induction on .
In round 0 exactly the pairs of an accepting state and a state that does not accept are marked, that is, the pairs that distinguishes.
Suppose the claim holds after round . A nonempty word of length at most is with , and by the claim on reading a word in two parts it distinguishes and exactly when distinguishes and .
So has a distinguishing word of length at most exactly when it has one of length at most , or some letter leads it to a pair that has one.
By the induction hypothesis, this is exactly the condition for the pair to be marked after round :
it was marked before, or round marks it.
(2) The marking at the end is correct. If round marks no pair, the rounds after it mark none either, because they check the same pairs against the same marks.
So, by (1), every pair that has a distinguishing word, of any length, is already marked when the algorithm stops, and every marked pair has a distinguishing word.
(3) The algorithm stops, by round at the latest, where . The relation “no distinguishing word of length at most ” is reflexive, symmetric and transitive, by the same argument as for equivalence, and by (1) it relates exactly the pairs not marked after round .
We write for the number of its classes. Marks are only added, so every class after round is contained in a class after round ; a round that marks a pair also splits a class, so then .
If all the states accept, or none of them does, round 0 marks nothing and the algorithm stops there.
Otherwise and always , so after round 0 there are at most rounds that mark a pair:
the algorithm stops by round at the latest. In particular, the shortest distinguishing word of a pair has length at most .
Quotient automaton
Question 4. We apply the table to the product of this lesson.
After removing , eight states remained, that is, pairs.
We go through the table round by round.
Figure: the product automaton (from the start of the lesson)
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)
(a) Round 0: how many pairs will be marked?
A:
The reasoning: the first round marks all the pairs.
Only pairs that have a distinguishing word are marked. In round 0 that word is , and it distinguishes only an accepting state from one that does not accept.
B:
The reasoning: a state that does not accept and an accepting state:
pairs.
This is the answer: distinguishes exactly an accepting state from a state that does not accept.
C:
The reasoning: the pairs of the five accepting states, .
Two accepting states give the same answer on , so their pair is not marked in round 0.
D:
The reasoning: we mark the pairs of two states that do not accept.
Round 0 marks a pair of an accepting state and a state that does not accept.
Two states that do not accept give the same answer on , so does not distinguish them.
(b) Round 1: how many new pairs will be marked?
A:
The reasoning: every pair not marked in round 0 is marked in round 1.
A pair is marked only if a letter leads it to a pair already marked.
The ten pairs of accepting states are not such pairs.
B:
The reasoning: now it is the turn of the pairs of accepting states.
From every accepting state every letter leads to an accepting state, so no letter leads a pair of two accepting states to a marked pair.
C:
The reasoning: the three pairs of the states that do not accept, with the words , and .
This is the answer: each of them has a letter that leads it to a pair of an accepting state and one that does not accept (Question 1 and the example before it).
D:
The reasoning: from every state that does not accept, the letters lead to similar states, so there is no new pair.
From the letter leads to an accepting state, and from to a state that does not accept, that is, to a pair marked in round 0.
Each of the three pairs of states that do not accept has such a letter.
(c) Round 2: what happens in it?
A: pairs of accepting states are marked, with words of length
The reasoning: what a short word did not separate, a longer word will.
From every accepting state every word is accepted, so a pair of two accepting states has no distinguishing word of any length (Question 2).
B: the pair is marked with the word
The reasoning: the letter leads it to a pair marked in round 1.
This pair was already marked in round 1, with the word .
Each pair is marked once, and no new word is written for it.
C: we go on to round 3, because the product has states
The reasoning: we stop only at round .
We stop at the first round that marks no pair. Round is only a bound on when this happens.
D: no new pair is marked, and the algorithm stops
The reasoning: the pairs left are only pairs of two accepting states.
This is the answer: every letter leads such a pair to a pair of two accepting states, which is not marked, or to a single state.
So the round marks nothing.
(d) The classes: how many classes of equivalent states are there?
A:
The reasoning: the accepting states, and the states that do not accept.
The three states that do not accept were separated from each other in round 1, so each of them is in a class of its own.
B:
The reasoning: each of the three states that do not accept alone, plus one class of all the accepting states.
This is the answer: , , and , which is the class of the five accepting states.
C:
The reasoning: the three states that do not accept, plus two classes of accepting states:
those with and those with .
No pair of two accepting states is marked, so all five accepting states are in one class.
For example (Question 2).
D:
The reasoning: every state is in a class of its own.
A pair that was not marked is a pair of equivalent states, and equivalent states are in the same class.
Ten pairs were not marked.
We build an automaton whose states are the classes. Let be a DFA.
The quotient automaton of is the DFA
with the components:
- States: , the classes of equivalent states.
- Start state: , the class of the start state.
- Accepting states: , the classes of the accepting states.
- Transition function: for every and every ,
That is, the transition on from a class is the class of the state that leads to from one of the states in the class.
The definition of picks a state from the class; below we prove that the result does not depend on the choice.
As for every DFA, is the extension of to words.
In the product, after removing the state that cannot be reached, the transition table of the quotient automaton is:
| State | on | on |
|---|---|---|
If we call by the name , by the name , by the name and by the name , we get exactly the table of the validator designed directly.
Removing the states that are not reachable and merging the equivalent states are together called minimization of the automaton, and here minimization led from the product to the small validator, without designing again, and among its four states there is no pair that can be merged:
every pair has a distinguishing word.
Think: in the definition of we chose one state from the class.
Why does the result not depend on the choice, and why does the quotient automaton recognize the same language as the original automaton?
Proof: the quotient automaton is well defined and recognizes the same language
Let be a DFA, and let be its quotient automaton, as defined.
(a) The transition is well defined. Suppose and let be a letter.
For every word , , by the claim on reading a word in two parts, and likewise for .
Since , the word does not distinguish from , so does not distinguish from .
This holds for every , so : two states of the same class move to the same class.
(b) The accepting states are well defined. If then does not distinguish them, that is, .
So each class either accepts entirely or does not accept at all.
(c) The run on a word. We prove by induction on the length of the claim:
for every state , .
- Base, : both sides equal by the definition of .
- 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 (well defined by (a)).
Conclusion. if and only if , if and only if (by (c)) , if and only if (by (b)) , if and only if .
Minimization: the full order
- Find the reachable states (by a search in the graph), and remove the rest.
- Fill in the table of pairs in rounds, until a round marks no pair.
- Merge each class of equivalent states into one state, and build the quotient automaton.
The result is equivalent to the original automaton, that is, it recognizes the same language (the proof is in the section Quotient automaton), it has no state that cannot be reached, and it has no two equivalent states.
The section A lower bound on the number of states shows that no DFA for the same language is smaller.
Connection to later courses: a small automaton in a lexical analyzer
A compiler begins by splitting the program text into words, such as variable names, numbers and reserved words; this part is done by a lexical analyzer, which has a DFA at its core.
When the DFA is built automatically from a description of the kinds of words, it sometimes comes out larger than necessary, and a minimization method like the one in this lesson shrinks its transition table.
A shorter method: splitting into classes
Table filling has one cell for every pair of states: the six states of the example in Question 3 have 15 cells, and the eight states of the product have 28.
We can work with one row per state instead: we keep the states split into classes, and split a class when its states behave differently on a letter.
This is partition refinement, the method of Edward Moore. We write for the class of the state after round .
- Round 0: two classes, the accepting states and the states that do not accept.
- Round : for every state we write its signature: for every letter , the class of the previous round. Over the signature is the pair . States of the same class whose signatures differ split into separate classes.
- Stop: when a whole round splits no class. The classes that remain are the classes of equivalent states.
The method runs the same rounds as table filling: after round two states are in the same class exactly when they have no distinguishing word of length at most , that is, when their pair was not marked in the table by round .
The difference is in the work: each round has rows, one per state, instead of cells, and we check only where each letter leads, without writing words.
Proof: the classes after each round
Claim. After round , if and only if have no distinguishing word of length at most .
Proof by induction on . In round 0 the states are in the same class exactly when both accept or neither accepts, that is, when does not distinguish them.
Suppose the claim holds after round . By the method, exactly when and for every letter , .
By the induction hypothesis, the condition means: have no distinguishing word of length at most , and for every letter the pair has no such word.
A nonempty word of length at most is with , and by the claim on reading a word in two parts it distinguishes from exactly when distinguishes from .
So the condition holds exactly when have no distinguishing word of length at most .
This is the argument of part (1) of the proof for table filling, so the stop, by round at the latest, carries over from part (3) there.
The split log. The classes say which states are equivalent, but they give no distinguishing word.
To get words, every time a class splits we write one line in a log:
what split from what, and a word.
- In round 0 the word is .
- In round the word is the letter on which the signatures differ, followed by the word already in the log for the two classes that leads to. Those two classes split in an earlier round, so their line is already in the log.
- A class that splits into more than two parts gets one line for every two parts.
The word of a pair of states is read from the first line of the log in which the two states are on different sides.
It distinguishes them: from all the states on one side leads to one class, from all the states on the other side to the other class, and the rest of the word distinguishes those two classes.
As in table filling, the word written in round has length , and the pair has no shorter distinguishing word, because in the previous round the two states were still in the same class.
Splitting into classes: the order of steps.
Input: a DFA with no states that cannot be reached.
Output: the classes of equivalent states, and a distinguishing word for every pair of states that are not equivalent.
- Initialization: is the list of the classes and , without an empty class. If neither is empty, write a line in the log: split from , with the word .
- Rounds: repeat steps (a) to (d) for , until step (d) stops:
- (a) for every state and every letter , write in the signature of the class of that contains .
- (b) split every class of into groups of states with the same signature; is the list of the groups.
- (c) for every two groups that came from the same class, choose a letter on which their signatures differ; it leads them to classes and of . Write in the log the two groups and the word , where is the word already in the log for and .
- (d) Stop: if , that is, no class split, stop.
- Output: the classes of are the classes of equivalent states. The word of a pair of states is in the first line of the log in which the two states are on different sides.
When has two classes, every round that splits a class increases the number of classes by at least one, and there are never more than classes; so at most rounds split.
Stopping is safe: the next round would compute the signatures from the same classes and get the same partition, and so would every round after it, so no class will ever split again.
After the stop we build the quotient automaton from the classes.
Example: the product of this lesson. After removing , eight states remain.
We name the classes with Roman numerals.
Figure: the product automaton (from the start of the lesson)
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)
Round 0: is the five accepting states, and is the three states .
Round 1: the signatures with respect to the classes of round 0.
| State | Class | on | on |
|---|---|---|---|
Inside all the states have the same signature, so it does not split.
Inside there are three different signatures, so it splits into three parts, and three lines are written in the log.
After the round stays as it was, , and .
Round 2: a class of a single state cannot split, so only is left to check.
From every accepting state every letter leads to an accepting state, so the signature of all five is .
No class split, and we stop: four classes, as in Question 4.
The log:
- Round 0: the five accepting states split from the three states that do not accept. The word .
- Round 1: split from . The signatures differ on ( against ), and the word of and in line 1 is . The word .
- Round 1: split from . The signatures differ on , and the word of and is again from line 1. The word .
- Round 1: split from . The signatures differ on both letters; we choose , and again the word of and is from line 1. The word .
The words are the same as those of table filling: for the fifteen pairs of an accepting state and a state that does not accept, and , , for the three pairs of states that do not accept, as in Question 1 and in part (b) of Question 4.
Each round had at most eight rows, instead of 28 cells.
Try it yourself. Apply splitting into classes to the DFA of the example in the section Table filling in rounds (Question 3).
In every round write the signatures and the classes, and keep a split log.
At the end compare the words in the log with the words in the table of Question 3.
Figure: the DFA of the table-filling example
Transitions of the diagram:
- δ(q_0, a) = q_5
- δ(q_0, b) = q_1
- δ(q_5, a) = q_2
- δ(q_5, b) = q_3
- δ(q_2, a) = q_5
- δ(q_2, b) = q_3
- δ(q_3, a) = q_2
- δ(q_3, b) = q_3
- δ(q_1, a) = q_4
- δ(q_1, b) = q_1
- δ(q_4, a) = q_4
- δ(q_4, b) = q_4
Answer
Round 0: and . In the log: split from the other states, with the word .
Round 1:
| State | Class | on | on |
|---|---|---|---|
splits: separates from . The signatures differ on ( against , the line of ), so the word is .
The classes: , , .
Round 2:
| State | Class | on | on |
|---|---|---|---|
splits: separates from . The signatures differ on ( against ), and the word of and in the log is , so the word is .
The classes: , , , .
Round 3: and have the signature , and and the signature .
No class splits, and we stop.
The classes are , , , . The log gives for the pairs of , for the pairs of a state from and a state from , and for the pairs and :
the same words as in the table of Question 3.
Indistinguishable words
The quotient automaton has no two equivalent states. It is not yet clear that there is no other DFA for the same language, with a completely different structure, with fewer states:
equivalence of states speaks about one automaton. We ask the same question about words, which does not depend on any automaton.
Let be a language, and let . A word distinguishes the words and with respect to if exactly one of the words and belongs to .
If they have no distinguishing word, they are indistinguishable words, and we write :
Otherwise and are distinguishable. Like the equivalence of states, the relation is reflexive, symmetric and transitive, so it splits all the words into classes; the class of is , and the classes are called the Myhill–Nerode classes, after John Myhill and Anil Nerode.
The link to states. Let be a DFA that recognizes , and write and .
By the claim on reading a word in two parts , so exactly when ; the same holds for and .
So distinguishes the words exactly when it distinguishes the states :
In particular, two words whose runs end in the same state are indistinguishable.
In a DFA whose states are all reachable, every class of equivalent states corresponds to one class of words:
the words whose runs end in its states.
Question 5. In the product of this lesson, the runs on , , and end in the four classes of the quotient automaton.
In each cell write a word that distinguishes, with respect to , the word of the row from the word of the column.
? | |||
? | ? | ||
? | ? | ? |
Answer: the reason for each cell
and : and . and : and .
and : and . In the row of the word distinguishes, because and the other three words are not in .
A lower bound on the number of states
Claim (lower bound). If are words every two of which are distinguishable with respect to , then every DFA that recognizes has at least states.
Proof. Let be a DFA for with fewer than states.
Each of the words is assigned the state , so there are with (the pigeonhole principle: when objects are put into fewer than boxes, some box holds at least two).
By the link to states , which contradicts their being distinguishable.
Conclusion: the quotient automaton is the smallest. In the quotient automaton every state is reachable and no two states are equivalent.
Choose for every state a word whose run ends in it; by the link to states every two of these words are distinguishable, and by the bound every DFA for the same language has at least as many states as the quotient automaton.
In the product of this lesson these are the words of Question 5:
there is no DFA for with three states, and the directly designed validator is the smallest.
Question 6. Let , the language of the words that end in .
Find three words every two of which are distinguishable with respect to .
What follows?
Hint
What must be remembered while reading to know whether the word will end in ?
Try one word for each state of that memory.
Answer
, and . and : gives and .
and : . and : . So every DFA for has at least three states.
The validator of exercise 2 in designing a DFA shows that three states are enough.
The smallest automaton
The smallest number of states of a DFA for is the number of classes of :
by the bound there is at least one state per class, and the automaton whose states are the classes shows that this is enough.
In the product of this lesson, we name every state of the quotient automaton by the class of the words whose runs end in it:
is , is , is and is .
This is the automaton of the classes of , in which the transition from a class on a letter is the class :
| State | on | on |
|---|---|---|
For example on is , because and are indistinguishable:
neither has a pair of equal adjacent letters, and both end in .
The automaton of the classes, and uniqueness up to renaming
The automaton of the classes. When has finitely many classes, define , where is the set of classes and
The transition is well defined: if , then for every the word does not distinguish and , so .
is well defined too, because does not distinguish two words of the same class.
By induction on the length of , (in the step, ), so exactly when , that is, when .
Building : the order of steps.
- Start with the representative : the class is the start state.
- For every representative and every letter , check whether is indistinguishable from one of the representatives. If so, is its class; if not, is the representative of a new class.
- Repeat step 2 until every representative has a transition on every letter.
- The accepting states are the classes of the representatives that belong to .
Uniqueness up to renaming. Let be a smallest DFA for .
Every state of it is reachable, since otherwise removing the state would give a smaller DFA.
Assign to every state the class of a word whose run ends in ; by the link to states the class does not depend on the choice of .
By the assignment preserves the transitions, the start state and the accepting states.
Every class is obtained from the state in which the run on ends, so the assignment is onto; since both automata have the same number of states (the number of classes), it is also one-to-one.
So every smallest DFA for is with other names for its states, and in particular table-filling minimization always gives the same automaton, from whatever DFA it starts.
Minimization in a tool, step by step
On the page Minimization Step by Step the product automaton of this lesson is loaded in the tool, and pressing “Minimise step by step” shows the steps:
which states were removed, which pairs were marked in each round, and which classes remained.
In the tool you can also draw another automaton, larger than necessary for some language, decide in advance how many states will remain, and check.
The page Minimization Practice: Table Filling has six minimization problems on paper with solutions, and a tool that draws a new DFA every time and checks each step:
the states that cannot be reached, every cell of the pair table, the classes and the quotient automaton.
On the page Three Processes on a DFA three processes run step by step on the same DFA, and the diagram is coloured at every step:
the sets of reachable states (from Minimization: Removing Unreachable States), the equivalent states by table filling or by splitting into classes with a split log, and the classes of words with a separating suffix for every pair of words.
Practice
1. Over we are given a DFA that counts the ‘s modulo 4:
states (the subscript is the remainder), start , the letter leads from to and the letter keeps the state.
The accepting states are and . Minimize the automaton and describe its language.
Hint
Which pairs are marked in round 0? Where does lead the pair , and was that pair marked?
Answer
All the states are reachable. In round 0 the pairs , , , are marked.
In round 1 there is no new pair: leads to and to , and neither pair was marked; keeps every pair in place.
The classes are and , and the quotient automaton has two states.
The language: the words with an even number of ‘s.
2. A validator for the language “ends in ” over was designed to remember the last two letters:
(start, no letter read), (one letter read), and (the last two letters).
From every state, the letter leads to the state of the last two letters after adding it (for example and ), and the only accepting state is .
Minimize the validator, and compare the result with the validator of exercise 2 in Designing a Deterministic Finite Automaton.
Hint
Which states lead on to ? What do they have in common?
Answer
All seven states are reachable. In round 0 every pair with in it is marked.
In round 1 every pair of a state from (ends in ) and a state from is marked, by the word .
In round 2 there is no new pair: within each of the two groups, leads both states to the group and leads both to the same group (to from the first group, and to from the second).
The classes are , and : three states, and after renaming this is the validator of exercise 2.
3. Prove or disprove: in every DFA, every two accepting states are equivalent.
Hint
Look for an automaton in which, on the same letter, one accepting state can move to a state that does not accept and the other cannot.
Answer
The claim is false. Take the counter of ‘s modulo 3 (, raises the remainder by 1, keeps the state) with the accepting states (the number of ‘s is not divisible by 3):
accepts and does not, so is a distinguishing word for two accepting states.
4. For the language “at least letters ” over (for ) we are given a counter with the states :
in the state , letters have been read (and in at least ), the letter raises the subscript by 1 up to , the letter keeps the state, the start state is and the accepting states are .
In which round of table filling will the pair be marked, and what is its distinguishing word?
How many states will remain?
Hint
Fill in the table for : which pair is marked in round 1, and which in round 2?
Look for the pattern.
Answer
In round (for ) the pairs of with every state of smaller subscript are marked:
brings to and the other state to a state that does not accept, and no shorter word distinguishes them, because does not change the state and a word with fewer than letters leaves both states below .
So is marked in round , by the word : from it reaches , and from it reaches .
The pairs among are not marked, because from each of them every letter leads to an accepting state; the three merge, and states remain.
Back to Minimization: Removing Unreachable States, or see the glossary.