Functions
Functions
Subtitle
E. Zimudzi
Department of Computer Science
University of Botswana
30 September, 2024
1 / 36
OUTLINE
1. INTRODUCTION TO FUNCTIONS
2. ONE-TO-ONE FUNCTIONS
3. ONTO FUNCTIONS
4. INVERSE FUNCTIONS
5. COMPOSITION OF FUNCTIONS
6. THE GRAPHS OF FUNCTIONS
2 / 36
Function
Definition 1
Let A and B be nonempty sets. A function f from A to B is an assignment of exactly one
element of B to each element of A. We write f (a) = b if b is the unique element of B assigned
by the function f to the element a of A. If f is a function from A to B, we write f : A → B.
Only (c) defines a function from X = {a, b, c} to Y = {1, 2, 3, 4}. In (a) the element b in X is
not related to any element of Y because there is no arrow that points from b to an element in
Y . And in (b) the element c is not related to a unique element of Y because from c there are
two arrows that point to two different elements of Y - one toward 2 and the other toward 3.
3 / 36
Definition 2
If f is a function from A to B, we say that A is the domain of f and B is the codomain of
f . If f (a) = b, we say that b is the image of a and a is a preimage of b. The range, or
image, of f is the set of all images of elements of A. Also, if f is a function from A to B, we
say that f maps A to B.
4 / 36
Example
Let R be the relation with ordered pairs (Abdul, 22), (Brenda, 24), (Carla, 21), (Desire, 22),
(Eddie, 24), and (Felicia, 22). Here each pair consists of a graduate student and this student’s
age. Specify a function determined by this relation.
Solution
If f is a function specified by R, then f (Abdul) = 22, f (Brenda) = 24, f (Carla) = 21,
f (Desire) = 22, f (Eddie) = 24, and f (F elicia) = 22. [Here, f (x) is the age of x, where x
is a student.] For the domain, we take the set Abdul, Brenda, Carla, Desire, Eddie, Felicia.
We also need to specify a codomain, which needs to contain all possible ages of students.
Because it is highly likely that all students are less than 100 years old, we can take the set of
positive integers less than 100 as the codomain.
5 / 36
Example
Let f be the function that assigns the last two bits of a bit string of length 2 or greater to that
string. For example, f (11010) = 10. Then, the domain of f is the set of all bit strings of
length 2 or greater, and both the codomain and range are the set 00, 01, 10, 11.
6 / 36
Example
Let f : Z → Z assign the square of an integer to this integer. Then, f (x) = x2 , where the
domain of f is the set of all integers, the codomain of f is the set of all integers, and the
range of f is the set of all integers that are perfect squares, namely, 0, 1, 4, 9, ....
7 / 36
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
8 / 36
Example
Let f1 and f2 be functions from R to R such that f1 (x) = x2 and f2 (x) = x − x2 . What are
the functions f1 + f2 and f1 f2 ?
Solution
From the definition of the sum and product of functions, it follows that
9 / 36
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) = t|∃s ∈ S(t = f (s)). We also use the shorthand f (s)|s ∈ S to
denote this set.
The notation f (S) for the image of the set S under the function f is potentially ambiguous.
Here, f (S) denotes a set, and not the value of the function f for the set S.
10 / 36
Example
Let A = {a, b, c, d, e} and B = {1, 2, 3, 4} with f (a) = 2, f (b) = 1, f (c) = 4, f (d) = 1, and
f (e) = 1. The image of the subset S = {b, c, d} is the set f (S) = {1, 4}.
11 / 36
Definition
One-to-One Function
A function f is said to be one-to-one, or an injection, if and only if f (a) = f (b) implies that
a = b for all a and b in the domain of f . A function is said to be injective if it is one-to-one.
NB: A function f is one-to-one if and only if f (a) ̸= f (b) whenever a ̸= b. This way of
expressing that f is one-to-one is obtained by taking the contrapositive of the implication in
the definition.
Using quantifiers
∀a∀b(f (a) = f (b) → a = b)
, or equivalently
∀a∀b(a ̸= b → f (a) ̸= f (b))
12 / 36
Example
Determine whether the function f from a, b, c, d to 1, 2, 3, 4, 5 with f (a) = 4, f (b) = 5,
f (c) = 1, and f (d) = 3 is one-to-one.
Solution The function f is one-to-one because f takes on different values at the four
elements of its domain.
13 / 36
Example
Determine whether the function f (x) = x2 from the set of integers to the set of integers is
one-to-one.
Solution: The function f (x) = x2 is not one-to-one because, for instance, f (1) = f (−1)1,
but 1 ̸= −1.
Example
Determine whether the function f (x) = x2 from Z+ XZ+ is one-to-one.
Solution: The function f (x) = x2 from Z+ XZ+ is one-to-one, ∀x∀y(f (x) = f (y) → x = y).
14 / 36
Example
1
Show that the function f : R − 0 → R defined as f (x) = x + 1 is injective.
Proof:
Suppose that f : R − {0} and f (a) = f (b).
This means
1 1
+1= +1
a b
1 1
=
a b
a=b
1
The function f (x) = x + 1 is one-to-one.
15 / 36
Example √
Prove that f : [−2, ∞) → R given by f (x) = x + 2 is injective.
Proof:
Suppose √= f (b) for some a, b ∈ [−2, ∞).
√ that f (a)
Then, a + 2 = b + 2
√ √
a+2= b+2
a+2=b+2
a=b
√
The function f (x) = x + 2 is one-to-one.
16 / 36
Onto
A function f from A to B is called onto, or a surjection, if and only if for every element
b ∈ B there is an element a ∈ A with f (a) = b. A function f is called surjective if it is onto.
A function f is onto if ∀y∃x(f (x) = y), where the domain for x is the domain of the function
and the domain for y is the codomain of the function.
Example Let f be the function from {a, b, c, d} to {1, 2, 3} defined by f (a) = 3, f (b) = 2,
f (c) = 1, and f (d) = 3. Is f an onto function?
Because all three elements of the codomain are images of elements in the domain, we see that
f is onto. Note that if the codomain were {1, 2, 3, 4}, then f would not be onto.
17 / 36
Example
Is the function f (x) = x2 from the set of integers to the set of integers onto?
Solution:
The function f is not onto because there is no integer x with x2 = −1, for instance.
18 / 36
Example
Let f be the function from {a, b, c, d} to {1, 2, 3} defined by f (a) = 3, f (b) = 2, f (c) = 1, and
f (d) = 3. Is f an onto function?
Solution: Because all three elements of the codomain are images of elements in the domain,
we see that f is onto. Note that if the codomain were {1, 2, 3, 4}, then f would not be onto.
19 / 36
Figure: Examples of different types of correspondences.
20 / 36
Example
1
Prove that f : R − 2 → R − {0} given by f (x) = x−2 is onto.
f : X → Y is onto iff ∀y ∈ Y ∃x ∈ X such that f (x) = y. Proof:
Let y ∈ R − 0.
1+2y 1+2y
Then, we can write x = y since y ̸= 0. Note, x ̸= 2, if it was 2, 2 = y ↔0=1
Then,
21 / 36
Example
Prove f : ZXZ → Z is onto if f (m, n) = 2m − n.
f : X → Y is onto iff ∀y ∈ Y ∃x ∈ X such that f (x) = y.
Proof:
Suppose y ∈ Z.
Then, (0, −y) ∈ ZXZ, and
23 / 36
Suppose that f : A → B
To show that it is injective Show that if f (x) = f (y) for arbitrary x, y ∈ A, then x = y.
To show that f is not injective Find particular elements x, y ∈ A such that x ̸= y and
f (x) = f (y).
To show that f is surjective Consider an arbitrary element y ∈ B and find an element x ∈ A
such that f (x) = y.
To show that f is not surjective Find a particular y ∈ B such that f (x) ̸= y for all x ∈ A.
24 / 36
Inverse Function
Definition
Let f be a one-to-one correspondence from the set A to the set B. The inverse function of f is
the function that assigns to an element b belonging to B the unique element a in A such that
f (a) = b. The inverse function of f is denoted by f −1 . Hence, f −1 (b) = a when f (a) = b.
• A one-to-one correspondence is called invertible because we can define an inverse of this
function.
• A function is not invertible if it is not a one-to-one correspondence, because the inverse
of such a function does not exist.
25 / 36
Example
Let f be the function from {a, b, c} to {1, 2, 3} such that f (a) = 2, f (b) = 3, and f (c) = 1.
Is f invertible, and if it is, what is its inverse?
Solution:
The function f is invertible because it is a one-to-one correspondence. The inverse function
f −1 reverses the correspondence given by f ,
so f −1 (1) = c, f −1 (2) = a, and f −1 (3) = b.
26 / 36
Example
Let f be the function from R to R with f (x) = x2 . Is f invertible?
Solution:
Because f (−2) = f (2) = 4, f is not one-to-one. If an inverse function were defined, it would
have to assign two elements to 4. Hence, f is not invertible.
(Note we can also show that f is not invertible because it is not onto.)
27 / 36
Example
5x−3
Find the inverse of f (x) = 3x+1 .
28 / 36
Composition of Functions
Let g be a function from the set A to the set B and let f be a function from the set B to the
set C. The composition of the functions f and g, denoted for all a ∈ A by f ◦ g, is the
function from A to C defined by
(f ◦ g)(a) = f (g(a)).
29 / 36
Example
Let g be the function from the set {a, b, c} to itself such that g(a) = b, g(b) = c, and g(c) = a.
Let f be the function from the set {a, b, c} to the set {1, 2, 3} such that f (a) = 3, f (b) = 2,
and f (c) = 1. What is the composition of f and g, and what is the composition of g and f?
Solution: The composition f ◦ g is defined by
(f ◦ g)(a) = f (g(a)) = f (b) = 2,
(f ◦ g)(b) = f (g(b)) = f (c) = 1, and
(f ◦ g)(c) = f (g(c)) = f (a) = 3.
30 / 36
Figure: The composition of the functions f and g.
31 / 36
Example
Let f and g be the functions from the set of integers to the set of integers defined by
f (x) = 2x + 3 and g(x) = 3x + 2. What is the composition of f and g? What is the
composition of g and f ?
Solution:
Both the compositions f ◦ g and g ◦ f are defined. Moreover,
(f ◦ g)(x) = f (g(x)) = f (3x + 2) = 2(3x + 2) + 3 = 6x + 7
and
(g ◦ f )(x) = g(f (x)) = g(2x + 3) = 3(2x + 3) + 2 = 6x + 11.
Note that the commutative law does not hold for the composition of functions.
32 / 36
The Graphs of Functions
Definition
Let f be a function from the set A to the set B. The graph of the function f is the set of
ordered pairs {(a, b)|a ∈ A and f (a) = b}.
33 / 36
Example
Display the graph of the function (1) f (n) = 2n + 1, and (2) f (x) = x2 from the set of
integers to the set of integers.
34 / 36
Floor and Ceiling Functions
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 ⌊x⌋.
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 ⌈x⌉.
35 / 36
The End
36 / 36