COMP11120 5 Relations

COMP11120
5 Relations
5.1
Introduction
The idea of a relation is one of the most fundamental concepts in mathematics. It provides a
mechanism for describing connections between objects which has applications across Mathematics and Computer Science.
Recall that the Cartesian product A × B of two sets A and B is defined to be the set of pairs
(a, b) where a ∈ A and b ∈ B. That is
A × B = {(a, b) | a ∈ A , b ∈ B}
Definition 5.1.1 A relation from A to B is a subset R of A × B. A is the domain of R and B is
the target (or codomain) of R. When A = B we say R is a relation on A.
For a ∈ A and b ∈ B we will write a R b to mean that (a, b) ∈ R. Intuitively we may regard
a R b as stating that a is related to b in a way which is specified by R.
5.1.1
Examples
1. Let S be the set of undergraduate students in this university and C be the set of courses
offered. Let T be the relation defined by the set {(s, c) | Student s takes course c}. Note
that if we fix a student s, then {c ∈ C | (s, c) ∈ T } is the set of courses taken by s, and if
we fix a course c, the set {s ∈ S | (s, c) ∈ T } is the set of students taking course c.
If D is the set of departments in the University we could define a relation P on C × D by
(c, d) ∈ P if course c is taught by staff from department d.
2. Let A = B = Z, let R be the set of pairs (a, b) such that a − b is even. So, for numbers a
and b, a R b if and only if a − b is even. For a given n ∈ Z when is 2 R n? The answer is
whenever 2 − n is even, which is precisely when n is even. If a R b and b R c is it true that
a R c? The answer is yes. If a − b is even and b − c is even, then (a − b) + (b − c) is also
even. Also for any number a, a R a since a − a = 0 is even.
3. Let P = P(A) be the power set of the set A. Recall that P(A) is defined to be the set
{S | S ⊆ A}, that is the set of all subsets of A. For example P({1, 2, 3}) is the set
/ {1}, {2}, {3}, {2, 3}, {1, 3}, {1, 2}, {1, 2, 3}}
{0,
Let R = {(X,Y ) ∈ P × P | X ⊆ Y }. That is R is a relation on P , and for X,Y ∈ P , X RY
if and only if X ⊆ Y . Two elements X and Y of P are related by R if X is a subset of Y .
For any subset X of A note that X R X since X ⊆ X. Also 0/ R X, and X R A, recall that A ⊆
A, so A ∈ P . For this relation it is true that if X,Y ∈ P then (X ∩Y ) R X and (X ∩Y ) RY .
Also X R (X ∪ Y ) and Y R (X ∪ Y ). That means for this relation, given X and Y there is
49
Relations
always some U such that U R X and U RY and there is always some V such that X RV
and Y RV .
4. Let P be some computer program. Let F(P) be the set of functions defined in P. We can
define a relation C on F(P) by f1 C f2 iff the function f1 is called in the definition of f2 .
5. Let f : A
> B be a function from the set A to the set B. This defines a relation
R ⊆ A × B given by
R = {(a, b) ∈ A × B | f (a) = b}
For a ∈ A and b ∈ B, a R b if an only if f (a) = b. For example, take f to be the function
from the real numbers to the real numbers which is the squaring function f (x) = x2 . One
can think of R as the usual graph of f as shown in the picture below.
The points which are plotted on the xy-plane are those points (x, y) ∈ R. This makes sense
because the graph y = x2 is exactly those points (x, y) where y = x2 , and this is just the
set R = {(x, y) | f (x) = y}.
In fact any function can be thought of a special kind of relation. A function from S to T
is a relation R from S to T with the property that
for each s ∈ S there is exactly one t ∈ T with (s,t) ∈ R
6. It is sometimes convenient to draw pictures of relations. The diagram below represents a
relation R amongst the names N shown in the picture. Name a and b are related by R if
and only if there is an arrow going from a to b.
Such a diagram is called a directed graph or digraph.
.
.
.
.
Boaz
Obed
Jesse
.
Eliab
.
Absolom
David
.
Amnon
.
Tamar
50
.
Abinadab
.
Solomon
COMP11120: 5
This particular relation is interpreted by a R b if and only if a is the father of b. So that
the digraph becomes a (partial) family tree. Thus David R Tamar and David R Solomon.
The fact that Amnon and Solomon are brothers is not recorded by this relation directly.
It can be deduced since there exists a third name X for which X R Solomon, and X R
Amnon.
We can use this to define a new relation ‘is brother of’. Let R1 be a relation defined by A
R1 B if and only if there is a name X such that X R A and X R B. In terms of the family
tree A R1 B if and only if they have the same father. Clearly A R1 B if and only if A and
B are brothers. Strictly speaking R1 has not yet been properly defined. In order for it to
qualify as a relation it must be specified as a subset of N × N, where N is the set of names
in the digraph above. Here is a formal definition of R1 .
R1 = {(a, b) | there exists an X ∈ N : X R a and X R b}
How could one define uncle in terms of this family tree? Your uncle is your father’s
brother in the above tree. Name U is the uncle of A if there is a name X which is the
brother of U and the father of A. So U is uncle to A if there exists X such that U R1 X
and X R A. We can define the uncle relation R2 as follows
R2 = {(a, b) | there exists an X ∈ N : aR1 X and X R b}
Thus aR2 b iff (a, b) ∈ R2 iff a is the uncle of b.
A directed graph (or digraph) consists of a set of nodes (or vertices) and edges between
them. Each edge in the graph has an initial node and a terminal node. In the above example
the nodes are names and the edges represent the relation ‘is father of’. The initial node of an
edge is the father and the terminal node the son.
n2
n3
n1
n4
n5
Since a digraph consists of a set of nodes and a set of edges we can define it as a pair G = (V, E)
where E ⊆ V × V . The set of edges E is itself a relation on the vertices V since it is a subset
of V × V . If we are given a relation R ⊆ A × A for some set A then this defines a digraph
G = (A, R).
5.1.2
More Examples
1. Let T be the set of towns and cities in the UK. We can define a relation R on T by
(t1 ,t2 ) ∈ R if and only if there is a direct train connection from t1 to t2 . Part of the
digraph for this relation is shown below.
51
Relations
Bolton
Wigan
Leeds
Liverpool
Manchester
Crewe
2. The following digraph represents the relation ⊂ on the power set of the set {1, 2, 3}, it is
/
given only in pictorial form. The bottom node {} is the empty set 0.
{1,2,3}
{1,2}
{1}
{1,3}
{2,3}
{2}
{3}
{}
In this picture there is an arrow from A to B if and only if A ⊂ B. Note that ⊂ is not the
same as ⊆, A ⊂ B if A and B are different and A is contained in B. This digraph represents
the relation
R = {(A, B) ∈ P({1, 2, 3}) × P({1, 2, 3}) | A ⊂ B}.
3. Let N5 be the set {1, 2, 3, 4, 5}. Define a relation R on N5 by (m, n) ∈ R if and only if
m − n is even. Then the digraph for R is
1
3
5
2
4
This relation has some interesting properties
(R) (n, n) ∈ R for all n ∈ N5
(S) Whenever (m, n) ∈ R then so is (n, m)
(T) Whenever (m, n) ∈ R and (n, p) ∈ R then so is (m, p)
52
COMP11120: 5
In terms of the digraph these properties can be interpreted
(R) There is always an arrow from any node to itself
(S) Whenever there is an arrow from m to n then there is also one from n to m
(T) Whenever we can get from m to p via a third node n, we can also get there directly.
Relations satisfying “R” are called reflexive, those satisfying “S” are called symmetric
and those satisfying “T” are called transitive.
4. If S is any set then there is a relation E = {(x, x)|x ∈ S}. So two elements are related by
this relation if and only if they are equal. We normally denote this relation by the symbol
=.
Note that this relation is also reflexive, symmetric and transitive.
5. Let N4 be the set {1, 2, 3, 4}. On N4 we have the normal inequality relation ≤ which can
be viewed as a subset of N4 × N4 , namely the set {(x, y) | x ≤ y}. This has digraph
1
2
3
4
This relation is reflexive and transitive, but not symmetric. In fact, if we know that both
x ≤ y and y ≤ x, then it must be the case that x = y. A relation satisfying this property is
called anti-symmetric. All order-like relations have this property.
5.1.3
Properties of Relations
To summarize the properties introduced above, we have
Definition 5.1.2 Let R ⊆ A × A be a relation.
• R is reflexive if for all a ∈ A a R a
• R is symmetric if for all a, b ∈ A a R b ⇒ b R a
• R is antisymmetric if for all a, b ∈ A (a R b and b R a) ⇒ a = b.
• R is transitive if for all a, b, c ∈ A (a R b and b R c) ⇒ a R c.
In terms of the digraph representation of a relation we have
• R is reflexive if every node of G has a loop attached to it
• R is symmetric if whenever there is an arrow from a to b there is also an arrow from b to
a.
• R is antisymmetric if the only case where one can have an arrow from a to b and from b
to a is when a = b.
53
Relations
• R is transitive if whenever there is an arrow from a to b and an arrow from b to c then
there is an arrow from a to c.
So whenever this picture occurs in G
a
b
c
Then in fact it can be filled out to this picture occurring in G
a
b
c
What kind of a relation can be symmetric and antisymmetric?
Notice that for a transitive relation R if there is a sequence a1 Ra2 , a2 R a3 , . . . an−1 R an , then
a1 R a n .
5.1.4
Examples
1. Consider again the relation R on Z where a R b ⇔ a − b is even. As was pointed out
earlier a R a is always true for a ∈ Z, so R is reflexive. If a − b is even so is b − a, thus R
is symmetric. Also if a − b and b − c are even, then so is a − c (= (a − b) + (b − c)), so
R is transitive.
2. Now consider the relation ⊆, that is the relation R such that U RV iff U ⊆ V . More
precisely, let A be a set and P = P(A) be the power set of A, define R = {(X,Y ) ∈ P × P |
X ⊆ Y }.
Since U ⊆ U is always true, U RU and R is reflexive. Consider if U RV and V RU, that
is U ⊆ V and V ⊆ U. In that case U = V . Thus R is antisymmetric. If U RV and V RW
then clearly U RW so R is transitive.
3. For a third example return to the family tree given earlier. The relation R given by the tree
represented fatherhood. Also defined there were the relations R1 and R2 , both constructed
from R. R1 represented brother of, and R2 represented uncle of.
R is not reflexive, whereas R1 is, but R2 is not. R is not symmetric, R1 is and R2 is not. R
is not transitive, R1 is and R2 is not. This is interesting because R1 is defined in terms of
R, and R2 is defined in terms of R and R1 yet these relations have different properties.
4. Consider the relation R given by < on N. For any n ∈ N, n 6< n so R is not reflexive. R is
not symmetric, but it is antisymmetric. To be antisymmetric means that if a R b and b R a
then a = b. There are no numbers a and b such that a R b and b R a, so the condition is
true by default. R is also transitive.
5. Next suppose R is given by ≤ on N. In this case R is reflexive and antisymmetric and
transitive.
6. As a final example let f : A ↔ A be a function. This defines a relation R = {(a, b) ∈
A × A | f (a) = b}. If R were reflexive that would mean f (a) = a for each a ∈ A, i.e f
would be the identity function. For R to be symmetric means f (a) = b ⇒ f (b) = a, (An
example of such a function is the f (x) = 1/x.)
54
COMP11120: 5
Suppose R is transitive. Therefore if f (a) = b and f (b) = c then f (a) = c also. Thus
b = f (a) = c, moreover f (b) = c = b. Thus for any b ∈ A if there is some a ∈ A such that
f (a) = b, then f (b) = b. In other words for every a ∈ A, f ( f (a)) = f (a). (An example
of such a function is f (x) = |x|.)
Exercises
5.1 List all the pairs in in the relation on the set {1, 2, 3, 4, 5, 6} defined by {(a, b)|a is a factor of b}.
Draw the digraph for this relation.
5.2 For each of the following relations on the set {1, 2, 3, 4}, decide whether it is reflexive,
whether it is symmetric, whether it is antisymmetric, and whether it is transitive. Draw a
digraph for each relation.
a)
b)
c)
d)
e)
f)
{(2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (3, 4)}
{(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}
{(2, 4), (4, 2)}
{(1, 2), (2, 3), (3, 4)}
{(1, 1), (2, 2), (3, 3), (4, 4)}
{(1, 3), (1, 4), (2, 3), (2, 4), (3, 1), (3, 4)}
5.3 Determine whether each relation R on the set of all people, is reflexive, symmetric, antisymmetric and/or transitive, where (a, b) ∈ R if and only if
a)
b)
c)
d)
a is taller than b.
a and b were born on the same day.
a has the same first name as b.
a and b have a common grandparent.
5.4 A relation on a finite set can be described in a table, similar to a multiplication table, in
which edges can be indicated by ticks and crosses. By considering the number of ways of
filling such a table, show that there are 29 different relations on a set of 3 elements. How many
of these relations are
a) reflexive.
b) symmetric.
c) both symmetric and reflexive.
5.2
Equivalence Relations
Very often elements of a set are regarded as equivalent or the same because they have some
set of properties in common. For example two electrical components might be regarded as
equivalent, even if they are produced by different manufacturers. Two different Java functions
might be regarded as equivalent if they always produced the same results, even if they were
implemented in completely different ways. What makes them ‘equivalent’ in both cases is the
behaviour.
From an abstract point of view equivalence is determined by a relation which is reflexive,
symmetric and transitive. It seems obvious that any notion of equivalence should satisfy the
following:
55
Relations
1. a is equivalent to a
2. If a is equivalent to b then b is equivalent to a
3. If a is equivalent to b and b is equivalent to c then a is equivalent to c
Definition 5.2.1 An equivalence relation on A is a relation R ⊆ A × A which is reflexive, symmetric and transitive.
For any set A there will be many possible equivalence relations.
5.2.1
Examples
1. Let A be any set and R = {(a, b) ∈ A × A | a = b}, i.e. a R b iff a = b. This R is an
equivalence relation.
2. Let R = {(a, b) ∈ N × N | a − b is even}. This relation was discussed earlier and shown
to be reflexive, symmetric and transitive, hence an equivalence relation.
3. For a, b and n ∈ Z define a ≡ b (mod n) if a−b is divisible by n. If a ≡ b (mod n) then
there is some k ∈ Z such that a = b+kn. This defines a relation R = {(a, b) ∈ Z×Z | a ≡ b
(mod n)}.
• R is reflexive since a ≡ a
(mod n)
• R is symmetric since a ≡ b
(mod n) ⇒ b ≡ a
• R is transitive since (a ≡ b
(mod n) and b ≡ c (mod n)) ⇒ a ≡ c (mod n)
(mod n)
R is an equivalence relation.
4. Define a relation R on the power set P(A) of some finite set A, by X RY iff X has the
same number of elements as Y . Why is R an equivalence relation?
5.2.2
Equivalence Classes and Partitions
The idea of an equivalence relation R on a set A is that if a R b then in some sense a and b are
the same. We will see that any equivalence relation on a set A divides A in a natural way into
disjoint parts. The idea is that each part contains elements that are equivalent to each other, so
two elements a, b are put into the same part if and only if a R b.
For example let A = N and R = {(a, b) | a ≡ b (mod 2)}. In this case every number will
either be R-equivalent to 0 or to 1. Thus
N = {a | a ≡ 0 (mod 2)} ∪ {a | a ≡ 1
(mod 2)}
So N is divided into two R-equivalence classes.
In general one can always use an equivalence relation to split up a set in this kind of way.
Definition 5.2.2 For an equivalence relation R over A, define the R-equivalence class [a]R to
be the set
{b ∈ A | a R b}
We often write [a] instead of [a]R if R is clear from the context.
56
COMP11120: 5
In the example above with the new notation, N = [0] ∪ [1]. The equivalence classes of a
relation have the following properties
Lemma 5.2.3 For an equivalence relation R over A
1. a ∈ [a]
2. b, c ∈ [a] ⇒ b R c
3. for any a, b ∈ A either [a] = [b] or [a] ∩ [b] = 0/
4. for any a, b ∈ A, [a] = [b] ⇔ a R b
Proof
1. This is true because R is reflexive, so a R a, hence a ∈ [a].
2. If a, b ∈ [a] then b R a and cRa. From symmetry b R a and a R c, hence from transitivity
b R c.
/ Let c ∈ [a] ∩ [b]. Therefore a R c and cRb and
3. Suppose that a, b ∈ A and [a] ∩ [b] 6= 0.
so a R b. Thus for all x ∈ [b], xRb and b R a, so xRa. Thus [b] ⊆ [a]. The same argument
works with a and b interchanged so [a] ⊆ [b]. Hence [a] = [b] which completes the proof.
4. Let a R b, then a ∈ [b], thus b ∈ [a] ∩ [b]. By part 3 then [a] = [b]. If [a] = [b] then a ∈ [b]
and so a R b.
This completes the proof.
For an equivalence relation R over A look at the set PR = {[a] | a ∈ A}. From the above
lemma it follows that each a ∈ A belongs to some element of PR , also distinct elements of PR
/
are disjoint as subsets of A. That is if x, y ∈ PR and x 6= y then x ∩ y = 0.
For example look at R = {(a, b) ∈ N×N | a−b ≡ 0 (mod 3)}. In this case PR = {[0], [1], [2]}.
It is also true that PR = {[1], [2], [3]}. It is also true that PR = {[0], [1], [2], [3]}, since of course
[3] = [0].
Definition 5.2.4 A partition of a set A is a set P of subsets of A such that
A=
[
p
p∈P
/
and for p, q ∈ P if p 6= q then p ∩ q = 0.
A partition is just a way of splitting up A into various disjoint subsets. We have already seen
various partitions. {[1], [2], [3]} is a partition of N for the previous example. Indeed the set of
R-equivalence classes always gives a partition of a set.
Lemma 5.2.5 Let R be an equivalence relation over A. The set A/R = {[a] | a ∈ A} is a partition
of A.
Proof
S
S
From the previous lemma a ∈ [a], thus A ⊆ p∈A/R p. Also because [a] ⊆ A then p∈PR p ⊆ A,
S
/
therefore A = p∈A/R p. Again by the previous lemma if p, q ∈ PR and p 6= q then p ∩ q = 0.
This completes the proof.
57
Relations
[x1]
[x5]
[x2]
[x4]
[x3]
In the above figure, we show a set on which a relation is defined which divides the set into
5 equivalence classes.
Here is an example of an equivalence on pairs of whole numbers. Let N+ be the set of
strictly positive whole numbers. Let
R = { (a, b), (c, d) ∈ (N+ × N+ ) × (N+ × N+ ) | ad = cb}
The idea is to think of (a, b) as the fraction a/b. Then pair (a, b) and (c, d) are to be equivalent
if they are the same fractional number, i.e. a/b = c/d. Thus [(2, 4)] = [(1, 2)] since 1/2 = 2/4
and so on.
With this example we can think of (N+ × N+ )/R as equal to the set of fractions. The set
(N+ × N+ )/R can be identified with the set of fractions a/b where a and b have no common
factors other than 1 (i.e. they are co-prime).
Exercises
5.5 Let A be the set of finite strings made from 0 and 1. Let R be the relation on A given by
a R b iff a and b have the same number of 1’s. Prove that R is an equivalence relation.
5.6 The relation R is defined on N by a R b iff i) a = b = 1 or ii) the smallest prime number
which is a factor of a is the same as the smallest prime number which is a factor of b.
Show that R is an equivalence relation and describe the equivalence classes.
> R. Let 1R ∈ A be the identity function. For
5.7 Let A be the set of functions f : R
f , g ∈ A define f Rg iff f ◦ g = 1R . Is R an equivalence relation? If so why, if not why?
5.8 Now define a relation R2 by f R2 g iff for every x ∈ R, f (x)g(x) = 1. Is R2 reflexive,
symmetric, transitive? Explain your answer.
5.3
Operations on Relations
There are many situations where one relation is constructed from one or more other relations.
Earlier the father of relation was defined in terms of a family tree. The brother of relation can be
defined in terms of father of. In the same example uncle of was defined in terms of father of and
brother of. In this section a notation is defined which provides a way of building new relations
out of old. The notation describes how various operators work such as union, intersection and
complement.
58
COMP11120: 5
Definition 5.3.1 Let R1 and R2 be relations on A, define
1. The union of R1 and R2 :
R1 ∪ R2 = {(a, b) ∈ A × A | (a, b) ∈ R1 or (a, b) ∈ R2 }
2. The intersection of R1 and R2 :
R1 ∩ R2 = {(a, b) ∈ A × A | (a, b) ∈ R1 and (a, b) ∈ R2 }
3. The complement of R1
Rc1 = {(a, b) | (a, b) 6∈ R1 }
4. The inverse of R1
R−1
1 = {(a, b) | (b, a) ∈ R1 }
The first two definitions above are redundant. Formally a relation on A is a subset of A × A,
so the union of R1 and R2 is already defined. The definition of R1 ∪ R2 above is simply the set
union of two subsets R1 and R2 of A × A. The same comment applies to ∩.
5.3.1
Example
Let P be the set of people who have ever lived. There is natural relation on P, ‘is-fatherof’ and ‘is-mother-of’. The union of these two relations is the relation ‘is-parent-of’ and the
intersection is empty!
The inverse of the ‘is-parent-of’ relation is the relation ‘is-child-of’. (a is-a-parent-of b if
and only if b is-a-child-of a).
Exercises
5.9 Let P be a property which can be any one of reflexive, symmetric or transitive. Prove that
if R1 and R2 are relations which both have property P then R1 ∩ R2 has property P. If R is a
relation with property P, do Rc and R−1 also have property P?
5.10 Let R be a relation on A, prove that Rc = A × A − R. What is the relation R ∪ Rc ? What is
the relation R ∩ Rc ?
5.11 Let A = N × N. Think of the set A as a set of grid points in the plane. Let RL be a relation
which determines if one grid point is to the left of another grid point. That is (x1 , y1 )RL (x2 , y2 )
if and only if y1 = y2 and x1 ≤ x2 .
Similarly one can define the relation RR where (x1 , y1 )RR (x2 , y2 ) if and only if y1 = y2 and
x1 ≥ x2 . Relation RR is the ‘right of’ relation.
−1
c
What is the relation R−1
L , (RL ∪ RR ) ? What is the relation (RL ∪ RR ) ? Let RA be the
‘above’ relation given by (x1 , y1 )RA (x2 , y2 ) iff x1 = x2 and y1 ≥ y2 . What are:
−1
−1
c
c
RL ∩ RA , R−1
A , RA ∩ RA , RA ∪ RL ∪ RR , RA ∪ RA .
59
Relations
5.4
Composition and Closure
Consider the relations ‘is-parent-of’ and ‘is-mother-of’ defined above. It is intuitively clear
that we can define a relation ‘is-maternal-grand-parent-of’ by combining these in some way.
To be precise, p is-maternal-grand-parent-of q if we can find some m, such that p is-parent-of
m and m is-mother-of q. This illustrates another way of combining relations
Definition 5.4.1 If R1 is a relation from A to B and R2 is a relation from B to C, we can define
the relational composition of R1 and R2 by
R2 ◦ R1 = {(a, c) ∈ A ×C | there is some b ∈ B such that (a, b) ∈ R1 and (b, c) ∈ R2 }
5.4.1
Examples
1. Let T be the ‘takes’ relation from S to C, where S is the set of undergraduate students in
this university and C is the set of courses offered. Let P be the ‘provides’ relation from
C to D, the set of departments.
The relation P ◦ D defines a relation from S to D which could be described as ‘takes a
course provided by’.
2. Let R be the relation on UK towns ‘has a direct rail connection to’, described above. We
can form the relation R ◦ R (usually denoted by R2 ), which could be described as ’has a
rail connection with one change with’.
> B, g : B
> C be functions and R f and Rg be the relations {(a, f (a) |
3. Let f : A
a ∈ A} and {(b, f (b) | b ∈ B} respectively. Then the relation Rg ◦R f is exactly the relation
Rg◦ f .
4. Consider again the ‘is-parent-of’ example, and call the relation RP . With this one can define the relation RP ◦ RP or R2P , which can be described as ‘is-grandparent-of’. Similarly
the relations R3P , R4P , . . . (is-a-great-grandparent-of etc etc).
If we take the union of all these relations RP ∪ R2P ∪ R3P ∪ R4P ∪ . . ., we have a new relation
‘is-ancestor-of’
The ancestor relation defined above is a transitive relation (if a is-an-ancestor-of b and b
is-an-ancestor-of c then a is-an-ancestor-of c), which the parent relation is not. This relation is
known as the transitive closure of RP . It is the smallest relation which contains RP and which
is transitive. By smallest we mean that if there is another relation S which also contains RP and
which is transitive then RA ⊆ S.
Definition 5.4.2 For a relation R and a property P, the relation S is the P closure of R if
1. S has property P
2. If R0 is another relation with property P and R ⊆ R0 then S ⊆ R0 .
Suppose then that P is the property of transitivity. The P closure of R is known as the
transitive closure of R. When P is reflexivity, the P closure of R is the reflexive closure of R,
and when P is symmetry, then the P closure of R is the symmetric closure.
60
COMP11120: 5
Intuitively the P closure is constructed by adding to R the minimum number of pairs (a, b)
which will make a new relation with property P. It is not clear from the definition that P closure
actually exists. However if we only consider P to be one of reflexive, symmetric or transitive
then the closure can always be constructed.
Definition 5.4.3 For a relation R let R∞ be the set of pairs (a, b) where there are a1 , a2 , . . ., an
such that
a = a1 R a2 R · · · an−1 R an = b
(By this we mean that a = a1 , a1 R a2 , a2 R a3 . . ., an−1 Ran and an = b.)
Lemma 5.4.4 The relation R∞ is the transitive closure of R.
Proof
The proof that R∞ is transitive is left as an exercise. To prove that R∞ is the transitive closure
of R we must prove that if S is a transitive relation and R ⊆ S, then in fact R∞ ⊆ S.
Suppose then that S is transitive and R ⊆ S. Let a R∞ b. That is there is a chain
a = a1 R a2 R · · · an−1 R an = b
Since S contains R this gives the chain
a = a1 Sa2 S · · · an−1 San = b
Relation S is also transitive and therefore aSb. This proves that R∞ ⊆ S, which completes the
proof.
5.4.2
Examples
1. Consider the relation R specified by the following digraph. The relation R is given by the
solid arrows. The dotted arrows are the extra arrows which have to be added to construct
the transitive closure. completion R∞ . The digraph should also have self loops on each
node; these have been omitted to avoid clutter.
a
b
c
d
In the original digraph it is possible to construct a walk between any two vertices. That
means in the completion every pair of vertices is related, thus R∞ is the complete graph
on 5 vertices.
61
Relations
Exercises
5.12 Prove that, for any relation R, the relation R∞ is a transitive relation. That is prove that
if a R∞ b and b R∞ c then a R∞ c.
5.13 Find R∞ for the relations specified by each of the digraphs below.
a
b
b
c
a
d
c
e
d
5.14 Given a relation R, describe how you would construct a relation Rr which is the reflexive
closure of R, and a relation Rs which is the symmetric closure of R.
5.5
Order relations
Equivalence relations are relations that share essential properties of the relation =. Another
commonly used type of relation is the set of relations that share the essential properties of ≤.
Such relations are called order relations.
The simplest sort of order relation is the partial order, which is defined as follows.
Definition 5.5.1 A partial order is a relation R which is reflexive, antisymmetric and transitive.
A set A together with a partial order on A is called a partially ordered set, or poset. The
relation ≤ on Z, makes Z a poset. This particular relation has an additional property not shared
by all partial orders; namely that, for any integers x, y then either x ≤ y or y ≤ x. Another way
of saying this is that any two integers are comparable with ≤.
A partial order relation in which any two elements are comparable is called a total order.
5.5.1
Examples
1. Let P = P(A) the power set of A, and look at the ⊆ relation on P . This relation makes
P into a poset, since ⊆ is reflexive, antisymmetric and transitive. One can think of ⊆ as
providing a way of ordering the sets contained in P .
This partial order relation is not a total order. For example, consider ⊆ on P({1, 2, 3});
the sets {1, 2} and {2, 3} are incomparable, since neither of the statements {1, 2} ⊆ {2, 3}
and {2, 3} ⊆ {1, 2} are true.
2. Suppose we have some production process, which involves a set of tasks T . We can
define a relation D on T , by t1 Dt2 if t1 must be completed before t2 can begin. This
defines an order relation on T but does not qualify as a partial order, since it is not
reflexive. If we expand this relation by adding all pairs (t,t), the relation becomes a
partial order.
3. The divisibility relation on Z+ is a partial order.
62
COMP11120: 5
4. Let P = P(A) be the power set of A, and let Q be any subset of P . Then the relation ⊆
on Q is a partial order.
5. Let a and b be strings (e.g "cat"). Define a ≤s b if by inserting extra letters into a we
can construct b. For example "cat" ≤s "I like cats", and
"blot" ≤s "xbxlxoxtx". Relation ≤s is a partial ordering. This ordering is known as
the insert ordering for strings.
6. Define the prefix ordering ≤ p on strings by a ≤ p b if a is a prefix of b, i.e. by adding
letters to the end of a we can construct b. So, if ∧ denotes string concatenation, then
a ≤ p b if and only if there is some c s.t a∧ c = b. This ordering is partial but not total.
7. Define the postfix ordering ≤o on strings by a ≤o b if a is a postfix of b, i.e. by adding
letters to the front of a we can construct b, i.e. there is some c s.t c∧ a = b. This ordering
is partial but not total.
8. Define the infix ordering ≤i on strings by a ≤i b if a is an infix of b, i.e. by adding letters
to the front and the end of a we can construct b, i.e. there are some c, c0 s.t c∧ a∧ c0 = b.
This ordering is partial but not total.
9. Let A be a poset with partial ordering R. Let L be the set of A lists (lists made from
elements in A). Let ≺ denote the lexicographic partial order defined by
l1 ≺ l2 = if l1 = [ ] then true
if l1 6= [ ] and l2 = [ ] then false
if l1 = (a :: al) and l2 = (b :: bl) then
(aRb) or (a = b and al ≺ bl)
Define ≺ to be the lexicographic ordering on A given by R.
> B and let B be a poset with partial order R. Define xR f y if f (x)R f (y).
10. Let f : A
The relation R f is a partial order on A.
Let A be the set of strings, let f be the explode function, this takes a string and returns the
list of letters in the string, e.g f (blob) = [b, l, o, b]. Let L be the set of lists of letters. Let R
be the usual alphabetical ordering on roman letters (e.g aRb, bRc etc). The lexicographic
ordering ≺ on L is total.
The ordering ≺ f is given by s1 ≺ f s2 ⇔ f (s1 ) ≺ f (s2 ). In this case ≺ f is the usual
lexicographic ordering on strings.
Exercises
5.15 Let S = {1, 2, 3, 4, 5}, why is the partial order ⊆ on P(S) not total?
5.16 Describe the infix ordering ≤i in terms of the postfix ordering ≤o and the prefix ordering
≤ p . Is there any connection between ≤s and ≤i ?
5.17 Let L N be the set of N lists (lists of natural numbers). Let f : N ↔ L N take a number
and return the list of digits in the decimal expansion of that number, e,g, f (1577) = [1, 5, 7, 7].
Let ≺ be the lexicographic ordering on L N given by the usual total ordering ≤ on N. What is
the ordering ≺ f .
63
Relations
5.5.2
Maximal and Minimal Elements
Given an ordering on a set an obvious idea to associate with the ordering is the greatest element
of the set and the least element. These are defined as follows
Definition 5.5.2 An element l of a poset A with partial order is said be be a least element
if, for all a ∈ A, l a.
An element m is said to be a greatest element if, for all a ∈ A, a m.
However, these things can not always be found for an arbitrary partial ordering; some posets
have least and greatest elements, others do not.
5.5.3
Examples
1. The relation ≤ on Z has no least or greatest elements. The relation ≤ on N has least
element 0, but no greatest element.
2. The relation ⊆ on P = P(A) the power set of A, has least element 0/ and greatest element
A.
3. The production process example is rather different, and of course depends on the exact
process involved. Suppose the process was the development of a piece of software (in
Java say), and each task was the development of a particular class. There is a greatest
element (the final program), but it is not at all clear that there is a least.
4. Divisibility on Z+ has a least element 1, but no greatest.
5. Let Q be the set of all elements of P({1, 2, 3}) with either one or two elements. So
Q = {{1}, {2}, {3}, {2, 3}, {1, 3}, {1, 2}}. This set has no least and no greatest element.
Even if a set has no greatest and least elements, we can often identify some lements which
are in some sense maximal or minimal.
Definition 5.5.3 A minimal element for a partial order of a set A is any element a ∈ A such
that if b a, then a = b. A maximal element of A is any element a such that if a b then
a = b.
This definition is somewhat subtle. A minimal element is one which can not have any
other element smaller than itself. This is not the same as saying that a minimal element is
smaller than every other element. The reason for this is that two elements are not necessarily
comparable by a partial order.
Similarly one can not say that a maximal element is bigger than all the other elements with
respect of the order. This is true for exactly the same reason, that elements may just not be
comparable.
It is also possible for an arbitrary partial order to have lots of minimal elements, or none at
all. The same goes for maximal elements.
We can draw a picture to describe a partial order. An example explains best.
Let Nn be the positive natural numbers from 2 to n. Let Rn be the relation over Nn where
aRn b if a divides b exactly. Below is a diagram representing R33 .
64
COMP11120: 5
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
12
13
9
6
14
10
7
15
5
3
16
11
8
4
2
For example, we can see that 2R33 32 holds because 32 is above 2 in the picture and there
is a connecting sequence of lines leading down from 32 to 2. That is we can reach 2 from 32
by descending to 16 along a line, then to 8 along a line then to 4 along a line, and finally to 2
along a line.
From the picture we also see that 2R33 33 does not hold because there is no way of reaching
2 by descending from 33 along any lines.
Notice that because 17 has no lines descending from it, 17 must be a prime number. We
could have chosen to draw a line between any pair of numbers which are related by R33 , but
this would have made the picture too cluttered to be of any use.
In general to draw the picture for a poset A with partial order ≺, place ‘larger’ elements at
the top of the picture and progressively less ‘large’ elements further down. Draw the minimum
number of lines so that if x ≺ y then there is some sequence of lines descending from y to x.
Such a picture is called the Hasse Diagram of ≺.
Definition 5.5.4
Let ≺ be a partial order on a set A. Let B ⊆ A.
• x is an upper bound for B if for every y ∈ B, y ≺ x.
• x is a least upper bound of B if x is an upper bound of B and there is no other upper bound
y of B s.t. y ≺ x. That is x is minimal in the set of upper bounds for B. When there is a
W
unique least upper bound for B we denote it by B, this is also known as the supremum
of B, or the l.u.b. of B.
• x is a lower bound for B if for every y ∈ B, x ≺ y.
• x is a greatest lower bound of B if x is a lower bound of B and there is no other lower
bound y of B s.t. x ≺ y. That is x is maximal in the set of lower bounds for B. When
V
there is a unique greatest lower bound for B we denote it by B, this is also known as the
infimum of B, or the g.l.b. of B.
V
W
We write x ∧ y to denote {x, y} and x ∨ y to denote {x, y} (when they exist). x ∧ y is
the meet of x and y, x ∨ y is the join of x and y.
65
Relations
5.5.4
Examples
1. Consider R33 drawn above. Let B = {2, 3, 6, 12, 8, 24}. In this case 24 =
have a unique g.l.b. Instead the set of g.l.b for B is {2, 3}.
W
B. B does not
Now take B = {3, 6, 7, 13}, in this case there are no upper or lower bounds, instead the
maximal set is {6, 7, 13}, and the minimal set is {3, 7, 13}. Notice that 7 and 13 are both
maximal and minimal in B.
It turns out that x ∨ y is the lowest common multiple of x and y.
2. Let R be the reals and let < the usual inequality. Let B = {x ∈ R | 1 ≤ x < 2}. In this
W
V
case B = 2, and B = 1, but notice that 2 6∈ B.
3. Let P (S) be the power set of S (the set of all subsets of S). Consider the subset relation
⊆. Suppose A ⊆ P (S), so A contains various subsets of S. In this case
W
A
V
S
A
=
TA∈A
A = A∈A A
Notation From now on we will write
S
A to denote
W
A and
T
A to denote
V
A.
Exercises
5.18 Let R be the partial order on S = {1, 2, 3, 4, 5, 6, 7, 8} whose picture is
8
7
6
5
4
3
2
1
Suppose x and y are such that x R y, what are {x, y} and {x, y}? For each two element subset
A ⊆ S whose elements are incomparable, work out the g.l.b and l.u.b. for A (there are 5 such
W
V
subsets). What is S, what is S.
W
V
5.19 In the relation Rn what is x ∧ y more commonly known as.
5.20 For the poset on P(A) given by ⊆, what are meet and join more commonly known as?
5.21 Let S be the set of subsets of {1, 2, 3, 4} with strictly less than four elements, together
with the relation ⊆. Draw the Hasse diagram which represents this relation.
5.22 Let N be the numbers from 0 to 9. Let S be the set of ascending lists whose elements
come from N. For example [1, 2, 3] ∈ S, [0, 2, 3, 8] ∈ S, but [0, 1, 1, 2] 6∈ S, and [1, 2, 0, 4] 6∈ S.
For l ∈ S let [l] = {a | a occurs in l}. For l1 , l2 ∈ S let l1 ≺ l2 if [l1 ] ⊆ [l2 ]. This is a partial
V
order on S. For A ⊆ S, when does A exist, and if it exists, what is it?
66
COMP11120: 5
5.23 Suppose that S is a poset with partial order ≺, and that meets and joins always exist. Is
it true that
x ∧ (y ∧ z) = (x ∧ y) ∧ z
Is x ∧ (y ∨ z) = (x ∧ y) ∨ (x ∧ z)? What is x ∧ x, x ∨ x. Suppose that
w ∧ x, what is w ∨ x for any x ∈ S?
67
W
S exists, call it w. What is
Relations
68