You are on page 1of 31

MTH1114 Computer Mathematics

UNIT 5
FUNCTIONS
Zaharin Yusoff (Prof Dr)

SCHOOL
 UNIT 4 – Properties of the Integers
 The Well-Ordering Principle:
Mathematical Induction Chapter 4:
 Recursive Definitions
4.1  4.5
 The Division Algorithm: Prime Numbers
pg 193  241
 The Greatest Common Divisor: The
Euclidean Algorithm
 The Fundamental Theorem of
Arithmetic (product of primes)
 UNIT 5 – Relations and Functions
Chapter 5:
 Cartesian Products and Relations
5.1  5.3 & 5.6
 Functions: Plain and One-to-One
pg 247  267,
 Onto Functions: Stirling Numbers of
pg 278  289
the Second Kind
 Function Composition and Inverse
Functions
 UNIT 6 – Relations: The Second Time Around Chapter 7:
 Relations Revisited: Properties of Relations 7.1  7.2
― Binary, Reflexive, Symmetric, Transitive Pg 337  356
 Computer Recognition: Zero-One Matrices and
Directed Graphs
UNIT 5 – Relations and Functions
UNIT 5 – Relations and Functions

 Cartesian Products and Relations

 Functions: Plain and One-to-One

 Onto Functions: Stirling Numbers of the Second Kind


ATA
 Function Composition and Inverse Functions D

(1) Cartesian Products and Relations


Functions (Counting)

Let ⎮A⎮ = m, ⎮B⎮ = n


Relations A x B 2 mn
Thus ⎮A x B⎮ = mn

Functions nm
[mapping from all elements of A,
not 1–many, i.e. unique element on RHS)

1–1 functions n!
[mapping from all elements of A, (n – m) !
not 1-many, i.e. unique element on RHS]
⎮A⎮ ≤⎮B⎮

onto functions n
Σk=0 (−1)k nCn−k (n−k)m
[mapping from all elements of A,
not 1-many, i.e. unique element on RHS]
⎮A⎮ ≥⎮B⎮

bijective functions
n!
[1–1 and onto]
⎮A⎮ =⎮B⎮
n!
others n –[(
m
+ n
Σk=0 (−1)k nCn−k (n−k)m ) – n ! ]
[not 1–1 nor onto] (n – m) !
Computer Representation

We shall see later in Unit 6 that any relation, hence functions


R: A  B with  A  = m and  B  = n,
can be represented by a m x n matrix.

a11 a12 ……………………. a1n


a21 a22 ….…………………. a2n
a31 .… a33 …….………..…. a3n

…...….

…...….
…...….

a(m-1)1 ……….……………... a(m-1)n


am1 ……….…………......…. amn

The computer representation for this is a 2-dimensional array, namely:

A[1….m, 1…n] where A[i,j] = aij


5.2 Functions: Plain and One-to-One
(pg. 252  260)
Functions
A function is a relation
without pairs represented
For nonempty sets A, B, a function, or mapping,
by the grey arrows below
f from A to B, denoted f: A  B, is a relation from
A to B in which every element of A appears B
exactly once as the first component of an ordered A
pair in the relation.

Usually written f(a) = b for (a, b) ∈ f


b is called the image of a
a is a preimage of b. A×B
f associates with each a ∈ A the unique element b
Thus (a, b), (a, c) ∈ f ⇒ b = c. . A
w
1 w B 1 B
A x
2 x 2 y
For A = {1, 2, 3} and B = {w, x, y, z}, 3 y 3 R1 z
f
f = {(1, w), (2, x), (3, x)} is a function z
A
1 w B
R1 = {(1, w), (2, x)} and R 2 = {(1, w), (2, w), (2, x), (3, z)} 2 x
are relations, but not functions, from A to B 3 y
R2 z
For the function f: A × B,
A is called the domain of f
B the codomain of f.
Range
The subset of B containing all images f is called
the range of f and is also denoted by f (A)

For A = {1, 2, 3} and B = {w, x, y, z},


f = {(1, w), (2, x), (3, x)} w B
A 1 Domain Codomain
Domain f = {1, 2, 3}, 2 x
Codomain f = {w, x, y, z}, 3 y
f
Range f = f (A) = {w, x} z
Examples

a) A common function encountered is the greatest integer function, or floor


function. This function f: R ® Z, is given by
f (x) = ëxû = the greatest integer less than or equal to x.
ë3.8û = 3, ë3û = 3, ë–3.8û = –4, ë–3û = –3;

b) A second function related to the floor function in part (a) is the ceiling function.
The function g: R ® Z is defined by
g(x) = éxù = the least integer greater than or equal to x.
é3ù = 3, é3.01ù = é3.7ù = 4 = é4ù , é–3ù = –3, é–3.01ù = é–3.7ù = –3
Recall: B
For finite sets A, B with ⎮A⎮ = m and ⎮B⎮= n, A
there are 2mn possible relations from A to B,
including the empty relation as well as the
relation A × B itself.

Of these, there are nm functions (or ⎮B⎮⎮A⎮).

Possible images for


each element of A A×B

n. n. … n = nm

m places

• If A = {x, y, z} and B = {1, 2},


then there are altogether 23 = 8 functions f: A ® B
• Similarly there are 32 = 9 functions g: B ® A
in this case, codomain(g) = 3 ≠ range(g) ≤ 2
[hence never onto – see later]
One-to-One Functions

A 1-1 function is a relation


A function f: A ® B is called one-to-one, or injective, without pairs represented
if each element of B appears at most once as the by the grey arrows below
image of an element of A
B
A

If f: A ® B is one-to-one, with A, B finite,


then½A½ £ ½B½.
A×B
For arbitrary sets A, B,
f: A ® B is one-to-one if and only if
for all, a1, a2 Î A, f (a1) = f (a2) Þ a1 = a2. .

If f: A ® B and A1 Í A, then A B
f (A1) = {b Î B ½b = f (a), for some a Î A1}, A1 Image = f(A1)

and f (A1) is called the image of A1 under f


Recall: B
For finite sets A, B with ⎮A⎮ = m and ⎮B⎮= n, If f: A A
® B is one-to-one, then½A½ £ ½B½.

This means there are n! / (n-m)!


one-one functions from A to B.

Possible images for


each element of A

n. n-1. … n-m

m places

• If A = {1, 2} and B = {x, y, z},


then there are altogether 3.2 = 6 one-one functions f: A ® B
and there are no one-one functions from B to A
• If A = {1, 2, 3} and B = {a, b, c, d, x, y, z},
then there are altogether 6.5..4 = 120 one-one functions f: A ® B
and there are no one-one functions from B to A
Examples: A B
Let g: R ® R be given by g(x) = x2. A1 Image = f(A1)

Then g(R) = the range of g = [0, + ¥).


The image of Z under g is g(Z) = {0, 1, 4, 9, 16, …},
and for A1 = [–2, 1] we get g (A1) = [0, 4].

Let h: Z x Z ® Z where h(x, y) = 2x + 3y.


The domain of h is Z x Z, not Z, and the codomain is Z.
We find, for example, that
h(0, 0) = 2(0) + 3(0) = 0
h(–3, 7) = 2(–3) + 3(7) = 15.
h(2, –1) = 2(2) + 3(–1) = 1,
and for each n Î Z,
h(2n, –n) = 2(2n) + 3(–n) = 4n – 3n = n.
Consequently, h(Z x Z) = the range of h = Z.

For A1 = {(0, n)½n Î Z+} = {0} x Z+ Í Z x Z,


the image of A1 under h is
h (A1) = {3, 6, 9, …} = {3n½n Î Z+}.
Let f: A ® B, with A1, A2 Í A. Then
a) f (A1 È A2) = f (A1) È f (A2) ;
b) f (A1 Ç A2) Í f (A1) Ç f (A2);
c) f (A1 Ç A2) = f (A1) Ç f (A2) when f is one-to-one. These have to be visualised
B
A
f(A1)
A1

Proof (for part (b)) f(A1)∩f(A2)


A1∩A2
For each b Î B,
b Î f (A1  A2) f(A2)
A2
Þ b = f (a), for some a Î A1 Ç A2 A×B
Þ [b = f (a) for some a Î A1] and
[b = f(a) for some a Î A2]
Þ b Î f (A1) and b Î f (A2)
Þ b Î f (A1) Ç f (A2) ,
so f (A1 Ç A2) Í f (A1) Ç f (A2).
5.3 Onto Functions: Stirling
Numbers of the Second Kind
(pg. 260  267)
Onto Functions: Stirling Numbers of the Second Kind

A function f: A® B is called onto, or surjective, if f (A) = B


– that is, if for all b Î B there is at least one a Î A with f (a) = b.

Examples:
• The function f: R ® R defined by f(x) = x3 is an onto function. Range
If r is any real number in the codomain of f, then the real
number 3Ör is in the domain of f and f (3Ör) = (3Ör)3 = r.
Hence codomain of f = R = range of f, thus f is onto. Domain Image =
Codomain =
Range

• The function g: R ® R, where g (x) = x2 for each real number x, is not an onto function.
No negative real number appears in the range of g.
e.g. For –9 to be in the range of g,
we would have to be able to find a real number r with g(r) = r2 = –9.
However, r2 = –9 ⇒ r = 3i or r = –3i, where 3i, –3i Î C, but 3i, –3i Ï R.
So here the range of g = g (R) = [0, +¥) Ì R, and the function g is not onto.
• But the function h: R ® [ 0, +¥ ) defined by h(x) = x2 is an onto function.
• The function f: Z ® Z, where f (x) = 3x + 1 for x Î Z is not onto.
The range f = {…, –8, –5, –2, 1, 4, 7, …} Ì Z,
for example, does not include 8.
The equation 3x + 1 = 8 gives x = 7/3, A
which is a rational number 7/3, and is not an integer. w B
1
2 x
• However, the following are onto functions:
 g: Q ® Q, where g(x) = 3x + 1 for x Î Q 3 y
 h: R ® R, where h(x) = 3x + 1 for x Î R f z

• If A, B are finite sets, then for an onto function f: A ® B to possibly exist we must
have ½A½ ³ ½B½where ½A½ = m ³ n = ½B½ [if less, there will be ‘spare’ elements in B]

More Examples: x B
A 1
• If A = {1, 2, 3, 4} and B = {x, y, z}, then 2 y
f1 = {(1, z), (2, y), (3, x), (4, y)} and 3
f2 = {(1, x), (2, x), (3, y), (4, z)} g z
4
are both functions from A onto B.
However, the function g = {(1, x), (2, x), (3, y), (4, y)} is not onto,
because g (A) = {x, y} Ì B [z has no preimage in A]
Possible images for
• If A = {x, y, z} and B = {1, 2}, each element of A
then all functions f: A ® B are onto
except the constant functions
f1 = {(x, 1), (y, 1), (z, 1)}
2. 2. 2 = 23
f2 = {(x, 2), (y, 2), (z, 2)}
So there are ½B½½A½ – 2 = 23 – 2 = 6 onto functions from A to B. Possible images for
each element of A
• In general, if ½A½ = m ≥ 2 and ½B½=2,
then there are 2m – 2 onto functions from A to B.
3. 3. 3. 3 = 34

• For A = {w, x, y, z} and B = {1, 2, 3}, there are 34 functions from A to B.


• Considering subsets of B of size 2 <⎮B⎮ [functions to these subsets will not be onto]
there are 24 functions from A to {1, 2}, 24 functions from A to {2, 3}, and 24 functions
from A to {1, 3). So the number of functions from A to B that are definitely not onto is:

• But is not the final answer, as not all of these latter 3(24) functions
are distinct.
From A to {1, 2}, we removed the constant function {(w, 2), (x, 2), (y, 2), (z, 2)}, and
the same one from A to {2, 3}. Consequently, we have removed twice each of the
constant functions f: A ® B, where f (A) is one of the sets {1}, {2}, or {3}. As such, we
need to add 3 back, giving the total number of onto functions from A to B as:
• …. As such, we need to add 3 back, giving the total number of onto functions from
A to B as:

• General formula – For finite sets A, B with ½A½ = m and ½B½ = n,


the number of onto functions from A to B is:

The nth term is 0


Example [from (n − n)m ].
It is just to
Let A = {1, 2, 3, 4, 5, 6, 7} and B = {w, x, y, z}.
make it easier to
Applying the general formula with m = 7 and n = 4, remember
we find that there are 8400 functions from A onto B

= = = 8,400
Functions (Counting)

Let ⎮A⎮ = m, ⎮B⎮ = n


Relations A x B 2 mn
Thus ⎮A x B⎮ = mn

Functions nm
[mapping from all elements of A,
not 1–many, i.e. unique element on RHS)

1–1 functions n!
[mapping from all elements of A, (n – m) !
not 1-many, i.e. unique element on RHS]
⎮A⎮ ≤⎮B⎮

onto functions n
Σk=0 (−1)k nCn−k (n−k)m
[mapping from all elements of A,
not 1-many, i.e. unique element on RHS]
⎮A⎮ ≥⎮B⎮

bijective functions
n!
[1–1 and onto]
⎮A⎮ =⎮B⎮
n!
others n –[(
m
+ n
Σk=0 (−1)k nCn−k (n−k)m ) – n ! ]
[not 1–1 nor onto] (n – m) !
5.6 Function Composition and
Inverse Functions
(pg. 278  289)
Function Composition and Inverse Functions

• For c, d ∈ Z, if c + d = d + c = 0
then d is the additive inverse of c.
(c is also the additive inverse of d). We now want to look at
the inverse of functions
• For t, u ∈ R, and t ≠ 0, if ut = tu = 1
then u is called the multiplicative inverse of t
(t is also the multiplicative inverse of u)

If f: A ® B, then f is said to be bijective, or to be a one-to-one correspondence,


if f is both one-to-one and onto.

Example
If A = {1, 2, 3, 4} and B = {w, x, y, z}, then
f = {(1, w), (2, x), (3, y), (4, z)}
is a one-to-one correspondence from A (on)to B, and
g = {(w, 1), (x, 2), (y, 3), (z, 4)}
is a one-to-one correspondence from B (on)to A.

The function 1A: A ® A, defined by 1A (a) = a for all a Î A,


is called the identity function for A.
If f, g: A ® B, we say that f and g are equal and write f = g,
if f (a) = g (a) for all a Î A. .

But sometimes f ¹ g even though f (a) = g (a), "a Î A. This occurs when f, g are
functions with a common domain A – but the codomains are not the same.
Example:
Let f: Z ® Z, g: Z ® Q where f (x) = x = g (x), for all x Î Z.
Then f, g share the common domain Z, and have the same range Z,
and act the same on every element of Z. Yet f ¹ g !
Here f is a one-to-one and onto correspondence,
whereas g is one-to-one but not onto;
so the codomains do make a difference.

Consider the functions f, g: R ® Z defined as follows:


If x Î Z, then f (x) = x = éxù = g (x).
For x Î R – Z, write x = n + r where n Î Z and 0 < r <1.
(For example, if x = 2.3, we write 2.3 = 2 + 0.3, with n = 2 and r = 0.3;
for x = –7.3 we have –7.3 = –8 + 0.7, with n = –8 and r = 0.7). Then
f (x) = ëxû + 1 = n + 1 = éxù = g (x).
Notice the functions f, g are defined by different formulas, but they are the
same function – because they have the same domain and codomain and
f (x) = g (x) for all x in the domain R.
If f: A ® B and g: B ® C, we define the composite function, which is denoted
g o f: A ® C, by (g o f ) (a) = g (f (a)), for each a Î A.

Example:
Let A = {1, 2, 3, 4}, A B C
B = {a, b, c}, and
C = {w, x, y, z} 1 w
a
with f: A ® B and g: B ® C given by x
2
f = {(1, a), (2, a), (3, b), (4, c)} b
g = {(a, x), (b, y), (c, z)}. y
3
For each element of A we find: c
(g o f) (1) = g (f (1))= g (a) = x 4 z
f g
(g o f) (2) = g (f (2))= g (a) = x
(g o f) (3) = g (f (3))= g (b) = y
(g o f) (4) = g (f (4))= g (c) = z
So
g o f = {(1, x), (2, x), (3, y), (4, z)}.
Note: The composition f o g is not defined.
(because domain of f = A ≠ C = codomain of g)
Example:

Let f: R ® R, g: R ® R be defined by f (x) = x2, g(x) = x + 5. Then


(g o f) (x) = g (f (x)) = g (x2) = x2 + 5,
while
(f o g) (x) = f (g (x)) = f (x+ 5) = (x+ 5)2 = x2 + 10x +
25.
Here g o f: R ® R and f o g: R ® R,
but (g o f) (1) = 6 ≠ 36 = (f o g) (1),
so even though both composites f o g and g o f can be formed,
we do not have f o g = g o f.
Consequently, the composition of functions is not, in general,
a commutative operation.

The definition and examples for composite functions require that


the codomain of f = domain of g.
If the range of f ⊆ domain of g,
this will actually be enough to yield the composite function g o f: A ® C.
Also, for any f: A ® B, we observe that f o 1A = f = 1B o f.
Let f: A ® B and g: B ® C.
a) If f, g are one-to-one, then g o f is one-to-one.
b) If f, g are onto, then g o f is onto.

Example:
Let f, g, h: R ® R, where f (x) = x2, g(x) = x + 5, and h(x) = Öx2 +2.
Then ((h o g) o f )(x) = (h o g) (f (x))
= (h o g) (x2) = h (g (x2))
= h (x2+ 5) = Ö (x2 + 5)2 + 2
= Ö(x4 + 10x2 + 27).

On the other hand, we see that (h o (g o f)) (x)


= h ((g o f ) (x)) = h (g ( f (x)))
= h (g (x2)) = h (x2 + 5)
= Ö(x2 + 5)2 + 2 = Öx4 + 10x2 + 27, as above
So in this particular example, (h o g) o f and h o (g o f ) are two functions with the
same domain and codomain, and for all x Î R,
((h o g) o f ) (x) = Öx4 + 10x2 + 27 = (h o (g o f )) (x).
Consequently, (h o g) o f = h o (g o f ). .
If f: A ® B, g: B ® C, and h: C ® D,
then (h o g) o f = h o (g o f )

The composition of functions is thus an associative operation

If f: A ® A we define f 1 = f, and for n Î Z+, f n+1 = f o (f n).

Example
With A = {1, 2, 3, 4} and f: A ® A defined by
f = {(1, 2), (2, 2), (3, 1), (4, 3)},
we have f 2 = f o f = {(1, 2), (2, 2), (3, 2), (4, 1)}
and f 3 = f o f 2 = f o f o f = {(1, 2), (2, 2), (3, 2), (4, 2)}
…..
For sets A, B, if R is a relation from A to B, then the converse of R, denoted Rc ,
is the relation from B to A defined by Rc = {(b, a)½(a, b) Î R}.

To get Rc from R, we simply interchange the components of each ordered pair


in R. So if A = {1, 2, 3, 4}, B = {w, x, y}, and
R = {(1, w), (2, w), (3, x)},
then Rc = {(w, 1), (w, 2), (x, 3)}, a relation from B to A.

Since a function is a relation we can also form the converse of a function.


For the same preceding sets A, B, let f: A ® B where
f = {(1, w), (2, x), (3, y), (4, x)}.
Then f c = {(w, 1), (x, 2), (y, 3), (x, 4)},
a relation, but not a function, from B to A.
We wish to investigate when the converse of a function yields a function.

Example
For A = {1, 2, 3} and B = {w, x, y}, let f: A ® B be given by
f = {(1, w), (2, x), (3, y)}.
Then f c = {(w, 1), (x, 2), (y, 3)}
is a function from B to A, and we observe that
f c o f = 1A and f o f c = 1B.
If f: A ® B, then f is said to be invertible if there is a function g: B ® A such that
g o f = 1A and f o g = 1B. (here g is also invertible)
Example
Let f, g: R ® R be defined by f (x) = 2x + 5, g (x) = (1/2)(x – 5).
Then (g o f) (x) = g (f (x)) = g (2x + 5) = (1/2)[(2x + 5) – 5] = x,
and (f o g ) (x) = f (g (x)) = f ((1/2)(x – 5)) = 2[(1/2)(x – 5)] + 5 = x,
so f o g = 1R and g o f = 1R.
Consequently, f and g are both invertible functions.

If a function f: A ® B is invertible and a function g: B ® A satisfies


g o f = 1A and f o g = 1B,
then this function g is unique.

We shall call the function g the inverse of f and shall adopt the notation g = f –1.
The above also implies that f –1 = f c – the inverse is the same as the converse
Whenever f is an invertible function, so is the function f -1, and (f –1) –1 = f

A function f: A ® B is invertible if and only if it is one-to-one and onto.

Example
The function f1: R ® R defined by f1 (x) = x2 is not invertible (it is neither one-to-
one nor onto), but f2: [0, +¥) ® [0, +¥) defined by f2(x) = x2 is invertible with f2–
1
(x) = Öx
THANK YOU TERIMA KASIH
MERCI ARIGATO/ OKINI
GRAZZIE GO MA SSEUM NI DA
GRACIAS SHUKRIYA
SPASIBA XIE-XIE NI
DANKE KAMSIAH / MMKOI
MANGE TAK JABAI INAU
NAN DHRI NGGO BUTE KABU
CAM ON KOP KUN KAH

You might also like