Week 7 - Friday. What did we talk about last time? Set disproofs Russell’s paradox Function...

38
CS322 Week 7 - Friday

Transcript of Week 7 - Friday. What did we talk about last time? Set disproofs Russell’s paradox Function...

CS322Week 7 - Friday

Last time

What did we talk about last time? Set disproofs Russell’s paradox Function basics

Questions?

Logical warmup

A man has two 10 gallon jars The first contains 6 gallons of wine and the

second contains 6 gallons of water He poured 3 gallons of wine into the water

jar and stirred Then he poured 3 gallons of the mixture in

the water jar into the wine jar and stirred Then he poured 3 gallons of the mixture in

the wine jar into the water jar and stirred He continued the process until both jars

had the same concentration of wine How many pouring operations did he do?

Functions

Definitions

A function f from set X to set Y is a relation between elements of X (inputs) and elements of Y (outputs) such that each input is related to exactly one output

We write f: X Y to indicate this X is called the domain of f Y is called the co-domain of f The range of f is { y Y | y = f(x), for

some x X} The inverse image of y is { x X | f(x) = y

}

Examples

Using standard assumptions, consider f(x) = x2

What is the domain? What is the co-domain? What is the range? What is f(3.2)? What is the inverse image of 4?

Assume that the set of positive integers is the domain and co-domain What is the range? What is f(3.2)? What is the inverse image of 4?

Arrow diagrams

With finite domains and co-domains, we can define a function using an arrow diagram

What is the domain? What is the co-domain? What are f(a), f(b), and f(c)? What is the range? What are the inverse images of 1, 2, 3, and 4? Represent f as a set of ordered pairs

a

b

c

1

2

3

4

X Yf

Functions?

Which of the following are functions from X to Y?

a

b

c

1234

X Yf

a

b

c

1234

X Yg

a

b

c

1234

X Yh

Function equality

Given two functions f and g from X to Y,

f equals g, written f = g, iff: f(x) = g(x) for all x X

Let f(x) = |x| and g(x) = Does f = g?

Let f(x) = x and g(x) = 1/(1/x) Does f = g?

2x

Applicability of functions

Functions can be defined from any well-defined set to any other

There is an identity function from any set to itself

We can represent a sequence as a function from a range of integers to the values of the sequence

We can create a function mapping from sets to integers, for example, giving the cardinality of certain sets

Logarithms

You should know this already But, this is the official place where it

should be covered formally There is a function called the

logarithm with base b of x defined from R+ - {1} to R as follows: logb x = y by = x

Functions defined on Cartesian products

For a function of multiple values, we can define its domain to be the Cartesian product of sets

Let Sn be strings of 1's and 0's of length n An important CS concept is Hamming

distance Hamming distance takes two binary strings of

length n and gives the number of places where they differ

Let Hamming distance be H: Sn x Sn Znonneg

What is H(00101, 01110)? What is H(10001, 01111)?

Well-defined functions

There are two ways in which a function can be poorly defined

It does not provide a mapping for every value in the domain

Example: f: R R such that f(x) = 1/x It provides more than one mapping for

some value in the domain Example: f: Q Z such that f(m/n) = m,

where m and n are the integers representing the rational number

One-to-one functions

Let F be a function from X to YF is one-to-one (or injective) if and

only if: If F(x1) = F(x2) then x1 = x2

Is f(x) = x2 from Z to Z one-to-one? Is f(x) = x2 from Z+ to Z one-to-one? Is h(x) one-to-one?

a

b

c

1234

X Yh

Proving one-to-one

To prove that f from X to Y is one-to-one, prove that x1, x2 X, f(x1) = f(x2) x1 = x2

To disprove, just find a counter example

Prove that f: R R defined by f(x) = 4x – 1 is one-to-one

Prove that g: Z Z defined by g(n) = n2 is not one-to-one

Onto functions

Let F be a function from X to YF is onto (or surjective) if and only

if: y Y, x X such that F(x) = y

Is f(x) = x2 from Z to Z onto? Is f(x) = x2 from R+ to R+ onto? Is h(x) onto?

a

b

c

123

X Yh

Inverse functions

If a function F: X Y is both one-to-one and onto (bijective), then there is an inverse function F-1: Y X such that: F-1(y) = x F(x) = y, for all x X and y

Y

Composition of Functions

Composition of functions

If there are two functions f: A B and g: Y Z such that the range of f is a subset of the domain of g, we can define a new function g o f: A Z such that (g o f)(x) = g(f(x)), for all x A

Finite sets

As before, we can show these functions for finite sets using arrow diagrams

What's the arrow diagram for (g o f)(x)?

1

2

3

e

x

y

z

a

b

c

d

f g

Identity function

The identity function (on set X) maps elements from set X to themselves

Thus, the identity function ix: X X is: iX(x) = x

For functions f: X Y and g: Y X What is (f o iX)(x)?

What is (iX 0 g)(x)?

One-to-one and onto

If functions f: X Y and g: Y Z are both one-to-one, then g o f is one-to-one

If functions f: X Y and g: Y Z are both onto, then g o f is onto

How would you go about proving these claims?

Inverses

If f: X Y is one-to-one and onto with inverse function f-1: Y X, then What is f-1 o f? What is f o f-1?

Pigeonhole PrincipleStudent Lecture

Pigeonhole Principle

Pigeonhole principle

If n pigeons fly into m pigeonholes, where n > m, then there is at least one pigeonhole with two or more pigeons in it

More formally, if a function has a larger domain than co-domain, it cannot be one-to-one

We cannot say exactly how many pigeons are in any given holes

Some holes may be empty But, at least one hole will have at least two

pigeons

Pigeonhole examples

A sock drawer has white socks, black socks, and red argyle socks, all mixed together,

What is the smallest number of socks you need to pull out to be guaranteed a matching pair?

Let A = {1, 2, 3, 4, 5, 6, 7, 8} If you select five distinct elements from A,

must it be the case that some pair of integers from the five you selected will sum to 9?

Generalized pigeonhole principle

If n pigeons fly into m pigeonholes, and for some positive integer k, n > km, then at least one pigeonhole contains k + 1 or more pigeons in it

Example: In a group of 85 people, at least 4 must

have the same last initial

Cardinality

Cardinality

Cardinality gives the number of things in a set

Cardinality is: Reflexive: A has the same cardinality as A Symmetric: If A has the same cardinality as B, B

has the same cardinality as A Transitive: If A has the same cardinality as B, and

B has the same cardinality as C, A has the same cardinality as C

For finite sets, we could just count the things to determine if two sets have the same cardinality

Cardinality for infinite sets

Because we can't just count the number of things in infinite sets, we need a more general definition

For any sets A and B, A has the same cardinality as B iff there is a bijective mapping A to B

Thus, for any element in A, it corresponds to exactly one element in B, and everything in B has exactly one corresponding element in A

Cardinality example

Show that the set of positive integers has the same cardinality as the set of all integers

Hint: Create a bijective function from all integers to positive integers

Hint 2: Map the positive integers to even integers and the negative integers to odd integers

Countability

A set is called countably infinite if it has the same cardinality as Z+

You have just shown that Z is countable It turns out that (positive) rational numbers

are countable too, because we can construct a table of their values and move diagonally across it, numbering values, skipping numbers that have been listed already

1/1 1/2 1/3 1/4

2/1 2/2 2/3 2/4

3/1 3/2 3/3 3/4

4/1 4/2 4/3 4/4

Uncountability

We showed that positive rational numbers were countable, but a trick similar to the one for integers can show that all rational numbers are countable

The book gives a classic proof that real numbers are not countable, but we don't have time to go through it

For future reference, the cardinality of positive integers, countable infinity, is named 0 (pronounced aleph null)

The cardinality of real numbers, the first uncountable infinity (because there are infinitely many uncountable infinities), is named 1 (pronounced aleph 1)

Upcoming

Next time…

Relations (after Spring Break) Exam 2 is the Monday after the

Monday after Spring Break

Reminders

Work on Homework 5 Due on Monday after Spring Break

Look at Homework 6 Read Chapter 8 for after Spring

Break