Every regular language can be pumped, i.e., any string in the language that is long enough can be made even longer or have some part chopped off, and still be in the language.
To prove that a language is not regular, we show that it can’t be pumped, i.e., it contains some long string that no longer belongs to the language when made longer or when some of its part is chopped off.
Theorem. The language \(A=\{ a^iba^i : i\ge 0\}\) is not regular.
Proof. Suppose for the sake of contradiction that \(A\) is regular and let \(M\) be a DFA accepting \(A\). Let \(M\) have \(p\) states. Consider the string \(a^pba^p\in A\). Let \(P\) be the \(a^p\)-path from the start state \(q_0\), ending in some state \(q_1\). Path \(P\) contains more than \(p\) states; therefore, it repeats some state. This means that \(P\) contains a closed walk of length \(\ell > 0\). Thus the \(a^{p+\ell}\)-path also goes from the start state \(q_0\) to the state \(q_1\). Therefore, \(a^{p+\ell}ba^p\in A\), a contradiction. \[\tag*{$\Box$}\]
The foregoing proof is an example of a pumping up argument. Instead of considering the \(a^{p+\ell}\)-path, we could also consider the \(a^{p-\ell}\)-path to get a contradiction. This is called pumping down.
The foregoing proof makes use of an important characteristic of all DFA’s: they have a finite number of states. If \(w\) is any string in the language that’s at least as long as the number of states, then the path the DFA traces as it processes \(w\) is bound to repeat some state. So this path contains a closed walk. This closed walk can either be removed or repeated any positive number of times to give more strings in the language. In fact, the closed walk appears quite early in this \(w\)-path, i.e., within the prefix subpath no longer than the number of states of the DFA. The following lemma states this fact formally.
Theorem. Any regular language \(A\) has a positive integer constant \(p\) such that any string \(w\) of length at least \(p\) can be written as \(w=xyz\) so that all the following statements hold:
Prove that the language \(\{ a^n \in \{a\}^* : n \textrm{ is a perfect square} \}\) is not regular by pumping up.
Prove the previous exercise by pumping down.
Prove that the language \(\{ a^p \in \{a\}^* : p \textrm{ is prime } \}\) is not regular.
Prove that the language \(\{ w \in \{a, b\}^* : |w|_a > |w|_b \}\) is not regular.
Prove that the language \(\{\, w \in \{a,b\}^* : |w|_a \ne |w|_b \,\}\) is not regular.