Chapter 5 Relations and Functions: Yen-Liang Chen Dept of Information Management National Central University
Chapter 5 Relations and Functions: Yen-Liang Chen Dept of Information Management National Central University
Yen-Liang Chen
Dept of Information Management
National Central University
5.1. Cartesian products and
relations
Definition 5.1. The Cartesian product of A a
nd B is denoted by AB and equals {(a, b)
aA and bB}. The elements of AB are or
dered pairs. The elements of A1A2…An ar
e ordered n-tuples.
AB=AB
Ex 5.1. A={2, 3, 4}, B={4, 5}.
What are AB, BA, B2 and B3?
Ex 5.2, What are RR, R+R+ and R3?
Tree diagrams for the Cartesian product
Relations
Definition 5.2. Any subsets of AB is called
a relation from A to B. Any subset of AA is
called a binary relation on A.
Ex 5.5. The following are some of relations
from A={2,3,4} to B={4,5}: (a) , (b) {(2,
4)}, (c) {(2, 4), (2, 5)}, (d) {(2, 4), (3, 4),
(4, 4)}, (e) {(2, 4), (3, 4), (4, 5)}, (f) AB.
For finite sets A and B with A=m and
B=n, there are 2mn relations from A to B.
There are also 2mn relations from B to A.
Examples
Ex 5.6. R is the subset relation where
(C, D)R if and only if C, DB and C
D.
Ex 5.7. We may define R on set A as
{(x, y)xy}.
Ex 5.8. Let R be the subset of NN wh
ere R={(m, n)n=7m}
For any set A, A=. Likewise, A
=.
Theorem 5.1.
A(BC)=(AB)(AC)
A(BC)=(AB)(AC)
(AB)C=(AC)(BC)
(AB)C=(AC)(BC)
Why?
5.2. Functions: Plain and one-to-
one
Definition 5.3. f: AB, A is called domain and B is cod
omain. f(A) is called the range of f.
For (a, b)f, b is called image of a under f whereas a i
s a pre-image of b.
Ex 5.10.
Greatest integer function, floor function
Ceiling function
Truncate function
Row-major order mapping function
Ex 5.12. a sequence of real numbers r1, r2,… can be th
ought of as a function f: Z+R and a sequence of inte
gers can be thought of as f: Z+Z
properties
For finite sets A and B with A=m and B=n
, there are nm functions from A to B.
Definition 5.5. f: AB, is one-to-one or inje
ctive, if each element of B appears at most
once as the image of an element of A. If so,
we must have AB. Stated in another
way, f: AB, is one-to-one if and only if for
all a1, a2A, f(a1)=f(a2) a1=a2.
Ex 5.13. f(x)=3x+7 for xR is one-to-one.
But g(x)=x4-x is not. (Why?)
Number of one-to-one functions
Ex 5.14. A={1, 2, 3}, B={1, 2, 3, 4,
5}, there are 215 relations from A to B
and 53 functions from A to B.
In the above example, we have P(5,
3) one-to-one functions.
Given finite sets A and B with A=m a
nd B=n, there are P(n, m) one-to-on
e functions from A to B.
Theorem 5.2.
Let f: AB with A1, A2A. Then
(a) f(A1A2)=f(A1)f(A2),
(b) f(A1A2)f(A1)f(A2),
(c) f(A1A2)=f(A1)f(A2) when f is one-to-
one.
A1={2,3,4}, A2={3,4,5}
f(2)=b, f(3)=a, f(4)=a, f(5)=b
Restriction and Extension
Definition 5.7. If f: AB and A1A, then fA1: AB is cal
led the restriction of f to A1 if fA1(a)=f(a) for all aA1.
Definition 5.8. Let A1A and f: A1B. If g: AB and g
(a)=f(a) for all aA1, then we call g an extension of f t
o A.
Ex 5.17.Let f: AR be defined by {(1, 10), (2, 13), (3,
16), (4, 19), (5, 22)}. Let g: QR where g(q)= 3q+7
for all qQ. Let h: RR where h(r)= 3r+7 for all rR.
g is an extension of f, f is the restriction of g
h is an extension of f, f is the restriction of h
h is an extension of g, g is the restriction of h
Ex 5.18. g and f are shown in Fig 5.5. f is an extension
of g.
5.3. Onto Functions: Stirling numb
ers of the second kind
Definition 5.9. f: AB, is onto, or surjective, if f(A)=
B-that is, for all bB there is at least one aA with f
(a)=B. If so, we must have AB.
Ex 5.19. The function f: RR defined by f(x)=x3 is an
onto function. But the function g: RR defined by f
(x)=x2 is not an onto function.
Ex 5.20. The function f: ZZ defined by f(x)=3x+1 is
not an onto function. But the function g: QQ defined
by g(x)=3x+1 is an onto function. The function h: R
R defined by h(x)=3x+1 is an onto function.
The number of onto functions
Ex 5.22. If A={x, y, z} and B={1,2}, there
are 23-2=6 onto functions. In general, if
A=m and B=2, then there are 2m-2
onto functions.
Ex 5.23. If A={w, x, y, x} and B={1,2, 3}.
There are C(3, 3)34 functions from A to B.
Consider subset B of size 2, such as {1, 2}, {1,
3}, {2, 3}, there are C(3, 2)24 functions from A
to B.
Consider subset B of size 1, such as {1}, {3},
{2}, there are C(3, 1)14 functions from A to B.
Totally, there are C(3, 3)34- C(3, 2)24+ C(3, 1)14
onto functions from A to B.
The number of onto functions
For finite sets A and B with A=m and
B=n, the number of onto functions is:
n m n n n 1 n m
n (n 1)
m
(n 2) ... (1) 1
m
n n 1 n 2 1
n
n
(1) k
(n k ) m
k 0 n k
Examples
Ex 5.24. Let A={1, 2, 3, 4, 5, 6, 7} and B={w, x, y,
z}. So, m=7 and n=4. There are 8400 onto functions.
C(4, 4)47-C(4, 3)37+C(4, 2)27-C(4, 1)17=8400
Ex 5.26. Let A={a, b, c, d} and B={1, 2, 3}. So, m=
4 and n=3. There are 36 onto functions, or equivalent
ly, 36 ways to distribute four distinct objects into thre
e distinguishable containers, with no container empty.
For mn, the number of ways to distribute m distinct
objects into n numbered containers with no container
left empty is :
n
n
( 1k
)
n k ( n k ) m
k 0
Distinguishable and identical
distribute m distinct (identical) objects into
n numbered (identical) containers
{a, b} in container 1, {c} in container 2, {d} in
container 3
{a, b} in one container, {c} in the other
container, {d} in another container
2 objects in container 1, 1 object in container 2,
1 object in container 3
2 objects in one container, 1 object in the other
container, 1 object in another container
Stirling number of the second kind
The stirling number of the second kin
d is the number of ways to distribute
m distinct objects into n identical cont
ainers, with no container left empty,
denoted S(m,n), which is
1 n k n
n! k 0
( 1)
n k ( n k ) m
n
S (m, i)
i 1
im coordinates.
The projection of a database
5.5. Pigeonhole principle
The pigeonhole principle: If m pigeons occupy n
pigeonholes and m>n, then at least one pigeonhole
has two or pigeons roosting in it.
Ex 5.39: among 13 people, at least two of them have
birthdays during the same month.
Ex 5.40. In a laundry bag, there are 12 pairs of socks.
Drawing the socks from the bag randomly, we will
draw at most 13 of them to get a matched pair.
Ex 5.42. Let SZ+ and S=37. Then S contains two
elements that have the same remainder upon division
by 36.
Examples
Ex 5.43. If 101 integers are selected from t
he set S={1, 2, …, 200}, then there are tw
o integers such that one divide the other.
For each xS, we may write x=2ky, with k0 and
gcd(2,y)=1. Then yT={1, 3, 5, …, 199}, where
T =100. By the principle, there are two distinc
t integers of the form a=2my and b=2ny for some
y in T.
Ex 5.44. Any subset of size 6 from the set
S={1, 2, …, 9} must contain two elements
whose sum is 10.
Examples
Ex 5.45. Triangle ACE is equilateral with AC=1. If five
points are selected from the interior of the triangle,
there are at least two whose distance apart is less
than 1/2.
Ex 5.46. Let S be a set of six positive integers whose
maximum is at most 14. The sums of the elements in
all the nonempty subsets of S cannot be all distinct.
There are 26-1=63 subsets of S.
1SA 9+10+…+14=69
If A=5, then 1SA 10+…+14=60
There are 62 nonempty subsets A of A with 5A.
Ex 5.47
Let m in Z+ and m is odd. There exists a positive integ
er n such that m divides 2n-1.
Consider the m+1 positive integers 21-1, 22-1,…, 2m-1
, 2m+1-1. By the principle, we have 1s<tm+1, where
2s-1 and 2t-1 have the same remainder upon division
by m.
Hence 2s-1=q1m+r and 2t-1=q2m+r.
(2t-1)-(2s-1)= 2t-2s=2s(2t-s-1)=(q2-q1)m.
Since m is odd, gcd(m, 2s)=1.
Hence, m2t-s-1, and the result follows with n=t-s.
Ex 5.49
For each nZ+, a sequence of n2+1 distinct real numbers cont
ains a decreasing or increasing subsequence of length n+1.
Let the sequence be a1, a2,…,an2+1. For 1k n2+1
xk= the maximum length of a decreasing subsequence that e
nds with ak.
yk= the maximum length of an increasing subsequence that e
nds with ak.
If there is no such sequence, then 1xkn and 1ykn for 1k
n2+1.
Consequently, there are at most n2 distinct ordered pairs of x
k and yk.
But we have n2+1 ordered pairs of xk and yk.
Thus, there are two identical (xi, yi) and (xj, yj).
But since every real number is distinct from one another, this
is a contradiction.
5.6. Function composition and
inverse function
For each integer c there is a second integer d where c
+d = d+c=0, and we call d the additive inverse of c.
Similarly, for each real number c there is a second rea
l number d where cd = dc=1, and we call d the multip
licative inverse of c.
Definition 5.15. If f: AB, then f is said to be bijective
, or to be one-to-one correspondence, if f is both onto
and one-to-one.
Definition 5.16. The function 1A: AA, defined by 1A
(a)=a for all aA, is called the identity function for A.
Equal function
Definition 5.17. If f, g : AB, we say that f
and g are equal and write f = g, if f(a)=g
(a) for all aA.
A common pitfall may happen when f and g
have a common domain A and f(a)=g(a) for
all aA, but they are not equal.
Ex 5.51. f and g look similar but they are n
ot equal.
Ex 5.52. f and g look different but they are
indeed equal.
Composite function
Definition 5.18. If f : AB and g : BC, we
define the composition function, which is de
noted by gf: AC, (gf) (a)=g(f(a)) for ea
ch aA.
Ex 5.53, Ex 5.54.
Properties
The codomain of f = domain of g
If range of f domain of g, this will be enough t
o yield gf: AC.
For any f : AB, f1A = f = 1Bf.
Is function composition associative?
Theorem 5.6. If f : AB and g : BC and h
: CD, then (hg)f=h(gf).
Ex 5.55.
Definitions
Definition 5.19. If f : AA, we define
f1=f and fn+1=ffn.
Ex 5.56
Definition 5.20. For sets A and B, if
is a relation from A to B, then the con
verse of , denoted by c, is the relat
ion from B to A defined by c={(b, a)
(a, b)}.
Ex 5.57
Invertible function
Definition 5.21. If f : AB, then f is s
aid to be invertible if there is a functi
on g: BA such that gf=1A and fg=
1B. (Ex 5.58 )
Theorem 5.7. If a function f : AB is i
nvertible and a function g : BA satis
fies gf=1A and fg=1B, then this func
tion g is unique.
Invertible function
Theorem 5.8. A function f : AB is invertibl
e if and only if it is one-to-one and onto.
Theorem 5.9. If f : AB and g : BC are in
vertible functions, then gf: AC is invertib
le and (gf)-1=f-1g-1.
Ex 5.60. f:RR is defined by f(x)=mx+b, a
nd f-1:RR is defined by f-1(x)=(1/m)(x-b).
Ex 5.61. f:RR+ is defined by f(x)=ex, and
f-1:R+R is defined by f-1(x)=ln x.
Preimage
Definition 5.22. If f: AB and B1B, t
hen f-1(B1)={xAf(x)B1}. The set f-1
(B1) is called the pre-image of B1 und
er f.
Ex 5.62. If f={(1, 7), (2, 7), (3, 8),
(4, 6), (5, 9), (6, 9)}, what are the pr
eimage of B1={6, 8}, B2={7, 8}, B3=
{8, 9}, B4={8, 9, 10}, B5={8, 10}.
Ex 5.64
Table 5.9 for f:ZR with f(x)=x2+5
Table 5.10 for g:RR with g(x)= x2+5
Theorems