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 p≥1p \geq 1 (the pumping length) such that for every w∈Lw \in L with ∣w∣≥p|w| \geq p:

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

  1. ∣xy∣≤p|xy| \leq p
  2. ∣y∣≥1|y| \geq 1 (so y≠εy \neq \varepsilon)
  3. xyiz∈Lxy^iz \in L for all i≥0i \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 w∈Lw \in L with ∣w∣≥n|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=q0→q1→⋯→q∣w∣=qfs = q_0 \to q_1 \to \cdots \to q_{|w|} = q_f.

Since ∣w∣≥n+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 ∣xy∣≤n=p|xy| \leq n = p
  • Condition 2: i<ji < j, so ∣y∣≥1|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 w∈Lw \in L with ∣w∣≥p|w| \geq p
  3. Show that for ALL possible decompositions w=xyzw = xyz satisfying conditions 1 and 2:
    • There exists ii such that xyiz∉Lxy^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:n≥0}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 ∣xy∣≤p|xy| \leq p and ∣y∣≥1|y| \geq 1:

  • Since ∣xy∣≤p|xy| \leq p, the substring xyxy consists of only aa‘s
  • Thus y=aky = a^k for some k≥1k \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 xy2z∉Lxy^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+2≥p2p+2 \geq p).

For any decomposition w=xyzw = xyz with ∣xy∣≤p|xy| \leq p and ∣y∣≥1|y| \geq 1:

  • ∣xy∣≤p|xy| \leq p means xyxy lies within the first apba^p b (actually, within first apa^p)
  • So y=aky = a^k for some k≥1k \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:n≥0}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 1≤k≤p1 \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 k≤pk \leq p.

So ap2+k∉La^{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