Non-regular languages

39
1 Non-regular languages

description

Non-regular languages. Non-regular languages. Regular languages. Prove that there is no DFA that accepts. How can we prove that a language is not regular?. Problem: this is not easy to prove. Solution: the Pumping Lemma !!!. The Pigeonhole Principle. pigeonholes. pigeonholes. - PowerPoint PPT Presentation

Transcript of Non-regular languages

Page 1: Non-regular languages

1

Non-regular languages

Page 2: Non-regular languages

2

Regular languages

ba* acb *

...etc

*)( bacb

Non-regular languages}0:{ nba nn

}*},{:{ bavvvR

Page 3: Non-regular languages

3

How can we prove that a languageis not regular?

L

Prove that there is no DFA that accepts L

Problem: this is not easy to prove

Solution: the Pumping Lemma !!!

Page 4: Non-regular languages

4

The Pigeonhole Principle

Page 5: Non-regular languages

5

pigeons4

pigeonholes3pigeonholes3

Page 6: Non-regular languages

6

A pigeonhole mustcontain at least two pigeons

Page 7: Non-regular languages

7

...........

pigeonsn

...........

pigeonholesm mn

Page 8: Non-regular languages

8

The Pigeonhole Principle

...........

pigeons

pigeonholes

n

m

mn There is a pigeonhole with at least 2 pigeons

Page 9: Non-regular languages

9

The Pigeonhole Principle

and

DFAs

Page 10: Non-regular languages

10

DFA with states 4

1q 2q 3qa

b

4q

b

b b

b

a a

Page 11: Non-regular languages

11

1q 2q 3qa

b

4q

b

b

b

a a

a

In walks of strings:

no stateis repeated

{q1, q2}

aab

aa

a

{q1, q2, q3}

{q1, q2 , q3 , q4}

Page 12: Non-regular languages

12

In walks of strings:

1q 2q 3qa

b

4q

b

b

b

a a

a

...abbbabbabb

abbabb

bbaa

aabb a stateis repeated

Page 13: Non-regular languages

13

If string has length :

1q 2q 3qa

b

4q

b

b

b

a a

a

w 4|| w

Thus, a state must be repeated

Then the transitions of string are more than the states of the DFA

w

Page 14: Non-regular languages

14

In general, for any DFA:

String has length number of states w

wA state must be repeated in the walk of q

Repeated state

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

walk of w

Page 15: Non-regular languages

15

In other words for a string : transitions are pigeons

states are pigeonholesq

a

w

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

walk of w

Repeated state

Page 16: Non-regular languages

16

The Pumping Lemma

Page 17: Non-regular languages

17

Take an infinite regular languageL

There exists a DFA that accepts L

mstates

Page 18: Non-regular languages

18

Take string with w Lw

There is a walk with label :w

.........

walk w

Page 19: Non-regular languages

19

If string has length w mw || (number of statesof DFA)

then, from the pigeonhole principle: a state is repeated in the walkw

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

walk w

Page 20: Non-regular languages

20

q

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

walk w

Let be the first state repeated in thewalk of w

Page 21: Non-regular languages

21

Write zyxw

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

x

y

z

Page 22: Non-regular languages

22

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

x

y

z

Observations: myx ||length numberof statesof DFA1|| ylength

Page 23: Non-regular languages

23

The string is accepted

zxObservation:

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

x

y

z

Page 24: Non-regular languages

24

The string is accepted

zyyxObservation:

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

x

y

z

Page 25: Non-regular languages

25

The string is accepted

zyyyxObservation:

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

x

y

z

Page 26: Non-regular languages

26

The string is accepted

zyx iIn General:...,2,1,0i

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

x

y

z

Page 27: Non-regular languages

27

Lzyx i ∈In General: ...,2,1,0i

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

x

y

z

Language accepted by the DFA

Page 28: Non-regular languages

28

In other words, we described:

The Pumping Lemma !!!

Page 29: Non-regular languages

29

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 andmyx || 1|| y

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

Page 30: Non-regular languages

30

Applications

of

the Pumping Lemma

Page 31: Non-regular languages

31

Theorem:The language }0:{ nbaL nn

is not regular

Proof: Use the Pumping Lemma

Page 32: Non-regular languages

32

Assume for contradictionthat is a regular languageL

Since is infinitewe can apply the Pumping Lemma

L

}0:{ nbaL nn

Page 33: Non-regular languages

33

Let be the integer in the Pumping Lemma

Pick a string such that: w Lw

mw ||length

mmbawWe pick

m

}0:{ nbaL nn

Page 34: Non-regular languages

34

it must be that length

From the Pumping Lemma 1||,|| ymyx

1, kay k

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

x y z

m m

Write: zyxba mm

Thus:

Page 35: Non-regular languages

35

From the Pumping Lemma: Lzyx i

...,2,1,0i

Thus:

mmbazyx

Lzyx 2

1, kay k

Page 36: Non-regular languages

36

From the Pumping Lemma:

Thus:

Lzyx 2

mmbazyx 1, kay k

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

x y z

km m

y

Lba mkm

Page 37: Non-regular languages

37

Lba mkm

}0:{ nbaL nnBUT:

Lba mkm

CONTRADICTION!!!

1≥k

Page 38: Non-regular languages

38

Our assumption thatis a regular language is not true

L

Conclusion: L is not a regular language

Therefore:

Page 39: Non-regular languages

39

Regular languages

Non-regular languages }0:{ nba nn