equivalence and order - cr.yp.tocr.yp.to/2005-261/bender1/eo.pdfequivalence and order example 2...

36
Unit EO Equivalence and Order Section 1: Equivalence The concept of an equivalence relation on a set is an important descriptive tool in mathe- matics and computer science. It is not a new concept to us, as “equivalence relation” turns out to be just another name for “partition of a set.” Our emphasis in this section will be slightly different from our previous discussions of partitions in Unit SF. In particular, we shall focus on the basic conditions that a binary relation on a set must satisfy in order to define a partition. This “local” point of view regarding partitions is very helpful in many problems. We start with the definition. Definition 1 (Equivalence relation) An equivalence relation on a set S is a partition K of S. We say that s, t S are equivalent if and only if they belong to the same block of the partition K. We call a block an equivalence class of the equivalence relation. If the symbol denotes the equivalence relation, then we write s t to indicate that s and t are equivalent (in the same block) and s t to denote that they are not equivalent. Here’s a trivial equivalence relation that you use all the time. Let S be any set and let all the blocks of the partition have one element. Two elements of S are equivalent if and only if they are the same. This rather trivial equivalence relation is, of course, denoted by “=”. Example 1 (All the equivalence relations on a set) Let S = {a, b, c}. What are the possible equivalence relations on S? Every partition of S corresponds to an equivalence relation, so listing the partitions also lists the equivalence relations. Here they are with the equivalences other than a a, b b and c c, which are always present. {a}, {b}, {c} no others {a}, {b, c} b c, c b {b}, {a, c} a c, c a {c}, {a, b} a b, b a {a, b, c} a b, b a, a c, c a, b c, c b What about the set {a, b, c, d}? There are 15 equivalence relations. For a five element set there are 52. As you can see, the number increases rapidly. EO-1

Upload: others

Post on 09-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Unit EO

Equivalence and Order

Section 1: Equivalence

The concept of an equivalence relation on a set is an important descriptive tool in mathe-matics and computer science. It is not a new concept to us, as “equivalence relation” turnsout to be just another name for “partition of a set.” Our emphasis in this section will beslightly different from our previous discussions of partitions in Unit SF. In particular, weshall focus on the basic conditions that a binary relation on a set must satisfy in order todefine a partition. This “local” point of view regarding partitions is very helpful in manyproblems. We start with the definition.

Definition 1 (Equivalence relation) An equivalence relation on a set S is a partitionK of S. We say that s, t ∈ S are equivalent if and only if they belong to the same block ofthe partition K. We call a block an equivalence class of the equivalence relation.

If the symbol ≡ denotes the equivalence relation, then we write s ≡ t to indicate thats and t are equivalent (in the same block) and s 6≡ t to denote that they are not equivalent.

Here’s a trivial equivalence relation that you use all the time. Let S be any set andlet all the blocks of the partition have one element. Two elements of S are equivalent ifand only if they are the same. This rather trivial equivalence relation is, of course, denotedby “=”.

Example 1 (All the equivalence relations on a set) Let S = {a, b, c}. What are thepossible equivalence relations on S? Every partition of S corresponds to an equivalencerelation, so listing the partitions also lists the equivalence relations. Here they are with theequivalences other than a ≡ a, b ≡ b and c ≡ c, which are always present.

{

{a}, {b}, {c}}

no others{

{a}, {b, c}}

b ≡ c, c ≡ b{

{b}, {a, c}}

a ≡ c, c ≡ a{

{c}, {a, b}}

a ≡ b, b ≡ a{

{a, b, c}}

a ≡ b, b ≡ a, a ≡ c, c ≡ a, b ≡ c, c ≡ b

What about the set {a, b, c, d}? There are 15 equivalence relations. For a five element setthere are 52. As you can see, the number increases rapidly.

EO-1

Page 2: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

Example 2 (Classification by remainder) Now let the set be the integers Z. Let’stry to define an equivalence relation by saying that n and k are equivalent if and only ifthey have the same remainder when divided by 24. In other words, n and k differ by amultiple of 24. Is this an equivalence relation? If it is we should be able to find the blocksof the partition. There are 24 of them, which we could number 0, . . . , 23. Block j consistsof all integers which equal j plus a multiple of 24; that is, they have a remainder of j whendivided by 24. We write this block as 24Z + j. If two integers a and b are equivalent, wewrite a = b (mod 24) or a ≡ b (mod 24).

For this to be an equivalence relation, we must verify that the 24 sets 24Z+ j, 0 ≤ j ≤23, are a partition of Z. Each of these blocks is clearly nonempty. Their union is Z sinceevery integer has some remainder 0 ≤ j ≤ 23 when divided by 24. Why are they disjoint?If x ∈ 24Z + j and x ∈ 24Z + k where j 6= k, then x would have two different remainders jand k when divided by 24. This is impossible.

Of course there is nothing magic about 24 — any positive integer would work. Westudied this in Section 1 of Unit NT. We proved an interesting property of these equivalencethere: They can be added, subtracted and multiplied. In other words, if a ≡ A and b ≡ B,then a + b ≡ A + B, a − b ≡ A − B and ab ≡ AB.

Example 3 (Using coimage to define equivalence) Suppose S and T are sets andF : S → T is a function. We can use the coimage of F to define an equivalence relation.Recall from Section 2 of Unit SF that the coimage of F is the partition of S given by

Coimage(F) = {F−1(b) | b ∈ T, F−1(b) 6= ∅} = {F−1(b) | b ∈ Image(F )}.

Since the coimage is a partition of S, it defines an equivalence relation. Thus s1 ≡ s2 ifand only if F (s1) = F (s2). As you can see, the idea is to define F (s) to be the property ofs that we are interested in. Almost all our examples are of this kind.

In the previous example, we could take S = Z and define F (n) to be the remainderwhen n is divided by 24.

The sets need not be numeric. For example, let S be the set of people and let T = S×S.Define

F (s) = (mother of s, father of s).

Then s1 ≡ s2 if and only if s1 and s2 are siblings (i.e., have the same parents).

Example 4 (Some equivalence classes of functions) We use the notation k to denote{1, 2, . . . , k}, the set of the first k positive integers. Consider all functions S = mn. Hereare some partitions based on the fact that S is a set of functions:

• We could partition the functions f into blocks according to the sum of the integers inthe Image(f). In other words, f ≡ g means

∑ni=1 f(i) =

∑ni=1 g(i).

• We could partition the functions f into blocks according to the max of the integers inImage(f). In other words, f ≡ g means that the maximum values of f and g are thesame.

• We could partition the functions f into blocks according to the vector v(f) where theith component vi(f) is the number of times f takes the value i; that is, vi(f) = |f−1(i)|.

EO-2

Page 3: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 1: Equivalence

For example, suppose f, g, h ∈ 34 in one-line notation are f = (3, 1, 2, 1), g = (1, 1, 3, 2)and h = (1, 2, 3, 2). Then f ≡ g 6≡ h because v(f) = v(g) = (2, 1, 1) but v(h) = (1, 2, 1).

Each of these defines a partition of S and hence and equivalence relation on S.

We can use the coimage idea of the previous example to describe these equivalencerelations:

• F (f) =∑n

i=1 f(i),

• F (f) = max(f) and

• F (f) = v(f).

Definition 2 (Binary relation on a set) Given a set S, a binary relation on S is asubset R of S × S. Given a binary relation R, we will write s R t if and only if (s, t) ∈ R.1

Example 5 (Equivalence relations as binary relations) Suppose ≡ is an equivalencerelation on S associated with the partition K. Then the set R = {(s, t) | s ≡ t} ⊆ S×S is abinary relation on S associated with the equivalence relation. Thus an equivalence relationis a binary relation.

The converse need not be true. For example x R y if and only if x < y defines a binaryrelation on Z, but it is not an equivalence relation because we never have x < x, but anequivalence relation requires x ≡ x for all x.

When is a binary relation an equivalence relation? The next theorem provides neces-sary and sufficient conditions for a binary relation to be an equivalence relation. Verifyingthe conditions is a sometimes a useful way to prove that some particular situation is anequivalence relation.

Theorem 1 (Reflexive, symmetric, transitive) Let S be a set and suppose that wehave a binary relation R on S. This binary relation is an equivalence relation if and onlyif the following three conditions hold.

(i) (Reflexive) For all s ∈ S we have s R s.

(ii) (Symmetric) For all s, t ∈ S such that s R t we have t R s.

(iii) (Transitive) For all r, s, t ∈ S such that r R s and s R t we have r R t.

Proof: We first prove that an equivalence relation satisfies (i)–(iii). Suppose that ≡ is anequivalence relation. Since s belongs to whatever block it is in, we have s ≡ s. Since s ≡ tmeans that s and t belong to the same block, we have s ≡ t if and only if we have t ≡ s.Now suppose that r ≡ s and s ≡ t. Then r and s are in the same block and s and t are inthe same block. Thus r and t are in the same block and so r ≡ t.

1 A binary relation is a special case of a relation from S to T (discussed in Unit SF),namely, T = S.

EO-3

Page 4: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

We now suppose that (i)–(iii) hold and prove that we have an equivalence relation;that is, a partition of the set S. What would the blocks of the partition be? Everythingequivalent to a given element should be in the same block. Thus, for each s ∈ S let B(s)be the set of all t ∈ S such that s R t. We must show that the set of these sets form apartition of S; that is, {B(s) | s ∈ S} is a partition of S.

In order to have a partition of S, we must have

(a) the B(s) are nonempty and every t ∈ S is in some B(s) and

(b) for every p, q ∈ S, B(p) and B(q) are either equal or disjoint.

Since R is reflexive, s ∈ B(s), proving (a). We now turn our attention to (b). SupposeB(p) ∩ B(q) is not empty. We must prove that B(p) = B(q). Suppose x ∈ B(p) ∩ B(q)and y ∈ B(p). We have, p R x, q R x and p R y. By the symmetric law, x R p. Usingtransitivity twice:

(

q R x and x R p)

implies q R p,(

q R p and p R y)

implies q R y.

By the definition of B, this means y ∈ B(q). Since this is true for all y ∈ B(p), we haveproved that B(p) ⊆ B(q). Similarly B(q) ⊆ B(p) and so B(p) = B(q). This proves (b).

Example 6 (The rational numbers) Let the set be S = Z×Z∗, where Z

∗ is the set ofall integers except 0. Write (a, b) ≡ (c, d) if and only if ad = bc.

We now use Theorem 1 to prove that, in fact, this is an equivalence relation.

(i) To verify (a, b) ≡ (a, b), we must check that ab = ba (since c = a and d = b). This isobviously true.

(ii) Suppose (a, b) ≡ (c, d). This means ad = bc. To verify that (c, d) ≡ (a, b), we mustcheck that cb = da. This follows easily from ad = bc.

(iii) Suppose (a, b) ≡ (c, d) and (c, d) ≡ (e, f). We must verify that (a, b) ≡ (e, f). In otherwords, we are given ad = bc and cf = de, and we want to conclude that af = be. Wehave (ad)(cf) = (bc)(de). We’re done if we can cancel c and d from both sides of thisequality. We can cancel d since d ∈ Z∗. If c 6= 0 we can cancel it, too, and we’re done.What if c = 0? In that case, since d 6= 0, it follows from ad = bc that a = 0. Similarly,it follows from cf = de that e = 0. Thus af = be = 0.

With a moment’s reflection, you should see that ad = bc is a way to check if the twofractions a/b and c/d are equal. We can label each equivalence class with the fraction a/bthat it represents.

Just because we’ve defined fractions, that doesn’t mean we can do arithmetic withthem. We need to prove that equivalence classes can be added, subtracted, multiplied, anddivided. This problem was mentioned for modular arithmetic at the end of Example 2. Wewon’t prove it for rational numbers.

In the exercises, you will acquire more practice with equivalence relations. You shouldfind them easier to deal with than the previous two examples.

EO-4

Page 5: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 1: Equivalence

The Pigeonhole Principle

We now look at a class of problems that relate to various types of restrictions on equivalencerelations. These problems are a part of a much more general and often very difficult branchof mathematics called extremal set theory. The following theorem is a triviality, but its nameand some of its applications are interesting. You should be able to prove the theorem.

Theorem 2 (Pigeonhole principle) Suppose K is a partition of a set S and |S| = s.If K has fewer than s blocks, then some block must have at least two elements.

Where did the name come from? Old style desks often had an array of small horizontalboxes for storing various sorts of papers — unpaid bills, letters, etc. These were calledpigeonholes because they often resembled the nesting boxes in pigeon coops. Imagine slipsof paper, with one element of S written on each slip. Put the slips into the boxes. At leastone box must receive more than one slip if there are more slips than boxes — that’s thepigeonhole principle. After the slips are in the boxes, a partition of the set of slips has beendefined. (The boxes are the blocks.)

Example 7 (Applying the pigeonhole principle) Designate the months of the yearby the set numbers M = 12 = {1, 2, . . . , 12}. What is the smallest integer k such thatamong any k people, there must be at least two people with the same first letter of theirlast name and same birth month? This is a typical application of the pigeonhole principle.

Recall that we can define a partition of a set P by defining a function f with domainP and letting the partition of P be the coimage of f . In this case, we let P be the set ofpeople and define f : P → M ×A, where A is the set of letters in the alphabet, as follows:f(p) = (m,a), where m is the month in which p was born and a is the first letter of p’s lastname. To be able to apply the pigeonhole principle to obtain the conclusion asked for, wemust have |M × A| < k, where k = |P |. In other words, we must have 12 × 26 = 312 < k.The smallest such k = 313. If k = 312 then it is possible to have a group of people, no twoof which have the same first letter of their last name and same birth month.

What we did in the last example is a common way to set things up for the pigeonholeprinciple. We are given a set S (people) and a property (birthdays and initials) of theelements of S. We want to know that two elements of S have equal properties. To use thecoimage, define a function f : S → T where T is the set of possible properties. Since thecoimage can have at most |T | blocks, we need |T | < |S| to use the pigeonhole principle.

EO-5

Page 6: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

Example 8 (A divisibility example) Here is a somewhat less trivial example. Letn > 0 be a an integer. What is the smallest integer k such that given any set {t1, t2, . . . , tk}of distinct integers, either there must be some i 6= j such that n | (ti − tj), or there mustbe some i such that n | ti? We must give a little thought as to how to use the coimageversion of the pigeonhole principle in this situation. It seems that the correct function isf : {t1, t2, . . . , tk} → {0, 1, . . . , n − 1} where f(x) = x (mod n). Suppose first that there isno i such that n | ti. Then |Image(f)| < n because the only values that can be in the imageare 1, 2, . . . , (n − 1). In that case, if k ≥ n then we can apply the pigeonhole principle.There must be at least one pair, i < j, such that f(ti) = f(tj) or, equivalently, ti (mod n)= tj (mod n). For this pair, n | (ti − tj). If k = n− 1, we can take the set {1, 2. . . . , n− 1}for which there is neither some i such that n |ti nor a pair i 6= j such that n | (ti−tj). Thus,the smallest k is k = n. You should think carefully about this example as it typical of onetype of analysis associated with these extremal problems. The idea is that one condition(in this case n | ti for some i), when negated, brings about a situation where the pigeonholeprinciple applies.

Results gotten from the application of the pigeonhole principle are sometimes used inclever ways to get new results. Suppose that we have a sequence a1, a2, . . . , an of positiveintegers. Then, by the previous paragraph applied to the “partial sums” of this sequence,there must be a partial sum, ti = a1 + a2 + · · · + ai such that either n | ti or there is apair i < j such that n | (tj − ti). Note that tj − ti = ai+1 + · · · + aj . Thus, if you haveany sequence of n positive integers, there is at least one “consecutive” sum of the form∑q

k=p ak that is divisible by n. For example, take n = 8 and take the sequence to be 11,12, 23, 5, 7, 9, 21, 9. The consecutive sum 12 + 23 + 5 = 40 is divisible by 8. In general,this consecutive sum that is divisible by n will, as in this example, not be unique.

Example 9 (Equal sums) Given a positive integer N , how large must t be so that, forevery list A = (a1, . . . , at) of t integers, there are i 6= j and k 6= m such that ai + aj =ak + am (mod N) and {i, j} 6= {k,m}. (The last condition avoids the trivial situationai + aj = ai + aj .) For example, if N = 5 and A = (1, 2, 5, 8), then 1 + 2 = 5 + 8 (mod 5).We want to look at sums of pairs of elements of A, so our set S will be pairs of indiceschosen from t and f(i, j) = ai + aj (mod N) defines a function f : S → {0, 1, . . . ,N − 1}.Thus there are N pigeonholes. What is |S|? In other words how many pairs can be chosenfrom t? The answer is

(

t2

)

= (t2−t)/2. For the pigeonhole principle we need (t2−t)/2 > N ,which is equivalent to t2 − t − 2N > 0. The curve y = x2 − x − 2N is a parabola openingupward. Thus y > 0 whenever x exceeds the larger root of the quadratic. Solving for thelarger root and setting t greater than it, we obtain

t >1 +

√1 + 8N

2implies that ai + aj = ak + am

for two distinct pairs of distinct indices {i, j} 6= {k,m}.

*Example 10 (Subset sums) In the set S = {1, 2, 3, 4} there are two different (not equalas sets) subsets P ⊂ S and Q ⊂ S such that the sum of the entries in P (designated by∑

P ) equals the sum of the entries in Q (take P = {1, 2, 3} and Q = {2, 4}). We say thatthe set S = {1, 2, 3, 4} has the two-sum property. In the set S = {1, 2, 4, 8} there is no suchpair of subsets. This set fails to have the two-sum property. Suppose we start with a set

EO-6

Page 7: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 1: Equivalence

U = n = {1, 2, . . . , n}. What conditions can we put on k such that every subset S ⊂ Uof size k has the two-sum property; i.e., S has a pair of distinct subsets P and Q with∑

P =∑

Q? This question has the aura of a pigeonhole problem, but how do we describethe function and coimage?

We will look just at the case n = 16. Thus U = 16. What is the largest subset ofU that does not have the two-sum property? Call the size of this set T (16). Using thepigeonhole principle, we will show that every S ⊂ U of size 7 has the two-sum property.You can check that {1, 2, 4, 8, 16}, a subset of size 5, does not have the two-sum property.2

Thus T (16) ≥ 5. Assuming the above mentioned result for sets of size 7, we now know thateither T (16) = 5 or T (16) = 6. After searching for a subset of size 6 that does not havethe two-sum property, you may become convinced that T (16) = 5. Unless you looked atall of the

(

166

)

= 8, 008 subsets, this is not a proof. Using a computer program to do this,we found that each of these 8,008 subsets has the two-sum property and so T (16) = 5.

Such gaps (Is T (16) = 5 or 6?) are common in applications of the pigeonhole principle.Any careful study of this problem would have to go into such gaps between the largestcounterexample we have found (k = 5) and the smallest k for which the pigeonhole principleworks (k = 7). This is an annoying feature of the pigeonhole principle in many cases whereit is applied.

We now show that every S ⊆ 16 with |S| = 7 has the two-sum property.

A subset S ⊆ U with |S| = k has 2k subsets. If we are going to find distinct subsetsP and Q of S with

P =∑

Q, then clearly neither P nor Q can be empty or equal to S.It seems that we want to apply the pigeonhole principle to the set K of all subsets of a setS, except ∅ and S. There are 2k − 2 such subsets. The function f : K → R will be givenby f(P ) =

P for P ∈ K. What is R? It is all possible subset sums. We need to workthis out.

The value of the sum of the entries over such a subset can be as small as 1 and as largeas r = (16− (k− 2))+ (16− (k− 3))+ · · ·+16 (the largest sum of any k− 1 elements fromU). The pigeonhole principle assures us that there will be two distinct elements X and Yin K with f(X) = f(Y ) if |K| > |R|. In other words, if 2k − 2 > r. Using a calculator, wesee that the first k that satisfies this inequality is k = 7. Thus, any subset S ⊆ 16 of size 7or larger has the two-sum property.

The pigeonhole principle answers the question

When must a partition of a set have a block of size at least two?

Sometimes that’s not enough. For example, what if we want more than two people to havethe same birthday? This is as easy to answer as the original question:

Theorem 3 (Extended pigeonhole principle) Suppose f : S → R is a function,|R| = r and |S| = s. The coimage of f must have a block of size ⌈s/r⌉ or larger.

2 You should be able to see why this is so by thinking in terms of the binary numbersystem: every positive integer has a unique representation as sums of powers of 2.

EO-7

Page 8: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

Proof: Suppose the Coimage(f) has t blocks. Since |R| = r, we have t ≤ r. Let{B1, B2, . . . , Bt} be the blocks of Coimage(f) and suppose |Bi| < s/r for i = 1, . . . , t.Now

s = |S| = |B1| + |B2| + · · · + |Bt| < (s/r) + (s/r) + · · · + (s/r) = (s/r)t ≤ (s/r)r = s,

a contradiction. Thus some Bi has |Bi| ≥ s/r. Since the size of a block is an integer ands/r may not be an integer, we can assert that Coimage(f) must have at least one block ofsize greater than or equal to ⌈s/r⌉.

For example, how many people must we have to be sure that at least k have the samebirthday? Let s be the number of people. Since there are 366 possible birthdays, r = 366.By the theorem, it suffices to have ⌈s/366⌉ ≥ k. In other words, s/366 > k − 1. Thuss > 366(k − 1) guarantees that at least k out of s people must have the same birthday.

In some instances, the most difficult part of applying the pigeonhole principle is findingthe right partition (equivalence relation). The next example is of this type.

*Example 11 (Monotone subsequences) A sequence is monotonic if it is either de-creasing or increasing.

Consider the sequence 7, 5, 2, 6, 8, 1, 9. Starting at a term, say 2, we can move tothe right selecting a subsequence (not necessarily consecutive) that is increasing: 2, 6, 8, 9.Or, starting at 2 we could do the same, only selecting a decreasing subsequence: 2, 1.

In a general sequence, we cannot guarantee a long increasing subsequence — the num-bers in the sequence might be decreasing. Similarly, we cannot guarantee a long decreasingsubsequence. However, we might hope to guarantee a long monotonic subsequence. For ex-ample, the longest decreasing subsequence in our example is 2, 1, but there is a monotonicsubsequence of length 4.

Let’s use the pigeonhole principle for the general case. Suppose we start with a se-quence of length m, a1, a2, . . . , am, where the terms are distinct real numbers. How longan increasing or decreasing subsequence must be present?

Suppose at = ad1, ad2

, . . . , adkis a decreasing subsequence of length k starting at at

and that at = ai1 , ai2 , . . . , ailis an increasing subsequence of length l starting at at.

• If at−1 > at, then at−1, ad1, ad2

, . . . , adkis a decreasing subsequence of length k + 1

starting at t − 1.

• If at−1 < at, then at−1, ai1 , ai2 , . . . , ailis an increasing subsequence of length l + 1

starting at t − 1.

Thus the length of either the increasing or decreasing sequence has increased by 1.

Let’s formalize this a bit. Let Dt and It be the lengths of the longest decreasing andlongest increasing subsequences starting at at. We’ve just shown that either Dt−1 = Dt +1or It−1 = It+1. Thus (It−1,Dt−1) 6= (It,Dt). All we used was that t−1 is less than t. Thuswe can replace t−1 by any u < t in the above argument to conclude that (Iu,Du) 6= (It,Dt)whenever u < t. In other words, f : m → Z × Z given by f(t) = (It,Dt) is an injection.

EO-8

Page 9: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 1: Equivalence

We’re ready to apply the pigeonhole principle. Why? The pigeonhole principle tells uswhen f cannot be an injection because the pigeonhole principle guarantees that Coimage(f)has a block of size greater than one.

Suppose that the overall longest increasing sequence has length ι (“iota”) and theoverall longest decreasing sequence has length δ (“delta”). Thus the image of f is containedin ι × δ and so |Coimage(f)| ≤ ιδ. Suppose ιδ < m. By the pigeonhole principle, theremust be p < q with f(p) = f(q), a contradiction because we know f is an injection.

We have shown that, if the longest decreasing subsequence has length δ and the longestincreasing subsequence has length ι, then the sequence has length at most ιδ. In otherwords, m ≤ ιδ.

Put another way, we have shown that, if m > αβ for some integers α and β, then theremust be either an increasing subsequence longer than α or a decreasing subsequence longerthan β. For example, if m = 100, there is either an increasing subsequence of length atleast 12 or a decreasing subsequence of length at least 10 because 100 > 99 = 11× 9. If wewrite 99 = 9 × 11, we see that there is either an increasing subsequence of length at least10 or a decreasing subsequence of length at least 12.

How long a monotonic subsequence must a sequence of length m have? In this case,we take α = β = n because we want to make sure the subsequence is long whether it isincreasing or decreasing. If m > n2, there must be a monotonic subsequence of length n+1or greater. Of course, if there is a monotonic subsequence of length at least n + 1, thenthere is one of length exactly n + 1: just throw some elements if the subsequence is toolong.

Sometimes, in working problems concerning partitions, there are restrictions on blocksizes. In such cases, can be useful to list the possible type vectors. A type vector ~v for apartition has vi equal to the number of blocks containing exactly i elements. For example,we list all type vectors for partitions of S = 15 with maximum block size 4 and exactly 5blocks. Since vi = 0 for i > 4, we give just v1, . . . , v4.

1 2 3 41 1 0 31 0 2 20 2 1 20 1 3 10 0 5 0

The top row represents the block sizes, ranging from 1 to maximum size of 4. The remainingrows tell us how many blocks of each size there are (i.e., these rows correspond to the typevectors). You should think carefully about why this list of type vectors is complete for therestrictions given.

In the exercises for this section you are asked to solve a problem related to the followingsituation: “Fifteen clients are being defended against lawsuits by a group of five lawyers.Each client is assigned exactly one lawyer and no lawyer is to represent less than one or morethan four clients.” To see the connection between this problem and partitions, note firstthat the condition that each client be assigned one lawyer specifies that the correspondencebetween clients and lawyers is a function, with domain size 15 (the clients) and codomain

EO-9

Page 10: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

size 5 (the lawyers). The condition that no lawyer is to represent less than one or morethan four clients specifies that the function is onto and that the maximum block size of thecoimage is four. That the function is onto and the codomain has five elements says thatthere are exactly five blocks in the coimage. Thus, the above table lists the type vectors ofall coimages for allowable correspondences between clients and lawyers.

Exercises for Section 1

1.1. Let S be the set of students in a college. Define students x ≡ y to be related if theyhave both the same age and the same number of years completed in college. Showthat ≡ is an equivalence relation by defining a function a whose coimage is the setof equivalence classes of ≡.

1.2. Let Z be the integers with d a positive integer. Define integers x ≡ y to be relatedif d | (x−y). Show that ≡ is an equivalence relation by defining a function m whosecoimage is the set of equivalence classes of ≡.

1.3. Let Fn be the set of all statement forms in n Boolean variables. Define forms x ≡ yto be related if they have the same truth table. Show that ≡ is an equivalencerelation by defining a function t with coimage the equivalence classes of ≡.

1.4. Let Z be the integers with d and k positive integers. Define x ≡ y to be related ifd | (xk − yk). Show that ≡ is an equivalence relation on Z by defining a functionm whose coimage is the set of equivalence classes of ≡.

1.5. Let R be the real numbers. Define x ≡ y to be related if x − y ∈ Z. Show that ≡is an equivalence relation on R by defining a function u whose coimage is the set ofequivalence classes of ≡.

1.6. In any group of 677 people, there must be at least two who have the same first andlast letters of their names. Explain.

1.7. In each case give an explanation in terms of functions and coimages.

(a) Must any set of k > 1 integers have at least two with the same remainder whendivided by k − 1?

(b) Must any set of k > 1 integers have at least two with the same remainder whendivided by k?

1.8. What is the smallest integer k such that every k-element subset of the set S = nmust always contain a pair of elements whose sum is n + 1?

EO-10

Page 11: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 1: Equivalence

1.9. Let n ≥ 1 be an integer. What is the smallest integer k such that every k-elementsubset of the set S = {0, 1, 2, . . . , n} must always contain an even integer? Mustalways contain an odd integer?

1.10. What is the smallest integer k such that any set S of k integers selected from theset 50 = {1, 2, . . . , 50} will always have two distinct integers, x ∈ S and y ∈ S suchthat gcd(x, y) > 1? (gcd(x, y) is the greatest common divisor of x and y.)

1.11. What is the smallest integer k such that any set S of k people must have at leastthree people who were born in the same month of the year?

1.12. Let P be a group of 30 people. Let f be the function from P to M , where M = 12represents the 12 months of the year, and f(x) is the birth-month of x. Amongsuch a group, there need not be any group of four people that have the same birth-month. One way this can happen is if Coimage(f) has ten blocks of size three.Describe the structure of the coimage of all other examples. What are their typevectors?

1.13. Some cultures divide a day into “quarter days” in order to pay respect to the tidalcycle (four six hour tidal cycles in each 24 hour period). There are 1461 ATCs(Annual Tidal Cycles) per solar year. What is the smallest integer k such thatamong k people there are at least four born in the same ATC?

1.14. There are N students in a class. Their exam scores ranged between 27 and 94. Allpossible scores were achieved by at least one student except for the scores 31, 43,and 55 (none of the students got these scores). What is the smallest value of Nthat guarantees that at least three students achieved the same score?

1.15. There are twelve 1967 pennies, seven 1968 pennies, and four 1971 pennies in a jar.Let Nk denote the smallest number of pennies you need to select to guarantee thatyou have k pennies of the same date. Find N4, N6 and N8.

1.16. Let t1, t2, . . . tn be n integers. Show that either n | tk for some k or n | (ti − tj) forsome i 6= j.

1.17. Let n > 1 be an integer. What is the smallest value of k such that, given any kdistinct integers, t1, t2, . . . tk, there must be two of them ti and tj , i 6= j, such thateither n | (ti − tj) or n | (ti + tj)?Hint: We want ti and tj to go in the same pigeonhole if either ti = −tj mod n (sothat n | (ti + tj)) or ti = tj mod n (so that n | (ti − tj)).

1.18. Let n > 1 be an integer. What is the smallest value of m such that, given any mdistinct integers, t1 < t2 < · · · < tm, chosen from the set S = n, there must be

EO-11

Page 12: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

i < j, such that ti | tj .Hint: Remove all factors of 2 from the elements of S.

*1.19. We want to show that m ≤ ιδ in Example 11 is best possible. In other words,there exist sequences of length ιδ with longest increasing subsequence of length ιand longest decreasing subsequence of length δ.

(a) Construct a sequence of length ι whose longest decreasing subsequence haslength δ = 1 and whose longest increasing subsequence has length ι.

(b) Construct a sequence of length 2ι whose longest decreasing subsequence haslength δ = 2 and whose longest increasing subsequence has length ι.

(c) Construct a sequence of length δι whose longest decreasing subsequence haslength δ and whose longest increasing subsequence has length ι.

*1.20. Suppose m = pq and an m-long sequence of distinct real numbers does not have a p-long decreasing subsequence. Prove that it has has a q-long increasing subsequence.

*1.21. Suppose m > n4. Let (a1, b1), . . . , (am, bm) be an m-long sequence where the ai

and bj are distinct real numbers. The goal of this exercise is to prove that thereis an (n + 1)-long subsequence (at1 , bt1), . . . , (atn+1

, btn+1) such that the sequences

at1 , . . . , atn+1and bt1 , . . . , btn+1

are both monotone.

(a) Let k = n2 + 1. Prove that the sequence a1, . . . , am has a k-long monotonesubsequence. Call it as1

, . . . , ask.

(b) Prove that the subsequence bs1, . . . , bsk

has an (n + 1)-long monotone subse-quence. Call it bt1 , . . . , btn+1

.

(c) Prove that the indices t1, . . . , tn+1 solve the problem.

1.22. Fifteen clients are being defended against lawsuits by a group of five lawyers. Eachclient is assigned exactly one lawyer and no lawyer is to represent less than oneor more than four clients. Show that if two lawyers are assigned less than threeclients, at least two must be assigned four clients.

Section 2: Order

In Theorem 1 we showed the connection between certain binary relations on a set S andpartitions of the same set. In this section we will study binary relations that are, as before,reflexive and transitive, but, instead of being symmetric, are “antisymmetric.” We beginby defining the most general idea of a relation from one set to another and, specializingfrom that, defining the central theme of this section, order relations.

Definition 3 (Order relation, partially ordered set, poset) Binary relations aredefined in Definition 2. If R is a binary relation on S, then (x, y) ∈ R is also denoted byx R y. Likewise, (x, y) /∈ R is denoted by x 6R y.

EO-12

Page 13: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

A binary relation on a set S is called an order relation if it satisfies the following threeconditions and then it is usually written x � y instead of x R y.

(i) (Reflexive) For all s ∈ S we have s � s.

(ii) (Antisymmetric) For all s, t ∈ S such that s 6= t, if s � t then t 6� s.

(iii) (Transitive) For all r, s, t ∈ S such that r � s and s � t we have r � t.

A set S together with an order relation � is called a partially ordered set or poset. Formally,a poset is a pair (S,�). We shall, once the binary relation is defined, refer to the poset bythe set S alone, not the pair.

Order relations and equivalence relations appear similar: Both are reflexive and transi-tive. The only difference is that one is antisymmetric and the other is symmetric. Althoughthis may seem a small difference, it makes a big difference in two types of relations, asyou’ll see if you compare the examples of order relations in this section with the examplesof equivalence relations in the previous section.

If we use the alternative notation R for the relation, then the three conditions for anorder relation are written as follows.

(i) For all s ∈ S we have (s, s) ∈ R.

(ii) For all s, t ∈ S such that s 6= t, if (s, t) ∈ R then (t, s) /∈ R.

(iii) For all r, s, t ∈ S such that (r, s) ∈ R and (s, t) ∈ R we have (r, t) ∈ R.

In the exercises for this section, you will get a chance to think about various binary rela-tions on a set S that may or may not satisfy the conditions of being reflexive, symmetric,antisymmetric, or transitive.

Example 12 (Some partially ordered sets) You are already familiar with a numberof basic sets S with order relations R (posets for short).

Total orders: Let S = Z, the integers, and define nR m if n ≤ m (usual orderingon integers). Clearly n ≤ n for all n ∈ Z (reflexive condition). For n,m ∈ Z, if n 6= mand n ≤ m, then m 6≤ n (antisymmetric condition). For all p, q, and r in Z, if p ≤ q andq ≤ r, then p ≤ r (transitive condition). We call the relation ≤, the natural ordering of theintegers. This same ordering applies to any subset of Z. For example,take S = n (the firstn positive integers) ordered by ≤. This S is a poset. The natural ordering on the integershas an additional property, namely, for all n,m ∈ Z, either m ≤ n or n ≤ m. The orderrelation ≤ is called a total ordering or linear ordering because, for any two elements x andy, either x ≤ y or y ≤ x (or both if x = y). The relation ≤ can be extended to the realnumbers R and the rational numbers Q.

Subset lattice: Given a set X, let S = P(X) be the power set of X (the set of allsubsets of X). For A,B ∈ P(X) we can define AR B by A ⊆ B. The relation ⊆ is an orderrelation (called set inclusion). To check the conditions that an order relation must satisfy,note that A ⊆ A for all A ∈ P(X). For all A,B ∈ P(X), if A 6= B and A ⊆ B, then thereis some x ∈ B, x /∈ A. Thus, B 6⊆ A. We leave transitivity for you to check. The posetP(X) with the relation ⊆ is called the lattice of subsets of X.3 The subset lattice has the

3 “Lattice” is a technical term whose meaning we will not explain. It is a poset withcertain additional properties.

EO-13

Page 14: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

property that, if |X| > 1 then there are always elements A,B ∈ P(X) such that A 6⊆ Band B 6⊆ A. For example, if X = {a, b}, then A = {a} and B = {b} are such incomparable

subsets. If X = {a, b, c}, then all three subsets of size two are pairwise incomparable. If|X| = n > 1, then the set Pk(X) of all subsets of size k, for any 0 < k < n, is always anontrivial (at least two elements) collection of pairwise incomparable subsets of X. Thenumber of elements in Pk(X) is the binomial coefficient C(n, k).

Divides relation: Another familiar poset is gotten by taking a collection of positiveintegers, say S = n, and defining the relation i R j to be i | j (the divides relation). Clearly,for all i ∈ S, i | i. For all i, j ∈ S, if i 6= j and i | j, then j does not divide i (antisymmetry).If i | j and j | k, then i | k (transitivity).

We recall some definitions that were mentioned in the previous example.

Definition 4 (Incomparable elements, linear order, total order, chain) Let (S,�)be a poset. If x, y ∈ S and neither x � y nor y � x are true, we call x and y incomparable.If either x � y or y � x, we say that x and y are comparable.

If every two elements of S are comparable, (S,�) is called a linear order. It is alsocalled a total order or a chain.

Since some students have the most trouble with so called “trivial” situations, we takea look at those in the next example.

Example 13 (Trivial examples of binary relations) Suppose first that S = ∅. SinceS is empty, so is S × S. Hence the only binary relation on S is R = ∅. Is R reflexive?symmetric? transitive? Yes. One way to see this is to note that the conditions talk aboutall s ∈ S (and possibly r and t). Since there is nothing in S, there is nothing to check.Another way to see this is to look at how you show a condition is not satisfied. For example,the way you show something is not reflexive is to find an x ∈ S such that (x, x) /∈ R. SinceS is empty, it is impossible to find such an x ∈ S. Thus, R is reflexive. Similarly, it is alsosymmetric, antisymmetric and transitive.

Suppose S is not empty, but R is empty. Then, if we choose any x ∈ S, (x, x) /∈ R.Thus, R is not reflexive. What about symmetric? To show that R is not symmetric, weneed to find x, y ∈ S such that (x, y) ∈ R, but . . . (stop right here). We can’t do this becauseR is empty. Thus R is symmetric. For the same basic reason, R is also antisymmetric andtransitive.

Most cases are of the form R ⊆ S × S with R (and thus S) not empty. The smallestcase is |S| = 1 and |R| = 1. In this case, if S = {a}, then S × S = {(a, a)} and soR = {(a, a)}. You should be able to verify that R is reflexive, symmetric, antisymmetricand transitive.

The next simplest case is |S| = 2. Things are suddenly more complicated. There arefour elements in S × S. Thus 24 = 16 choices for R, fifteen of which are nonempty. Toget a feeling for the situation, we look at some incidence matrices for R. These are 2 × 2matrices whose rows and columns are labeled with the elements of S. The entry (x, y) is 1

EO-14

Page 15: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

if (x, y) ∈ R and is 0 if (x, y) /∈ R. Here are six of the fifteen possible incidence matricesfor S = {a, b}:

a ba 1 1b 0 0

A

a ba 1 0b 0 1

B

a ba 1 1b 1 0

C

a ba 1 0b 1 0

D

a ba 1 0b 1 1

E

a ba 1 1b 1 1

F

The first matrix A describes the binary relation {(a, a), (a, b)} because A(a, a) = A(a, b) =1 and A(b, a) = A(b, b) = 0. The entries in positions (a, a) and (b, b) are called the entries onthe “main diagonal” of A. Positions (a, b) and (b, a) are “symmetric off-diagonal positions”about the main diagonal and their entries are “symmetric off-diagonal entries” with respectto A. The relation defined by A (or more simply, “the matrix A”) is not reflexive, isantisymmetric, is not symmetric, and is transitive. With regard to the last statement, notethat, since R = {(a, a), (a, b)}, there is not really anything to check since combining (a, a)with (a, b) using transitivity just gives us (a, b) again. This is always true: we never needto use a diagonal entry like (a, a) in checking transitivity. On the other hand, matrix C isnot transitive because (b, a) ∈ R and (a, b) ∈ R would give us (b, b) ∈ R, which is not true.Note that there is already a lesson here. If symmetric off-diagonal entries are both 1, buteither of their corresponding diagonal entries is not 1, then the relation is not transitive.This is true for the incidence matrix of any relation. For the various matrices we have

reflexive symmetric antisymmetric transitive

A no no yes yesB yes yes yes yesC no yes no noD no no yes yesE yes no yes yesF yes yes no yes

You should make sure you understand the reasons for all of these statements.

Example 14 (Counting relations) As we have seen in the previous example, relationson a set S correspond to matrices of zeroes and ones (the incidence matrices). A relationon a four element set, for example, corresponds to a 4 × 4 matrix of zeroes and ones (anincidence matrix). The matrix below, with appropriate substitutions of 0’s and 1’s for thesymbolic entries, is such an incidence matrix. The rows and columns should be labeledwith the four elements of the set (as in the previous example, where we worked with 2× 2incidence matrices), but we omit that here for simplicity.

Since an n × n matrix has n2 entries and each entry can be either a 0 or a 1, thereare 2n2

such matrices. This number grows very rapidly; for example, when n = 4 we have242

= 216 = 65, 536.

Let’s look at 4× 4 matrices We could think of starting with a matrix, such as the onebelow, labeled with symbols di (for diagonal), ui (for upper), and li (for lower), and then,in some manner (just how is up to us) substituting zeroes and ones for the sixteen symbols.

d1 u1 u2 u3

l1 d2 u4 u5

l2 l4 d3 u6

l3 l5 l6 d4

EO-15

Page 16: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

• If we want the relation to be reflexive, we must make all the di = 1.

• If we want the relation to be symmetric, then we must have ui = li for all i.

• If we want the relation to be antisymmetric, then we can never have ui = li = 1 forany i (but ui = li = 0 is allowed).

You should make sure you understand the reasons for these three statements. You mayhave noticed that transitivity was not mentioned. It cannot be described in such simpleterms.

The 4 × 4 matrix above can easily be extended to a general n × n matrix. As wecontinue to describe certain properties of the 4× 4 case, you should think about how thesedescriptions extend to the n×n case. As far as the situations just described, we do exactlythe same thing in the n × n case.

From what we have just said, there are 212 reflexive relations on a four element set.Why? We must set all of the di = 1 and then we can choose freely the ui and li to be 0 or1. There are 12 total ui and li, giving 212 choices. In general, there are n2 − n entries inan n × n matrix which are not di’s. Thus there are 2n2

−n = 2n(n−1) reflexive relations ona set with n elements.

Let’s try one more example. How many relations are both reflexive and antisymmetric?All of the di = 1. For each pair (li, ui), we have three choices: (li, ui) = (0, 0), (li, ui) =(1, 0), (li, ui) = (0, 1). In the 4 element case there are 36 such relations. What is theformula for general n? We have seen that there are n2 − n elements li and ui and so thereare (n2 − n)/2 pairs (li, ui). Thus there are 3(n2

−n)/2 relations on an n-set which are bothreflexive and antisymmetric.

Example 15 (Partitions of a set) The collection Π(S) of all partitions of a set S canbe made into a poset. Let S = 15. Consider the following partition of S:

α ={

{1}, {2}, {9}, {3, 5}, {4, 7}, {6, 8, 10, 15}, {11, 12, 13, 14}}

.

We can refine the partition α by taking any block or blocks with at least two elementsand splitting each of them into two or more blocks. For example, we could choose theblock {6, 8, 10, 15} and split it into two blocks: {6, 15}, {8, 10}. We could also choose theblock {11, 12, 13, 14} and split it into (for example) three blocks: {13}, {14}, {11, 12}. Theresulting partition β is called a refinement of α (we write β � α):

β ={

{1}, {2}, {9}, {3, 5}, {4, 7}, {6, 15}, {8, 10}, {13}, {14}, {11, 12}}

.

The set of all partitions of S, Π(S), together with the refinement relation is a poset — thelattice of partitions of S. By definition, α � α for any α ∈ Π(S). We leave it to you tocheck antisymmetry and transitivity.

EO-16

Page 17: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

New Posets from Old Ones

We now examine restrictions, direct products and lexicographic order, which are three waysof forming new posets from old ones.

Definition 5 (Restriction of a poset) Let (S,�) be a poset and let X be a subsetof S. For u, v ∈ X, define the order relation �X by u �X v if and only if u � v in (S,�).We call (X,�X) a subposet of S or the restriction of S to X. Instead of introducing a newsymbol �X for the order relation, one usually uses �, writing (X,�).

Example 16 (Restrictions of posets) Consider the divides poset on S = 20. LetX = {2, 4, . . . , 20} — the even numbers in S. The set X with the same divides relation is asubposet of S or a restriction of S to X. Alternatively, let Y be the divisors of 20, namely{1, 2, 4, 5, 10, 20} with the same divides relation. This is also a subposet.

As another example, consider the subset lattice P(S), S = {a, b, c}. Remove from thisposet the empty set and the set S. This gives a new poset P ′(S) with six elements (sixsubsets of S) ordered by set inclusion. The poset P ′(S) is a subposet of P(S):

P ′(S) ={

{a}, {b}, {c}, {a, b}, {a, c}, {b, c}}

.

Since this is a restriction of P(S), it still has “subset of” as the order relation.

Example 17 (Direct products of posets) Suppose we have two posets P and Q. Let�P be the relation on P and �Q be the relation on Q. The direct product of the posets(P,�P ) and (Q,�Q) is the poset (P × Q,�) where (p1, q1) � (p2, q2) if p1 �P p2 andq1 �Q q2. Sometimes this product order is called “coordinate order.” Just as we can defineCartesian product of several sets, we can define the direct product of several posets.

A simple application of this idea is to take P = Q = {0, 1}. Then,

P × Q = {(0, 0), (0, 1), (1, 0), (1, 1)}

has just four elements. Suppose S = {a, b} is a two-element set. We can think of theelements of P × Q as the one-line forms for the functions f : S → {0, 1}. With each ofthese functions is associated the subset f−1(1) of S. Using one-line notation for functionswith S in the order (a, b), we see that

• (0, 0) corresponds to the empty set,

• (0, 1) corresponds to the set {b},• (1, 0) corresponds to the set {a}, and

• (1, 1) corresponds to the set {a, b}.

EO-17

Page 18: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

In this way the four functions f : S → {0, 1} become alternative descriptions of the foursubsets of the subset lattice P(S). Thought of in this way, they are called the characteristic

functions of the subsets of S. The poset of characteristic functions with coordinate orderis just another way to describe the subset lattice with set inclusion.

Instead of a two element subset, we could consider an n-set S. In this case, we formthe direct product of n copies of P = ({0, 1},≤). The characteristic function is a bijectionfrom P(S) to n-long vectors of zeroes and ones. We leave it to you to fill in the details.

Is the direct product of posets again a poset? Yes. In fact we now define the directproduct of binary relations and prove that properties are “inherited.”

Definition 6 (Direct product of binary relations) Let S1, S2, . . . , Sn be sets and letRi be a binary relation on Si for i = 1, . . . , n. The direct product is the Cartesian productS = S1 × S2 × · · · × Sn with the binary relation R defined by

(a1, a2, . . . , an) R (b1, b2, . . . , bn) if and only if ai Ri bi for i = 1, 2, . . . , n.

You should verify that this definition gives the definition for the direct product of posetswhen the (Si, Ri) are all posets.

The following theorem implies that the direct product of posets is again a poset. Thereare four statements in one — choose any property in the first { } and then choose the sameproperty in the second { }

Theorem 4 (Properties of direct products) If each of the binary relations Ri on

the set Si is

reflexivesymmetric

antisymmetrictransitive

, then the direct product is also

reflexivesymmetric

antisymmetrictransitive

.

Proof: We prove transitivity and leave the rest to you. Suppose that

(a1, a2, . . . , an) R (b1, b2, . . . , bn) and (b1, b2, . . . , bn) R (c1, c2, . . . , cn)

From the definition of R, ai Ri bi and bi Ri ci for i = 1, . . . , n. Since Ri is transitive,ai Ri ci for i = 1, . . . , n. By the definition of R, (a1, a2, . . . , an) R (c1, c2, . . . , cn). Thisproves transitivity of R.

Definition 7 (Isomorphism of posets) Let (S,�S) and (T,�T ) be posets. We saythe posets are isomorphic if we have a bijection f : S → T such that x �S y if and only iff(x) �T f(y). We then call f an isomorhism between the posets.

In Example 17, we used the characteristic function to construct an isomorphism be-tween the subset lattice and the direct product P ×· · · ×P where P = ({0, 1},≤). We nowlook at another example.

EO-18

Page 19: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

Example 18 (The divisibility relation again) Let T = {1, 2, 3, 4, 6, 12}, the set ofdivisors of 12, and let the order relation be “divides.” Consider the two chains (linearorders) C2 = {1, 2, 4} and C3 = {1, 3} where the ordering can be thought of as eitherdivisibility or ordinary ≤ since it gives the same ordering.

The posets T and S = C2 × C3 describe the same situation. To see this, let(a, b) ∈ C2 × C3 correspond to ab ∈ S. In this case f((a, b)) = ab and the posets areisomorphic.

The previous idea can be applied to the set of divisors of n for any n > 0. The numberof chains will equal the number of different primes dividing n.

We looked at the divisors of 12. What about the set 12 of positive integers less thanor equal to 12 ordered by divisibility? This is not isomorphic to a direct product of chains.However, it is isomorphic to a restriction of a direct product of chains. Here is one way todo this. Let

V = ({1, 2, 4, 8}, | ) × ({1, 3, 9}, | ) × ({1, 5}, | ) × ({1, 7}, | ) × ({1, 11}, | ).

The map f((a, b, c, d, e)) = abcde shows that V is isomorphic to W the poset of divisors of8 × 9 × 5 × 7 × 11 with the divides relation. Since 12 ⊂ W , 12 is a subposet W .

The next concept, when applied to products of linearly ordered sets, is one of the mostuseful elementary ideas to be found in computer science. It’s found in every subdisciplineof computer science and in almost every program of any length or complexity.

Definition 8 (Strings and lexicographic order) Let (S,�) be a poset. We use S∗

to denote the set of all “strings” over S; that is S∗ contains

• for each k > 0, the set of k-long strings (x1, . . . , xk) of elements in S, which is denotedSk = ×kS;

• the empty string ǫ.

We now define a relation �L on S∗. This relation is called lexicographic order or, morebriefly, lex order. Let (a1, a2, . . . , am) and (b1, b2, . . . , bn) be two elements of S∗ with m,n >0. We say that

(a1, a2, . . . , am) �L (b1, b2, . . . , bn)

if either of the following two conditions hold:

(1) m ≤ n and ai = bi for i = 1, . . . ,m.

(2) For some k < min(m,n), ai = bi, i = 1, . . . , k, ak+1 6= bk+1, and ak+1 � bk+1.

In addition we have a third condition:

(3) For the empty string ǫ, we have ǫ �L x for every string x ∈ S∗.

Notice that we said “define a relation �L on S∗” rather than “define a partial order �L

on S∗.” Why is that? By its definition, �L is obviously a relation. The fact that it is apartial order requires proof. We’ll give a proof after the next example.

EO-19

Page 20: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

The term “lexicographic” comes from the listing of words in a dictionary. One writesS0 = {ǫ} and so S∗ = ∪∞

k=0Sk. Other notations for the k-tuple (x1, x2, . . . , xk) are

x1, x2, . . . , xk (leave off the parentheses) or x1x2 . . . xk (leave off the parentheses and thecommas). Each of these latter notations leaves off information and can be confusing (forexample, 112131212131414 = (11, 21, 312, 121, 31414), or does it?). Mostly, we will stick tothe full notation (vector notation). Such k-tuples are sometimes referred to as strings of

length k over S. The term “words” over S is also used in this context as meaning the samething as “strings.”

Example 19 (Lexicographic order) At this stage, all we know is that �L is a rela-tion on strings. Consider the lattice of subsets of {1, 2, 3}; that is, (P({1, 2, 3}),⊆). ByCondition (1),

({1}, {2}, {1, 3}) �L ({1}, {2}, {1, 3}, {1, 2}).By Condition (2),

({1}, {2}, {1}, {1, 2}) �L ({1}, {2}, {1, 3}).On the other hand,

({1}, {2}, {1, 2}) 6�L ({1}, {2}, {1, 3})and

({1}, {2}, {1, 3}) 6�L ({1}, {2}, {1, 2}).The two strings ({1}, {2}, {1, 2}) and ({1}, {2}, {1, 3}) are incomparable in lex order because{1, 2} and {1, 3} are incomparable in the subset lattice. If, on the other hand, S is linearlyordered (it is not in this example where S is the lattice of subsets) then S∗ with lex orderis linearly ordered.

We now prove that the lexicographic relation in Definition 8 is an order relation onS∗.

Theorem 5 (The relation �L is an order relation) Let S be a set with order relation�. Let �L be the lexicographic relation on the strings S∗. Then, �L is an order relationon S∗. If the poset S is linearly ordered, so is S∗.

*Proof: In the proof, we refer to the conditions (1), (2) and (3) of that discussion. Wealso omit commas and parentheses in the strings as there is no possibility of confusion.

First we show that the reflexive property is true. Let w ∈ S∗. If w = ǫ is the nullstring, then the reflexive property follows from Condition (3). If w = a1a2 · · · am withm ≥ 1 then the reflexive property follows immediately from Condition (1).

Next we show the antisymmetric property. Suppose that

a1a2 · · · am �L b1b2 · · · bn and b1b2 · · · bn �L a1a2 · · · am.

This would be impossible if either of these relations were due to Condition (2) since ak+1 �bk+1 and ak+1 6= bk+1 implies bk+1 6� ak+1. We have used here the fact that � is apartial order relation on S and hence is antisymmetric. Thus both relations are due to

EO-20

Page 21: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

Condition (1). Hence, m ≤ n and n ≤ m, so m = n, and ai = bi for 1 ≤ i ≤ m. Thisproves the antisymmetric property.

Next we show the transitive property. Suppose that

a1a2 · · · am �L b1b2 · · · bn and b1b2 · · · bn �L c1c2 · · · ct.

If m = 0 (the empty string), transitivity is trivial by Condition (3). Thus we may supposem,n, t > 0. We consider cases.

• If both �L relations are due to Condition (1) then a1a2 · · · am �L c1c2 · · · ct fromCondition (1) also.

• If a1a2 · · · am �L b1b2 · · · bn is due to Condition (1) but b1b2 · · · bn �L c1c2 · · · ct isdue to Condition (2), let k be the smallest integer such that bk+1 6= ck+1. If k < mthen, using the fact that � is a partial order, a1a2 · · · am �L c1c2 · · · ct follows fromCondition (2), otherwise (i.e., k ≥ m) it follows from Condition (1).

• If a1a2 · · · am �L b1b2 · · · bn is due to Condition (2) but b1b2 · · · bn �L c1c2 · · · ct is dueto Condition (1), the proof is similar to the preceding case.

• Finally, if a1a2 · · · am �L b1b2 · · · bn and b1b2 · · · bn �L c1c2 · · · ct are both due toCondition (2), then, using the fact that � is a partial order relation, a1a2 · · · am �L

c1c2 · · · ct follows from Condition (2) also.

We have proved that �L is an order relation.

It remains to show that if the poset S is linearly ordered, so is S∗. Suppose that weare given any two strings a1a2 · · · am and b1b2 · · · bn. Suppose, without loss of generality,that m ≤ n. Then either

(a) a1 = b1, . . . , am = bm or

(b) there is a smallest k < m such that ak+1 6= bk+1.

We consider cases.

• If (a) holds, then a1a2 · · · am �L b1b2 · · · bn by Condition (1).

• If (b) holds, then either a1a2 · · · am �L b1b2 · · · bn or b1b2 · · · bn �L a1a2 · · · am byCondition (2). This follows since either ak+1 � bk+1 or bk+1 � ak+1, because � is alinear order.

We have shown that, given any two strings, either the first is less than or equal to thesecond in lex order or the reverse. Thus, S∗ is linearly ordered by lex order.

There is a variation on lex order on S∗ which first orders the strings by length. Stringsof the same length are then ordered lexicographically by restricting the above definition tosubsets of S∗ of the same length. This order relation is called short lexicographic order orlength-first lexicographic order.

We now present an alternative proof of the theorem. You may find this proof harder tofollow because it is somewhat more abstract. So why give it? It illustrates some techniquesthat are often used by people doing mathematics. Specifically, we will reduce an infinite

EO-21

Page 22: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

problem (S∗) to a finite one (Sm below). We then embed this in another problem (Tm

below) that lets us use previous results (Theorem 4).

Proof: Review Definitions 5 and 6 on restrictions and direct products of posets.

Let Sm = ∪mk=0S

k. We claim it suffices to prove the theorem for the restriction of(S∗,�L) to (Sm,�L) for each m = 1, 2, . . .. Why? The conditions for being a partial orderand for being a linear order refer to at most three elements of the poset. Suppose, forexample, we want to verify transitivity. Someone gives us r �L s and s �L t. Let m bethe longest length of r, s and t. Then r, s, t ∈ Sm. By the definition of a restriction �L isthe same in the restriction as it is in the full poset, so we can work in the restriction. Inother words, if the theorem is true with S∗ replaced by Sm, then it is true for S∗.

We begin by adding a “blank” to S. As we shall see, this lets us use a restriction ofa direct product. Let ⊔ be something that is not in S. You can think ⊔ as a blank space.Let T = S ∪ {⊔} and define � on T to be the same as it is on S together with ⊔ � x forall x ∈ S. We’ll still call it �. Let (Tm,�m) be the direct product of m copies of (T,�).This is a poset by Theorem 4.

Let Um be the restriction of Tm to those strings in which ⊔ is never followed by anelement of S, but may be followed by more ⊔’s. In other words, blanks appear only at theend of a string.

Define f(x) for x ∈ Sm to be x “padded out” at the end with enough blanks to givea string of length m. You should have no trouble verifying that f is a bijection from Sm

to Um. You should also check that x �L y if and only if f(x) �m f(y). This gives us anisomorphism between (Sm,�L) and the poset (Tm,�m). Thus (Sm,�L) is a poset.

Example 20 (Lexicographic bucket sort) Let S = {1, 2, 3} be ordered in the usualway (as integers). Consider all strings of length three, ×3S = S3. Take some subset of S3,say the set

A ={

(2, 1, 3), (3, 2, 3), (1, 2, 1), (2, 3, 2), (1, 1, 3), (3, 1, 1), (3, 3, 1), (2, 2, 2)}

.

We are interested in an algorithm for sorting the elements of A so that they are in lexico-graphic order. The topic of sorting is very important for computer science. The literatureon sorting methods is vast.

One type of sorting algorithm involves comparisons only. Imagine a bin of bananasthat are to be sorted by weight using only a beam balance that tells which of two bananasweighs the most. No numerical values are recorded. Start with one banana. Get anotherand compare it with the first, laying them on a table in order of weight, left to right.Each new banana is compared with the bananas already sorted until all bananas are sortedby weight. In this manner you can sort the bananas by weight without actually knowingthe numerical value of the weight of any banana. Such a sorting algorithm is called acomparison sort.

As another approach to sorting bananas by weight, suppose we have a scale that returnsthe weight of a banana to the nearest one-tenth of an ounce. Suppose we know that thebananas in the bin weigh between 4.0 oz. and 6.0 oz. We put 21 buckets on the table, thebuckets labeled with the number 4.0, 4.1, 4.2, . . . , 5.7, 5.8, 5.9, 6.0. Take the bananas from

EO-22

Page 23: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

the bin one by one and weigh them, accurate to 0.1 oz. Put each banana in the bucketcorresponding to its weight. This type of sorting is called a bucket sort.

These two basic types of sorting, as well as hybrid forms of these two types, occurin many computer related applications. Comparison sorts are used with tree-type datastructures, linked lists, etc. Bucket sorts are implemented by arrays where the bucketscorrespond to index references into an array.

Returning to the set A, we can sort the elements of A lexicographically using a variationon the bucket sort. We use three buckets, labeled 1, 2, and 3. On the first “pass” throughthe set A we place elements of

A ={

(2, 1, 3), (3, 2, 3), (1, 2, 1), (2, 3, 2), (1, 1, 3), (3, 1, 1), (3, 3, 1), (2, 2, 2)}

into buckets according to the rightmost entry in that element:

PASS 1Bucket 1: (1, 2, 1), (3, 1, 1), (3, 3, 1)Bucket 2: (2, 3, 2), (2, 2, 2)Bucket 3: (2,1,3), (3, 2, 3), (1, 1, 3)

Although A is a set and, technically, has no order, we now have imposed a linear order onA. This linear order is gotten, from the placement in the buckets, by reading the elementsin the buckets from left to right, first from Bucket 1, then from Bucket 2 and finally fromBucket 3. We obtain the Pass 1 concatenated order :

(1, 2, 1), (3, 1, 1), (3, 3, 1), (2, 3, 2), (2, 2, 2), (2, 1, 3), (3, 2, 3), (1, 1, 3).

Notice that if you just read the third elements of each vector (string) you obtain, in orderleft to right, 1, 1, 1, 2, 2, 3, 3, 3. These strings of length one are in order.

We now do PASS 2. We go through the Pass 1 concatenated order, left to right, puttingstrings into buckets based on the value of their second-from-the-right coordinate (middlecoordinate). In carrying this out, it is essential that the the order of the strings in eachbucket is the correct order relative to PASS 1 concatenated order. The term “bucket” isnot suggestive of order. Perhaps “sublist” would be better here, but we follow conventionalterminology. Here is the composition of the buckets after PASS 2:

PASS 2Bucket 1: (3, 1, 1), (2, 1, 3), (1, 1, 3)Bucket 2: (1, 2, 1), (2, 2, 2), (3, 2, 3)Bucket 3: (3, 3, 1), (2, 3, 2)

PASS 2 concatenated order is

(3, 1, 1), (2, 1, 3), (1, 1, 3), (1, 2, 1), (2, 2, 2), (3, 2, 3), (3, 3, 1), (2, 3, 2).

Note now that the list of all last two elements is in lexicographic order:

(1, 1), (1, 3), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2).

EO-23

Page 24: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

Finally, we do PASS 3, putting strings into buckets according to first elements, retainingwithin each bucket the PASS 2 concatenated order.

PASS 3Bucket 1: (1, 1, 3), (1, 2, 1)Bucket 2: (2, 1, 3), (2, 2, 2), (2, 3, 2)Bucket 3: (3, 1, 1), (3, 2, 3), (3, 3, 1)

PASS 3 concatenated order is the lexicographic order on A.

(1, 1, 3), (1, 2, 1), (2, 1, 3), (2, 2, 2), (2, 3, 2), (3, 1, 1), (3, 2, 3), (3, 3, 1).

This process extends to a general algorithm called the lexicographic bucket sort. The cor-rectness of the algorithm can be proved by induction on the number of passes (the lengthof the strings).

The lexicographic bucket sort was used in the early days of computers to sort “punchedcards” on which data was stored.

Example 21 (Lexicographic order and domino coverings) Lexicographic order isused in many computer applications where geometric objects are being manipulated asinput data. We give an example from a class of problems called “tiling problems.” Belowwe show a 3× 4 “chess board” or grid. The grid is to be tiled or “covered” with horizontaland vertical dominoes (little 1 × 2 size rectangles):

h = horizontal domino v = vertical domino

vhvhhh

hhvvvvhhvvhhhhvhvhhhhvvhhhhhhh

hvvvvhhvvhhh

3 x 4 board

vvhhhh vvhvvh vvvvhh

If the squares of the board are numbered systematically, left to right, top to bottom, from1 to 12, we can describe any placement of dominoes by a sequence of 6 h’s and v’s: Each ofthe domino placements in the above picture has such a description just below it. Take as anexample, hhvhvh (the third domino covering in the picture). We begin with no dominoeson the board. None of the squares, numbered 1 to 12 are covered. The list of “unoccupiedsquares”is as follows:

1 2 3 45 6 7 89 10 11 12

Thus, the smallest unoccupied square is 1. The first symbol in hhvhvh is the h. Thatmeans that we take a horizontal domino and cover the square 1 with it. That forces us tocover square 2 also. The list of unoccupied squares is as follows:

3 45 6 7 89 10 11 12

EO-24

Page 25: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

Now the smallest unoccupied square is 3. The second symbol in hhvhhv is also an h. Coversquare 3 with a horizontal domino, forcing us to cover square 4 also. The list of unoccupiedsquares is as follows:

5 6 7 89 10 11 12

At this point, the first row of the board is covered with two horizontal dominoes (checkthe picture). Now the smallest unoccupied square is 5 (the first square in the second row).The third symbol in hhvhvh is v. Thus we cover square 5 with a vertical domino, forcingus to cover square 9 also. The list of unoccupied squares is as follows:

6 7 810 11 12

We leave it to you to continue this process to the end and obtain the domino coveringshown in the picture.

Here is the general description of the process. Place dominoes sequentially as follows.If the first unused element in the sequence is h, place a horizontal domino on the first(smallest numbered) unoccupied square and the square to its right. If the first unusedelement in the sequence is v, place a vertical domino on the first unoccupied square andthe square just below it. Not all sequences correspond to legal placements of dominoes (tryhhhhhv). For a 2× 2 board, the only legal sequences are hh and vv. For a 2× 3 board, thelegal sequences are hvh, vhh and vvv. For a 3 × 4 board, there are eleven legal sequencesas shown in the above picture.

Having developed this correspondence between tiling of a rectangular board and stringsof letters from the set S = {h, v}, we can now list the strings that represent coverings ofthe board in lexicographic order. This order is useful for generating, storing, retrieving,and comparing domino coverings.

More Poset Concepts

In the next example we introduce a useful pictorial or geometric way of visualizing a relation.The only problem with this method of thinking about relations is that the picture canbecome much too complicated. These pictures are combined with the idea of “transitiveclosure” to deal with this growth of complexity.

EO-25

Page 26: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

Example 22 (Transitive closure and directed graph diagrams) Consider therelation R = {(1, 2), (2, 3), (2, 4), (4, 3), (4, 2)} on the set S = {1, 2, 3, 4}. Figure (a) belowis another way of representing R using a directed graph diagram. The elements of S arewritten down in some manner, in this case one after the other in a straight line (anyway will do). An arrow is drawn between i and j if and only if (i, j) ∈ R. Note thatR is not transitive. For example, (1, 2) ∈ R and (2, 3) ∈ R, but (1, 3) /∈ R. Supposewe add the missing pair (1, 3) to R as indicated in Figure (b) below. This gives a newrelation {(1, 2), (2, 3), (2, 4), (4, 3), (4, 2), (1, 3)}. This new relation is still not transitive.For example, (2, 4) ∈ R and (4, 2) ∈ R, but (2, 2) /∈ R. So, add (2, 2) to R. Keep repeatingthis process until no violations of transitivity can be found. The directed graph diagram ofthis final transitive relation is shown in Figure (b). This relation is the smallest transitiverelation that contains R. It is called the transitive closure of R.

1 2 3 4

1 2 3 4 1 2 3 4

1 2 3 4

(a)

(c)

(b)

(d)

Note that there are even smaller (fewer elements) relations than R whose transitive closure isthe same as R. The directed graph diagrams of two such relations are shown in Figures (c)and (d). By the way, we use the terminology “directed graph diagram,” so you mightnaturally wonder what is a directed graph (the thing that is being “diagrammed” here)?The answer is that directed graphs and binary relations are, mathematically, the samething. The terminology “directed graph diagram” is standard in this context, rather thanthe more natural “relation diagram.”

*Example 23 (Transitive closure and matrices) There is another way to computetransitive closure. We start the same relation, R = {(1, 2), (2, 3), (2, 4), (4, 3), (4, 2)} onthe set S = {1, 2, 3, 4}, used in the previous example. Here is the “incidence matrix” ofthis relation:

A =

0 1 0 00 0 1 10 0 0 00 1 1 0

The interpretation is that if A(i, j) = 1 then (i, j) ∈ R, else (i, j) /∈ R. If we compute the

square of A, then, by definition of matrix multiplication, A2(i, j) =∑4

k=0 A(i, k)A(k, j).Note that A2(i, j) 6= 0 if and only if there is a pair (i, t) ∈ R and (t, j) ∈ R. In other words,for this pair, A(i, t)A(t, j) = 1 so A2(i, j) > 0. For our purposes, we don’t care how big

EO-26

Page 27: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

A2(i, j) is only whether or not it is zero. So, we replace all nonzero entries in A2(i, j) by 1.This is called the “Boolean product” of A with A. We just use the same notation for thisBoolean product as for the square. Here is this Boolean product:

A2 =

0 0 1 10 1 1 00 0 0 00 0 1 1

You can think of the Boolean product as follows: Multiply matrices in the usual way bereplace “plus” with ∨ and “times” with ∧. Thus

A2(i, j) =(

A(i, 1) ∧ A(1, j))

∨(

A(i, 2) ∧ A(1, 2))

∨ · · · ∨(

A(i, n) ∧ A(1, n))

.

If we now form the “Boolean sum” A + A2 (Again, replace “plus” with ∨.) we get thefollowing matrix:

A + A2 =

0 1 1 10 1 1 10 0 0 00 1 1 1

This matrix has a 1 in position (i, j) if and only if either (i, j) ∈ R or (i, t) ∈ R and (t, j) ∈ Rfor at least one t (perhaps both of these conditions hold). In terms of the directed graphdiagram, this matrix has a 1 in position (i, j) if and only if there is a directed arrow joiningi to j or a sequence of two directed arrows that you can follow to go from i to j. Such asequence is called a directed path of length two from i to j.

We could continue this process to compute the Boolean matrix A + A2 + A3, but, ifwe do, we see that this latter matrix is the same as A + A2. A little thought should tellyou that this means A + A2 is the incidence matrix of the transitive closure of R.

This idea can be applied to any binary relation. For large relations a computer helps.You start with the incidence matrix A and keep forming Boolean partial sums Sk =

∑ki=1 Ai

until, for some k = t, St = St+1. Then we’ll have St+i = St for all i ≥ 0. At this pointSt is the incidence matrix of the transitive closure. Note that S1 = A, S2 = AS1 + A,S3 = AS2 + A, and, in general Sk+1 = ASk + A. This is a convenient way to carry outthese computations. It also makes it easy to prove the earlier claim that St+i = St: Useinduction in i and note that St+i = ASt+i−1 + A, which equals ASt + A by the inductionhypothesis.

The story doesn’t end here. We can find a similar algorithm that is much faster forlarge problems. We claim that St St + A = S2t. Why is this? If you consider ordinarymultiplication, you should see that St St consists of all the powers A2, A3, . . . , A2t addedtogether, some of them many times. Notice that when you do Boolean addition for anymatrix B, you have B + · · · + B = B. Thus St St = A2 + · · · + A2t when we do Booleanaddition and multiplication. Here’s our new algorithm:

P0 = A and Pk+1 = Pk Pk + A for k ≥ 0,

and we stop when Pk = Pk+1. You should be able to prove by induction that Pk = S2k .

EO-27

Page 28: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

Is this algorithm really faster? Yes. The simplest example of this is a chain:

S = {0, 1, . . . , n} and R = {(0, 1), (1, 2), . . . , (n − 1, n)}.

We claim that Sn+1 = Sn and the n matrices S1, S2, . . . , Sn are all different.4 Thus wemust compute S2, . . . , Sn+1 to obtain the transitive closure if we use the first algorithm.For the second algorithm, we compute P1, . . . , Pm+1 where m = ⌈log2 n⌉. Why this valueof m? We will not have Pk = Pk+1 until 2k ≥ n and m is the smallest such k. For largevalues of n, log2 n is much smaller than n.

Which algorithm should you use in the problems? It doesn’t make much differencebecause the sets S we look at are small.

Example 24 (Covering relations and Hasse diagrams) Let S be a finite poset withrelation �. We define a new relation on S called the covering relation, denoted by ≺c. Forx, y ∈ S, we say x ≺c y if

(a) x 6= y and x � y, and

(b) x � z � y implies that either x = z or y = z.

In words, x ≺c y if x and y are different and there is no third element of S “between” xand y. In this case, we say that “y covers x” or “x is covered by y.”

The condition x 6= y means that the covering relation of a nonempty set S is neverreflexive. In fact, x 6≺c x for all x ∈ S. Thus, the covering relation fails badly the test ofbeing reflexive. The covering relation is always antisymmetric. If there are three distinctelements a � b � c in S then the covering relation is not transitive; otherwise, it is triviallytransitive.

If you recall the discussion of Example 22 you can easily see that any order relation isalmost the transitive closure of its covering relation. Missing, when we take the transitiveclosure of the covering relation, are all of the relations of the form x � x. If you add thoseat the end, after taking the transitive closure of the covering relation, then you recover�. Or, start with the covering relation, add in all pairs (x, x), x ∈ S, and then take thetransitive closure.5

Take for example a set A = {1, 2, 3} and the subset lattice P(A). Let x = {1} andy = {1, 2, 3}. In this example, x ⊆ y but y does not cover x, written x 6⊂c y. To see why,note that there is a third element z = {1, 2} between x and y: {1} ⊆ {1, 2} ⊆ {1, 2, 3}. Inthis example, x is covered by z and z is covered by y. Here is the directed graph diagram

4 You are encouraged to experiment with small values of n to convince yourself that thisis true.

5 If S is not finite, this process may not work. For example, the covering relation forthe real numbers, (R,≤), is empty!

EO-28

Page 29: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

for the covering relation:{1, 2, 3}

{2, 3}

{3}

Empty Set

{1, 3}

{2}

{1, 2}

{1}

The directed graph diagram of the covering relation of a poset is called the Hasse diagram

of the poset. The Hasse diagram is a very useful geometric way to picture posets. Thetransitive closure of the relation represented by the Hasse diagram, plus all pairs (x, x), xin the poset, is the order relation.

Example 25 (Poset terminology) Here are the Hasse diagrams of two posets, thesecond a subposet of the first:

{2, 3}

{3}

{1, 3}

{2}

{1, 2}

{1}

{1, 2, 3}

{2, 3}

{3}

Empty Set

{1, 3}

{2}

{1, 2}

{1}

The subset{

{1}, {1, 3}, {1, 2, 3}}

, of the first poset is called a chain in that poset. It isa chain because, as a subposet, it is linearly ordered: {1} ⊆ {1, 3} ⊆ {1, 2, 3}. The length

of this chain is two (one less than the number of elements in the chain). The longest chainin this poset has length three. There are six such “maximal” chains. You should try tofind them all. In this first poset, the empty set x = ∅ is special in that for all y in theposet, x ⊆ y. Such an element is called the least element in the poset. Correspondingly,the element t = {1, 2, 3}, is the greatest element in the poset because y ⊆ t for all y in theposet. There can be at most one greatest element and at most one least element in a poset.

Consider now the second poset. There is no least element and no greatest element inthis poset. The element x = {2} has the property that there is no y in the poset with y 6= x

EO-29

Page 30: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

and y ⊆ x. Such an element x is called a minimal element of a poset. A least element is aminimal element, but not necessarily the other way around. Similarly, {1, 2} is a maximal

element of this poset (but not a greatest element). Confused? Read it over again and lookat the pictures. It is not that bad!

Example 26 (Linear extensions — topological sorts) For this example, we shallreturn to the lattice of subsets of the set {1, 2, 3}. Recall its Hasse diagram:

{1, 2, 3}

{2, 3}

{3}

Empty Set

{1, 3}

{2}

{1, 2}

{1}

Here is a special listing of the elements of the lattice of subsets in which every elementoccurs exactly once:

∅, {1}, {2}, {1, 2}, {3}, {1, 3}, {2, 3}, {1, 2, 3}.What is special about this listing? If you scan the list from left to right, you will find thatfor each set in the list, all of its supersets are to the right of it. Or, said in another way,if you scan from right to left, no set is a subset of some other set located to its left. Sucha listing is called a linear extension of the poset (by mathematicians) or a topological sort

(by computer scientists). Here is another linear extension of the poset:

∅, {3}, {2}, {1}, {1, 3}, {1, 2}, {2, 3}, {1, 2, 3}.This poset has 48 linear extensions. Can you list them all?

Here is a listing of the elements of the lattice of subsets that is not a linear extension:

∅, {1}, {2}, {1, 2}, {1, 3}, {3}, {2, 3}, {1, 2, 3}.Scanning from left to right, the set {3} does not have all of its supersets to the right of it(the superset {1, 3} is to the left). Scanning from right to left, we again see that {3} is asubset of {1, 3} which is to the left.

In general, let S be a poset with n elements and with relation �. A linear extension

of S is a listing of the elements of S, s1, s2, . . . , sn, such that for any 1 ≤ i, j ≤ n, if si � sj

then i ≤ j.

It is usually difficult to count the number of linear extensions of an arbitrary posetexcept by listing them. There are no easy formulas for many common posets. An easy case isan n-set with the empty relation (the “discrete” poset): There are n! linear extensions.

EO-30

Page 31: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

Exercises for Section 2

2.1. In each case a binary relation R on a set S is specified directly as a subset of S×S.Determine, for each property, whether the relation R is reflexive, symmetric, ortransitive. Explain your answers.

(a) R = {(0, 0), (0, 1), (0, 3), (1, 0), (1, 1), (2, 3), (3, 3)} where S = {0, 1, 2, 3}.(b) R = {(1, 3), (3, 1), (0, 3), (3, 0), (3, 3)} where S = {0, 1, 2, 3}.(c) R = {(a, a), (a, b), (b, c), (a, c)} where S = {a, b, c}.(d) R = {(a, a), (b, b)} where S = {a, b, c}.(e) R = ∅ where S = {a}.

2.2. Define a binary relation on R (the reals) by x R y if ∃ n ∈ Z (the integers) suchthat x2+y2 = n2. Determine, for each property, whether the relation R is reflexive,symmetric, or transitive. Explain your answers.

2.3. Define a binary relation on Z by x R y if x = y or if x−y = 2k +1 for some integerk. Determine, for each property, whether the relation R is reflexive, symmetric, ortransitive. Explain your answers.

2.4. Let S = R, the real numbers. Define a binary relation on S by x R y if x2 = y2.Determine, for each property, whether the relation R is reflexive, symmetric, ortransitive. Explain your answers.

2.5. Define a binary relation on N+ (the positive integers) by x R y if gcd(x, y) > 1.

Determine, for each property, whether the relation R is reflexive, symmetric, ortransitive. Explain your answers.

2.6. Let S = P(4) − {∅}, the power set of 4 = {1, 2, 3, 4} with the empty set discarded.Define a binary relation on S by X R Y if X∩Y 6= ∅. Determine, for each property,whether the relation R is reflexive, symmetric, or transitive. Explain your answers.

2.7. Let S = P(T ), be the power set of T = {1, 2, 3, 4}. Define a binary relation on Sby X R Y if either X ⊆ Y or Y ⊆ X. Determine, for each property, whether therelation R is reflexive, symmetric, or transitive. Explain your answers.

2.8. Let S be a set with n elements. How many binary relations on S are reflexive?How many are not reflexive?

2.9. Let S be a set with n elements. How many binary relations on S are symmetric?How many are not symmetric?

EO-31

Page 32: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

2.10. Let S be a set with n elements. How many binary relations on S are reflexive andsymmetric?

2.11. Let S be a set with n elements. How many binary relations on S are antisymmetric?How many are reflexive and antisymmetric?

2.12. Let R = {(0, 0), (0, 3), (1, 0), (1, 2), (2, 0), (3, 2)} be a binary relation on {0, 1, 2, 3}.Find the transitive closure of R.

2.13. Let R = {(a, c), (b, c), (c, d)} be a binary relation on {a, b, c, d}. Find the transitiveclosure of R by experimentation and by the matrix method.

2.14. Let S be the set of composite integers n, 4 ≤ n ≤ 20. Order S with the dividesrelation. What is the covering relation? Draw the Hasse diagram. List the minimaland maximal elements. Specify a chain of longest length.

2.15. Let S = {1, 2, 3, 4, 5}. Let P(2)(S) denote the subset of P(S) consisting of all subsetsA such that if i, j ∈ A, then i 6= j implies that |i − j| ≥ 2. Order the elements ofP(2)(S) by set inclusion. What is the cardinality of the covering relation of P(2)(S)?How many chains are there of length three? What are the maximal elements? theminimal elements? Is there a greatest element? a least element?

2.16. Give an example of a poset with no maximal element.

2.17. Let S2 = {0, 1} × {0, 1} = ×2{0, 1}. Use coordinate order: (x1, x2) ≤ (y1, y2) ifx1 ≤ y1 and x2 ≤ y2. What is the covering relation? Compare this covering relationwith P(X), |X| = 2, and set inclusion as the order relation. How do these ideasextend to ×3{0, 1}. To ×n{0, 1}?

2.18. Let S be the set of composite integers n, 4 ≤ n ≤ 20. Order S with the dividesrelation. Let S∗ denote the set of all finite strings (words) over S ordered lexico-graphically based on the poset S. Answer the following by stating whether or notthe pair of strings (read left to right) is in order, in reverse order, or incomparablelexicographically.

(a) 4 6 18 and 4 6 9

(b) 4 6 8 and 4 6 8 9

(c) 4 16 8 and 4 6 10 9

2.19. Let S be an n-element set where n ≥ 3 and let x, y ∈ S where x 6= y. Supposethat S is made into a poset in such a way that all pairs of elements are comparableexcept x and y.

(a) What is the covering relation for S and does the Hasse diagram of S look like?(Describe all possible answers.)

EO-32

Page 33: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Section 2: Order

(b) Let the poset T be S×S with the lex order. How many pairs{

(a1, a2), (b1, b2)}

of incomparable elements does T have?

2.20. List in lexicographic order all ways of placing six dominoes on a 2 × 6 board.

2.21. Sort the following list into lexicographic order using a three-pass bucket sort: 321,441, 143, 312, 422, 221, 214, 311, 234, 111. (Each element in the list is a sequenceof three digits — not a 3-digit number. Thus 321 is the list (3,2,1).) Show thecomposition of the buckets after each pass.

2.22. Let S be the set of composite integers n, 4 ≤ n ≤ 20. Order S with the dividesrelation. Let x1, x2, . . . , x11 be a topological sort of this poset. A pair (i, j), wherei < j and the integer xi is smaller than the integer xj will be called an “in-orderpair.” Find a topological sort where the number of in order pairs is less than orequal to 26.Hint: First draw the Hasse diagram.

2.23. Let S = {a, b, c}, a set with three elements. Let P(S) be the set of all subsets of Sordered by set inclusion. Find 48 different topological sorts of P(S). You need notlist them all if you can describe them in a convincing way.

EO-33

Page 34: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

Multiple Choice Questions for Review

In each case there is one correct answer (given at the end of the problem set). Tryto work the problem first without looking at the answer. Understand both why thecorrect answer is correct and why the other answers are wrong.

1. Let S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. What is the smallest integer K such that any subsetof S of size K contains two disjoint subsets of size two, {x1, x2} and {y1, y2}, such thatx1 + x2 = y1 + y2 = 9?

(a) 8 (b) 9 (c) 7 (d) 6 (e) 5

2. There are K people in a room, each person picks a day of the year to get a free dinnerat a fancy restaurant. K is such that there must be at least one group of six peoplewho select the same day. What is the smallest such K if the year is a leap year (366days)?

(a) 1829 (b) 1831 (c) 1830 (d) 1832 (e) 1833

3. A mineral collection contains twelve samples of Calomel, seven samples of Magnesite,and N samples of Siderite. Suppose that the smallest K such that choosing K samplesfrom the collection guarantees that you have six samples of the same type of mineralis K = 15. What is N?

(a) 6 (b) 2 (c) 3 (d) 5 (e) 4

4. What is the smallest N > 0 such that any set of N nonnegative integers must havetwo distinct integers whose sum or difference is divisible by 1000?

(a) 502 (b) 520 (c) 5002 (d) 5020 (e) 52002

5. Let S = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21}. What is the smallest integer N > 0 suchthat for any set of N integers, chosen from S, there must be two distinct integers thatdivide each other?

(a) 10 (b) 7 (c) 9 (d) 8 (e) 11

6. The binary relation R = {(0, 0), (1, 1)} on A = {0, 1, 2, 3, } is

(a) Reflexive, Not Symmetric, Transitive

(b) Not Reflexive, Symmetric, Transitive

(c) Reflexive, Symmetric, Not Transitive

(d) Reflexive, Not Symmetric, Not Transitive

(e) Not Reflexive, Not Symmetric, Not Transitive

7. Define a binary relation R = {(0, 1), (1, 2), (2, 3), (3, 2), (2, 0)} on A = {0, 1, 2, 3}. Thedirected graph (including loops) of the transitive closure of this relation has

EO-34

Page 35: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Review Questions

(a) 16 arrows

(b) 12 arrows

(c) 8 arrows

(d) 6 arrows

(e) 4 arrows

8. Let N+ denote the nonzero natural numbers. Define a binary relation R on N+ × N+

by (m,n)R(s, t) if gcd(m,n) = gcd(s, t). The binary relation R is

(a) Reflexive, Not Symmetric, Transitive

(b) Reflexive, Symmetric, Transitive

(c) Reflexive, Symmetric, Not Transitive

(d) Reflexive, Not Symmetric, Not Transitive

(e) Not Reflexive, Not Symmetric, Not Transitive

9. Let N+2 denote the natural numbers greater than or equal to 2. Let mRn if gcd(m,n) >

1. The binary relation R on N2 is

(a) Reflexive, Symmetric, Not Transitive

(b) Reflexive, Not Symmetric, Transitive

(c) Reflexive, Symmetric, Transitive

(d) Reflexive, Not Symmetric, Not Transitive

(e) Not Reflexive, Symmetric, Not Transitive

10. Define a binary relation R on a set A to be antireflexive if xRx doesn’t hold for anyx ∈ A. The number of symmetric, antireflexive binary relations on a set of ten elementsis

(a) 210 (b) 250 (c) 245 (d) 290 (e) 255

11. Let R and S be binary relations on a set A. Suppose that R is reflexive, symmetric,and transitive and that S is symmetric, and transitive but is not reflexive. Whichstatement is always true for any such R and S?

(a) R ∪ S is symmetric but not reflexive and not transitive.

(b) R ∪ S is symmetric but not reflexive.

(c) R ∪ S is transitive and symmetric but not reflexive

(d) R ∪ S is reflexive and symmetric.

(e) R ∪ S is symmetric but not transitive.

12. Define an equivalence relation R on the positive integers A = {2, 3, 4, . . . , 20} by m R nif the largest prime divisor of m is the same as the largest prime divisor of n. Thenumber of equivalence classes of R is

(a) 8 (b) 10 (c) 9 (d) 11 (e) 7

EO-35

Page 36: Equivalence and Order - cr.yp.tocr.yp.to/2005-261/bender1/EO.pdfEquivalence and Order Example 2 (Classification by remainder) Now let the set be the integers Z. Let’s try to define

Equivalence and Order

13. Let R = {(a, a), (a, b), (b, b), (a, c), (c, c)} be a partial order relation on Σ = {a, b, c}.Let � be the corresponding lexicographic order on Σ∗. Which of the following is true?

(a) bc � ba

(b) abbaaacc � abbaab

(c) abbac � abb

(d) abbac � abbab

(e) abbac � abbaac

14. Consider the divides relation, m | n, on the set A = {2, 3, 4, 5, 6, 7, 8, 9, 10}. Thecardinality of the covering relation for this partial order relation (i.e., the number ofedges in the Hasse diagram) is

(a) 4 (b) 6 (c) 5 (d) 8 (e) 7

15. Consider the divides relation, m | n, on the set A = {2, 3, 4, 5, 6, 7, 8, 9, 10}. Which ofthe following permutations of A is not a topological sort of this partial order relation?

(a) 7,2,3,6,9,5,4,10,8

(b) 2,3,7,6,9,5,4,10,8

(c) 2,6,3,9,5,7,4,10,8

(d) 3,7,2,9,5,4,10,8,6

(e) 3,2,6,9,5,7,4,10,8

16. Let A = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} and consider the divides relationon A. Let C denote the length of the maximal chain, M the number of maximalelements, and m the number of minimal elements. Which is true?

(a) C = 3, M = 8, m = 6

(b) C = 4, M = 8, m = 6

(c) C = 3, M = 6, m = 6

(d) C = 4, M = 6, m = 4

(e) C = 3, M = 6, m = 4

Answers: 1 (c), 2 (b), 3 (e), 4 (a), 5 (d), 6 (b), 7 (a), 8 (b), 9 (a), 10 (c), 11 (d),12 (a), 13 (b), 14 (e), 15 (c), 16 (a).

EO-36