25
Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

Embed Size (px)

Citation preview

Page 1: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

Lecture 2.3: Set Theory, and Functions

CS 250, Discrete Structures, Fall 2014

Nitesh Saxena

*Adopted from previous lectures by Cinda Heeren

Page 2: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 2

Course Admin HW1

Provided the solution We have been grading

Mid Term 1: Oct 7 (Tues) Review Oct 2 (Thu) Covers Chapter 1 and Chapter 2

HW2 coming out: early next week Due Oct 14 (Tues)

Page 3: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 3

Outline

Sets: Inclusion/Exclusion Principle Functions

Page 4: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 4

Suppose to the contrary, that A B , and that x A B.

A Proof Pv that if (A - B) U (B - A) = (A U B) then

Then x cannot be in A-B and x cannot be in B-A.

But x is in A U B since (A B) (A U B).

A B =

Thus, A B = .

a) A U B = b) A = B

c) A B = d) A-B = B-A =

Then x is not in (A - B) U (B - A).

Page 5: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 5

Set Theory - Inclusion/Exclusion

Example:How many people are wearing a watch? aHow many people are wearing sneakers?

b

How many people are wearing a watch OR sneakers? a + b

What’s wrong?

AB

Wrong.

|A B| = |A| + |B| - |A B|

Page 6: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 6

Set Theory - Inclusion/Exclusion

Example:There are 217 cs majors.157 are taking cs125.145 are taking cs173.98 are taking both.

How many are taking neither?

217 - (157 + 145 - 98) = 13

125173

Page 7: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 7

Set Theory – Generalized Inclusion/Exclusion

Suppose we have:

And I want to know |A U B U C|

A B

C

|A U B U C| = |A| + |B| + |C|

+ |A B C| - |A B| - |A C| - |B C|

Now let’s do it for 4 sets!

kidding.

Page 8: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

Set Theory – Generalized Inclusion/Exclusion

* Image courtesy wikipedia

Page 9: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 9

Functions

Suppose we have:

And I ask you to describe the yellow function.

Notation: f: RR, f(x) = -(1/2)x - 25

What’s a function? y = f(x) = -(1/2)x - 25

domain co-domain

-50 -25

Page 10: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 10

Functions: Definitions

A function f : A B is given by a domain set A, a codomain set B, and a rule which for every element a of A, specifies a unique element f (a) in B

f (a) is called the image of a, while a is called the pre-image of f (a)

The range (or image) of f is defined byf (A) = {f (a) | a A }.

Page 11: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 11

Function or not?

A

B

A

B

Page 12: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 12

Functions: examples

Ex: Let f : Z R be given by f (x ) = x 2

Q1: What are the domain and co-domain?Q2: What’s the image of -3 ?Q3: What are the pre-images of 3, 4?Q4: What is the range f ?

Page 13: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 13

Functions: examplesf : Z R is given by f (x ) = x 2

A1: domain is Z, co-domain is RA2: image of -3 = f (-3) = 9A3: pre-images of 3: none as 3 isn’t an

integer! pre-images of 4: -2 and 2

A4: range is the set of perfect squares = {0,1,4,9,16,25,…}

Page 14: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 14

Functions: examples

A = {Michael, Tito, Janet, Cindy, Bobby}B = {Katherine Scruse, Carol Brady, Mother

Teresa}

Let f: A B be defined as f(a) = mother(a).

Michael Tito Janet Cindy Bobby

Katherine Scruse

Carol Brady

Mother Teresa

Page 15: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 15

Functions - image set

For any set S A, image(S) = {f(a) : a S}

So, image({Michael, Tito}) = {Katherine Scruse} image(A) = B - {Mother Teresa}

image(A) is also called range

image(S) = f(S)

Michael Tito Janet Cindy Bobby

Katherine Scruse

Carol Brady

Mother Teresa

Page 16: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 16

Functions – preimage set

For any S B, preimage(S) = {a A: f(a) S}

So, preimage({Carol Brady}) = {Cindy, Bobby} preimage(B) = A

preimage(S) = f-

1(S)

Michael Tito Janet Cindy Bobby

Katherine Scruse

Carol Brady

Mother Teresa

Page 17: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 19

Functions - injection

A function f: A B is one-to-one (injective, an injection) if a,b,c, (f(a) = b f(c) = b) a = c

Not one-to-one

Every b B has at most 1 preimage.

Michael Tito Janet Cindy Bobby

Katherine Scruse

Carol Brady

Mother Teresa

Page 18: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 20

Functions - surjection

A function f: A B is onto (surjective, a surjection) if b B, a A, f(a) = b

Not onto

Every b B has at least 1 preimage.

Michael Tito Janet Cindy Bobby

Katherine Scruse

Carol Brady

Mother Teresa

Page 19: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 21

Functions - bijection

A function f: A B is bijective if it is one-to-one and onto.

Isaak Bri

Lynette

Aidan Evan

Cinda Dee Deb Katrina Dawn

Every b B has exactly 1 preimage.

An important implication of this

characteristic:The preimage (f-1)

is a function!

Alice Bob Tom

Charles Eve

A B C D

A-

Page 20: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 22

Functions - examples

Suppose f: R+ R+, f(x) = x2.

Is f one-to-one?

Is f onto?

Is f bijective?

yes

yes

yes

Page 21: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 23

Functions - examples

Suppose f: R R+, f(x) = x2.

Is f one-to-one?

Is f onto?

Is f bijective?

no

yes

no

Page 22: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 24

Functions - examples

Suppose f: R R, f(x) = x2.

Is f one-to-one?

Is f onto?

Is f bijective?

no

no

no

Page 23: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 25

Functions - examples

Q: Which of the following are 1-to-1, onto, a bijection? If f is invertible, what is its inverse?

1. f : Z R is given by f (x ) = x 2

2. f : Z R is given by f (x ) = 2x3. f : R R is given by f (x ) = x 3

4. f : Z N is given by f (x ) = |x |5. f : {people} {people} is given by

f (x ) = the father of x.

Page 24: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 26

Functions - examples

1. f : Z R, f (x ) = x 2: none2. f : Z Z, f (x ) = 2x : 1-13. f : R R, f (x ) = x 3: 1-1, onto,

bijection, inverse is f (x ) = x (1/3)

4. f : Z N, f (x ) = |x |: onto5. f (x ) = the father of x : none

Page 25: Lecture 2.3: Set Theory, and Functions CS 250, Discrete Structures, Fall 2014 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren

9/6/2011Lecture 2.3 -- Set Theory, and

Functions 27

Today’s Reading Rosen 2.3 and 2.4