47.01.04 · theoretical-cs / formal-languages-automata

Pumping Lemma for Regular Languages: Proving Non-Regularity

shipped3 tiersLean: nonepending prereqs

Anchor (Master): Sipser 2013 Introduction to the Theory of Computation 3e (Cengage) §1.4; Hopcroft, Motwani & Ullman 2006 Introduction to Automata Theory, Languages, and Computation 3e (Pearson) §2.4 (Myhill-Nerode characterisation as the structural reason behind the pumping lemma, closure properties under homomorphism)

Intuition Beginner

Imagine a hotel with only five rooms. Six guests arrive, each needing a private room. By the pigeonhole principle, at least two guests must share a room. No matter how you assign the rooms, you cannot give each guest a separate one.

A DFA faces the same problem. It has a fixed number of states. When it reads a long string, it passes through many states — one per symbol. If the string is longer than the number of states, some state gets visited twice. The DFA has looped back on itself.

That loop is the key. The substring that caused the DFA to go around the loop can be repeated any number of times, or skipped entirely, and the DFA will still end up in the same final state. The string "pumps" through the loop.

This is the pumping lemma. It says: in any regular language, every sufficiently long string contains a loop that can be pumped. If you can find a language where pumping breaks things — where repeating a substring kicks you out of the language — then that language is not regular.

For example, the language of all strings with equal numbers of 0s and 1s is not regular. A DFA has finite memory. It cannot count arbitrarily high to verify that the number of 0s matches the number of 1s. The pumping lemma turns this intuition into a rigorous proof.

Visual Beginner

A DFA reading a long string must revisit a state:

States:  q0 → q1 → q2 → q3 → q2 → q4
Symbols:  a    b    c    d    e    f
                       ↑         ↑
                       └── y ────┘
                 ↑↑↑          ↑↑↑
                  x            z

String s = abcdef, with y = de (the loop).
s = xyz where:
  x = abc  (leads to first visit of q2)
  y = de   (loop: q2 → q3 → q2)
  z = f    (continues from q2)

Pumping the loop:

Version String In language?
abcf Depends on language
abcdef Yes (original)
abcdedef Depends on language
abcdedededef Depends on language

The pumping lemma guarantees that if the original string is in a regular language, then all pumped versions are also in the language. If any pumped version escapes, the language is not regular.

Worked example Beginner

We prove that is not regular.

Suppose for contradiction that is regular. Then there is a pumping length . Consider the string (that is, zeroes followed by ones). This string is in and has length .

By the pumping lemma, we can write where , , and for all .

Since , the substring lies entirely within the first symbols. So consists only of 0s. Say for some .

Now pump down: consider . This removes zeroes from the string, giving . But (because ), so this string has fewer 0s than 1s. It is not in .

This contradicts the pumping lemma. So is not regular.

Check your understanding Beginner

Formal definition Intermediate+

Lemma (Pumping lemma for regular languages). Let be a regular language. Then there exists a constant (the pumping length) such that every string with can be written as where:

  1. For each , .
  2. (the pumpable part is nonempty).
  3. (the loop occurs within the first symbols).

Proof. Let be a DFA recognising with states. Set . Let with . Consider the sequence of states visited:

This sequence has entries drawn from a set of states. By the pigeonhole principle, some state repeats: there exist indices with . Set , , . Then:

  • and , verifying conditions 2 and 3.
  • For any , reading from reaches via , loops times through (returning to each time), then continues via to . Hence .

Counterexamples to common slips

  • "If a language satisfies the pumping lemma, it must be regular." The pumping lemma is necessary but not sufficient. The language restricted appropriately can pump without issue while being non-regular. A classical counterexample is over a suitable alphabet extension; for a standard one see [Hopcroft, Motwani & Ullman §2.4].

  • "The pumping lemma can prove a language is regular." No. The pumping lemma is exclusively a tool for proving non-regularity. The Myhill-Nerode theorem provides a necessary and sufficient condition [Hopcroft, Motwani & Ullman §2.4].

  • "You get to choose how splits into ." No. The pumping lemma guarantees the existence of a split. In a non-regularity proof, the adversary chooses the split, and you must show that every valid split leads to a contradiction.

Key theorem with proof Intermediate+

Theorem (non-regularity via pumping). The following languages are not regular:

(a) . (b) . (c) .

Proof of (a). Shown in the worked example above. Given pumping length , choose . Any valid split has for some , and pumping down gives .

Proof of (b). Let be the pumping length. Choose (here ). Then with and , so for some . Pumping gives , which has more leading 0s than the 0s before the first "1" in the second copy. The resulting string is not of the form .

Proof of (c). Let be the pumping length. Choose , which has length . Then with for some . Pumping once gives . Since , we have . So is strictly between consecutive powers of 2 and hence is not a power of 2. Thus .

Bridge. The pumping lemma builds toward the Myhill-Nerode theorem in 47.01.02 where the pigeonhole argument reappears as the structural reason that has finitely many classes for regular . This is exactly the content of the forward direction of Myhill-Nerode: finiteness of the state set forces a finite index. The lemma appears again in 47.01.05 where the context-free pumping lemma generalises the regular version by allowing two pumpable regions, and in 47.01.06 where the CYK algorithm provides a positive test for context-free membership that complements the negative test of the pumping lemma. The central insight is that the pumping lemma converts a structural property of DFAs (finite state set) into an algebraic property of languages (closure under pumping), and this is exactly why it is the primary tool for establishing language-theoretic lower bounds.

Exercises Intermediate+

Lean formalization Intermediate+

Mathlib has Computability.DFA and Computability.RegularLanguages with closure properties under Boolean operations and homomorphisms, but it does not formalise the pumping lemma. The foundational gap is the absence of a RegularLanguages.pumping_lemma theorem stating that for any regular language there exists such that every string with decomposes as with , , and . A formal proof would extract the pumping length from the state count of the minimal DFA and construct the decomposition from the repeated state. This unit ships without a lean_module.

Advanced results Master

Three results extend the pumping lemma framework.

Theorem 1 (Myhill-Nerode as the structural explanation of pumping). The pumping lemma is a consequence of the Myhill-Nerode theorem: if is regular with a -state DFA, then has at most classes. For any with , the sequence of prefixes has elements, so two prefixes and are -equivalent. The substring can then be inserted or deleted without changing membership, because equivalent prefixes behave identically under all continuations. The Myhill-Nerode theorem also provides the converse direction that the pumping lemma lacks: is regular iff has finite index [Hopcroft, Motwani & Ullman §2.4].

Theorem 2 (closure under inverse homomorphism). If is regular and is a homomorphism, then is regular. This gives an alternative proof strategy for non-regularity: if is not regular, then is not regular (contrapositive). For example, the homomorphism pulls back from .

Theorem 3 (pumping lemma is not sufficient). Define . This language satisfies the pumping lemma conditions (any long enough string can be pumped within a region that does not disturb the non-equality), but is not regular because its complement within a^\astb^\astc^\ast is , which is not regular (and not even context-free). This demonstrates that the pumping lemma is strictly weaker than the Myhill-Nerode characterisation [Hopcroft, Motwani & Ullman §2.4].

Synthesis. The pumping lemma is the foundational reason that finite memory is detectable from the outside: the central insight is that finiteness of the DFA state set creates a loop that forces algebraic structure on the language. This builds toward the Myhill-Nerode theorem in 47.01.02 which replaces the one-directional pumping lemma with a necessary and sufficient characterisation of regularity. The lemma appears again in 47.01.05 where the context-free pumping lemma operates on parse trees rather than state sequences, and in 47.02.01 where the P-vs-NP framework asks analogous questions about the limits of polynomial-time computation. Putting these together, the pumping lemma is the first and most accessible instance of a general pattern in theoretical computer science: structural limitations of computational models manifest as algebraic properties of the languages or problems they can handle.

Full proof set Master

Proposition 1 (pumping lemma correctness). If is regular, then the pumping lemma conditions hold for .

Proof. Let recognise with . Set . Let with . Define for . Since , the sequence has elements from a set of states. By the pigeonhole principle there exist with .

Set , , . Then and .

For any : reading from reaches after , then loops times from through back to , then reads from to . Since (as ), we have .

Proposition 2 ( is not regular). The language is not regular.

Proof. Suppose is regular with pumping length . Choose . By the pumping lemma, with , , and . Since , for some . Then , which has zeroes and ones. Since , , so . Contradiction.

Proposition 3 ( is not regular). The language is not regular.

Proof. Suppose is regular with pumping length . Choose (with ). Since , the pumping lemma applies. The split has and , so for some (all within the leading block). Then . For this to be in , we need the first half to equal the second half: . But , so this fails. Thus . Contradiction.

Connections Master

  • 47.01.01 — The DFA model with its finite state set provides the structural basis for the pumping lemma; the pigeonhole argument on DFA state sequences is the mechanism behind every pumping-lemma proof.

  • 47.01.02 — Nondeterminism and the subset construction show that NFAs recognise the same regular languages as DFAs; the pumping lemma applies equally to NFA-recognisable languages since they coincide with DFA-recognisable ones.

  • 47.01.03 — Regular expressions describe the same class as DFAs; the pumping lemma applies to the language of any regular expression, and its contrapositive proves that certain patterns cannot be expressed by any regular expression.

  • 47.01.05 — Context-free grammars generate languages that properly contain the regular languages; the context-free pumping lemma extends the regular version by allowing two pumpable regions.

  • 47.02.01 — The P-vs-NP question asks whether polynomial-time computation has a structural limitation analogous to the finite-memory limitation that the pumping lemma exposes for DFAs.

Historical & philosophical context Master

The pumping lemma for regular languages was implicit in the work of Rabin and Scott (1959) on finite automata, where the pigeonhole argument on state sequences appeared as a structural observation. The first explicit statement as a tool for proving non-regularity is due to Bar-Hillel, Perles, and Shamir (1961) in their paper "On Formal Properties of Simple Phrase Structure Grammars," where they also proved the context-free version [Sipser §1.4].

The philosophical significance is that the pumping lemma provides the first instance of a recurring pattern in theoretical computer science: computational models with bounded resources (finite memory, polynomial time, logarithmic space) induce structural properties on the problems they can solve, and these properties can be used to prove impossibility results without constructing explicit counterexample machines. This pattern repeats in the time hierarchy theorem 47.02.02, the space hierarchy theorem 47.02.05, and the Baker-Gill-Solovay oracle results 47.02.04.

The pumping lemma also illustrates the gap between necessary and sufficient conditions. The Myhill-Nerode theorem (1957-1958) provides a necessary and sufficient condition for regularity, but the pumping lemma — being only necessary — is sometimes inadequate. This gap motivates the study of stronger separation techniques such as the interchange lemma and the Kolmogorov-complexity approach to non-regularity.

Bibliography Master

@book{sipser2013,
  author    = {Sipser, Michael},
  title     = {Introduction to the Theory of Computation},
  edition   = {3rd},
  publisher = {Cengage Learning},
  year      = {2013},
}
@book{hopcroft2006,
  author    = {Hopcroft, John E. and Motwani, Rajeev and Ullman, Jeffrey D.},
  title     = {Introduction to Automata Theory, Languages, and Computation},
  edition   = {3rd},
  publisher = {Pearson},
  year      = {2006},
}
@article{barhillel1961formal,
  author  = {Bar-Hillel, Yehoshua and Perles, Micha and Shamir, Eli},
  title   = {On Formal Properties of Simple Phrase Structure Grammars},
  journal = {Zeitschrift f\"ur Phonetik, Sprachwissenschaft und Kommunikationsforschung},
  volume  = {14},
  pages   = {143--172},
  year    = {1961},
}
@article{rabin1959finite,
  author  = {Rabin, Michael O. and Scott, Dana},
  title   = {Finite Automata and Their Decision Problems},
  journal = {IBM Journal of Research and Development},
  volume  = {3},
  number  = {2},
  pages   = {114--125},
  year    = {1959},
}