Lecture Notes 07, Relations and Functions
Lecture Notes 07, Relations and Functions
Imran Shafi
Email: Imran.shafi@umt.edu.pk
Lecture Contents
Ordered Pairs
Cartesian Product
Relations
Relation Types
1. Reflexive
2. Symmetric
3. Transitive
Functions (Definition, Examples)
Range of a function
Graph of a function
Types of Functions
1. One to One Function (definition, example, graph)
2. Onto Function (definition, example, graph)
3. Bijection Function (definition, example, graph)
Ordered Pairs
An ordered pair (a, b) consists of two elements “a” and “b” in which “a” is the
first element and “b” is the second element
The ordered pairs (a, b) and (c, d) are equal if, and only if, a = c and b = d
R1 =
R2 = {(0,1)}
R3 = {(1,1)}
R4 = {(0,1), (1,1)}
Exercises
Let A = {1, 2, 3, 4}
Define a relation R on A as
(a, b) R iff a divides b {symbolically written as a | b}
1 R
x
2
y
3
A B
Directed Graph of a Relation
Let A be a set and R be a relation on it then The directed graph of
R is obtained by representing points of A only once, and drawing
an arrow from each point of A to each related point. If a point is
related to itself, a loop is drawn that extends out from the point
and goes back to it.
1
0
2 3
Matrix Representation of a Relation
Let A = {a1, a2, …, an} and B = {b1, b2, …, bm}. Let R be a relation from
A to B. Define the n x m order matrix M by
1 if (ai , bi ) R
m(i, j )
0 if (ai , bi ) R
for i=1,2,…,n and j=1,2,…,m
1 2 3
1 1 0 1
M 2 1 0 0
3 0 1 1
Example
Let A = {2, 3, 5, 6, 8}
The congruence modulo 3 relation T is defined on A as follows:
for all integers m, n A, mTn 3 | (m – n)
i.e. m-n is divisible by 3
Write T as a set of ordered pairs.
The directed graph representation.
The matrix representation.
Example
Define a binary relation S from R to R as follows:
for all (x, y) RXR, xSy x y.
Is (2,1) S?
Is (2,2) S?
Is 2S3?
Is (-1) S (-2)?
Draw the directed graph of S
Example
Let A = {2, 4} and B = {6, 8, 10} and define relations R and S from A to
B as follows:
for all (x,y) A X B, x R y x | y
for all (x,y) A X B, x S y y – 4 = x
State explicitly which ordered pairs are in A X B, R, S, R S and R S
Reflexive Relation
Let R be a relation on a set A. R is reflexive if, and only if, for all a A, (a, a)
R. Or equivalently aRa.
That is, each element of A is related to itself.
REMARK
R is not reflexive iff there is an element “a” in A such that (a, a) R. That is,
some element “a” of A is not related to itself.
Reflexive Relation
Let A = {1, 2, 3, 4} and define relations R1, R2, R3, R4 on A as follows:
R1 = {(1, 1), (3, 3), (2, 2), (4, 4)}
R2 = {(1, 1), (1, 4), (2, 2), (3, 3), (4, 3)}
R3 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}
R4 = {(1, 3), (2, 2), (2, 4), (3, 1), (4, 4)}
Which one of R1, R2, R3 & R4 are not reflexive? Why?
Reflexive Relation: Example
Let A = {1, 2, 3, 4} and define relations R1, R2, R3, and R4 on A by
R1 = {(1, 1), (3, 3), (2, 2), (4, 4)}
R2 = {(1, 1), (1, 4), (2, 2), (3, 3), (4, 3)}
Then their directed graphs are:
Reflexive Relation: Example
Let A = {1, 2, 3, 4} and define relations R1, R2, R3, and R4 on A by
R3 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}
R4 = {(1, 3), (2, 2), (2, 4), (3, 1), (4, 4)}
Then their directed graphs are:
Reflexive Relation: Matrix Representation
Let A = {a1, a2, …, an}. A Relation R on A is reflexive if and only if (ai, ai) R
i=1,2, …,n.
Accordingly, R is reflexive if all the elements on the main diagonal of the
matrix M representing R are equal to 1.
e.g. The relation R = {(1,1), (1,3), (2,2), (3,2), (3,3)} on
A = {1,2,3} represented by the following matrix M, is reflexive.
1 2 3
1 1 0 1
M 2 0 1 0
3 0 1 1
Symmetric Relation
Let R be a relation on a set A. R is symmetric if, and only if, for all a, b A, if
(a, b) R then (b, a) R.
That is, if aRb then bRa.
Example: Let A = {1, 2, 3, 4} and define relations R1, R2, R3, R4 on A as
follows. Which of them are symmetric?
R1 = {(1, 1), (1, 3), (2, 4), (3, 1), (4,2)}
R2 = {(1, 1), (2, 2), (3, 3), (4, 4)}
R3 = {(2, 2), (2, 3), (3, 4)}
R4 = {(1, 1), (2, 2), (3, 3), (4, 3), (4, 4)}
Note: For a symmetric directed graph whenever there is an arrow going from one
point of the graph to a second, there is an arrow going from the second point back
to the first.
Directed Graph: Example
Let A = {1, 2, 3, 4} and define relations R1, R2, R3 and R4 on A by the
directed graphs:
R1 = {(1, 1), (1, 3), (2, 4), (3, 1), (4,2)}
R2 = {(1, 1), (2, 2), (3, 3), (4, 4)}
R3 = {(2, 2), (2, 3), (3, 4)}
R4 = {(1, 1), (2, 2), (3, 3), (4, 3), (4, 4)}
Directed Graph: Example continue….
R1 = {(1, 1), (1, 3), (2, 4), (3, 1), (4,2)}
R2 = {(1, 1), (2, 2), (3, 3), (4, 4)}
R3 = {(2, 2), (2, 3), (3, 4)}
R4 = {(1, 1), (2, 2), (3, 3), (4, 3), (4, 4)}
EXAMPLE:
Let A = {1, 2, 3, 4} and
R = {(1,1), (2,2), (2,4), (3,3), (4,2), (4,4)}
be a binary relation on A.
EXAMPLE :
Let A = {1,2,3} and R = {(1,3), (2,1), (2,3), (3,2)} be
represented by the matrix 1 2 3
1 0 0 1
M 2 1 0 1
3 0 1 0
R is irreflexive, since all elements in the main diagonal are 0’s.
Irreflexive Relation: Example
Let R be the relation on the set of integers Z defined as:
for all a,b Z, (a,b) R a > b.
Is R irreflexive?
Anti-Symmetric Relation
Let R be a binary relation on a set A.
R is anti-symmetric iff
a, b A if (a,b) R and (b,a) R then a = b
Remarks:
1. R is not anti-symmetric iff there are elements a and b in A such that (a,b)
R and (b, a) R but a b
2. The properties of being symmetric and being anti-symmetric are not
negative of each other
Anti-Symmetric Relation: Example
Let A = {1,2,3,4} and define the following relations on A.
R1 = {(1,1),(2,2),(3,3)}
R2 = {(1,2),(2,2), (2,3), (3,4), (4,1)}
R3={(1,3),(2,2), (2,4), (3,1), (4,2)}
R4={(1,3),(2,4), (3,1), (4,3)}
EXAMPLE :
Let A = {1,2,3} and a relation R = 1 2 3
{(1,1), (1,2), (2,3), (3,1)} on A be 1 1 1 0
represented by the matrix.
M 2 0 0 1
3 1 0 0
Partial Order Relation
Let R be a binary relation defined on a set A. R is a partial order
relation, iff R is reflexive, anti-symmetric, and transitive
The set A together with a partial ordering R is called a partially
ordered set.
Partial Order Relation: Example
A = {1,2,3,4} and
R1 = {(1,1),(2,2),(3,3),(4,4)}
R2 = {(1,1),(1,2), (2,1), (2,2), (3,3),(4,4)}
R3={(1,1),(1,2), (1,3), (1,4), (2,2), (2,3),(2,4), (3,3),(3,4), (4,4)}
R1 is a partial order relation because you can see easily that the relation is reflexive,
anti-symmetric and reflexive
R2 is not anti-symmetric. Note that R2 is reflexive and transitive but not anti-
symmetric as (1,2) & (2,1) R2 but 1 2; Hence not a partial order relation.
R3 is a partial order relation you can easily see that it is reflexive anti-symmetric
and transitive
Partial Order Relation: Example
Let R be the set of real numbers and define the “less than or equal to” ,
on R as follows:
for all real numbers x and y in R.
x y x < y or x = y
Show that is a partial order relation
Partial Order Relation: Example
Let A be a non-empty set and P(A) the power set of A. Define the “subset”
relation, , as follows:
for all X,Y P(A), X Y x, iff x X then x Y.
Show that is a partial order relation
Partial Order Relation: Example
Let “|” be the “divides” relation on a set A of positive integers. That is, for all
a, b A,
a|b b = ka for some integer k.
Prove that | is a partial order relation on A.
Partial Order Relation: Example
Let “R” be the relation defined on the set of integers Z as follows:
for all a, b Z, aRb b=ar for some positive integer r.
Show that R is a partial order on Z.
Function
A Function assigns to each element of a set, exactly one element of a related
set
Functions find their application in various fields like representation of the
computational complexity of algorithms, counting objects, study of sequences
and strings etc
The Definition
A function (Defined as f: X→Y where X & Y are non-empty sets) F from a set X
to a set Y is a relation from X to Y that satisfies the following two properties:
1. For every element x in X, there is an element y in Y such that (x, y) F i.e.
every element of X is the first element of some ordered pair of F
2. For all elements x in X and y and z in Y, if (x, y) F and (x, z) F, then y =
z i.e. no two distinct ordered pairs in F have the same first element.
Function ………. Examples
Which of the relations define functions from X = {2,4,5} to Y={1,2,4,6}?
R1 = {(2,4), (4,1)}
R2 = {(2,4), (4,1), (4,2), (5,6)}
R3 = {(2,4), (4,1), (5,6)}
a) R1 is not a function, because 5 X does not appear as the first element in any
ordered pair in R1.
b) R2 is not a function, because the ordered pairs (4,1) and (4,2) have the same
first element but different second elements.
c) R3 defines a function because it satisfy both the conditions of the function
Function ………. Examples
Let A = {4,5,6} and B = {5,6} and define binary relations R and S from A to
B as follows:
for all (x,y) A B, (x,y) R xy
for all (x,y) A B, xSy 2|(x-y)
a) Represent R and S as a set of ordered pairs
b) Indicate whether R or S is a function
Functions
A function f from a set X to a set Y is a relationship between elements of
X and elements of Y such that each element of X is related to a unique
element of Y, and is denoted f : X Y. The set X is called the domain of f
and Y is called the co-domain of f.
Functions
The definition of a function implies that the arrow diagram for a function
f has the following two properties:
1. Every element of X has an arrow coming out of it
2. No two elements of X has two arrows coming out of it that point to
two different elements of Y.
f
EXAMPLE
Let X = {a, b, c} and Y={1,2,3,4} .1
a.
.2
Define a function f from X to Y by the arrow diagram b.
.3
c.
.4
X Y
Range of a Functions
Let f: XY. The range of f consists of those elements of Y that are image of
elements of X.
Symbolically: Range of f = {y Y| y = f(x), for some x X}
NOTE
1. The range of a function f is always a subset of the co-domain of f.
2. The range of f: X Y is also called the image of X under f.
3. When y = f(x), then x is called the pre-image of y.
4. The set of all elements of X, that are related to some y Y is called the
inverse image of y.
Range of a Functions … Examples
Determine the range of the functions f, g, h from X = {2,4,5} to Y = {1,2,4,6}
defined as:
x y=f(x)
-3 9 y-axis
y = x2 y = x2
-2 4
-1 1
0 0 (-3,9) (3,9)
+1 1
(x , f(x))
+2 4
+3 9 (-2,4) (2,4)
(-1,1) (1,1)
O (o,o) x-axis
Vertical Line Test for a Function
For a graph to be the graph of a function, any given vertical line in its
domain intersects the graph in at most one point.
EXAMPLE:
The graph of the relation y = x2 on R defines y-axis y=x2
a function by vertical line test.
x-axis
Vertical Line Test for a Function
Define a binary relation P from R to R as follows:
for all real numbers x and y (x, y) P x = y2
Is P a function? Explain.
The graph of the relation x = y2 is shown below
x Y
9 -3
4 -2
1 -1
0 0
1 1
4 2
9 3
Exercise
Find all functions from X = {a, b} to Y = {u, v}
Find four binary relations from X = {a, b}to Y = {u, v}that are not
functions.
How many functions are there from a set with three elements to
a set with four elements?
Types of Functions
1. Injection
2. Surjection
3. Bijection
Injective (One to One) Function
A function from A to B is one-to-one or injective, if for all elements x ,x in
1 2
A such that f(x1) = f(x2), i.e x1=x2
No elements of A are assigned to the same element in B and each element
of the range corresponds to exactly one element in domain
Examples
Surjective (Onto) Function
A function (f: A→B) from A to B is onto or surjective, if every element of B
is the image of some element in A i.e all the elements of B has a pre-image
in A
The image or range of a surjective function is equal to its co-domain
For every b ∈ B, there exists some a ∈ A in f such that f(a) = b
Surjective (Onto) Function… Examples
f: Z+Z+, f(x)=x2 is surjective function
Not a Surjective (Onto) Function
A function f:XY is not onto iff there exists y Y such that
x X, f(x)y.
That is, there is some element in Y that is not the image of any
element in X.
Example
Graph of Onto Function
A graph of a function f is onto iff every horizontal line
intersects the graph in at least one point.
Examples
Bijective Function
A function from A to B is Bijective correspondence, if f is both
injective(one-to-one) and surjective(onto).
Bijective Function … Example
Function f: R→R defined by f(x) = 2x − 3 is a bijective function
f will be injective if for all elements x1, x2 in A, f(x1) = f(x2) only if x1=x2
Let f(x1) = f(x2)
2x1 − 3 = 2x2 − 3
x1=x2 hence proved that f is injective
Now we have to prove that f is surjective
Bijective Function … Example