Applications of the Pumping Lemma

Lesson 11 is a worked catalogue of non-regularity proofs. It gives the canonical matched-counts proof and the trap of choosing your own split, then counting languages and the line between bounded and unbounded quantities, and shape languages such as palindromes and repeated blocks, handled with the marker trick. It works arithmetic languages that need gap and factorization arguments, for the perfect squares and for the primes, and shows closure arguments as the shorter alternative. It ends with a language that pumps yet is not regular, together with the distinguishable-prefix fallback, and a diagnostic table for repairing failed attempts.

Subject: Theory of Computation · 120 slides · symbolic lesson

Open the interactive version of this deck · Homework for this lesson

What this lesson covers

The lesson, slide by slide

1. Applications of the Pumping Lemma

Title

Theory of Computation · Lesson 11

A catalogue of non-regularity proofs: the string to choose, the repetition count to pick, and the cases where pumping is the wrong tool entirely.

2. What you will be able to do

Objectives

Lesson 10 built the tool. This lesson uses it, repeatedly, until the choices become automatic. By the end you can:

  1. Write the canonical proof for matched counts, in five sentences, from memory.
  2. Handle shape languages such as palindromes and repeated blocks.
  1. Handle arithmetic languages, where a large repetition count is needed rather than zero or two.
  2. Recognize when a closure argument from Lesson 7 is shorter than pumping, and use it.
  1. Diagnose a failed proof attempt and choose a better string.
  2. Handle a language that pumps but is still not regular, using distinguishable prefixes.

3. What survived from The Pumping Lemma for Regular Languages?

Warm-up

Discussion prompt

Before we open Applications of the Pumping Lemma: without looking back, what was the main idea of The Pumping Lemma for Regular Languages, and what could you do by the end of it that you could not do before?

Hint: One sentence for the idea, one for the skill. If the second one is blank, that is the part to revisit.

Answer:

Lesson 10 supplies the first tool for proving a language has no finite automaton. Covers why every earlier technique proves only the positive direction, how finiteness plus the pigeonhole principle forces a repeated state and hence a pumpable cycle, the exact statement with its three conditions and the quantifier order, the adversary game that makes the alternation manageable, the proof of the lemma itself with each condition traced to its source, and how to set a proof up: choosing a string built from the pumping length with a uniform prefix, and choosing the repetition count.

4. The Canonical Proof

Section

Section 1

5. The template, restated

Concept

Every proof in this lesson is the same five sentences from Lesson 10. Only the string and the repetition count change.

  1. Suppose the language is regular; let p be the pumping length.
  2. Consider a specific string, built from p, in the language, of length at least p.
  3. The lemma splits it, with a nonempty middle inside the first p symbols.
  4. Argue what the middle part must consist of.
  5. Pump, show the result leaves the language, contradiction.

Sentence four is the one that varies most, and it is where a badly chosen string reveals itself: if you cannot say what the middle must be, the string was wrong.

6. Break it if you can: The template, restated

Counterexample

Discussion prompt

Every proof in this lesson is the same five sentences from Lesson 10. Only the string and the repetition count change.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

Answer:

Sentence four is the one that varies most, and it is where a badly chosen string reveals itself: if you cannot say what the middle must be, the string was wrong.

7. What has to happen first: The matched-counts language

Ranking

Put in order

Put the moves of The matched-counts language into the order they have to happen.

  1. Assume regularity and take the pumping length
  2. Choose the string
  3. Apply the lemma and pin down the middle
  4. Pump with two copies
  5. Verify the result is outside the language, for every legal split

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Suppose the language were regular.

8. The matched-counts language

Worked example

The standard first example. Prove that the strings of some number of zeros followed by the same number of ones is not regular.

\[ L = \{\, 0^{n}1^{n} : n \ge 0 \,\} \]

Assume regularity and take the pumping length

Why: Suppose the language were regular. The lemma then provides a pumping length p, whose value we do not know.

Choose the string

Why: Take p zeros followed by p ones. It is in the language, since the counts match, and its length is twice p, which is at least p.

\[ w = 0^{p}1^{p} \in L, \qquad |w| = 2p \ge p \]

Apply the lemma and pin down the middle

Why: The split has a nonempty middle with the first two parts together at most p long. The first p symbols of the string are all zeros, so the middle lies entirely inside that block.

\[ y = 0^{k}, \qquad 1 \le k \le p \]

Pump with two copies

Why: The middle is duplicated, adding k more zeros. The block of ones is untouched, since it sits entirely in the third part.

\[ xy^{2}z = 0^{p+k}1^{p} \]

Verify the result is outside the language, for every legal split

Why: Since k is at least one, the zero count strictly exceeds the one count, so the string does not have the required form. This holds for every value of k the adversary could have chosen, so the contradiction is complete and the language is not regular.

\[ p+k > p \;\Rightarrow\; 0^{p+k}1^{p} \notin L \ \checkmark \]

9. The matched-counts language — line by line

Picture it

Animation

Shows: Each line of the worked example "The matched-counts language", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Since k is at least one, the zero count strictly exceeds the one count, so the string does not have the required form. This holds for every value of k the adversary could have chosen, so the contradiction is complete and the language is not regular.

10. Why this string is the right one

Intuition

Every requirement from the string-choice pattern is met, and it is worth checking them off explicitly this once.

RequirementHow the string meets it
in the languagethe counts match by construction
length at least pits length is twice p
uniform first p symbolsthe leading block is all zeros
pumping breaks the conditiononly the zero count changes

The third row is what makes the fourth possible. Because the middle is forced into the zeros, pumping can only ever change one of the two counts — and a condition demanding they stay equal cannot survive that.

11. Fill in: How the string meets it for Why this string is the right one

Comparison

Comparison matrix

From Why this string is the right one: refill the How the string meets it column from what you know. The rest of the table is as it appeared.

RequirementHow the string meets it
in the languagethe counts match by construction
length at least pits length is twice p
uniform first p symbolsthe leading block is all zeros
pumping breaks the conditiononly the zero count changes

12. Something is wrong here: choosing the split yourself

Anomaly

Predict first

A student writes this, and it looks reasonable:

Prove the matched-counts language is not regular.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: Take the string with p zeros and p ones, and let the middle part be the single zero at the boundary — the one just before the ones begin.

Prove the matched-counts language is not regular.

Why: Take the string with p zeros and p ones, and let the middle part be the single zero at the boundary — the one just before the ones begin.

13. Trap: choosing the split yourself

Trap

The trap

Prove the matched-counts language is not regular.

Pick a convenient split

Why: Take the string with p zeros and p ones, and let the middle part be the single zero at the boundary — the one just before the ones begin.

\[ x = 0^{p-1}, \quad y = 0, \quad z = 1^{p} \]

Pump and declare victory

Why: Duplicating that zero unbalances the counts, so the result is outside the language and the proof is finished.

\[ xy^{2}z = 0^{p+1}1^{p} \notin L \]

The fix

Prove the matched-counts language is not regular.

Notice the split is not yours to choose

Why: The lemma promises that some valid split exists — it does not promise the one you picked. A proof must derive its contradiction for every split satisfying the two side conditions.

\[ \exists (x,y,z) \text{, not } \forall (x,y,z) \text{ of your choosing} \]

Argue from the conditions instead

Why: The early-split condition says the first two parts total at most p symbols. Since the first p symbols are all zeros, every legal middle is a nonempty run of zeros — which is all the argument ever needed.

\[ |xy| \le p \;\Rightarrow\; y = 0^{k}, \; 1 \le k \le p \]

Now the conclusion covers every case

Why: Pumping any such middle adds zeros only, so the counts differ for every legal split. The proof is now valid, and it is barely longer.

\[ 0^{p+k}1^{p} \notin L \text{ for all } 1 \le k \le p \ \checkmark \]

14. Decode the notation: Trap: choosing the split yourself

Notation

Annotate

From Trap: choosing the split yourself — read this one piece at a time. What is each part doing?

On: \( x = 0^{p-1}, \quad y = 0, \quad z = 1^{p} \)

  • Take the string with p zeros and p ones, and let the middle part be the single zero at the boundary — the one just before the ones begin.
  • Duplicating that zero unbalances the counts, so the result is outside the language and the proof is finished.
  • The lemma promises that some valid split exists — it does not promise the one you picked. A proof must derive its contradiction for every split satisfying the two side conditions.

15. Rebuild the recipe: Writing the proof so it is checkable

Ranking

Put in order

These are the steps of Writing the proof so it is checkable, scrambled. Put them back in order before the next slide shows you.

  1. Name the pumping length and say explicitly that its value is unknown.
  2. State the chosen string and verify both of its obligations: in the language, and long enough.
  3. Quote the early-split condition and derive the shape of the middle from it.
  4. Say which repetition count you are using, and why.
  5. State the contradiction as a property that fails, not merely as 'this is not in the language'.

Why: This is the order the recipe itself gives. Recalling the sequence without the slide in front of you is the difference between recognising the method and being able to run it — most of what goes wrong in practice is a step done out of turn.

16. Writing the proof so it is checkable

Pattern

A correct proof and a plausible one look similar. These habits keep them apart.

  1. Name the pumping length and say explicitly that its value is unknown.
  2. State the chosen string and verify both of its obligations: in the language, and long enough.
  3. Quote the early-split condition and derive the shape of the middle from it.
  4. Say which repetition count you are using, and why.
  5. State the contradiction as a property that fails, not merely as 'this is not in the language'.

The third bullet is the one graders look for. A proof that never mentions the early-split condition has almost certainly chosen its own split.

17. Rule out three: Check yourself: the canonical proof

Elimination

Eliminate the wrong options

In the proof for the matched-counts language, which condition guarantees the middle part contains only zeros?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. The first two parts together have length at most p
  • B. The middle part is nonempty
  • C. The string was chosen to be in the language
  • D. The repetition count may be taken to be zero

Survives elimination: A

Why: The condition bounds the combined length of the first two parts by p, so the middle lies inside the first p symbols of the string. Since those were all chosen to be zeros, the middle can contain nothing else.

18. Check yourself: the canonical proof

Check

Think about which condition forces the middle part into the zeros.

Check your understanding

In the proof for the matched-counts language, which condition guarantees the middle part contains only zeros?

  • A. The first two parts together have length at most p (correct)
  • B. The middle part is nonempty
  • C. The string was chosen to be in the language
  • D. The repetition count may be taken to be zero

Answer: A

Why: The condition bounds the combined length of the first two parts by p, so the middle lies inside the first p symbols of the string. Since those were all chosen to be zeros, the middle can contain nothing else.

Why B tempts people
Nonemptiness guarantees pumping actually changes the string, but it says nothing about which symbols the middle contains.
Why C tempts people
Membership is required for the lemma to apply at all, but it constrains the whole string rather than the location of the split.
Why D tempts people
The repetition count is chosen after the split and cannot influence where the split fell.

19. Plan first: A variant: more ones than zeros

Step zero

Discussion prompt

A variant: more ones than zeros — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Choose the string carefully

Answer:

  1. Choose the string carefully
  2. Pin down the middle
  3. Choose the repetition count to close the margin
  4. Check the inequality now fails
  5. Verify the choice of margin was necessary

20. A variant: more ones than zeros

Worked example

The same shape of argument on a language whose condition is an inequality rather than an equality.

\[ L = \{\, 0^{m}1^{n} : n > m \ge 0 \,\} \]

Choose the string carefully

Why: Take p zeros followed by p plus one ones. The inequality holds by exactly one, which is the tightest margin available.

\[ w = 0^{p}1^{p+1} \in L \]

Pin down the middle

Why: The first p symbols are zeros, so the middle is a nonempty run of zeros.

\[ y = 0^{k}, \qquad 1 \le k \le p \]

Choose the repetition count to close the margin

Why: The margin was one, so adding even a single zero destroys it. Two copies add k zeros, and k is at least one.

\[ xy^{2}z = 0^{p+k}1^{p+1} \]

Check the inequality now fails

Why: The one count is p plus one and the zero count is p plus k, which is at least p plus one. So the ones no longer strictly outnumber the zeros.

\[ p+1 > p+k \text{ is false for } k \ge 1 \]

Verify the choice of margin was necessary

Why: Had the string used p zeros and two-p ones, adding k zeros would leave the ones still ahead whenever k is small, and no contradiction would follow. Choosing the tightest possible margin is what makes a single pump decisive.

\[ \text{tight margin} \;\Rightarrow\; \text{one pump suffices} \ \checkmark \]

21. A variant: more ones than zeros — line by line

Picture it

Animation

Shows: Each line of the worked example "A variant: more ones than zeros", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The one count is p plus one and the zero count is p plus k, which is at least p plus one. So the ones no longer strictly outnumber the zeros.

22. Tight margins make short proofs

Intuition

The variant above illustrates a general principle worth carrying into every proof.

When the condition is an inequality, choose the string so the inequality is as close to failing as the language allows. Then the smallest possible change breaks it, and you do not have to reason about how large the middle part might be.

When the condition is an equality, any change breaks it, so the margin question does not arise — which is why matched-count languages are the easiest of all.

\[ \text{equality} : \text{any pump works} \qquad \text{inequality} : \text{make it tight first} \]

23. By analogy: Tight margins make short proofs

Analogy

Discussion prompt

Explain Tight margins make short proofs by analogy to something with no Theory of Computation in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

When the condition is an equality, any change breaks it, so the margin question does not arise — which is why matched-count languages are the easiest of all.

24. Counting Languages

Section

Section 2

25. Counting conditions and what breaks them

Concept

A counting language constrains how many of something a string contains. Whether pumping breaks it depends on what the count is compared against.

ConditionRegular?Why
count is evenyesonly the parity matters — two values
count is at most fiveyescapped — six values
count is a multiple of sevenyesremainder — seven values
two counts are equalnothe difference is unbounded
one count exceeds anothernothe difference is unbounded

The line is always the same: a count taken against a fixed bound or modulus is fine, and a count compared against another count is not.

26. Which is which, by Regular?

Discrimination

Sort into buckets

Sort these by Regular?, from memory, without looking back at Counting conditions and what breaks them. Telling them apart on the spot is the skill; the table is only where the answer happens to be written down.

yes
count is even; count is at most five; count is a multiple of seven
no
two counts are equal; one count exceeds another
g1
Regular? is "yes" for count is even, count is at most five, count is a multiple of seven — that is what the table on "Counting conditions and what breaks them" records, and it is the single property separating this group from the rest.
g2
Regular? is "no" for two counts are equal, one count exceeds another — that is what the table on "Counting conditions and what breaks them" records, and it is the single property separating this group from the rest.

27. Guess the shape of the answer: Equal zeros and ones, in any order

Estimation

Predict first

The counts need not be in separate blocks for the language to be irregular.

Commit before you compute: what does Equal zeros and ones, in any order come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify by comparing with the closure route

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. Lesson 7 proved this same language irregular by intersecting it with the regular language of zeros-then-ones.

28. Equal zeros and ones, in any order

Worked example

The counts need not be in separate blocks for the language to be irregular.

\[ L = \{\, w \in \{0,1\}^{*} : \#_0(w) = \#_1(w) \,\} \]

Choose a string with a uniform prefix

Why: Take p zeros followed by p ones. It has equal counts, so it is in the language, and its prefix is uniform.

\[ w = 0^{p}1^{p} \]

Pin down the middle and pump

Why: The middle is a nonempty run of zeros, and duplicating it adds zeros without adding ones.

\[ xy^{2}z = 0^{p+k}1^{p} \]

Check the counts

Why: The zero count is p plus k and the one count is p. Since k is at least one, they differ.

Note that this also proves a stronger statement

Why: The same string works whether the language demands the zeros come first or allows any order, because the chosen string happens to have them in order. A proof for the general language is therefore no harder.

Verify by comparing with the closure route

Why: Lesson 7 proved this same language irregular by intersecting it with the regular language of zeros-then-ones. Both routes reach the same conclusion; this one is self-contained, and that one is shorter once the matched-counts result is already available.

\[ \#_0 \neq \#_1 \;\Rightarrow\; 0^{p+k}1^{p} \notin L \ \checkmark \]

29. Equal zeros and ones, in any order — line by line

Picture it

Animation

Shows: Each line of the worked example "Equal zeros and ones, in any order", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The zero count is p plus k and the one count is p. Since k is at least one, they differ.

30. What has to be given first: A count against a fixed multiple

Missing information

Discussion prompt

Not every language with two counts is irregular. This one is, but the reason is worth seeing fail first.

What do you need to know — or decide — before the first line can be written? List everything the problem has to hand you.

Hint: Anything you would have to invent to get started is a thing the problem must supply.

Answer:

Take p zeros followed by twice p ones. The condition holds and the prefix is uniform.

31. A count against a fixed multiple

Worked example

Not every language with two counts is irregular. This one is, but the reason is worth seeing fail first.

\[ L = \{\, 0^{n}1^{2n} : n \ge 0 \,\} \]

Choose the string

Why: Take p zeros followed by twice p ones. The condition holds and the prefix is uniform.

\[ w = 0^{p}1^{2p} \]

Pin down the middle

Why: As before, the middle is a nonempty run of zeros from the leading block.

\[ y = 0^{k}, \qquad 1 \le k \le p \]

Pump and check the ratio

Why: Duplicating gives p plus k zeros and still twice p ones. The condition would require the ones to be twice the zeros, so it would need twice p plus twice k ones.

\[ 2(p+k) = 2p + 2k \neq 2p \]

Confirm the mismatch for every legal k

Why: Since k is at least one, the required count exceeds the actual count by at least two. The condition fails regardless of the split.

Verify that the fixed ratio did not save the language

Why: It might seem that a fixed multiplier makes the relationship more machine-friendly, but the quantity that must be remembered is still the zero count itself, which is unbounded. The proof goes through unchanged.

\[ 0^{p+k}1^{2p} \notin L \ \checkmark \]

32. A count against a fixed multiple — line by line

Picture it

Animation

Shows: Each line of the worked example "A count against a fixed multiple", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: It might seem that a fixed multiplier makes the relationship more machine-friendly, but the quantity that must be remembered is still the zero count itself, which is unbounded. The proof goes through unchanged.

33. Why a ratio is no easier than an equality

Intuition

A machine reading the zeros has to hand something to the part of itself that reads the ones. That handover is the whole difficulty, and multiplying by a constant does not shrink it.

Whether the machine must produce the same number, twice the number, or the number plus three, it must first know the number — and the number is unbounded.

The only conditions that escape are those where a bounded summary suffices: a parity, a remainder, or a capped count. Anything requiring the exact value fails, whatever is done with it afterwards.

\[ \text{exact unbounded value needed} \;\Rightarrow\; \text{not regular} \]

34. Teach it back: Why a ratio is no easier than an equality

Explain it

Discussion prompt

Explain Why a ratio is no easier than an equality to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

A machine reading the zeros has to hand something to the part of itself that reads the ones. That handover is the whole difficulty, and multiplying by a constant does not shrink it.

35. Counting occurrences of a block

Worked example

A counting language where the thing being counted is a two-symbol block rather than a symbol.

\[ L = \{\, w : \#_{ab}(w) = \#_{ba}(w) + 1 \,\} \]

Ask whether the quantity is bounded

Why: The difference between the two block counts must be exactly one. The difference itself ranges over all integers as the string grows, so it is unbounded — which suggests irregularity.

Test the suggestion before proving it

Why: Try a few strings by hand. Every occurrence of the first block that is not immediately balanced seems recoverable later, which is a warning sign that the condition may be looser than it looks.

Discover the language is in fact regular

Why: Between any two occurrences of one block there must be an occurrence of the other, because the string has to return. So the difference never leaves the range from minus one to one, and three states suffice.

\[ \#_{ab}(w) - \#_{ba}(w) \in \{-1, 0, 1\} \]

Note what went wrong with the first instinct

Why: The quantity looked unbounded but was constrained by the structure of the string itself. Checking whether a quantity can actually reach large values, rather than whether it could in principle, is a step worth taking.

Verify by exhibiting the machine's behaviour on three strings

Why: The string ab has a difference of one and is accepted; ba has minus one and is rejected; abab has one and is accepted. All three agree with the three-state design, confirming the language is regular after all.

\[ ab,\ abab \in L \qquad ba,\ \varepsilon \notin L \ \checkmark \]

36. Counting occurrences of a block — line by line

Picture it

Animation

Shows: Each line of the worked example "Counting occurrences of a block", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The string ab has a difference of one and is accepted; ba has minus one and is rejected; abab has one and is accepted. All three agree with the three-state design, confirming the language is regular after all.

37. Unbounded in principle is not unbounded in fact

Intuition

That example is worth dwelling on, because it is the most common way a classification goes wrong in the safe direction.

A quantity is only a problem if the strings of the language can actually drive it to arbitrarily large values. If the structure of the strings keeps it inside a fixed window, the machine can track it after all.

So the classification question is really: over the strings of this language, does the quantity take unboundedly many values? Answering it for arbitrary strings rather than for members of the language is the error.

\[ \text{unbounded over } \Sigma^{*} \;\not\Rightarrow\; \text{unbounded over } L \]

38. Answer it before you see the options: Check yourself: counting languages

Prediction

Predict first

Which of these languages over the alphabet of zeros and ones is NOT regular?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: Strings where the number of zeros equals the number of ones

Why: Deciding this requires remembering the running difference between the two counts, and that difference is unbounded — a prefix with a gap of three and one with a gap of four have different futures, so no finite state set can separate them all.

39. Check yourself: counting languages

Check

Three of these are regular and one is not.

Check your understanding

Which of these languages over the alphabet of zeros and ones is NOT regular?

  • A. Strings where the number of zeros equals the number of ones (correct)
  • B. Strings where the number of zeros is a multiple of five
  • C. Strings with at most seven ones
  • D. Strings where the number of zeros is even and the number of ones is odd

Answer: A

Why: Deciding this requires remembering the running difference between the two counts, and that difference is unbounded — a prefix with a gap of three and one with a gap of four have different futures, so no finite state set can separate them all.

Why B tempts people
Only the remainder modulo five matters, so five states suffice. This is regular.
Why C tempts people
The count can be capped at eight, since anything beyond seven is equally fatal. Eight states suffice.
Why D tempts people
Two parities, so four states via the product construction. Both conditions are bounded, so this is regular.

40. Plan first: A counting language that is regular after all

Step zero

Discussion prompt

A counting language that is regular after all — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: State the language

Answer:

  1. State the language
  2. Ask what must be remembered
  3. Count the values
  4. Note why the cap is legitimate
  5. Verify the state count by checking the boundary

41. A counting language that is regular after all

Worked example

Practise the classification by proving a suspicious-looking language regular instead.

State the language

Why: The strings over the alphabet of zeros and ones in which the number of zeros and the number of ones differ by at most two.

Ask what must be remembered

Why: The running difference — but only while it stays within the window from minus two to two. Once it leaves that window it can never come back into the language's favour without passing through, so the machine can cap it.

Count the values

Why: Five values inside the window, plus one state meaning 'has drifted too far'. Six states in total, and the drifted state is a dead state.

\[ \text{difference} \in \{-2,-1,0,1,2\} \;\cup\; \{\text{out of range}\} \]

Note why the cap is legitimate

Why: The condition is about the final difference, and a string whose difference has left the window could still return. So the cap is only legitimate here because leaving the window by more than two cannot be undone within the window's own bookkeeping — the drifted state must record the direction as well.

Verify the state count by checking the boundary

Why: Tracking direction as well as magnitude gives states for differences from minus three to three, with the two extremes absorbing — seven states. Testing the strings 000, 0011 and the empty string against this design gives reject, accept and accept, matching the specification.

\[ \varepsilon,\ 0011,\ 001 \in L \qquad 000 \notin L \ \checkmark \]

42. A counting language that is regular after all — line by line

Picture it

Animation

Shows: Each line of the worked example "A counting language that is regular after all", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Tracking direction as well as magnitude gives states for differences from minus three to three, with the two extremes absorbing — seven states. Testing the strings 000, 0011 and the empty string against this design gives reject, accept and accept, matching the specification.

43. The classification question comes first

Intuition

Half the value of these lessons is knowing which tool to reach for, and that decision takes seconds if made deliberately.

Attempting a pumping proof on a regular language wastes an hour and always fails, because the adversary genuinely has a winning strategy. Attempting a machine on an irregular language wastes the same hour.

44. Shape Languages

Section

Section 3

45. Conditions about structure rather than count

Concept

A shape language constrains how parts of the string relate to each other — symmetry, repetition, or matching — rather than how many symbols it has.

LanguageCondition
palindromesreads the same in both directions
a string followed by itselfthe two halves are identical
a string followed by its reversalthe second half mirrors the first
balanced bracketsevery opening has a matching closing

All four are non-regular, and all four fail for the same underlying reason: the machine would have to remember an unbounded prefix in order to check it against what comes later.

46. What each one costs: Conditions about structure rather than count

Trade off

Comparison matrix

From Conditions about structure rather than count: every row here is a choice with a cost. Fill the Condition column, then say which row you would actually pick and what you give up for it.

LanguageCondition
palindromesreads the same in both directions
a string followed by itselfthe two halves are identical
a string followed by its reversalthe second half mirrors the first
balanced bracketsevery opening has a matching closing

47. Complete the line: The palindromes

Fill the middle

Fill in the blanks

From The palindromes — finish the line. Write what belongs on the right of the equals sign before you look.

xy^a^{p+k}\,b\,a^{p}z = ___

Why: Producing the right-hand side unprompted is the difference between recognising this line and being able to use it. Take p copies of a, then a single b, then p copies of a.

48. The palindromes

Worked example

Prove that the strings reading the same in both directions are not regular, over a two-symbol alphabet.

\[ L = \{\, w \in \{a,b\}^{*} : w = w^{R} \,\} \]

Choose a string with a uniform prefix and a marker

Why: Take p copies of a, then a single b, then p copies of a. It reads the same both ways, so it is in the language.

\[ w = a^{p}\,b\,a^{p} \]

Pin down the middle

Why: The first p symbols are all a's, so the middle is a nonempty run of a's from the leading block.

\[ y = a^{k}, \qquad 1 \le k \le p \]

Pump with two copies

Why: The leading block grows and the trailing block does not, since it lies entirely in the third part.

\[ xy^{2}z = a^{p+k}\,b\,a^{p} \]

Check the symmetry

Why: Reversing the pumped string gives p a's, then b, then p plus k a's. That differs from the pumped string, since the two runs have different lengths.

Verify the marker was necessary

Why: Without the b, the string would be a uniform run of a's, and every such run is a palindrome — pumping would produce another palindrome and the proof would fail. The single b is what makes the two blocks distinguishable.

\[ a^{p+k}ba^{p} \neq \big(a^{p+k}ba^{p}\big)^{R} \ \checkmark \]

49. The palindromes — line by line

Picture it

Animation

Shows: Each line of the worked example "The palindromes", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Reversing the pumped string gives p a's, then b, then p plus k a's. That differs from the pumped string, since the two runs have different lengths.

50. The marker trick

Intuition

The b in that proof did no counting and satisfied no condition. It was there purely to make the two blocks tell-apart-able.

This trick recurs constantly. When a language is about symmetry or repetition, insert a symbol that appears exactly once, so that 'before the marker' and 'after the marker' are unambiguous notions.

Without it, pumping often produces another member of the language and the proof collapses — not because the language is regular, but because the string was too uniform to expose the problem.

\[ \text{uniform string} \;\Rightarrow\; \text{pumping may stay inside } L \]

51. Where does each piece belong: Applications of the Pumping Lemma

Sorting

Sort into buckets

These are the pieces of Applications of the Pumping Lemma, out of order. Put each one back under the part of the lesson it belongs to.

The Canonical Proof
The template, restated; The matched-counts language; Why this string is the right one
Counting Languages
Counting conditions and what breaks them; Equal zeros and ones, in any order; A count against a fixed multiple
Shape Languages
Conditions about structure rather than count; The palindromes; The marker trick
s1
The Canonical Proof is where Applications of the Pumping Lemma puts The template, restated, The matched-counts language, Why this string is the right one. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.
s2
Counting Languages is where Applications of the Pumping Lemma puts Counting conditions and what breaks them, Equal zeros and ones, in any order, A count against a fixed multiple. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.
s3
Shape Languages is where Applications of the Pumping Lemma puts Conditions about structure rather than count, The palindromes, The marker trick. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.

52. State the rule before it runs: A string followed by itself

Hypothesis

Predict first

A string followed by itself is about to be worked. State your hypothesis first: which rule or definition decides this one, and what is the first move it forces? Then watch whether the example agrees with you.

Correct: Choose a string that resists an easy repair

Why: Take a block of p a's followed by a b, written twice. The whole string is in the language by construction.

A hypothesis you wrote down is falsifiable; a vague sense of how it will go is not. If the example opens somewhere else, that gap is the thing worth chasing.

53. A string followed by itself

Worked example

Prove that the strings consisting of some block written twice are not regular.

\[ L = \{\, ww : w \in \{a,b\}^{*} \,\} \]

Choose a string that resists an easy repair

Why: Take a block of p a's followed by a b, written twice. The whole string is in the language by construction.

\[ s = a^{p}b\,a^{p}b \]

Pin down the middle

Why: The first p symbols are all a's, so the middle is a nonempty run of a's from the first block.

\[ y = a^{k}, \qquad 1 \le k \le p \]

Pump and inspect the halves

Why: Two copies give p plus k a's, then b, then p a's, then b. The total length is odd in the sense that the two halves can no longer match.

\[ xy^{2}z = a^{p+k}b\,a^{p}b \]

Show no split into two equal halves works

Why: For the string to be in the language it would have to split into two identical halves. The two b's are at positions p plus k plus one and p plus k plus p plus two, so the halves would have to place their b at the same offset — which requires the two a-runs to be equal, and they are not.

Verify the choice of block was necessary

Why: Had the block been a run of a's alone, the pumped string would be a run of a's of some length, and any even-length run of a's is a block written twice. The trailing b in each half is what prevents that escape.

\[ a^{p+k}b\,a^{p}b \notin L \ \checkmark \]

54. A string followed by itself — line by line

Picture it

Animation

Shows: Each line of the worked example "A string followed by itself", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Had the block been a run of a's alone, the pumped string would be a run of a's of some length, and any even-length run of a's is a block written twice. The trailing b in each half is what prevents that escape.

55. Something is wrong here: a string too uniform to expose the problem

Anomaly

Predict first

A student writes this, and it looks reasonable:

Prove the palindromes are not regular.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: Take a run of p copies of a. It is a palindrome, and its length is at least p.

Prove the palindromes are not regular.

Why: Take a run of p copies of a. It is a palindrome, and its length is at least p.

56. Trap: a string too uniform to expose the problem

Trap

The trap

Prove the palindromes are not regular.

Choose the simplest long string

Why: Take a run of p copies of a. It is a palindrome, and its length is at least p.

\[ w = a^{p} \]

Pump it

Why: The middle is a run of a's, and duplicating gives a longer run of a's.

\[ xy^{2}z = a^{p+k} \]

Look for the contradiction and fail to find one

Why: A run of a's of any length reads the same in both directions, so the pumped string is still a palindrome. No contradiction appears, and the proof cannot be completed.

\[ a^{p+k} \in L \quad \text{— no contradiction} \]

The fix

Prove the palindromes are not regular.

Choose a string whose two ends must stay balanced

Why: Insert a marker between two uniform blocks, so that pumping the first block breaks the balance with the second.

\[ w = a^{p}\,b\,a^{p} \]

Pump it

Why: The middle lies in the leading block, so duplicating lengthens that block and leaves the trailing one alone.

\[ xy^{2}z = a^{p+k}\,b\,a^{p} \]

Find the contradiction

Why: The reversal places the longer run after the marker instead of before it, so the pumped string is not a palindrome. The proof closes.

\[ a^{p+k}ba^{p} \notin L \ \checkmark \]

57. Which of these survive contact with Applications of the Pumping Lemma?

Two truths and a lie

Sort into buckets

Some of these hold up and some are the exact mistakes this lesson is built to prevent. Sort them.

Holds up
Every proof in this lesson is the same five sentences from Lesson 10. Only the string and the repetition count change.; Every requirement from the string-choice pattern is met, and it is worth checking them off explicitly this once.; When the condition is an equality, any change breaks it, so the margin question does not arise — which is why matched-count languages are the easiest of all.
Breaks
Prove the matched-counts language is not regular.; Prove the palindromes are not regular.
sound
These are stated as this lesson states them — each one survives the edge cases Applications of the Pumping Lemma puts it through.
flawed
Each of these is lifted from a trap in this deck: reasonable-sounding, and wrong in a way that only shows up once you rely on it.

58. What has to happen first: Balanced brackets

Ranking

Put in order

Put the moves of Balanced brackets into the order they have to happen.

  1. Choose a string that sits exactly on the condition
  2. Pin down the middle
  3. Pump with two copies
  4. State why this language matters
  5. Verify the mismatch for every legal split

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Take p opening brackets followed by p closing brackets.

59. Balanced brackets

Worked example

The language behind every parser, and the reason the next chapters exist.

\[ L = \{\, w : \text{every opening bracket has a matching closing one} \,\} \]

Choose a string that sits exactly on the condition

Why: Take p opening brackets followed by p closing brackets. Every opening is matched, so it is in the language.

\[ w = \text{(}^{p}\,\text{)}^{p} \]

Pin down the middle

Why: The first p symbols are all opening brackets, so the middle is a nonempty run of them.

Pump with two copies

Why: The opening count rises and the closing count does not, so some opening bracket is left without a partner.

\[ \text{(}^{p+k}\,\text{)}^{p} \]

State why this language matters

Why: Nested structure — brackets, tags, block delimiters — is the everyday case that finite memory cannot handle. Recognizing it is exactly what the stack machines of Lesson 16 are built for.

Verify the mismatch for every legal split

Why: Since the middle was nonempty, at least one extra opening bracket appears with no closing partner, for every value of k the adversary could choose. So the pumped string is unbalanced and the language is not regular.

\[ k \ge 1 \;\Rightarrow\; \text{(}^{p+k}\text{)}^{p} \notin L \ \checkmark \]

60. Balanced brackets — line by line

Picture it

Animation

Shows: Each line of the worked example "Balanced brackets", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Since the middle was nonempty, at least one extra opening bracket appears with no closing partner, for every value of k the adversary could choose. So the pumped string is unbalanced and the language is not regular.

61. Nested versus flat structure

Concept

The bracket example points at the real dividing line between this chapter and the next.

StructureExampleRegular?
flat, bounded lookbackends in 01yes
flat, modular countingeven lengthyes
nested, unbounded depthbalanced bracketsno
two independent nestingsequal a's, b's and c'sno, and not context-free either

Rows three and four both defeat finite automata, but only row three is handled by the stack machines ahead. That distinction is what Lesson 18's pumping lemma is for.

62. Which is which, by Regular?

Discrimination

Sort into buckets

Sort these by Regular?, from memory, without looking back at Nested versus flat structure. Telling them apart on the spot is the skill; the table is only where the answer happens to be written down.

yes
flat, bounded lookback; flat, modular counting
no
nested, unbounded depth
no, and not context-free either
two independent nestings
g1
Regular? is "yes" for flat, bounded lookback, flat, modular counting — that is what the table on "Nested versus flat structure" records, and it is the single property separating this group from the rest.
g2
Regular? is "no" for nested, unbounded depth — that is what the table on "Nested versus flat structure" records, and it is the single property separating this group from the rest.
g3
Regular? is "no, and not context-free either" for two independent nestings — that is what the table on "Nested versus flat structure" records, and it is the single property separating this group from the rest.

63. Choosing a string for a shape language

Pattern

Shape languages need one more consideration than counting languages, and it is the one the trap illustrates.

  1. Identify which two parts of the string the condition ties together.
  2. Make the first of those parts uniform and at least p long, so the middle lands inside it.
  3. Separate the two parts with a symbol appearing exactly once, so they cannot be reinterpreted.
  4. Check that pumping the first part genuinely breaks the tie to the second.
  5. Confirm that no alternative reading of the pumped string rescues it.

Step five is the one skipped most often. For repetition languages especially, the pumped string can sometimes be re-split into halves in a way that satisfies the condition, and the proof must rule that out.

64. Check yourself: shape languages

Check

Think about what pumping a uniform run produces.

Check your understanding

Why does the string consisting of p copies of a fail as a choice for proving the palindromes irregular?

  • A. Every pumped version is still a palindrome, so no contradiction arises (correct)
  • B. Its length is not at least p
  • C. It is not in the language
  • D. The middle part cannot be pinned down

Answer: A

Why: A run of a single symbol reads the same in both directions no matter how long it is, so lengthening or shortening it produces another member of the language. The proof needs a string whose pumped versions leave the language.

Why B tempts people
Its length is exactly p, which satisfies the requirement of being at least p.
Why C tempts people
It is a palindrome, so it is in the language. Membership is not the problem.
Why D tempts people
The middle is pinned down perfectly — it is a nonempty run of a's. The problem is that pinning it down leads nowhere.

65. Arithmetic Languages

Section

Section 4

66. When zero and two are not enough

Concept

For counting and shape languages, deleting or duplicating the middle part breaks the condition immediately. Arithmetic languages resist that.

If the condition is that the length satisfies some arithmetic property, then pumping changes the length by a multiple of the middle part's size — and the new length may well satisfy the property again by accident.

\[ |xy^{i}z| = |w| + (i-1)|y| \]

So the repetition count must be chosen to land the length strictly between two values the property allows. That takes a small argument rather than a reflex.

67. Guess the shape of the answer: Lengths that are perfect squares

Estimation

Predict first

Prove that the strings whose length is a perfect square are not regular.

Commit before you compute: what does Lengths that are perfect squares come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify no square lies in that gap, and conclude

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. The new length sits strictly between two consecutive perfect squares, and there is no square strictly between them.

68. Lengths that are perfect squares

Worked example

Prove that the strings whose length is a perfect square are not regular.

\[ L = \{\, a^{n^{2}} : n \ge 0 \,\} \]

Choose the string

Why: Take a run of p squared copies of a. Its length is a perfect square, so it is in the language, and p squared is at least p.

\[ w = a^{p^{2}} \]

Pin down the middle

Why: Everything is the same symbol, so the middle is simply a nonempty run of at most p copies.

\[ y = a^{k}, \qquad 1 \le k \le p \]

Pump with two copies and compute the new length

Why: Duplicating adds k symbols, so the length becomes p squared plus k.

\[ |xy^{2}z| = p^{2} + k \]

Trap the new length strictly between consecutive squares

Why: The new length is strictly greater than p squared. It is also at most p squared plus p, which is strictly less than p squared plus twice p plus one — the next square.

\[ p^{2} < p^{2}+k \le p^{2}+p < p^{2}+2p+1 = (p+1)^{2} \]

Verify no square lies in that gap, and conclude

Why: The new length sits strictly between two consecutive perfect squares, and there is no square strictly between them. So the pumped string is outside the language for every legal k, and the contradiction holds.

\[ p^{2} < |xy^{2}z| < (p+1)^{2} \;\Rightarrow\; |xy^{2}z| \text{ is not a square} \ \checkmark \]

69. Lengths that are perfect squares — line by line

Picture it

Animation

Shows: Each line of the worked example "Lengths that are perfect squares", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The new length sits strictly between two consecutive perfect squares, and there is no square strictly between them. So the pumped string is outside the language for every legal k, and the contradiction holds.

70. Why the gap argument works

Intuition

The whole proof turns on one inequality, and it is worth seeing why it is available.

Consecutive squares are p squared and p squared plus twice p plus one, so the gap between them has width twice p plus one. The early-split condition caps the middle part at p symbols, so pumping once can add at most p.

Adding at most p to a square therefore cannot reach the next square, since that would need twice p plus one. The constraint that made the middle part small is exactly the constraint that makes the argument close.

\[ |y| \le p < 2p+1 = \text{gap between consecutive squares} \]

71. Plan first: Lengths that are prime

Step zero

Discussion prompt

Lengths that are prime — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Choose a string

Answer:

  1. Choose a string
  2. Pin down the middle
  3. Choose the repetition count to force a factorization
  4. Check both factors exceed one
  5. Verify the product is composite, and conclude

72. Lengths that are prime

Worked example

A language where a large repetition count is the only route.

\[ L = \{\, a^{n} : n \text{ is prime} \,\} \]

Choose a string

Why: Let p be the pumping length and take a prime n at least as large as p plus one. Use a run of n copies of a.

\[ w = a^{n}, \qquad n \text{ prime}, \; n \ge p+1 \]

Pin down the middle

Why: The string is uniform, so the middle is a nonempty run of at most p copies. Write its length as k.

Choose the repetition count to force a factorization

Why: Take the count to be n plus one. Then the new length is n plus n times k, which factors.

\[ |xy^{n+1}z| = n + n\,k = n(1+k) \]

Check both factors exceed one

Why: The first factor is n, which is at least two since it is prime. The second is one plus k, which is at least two since k is at least one.

Verify the product is composite, and conclude

Why: A product of two factors each at least two is composite, so the pumped string's length is not prime and the string is outside the language. The contradiction holds for every legal split.

\[ n \ge 2, \; 1+k \ge 2 \;\Rightarrow\; n(1+k) \text{ composite} \ \checkmark \]

73. Lengths that are prime — line by line

Picture it

Animation

Shows: Each line of the worked example "Lengths that are prime", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The first factor is n, which is at least two since it is prime. The second is one plus k, which is at least two since k is at least one.

74. Lengths that are powers of two

Worked example

A third arithmetic case, with the same gap technique as the squares but a much wider gap.

\[ L = \{\, a^{2^{n}} : n \ge 0 \,\} \]

Choose the string

Why: Take a run whose length is a power of two at least as large as p. Such a power exists because the powers grow without bound.

\[ w = a^{m}, \qquad m = 2^{n} \ge p \]

Pin down the middle

Why: The string is uniform, so the middle is a nonempty run of at most p copies, and p is at most m.

\[ 1 \le k \le p \le m \]

Pump with two copies and bound the new length

Why: The new length is m plus k. It exceeds m, and since k is at most m it is at most twice m.

\[ m < m + k \le 2m \]

Exclude the endpoint

Why: The new length equals twice m only when k equals m, which would require the middle part to be the entire string — possible only if the first part is empty and the middle is everything, and then k equals m is allowed. Handle it by choosing the string longer than p, so that k is at most p which is strictly less than m.

\[ k \le p < m \;\Rightarrow\; m < m+k < 2m \]

Verify no power of two lies strictly between consecutive ones

Why: The next power after m is twice m, and the new length lies strictly between them. So it is not a power of two, the pumped string is outside the language, and the contradiction holds for every legal split.

\[ m < |xy^{2}z| < 2m \;\Rightarrow\; |xy^{2}z| \text{ is not a power of two} \ \checkmark \]

75. Lengths that are powers of two — line by line

Picture it

Animation

Shows: Each line of the worked example "Lengths that are powers of two", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The next power after m is twice m, and the new length lies strictly between them. So it is not a power of two, the pumped string is outside the language, and the contradiction holds for every legal split.

76. Choosing the repetition count algebraically

Intuition

The prime proof did something the earlier ones did not: it picked the count to make the resulting length factor.

The general move is to write the pumped length as a formula in the count, then choose the count so the formula visibly fails the property — by factoring, by landing in a gap, or by matching a forbidden residue.

\[ |xy^{i}z| = |x| + i|y| + |z| \]

Property of the lengthCount to choose
a perfect squaretwo — land inside the gap
primethe length itself plus one — force a factorization
a power of twotwo — land strictly between powers
equal to another countzero or two — any change suffices

77. How sure are you: Check yourself: arithmetic languages

Commit first

Predict first

In the perfect-squares proof, why can pumping once never reach the next square?

Commit to an answer, then rate it — certain, fairly sure, or guessing — and write the rating down before you turn the page.

Correct: The middle part is at most p long, and the gap between consecutive squares exceeds p

Why: The early-split condition caps the middle part at p symbols, so one duplication adds at most p. The gap from p squared to the next square is twice p plus one, which is strictly larger, so the new length lands strictly inside the gap.

The rating matters as much as the answer: confident-and-wrong is the combination that survives revision, because nothing about it feels like it needs revisiting.

78. Check yourself: arithmetic languages

Check

Think about how much pumping once can add.

Check your understanding

In the perfect-squares proof, why can pumping once never reach the next square?

  • A. The middle part is at most p long, and the gap between consecutive squares exceeds p (correct)
  • B. The middle part must have length exactly one
  • C. Squares are always even, so adding an odd amount fails
  • D. The pumped length is always smaller than the original

Answer: A

Why: The early-split condition caps the middle part at p symbols, so one duplication adds at most p. The gap from p squared to the next square is twice p plus one, which is strictly larger, so the new length lands strictly inside the gap.

Why B tempts people
The middle may be any nonempty length up to p. The argument works for all of them precisely because it uses only the upper bound.
Why C tempts people
Squares are not always even — nine and twenty-five are odd. Parity plays no role in this proof.
Why D tempts people
Duplicating makes the string longer, not shorter. Deleting would make it shorter, and that case needs its own gap argument.

79. When Pumping Is the Wrong Tool

Section

Section 5

80. What has to be given first: A string followed by its reversal

Missing information

Discussion prompt

The mirror-image relative of the repeated-block language, and it needs the same marker trick.

What do you need to know — or decide — before the first line can be written? List everything the problem has to hand you.

Hint: Anything you would have to invent to get started is a thing the problem must supply.

Answer:

Take p a's, then a b, then a b, then p a's. That is the block of p a's followed by a b, written and then mirrored.

81. A string followed by its reversal

Worked example

The mirror-image relative of the repeated-block language, and it needs the same marker trick.

\[ L = \{\, w\,w^{R} : w \in \{a,b\}^{*} \,\} \]

Choose a string sitting exactly on the condition

Why: Take p a's, then a b, then a b, then p a's. That is the block of p a's followed by a b, written and then mirrored.

\[ s = a^{p}b\,b\,a^{p} \]

Pin down the middle

Why: The first p symbols are all a's, so the middle is a nonempty run of a's from the leading block.

Pump and check the mirror condition

Why: Two copies lengthen the leading run of a's while leaving the trailing run alone, so the string no longer mirrors about its centre.

\[ a^{p+k}b\,b\,a^{p} \]

Rule out an alternative reading

Why: For the pumped string to be in the language it would have to split into some block and that block reversed. The two b's sit adjacent at a position no longer central, so no such split exists.

Verify the doubled marker was necessary

Why: With a single b the string would have odd length and could never be a block followed by its reversal at all, so it would not be in the language to begin with. Doubling the marker keeps the length even and places it exactly at the centre, which is what makes the string a legitimate member.

\[ a^{p+k}bba^{p} \notin L \ \checkmark \]

82. A string followed by its reversal — line by line

Picture it

Animation

Shows: Each line of the worked example "A string followed by its reversal", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: With a single b the string would have odd length and could never be a block followed by its reversal at all, so it would not be in the language to begin with. Doubling the marker keeps the length even and places it exactly at the centre, which is what makes the string a legitimate member.

83. Marker placement is part of the design

Concept

Three shape proofs have now used a marker, and each placed it differently. The placement is not arbitrary.

LanguageMarkerWhy there
palindromesone symbol at the centrekeeps the string symmetric and odd-length
a block written twiceone symbol ending each halfmakes the half-boundary identifiable
a block then its reversaltwo adjacent symbols at the centrekeeps the length even and centres the mirror

In every case the marker must leave the string inside the language while making the two tied parts impossible to confuse. Getting the first half right and the second half wrong is the usual failure.

84. Fill in: Why there for Marker placement is part of the design

Comparison

Comparison matrix

From Marker placement is part of the design: refill the Why there column from what you know. The rest of the table is as it appeared.

LanguageMarkerWhy there
palindromesone symbol at the centrekeeps the string symmetric and odd-length
a block written twiceone symbol ending each halfmakes the half-boundary identifiable
a block then its reversaltwo adjacent symbols at the centrekeeps the length even and centres the mirror

85. Closure arguments are often shorter

Concept

Once one non-regular language is established, Lesson 7's closure properties multiply it cheaply, and the resulting proofs are often three lines.

The move: assume the candidate is regular, intersect it with a simple regular language to expose a known non-regular one, and take the contradiction.

\[ L \cap R = N, \; R \text{ regular}, \; N \text{ not regular} \;\Rightarrow\; L \text{ not regular} \]

This needs no string choice, no split analysis and no repetition count. When a closure argument is available it is almost always the better proof.

86. Guess the shape of the answer: Prove a language irregular by closure instead

Estimation

Predict first

Take a language where a direct pumping proof is fiddly and a closure argument is immediate.

Commit before you compute: what does Prove a language irregular by closure instead come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify the intersection equality in both directions

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. Any string in the intersection has equal counts and zeros first, so it has the matched form; and any matched string has equal counts and zeros first, so it is in the intersection.

87. Prove a language irregular by closure instead

Worked example

Take a language where a direct pumping proof is fiddly and a closure argument is immediate.

\[ L = \{\, w \in \{0,1\}^{*} : \#_0(w) = \#_1(w) \,\} \]

Assume the candidate is regular

Why: For contradiction, suppose some machine recognizes it.

Choose a regular helper that isolates a known shape

Why: Take the strings with all zeros before all ones. A three-state machine recognizes it, so it is regular.

\[ R = 0^{*}1^{*} \]

Compute the intersection

Why: A string with equal counts whose zeros all precede its ones is exactly a matched-counts string.

\[ L \cap R = \{\, 0^{n}1^{n} : n \ge 0 \,\} \]

Invoke closure and take the contradiction

Why: The regular languages are closed under intersection, so the result would have to be regular. It is not, by Section 1. So the assumption fails.

Verify the intersection equality in both directions

Why: Any string in the intersection has equal counts and zeros first, so it has the matched form; and any matched string has equal counts and zeros first, so it is in the intersection. Getting this equality exactly right is where closure proofs usually go wrong, and here both inclusions are immediate.

\[ L \cap R = \{0^{n}1^{n}\} \ \checkmark \]

88. Prove a language irregular by closure instead — line by line

Picture it

Animation

Shows: Each line of the worked example "Prove a language irregular by closure instead", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Any string in the intersection has equal counts and zeros first, so it has the matched form; and any matched string has equal counts and zeros first, so it is in the intersection. Getting this equality exactly right is where closure proofs usually go wrong, and here both inclusions are immediate.

89. Without one step: Choosing between pumping and closure

Constraint

Discussion prompt

Run Choosing between pumping and closure with this step confiscated:

Is it the first irregular language of its kind? Use pumping — closure has nothing to build on.

Is it still possible? If it is, say what takes its place and what it costs you. If it is not, say exactly what that step was providing that nothing else does.

Hint: A step you can drop for free was never load-bearing. If you cannot drop it, name the thing that goes wrong the moment it is gone.

Answer:

  1. Is the language a small variation on one already known irregular? Use closure.
  2. Can a simple regular pattern intersect it down to a known case? Use closure.
  3. Is it the first irregular language of its kind? Use pumping — closure has nothing to build on.
  4. Does pumping resist because the language is too loose? Try closure, then distinguishable prefixes.
  5. Is the condition arithmetic? Use pumping with an algebraically chosen count.

90. Choosing between pumping and closure

Pattern

A quick decision procedure, worth running before writing anything.

  1. Is the language a small variation on one already known irregular? Use closure.
  2. Can a simple regular pattern intersect it down to a known case? Use closure.
  3. Is it the first irregular language of its kind? Use pumping — closure has nothing to build on.
  4. Does pumping resist because the language is too loose? Try closure, then distinguishable prefixes.
  5. Is the condition arithmetic? Use pumping with an algebraically chosen count.

The third line is the reason Lesson 10 exists at all. Closure arguments are derivative; something has to be proved from scratch first, and the pumping lemma is what does it.

91. Where does it stop working: Choosing between pumping and closure

Edge cases

Discussion prompt

Choosing between pumping and closure works on the cases you have just seen. Push it to the edge: what is the most degenerate input it still handles — empty, zero, one item, everything equal — and what is the first case where it stops being true? Name the case, not just "it breaks".

Hint: Try the smallest legal input, then the largest, then the one where two things collide. Methods are specified at their edges; the middle takes care of itself.

Answer:

A quick decision procedure, worth running before writing anything.

92. A language that pumps but is not regular

Concept

The pumping lemma is a one-way implication, and here is the language that proves the converse genuinely fails.

Consider the strings over a three-symbol alphabet that either begin with the symbol c and are otherwise unconstrained, or contain no c at all and have equal counts of a and b.

\[ L = \{\, c\,x : x \in \Sigma^{*} \,\} \;\cup\; \{\, w \in \{a,b\}^{*} : \#_a(w) = \#_b(w) \,\} \]

Every sufficiently long string of this language satisfies the pumping condition, because the first branch is so permissive that a valid split always exists. Yet the language is not regular, since the second branch requires unbounded counting.

So exhibiting a valid split proves nothing. Only failure to pump is informative, exactly as Lesson 10's trap warned.

93. Plan first: Handle it with distinguishable prefixes instead

Step zero

Discussion prompt

Handle it with distinguishable prefixes instead — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Find an infinite family of candidate prefixes

Answer:

  1. Find an infinite family of candidate prefixes
  2. Show any two of them are distinguishable
  3. Check the separating string does its job
  4. Apply the counting argument
  5. Verify the family really is pairwise distinguishable

94. Handle it with distinguishable prefixes instead

Worked example

When pumping is silent, the Myhill-Nerode argument from Lesson 6 still works, because it is a genuine characterization.

Find an infinite family of candidate prefixes

Why: Take the strings consisting of some number of a's, one family member per count.

\[ u_i = a^{i}, \qquad i = 0, 1, 2, \dots \]

Show any two of them are distinguishable

Why: Take two with different counts. Append the matching number of b's for the first one.

\[ z = b^{i}, \qquad u_i z \in L, \; u_j z \notin L \text{ for } j \neq i \]

Check the separating string does its job

Why: The first extension has equal counts and no c, so it is in the language. The second has unequal counts and no c, so it is not.

Apply the counting argument

Why: Pairwise distinguishable prefixes can never share a state, so a machine would need at least as many states as there are family members — and there are infinitely many.

\[ \text{infinitely many distinguishable prefixes} \;\Rightarrow\; \text{no finite } Q \]

Verify the family really is pairwise distinguishable

Why: For any two distinct counts, the separating string built from the smaller one sends exactly one of the two extensions into the language. So every pair is separated, not merely consecutive pairs, and the conclusion follows.

\[ \forall i \neq j \; \exists z : \text{exactly one of } u_iz, u_jz \in L \ \checkmark \]

95. Handle it with distinguishable prefixes instead — line by line

Picture it

Animation

Shows: Each line of the worked example "Handle it with distinguishable prefixes instead", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The first extension has equal counts and no c, so it is in the language. The second has unequal counts and no c, so it is not.

96. Three tools, in order of preference

Intuition

Collected, so the choice is automatic.

ToolUse whenCost
closure argumenta known irregular language is one intersection awaythree lines
pumping lemmathe language is a fresh case with a tight conditionfive sentences
distinguishable prefixespumping is silent, or an exact state count is wantedan infinite family plus separators

Try them in that order. The last one always works but takes the most writing, so it is the fallback rather than the default.

97. Answer it before you see the options: Check yourself: choosing the tool

Prediction

Predict first

You verify that every long string of some language can be pumped. What follows?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: Nothing — the lemma only says regular implies pumpable

Why: The lemma is a one-way implication, and its only legitimate use is the contrapositive: failure to pump proves irregularity. Successful pumping is consistent with both regular and irregular languages, and this lesson exhibits an irregular language that pumps.

98. Check yourself: choosing the tool

Check

Recall which implication the pumping lemma states.

Check your understanding

You verify that every long string of some language can be pumped. What follows?

  • A. Nothing — the lemma only says regular implies pumpable (correct)
  • B. The language is regular
  • C. The language is not regular
  • D. The language is finite

Answer: A

Why: The lemma is a one-way implication, and its only legitimate use is the contrapositive: failure to pump proves irregularity. Successful pumping is consistent with both regular and irregular languages, and this lesson exhibits an irregular language that pumps.

Why B tempts people
This is the classic misreading. Non-regular languages satisfying the pumping condition exist, so the inference is invalid.
Why C tempts people
Pumping successfully is evidence in the opposite direction, if anything. It certainly does not establish irregularity.
Why D tempts people
Finiteness is unrelated. Most regular languages are infinite, and all of them pump.

99. Diagnosis and Catalogue

Section

Section 6

100. Diagnosing a failed attempt

Concept

A proof that will not close is usually failing for one of four identifiable reasons.

SymptomCauseFix
pumped string is still in the languagestring too uniformadd a marker between the tied parts
cannot say what the middle containsprefix not uniformput p copies of one symbol first
the condition still holds after pumpingmargin too loosemake the condition as tight as allowed
every string seems to work for the adversarythe language may be regulartry to build a machine instead

The last row is worth taking seriously rather than pushing harder. A genuine machine is the fastest way to find out that no pumping proof exists.

101. What each one costs: Diagnosing a failed attempt

Trade off

Comparison matrix

From Diagnosing a failed attempt: every row here is a choice with a cost. Fill the Cause column, then say which row you would actually pick and what you give up for it.

SymptomCauseFix
pumped string is still in the languagestring too uniformadd a marker between the tied parts
cannot say what the middle containsprefix not uniformput p copies of one symbol first
the condition still holds after pumpingmargin too loosemake the condition as tight as allowed
every string seems to work for the adversarythe language may be regulartry to build a machine instead

102. What has to happen first: Diagnose and repair a failing attempt

Ranking

Put in order

Put the moves of Diagnose and repair a failing attempt into the order they have to happen.

  1. Try the obvious string
  2. Watch the attempt fail
  3. Repair by choosing a string that engages the condition
  4. Verify the repaired proof closes

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Take p copies of c. It has zero a's and zero b's, so the counts match and it is in the language.

103. Diagnose and repair a failing attempt

Worked example

Work through a repair, on the language of strings with equally many a's and b's over a three-symbol alphabet including c.

Try the obvious string

Why: Take p copies of c. It has zero a's and zero b's, so the counts match and it is in the language.

\[ w = c^{p} \]

Watch the attempt fail

Why: The middle is a nonempty run of c's, and pumping produces another run of c's — which still has zero a's and zero b's, so it is still in the language.

\[ c^{p+k} \in L \quad \text{— no contradiction} \]

Diagnose

Why: The string is too uniform in the wrong way: it satisfies the condition trivially, so changing its length cannot break it. The chosen symbols do not participate in the condition at all.

Repair by choosing a string that engages the condition

Why: Take p copies of a followed by p copies of b. The counts match, the prefix is uniform, and the two blocks are tied together by the condition.

\[ w = a^{p}b^{p} \]

Verify the repaired proof closes

Why: The middle is a nonempty run of a's, and pumping adds a's without adding b's, so the counts differ. The repaired string engages the condition and the contradiction follows for every legal split.

\[ a^{p+k}b^{p} \notin L \ \checkmark \]

104. Diagnose and repair a failing attempt — line by line

Picture it

Animation

Shows: Each line of the worked example "Diagnose and repair a failing attempt", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The middle is a nonempty run of a's, and pumping adds a's without adding b's, so the counts differ. The repaired string engages the condition and the contradiction follows for every legal split.

105. The string must engage the condition

Intuition

The repair above illustrates the single most useful diagnostic question: does my string actually exercise the property that makes this language hard?

A string satisfying the condition trivially — zero of everything, or a uniform run — cannot be broken by pumping, because there is nothing to break. The string must sit at a point where the condition is delicately balanced.

For counting languages that means equal nonzero counts; for shape languages it means two blocks tied across a marker; for arithmetic languages it means a length sitting exactly on the property.

\[ \text{trivially satisfied} \;\Rightarrow\; \text{pumping cannot break it} \]

106. Rule out three: Check yourself: diagnosing a failure

Elimination

Eliminate the wrong options

Your pumped string keeps landing back inside the language. What is the most likely cause?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. The chosen string satisfies the condition too easily, so changing it breaks nothing
  • B. The pumping length is too large
  • C. You used the wrong repetition count and should try one
  • D. The lemma does not apply to this language

Survives elimination: A

Why: A string that meets the condition trivially — a uniform run, or one with zero of the relevant symbols — has no delicate balance to disturb. The repair is to choose a string sitting exactly on the condition, with the tied parts separated so pumping breaks the tie.

107. Check yourself: diagnosing a failure

Check

Match the symptom to its cause.

Check your understanding

Your pumped string keeps landing back inside the language. What is the most likely cause?

  • A. The chosen string satisfies the condition too easily, so changing it breaks nothing (correct)
  • B. The pumping length is too large
  • C. You used the wrong repetition count and should try one
  • D. The lemma does not apply to this language

Answer: A

Why: A string that meets the condition trivially — a uniform run, or one with zero of the relevant symbols — has no delicate balance to disturb. The repair is to choose a string sitting exactly on the condition, with the tied parts separated so pumping breaks the tie.

Why B tempts people
The pumping length is the adversary's move and cannot be influenced. A correct proof works for every value of it.
Why C tempts people
A repetition count of one reproduces the original string, which is in the language by construction, so it can never yield a contradiction.
Why D tempts people
The lemma applies to every language — it just says nothing useful when the language is regular, or when the chosen string is poor.

108. What a failed proof does and does not tell you

Intuition

A proof that will not close is information, but it is weaker information than it feels.

It does not show the language is regular. The lemma is one-way, so a failure to find a breaking string is consistent with an irregular language that pumps, or simply with a poor choice of string.

What it should trigger is the diagnostic table: try a marker, tighten the margin, engage the condition. If three genuinely different strings all fail, the useful next move is to spend ten minutes trying to build a machine — succeeding settles the question, and failing usually reveals the unbounded quantity you need.

\[ \text{proof fails} \;\not\Rightarrow\; \text{language regular} \]

109. Teach it back: What a failed proof does and does not tell you

Explain it

Discussion prompt

Explain What a failed proof does and does not tell you to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

A proof that will not close is information, but it is weaker information than it feels.

110. The catalogue

Concept

The standard examples, with the choices that make each proof work. Worth memorizing the middle column.

LanguageString to chooseCount
matched countsp zeros then p oneszero or two
equal counts, any orderp zeros then p oneszero or two
more ones than zerosp zeros then p plus one onestwo
palindromesp a's, one b, p a'stwo
a block written twicep a's, b, p a's, btwo
length a perfect squarep squared copiestwo, with a gap argument
length primea prime run at least p plus onethe length plus one

111. Fill in: String to choose for The catalogue

Comparison

Comparison matrix

From The catalogue: refill the String to choose column from what you know. The rest of the table is as it appeared.

LanguageString to chooseCount
matched countsp zeros then p oneszero or two
equal counts, any orderp zeros then p oneszero or two
more ones than zerosp zeros then p plus one onestwo
palindromesp a's, one b, p a'stwo
a block written twicep a's, b, p a's, btwo
length a perfect squarep squared copiestwo, with a gap argument
length primea prime run at least p plus onethe length plus one

112. Rebuild the recipe: The complete procedure

Ranking

Put in order

These are the steps of The complete procedure, scrambled. Put them back in order before the next slide shows you.

  1. Classify: what must be remembered, and is it bounded? If bounded, build a machine.
  2. Look for a closure argument against a language already known irregular.
  3. Otherwise choose a string built from p, uniform in its first p symbols, engaging the condition tightly.
  4. Derive the middle part's composition from the early-split condition.
  5. Choose a repetition count, algebraically if the condition is arithmetic, and state the contradiction.

Why: This is the order the recipe itself gives. Recalling the sequence without the slide in front of you is the difference between recognising the method and being able to run it — most of what goes wrong in practice is a step done out of turn.

113. The complete procedure

Pattern

Everything from Lessons 10 and 11, as one routine.

  1. Classify: what must be remembered, and is it bounded? If bounded, build a machine.
  2. Look for a closure argument against a language already known irregular.
  3. Otherwise choose a string built from p, uniform in its first p symbols, engaging the condition tightly.
  4. Derive the middle part's composition from the early-split condition.
  5. Choose a repetition count, algebraically if the condition is arithmetic, and state the contradiction.

If step three cannot produce a string that engages the condition, the language may pump despite being irregular — fall back to distinguishable prefixes.

114. Where this shows up: Applications of the Pumping Lemma

Real world

Discussion prompt

Outside this lesson: where does Applications of the Pumping Lemma actually turn up? Name one concrete situation — a job, a piece of software someone ships, a decision somebody has to make — and say which part of The complete procedure is doing the work in it.

Hint: Vague is the failure mode here. "Engineering" is not a situation; "deciding whether this build is fast enough to ship" is.

Answer:

Lesson 11 is a worked catalogue of non-regularity proofs. It gives the canonical matched-counts proof and the trap of choosing your own split, then counting languages and the line between bounded and unbounded quantities, and shape languages such as palindromes and repeated blocks, handled with the marker trick. It works arithmetic languages that need gap and factorization arguments, for the perfect squares and for the primes, and shows closure arguments as the shorter alternative. It ends with a language that pumps yet is not regular, together with the distinguishable-prefix fallback, and a diagnostic table for repairing failed attempts.

115. Why the same argument keeps working

Intuition

Seven languages, one argument. It is worth naming what they all have in common.

In every case the machine must carry a quantity from an early part of the string to a later part — a count, a block, a length. The early-split condition forces the cycle into that early part, and pumping corrupts what was being carried.

So the proofs are not seven tricks but one: put the thing that must be remembered inside the first p symbols, and let the lemma damage it. Choosing the string well is entirely a matter of arranging that.

\[ \text{what must be carried} \;\subseteq\; \text{first } p \text{ symbols} \]

116. By analogy: Why the same argument keeps working

Analogy

Discussion prompt

Explain Why the same argument keeps working by analogy to something with no Theory of Computation in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

Seven languages, one argument. It is worth naming what they all have in common.

117. What this closes, and what opens next

Concept

With this lesson the regular languages are fully mapped: four ways to show membership, three ways to show non-membership.

The natural next question is what a machine would need in order to recognize the matched-counts language. The answer is an unbounded memory with a restricted discipline — a stack — and that is the model of Lessons 13 to 19.

Those machines recognize the matched-counts language easily, and they have their own pumping lemma with its own catalogue of languages beyond reach. The pattern of this lesson repeats one level up.

\[ \text{regular} \;\subsetneq\; \text{context-free} \;\subsetneq\; \cdots \]

118. Break it if you can: What this closes, and what opens next

Counterexample

Discussion prompt

With this lesson the regular languages are fully mapped: four ways to show membership, three ways to show non-membership.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

119. Connect it up: Applications of the Pumping Lemma

Connect it up

Draw it

One page, no notation unless you need it: draw how these connect — The Canonical Proof · Counting Languages · Shape Languages · Arithmetic Languages · When Pumping Is the Wrong Tool · Diagnosis and Catalogue. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.

120. What you can do now

Recap

You can prove languages irregular fluently, and you know which of three tools to reach for.

SituationMove
two counts must matchp of each, pump by zero or two
the string must be symmetricuniform block, marker, uniform block
the length must satisfy arithmeticchoose the count to land in a gap or force a factor
a known irregular language is nearbyintersect with a simple pattern
pumping succeeds but the language feels irregulardistinguishable prefixes

Lesson 12 looks at some surprising positive results about regular languages before the course moves on to grammars in Lesson 13.

Sources

  1. Sipser, Introduction to the Theory of Computation, 3rd ed., Ch. 1.4, Examples 1.73-1.77 (Non-regular languages) — Cengage, 2013.
  2. Hopcroft, Motwani & Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Ch. 4.1-4.2 (Applications of the pumping lemma and closure) — Pearson, 2007.
  3. Nerode, 'Linear automaton transformations', Proceedings of the AMS 9 (the distinguishable-prefix characterization) — AMS, 1958.
  4. Lewis & Papadimitriou, Elements of the Theory of Computation, 2nd ed., Ch. 2.4 — Prentice Hall, 1998.
  5. Every string choice, split analysis and arithmetic bound in this deck was checked by hand, including the gap argument for squares and the factorization for primes. — Verified 2026-08-03.

Want this taught 1-on-1? Alexander tutors Theory of Computation — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108