Theory of Computation: Lecture 3
Non-regular languages, the pigeonhole argument, the pumping lemma as an adversary game, closure-based reductions, and a regular surprise.
The Edge of Finite Memory
Every NFA has an equivalent DFA, so DFAs, NFAs, and all the closure constructions draw one and the same boundary: the regular languages. What sits comfortably inside that boundary:
- Pattern matching. Fixed substrings, such as strings containing
1011011: one waiting state per matched prefix. - Modular counting. Parity, divisibility, anything counted "modulo some number", such as strings whose number of
1symbols is divisible by 5. - Bounded position information. Fixed prefixes, suffixes, or positions, such as strings whose second-to-last bit is
1. - Pattern shapes. Languages like , and anything assembled from regular pieces by complement, union, intersection, and concatenation.
The common thread is that finitely many states suffice to summarize everything relevant about the prefix read so far. The limit appears when a language needs exact unbounded memory: a finite automaton can count modulo a fixed number, but it cannot remember an arbitrary number exactly.
Non-regular language. A language that no DFA, and equivalently no NFA, recognizes.
Proving non-regularity is a statement about every machine at once. It is not enough that the language feels hard or that one design fails; the proof must show that every possible finite automaton is wrong somewhere. Three test languages calibrate where the boundary runs: , the strings ; , the strings with as many 0s as 1s; and , the strings with as many occurrences of 01 as of 10 as substrings. Which of the three are regular? The intuition "anything that counts is non-regular" misleads for exactly one of them.
The First Non-Regular Language
Start with
The number of 1 symbols must match exactly the number of earlier 0 symbols, and the number to remember is unbounded. That intuition becomes a proof through the pigeonhole principle: a DFA with states cannot keep different prefixes apart.
Theorem. is not regular.
1. Assumption. Suppose, for contradiction, that a DFA with states recognizes .
2. Repeated state. Feed the prefixes . They land in at most states, so by the pigeonhole principle there are such that and end in the same state.
3. Same suffix. A DFA is deterministic, so from one state the same suffix always produces the same verdict. Append to both prefixes: since the machine accepts it, and therefore it must also accept .
4. Contradiction. Because , the string has more 0s than 1s, so it is not in . Thus accepts a string outside , contradicting .
Once two different prefixes share a state, the machine has forgotten their difference forever, and no suffix can restore the lost information.
The argument never used anything specific to except at the very end. Long accepted strings force a repeated state, and the input read between the two visits can be repeated or removed freely. Packaging that observation once and for all gives the central tool of the lecture.
The Pumping Lemma
Pumping lemma for regular languages. If is regular, then there exists a number , the pumping length, such that every string with can be written as with:
- for every ,
- ,
- .
| Part | Meaning |
|---|---|
| input read before entering the repeated state | |
| nonempty input read while going around the loop | |
| remaining suffix after the loop | |
| the string obtained by taking the loop times |
With the loop is removed and the string becomes ; with the loop is taken twice and the string becomes . A pumping length is not unique: if works, any larger number works. And if is finite, the lemma holds vacuously, because choosing longer than every string in leaves no string with .
Proof. Choose a DFA with and let . Take any with . Reading the first symbols visits state positions, the start state plus one per symbol, so some state repeats; say its first two visits happen at times . Split into , the first symbols, , the symbols from through , and , the rest. Then is nonempty and , and the accepting run has the shape
Reading returns the machine to , so the loop can be taken any number of times without changing where the run ends:
so for every .
The pumping lemma is the pigeonhole principle applied to a DFA run, stated once so that each non-regularity proof does not have to reopen the machine.
Proving Non-Regularity
The lemma gives a necessary condition for regularity, so it is used by contradiction: exhibit a string that cannot be pumped. The proof is best played as a game against an adversary who defends the (impossible) DFA.
Recipe: non-regularity via the pumping lemma.
- Assume is regular. The adversary announces a pumping length . You do not know ; treat it as a parameter.
- Choose a witness. Pick one string with , phrased in terms of . This is the creative step.
- Face every split. The adversary picks the decomposition with and . Your argument must work for every such split. Use to pin down what can look like; with the right witness, the constraint forces into one uniform block.
- Pump. Choose one , often or , and show .
- Conclude. The lemma is violated, so is not regular. If instead some split survives every , the witness was too weak; return to step 2 with a stronger string.
You choose the string and the pump count; the adversary chooses the length and the split. A proof is a winning strategy against every split, not one lucky play.
Example 1. The copy language.
Let : strings made by writing the same string twice. In : , 00, 0101, 001001. Not in : 01, 001, 0110.
Assume is regular with pumping length , and pick the witness
Every split with puts and inside the first block of zeros, so with . Pump up once:
If is odd, the length is odd and the string cannot be . If is even, the midpoint moves into the first block of 1s, so the first half starts with 0 and the second half starts with 1, and the halves differ. Either way , contradiction: is not regular.
The witness did the work. Choosing forces every legal into the first zero block, so pumping damages only the first copy.
Example 2. More zeros than ones.
Let .
Assume is regular with pumping length , and pick . Every legal split has with . Pumping up only adds zeros and stays in ; the contradiction comes from pumping down with :
Since , the string has at most zeros against ones, so . Contradiction: is not regular. The useful pump count is not always up.
Example 3. Equal zeros and ones.
Let .
A first witness attempt fails instructively. The string is in and long enough, but the adversary answers with the split , : then stays in for every , and that single surviving split destroys the whole attempt. A witness must lose to no split.
Pick instead . Now every legal split has with , and pumping up gives
Contradiction: is not regular.
Non-Regularity by Closure
Knowing one non-regular language unlocks others without touching the pumping lemma again: reduce the new language to a known one through closure operations.
Containment alone proves nothing. and non-regular does not make non-regular, just as does not make non-regular. The operation must transform the whole language, and intersection with a regular filter is the workhorse.
Recipe: non-regularity by closure reduction.
- Assume is regular.
- Combine with known regular languages using operations under which regular languages are closed: intersection with a regular filter, complement, union.
- Identify the result as a language already known to be non-regular.
- Conclude. Closure would force that language to be regular, a contradiction, so is not regular.
For , filter with , which is regular: a three-state DFA checks that no 0 follows a 1. If were regular then would be regular, because regular languages are closed under intersection. But
and is not regular. Contradiction: is not regular, now proved a second way.
A closure reduction says: if this language were regular, a known non-regular language would become regular after a harmless operation. The filter strips away everything except the hard core.
A Regular Surprise
The third test language counts, yet it is regular:
An occurrence here is an adjacent pair of symbols, so the counts track changes from 0 to 1 and from 1 to 0, not symbol totals.
Boundary-change characterization. A binary string has equally many 01 and 10 substrings if and only if it is empty or its first and last symbols are equal.
Scanning left to right, the changes alternate: after a 0 to 1 change, the next change can only be 1 to 0, and conversely. The counts therefore differ by at most one, and they are equal exactly when the string ends on the same symbol value it started with. A string starting with 0 and ending with 1 has one extra 01; starting with 1 and ending with 0, one extra 10.
A DFA for needs to remember only the first symbol and the most recent symbol:
| State | Meaning |
|---|---|
| no symbol has been read | |
first symbol 0, last symbol 0 | |
first symbol 0, last symbol 1 | |
first symbol 1, last symbol 1 | |
first symbol 1, last symbol 0 |
The accepting states , , are exactly the cases where the string is empty or its first and last symbols agree.
Accepted: , 0, 1, 00, 11, 010, 101. Rejected: 01, 10, 001, 110.
looks like it compares two unbounded counts, but the difference between the counts is fully determined by the first and last symbols, and that is two bits of memory. Regularity is about how much information must be carried, not about how the language is phrased; whenever a counting language is regular, some bounded quantity secretly carries the count. Past this boundary lies computation with unbounded memory, Turing machines, where both the powers and the limits change shape.