Está en la página 1de 47

Non-regular languages

(Pumping Lemma)

Fall 2006

Costas Busch - RPI

{a b : n 0}
n n

Non-regular languages

{vv : v {a, b}*}


R

Regular languages

a *b

b*c a

b c ( a b) *
etc...
Fall 2006

Costas Busch - RPI

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 !!!


Fall 2006

Costas Busch - RPI

The Pigeonhole Principle

Fall 2006

Costas Busch - RPI

4 pigeons

3 pigeonholes

Fall 2006

Costas Busch - RPI

A pigeonhole must
contain at least two pigeons

Fall 2006

Costas Busch - RPI

n pigeons
...........

pigeonholes

nm

...........
Fall 2006

Costas Busch - RPI

The Pigeonhole Principle

n pigeons

pigeonholes

nm

There is a pigeonhole
with at least 2 pigeons

...........
Fall 2006

Costas Busch - RPI

The Pigeonhole Principle


and
DFAs

Fall 2006

Costas Busch - RPI

Consider a DFA with

q1

states

q2

q3

a
Fall 2006

Costas Busch - RPI

q4

a
10

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

q3

a
Fall 2006

aaaab

Costas Busch - RPI

q4
11

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)
Fall 2006

q2
Costas Busch - RPI

q3

Repeated
state

q4
12

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
Fall 2006

q2

q3

q4

q2

aabb

q4

aabb

a
a

q3

Costas Busch - RPI

q4
13

The state is repeated as a result of


the pigeonhole principle
Walk of
Pigeons:

q1

q2

q3

aabb
q4

q4

(walk states)

Are more than

Nests:
(Automaton states)
Fall 2006

q1

q2

q3

Automaton States
Costas Busch - RPI

q4

Repeated
state
14

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.... k

qz

Arbitrary DFA
q1 1
Fall 2006

k
......
qz
qi
Repeated state

2 ......

Costas Busch - RPI

15

| w | # states of DFA m
Pigeons:

Walk of

(walk states)

q1

....

qi

....

w
qi

....

qz

Are
more
than

Nests: q1

q2

(Automaton states)
Fall 2006

....

qi

....

qm1

qm

A state is
repeated
Costas Busch - RPI

16

The Pumping Lemma

Fall 2006

Costas Busch - RPI

17

Take an infinite regular language L


(contains an infinite number of strings)

There exists a DFA that accepts

states

Fall 2006

Costas Busch - RPI

18

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


Fall 2006

Costas Busch - RPI

19

There could be many states repeated


Take

to be the first state repeated

One dimensional projection of walk

First

Second

occurrence

occurrence

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

w:

j 1.... k

Unique states
Fall 2006

Costas Busch - RPI

20

We can write

w xyz

One dimensional projection of walk


1

Second

occurrence

occurrence

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

x 1 i
Fall 2006

First

y i 1 j
Costas Busch - RPI

w:

j 1.... k

z j 1 k
21

In DFA:

w x y z
contains only
first occurrence of q

y
...
j

...

Fall 2006

i 1

j 1

...

...

z
Costas Busch - RPI

22

Observation:

length

| x y | m number
of states
of DFA

y
...

Unique States
j

...

Fall 2006

i 1

Costas Busch - RPI

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

23

Observation:

length

| y | 1

Since there is at least one transition in loop

y
...
j

i 1

Fall 2006

Costas Busch - RPI

24

We do not care about the form of string

may actually overlap with the paths of

and

y
...

z
...

Fall 2006

Costas Busch - RPI

25

Additional string:

Do not follow loop

The string
is accepted

xz

y
...

...

Fall 2006

i 1

j 1

...

...

z
Costas Busch - RPI

26

Additional string:

Follow loop
2 times

xyyz

y
...
j

...

Fall 2006

The string
is accepted

i 1

j 1

...

...

z
Costas Busch - RPI

27

Additional string:

The string
is accepted

Follow loop
3 times

y
...
j

...

Fall 2006

xyyyz

i 1

j 1

...

...

z
Costas Busch - RPI

28

In General:

The string
is accepted

Follow loop
times

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

...
j

...

Fall 2006

i 1

j 1

...

...

z
Costas Busch - RPI

29

Therefore:

i 0, 1, 2, ...

x y z L
i

Language accepted by the DFA

y
...
j

...

Fall 2006

i 1

j 1

...

...

z
Costas Busch - RPI

30

In other words, we described:

The Pumping Lemma !!!

Fall 2006

Costas Busch - RPI

31

The Pumping Lemma:


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

with

(critical length)

with length

| w| m

w x y z

| x y | m and | y | 1

such that:
Fall 2006

w L

xy z L
i

Costas Busch - RPI

i 0, 1, 2, ...
32

In the book:
Critical length

Fall 2006

= Pumping length

Costas Busch - RPI

33

Applications
of
the Pumping Lemma

Fall 2006

Costas Busch - RPI

34

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)

Fall 2006

Costas Busch - RPI

35

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,
Fall 2006

is not regular

Costas Busch - RPI

36

Explanation of Step 3: How to get a contradiction


1. Let

be the critical length for

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

i 1

5. This gives a contradiction, since from


pumping lemma
Fall 2006

w xy z L
i

Costas Busch - RPI

37

Note:

It suffices to show that


only one string w L
gives a contradiction

You dont need to obtain


contradiction for every w L

Fall 2006

Costas Busch - RPI

38

Example of Pumping Lemma application

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


is not regular

Proof:

Fall 2006

Use the Pumping Lemma

Costas Busch - RPI

39

L {a b : n 0}
n n

Assume for contradiction


that L is a regular language

Since L is infinite
we can apply the Pumping Lemma
Fall 2006

Costas Busch - RPI

40

L {a b : n 0}
n n

Let

be the critical length for L

Pick a string

w such that: w L
and length

We pick
Fall 2006

| w| m

wa b

m m

Costas Busch - RPI

41

From the Pumping Lemma:


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

| x y | m, | y | 1

m
w xyz a mb m

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

Thus: y a , 1 k m
k

Fall 2006

Costas Busch - RPI

42

y a , 1k m
k

x y za b

m m

From the Pumping Lemma:

xy z L
i

i 0, 1, 2, ...
Thus:

Fall 2006

xy z L
2

Costas Busch - RPI

43

y a , 1k m
k

x y za b

m m

From the Pumping Lemma:

xy z L
2

mk

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

x
Thus:
Fall 2006

m k m

b L

Costas Busch - RPI

44

BUT:

m k m

b L

k 1

L {a b : n 0}
n n

m k m

b L

CONTRADICTION!!!
Fall 2006

Costas Busch - RPI

45

Therefore:

Our assumption that L


is a regular language is not true

Conclusion: L is not a regular language


END OF PROOF
Fall 2006

Costas Busch - RPI

46

Non-regular language

{a b : n 0}
n n

Regular languages

* *

L( a b )

Fall 2006

Costas Busch - RPI

47

También podría gustarte