Formal languages / regular languages

Pumping Lemma for Regular Languages: How to Prove a Language Is Not Regular

For every regular language there is a number p such that any string of length at least p can be split into x, y and z with |y| ≥ 1 and |xy| ≤ p, and xy^iz stays in the language for all i ≥ 0. Showing that this fails proves a language is not regular. The reverse does not hold.

Published
ScopeRegular languages
Conditions on the split3
Splits of a^p b^pp(p+1)/2
Direction it proves1

Pumping aⁿbⁿ, split by split

  1. Assume L = {aⁿbⁿ : n ≥ 0} is regular, and look for a contradiction.

    L is the set of strings with some a symbols followed by the same number of b symbols: ε, ab, aabb, aaabbb and so on. The pumping lemma can only show that a language is not regular, so the proof starts from the opposite claim. It assumes that L is regular and looks for a contradiction.

  2. If L were regular, it would have a pumping length p; take p = 4.

    A regular language has a pumping length p of at least 1 that depends only on the language. The proof does not get to choose it, so the argument has to work for any fixed p. The case p = 4 is one instance; the same reasoning applies to every value of p.

  3. Choose w = a⁴b⁴, which is in L and has length 8.

    The prover does choose the string, and the choice depends on p. With w = aᵖbᵖ the string lies in L and has length 2p, which is at least p. Here that is w = a⁴b⁴, of length 8. The first p symbols are all a, and that is the fact the rest of the proof relies on.

  4. w has 10 allowed splits, and in all 10 of them y contains only a.

    The lemma promises some split of w, and the prover cannot pick it, so every allowed split has to fail. The conditions |xy| ≤ p and |y| ≥ 1 keep xy inside the first p symbols. For p = 4 that leaves 10 splits, which is p(p+1)/2, and y consists only of a in each of them.

  5. Pumping with i = 2 adds |y| copies of a and no b.

    The lemma says xyⁱz stays in L for every i, so one failing i is enough. Take i = 2. Because y is a run of a, xy²z equals a to the power p + |y|, followed by bᵖ. With p = 4 and y = a, the pumped string is a⁵b⁴, with 5 a against 4 b.

  6. In all 10 splits xy²z has more a than b, so none stays in L.

    The check runs through every allowed split and tests xy²z against the set definition of L. For p = 4 that is 10 splits, with 0 still in L. From p = 1 to 8 the counts are 1, 3, 6, 10, 15, 21, 28, 36, and none stays in L. These counts check small cases; the argument that y holds only a covers every p.

  7. No split survives, so L is not regular; passing the test would prove nothing.

    Every allowed split fails, which contradicts the lemma, so L is not regular. The reverse does not hold. For {aⁱbʲcᵏ : i = 0 or j = k}, all 95 nonempty strings up to length 10 pump without leaving the language when y is the first symbol, and it is still not regular. Passing shows nothing; only failing is a proof.

xy²z

Assume regular

Assume L = {aⁿbⁿ : n ≥ 0} is regular, and look for a contradiction.

    Sources: Wikipedia, Pumping lemma for regular languages, Cornell University, CS 2800, Lecture 36, Hunter College, CSCI 265, Proving regularity, Korea University, COSE215, Lecture 8, Wikipedia, Chomsky hierarchy.

    The pumping lemma is the standard tool for showing that a language is not regular. It turns the fact that a finite automaton has only finitely many states into a statement about long strings, and a proof then looks for a contradiction. The page belongs to the wider topic of formal languages and the Chomsky hierarchy.

    What does the pumping lemma for regular languages say?

    If L is a regular language, there is an integer p ≥ 1, the pumping length, that depends only on L. Every string w in L with |w| ≥ p can be written as w = xyz so that three conditions hold:

    1. |y| ≥ 1, so the middle part is not empty.
    2. |xy| ≤ p, so the middle part lies within the first p symbols.
    3. x yi z is in L for every i ≥ 0, so the middle part can be repeated any number of times, or deleted.

    Course notes use other letters. The Cornell lecture notes, for example, write the pumping length as n and the three parts as u, v and w, with the repetition count named k. The statements are the same, and this page uses p, x, y and z.

    The lemma speaks about languages recognized by a finite automaton, since those are the regular languages. In the language of an automaton, pumping y means running through a loop of the automaton zero, one or many times.

    What is the pumping length?

    The pumping length p is a property of the language, not of a particular string. It is at least 1, and it exists whenever the language is regular. One way to see where it comes from is to think of a DFA with n states for the language. A string with at least n symbols makes the automaton visit n + 1 states while it reads its first n symbols, so two of them must be the same state. The stretch between the two visits is a loop that can be traversed any number of times, and that loop is the middle part y.

    In a proof the pumping length is an unknown. The prover may not pick a convenient value for p. The argument has to work for every p, because the lemma only promises that some p exists. The prover also does not get to pick the split of the string into x, y and z: the proof must handle every split that meets the conditions. What the prover does choose is the string w, and later the exponent i.

    How do you prove a language is not regular with the pumping lemma?

    The proof runs by contradiction.

    1. Assume that the language L is regular. Then the lemma applies, and L has a pumping length p.
    2. Choose a string w in L with |w| ≥ p. The choice may depend on p, and a good choice makes the next step easy.
    3. Consider every split w = xyz with |y| ≥ 1 and |xy| ≤ p. The conditions limit where y can lie.
    4. For each split, find an exponent i, possibly different for different splits, such that x yi z is not in L.
    5. This contradicts the lemma, which says that all pumped strings stay in L. The assumption was false, so L is not regular.

    Step 3 is where the work happens. The condition |xy| ≤ p pins y to the beginning of the string, and a well-chosen w turns that into a strong restriction on what y can contain.

    Worked example: anbn is not regular

    Let L be the set of strings anbn for n ≥ 0: some a symbols followed by the same number of b symbols. Assume L is regular, and let p be its pumping length.

    Choose w = apbp. It is in L and has length 2p, which is at least p. Take any split w = xyz that satisfies |xy| ≤ p and |y| ≥ 1. Because w starts with p symbols a and xy lies within the first p symbols, both x and y consist only of a. So y = ak for some k ≥ 1.

    Now pump with i = 2. The string x y2 z has k extra copies of a, so it equals ap+kbp. It has more a symbols than b symbols, and therefore it is not in L. This holds for every split, and the lemma says it cannot, so L is not regular.

    The number of splits to consider is smaller than it first looks. Write x = as and y = at with t ≥ 1 and s + t ≤ p. For p = 1 to 8 this gives 1, 3, 6, 10, 15, 21, 28 and 36 splits, which is p(p+1)/2 in general. In none of them does the pumped string x y2 z belong to L. That count is a check on the cases for small p; the argument for all p is the one in the paragraph above.

    The same proof appears in the Cornell notes for the language of 0n1n, with x = 0n1n and k = 2. A course at Korea University proves the same statement with i = 0 instead, which deletes y and leaves fewer a than b.

    Can the pumping lemma prove that a language is regular?

    No. The lemma gives a necessary condition for regularity and not a sufficient one. If a language fails the condition, it is not regular. If it satisfies the condition, nothing follows, because some non-regular languages pass the test as well.

    A standard counterexample is the language of strings aibjck where i = 0 or j = k. It satisfies the pumping conditions with p = 1: any nonempty string in it can be split with y equal to its first symbol and pumped any number of times without leaving the language. Yet the language is not regular. One way to see this is to intersect it with the regular language ab*c*. The intersection is the set of strings abjcj, which is not regular, and regular languages are closed under intersection. The theorem of Myhill and Nerode gives the same result.

    LanguagePumping conditionRegular
    anbnfailsno
    aibjck with i = 0 or j = kholdsno
    strings that end in 1holdsyes

    To show that a language is regular, build a finite automaton or a regular expression for it. A language such as anbn is context-free and not regular, and a grammar like the mixed one in the page on left-linear and right-linear grammars can generate it.

    Where do pumping proofs usually go wrong?

    • Picking the split. The decomposition is not the prover's choice. If a proof fixes one convenient y, it covers only that case, and the lemma allows any valid split.
    • Ignoring |xy| ≤ p. This condition is what confines y to a known part of the string. Without it, y could lie anywhere in the string, including over the b symbols, and the argument above would fail.
    • Choosing w without regard to p. The string must have length at least p and must be built from p, as in apbp. A fixed string like aaabbb does not work for every p.
    • Fixing i in advance. The exponent may be chosen after the split is known. For anbn, i = 2 works and so does i = 0, but for other languages no single exponent works for every split. For the strings of a whose length is a prime number, checks for p from 4 to 15 found splits for which both i = 0 and i = 2 give a prime length again.
    • Reading a passed test as proof of regularity. Passing shows nothing.
    FAQ

    Frequently asked questions

    01What is pumping length in the pumping lemma?

    The pumping length p is a number that depends only on the language. Every string in the language that is at least p symbols long can be split and pumped. In a proof, p is treated as an unknown fixed number that the prover does not get to choose.

    02Can the pumping lemma be used to prove a language is regular?

    No. The lemma is a necessary condition for regularity, not a sufficient one. A language that fails it is not regular, but a language that passes it may still be non-regular, so passing the test says nothing.

    03Is there a pumping lemma for context-free languages?

    Yes, as a separate statement. It splits a long string into five parts, written uvwxy, with the middle part vwx at most p symbols long and v and x not both empty, and it pumps v and x together. It is a different lemma from the one on this page.