3
CS340: Theory of Computation Sem I 2015-16 Lecture Notes 6: Non-regular languages Raghunath Tewari IIT Kanpur Limitations of finite automata. 1. Not all languages are regular. 2. Intuitively languages that “require” some sort of counting are generally not regular. 1 The Pumping Lemma Theorem 1.1 (Pumping Lemma). Let L be a regular language. There exists and integer p 0, such that for all w 2 L of length at least p, there exists a partition of w = xyz such that |xy| p, |y| > 0, and for all i 0, xy i z 2 L. Informally pumping lemma says that if L is a regular language then all strings in L having length greater than some quantity, has a non-null substring that can be repeated as many times as you want and the resultant string is still in the language. Note 1.1. Pumping lemma is a property of regular languages. In other words if a language is regular then it satisfies the above property. It may very well be true that certain non-regular languages also satisfy the above property. To prove that certain languages are not regular, we will use the pumping lemma in the contrapositive form. Theorem 1.2 (Contrapositive form of Pumping Lemma). Let L be a language. If - 8p 0, (opponent’s move) - 9w 2 L with |w| p, such that, (your move) - 8 possible partitions of w as w = xyz , satisfying (opponent’s move) - |xy| p, and - |y| > 0, - 9i 0 such that xy i z/ 2 L, (your move) then L is not regular. Think of it as a game between you and an all powerful opponent. Both you and your opponent have to follow the rules of the game (the conditions of the theorem). Your goal is to finally find an i such that xy i z is not in L and your opponents goal is to choose the partition of w in such a manner that no matter what i you choose, xy i z will be in L. Pumping lemma gives a sucient condition for non-regular languages. It is not a necessary condition. In other words, there exists non-regular languages that do not satisfy the pumping lemma. Therefore, You WIN = ) L is not regular, but You LOSE 6 = ) L is regular

06-toc

Embed Size (px)

DESCRIPTION

toc

Citation preview

Page 1: 06-toc

CS340: Theory of Computation Sem I 2015-16

Lecture Notes 6: Non-regular languages

Raghunath Tewari IIT Kanpur

Limitations of finite automata.

1. Not all languages are regular.

2. Intuitively languages that “require” some sort of counting are generally not regular.

1 The Pumping Lemma

Theorem 1.1 (Pumping Lemma). Let L be a regular language. There exists and integer p � 0,such that for all w 2 L of length at least p, there exists a partition of w = xyz such that |xy| p,

|y| > 0, and for all i � 0, xyiz 2 L.

Informally pumping lemma says that if L is a regular language then all strings in L having lengthgreater than some quantity, has a non-null substring that can be repeated as many times as youwant and the resultant string is still in the language.

Note 1.1. Pumping lemma is a property of regular languages. In other words if a language isregular then it satisfies the above property. It may very well be true that certain non-regularlanguages also satisfy the above property.

To prove that certain languages are not regular, we will use the pumping lemma in thecontrapositive form.

Theorem 1.2 (Contrapositive form of Pumping Lemma). Let L be a language. If

- 8p � 0, (opponent’s move)

- 9w 2 L with |w| � p, such that, (your move)

- 8 possible partitions of w as w = xyz, satisfying (opponent’s move)

- |xy| p, and

- |y| > 0,

- 9i � 0 such that xy

iz /2 L, (your move)

then L is not regular.

Think of it as a game between you and an all powerful opponent. Both you and your opponenthave to follow the rules of the game (the conditions of the theorem). Your goal is to finally findan i such that xyiz is not in L and your opponents goal is to choose the partition of w in such amanner that no matter what i you choose, xyiz will be in L.Pumping lemma gives a su�cient condition for non-regular languages. It is not a necessarycondition. In other words, there exists non-regular languages that do not satisfy the pumpinglemma. Therefore,

You WIN =) L is not regular, butYou LOSE 6=) L is regular

Page 2: 06-toc

2 Examples of Non-regular Languages

1.L1 = {0n1n | n � 0}

Given p � 0, pick w = 0n1n. Now for any partition of w = xyz such that |xy| p and|y| > 0, it must be the case that y = 0t for some t > 0. Therefore xy

0z = 0p�t1p /2 L1 since

t > 0. Therefore L1 is not regular.

2.L2 = {albmc

n | l,m, n � 0 and l +m = n}

Given p � 0, pick w = a

pb

pc

2p. Now for any partition of w = xyz such that |xy| p and|y| > 0, it must be the case that y = a

t for some t > 0. Therefore xy

2z = a

p+tb

pc

2p /2 L2

since t > 0. Therefore L2 is not regular.

3.L3 = {w 2 {0, 1}⇤ | #0(w) = #1(w)}

Note that L3 \ L(0⇤1⇤) = L1. Since we have shown that L1 is not regular therefore it mustbe the case that L3 is also not regular.

Remark. Intersection of a non-regular language with a regular/non-regular language can beboth regular or non-regular. Same is true for union as well. Verify for yourself byconstructing toy examples.

4.L4 = {0k | k is a prime}

Given p � 0, pick w = 0q, where q is the smallest prime greater than or equal to p. Now forany partition of w = xyz such that |xy| p and |y| > 0, let |y| = l. Then 0 < l p. Choosei = q + 1. Then, |xyiz| = q + l(i� 1) = q + lq = q(l + 1). Hence xy

iz /2 L4. Therefore L4 is

not regular.

Exercise 1. Show that the following languages are not regular.

1.{0n2

1n | n � 0}

2.{0n1m | n > m}

3.{ww | w 2 {0, 1}⇤}

Proof of Theorem 1.1. Let D = (Q,⌃, �, q0, F ) be a DFA for L. Let p = |Q|. Let w be a string oflength at least p in L and |w| = t. There is a sequence of states q0, q1, . . . qt that the DFAtraverses on the string w where qt 2 F . By pigeon hole principle, there exists integers i, j suchthat 0 m < n qp and qm = qn. Now consider a partition w = xyz, such that

- x is the smallest string having the property that �(q0, x) = qm,

- y is the smallest non-empty string such that �(qm, y) = qm, and

Page 3: 06-toc

- z is the remaining part of w.

In other words, the DFA traverses from q0 to qm on x, traverses from qm to qn (qn is the same asqm) on y and then proceeds to qt. Since m < n therefore |y| > 0. Now for all i � 0,�(q0, xyi) = qm, as the automaton loops on the state qm on the string y. Therefore �(q0, xyiz) = qt

and hence xy

iz 2 L.

Note 2.1. Observe that in the above proof we are “overloading” the definition of � toaccommodate strings as well instead of symbols only. We can formalize this by defining �

recursively as follows:

� : Q⇥ ⌃⇤ �! Q

such that

�(q, ✏) = q,

�(q, xa) = �(�(q, x), a).