4.6.7Theory of Computation

Pumping lemma for regular languages — proof and using to show non-regularity

2,520 words11 min readdifficulty · medium5 backlinks

WHY this lemma exists

A DFA has a fixed, finite set of states. Memory = current state only. So a DFA cannot count without bound — it cannot remember "I have seen exactly nn a's" for arbitrarily large nn, because that would need infinitely many states. The pumping lemma is the formal weapon that turns "can't count" into a contradiction proof.


The Pumping Lemma (statement)

The lemma is a necessary condition, not sufficient. Passing it does NOT prove regular; failing it proves non-regular.


Deriving it from first principles (the proof)

Setup. LL regular ⇒ there is a DFA M=(Q,Σ,δ,q0,F)M=(Q,\Sigma,\delta,q_0,F) accepting LL. Let p=Q(number of states).p = |Q| \quad(\text{number of states}).

Take any wLw \in L with w=np|w| = n \ge p. Write w=a1a2anw = a_1 a_2 \dots a_n.

Trace the run. Define the sequence of states visited: r0=q0,rk=δ(rk1,ak)  (k=1,,n).r_0 = q_0,\qquad r_k = \delta(r_{k-1}, a_k)\ \ (k=1,\dots,n). Since wLw\in L, rnFr_n \in F.

Pigeonhole. Look at the first p+1p+1 states r0,r1,,rpr_0, r_1, \dots, r_p. That's p+1p+1 states but only pp distinct states exist. So two of them are equal: there exist indices 0j<kpwithrj=rk.0 \le j < k \le p \quad\text{with}\quad r_j = r_k.

Split the string around the repeated state: x=a1aj,y=aj+1ak,z=ak+1an.x = a_1\dots a_j,\qquad y = a_{j+1}\dots a_k,\qquad z = a_{k+1}\dots a_n.

Check the three conditions:

  • y=kj1|y| = k - j \ge 1 because j<kj < k. ✓ (condition 1)
  • xy=kp|xy| = k \le p because kpk \le p. ✓ (condition 2)

Why pumping works (condition 3). Reading xx takes q0rjq_0 \to r_j. Reading yy takes rjrk=rjr_j \to r_k = r_j — a self-loop on state rjr_j. So reading yy again leaves us back at rjr_j: q0xrjyrjyrjyrjzrnF.q_0 \xrightarrow{x} r_j \xrightarrow{y} r_j \xrightarrow{y} r_j \dots \xrightarrow{y} r_j \xrightarrow{z} r_n \in F. Thus for every i0i\ge 0, reading xyizxy^iz ends in rnFr_n\in F, so xyizLxy^iz \in L. \blacksquare

Figure — Pumping lemma for regular languages — proof and using to show non-regularity

HOW to USE it (the proof-by-contradiction recipe)

It is an adversary game. The lemma gives you pp (you don't choose it); you must beat every possible pp and every split.

Memory aid for who-chooses-what: ∃p, ∀w, ∃split, ∀i — but for the proof of non-regularity we flip it: we pick ww, the adversary picks the split, we pick ii.


Worked Examples


Common Mistakes (Steel-manned)


Active Recall

Recall What three conditions must the split

w=xyzw=xyz satisfy? y1|y|\ge1; xyp|xy|\le p; and xyizLxy^iz\in L for all i0i\ge0.

Recall Which combinatorial principle drives the proof, and what plays the role of "pigeons" and "holes"?

Pigeonhole. Pigeons = the p+1p+1 states r0rpr_0\dots r_p visited; holes = the pp states of the DFA. Two pigeons share a hole ⇒ a repeated state ⇒ a loop yy.

Recall Why must your chosen

ww depend on pp? Because pp is given by the adversary and unknown; ww must satisfy wp|w|\ge p for any pp.

Recall Does passing the pumping lemma prove a language is regular?

No. It is necessary, not sufficient. Use Myhill–Nerode or build a DFA to prove regularity.

Recall For

anbna^nb^n, why does xyp|xy|\le p matter? It forces yy to lie entirely in the a-block, so pumping changes the number of a's only, breaking i=ji=j.

Recall Explain it to a 12-year-old.

Imagine a toy train with only a few colored stations and a very long track of letters. If the track is longer than the number of stations, the train must visit some station twice. Whatever loop of track it drove between those two same-color stations, it could drive that loop again and again (or skip it) and still finish at the same place. So if a language is "made by such a train," repeating that middle loop must always still be allowed. If you find a word where repeating the loop gives something not in the language, then no such train (machine) exists — the language is too clever for finite memory.


Flashcards

State the pumping lemma for regular languages.
If LL regular, p1\exists p\ge1 s.t. every wL, wpw\in L,\ |w|\ge p splits w=xyzw=xyz with y1|y|\ge1, xyp|xy|\le p, and xyizLxy^iz\in L for all i0i\ge0.
What is the pumping length pp in the proof?
The number of states of a DFA accepting LL (p=Qp=|Q|).
Which principle proves the lemma?
Pigeonhole: p+1p+1 visited states but only pp states ⇒ a state repeats ⇒ a loop.
What does condition xyp|xy|\le p buy you in proofs?
It localizes yy to the first pp symbols, letting you force yy into a specific block.
Which string proves anbna^nb^n non-regular?
w=apbpw=a^pb^p, then pump i=2i=2 to get unequal a's and b's.
Which string proves {an2}\{a^{n^2}\} non-regular and why?
w=ap2w=a^{p^2}; pumping by mpm\le p lands strictly between consecutive squares since the gap is 2p+1>p2p+1>p.
Pump up vs pump down — which ii values?
Up: i2i\ge2; down: i=0i=0 (i.e. xzxz). Both allowed by condition 3.
Does passing the pumping lemma imply regularity?
No — it's necessary, not sufficient.
Who chooses the split x,y,zx,y,z — you or the adversary?
The adversary (lemma says "there exists"); you must beat all legal splits.
Better tool to prove regularity (not just non)?
Build a DFA/NFA/regex, or use the Myhill–Nerode theorem.

Connections

  • Finite Automata (DFA NFA) — the source of the finite-state / pigeonhole argument.
  • Myhill–Nerode Theorem — exact characterization of regularity; proves regularity and non-regularity.
  • Pigeonhole Principle — combinatorial engine of the proof.
  • Regular Expressions — equivalent definition of regular languages.
  • Pumping Lemma for Context-Free Languages — the uvxyzuvxyz analogue with two loops.
  • Closure Properties of Regular Languages — sometimes easier than pumping (intersect with a regular set first).

Concept Map

recognized by

finite states cause

long string forces

two states equal

self-loop lets us

proves

is only

weaponized by

failing gives

shows

passing does not prove

DFA finite states p

Regular language L

Pigeonhole principle

Repeated state = loop y

Split w = xyz

Pumping Lemma

Necessary not sufficient

Contradiction proof

Language not regular

Cannot count unboundedly

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, pumping lemma ka core idea bahut simple hai. Har regular language ke peeche ek DFA hota hai jiske paas sirf finite number of states hote hain — maan lo pp states. Ab agar koi string isse lambi hai (wp|w| \ge p), to machine ko string padhte waqt koi ek state do baar visit karni hi padegi — yeh pigeonhole principle hai (zyada pigeons, kam holes). Jo portion us repeated state ke beech padha gaya, woh ek loop ban jaata hai, jise hum yy kehte hain. Loop ka matlab — usko 0 baar, 1 baar, 2 baar, jitni baar chaaho chala sakte ho aur machine same accepting state pe khatam hogi. Isiliye xyizxy^iz bhi language mein hona chahiye, har i0i \ge 0 ke liye.

Yeh lemma hum non-regularity prove karne ke liye use karte hain, ulta tareeke se. Maan lo language regular hai, to pp exist karega. Phir tum ek clever string ww choose karte ho jo pp pe depend kare, jaise apbpa^pb^p. Ab adversary (lemma) split xyzxyz deta hai, par condition xyp|xy|\le p ke wajah se yy sirf shuru ke a's mein phasta hai. Phir tum i=2i=2 ya i=0i=0 choose karke count tod dete ho — a's badh jaate hain par b's same, to anbna^{n}b^{n} wali equality break ho jaati hai. Contradiction! Matlab language regular thi hi nahi.

Do important traps yaad rakhna. Pehla: split tum nahi chunte, adversary chunta hai — isliye saare possible splits handle karne padte hain (par xyp|xy|\le p tumhari madad karta hai). Doosra: agar koi language pumping lemma pass kar leti hai, iska matlab regular nahi hota — yeh sirf one-way tool hai. Regular prove karna ho to DFA banao ya Myhill–Nerode use karo. Mnemonic "PUMP" yaad rakho: Pigeonhole, Unknown pp, Middle yy non-empty, Pick ii.

Go deeper — visual, from zero

Test yourself — Theory of Computation

Connections