There is a very useful alternative (to FA and NFA) way to finitely represent the L ( M )-sets via a system of notation , or naming , that is called regular expressions. Regular expressions are familiar to users of the UNIX operating system. They are more than “just names” as they embody enough information—as we will see—to be mechanically transformable into a NFA (and via Theorem 3.2.1.4 to a FA).

3.3.0.7 Definition. (Regular Expressions over Σ) Given the alphabet Σ, we form the extended alphabet

images

where the symbols images , +, ·, *, (,) (not including the comma separators) are all abstract or formal 118 and do not occur in Σ. In particular, “ images ” in this alphabet is just a symbol, and so are “+”, “·”, “*”, and the brackets. All these symbols will be interpreted shortly.

The set of regular expressions over Σ is a set of strings over the augmented alphabet above, given as the closure Cl( images , images ), where

images = Σ ∪{ images }

and images contains three operations

(1) From strings α and β form the string ( α + β )

(2) From strings α and β form the string ( α · β )

(3) From string α form the string ( α *)

The letters α , β , γ are used as metavariables ( syntactic variables ) in this definition. They will stand for arbitrary regular expressions (we may add primes or subscripts to increase the number of our metavariables). images

images 3.3.0.8 Remark.

(i) We emphasize that regular expressions are built starting from the objects contained in Σ ∪ { images }. We also emphasize that we have not talked about semantics yet, that is, we did not say what sets these expressions will represent or name , nor, what “+”, “·”, and “*” mean.

(ii) We will often omit the “dot” in ( α · β ) and write simply ( α β ).

(iii) We assign the highest priority to *, the next lower to ·, and the lowest to +. We will let α ο α′ ο α″ ο α‴ group (“associate”) from right to left for ο ∈ {+, ·, * }. Given these priorities, we may omit some brackets, as is usual. Thus, α + β γ * means images and αβγ means ( α ( βγ )). images

We next define what sets these expressions name (semantics).

3.3.0.9 Definition. (Regular Expression Semantics) We define the semantics of any regular expression over Σ by recursion over the set of all such regular expressions. We use the notation L (α) to indicate the set named by α .

(1) L( images ) = images , where the left “ images ” is the symbol in the augmented alphabet (1) above, while the right “ images ” is the name of the empty set.

(2) L ( a ) = { a }, for each a ∈ Σ

(3) L ( α + β ) = L ( α ) ∪ L ( β )

(4) L ( α · β ) = L ( α ) L ( β )—cf. Definition 1.1.3.3 .

(5) L ( α *) = images

A language over Σ (cf. 1.1.3.2 ) obtained as L ( α ) from some α over Σ is called a regular language. images

3.3.0.10 Example. Let Σ = {0,1}. Then images = Σ * . Indeed, this is because L (0 + l) = L (0) ∪ L (1) = {0} ∪ {1} = {0, 1} = Σ. images

3.3.0.11 Example. We note that L ( images *) = images = images * = { images } (cf. p. 40 ). images

Of course, two regular expressions α and β over the same alphabet Σ are equal, written α = β , iff they are so as strings. We also have another, semantic , concept of regular expression “equality”:

3.3.0.12 Definition. (Regular Expression Equivalence) We say that two regular expressions α and β over the same alphabet Σ are equivalent , written α ∼ β , iff they name the same language , that is, iff L ( α ) = L ( β ). images

3.3.0.13 Example. Let Σ = {0, 1}. Then (0 + 1)* ∼ (0*1*)*.

Indeed, L ((0+1)*) = Σ*, by 3.3.0.10 . It suffices to show that L ((0*1*)*) = Σ* as well. To this end, the inclusion L ((0*1*)*) ⊆ Σ* is trivial, as the left hand side is a set of strings over Σ.

We turn to L ((0*1*)*) ⊇ Σ*. Now let us write A = L (0*) and B = L (1*). Thus the left hand side is ( AB )*. Given that A = {0}* = {0 n : n ≥ 0} and B = {1}* = {1 m : m ≥ 0},

images

Let now x ∈ Σ*. We show by induction on the length, k , of x that x belongs to the left hand side. For k = 0 we have x = images and the claim follows from the definition of the Kleene star ( p. 40 ) of any set X (here X = AB ).

Assume the claim for a fixed k (this is the I.H.). The case for k + 1 has two sub-cases: First, x = 0 y . By the I.H. and by (1), y , which has length k , has the form below.

0 n 1 1 m 1 0 n 2 1 m 2 0 n 3 1 m 3 . . . 0 n r 1 m r

But x has the same form, hence is in the left hand side.

Second, let x = 1 z . By the I.H. and by (1), z (of length k ) has the form above. But x has the same form, since it is obtained by adding 0 0 1 1 to the left of (1). Hence x is in the left hand side. images

images By the above example, α ∼ β does not imply α = β . images

3.3.1   From a Regular Expression to NFA and Back

There is a mechanical procedure (algorithm), which from a given regular expression α constructs a NFA M so that L ( α ) = L ( M ), and conversely: Given a NFA M constructs a regular expression α so that L ( α ) = L ( M ).

We split the procedure into two directions. First, we go from a regular expression to a NFA.

images 3.3.1.1 Remark. Every NFA M can be considered, without loss of generality, to have exactly one accepting state. This means that, if it does not, we can construct an equivalent NFA, M ′, that does. Indeed, if M has no accepting states at all then we just add one accepting state to it, to obtain M ′. We add no edges . Thus, just like the original, M ′ has no accepting paths. That is, L ( M ) = L ( M ′) = images .

Suppose now that M has several accepting states ,

images

We form M ′ by doing this:

  • add a new state, H , and designate it accepting
  • connect each original accepting state to H via an images -move; we add no other edges
  • make all the P j in (1) rejecting.

Trivially, M ′ has just one accepting state. On the other hand, say x ∈ L ( M ). Then there is an accepting path in M that ends, say, with P k , for some k . This path is labeled x . But then so is the path that we obtain by following the empty move to H : it is labeled x images = x . Thus, x ∈ L ( M ′).

Conversely, let z ∈ L ( M ′). Thus there is an accepting path that must end with H . The label of this path is z . Moreover, the path passes through, say, some P m as this is the only way to reach H , and indeed the latter is reached from P m via a single images -move.

Thus, if y is the label of the portion of the path from start state to P m , then z = y images = y . In other words, z ∈ L ( M ), since P m is accepting in M and therefore y ∈ L ( M ). images

3.3.1.2 Theorem. (Kleene) For any regular expression α over an alphabet Σ we can construct a NFA M with input alphabet Σ so that L ( α ) = L ( M ).

Proof . Induction over the closure of Definition 3.3.0.7 —that is, on the formation of a regular expression α according to the said definition. For the basis we consider the cases

  • α = images ; the NFA below works

    images

  • α = a , where a ∈ Σ; the NFA below works

images

Both of the above NFA have the form guaranteed by Remark 3.3.1.1 . All the NFA we construct in this proof will have that form, namely,

images

Assume now (the I.H. on regular expressions) that we have built NFA for α and β — M and N —so that L ( α ) = L ( M ) and L ( β ) = L ( N ). Moreover, these M and N have the form above . For the induction step we have three cases:

  • To build a NFA for α + β , that is, one that accepts the language L ( M ) ∪ L ( N ). The NFA below works since the accepting paths are precisely those from M and those from N . However, to maintain the single accepting state form, we apply Remark 3.3.1.1 to the NFA below.

    images

  • To build a NFA for αβ , that is, one that accepts the language L ( M ) L ( N ). The NFA below works—since the accepting paths are precisely those formed by concatenating an accepting path of M [labeled by some x ∈ L ( M )] with an images -move and then with an accepting path of N [labeled by some y ∈ L ( N )], in that left to right order. The images that connects M and N will not affect the path name: x images y = xy .

    images

  • To build a NFA for α*, that is, one that accepts the language L ( M )*. The NFA below, that we call P , works. That is, L ( P ) = L ( M )*.

    images

    (⊇ part) Indeed, let x ∈ L ( M )*. Then either x = images , or

    images

    images

    In the former case, since x labels the one-edge path from the start state of P to its accepting state, it is in L ( P ).

    If, on the other hand, x is given by (1), then again P accepts it, since it has a path from its start state to the accepting state, labeled x . Here is why: this path starts at the start state of P , follows the images -move to the start state of M , and then follows a path labeled z 1 in M . The path returns to the start state of P via the images -move.

    We repeat this path-building process, but this time we will traverse a path in M labeled z 2 . We continue like this until we traverse a path labeled z k in M and then follow the images -move back to the start state of P . From here we move to the accepting state of P via an images -move.

    All the paths that we said we traverse in M exist by virtue of (2).

    The entire path traversed via this process—in P —is labeled by

    images z 1 images images z 2 images . . . images z k images images

    which is equal to x .

    (⊆) Let now, for the converse inclusion, that y ∈ L ( P ). This y labels a path from the start state of P to its accepting state .

    There are only two kinds of such paths: One is the one-edge path labeled images from the start state of P directly to its accepting state. Thus y = images . But then, y ∈ L ( M )*.

    The other kind of path is one that follows the loop that contains M one or more times , finally to “exit” to the accepting state by following the images -move in the figure above. If we denote by w j the name of the path traversed in M —from M ’s start to its accepting state— the j-th time around the loop , and if y caused the computation to enter the loop r times in total, then

    y = images w 1 images images w 2 images images w 3 images . . . images w r images images = w 1 w 2 w 3 . . . w r

    But each w j is in L ( M ) by virtue of what path it names in M . Hence, y ∈ L ( M )* as we needed to prove. images

3.3.1.3 Theorem. (Kleene) For any FA or NFA M with input alphabet Σ we can construct a regular expression α over Σ so that L (α) = L ( M ).

Proof . Given a FA M (if a NFA is given, then we apply 3.2.1.4 first). We will construct an α with the required properties. The idea is to express L ( M ) in terms of simple (indeed, finite) sets of strings over Σ by repeatedly using the operations ·, ∪ and Kleene star, a finite number of times. It will be clear that a so constructed set can be named by a regular expression.

So let Q = { q 1 , q 2 , . . . , q n } be the set of states of M , where q 1 is the start state. We will refer to the transition function of M as δ and to the set of its accepting states as F .

We next define several sets of strings (over Σ)—denoted by images , for k = 0, 1, . . . , n and each i and j ranging from 1 to n .

images

images A superscript of n removes the restriction on the path q i x images xq j since every state q m satisfies m ≤ n . images

We first note that for k = 0 we get very small finite sets. Indeed, since state numbering starts at 1, the condition m ≤ 0 is false and therefore in images , if we have i ≠ j , then the condition q i x images xq j can hold precisely when x = a ∈ Σ for some a —that is, iff δ ( q i , a ) = q j . The case i = j also allows images in the set, since q i images images images q i for all i . To summarize, for all i and j we have

images

Since every finite set of strings can be named by a regular expression (cf. Exercise 3.5.26 ),

images

Next note that the images can be given recursively using k as the recursion variable and i , j as parameters, and taking (2) as the basis of the recursion.

To see this, consider a path labeled x in images for k > 0. It is possible that all q m (other than q i and q j ) that occur in the path have m < k . Then this x also belongs to images .

If, on the other hand, we have q k appear in the interior of the path labeled x once or more times, then we have the picture below:

images

where the q k occurrences start immediately after the path named z 0 and are connected by paths named z i , for i = 1, . . . , t . Thus, x = z 0 z 1 z 2 . . . z t z t +1 . Noting that z 0 ∈ images , z i ∈ images —for i = l, . . . , t —and z t +1 ∈ images , we have that x ∈ images ·( images )*· images · 119 We have established, for all k ≥ 1 and all i, j , that

images

Now take the I.H. that for k − 1 ≥ 0 (fixed!) and all values of i and j we have regular expressions images such that L ( images ) = images . We see that we can construct—from the images —regular expressions images for the images . Indeed, using the I.H. and (4), we have, for all i , j and the fixed k ,

images

Along with the basis (3) that the images sets can be named, this induction proves that all the images can be named by regular expressions, which we may construct, from the basis up.

Finally, the set L ( M ) can be so named. Indeed,

images

The above is a finite union ( F is finite!) of sets named by images with q j ∈ F . Thus we may construct its name as the “sum” (using “+”, that is) of the names images with q j ∈ F . images

images Because of the two Kleene theorems, every language that is accepted by a FA or NFA is a regular language . images

3.3.1.4 Example. Consider the FA of Example 3.1.1.4 , reproduced below.

images

We will rename its states q 0 , q 1 , to q 1 , q 2 respectively (not shown), so that we can conform with the notation in the proof of Theorem 3.3.1.3 .

We will compute regular expressions for:

  • all sets images
  • all sets images
  • all sets images

Recall the definition of the images , here for k = 0, 1, 2 and i, j ranging in {1, 2} (cf. proof of 3.3.1.3 ):

{ x : q i x ⊢* xq j , where no state in this computation,
             other than possibly the end-points q i and q j , has index higher than k }

This leads to the recurrence:

images

Below I employ the abbreviated (regular expression) name “ images ” for images *.

images

Superscript 1 now:

images

Using the previous table, the reader will have no difficulty to fill in the regular expressions under the heading “Direct Substitution” in the next table. To make things easier it is best to simplify the regular expressions of the previous table, meaning, finding simpler, equivalent ones. For example, L ( images + 0 + ( images + 0)( images + 0)*( images + 0)) = { images , 0} ∪ { images , 0}{ images , 0}*{ images , 0} = {0}*, thus

images + 0 +( images + 0)( images + 0)*( images + 0) ∼ 0*

Superscript 2:

images

images 3.3.1.5 Remark. We have the tools now to tackle the following question: Is there a converse to the pumping lemma ( 3.1.3.1 )?

That is, if a language _L “can be pumped” , must _it be regular?

Of course, we can certify the regularity of a language L by verifying one of L = L ( M ) or L = L (α), for some FA or NFA M , or some regular expression α ; but is pump-ability an alternative tool for such certification?

First off, the colloquialism “can be pumped” means exactly this: For the given L there is a positive integer C —a pumping constant—such that, if z ∈ L and | z | ≥ C , then z can be decomposed as z = uvw and all of (a)–(c) hold

(a) v ≠ images

(b)| uv | ≤ C

(c) uv i w ∈ L , for all i ≥ 0.

No. The pumping lemma goes “one way”!

Here is why.

(i) First, we prove that the language L over Σ = { a , b , c } given below

images

“can be pumped” in the sense above.

Proof

To settle the part that a C with the required properties exists, we make an educated guess: 120 we pick C = 3, and show that this C works for the given L. That is, we prove the existential claim “there is a positive integer C , etc.” constructively.

Pause. In earlier proofs by pumping lemma—cf. examples following 3.1.3.1 —that a given language is not regular, we did not take care to hand-pick a C . We just said, “let C be an associated pumping constant”. How come we now need to pick one that works? images

We show now that all z ∈ L , where |z| ≥ 3, “pump” in the sense (c) above. Let then z be arbitrary in L , and longer than 3.

(I) Case: z = a l b j c j . Take u = images , v = a . Pumping up or down—i.e., k > 0 or k = 0 in uv k w —we are still producing strings in L by the condition to the left of “and” in (1).

(II) Case: z = a i b j c k , i ≥ 2. Take u = aa , v the first symbol after the second a (recall | z | ≥ 3).

(III) Case: z contains no a ( i = 0). Take u = images , v the first symbol in the string. images

Pause. Will either of the choices C = 1 or C = 2 work? images

(ii) We next prove that L , notwithstanding that “it pumps”, is not regular.

Pause. Hmm. How does one prove that L is not regular if the pumping lemma does not help? All the non regular languages in our earlier examples were proved as such by showing that “they cannot pump”. images

There are are a number of alternative techniques, that go like “if L is regular, then so is this L′ , obtained from L , by such and such operations that preserve regularity.” We try to make L′ such that its non regularity is amenable to a proof by pumping lemma.

This idea works here. If L is regular, then so is

L images L ( ab * c *) = { ab n c n : n ≥ 0}

by 3.1.2.2 , using also Kleene’s theorems. Now the standard pumping lemma proof shows that it is not; cf. Exercise 3.5.28. Images

images Worth emphasizing. The pumping lemma is used for “negative” results of the type “L is not regular”. It is used as follows:

“ If L is regular, then it pumps”. The lemma has no expectations or opinion on whether non regular languages are allowed to pump (or not). So, the existence of a non regular language L “that pumps” is fine, but the lemma cannot show via direct application the non regularity of this L . Images