# The Pumping Lemma

> Every long enough string in a regular language has a middle part you can repeat and still stay in the language.

**Field:** Software & systems · **Reliability:** Empirical · **Coined:** 1959

*Also known as: The pumping lemma for regular languages; The Bar-Hillel lemma*

## What it means

The pumping lemma is a property that every regular language must satisfy, used chiefly to prove that a given language is not regular. It says that if a language is regular, there is a pumping length such that any string in the language at least that long can be split into three parts, x, y, and z, where the middle part y is non-empty, x and y together fit within the pumping length, and the string with y repeated any number of times, or removed, is still in the language. The middle can be pumped up or down without leaving the language. Because non-regular languages violate this, the lemma is a workhorse for proving non-regularity.

## How it works

The lemma follows from the pigeonhole principle applied to finite automata. A regular language is recognised by a finite automaton with some number of states; reading a string longer than that number forces the machine to visit some state twice, and the loop between those two visits is the pumpable middle y. To prove a language is not regular, one assumes it is, obtains the pumping length, cleverly chooses a string in the language that must therefore be pumpable, and shows that some pumped version falls outside the language, a contradiction. An analogous lemma for context-free languages splits a string into five parts and pumps two of them together.

## Examples

- **Equal a's and b's:** The language of strings with n a's followed by n b's is not regular: pumping the a's in a chosen string adds unmatched a's, breaking the balance and leaving the language, a contradiction.
- **The loop in an automaton:** In a finite automaton with p states, a string of length at least p forces a repeated state, and the segment traversed between the two visits is the pumpable middle.
- **The context-free version:** The context-free pumping lemma splits a string into five parts and pumps two together, used to show, for instance, that strings with equal a's, b's, and c's are not context-free.

## Why it matters

The pumping lemma is a fundamental tool in the theory of formal languages and automata, giving a clean, mechanical way to prove that languages such as balanced brackets or equal-count strings lie beyond the reach of regular expressions and finite automata. It sharpens the boundary between the regular languages and the richer classes above them, and its context-free analogue does the same one level up.

## Where it breaks down

The pumping lemma is a necessary but not sufficient condition for regularity: some non-regular languages also satisfy the pumping property, so passing the lemma does not prove a language is regular, only failing it proves non-regularity. A definitive characterisation, both necessary and sufficient, is given instead by the Myhill-Nerode theorem. In applying the lemma, the prover chooses the witness string but the decomposition into x, y, and z is adversarial, so the argument must succeed against every valid split, which is where careless proofs go wrong.

## Common misreadings

The pumping lemma proves that a language is not regular; it never proves that a language is regular, since satisfying it is not enough. The condition is necessary but not sufficient, so a non-regular language can pass the test, and the Myhill-Nerode theorem is needed for a full characterisation. The prover selects the string, but the split into three parts is chosen adversarially, so the proof must handle every valid decomposition, not just a convenient one.

## Origin

The regular pumping lemma was first proved by Michael Rabin and Dana Scott in 1959 and rediscovered by Yehoshua Bar-Hillel, Micha Perles, and Eli Shamir in 1961, who also gave the context-free version.

## Related

- [The Turing Machine](https://conyso.com/lawtome/laws/the-turing-machine/) — kindred

## Sources

- [Pumping lemma for regular languages, Wikipedia. — the three conditions, the non-regularity proof method, and the necessary-not-sufficient point.](<https://en.wikipedia.org/wiki/Pumping_lemma_for_regular_languages>)
- [Pumping lemma for context-free languages, Wikipedia. — the five-part decomposition and the two-part pumping for context-free languages.](<https://en.wikipedia.org/wiki/Pumping_lemma_for_context-free_languages>)

---
Source: https://conyso.com/lawtome/laws/the-pumping-lemma/ · The Law Tome — a sourced index of named laws.
