Introduction

The pumping lemma for regular languages is a necessary condition that every regular language satisfies. Its main use is negative: if you can show that a language breaks the condition, the language is not regular. It is not a sufficient test; some non-regular languages still satisfy the numeric conclusion for tricky reasons, so failing to pump does not prove regularity.

The skills are the classic non-regular proofs ({anbn}\{a^n b^n\}, {ww}\{ww\}, {an2}\{a^{n^2}\}) and the correct quantifier order in the lemma statement.

Prerequisites

Core concepts

Statement

If LL is regular, then there exists a pumping length p≥1p \ge 1 such that every w∈Lw \in L with ∣w∣≥p|w| \ge p can be written w=xyzw = xyz with:

  1. ∣xy∣≤p|xy| \le p,
  2. ∣y∣≥1|y| \ge 1,
  3. xykz∈Lx y^k z \in L for every integer k≥0k \ge 0.

Intuition. In a DFA with p=∣Q∣p = |Q| states, a path of length ≥p\ge p repeats a state inside the first p+1p+1 states visited; the loop is yy.

Quantifiers (memorize the order)

  • ∃p\exists p (depends on LL only),
  • ∀w∈L\forall w \in L with ∣w∣≥p|w| \ge p,
  • ∃\exists split xyzxyz obeying (1)-(2),
  • ∀k≥0\forall k \ge 0, xykz∈Lxy^k z \in L.

To show non-regularity, negate: ∀p\forall p, ∃w∈L\exists w \in L with ∣w∣≥p|w|\ge p, ∀\forall splits xyzxyz with (1)-(2), ∃k\exists k with xykz∉Lxy^k z \notin L.

What the lemma does not do

  • It does not prove regularity.
  • A language may be non-regular yet hard to pump; use Myhill-Nerode or closure arguments instead.
  • Mis-pumping outside the first pp symbols is a common wrong proof.
Pumping decomposition xyz on a DFA path with a repeated state
Figure 1. DFA path on a long accepted string w; a repeated state among the first p+1 states cuts w into x (to first visit), y (loop, nonempty), and z (rest), so xy^k z stays accepted for all k.

How it works

Template proof that LL is not regular

  1. Assume LL is regular; let pp be the pumping length.
  2. Choose a specific w∈Lw \in L with ∣w∣≥p|w| \ge p (clever choice).
  3. Consider an arbitrary split w=xyzw=xyz with ∣xy∣≤p|xy|\le p and ∣y∣≥1|y|\ge 1.
  4. Show some pumped string xykzxy^k z (often k=0k=0 or k=2k=2) leaves LL.
  5. Contradiction; LL is not regular.

Choosing ww

For {anbn∣n≥0}\{a^n b^n \mid n \ge 0\}, take w=apbpw = a^p b^p. Then yy lies inside the leading aa's (because ∣xy∣≤p|xy|\le p), so pumping changes the number of aa's only.

Algorithms and pseudocode

There is no "algorithm" inside the lemma; DFA cycle detection explains why it holds:

Input strings use 1-based positions; run-state visits use indices 0 through |w|.

Text
WHY-PUMPING(M, w)  // |w| >= |Q|, w accepted
1  run M on w, record states s0,s1,...,s_|w|
2  among s0..s_p find i < j with si = sj   // p=|Q|
3  x <- w[1..i]; y <- w[i+1..j]; z <- w[j+1..|w|]
4  return (x,y,z)  // pumping the loop y

Mathematical explanation

Proof of the lemma

Let MM be a DFA for LL with p=∣Q∣p = |Q|. Take w∈Lw \in L, ∣w∣≥p|w|\ge p. The run visits p+1p+1 states in the first pp symbols plus the start, so by pigeonhole two visits si=sjs_i = s_j occur with 0≤i<j≤p0 \le i < j \le p. Set yy to the substring between them. The loop can be taken kk times, staying accepting because the original run ended accepting and the loop returns to the same state.

Myhill-Nerode alternative

For {anbn}\{a^n b^n\}, the prefixes aia^i are pairwise distinguishable by the continuations bib^i. Infinitely many classes ⇒\Rightarrow not regular.

Worked examples

Example 1: {anbn∣n≥0}\{a^n b^n \mid n \ge 0\}

Assume regular, pumping length pp. Let w=apbpw = a^p b^p. For any xyzxyz with ∣xy∣≤p|xy|\le p, y=aty = a^t for some t≥1t \ge 1. Then xy2z=ap+tbp∉Lxy^2 z = a^{p+t} b^p \notin L. Done.

Example 2: {ww∣w∈{0,1}∗}\{ ww \mid w \in \{0,1\}^* \}

Take w=0p10p1∈Lw = 0^p 1 0^p 1 \in L. Because ∣xy∣≤p|xy| \le p, the piece y=0ty = 0^t (t≥1t \ge 1) lies in the first block of 0s. Then xy2z=0p+t10p1xy^2z = 0^{p+t} 1 0^p 1: its two halves cannot be equal, since the only way to split it into equal halves of a string with exactly two 1s puts one 1 at the end of each half, which forces equal 0-blocks. So xy2z∉Lxy^2z \notin L. The choice of ww matters: w=0p0pw = 0^p 0^p is in LL but pumps happily (pumping by an even tt stays in LL, and for p≥2p\ge2 the adversary may pick t=2t=2; an assumed pumping length can always be enlarged to at least 2), so it proves nothing.

Example 3: {an2∣n≥0}\{ a^{n^2} \mid n \ge 0 \}

Take w=ap2w = a^{p^2}. Pumping adds ∣y∣|y| letters with 1≤∣y∣≤p1 \le |y| \le p, producing a length strictly between consecutive squares p2p^2 and (p+1)2=p2+2p+1(p+1)^2 = p^2 + 2p + 1, hence not a square.

Example 4: a regular language that pumps

L=a∗L = a^* is regular. For p=1p=1, any w=anw=a^n (n≥1n\ge 1) splits as x=εx=\varepsilon, y=ay=a, z=an−1z=a^{n-1}; pumping stays in a∗a^*. Satisfying the lemma does not by itself prove regularity (but here we already know it is regular via a 1-state DFA).

Example 5: choosing k=0k = 0

L={0n1m∣n>m}L = \{0^n 1^m \mid n > m\}. Take w=0p+11pw = 0^{p+1} 1^p. Every legal yy is 0t0^t with 1≤t≤p1 \le t \le p. Pumping up keeps n>mn > m, so it fails to leave LL; pumping down (k=0k = 0) gives 0p+1−t1p0^{p+1-t} 1^p with p+1−t≤pp + 1 - t \le p, so n≤mn \le m and the string is outside LL. Stopping after k=2k = 2 would wrongly suggest that the language pumps.

Example 6: primes

L={aq∣q prime}L = \{a^q \mid q \text{ prime}\}. Take a prime q≥p+2q \ge p + 2 and w=aqw = a^q, with ∣y∣=t|y| = t, 1≤t≤p1 \le t \le p. Pump with k=q−tk = q - t: the length is q−t+(q−t)t=(q−t)(1+t)q - t + (q - t)t = (q - t)(1 + t). Both factors are at least 2 (q−t≥2q - t \ge 2 because q≥p+2q \ge p + 2), so the length is composite and xykz∉Lxy^k z \notin L.

Example 7: languages that look non-regular but are regular

LanguageRegular?Reason
{anan∣n≥0}\{a^n a^n \mid n \ge 0\}yesit is (aa)∗(aa)^*
{anbn∣0≤n≤100}\{a^n b^n \mid 0 \le n \le 100\}yesfinite
{anbm∣n,m≥0}\{a^n b^m \mid n, m \ge 0\}yesa∗b∗a^* b^*; the exponents are independent
{w∈{a,b}∗∣#ab(w)=#ba(w)}\{w \in \{a,b\}^* \mid \#_{ab}(w) = \#_{ba}(w)\}yesthe counts of the factors ab and ba differ by at most 1, and they are equal iff ww is empty or starts and ends with the same symbol
{anbm∣n≡m(mod3)}\{a^n b^m \mid n \equiv m \pmod 3\}yes3 residues of n−mn - m
{wwR∣w∈{a}∗}\{w w^R \mid w \in \{a\}^*\}yesagain (aa)∗(aa)^*
{wwR∣w∈{a,b}∗}\{w w^R \mid w \in \{a,b\}^*\}noapbbapa^p b b a^p pumps to ap+tbbapa^{p+t} b b a^p
{anbm∣n≠m}\{a^n b^m \mid n \ne m\}noclosure: complement within a∗b∗a^* b^* is anbna^n b^n

IMPERATIVE RULE. Before pumping, ask whether the "counting" is really unbounded and coupled. Precisely bounded counts and fixed modular conditions often yield finite-state constructions. A unary alphabet alone is no guarantee: a unary language is regular exactly when its set of lengths is ultimately periodic.

Example 8: minimum pumping length

The minimum pumping length of a regular LL is the smallest pp for which the lemma's conclusion holds. For L=0001∗L = 0001^* it is 4: the string 000 (length 3) cannot be pumped, because removing or repeating any nonempty piece of it leaves LL; with p=4p = 4, every w=0001jw = 0001^j (j≥1j \ge 1) pumps with yy = the first 1. For L=(01)∗L = (01)^* it is 2: with p=1p = 1 the string 01 would need y=0y = 0, and 1 ∉L\notin L; with p=2p = 2, take y=01y = 01. For a finite language, any pp larger than its longest string works vacuously, so a finite language never needs to pump.

Example 9: a non-regular language that satisfies the lemma

L={aibjck∣i=0 or j=k}L = \{a^i b^j c^k \mid i = 0 \text{ or } j = k\}. With p=1p = 1, every nonempty w∈Lw \in L pumps with yy = its first symbol: if i≥1i \ge 1, changing the number of aas keeps j=kj = k or produces i=0i = 0, both in LL; if i=0i = 0, the string is bjckb^j c^k and changing its first block keeps i=0i = 0. Yet LL is not regular: L∩ab∗c∗={abncn}L \cap a b^* c^* = \{a b^n c^n\}, and the left quotient by aa gives {bncn}\{b^n c^n\}, which is not regular. So passing the lemma proves nothing.

Example 10: misuse

Wrong: "take w=apbpw=a^p b^p and set y=ap/2bp/2y=a^{p/2} b^{p/2}". That split may violate ∣xy∣≤p|xy|\le p or place yy across the boundary; the adversary chooses the split, so your proof must handle every legal split.

Important properties and observations

  • Pumping length can be taken as the number of DFA states.
  • k=0k=0 deletes yy (useful often); k=2k=2 duplicates yy.
  • Closure arguments often beat pumping: {w∣#a(w)=#b(w)}∩a∗b∗={anbn}\{w \mid \#_a(w) = \#_b(w)\} \cap a^* b^* = \{a^n b^n\} proves non-regularity in one line (see Closure and Decision Properties of Regular Languages).
  • The lemma gives a necessary condition only. A language that satisfies it may still be non-regular (Example 9).

Common misconceptions.

  • Using pumping to "prove" regularity.
  • Picking one convenient split instead of arguing against all splits.
  • Forgetting ∣y∣≥1|y| \ge 1, which would make pumping trivial.

GATE examination perspective

  • WRITE QUANTIFIERS. Questions can test the quantifier order ∀p ∃w ∀xyz ∃k\forall p\, \exists w\, \forall xyz\, \exists k: know which choices are yours and which are the adversary's.
  • FORCE yy INTO ONE BLOCK. Choose ww so that the first pp symbols are a single letter run.
  • PREFER MYHILL-NERODE. When prefixes are obviously distinguishable.
  • DO NOT PUMP NON-REGULAR CANDIDATES BLINDLY. Without checking the split constraints.
  • TRY BOTH DIRECTIONS. If pumping up stays in LL, try k=0k = 0 (Example 5).
  • "WHICH OF THESE IS REGULAR". Check for bounded counts, moduli and hidden independence (Example 7) before declaring a language non-regular.
  • THE LEMMA IS ONE-WAY. "LL satisfies the pumping lemma, hence regular" is always a wrong option.
  • MINIMUM PUMPING LENGTH. The least positive integer pp such that every w∈Lw\in L with ∣w∣≥p|w|\ge p has a split w=xyzw=xyz satisfying ∣xy∣≤p|xy|\le p, ∣y∣≥1|y|\ge1, and xyiz∈Lxy^i z\in L for every integer i≥0i\ge0. Prefix legality depends on the same candidate pp; the length of the longest unpumpable word alone is not a general rule.

Summary

Sources

  1. J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley: Section 4.1 (proving languages not to be regular: the pumping lemma and its applications).
  2. M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 1.4 (nonregular languages; the pumping lemma for regular languages).
  3. P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning: Section 4.3 (identifying nonregular languages: using the pigeonhole principle, a pumping lemma).

Next steps