0% found this document useful (0 votes)
13 views9 pages

1 Lesson 05 Notes

Uploaded by

xdong2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

1 Lesson 05 Notes

Uploaded by

xdong2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Discrete Mathematics for Computer Science

Nirdosh Bhatnagar

Lesson 05 Relations and Functions

1. Introduction

Relations and functions are studied in this lesson. These are:

1. The Cartesian products and relations


2. Functions: plain and one-to-one
3. Onto functions: Stirling numbers of the second kind
4. Special functions
5. The pigeonhole principle
6. Function composition and inverse functions.

1
Discrete Mathematics for Computer Science 2

2. Cartesian Products and Relations

Cartesian Products

De…nition Cartesian product. Let A and B be any two sets. The Cartesian product
or cross product of sets A and B; denoted by A B is the set of all ordered pairs (a; b)
where a 2 A and b 2 B:
A B = f(a; b) j a 2 A, b 2 Bg
The Cartesian product of a set with itself, A A is denoted by A(2) or simply A2 : In a
similar manner
A(n) , An = A A A
| {z }
n tim es

The Cartesian product of the sets A1 ; A2 ; : : : ; An is denoted by


n
i=1 Ai

Observation Let jAj denote the cardinality of the set A. Then jA Bj = jAj jBj.

Relations

De…nition Relation or binary relation. Let A and B be any two sets. A relation (or
binary relation or binary operation) R from A to B is a subset of A B: The set R is
a set of ordered pairs. That is: R = f(a; b) j a 2 A and b 2 Bg A B:
Let S be any set. A relation on a set S; is a binary relation from S to S; which is a
subset of S S:

Observations

1. Let jAj = m, and jBj = n, then there are 2mn relations from A to B.
2. For any set A, A ? = ?.

3. For any sets A; B; C U:

(a) A (B \ C) = (A B) \ (A C)
(b) A (B [ C) = (A B) [ (A C)
(c) (A \ B) C = (A C) \ (B C)
(d) (A [ B) C = (A C) [ (B C)
Discrete Mathematics for Computer Science 3

3. Functions: Plain and One-to-One

De…nitions. Function. Let A and B be any two nonempty sets. The function f is a
relation from A to B. Assign to each element a of the set A; a unique element b of the
set B: The set of such assignments is called a function or mapping from A into B: It is
indicated as f : A ! B: The function f is sometimes denoted by f ( ) :

The speci…c element b 2 B assigned to a 2 A is denoted by f (a). It is written as


f (a) = b:

Furthermore, f (a) is sometimes called the image of a or the value of f at a:


Also a is called the preimage of b:
The set A is called the domain of f and the set B is called the codomain of f:
The range of f is denoted by f (A). It is the set of images

f (A) = ff (a) j a 2 A and f (a) 2 Bg

Sometimes “codomain” and “range” are used synonymously.


Observe that f(a; b) j a 2 A and f (a) = bg A B:

De…nition One-to-one function. A function f : A ! B is said to be injective or


one-to-one if di¤ erent elements of the domain A are mapped to di¤ erent elements of the
codomain B: Therefore, if a1 ; a2 2 A; then f (a1 ) = f (a2 ) ) a1 = a2 :

Observation Let the cardinality of the sets A and B be …nite. That is, let jAj = m,
and jBj = n.

(a) The number of relations from A to B is equal to 2mn .


(b) The number of functions from A to B is equal to nm .
(c) The number of one-to-one functions from A to B is equal to

n!
n (n 1) : : : (n m + 1) =
(n m)!
Discrete Mathematics for Computer Science 4

4. Onto Functions: Stirling Numbers of the Second Kind

De…nition. Onto function. A function f : A ! B is surjective or onto if every ele-


ment b 2 B is the image of at least one element a 2 A:That is, f (A) = B:

The number of onto functions f : A ! B, when jAj = m 2 P and jBj = n 2 P is next


determined in several steps. Actually the correctness of the …nal result is demonstrated
via examples.

Case 1 : n = 1:
Let A = fx; y; zg, and B = f1g. That is, m = 3 and n = 1.
There is only one onto function f(x; 1) ; (y; 1) ; (z; 1)g.
Case 2 : n = 2.

Subcase 2.1 : m = 1 and n = 2.


Let A = fxg, and B = f1; 2g. There are no onto functions from A to B.
Subcase 2.2 : m = 2 and n = 2.
Let A = fx; yg, and B = f1; 2g. There are two onto functions from A to B.
These are: f(x; 1) ; (y; 2)g and f(x; 2) ; (y; 1)g.
Subcase 2.3: m = 3 and n = 2.
Let A = fx; y; zg, and B = f1; 2g. Then all functions f : A ! B are onto
except the constant functions. The constant functions are

f(x; 1) ; (y; 1) ; (z; 1)g , and f(x; 2) ; (y; 2) ; (z; 2)g

So there are 23 2 = 6 onto functions from A to B.


Subcase 2.4 : m 2 and n = 2.
There are (2m 2) onto functions from A to B.

Case 3 : n = 3.

Subcase 3.1 : m = 1 and n = 3.


Let A = fxg, and B = f1; 2; 3g. There are no onto functions from A to B.
Subcase 3.2 : m = 2 and n = 3.
Let A = fx; yg, and B = f1; 2; 3g. There are no onto functions from A to B.
Subcase 3.3 : m = 3 and n = 3.
Let A = fx; y; zg, and B = f1; 2; 3g. There are 33 functions from A to B.
Consider subsets of B of size 2. There are 23 functions from A to f1; 2g.
Similarly, there are 23 functions from A to f1; 3g. So we have 3 23 = 32 23
functions from A to B that are de…nitely not onto.
3 3
Note that 33 2 2 is not the …nal answer. We should realize that not all of
these 32 23 functions are distinct. For when, we consider all the functions from
A to f1; 2g, we are removing, among these, the function f(x; 2) ; (y; 2) ; (z; 2)g.
Discrete Mathematics for Computer Science 5

Then considering the functions from A to f2; 3g, we remove the same function
3 3
f(x; 2) ; (y; 2) ; (z; 2)g. Consequently, in the result 33 2 2 we have twice
removed each of the constant functions f : A ! B, where f (A) is one of the
sets f1g ; f2g ; or f3g. Adjusting our present result for this, we …nd that there
are
3 3 3 3 3 3 3 3
33 2 +3= 3 2 + 1 =6
2 3 2 1
onto functions from A to B.
Subcase 3.4 : m = 4 and n = 3.
Let A = fw; x; y; zg, and B = f1; 2; 3g. There are 34 functions from A to B.
Consider subsets of B of size 2. There are 24 functions from A to f1; 2g.
Similarly, there are 24 functions from A to f1; 3g. So we have 3 24 = 32 24
functions from A to B that are de…nitely not onto.
3 4
Note that 34 2 2 is not the …nal answer. We should realize that not all of
3 4
these 2 2 functions are distinct. For when, we consider all the functions from
A to f1; 2g, we are removing, among these, the function

f(w; 2) ; (x; 2) ; (y; 2) ; (z; 2)g

Then considering the functions from A to f2; 3g, we remove the same function
3 4
f(w; 2) ; (x; 2) ; (y; 2) ; (z; 2)g. Consequently, in the result 34 2 2 we have
twice removed each of the constant functions f : A ! B, where f (A) is one
of the sets f1g ; f2g ; or f3g. Adjusting our present result for this, we …nd that
there are
3 4 3 4 3 4 3 4
34 2 +3= 3 2 + 1 = 36
2 3 2 1
onto functions from A to B.
Subcase 3.5 : m 3 and n = 3.
There are 33 3m 3 m
2 2 +
3
1 1m onto functions from A to B.

Case 4 : The last two cases suggest a pattern that is now stated as a general formula.
For …nite sets jAj = m 2 P and jBj = n 2 P, where m n, the number of onto
functions f : A ! B is

n m n m n m
n (n 1) + (n 2) :::
n n 1 n 2
n 2 n m n 1 n
+ ( 1) 2 + ( 1) 1m
2 1
n
X1 k n m
= ( 1) (n k)
n k
k=0
n
X k n m
= ( 1) (n k)
n k
k=0

Example Let A = f1; 2; 3; 4; 5; 6; 7g and B = fw; x; y; zg. The number of onto func-
tions from A to B by using the general formula, where jAj = m = 7 and jBj = n = 4
Discrete Mathematics for Computer Science 6

is
4
X k 4 7
( 1) (4 k) = 8400
4 k
k=0

The number P of onto functions bears a resemblance to the following problem. For
n k m
m n there are k=0 ( 1) n n k (n k) ways to distribute m distinct objects into n
numbered (but otherwise identical) containers with no containers left empty.
Removing the numbers on containers, so that they are now identical in appearance, we
…nd that one distribution into these n (nonempty) identical containers corresponds with
n! such distributions into the numbered containers. So the number of ways in which it is
possible to distribute the m distinct objects into n identical containers, with no container
left empty, is
n
1 X k n m
( 1) (n k)
n! n k
k=0

These numbers are denoted by S (m; n), and are called Stirling numbers of the second
kind.
Thus for jAj = m, jBj = n, where m n, the number of onto functions from A to B
is given by n!S (m; n).

Theorem Let m; n 2 P, where 1 < n m. Then

S (m + 1; n) = S (m; n 1) + nS (m; n)

Proof. Let A = fa1 ; a2 ; : : : ; am ; am+1 g. Then S (m + 1; n) counts the number of


ways in which the objects of A can be distributed among n identical containers, with no
container left empty.
There are S (m; n 1) number of ways of distributing a1 ; a2 ; : : : ; am among (n 1)
identical containers, with no container left empty. Then placing am+1 in the remain-
ing empty container results in S (m; n 1) of the distribution counted in S (m + 1; n) -
namely, those distributions where am+1 is in a container by itself.
Alternatively, distributing a1 ; a2 ; : : : ; am among the n identical containers with none
left empty, we have S (m; n) distributions. Now, however for each of these S (m; n) dis-
tributions the n containers become distinguished by their contents. Selecting one of the
n distinct containers for am+1 , we have nS (m; n) distributions of the total S (m + 1; n) -
namely, those were am+1 is in the same container as another object from A. The result
then follows by the rule of sum.

Example Let m = 7 and n = 3. Then S (8; 3) = 966, S (7; 2) = 63, and S (7; 3) = 301.
It can be checked that

S (7; 2) + 3S (7; 3)
= 63 + 3 (301)
= 966 = S (8; 3)
Discrete Mathematics for Computer Science 7

5. Special Functions

De…nitions

1. Binary operation. For any nonempty sets A; B; and any function f : A A ! B


is called a binary operation on A: If B A, then the binary operation is said to be
closed (on A).
2. Unary or monary operation. A function g : A ! A is called unary or monary
operation on A.
3. Let f : A A ! B, that is f is a binary operation on A.

(a) Commutative function. The function f is said to be commutative if f (a; b) =


f (b; a) for all (a; b) 2 A A.
(b) Associative function. When B A (that is, when f is closed ), f is said to be
associative if for all a; b; c 2 A, f (f (a; b) ; c) = f (a; f (b; c)).

4. Identity element. Let f : A A ! B be a binary operation on A. An element


x 2 A is called an identity (or identity element) for f if f (a; x) = f (x; a) = a, for
all a 2 A.

Theorem Let f : A A ! B be a binary operation. If f has an identity element,


then that identity is unique.

De…nition. Projection. For sets A and B, if D A B, then A : D ! A, de…ned


by A (a; b) = a, is called the projection on the …rst coordinate. The function B : D ! B,
de…ned by B (a; b) = b, is called the projection on the second coordinate.
Discrete Mathematics for Computer Science 8

6. The Pigeonhole Principle

The pigeonhole principle is a simple and obvious idea.

The Pigeonhole Principle. If m pigeons occupy n pigeonholes, and m > n, then at


least one pigeonhole has two or more pigeons roosting in it.

The pigeonhole principle can be proved by contradiction. If the result is not true, then
each pigeonhole has at most one pigeon roosting in it, for a total of at most n (less than
m) pigeons. Somewhere we have lost at least (m n) pigeons.

Example. To ensure that a class includes at least 2 students whose last names begin
with the same letter of the English alphabet, the class should have at least 27 students.
Here the letters are the pigeonholes.

Example. Suppose there are several red socks, several white socks, and several blue
socks in a box. What is the least number of socks that one should grab from the box
(without looking at the contents) to be sure of getting a matching pair?
If each color is considered a pigeonhole, then n = 3. Therefore, if one grabs (n + 1)
pigeons (socks), at least 2 of them will share a color.

Notation. d e is the ceiling function. For example d5:6e = 6, d 5:6e = 5, and


d5:0e = 5.

Generalized Pigeonhole Principle. If N objects are placed into k boxes, then


there is at least one box containing at least dN=ke objects.
Proof. The proof is via contraposition. Suppose that none of the boxes contain more
than dN=ke 1 objects. Then the total number of objects is at most

N N
k 1 <k +1 1 =N
k k

where the inequality dN=ke < (N=k) + 1 has been used. This is a contradiction because
there are a total of N objects.

Example. Among 100 people there are at least d100=12e = 9 who were born in the
same month.
Discrete Mathematics for Computer Science 9

7. Function Composition and Inverse Functions

De…nitions.

1. Bijective function. A function f : A ! B is bijective if it is both surjective and


injective. If the sets A and B are …nite, then jAj = jBj : A bijective function is also
said to be a one-to-one correspondence.
2. Identity function. The function 1A : A ! A, de…ned by 1A (a) = a for all a 2 A, is
called the identity function for A.
3. Equal functions. 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.
4. Composite function. If f : A ! B, and g : B ! C, the composite function, which
is denoted g f : A ! C, is (g f ) (a) = g (f (a)), for each a 2 A.
5. Invertible function. If f : A ! B, then f is said to be invertible if there is a
function g : B ! A such that g f = 1A and f g = 1B . The function g is also
denoted as f 1 .

Theorem. Let f : A ! B, and g : B ! C.

(a) If f and g are one-to-one, then g f is one-to-one.


(b) If f and g are onto, then g f is onto.

Theorem. If a function f : A ! B, is invertible, and a function g : B ! A satis…es


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

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

Theorem. If f : A ! B, and g : B ! C are invertible functions, then g f : A ! C


1
is invertible and (g f ) = f 1 g 1 .

Theorem. Let f : A ! B, where A and B are …nite sets with jAj = jBj. Then the
following statements are equivalent.

(a) f is one-to-one.
(b) f is onto.
(c) f is invertible.

You might also like