Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 21

The Pumping Lemma for Regular Languages

Recommended resources

Hello! Welcome to the next lesson in our exploration of the theory of computation.

In the previous lesson, we saw how regular expressions and finite automata are the workhorses behind lexical analysis, a fundamental part of every compiler. We learned that for any pattern we can describe with a regular expression, we can build a finite automaton to recognize it.

This raises a crucial question: are there patterns that finite automata cannot recognize? The answer is yes. The finite memory of an automaton—its fixed number of states—imposes fundamental limits on the complexity of languages it can handle.

Today, we will formalize this limitation by introducing the Pumping Lemma for Regular Languages. This isn't a tool for building things, but rather a powerful theoretical device for proving that a language is not regular. By the end of this lesson, you will be able to state the Pumping Lemma and explain the underlying logic of why it must hold true for every regular language.


1. The Core Idea: Why Regular Languages Must "Pump"

The logic behind the Pumping Lemma comes directly from the definition of a Deterministic Finite Automaton (DFA). Remember the 'F' in DFA stands for finite. A DFA has a fixed, finite number of states.

Now, consider what happens when we feed a very long string to a DFA.

  • Let the DFA have p states.
  • If we process an input string w of length p or more, the machine will visit p+1 or more states in its computational path (one for the start state, plus one for each character consumed).

This is a classic application of the Pigeonhole Principle: if you have more pigeons (p+1 states visited) than pigeonholes (p available states), at least one pigeonhole must be used more than once.

Therefore, for any sufficiently long string, the DFA must revisit at least one state while processing the string. This revisited state creates a loop or cycle in the computation path.

This loop is the key. Once a loop is established, we can go around it any number of times (or not at all) and still end up at the same state. If the rest of the string then leads to an accepting state, it means we can generate an infinite set of other strings that are also in the language simply by "pumping" the part of the string that corresponds to the loop.

The following video provides an excellent intuitive and then formal explanation of this concept.

Pumping Lemma for Regular Languages FULL PROOF

This video, 'Pumping Lemma for Regular Languages FULL PROOF' from the Easy Theory channel, masterfully builds the argument from the ground up. It starts by asking if a loop can be guaranteed in a DFA.

Please watch from the beginning to 07:40. The first part introduces the idea of guaranteeing a loop, and the second part uses the Pigeonhole Principle to prove why a loop must exist for any string longer than the number of states in the DFA.

This leads us to a visual model. We can decompose any sufficiently long accepted string w into three parts:

  • x: The part of the string that takes the DFA from the start state to the beginning of the first loop.
  • y: The part of the string that corresponds to traversing the loop exactly once.
  • z: The part of the string that takes the DFA from the loop to a final (accepting) state.
Finite Automaton Illustrating the Pumping Lemma
This diagram illustrates the decomposition of a string `w` into parts `x`, `y`, and `z`. The `x` part leads to a state `rj`, the `y` part loops from `rj` back to itself, and the `z` part leads from `rj` to a final accepting state.

Because y represents a loop, we can traverse it i times (where i could be 0, 1, 2, ...) and the machine will still be in the same state rj afterwards. Since the machine accepts xyz (the original string), it must also accept xz (looping zero times), xyyz (looping twice), xyyyz, and so on.



2. The Formal Statement of the Pumping Lemma

Now that we have the intuition, let's look at the precise, formal statement of the lemma. Mastering this statement is crucial, as every part of it is important when constructing a proof.

Pumping lemma for regular languages

This Wikipedia article provides a clear and standard formal definition of the Pumping Lemma.

Please read the section 'Formal statement'. Pay close attention to the quantifiers (like 'for any' and 'there exists') and the three conditions that must be satisfied.

Let's break down the formal statement into its components:

Lemma: If L is a regular language, then there exists a number p (the pumping length) such that for any string w in L with length |w| ≥ p, the string w can be divided into three pieces, w = xyz, satisfying the following three conditions:

  1. |y| > 0

    • Meaning: The string y (the loop part) must not be empty.
    • Logic: In a DFA, a transition corresponds to reading an input symbol. A loop must consist of at least one transition, so y must contain at least one character.
  2. |xy| ≤ p

    • Meaning: The combined length of the x and y parts must be no more than the pumping length p.
    • Logic: As we established with the Pigeonhole Principle, a state repetition is guaranteed to occur within the first p+1 visited states (i.e., within the first p characters of the string). This means the first loop must finish at or before the p-th character of the string.
  3. For every i ≥ 0, xyⁱz ∈ L

    • Meaning: You can repeat (or "pump") the y part any number of times (including zero times, which removes it), and the resulting string must still be in the language L.
    • Logic: This is the heart of the lemma. Since y corresponds to a cycle, traversing it multiple times or not at all doesn't change the ultimate destination of the DFA. The path still ends in the same accepting state.

The Easy Theory video you started watching continues to explain these three conditions and the formal statement clearly.

Pumping Lemma for Regular Languages FULL PROOF

Let's continue with the 'Pumping Lemma for Regular Languages FULL PROOF' video to see the formal statement and the breakdown of the three conditions.

Please watch from 07:40 to 21:24. This segment introduces the pumping constant p, formally states the lemma, breaks down the string into x, y, and z, and explains each of the three conditions in detail.

Test your understanding!

The condition |xy| ≤ p is a crucial constraint. What might go wrong in a proof if this condition were omitted? For example, if we were trying to prove a language like L = {aⁿbⁿ | n ≥ 0} is not regular, why is it important that the pumpable section y must be near the beginning of the string?

Show answer

Without the |xy| ≤ p condition, an adversary could always claim that the pumpable section y exists in a part of the string that doesn't break the language's rule.

For L = {aⁿbⁿ | n ≥ 0} and a long string like aᵖbᵖ, if the adversary could place y anywhere, they could just choose y to be a single b near the end of the string. Pumping it would create aᵖbᵖ⁺ᵏ, which is clearly not in L, and that would seem to work.

However, the power of the Pumping Lemma for the person using it is that we get to choose the string w, but the adversary has to show that any valid decomposition of w (respecting all three conditions) can be pumped. The condition |xy| ≤ p forces the adversary to find the pumpable segment y within the first p characters. For our chosen string w = aᵖbᵖ, this means y must consist entirely of a's. Pumping y then increases the number of a's but not b's, resulting in a string aᵖ⁺ᵏbᵖ, which is not in L. The constraint |xy| ≤ p is what makes the proof possible by limiting where the loop can be.



3. A Look at the Proof

Given your background, you'll likely appreciate seeing how these ideas are assembled into a concise mathematical proof. The logic is exactly what we've discussed: assume a DFA exists, use the Pigeonhole Principle on a long string, identify the loop, and show that this structure implies the three conditions of the lemma.

The Pumping Lemma for Regular Languages - COSE215

These lecture slides from Korea University, titled 'The Pumping Lemma for Regular Languages', provide a very clean and formal proof.

Please read slides 6 through 9, labeled 'Proof of Pumping Lemma'. This section formally walks through the steps, defining the states visited (pᵢ), using the Pigeonhole Principle to find a repeated state (pᵢ = pⱼ), and then mapping x, y, and z to prove the three conditions.



4. How the Lemma Is Used: The Contrapositive

It is critical to understand that the Pumping Lemma is a property that if a language is regular, then it must be pumpable. You can never use it to prove that a language is regular. Showing that a language can be pumped doesn't prove its regularity, as some non-regular languages can also be pumped.

The true utility of the lemma lies in its contrapositive form:

  • If a language L does not have the pumping property, then L is not regular.

This turns the lemma into a destructive tool. To prove a language is not regular, we assume it is regular (and therefore must be pumpable) and then show that this leads to a contradiction—we find a string that cannot be pumped according to the rules. This is a proof by contradiction.

Pumping Lemma (For Regular Languages)

The channel Neso Academy provides a very direct explanation of this proof strategy.

Please watch the video from the beginning to 01:14 and then from 04:09 to 07:29. The first segment clarifies what the lemma is used for (and not for). The second segment outlines the exact steps of a proof by contradiction using the lemma. This will be the framework we use in the next lesson.

This sets up a "game" for proving non-regularity:

  1. Opponent: Claims a language L is regular and gives you a pumping length p.
  2. You: Choose a clever string w in L such that |w| ≥ p.
  3. Opponent: Must show that w can be split into xyz satisfying the conditions (|y| > 0, |xy| ≤ p).
  4. You: Show that for all possible ways the opponent could split w (respecting the conditions), there is at least one value of i for which xyⁱz is not in L.

If you can always win this game, you have proven the language is not regular.



Conclusion

In this lesson, we established the theoretical basis for the limits of regular languages. We moved from the intuitive idea that a finite machine must loop on long inputs to the rigorous statement of the Pumping Lemma.

Key Takeaways:

  • The Pumping Lemma is a necessary property of all regular languages.
  • The underlying logic stems from the Pigeonhole Principle: a DFA with p states must revisit a state when processing any string of length p or more.
  • This state repetition creates a loop that corresponds to a "pumpable" substring y.
  • The lemma formally states that any sufficiently long string w in a regular language can be split into xyz such that:
    1. |y| > 0 (the loop is non-empty)
    2. |xy| ≤ p (the loop occurs early in the string)
    3. xyⁱz is in the language for all i ≥ 0 (the loop can be repeated or skipped)
  • The lemma is used via its contrapositive to prove a language is not regular by contradiction.

Preview of the Next Lesson:
We have learned the rules of the game. In the next lesson, we will play it. We will apply the Pumping Lemma in formal proofs to demonstrate that several key languages, such as {aⁿbⁿ | n ≥ 0}, are not regular. This will solidify your understanding of the lemma and motivate the need for more powerful computational models.