1 let’s recapitulate. 2 regular languages dfas nfas regular expressions regular grammars

53
1 Let’s Recapitulate

Upload: phoebe-ponds

Post on 01-Apr-2015

247 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

1

Let’s Recapitulate

Page 2: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

2

Regular Languages

DFAs

NFAsRegularExpressions

RegularGrammars

Page 3: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

3

A standard representationof a regular language :

L

A DFA that accepts M L

A NFA that accepts M L

A regular expression that generates

RL

A regular grammar that generates

GL

Page 4: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

4

When we say:

“We are given a Regular Language “

We mean:

L

Language in a standard representation

Page 5: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

5

Elementary Questions

about

Regular Languages

Page 6: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

6

Question:Given regular languagehow can we checkif a string ?

L

Lw

Page 7: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

7

Question:Given regular languagehow can we checkif a string ?

L

Lw

Answer: Take the DFA that acceptsand check if is accepted

Lw

Page 8: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

8

Question:Given regular languagehow can we checkif is empty, finite, infinite ?

L

L

Answer: Take the DFA that accepts

Then check the DFA

L

)( L

Page 9: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

9

If there is a walk from the start stateto a final state then: is not emptyL

If the walk contains a cycle then:

is infiniteL

Otherwise finite

Otherwise empty

Page 10: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

10

Question:

Given regular languages and how can we check if ?

1L 2L

21 LL

Page 11: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

11

Question:

Given regular languages and how can we check if ?

1L 2L

21 LL

Answer:

)()( 2121 LLLLL take

And find if L

Page 12: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

12

Question:

Given languagehow can we checkif is not a regular language ?

L

L

Page 13: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

13

Question:

Given languagehow can we checkif is not a regular language ?

L

L

Answer: The answer is not obvious

We need the Pumping Lemma

Page 14: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

14

The Pigeonhole Principle

Page 15: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

15

4 pigeons

3 pigeonholes

Page 16: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

16

A pigeonhole musthave two pigeons

Page 17: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

17

...........

...........

pigeons

pigeonholes

n

m

mn

Page 18: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

18

The Pigeonhole Principle

...........

pigeons

pigeonholes

n

m

mn There is a pigeonhole with at least 2 pigeons

Page 19: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

19

The Pigeonhole Principle

and

DFAs

Page 20: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

20

DFA with states 4

1q 2q 3qa

b

2q

b

b b

b

a a

Page 21: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

21

1q 2q 3qa

b

2q

b

b

b

a a

a

In walks of strings:

aab

aa

a no stateis repeated

Page 22: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

22

In walks of strings:

1q 2q 3qa

b

2q

b

b

b

a a

a

...abbbabbabb

abbabb

bbaa

aabba stateis repeated

Page 23: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

23

If the walk of string has length

1q 2q 3qa

b

2q

b

b

b

a a

a

w 4|| w

Then a state is repeated

Page 24: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

24

If in a walk: transitions states

Then: A state is repeated

1q 2q 3qa

b

2q

b

b

b

a a

a

The pigeonhole principle:

Page 25: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

25

In other words: transitions are pigeons

states are pigeonholes

1q 2q 3qa

b

2q

b

b

b

a a

a

q

a

Page 26: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

26

In general:

A string has length number of states w

A state must be repeated in the walk wq

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

Page 27: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

27

The Pumping Lemma

Page 28: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

28

Take an infinite regular languageL

DFA that accepts L

mstates

Page 29: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

29

Take string

with

w

Lw

There is a walk with label :w

.........

Page 30: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

30

If string has length w mw || number of states

Then, from the pigeonhole principle: A state is repeated in the walkq w

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

Page 31: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

31

Write zyxw

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

x

y

z

Page 32: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

32

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

x

y

z

Observations : myx ||length numberof states

1|| ylength

Page 33: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

33

The string is accepted zxObservation:

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

x

y

z

Page 34: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

34

The string is accepted

zyyxObservation:

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

x

y

z

Page 35: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

35

The string is accepted

zyyyxObservation:

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

x

y

z

Page 36: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

36

The string is accepted

zyx iIn General:

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

x

y

z

...,2,1,0i

Page 37: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

37

In other words, we described:

The Pumping Lemma

Page 38: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

38

The Pumping Lemma:

1. Given a infinite regular language L

2. There exists an integer m

3. For any string with length Lw mw ||

4. We can write zyxw

5. With andmyx || 1|| y

6. Such that: string Lzyx i

...,2,1,0i

Page 39: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

39

Applications of

the Pumping Lemma

Page 40: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

40

Claim:

The language }0:{ nbaL nn

is not regular

Proof:

Use the Pumping Lemma

Page 41: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

41

Proof:

Assume for contradictionthat is a regular languageL

Since is infinitewe can apply the Pumping Lemma

L

Page 42: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

42

mLet be the integerin the Pumping Lemma

Pick a string such that: w Lw

mw ||length

Example: mmbawpick

Page 43: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

43

Write zyxba mm

it must be that length

From the Pumping Lemma myx ||

Therefore:babaaaa ............

kay x y z

m m

Page 44: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

44

From the Pumping Lemma: Lzyx i

...,2,1,0i

Thus:

mmbazyx kay

Lbazyyxzyx mkm 2

Lzyx 2

Page 45: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

45

Lba mkm Therefore,

}0:{ nbaL nnBUT:

and

Lba mkm

CONTRADICTION!!!

Page 46: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

46

Our assumption thatis a regular languagecannot be true

L

CONCLUSION:

L is not a regular language

Therefore:

Page 47: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

47

Claim:

The language *}:{ wwwL R

is not regular

Proof:

Use the Pumping Lemma

Page 48: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

48

Proof:

Assume for contradictionthat is a regular languageL

Since is infinitewe can apply the Pumping Lemma

L

Page 49: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

49

mLet be the integerin the Pumping Lemma

Pick a string such that: w Lw

mw ||length

Example: mmmm abbawpick

Page 50: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

50

Write zyxabba mmmm

it must be that length

From the Pumping Lemma myx ||

Therefore:ababbabaaaa ..................

kay x y z

m m m m

Page 51: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

51

From the Pumping Lemma: Lzyx i

...,2,1,0i

Thus:

mmmm abbazyx kay

Labbazyyxzyx mmmkm 2

Lzyx 2

Page 52: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

52

Labba mmmkm Therefore,

BUT:

and

Labba mmmkm

CONTRADICTION!!!

*}:{ wwwL R

Page 53: 1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars

53

Our assumption thatis a regular languagecannot be true

L

CONCLUSION:

L is not a regular language

Therefore: