Professional Documents
Culture Documents
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
+ 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”.
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?
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?
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)
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
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
Answer:
R -1 given by Is____Of
R1 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
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:
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
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?
* 0 1 1
0 * 0 0
1 0 * 1
1 *
0 1
Exercise:
Which of the following relations are reflexive?
symmetric? transitive?
ab, 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
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:.