Sie sind auf Seite 1von 16

Nonregular Languages

Chapter 1.4

Chapter 1.4

Nonregular Languages
To understand the power of regular languages, we must also understand what they cant do. The FA for a regular language requires a nite amount of memory and number of states. Example: B = {0n1n | n 0} Example: C = { | has an equal number of 0s and 1s } Example: D = { | has an equal number of occurrences of 01 and 10 as substrings} It is not always easy to tell!

Chapter 1.4

The Pumping Lemma


Used to prove that languages are nonregular All regular languages have a property that if they are a certain length at a minimum (the pumping length), then they have a section that can be repeated again and again, and all resulting strings will still be in language. Theorem: (Pumping Lemma) If A is a regular language, then there is a number p (the pumping length) such that if s A, |s| p, then s = xyz and the following conditions hold: 1. i 0, xy iz A 2. |y| > 0 3. |xy| p

Chapter 1.4

The Pumping Lemma


Proof Idea: Let M = (Q, , , q1, F ) be a DFA that recognizes A. Let p = |Q|. There are two cases: 1. No string in A is of at least length p. (The Pumping Lemma (PL) is vacuously true!) 2. There is a string s such that |s| p. Example: Suppose |s| = 3, s = s1s2s3 and Q has 3 states Q = {q0, q1, q2}.
s1 q0 q1 s2 q2 s3 q???
Chapter 1.4 4

The Pumping Lemma


One of Qs states must be repeated. This is the Pidgeon Hole Principle. Lets take a slightly longer s = s1 s2s3s4s5s6 and Q = {q0, q1, q2, q3, q4, q5}.
s1 q0 q2 s2 q5 s3 q1 s4 q5 s5 q3 s6 q4

We can divide s into three substrings: s = xyz where: x = s1 s2 , y = s3s4, and z = s5s6 I know that whenever I am in state q5 and I see symbol s3 I go to state q1, and I know that if I am in state q1 and I see symbol s4 I go back to q5. So I know that whenever I am in state q5 and I see symbol s3 followed by s4 that I will return to state q5.
q0 s1 q2 s2 s3 q1 q5 s5 s4 q3 s6 q4

Chapter 1.4

The Pumping Lemma


q0 s1 q2 s2 s3 q1 q5 s5 s4 q3 s6 q4

So, string s1s2s5s6 is accepted (that is, xz). String s1s2s3s4 s5s6 is accepted (that is, s = xyz) String s1s2s3s4 s3s4s5s6 is accepted (that is, xyyz). String s1s2s3s4 s3s4s3s4s5s6 is accepted (that is, xyyyz). In fact, I can pump y down (that is, take is out to get xz) or I can pump y up (that is, add a copies of y between x and z) as many times as I want. If s = xyz A where A is the language recognized by this machine, then each string xy nz A, n 0.

Chapter 1.4

The Pumping Lemma


A specic example: L = {| each 0 is followed by a 1 and each 1 is followed by 0 or ends the string, starts with 0 }. L = {01, 0101, 010101, ...}
0 1

0 0 a b 1 c 0 b 1 c

So x = 0, y = 10, and z = 1.

Chapter 1.4

The Pumping Lemma


Theorem: (Pumping Lemma) If A is a regular language, then there is a number p (the pumping length) such that if s A, |s| p, then s = xyz and the following conditions hold: 1. i 0, xy iz A 2. |y| > 0 3. |xy| p Formal Proof: Let M = (Q, , , q1, F ) by a DFA recognizing A, and let p (the pumping length) be the number of states of M , that is, p = |Q|. Let s = s1...sn be a string of length n where n p.

Chapter 1.4

The Pumping Lemma


Let r0, r1, ..., rn be the sequence of states that M enters while processing s, so (ri1, si) = ri for 1 i n. s1 s2 ... sn r0 r1 r2 ... rn1 rn This sequence of states has length n + 1, which is at least p + 1. Among the rst p + 1 states in the sequence, two must be the same state by the PHP. Call this rst state like this rj and the second occurrence of this state in the sequence rl .
s1 r0 r1 s2 r2 s(j+1) rj sl rl sn r(n1) rn

...

...

...

Chapter 1.4

The Pumping Lemma


Because rl occurs in the rst p + 1 places in a sequence of states starting with r0, we have l p+1 Now let x = s0...sj , y = sj+1 ...sl , and z = sl+1...sn.
x s1 r0 r1 s2 r2 ... sj rj s(j+1) y ... sl rl s(l+1) z ... r(n1) sn rn

x takes machine M from r0 to rj . y takes machine M from rj to rl . (where rl is the same state as rj ) z takes machine M from rl to rn. (rn is an accept state) Since rj = rl , l p + 1, j < p + 1, and j = l then |y| > 0 and M must accept xy iz for i 0.
Chapter 1.4 10

The Pumping Lemma


How does the PL apply to a nite regular language like: L = {0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101, 110, 111} Remember, if the condition of a rule is not satised, it does not make the rule untrue! Theorem: (Pumping Lemma) If A is a regular language, then there is a number p (the pumping length) such that if s A, and |s| p, then s = xyz and the following conditions hold: 1. i 0, xy iz A 2. |y| > 0 3. |xy| p So if L, above, is regular, what is its pumping length, p?
Chapter 1.4 11

Using the PL to Prove that a Language B is NOT Regular


1. Assume B is regular 2. Use the PL to assert that there must be a pumping length p such that if there are strings of length p or greater in B, they can be pumped to get more strings in B. 3. Find a string s in B of length p or greater that cannot be pumped. 4. Show that s cannot be pumped be considering all ways of dividing s into xyz. (Use condition 3 of the PL, if needed.) For each division, show that there is an i such that xy iz B. 5. The existence of s contradicts the PL (and therefore that B is a regular language). Therefore B is NOT regular.

Chapter 1.4

12

The Pumping Lemma


Example: Let B = {0n1n | n 0}. Prove that B is not regular.

Chapter 1.4

13

The Pumping Lemma


Example: Let C = { | has an equal number of 0s and 1s}. Prove that C is not regular.

Chapter 1.4

14

The Pumping Lemma


Example: Let F = { | {0,1}}. Show that F is not regular.

Chapter 1.4

15

The Pumping Lemma


Example: Show that E = {0i1j | i > j} is not regular.

Chapter 1.4

16

Das könnte Ihnen auch gefallen