6 Relations 1
6 Relations 1
Functions as Relations
Let A and B be nonempty sets.
A function f from A to B is an assignment of
exactly one element of B to each element of A.
We write f(a) = b if b is the unique element of
B assigned by the function f to the element a
of A.
If f is a function from A to B,
we write f:A→B
1
Relations
binary relation
Let A, B be sets, a binary relation R from A to
B,
is a subset of A×B. R AxB
R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),
(3,3),
(3,4),(4,4)}
1
loop
2
4 3
vertex(node)
edge(arc) 6
Relations
Representation of relation (matrix)
A relation between finite sets can be
represented using a zero-one matrix.
Suppose that R is a relation from A={a1,a2,
…,am) to B={b1,b2,….,bn}. This relation can be
represented by the matrix MR=[mij], where:
[mij]= 1 if (ai,bj) R
0 if (ai,bj) R
Example a Let
b A ={0,1,2} and B={a,b} and the
relation R from A to B is {(0,a),(0,b),(1,a),
0
(2,b)}. 1 1
1 MR 1 0
= 7
2 0 1
Relations on a Set
A (binary) relation from a set A to itself is
called a relation on the set A.
Example
Let A={1,2,3,4} which ordered pairs are in the
R={(a,b) | a divides b}.
R 1 2 3 4
1,2,3,4 are positive integer, max is 4
R= {(1,1),(1,2),(1,3),(1,4),(2,2),(2,4),1 x x x x
(3,3),(4,4)}
2 x x
3 x
Draw the arrow diagram, digraph, 4 x
and matrix?
8
Relations on a Set
Example
Consider these relations on the set of integers
R1={(a,b) | a b}
R2={(a,b) | a b}
R3={(a,b) | a=b or a=-b}
R4={(a,b) | a=b}
R5={(a,b) | a=b+1}
R6={(a,b) | a+b 3}
Which of these relations contain each of the
pairs (1,1), (1,2), (2,1), (1,-1), and (2,2) ?
2
Thus there are 2 relations on a set with n
n
elements.
2
For example there are 23 = 29 =512 relations
on the set {a,b,c} 10
Properties of Relations
There are several properties that are used to
classify relations on a set.
11
Properties of Relations
A relation R on a set A is called reflexive if
(a,a)R for every element aA (aA), aRa.
–E.g., the relation ≥ :≡ {(a,b) | a≥b} is
reflexive
A relation R on the set A is reflexive if
a((a,a)R) when the universe of discourse is
the set of all elements in A.
15
Properties of Relations
A relation R on a set A is called reflexive if and
only if there is a loop at every vertex of the
directed graph.
R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),
(3,3),
(3,4),(4,4)}
1
2
4 3
irreflexive ? 16
Properties of Relations
A relation R on a set A is called reflexive if and
only if (ai,ai)R this means that mii=1 for
i=1,2,.,n
All the elements on the main diagonal of MR
are equal to 1
R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),
(3,3),
(3,4),(4,4)} 1 1 1 1
0 1 1 1
MR
= 0 0 1 1
0 0 0 1
irreflexive ? 17
Properties of Relations
A relation R on a set A is symmetric
if (b,a)R whenever (a,b)R for all a,b A
ab((a,b) R → (b,a)R )
example
Let R be the following relation defined on the
set
{a, b, c, d}:
R = {(a, a), (b, b), (c, c), (d, d)}.
Determine whether R is:
(a) reflexive. Yes
(b) symmetric. yes
(c) antisymmetric. yes 20
Properties of Relations
Example
Consider the following relations on the
{1,2,3,4}
R1 ={(1,1),(1,2),(2,1),(2,2),(3,4),(4,1),(4,4)}
R2 ={(1,1),(1,2),(2,1)}
R3 ={(1,1),(1,2),(1,4),(2,1),(2,2),(3,3),(4,1),
(4,4)}
R4 ={(2,1),(3,1),(3,2),(4,1),(3,4)}
R5 ={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),
(3,3),
(3,4),(4,4)}
R6 ={(3,4)}
21
Which of these relations are symmetric and
Properties of Relations
Example
Consider the following relations on the set of
integers
R1={(a,b) | a b}
R2={(a,b) | a b}
R3={(a,b) | a=b or a=-b}
R4={(a,b) | a=b}
R5={(a,b) | a=b+1}
R6={(a,b) | a+b 3}
Which of these relations are symmetric and
which are antisymmetric ?
R3 , R4 ,and R6 are symmetric because in each
22
case (b,a) belongs to the relation whenever
Properties of Relations
Example
Consider the following relations on the set of
integers
R1={(a,b) | a b} ab and ba imply that
a=b
R2={(a,b) | a b}
R3={(a,b) | a=b or a=-b}
R4={(a,b) | a=b}
R5={(a,b) | a=b+1}
R6={(a,b) | a+b 3}
R1 , R2 , R4 , R5 are antisymmetric
R2 is antisymmetric it is impossible for a>b 23
and
Properties of Relations
Example
Is the “divides” relation on the set of positive
integers symmetric? Is it antisymmetric ?
This relation is not symmetric because 1|2, but
2|1.
24
Properties of Relations
A relation R on a set A is called symmetric if
and only if for every edge between distinct
vertices in its directed graph there is an edge
in the opposite direction.
R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),
(3,3),
(3,4),(4,4)} 2
1
Not
symmetri
c
3 4
25
Properties of Relations
A relation R on a set A is called antisymmetric
if and only if there are never two edges in the
opposite direction between distinct vertices in
its directed graph
2
1
Antisymmetr
ic
Not reflexive
Not
3 4
symmetric
26
Properties of Relations
A relation R on a set A is called symmetric if
and only if mij=mji of MR for i=1,2,.,n j=1,2,.,n
R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),
(3,3),
(3,4),(4,4)}
(a,b) 1 2 3 4
1 1 1 1 1
2 0 1 1 1
Antisymmet MR
ric 3 = 0 0 1 1
4 0 0 0 1
27
Properties of Relations
A relation R on a set A is called symmetric if
and only if mij=mji of MR for i=1,2,.,n j=1,2,.,n
R={(1,1),(1,2),(1,3),(2,2),(2,3),(2,4),(3,3),
(3,4),(4,4)}
(a,b) 1 2 3 4
1 1 1 1 0
2 0 1 1 1
Antisymmet MR
ric 3 = 0 0 1 1
4 0 0 0 1
28
Properties of Relations
Suppose that the relation R on a set A is
represented by the matrix
A relation R is reflexive iff
1 1 0 (ai,ai)R this means that mii=1
for i=1,2,.,n
MR 1 1 1
=
0 1 1
A relation R is symmetric
1 1 0
if (a,b)R ↔ (b,a)R
MR 1 1 1 this means that mij=mji for
= i=1,2,.,n
0 1 1
29
Properties of Relations
Suppose that the relation R on a set A is
represented by the matrix
1 1 0
0 0 0
MR 1 1 1 This relation is reflexive
= symmetric
1 0 1 antisymmetric
30
Properties of Relations
Suppose that the relation R on a set A is
represented by the matrix
1 1 0
1 1 0
MR 1 1 0 This relation is reflexive
= symmetric
0 0 1 antisymmetric
31
Properties of Relations
Let R be the relation consisting of all pairs
(x,y) of students at your school, where x has
taken more credits than y.
Suppose that x is related to y and y related to
z.
This means that
x has taken more credits than y and
y has taken more credits than z
We can conclude that
x has taken more credits than z, so that x is
related to z.
33
Properties of Relations
Consider the following relations on the
{1,2,3,4}
R1 ={(1,1),(1,2),(2,1),(2,2),(3,4),(4,1),(4,4)}
R2 ={(1,1),(1,2),(2,1)}
R3 ={(1,1),(1,2),(1,4),(2,1),(2,2),(3,3),(4,1),
(4,4)}
R4 ={(2,1),(3,1),(3,2),(4,1),(4,2),((4,3)}
R5 ={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),
(3,3),
(3,4),(4,4)}
R6 ={(3,4)}
Which of these relations are transitive ?
The relation is transitive 34
Properties of Relations
Consider the following relations on the set of
integers
R1={(a,b) | a b}
R2={(a,b) | a b}
R3={(a,b) | a=b or a=-b}
R4={(a,b) | a=b}
R5={(a,b) | a=b+1}
R6={(a,b) | a+b 3}
Which of these relations are transitive ?
36
Properties of Relations
A relation is transitive if and only if whenever
there is an edge from a vertex x to a vertex y
and an edge from a vertex y to a vertex z,
there is an edge from a vertex x to a vertex z
completing a triangle where each side is a
directed edge with the correct direction.
2
1
3 4
37
Properties of Relations
Exercises PP.542-544
2-3
13-14
22-28
32
38
Combining Relations
Let A={1,2,3} and B={1,2,3,4}
The relation
R1={(1,1),(2,2),(3,3)}
R2={(1,1),(1,2),(1,3),(1,4)}
R1 R2 = {(1,1),(1,2),(1,3),(1,4),(2,2),(3,3)}
R1 R2 = {(1,1)}
R1 - R2 = {(2,2),(3,3)}
R2 - R1 = {(1,2),(1,3),(1,4)}
R1 R2 = R2 R1 = R1 R2 - R1 R2
= {(1,2),(1,3),(1,4),(2,2),(3,3)}
39
Combining Relations
Let A={1,2,3} and B={1,2,3,4}
The relation
R1={(1,1),(2,2),(3,3)}
R2={(1,1),(1,2),(1,3),(1,4)}
Construct MR1 and MR2
40
Compositions of Relations
Let R be a relation from a set A to a set B and
S a relation from B to a set C.
The composite of R and S is the relation
consisting of ordered pairs (a,c), where aA ,
cC, and for which there exists an element
bB such that (a,b)R and (b,c)S. we denote
the composite of R and S by SR
Example
R is the relation from {1,2,3} to {1,2,3,4}
S is the relation from {1,2,3,4} to {0,1,2}
R = {(1,1),(1,4),(2,3),(3,1),(3,4)}
S = {(1,0),(2,0),(3,1),(3,2),(4,1)}
SR={(1,0),(1,1),(2,1),(2,2),(3,0),(3,1)}} T/F
41
Compositions of Relations
To find the matrix representing the relation
SR (composite of R and S)
Construct MR and Ms
MSR= MR ⊙ Ms
42
Compositions of Relations
•The nth power Rn of a relation R on a set A can
be defined recursively by:
R1 =R Rn+1 = RnR for all n>0.
R2= RR , R3= R2R = (RR)R
Example
R = {(1,1),(2,1),(3,2),(4,3)}, find the powers
Rn,n=2,3,4,….
43
Compositions of Relations
Let R be a relation from a set A to a set B,
44
Closures of Relations
Consider relation R={(1,2),(2,2),(3,3)} on the
set A = {1,2,3,4}.
Is R reflexive? No
45
Closures of Relations
In general
Let R be a relation on a set A
R may or may not have some property P such
as:
Reflexivity – Symmetry – Transitivity
Is R is equivalence relation?
R={(a,b) | a=b or a=-b} r,s, and t