1
COMP S264F Unit 4:
Functions
Dr. Keith Lee
School of Science and Technology
Hong Kong Metropolitan University
2
Overview
• What is a function?
• Domain, image, range
• One-to-one, Onto, Bijective
• Inverse function
• Composite function
• Non-functions
• Some useful functions:
➢floor, ceiling, exponential, log, mod
• Cardinality of infinite sets: Countable / Uncountable
• Functions with more than 1 argument
3
Functions
• Let A and B be 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 element of B assigned to
the element a of A.
Example: Let A = {John, Mary, Peter}. Let B = {A,B,C,D,E}.
Define a function Grade as follows:
A
Grade(John) = A John B
Grade(Mary) = A Mary C
Grade(Peter) = D Peter D
E
NB. A function is also called a mapping.
4
Basic terminology
Consider a function f from A to B.
• A is the domain of f. A B
• B is the codomain of f.
• We write f : A → B
• If f(a) = b, b is the image of a.
• The range of f is the set comprising the images of
elements of A.
I.e., { b | b B and ( a f(a) = b ) }.
Example: Let f1 be the function from ℤ to ℤ such that, for
every x ℤ, f1(x) = x2.
Domain = ℤ. Range = ℤ ?
5
One-to-one, Onto, Bijective
• A function f is said to be one-to-one (injective) if, for every
distinct elements x, y in the domain, f(x) f(y).
• A function f from A to B is said to be onto (surjective) if, for
every element b of codomain B, there exists an element a
of A such that f(a) = b.
B
➢I.e., the range of f is exactly B.
A
• A one-to-one and onto function is also called a one-to-one
correspondence, or a bijective function, or a bijection.
6
Example 1
Consider a function f2: ℤ → ℕ such that,
for any a ℤ, f2(a) = a2.
• Is f2 one-to-one?
• Is f2 onto?
• If f2 is one-to-one (injective), then for any x, y ℤ,
➢ x y f2(x) f2(y)
➢ In other words, f2(x) = f2(y) x = y
• If f2 is onto (surjective), then for any b ℕ,
there is a ℤ such that f2(a) = b.
7
Example 1 (cont’)
Consider a function f2: ℤ → ℕ such that,
for any a ℤ, f2(a) = a2.
• Is f2 one-to-one?
No. Let x = -2 and y = 2.
Then, f(x) = (-2)2 = 4 and f(y) = 22 = 4.
Therefore, x y f2(x) f2(y) is false.
• Is f2 onto?
No. Let b = 2.
b = f2(a) 2 = a2
a = 2 or − 2
Therefore, there does not exist a ℤ such that f2(a) = b.
8
Example 2
Consider a function f3: ℤ → ℤ such that,
for any a ℤ, f3(a) = a-1.
• Is f3 one-to-one?
Yes. Let x and y such that f3(x) = f3(y).
x-1 = y -1
x=y
• Is f3 onto?
Yes. For any b ℤ,
b = f3(a) a-1 = b
a = b+1
aℤ
• Therefore, f3 is bijective.
9
f
Inverse functions A
f -1
B
• If f is a bijection (one-to-one and onto function) from the set
A to the set B, then we can define the inverse of f (denoted
by f -1) as follows:
➢f -1 is a function from B to A.
➢For every element b of B, f -1(b) = a if and only if f(a) = b.
1. Is f -1 a bijection?
2. Recall that f3(a) = a+1 for any a ℤ. What is the inverse of f3?
3. If f is not one-to-one, f -1 may not be well-defined. Why?
4. What happens if f is not an onto function?
10
Composite functions A
g
B
f
C
Consider two functions
g : A → B and f : B → C.
The composition of f and g, denoted by f g, is a function
from A to C, defined as follows.
For any a A, f g (a) = f( g (a) ).
Note that g f may not be well-defined.
Example: For x ℝ, f(x) = 3x + 2 and g(x) = x2 + x.
• f g (x) = ?
• g f (x) = ?
• What is f3-1 f3 ? f3 f3-1 ?
11
Non-functions
• If f(a) = b has more than one value or no value of b for a
particular a, then f is a non-function (i.e., not a function).
➢ f is just a relation that relates a to b.
Function or non-function?
1. 𝑓: ℝ → ℝ such that 𝑥 = (𝑓 𝑥 )2 .
Non-function. When 𝑥 = 4, 𝑓 𝑥 = 2 or − 2.
2. 𝑓: ℝ → ℝ such that 𝑓(𝑥) = 𝑥.
Non-function. 𝑓(𝑥) is undefined if 𝑥 < 0.
3. 𝑓: ℝ+ → ℝ such that 𝑓(𝑥) = 𝑥.
Function. 𝑓(𝑥) has exactly one value for all 𝑥 ℝ+.
12
The floor and ceiling functions
• Floor function: f(x) = x, where f(x) ℤ and f(x) x f(x) + 1
• E.g., 2.3 = 2
-2.3 = -3
• Ceiling function: f(x) = x, where f(x) ℤ and f(x) - 1 x f(x)
• E.g., 2.3 = 3
-2.3 = -2
13
Floor and ceiling properties
Floor Ceiling
𝑥+1 = 𝑥 +1 𝑥+1 = 𝑥 +1
𝑥−1 = 𝑥 −1 𝑥−1 = 𝑥 −1
𝑥 = 𝑥 if and only if 𝑥 ∈ ℤ
𝑥 = 𝑥 + 1 if and only if 𝑥 ℤ
• Is the inverse of the floor function
well-defined?
• Is the inverse of the ceiling function
well-defined?
14
Exponential Functions
• f(x) = bx is the exponential function for the base b, where
b 1 and b 0.
• f : ℝ → ℝ+
• E.g., when the base b = 2, f(x) = 2x.
Properties: Let a, b ℝ+ s.t. a 1, b 1, and let x, y ℝ.
• •
• •
•
•
•
•
15
Logarithmic functions (log functions)
• The inverse of an exponential function is called a
logarithmic function.
• For b > 0 and b 1,
f(x) = logb x is equivalent to x = bf(x) .
• logb x is read as log to the base b of x.
• f : ℝ+ → ℝ
• ln x = loge x (natural log; e = 2.7182… is the Euler’s number)
• lg x = log2 x (binary log)
• log x may equal log10 x or log2 x depending on context.
16
Graph of Log function
exp(x) = ex and ln(x) = loge(x)
17
Log function properties
• logb(bx) = x
Proof. Let y = logb(bx). Then,
by = bx (by definition of log)
y = x (by properties of exponential function)
logb(bx) = x
• logb(xy) = y logb x
Proof. Let p = logb x. Then,
x = bp (by definition of log)
xy = (bp)y = bpy
logb(xy) = py (by definition of log)
logb(xy) = y logb x
18
Change of base in log function
•
Proof. Let
By definition of log,
19
Let a, b ℝ+ s.t. a 1, b 1, and let x, y, p, q ℝ.
• •
• •
•
•
•
•
• •
•
•
•
•
20
Modulo functions (mod functions)
• f(x) = x mod m, where m > 0, is the modulo function
which is the remainder of the division of x by m.
• Note that
f(x) = x - m x/m
• The graph of y = x mod 3 is shown below:
21
Mod function properties
•
• Let a ℝ such that a and m are relatively prime. Then,
22
Cardinality of infinite sets
• The cardinality of a finite set is the number of elements in
the set.
• What about infinite sets? No exact number.
• Two sets A and B are said to have the same cardinality if
and only if there is a bijection from A to B.
• Infinite sets are classified as countable or uncountable.
• Definition. A set is said to be countable if it
➢is finite; or
➢has the same cardinality as the set of natural numbers
(i.e., ℕ = {0, 1, 2, 3, …}).
• A set that is not countable is called uncountable.
23
Countable or not?
• The set of all (HKMU) Computing students who were
admitted in the year 2020.
• ℕ = {0, 1, 2, …}
• {1, 3, 5, …} (I.e., the set of all odd positive integers)
Consider the following bijection: f(0) = 1, f(1) = 3, …
In general, f(𝒾) = 2𝒾 + 1
• ℤ = the set of all integers (including –ve integers)
24
Countable or not?
ℤ = the set of all integers (including –ve integers)
• Consider the following bijection:
f(0) = 0, f(1) = 1, f(2) = -1, f(3) = 2, f(4) = -2, …
• In general, (𝒾 +1)/2 if 𝒾 is odd
f(𝒾) =
- 𝒾 /2 if 𝒾 is even
• Therefore, ℤ is countable.
25
Countable or not: the set of all prime integers
• In general, let A be a countable set and let B be a subset
of A. Is B countable? Yes.
• Assume B is infinite.
• Since A is countable, there exists a bijection f from ℕ to A.
• The elements of A can be enumerated (written down) in
the order of
f(0), f(1), f(2), f(3), f(4), f(5), f(6), f(7), f(8), …
26
• Assume B is infinite.
• Since A is countable, there exists a bijection f from ℕ to A.
• The elements of A can be enumerated (written down) in the
order of
f(0), f(1), f(2), f(3), f(4), f(5), f(6), f(7), f(8), …
• Define a function g from ℕ to B as follows:
f(0), f(1), f(2), f(3), f(4), f(5), f(6), f(7), f(8), …
B B B B B B B B B 0
g(0), g(1), g(2), g(3), … 1
2
g B
…
• Precisely, let a-1 = -1. For any integer i 0,
• let ai be the smallest integer > ai-1 such that f(ai) B; and
• define g(i) = f(ai).
• E.g., when i = 2, ai = 6.
27
Claim: g is bijective.
Lemma 1. g is one-to-one.
Proof.
Consider any i, j ℕ.
g(i) = g(j)
f(ai) = f(aj) (as g(i) = f(ai) and g(j) = f(aj) )
ai = aj (as f is one-to-one)
i = j (as ai’s are all distinct)
Therefore, g is one-to-one.
28
Claim: g is bijective.
Lemma 2. g is onto.
Proof.
Consider any element x B.
As B A, x A.
Because f is onto, there exists i ℕ such that f(i) = x.
Let k be the number of elements in { f(0), f(1), …, f(i-1) } B.
f(0), f(1), f(2), f(3), … , f(i-1), f(i), f(i+1), …
B
g(0), g(1), …, g(k-1), g(k)
Note that i k 0, and k ℕ.
As x B, by definition of g, g(k) = f(i) = x.
29
Theorem 3. g is bijective.
Proof.
By Lemma 1, g is one-to-one.
By Lemma 2, g is onto.
Therefore, g is bijiective.
• Let A be a countable set and let B be a subset of A.
• Is B countable? Yes, we have formally proven it.
• Is the set of all prime integers countable?
30
Countable or not: the set of real numbers
Theorem 4. Let R be the set of all real numbers a such that
0 a < 1. Then R is uncountable.
Proof. Suppose R is countable.
Then, there is a bijective function 𝑓 from ℕ to R.
We construct a real number x < 1 as follows: …
We can show that
• x = 𝑓(i) for some integer i; and
• x 𝑓(i) for all integers i.
Then a contradiction occurs. (I.e., if R is countable, then “x
= 𝑓(i) for some integer i“ and “x 𝑓(i) for all integers i”.)
Therefore, R is uncountable.
31
What is x?
• Recall that 𝑓 is a bijective function from ℕ to R.
We can enumerate elements of R in order, e.g.,
• 𝑓(0) = 0.111
• 𝑓(1) = 0.33333…
• 𝑓(2) = 0.5
• …
𝑓(0) = 0. 1 1 1
𝑓(1) = 0. 3 3 3 …
𝑓(2) = 0. 5 0 0
…
x= 0. 2 4 1 …
• x = 0.241… Such x 𝑓(i) for all integers i.
32
What is x?
Notation: For any real number y R, for any integer i 0, let
yi be the (i+1)-th digit after the decimal point.
E.g., Suppose y = 0.101. Then y0 = 1; y1 = 0; y2 = 1; y3 = y4 = … = 0
Recall that 𝑓 is a bijective function from ℕ to R.
We can enumerate elements of R in the order of
𝑓(0), 𝑓(1), 𝑓(2), 𝑓(3), …
Define a real number x in R such that for all i 0, xi 𝑓(i)i .
• Obviously, x 𝑓(i) for all integers i.
• On the other hand, x is in R and 𝑓 is bijective; thus, there
exists an integer i such that x = 𝑓(i).
33
Countable or not: the set of real numbers
Corollary 5. The set of real numbers is uncountable.
Proof.
By Theorem 3, if the set of real numbers is countable, then
R (which is a subset of real numbers) is also countable.
As Theorem 4 shows that R is uncountable, the set of real
numbers is also uncountable. (Modus tollens)
34
Functions with more than 1 argument
• If f(x) = y, then x is called an argument of f,
and y is called a value of f.
• If the domain of f is the Cartesian product A1 A2 … An,
then f has n arguments.
• f(x1, x2, …, xn) denotes the value at (x1, x2, …, xn), where
x1 A1, x2 A2, …, xn An.
• Example: Let f: ℝ ℝ → ℝ such that f(x, y) = x+y.