Mathematics.

formal languages

The Pumping Lemma

Theory of Computation40 minDifficulty6 out of 10

You should know: finite automata

Overview

The pumping lemma for regular languages is the standard tool for PROVING a language is NOT regular — that is, that no finite automaton can recognize it. It formalizes an unavoidable consequence of having only finitely many states: any sufficiently long accepted string must revisit some state, and the loop between the two visits can be repeated ('pumped') any number of times while the machine still accepts. If a language has strings that cannot survive this repetition, no finite automaton — however large — can recognize it.

Intuition

Picture a finite automaton with only k states processing a string longer than k symbols. By the pigeonhole principle, the machine must pass through the same state twice before finishing — say at positions i and j, with i < j. The path between those two visits forms a loop the machine could traverse zero times, once, or any number of times, always landing back in the same state and hence reaching the same fate (accept or reject) on the rest of the string. So if the original string was accepted, so is the string with that loop repeated any number of times, or removed entirely. Languages where this can't possibly hold true — like matching counts that would be destroyed by repeating a chunk — cannot be regular.

Formal Definition

Definition

If A is a regular language, there exists a pumping length p such that every string s in A with |s| ≥ p can be split into three pieces s = xyz satisfying:

i0, xyizA\forall i \ge 0,\ xy^i z \in A
Condition 1 — pumping y any number of times stays in A
y>0|y| > 0
Condition 2 — the pumped piece is nonempty
xyp|xy| \le p
Condition 3 — the split happens within the first p symbols

Notation

NotationMeaning
ppThe pumping length (at least the number of states in a DFA for A)
x,y,zx, y, zThe three pieces of s, with y the 'pumpable' loop segment
xyizxy^i zString s with the loop segment y repeated i times (i = 0 means y is deleted)

Theorems

Theorem 1: Pumping lemma for regular languages
If A is regular, p1 such that every sA with sp can be split s=xyz with y>0, xyp, and xyizA i0.\text{If } A \text{ is regular, } \exists p \ge 1 \text{ such that every } s \in A \text{ with } |s|\ge p \text{ can be split } s=xyz \text{ with } |y|>0,\ |xy|\le p,\ \text{and } xy^iz \in A\ \forall i \ge 0.
Theorem 2: Contrapositive (proof-by-pumping strategy)
If, for every candidate p, some sA with sp has NO valid split satisfying all three conditions, then A is not regular.\text{If, for every candidate } p, \text{ some } s \in A \text{ with } |s|\ge p \text{ has NO valid split satisfying all three conditions, then } A \text{ is not regular.}

Applications

Compiler and language-design theory uses the pumping lemma to prove certain syntax features (like matching an unbounded count of nested constructs) cannot be handled by a purely regex/lexer-based (regular) scanner and require a parser.

Worked Examples

  1. Assume L is regular with pumping length p. Choose the string s = 0ᵖ1ᵖ, which is in L and has length 2p ≥ p.

    s=0p1pLs = 0^p 1^p \in L
  2. By condition 3, |xy| ≤ p, so xy lies entirely within the first p symbols — meaning x and y consist only of 0s.

    x=0a, y=0b, z=0pab1p,b>0x = 0^a,\ y = 0^b,\ z = 0^{p-a-b}1^p, \quad b > 0
  3. Pump with i = 2: this adds b extra 0s but no extra 1s, so the 0-count no longer equals the 1-count.

    xy2z=0p+b1pL since p+bpxy^2z = 0^{p+b}1^p \notin L \text{ since } p+b \ne p
  4. This contradicts condition 1 (that xyⁱz ∈ L for all i), so no valid split exists — L is not regular.

    Contradiction    L is not regular\text{Contradiction} \implies L \text{ is not regular}

Answer: L = {0ⁿ1ⁿ} fails the pumping lemma, so it is not regular (it requires a stack — it's context-free instead).

Practice Problems

Difficulty 6/10

Sketch a pumping-lemma proof that L = {wwᴿ : w ∈ {0,1}*} (even-length palindromes) is not regular. (Hint: pick s = 0ᵖ1 1 0ᵖ.)

Difficulty 5/10

Why must the string chosen for a pumping-lemma proof have length at least p, and why do we get to choose it adversarially?

Difficulty 5/10

The pumping lemma is used almost exclusively to:

Common Mistakes

Common Mistake

Using the pumping lemma to try to prove a language IS regular.

The pumping property is a necessary, not sufficient, condition for regularity — some non-regular languages can still satisfy the pumping conditions by accident. The lemma is a one-way tool: only useful for disproving regularity via contradiction.

Common Mistake

Choosing the string s before knowing the adversary's pumping length p, or choosing a split (x, y, z) yourself.

The correct proof structure is: assume p is given by the adversary, THEN choose s (which may depend on p), and finally show that EVERY possible split the adversary could pick fails — you don't get to choose the split.

Quiz

The pumping lemma for regular languages is primarily used to:
In the proof that {0ⁿ1ⁿ} is not regular, why must y consist only of 0s?
What logical structure does a pumping-lemma proof of non-regularity follow?

Historical Background

The pumping lemma for regular languages emerged from the automata theory developed by Rabin, Scott, and others in the late 1950s, formalizing the pigeonhole-principle argument implicit in finite-state behavior. An analogous but distinct pumping lemma for context-free languages was proved by Yehoshua Bar-Hillel, Micha Perles, and Eli Shamir in 1961, extending the same repetition idea to grammars with a stack.

  1. 1959

    Rabin and Scott's foundational work on finite automata implicitly contains the pigeonhole argument behind pumping

    Michael Rabin, Dana Scott

  2. 1961

    Bar-Hillel, Perles, and Shamir prove the pumping lemma for context-free languages

    Yehoshua Bar-Hillel, Micha Perles, Eli Shamir

Summary

  • Every regular language has a pumping length p beyond which accepted strings contain a repeatable ('pumpable') loop.
  • The lemma gives three conditions on the split s = xyz: xyⁱz ∈ A for all i≥0, |y|>0, |xy|≤p.
  • It is used via contradiction to prove languages like {0ⁿ1ⁿ} are NOT regular.
  • Satisfying the pumping conditions is necessary but not sufficient for regularity — the lemma cannot prove a language regular.

References