0% found this document useful (0 votes)
39 views56 pages

Non-Regular Languages: Md. Rafsan Jani Assistant Professor Department of CSE Jahangirnagar University

This document discusses the Pumping Lemma, which can be used to prove that a language is not regular. It begins by explaining that to prove a language L is not regular, one must prove that there is no finite automaton that accepts L. It then introduces the Pigeonhole Principle, which states that if there are more pigeons than pigeonholes, at least one pigeonhole will contain multiple pigeons. Applying this to finite automata, if a string's length is greater than or equal to the number of states in an automaton, at least one state will be repeated in the string's walk. This repeated state can be used to pump sections of the string and generate new strings that still must

Uploaded by

tom jerry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views56 pages

Non-Regular Languages: Md. Rafsan Jani Assistant Professor Department of CSE Jahangirnagar University

This document discusses the Pumping Lemma, which can be used to prove that a language is not regular. It begins by explaining that to prove a language L is not regular, one must prove that there is no finite automaton that accepts L. It then introduces the Pigeonhole Principle, which states that if there are more pigeons than pigeonholes, at least one pigeonhole will contain multiple pigeons. Applying this to finite automata, if a string's length is greater than or equal to the number of states in an automaton, at least one state will be repeated in the string's walk. This repeated state can be used to pump sections of the string and generate new strings that still must

Uploaded by

tom jerry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 56

CSE-309

Theory of Computation

Lecture 05

Non-regular Languages

Md. Rafsan Jani


Assistant Professor
Department of CSE
Jahangirnagar University
n n
{a b : n  0}
Non-regular languages
R
{vv : v {a, b}*}

Regular languages
a *b b*c  a
b  c ( a  b) *
etc...
2
How can we prove that a language L
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 !!!


3
The Pigeonhole Principle

4
4 pigeons

3 pigeonholes

5
A pigeonhole must
contain at least two pigeons

6
n pigeons

...........

m pigeonholes nm

...........

7
The Pigeonhole Principle

n pigeons
m pigeonholes
There is a pigeonhole
nm with at least 2 pigeons

...........

8
The Pigeonhole Principle

and

DFAs

9
Consider a DFA with 4 states

b
b b

a a b
q1 q2 q3 q4
a a
10
Consider the walk of a “long’’ string: aaaab
(length at least 4)

A state is repeated in the walk of aaaab


q1 a q2 a q3 a q2 a q3 b q4

b
b b

a a b
q1 q2 q3 q4
a a 11
The state is repeated as a result of
the pigeonhole principle

Walk of aaaab
Pigeons: q1 a q2 a q3 a q2 a q3 b q4
(walk states)

Are more than

Nests: q1 q2 q3 q4
(Automaton states) Repeated
state
12
Consider the walk of a “long’’ string: aabb
(length at least 4)

Due to the pigeonhole principle:


A state is repeated in the walk of aabb
q1 a q2 a q3 b q4 b q4

b
b b

a a b
q1 q2 q3 q4
a a 13
The state is repeated as a result of
the pigeonhole principle

Walk of aabb
Pigeons: q1 a q2 a q3 b q4 b q4
(walk states)

Are more than

Nests: q1 q2 q3 q4
(Automaton states) Repeated
Automaton States
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 .... j
qi
 j 1
.... k
qz
i

Arbitrary DFA
q1 1 2
...... ...... k
qi qz
Repeated state
15
| w |  # states of DFA  m

Pigeons: (walk states)


Walk of w
q1 .... qi .... qi .... qz

Are
more
than

Nests: q1 q2 .... qi .... qm1 qm


(Automaton states) A state is
repeated
16
The Pumping Lemma

17
Take an infinite regular language L
(contains an infinite number of strings)

There exists a DFA that accepts L

m
states

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
1  2 ...... q ......  k
Repeated state in DFA
19
There could be many states repeated

Take q to be the first state repeated

One dimensional projection of walk w:


First Second
occurrence occurrence
 2 ....  i q i 1 .... j
1 q ....  k
 j 1

Unique states

20
We can write w  xyz

One dimensional projection of walk w:


First Second
occurrence occurrence
 2 ....  i q i 1 .... j  j 1
1 q ....  k

x  1 i y   i 1 j z   j 1 k

21
In DFA: w x y z
contains only
y first occurrence of q

...

j  i 1
1
... i
q  j 1
... ... k

x z
22
Observation: length | x y |  m number
of states
of DFA

y
...
Unique States
j  i 1
1
... i
q Since, in xy no
state is repeated
x (except q) 23
Observation: length | y | 1
Since there is at least one transition in loop

y
...

j  i 1

24
We do not care about the form of string z

z may actually overlap with the paths of x and y


y
...

z
... q

x 25
Additional string: The string x z
is accepted, so

Do not follow loop


y
...

j  i 1
1
... i
q  j 1
... ... k

x z
26
Additional string: The string x y yz
is accepted, so

Follow loop y
2 times
...

j  i 1
1
... i
q  j 1
... ... k

x z
27
Additional string: The string x y yyz
is accepted, so

Follow loop y
3 times
...

j  i 1
1
... i
q  j 1
... ... k

x z
28
i
In General: The string xy z
is accepted i  0, 1, 2, ...

Follow loop y
i times
...

j  i 1
1
... i
q  j 1
... ... k

x z
29
Therefore: x y z L
i
i  0, 1, 2, ...

Language accepted by the DFA


y
...

j  i 1
1
... i
q  j 1
... ... k

x z
30
In other words, we described:

The Pumping Lemma !!!

31
The Pumping Lemma:
• Given a infinite regular language L
• there exists an integer m (critical length)

• for any string w L with length | w |  m


• we can write w x y z

• with | x y |  m and | y |  1
i i  0, 1, 2, ...
• such that: xy z  L
32
In the book:

Critical length m = Pumping length p

33
Applications

of

the Pumping Lemma

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

Therefore, every non-regular language


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

35
Suppose you want to prove that
An infinite language L is not regular

1. Assume the opposite: L is regular

2. The pumping lemma should hold for L


3. Use the pumping lemma to obtain a
contradiction

4. Therefore, L is not regular

36
Explanation of Step 3: How to get a contradiction
1. Let mbe the critical length for L
. Choose a particular string w which
L 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 w  xy z  L
i

37
Note: It suffices to show that
only one string w L
gives a contradiction

You don’t need to obtain


contradiction for every w L

38
Example of Pumping Lemma application

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


is not regular

Proof: Use the Pumping Lemma

39
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

40
n n
L  {a b : n  0}

Let m be the critical length for L

Pick a string w such that: w  L


and length | w| m

m m
We pick wa b

41
From the Pumping Lemma:

we can write w  a m b m  x y z

with lengths | x y |  m, | y | 1

m m
m m
w  xyz a b  a...aa...aa...ab...b
x y z

Thus: y  a , 1  k  m
k

42
m m
x y za b y a , 1k m
k

i
From the Pumping Lemma: xy z  L
i  0, 1, 2, ...

2
Thus: xy z  L

43
x y za b m m y a , 1k m
k

2
From the Pumping Lemma: xy z  L

mk m
2
xy z  a...aa...aa...aa...ab...b  L
x y y z

m k m
Thus: a b L
44
m k m
a b L k≥ 1

n n
BUT: L  {a b : n  0}

m k m
a b L

CONTRADICTION!!!
45
Therefore: Our assumption that L
is a regular language is not true

Conclusion: L is not a regular language

END OF PROOF
46
n n
Non-regular language {a b : n  0}

Regular languages

* *
L(a b )

47
Non-regular languages R
L  {vv : v  *}

Regular languages

48
Theorem: The language
R
L  {vv : v  *}   {a, b}
is not regular

Proof: Use the Pumping Lemma

49
R
L  {vv : v  *}

Assume for contradiction


that L is a regular language

Since L is infinite
we can apply the Pumping Lemma

50
R
L  {vv : v  *}
Let m be the critical length for L

Pick a string w such that: w  L


and length | w| m

m m m m
We pick wa b b a
51
From the Pumping Lemma:

we can write: w  a b b a x y z
m m m m

with lengths: | x y |  m, | y | 1

m m m m
w  xyz  a...aa...a...ab...bb...ba...a
x y z

Thus: y a , 1k m
k

52
m m m m
x y za b b a y a , 1k m
k

i
From the Pumping Lemma: xy z  L
i  0, 1, 2, ...

2
Thus: xy z  L
53
m m m m
x y za b b a y a , 1k m
k

2
From the Pumping Lemma: xy z  L

m+k m m m
2
xy z = a...aa...aa...a...ab...bb...ba...a ∈ L
x y y z

m k m m m
Thus: a b b a L
54
m k m m m
a b b a L k 1

R
BUT: L  {vv : v  *}

m k m m m
a b b a L

CONTRADICTION!!!
55
Therefore: Our assumption that L
is a regular language is not true

Conclusion: L is not a regular language

END OF PROOF
56

You might also like