Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Non-Regular Languages: (Pumping Lemma)

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 47

Non-regular languages

(Pumping Lemma)

n n

Non-regular languages

{a b : n 0}
R

{vv : v {a, b}*}

Regular languages

a *b

b*c a

b c ( a b) *
etc...

How can we prove that a language


is not regular?

Prove that there is no DFA or NFA or RE


that accepts L

Difficulty: this is not easy to prove

(since there is an infinite number of them)

Solution: use the Pumping Lemma !!!

The Pigeonhole Principle

4 pigeons

3 pigeonholes

A pigeonhole must
contain at least two pigeons

pigeons
...........

pigeonholes
...........

nm

The Pigeonhole Principle

pigeons

pigeonholes

nm

There is a pigeonhole
with at least 2 pigeons

...........

The Pigeonhole Principle


and
DFAs

Consider a DFA with

q1

states

q2

q3

q4

Consider the walk of a long string:


(length at least 4)

aaaab

A state is repeated in the walk of


q1

q1

q2

q3

q2

q3

q2

q4

a
a

q3

q4

aaaab

The state is repeated as a result of


the pigeonhole principle
Walk of
Pigeons:

(walk states)

q1

q2

q3

aaaab
q2

q3

q4

Are more than

Nests:

q1

(Automaton states)

q2

q3

Repeated
state

q4

Consider the walk of a long string:


(length at least 4)
Due to the pigeonhole principle:
A state is repeated in the walk of
q1

q1

q2

q3

q4

q2

aabb

q4

aabb

a
a

q3

q4

The state is repeated as a result of


the pigeonhole principle
Walk of
q1 a q2 a q3 b

Pigeons:

aabb
q4

q4

(walk states)

Are more than

Nests:
(Automaton states)

q1

q2

q3

Automaton States

q4

Repeated
state

In General: If | w | # states of DFA ,


by the pigeonhole principle,
a state is repeated in the walk w
Walk of w 1 2 k

q1 1

2 .... i q i 1 ....
i

qi

j 1

....

Arbitrary DFA
q1 1

k
......
......
qz
qi
Repeated state

qz

| w | # states of DFA m
Pigeons:

Walk of

(walk states)

q1

....

qi

....

....

qi

w
qi

....

qz

Are
more
than
Nests: q1

q2

(Automaton states)

....

A state is
repeated

qm1

qm

The Pumping Lemma

Take an infinite regular language L


(contains an infinite number of strings)
There exists a DFA that accepts

states

Take string

w L

with

| w| m
(number of
states of DFA)

then, at least one state is repeated


in the walk of w
Walk in DFA of
w 1 2 k

2 ......

...... k

Repeated state in DFA

There could be many states repeated


Take

to be the first state repeated

One dimensional projection of walk


First

occurrence

2 .... i q i 1 ....

Unique states

w:

Second
occurrence

.... k

j 1

We can write

w xyz

One dimensional projection of walk


First

occurrence

2 .... i q i 1 ....

x 1 i

w:

Second
occurrence

y i 1 j

j 1

.... k

z j 1 k

In DFA:

w x y z
contains only
first occurrence of q

y
...
j

...

i 1

j 1

...

...

Observation:

length

| x y | m number
of states
of DFA

y
...
Unique States
j

...

i 1

Since, in xy no
state is repeated
(except q)

Observation:

length

| y | 1

Since there is at least one transition in loop

y
...
j

i 1

We do not care about the form of string

may actually overlap with the paths of

...

z
...

and

Additional string:

Do not follow loop

The string
is accepted

xz

y
...

...

i 1

j 1

...

...

Additional string:

Follow loop
2 times

The string
is accepted

xyyz

y
...
j

...

i 1

j 1

...

...

Additional string:

The string
is accepted

Follow loop
3 times

xyyyz

...
j

...

i 1

j 1

...

...

In General:

The string
is accepted

Follow loop
times

xy z
i 0, 1, 2, ...

...
j

...

i 1

j 1

...

...

Therefore:

i 0, 1, 2, ...

x y z L
i

Language accepted by the DFA

y
...
j

...

i 1

j 1

...

...

In other words, we described:

The Pumping Lemma !!!

The Pumping Lemma:


Given a infinite regular language
there exists an integer
for any string
we can write
with

w L

(critical length)

with length

| w| m

w x y z

| x y | m and | y | 1

such that:

xy z L

i 0, 1, 2, ...

In the book:
Critical length

= Pumping length

Applications
of
the Pumping Lemma

Observation:
Every language of finite size has to be regular
(we can easily construct an NFA
that accepts every string in the language)

Therefore, every non-regular language


has to be of infinite size
(contains an infinite number of strings)

Suppose you want to prove that


An infinite language L is not regular
1. Assume the opposite:

is regular

2. The pumping lemma should hold for


3. Use the pumping lemma to obtain a
contradiction
4. Therefore,

is not regular

Explanation of Step 3: How to get a contradiction


1. Let

m be the critical length for L

2. Choose a particular string w L which satisfies


the length condition | w | m
3. Write

w xyz

4. Show that

w xy z L
i

for some

5. This gives a contradiction, since from


pumping lemma

w xy z L
i

i 1

Note:

It suffices to show that


only one string w L
gives a contradiction

You dont need to obtain


contradiction for every w L

Example of Pumping Lemma application

Theorem: The language L {a nb n : n 0}


is not regular

Proof:

Use the Pumping Lemma

n n

L {a b : n 0}

Assume for contradiction


that L is a regular language

Since L is infinite
we can apply the Pumping Lemma

n n

L {a b : n 0}
Let

be the critical length for L

Pick a string

such that:

w L

and length

We pick

m m

wa b

| w| m

From the Pumping Lemma:


we can write w a m b m x y z
with lengths

| x y | m, | y | 1

m
w xyz

m m

a b

a...aa...aa...ab...b

Thus: y a , 1 k m
k

y a , 1k m

m m

x y za b

From the Pumping Lemma:

xy z L
i 0, 1, 2, ...

Thus:

xy z L

y a , 1k m

m m

x y za b

From the Pumping Lemma:

xy z L

mk

xy z a...aa...aa...aa...ab...b L

x
Thus:

m k m

b L

BUT:

m k m

b L

k 1

n n

L {a b : n 0}

m k m

b L

CONTRADICTION!!!

Therefore:

Our assumption that L


is a regular language is not true

Conclusion: L

is not a regular language

END OF PROOF

Non-regular language

n n

{a b : n 0}

Regular languages

* *

L(a b )

You might also like