You are on page 1of 112

 At the end of the period, you should be

able to:
 Evaluate relations.
 Identify special types of relations.
 Understand equivalence and ordering
relations.
 Recall:
 Relation: a set of ordered pairs
 Domain: the set of x-coordinates
 Range: the set of y-coordinates
 Example:
 Given the relation:
{(2, -6), (1, 4), (2, 4), (0,0), (1, -6), (3, 0)}
 State the domain:
D: {0,1, 2, 3}
 State the range:
R: {-6, 0, 4}
 Relations can be written in several ways:
 ordered pairs,
 table,
 graph, or
 mapping.
 Example:
 Given in ordered x y
pairs, 3 4
 {(3, 4), (7, 2), (0, -1),
(-2, 2), (-5, 0), (3, 3)}
7 2
0 -1
-2 2
 In tabular form, -5 0
3 3
 Mapping.
 Create two ovals with the domain on the
left and the range on the right.
 Elements are not repeated.
 Connect elements of the domain with the
corresponding elements in the range by
drawing an arrow.
 Mapping.
 Given: {(2, -6), (1, 4), (2, 4), (0, 0), (1, -6), (3, 0)}

2
-6
1
4
0
0
3
 Other Examples:
1 Name
 Relational databases.
2 Favorite Soap
3 Favorite Color
4 Occupation

1 Kate Winslet Leonardo DiCaprio


2 Dove Dial
3 Purple Green
4 Movie star Movie star
 Other Examples:
 The table for mod 2 addition:

+ 0 1

0 0 1

1 1 0
 Other Examples:
 pigeon to crumb pairing where pigeons may
share a crumb:
Crumb 1
Pigeon 1 Crumb 2
Pigeon 2 Crumb 3
Pigeon 3 Crumb 4
Crumb 5
 Other Examples:
 The concept of “siblinghood”.

 All of the 4 examples had a common thread:


 They related elements or properties with
each other.
 Relations:
 Represented as Subsets of Cartesian
Products.
 In more rigorous terms, all 4 examples
could be represented as subsets of certain
Cartesian products.

 Question:
 How is this done for examples 1, 2, 3 and 4?
 Relations:
 Represented as Subsets of Cartesian
Products.
1) Database 
{Names}×{Soaps}×{Colors}×{Jobs}
2) mod 2 addition  {0,1}×{0,1}×{0,1}
3) Pigeon-Crumb feeding 
{pigeons}×{crumbs}
4) Siblinghood  {people}×{people}
 Relations:
 Represented as Subsets of Cartesian
Products.

 Question:
 What is the actual subset for mod 2
addition?

 Answer: The subset for mod 2 addition:


 { (0,0,0), (0,1,1), (1,0,1), (1,1,0) }
 Let A and B be sets. A binary relation R is a
subset of A  B
 Example:
 Let A be the students in a CS major
A = {Alice, Bob, Claire, Dan}
 Let B be the courses the department offers
B = {CS101, CS201, CS202}
 We specify relation R = A  B as the set that
lists all students a  A enrolled in class b  B
 R = { (Alice, CS101), (Bob, CS201), (Bob,
CS202), (Dan, CS201), (Dan, CS202) }
 Another relation example:
 Let A be the cities in the Phil
 Let B be the provinces in the Phil
 We define R to mean a is a city in province b
 Thus, the following are in our relation:
(Sta. Rosa, Laguna)
(Lipa, Batangas)
(Calapan, Mindoro)
(Naga, Cebu)
Etc…
 We can represent relations in a table:

CS101 CS201 CS202

Alice X
Bob X X
Claire

Dan X X
 We can represent relations graphically:

Alice
CS101
Bob
CS201
Claire
CS202
Dan
 Relations on a set :
 A relation on the set A is a relation from
A to A
In other words, the domain and co-
domain are the same set.
We will generally be studying relations
of this type.
 Example:
Let A be the set { 1, 2, 3, 4 }
Which ordered pairs are in the relation
R = { (a, b) | a divides b }.

 Answer:
R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,4),
(3,3), (4,4) }
 Answer:
R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,4),
(3,3), (4,4) }

1 1 R 1 2 3 4
1 X X X X
2 2
2 X X
3 3 3 X
4 X
4 4
 Consider some relations on the set Z
 Are the following ordered pairs in the relation?

(1,1) (1,2) (2,1) (1,-1) (2,2)


 R1 = { (a,b) | a ≤ b } X X X
 R2 = { (a,b) | a >b } X X
 R3 = { (a,b) | a =|b| } X X X
 R4 = { (a,b) | a =b } X X
 R5 = { (a,b) | a =b+1 } X
 R6 = { (a,b) | a +b ≤3 } X X X X
 DEF: A relation on the set A is a subset
of A × A.

 Question:
Which of examples 1, 2, 3, 4 was a
relation on A for some A ?
(Celebrity Database, mod 2 addition,
Pigeon-Crumb feeding, Siblinghood)

 An: Siblinghood. A = {people}


 DEF: Let A1, A2, … , An be sets. An n-ary
relation on these sets (in this order) is a
subset of A1×A2× … ×An.
 Most of the time we consider n = 2 in
which case have a binary relation and also
say the relation is “from A1 to A2”.

 Q: How many n-ary relations are there on


A1, A2, … , An ?
 A: Just the number of subsets of
A1×A2× … ×An or 2|A1|·|A2|· … ·|An|
 Relations as Subsets: , , , -,
 Because relations are just subsets, all the
usual set theoretic operations are
defined between relations which belong
to the same Cartesian product.
 Example:
 Suppose we have relations on {1,2} given
by R = {(1,1), (2,2)}, S = {(1,1),(1,2)}.
 Find:
1. The union R S
2. The intersection R  S
3. The symmetric difference R S
4. The difference R-S
5. The complement R
 Example:
 Suppose we have relations on {1,2} given
by R = {(1,1), (2,2)}, S = {(1,1),(1,2)}.

 Answer:
1. R S = {(1,1),(1,2),(2,2)}
2. R S = {(1,1)}
3. R S = {(1,2),(2,2)}.
4. R-S = {(2,2)}.
5. R = {(1,2),(2,1)}
 Relations as Bit-Valued Functions
 In general subsets can be thought of as functions
from their universe into {0,1}. The function outputs 1
for elements in the set and 0 for elements not in the
set.
 This works for relations also. In general, a relation R
on A1×A2× … ×An is also a bit function R (a1,a2, … ,an) =
1 iff (a1,a2, … ,an)  R.
Q: Suppose that R = “mod 2 addition”
1) What is R (0,1,0) ?
2) What is R (1,1,0) ?
3) What is R (1,1,1) ?
Relations as Bit-Valued Functions
 A: R = “mod 2 addition”
1) R (0,1,0) = 0
2) R (1,1,0) = 1
3) R (1,1,1) = 0
 Representing Binary Relations
-Boolean Matrices
 Can represent binary relations using Boolean
matrices, i.e. 2 dimensional tables consisting
of 0’s and 1’s.
 For a relation R from A to B define matrix
MR by:
 Value at i th row and j th column is
1 if i th element of A is related to j th
element of B
0 otherwise
 Boolean Matrices
Crumb 1
Pigeon 1 Crumb 2
Pigeon 2 Crumb 3
Pigeon 3 Crumb 4
Crumb 5
0 0 0 1 1
A:  
1 0 0 1 0
 0 0 0 0 0
 
Operations on Binary
Relations
 Inverting Relations:
 Let R be a binary relation. The inverse of R,
denoted by R-1 , is
 y, x   x, y  R
 Example:
 If
R  0,1, 1,2, 2,3, 3,4

 then

R 1  1,0, 2,1, 3,2, 4,3


 Inverting Relations:
 Relational inversion amounts to just
reversing all the tuples of a binary relation.

 DEF: If R is a relation from A to B, the


inverse of R is the relation R -1 from B to A
defined by setting bR -1a if and only aRb.
 Example:
 Suppose R defined on N by xRy iff y = x 2.
What is the inverse R -1 ?

 Answer:
 R is the square function so R -1 is square
root:
 xR -1y iff y = ±x where x is non-negative
 Example:
The relation R given by IsParentOf
R  Re d , Ally , Dolly, Isaac, Carl , Ella 

What is the inverse R -1 ?

 Answer:
R -1 given by Is____Of
R1   Ally, Re d ,  Isaac , Dolly,  Ella, Carl 
 Composing Relations:
 Just as functions may be composed, so can
binary relations:
 DEF: If R is a relation from A to B, and S is
a relation from B to C then the composite of
R and S is the relation S R (or just SR )
from A to C defined by setting a (S R )c if
and only if there is some b such that aRb and
bSc.
 Composition:
 If
R  0,0, 1,2, 2,4, 3,6, 4,8

 S  0,0, 1,1, 2,4, 3,9, 4,16


 then

SR  0,0, 1,4, 2,16


 Example:
 Suppose R defined on N by:
 xRy iff y = x 2
 and S defined on N by:
 xSy iff y = x 3
 What is the composite SR ?
 Composing Relations:
 xRy iff y = x 2 xSy iff y = x 3

 A: These are functions (squaring and


cubing) so the composite SR is just the
function composition (raising to the 6th
power). xSRy iff y = x 6 (in this odd case
RS = SR )
 Example:
Family Tree
Composing Relations
Q: Compose the following:
1 1 1
2 2 2
3 3 3
4 4
5
A: Draw all possible shortcuts. In our case,
all shortcuts went through 1:
1 1
2 2
3 3
4
1 1 1
2 2 2
3 3 3
4 4
5
A: Draw all possible shortcuts. In our case,
all shortcuts went through 1:
1 1
2 2
3 3
4
1 1 1
2 2 2
3 3 3
4 4
5
A: Draw all possible shortcuts. In our case,
all shortcuts went through 1:
1 1
2 2
3 3
4
1 1 1
2 2 2
3 3 3
4 4
5
A: Draw all possible shortcuts. In our case,
all shortcuts went through 1:
1 1
2 2
3 3
4
1 1 1
2 2 2
3 3 3
4 4
5
A: Draw all possible shortcuts. In our case,
all shortcuts went through 1:
1 1
2 2
3 3
4
 Exponentiation:
 A relation R on A can be composed with itself, so
can exponentiate:
R 
n
R 
R 
 R

n times

 Q: Find R 3 if R is given by:


 1 1
 2 2
 3 3
 4 4
Exponentiation
A: R R
1 1 1
2 2 2
3 3 3
4 4 4
Exponentiation
A: R R R2
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
Exponentiation
A: R R R2
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
R2 R
1 1 1
2 2 2
3 3 3
4 4 4
Exponentiation
A: R R R2
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
R2 R R3
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
 Digraph Representation:
 The last way of representing a relation R on
a set A is with a digraph which stands for
“directed graph”. The set A is represented
by nodes (or vertices) and whenever aRb
occurs, a directed edge (or arrow) ab is
created. Self pointing edges (or loops) are
used to represent aRa.
 Q: Represent previous page’s R 3 by a
digraph.
Digraph Representation
R3
1 1
2 2
3 3
4 4
Digraph Representation
R3
1 1
2 2
3 3
4 4 2
A:
1 3

4
 Database Operations;
 Many more operations are useful for
databases. We’ll study 2 of these:
 Join: a generalization of intersection as
well as Cartesian product.
 Projection: restricting to less
coordinates.
Join
 The join of two relations R, S is the
combination of the relations with respect to
the last few types of R and the first few
types of S (assuming these types are the
same). The result is a relation with the
special types of S the common types of S
and R and the special types of R.
 Example:
 Suppose R is mod 2 addition and S is mod 2
multiplication:
 R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) }
 S = { (0,0,0), (0,1,0), (1,0,0), (1,1,1) }
 In the 2-join we look at the last two
coordinates of R and the first two
coordinates of S. When these are the same
we join the coordinates together and keep
the information from R and S
(0,1,1)
2-join (0,1,1,1)
(1,1,1)
Join
 R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) }
 S = { (0,0,0), (0,1,0), (1,0,0), (1,1,1) }
 We use the notation J2(R,S) for the 2-join.
 J2(R,S) =
 { (0,0,0,0), (0,1,1,1), (1,0,1,0), (1,1,0,0) }
Projection
 Projection is a “forgetful” operation. You
simply forget certain unmentioned
coordinates. EG, consider R again:
 R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) }
 By projecting on to the 1st and 3rd
coordinates, we simply forget the 2nd
coordinate. we generate an element of the
1,3 projection as follows:
(0,1,1) 1,3 projection (0,1)
Projection
 R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) }
 We use the notation P1,3(R) for 1,3
projection.
 P1,3(R) = { (0,0), (0,1), (1,1),(1,0) }
Exercises
 1. Define the relation R by setting
 R(a,b,c) = “ab = c“
 with a,b,c non-negative integers.
Describe in English what P1,3 (R )
represents.
 2. Define composition in terms of
projection and join.
 Composition:
 If R is defined by IsMotherOf
S is defined by IsFatherOf

 then

SR is defined by IsGrandfatherOf
Six properties of relations:
Reflexive
Irreflexive
Symmetric
Asymmetric
Antisymmetric
Transitive
 Special properties for relation on a set A:
 reflexive : every element is self-related.
I.e. aRa for all a A
 symmetric : order is irrelevant. I.e. for all
a,b A aRb iff bRa
 transitive : when a is related to b and b is
related to c, it follows that a is related to c.
I.e. for all a,b,c A aRb and bRc implies aRc
 Let R be a relation on a set A.
 R is reflexive if
x  A, (x, x)  R.
 R is symmetric if
x, y  A, (x, y)  R  (y, x)  R.
 R is transitive if
x, y, z  A,
 (x, y)  R and (y, z)  R  (x, z)  R.
 Example:
Reflexive:
The relation R on {1,2,3} given by
R = {(1,1), (2,2), (2,3), (3,3)}
is reflexive.
(All loops are present.)
 Example:
 Symmetric:
 The relation R on {1,2,3} given by
R = {(1,1), (1,2), (2,1), (1,3), (3,1)}
 is symmetric.
 (All paths are 2-way.)
 Example:
 Transitive:
 The relation R on {1,2,3} given by
R = {(1,1), (1,2), (2,1), (2,2), (2,3), (1,3)}
 is transitive.
 (If I can get from one point to another in 2
steps, then I can get there in 1 step.):
 Example:

 Why is R = {(1,1), (2,2), (3,3)} not reflexive on


{1,2,3,4}?
 Because (4,4) is missing.

 Why is R = {(1,2), (2,1), (3,1)} not symmetric?


 Because (1,3) is missing.
 Example:

 Why is R = {(1,2), (2,3), (1,3), (2,1)} not


transitive?
 Because (1,1) and (2,2) are missing.

 Is {(1,1), (2,2), (3,3)} symmetric? transitive?


 Yes! Yes!
 Example:
Which of these properties hold for:
1) “Siblinghood” 2) “<” 3) “”

 Answer:
 1) “Siblinghood”: not reflexive (I’m not
my brother), is symmetric, is transitive.
 2) “<”: not reflexive, not symmetric, is
transitive
 3) “”: is reflexive, not symmetric, is
transitive
 An equivalence relation is a relation on A
which is reflexive, symmetric and transitive.

 Example:
 1. For any set X, the equality relation (=) is
an equivalence relation.
 2. The relation SAMESUIT is an equivalence
relation.
 Reflexivity:
 A relation is reflexive if every element is
related to itself
(a, a)R
 Examples of reflexive relations:
 =, ≤, ≥
 Examples of relations that are not
reflexive:
 <, >
 Irreflexivity
 A relation is irreflexive if every element
is not related to itself ,
(a,a)R
Irreflexivity is the opposite of
reflexivity
 Examples of irreflexive relations:
 <, >
 Symmetry
 A relation is symmetric if, for every
(a,b)R, then (b,a)R

 Examples of symmetric relations:


=, isTwinOf()

 Examples of relations that are not


symmetric:
<, >, ≤, ≥
 Asymmetry
 A relation is asymmetric if, for every
(a,b)R, then (b,a)R
Asymmetry is the opposite of
symmetry
 Examples of asymmetric relations:
 <, >
 Examples of relations that are not
asymmetric:
=, isTwinOf(), ≤, ≥
 Antisymmetry
 A relation is antisymmetric if, for every
(a,b)R, then (b,a)R is true only when a=b
Antisymmetry is not the opposite of
symmetry
 Examples of antisymmetric relations:
=, ≤, ≥
 Examples of relations that are not
antisymmetric:
<, >, isTwinOf()
 Antisymmetry
 Example:
 R = {(1,1), (1,2), (3,2), (3,3)} is
antisymmetric.

 Is every relation symmetric or anti-


symmetric?
 No! Consider R = {(1,2), (2,1), (1,3)}.
 Notes on *symmetric relations:
 A relation can be neither symmetric or
asymmetric
R = { (a,b) | a=|b| }
This is not symmetric
-4 is not related to itself
This is not asymmetric
4 is related to itself
Note that it is antisymmetric
 Transitivity
 A relation is transitive if, for every (a,b)R
and (b,c)R, then (a,c)R

 If a < b and b < c, then a < c


Thus, < is transitive

 If a = b and b = c, then a = c
Thus, = is transitive
 Transitivity examples:
 Consider isAncestorOf()
Let Alice be Bob’s parent, and Bob be
Claire’s parent
Thus, Alice is an ancestor of Bob, and Bob
is an ancestor of Claire
Thus, Alice is an ancestor of Claire
Thus, isAncestorOf() is a transitive
relation
 Transitivity examples:
 Consider isParentOf()
Let Alice be Bob’s parent, and Bob be
Claire’s parent
Thus, Alice is a parent of Bob, and Bob is
a parent of Claire
However, Alice is not a parent of Claire
Thus, isParentOf() is not a transitive
relation
 Relations summary
= < > ≤ ≥

Reflexive X X X

Irreflexive X X

Symmetric X

Asymmetric X X

Antisymmetric X X X

Transitive X X X X X
 Visualizing the Properties:
 For relations R on a set A.
Q: What does MR look like when R is
reflexive?

A: Reflexive. Upper-Left corner to


Lower-Right corner diagonal is all 1’s.
 1 * * *
 
 * 1 * *
 * * 1 *
 
 * * * 1
 
 Visualizing the Properties:
 For relations R on a set A.
Q: How about if R is symmetric?

A: A symmetric matrix. I.e., flipping


across diagonal does not change matrix..

* 0 1 1
 
0 * 0 0
1 0 * 1
 
1 * 
 0 1
 Exercise:
 Which of the following relations are reflexive?
symmetric? transitive?
 ab, on Z.
 A  B, on (U).
 p  q, on a set of statements.
 a  b (mod 10), on Z.
 gcd(a, b) > 1, on Z.
 p  q = p, on a set of statements.
 R  R, on R.
 Partitions:
 Let X be a nonempty set. A partition of
X is a set Y of nonempty subsets of X
such that every element of X is in
exactly one element in Y.
 Example:
 Let X be the set of cards in an ordinary
deck.
 Y = { hearts, diamond, spades, clubs}
is a partition of X.
 Partitions: Theorem
 Let X be a set, and Y be a set of subsets
of X. Then, Y is a partition of X if and
only if:
Each element of Y is a nonempty
subset of X,
Any two distinct two sets u, v in Y are
disjoint.
The union of all the elements of Y is X.
 Partitions: Theorem
 Let ˜ be an equivalence relation on a set
X. For any x є X , let

x  y  X x  y

 is called the equivalence class of x.


 Example:
 The equivalence relation samesuit:
 The equivalence classes
clubs
spades
diamonds
hearts
 Example:
 The equivalence relation MOD5:
 The equivalence classes
0  0,5,10,15,...
1  1,6,11,16,...
2  2,7,12,17,...
3  3,8,13,18,...
4  4,9,14,19,...
 Ordering Relations:
 A binary relation R on a nonempty set X is
a partial ordering if R is a reflexive,
transitive, antisymmetric relation.

 Example 1:
 If U = {0, 1, 2}, then the subset relation is
a partial ordering on the power set of U.
 Example 1:
 If U = {0, 1, 2}, then the subset relation is
a partial ordering on the power set of U.
 Representation of the partial ordering
 Example 2:
 If U = {0, 1, 2,3}, then the odd subsets
relation is given by
 Example 3:
 Divides for U = {0,1,2,3, . . ., 12}.
 Linear Orderings:
 Let R be a binary relation on a set X.
 R is a linear ordering, or total ordering,
on X if R is a transitive relation that
satisfies the law of trichotomy:
 For every x, y in X, exactly one of the
followingconditions holds:
(i)xRy,
(ii)x=y,
(iii)yRx.
 Example:
 < is a linear ordering on the set of real
numbers.
 The name linear ordering suggests points
on a line, and lR is the standard
mathematical model of a line.
 Condition (ii) is never true for this
relation.
 < is a linear ordering on the set of
natural numbers.
 Application: Lexicographic or Dictionary
Ordering:
 The alphabetical (dictionary) ordering of
words is the basis for being able to sort
sets of words in increasing or decreasing
order.
 Example:
 Let English be the set of words in the
latest edition of the Oxford English
Dictionary, and let < be their alphabetical
ordering, in which the letters of the
alphabet are ordered from a to z, with
blank being less than a.
elephant < tiger
aardvark < ant
oz < ozymandias
 Application: Extended ASCII Code
 The complete extended ASCII code
assigns 8-bit binary strings to each letter
of the alphabet so that “A” < “B” < “C” < …
< “X” < “Y” < “Z”
 For example,
“A” = 01000001
“B” = 01000010
We see that 01000001 < 01000010 so
that “A” < “B” .
 Exercise:
 The relation > on A = { 1, 2, 3, 4 } is a
linear ordering. Verify. Draw the diagram
representation of the relation on A.
 Let P be the set of presidents of the
Philippines. Define R such that xRy if x
ruled before y. Is R a linear ordering on P?
 Comparable Elements:
 Let R be a partial or linear ordering on a set
X. Elements x, y in X are said to be
comparable under R if xRy or yRx holds.
 Example:
 For X = { 0, 1, 2, 3} partially ordered by the
relation set inclusion on P(X), then, {0, 1} and
{0, 1, 2} are comparable, but {0, 2, 3} and {0,
1} are not.
 Optimal Elements:
 Let R be a partial ordering or a linear
ordering on a set X.
 For elements x, y in X, if xRy and x≠y, then
x is below y.
 We say x is above y if y is below x.
 Example:
 Let X = {1,2,3,4}.
 P(X) together with set-inclusion is a partial
order.
{1} is below {1,2}.
{1,2} is below {1,2,3,4}.
{2,3} is above both {2} and {3}.
{1,2,3,4} is above each element of P(X)
distinct from itself.
 Optimal Elements:
 Let R be a partial or a linear ordering on a set X. Let
x be an element of X.
 x is a minimal element of X if there is no y in X
such that y is below x.
 x is the minimum element of X if x is below every
other element of X.
 x is a maximal element of X if there is no y in X
such that y is above x.
 x is the maximum element of X if x is above
every other element of X.
 Optimal Elements:
 A is the maximum element.
 Optimal Elements:
 A is the minimum element.
 Example:
 Find a minimal element of X = {5, 3, 4, 1, 2}
in the partial order shown:.

You might also like