0% found this document useful (0 votes)
54 views7 pages

CS30L7 Handout

The document discusses functions, which are important in mathematics and computer science. It defines what a function is and provides examples. It also defines domain, codomain, range, and inverse functions. It discusses operations on functions like addition, multiplication, and composition. It introduces special functions like floor and ceiling functions.

Uploaded by

Race Cari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views7 pages

CS30L7 Handout

The document discusses functions, which are important in mathematics and computer science. It defines what a function is and provides examples. It also defines domain, codomain, range, and inverse functions. It discusses operations on functions like addition, multiplication, and composition. It introduces special functions like floor and ceiling functions.

Uploaded by

Race Cari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1 CS 30 : Discrete Mathematics for Computer Science I

Lesson 7: Functions
Main reference : Discrete Mathematics and Its Applications, 7th edition, Kenneth H. Rosen

In many instances we assign to each element of a set a particular element of a second


set. For example, suppose that we wish to assign to each student in a discrete mathematics
class, a numerical grade from 50 to 100. This assignment is an example of a function.

100

90
A
80

B 70

60

C
50

Figure 1: An example of a function that assigns grades to students

The concept of a function is extremely important in mathematics and computer science.


For example, in discrete mathematics, functions are used in the definition of discrete struc-
tures such as sequences and strings. Functions are also used to represent how long it takes
a computer to solve problems of a given size. Many computer programs and subroutines are
designed to calculate values of functions. Recursive functions, which are functions defined in
terms of themselves, are used throughout computer science.

1 Definitions and Notations

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.

Definition 1 Given sets A and B, a function from A to B, denoted as f : A → B, is a


relation from A to B such that each x ∈ A is related to a unique y ∈ B.
The function f can also be written as f (x) = y, or x f y, or (x, y) ∈ f . When f is understood
to be the function in context, it can also be denoted as x 7→ y.

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

Definition 2 If f is a function from A to B, we say that

1. The domain of f , denoted as dom(f ) is A.


2. The codomain of f is B.
3. If f (x) = y, we say that y is the image of x and x is a preimage of y.
4. The range, or image, of f is

ran(f ) = {y | y ∈ B, x 7→ y, for some x ∈ A}

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.

1.1 Operations on Functions


A function is called real-valued if its codomain is the set of real numbers, and it is called
integer-valued if its codomain is the set of integers. Two real-valued functions or two integer-
valued functions with the same domain can be added, as well as multiplied.

Definition 3 Let f1 and f2 be functions from A to R. Then f1 + f2 and f1 f2 are also


functions from A to R defined for all x ∈ A by
(f1 + f2 )(x) = f1 (x) + f2 (x),
(f1 f2 )(x) = f1 (x)f2 (x).
Example 3 Suppose f1 and f2 are functions from R to R where

f1 (x) = x2 and f2 (x) = x + 1

Then

(f1 + f2 )(x) = f1 (x) + f2 (x) = x2 + x + 1

(f1 f2 )(x) = f1 (x)f2 (x) = x2 (x + 1) = x3 + x2

Definition 4 Given functions g : A → B and f : B → C, the composition of the


functions f and g, denoted by f ◦ g, is the function f ◦ g : A → C, defined as

∀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

Figure 2: Illustration of composition of the functions f and g, f ◦ g : A → C

Example 4 Let f : Z → Z be defined as f (x) = x + 1, and let g : Z → Z be defined as


g(x) = x2 . What is f ◦ g? Is g ◦ f = 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.

When f is a function from A to B, the image of a subset of A can also be defined.

Definition 5 Let f be a function from A to B and let S be a subset of A. The image of


S under the function f is the subset of B that consists of the images of the elements of
S. We denote the image of S by f (S), so f (S) = {f (x) | x ∈ S}.

Example 5 Suppose f : Z → Z where f (x) = x + 1.


What is f (N)?

f (N) = {f (x) | x ∈ N}
= {x + 1 | x ∈ {0, 1, 2, · · · }}
= {1, 2, 3, · · · } = Z+

1.2 Inverse Images


Since a function is a relation, then it has an inverse. But the inverse may not be a function.
Example 6 Consider the function g : R → R, g(x) = x2 . We can think of this as the
relation g = {(x, x2 ) | x ∈ R}. Its inverse is the relation g −1 = {(x2 , x) | x ∈ R}. Note that
g −1 is not a function, since (1, 1) and (1, −1) are both in g −1 .

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

Example 7 Let f : R → R, f (x) = x + 1.


Then, we say that g : R → R, g(x) = x − 1 is the inverse of f since ∀x ∈ R:
Suppose f (x) = y, that is, y = x + 1. Then g(y) = g(x + 1) = (x + 1) − 1 = x.

Theorem 1
Given a set A, define the identity function idA on A as the function idA : A → A,

∀x ∈ A, idA (x) = x.

The function g : B → A is said to be the inverse of the function f : A → B if

f ◦ g = idA .

Example 8 Consider the previous example.


Let f : R → R, f (x) = x + 1.
Then, we say that g : R → R such that g(x) = x − 1, is the inverse of f since

(f ◦ g)(x) = f (g(x)) = f (x − 1) = (x − 1) + 1 = x

Example 9 Show that f : R → R, defined by f (x) = x3 , and g : R → R, defined by


1
g(x) = x 3 are inverses of one another.

1.3 Special Types of Functions


Next, we introduce two important functions in discrete mathematics, namely, the floor and
ceiling functions. These functions are often used when objects are counted. They play an
important role in the analysis of the number of steps used by procedures to solve problems
of a particular size.

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

Theorem 2 Let n ∈ Z and x ∈ R. Then


(1a) bxc = n if and only if n ≤ x < n + 1
(1b) dxe = n if and only if n − 1 < x ≤ n

(1c) bxc = n if and only if x − 1 < n ≤ x


(1d) dxe = n if and only if x ≤ n < x + 1
(2) x − 1 < bxc ≤ x ≤ dxe < x + 1
(3a) b−xc = −dxe

(3b) d−xe = −bxc


(4a) bx + nc = bxc + n
(4b) dx + ne = dxe + n

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 .

(a) f is one-to-one, or injective (f : X  Y ), iff

∀x1 , x2 ∈ X, f (x1 ) = f (x2 ) → x1 = x2

(b) f is onto, or surjective (f : X  Y ), iff ran(f ) = Y .


(c) f is bijective (f : X  → Y ), iff f is both one-to-one and onto. That is, each
element of Y is the image of exactly one element of X.

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 ).

Example 11 Show that the function f : Z → Z, defined as f (x) = 2x is injective.


Proof: Suppose that n1 , n2 ∈ Z, and f (n1 ) = f (n2 ). That is 2n1 = 2n2 . Multiplying both
sides by 12 , the result would be n1 = n2 .
Hence, f is injective.


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 ).

Example 12 Show that g : R → R, defined as g(x) = x2 , is not injective.


Proof: Note that g(1) = 12 = 1 and g(−1) = (−1)2 = 1.
Hence, there exist x1 , x2 ∈ R such that g(x1 ) = g(x2 ) ∧ x1 6= x2 .
Therefore, g is not injective.

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 not a Surjection.


To prove that f is not surjective, we need to show that there is an element of codomain
of f which is not in ran(f ).

Example 14 Show that g : R → R, defined as g(x) = x2 , is not surjective.


Proof: Note that −1 ∈ R (codomain of g), but there is no real number x such that
g(x) = x2 = −1. (Only ± i have squares equal to −1, but ± i ∈
/ R.)
Hence, −1 ∈/ ran(g). Therefore, g is not surjective.


Proving Bijection.
To prove that f is bijective, we need to show that f is both injective and surjective.

Example 15 Let f : R → R, defined by f (x) = x3 . Show that f is bijective.


Proof: (Injective) Suppose that x1 , x2 ∈ R, and that f (x1 ) = f (x2 ). That is, x31 = x32 .
Taking the cuberoot of both sides, we have x1 = x2 . Hence, f is injective.

(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

Proving not a Bijection.


To prove that f is not bijective, we need to show that either f is not injective or f is not
surjective.

Example 16 The function g : R → R where g(x) = x2 is not bijective.

If a function f is not a one-to-one correspondence, we cannot define an inverse function of


f . Since if f is not a one-to-one correspondence, then either it is not one-to-one or it is not
onto. If f is not one-to-one, some element y in the codomain is the image of more than one
element in the domain. If f is not onto, for some element y in the codomain, no element x in
the domain exists for which f (x) = y. Consequently, if f is not a one-to-one correspondence,
we cannot assign to each element y in the codomain a unique element x in the domain such
that f (x) = y (because for some y there is either more than one such x or no such x). We say
that a one-to-one correspondence is invertible because we can define an inverse function of
this function. This is summarized in the following theorem:

Theorem 3 Let f : X → Y be any function,

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]

You might also like