Вы находитесь на странице: 1из 31

Relations and Functions (Books Ch 5)

CSE 173 - AdF

5.1. Cartesian products and
Definition 5.1. The Cartesian product of A
and B is denoted by AB and equals {(a,
b)aA and bB}. The elements of AB are
ordered pairs. The elements of A1A2An
are ordered n-tuples.
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
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.
Ex 5.7. We may define R on set A as
{(x, y)xy}.
Ex 5.8. Let R be the subset of NN
where R={(m, n)n=7m}
For any set A, A=. Likewise, A
Theorem 5.1.
5.2. Functions: Plain and one-to-
Definition 5.3. f: AB, A is called domain and B is
codomain. f(A) is called the range of f.
For (a, b)f, b is called image of a under f whereas a
is 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
thought of as a function f: Z+R and a sequence of
integers can be thought of as f: Z+Z
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
injective, 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
and B=n, there are P(n, m) one-to-
one 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-
A1={2,3,4}, A2={3,4,5}
f(2)=b, f(3)=a, f(4)=a, f(5)=b
5.3. Onto Functions
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:
RR defined by h(x)=3x+1 is an onto function.
5.4. Special functions
Definition 5.10. f: AAB is called a binary
operation. If BA, then it is closed on A.
Definition 5.11. A function g:AA is called
unary, or monary, operation on A.
the function f: ZZZ, defined by f(a, b)=a-b, is
a closed binary operation.
The function g: Z+Z+Z, defined by g(a, b)=a-
b, is a binary operation on Z+, but it is not
The function h: R+R+, defined by h(a)=1/a, is
a unary operation.
Definition 5.13. Let f: AAB be a
binary operation on A. An element x
in A is called an identity for f if f(a,
x)= f(x, a)=a for all a in A.
Ex 5.34.
If f(a, b)=a+b, then 0 is the identity.
If f(a, b)=ab, then 1 is the identity.
If f(a, b)=a-b, then there is no identity.
Definition 5.14. if DAB, then A: DA,
defined by A(a, b)=a is called the
projection on the first coordinate. The
function B: DB, defined by B(a, b)=b is
called the projection on the second
if DA1 A2An, then A: DAi Ai 1 2

Ai ,,,, Ai , defined by (a1, a2, , an)= ai ,

3 m 1

ai , ai , , ai is called the projection on the

2 3 m

i1, i2, , 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.
Homeworks for Saturday:
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.
Ex 5.43. If 101 integers are selected from
the set S={1, 2, , 200}, then there are
two 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
distinct 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. [May show up in Final]
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.52. f and g look different but they are
indeed equal. [NEXT SLIDE]
Composite function
Definition 5.18. If f : AB and g : BC, we
define the composition function, which is
denoted by gf: AC, (gf) (a)=g(f(a)) for
each aA.
Ex 5.53, Ex 5.54. [NEXT SLIDE]
The codomain of f = domain of g
What about f o g? [Classwork]
Definition 5.20. For sets A and B, if
is a relation from A to B, then the
converse of , denoted by c, is the
relation from B to A defined by
c={(b, a) (a, b)}.
Simply turn it upside down and make
sure that it is a function afterall.
Invertible function
Definition 5.21. If f : AB, then f is
said to be invertible if there is a
function g: BA such that gf=1A and
fg=1B. (Ex 5.58 ) [Next Slide]
Theorem 5.7. If a function f : AB is
invertible and a function g : BA
satisfies gf=1A and fg=1B, then this
function g is unique.
Invertible function
Theorem 5.8. A function f : AB is
invertible if and only if it is one-to-one and
Theorem 5.9. If f : AB and g : BC are
invertible functions, then gf: AC is
invertible and (gf)-1=f-1g-1.
Ex 5.60. f:RR is defined by f(x)=mx+b,
and 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.
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
Theorem 5.11.
If f : AB and A=B. Then the
following statements are equivalent:
(a) f is one-to-one; (b) f is onto, (c) f
is invertible.
Ex. 5.62