fall 2004comp 3351 standard representations of regular languages regular languages dfas nfas regular...

82
Fall 2004 COMP 335 1 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Post on 21-Dec-2015

247 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 1

Standard Representations of Regular Languages

Regular Languages

DFAs

NFAsRegularExpressions

RegularGrammars

Page 2: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 2

When we say: We are given a Regular Language

We mean:

L

Language is in a standard representation

L

Page 3: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 3

Elementary Questions

about

Regular Languages

Page 4: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 4

Membership Question

Question: Given regular languageand string how can we check if ?

L

Lw w

Answer: Take the DFA that acceptsand check if is accepted

Lw

Page 5: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 5

DFA

Lw

DFA

Lw

w

w

Page 6: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 6

Given regular languagehow can we checkif is empty: ?

L

L

Take the DFA that accepts

Check if there is any path from the initial state to a final state

L

)( L

Question:

Answer:

Page 7: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 7

DFA

L

DFA

L

Page 8: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 8

Given regular languagehow can we checkif is finite?

L

L

Take the DFA that accepts

Check if there is a walk with cyclefrom the initial state to a final state

L

Question:

Answer:

Page 9: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 9

DFA

L is infinite

DFA

L is finite

Page 10: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 10

Given regular languages and how can we check if ?

1L 2L

21 LL Question:

)()( 2121 LLLLFind ifAnswer:

Page 11: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 11

)()( 2121 LLLL

21 LL 21 LLand

21 LL

1L 2L 1L2L

21 LL 12 LL 2L 1L

Page 12: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 12

)()( 2121 LLLL

21 LL 21 LLor

1L 2L 1L2L

21 LL 12 LL

21 LL

Page 13: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 13

Non-regular languages

Page 14: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 14

Regular languages

ba* acb *

...etc

*)( bacb

Non-regular languages}0:{ nba nn

}*},{:{ bavvvR

Page 15: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 15

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 16: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 16

The Pigeonhole Principle

Page 17: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 17

pigeons

pigeonholes

4

3

Page 18: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 18

A pigeonhole mustcontain at least two pigeons

Page 19: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 19

...........

...........

pigeons

pigeonholes

n

m mn

Page 20: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 20

The Pigeonhole Principle

...........

pigeons

pigeonholes

n

m

mn There is a pigeonhole with at least 2 pigeons

Page 21: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 21

The Pigeonhole Principle

and

DFAs

Page 22: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 22

DFA with states 4

1q 2q 3qa

b

4q

b

a b

b

a a

Page 23: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 23

1q 2q 3qa

b

4q

b

b

b

a a

a

In walks of strings:

aab

aa

a no stateis repeated

Page 24: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 24

In walks of strings:

1q 2q 3qa

b

4q

b

b

b

a a

a

...abbbabbabb

abbabb

bbaa

aabb a stateis repeated

Page 25: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 25

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 26: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 26

In general, for any DFA:

String has length number of states w

A state must be repeated in the walk of wq

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

walk of w

Repeated state

Page 27: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 27

In other words for a string : transitions are pigeons

states are pigeonholesq

a

w

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

walk of w

Repeated state

Page 28: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 28

The Pumping Lemma

Page 29: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 29

Take an infinite regular languageL

There exists a DFA that accepts L

mstates

Page 30: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 30

Take string with w Lw

There is a walk with label :w

.........

walk w

Page 31: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 31

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 32: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 32

q

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

walk w

Let be the first state repeated in thewalk of w

Page 33: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 33

Write zyxw

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

x

y

z

Page 34: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 34

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

x

y

z

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

Page 35: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 35

The string is accepted

zxObservation:

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

x

y

z

Page 36: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 36

The string is accepted

zyyxObservation:

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

x

y

z

Page 37: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 37

The string is accepted

zyyyxObservation:

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

x

y

z

Page 38: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 38

The string is accepted

zyx iIn General:

...,2,1,0i

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

x

y

z

Page 39: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 39

Lzyxw ii ∈In General: ...,2,1,0i

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

x

y

z

Language accepted by the DFA

Page 40: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 40

In other words, we described:

The Pumping Lemma !!!

Page 41: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 41

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: ,Lzyxw ii ...,2,1,0i

Page 42: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 42

Applications

of

the Pumping Lemma

Page 43: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 43

Theorem: The language }0:{ nbaL nn

is not regular.

Proof: Use the Pumping Lemma

Page 44: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 44

Assume that is a regular languageL

Since is an infinite language,we can apply the Pumping Lemma

L

}0:{ nbaL nn

Page 45: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 45

Let be the integer in the Pumping Lemma

Pick a string such that: (1) w Lw

mw ||

and

mmbawWe pick:

m

}0:{ nbaL nn

(2) length

Page 46: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 46

it must be that length

From the Pumping Lemma 1||,|| ymyx

babaaaaabaxyzw mm ............

1, kay k

x y z

m m

Write: zyxba mm

Thus:

Page 47: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 47

From the Pumping Lemma: Lzyxw ii

...,2,1,0i

Thus:

mmbazyx

Lzyxw 22

1, kay k

Page 48: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 48

From the Pumping Lemma:

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

x y z

km m

Thus:

Lzyx 2

mmbazyx 1, kay k

y

Lba mkm

Page 49: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 49

Lba mkm

}0:{ nbaL nnBut:

Lba mkm

CONTRADICTION!!!

1≥k

Page 50: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 50

Our assumption thatis a regular language is not true

L

Conclusion: L is not a regular language

Therefore:

Page 51: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 51

Regular languages

Non-regular languages }0:{ nba nn

Page 52: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 52

More Applications

of

the Pumping Lemma

Page 53: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 53

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 54: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 54

Regular languages

Non-regular languages *}:{ vvvL R

Page 55: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 55

Theorem:The language

is not regular

Proof: Use the Pumping Lemma

*}:{ vvvL R },{ ba

Page 56: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 56

Assume for contradictionthat is a regular languageL

Since is infinitewe can apply the Pumping Lemma

L

*}:{ vvvL R

Page 57: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 57

mmmm abbaw We pick

Let be the integer in the Pumping Lemma

Pick a string such that: w Lw

mw ||length

m

and

*}:{ vvvL R

Page 58: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 58

Write zyxabba mmmm

it must be that length

From the Pumping Lemma

ababbabaaaaxyz ..................

x y z

m m m m

1||,|| ymyx

1, kay kThus:

Page 59: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 59

From the Pumping Lemma: Lzyx i

...,2,1,0i

Thus: Lzyx 2

1, kay kmmmm abbazyx

Page 60: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 60

From the Pumping Lemma:

Lababbabaaaaaazxy ∈.....................=2

x y z

km + m m m

1, kay k

y

Lzyx 2

Thus:

mmmm abbazyx

Labba mmmkm

Page 61: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 61

Labba mmmkm

Labba mmmkm

BUT:

CONTRADICTION!!!

1k

*}:{ vvvL R

Page 62: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 62

Our assumption thatis a regular language is not true

L

Conclusion: L is not a regular language

Therefore:

Page 63: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 63

Regular languages

Non-regular languages

}0,:{ lncbaL lnln

Page 64: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 64

Theorem:The language

is not regular

Proof: Use the Pumping Lemma

}0,:{ lncbaL lnln

Page 65: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 65

Assume for contradictionthat is a regular languageL

Since is infinitewe can apply the Pumping Lemma

L

}0,:{ lncbaL lnln

Page 66: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 66

mmm cbaw 2We pick

Let be the integer in the Pumping Lemma

Pick a string such that: w Lw

mw ||length

m

}0,:{ lncbaL lnln

and

Page 67: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 67

Write zyxcba mmm 2

it must be that length

From the Pumping Lemma

cccbcabaaaaaxyz ..................

x y z

m m m2

1||,|| ymyx

1, kay kThus:

Page 68: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 68

From the Pumping Lemma: Lzyx i

...,2,1,0i

Thus:

mmm cbazyx 2

Lxzzyx ∈=0

1, kay k

Page 69: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 69

From the Pumping Lemma:

Lcccbcabaaaxz ...............

x z

km m m2

mmm cbazyx 2 1, kay k

Lxz

Thus: Lcba mmkm 2

Page 70: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 70

Lcba mmkm 2

Lcba mmkm 2

BUT:

CONTRADICTION!!!

}0,:{ lncbaL lnln

1k

Page 71: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 71

Our assumption thatis a regular language is not true

L

Conclusion: L is not a regular language

Therefore:

Page 72: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 72

Regular languages

Non-regular languages }0:{ ! naL n

Page 73: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 73

Theorem:The language

is not regular

Proof: Use the Pumping Lemma

}0:{ ! naL n

nnn )1(21!

Page 74: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 74

Assume for contradictionthat is a regular languageL

Since is infinitewe can apply the Pumping Lemma

L

}0:{ ! naL n

Page 75: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 75

!mawWe pick

Let be the integer in the Pumping Lemma

Pick a string such that: w Lw

mw ||length

m

}0:{ ! naL n

Page 76: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 76

Write zyxam !

it must be that length

From the Pumping Lemma

aaaaaaaaaaaxyz m ...............!

x y z

m mm !

1||,|| ymyx

mkay k 1,Thus:

Page 77: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 77

From the Pumping Lemma: Lzyx i

...,2,1,0i

Thus:

!mazyx

Lzyx 2

mkay k 1,

Page 78: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 78

From the Pumping Lemma:

Laaaaaaaaaaaazxy ..................2

x y z

km mm !

Thus:

!mazyx mkay k 1,

Lzyx 2

y

La km !

Page 79: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 79

La km !

!! pkm

}0:{ ! naL nSince:

mk 1

There must exist such that: p

Page 80: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 80

However:

)!1(

)1(!

!!

!!

!

m

mm

mmm

mm

mmkm ! for 1m

)!1(! mkm

!! pkm for any p

Page 81: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 81

La km !

La km !

BUT:

CONTRADICTION!!!

}0:{ ! naL n

mk 1

Page 82: Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars

Fall 2004 COMP 335 82

Our assumption thatis a regular language is not true

L

Conclusion: L is not a regular language

Therefore: