Docsity

Identifying Non-Regular Languages: Using the Pumping Lemma and Closure Operations - Prof. , Study notes of Discrete Structures and Graph Theory

Toggle sidebar
bg1
COT 4210 Section E Spring 2001
Pumping Lemma for Regular Languages
We have completed our study of closure properties of Regular Languages and various formal
systems for defining or describing them. The question we wish to consider next is, how can
non-Regular languages be identified? The first such tool is the pumping lemma for Regular
languages. It defines a key property possessed by all Regular languages, specifically all infinite
Regular languages (for it is only the infinite languages that can be non-Regular). As a logical
assertion, it states that, “L is regular  L has property P”. Negating this implication we have,
“L does not have property P  L is not regular.” It is the contra-positive form that is useful in
proving languages to be non-Regular. That is, typical proofs using the Pumping Lemma assert
that a given language, L, is Regular, and then proceed to obtain a contradiction by showing L
does not have property, P. We’ll explain what property “P” is after the statement of our next
theorem.
Theorem 9 (Pumping Lemma for Regular Languages(PLR)). Let L be a Regular language
over . There exits a positive integer  depending only on L, such that for every x  L with
|x|  , then there exists a decomposition of x in the form uvw, where |uv|   and |v|  1, such
that for every value of k  0, uvkw  L.
The “property P” of Regular languages described in the PLR is: there is a fixed number 
associated with each regular language, L, such that all strings, x, belonging to L and having
length at least  , define an infinite subset of L, denoted Lx, defined by
Lx = { uvkw | k  0, where x = uvw for some strings u,v,w satisfying |uv|   and |v|  1 }
The figure below illustrates this concept.
NOTE: You may be wondering about finite languages. Since the PLR applies to all Regular
languages, how does the result hold for finite Regular languages? The answer is that the value of
Feb. 22, 2001
Page 48
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Identifying Non-Regular Languages: Using the Pumping Lemma and Closure Operations - Prof. and more Study notes Discrete Structures and Graph Theory in PDF only on Docsity!

Pumping Lemma for Regular Languages

We have completed our study of closure properties of Regular Languages and various formal

systems for defining or describing them. The question we wish to consider next is, how can

non-Regular languages be identified? The first such tool is the pumping lemma for Regular

languages. It defines a key property possessed by all Regular languages, specifically all infinite

Regular languages (for it is only the infinite languages that can be non-Regular). As a logical

assertion, it states that, “L is regular  L has property P”. Negating this implication we have,

“L does not have property P  L is not regular.” It is the contra-positive form that is useful in

proving languages to be non-Regular. That is, typical proofs using the Pumping Lemma assert

that a given language, L, is Regular, and then proceed to obtain a contradiction by showing L

does not have property, P. We’ll explain what property “P” is after the statement of our next

theorem.

Theorem 9 (Pumping Lemma for Regular Languages(PLR)). Let L be a Regular language

over . There exits a positive integer  depending only on L, such that for every x  L with

|x|  , then there exists a decomposition of x in the form uvw , where |uv|   and |v|  1, such

that for every value of k  0, uv

k

w  L.

The “property P” of Regular languages described in the PLR is: there is a fixed number 

associated with each regular language, L, such that all strings, x, belonging to L and having

length at least , define an infinite subset of L, denoted L x , defined by

L

x = { uv

k

w | k  0, where x = uvw for some strings u,v,w satisfying |uv|   and |v|  1 }

The figure below illustrates this concept.

NOTE: You may be wondering about finite languages. Since the PLR applies to all Regular

languages, how does the result hold for finite Regular languages? The answer is that the value of

Feb. 22, 2001

for finite languages, L, is always greater than the length of the longest string in L; all members

of a finite language are therefore considered to be “short” strings.

Before proving the PLR we apply it to an example. We had stated earlier that certain languages

were known to be non-Regular without giving any proof. One of these is L = {a

n

b

n

| n  0 }.

Using the PLR we now supply the proof.

Corollary PLR-1 : L = { a

n

b

n

| n  0 } is non-Regular.

Proof. The proof will proceed by contradiction. Suppose L is Regular, then the conclusion of

the PLR must hold for L. In particular, consider x = a



b



 L (a long member of L), where  is

the parameter defined for L by the PLR. To obtain a contradiction we must show that for each

decomposition of the selected long string x in the form uvw, there exists a k  0, such that

uv

k

w  L.

It is really easier to think of applying the contra-positive of the PLR,

“If ~P(L), then L  R().” The contra-positive theorem takes the following form;

that is, show:

(a) If for all  > 0,

(b) ) there exists x L for which |x|  , and

(c) for every decomposition of x in the form uvw, where |uv|  and v ,

(d) there exists a k  0, such that uv

k

w L,

(e) Then L is not Regular!

Applying this proof template to our example we have:

(a) Let  > 0 b) e given, and consider

(b) ) x L where x = a



b



( |x| = 2  )

(c) Let x = uvw b) e any decomposition of x, where |uv|   and |v| > 0. Then v = a

p

for some

p, 1  p  . Furthermore, uv

k

w = a

 +(k-1)p

b



for all k  0.

(d) For any value of p > 0 and any k  1, uv

k

w L. Thus for every decomposition of

x = uvw there exists a k  0 for which uv

k

w L and we conclude,

(e) L is not Regular!

Feb. 22, 2001

Corollary PLR-2. L = { a

f(i)

| where i  0 and f(i) = i

2

. } = { , a, aaaa, aaaaaaaa, … } is not

Regular.

Proof. Once again let us use the template of the contra-positive version of the PLR.

(a) If for all  > 0,

(b) ) there exists x L for which |x|  , and

(c) for every decomposition of x in the form uvw, where |uv|  and v ,

(d) there exists a k  0, such that uv

k

w L,

(e) Then L is not Regular!

(a) Let  > 0 b) e given, and consider

(b) ) x = a

f(i)

where i is chosen so that 2i + 1 >  ,

(c) Let uvw b) e any decomposition of x, where 1|v|  . Then clearly v = a

p

for some p

satifying: 1  p   , and uv

k

w = a

f(i)+(k-1)p

.

(d) For k = 2, we have uv

2

w = a

f(i)+p

. But f(i) = i

2

< f(i) + |v|i

2

+  < f(i+1) = (i+1)

2

= i

2

+ 2i

+ 1 = f(i) + 2i + 1. Thus uv

2

wL for any value of p satisfying: 1  p  .

(e) W e may thus conclude that L cannot be Regular.

Feb. 22, 2001

Exercise 12. Show that each of the following languages is non-Regular using the PLR.

(a) L = { a

n

b

m

| 0  n < m }

(b) L = { a

n

b

m

| m  n, 0  n, m }

(c) L = { x#c

k

| x  {a,b}* and k = |x| a or k = |x| b }  {a,b,c, }*

(d) L = { x#x | x  {0,1}

}

(e) L = { x | x  {a,b,c}* |x| a = |x| b }

(f) L = {a,b}*  {c}

{a

n

b

n

| n  0 }

(g) L = { x#c

k

| x  {a,b}* and k = 2|x| a }  {a,b,c, }*

(h) L = { x#c

k

| x  {a,b}* and k = 2|x| a

  • 5|x| b }  {a,b,c, }*

(i) L = { 0

n 10

m 10

k | n,m,k  0 and n+m = k }

(j) L = { 0

n

10

m

10

k

| n,m,k  0 and n+k = m }

(k) L = {a

n

b

n

| n is odd }

Proof of (b) )

We copy the proof template and fill in the “blanks”.

(a) Let  > 0 b) e given,

(b) ) consider x = a



b)

 + 

 L. Clearly, |x|  , and

(c) every decomposition of x in the form uvw, where |uv|  and v , implies

v = a

p

, for some p, 1  p  . Furthermore, for every k  0, uv

k

w = a

 +(k-1)p

b)

 + 

(d) Choose

p

k

!

1



  (k must exist b) ecause p is a factor of  !). Then (k-1)p = ! and

uv

k

w = a

 + 

b)

 + 

L.

(e) Thus, L is not Regular!

Feb. 22, 2001

Example 28.

(a) Let L = { a

n

b

n

| n  0 } and let R  L be finite. Then by Theorem 10, L - R is non-

Regular. This follow trivially from the fact that L = (L - R)  R. R is Regular (it is

finite) and Regular languages are closed under union. Since L is a known non-Regular

language by Corollary PLR-1, it follows that L-R must be non-Regular.

(b) Let L = { a

n

b

n

| n  0 } and L’ = { x  {a,b}* | |x| a = |x| b }. Then L’ is non-Regular since

L = L’  R, where R = {a}{b}. It is obvious that R is Regular, and L is known to be

non-Regular. Since Regular languages are closed under intersection, it must follow by

Theorem 10 that L’ is non-Regular.

Exercise 13. Show that each of the following languages is non-Regular using only Theorem 10,

Example 28, and Corollary PLR-1.

(a) L = { 0

n

b

m

| 0  n < m }

(b) L = { a

n

m

| m  n, 0  n, m }

(c) L = { x#c

k

| x  {a,b}* and k = |x| a or k = |x| b }  {a,b,c, }*

(d) L = { x#x | x  {0,1}

(e) L = { x | x  {a,b,c}* |x| a

= |x| b

(f) L = {a,b}*  {c}

{a

n

b

n

| n  0 }

(g) L = { x#c

k

| x  {a,b}* and k = 2|x| a }  {a,b,c, }*

(h) L = { x#c

k

| x  {a,b}* and k = 2|x| a

  • 5|x| b }  {a,b,c, }*

(i) L = { 0

n

m

k

| n,m,k  0 and n+m = k }

(j) L = { 0

n

10

m

10

k

| n,m,k  0 and n+k = m }

(k) L = {a

n

b

n

| n is odd }

Proof of (f). L(f) is a language that cannot be proven to be non-Regular using the PLR!

L

1

= L

f

 {c}

{a}{b} = {c}

{a

n

b

n

| n  0 }

L

2 = h(L 1 ), where h is the homomorphism given by h(a) = a, h(b) = b, h(c) = 

L

2 = {a

n

b

n

| n  0}

Feb. 22, 2001

Myhill-Nerode: An Algeb) raic Characterization of Regular Languages

We have characterized Regular languages in terms of NFAs (DFAs) and Regular Expressions. In

Section A we also stated (without proof) that Regular languages are also be defined by Left- and

Right-linear grammars. With so many equivalent representations for the family of Regular

languages, one is led to wonder if there are any other ways they might be characterized. Also, as

we have seen from Exercise 12(f), the Pumping Lemma is not an absolute test for Regular

languages, that is, there are some non-Regular languages that cannot be proven so using the PLR.

This raises the question: is there a property P’ such that, “ R is Regular if and only if P’(R)”?

Myhill and Nerode have given us an affirmative answer to this question! Their celebrated result

is stated below as Theorem 10 and is one of the most elegant results of language theory.

Theorem 10 is important for three primary reasons: (1) it gives a purely algebraic

characterization of Regular Languages distinct from grammars and automata, (2) it gives an

absolute test for distinguishing Regular from non-Regular languages, and (3) it provides the basis

for constructing the minimal-state DFA recognizing a given Regular language.

To help build your intuition about the concepts central to the proof of Theorem 10, consider the

problem of reducing the number of states in a DFA, M = (Q, , , q 0 , A). We know intuitively

that not all equivalent DFAs have the same number of states. This is demonstrated by a trivial

example. Consider M and M' illustrated in the figure below. It is clear that L(M) = L(M') = *.

For any DFA, M, and any state q  Q, we can define two sets of strings determined by q. The

first set we shall denote as R q = { x | 


(q 0 ,x) = q }. This is just the strings that leave M in state q

  • you were introduced to this set in Theorem 7 when we solved a system of regular equations to

obtain the regular expression e q that satisfies L[e q

] = R

q

. The second set determined by q is S q

and is given by S q = {x | 


(q, x)  A }. These are the strings that would allow M to accept,

once M has reached state q. Given these sets, the following is true about L(M).

Now suppose that S q

= S

q' for two distinct state q and q'. To see that this is possible, refer to our

machine M above. Clearly S 1

= S

2 = *. However, assuming q and q' are both reachable states

of M, then it is never true that R q

= R

q' , in fact R q

 R

q' = . For suppose that x  R q

 R

q'

Because 

M is a function we have 

M (q 0 ,x) = q = q', contradicting our assumption that q and q'

are distinct. The consequence of the fact that S q

= S

q' is that the equation for L(M) can now be

written as:

This says that, with respect to what M will eventually accepts, there is no difference in the

behavior of M once it reaches q or q'. We say that q and q' are indistinguishable. Restating, we

can merge q and q' into one state by "rewiring" M in the following way. If p  q' is any state in

Q and (p, a) = q', then redefine the transition to go to q instead; that is, redefine (p,a) = q.

Feb. 22, 2001

a

b)

a, b)

a,b)

M'

M

qQ

q q

L M R S

( ) 

  q q q

pQ q q

p p

L M R S R R S '

{,' }

( )   

 

(a) R L is reflexive: this is a trivial consequence of the definition of R L

  • replacing "y" by "x"

produces a tautology.

(b) R L is symetric: that (x,y)  R L and (y,x)  R L should again be obvious since logical

equivalence () is symetric. Specifically, z*[ xzL  yz L] holds if and only if

z*[ yzL  xz L]. But this implies (y,x)  R L

(c) R L is transitive: if (x,y) and (y,z)  R L then for all w *, xw, yw, and zw are all in L or all

are not in L. In particular, it is true that xw and zw are both in L or are both not in L for all w.

Thus (x,z)  R L

(d) R L is right invariant with respect to string concatenation: to show right invariance we must

show that for any u , (x,y)  R L implies (xu, yu)  R L ; to this end let w  and consider

xuw and yuw. Since (x,y)  R L if follows that for any z *, xz and yz are both in L or both

not in L. In particular this is true for all z of the form uw, where w * is arbitrary and u is

fixed. Thus, for all w *, xuw and yuw are both in L or both not in L and we have established

(xu,yu)  R L

Proof of Myhill-Nerode.

(a) (b) )

If L is regular, then L = L(M) for some DFA M = (Q, , , q 0 , A). Define the relation R M on *

as follows, (x,y) R M if and only if 

M (q 0 ,x) = 

M (q 0 ,y). That is, x and y are related by R M if and

only if both define computations of M that end in the same state. We now show that R M is a right

invariant equivalence relation with respect to string concatenation.

(1) R

M is reflexive: 

M (q 0 ,x) = 

M (q 0 ,x). Follows from reflexive property of equality (=).

(2) R

M is symetric: 

M (q 0 ,x) = 

M (q 0 ,y) iff 

M (q 0 ,y) = 

M (q 0 ,x) by symetry of “=.”

(3) R

M is transitive: 

M (q 0 ,x) = 

M (q 0 ,y) and 

M (q 0 ,y) = 

M (q 0 ,z) imply 

M (q 0 ,x) = 

M (q 0 ,z) by the

transitivity of "=".

(4) R

M is right invariant: for any z  *, 

M (q 0 ,xz) = 

M

M (q 0 ,x),z) = 

M

M (q 0 ,y),z)

M (q 0 ,yz), if 

M (q 0 ,x) = 

M (q 0 ,y). Thus (x,y) R M implies (xz,yz) R M , for all z  *.

To complete this part of the proof we note that R M is of finite index. Specifically, each state of M

defines an equivalence class, [y] q

= { y |  M (q 0 ,y) = q}. So, R M is of finite index and we finally

observe that L =

[ y ] q

qA

(b) )(c) We assume that L is the union of some of the equivalence classes of a right invariant

equivalence relation of finite index, say E. From Lemma 5 we have already established that

R

L is a right invariant equivalence relation, so what remains is to show that that R L is of finite

index. We do this by showing that for all x *, [x] E

[ x]

R L

. If we can show this, then

the index of R L can be no larger than the index of E. This holds because each equivalence

Feb. 22, 2001

class,

[ x] R L

, of R L contains one or more equivalence classes [x] E of E.

To the contrary suppose there is some [x] E such that [x] E

[ x]

R L

 and [x] E

[ x ]

R L

. Then let u [x] E

[ x]

R L

and v [x] E

[ x]

R L

. Because u and v are not in the same

equivalence class under R L , it follows that there is a z * such that uz L but vz L. Now,

by assumption, L is the union of some equivalence classes under E. Thus uz and uv must

belong to different equivalence classes under E. But because E was assumed to be right

invariant, and because u,v [x] E , it must be the case that uz and uv belong to the same

equivalence class under E. Thus we have a contradiction and it must follow that for every x,

that [x] E

[ x ]

R L

=  or [x] E

[ x]

R L

= . This implies that E is a refinement of R L and

must therefore have an index no smaller than R L

. Thus R L is of finite index.

( c)  (a) Now we assume that R L is of finite index. We define a DFA M L = (Q, , , q 0

, A)

where Q = {

[ x ] R L

| x  *} the set of equivalence classes under R L is a finite set,

q 0

[  ] R L

, the class containing the null string, A = {

[ x] R L

[ x] R L

 L  },

[ x]

R L

, a) =

[ xa]

R L

, for all

[ x]

R L

 Q and a  .

To show this definition is valid, we must show that L is the union of some of the equivalence

classes of R L and that  is a function and not a multi-valued relation. To show that L is the

union of some of the equivalence classes, we observe that if u,v are any two distinct members

of

[ x]

R L

, then uz and vz are both in L or both not in L for all z *. In particular then, this

holds for z = . Thus either u and v are both in L or both are not in L. Consequently,

[ x]

R L

 L or

[ x]

R L

 L  , for all

[ x]

R L

Q.

To show  is a function, let u and v be any two distinct members of

[ x ]

R L

and let a . By

the right invariance of R L (Lemma 5) we have

[ ua ] [ va]

R R L L

. Thus  assigns only one

state to a given member of Q and is therefore a function.

To complete the proof we note that L(M L ) = L. This follows from the fact that 

(q 0 , x) =

[  ] R L

, x) =

[ x] R L

 A if and only if

[ x] R L

 L if and only if x  L. This fact follows

by induction on |x| from the definition of .

Finally, we note that from the proof of (a) (b) ) that every DFA for L has no fewer states than

the number of states in M L

. This follows from the fact that the number of states in M L is exactly

the index of R L together with the fact that the proof of (a) (b) ) implies that for any DFA M for

which L(M) = L, the index of R M = number of states of M  index of R L

. Thus M L is the

smallest DFA that accepts L!!!!!!!!!!!!!

Constructing M L

Feb. 22, 2001

[

M

M (q 0 ,x),z) A  

M

M (q 0 ,y),z) A]. But by properties of 

M , this holds if and only if

z * [

M (q 0 ,xz) A  

M (q 0 ,yz) A]. And this holds by definition of membership to L =

L(M) if and only if z *[ xz  L  yz  L]. But this last statement is just the definition of

(x, y)  R L

. QED

The next theorem gives us an iterative algorithm for computing the relation  on the state set of

a given DFA, M. It also establishes that the minimal state DFA accepting L(M) can be derived

from  by treating equivalence classes [q]  as states of this machine.

Theorem 12. Let M = (Q, , , q 0 , A) be a DFA and for all k  0 define the relation  k on Q as

follows: q 1  k q 2 if and only if z *

k

[

M (q 1 ,z) A  

M (q 2 ,z) A]. (We say that q 1 and q 2

are indistinguishable by strings of length k or less .) Then

(a)  0 = {Q-A, A} and for each k  0, q 1  k+ q 2 if and only q 1  k q 2 and if for every

a , (q 1 ,a)  k (q 2 ,a); and

(b) for some k  n-2, where n is the number of states in M, = k ; and finally,

(c) M L = (Q', , ', [q 0

]

 , A') , where Q' = { [q]  | q Q}, A' = { [q]  | q A}, and

for all a  , '([q]  , a) = [(q,a)] 

Proof (a). Applying the definition for k = 0, we see that q 1  0 q 2 if and only if [q 1

M(q 1 ,) A 

q 2

M (q 2 ,) A]. Thus  0 = {Q-A, A}. Now consider q 1

k+ q 2

. Clearly if z *

(k+1)

[

M (q 1

z) A  

M (q 2 , z) A], then z *

k

[

M (q 1 ,z) A  

M (q 2 ,z) A]. Thus q 1

k q 2

. But

because *

(k+1)

k

, q 1

k+ q 2 holds if and only if a  [z *

k

[

M (q 1 , az) A  

M (q 2

az) A]. And this holds if and only if a  [z *

k

[

M ((q 1 ,a),z) A  

M ((q 2 ,a),z)

A]. And finally this holds if and only if a  [(q 1 ,a) k (q 2 ,a)].

(b) We first show that if  k

k+ , then  k = . It should be clear that q 1  q 2 if and only if for

all k  , q 1

k q 2

. What we will show is that if  k

k+ , then  k

k+n , for all n  1. This is

easily established by induction on n. The basis (n = 1) is given by assumption. Now suppose q 1

k+n+ q 2

. Then by part (a) applied to  k+n+ we have, q 1

k+n+ q 2 if and only if q 1

k+n q 2 and for

all a  [ (q 1 ,a)  k+n (q 2 ,a)]. But by our induction hypothesis,  k

k+n , and we have q 1

k+n+ q 2 if and only if q 1

k q 2 and for all a  [ (q 1 ,a)  k (q 2 ,a)]. But this is the same as

saying

q 1

k+ q 2

. And then, since  k

k+ , it follows that q 1

k+n+ q 2 if and only if q 1

k q 2

Thus  k

k+n + and the induction is complete.

To finish (b) suppose M has n states and assume both Q-A and A are non-empty. Then by part

(a),  0 = { Q-A, A}. Suppose that  0

1 , then  1 must have at least one more equivalence

class than  0 (at least 3). Furthermore, because q 1

k+ q 2 implies q 1

k q 2 , then at least one

class of  1 was formed by splitting one of the classes of  0

. Thus if we consider the

progression of equivalence relations,  0

1

k , where | 0 | = 2 and | j+

j |+1, then

since the | k | cannot exceed the number of states of M, it follows that k  n-2 and  k

k+ .

Thus for any j > n-2, it must follow that  j

k

Feb. 22, 2001

STATE MINIMIZATION ALGORITHM

Let M = (Q, , , q 0 , A) be a DFA. The minimal state DFA equivalent to M can be computed in

the following way.

Step 1: Eliminate the unreachable states of M to obtain M’ = (Q’, , , q 0 , A’). The only

difference between M and M’ will be that Q’  Q and A’  A.

Step 2 : If A’ = , then L(M) = L(M’) = , and both are equivalent to the 1-state DFA,

M’’ = ({q 0 }, , ’’, q 0 , ), where ’’(q 0 ,a) = q 0 , for all a . On the other hand, if A’ = Q’,

then L(M) = L(M’) = *, and both are equivalent to M’’ = ({q 0

}, , ’’, q 0 , {q 0

}), where

’’(q 0 ,a) = q 0 , for all a .

Step 3 : If A’  and Q’-A’ , then do the following.

For k = 0, 1, … , compute  k until  k

k+

. The minimal state DFA equivalent to M’ is the

machine, M L

= (Q', , ', [q 0

]

, A') , where Q' = { [q] 

| q Q}, A' = { [q] 

| q A}, and for

all a  , '([q]  , a) = [(q,a)] 

. Use  k as .

Example 30. Constructing the minimal-state DFA for a given regular language L.

Consider the DFA, M, shown below for L(M) = { aaa, aba, baa, bba }.

a,b

a,b

a,b

a

a

a

a

b

b

a a

b

b

b

b

b

a

a,b

0

= { A:[1, 2, 3, 4, 6, 7, 8, 9, 10], B:[5, 11] }

A B

a A A B B A A B B A A A

b) A A A A A A A A A A A

1

= { A:[1, 2, 6, 7, 10], C:[3, 4, 8, 9], B:[5, 11] }

A C B

a A C A C A B B B B A A

Feb. 22, 2001