CS30L7 Handout
CS30L7 Handout
Lesson 7: Functions
Main reference : Discrete Mathematics and Its Applications, 7th edition, Kenneth H. Rosen
100
90
A
80
B 70
60
C
50
In this section, we’ll discuss the basic concepts involving functions needed in discrete math-
ematics. We’ll start off with some definitions and notations.
Note that:
• Functions are sometimes also called mappings or transformations.
• We can also think of the set of all functions from A to B as a proper subset of the set
of all relations over A × B.
Example 1
1. Let g be the function that assigns grades to students in a class, illustrated in Figure 1.
2. Let f : Z → Z where f (x) = x + 1.
3. Let R be given by {(2, a), (5, b), (3, c), (−1, b), (0, e), (4, a), (1, i)}.
Copyright c 2020 Nestine Hope S. Hernandez, Richelle Ann B. Juayong and Kelvin C. Buño
nshernandez@ up. edu. ph; rbjuayong@ up. edu. ph; kcbuno@ up. edu. ph
2 CS 30 : Discrete Mathematics for Computer Science I
Example 2 For the functions in Example 1, describe the domain, the codomain, the range,
and the assignment of values to elements of the domain.
When we define a function we specify its domain, its codomain, and the mapping of elements
of the domain to elements in the codomain. Two functions are equal when they have the
same domain, have the same codomain, and map each element of their common domain to
the same element in their common codomain. Note that if we change either the domain or
the codomain of a function, then we obtain a different function. If we change the mapping
of elements, then we also obtain a different function.
Then
∀x ∈ A, (f ◦ g)(x) = f (g(x)).
In other words, f ◦ g is the function that assigns to the element x of A the element
assigned by f to g(x). That is, to find (f ◦ g)(x) we first apply the function g to x to obtain
g(x) and then we apply the function f to the result g(x) to obtain (f ◦ g)(x) = f (g(x)). Note
that the composition f ◦ g cannot be defined unless the range of g is a subset of the domain
of f .
Copyright c 2020 Nestine Hope S. Hernandez, Richelle Ann B. Juayong and Kelvin C. Buño
[email protected];[email protected];[email protected]
3 CS 30 : Discrete Mathematics for Computer Science I
(f ◦ g)(x)
g(x) f (g(x))
• • •
x g(x) f(g(x))
g f
A B C
f ◦g
Solution:
f (g(x)) = f (x2 ) = x2 + 1
g(f (x)) = g(x + 1) = (x + 1)2 = x2 + 2x + 1
Hence, g ◦ f 6= f ◦ g.
f (N) = {f (x) | x ∈ N}
= {x + 1 | x ∈ {0, 1, 2, · · · }}
= {1, 2, 3, · · · } = Z+
Suppose we have a function whose inverse is also a function. Then, we have the following
definition:
Definition 6 Let f be a function from the set A to the set B. The inverse function of f ,
if it exists, is the function that assigns to an element y belonging to B the unique element x
in A such that f (x) = y. The inverse function of f is denoted by f −1 . Hence, f −1 (y) = x
when f (x) = y.
Copyright c 2020 Nestine Hope S. Hernandez, Richelle Ann B. Juayong and Kelvin C. Buño
nshernandez@ up. edu. ph; rbjuayong@ up. edu. ph; kcbuno@ up. edu. ph
4 CS 30 : Discrete Mathematics for Computer Science I
Theorem 1
Given a set A, define the identity function idA on A as the function idA : A → A,
∀x ∈ A, idA (x) = x.
f ◦ g = idA .
(f ◦ g)(x) = f (g(x)) = f (x − 1) = (x − 1) + 1 = x
Definition 7 The floor function assigns to the real number x the largest integer that is less
than or equal to x. The value of the floor function at x is denoted by bxc.
Definition 8 The ceiling function assigns to the real number x the smallest integer that is
greater than or equal to x. The value of the ceiling function at x is denoted by dxe.
Example 10 Data stored on a computer disk or transmitted over a data network are usually
represented as a string of bytes. Each byte is made up of 8 bits. How many bytes are required
to encode 100 bits of data?
Solution:
To determine the number of bytes needed, we need to compute for how many 8 bits are in
100, but where extra bits are rounded up to 1 byte. Hence, we are computing for d100/8e =
d12.5e = 13 bytes.
Copyright c 2020 Nestine Hope S. Hernandez, Richelle Ann B. Juayong and Kelvin C. Buño
nshernandez@ up. edu. ph; rbjuayong@ up. edu. ph; kcbuno@ up. edu. ph
5 CS 30 : Discrete Mathematics for Computer Science I
The list in Theorem 2 displays some simple but important properties of the floor and
ceiling functions. Because these functions appear so frequently in discrete mathematics, it
is useful to look over these identities. Each property in this list can be established using the
definitions of the floor and ceiling functions.
2 Properties of Functions
Functions are also often classified according to whether they have these properties: injection,
surjection and bijection.
Definition 9 Let f : X → Y .
We now look at ways to prove whether or not a certain function has these properties.
Proving Injection. To prove that a function f is injective, we need to show that ∀x1 , x2 ∈
dom(f ), if f (x1 ) = f (x2 ) then x1 = x2 ).
Copyright c 2020 Nestine Hope S. Hernandez, Richelle Ann B. Juayong and Kelvin C. Buño
nshernandez@ up. edu. ph; rbjuayong@ up. edu. ph; kcbuno@ up. edu. ph
6 CS 30 : Discrete Mathematics for Computer Science I
Proving not an Injection. To prove that a function f is not injective, we need to show
that there exists x1 , x2 ∈ dom(f ), where x1 6= x2 but f (x1 ) = f (x2 ).
Proving Surjection.
To prove that f is surjective, we need to show that ran(f ) = codomain of f . That is, we
need to show that for each y ∈ codomain of f, ∃x ∈ dom(f ) such that f (x) = y.
Example 13 Let d ∈ Z+ . Show that the function f : Z → {0, 1, ..., d − 1}, defined as
f (x) = x (mod d) is surjective.
Proof: Suppose that r ∈ {0, 1, ..., d − 1}, that is 0 ≤ r < d.
Since {0, 1, ..., d − 1} ⊆ dom(f ), then f (r) is defined.
By definition of (mod d), r (mod d) = r, that is f (r) = r.
This implies that every r ∈ {0, 1, ..., d − 1} is an image of some element of Z.
Hence, the range of f is {0, 1, ..., d − 1}, which is the codomain of f . Thus, f is surjective.
Proving Bijection.
To prove that f is bijective, we need to show that f is both injective and surjective.
(Surjective) Suppose that y ∈ R. Show that there exists an x ∈ R such that f (x) = y. Let
1 1 1
x = y 3 . Hence, f (x) = f (y 3 ) = (y 3 )3 = y. Since y is chosen arbitrarily, every element of
the codomain in R is the image of some element from the domain R. Hence, the ran(f ) = R,
which is also the codomain of f . Hence, f is surjective.
The function f (x) = x3 is both injective and surjective. Therefore f is bijective.
Copyright c 2020 Nestine Hope S. Hernandez, Richelle Ann B. Juayong and Kelvin C. Buño
[email protected];[email protected];[email protected]
7 CS 30 : Discrete Mathematics for Computer Science I
1. If f is a bijection, then
(a) f −1 is a function and,
(b) f and f −1 are inverses of one another.
2. If there is a function g : Y → X such that f and g are inverses of one another, then
(a) f is a bijection and,
(b) g = f −1
1
Example 17 Let f : R → R such that f (x) = x3 . Consider g : R → R such that g(x) = x 3 .
1 1
f (g(x)) = f (x 3 ) = (x 3 )3 = x
Hence, by Theorem 1, g = f −1 .
We have previously shown that f is a bijection. Then from Theorem 3.1, g is a function
and, f and g are inverses of one another.
Note that,
1
g(f (x)) = g(x3 ) = (x3 ) 3 = x
and indeed, f = g −1 .
Example 18 Since the function g : R → R where g(x) = x2 is not bijective, then by Theorem
3.2, g is not invertible.
This serves as an accompanying handout to the video lecture series on Topic of Lecture Series for CS 30.
Copyright c 2020 Nestine Hope S. Hernandez, Richelle Ann B. Juayong and Kelvin C. Buño
[email protected];[email protected];[email protected]