Top Banner
Fall 2019 Costas Busch - RPI 1 Non-regular languages (Pumping Lemma)
47

Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Mar 26, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 1

Non-regular languages

(Pumping Lemma)

Page 2: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 2

Regular languages

ba* acb *

...etc

*)( bacb

Non-regular languages }0:{ nba nn

}*},{:{ bavvvR

Page 3: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 3

How can we prove that a language

is not regular?

L

Prove that there is no DFA or NFA or RG

that accepts L

Difficulty: this is not easy to prove

(since there is an infinite number of them)

Solution: use the Pumping Lemma !!!

Page 4: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 4

The Pigeonhole Principle

Page 5: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 5

pigeons

pigeonholes

4

3

Page 6: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 6

A pigeonhole must

contain at least two pigeons

Page 7: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 7

...........

...........

pigeons

pigeonholes

n

m mn

Page 8: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 8

The Pigeonhole Principle

...........

pigeons

pigeonholes

n

m

mn There is a pigeonhole

with at least 2 pigeons

Page 9: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 9

The Pigeonhole Principle

and

DFAs

Page 10: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 10

Consider a DFA with states 4

1q 2q 3qa

b

4q

b

a b

b

a a

Page 11: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 11

Consider the walk of a “long’’ string:

1q 2q 3qa

b

4q

b

b

b

a a

a

aaaab

1q 2q 3q 2q 3q 4qa a a a b

A state is repeated in the walk of

(length at least 4)

aaaab

Page 12: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 12

aaaab

1q 2q 3q 2q 3q 4qa a a a b

1q 2q 3q 4q

Pigeons:

Nests: (Automaton states)

Are more than

Walk of

The state is repeated as a result of

the pigeonhole principle

(walk states)

Repeated

state

Page 13: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 13

Consider the walk of a “long’’ string:

1q 2q 3qa

b

4q

b

b

b

a a

a

aabb

1q 2q 3q 4q 4qa a b b

A state is repeated in the walk of

(length at least 4)

Due to the pigeonhole principle:

aabb

Page 14: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 14

aabb

1q 2q 3q 4q

Automaton States

Pigeons:

Nests: (Automaton states)

Are more than

Walk of

The state is repeated as a result of

the pigeonhole principle

(walk states) 1q 2q 3q 4q 4qa a b b

Repeated

state

Page 15: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 15

iq...... ......

Repeated state

kw 21

1 2 k

Walk of

iq.... iq.... .... 1 2 ki j1i 1j

Arbitrary DFA

DFA of states#|| wIf ,

by the pigeonhole principle,

a state is repeated in the walk

In General:

1qzq

zq1q

w

Page 16: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 16

mDFA of states#|| w

1q 2q 1mq mq

Walk of wPigeons:

Nests: (Automaton states)

Are

more

than

(walk states)

iq.... iq.... ....

1q

iq.... ....

zq

A state is

repeated

Page 17: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 17

The Pumping Lemma

Page 18: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 18

Take an infinite regular language L

There exists a DFA that accepts L

mstates

(contains an infinite number of strings)

Page 19: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 19

mw ||(number of

states of DFA)

then, at least one state is repeated

in the walk of w

q...... ...... 1 2 k

Take string with Lw

kw 21

Walk in DFA of

Repeated state in DFA

Page 20: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 20

Take to be the first state repeated q

q....

w

There could be many states repeated

q.... ....

Second

occurrence

First

occurrence

Unique states

One dimensional projection of walk :

1 2 ki j1i 1j

Page 21: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 21

q.... q.... ....

Second

occurrence

First

occurrence 1 2 ki j

1i 1j

wOne dimensional projection of walk :

ix 1 jiy 1 kjz 1

xyzw We can write

Page 22: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 22

zyxw

q... ...

x

y

z

In DFA:

...

...

1 ki

1ij

1j

contains only

first occurrence of q

Page 23: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 23

Observation: myx ||length number

of states

of DFA

Since, in no

state is repeated

(except q)

xy

Unique States

q...

x

y

...

1 i

1ij

Page 24: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 24

Observation: 1|| ylength

Since there is at least one transition in loop

q

y

...

1ij

Page 25: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 25

We do not care about the form of string z

q...

x

y

z

...

z may actually overlap with the paths of and x y

Page 26: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 26

The string

is accepted

zxAdditional string:

q... ...

x z

...

Do not follow loop y

...

1 ki

1ij

1j

Page 27: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 27

The string

is accepted

zyyx

q... ... ...

x z

Follow loop

2 times

Additional string:

y

...

1 ki

1ij

1j

Page 28: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 28

The string

is accepted

zyyyx

q... ... ...

x z

Follow loop

3 times

Additional string:

y

...

1 ki

1ij

1j

Page 29: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 29

The string

is accepted

zyx iIn General:

...,2,1,0i

q... ... ...

x z

Follow loop

times iy

...

1 ki

1ij

1j

Page 30: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 30

Lzyx i Therefore: ...,2,1,0i

Language accepted by the DFA

q... ... ...

x z

y

...

1 ki

1ij

1j

Page 31: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 31

In other words, we described:

The Pumping Lemma !!!

Page 32: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 32

The Pumping Lemma:

• Given a infinite regular language L

• there exists an integer m

• for any string with length Lw mw ||

• we can write zyxw

• with and myx || 1|| y

• such that: Lzyx i ...,2,1,0i

(critical length)

Page 33: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 33

In the book:

Critical length = Pumping length m p

Page 34: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 34

Applications

of

the Pumping Lemma

Page 35: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 35

Observation:

Every language of finite size has to be regular

Therefore, every non-regular language

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

(we can easily construct an NFA

that accepts every string in the language)

Page 36: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 36

Suppose you want to prove that

An infinite language 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

L

L

L

4. Therefore, is not regular L

Page 37: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 37

Explanation of Step 3: How to get a contradiction

2. Choose a particular string which satisfies

the length condition Lw

3. Write xyzw

4. Show that Lzxyw i for some 1i

5. This gives a contradiction, since from

pumping lemma Lzxyw i

mw ||

1. Let be the critical length for m L

Page 38: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 38

Note: It suffices to show that

only one string

gives a contradiction

Lw

You don’t need to obtain

contradiction for every Lw

Page 39: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 39

Theorem: The language }0:{ nbaL nn

is not regular

Proof: Use the Pumping Lemma

Example of Pumping Lemma application

Page 40: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 40

Assume for contradiction

that is a regular language L

Since is infinite

we can apply the Pumping Lemma

L

}0:{ nbaL nn

Page 41: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 41

Let be the critical length for

Pick a string such that: w Lw

mw ||and length

mmbaw We pick

m

}0:{ nbaL nn

L

Page 42: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 42

with lengths

From the Pumping Lemma:

1||,|| ymyx

babaaaaabaxyz mm ............

mkay k 1,

x y z

m m

we can write zyxbaw mm

Thus:

w

Page 43: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 43

From the Pumping Lemma: Lzyx i

...,2,1,0i

Thus:

mmbazyx

Lzyx 2

mkay k 1,

Page 44: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 44

From the Pumping Lemma:

Lbabaaaaaaazxy ...............2

x y z

km m

Thus:

Lzyx 2

mmbazyx

y

Lba mkm

mkay k 1,

Page 45: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 45

Lba mkm

}0:{ nbaL nnBUT:

Lba mkm

CONTRADICTION!!!

1≥k

Page 46: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 46

Our assumption that

is a regular language is not true

L

Conclusion: L is not a regular language

Therefore:

END OF PROOF

Page 47: Languages and Finite Automata - web2.aabu.edu.jo · Fall 2019 Costas Busch - RPI 3 How can we prove that a language is not regular? L Prove that there is no DFA or NFA or RG that

Fall 2019 Costas Busch - RPI 47

Regular languages

Non-regular language }0:{ nba nn

)( **baL