4.6.7 · D4Theory of Computation

Exercises — Pumping lemma for regular languages — proof and using to show non-regularity

3,314 words15 min readBack to topic

Throughout, remember the adversary game from the parent note: the lemma hands you , you pick a string , the adversary picks a split (with , ), and you pick a pumping power to break membership. Symbols used everywhere below:

  • = the empty string (a string of length ).
  • = the length of (how many symbols it has).
  • = the symbol written times in a row; .
  • = the chunk repeated times; .

Level 1 — Recognition

Exercise 1.1

State the three conditions the split must satisfy, and say who chooses the split.

Recall Solution 1.1

The three conditions are:

  1. — the pumpable middle is non-empty.
  2. — the middle lives inside the first symbols.
  3. for every .

The adversary (the lemma) chooses the split; you only choose and .

Exercise 1.2

For the string with pumping length , list every position where the middle is allowed to start and end, given the constraint . (Do not worry about membership in any language.)

Recall Solution 1.2

Number the symbols : . Condition means must finish by position . Condition means is non-empty. So is a non-empty substring lying entirely within positions . The legal 's are: , , , , , . That is possible middles.

Exercise 1.3

True or false: "If a language passes the pumping lemma, it is regular." Explain in one line.

Recall Solution 1.3

False. The lemma is necessary, not sufficient: every regular language pumps, but some non-regular languages also pump (see Example 4 in the parent note). To prove regularity you build a DFA/regex or use Myhill–Nerode Theorem.


Level 2 — Application

Exercise 2.1

Prove is not regular. Show every step.

Recall Solution 2.1
  1. Assume regular pumping length exists.
  2. Choose . Then and . ✓
  3. Adversary splits with , . The first symbols are all 's, so and lie entirely inside the -block: with .
  4. Pump : .
  5. Since , , so . This contradicts condition 3. is not regular.

Exercise 2.2

Prove is not regular. (The counts differ by exactly one.)

Recall Solution 2.2
  1. Assume regular .
  2. Choose , . ✓
  3. traps inside the -block: , .
  4. Pump : . This has 's and 's.
  5. Membership requires the -count to be exactly one more than the -count: , which simplifies to — impossible since . So . Contradiction not regular.

Exercise 2.3

Prove is not regular.

Recall Solution 2.3
  1. Assume regular .
  2. Choose , . ✓
  3. First symbols are all 's, so , .
  4. Pump : .
  5. Membership needs the -count to be double the -count: , forcing — impossible. So . Contradiction not regular.

Level 3 — Analysis

Exercise 3.1

A student "proves" non-regular by choosing and then asserting . Find the flaw and repair the proof.

Recall Solution 3.1

Flaw: the student chose the split . But the split is chosen by the adversary, not by you — you cannot assume is any particular thing. Repair: derive constraints on from the conditions instead. From and the first symbols being 's, the only thing you may conclude is for some . Then pumping gives for every such . That handles all splits at once — which is exactly what the proof requires.

Exercise 3.2

Explain precisely why (pumping down) is the natural choice for , whereas would fail to give a contradiction. Then complete a correct proof.

Recall Solution 3.2

Choose (since ), . ✓ The -block occupies the first symbols, and traps , .

Why fails: . Here is still true, so the string is still in — no contradiction. Pumping up only widens the gap, keeping membership.

Why works: . Choosing removes 's, shrinking the gap. If and specifically when the removal makes -count -count, membership breaks. The worst case for us is , giving , where is false, so . For any , , so the string is not in . Contradiction not regular.

Moral: choose the direction of pumping that moves toward the boundary of membership.

Exercise 3.3

Prove (strings of 's whose length is a perfect square) is not regular, and pinpoint exactly which inequality about gaps between squares makes it work.

Figure — the number line of lengths (below). The chalk-blue dots mark perfect squares ; the shaded band between and is the "no perfect square here" zone; the pale-yellow diamond is the pumped length ; the yellow double-arrow marks the gap , which is strictly larger than any jump that pumping can produce. Use it to see why the pumped length can never re-hit a square.

Figure — Pumping lemma for regular languages — proof and using to show non-regularity
Recall Solution 3.3
  1. Assume regular .
  2. Choose ; . ✓
  3. Any split gives with .
  4. Pump : length becomes .
  5. Key inequality: the gap between consecutive squares at is Since , we get . So sits strictly between two consecutive perfect squares — it cannot itself be a perfect square. Hence . Contradiction not regular.

Look at the figure above: the pale-yellow mark lands in the shaded "no-square zone" between and ; the yellow arrow shows the gap is wider than the biggest jump pumping can make, so no square is reachable.


Level 4 — Synthesis

Exercise 4.1

Prove (any string repeated twice) is not regular. Design the string carefully so that pins down.

Recall Solution 4.1
  1. Assume regular .
  2. Choose . This is with , so ; . ✓
  3. The first symbols are all 's, so forces , , drawn from the first zero-block.
  4. Pump : .
  5. For this to be of the form , split it into two equal halves. The total length is ; if is odd the length is odd and cannot be at all. If is even, the first half is but the string has only one before the middle on the left and the tail structure on the right cannot match — concretely the first half would contain more than zeros before its first , while the second half has exactly zeros before its , so the two halves differ. Either way . Contradiction not regular. (A cleaner alternative: choosing and gives , whose two halves and differ since .)

Exercise 4.2

Combine two tools: prove non-regular using closure plus a known non-regular language, without directly pumping itself.

Recall Solution 4.2

The goal is to transport non-regularity from a known hard case into , using only closure properties (no pumping of ).

Known fact (our anchor): is not regular. (Standard pumping proof: choose , traps , pump up to break the -count.)

Suppose, for contradiction, were regular.

Step 1 — define an intermediate language. Let Here (all strings of 's) is regular, and regular languages are closed under concatenation. So if were regular, would be regular too.

Step 2 — intersect with a regular filter. The set is what we assumed regular; instead of re-using it, take the plain regular set of "matching tails." Concretely, note that — but is itself non-regular, so that filter is illegal. The clean fix: filter so that the -count is forced to equal the -count using regularity of again. Precisely, apply the symmetric construction: let If were regular then would be regular (concatenation with the regular set ). Now both filters are (assumed) regular, and

Why this intersection equals (step by step). A string lies in iff it satisfies both memberships:

  • forces : an -block, then an equal-length -block, then some 's.
  • forces : some 's, then a -block equal in length to the -block. Matching the two forms symbol-block by symbol-block: the shape must be , with (from ) and (from ). Together , i.e. . So .

Step 3 — closure contradiction. Regular languages are closed under intersection. So if and were both regular, then and would be regular, hence would be regular. But is not regular — contradiction. Therefore at least one of , is non-regular; by the left–right symmetry of the argument the same reasoning proves each individually non-regular, so is not regular.

Point of the exercise: closure under concatenation and intersection lets you build out of the assumed-regular pieces, then the known non-regularity of back-propagates to refute the assumption — no pumping of needed.


Level 5 — Mastery

Exercise 5.1

Show that the pumping lemma cannot prove non-regular, i.e. this passes the lemma — yet is not regular. Give a pumpable split for an arbitrary , then explain the correct tool.

Recall Solution 5.1

It passes. Let be the claimed pumping length. Take any , .

Split with and the first symbol of , the rest. Then and . We check for all :

  • If starts with and has 's (i.e. ): pumping the leading keeps , so the antecedent is false, making the implication vacuously true — the string stays in .
  • If starts with and has exactly one (so must hold): pumping that single up gives 's (antecedent false ⇒ in ), and pumping down () gives 's (antecedent false ⇒ in ).
  • If starts with or : then , antecedent false, and pumping the first (or ) still leaves ; string stays in .

In every case some legal split pumps forever inside , so satisfies the pumping lemma.

But is not regular. Restrict via intersection with the regular set (closure under intersection): , which is essentially shifted — provably non-regular by pumping. Since regular languages are closed under intersection with regular sets, cannot be regular.

Correct tool: use closure properties or Myhill–Nerode Theorem — the pumping lemma alone is powerless here.

Exercise 5.2

Use the Myhill–Nerode Theorem instead of pumping to prove is not regular. Exhibit an infinite family of pairwise-distinguishable strings.

Recall Solution 5.2

Myhill–Nerode idea: if is regular, the number of classes under the relation is finite (it equals the number of states of the minimal DFA). To prove non-regularity, exhibit infinitely many strings that are pairwise distinguishable — meaning for each pair there is a suffix that one can complete into but the other cannot.

Construct the infinite family. Take an infinite set of strings.

Show every pair is distinguishable. Pick any two distinct members and with . Use the suffix :

  • (equal counts). ✓
  • (since , the counts differ). ✗

So the suffix distinguishes from : appended to one it lands in , appended to the other it does not. Because this works for every pair , all the strings lie in pairwise distinct equivalence classes.

Finish the argument. We have exhibited infinitely many mutually distinguishable strings, so the relation has infinitely many classes. But a regular language has only finitely many. Contradiction is not regular.

Compare: where pumping needed a clever and case analysis over splits, Myhill–Nerode just needs an infinite distinguishable family — often cleaner, and it is an if-and-only-if characterisation (unlike pumping).

Exercise 5.3

Design (do not just recall) a non-regularity proof for . This one is subtle: a plain pump-up trick fails. Show the full reasoning.

Figure — Pumping lemma for regular languages — proof and using to show non-regularity
Recall Solution 5.3

Naive pumping of fails: the adversary picks , and pumping up gives , which is in as long as — the adversary can arrange this to stay inside . We need a sharper string.

Choose , where . This is in (since as ) and . ✓

The adversary splits with , . Now pump to . Why is this an integer? Because , so divides (every integer is a factor of ). Then the number of 's becomes So , which has equal counts of and — hence (recall requires ). Contradiction with condition 3. not regular.

Look at the figure: the -count starts at (chalk-blue), and each extra copy of adds ; the pale-yellow choice lands the count exactly on , matching the fixed -count and killing the inequality.

Alternative (cleaner): use closure — (complement) intersected with gives ; since is non-regular and regular languages are closed under complement and intersection, is non-regular. This avoids the factorial trick entirely.


Wrap-up Recall

Recall Across all levels, what is the single most common structural error?

Believing you choose the split . You do not — the adversary does. You only choose (make it depend on ) and (aim it at the membership boundary), and you must defeat every legal split.

Recall When the pumping lemma cannot decide a language, what two tools take over?

Myhill–Nerode Theorem (an if-and-only-if characterisation) and closure properties (transport non-regularity from a known case).