Myhill–Nerode Practice
Complete the automaton of the classes in a tool that checks every transition, and questions to solve on paper: the classes of a finite language and of new languages, the classes of the complement, a bound on the number of classes of an intersection, and a claim to refute.
Last updated:
On this page we practise building the automaton from the classes of a language, and using the Myhill–Nerode classes in proofs, following the lesson “Minimization: Merging Equivalent States”.
Completing the automaton of the classes
Choose a language. The tool shows its classes, each named by its shortest word (among several, the first in alphabetical order), and we complete :
where each class goes on each letter, and which classes are accepting.
By the construction of , the transition from on is the class of , so each cell asks which class one word belongs to.
For a wrong answer the tool shows a distinguishing word.
The tool needs JavaScript. Use Questions 1 to 3 on paper.
Questions on paper
Question 1. Let . How many classes does have? Find a representative word for each class, prove that every two of them are distinguishable, and build .
Hint
After no continuation brings the word into the language.
Which other words behave like that?
Answer
Five classes: , , , and , all the other words:
they are not prefixes of , or , so no continuation of them is in the language, and no word distinguishes them.
Distinguishing words: distinguishes every word of from every word of , because and ; and :
(, ); and : ; and :
(, ); and : (, ).
The words and are in the same class, because both are in the language and every nonempty continuation takes both out of it.
| State | on | on |
|---|---|---|
The class is a rejecting trap state.
Question 2. Let
the words that end with and contain no . How many states does the smallest DFA for have?
Prove the lower bound, and build .
Hint
What must be remembered: the last letter, and whether has already appeared.
Is the empty word in the class of another word?
Answer
Four. The words are pairwise distinguishable: distinguishes from each of the others; and :
(, ); and , and also and :
(, ). Four states are enough: ; is the words that end in and contain no ; is the words that end in and contain no ; is the words that contain .
The table is a DFA for :
| State | on | on |
|---|---|---|
Question 3. Let . Find the classes of and .
Answer
Three classes, by the remainder of on division by 3: (remainder 0, accepting), (remainder 1) and (remainder 2).
Words with the same remainder are indistinguishable, because for every the remainder of depends only on the remainder of and on the word .
Distinguishing words: between and the other two, and between and ( is in the language, is not).
The transitions: adds 1 to the remainder and subtracts 1, that is and .
Question 4. Let be a language and its complement.
Prove that for every two words , if and only if .
What follows about the numbers of classes of and of ?
Hint
For every word , if and only if . What does this say about the statement ""?
Answer
For every , , and likewise for . So if and only if , if and only if , because negating both sides of an “if and only if” does not change its truth value.
The condition holds for every for exactly when it holds for every for , so the two relations are the same, and the two languages have the same classes.
In particular, for a language that has a DFA, the smallest DFAs for and for have the same number of states; this agrees with the complement automaton, which changes only the accepting states.
Question 5. Suppose the language has a DFA and classes, and the language has a DFA and classes.
Prove that has at most classes. Give an example in which exactly is reached.
Hint
What are the states of the product automaton of and ?
What does the lower bound say about any DFA for the language?
Answer
By the smallest-automaton theorem, has a DFA with states and has a DFA with states.
Their product automaton, with the accepting states of “and”, recognizes and has states.
By the lower bound, if had more than classes, one word from each class would give more than pairwise distinguishable words, and the product automaton would need more than states; a contradiction.
Example: and , “the number of is even” and “the number of is even”, two classes each.
The intersection is from the lesson, with four classes.
Question 6. Prove or refute: if and both have a DFA, then has at most as many classes as .
Answer
The claim is false; a counterexample: . The language has one class, because every word and every continuation of it is in the language.
The language has three classes: , and (all the other words, which are not prefixes of , so no continuation of them is in the language); distinguishes from the other two, and distinguishes from .
The k-th letter from the end
For we define over the language
that is, the words whose -th letter from the end is .
For example, and are in , and and are not.
Question 7. How many states does the smallest DFA for have?
Predict a number, and then find as many words as you can, every two of which are distinguishable with respect to .
Hint
Try the four words of length 2. What distinguishes from ?
What distinguishes from ?
Answer
The four words are pairwise distinguishable. If two words differ in the first letter, distinguishes them, because the first letter of a word of length 2 is the second letter from the end; for example and .
If they agree in the first letter and differ in the second, distinguishes them, because after adding the second letter of the original word is the second letter from the end; for example and .
So every DFA for has at least four states.
The same argument works for every . Let be two words of length , and let be the first position (from the left) in which they differ; suppose that in this position has and has .
We add : in the word , whose length is , the letter in position is the -th letter from the end, so and .
All words of length are pairwise distinguishable, and by the lower bound every DFA for has at least states.
A DFA for can remember the last letters read: a state for each word of length , and the first letter of the word in the state is the -th letter from the end.
But at the beginning of reading, letters have not yet been read.
A DFA that remembers everything read, as long as fewer than letters have been read, has a state for each word of length , that is,
states. A shorter way is a convention: we start as if letters had already been read before the word.
The states are for each word of length , the start state is , the transition on the letter deletes the first letter and adds at the end ( for every letter and word of length ), and the accepting states are those whose first letter is .
This automaton has states.
The convention does not change the language. After reading the automaton is in the state of the last letters of .
If , these are the last letters of , and the state accepts exactly when .
If , the -th letter from the end of is one of the letters we added, so the state does not accept; and too, because it has no -th letter from the end.
For :
| State | on | on |
|---|---|---|
Transitions of the diagram:
- δ(q_bb, a) = q_ba
- δ(q_bb, b) = q_bb
- δ(q_ba, a) = q_aa
- δ(q_ba, b) = q_ab
- δ(q_aa, a) = q_aa
- δ(q_aa, b) = q_ab
- δ(q_ab, a) = q_ba
- δ(q_ab, b) = q_bb
By the lower bound there is no DFA for with fewer than states, so this automaton is the smallest, and by the second conclusion of the uniqueness theorem it is up to renaming.
In the automaton with states all the states are reachable, and it recognizes the same language with more than states; so by the uniqueness theorem it has two different equivalent states.
Question 8. For : how many states does the smallest DFA for have?
Find a distinguishing word for and , and for and .
Answer
states. and first differ in position 2, so :
(the third letter from the end is ) and .
and first differ in position 2; here has , so gives and .
Minimizing the automaton without the convention
The DFA for that remembers everything read, up to two letters, has seven states, with and accepting:
| State | on | on |
|---|---|---|
Question 9. How many states will remain after minimization, and which states will merge?
Give reasons using the classes of , and check with table filling.
You can also check the answer with the tool “Minimization through words” on the practice page with tools.
Answer
Four states will remain, the number of classes. By the claim on equivalent states and indistinguishable words, two states are equivalent exactly when the words that reach them are in the same class:
(the class , which also contains and ), and (the class ).
and remain alone. This is exactly the convention:
and behave like , and like .
Continue with The Lower Bound in Action, go back to Minimization: Merging Equivalent States, or see the glossary.