DEV Community

baaz
baaz

Posted on

Pumping Lemma Explained: Proving a Language Isn't Regular

The Pumping Lemma: How to Prove a Language Isn't Regular

If you've spent any time with automata theory, you've probably built a dozen DFAs and NFAs without much trouble. Given a language, you draw states, you connect transitions, you're done. But then you hit a language like {aⁿbⁿ | n ≥ 0} — equal numbers of a's followed by equal numbers of b's — and no matter how you draw it, you can't make a finite-state machine that accepts it and rejects everything else.

That's not a failure of your drawing skills. It's because the language genuinely isn't regular — and the Pumping Lemma is the tool that lets you prove it, instead of just failing to find a machine and hoping that means something.

The Core Idea, Before the Formalism

A finite automaton has a fixed number of states — say, n of them. If you feed it a string longer than n symbols, something has to give: by the time the machine has read n symbols, it must have visited some state twice (there are only n states, so n transitions can't all land on new ones). That repeated state means the machine has looped.

And if it looped once, it can loop any number of times — zero times, twice, a hundred times — and still end up in the same place, because a loop is a loop. So if a long-enough string is accepted, then so is that string with the looped segment repeated any number of times, or removed entirely.

That's the entire lemma. Everything else is just writing it precisely enough to use in a proof.

The Formal Statement

For any regular language L, there exists a pumping length p such that every string s in L with length at least p can be split into three parts, s = xyz, satisfying:

  1. |y| > 0 — the middle piece isn't empty (there's actually something to repeat)
  2. |xy| ≤ p — the split happens within the first p characters (the repeat has to occur early, where the state-repetition argument applies)
  3. For every i ≥ 0, xyⁱz is also in L — you can repeat y any number of times (including zero) and the result still belongs to the language

Note what this is: a property every regular language must have. It doesn't tell you how to build an automaton, and it doesn't prove a language is regular. It's a one-way test — a necessary condition, not a sufficient one.

Using It: Proof by Contradiction

Because it's a necessary condition, the Pumping Lemma is almost always used in reverse: assume the language is regular, show that leads to a contradiction, and conclude it isn't.

Claim: L = {aⁿbⁿ | n ≥ 0} is not regular.

Proof:
Assume, for contradiction, that L is regular. Then a pumping length p exists.

Choose the string s = aᵖbᵖ. This is in L, and its length is 2p ≥ p, so the lemma applies — s must split into xyz satisfying all three conditions.

Since |xy| ≤ p, and the first p characters of s are all a's, both x and y consist entirely of a's. Since |y| > 0, y is a nonempty string of a's — say, y = aᵏ for some k ≥ 1.

Now pump y: consider xy²z. This adds k extra a's without touching the b's, giving a string with p + k a's and only p b's. That string has unequal numbers of a's and b's — so it's not in L.

But the lemma guarantees xy²z must be in L, since i = 2 is a valid choice. Contradiction.

Therefore, L is not regular. ∎

Where Students Usually Go Wrong

Picking the wrong string. The lemma lets you pick s, as long as it's in L and long enough. Pick something that forces the split to land in a "rigid" part of the string — like the block of a's before any b's appear — so that pumping is guaranteed to break something.

Forgetting condition 2. Students often try to pump the middle of the string and forget that the split xy must fall within the first p characters. This is exactly what pins y down to being made of only one kind of symbol in languages like aⁿbⁿ.

Trying to prove a language IS regular using the lemma. It can't do that — satisfying the pumping property doesn't guarantee regularity (some non-regular languages happen to satisfy it too). It only rules languages out.

Why It's Worth Actually Understanding

Beyond exams, this is one of the first real "limits of computation" results you encounter — a formal, provable boundary on what a certain class of machines can do. The same style of argument (find a bound, force a repetition, derive a contradiction) reappears throughout theoretical CS, including in the Pumping Lemma for context-free languages and, in spirit, in results like the Halting Problem. Once this clicks, a lot of automata theory stops feeling like memorized rules and starts feeling like one coherent idea applied over and over.

Top comments (0)