• Home
  • Queen's University
  • Software Specifications
  • Nonregular Languages and the Pumping Lemma

Nonregular Languages and the Pumping Lemma

CISC/CMPE-223, Winter 2023, Nonregular languages 1 Pumping lemma for regular languages While the regular languages have nice properties (as we have seen in the early part of the course), unfortunately many languages that we encounter in practice are nonregular. We discuss a method to prove that a given language is nonregular. Such a method is important for understanding the limits of state diagrams and regular expressions. If we can establish nonregularity of a language, there is no need to try construct a regular expression for it. This material is from Section 9.4 in the textbook. All regular languages L have the following property: · corresponding to L there is a constant value called the "pumping length" such that all strings in the language of length at least the "pumping length" can be "pumped", that is, some substring can be repeated arbitrarily many times and the resulting string must remain in the language L. The result is stated more formally in the below pumping lemma. The pumping lemma gives a general technique for showing that certain languages are not regular. The proof of the pumping lemma will be discussed in class. Pumping lemma. For every regular language L there exists a constant n such that any string x E L of length at least n can be written in three parts x = p . q . r where (P1) q= = (P2) |p . q| ?n (P3) pqkr E L for all k ? 0. CISC/CMPE-223, Winter 2023, Nonregular languages 2 Note: In the proof of the pumping lemma we can use as n the number of states of a state diagram accepting L. We know that n is a constant, but n can be arbitrarily large. Examples. The following languages are not regular: {0212 | { ? 0} {024 | ¿ > 0} (this language consists of all strings of 0's having a length that is a power of 2) How would you use the pumping lemma to show that the above languages are not regular? (Will be done in class.) Note 2. If Ls is a finite language, no string x E Lf can be written in three parts p . q . r such that conditions (P1) and (P3) hold because, for large enough k, the strings pqªr will be longer than the longest string of Lf. Do finite languages satisfy the conditions of the pumping lemma? Why or why not? Are all finite languages regular? The general method of using the pumping lemma to show that a given language L is not regular can be described as follows. The method uses proof by contradiction. 1. For the sake of contradiction we assume that L is regular. Then the pumping lemma gives us the pumping length n. We don't know what n is (it can be arbitrarily large), we only know that it is a constant (positive) integer. 2. Choose a string x E L of length at least n. 3. Consider all the possible decompositions of