Nonregular Languages

Nonregular Languages

All regular languages have a property that proves that they are regular.

Example:

Observations:

Layperson’s:

  1. If a language is regular, it can recognize an infinite set of strings.
  2. If machine can’t loop, it’ll run out of states.
  3. Thus, to accept infinite-length strings, you need a repeating portion (the pumped portion).

Pumping Lemma

If A is a regular language, then there is a number p (the pumping length) where if |s| \ge p, then s may be divided into three pieces, s=xyz, satisfying the following conditions:

  1. for each i \ge 0, xy^iz \in A,
  2. |y| > 0, and
  3. |xy| \le p

Observations:

Remember: Pumping Lemma is used to prove a language is NOT regular.

Usage

How-to Use Pumping Lemma:

  1. Assume A is regular
  2. It has to have a Pumping Length (P)
  3. All strings longer than P can be pumped |S| \ge P
  4. Now find a string S in A such that |S| \ge P
  5. Divide S into xyz
  6. Show that xy^iz \not\in A for some i
  7. Then consider all the ways that S can be divided into xyz.
  8. Show that none of these can satisfy all the 3 pumping conditions at the same time.
  9. If S cannot be pumped, then A is not regular.

Remember: Don’t give p a concrete value!

Related Notes: Proof by Contradiction (CS1300)

Example: Pumping Lemma

Q: Is L = \{ a^n b^n | n \ge 0 \} regular?

A:

Assume L is regular so pumping lemma applies on L

Let p be the pumping length, then any string in L where |s| \ge p, there exists strings x, y, z such that s = xyz and:

  1. xy^iz \in L for each i \ge 0, and
  2. |y| \ge 0, and
  3. |xy| \ge p

Consider the string a^p b^p, s \in L and |s| \ge p

Looking at condition 3, we can smartly see that the maximum we can cut is up to middle of our string, as |a^p| = p, so cutting any further would violate condition 3.

Thus, xy can only contain zero or more a’s

But/further, from condition 2, y can only contain one or more a’s.

Let’s consider condition 1 when i=0.

  1. xy^iz = xz \in L
  2. xy has one or more a’s (definition of y) removed from s, resulting in fewer a’s than b’s
  3. This violates L = \{a^n b^n\}, so xz \not\in L, which is a contradiction.
\therefore L must not be regular language.

Note: If a language is finite (e.g., \{ a^n b^n | n \le 7 \}), it is a regular language because a DFA can clearly be made.