Discrete Structures for Computing
Notes 10
------------------------------------------------------------------------
Chapter 8: Relations
------------------------------------------------------------------------
A "relation" is a mathematical way to model a relationship between
elements of sets.
For instance, pairing people's names and social security numbers.
------------------------------------------------------------------------
8.1 Relations and their Properties
------------------------------------------------------------------------
More formally, a BINARY RELATION R from set A to set B is a subset
of A x B.
Notation: a R b means (a,b) element-of R.
Example: S is set of students, C is set of courses, ENROLLED
is subset of S x C such that (a,b) is in ENROLLED iff student a
is enrolled in course b.
Example: A = {0,1,2} and B = {a,b}. Then one possible relation
from A to B is {(0,a), (0,b), (1,a), (2,b)}.
<< Fig 1, p. 520 >>
Notice some similarities and differences between binary relations and
functions.
** A function from A to B is a binary relation from A to B.
** Not every binary relation is a function, though (see example above).
(Refer to a "binary relation" just as a "relation" from now on.)
In many situations involving relations, A and B are the same set.
Called a RELATION ON A.
Example: A = {1,2,3,4}, R is the relation from A to A consisting
of all pairs (a,b) such that a divides b. Specifically, R is
{(1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4)}
<< Fig 2, p. 521 >>
Example: The following are relations on the set of integers:
R1 = {(a,b) : a <= b}
R2 = {(a,b) : a > b}
R3 = {(a,b) : a = b or a = -b}
R4 = {(a,b) : a = b}
R5 = {(a,b) : a = b+1}
R6 = {(a,b) : a+b <= 3}
How many different relations are there on a set A with n elements?
Each relation is a subset of A x A.
The number of subsets of A x A is 2 raised to the power (size of A x A).
How big is A x A? It is n^2.
So the number of different relations is 2^{n^2}.
Next, list some properties that some relations have (not necessarily
all relations):
DEF: A relation R on set A is REFLEXIVE if (a,a) element-of R
(or, a R a) for every a in A.
Referring to example relations from above:
* R1 is reflexive (since a <= a)
* R2 is not reflexive (since a is not > a).
* R3 is reflexive
* R4 is reflexive
* R5 is not reflexive
* R6 is not reflexive
How many different reflexive relations are there on a set A
with n elements?
A relation is specified by deciding, for each of the n^2 pairs
(a,b), whether it is in the relation or not.
For a reflexive relation, each of the n pairs (a,a) must be in the relation.
For each of the remaining n^2 - n = n(n-1) pairs (a,b), we have a
choice to put it in the relation or not.
So by the product rule for counting, the number of reflexive relations
is 2^{n(n-1)}.
DEF: A relation R on set A is SYMMETRIC if (a,b) element-of R
implies (b,a) element-of R.
Referring to example relations from above:
* R1 is not symmetric (since a <= b does not necessarily imply b <= a,
think of situation when a = 3 and b = 4).
* R2 is not symmetric
* R3 is symmetric (since if a = b or a = -b, it follows that b = a or b = -a).
* R4 is symmetric
* R5 is not symmetric
* R6 is symmetric
DEF: A relation R on set A is ANTISYMMETRIC if (a,b) element-of R
and (b,a) element-of R implies that a = b.
Referring to example relations from above:
* R1 is antisymmetric: if a <= b and b <= a, it follows that a = b.
* R2 is antisymmetric vacuously. This is kind of tricky, so pay attention.
The def. of antisymmetric says that if (a,b) and (b,a) are both in
the relation, then a = b. For the relation R2, it is not possible
for (a,b) and (b,a) to both be in the relation, that is, it is not
possible for a > b and b < a to both be true. Since the premise of
the conditional is false, the entire conditional is true.
* R3 is not antisymmetric: Here is a counter-example: (3,-3) and
(-3,3) are both in the relation (since 3 = -(-3) and -3 = -(3),
but 3 is not equal to -3.
* R4 is antisymmetric: If a = b and b = a, then a = b.
* R5 is antisymmetric vacuously: similar argument to R2 (it is not
possible for a = b+1 and b = a+1 to both be true).
* R6 is not antisymmetric: Here is a counter-example: (2,1) and
(1,2) are both in the relation (since 2+1 = 3 and 1+2 = 3), but
1 is not equal to 2.
*** antisymmetric is not the opposite of symmetric! ***
DEF: A relation R on set A is TRANSITIVE if (a,b) element-of R
and (b,c) element-of R implies (a,c) element-of R.
Examples: R1, R2, R3, and R4 are transitive. R5 and R6 are not transitive.
------------
Since relations are sets, relations can be combined with union,
intersection and difference.
Example: Suppose A = {1,2,3}, B = {1,2,3,4},
R1 = {(1,1), (2,2), (3,3)},
R2 = {(1,1), (1,2), (1,3), (1,4)}.
Then
R1 U R2 = {(1,1), (1,2), (1,3), (1,4), (2,2), (3,3)}
R1 /\ R2 = {(1,1)}
R1 = R2 = {(2,2), (3,3)}
Example: R1 is the "less than" relation on the real numbers,
R2 is the "greater than" relation on the real numbers.
What is R1 U R2? It is all pairs (x,y) s.t. x != y
What is R1 /\ R2? It is the empty set.
Another way to combine relations is analogous to function composition:
DEF: Suppose R is a relation from A to B, and S is a relation
from B to C. The COMPOSITE of R and S is the relation from A to C
consisting of ordered pairs (a,c) such that there exists a b in B with
(a,b) element-of R and (b,c) element-of S.
Notation is S o R.
Example: A = {1,2,3}, B = {1,2,3,4}, C = {0,1,2},
R = {(1,1), (1,4), (2,3), (3,1), (3,4)}
S = {(1,0), (2,0), (3,1), (3,2), (4,1)}
Then R o S = {(1,0), (1,1), (2,1), (2,2), (3,0), (3,1)}.
Example: Suppose R is the relation on the set of all people such that
(a,b) element-of R iff person a is a parent of person b (R is the
"parent" relation).
Then R o R consists of pairs (a,c) such that there is a person b where
a is a parent of b, and b is a parent of c. I.e., R o R is the
"grandparent" relation.
DEF: Suppose R is relation on set A. The POWERS of R are defined
(recursively) as
R^1 = R
R^{n+1} = R^n o R.
Example: Suppose A = {1,2,3,4} and R is the relation
{(1,1), (2,1), (3,2), (4,3)}. Then
R^1 = R
R^2 = {(1,1), (2,1), (3,1), (4,2)}
R^3 = {(1,1), (2,1), (3,1), (4,1)}
R^4 = R^3
etc.
THEOREM: A relation R on a set A is transitive if and only if
R^n subset-eq R for n = 1,2,3,...
PROOF: First show the "if" part, i.e., if R^n subset-eq R, n = 1,2,3,...,
then R is transitive.
Suppose (a,b) is in R and (b,c) is in R.
We'd like to show that (a,c) is also in R.
Important point is that (a,c) is in R^2 (follows from definition
of R^2 = R o R).
Since we are assuming R^2 is a subset of R, then (a,c) is in R.
Therefore R is transitive.
Now show the "only if" part, i.e., if R is transitive, then R^n
subset-eq R, n = 1,2,3,...
We will use induction on n.
Basis: n = 1. Then R^1 = R, so obviously R^1 is a subset of R.
Inductive Step: Assume that R^n is a subset of R (the inductive
hypothesis). We will prove that R^{n+1} is also a subset of R.
Consider any (a,b) in R^{n+1}; we must show (a,b) is also in R.
By definition, R^{n+1} = R^n o R.
Thus there is some x in A such that (a,x) is in R and (x,b) is in R^n.
** By inductive hypothesis that R^n is a subset of R,
(x,b) is in R.
** By assumption that R is transitive, since (a,x) and (x,b) are
both in R, it follows that (a,b) is in R.
This is what we needed to prove.
QED
------------------------------------------------------------------------
8.2 n-ary Relations and Database Applications
------------------------------------------------------------------------
*** We may return to this section if there is time. ***
------------------------------------------------------------------------
8.3 Representing Relations
------------------------------------------------------------------------
Discuss two ways to represent binary relations between finite sets:
(1) zero-one matrices, and
(2) directed graphs.
Quick intro/review of matrices (refer to Section 3.8 in Ch 3):
DEFS:
* A MATRIX is a rectangular array of numbers.
* An m x n matrix has m rows and n columns.
* Refer to (i,j)-th element of matrix A (number in row i and column j)
as a_{i,j},
* If m = n, then it is a SQUARE matrix.
* Two matrices are EQUAL if they the same number of rows, same number
of columns, and corresponding entries are the same.
Example: 1 1
0 2
1 3
DEF: Suppose A is an m x n matrix. The TRANSPOSE of A, denoted
A^T, is the n x m matrix obtained by interchanging the rows and columns.
So the (i,j) entry of A^T is the (j,i) entry of A.
Example: 1 2 3
4 5 6
is transposed into
1 4
2 5
3 6
DEF: A square matrix A is SYMMETRIC if it is equal to its transpose.
Example: 1 1 0
1 0 1
0 1 0
We will be using a special kind of matrix, where the entries are
just zeros and ones, called ZERO-ONE matrices.
We can combine two zero-one matrices by performing boolean operations
of \/ and /\ on corresponding elements:
Boolean operations on 0 and 1 are analogous to the logical operations
on False and True, with \/ the analog of "or" and /\ the analog of "and".
DEF: Suppose A and B are m x n zero-one matrices. The JOIN of A and B,
denoted A \/ B, is the zero-one matrix whose (i,j) entry is
a_{i,j} \/ b_{i,j}. (I.e., "or" together corresponding entries.)
DEF: Suppose A and B are m x n zero-one matrices. The MEET of A and B,
denoted A /\ B, is the zero-one matrix whose (i,j) entry is
a_{i,j} /\ b_{i,j}. (I.e., "and" together corresponding entries.)
Example: A B
1 0 1 0 1 0
0 1 0 1 1 0
Then A \/ B is 1 1 1
1 1 0
and A /\ B is 0 0 0
0 1 0
DEF: Suppose A is an m x k zero-one matrix and B is a k x n zero-one matrix.
The BOOLEAN PRODUCT of A and B, denoted A (.) B, is the m x n matrix
whose (i,j) entry equals
(a_{i,1} /\ b_{1,j}) \/ (a_{i,2} /\ b_{2,j}) \/ ... \/ (a_{i,k} /\ b_{k,j})
Example: A B
1 0 1 1 0
0 1 0 1 1
1 0
Then A (.) B is 1 1 0
0 1 1
1 1 0
-------
Back to representing relations:
Suppose R is a relation from A = {a_1, a_2, ..., a_m} to
B = {b_1, b_2, ..., b_n}.
Represent R with matrix M_r whose (i,j)-th entry is 1 if (a_i,b_j)
is in R and is 0 otherwise.
Note that the matrix depends on the order in which the elements
of A and B are listed. It doesn't matter what order you use, but
if A = B, then use the same order for rows as for columns.
Example: A = {1,2,3} and B = {1,2}.
Suppose R contains all ordered pairs (a,b) with a > b.
Using the implicit ordering of elements of A and B given above, we get:
0 0
1 0
1 1
If A = B, then the matrix of a relation gives a visual way to see if the
relation has certain properties:
* reflexive: all the elements on the main diagonal are 1
* symmetric: the (i,j) entry of the matrix equals the (j,i)
entry of the matrix.
I.e., the matrix equals its transpose
* antisymmetric: either the (i,j) entry of the matrix
or the (j,i) entry of the matrix (or both) equals 0, for i != j
Example: What are the properties of the relation represented by
this matrix?
1 1 0
1 1 1
0 1 1
It is reflexive, is symmetric, but is not antisymmetric.
What about the union of two relations? Suppose relation R1 is
represented by matrix M1 and relation R2 is represented by matrix M2.
Then the relation R1 U R2 is represented by the matrix
M1 \/ M2, where \/ indicates the "join" operation (perform boolean "or"
on corresponding entries).
Example: M1 M2
1 0 1 1 0 1
1 0 0 0 1 1
0 1 0 1 0 0
So M1 \/ M2 is 1 0 1
1 1 1
1 1 0
For the intersection, R1 /\ R2 is represented by the matrix M1 /\ M2,
where /\ represents the "meet" operation (perform boolean "and" on
corresponding entries).
Example: M1 /\ M2 is 1 0 1
0 0 0
0 0 0
Suppose M_R is the matrix representing relation R
and M_S is the matrix representing relation S.
Then the matrix representing S o R has a 1 in entry (i,j) iff
there exist a k such that entry (i,k) in M_R is 1 and entry
(k,j) in M_S is 1. Note the order!!
This can be calculated using the "Boolean product" of the two
matrices. So M_{SoR} = M_R (.) M_S.
Example: M_R M_S
1 0 1 0 1 0
1 1 0 0 0 1
0 0 0 1 0 1
The matrix for S o R is 1 1 1
0 1 1
0 0 0
Same thing works when S = R.
------------------------------------------------------------------------
8.4 Closures of Relations
------------------------------------------------------------------------
Sometimes we have a relation that does *not* have a desired property
(such as transitivy or symmetry or reflexivity) and we would like to
modify the relation as little as possible so that it does have the
property.
Example: Suppose we have information about the existence of direct bus
service between pairs of cities. For instance, we could have (College
Station, Dallas) and (Dallas, Houston) in the DirectBusService
relation (there is a bus that goes directly from CS to Dallas and
similarly for Dallas and Houston). Suppose we want to know if it's
possible to get from one city to another by bus if we are willing to
change buses. I.e., we'd like to get a transitive "version" of
DirectBus Service, which would be BusService. In the example, we
would have to add (College Station, Houston) to the DirectBus relation
to get the BusService relation.
DEF: Given a relation R on a set, the smallest superset of R that is
reflexive/symmetric/transitive
is called the reflexive/symmetric/transitive CLOSURE of R.
In particular,
* S contains R
* S is reflexive/symmetric/transitive
* S is a subset of every reflexive/symmetric/transitive relation
that contains R
How to compute the closures of a relation?
Reflexive Closure:
------------------
* Just add all pairs of the form (a,a)
Example: What is the reflexive closure of the less than relation on
the integers? Just add (a,a). This gives the less than or equal relation.
Symmetric Closure:
------------------
* Just add all pairs that are the "opposite" of the pairs in the relation.
I.e., compute R U R^{-1}, where R^{-1} = {(b,a) : (a,b) element-of R}.
Example: What is the symmetric closure of the greater than relation
on the positive integers? Just add all the less than relationships.
This gives the not-equals relation.
Transitive Closure:
------------------
This is more complicated than the other two, but is the closure that
is most useful in practice (cf. bus service example above).
General idea is to keep adding new pairs that are required for
transitivity until no new pairs are needed.
To develop algorithms for computing the transitive closure, it is
convenient to use the directed graph representation for relations.
<< Draw Fig 1 on p. 546 and go over definition of path, length, cycle >>
FACT: Let R be a relation on a set. There is a path of length n
in the graph representing R if and only if (a,b) is in R^n.
This should be intuitively obvious, and can also be proved by induction
on n (see textbook).
THEOREM: The transitive closure of relation R is U_{n=1}^infinity R^n.
PROOF: Let's let R* be a more convenient name for U_{n=1}^infinity R^n
We must show that
(1) R* contains R
(2) R* is transitive
(3) R* is a subset of every transitive relation that contains R
(1) R* contains R because R = R^1.
(2) R* is transitive: If (a,b) is in R* and (b,c) is in R*,
show (a,c) is in R*.
Since (a,b) is in R*, (a,b) is in some R^m.
By the fact, there is a path from a to b of length m in the graph
representing R^m.
Since (b,c) is in R*, (b,c) is in some R^n.
By the fact, there is a path from b to c of length n in the graph
representing R^n.
Thus there is a path from b to c of length m+n in the graph
representing R^{m+n}.
Thus (a,c) is in R*.
(3) Show R* is a subset of every transitive relation that contains R.
Suppose S is a transitive relation containing R. We have to
show that S also contains R*.
Strategy: Show R* is a subset of S* = U_{k=1}^infinity S^k
and show S* is a subset of S.
Why is R* a subset of S*? Since R is a subset of S, any path
in the graph of R is also a path in the graph of S.
Why is S* a subset of S?
By theorem proved earlier, since S is transitive, each of the S_k's
is a subset of S.
QED
Now, how can we compute R*?
LEMMA: Suppose R is a relation on a set with n elements
and there is a path from a to b in the graph of R.
* If a = b, then there is a path of length at most n.
* If a != b, then there is a path of length at most n-1.
PROOF: Do the a = b case. Suppose in contradiction the shortest
path from a to a has length m greater than n. Note that this path
is a cycle (starts and ends at a), say a = x_0, x_1, ..., x_{m-1}, x_m = a.
Since the length of the path
is greater than n, by the pigeonhole principle, there are two
repeated vertices in the cycle other than the endpoints.
So there is another cycle in the main cycle: <<< draw fig >>>
We can remove that cycle and get a shorter path from a to b,
which contradicts the assumption that we had the shortest path.
QED
Thus we don't need to look for paths longer than n.
I.e., R* = R U R^2 U R^3 U ... U R^n.
We can compute with the zero-one matrices representing these relations:
THEOREM: Let M_R be the zero-one matrix of the relation R on a set
with n elements. Then the zero-one matrix of the transitive closure
R* is the following join:
M_R \/ M_R^[2] \/ M_R^[3] \/ ... \/ M_R^[n].
Example: 1 0 1
0 1 0
1 1 0
Compute M \/ M^[2] \/ M^[3].
End result is 1 1 1
0 1 0
1 1 1
Algorithm:
input is matrix M representing relation R
A := M // A holds increasing larger powers of M
B := A // B holds join of powers computed so far
for i := 2 to n do
A := A (.) M // compute boolean product
B := B \/ A // compute join
endfor
Number of bit operations:
* each Boolean product takes n^2(2n-1) bit operations
* number of Boolean products is n-1
* each join takes n^2 bit operations
* number of joins is n-1
* Total is O(n^4) bit operations.
------------------------------------------------------------------------
8.5 Equivalence Relations
------------------------------------------------------------------------
Equivalence relations capture the situation when we want to group
things together in such a way that everything in the same group is
some the same (or equivalent) with respet to some criterion.
DEF: A relation on a set is an EQUIVALENCE relation if it is reflexive,
symmetric and transitive. If (a,b) is in an equivalence relation,
then we say they are EQUIVALENT, denoted a ~ b.
EX: Let R = {(a,b) : a = b or a = -b}.
Verify that R is reflexive, symmetric and transitive, i.e., R is
an equivalence relation.
EX: Let R = {(a,b) : a - b is an integer}.
Reflexive: Yes, since a - a = 0, which is an integer.
Symmetric: Yes, since if a = b or a = -b, then b = a or b = -a.
Transitive: Yes, since if a = b or a = -b, and b = c or b = -c,
then a = c or a = -c.
So R is an equivalence relation.
EX: Consider a positive integer m.
Let R = {(a,b) : a and b have the same remainder when divided by m}.
Notation: a =- b (mod m).
Show R is an equivalence relation.
Reflexive: Obviously a and a have the same remainder when divided by m.
Symmetric: If a and b have the same remainder when divided by m,
then b and a have the same remainder when divided by m.
Transitive: Suppose a and b have the same remainder when divided by m
and b and c have same remainder when divided by m.
EX: Consider a positive integer n and a set of strings S.
Let R = {(a,b) : a = b or n-character prefix of a = n-character prefix of b}.
Show R is an equivalence relation.
Reflexive: Yes, since a = a.
Symmetric: If a = b, then b = a.
If a and b have the same n-character prefix, then so do b and a.
Transitive: Suppose a = b or a and b have same n-character prefix.
Suppose b = c or b and c have the same n-character prefix.
There are 4 cases.
Case 1: a = b and b = c. Then a = c.
Case 2: a and b have same n-character prefix and b = c.
Then a and c have same n-character prefix.
Case 3: a = b and b and c have same n-character prefix.
Then a and c have same n-character prefix.
Case 4: a and b have same n-character prefix and
b and c have same n-character prefix. Then a and c
have same n-character prefix.
EX: Let R = {(a,b) : a divides b}. (So a and b are positive integers.)
Reflexive: yes, since a divides a.
Symmetric: Suppose a divides b (e.g., 2 divides 4). The problem is
that b does not necessarily divide a (e.g., 4 does not divide 2).
So R is not symmetric and thus is not an equivalence relation.
EX: let R = {(x,y) : |x - y| < 1}. (So x and y are real numbers.)
Reflexive: yes, since |x - x| = 0 < 1.
Symmetric: yes, since |x - y| = |y - x|.
Transitive: Suppose |x - y| < 1 and |y - z| < 1. Does it follow
that |x - z| < 1? No, counterexample is x = 2.8, y = 1.9, z = 1.1.
So R is not transitive and thus is not an equivalence relation.
DEF: Let R be an equivalence relation on a set A. The EQUIVALENCE
CLASS OF a is {b : (a,b) is in R}. Notation is [a]_R. Each element
of [a]_R is a REPRESENTATIVE of the equivalence class.
EX: For the relation R = {(a,b) : a = b or a = -b} on the integers,
[a] = {a,-a}. In particular,
[0] = {0}
[1] = {1,-1}
[2] = {2,-2}
etc.
EX: For the relation
R = {(a,b) : a and b have the same remainder when divided by 4},
[0] = {0,4,-4,8,-8,12,-12,...}
[1] = {1,5,-3,9,-7,...}
[2] = {2,-2,6,-6,10,-10,...}
[3] = {3,-1,7,-5,11,...}
EX: For the relation
R = {(s,t) : s = t or s and t have the same 3-character prefix}
on bit strings,
[011] = {011,0110,0111,01100,01101,01110,01111,...}
etc.
EX: In Standard C, two identifiers (name of a variable, function, etc.)
are considered equal if they agree on the first 31 characters.
(So don't use 2 variable names that are the same for the first 31
characters.)
THEOREM: let R be an equivalence relation on a set A. Then the following
are equivalent:
(1) (a,b) is in R
(2) [a] = [b]
(3) [a] /\ [b] != emptyset
PROOF: Strategy: We will show
(1) => (2),
(2) => (3),
(3) => (1).
Thus either they are all true or all false.
Show (1) => (2): Assume (a,b) is in R.
We have to show [a] = [b].
Let's do it by showing [a] is a subset of [b], and [b] is a subset of [a].
Why is [a] a subset of [b]? Suppose c is in [a], i.e., (a,c) is in R.
We have to show c is also in [b], i.e., (b,c) is in R.
Since (a,b) is in R, symmetry implies that (b,a) is in R.
Since (b,a) and (a,c) are in R, transitivity implies (a,c) is in R.
Argument to show [b] is a subset of [a] is similar.
Show (2) => (3). Assume [a] = [b].
We have to show [a] /\ [b] is nonempty.
Since [a] = [b], their intersection is equal to [a], which contains a.
Show (3) => (1). Assume [a] /\ [b] is nonempty.
We have to show (a,b) is in R.
Let c be an element in the intersection.
Then (a,c) is in R, and (b,c) is in R.
By symmetry, (c,b) is in R.
So by transitivity, (a,b) is in R.
QED
The equivalence classes of a set form a PARTITION of the set,
a collection of disjoint subsets whose union equals the set.
<< Fig 1 on p. 561 >>
Conversely, any partition of a set forms an equivalence relation
(each subset of the partition corresponds to an equivalence class of the
relation ).
EX: Given an integer m, the set of integers can be partitioned into
m equivalence classes using the equivalence relation "congruence modulo 4".
(I.e., put all the integers that have the same remainder when divided
by 4 into the same equivalence class.)
Recall [0], [1], [2], and [3] from previous example.
EX: Recall the relation
R = {(s,t) : s = t or s and t have the same 3-character prefix}
on bit strings.
[empty string] = {empty string}
[0] = {0}
[1] = {1}
[00] = {00}
[01] = {01}
[10] = {10}
[11] = {11}
[000] = {000,0000,0001,00000,00001,00010,00011,...}
[001] = {001,0010,0011,00100,00101,00110,00111,...}
[010] = ...
[011] = ...
[100] = ...
[101] = ...
[110] = ...
[111] = ...
These 15 equivalence classes are disjoint and every bit string is in
exactly one of them. So these equivalence classes partition the set
of all bit strings.
------------------------------------------------------------------------
8.5 Equivalence Relations
------------------------------------------------------------------------
Relations can be used to order some, or all, of the elements of a set.
The idea is that we put (x,y) in the relation iff x comes before y
in the ordering we are modeling.
DEF: A relation R on a set S is a PARTIAL ORDER if it is reflexive,
antisymmetric, and transitive. The set S together with the relation R
is called a POSET, denoted (S,R).
*** Warning! Note difference between and partial order and an
equivalence relation. ***
EX: Show that >= is a partial ordering on the set of integers.
(I.e., (Z, >=) is a poset.)
Reflexive: Yes, since a >= a .
Antisymmetric: Yes, since a >= b, and b >= a implies a = b.
Transitive: Yes, since a >= b and b >= c implies a >= c.
EX: Divisibility relation is a partial ordering on the set of positive
integers. Previous example showed the 3 properties.
EX: Show that the subset relation is a partial ordering on the powerset
of a set S.
*** Be careful here. The set we are working with contains subsets of S.
Reflexive: Yes, since S1 subsetof S1.
Antisymmetric: Yes, since S1 subsetof S2 and S2 subsetof S1 implies
S1 = S2.
Transitive: Yes, since S1 subset of S2 and S2 subsetof S3 implies
S1 subsetof S3.
Notice in the examples above that the different posets had different
operations or orderings (<=, |, subsetof).
We need a common, consistent, notation for the ordering of an arbitrary poset.
Usually use curly-<=.
DEF: Consider a poset (S,curly-<=). Elements a and b are COMPARABLE
if a curly-<= b or b curly-<= a. Othrewise INCOMPARABLE.
EX: In the poset (Z,<=), 3 and 4 are comparable.
EX: In the poset (Z+,|), 3 and 9 are comparable (since 3 divides 9).
But 5 and 7 are incomparable (since 5 does not divide 7).
EX: In the poset (2^S,subsetof), where S = {X,Y,Z}, {X,Y} and {Y} are
comparable. But {X,Y} and {Y,Z} are incomparable.
"Partial" comes from the fact that not all the elements of a poset
are necessarily comparable.
DEF: If every pair of elements in a poset are comparable, then
the relation is called a TOTAL ORDER.
EX: (Z,<=) is a total order.
----------
LEXICOGRAPHIC ORDERING:
Think about how words in a dictionary are ordered.
Each word is a string of letters, and the there is an ordering
on the letters (namely, alphabetical order). The alphabetical
order of the letters is then used to order the words (strings of
letters) alphabetically.
Let's start with defining the lexicographic ordering of the
Cartesian product of 2 posets.
Suppose we have two posets, (A_1,curly-<=_1) and (A_2,curly-<=_2).
Consider the Cartesian product A_1 x A_2. The LEXICOGRAPHIC ORDERING
on A_1 x A_2 is defined by:
(a_1,b_1) curly-<= (a_2,b_2) if (a_1,b_1) = (a_2,b_2) or
a_1 = a_2 and b_1 curly-<=_2 b_2 or
a_1 curly-<=_1 a_2
If (a_1,b_1) curly-<= (a_2,b_2) but they are not equal, then we
use the notation (a_1,b_1 curly-< (a_2,b_2).
EX: Suppose A_1 and A_2 are both (Z,<=) (integers with less than or
equal to). Then the lexicographic ordering on Z x Z with <= is
(a_1,b_1) <= (a_2,b_2) if the pairs are equal or if a_1 = a_2
and b_1 < b_2, or a_1 < a_2 (no matter what b_1 and b_2 are).
So (3,5) < (4,8) and (3,8) < (4,5).
Now extend to the Cartesian product of n posets.
EX: (1,2,3,5) < (1,2,4,3).
Now extend to strings. Difference from Cartesian product is
that they are not necessarily the same length.
Given two strings, determine lexicographic ordering like this:
(1) If strings are of different length,
truncate longer string to the length of the shorter string.
(2) Now think of the two strings as t-tuples (where t is the common
length), and do lexicographic ordering as for Cartesian product.
(3) If one string is a prefix of the other string, then the shorter
string comes before the longer string in the ordering.
EX: Consider set of strings of lowercase English letters and
alphabetical ordering of the letters.
discreet curly-< discrete
discreet curly-< discreetness
dicrete curly-< discretion
-------------
Concise notation for representing posets: based on directed graphs,
but don't put in redundant edges (i.e., edges that can be deduced from
the edges that are present). Called Hasse diagrams.
<<< Fig 2 on p. 571 >>>
General process:
* Start with the directed graph for the partial order relation.
* remove self-loops (we know the relation is reflexive)
* remove all edges that must be present because of transitivity:
i.e., if (a,b) and (b,c) are present, remove (a,c).
* arrange each edge so that all edges point up
* remove arrowheads
EX: divides partial order on {1,2,3,4,6,8,12}.
<<< Fig 3, p. 572 >>>
EX: subset partial order on powerset of {a,b,c}
<<< Fig 4, p. 573 >>>
--------
DEF: Consider a poset (S, curly-<=).
a is a MAXIMAL element if there is no b in S such that a curly-< b.
a is a MINIMAL element if there is no b in S such that b curly-< a.
a is the GREATEST ELEMENT if for all b in S, b curly-<= a.
a is the LEAST ELEMENT if for all b in S, a curly-<= b.
<<< Fig 5, p. 573 >>>
Maximal elements are 12, 20, and 25.
Minimal elements are 2 and 5.
No greatest element.
No least element.
*** do previous examples ***
More examples:
<<< Fig 6, p. 573 >>>
Sometimes we need to consider a subset of a poset and find elements
of the poset that bound the elements in the subset.
DEF: Consider poset (S,curly-<=) and a subset A of S.
If u is an element of S such that a curly-<= u for all a in A, then
u is an UPPER BOUND of A.
Furthermore, if u is curly-<= every other upper bound of A, then
u is the LEAST UPPER BOUND.
If u is an element of S such that u curly-<= a for all a in A, then
u is a LOWER BOUND of A.
Furthermore, if every other upper bound of A is curly-<= u, then
u is the GREATEST LOWER BOUND.
EX: <<< fig 7, p. 574 >>>
Consider {a,b,c}.
* upper bounds are e, f, j, and h
* least upper bound is e
* lower bound is a
* greatest lower bound is a
Consider {j,h}.
* no upper bound
* no least upper bound
* lower bounds are a, b, c, d, e, and f
* greatest lower bound is f
Consider {a,c,d,f}.
* upper bounds are f, h and j
* least upper bound is f
* lower bound is a
* greatest lower bound is a
Consider {b,d,g}
* upper bounds are g and h
* least upper bound is g
* lower bounds are a and b
* greatest lower bound is b
EX: Consider the poset (Z+,|) (divides relation on the positive integers).
Consider {3,9,12}.
* upper bounds are all pos integers that are divisible by 3, 9 and 12, that is,
all pos integers that are divisible by their least common multiple, 36.
* least upper bound is 36
* lower bounds are all pos integers that divide 3, 9 and 12, that is
1 and 3.
* greatest upper bound is 3.
-------------
DEF: A LATTICE is a partially ordered set in which every pair of elements
has a least upper bound and a greatest lower bound.
EX: <<< Fig 8, p. 575 >>>
(a) and (c) are lattices, but (b) is not. Reason is that b and c
have as their upper bounds d, e, and f, but none of these 3 elements
precedes the other 2 w.r.t. the ordering of the poset.
EX: Is (Z+,|) a lattice?
Yes: given a and b, their least upper bound is their least common multiple,
and their greatest lower bound is their greatest common divisor.
EX: Is ({1,2,3,4,5},|) a lattice?
No: The two elements 2 and 3 have no upper bound in the lattice
(draw it), so they have no least upper bound.
EX: Is (2^S,subseteq) a lattice (powerset of S w.r.t. containment)?
Yes: Given two subsets A and B of S, their least upper bound is A U B,
and their greatest lower bound is A /\ B.
-------------------
A partial order describes ordering relationships between some, but not
necessarily all, of the elements of a set. We've seen several examples
where not all of the elements of the set are comparable to each other
(e.g., set containment, the divides relation).
However, sometimes it is convenient to list all the elements of a relation
in some order. In this order, we want
* comparable elements are in the proper order with respect to each other
* incomparable elements can be put in any order with respect to each other
EX: Suppose we have a set of tasks to accomplish, some of which must
be done before others. For instance, to eat breakfast we have to:
* get out bowl
* get out spoon
* pour cereal
* pour milk
* eat cereal
* wash dishes
<<< draw the standard ordering >>>
If someone is eating breakfast, s/he can only do one thing at a time.
There are options as to whether to get the bowl first or the spoon first,
but they both must be gotten before pouring the cereal.
Finding a total order that is consistent ("compatible") with a partial
order is called TOPOLOGICAL SORTING.
Here is a very high level description of an algorithm for topological
sorting (you will see a more concrete algorithm in data structures/
algorithms course):
input: partial order (S,<=) where S is finite
i := 1
while S is not empty do
x := a minimal element of S // can be shown to exist
T[i] := x
i := i+1
S := S - {x}
endwhile
return T