Skip to content
Part IA Michaelmas, Lent Term

The Pumping Lemma

Statement

Theorem (Pumping Lemma for Regular Languages):

Let LL be a regular language. There exists p1p \geq 1 (the pumping length) such that for every wLw \in L with wp|w| \geq p:

ww can be written as w=xyzw = xyz where:

  1. xyp|xy| \leq p
  2. y1|y| \geq 1 (so yεy \neq \varepsilon)
  3. xyizLxy^iz \in L for all i0i \geq 0

Intuition

If a string is long enough and the language is regular, then some part of the string can be “pumped” (repeated) any number of times while staying in the language.

The pumped part corresponds to a loop in an accepting computation of the DFA.

Proof Idea

Let M=(Q,Σ,δ,s,F)M = (Q, \Sigma, \delta, s, F) be a DFA for LL with Q=n|Q| = n.

Set p=np = n.

For any wLw \in L with wn|w| \geq n: the computation visits n+1n+1 states in sequence. By the pigeonhole principle, some state is visited twice.

The part of ww that causes the loop can be pumped.

Formal Argument

Path through DFA: s=q0q1qw=qfs = q_0 \to q_1 \to \cdots \to q_{|w|} = q_f.

Since wn+1|w| \geq n+1 states are visited, but there are only nn states, some qi=qjq_i = q_j for i<ji < j.

Let x=w[0..i]x = w[0..i] (before the loop), y=w[i..j]y = w[i..j] (the loop), z=w[j..w]z = w[j..|w|] (after).

  • Condition 1: Loop occurs within first nn states, so xyn=p|xy| \leq n = p
  • Condition 2: i<ji < j, so y1|y| \geq 1
  • Condition 3: Repeating or omitting the loop keeps the computation in the accepting state

Using the Pumping Lemma

To Prove Non-regularity

  1. Assume LL is regular with pumping length pp
  2. Choose a string wLw \in L with wp|w| \geq p
  3. Show that for ALL possible decompositions w=xyzw = xyz satisfying conditions 1 and 2:
    • There exists ii such that xyizLxy^iz \notin L
  4. Conclude: contradiction, so LL is not regular

Key Point

You must show that the pumping lemma fails for every possible choice of x,y,zx, y, z satisfying the conditions.

Application: L={anbn:n0}L = \{a^n b^n : n \geq 0\}

Proof

Assume LL is regular with pumping length pp.

Choose w=apbpw = a^p b^p (in LL, length p\geq p).

For any decomposition w=xyzw = xyz with xyp|xy| \leq p and y1|y| \geq 1:

  • Since xyp|xy| \leq p, the substring xyxy consists of only aa‘s
  • Thus y=aky = a^k for some k1k \geq 1

Consider xy2z=ap+kbpxy^2z = a^{p+k} b^p:

  • Number of aa‘s is p+k>pp+k > p
  • Number of bb‘s is pp
  • Not equal, so xy2zLxy^2z \notin L

Contradiction. Thus LL is not regular.

Application: L={ww:w{a,b}}L = \{ww : w \in \{a, b\}^*\}

Proof

Assume LL is regular with pumping length pp.

Choose w=apbapbw = a^p b a^p b (in LL, length 2p+2p2p+2 \geq p).

For any decomposition w=xyzw = xyz with xyp|xy| \leq p and y1|y| \geq 1:

  • xyp|xy| \leq p means xyxy lies within the first apba^p b (actually, within first apa^p)
  • So y=aky = a^k for some k1k \geq 1

Consider xy2z=ap+kbapbxy^2z = a^{p+k} b a^p b:

  • This is not of the form wwww (different lengths of prefix)
  • Alternatively: after pumping, the string is ap+kbapba^{p+k} b a^p b, not a square

Contradiction.

Application: L={an2:n0}L = \{a^{n^2} : n \geq 0\}

Proof

Choose w=ap2w = a^{p^2}.

The pumped string is ap2+ka^{p^2+k} for some kk with 1kp1 \leq k \leq p.

We need p2+kp^2 + k to be a perfect square.

But (p+1)2=p2+2p+1>p2+k(p+1)^2 = p^2 + 2p + 1 > p^2 + k for kpk \leq p.

So ap2+kLa^{p^2+k} \notin L.

Limitations of the Pumping Lemma

The pumping lemma is a necessary condition for regularity, not sufficient.

Some non-regular languages satisfy the pumping lemma conditions.

For proving non-regularity, use:

  • Pumping lemma
  • Myhill-Nerode theorem
  • Closure properties

Summary

  • Pumping lemma: long strings in regular languages have pumpable parts
  • Proof uses pigeonhole principle on DFA states
  • Use: assume regular, find a counterexample string, show pumping fails
  • Applications: anbna^n b^n, wwww, {an2}\{a^{n^2}\} are not regular
  • Not a characterisation: necessary, not sufficient