Contents / Discrete Mathematics / Relations and Equivalence
Chapter 3
Relations and Equivalence
Binary relations, their matrices and digraphs; the five properties shown independent by explicit witnesses; the correspondence between equivalence relations and partitions proved in both directions; congruence modulo n; transitive closure as a union of powers and as a smallest relation; partial orders, Hasse diagrams and maximal elements; and total orders with topological sorting.
Introduction
A set knows only which objects belong to it. It has nothing to say about how those objects stand to one another — which files depend on which, which records share a key, which version supersedes which. That information is carried by a relation, and a relation is a startlingly cheap object: just a set of ordered pairs. Everything in this chapter is extracted from that one definition by imposing conditions on the pairs.
Two families of conditions matter above all others. Impose reflexivity, symmetry and transitivity and you get an equivalence relation, which behaves like equality: it declares certain objects interchangeable for the purpose at hand. Impose reflexivity, antisymmetry and transitivity and you get a partial order, which behaves like : it ranks objects, but tolerates pairs it refuses to rank. These two are not arbitrary picks from the sixteen-odd combinations available. Each is the exact structure that answers a question that keeps recurring: when may I treat two things as the same? and when must one thing come before another?
The centrepiece of the chapter is the theorem that equivalence relations on a set are the same data as partitions of it. Not merely that one produces the other — that the correspondence is a bijection, so that every fact about equivalence relations translates into a fact about partitions and back. It is the first place in a mathematics course where two definitions that look nothing alike turn out to be two descriptions of one object, and the proof is worth the care it takes.
For orders, the payoff is algorithmic. Every finite partially ordered set can be flattened into a linear list that respects all the constraints it did impose — that is topological sorting, which is what a build system does when it decides the order to compile your files, what a package manager does when it installs dependencies, and what a spreadsheet does when it decides which cells to recalculate. We will prove that it is always possible, and the proof is essentially the algorithm.
Throughout, denotes a set, and when is finite. We write for the integers and for .
3.1Relations, their representations, and composition
Start with the definition, which is deliberately thin. A relation is not required to be meaningful, computable, or describable by a rule; it is a set of pairs and nothing else. The thinness is the point, because it means the theorems we prove apply to every relation, including the ones nobody would think to write down.
Definition 3.1 (Binary relation). Let and be sets. A binary relation from to is a subset of the Cartesian product. We write as shorthand for , and when .
A relation on is a relation from to , that is, a subset of .
Unless stated otherwise every relation in this chapter is a relation on a single set, because the properties we care about — reflexivity, transitivity and the rest — compare the two coordinates and so need them drawn from the same place.
Intuition. Picture the elements of as dots. A relation is a choice, for each ordered pair of dots, of whether to draw an arrow from the first to the second. A dot may point at itself. The arrows and are different choices and may be made independently.
Definition 3.2 (Domain, range, inverse, identity). Let be a relation on .
- , the domain.
- , the range.
- , the inverse (or converse) relation.
- , the identity or diagonal relation on .
The diagonal is the relation of literal equality, and it will keep reappearing: reflexivity is the statement , and antisymmetry is the statement . Translating conditions into set containments like these is not a stylistic preference; it is what makes them provable in one line instead of three.
Proposition 3.3 (How many relations a set carries). A set with carries exactly
relations.
Proof. A relation on is by definition an arbitrary subset of , and no condition restricts which subsets qualify. Since , and a set of size has exactly subsets, the number of relations is .∎
For that is , and for it is . The count grows so fast that exhaustive search over relations is hopeless past ; this is why we reason about relations by their properties rather than by enumerating them.
Two representations
A relation on a finite set can be written down in two ways that are genuinely useful, as opposed to merely listing the pairs.
Definition 3.4 (Matrix of a relation). Let with a fixed ordering of its elements, and let be a relation on . The matrix of is the array with entries in given by
Definition 3.5 (Digraph of a relation). The digraph (directed graph) of has one vertex for each element of and a directed edge from to exactly when . An edge from a vertex to itself is a loop.
The matrix is what a computer stores; the digraph is what a human draws. They carry identical information, and different properties are easy to see in each. Reflexivity is a glance at the diagonal of the matrix; transitivity is a statement about paths in the digraph.
Example 3.6 (Both representations of one relation). Let and . Write the matrix of , list and , and describe the digraph.
Solution.
- Row of records which elements points at. Row : and are present, is not, giving . Row : only , giving . Row : only , giving . So
- The first coordinates occurring are , so . The second coordinates occurring are as well, so .
- The digraph has loops at and , no loop at , and a two-way pair of edges between and . Vertex is isolated apart from its loop.
The number of s in the matrix is , which is the check to run every time: counts entries, not rows.□
Composition and powers
Composition is where relations start to do work. If records "imports directly" and we want "imports, possibly through a chain", we need to follow two arrows and then many.
Definition 3.7 (Composition of relations). Let and be relations on . Their composition is
In words: reaches by first taking an -step and then an -step.
Notation. The order in follows the convention for functions, where applies first. Some books write for the same thing with the steps in reading order. We will mostly compose a relation with itself, where the question does not arise.
Definition 3.8 (Powers of a relation). For a relation on define and for .
Unwinding the definition, exactly when there is a chain of elements of with for each — that is, a walk of length exactly from to in the digraph of . We record this because it is the fact every later proof about closures uses.
Lemma 3.9 (Powers are walks). For every and all , we have if and only if there exist with , and for .
Proof. Induct on . For the claim is that if and only if there is a chain with , which is a restatement.
Suppose the claim holds for . By definition means there is some with and . By the induction hypothesis, is equivalent to the existence of a walk of length ; appending using the edge produces a walk of length from to . Conversely, a walk from to splits at : its initial segment is a walk of length from to , so by the induction hypothesis, and , so .∎
Now the connection to linear algebra. Define the Boolean product of two - matrices and of size by
where is logical and ( if both are ) and is logical or ( if any term is ). This is the ordinary matrix product with replaced by "or" and by "and"; equivalently, it is the ordinary product followed by replacing every nonzero entry with .
Theorem 3.10 (Composition is Boolean matrix product). Let and be relations on a finite set with a fixed ordering of elements. Then
Consequently is the -fold Boolean power of .
Proof. Both sides are - matrices, so it suffices to show they have a in the same positions. Fix and .
The entry is exactly when , which by the definition of composition holds exactly when there exists an index with and .
The entry is exactly when the disjunction is , which holds exactly when there is some index for which both and — that is, some with and .
The two conditions are word for word the same, so the entries agree for every . The statement about powers follows by induction on , the inductive step being the case , of what was just proved.∎
Remark. This is why reachability in a graph on vertices can be computed with matrix multiplications rather than by an explicit search: Boolean squarings of the adjacency matrix suffice to find all walks of length up to . It is also why the same code that multiplies matrices of numbers computes transitive closures if you swap the two arithmetic operations.
Example 3.11 (Composing a small relation with itself). Let and . Compute and , and say how many pairs has.
Solution.
- By the lemma Powers are walks, consists of the pairs joined by a walk of length . The walks are and , so .
- Walks of length : only , so .
- A walk of length would need five distinct steps' worth of vertices in a chain that stops at ; since has no edge out of , no walk of length exists and , which has pairs.
Notice the sizes : each extra step costs one starting point, which is what a path-shaped relation does.□
3.2The five properties and their independence
Five conditions on a relation account for almost everything that follows. Each is a single quantified sentence, and each has a one-line translation into the matrix and into the digraph.
Definition 3.12 (The five properties). Let be a relation on . Then is
- reflexive if for every ;
- irreflexive if for every ;
- symmetric if implies , for all ;
- antisymmetric if and together imply , for all ;
- transitive if and together imply , for all .
is connex (or total, or complete) if for all at least one of and holds.
Pitfall. "Antisymmetric" is not the negation of "symmetric", and the two are not alternatives. The negation of symmetric is: some pair is related one way only. Antisymmetric is: no pair of distinct elements is related both ways. A relation can be both, and a relation can be neither — we prove exactly that below. Likewise "irreflexive" is not the negation of "reflexive": a relation with a loop at but not at is neither reflexive nor irreflexive.
Proposition 3.13 (The properties read off the matrix). Let be a relation on the finite set , with matrix .
- is reflexive if and only if for all ; irreflexive if and only if for all .
- is symmetric if and only if .
- is antisymmetric if and only if for all .
- is transitive if and only if , equivalently implies .
Proof. Parts 1 to 3 are the definitions rewritten with substituted throughout. For 1, " for all " becomes " for all ". For 2, symmetry says , that is for all , which is exactly . For 3, antisymmetry forbids and both lying in when , that is, forbids .
For 4, unfold the composition: means there is with and . So the containment says precisely that whenever such a exists, — which is transitivity. The matrix form is then the theorem Composition is Boolean matrix product applied with .∎
Part 4 is the useful one. It replaces a statement with three quantified variables by a containment between two sets, and containments can be manipulated. Every proof of transitivity in the rest of the chapter can be run either way; we will pick whichever is shorter.
Proposition 3.14 (Counting relations with a given property). Let . The number of relations on that are
- reflexive is ;
- symmetric is ;
- both reflexive and symmetric is .
Proof. Each part counts matrices with a constraint, using the fact that free entries may be filled in independently.
- Reflexivity fixes the diagonal entries to and constrains nothing else. The remaining off-diagonal entries are free, giving choices.
- Symmetry means the matrix is determined by its entries on and above the diagonal, of which there are , and any assignment to those extends uniquely to a symmetric matrix. Hence .
- Imposing both, the diagonal is forced and the strictly-upper entries — there are of them — are free and determine the strictly-lower ones. Hence .
Example 3.15 (Counting on a four-element set). With , how many relations on are reflexive? How many are symmetric? How many are both?
Solution.
- Reflexive: .
- Symmetric: .
- Both: .
As a check, every relation counted in part 3 is counted in both parts 1 and 2, and is indeed a common divisor's worth smaller than each — in fact , which is the inclusion–exclusion identity for two independent constraints on disjoint sets of matrix entries.□
The properties are genuinely independent
It is easy to believe, after seeing and , that the properties come in fixed bundles: that symmetric and antisymmetric are opposites, that transitive implies reflexive, and so on. They do not. The following proposition settles the question by exhibiting, for each of the combinations that students conflate, a relation realising it.
Proposition 3.16 (Independence of the five properties). Let . Then:
- There is a relation on that is both symmetric and antisymmetric.
- There is a relation on that is neither symmetric nor antisymmetric.
- There is a relation on that is symmetric and transitive but not reflexive.
- There is a relation on that is reflexive and symmetric but not transitive.
- There is a relation on that is reflexive and transitive but not symmetric and not antisymmetric.
- There is a relation on that is both irreflexive and transitive, and one that is neither reflexive nor irreflexive.
Proof. We exhibit a relation in each case and verify the claims directly from the definition of The five properties.
- Take . It is symmetric, since the reverse of is . It is antisymmetric, since the only pairs have already, so the implication's conclusion holds vacuously whenever its hypothesis does. More generally any is both, and these are the only such relations: if is symmetric and antisymmetric and , then by symmetry and hence by antisymmetry.
- Take . It fails symmetry because but . It fails antisymmetry because and are both in while . So the two properties are not exhaustive either.
- Take . Symmetric and transitive by the same vacuous reasoning as in part 1, but not reflexive since . This example matters: it is the standard refutation of the false claim that symmetry plus transitivity imply reflexivity. The bogus argument reads " gives by symmetry, then by transitivity", and it breaks for any that is related to nothing at all.
- Take . It is reflexive by construction and symmetric because the non-diagonal pairs were added in mirrored couples. It is not transitive: and but . (Read as "differs by at most one", which is exactly the relation that is not transitive in everyday life: near-duplicates in a database are pairwise similar without all being the same record.)
- Take . Reflexive by construction. Not symmetric, since and . Not antisymmetric, since with . For transitivity, the only composable non-diagonal chains are then , needing ✓; then , needing ✓; then , needing ✓; then , needing ✓. Chains through a diagonal pair add nothing new. So is transitive.
- For the first, take : no loops, so irreflexive, and the only composable chain has its shortcut present, so transitive. For the second, take again on : it has a loop at , so it is not irreflexive, and lacks a loop at , so it is not reflexive.
Intuition. The useful mental picture is that each property constrains a different feature of the digraph — loops (reflexive, irreflexive), the pairing of opposite edges (symmetric, antisymmetric), and shortcuts across two-step paths (transitive) — and these features can be adjusted independently. That is why so many combinations occur.
Closures
Given a relation that fails a property, the natural repair is to add the missing pairs and nothing more.
Definition 3.17 (Closure with respect to a property). Let be one of the properties reflexive, symmetric, transitive, and let be a relation on . The -closure of is a relation such that (i) has property , (ii) , and (iii) for every relation with property and .
Condition (iii) is what makes the closure unique if it exists: two relations each contained in the other are equal. The reflexive closure is easy, being , and the symmetric closure is . The transitive closure is the interesting one, and it is not obtained by one pass of adding shortcuts.
Definition 3.18 (Transitive closure). The transitive closure of is written , and the reflexive transitive closure is .
Theorem 3.19 (The transitive closure is the union of the powers). Let be a relation on a set and put
Then is transitive, contains , and is contained in every transitive relation containing . That is, is the transitive closure of , and it consists exactly of the pairs joined by a walk of positive length in the digraph of .
Proof. contains . Immediate, since is one of the sets in the union.
is transitive. Suppose and . Then and for some . By the lemma Powers are walks there is a walk of length from to and a walk of length from to ; concatenating them at gives a walk of length from to , so .
is smallest. Let be any transitive relation with . We show for every by induction on . For this is the hypothesis . Assume and let . By definition there is with and . Then by the induction hypothesis and since , so by transitivity of . Hence , and taking the union over gives .
The description in terms of walks is the lemma Powers are walks read across the union: if and only if for some , if and only if some walk of positive length runs from to .∎
Corollary 3.20 (A finite bound on the union). If then .
Proof. One containment is clear, since the right-hand side is part of the union defining . For the other, suppose with minimal. By the lemma Powers are walks there is a walk . If two of coincided, say with , then deleting the steps between them would leave a walk of length from to , contradicting minimality of . So the vertices are distinct, and since they all lie in we get , hence .∎
Example 3.22 (Computing a transitive closure). Let and , a directed cycle. Compute and give .
Solution.
- By the theorem The transitive closure is the union of the powers, exactly when some walk of positive length runs from to .
- In a directed -cycle you may walk any number of steps forward, so from any vertex you can reach every vertex, including itself after four steps.
- Hence , and .
The closure of a cycle is everything, which is worth contrasting with the path of the figure, whose closure has only pairs. A single extra edge closing the loop takes the closure from pairs to .□
Example 3.23 (Closure under dependency). A build system records that module depends directly on , on , and on . Which rebuilds are triggered by a change to ?
Solution.
- Model the direct dependencies as on , where reads "a change to forces a rebuild of ".
- The set of modules needing a rebuild is . Powers: and .
- So and changing rebuilds and , two modules. The component is untouched, which is exactly the property a build system exploits to avoid rebuilding the world.
3.3Equivalence relations
Definition 3.24 (Equivalence relation). A relation on is an equivalence relation if it is reflexive, symmetric and transitive. We write and say and are equivalent.
The three conditions are exactly the three properties of literal equality that any notion of "same for present purposes" must retain. Drop reflexivity and some object fails to be the same as itself; drop symmetry and sameness acquires a direction; drop transitivity and sameness fails to propagate, which is the failure of "differs by at most one" in the proposition Independence of the five properties.
Intuition. An equivalence relation is a way of deciding to forget information. Congruence mod forgets everything about an integer except its clock position. Comparing files by content hash forgets their names. What survives the forgetting is exactly what the relation cannot tell apart.
Proposition 3.25 (Two extreme examples). On any set , both and are equivalence relations. Moreover, if is any equivalence relation on , then .
Proof. is reflexive by definition; it is symmetric and transitive because, as in part 1 of the proposition Independence of the five properties, every pair in it has equal coordinates. contains every pair, so all three conditions hold trivially. For the containments: is precisely reflexivity of , and holds because every relation on is a subset of .∎
So equivalence relations on form a range from the finest (: nothing is identified with anything else) to the coarsest (: everything is identified with everything). Every interesting equivalence lies strictly between.
Proposition 3.26 (The kernel of a function). Let be any function and define to mean . Then is an equivalence relation on , called the kernel of .
Proof. Reflexive: for every , since equality in is reflexive. Symmetric: if then . Transitive: if and then . Each of the three conditions is the corresponding property of equality in , transported along .∎
This little proposition is more powerful than it looks: it says that every way of grouping objects by a computed value is automatically an equivalence relation. Grouping records by department, files by hash, integers by remainder, strings by length — all are kernels, so none of them needs a separate three-part verification. In fact the theorem Equivalence relations are partitions, proved in the next section, will show the converse: every equivalence relation is the kernel of some function.
Definition 3.27 (Congruence modulo ). Fix an integer . For write
that is, for some .
Theorem 3.28 (Congruence mod is an equivalence with classes). For every integer , congruence modulo is an equivalence relation on , and it has exactly distinct equivalence classes, represented by .
Proof. Equivalence. Reflexive: , so . Symmetric: if then and . Transitive: if and then with .
At most classes. Let . Division with remainder gives unique integers and with and . Then , so with . Hence every integer is congruent to one of these values, so there are at most classes.
At least classes. Suppose with . Then , while because both lie in an interval of length . The only multiple of of absolute value less than is , so and . Hence the values lie in pairwise distinct classes, giving at least classes.
Combining the two counts, there are exactly classes.∎
Remark. Congruence mod is also the kernel of the function , so the proposition The kernel of a function gives the equivalence half of the theorem instantly. The counting half is the part that needs division with remainder, which is where the arithmetic actually enters.
Example 3.29 (Congruence in practice). On , how many equivalence classes does congruence mod have, and which class contains ?
Solution.
- By the theorem Congruence mod is an equivalence with classes, there are exactly classes.
- Divide with remainder: , and , so .
- The class is therefore .
The trap is answering or : the remainder is required to be non-negative, so the quotient is , not .□
Definition 3.30 (Equivalence class). Let be an equivalence relation on and . The equivalence class of is
Any element with is called a representative of the class.
The next lemma is short but it is the engine of the whole theory: it says that a class does not depend on which of its members you name it after.
Lemma 3.31 (Classes coincide exactly for equivalent elements). Let be an equivalence relation on and . The following are equivalent:
- ;
- ;
- .
Proof. (1) implies (2). Suppose . Let , so . Combined with , transitivity gives , so ; hence . Symmetry of gives , and the same argument with the roles exchanged gives . Therefore .
(2) implies (3). By reflexivity , so , and thus , which is therefore non-empty.
(3) implies (1). Let . Then and . By symmetry , and with transitivity gives .∎
Pitfall. Every step of that proof used a different one of the three axioms, and none was decorative. Reflexivity is what makes non-empty; symmetry is what lets the argument run in both directions; transitivity is what glues two chains together. A "proof" of the lemma that names only transitivity has a gap.
3.4Partitions and the fundamental correspondence
Definition 3.32 (Partition). A partition of a set is a collection of subsets of , called blocks, such that
- every block is non-empty;
- the blocks cover : every lies in some block;
- the blocks are pairwise disjoint: distinct blocks satisfy .
Equivalently: every element of lies in exactly one block.
The last sentence of the definition is worth checking against the three conditions, because it is the form we will actually use. Coverage says "at least one block"; disjointness says "at most one block"; together they say "exactly one". Non-emptiness is a separate normalisation that rules out padding a partition with copies of , which would otherwise break the correspondence we are about to prove by making infinitely many partitions out of one.
Here, then, is the central theorem of the chapter.
Theorem 3.34 (Equivalence relations are partitions). Let be a set.
- If is an equivalence relation on , then the collection of its equivalence classes
is a partition of .
- If is a partition of , then the relation defined by
is an equivalence relation on .
- These constructions are mutually inverse: starting from an equivalence relation , forming its classes and then forming the same-block relation returns ; and starting from a partition , forming the same-block relation and then its classes returns .
Hence the map is a bijection from the set of equivalence relations on to the set of partitions of .
Proof. Part 1: classes form a partition. Let be an equivalence relation.
Blocks are non-empty. Every block of has the form for some . By reflexivity , so and .
Blocks cover . Given , the block belongs to and contains , again by reflexivity.
Blocks are pairwise disjoint. Let and be blocks with . By the lemma Classes coincide exactly for equivalent elements, condition (3) implies condition (2), so . Contrapositively, two blocks that are not equal have empty intersection, which is exactly condition 3 of the definition of Partition.
Part 2: a partition induces an equivalence. Let be a partition. By the definition of Partition, each lies in exactly one block; write for that block, so that means .
Reflexive. , so .
Symmetric. If then .
Transitive. If and then .
(Each is the corresponding property of equality between blocks; this is the proposition The kernel of a function applied to , and the fact that is a well-defined function is precisely where "exactly one block" is used.)
Part 3, first direction: classes then same-block returns . Let be an equivalence relation, let , and let be the same-block relation of . By part 1, is a partition, and by part 1's first bullet the block containing is — it contains , and by disjointness it is the only block that does. So means , which by the lemma Classes coincide exactly for equivalent elements holds if and only if . Hence and contain the same pairs, so .
Part 3, second direction: same-block then classes returns . Let be a partition and its same-block relation, with as above. We claim for every , where is the -class.
If then , that is ; since , we get . Conversely if then is a block containing , and since lies in exactly one block, , so and . Hence .
It follows that . Every is a block of , so this collection is contained in ; conversely every block is non-empty, so it contains some , and then lies in the collection. Therefore .
Conclusion. Parts 1 and 2 give maps in both directions between equivalence relations on and partitions of , and part 3 shows each composite is the identity. A pair of mutually inverse maps is a bijection.∎
Remark. Note where non-emptiness of blocks was used: only in the very last step, to recover from the classes. Allow as a block and the correspondence stops being injective, since and would induce the same relation. Small hypotheses of this kind usually earn their place at exactly one point in a proof, and finding that point is how you tell whether a hypothesis is needed.
Definition 3.35 (Quotient set). The set of equivalence classes is called the quotient of by . The map with is the canonical projection.
Corollary 3.36 (Every equivalence is a kernel). Every equivalence relation on is the kernel of a function, namely of the canonical projection .
Proof. By definition means , which by the lemma Classes coincide exactly for equivalent elements is equivalent to . So the kernel of , in the sense of the proposition The kernel of a function, is exactly .∎
Together with that proposition this closes the circle: equivalence relations, partitions, and "group by a computed value" are three descriptions of one idea. A database index on a column is a partition of the rows; the equivalence relation is "these rows agree in that column"; the quotient set is the set of distinct keys.
Definition 3.37 (Bell and Stirling numbers). The Bell number is the number of partitions of an -element set, and the Stirling number of the second kind is the number of partitions into exactly non-empty blocks. Thus
Corollary 3.38 (Counting equivalence relations). The number of equivalence relations on an -element set is , and the number with exactly classes is .
Proof. By the theorem Equivalence relations are partitions, the map sending an equivalence relation to its set of classes is a bijection onto the partitions of , so the two collections have the same size, which is by definition. The bijection sends an equivalence with classes to a partition with blocks and back, so it restricts to a bijection between those subcollections, giving .∎
The first Bell numbers are , , , , , , . Compare with the relations of the proposition How many relations a set carries: on a -element set, of the relations are equivalences. The conditions are extremely restrictive, which is another way of saying that an equivalence relation carries a lot of structure.
Example 3.39 (Listing the equivalence relations on a three-element set). List all partitions of and confirm the count . How many have exactly two blocks?
Solution.
- One block: the only option is , so .
- Two blocks: one block is a pair and the other a singleton. Choosing the singleton in ways gives , , , so .
- Three blocks: all singletons, , so .
- Total , and exactly have two blocks.
The corresponding equivalence relations have , , , and pairs respectively — a relation with blocks of sizes has pairs, since it is the union of the full relations on each block.□
Example 3.40 (Size of an equivalence relation as a set of pairs). An equivalence relation on a -element set has classes of sizes . How many ordered pairs does it contain?
Solution.
- By the theorem Equivalence relations are partitions, holds exactly when and lie in the same class, so the relation is the disjoint union of over the classes .
- A class of size contributes pairs.
- Total: .
The smallest possible value for a -element set is (all singletons) and the largest is (one class), and every equivalence sits between.□
Example 3.41 (Rows of a database table). A table has rows and a column dept taking exactly distinct values, with , , and rows respectively. Describe the induced equivalence and give the size of the quotient set.
Solution.
- Define when the two rows agree in
dept. By the proposition The kernel of a function this is an equivalence relation, no verification needed. - Its classes are the four groups of rows, of sizes , which sum to as a partition must.
- The quotient set has one element per distinct value, so — which is precisely what a
SELECT COUNT(DISTINCT dept)returns.
3.5Partial orders
Swap symmetry for antisymmetry and the character of the relation changes completely: instead of identifying elements, it ranks them.
Definition 3.42 (Partial order and poset). A relation on is a partial order if it is reflexive, antisymmetric and transitive. The pair is a partially ordered set, or poset.
Elements are comparable if or , and incomparable otherwise. We write for " and ".
Proposition 3.43 (Three standard posets). Each of the following is a partial order:
- on the power set of any set ;
- divisibility on the positive integers ;
- on .
Proof.
- Reflexive: , since every element of is in . Antisymmetric: if and then and have the same elements, so by extensionality. Transitive: if and , then , hence .
- Reflexive: , so . Transitive: if and then . Antisymmetric: if and with , write and with ; then , so , forcing and . (The restriction to positive integers is essential: on we have and with , so divisibility on is not antisymmetric.)
- The three properties of on are standard: ; and give ; and gives .
In (1) the sets and are incomparable, and in (2) the integers and are incomparable, neither dividing the other. In (3) no pair is incomparable, which is the extra condition that makes a total order — the subject of the next section.
Intuition. A partial order encodes constraints that must be respected while staying silent about everything else. "This task must finish before that one" is a constraint; two tasks with no dependency between them are incomparable, and the order deliberately declines to say which runs first. That silence is what lets a scheduler run them in parallel.
Definition 3.44 (Covering relation and Hasse diagram). In a poset , we say covers , written , if and there is no with .
The Hasse diagram of a finite poset draws each element as a point, placed so that sits higher than whenever , and joins to by a line segment exactly when .
The Hasse diagram omits loops (implied by reflexivity) and every edge forced by transitivity, leaving only the covers. Nothing is lost: for a finite poset the full order is recovered by taking the reflexive transitive closure of the covering relation, since holds exactly when an upward path of covers runs from to .
Definition 3.46 (Extremal elements). Let be a poset and .
- is maximal if no satisfies ; minimal if no satisfies .
- is a greatest element if for every ; a least element if for every .
The distinction between maximal and greatest is the one students lose. Maximal means "nothing is above it"; greatest means "it is above everything". In a total order they coincide, which is why the difference is invisible until you meet a genuine poset.
Proposition 3.47 (Greatest implies maximal, and greatest is unique). Let be a poset.
- A greatest element, if one exists, is maximal.
- There is at most one greatest element.
- A maximal element need not be greatest.
Proof.
- Let be greatest and suppose for some . Since is greatest, ; combined with , antisymmetry gives , contradicting , which requires . So no such exists and is maximal.
- Let and both be greatest. Then because is greatest, and because is greatest; antisymmetry gives .
- Take ordered by divisibility. Then is maximal, since neither nor is a proper multiple of inside , and is maximal for the same reason. But neither is greatest, since and . Indeed part 2 already shows that two distinct maximal elements cannot both be greatest.
Theorem 3.48 (Every finite non-empty poset has a maximal element). Let be a poset with finite and non-empty. Then has at least one maximal element, and likewise at least one minimal element.
Proof. Suppose, for contradiction, that no element of is maximal. Pick any , which is possible since . Since is not maximal, there is with . Since is not maximal, there is with , and continuing we obtain an infinite sequence .
All the are distinct. Indeed if then repeated transitivity along the chain gives , and in fact : if then from and antisymmetry would force , contradicting .
So contains infinitely many distinct elements, contradicting finiteness. Hence some element is maximal. The statement about minimal elements is the same argument applied to the reverse order , which is a partial order because reflexivity, antisymmetry and transitivity are each unchanged when both coordinates are swapped.∎
Remark. Finiteness is not a technicality here. The poset has no maximal element, and the poset of finite subsets of ordered by has none either. What the proof actually needs is that no infinite strictly ascending chain exists, a condition called the ascending chain condition, which finite posets satisfy automatically.
Example 3.49 (Extremal elements of a divisibility poset). In the poset , list the minimal elements, the maximal elements, and say whether a greatest element exists.
Solution.
- Minimal: an element is minimal when nothing else in the set properly divides it. Nothing in the set divides or other than themselves, so and are minimal. Every other element is a proper multiple of or of , so the minimal elements are — two of them.
- Maximal: nothing in the set is a proper multiple of , and nothing is a proper multiple of . But and , so and are not maximal. The maximal elements are .
- A greatest element would have to be a multiple of every element, in particular of both and , hence of , which is not in the set. Moreover by the proposition Greatest implies maximal, and greatest is unique a greatest element would be the unique maximal element, and there are two. So no greatest element exists.
Definition 3.50 (Chains and antichains). In a poset, a chain is a subset in which every two elements are comparable, and an antichain is a subset in which every two distinct elements are incomparable. The height of a finite poset is the size of its largest chain, and its width is the size of its largest antichain.
Example 3.51 (A chain and an antichain in the subsets of a three-set). In , give a chain of maximum size and an antichain of maximum size.
Solution.
- A chain must be a nested family; each step up can add at least one element, and going from to takes three steps. So is a chain of size , and no chain is longer, since the sizes of the sets in a chain are strictly increasing integers between and .
- The three two-element subsets are pairwise incomparable, giving an antichain of size . So is the family of singletons. No antichain of size exists here — that is Sperner's theorem, whose answer matches.
- So the height is and the width is .
3.6Total orders, linear extensions and Zorn's lemma
Definition 3.52 (Total order). A partial order on is a total order (or linear order) if every two elements are comparable: for all , either or . A totally ordered set is also called a chain.
Equivalently, a total order is a partial order whose only antichains are the subsets with at most one element. The usual order on , , and is total; so is dictionary order on strings, and so is chronological order on timestamps. Subset inclusion and divisibility are not.
Proposition 3.53 (Totality strengthens antisymmetry to trichotomy). If is a total order on , then for all exactly one of , , holds.
Proof. At least one. By totality, or . In the first case either or ; in the second either or .
At most one. If then neither nor can hold, since both require . And and cannot both hold: they give and , so by antisymmetry, contradicting .∎
Definition 3.54 (Linear extension). A linear extension of a poset is a total order on the same set such that implies . Producing one from a finite poset is called topological sorting.
Theorem 3.55 (Every finite poset has a linear extension). Let be a poset with finite. Then a linear extension of exists. Concretely, repeatedly extracting a minimal element from what remains produces a listing of such that implies .
Proof. Induct on .
Base case. If the empty order is a linear extension, vacuously.
Inductive step. Let and assume the result for all posets with fewer than elements. Since is finite and non-empty, the theorem Every finite non-empty poset has a maximal element supplies a minimal element; call it .
Let and let be the restriction of to . Restricting a partial order to a subset again gives a partial order, since reflexivity, antisymmetry and transitivity are statements about elements that remain true when fewer elements are available. As , the induction hypothesis gives a listing of with for .
Set and consider the listing of . We must check that implies . If this is the induction hypothesis. If then holds automatically. The remaining case is and : then with , that is , contradicting minimality of . So this case does not occur.
Finally, define to mean . This is a total order, being a copy of the usual order on transported along the bijection , and by the property just verified implies . Hence is a linear extension.∎
Intuition. The proof is a program. Keep a set of "ready" items — those with no unmet prerequisite, that is, the minimal elements — emit one, delete it, and repeat. That is Kahn's algorithm, and the theorem says it never gets stuck on a finite poset: a non-empty remainder always has a minimal element to emit. A scheduler that does get stuck is looking at a digraph with a cycle, which is therefore not a poset at all, since a cycle violates antisymmetry.
Example 3.56 (Counting linear extensions). The poset on has , , and (plus what reflexivity and transitivity force), with and incomparable. How many linear extensions does it have?
Solution.
- A linear extension is an ordering of the four elements respecting all constraints. Since and , the element must come first and last.
- That leaves and in the two middle positions, in either order, and both choices respect every constraint because and are incomparable.
- So there are linear extensions: and .
This poset is the "diamond". Contrast the four-element antichain, which has extensions, and the four-element chain, which has exactly : the number of extensions measures how much freedom the order leaves.□
Example 3.57 (Topological sort of a dependency graph). A package manager must install packages with these direct dependencies: needs ; needs ; needs and ; needs . Give an installation order, and count how many valid orders exist.
Solution.
- Take the reflexive transitive closure of the dependency digraph; it is a partial order because the digraph is acyclic. Minimal elements are packages with no unmet dependency.
- Run the extraction: only is minimal, so emit . Now and are minimal; emit , then ; now and are minimal; emit , then . The order works.
- Counting all valid orders: must be first. Of the remaining arrangements of , we need before , before and before . Enumerating the orders of that satisfy all three gives , , , , — five of them. So there are valid installation orders.
Theorem 3.58 (A finite total order is a numbering). Let be a totally ordered set with . Then there is a bijection such that
Such an is unique, so up to relabelling there is exactly one total order on an -element set.
Proof. Existence. Apply the theorem Every finite poset has a linear extension to , obtaining a listing with , and set . This is a bijection onto because the listing enumerates each element of exactly once.
It remains to prove the equivalence. The forward implication is the property of the listing. For the converse, suppose , that is . If then and by reflexivity. If , totality gives or ; in the latter case the forward implication would give , contradicting . So .
(This is the step where totality is indispensable. For a general poset the listing produced by topological sorting satisfies only the forward implication, and indeed the diamond poset above has two different listings, so no such can be canonical.)
Uniqueness. Suppose and both have the stated property, and suppose . Among the elements where they differ, and using the total order on , pick with least. Let . The set is mapped by onto : it is mapped into that set by the stated property, and onto it because is a bijection and any with satisfies . The same argument applies to , so both and send to the size of , that is — contradicting the choice of . Hence .∎
The theorem is the reason sorting is a well-posed problem. Whatever finite set of comparable items you are handed — version numbers, timestamps, strings — there is exactly one arrangement consistent with the order, so "sort this list" has a single right answer, and any two correct sorting algorithms must produce the same output.
Definition 3.59 (Well-order). A total order on is a well-order if every non-empty subset of has a least element.
Proposition 3.60 (Finite total orders are well-orders). Every total order on a finite set is a well-order.
Proof. Let be non-empty with finite. Then is a finite non-empty poset, so by the theorem Every finite non-empty poset has a maximal element it has a minimal element . Since is total, every is comparable to , and must hold — otherwise , contradicting minimality. So is a least element of .∎
is well-ordered, which is exactly the principle that makes induction and "least counterexample" arguments work. is not, since itself has no least element, and is not, since the interval has no least element either: for any candidate , the number is smaller and still in the interval. Both are total orders, so well-ordering is a strictly stronger condition.
Theorem 3.61 (Zorn's lemma, stated without proof). Let be a non-empty poset in which every chain has an upper bound in . Then has a maximal element.
Remark. Zorn's lemma is the infinite analogue of the theorem Every finite non-empty poset has a maximal element, and it is emphatically not a theorem of the kind proved in this chapter: it is equivalent to the axiom of choice and to the well-ordering theorem (that every set admits a well-order), and it is proved — or adopted — in Set Theory, not here. No argument in this chapter uses it, and none needs to, because every poset we meet is finite. Where it does earn its keep is in algebra and analysis: that every vector space has a basis, and that every non-trivial ring has a maximal ideal, are Zorn's lemma applied to a poset of subsets ordered by inclusion.
Example 3.62 (Version ordering). Semantic versions are compared by major, then minor, then patch. Is this a total order on a finite set of versions, and what is the first version in the list , , , ?
Solution.
- Comparison is lexicographic on triples of integers. Given two distinct versions, the first coordinate where they differ decides, so every pair is comparable and the order is total; reflexivity, antisymmetry and transitivity are inherited coordinatewise.
- By the theorem A finite total order is a numbering, the four versions have a unique correct arrangement.
- Compare major numbers first: has major , the others have major , so is least.
The classic bug is comparing versions as strings, which puts before because the character 1 precedes 2. Lexicographic order on strings and lexicographic order on tuples of integers are different total orders on the same set.□
- Treating "symmetric" and "antisymmetric" as opposites. The proposition Independence of the five properties exhibits a relation that is both (any subset of the diagonal) and one that is neither. The same applies to reflexive and irreflexive: a relation with some loops but not all is neither.
- "Symmetric plus transitive implies reflexive." The argument ", so , so " silently assumes that is related to something. The relation on is symmetric and transitive but not reflexive.
- Computing a transitive closure with one pass. Adding every shortcut for existing pairs does not in general produce a transitive relation, because the new pairs create new two-step paths. The closure is a union over all powers, bounded by terms on an -element set.
- Confusing maximal with greatest. Maximal means nothing is above it; greatest means it is above everything. A poset can have many maximal elements and no greatest one, as in .
- Counting relations instead of pairs. On an -set there are relations but only pairs available; and an equivalence relation with class sizes contains pairs, not or .
- Forgetting that a class is a set, not an element. is a subset of ; lives in the quotient . Writing is a type error.
- Allowing the empty block in a partition. Non-emptiness is what makes the correspondence of the theorem Equivalence relations are partitions a bijection rather than merely a surjection.
- Assuming every digraph gives a poset. A digraph with a directed cycle through two distinct vertices violates antisymmetry, so no topological sort exists — which is exactly what a build tool reports as a circular dependency.
- Expecting a maximal element in an infinite poset. The theorem needs finiteness (or the ascending chain condition). In the infinite case you need Zorn's lemma, and Zorn's lemma has a hypothesis — every chain has an upper bound — that must be checked.