Exercise

Pumping Lemma Game: Refuting Regularity

A game for practicing the pumping lemma for regular languages: choose a word, let the adversary split it, and see whether you can pump it out of the language.

Last updated:


Which word makes the adversary lose?

The pumping lemma is a necessary condition that every regular language satisfies.
Using it to refute regularity is a game with alternating moves:

If L is regular, there is N∈N+ such that for every word w∈L with ∣w∣≥Nthere is a split w=xyz with ∣y∣>0, ∣xy∣≤N and ∀i≥0 ⁣: xyiz∈L.\begin{aligned} &\text{If } L \text{ is regular, there is } N\in\mathbb{N}^+ \text{ such that for every word } w\in L \text{ with } |w|\geq N\\ &\text{there is a split } w=xyz \text{ with } |y|>0,\ |xy|\leq N \text{ and } \forall i\geq 0\!:\ xy^iz\in L. \end{aligned}

To refute regularity you play against that claim:

  1. The adversary announces the number NN⁠. You do not know it, so your word must be written as a formula in NN⁠.
  2. You choose a word w∈Lw\in L with ∣w∣≥N|w|\geq N⁠.
  3. The adversary chooses a split w=xyzw=xyz with ∣y∣>0|y|>0 and ∣xy∣≤N|xy|\leq N⁠, the hardest one for you.
  4. You choose ii so that xyiz∉Lxy^iz\notin L⁠.

You win if your word beats every split the adversary may choose.
Then the assumption that LL is regular leads to a contradiction.

Play

Choose a language, type a word in mathematical notation, and predict the result before you check.
The word may contain only letters of the language’s alphabet and the pumping length NN (inside exponents).
The adversary chooses NN⁠, so you do not. A word that beats the page’s tests is strong evidence, not a proof.
The proof is the written argument, which works for every NN at once.

What the page tests

The page tests your word for many values of NN⁠, from 3 up to 1,000,000, because a good word must work for every NN⁠.
For each NN it tries the exponents i=0,…,4i=0,\dots,4 on the splits:
all of them for small NN⁠, and for large NN every split near the place where one run of equal letters ends and the next begins (for example between the aa‘s and the bb‘s) plus a random sample.

How to write the word

Write the word with the letters of the alphabet, side by side, and use NN only in exponents.
An exponent is written after ^: a number, N, or an expression in braces.
Spaces are ignored.

  • a^N b^N: aNbNa^Nb^N
  • a^{N+1} b^N: aN+1bNa^{N+1}b^N
  • a^{2N}, a^{N^2}: a2Na^{2N}⁠, aN2a^{N^2}
  • (ab)^N: the word abab repeated NN times
  • ε: the empty word

The game needs JavaScript. Use the questions below instead.

Try to win on every language in the list.

Build the proof

In an exam you must write the proof, not only find a good word.
Here the proof is built step by step. Each step has a field, the page checks it, and when all the steps are right the page writes the proof for you.
Steps 1 and 2 are always the same, steps 3 to 5 are yours. Note that here you choose one ii that works for every split; in general the lemma allows ii to depend on the split, so this is a simplified format that suits words like aNbNa^Nb^N⁠.

This part needs JavaScript. Use the written proof below the game.

Questions

Question 1. In the language {anbn∣n∈N}\{a^nb^n\mid n\in\mathbb{N}\} with the word aNbNa^Nb^N⁠, why can yy contain only aa‘s?

Hint

Which part of the word do the first NN letters cover, and what does the condition ∣xy∣≤N|xy|\leq N say about where yy ends?

Answer

The first NN letters of aNbNa^Nb^N are all aa‘s, and xyxy lies inside them because ∣xy∣≤N|xy|\leq N⁠.
So y=aky=a^k with 1≤k≤N1\leq k\leq N⁠, and pumping changes only the number of aa‘s.

Question 2. For the language of words with equally many aa‘s and bb‘s, why does the word (ab)N(ab)^N not beat the adversary?

Hint

Look for a split where yy itself contains equally many aa‘s and bb‘s.

Answer

Take x=εx=\varepsilon and y=aby=ab⁠. Pumping gives (ab)N−1+i(ab)^{N-1+i}⁠, which always has equally many aa‘s and bb‘s, so it stays in the language for every ii⁠.
The adversary wins with this split. (This needs N≥2N\geq 2 so that ∣xy∣=2≤N|xy|=2\leq N⁠. If the lemma gives N=1N=1⁠, any larger number also works as the pumping length, so we may assume N≥2N\geq 2⁠.)

Question 3. Can you refute the regularity of {aibj∣i,j≥0}\{a^ib^j\mid i,j\geq 0\} with the pumping lemma?

Answer

No, because this language is regular: a deterministic finite automaton with three states (one of them a trap state) recognizes it.
The pumping lemma is only a necessary condition, and a regular language satisfies it, so no choice of word can defeat the adversary.

A written proof for {anbn}\{a^nb^n\}

Assume, for contradiction, that L={anbn∣n∈N}L=\{a^nb^n\mid n\in\mathbb{N}\} is regular. Then the pumping lemma holds for some NN⁠.
Choose w=aNbN∈Lw=a^Nb^N\in L with ∣w∣≥N|w|\geq N⁠. For every split w=xyzw=xyz with ∣y∣>0|y|>0 and ∣xy∣≤N|xy|\leq N⁠, we have y=aky=a^k for some 1≤k≤N1\leq k\leq N⁠, because ∣xy∣≤N|xy|\leq N and the first NN letters of ww are all aa‘s.
For i=2i=2 the word xy2z=aN+kbNxy^2z=a^{N+k}b^N has more aa‘s than bb‘s, so it is not in LL⁠.
This contradicts the lemma, so LL is not regular.

Back to Combining Automata: Complement and Product, or see the glossary.