Sub topic 12
The Myhill-Nerode Theorem
Prerequisites and the central idea
Assume that you know basic set theory, strings, equivalence relations, and proof by contradiction. You should also know the definition of a deterministic finite automaton (DFA).
A DFA has finite memory. After reading a prefix of an input string, it remembers only the information needed to classify every possible continuation. The Myhill-Nerode theorem makes this idea precise. It gives both:
- a test for whether a language is regular;
- a way to find the minimum number of states in any DFA for that language.
Distinguishable strings
Let \(L\) be a language over alphabet \(\Sigma\). Two strings \(x\) and \(y\) are equivalent with respect to \(L\) when every continuation gives the same result:
\[ x \equiv_L y \quad\text{if and only if}\quad \text{for every } z \in \Sigma^*,\ xz \in L \Longleftrightarrow yz \in L. \]
Here, \(z\) is called a continuation or suffix.
Strings \(x\) and \(y\) are distinguishable if there is at least one continuation \(z\) for which exactly one of \(xz\) and \(yz\) belongs to \(L\).
For example, let \(L\) be the language of binary strings ending in 01.
- The strings
0and the empty string \(\epsilon\) are distinguishable by1. 01belongs to \(L\), but1does not.- Therefore,
0and \(\epsilon\) cannot represent the same DFA state.
The strings need not have the same length. What matters is whether some continuation separates them.
The theorem
The Myhill-Nerode theorem states:
> A language \(L\) is regular if and only if the relation \(\equiv_L\) has finitely many equivalence classes.
The equivalence classes group prefixes that have identical behavior for every possible continuation.
For the language of strings ending in 01, useful classes can be represented as follows:
| Representative | Meaning of the remembered suffix |
|---|---|
| \(\epsilon\) | No useful partial match for `01` |
| `0` | The current string ends in `0` |
| `01` | The current string ends in `01` |
Each class corresponds to one state in the minimal DFA.
Why the theorem works
If a DFA recognizes \(L\), two prefixes that reach the same state must be equivalent. From that state, every continuation follows the same transitions and therefore has the same acceptance result. Since the DFA has finitely many states, only finitely many equivalence classes are possible.
Conversely, if there are finitely many classes, construct a DFA whose states are those classes. The start state is \([\epsilon]\). On input symbol \(a\), move from \([x]\) to \([xa]\). Mark \([x]\) accepting exactly when \(x \in L\). The equivalence relation guarantees that these definitions do not depend on which representative is chosen.
Applying the theorem
To prove that a language is not regular:
- Assume there are finitely many equivalence classes.
- Choose infinitely many strings.
- Show that every pair is distinguishable.
- Conclude that infinitely many classes are required, which is impossible for a regular language.
A common error is to find different continuations for different pairs without clearly showing that each pair is separated. Another error is to prove only that some strings behave differently. The theorem requires infinitely many pairwise distinguishable strings.
Exercise
For L = {w in {0,1}* : w ends in 1}, are the strings 0 and 00 distinguishable with respect to L?
Show answer
No. For every continuation z, both 0z and 00z end in 1 exactly when z ends in 1. Thus they belong to the same Myhill-Nerode class.