cd5560 faber formal languages, automata and models of computation lecture 4 mälardalen university

97
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 4 Mälardalen University 2005

Upload: opa

Post on 14-Jan-2016

31 views

Category:

Documents


0 download

DESCRIPTION

CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 4 Mälardalen University 2005. Content - More Properties of Regular Languages (RL) - Standard Representations of RL - Elementary Questions about RL - Non-Regular Languages - The Pigeonhole Principle - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

1

CD5560

FABER

Formal Languages, Automata and Models of Computation

Lecture 4

Mälardalen University

2005

Page 2: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

2

Content

- More Properties of Regular Languages (RL)- Standard Representations of RL- Elementary Questions about RL- Non-Regular Languages- The Pigeonhole Principle- The Pumping Lemma- Applications of the Pumping Lemma

Page 3: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

3

More Properties of

Regular Languages

Page 4: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

4

We have shown

Regular languages are closed under

Union

Concatenation

Star operation

Reverse

Page 5: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

5

Namely, for regular languages and :1L 2L

21 LL

21LL

1L

Union

Concatenation

Star operation

Reverse RL1

Regular

Languages

Page 6: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

6

We will show

Regular languages are also closed under

Complement

Intersection

Page 7: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

7

Namely, for regular languages and :1L 2L

1L

21 LL

Complement

Intersection

Regular

Languages

Page 8: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

8

Complement

Theorem For regular language

the complement is regular LL

Proof Take DFA that accepts and change:L

• non-final states final states

• non-accepting states accepting states

LResulting DFA accepts

Page 9: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

9

Examplea

b ba,

ba,

0q 1q 2q

)*( baLL

a

b ba,

ba,

0q 1q 2q

)))((( bababaaLL

Page 10: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

10

Intersection

Theorem For regular languages and

the intersection is regular 21 LL 1L 2L

Proof Apply DeMorgan’s Law:

2121 LLLL

Page 11: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

11

21 , LL regular

21 , LL regular

21 LL regular

21 LL regular

21 LL regular

Page 12: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

12

Standard Representations of

Regular Languages

Page 13: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

13

Standard Representations of Regular Languages

DFAs

NFAs

Regular

Expressions

Regular

Grammars

Regular

Languages

Page 14: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

14

Elementary Questionsabout

Regular Languages

Page 15: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

15

Membership Question

Question: Given regular language

and string

how can we check if ?

L

Lw w

Answer: Take the DFA that accepts

and check if is accepted

Lw

Page 16: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

16

Lw

DFAw

Lw

DFAw

Page 17: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

17

Take the DFA that accepts

Check if there is a path from

the initial state to a final state

L

Given regular language

how can we check

if is empty: ?

L

L )( L

Question:

Answer:

Page 18: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

18

DFA

L

L

DFA

Page 19: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

19

Given regular language

how can we check

if is finite?

L

L

Take the DFA that accepts

Check if there is a walk with cycle

from the initial state to a final state

L

Question:

Answer:

Page 20: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

20

DFA

L is infinite

DFA

L is finite

Page 21: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

21

Given regular languages and

how can we check if ? 1L 2L

21 LL Question:

)()( 2121 LLLLFind ifAnswer:

Page 22: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

22

)()( 2121 LLLL

21 LL 21 LLand

21 LL

1L 2L 1L2L

21 LL 12 LL 2L 1L

Page 23: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

23

)()( 2121 LLLL

21 LL 21 LLor

1L 2L 1L2L

21 LL 12 LL

21 LL

Page 24: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

24

Non-Regular Languages

Page 25: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

25

Regular languages

ba* acb *

...etc

*)( bacb

Non-regular languages???

Chomsky’s Language Hierarchy

Page 26: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

26

How can we prove that a language

is not regular?

L

Prove that there is no DFA that accepts L

Problem: this is not easy to prove

Solution: the Pumping Lemma !

Page 27: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

27

The Pigeonhole Principle

Page 28: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

28

The Pigeonhole Principle

Page 29: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

29

pigeons

pigeonholes

4

3

Page 30: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

30

A pigeonhole must

contain at least two pigeons

Page 31: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

31

...........

...........

pigeonsn

pigeonholesm mn

Page 32: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

32

The Pigeonhole Principle

...........

pigeons

pigeonholes

n

m

mn There is a pigeonhole

with at least 2 pigeons

Page 33: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

33

The Pigeonhole Principleand

DFAs

Page 34: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

34

DFA with states 4

1q 2q 3qa

b

4q

b

b b

b

a a

Page 35: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

35

1q 2q 3qa

b

4q

b

b

b

a a

a

In walks of strings:

aab

aa

ano state

is repeated

Page 36: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

36

In walks of strings:

1q 2q 3qa

b

4q

b

b

b

a a

a

...abbbabbabb

abbabb

bbaa

aabb a state

is repeated

Page 37: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

37

If the walk of string has length

1q 2q 3qa

b

4q

b

b

b

a a

a

w 4|| w

then a state is repeated

Page 38: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

38

If in a walk of a string

transitions states of DFA

then a state is repeated

Pigeonhole principle for any DFA:

w

Page 39: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

39

In other words for a string

transitions are pigeons

states are pigeonholesq

a

w

Page 40: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

40

A string has length number of states w

A state must be repeated in the walk of wq

In general

...... ......

walk of w

q

Page 41: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

41

The Pumping Lemmafor Regular Languages

Page 42: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

42

Take an infinite regular language L

DFA that accepts L

nstates

Page 43: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

43

Take string with w Lw

There is a walk with label w

.........

walk w

Page 44: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

44

If string has length w1|| nmw

then, from the pigeonhole principle:

a state is repeated in the walkq w

...... ......

walk w

( number of states)

q

n

Page 45: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

45

Write zyxw

...... ......

x

y

z

q

Page 46: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

46

myx ||

Lengths:

1|| y

...... ......

x

y

z

q

(from pigeon principle, as q is the first repetition in sequence)

(there is a walk in the graph)

Page 47: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

47

The string is accepted zxObservation

...... ......

x

y

z

q

Page 48: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

48

The string

is accepted

zyyxObservation

...... ......

x

y

z

q

Page 49: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

49

The string

is accepted

zyyyxObservation

...... ......

x

y

z

q

Page 50: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

50

The string

zyx iGenerally

...,2,1,0i

...... ......

x

y

z

q

is accepted

Page 51: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

51

The Pumping Lemma

Given an 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 52: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

52

Applications of

the Pumping Lemma

Page 53: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

53

Theorem

The language}0:{ nbaL nn

is not regular

Proof

Use the Pumping Lemma!

Page 54: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

54

Assume to the contrary,

that is a regular languageL

Since is infinite

we can apply the Pumping Lemma

L

}0:{ nbaL nn

Page 55: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

55

Let be the integer in the Pumping Lemma

Pick a string such that: w Lw

mw ||length

mmbawe.g. pick

m

}0:{ nbaL nn

Page 56: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

56

Write: zyxba mm

it must be that: length

From the Pumping Lemma

1||,|| ymyx

Therefore:

1, kay k

babaaaaba mm ............

x y z

m m

Page 57: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

57

From the Pumping Lemma: Lzyx i ...,2,1,0i

We can choose

mmbazyx

0i

We have:

1, kay k

Lbaw mkm

CONTRADICTION!

Page 58: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

58

Therefore: Our assumption that

is a regular language is not true

L

Conclusion

L is not a regular language

END OF PROOF

Page 59: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

59

Regular languages

ba* acb *

...etc

*)( bacb

Non-regular languages

}0:{ nba nn

Page 60: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

60

Theorem The language

Proof

Use the Pumping Lemma!

is not regular

*}:{ wwwL R },{ ba

Page 61: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

61

*}:{ wwwL R

Assume to the contrary,

that is a regular language

Since is infinite

we can apply the Pumping Lemma

L

L

Page 62: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

62

mmmm abbawpick

Pick a string such that: w Lw

mw ||length

Let be the integer in the Pumping Lemmam

*}:{ wwwL R

Page 63: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

63

Write zyxabba mmmm

it must be that length

From the Pumping Lemma

ababbabaaaaabba mmmm ..................

x y z

m m m m

1||,|| ymyx

1, kay k

Page 64: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

64

ababbabaaaaabba mmmm ..................

x y z

m m m m

1, kay k

We can choose 0i

CONTRADICTION!

So we get a’s on the left,

while is on the right:

km m

Page 65: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

65

Conclusion

L is not a regular language

Our assumption that

is a regular language is not true

Therefore:

END OF PROOF

L

Page 66: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

66

Regular languages

ba* acb *

...etc

*)( bacb

Non-regular languages

}0:{ nba nn *}:{ wwwR

Page 67: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

67

Theorem The language

is not regular

Proof

Use the Pumping Lemma

}0,:{ lncbaL lnln

Page 68: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

68

Assume to the contrary

that is a regular languageL

Since is infinite

we can apply the Pumping Lemma

L

}0,:{ lncbaL lnln

Page 69: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

69

mmm cbaw 2Pick

Let be the integer in the Pumping Lemma

Pick a string such that: w Lw

mw ||length

m

}0,:{ lncbaL lnln

Page 70: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

70

Write zyxcba mmm 2

cccbcabaaaaacba mmm ..................2

x y z

m m m2

it must be that length

From the Pumping Lemma

1||,|| ymyx

1, kay k

Page 71: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

71

From the Pumping Lemma

Lzyx i ...,2,1,0i

Thus:

Lcbazxzyx mmkm 20

Lzyx 0

mmm cbazyx 2We have:

1, kay k

Page 72: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

72

Lcba mmkm 2Therefore:

Lcba mmkm 2

BUT:

CONTRADICTION!

}0,:{ lncbaL lnln

Page 73: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

73

Conclusion

L is not a regular language

LTherefore: Our assumption that

is a regular language is not true

END OF PROOF

Page 74: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

74

Regular languages

Non-regular languages

}0,:{ lncba lnln

*}:{ wwwR }0:{ nba nn

Page 75: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

75

Theorem

The language

is not regular

ProofUse the Pumping Lemma

}0:{ ! naL n

nnn )1(21!

Page 76: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

76

Assume to the contrary

that is a regular languageL

Since is infinite

we can apply the Pumping Lemma

L

}0:{ ! naL n

Page 77: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

77

!mawPick

Pick a string such that: w

Lw mw ||length

Let be the integer in the Pumping Lemmam

}0:{ ! naL n

Page 78: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

78

Write zyxam !

From the Pumping Lemma

aaaaaaaaaaam ...............!

x y z

m mm !

it must be that length 1||,|| ymyx

mkay k 1,

Page 79: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

79

From the Pumping Lemma:

Lzyx i ...,2,1,0i

Thus:

!mazyx

Lazyyxzyx km !2

Lzyx 2

We have:

mkay k 1,

Page 80: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

80

La km !Therefore:

!! pkm

}0:{ ! naL nAnd since:

mk 1

mk 1There is p

Page 81: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

81

However

)!1( m)1(! mm!! mmm

!! mm! mmkm !

for 1m

)!1(! mkm

!! pkm for any p

Page 82: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

82

La km !Therefore:

La km !

BUT:

CONTRADICTION!

}0:{ ! naL n mk 1and

Page 83: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

83

Conclusion

L is not a regular language

Our assumption that

is a regular language is not true

LTherefore:

END OF PROOF

Page 84: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

84

Regular languages

Non-regular languages

}0:{ ! nan}0,:{ lncba lnln

*}:{ wwwR }0:{ nba nn

Page 85: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

85

Theorem

The language

is not regular

ProofUse the Pumping Lemma

}:{ primeiaL i

Page 86: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

86

Assume to the contrary

that is a regular languageL

Since is infinite

we can apply the Pumping Lemma

L

}:{ primeiaL i

Page 87: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

87

From the Pumping Lemma

it must be that length 1||,|| ymyx

From the Pumping Lemma:

Lzyx i ...,2,1,0i

The length of zxyw k 1

must be prime for each string of

mk

Lw mw ||length

L

Page 88: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

88

Thus:

But

which is not prime!

CONTRADICTION!

))(1(

))((

)()(

)()( 1

ylengthk

ylengthkk

ylengthxyzlength

zxyylengthzxylengthk

kk

)( mk

Lw

Page 89: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

89

Conclusion

L is not a regular language

Our assumption that

is a regular language is not true

LTherefore:

END OF PROOF

Page 90: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

90

Regular languages

Non-regular languages

}0:{ ! nan}0,:{ lncba lnln

*}:{ wwwR }0:{ nba nn

}:{ primeiaL i

Page 91: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

91

Theorem

The language}0:{ nbaL nn

is not regular

Proof

Use the Pumping Lemma!

An alternative variant of proof from slide 53.

Page 92: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

92

Assume to the contrary

that is a regular languageL

Since is infinite

we can apply the Pumping Lemma

L

}0:{ nbaL nn

Page 93: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

93

Pick a string such that: w Lw

mw ||length

mmbawPick

Let be the integer in the Pumping Lemmam

}0:{ nbaL nn

Page 94: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

94

Write: zyxba mm

it must be that: length

From the Pumping Lemma

1||,|| ymyx

Therefore: babaaaaba mm ............

1, kay kx y z

m m

Page 95: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

95

From the Pumping Lemma: Lzyx i

...,2,1,0i

Thus:

mmbazyx

Lbazyyxzyx mkm 2

Lzyx 2

We have: 1, kay k

Page 96: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

96

Lba mkm Therefore:

}0:{ nbaL nnBUT:

Lba mkm

CONTRADICTION

Page 97: CD5560 FABER Formal Languages, Automata  and Models of Computation Lecture 4 Mälardalen University

97

Our assumption that

is a regular language is not true

L

Conclusion: L is not a regular language

Therefore:

END OF PROOF