Lecture 03 Relation
Lecture 03 Relation
Lecture 03 Relation
Lecture 3
1
Cartesian product (review)
Let
A={a1, a2, ..ak} and
B={b1,b2,..bm}.
3
Binary relation
Definition: Let A and B be two sets. A binary relation
from A to B is a subset of a Cartesian product A x B.
a→b
Example:
• Let A = {0, 1, 2}, B = {u,v} and
0 u
7
1 V
Representing Binary relation
We can graphically represent a binary relation R as follows:
• if a R b then draw an arrow from a to b.
a→b
Example:
• Let A = {0, 1, 2}, B = {u,v} and
b 3
9
Relation and Function
Relations represent one to many relationships between
elements in A and B.
• Example: a 1
b 3
R 1 2 3 4
1 x x x x
2 x x
3 x
4 x 11
Relation on the set
Definition: A relation on the set A is a relation from A to
itself.
Example 2:
• Let A = {1,2,3,4}.
• Define a R≠ b if and only if a ≠ b.
R≠ = {(a,b)| a ≠ b}
R≠={(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,2),(4,3)}
R 1 2 3 4
1 x x x
2 x x x
3 x x x
4 x x x 12
Binary Relation
Theorem: The number of binary relations on a set A, where
| A | = n is:
n2
Proof:
2
• If | A | = n then the cardinality of the Cartesian product
| A x A | = n 2.
• R is a binary relation on A if R A A (that is, R is a subset
of A x A).
• The number of subsets of a set with k elements : 2k
A A
• The number of subsets of A x A is : 2 2 n2
13
Binary Relation
Example: Let A = {1,2} |A|=2
• What is A x A = {(1,1),(1,2),(2,1),(2,2)} |AXA|=4
{(1,1),(1,2),(2,1)} {(1,1),(1,2),(2,2)} 4
{(1,1),(2,1),(2,2)} {(1,2),(2,1),(2,2)}
{(1,1),(1,2),(2,1),(2,2)} 1
Use formula: 24 = 16 16
14
Reflexive Relation
Definition (reflexive relation) : A relation R on a set A is
called reflexive if (a,a) ϵ R for every element a ϵ A.
Example 1:
• Is Rdiv reflexive?
15
Reflexive Relation
Definition (reflexive relation) : A relation R on a set A is
called reflexive if (a,a) ϵ R for every element a ϵ A.
Example 1:
• Is Rdiv reflexive?
16
Reflexive Relation
Reflexive relation
• Rdiv ={(a b), if a |b} on A = {1,2,3,4}
0 1 0 1
0 0 1 0
0 0 0 1
17
Reflexive Relation
Definition (reflexive relation) : A relation R on a set A is
called reflexive if (a,a) ϵ R for every element a ϵ A.
Example 2:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun reflexive?
18
Reflexive Relation
Definition (reflexive relation) : A relation R on a set A is
called reflexive if (a,a) ϵ R for every element a ϵ A.
Example 2:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun reflexive?
19
Irreflexive Relation
Definition (irreflexive relation): A relation R on a set A is
called irreflexive if (a,a) R for every a ϵ A.
Example 1:
• Assume relation R≠ on A={1,2,3,4}, such that a R≠ b if and
only if a ≠ b.
R≠ =
{(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,2),(
4,3)}
• Is R≠ irreflexive?
20
Irreflexive Relation
Definition (irreflexive relation): A relation R on a set A is
called irreflexive if (a,a) R for every a ϵ A.
Example 1:
• Assume relation R≠ on A={1,2,3,4}, such that a R≠ b if and
only if a ≠ b.
R≠ =
{(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,2),(
4,3)}
• Is R≠ irreflexive?
• R≠={(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,2),(4,3)}
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
Example 2:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun irreflexive?
23
Irreflexive Relation
Definition (irreflexive relation): A relation R on a set A is
called irreflexive if (a,a) R for every a ϵ A.
Example 2:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun irreflexive?
24
Symmetric Relation
Definition (symmetric relation): A relation R on a set A is
called
symmetric if
. a, b A( a, b) R (b, a ) R
Example 1:
• Is Rdiv symmetric?
25
Symmetric Relation
Definition (symmetric relation): A relation R on a set A is
called symmetric if
. a, b A( a, b) R (b, a ) R
Example 1:
• Is Rdiv symmetric?
Example 2:
R≠={(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,
2),(4,3)}
• Is R≠ symmetric ?
27
Symmetric Relation
Definition (symmetric relation): A relation R on a set A is
called symmetric if
a, b A(a, b) R (b, a ) R
Example 2:
R≠={(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,
2),(4,3)}
• Is R≠ symmetric ?
1 0 1 1
1 1 0 1
1 1 1 0
29
Symmetric Relation
Definition (symmetric relation): A relation R on a set A is
called symmetric if
a, b A(a, b) R (b, a ) R
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun symmetric?
30
Symmetric Relation
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun symmetric?
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,1),(3,2)}.
• Is Rfun asymmetric?
32
Asymmetric Relation
Definition (asymmetric relation): A relation on a set A is
called anti-symmetric if
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,1),(3,2)}.
• Is Rfun asymmetric?
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,3),(3,3)}.
• Is Rfun asymmetric?
34
Asymmetric Relation
Definition (asymmetric relation): A relation on a set A is
called anti-symmetric if
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,3),(3,3)}.
• Is Rfun asymmetric?
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun anti-symmetric?
36
Anti-symmetric Relation
Definition (anti-symmetric relation): A relation on a set A
is called anti-symmetric if
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun anti-symmetric?
0 1 0 0
0 1 0 0
0 0 1 0
0 0 0 0
• Example 1:
• Is Rdiv transitive? 11 12 12 12 22 12 13 33 13
11 13 13 12 24 14 14 44 14
11 14 14 22 24 24 33 33 33
24 44 24 44 44 44 39
Transitive Relation
Definition (transitive relation): A relation R on a set A is
called transitive if
• [(a,b) ϵ R and (b,c) ϵ R] → (a,c) ϵ R for all a, b, c ϵ A.
• Example 1:
• Is Rdiv transitive?
• Answer: Yes.
40
Transitive Relation
Definition (transitive relation): A relation R on a set A is
called transitive if
• [(a,b) ϵ R and (b,c) ϵ R] → (a,c) ϵ R for all a, b, c ϵ A.
• Example 2:
•
R≠={(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,
2),(4,3)}
• Is R≠ transitive ?
41
Transitive Relation
Definition (transitive relation): A relation R on a set A is
calledtransitive if
• [(a,b) ϵ R and (b,c) ϵ R] → (a,c) ϵ R for all a, b, c ϵ A.
• Example 2:
• Is R≠ transitive ?
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun transitive? 12 22 12
22 22 22
33 33 33
abbc ac
43
Transitive Relation
Definition (transitive relation): A relation R on a set A is
called transitive if
• [(a,b) ϵ R and (b,c) ϵ R] → (a,c) ϵ R for all a, b, c ϵ A.
Example 3:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun transitive?
44
Transitive Relation
Find the smallest relation containing the relation
{(1, 2), (1, 4), (3, 3), (4, 1)} that is
a) reflexive and transitive.
b) symmetric and transitive.
c) reflexive, symmetric, and transitive. on {1,2,3,4}
45
Transitive Relation
Find the smallest relation containing the relation
{(1, 2), (1, 4), (3, 3), (4, 1)} that is
R= {(11)(12)(13)(14)
(21)(22)(23)(24)
(31)(32)(33)(34)
(41)(42)(43)(44)}
46
Transitive Relation
Find the smallest relation containing the relation
{(1, 2), (1, 4), (3, 3), (4, 1)} that is
47
Transitive Relation
Find the smallest relation containing the relation
{(1, 2), (1, 4), (3, 3), (4, 1)} that is
R = {(1,1), (1, 2) (1, 4) (2,1) (2,2) (2,4) (3, 3) (4,1) (4, 2) (4,4) }
48
Intermission
49
Cartesian product (review)
Let
A={a1, a2, ..ak} and
B={b1,b2,..bm}.
51
Binary relation
Definition: Let A and B be two sets. A binary relation
from A to B is a subset of a Cartesian product A x B.
53
Reflexive Relation
Definition (reflexive relation) : A relation R on a set A is
called reflexive if (a,a) ϵ R for every element a ϵ A.
Example 1:
• Is Rdiv reflexive?
54
Reflexive Relation
Definition (reflexive relation) : A relation R on a set A is
called reflexive if (a,a) ϵ R for every element a ϵ A.
Example 1:
• Is Rdiv reflexive?
55
Reflexive Relation
Definition (reflexive relation) : A relation R on a set A is
called reflexive if (a,a) ϵ R for every element a ϵ A.
Example 2:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun reflexive?
56
Reflexive Relation
Definition (reflexive relation) : A relation R on a set A is
called reflexive if (a,a) ϵ R for every element a ϵ A.
Example 2:
• Relation Rfun on A = {1,2,3,4} defined as:
• Rfun = {(1,2),(2,2),(3,3)}.
• Is Rfun reflexive?
57
Symmetric Relation
Definition (symmetric relation): A relation R on a set A is
called symmetric if
a, b A(a, b) R (b, a ) R
Example 1:
• Is Rdiv symmetric?
58
Symmetric Relation
Definition (symmetric relation): A relation R on a set A is
called symmetric if
. a, b A( a, b) R (b, a ) R
Example 1:
• Is Rdiv symmetric?
Example 2:
R≠={(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,
2),(4,3)}
• Is R≠ symmetric ?
60
Symmetric Relation
Definition (symmetric relation): A relation R on a set A is
called symmetric if
a, b A(a, b) R (b, a ) R
Example 2:
R≠={(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,
2),(4,3)}
• Is R≠ symmetric ?
• Is Rdiv transitive?
62
Transitive Relation
Definition (transitive relation): A relation R on a set A is
called transitive if
[( a, b) R and (b, c) R ] (a, c) R a, b, c A
• Example 1:
• Is Rdiv transitive?
• Answer: Yes.
Is this one transitive? R={(2,3),(3,4),(2,4)}
63
Transitive Relation
Definition (transitive relation): A relation R on a set A is
called transitive if
[( a, b) R and (b, c) R ] (a, c) R a, b, c A
• Example 2:
•
R≠={(1,2),(1,3),(1,4),(2,1),(2,3),(2,4),(3,1),(3,2),(3,4),(4,1),(4,
2),(4,3)}
• Is R≠ transitive ? 12 21 11
64
Transitive Relation
Definition (transitive relation): A relation R on a set A is
calledtransitive if
[( a, b) R and (b, c) R ] (a, c) R a, b, c A
• Example 2:
• Is R≠ transitive ?
Combining Relations
• Relations are sets → combinations via set operations
• Set operations of: union, intersection, difference and
symmetric difference.
66
Combining Relation
Example:
• Let A = {1,2,3} and B = {u,v} and
• R1 = {(1,u), (2,u), (2,v), (3,u)}
• R2 = {(1,v),(3,u),(3,v)}
What is:
• R1 U R2 = ?
67
Combining Relation
Example:
• Let A = {1,2,3} and B = {u,v} and
• R1 = {(1,u), (2,u), (2,v), (3,u)}
• R2 = {(1,v),(3,u),(3,v)}
What is:
• R1 U R2 = {(1,u),(1,v),(2,u),(2,v),(3,u),(3,v)}
• R1 ∩ R2 = ?
68
Combining Relation
Example:
• Let A = {1,2,3} and B = {u,v} and
• R1 = {(1,u), (2,u), (2,v), (3,u)}
• R2 = {(1,v),(3,u),(3,v)}
What is:
• R1 U R2 = {(1,u),(1,v),(2,u),(2,v),(3,u),(3,v)}
• R1 ∩ R2 = {(3,u)}
• R1 - R2 = ?
69
Combining Relation
Example:
• Let A = {1,2,3} and B = {u,v} and
• R1 = {(1,u), (2,u), (2,v), (3,u)}
• R2 = {(1,v),(3,u),(3,v)}
What is:
• R1 U R2 = {(1,u),(1,v),(2,u),(2,v),(3,u),(3,v)}
• R1 ∩ R2 = {(3,u)}
• R1 - R2 = (1,u),(2,u),(2,v)}
• R2 - R1 = ?
70
Combining Relation
Example:
• Let A = {1,2,3} and B = {u,v} and
• R1 = {(1,u), (2,u), (2,v), (3,u)}
• R2 = {(1,v),(3,u),(3,v)}
What is:
• R1 U R2 = {(1,u),(1,v),(2,u),(2,v),(3,u),(3,v)}
• R1 ∩ R2 = {(3,u)}
• R1 - R2 = (1,u),(2,u),(2,v)}
• R2 - R1 = {(1,v),(3,v)}
71
Composite Relation
Examples:
• Let A = {1,2,3}, B = {0,1,2} and C = {a,b}.
• R = {(1,0), (1,2), (3,1),(3,2)}
• S = {(0,b),(1,a),(2,b)}
• SoR = {(1,b)(3,a)(3,b)}
RoS = {} 72
Composite Relation
Examples:
• Let A = {1,2,3}, B = {0,1,2} and C = {a,b}.
• R = {(1,0), (1,2), (3,1),(3,2)}
• S = {(0,b),(1,a),(2,b)}
• SoR = {(1,b),(3,a),(3,b)}
73
Composite Relation
Definition: Let R be a relation on a set A. The powers Rn, n
= 1,2,3,... is defined inductively by
• R1 = R and Rn+1 = Rn O R.
R2 = R1 O R = {(13)(14)(23)(33)}
R3 = R2 O R = {(13)(23)(33)}
R4 = R3 O R = {(13)(23)(33)}
Examples
• R = {(1,2),(2,3),(2,4), (3,3)} is a relation on A = {1,2,3,4}.
• R1 = {(1,2),(2,3),(2,4), (3,3)}
74
Composite Relation
• R1 = R and Rn+1 = Rn O R.
Examples
• R = {(1,2),(2,3),(2,4), (3,3)} is a relation on A = {1,2,3,4}.
• R1 = {(1,2),(2,3),(2,4), (3,3)}
• R2 = ?
75
Composite Relation
• R1 = R and Rn+1 = Rn O R.
Examples
• R = {(1,2),(2,3),(2,4), (3,3)} is a relation on A = {1,2,3,4}.
• R1 = {(1,2),(2,3),(2,4), (3,3)}
• R2 = {(1,3), (1,4), (2,3), (3,3)}
• R3 = ?
76
Composite Relation
• R1 = R and Rn+1 = Rn O R.
Examples
• R = {(1,2),(2,3),(2,4), (3,3)} is a relation on A = {1,2,3,4}.
• R1 = {(1,2),(2,3),(2,4), (3,3)}
• R2 = {(1,3), (1,4), (2,3), (3,3)}
• R3 = {(1,3), (2,3), (3,3)}
• R4 =
77
Composite Relation
• R1 = R and Rn+1 = Rn O R.
Examples
• R = {(1,2),(2,3),(2,4), (3,3)} is a relation on A = {1,2,3,4}.
• R1 = {(1,2),(2,3),(2,4), (3,3)}
• R2 = {(1,3), (1,4), (2,3), (3,3)}
• R3 = {(1,3), (2,3), (3,3)}
• R4 = {(1,3), (2,3), (3,3)}
• Rk = ? when k>3
78
Composite Relation
• R1 = R and Rn+1 = Rn O R.
Examples
• R = {(1,2),(2,3),(2,4), (3,3)} is a relation on A = {1,2,3,4}.
• R1 = {(1,2),(2,3),(2,4), (3,3)}
• R2 = {(1,3), (1,4), (2,3), (3,3)}
• R3 = {(1,3), (2,3), (3,3)}
• R4 = {(1,3), (2,3), (3,3)}
• Rk = {(1,3), (2,3), (3,3)}
79
Closure of a Relation
• Answer: ?
80
Closure of a Relation
• Answer: ?
81
Closure of a Relation
83
Closure of a Relation
84
Closure of a Relation
• S=?
85
Closure of a Relation
86
Closure of a Relation
• Is R transitive?
87
Closure of a Relation
• Is R transitive? No.
• How to make it transitive?
• S = {(1,2), (2,2), (2,3)} U {(1,3)}
= {(1,2), (2,2), (2,3),(1,3)}
• S is the transitive closure of R
88
Path length
89
Path length
90
Path length
91
Path length
R Rk
*
k 1
Example:
• A = {1,2,3,4}
• R = {(1,2),(1,4),(2,3),(3,4)}
R1 = {(1,2),(1,4),(2,3),(3,4)}
R2 = R1oR = {(1,3)(2,4)}
R3 = R2oR = {(1,4)}
R4 = R3oR = {} 94
Connectivity Relation
Definition: Let R be a relation on a set A. The connectivity
relation R* consists of all pairs (a,b) such that there is a path (of
any length, ie. 1 or 2 or 3 or ...) between a and b in R.
R Rk
*
k 1
Example:
• A = {1,2,3,4}
• R = {(1,2),(1,4),(2,3),(3,4)}
• R2 =?
95
Connectivity Relation
Definition: Let R be a relation on a set A. The connectivity
relation R* consists of all pairs (a,b) such that there is a path (of
any length, ie. 1 or 2 or 3 or ...) between a and b in R.
R Rk
*
k 1
Example:
• A = {1,2,3,4}
• R = {(1,2),(1,4),(2,3),(3,4)}
• R2 = {(1,3),(2,4)}
• R3 = ?
96
Connectivity Relation
Definition: Let R be a relation on a set A. The connectivity
relation R* consists of all pairs (a,b) such that there is a path (of
any length, ie. 1 or 2 or 3 or ...) between a and b in R.
R Rk
*
k 1
Example:
• A = {1,2,3,4}
• R = {(1,2),(1,4),(2,3),(3,4)}
• R2 = {(1,3),(2,4)}
• R3 = {(1,4)}
•R4 = ?
97
Connectivity Relation
Definition: Let R be a relation on a set A. The connectivity
relation R* consists of all pairs (a,b) such that there is a path (of
any length, ie. 1 or 2 or 3 or ...) between a and b in R.
R Rk
*
k 1
Example:
• A = {1,2,3,4}
• R = {(1,2),(1,4),(2,3),(3,4)}
• R2 = {(1,3),(2,4)}
• R3 = {(1,4)}
•R4 =Ø
• R* =?
98
Connectivity Relation
Definition: Let R be a relation on a set A. The connectivity
relation R* consists of all pairs (a,b) such that there is a path (of
any length, ie. 1 or 2 or 3 or ...) between a and b in R.
R Rk
*
k 1
Example:
• A = {1,2,3,4}
• R = {(1,2),(1,4),(2,3),(3,4)}
• R2 = {(1,3),(2,4)}
• R3 = {(1,4)}
•R4 =Ø
• R* = {(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}
99
Equivalence relation
A={1,2,3}
R={(1,1)(1,2)(2,1)(2,2)(3,3)}
Is it Reflexive?
100
Equivalence relation
A={1,2,3}
R={(1,1)(1,2)(2,1)(2,2)(3,3)}
Is it Reflexive? yes
It it Symmetric?
101
Equivalence relation
A={1,2,3}
R={(1,1)(1,2)(2,1)(2,2)(3,3)}
Is it Reflexive? yes
It it Symmetric? yes
Is it Transitive?
102
Equivalence relation
Reflexive, Symmetric and Transitive at the same
time
A={1,2,3}
R={(1,1)(1,2)(2,1)(2,2)(3,3)}
Is it Reflexive? yes
It it Symmetric? yes
Is it Transitive? yes
103
Is it an Equivalence relation? yes
(mod) congruence Formal Definition
Congruence mod
• Relates two numbers a, a’ to each other relative some base b
• a a’ (mod b) means that a and a’ have the same remainder
when dividing by b
• A:
• 3 3 (mod 17) True.
any number is congruent to itself (3-3 = 0,
divisible by all)
• 3 -3 (mod 17) False.
(3-(-3)) = 6 isn’t divisible by 17.
• 172 177 (mod 5) True.
172-177 = -5 is a multiple of 5
• -13 13 (mod 26) True.
-13-13 = -26 divisible by 26.
105
Equivalence Relation
106
Equivalence Relation
Is R reflexive
108
Equivalence Relation
Is R reflexive Yes
Is R symmetric
109
Equivalence Relation
Is R reflexive Yes
Is R symmetric Yes
Is R transitive 110
Equivalence Relation
Example: Let A = {0,1,2,3,4,5,6} and
• R= {(a,b)| a,b ϵ A, a ≡ b mod 3} (a is congruent to b modulo 3)
Relation R has the following pairs:
• (0,0) (0,3), (3,0), (0,6), (6,0)
• (3,3), (3,6) (6,3), (6,6) (1,1),(1,4), (4,1), (4,4)
• (2,2), (2,5), (5,2), (5,5)
Is R reflexive Yes
Is R symmetric Yes
Is R transitive Yes
111
Then R is an equivalence relation.
Example on Relation
112
Equivalence Relation
113
Equivalence Relation
114
Thank You
115