24
Lecture 7 UofH - COSC 3340 - Dr. Ve rma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Embed Size (px)

Citation preview

Page 1: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma1

COSC 3340: Introduction to Theory of Computation

University of Houston

Dr. Verma

Lecture 7

Page 2: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma2

Are all languages regular?

Ans: No. How do we know this?

– Ans: Cardinality arguments.

Let C(DFA) = {M | M is a DFA}. – C(DFA) is a countable set. Why?

Let AL = { L | L is a subset of *}. – AL is uncountable.

Page 3: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma3

Cardinality

Def: A set is countable if it is (i) finite or

(ii) countably infinite.

Def: A set S is countable infinite if there is a bijection from N to S.

– Note: Instead of N to S we can also say S to N.

N = {0, 1, 2, 3, ...} -- the set of natural numbers.

Def: A set that is not countable is uncountable.– Or, any infinite set with no bijection from N to itself.

Page 4: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma4

Examples

1. The set of chairs in this classroom is finite.

2. The set of even numbers is countably infinite.

3. The set of all subsets of N is uncountable.– Notation: 2N

Page 5: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma5

Exercises

What is the cardinality of?1. Z - the set of integers.

2. N X N = {(a,b) | a, b in N}.

3. R - the set of real numbers.

Page 6: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma6

Pumping Lemma

First technique to show that specific given languages are not regular.

Cardinality arguments show existence of languages that are not regular.

There is a big difference between the two!

Page 7: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma7

Statement of Pumping Lemma

If A is a regular language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divided into three pieces, s = xyz, satisfying the following conditions:1. for each i 0, xyiz A,

2. |y| > 0, and

3. |xy| p.

Page 8: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma8

Proof of pumping lemma

Idea: If a string w of length m is accepted by a DFA with n states, and n < m, then there is a cycle (repeated state) on the directed path from s to a final state labeled w.– Recall: directed path is denoted by *(s,w).– Uses: Pigeon-hole principle

Page 9: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma9

Pigeon-hole principle

4 pigeons

3 pigeonholes

Page 10: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma10

Pigeon-hole principle (contd.)

A pigeonhole must

have two pigeons

Page 11: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma11

Pigeon-hole principle (contd.)

...........

...........

pigeonholes

n

m

mn

Page 12: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma12

Details of Proof of Pumping Lemma.

Consider L - any infinite regular language. 1. L regular there is a DFA M with L(M) = L.

2. Let DFA have p states (say).

3. Let w in L be of length more than p. Why does w exist? Ans: because L is infinite.

4. *(s,w) = f (some final state) must be

*(s, w = xyz) = *(q,yz) = *(q,z) = f

5. So xynz in L for n = 0, 1, 2, 3, ....

since *(s, xynz) = *(q, ynz) = *(q, y{n-1}z) = ... = *(q,z) = f.

Page 13: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma13

Describing the pumping lemma

Take an infinite regular language L

DFA that accepts L

m

states

Page 14: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma14

Describing the pumping lemma (contd.)

Take string

with

w

Lw

There is a walk with label: w

.........

Page 15: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma15

Describing the pumping lemma (contd.)

If string has length w mw || number

of states

Then, from the pigeonhole principle:

A state is repeated in the walkq w

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

Page 16: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma16

Describing the pumping lemma (contd.)

Write zyxw

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

x

y

z

Page 17: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma17

Describing the pumping lemma (contd.)

Observations : myx ||length number

of states1|| ylength

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

x

y

z

Page 18: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma18

Describing the pumping lemma (contd.)

The string is accepted zxObservation:

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

x

y

z

Page 19: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma19

Describing the pumping lemma (contd.)

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

x

y

z

The string

is accepted

zyyxObservation:

Page 20: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma20

Describing the pumping lemma (contd.)

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

x

y

z

The string

is accepted

Observation: zyyyx

Page 21: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma21

Describing the pumping lemma (contd.)

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

x

y

z

The string

is accepted zyx i

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

Page 22: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma22

Some Applications of Pumping Lemma

The following languages are not regular.1. {anbn | n 0 }.

2. {w = wR | w in {a,b}* } (language of palindromes).

3. {wwR | w in {a,b}*}.

4. {a{n2} | n 0}.

Page 23: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma23

Tips of the trade -- Do not forget!

Closure properties can be used effectively for:(1) shortening cumbersome Pumping lemma

arguments. Example: {w in {a, b}* | w has equal a's and b's}.

(2) for showing that certain languages are regular. Example: {w in {a, b}* | w begins with a and w contains a b}.

Page 24: Lecture 7UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 7

Lecture 7 UofH - COSC 3340 - Dr. Verma24

References

Pigeonhole Principle & Pumping Lema Description– www.cs.rpi.edu/courses/fall00/modcomp3/class8.ppt

Author: Costas Busch, Rensselaer Polytechnic Institute, NY