Partial Orders
Some things can be ranked completely, like numbers by size. Others only partly: version ranges, task dependencies, subsets ordered by inclusion, or job candidates where one is better in salary and another in location. A partial order captures "comes before" or "is at most" when not every pair needs to be comparable.
Properties of relations on a set
For a relation on a set :
| Property | Definition | Example that has it |
|---|---|---|
| reflexive | for all | , , |
| irreflexive | never | , "is a parent of" |
| symmetric | "is a sibling of", | |
| antisymmetric | , , divides (on positive integers) | |
| asymmetric | , "is a parent of" | |
| transitive | , , , divides |
Two kinds of partial order
- A weak partial order is reflexive, antisymmetric and transitive. Examples: on numbers, on sets, (divides) on positive integers.
- A strict partial order is irreflexive and transitive (and hence asymmetric). Examples: , , "must be done before" for tasks.
They come in pairs: . A strict partial order is exactly the reachability relation of a DAG: " if there is a path of positive length from to ".
A partial order is total (or linear) if every two elements are comparable: or . Divisibility is not total: neither nor . Elements that are not comparable are incomparable.
from itertools import product
A = range(1, 13)
divides = lambda a, b: b % a == 0
props = {
"reflexive": all(divides(a, a) for a in A),
"antisymmetric": all(not (divides(a, b) and divides(b, a)) or a == b for a, b in product(A, A)),
"transitive": all(not (divides(a, b) and divides(b, c)) or divides(a, c) for a, b, c in product(A, A, A)),
"total": all(divides(a, b) or divides(b, a) for a, b in product(A, A)),
}
print("divides on 1..12:", props)
print("incomparable pairs, e.g.:", [(a, b) for a, b in product(A, A) if a < b and not divides(a, b)][:6])divides on 1..12: {'reflexive': True, 'antisymmetric': True, 'transitive': True, 'total': False}
incomparable pairs, e.g.: [(2, 3), (2, 5), (2, 7), (2, 9), (2, 11), (3, 4)]
Hasse diagrams
A finite partial order is drawn as a Hasse diagram: draw an edge from up to when and nothing lies strictly between them ( covers ). The other relations follow by transitivity, so they are omitted. The covering relation for divisibility on :
A = range(1, 13)
lt = lambda a, b: a != b and b % a == 0
covers = [(a, b) for a in A for b in A if lt(a, b) and not any(lt(a, c) and lt(c, b) for c in A)]
for a in A:
up = [b for x, b in covers if x == a]
if up:
print(f"{a:2d} -> {up}")
print("minimal elements:", [a for a in A if not any(lt(b, a) for b in A)])
print("maximal elements:", [a for a in A if not any(lt(a, b) for b in A)]) 1 -> [2, 3, 5, 7, 11]
2 -> [4, 6, 10]
3 -> [6, 9]
4 -> [8, 12]
5 -> [10]
6 -> [12]
minimal elements: [1]
maximal elements: [7, 8, 9, 10, 11, 12]
Each cover multiplies by a prime: . The minimal element is 1 (it divides everything), and the maximal elements are those with no multiple left in the set.
Product orders and representing orders as subsets
Two common constructions:
- Product order: if and . Comparing laptops by (RAM, storage), only some pairs are comparable; the non-dominated ones form the Pareto front.
- Lexicographic order: compare the first components, and only if they are equal, the second. It is total. Python compares tuples and strings this way.
Theorem. Every partial order on a set is isomorphic to a family of sets ordered by : map to its down-set . Then .
In software
Semantic versioning, type hierarchies (a subclass is "below" its superclass), lattice-based access control, vector clocks in distributed systems (one event happened before another only if every component is ) and Pareto-optimal results in multi-objective optimization are partial orders. Sorting needs a total order; topological sort extends a partial order to a total one.
Exercises
Exercise 1: Classify relations
Which properties do these relations on people have? (a) "is an ancestor of"; (b) "has the same birthday as"; (c) "is at least as tall as".
Answer
(a) irreflexive, asymmetric, transitive (a strict partial order); (b) reflexive, symmetric, transitive; (c) reflexive, transitive, total, but not antisymmetric.
Solution
(a) Nobody is their own ancestor; ancestry cannot go both ways; an ancestor of an ancestor is an ancestor. (b) is an equivalence relation (next lesson). (c) Two different people of the same height are each at least as tall as the other, so antisymmetry fails; it is a total preorder.
Exercise 2: Subsets
Draw (or list) the Hasse diagram of under . How many covering pairs are there?
Answer
It is a cube; 12 covering pairs.
Solution
covers when adds exactly one element to . Each of the 8 subsets can add each element it does not have; summing over subsets, . The diagram has at the bottom, the three singletons, the three pairs, and at the top.
Exercise 3: Pareto front (code)
Laptops as (RAM GB, battery hours): (8, 10), (16, 6), (16, 9), (32, 5), (8, 12), (12, 9). Which are not dominated in the product order?
Answer
(8, 12), (16, 9), (32, 5).
Solution
A laptop is dominated if another one is at least as good in both coordinates and different.
pts = [(8, 10), (16, 6), (16, 9), (32, 5), (8, 12), (12, 9)]
dom = lambda p, q: p != q and q[0] >= p[0] and q[1] >= p[1]
print([p for p in pts if not any(dom(p, q) for q in pts)])[(16, 9), (32, 5), (8, 12)]
Test yourself
A weak partial order is…
- reflexive, symmetric, transitive
- reflexive, antisymmetric, transitive
- irreflexive and symmetric
- total and symmetric
Under divisibility on , which pair is incomparable?
- (2, 8)
- (3, 12)
- (4, 6)
- (1, 7)
How does Python compare the tuples (2, 9) and (3, 1)?
- They are incomparable
(2, 9) < (3, 1)by lexicographic order(3, 1) < (2, 9)because 1 < 9- By the sum of components