Sub topic 11
The Pumping Lemma and Non-Regular Languages
Prerequisites and purpose
Assume you know strings, languages, regular expressions, and deterministic finite automata (DFAs). You should also be comfortable with contradiction proofs and basic counting.
The pumping lemma gives a necessary property of every regular language. It is mainly used to prove that a language is not regular. A language is regular if some finite automaton recognizes it.
The pumping lemma
If a language \(L\) is regular, then there is a number \(p\), called the pumping length, such that every string \(w\) in \(L\) with length at least \(p\) can be divided as
\[ w = xyz \]
with these conditions:
| Condition | Meaning | Column | Column |
|---|---|---|---|
| \( | xy | \le p\) | The prefix \(xy\) lies within the first \(p\) symbols |
| \( | y | \ge 1\) | The middle part \(y\) is not empty |
| \(xy^iz \in L\) for every \(i \ge 0\) | The part \(y\) can be repeated or removed |
The lemma comes from a DFA having finitely many states. A sufficiently long input must visit some state twice. The symbols read between those visits form a loop. That loop can be traversed zero, one, or many times.
Worked proof: equal numbers of zeros and ones
Consider
\[ L = \{0^n1^n \mid n \ge 0\}. \]
This language contains strings such as 01, 0011, and 000111. It requires the number of zeros to equal the number of ones.
Suppose, for contradiction, that \(L\) is regular. Let \(p\) be its pumping length. Choose the string
\[ w = 0^p1^p. \]
This string belongs to \(L\), and its length is at least \(p\). The lemma says that \(w=xyz\), where \(|xy|\le p\) and \(|y|\ge1\).
Because the first \(p\) symbols of \(w\) are all zeros, \(y\) contains only zeros. Write \(y=0^k\), where \(k\ge1\).
Pump \(y\) out by choosing \(i=0\). The resulting string is
\[ xz = 0^{p-k}1^p. \]
It has fewer zeros than ones, so it is not in \(L\). This contradicts the pumping lemma. Therefore, \(L\) is not regular.
Common errors
- Choosing a string that does not belong to the language.
- Forgetting that the proof must handle every valid division into \(x\), \(y\), and \(z\).
- Choosing \(y\) freely instead of using \(|xy|\le p\) to restrict its location.
- Showing that one pumping choice remains in the language. To find a contradiction, it is enough to find one value of \(i\) that leaves the language.
- Using the lemma to prove that a language is regular. The lemma gives a necessary condition, not a sufficient one.
Exercise
Use the pumping lemma to show that L = {0^n1^n | n >= 0} is not regular. Which pumped string gives the contradiction?
Show answer
Choose w = 0^p1^p. The condition |xy| <= p forces y to contain only zeros. Pumping with i = 0 produces 0^(p-k)1^p, which has unequal numbers of zeros and ones and is therefore outside L.