Functions
Rosen 2.3, 2.5
f( ) =
A B
Lecture 5: Sept 16
Functions
f :A B
function, f, from set A to set B
f (a) B
associates an element a A.
, with an element
The domain of f is A.
The codomain of f is B.
For every input there is exactly one output.
Functions
domain = R
codomain = R+-{0}
domain = R+-{0}
codomain = R
domain = R
codomain = [0,1]
domain = R+
codomain = R+
Functions
domain = the set of all sets
f(S) = |S|
codomain = non-negative integers
domain = the set of all strings
f(string) = length(string)
codomain = non-negative integers
not a function,
f(student-name) = student-ID since one input could have
more than one output
f(x) = is-prime(x) domain = positive integers
codomain = {T,F}
Functions
•Let f1 and f2 be functions from A to R.
•Then the sum and the product of f1 and f2 are
also functions from A to R defined by:
•(f1 + f2)(x) = f1(x) + f2(x)
•(f1f2)(x) = f1(x) f2(x)
•Example:
•f1(x) = 3x, f2(x) = x + 5
•(f1 + f2)(x) = f1(x) + f2(x) = 3x + x + 5 = 4x +
5
•(f1f2)(x) = f1(x) f2(x) = 3x (x + 5) = 3x2 + 15x
Functions
•We already know that the range of a function f:AB is the set of
all images of elements aA.
•If we only regard a subset SA, the set of all images of
elements sS is called the image of S.
•If f(a)=b, b is the image of a and a is preimage of b
•We denote the image of S by f(S):
•f(S) = {f(s) | sS}
Increasing/decreasing functions
Increasing (decreasing):
•If f(x)≤f(y) (f(x)≥f(y)), whenever x<y and x,
y are in the domain of f
xy ( x y f ( x) f ( y ))
Strictly increasing (decreasing):
•If f(x)<f(y) (f(x) > f(y)) whenever x<y, and
x, y are in the domain of f
•A function that is either strictly increasing
or decreasing must be one-to-one
7
Injections (One-to-One)
f : A B is an injection iff no two inputs have the same
output.
≤ 1 arrow in
f( ) =
A B
a, a A.
( f (a ) f (a ')) (a a ') |A| ≤ |B|
Surjections (Onto)
f :A B is a surjection iff every output is possible.
f( ) = 1 arrow in
A B
b B a A. f (a ) b |A| ≥ |B|
Bijections (one-and-one correspondence)
f :A B is a bijection iff it is surjection and injection.
exactly one arrow in
f( ) =
A B
|A| = |B|
Identity function: A : A A, A ( x) x, x A
In-Class Exercises
Function Domain Codomain Injective? Surjective Bijective?
?
f(x)=sin(x Real Real
) No No No
f(x)=2x Real Positive
real Yes Yes Yes
f(x)=x2 Real Non-
negative No Yes No
real
Reverse Bit strings Bit strings
Yes Yes Yes
string of length of length
n n
Whether a function is injective, surjective, bijective
depends on its domain and the codomain.
Inverse Sets
A B
Given an element y in B, the inverse set of y := f-1(y) = {x in A | f(x) = y}.
Inverse Function
Informally, an inverse function f-1 is to “undo” the operation of function f.
exactly one arrow in
f( ) =
A B
There is an inverse function f-1 for f if and only if f is a bijection.
Composition of Functions
Two functions f:X->Y’, g:Y->Z so that Y’ is a subset of Y,
then the composition of f and g is the function g 。 f: X->Z, where
g 。 f(x) = g(f(x)).
f Y’ g
X Z
Y
In-Class Exercises
Function f Function g g。f g。f g。f
injective? surjective? bijective?
f:X->Y g:Y->Z No No No
f surjective g injective
f:X->Y g:Y->Z No Yes No
f surjective g surjective
f:X->Y g:Y->Z No No No
f injective g surjective
f:X->Y g:Y->Z Yes Yes Yes
f bijective g bijective
f:X->Y f-1:Y->X Yes Yes Yes
Pigeonhole Principle
If more pigeons
than pigeonholes,
Pigeonhole Principle
then some hole must have at least two
pigeons!
Pigeonhole principle
A function from a larger set to a smaller set cannot be injective.
(There must be at least two elements in the domain that have
the same image in the codomain.)
Example
Question: Let A = {1,2,3,4,5,6,7,8}
If five integers are selected from A,
must a pair of integers have a sum of 9?
Consider the pairs {1,8}, {2,7}, {3,6}, {4,5}.
The sum of each pair is equal to 9.
If we choose 5 numbers from this set,
then by the pigeonhole principle,
both elements of some pair will be chosen,
and their sum is equal to 9.
Birthday Paradox
a group of 366 people, there must be two people having the same birthday.
Suppose n <= 365, what is the probability that in a random set of n people,
ome pair of them will have the same birthday?
can think of it as picking n random numbers from 1 to 365 without repetition.
There are 365n ways of picking n numbers from 1 to 365.
There are 365·364·363·…·(365-n+1) ways of
picking n numbers from 1 to 365 without repetition.
So the probability that no pairs have the same birthday is
equal to 365·364·363·…·(365-n+1) / 365n
This is smaller than 50% for 23 people, smaller than 1% for 57 people.
Generalized Pigeonhole Principle
Generalized Pigeonhole Principle
If n pigeons and h holes,
n
then some hole has at least pigeons.
h
♠ ♥ ♣ ♦
Subset Sum
different subsets of the 90 25-digit numbers shown above have the same sum.
Subset Sum
90 numbers, each with at most 25 digits.
So the total sum is at most 90x1025
Let A be the set of all subsets of the 90 numbers. (pigeons)
Let B be the set of integers from 0 to 90x1025. (pigeonholes)
By pigeonhole principle, there are two different subsets with the same sum.
This is an example of a non-constructive proof.
Cardinality
Functions are useful to compare the sizes of two different sets.
Question: Are all infinite sets having the same cardinality?
Two sets A and B have the same cardinality if and only if
there is a bijection between A and B.
A set is countable if it has the same cardinality
as the set of positive integers.
When an infinite set S is countable, we denote the
cardinality of S by ℕ0, i.e., |S|= ℕ0
Integers vs Positive Integers
Is the set of integers countable?
Define a bijection between the positive integers and all integers
1 2 3 4 5 6 7 8..
.
0 1 −1 2 −2 3 −3
4...
n/2, if n is even;
f(n) =
−(n − 1)/2, if n is
odd.
So, the set of integers is countable.
Odd Positive Integers vs Positive Integers
Is the set of odd positive integers countable?
Define a bijection between the positive integers and odd positive integers
1 2 3 4 5 6 7 8...
1 3 5 7 9 11 13
15 . . .
f(n) = 2n − 1
So, the set of odd positive integers is countable.
Rational Numbers vs Positive Integers
Question: Is the set of rational number countable?
e set of “pair of integers” (a,b) is not smaller than the set of rational number.
We want to show that the set of “pair of integers”
is countable, by defining a bijection to the set of positive integers.
This would then imply the set of rational is countable.
Rational Numbers vs Positive Integers
(0, 0), (0, 1), (0,−1), (0, 2), (0,−2), (0, 3), (0,−3), . . .
(1, 0), (1, 1), (1,−1), (1, 2), (1,−2), (1, 3), (1,−3), . . .
(−1, 0),(−1, 1),(−1,−1),(−1, 2),(−1,−2),(−1, 3), (−1,−3), . . .
(2, 0), (2, 1), (2,−1), (2, 2), (2,−2), (2, 3), (2,−3), . . .
(−2, 0),(−2, 1),(−2,−1),(−2, 2),(−2,−2), (−2, 3),(−2,−3), . . .
If you map the set of positive integers to the top row first,
then you will not be able to reach the second row.
The trick is to visit the rational numbers diagonal by
diagonal.
Each diagonal is finite, so eventually every pair will be visited.
Therefore, there is a bijection from the set of positive integers,
o the set of pair of integers, and so the set of rational numbers is countable.
Real Numbers vs Positive Integers
Question 1: Is the set of real number countable?
Theorem: No surjection mapping positive integers to real numbers.
Also, show that power sets can be proved to be uncountable.
Challenge for the
Bored!!!