...

/

Nonregular Languages

Nonregular Languages

Learn to use the pumping theorem to prove a language is nonregular.

Examples of nonregular languages

We’ll use the pumping theorem to prove that the following languages are not regular:

  • The language Lab=anbnL_{ab}=a^nb^n.
  • The language of palindromes.
  • The language of repeated halves, {ww    w(a+b)}\{ww \;|\; w \in (a+b)^*\}.
  • The language over Σ={(,)}\Sigma=\{(,)\} of balanced parentheses.
  • The language {ambn    m>n}\{a^mb^n \;|\; m > n\}.
  • The language PRIME = {an}\{a^n\}, where nn is a prime number.
  • The language {an2    n>0}\{a^{n^2} \;|\; n>0\}.

The language LabL_{ab}

We’ll now show that the language Lab=anbnL_{ab}=a^nb^n is not regular by showing that it does not satisfy the pumping theorem.

Intuitively, we can surmise that LabL_{ab} is not regular because a finite machine has no way to track an arbitrarily large number of aa's to match the subsequent bb's. We can only go so far before we run out of states. Consider the diagram below accepting the singleton language {ab}\{ab\}. (Once again, we omit the jail state for readability.)

Press + to interact
Accepts the language {ab}
Accepts the language {ab}

Now, how can we define a machine to accept {ab,aabb}\{ab,aabb\}? Or {ab,aabb,aaabbb}\{ab,aabb,aaabbb\}? We need to add more states. See the animation below.

A machine with a finite number of states will never have enough states to match an arbitrarily large number of symbols.

The reasoning above satisfies our intuition, but it is not a proof! If Lab=anbnL_{ab}=a^nb^n were regular, then per the pumping theorem, we could pick any string in this language of at least pp symbols in length, and partition it into three concatenated substrings, xyzxyz, and then pump yy however much we require and still obtain a string in the language. This is how infinite regular languages behave. We’ll choose the string apbpa^pb^p, which is more than long enough for us to invoke the pumping theorem and show that it cannot be partitioned this way.

If LabL_{ab} were regular, then, using the pumping theorem, we could partition apbpa^pb^p into three parts, xyzxyz. Since the condition xyp|xy| \leq p must hold, we know that the substring yy ...