Relations of Discrete Functions Notes
Relations of Discrete Functions Notes
Week12 Relations
Chapter 8 Relations
Chih-Wei Yi
2 May 2008
Discrete Mathematics
Chapter 8 Relations
8.1 Relations and Their Properties
Binary Relations
De…nition
Let A and B be any two sets. A binary relation R from A to B,
written R : A $ B, is a subset of A B. The notation aRb means
(a, b ) 2 R.
If aRb, we may say “a is related to b (by relation R)”, or “a
relates to b (under relation R)”.
Example
<: N $ N : f(n, m) j n < mg. a < b means (a, b ) 2<.
Complementary Relations
De…nition
Let R : A $ B be any binary relation. Then, R : A $ B, the
complement of R, is the binary relation de…ned by
R: f(a, b ) j (a, b ) 2
/ R g = (A B) R.
Inverse Relations
De…nition
Any binary relation R : A $ B has an inverse relation
R 1 : B $ A, de…ned by
1
R : f(b, a) j (a, b ) 2 R g.
Examples
Examples
Example
Let A = f1, 2, 3, 4, 5g and R : A $ A : f(a, b ) : a j b g. What
are R and R 1 ?
Solution
(1, 1) , (1, 2) , (1, 3) , (1, 4) , (1, 5) , (2, 2) , (2, 4) ,
R=
(3, 3) , (4, 4) , (5, 5)
Discrete Mathematics
Chapter 8 Relations
8.1 Relations and Their Properties
Examples
Example
Let A = f1, 2, 3, 4, 5g and R : A $ A : f(a, b ) : a j b g. What
are R and R 1 ?
Solution
(1, 1) , (1, 2) , (1, 3) , (1, 4) , (1, 5) , (2, 2) , (2, 4) ,
R=
(3, 3) , (4, 4) , (5, 5)
8 9
< (2, 1) , (2, 3) , (2, 5) , (3, 1) , (3, 2) , (3, 4) , (3, 5) , =
R= (4, 1) , (4, 2) , (4, 3) , (4, 5) , (5, 1) , (5, 2) , (5, 3) ,
: ;
(5, 4)
Discrete Mathematics
Chapter 8 Relations
8.1 Relations and Their Properties
Examples
Example
Let A = f1, 2, 3, 4, 5g and R : A $ A : f(a, b ) : a j b g. What
are R and R 1 ?
Solution
(1, 1) , (1, 2) , (1, 3) , (1, 4) , (1, 5) , (2, 2) , (2, 4) ,
R=
(3, 3) , (4, 4) , (5, 5)
8 9
< (2, 1) , (2, 3) , (2, 5) , (3, 1) , (3, 2) , (3, 4) , (3, 5) , =
R= (4, 1) , (4, 2) , (4, 3) , (4, 5) , (5, 1) , (5, 2) , (5, 3) ,
: ;
(5, 4)
1 (1, 1) , (2, 1) , (3, 1) , (4, 1) , (5, 1) , (2, 2) , (4, 2) ,
R =
(3, 3) , (4, 4) , (5, 5)
Discrete Mathematics
Chapter 8 Relations
8.1 Relations and Their Properties
Relations on a Set
De…nition
A (binary) relation from a set A to itself is called a relation on the
set A.
Re‡exivity
De…nition
A relation R on A is re‡exive if 8a 2 A, aRa. A relation is
irre‡exive i¤ its complementary relation is re‡exive.
E.g., the relation : f(a, b ) j a b g is re‡exive.
E.g., < is irre‡exive.
"irre‡exive"6="not re‡exive"!
"likes" between people is not re‡exive, but not irre‡exive
either. (Not everyone likes themselves, but not everyone
dislikes themselves either.)
Discrete Mathematics
Chapter 8 Relations
8.1 Relations and Their Properties
Example
Consider the following relations on f1, 2, 3, 4g.
R1 = f(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)g ,
R2 = f(1, 1), (1, 2), (2, 1)g ,
R3 = f(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)g ,
R4 = f(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)g ,
(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3),
R5 = ,
(3, 4), (4, 4)
R6 = f(3, 4)g .
Transitivity
De…nition
A relation R is transitive i¤
Combining Relations
R1 [ R2 = f(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (3, 3)g ,
R1 \ R2 = f(1, 1)g ,
R1 R2 = f(2, 2), (3, 3)g
R2 R1 = f((1, 2), (1, 3), (1, 4)g .
Quiz: What is R1 R2 ?
Discrete Mathematics
Chapter 8 Relations
8.1 Relations and Their Properties
Composite Relations
Theorem
The relation R on a set A is transitive if and only if R n R for all
n = 1, 2, 3, .
Think about what (a, b ) 2 R k means?
How to prove an "if and only if" statement?
Let R = f(1, 1), (2, 1), (3, 2), (4, 3)g. Find the powers R n for
n = 2, 3, .
Let R = f(1, 2), (1, 3), (2, 2), (2, 3), (4, 3)g. Find the powers
R n for n = 2, 3, .
Discrete Mathematics
Chapter 8 Relations
8.2 n-ary Relations and Their Applications
n-ary Relations
De…nition
An n-ary relation R on sets A1 , , An , written R : A1 , , An , is
a subset R A1 An .
Relational Databases
Selection Operators
sC ( R ) = R \ f a 2 A j sC ( a ) = T g
= f a 2 R j sC ( a ) = T g .
Discrete Mathematics
Chapter 8 Relations
8.2 n-ary Relations and Their Applications
Projection Operators
is de…ned by
P f i k g ( a1 , , an ) = ( ai 1 , , ai m ) .
Discrete Mathematics
Chapter 8 Relations
8.2 n-ary Relations and Their Applications
Projection Example
Join Operator
Join Example
Representing Relations
Examples
Example
Let S = fSpring,Summer,Fall,Winterg and
F = fApple,Berry,Cherry,Durian,E*g. Which ordered pairs are in
the relation R represented by the matrix?
an
an
yt
yt
hin
h
any- 1 0
in
g
0
g
thing thing
any-
1 0 0 0
Reflexive: Irreflexive: Symmetric: Antisymmetric:
all 1’s on diagonal all 0’s on diagonal all identical all 1’s are across
across diagonal from 0’s
MR 1 [R 2 = MR 1 _ MR 2 ; MR 1 \R 2 = MR 1 ^ MR 2 .
_ and ^ are element-wise Boolean operators.
MS R = MR MS ; MR n = (MR )n .
denotes Boolean matrix multiplications.
MR = (MR )T .
1
Edge set EG
MR Susan Mary Sally GR (blue arrows)
Joe 1 1 0 Joe Susan
Fred 0 1 0 Fred Mary
Mark 0 0 1 Mark Sally
Node set VG
(black dots)
Discrete Mathematics
Chapter 8 Relations
8.3 Representing Relations
P
P P
P P
P P P P P P
Reflexive: Irreflexive: Symmetric: Antisymmetric:
Every node No node Every link is No link is
has a self-loop links to itself bidirectional bidirectional
Asymmetric, non-antisymmetric Non-reflexive, non-irreflexive
Discrete Mathematics
Chapter 8 Relations
8.4 Closures of Relations
Closures of Relations
Theorem
There exists a path of length n from a to b in R if and only if
(a, b ) 2 R n .
Lemma
Let A be a set with n element, and let R be a relation on A. If
there is a path of length at least one in R from a to b, then there
is such a path with length not exceeding n.
Roy-Warshall Algorithm
Examples
Example
Find the symmetric closure, re‡exive closure, and transitive closure
of the following relation.
P
Discrete Mathematics
Chapter 8 Relations
8.5 Equivalence Relations
Equivalence Relations
De…nition
An equivalence relation (e.r.) on a set A is simply any binary
relation on A that is re‡exive, symmetric, and transitive.
Examples of E.R.’s
Examples
Examples of E.R.’s
Examples
Examples of E.R.’s
Examples
Examples of E.R.’s
Examples
Equivalence Classes
De…nition
Let R be any equivalence relation on a set A. The equivalence
class of a is
Partitions
De…nition
A partition of a set A is the set of all the equivalence classes
fA1 , A2 , . . . g for some e.r. on A.
Example
Let m 2 Z+ . For any a, b 2 Z, we de…ne aRb i¤ m j a b. Then,
R is an e.r., and f[0] , [1] , , [m 1]g is a partition of Z for R.
Partial Orderings
De…nition
A relation R on a set S is called a partial ordering or partial order
if it is re‡exive, antisymmetric, and transitive. A set S together
with a partial ordering R is called a partially ordered set, or poset,
and is denoted by (S, R ).
Total Orderings
De…nition
If (S, 4) is a poset and every two elements of S are comparable, S
is called a totally ordered set or linearly ordered set, and 4 is called
a total order or a linear order. A totally ordered set is also called a
chain.
E.g., (N, ).
Discrete Mathematics
Chapter 8 Relations
8.6 Partial Orderings
Lexicographic Order
Hasse Diagrams
P
P
P
P
P
P P
Discrete Mathematics
Chapter 8 Relations
8.6 Partial Orderings
De…nition
a is a maximal (resp., minimal) element in the poset (S, 4) if
there is no b 2 S such that a b (resp., b a).
De…nition
a is the greatest (resp., least) element of the poset (S, 4) if b 4 a
(resp., a 4 b) for all b 2 S.
Lemma
Every …nite nonempty poset (S, 4) has a minimal element.
Discrete Mathematics
Chapter 8 Relations
8.6 Partial Orderings
De…nition
(S, 4) is a well-ordered set if it is a poset such that 4 is a total
ordering and every nonempty subset of S has a least element.
E.g., (Z+ , ) is well-ordered but (R, ) is not.
There is "well-ordered induction".
Discrete Mathematics
Chapter 8 Relations
8.6 Partial Orderings
Lattices
De…nition
A partially ordered set in which every pair of elements has both a
least upper bound and a greatest lower bound is called a lattice.
i h
g f
e d
c b
a
Example
Determine whether the posets (f1, 2, 3, 4, 5g , j) and
(f1, 2, 4, 8, 16g , j) are lattices.
Discrete Mathematics
Chapter 8 Relations
8.6 Partial Orderings
Topological Sorting