Standard Representations of Regular Languages DFAs NFAs Fall

  • Slides: 82
Download presentation
Standard Representations of Regular Languages DFAs NFAs Fall 2004 Regular Grammars Regular Expressions COMP

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

When we say: We mean: Fall 2004 We are given a Regular Language is

When we say: We mean: Fall 2004 We are given a Regular Language is in a standard representation COMP 335 2

Elementary Questions about Regular Languages Fall 2004 COMP 335 3

Elementary Questions about Regular Languages Fall 2004 COMP 335 3

Membership Question: Answer: Fall 2004 Given regular language and string how can we check

Membership Question: Answer: Fall 2004 Given regular language and string how can we check if ? Take the DFA that accepts and check if is accepted COMP 335 4

DFA Fall 2004 COMP 335 5

DFA Fall 2004 COMP 335 5

Question: Answer: Given regular language how can we check if is empty: ? Take

Question: Answer: Given regular language how can we check if is empty: ? Take the DFA that accepts Check if there is any path from the initial state to a final state Fall 2004 COMP 335 6

DFA Fall 2004 COMP 335 7

DFA Fall 2004 COMP 335 7

Question: Given regular language how can we check if is finite? Answer: Take the

Question: Given regular language how can we check if is finite? Answer: Take the DFA that accepts Check if there is a walk with cycle from the initial state to a final state Fall 2004 COMP 335 8

DFA is infinite DFA is finite Fall 2004 COMP 335 9

DFA is infinite DFA is finite Fall 2004 COMP 335 9

Question: Given regular languages how can we check if Answer: Fall 2004 and ?

Question: Given regular languages how can we check if Answer: Fall 2004 and ? Find if COMP 335 10

and Fall 2004 COMP 335 11

and Fall 2004 COMP 335 11

or Fall 2004 COMP 335 12

or Fall 2004 COMP 335 12

Non-regular languages Fall 2004 COMP 335 13

Non-regular languages Fall 2004 COMP 335 13

Non-regular languages Regular languages Fall 2004 COMP 335 14

Non-regular languages Regular languages Fall 2004 COMP 335 14

How can we prove that a language is not regular? Prove that there is

How can we prove that a language is not regular? Prove that there is no DFA that accepts Problem: this is not easy to prove Solution: the Pumping Lemma !!! Fall 2004 COMP 335 15

The Pigeonhole Principle Fall 2004 COMP 335 16

The Pigeonhole Principle Fall 2004 COMP 335 16

pigeons pigeonholes Fall 2004 COMP 335 17

pigeons pigeonholes Fall 2004 COMP 335 17

A pigeonhole must contain at least two pigeons Fall 2004 COMP 335 18

A pigeonhole must contain at least two pigeons Fall 2004 COMP 335 18

pigeons. . . pigeonholes. . . Fall 2004 COMP 335 19

pigeons. . . pigeonholes. . . Fall 2004 COMP 335 19

The Pigeonhole Principle pigeons pigeonholes There is a pigeonhole with at least 2 pigeons

The Pigeonhole Principle pigeons pigeonholes There is a pigeonhole with at least 2 pigeons . . . Fall 2004 COMP 335 20

The Pigeonhole Principle and DFAs Fall 2004 COMP 335 21

The Pigeonhole Principle and DFAs Fall 2004 COMP 335 21

DFA with Fall 2004 COMP 335 states 22

DFA with Fall 2004 COMP 335 states 22

no state is repeated In walks of strings: Fall 2004 COMP 335 23

no state is repeated In walks of strings: Fall 2004 COMP 335 23

a state is repeated In walks of strings: Fall 2004 COMP 335 24

a state is repeated In walks of strings: Fall 2004 COMP 335 24

If string has length : Then the transitions of string are more than the

If string has length : Then the transitions of string are more than the states of the DFA Thus, a state must be repeated Fall 2004 COMP 335 25

In general, for any DFA: String A state has length number of states must

In general, for any DFA: String A state has length number of states must be repeated in the walk of. . . Fall 2004 . . . Repeated state COMP 335 26

In other words for a string : transitions are pigeons states are pigeonholes walk

In other words for a string : transitions are pigeons states are pigeonholes walk of. . . Fall 2004 . . . Repeated state COMP 335 27

The Pumping Lemma Fall 2004 COMP 335 28

The Pumping Lemma Fall 2004 COMP 335 28

Take an infinite regular language There exists a DFA that accepts states Fall 2004

Take an infinite regular language There exists a DFA that accepts states Fall 2004 COMP 335 29

Take string with There is a walk with label : . . Fall 2004

Take string with There is a walk with label : . . Fall 2004 walk COMP 335 30

If string has length (number of states of DFA) then, from the pigeonhole principle:

If string has length (number of states of DFA) then, from the pigeonhole principle: a state is repeated in the walk . . . Fall 2004 . . . walk COMP 335 31

Let be the first state repeated in the walk of . . . Fall

Let be the first state repeated in the walk of . . . Fall 2004 . . . walk COMP 335 32

Write . . . Fall 2004 . . . COMP 335 33

Write . . . Fall 2004 . . . COMP 335 33

Observations: number of states of DFA length . . . Fall 2004 . .

Observations: number of states of DFA length . . . Fall 2004 . . . COMP 335 34

Observation: The string is accepted . . . Fall 2004 . . . COMP

Observation: The string is accepted . . . Fall 2004 . . . COMP 335 35

Observation: The string is accepted . . . Fall 2004 . . . COMP

Observation: The string is accepted . . . Fall 2004 . . . COMP 335 36

Observation: The string is accepted . . . Fall 2004 . . . COMP

Observation: The string is accepted . . . Fall 2004 . . . COMP 335 37

In General: The string is accepted . . . Fall 2004 . . .

In General: The string is accepted . . . Fall 2004 . . . COMP 335 38

In General: Language accepted by the DFA . . . Fall 2004 . .

In General: Language accepted by the DFA . . . Fall 2004 . . . COMP 335 39

In other words, we described: The Pumping Lemma !!! Fall 2004 COMP 335 40

In other words, we described: The Pumping Lemma !!! Fall 2004 COMP 335 40

The Pumping Lemma: • Given a infinite regular language • there exists an integer

The Pumping Lemma: • Given a infinite regular language • there exists an integer • for any string with length • we can write • with and • such that: Fall 2004 COMP 335 41

Applications of the Pumping Lemma Fall 2004 COMP 335 42

Applications of the Pumping Lemma Fall 2004 COMP 335 42

Theorem: The language is not regular. Proof: Fall 2004 Use the Pumping Lemma COMP

Theorem: The language is not regular. Proof: Fall 2004 Use the Pumping Lemma COMP 335 43

Assume that is a regular language Since is an infinite language, we can apply

Assume that is a regular language Since is an infinite language, we can apply the Pumping Lemma Fall 2004 COMP 335 44

Let be the integer in the Pumping Lemma Pick a string such that: (1)

Let be the integer in the Pumping Lemma Pick a string such that: (1) and (2) length We pick: Fall 2004 COMP 335 45

Write: From the Pumping Lemma it must be that length Fall 2004 Thus: COMP

Write: From the Pumping Lemma it must be that length Fall 2004 Thus: COMP 335 46

From the Pumping Lemma: Thus: Fall 2004 COMP 335 47

From the Pumping Lemma: Thus: Fall 2004 COMP 335 47

From the Pumping Lemma: Thus: Fall 2004 COMP 335 48

From the Pumping Lemma: Thus: Fall 2004 COMP 335 48

But: CONTRADICTION!!! Fall 2004 COMP 335 49

But: CONTRADICTION!!! Fall 2004 COMP 335 49

Therefore: Our assumption that is a regular language is not true Conclusion: Fall 2004

Therefore: Our assumption that is a regular language is not true Conclusion: Fall 2004 is not a regular language COMP 335 50

Non-regular languages Regular languages Fall 2004 COMP 335 51

Non-regular languages Regular languages Fall 2004 COMP 335 51

More Applications of the Pumping Lemma Fall 2004 COMP 335 52

More Applications of the Pumping Lemma Fall 2004 COMP 335 52

The Pumping Lemma: • Given a infinite regular language • there exists an integer

The Pumping Lemma: • Given a infinite regular language • there exists an integer • for any string with length • we can write • with and • such that: Fall 2004 COMP 335 53

Non-regular languages Regular languages Fall 2004 COMP 335 54

Non-regular languages Regular languages Fall 2004 COMP 335 54

Theorem: The language is not regular Proof: Fall 2004 Use the Pumping Lemma COMP

Theorem: The language is not regular Proof: Fall 2004 Use the Pumping Lemma COMP 335 55

Assume for contradiction that is a regular language Since is infinite we can apply

Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma Fall 2004 COMP 335 56

Let be the integer in the Pumping Lemma Pick a string such that: and

Let be the integer in the Pumping Lemma Pick a string such that: and length We pick Fall 2004 COMP 335 57

Write From the Pumping Lemma it must be that length Thus: Fall 2004 COMP

Write From the Pumping Lemma it must be that length Thus: Fall 2004 COMP 335 58

From the Pumping Lemma: Thus: Fall 2004 COMP 335 59

From the Pumping Lemma: Thus: Fall 2004 COMP 335 59

From the Pumping Lemma: Thus: Fall 2004 COMP 335 60

From the Pumping Lemma: Thus: Fall 2004 COMP 335 60

BUT: CONTRADICTION!!! Fall 2004 COMP 335 61

BUT: CONTRADICTION!!! Fall 2004 COMP 335 61

Therefore: Our assumption that is a regular language is not true Conclusion: Fall 2004

Therefore: Our assumption that is a regular language is not true Conclusion: Fall 2004 is not a regular language COMP 335 62

Non-regular languages Regular languages Fall 2004 COMP 335 63

Non-regular languages Regular languages Fall 2004 COMP 335 63

Theorem: The language is not regular Proof: Fall 2004 Use the Pumping Lemma COMP

Theorem: The language is not regular Proof: Fall 2004 Use the Pumping Lemma COMP 335 64

Assume for contradiction that is a regular language Since is infinite we can apply

Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma Fall 2004 COMP 335 65

Let be the integer in the Pumping Lemma Pick a string such that: and

Let be the integer in the Pumping Lemma Pick a string such that: and length We pick Fall 2004 COMP 335 66

Write From the Pumping Lemma it must be that length Thus: Fall 2004 COMP

Write From the Pumping Lemma it must be that length Thus: Fall 2004 COMP 335 67

From the Pumping Lemma: Thus: Fall 2004 COMP 335 68

From the Pumping Lemma: Thus: Fall 2004 COMP 335 68

From the Pumping Lemma: Thus: Fall 2004 COMP 335 69

From the Pumping Lemma: Thus: Fall 2004 COMP 335 69

BUT: CONTRADICTION!!! Fall 2004 COMP 335 70

BUT: CONTRADICTION!!! Fall 2004 COMP 335 70

Therefore: Our assumption that is a regular language is not true Conclusion: Fall 2004

Therefore: Our assumption that is a regular language is not true Conclusion: Fall 2004 is not a regular language COMP 335 71

Non-regular languages Regular languages Fall 2004 COMP 335 72

Non-regular languages Regular languages Fall 2004 COMP 335 72

Theorem: The language is not regular Proof: Fall 2004 Use the Pumping Lemma COMP

Theorem: The language is not regular Proof: Fall 2004 Use the Pumping Lemma COMP 335 73

Assume for contradiction that is a regular language Since is infinite we can apply

Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma Fall 2004 COMP 335 74

Let be the integer in the Pumping Lemma Pick a string such that: length

Let be the integer in the Pumping Lemma Pick a string such that: length We pick Fall 2004 COMP 335 75

Write From the Pumping Lemma it must be that length Thus: Fall 2004 COMP

Write From the Pumping Lemma it must be that length Thus: Fall 2004 COMP 335 76

From the Pumping Lemma: Thus: Fall 2004 COMP 335 77

From the Pumping Lemma: Thus: Fall 2004 COMP 335 77

From the Pumping Lemma: Thus: Fall 2004 COMP 335 78

From the Pumping Lemma: Thus: Fall 2004 COMP 335 78

Since: There must exist Fall 2004 COMP 335 such that: 79

Since: There must exist Fall 2004 COMP 335 such that: 79

However: for any Fall 2004 COMP 335 80

However: for any Fall 2004 COMP 335 80

BUT: CONTRADICTION!!! Fall 2004 COMP 335 81

BUT: CONTRADICTION!!! Fall 2004 COMP 335 81

Therefore: Our assumption that is a regular language is not true Conclusion: Fall 2004

Therefore: Our assumption that is a regular language is not true Conclusion: Fall 2004 is not a regular language COMP 335 82