Order theory

Introduction

Order theory is the branch of mathematics that formalizes the concept of order using binary relations. This page introduces its basic definitions.

Definitions

Binary relations

Definition

A binary relation on sets XX and YY, denoted RR, is defined as the tuple (X,Y,G(R))(X,Y,G(R)), where XX is called the domain, YY the codomain, and G(R)⊆X×Y={(x,y):x∈X,y∈Y}G(R)\subseteq X\times Y=\{(x,y):x\in X,y\in Y\} the graph of the binary relation RR. xRyxRy holds if and only if (x,y)∈G(R)(x,y)\in G(R).

If X=YX=Y, the binary relation is called a homogeneous relation or an endorelation.

Unless stated otherwise, all binary relations below are homogeneous relations.

For example, on N+\mathbf{N}_+, divisibility ∣\mid and less-than-or-equal-to ≤\leq are both binary relations.

When studying binary relations, we are often interested in whether they have certain special properties. For a set SS and a binary relation RR on it, define the following properties:

  1. Reflexive: (∀ a∈S)  aRa(\forall~a \in S)~~aRa,
  2. Irreflexive (anti-reflexive): (∀ a∈S)  ¬(aRa)(\forall~a \in S)~~\lnot(aRa),
  3. Symmetric: (∀ a,b∈S)  aRb  ⟺  bRa(\forall~a,b \in S)~~aRb \iff bRa,
  4. Antisymmetric: (∀ a,b∈S)  (aRb∧bRa)  ⟹  a=b(\forall~a,b \in S)~~(aRb \land bRa) \implies a=b,
  5. Asymmetric: (∀ a,b∈S)  aRb  ⟹  ¬(bRa)(\forall~a,b \in S)~~aRb \implies \lnot(bRa),
  6. Transitive: (∀ a,b,c∈S)  (aRb∧bRc)  ⟹  aRc(\forall~a,b,c \in S)~~(aRb \land bRc) \implies aRc,
  7. Connected: (∀ a,b∈S)  a≠b  ⟹  (aRb∨bRa)(\forall~a,b \in S)~~a \neq b \implies (aRb \lor bRa),
  8. Well-founded: (∃ m∈S≠∅)  (∀ a∈S∖{m})  ¬(aRm)(\exists~m \in S \neq \varnothing)~~(\forall~a \in S\setminus\{m\})~~\lnot(aRm) (that is, a nonempty set SS contains a minimal element mm),
  9. Transitive of incomparability: (∀ a,b,c∈S)  (¬(aRb∨bRa)∧¬(bRc∨cRb))  ⟹  ¬(aRc∨cRa)(\forall~a,b,c \in S)~~(\lnot(aRb \lor bRa) \land \lnot(bRc \lor cRb)) \implies \lnot(aRc \lor cRa) (if ¬(aRb∨bRa)\lnot(aRb \lor bRa), then aa and bb are called incomparable).

We also define several special binary relations:

Binary relationReflexiveIrreflexiveSymmetricAntisymmetricAsymmetricTransitiveConnectedWell-foundedTransitive of incomparability
Equivalence relationYesYesYes
Preorder (quasiorder)YesYes
Partial orderYesYesYes
Total orderYesYesYesYes
Well-orderYesYesYesYesYes
Strict preorderYesYes
Strict partial orderYesYesYes
Strict weak orderYesYesYesYes
Strict total orderYesYesYesYes

Operations on relations

For sets XX and YY, and binary relations RR and SS on them, we can define the following operations:

  1. The union of RR and SS, R∪SR\cup S, satisfies G(R∪S):={(x,y):xRy∨xSy}G(R\cup S):=\{(x,y):xRy \lor xSy\} (for example, ≤\leq is the union of << and ==),
  2. The intersection of RR and SS, R∩SR\cap S, satisfies G(R∩S):={(x,y):xRy∧xSy}G(R\cap S):=\{(x,y):xRy \land xSy\},
  3. The complement of RR, Rˉ\bar{R}, satisfies G(Rˉ):={(x,y):¬(xRy)}G(\bar{R}):=\{(x,y):\lnot(xRy)\},
  4. The dual of RR, RTR^T, satisfies G(RT):={(y,x):xRy}G(R^T):=\{(y,x):xRy\}.

For sets XX and YY with a binary relation RR, and sets YY and ZZ with a binary relation SS, we can define their composition S∘RS\circ R by G(S∘R):={(x,z):(∃ y∈Y)  xRy∧ySz}G(S\circ R):=\{(x,z):(\exists~y\in Y)~~xRy\land ySz\}.

Partially ordered sets

Definition

If, on a set SS, a binary relation ⪯\preceq is reflexive, antisymmetric, and transitive, then SS is called a partially ordered set (poset), and ⪯\preceq is a partial order on it.

If the partial order ⪯\preceq is also connected, it is called a total order. The corresponding set is called a totally ordered set, a linearly ordered set (loset), or a simply ordered set.

It is easy to see that N\mathbf{N}, Z\mathbf{Z}, Q\mathbf{Q}, and R\mathbf{R} are all totally ordered sets under ≤\leq.

Visual representation of a poset: Hasse diagrams

For a finite poset, we can use a Hasse diagram to visualize its partial order.

Definition

For a finite poset SS with partial order ⪯\preceq, define x≺y  ⟺  (x⪯y∧x≠y)x\prec y\iff (x\preceq y\land x\neq y). Its corresponding Hasse diagram is a graph G=⟨V,E⟩G=\langle V,E\rangle satisfying:

  • V=SV=S,
  • E={(x,y)∈S×S:x≺y∧((∄ z∈S)  x≺z≺y)}E=\{(x,y)\in S\times S: x\prec y \land ((\nexists~z\in S)~~x\prec z\prec y)\}

For example, for the power set {0,1,2}\{0,1,2\}, denoted SS, with the subset relation ⊆\subseteq, the corresponding Hasse diagram is:

Figure: order theory1

Because a partial order is antisymmetric, a Hasse diagram is necessarily a directed acyclic graph. We can therefore construct a total order for any finite poset using topological sorting.

Chains and antichains

Definition

For a poset SS with partial order ⪯\preceq, a totally ordered subset of SS is called a chain. If SS has a subset TT in which every pair of distinct elements is incomparable (that is, (∀ a,b∈T)  a≠b  ⟹  (a⋠b∧b⋠a)(\forall~a,b \in T)~~a \neq b \implies (a \npreceq b \land b \npreceq a)), then TT is called an antichain.

For a poset SS with partial order ⪯\preceq, we call the length of the longest antichain of SS the width (partial-order width).

For example, for the power set {0,1,2}\{0,1,2\}, denoted SS, with the subset relation ⊆\subseteq, {∅,{1},{1,2}}\{\varnothing,\{1\},\{1,2\}\} is a chain, {{1},{0,2}}\{\{1\},\{0,2\}\} is an antichain, and the width of SS is 33.

Special elements in preordered sets

In a preordered set, we can define concepts such as maximal and minimal elements, upper and lower bounds, and suprema and infima. These concepts extend to other order relations.

Definition

For a preordered set SS with preorder ⪯\preceq, take an element of SS, mm:

  1. If (∀ a∈S∖{m})  ¬(m⪯a)(\forall~a \in S\setminus\{m\})~~\lnot(m\preceq a), then mm is a maximal element,
  2. If T⊆ST \subseteq S satisfies (∀ t∈T)  t⪯m(\forall~t\in T)~~t\preceq m, then mm is an upper bound of TT,
  3. If T⊆ST \subseteq S satisfies that mm is an upper bound of TT and every upper bound of TT, nn, satisfies m⪯nm \preceq n, then mm is the supremum of TT.

The concepts of a minimal element, lower bound, and infimum are defined analogously.

For example, 11 is a minimal element and a lower bound of N+\mathbf{N}_+.

It can be proved that:

  • In a preordered set, maximal and minimal elements, upper and lower bounds, and suprema and infima need not exist; even when they exist, they need not be unique.

  • If a poset SS has a subset TT with a supremum or infimum, it is unique.

    We denote the supremum and infimum of TT by sup⁡T\sup T and inf⁡T\inf T, respectively. If a poset SS has both an upper bound and a lower bound, then SS is called bounded.

In an infinite poset, a maximal element need not exist. Zorn's Lemma can be used to determine whether an infinite poset has a maximal element.

Zorn's Lemma

Zorn's Lemma, also called the Kuratowski–Zorn Lemma, states that if every chain of a nonempty poset has an upper bound, then the poset has a maximal element.

Zorn's Lemma is equivalent to the axiom of choice and the well-ordering theorem.

Directed sets and lattices

We know that if a subset of a poset has a supremum or infimum, it is unique. This does not hold for maximal and minimal elements. For example, consider the poset S={{0},{1},{2},{0,1},{0,2},{1,2}}S=\{\{0\},\{1\},\{2\},\{0,1\},\{0,2\},\{1,2\}\} under the partial order ⊆\subseteq. It is easy to see that it has 33 maximal elements and 33 minimal elements.

We would like to add conditions to a poset so that whenever a maximal or minimal element exists, it is unique; this would let us define greatest and least elements.

Directed sets

For a preordered set SS with preorder ⪯\preceq, if (∀ a,b∈S)  (∃ c∈S)  a⪯c∧b⪯c(\forall~a,b\in S)~~(\exists~c\in S)~~a\preceq c\land b\preceq c, then ⪯\preceq is called a direction on SS, and SS is called a directed set or a filtered set.

A set SS satisfying the definition above is sometimes called an upward directed set; a downward directed set is defined similarly.

Directed sets can also be defined as follows:

Equivalent definition of a directed set

For a preordered set SS with preorder ⪯\preceq, if every finite subset of SS (denoted TT) has an upper bound, then ⪯\preceq is called a direction on SS, and SS is called a directed set.

It is easy to see that:

  • If an upward directed set has a maximal element, it is unique. We call the maximal element of an upward directed set its greatest element.
  • If a downward directed set has a minimal element, it is unique. We call the minimal element of a downward directed set its least element.

In a directed poset, for any elements a,ba,b, the set {a,b}\{a,b\} has an upper bound. Replacing “upper bound” with “supremum” gives the definition of a join-semilattice.

For a poset SS with partial order ⪯\preceq:

Join-semilattice

If SS is such that, for any elements a,ba,b, the set {a,b}\{a,b\} has a supremum cc, then SS is called a join-semilattice (upper semilattice), and cc is called the join of aa and bb, denoted a∨ba\lor b.

Meet-semilattice

If SS is such that, for any elements a,ba,b, the set {a,b}\{a,b\} has an infimum cc, then SS is called a meet-semilattice (lower semilattice), and cc is called the meet of aa and bb, denoted a∧ba\land b.

Lattice

If SS is both a join-semilattice and a meet-semilattice, then SS is called a lattice.

For example, the set of positive divisors of 6060, S={1,2,3,4,5,6,10,12,15,20,30,60}S=\{1,2,3,4,5,6,10,12,15,20,30,60\}, forms a poset under divisibility. For any positive integers a,ba,b in it, lcm⁡(a,b)\operatorname{lcm}(a,b) is the join of aa and bb, while gcd⁡(a,b)\gcd(a,b) is the meet of aa and bb, so SS is a lattice.

Duality

Duality is a common concept in order theory. Examples mentioned above include the duality between maximal and minimal elements, between upper and lower bounds, and between suprema and infima.

For a poset PP with partial order ⪯\preceq, define its dual (opposite) poset PdP^d by: x⪯yx \preceq y holds in PP if and only if y⪯xy \preceq x holds in PdP^d. Reversing the edges of the Hasse diagram of PP gives the Hasse diagram of PdP^d.

Dilworth's theorem and Mirsky's theorem

For a finite poset SS with partial order ⪯\preceq, we have the following pair of dual theorems:

Dilworth's theorem

The width of SS (the length of its longest antichain) equals the minimum number of chains in a chain cover.

Proof

Consider induction. When ∣S∣≤3|S|\leq 3, the claim is obvious.

Assume the claim holds for every poset with fewer than ∣S∣|S| elements, and let the width of SS be dd. If all ∣S∣|S| elements are pairwise incomparable, the claim is obvious; otherwise, choose in SS a chain of length greater than 11, and let its minimal and maximal elements be mm and MM.

Let T=S∖{m,M}T=S\setminus\{m,M\}. If the width of TT is at most d−1d-1, then by induction TT can be covered by at most d−1d-1 chains, so SS can be covered by those chains together with the chain {m,M}\{m,M\}, proving the claim. Otherwise, the width of TT is also dd; let the longest antichain in TT be AA.

Consider the following two sets:

S+:={x∈S:(∃ a∈A)  a⪯x}S^+:=\{x\in S:(\exists~a\in A)~~a\preceq x\} S−:={x∈S:(∃ a∈A)  x⪯a}S^-:=\{x\in S:(\exists~a\in A)~~x\preceq a\}

It is easy to see that:

  • S+∪S−=SS^+\cup S^-=S,
  • S+∩S−=AS^+\cap S^-=A,
  • ∣S+∣<∣S∣|S^+|<|S|,∣S−∣<∣S∣|S^-|<|S| (because m∉S+m\notin S^+ and M∉S−M\notin S^-).

Applying the induction hypothesis to both S+S^+ and S−S^-, their minimum chain-cover number is dd, and each of these covers contains exactly one element of the antichain AA, say aa. Denote the corresponding chains by Ca+C_a^+ and Ca−C_a^-. Then {Ca−∪{a}∪Ca+}a∈A\{C_a^-\cup\{a\}\cup C_a^+\}_{a\in A} is a minimum chain cover of SS, proving the claim.

Mirsky's theorem

The length of the longest chain in SS equals the minimum number of antichains in an antichain cover.

Proof

Let the length of the longest chain in SS be dd. By definition, the minimum number of antichains in a cover is at least dd.

Let f(s)f(s) be the length of the longest chain whose minimal element is ss. If f(s)=f(t)f(s)=f(t), then ss and tt are incomparable, so (∀ n∈N)  f−1({n})(\forall~n\in\mathbf{N})~~f^{-1}(\{n\}) is an antichain, where f−1({n}):={a∈S:f(a)=n}f^{-1}(\{n\}):=\{a\in S:f(a)=n\} is called a level set.

It follows that {f−1({i}):1≤i≤d}\{f^{-1}(\{i\}):1\leq i\leq d\} is an antichain cover, so the minimum number of antichains in a cover is at most dd.

Dilworth's theorem is equivalent to Hall's marriage theorem.

We can use Dilworth's theorem to prove the following theorem:

Erdős–Szekeres theorem

A real sequence with at least rs+1rs+1 elements, {ai}\{a_i\}, either has a nondecreasing subsequence of length r+1r+1 or a nonincreasing subsequence of length s+1s+1.

Proof

Let the sequence length be n≥rs+1n\geq rs+1, and define the poset {(i,ai)}i=1n\{(i,a_i)\}_{i=1}^{n} with partial order ⪯\preceq given by:

(i,ai)⪯(j,aj)  ⟺  (i≤j∧ai≤aj)(i,a_i)\preceq (j,a_j)\iff (i\leq j\land a_i\leq a_j)

If the width of this poset is at most ss, then by Dilworth's theorem it can be covered by at most ss chains. If all those chains have length at most rr, the sequence contains at most rsrs elements, contradicting the assumption.

Examples

Luogu P1020 [NOIP 1999 Advanced Group] Missile Interception

To defend against missile attacks from an enemy country, a country developed a missile-interception system. However, the system has a defect: although its first shell can reach any altitude, every later shell cannot be higher than the preceding shell. One day, radar detected incoming enemy missiles. Since the system was still in a trial phase, there was only one system, so it might not be possible to intercept all the missiles.

Given the altitudes of the missiles in arrival order, compute how many missiles this system can intercept at most, and how many such systems are needed at minimum to intercept all missiles.

For all test data, missile altitudes are positive integers no greater than 5×1045\times 10^4.

Solution

Suppose there are nn missiles, and the altitude of the ii-th missile is hih_i. Then {(i,hi)}i=1n\{(i,h_i)\}_{i=1}^{n} is a poset with partial order ⪯\preceq defined by:

(i,hi)⪯(j,hj)  ⟺  (i≤j∧hi≥hj)(i,h_i)\preceq(j,h_j) \iff (i\leq j \land h_i\geq h_j)

By Dilworth's theorem, the minimum number of nonincreasing subsequences covering the sequence equals the length of its longest increasing subsequence. Thus the problem can be solved using the O(nlog⁡n)O(n\log n) method for the longest nondecreasing subsequence.

Reference code
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> a;
  int x;
  while (cin >> x) a.push_back(x);
  vector<int> f, g;
  for (int i : a) {
    if (f.empty() || -i >= f.back())
      f.push_back(-i);
    else
      *upper_bound(f.begin(), f.end(), -i) = -i;
    if (g.empty() || i > g.back())
      g.push_back(i);
    else
      *lower_bound(g.begin(), g.end(), i) = i;
  }
  cout << f.size() << '\n' << g.size() << '\n';
  return 0;
}
[TJOI2015] Combinatorics

Given an nn-row, mm-column grid, with some treasures in every cell. Starting from the upper-left corner, one may move only right or down, and may collect at most one treasure each time a cell is visited. What is the minimum number of traversals needed to collect all treasures?

1≤n≤10001\le n \le 1000, 1≤m≤10001\le m \le 1000, and each cell contains at most 10610^6 treasures.

Solution

Ignoring vertex weights, it is easy to see that walking on the grid under the given rules is equivalent to walking on a DAG. We can therefore regard it as a Hasse diagram to construct a poset, and Dilworth's theorem gives: the minimum chain-cover number of a DAG equals the size of its largest vertex-independent set.

Therefore, the answer is the total weight of a maximum-weight independent set in the given grid graph.

Let aija_{ij} be the weight of grid vertex (i,j)(i,j), and let f(i,j)f(i,j) be the answer for the subgrid from (i,j)(i,j) to (1,m)(1,m). Since each vertex is nonadjacent to its upper-right vertex, the state transition is:

f(i,j)=max⁡{f(i−1,j),f(i,j+1),f(i−1,j+1)+aij}f(i,j)=\max\{f(i-1,j),f(i,j+1),f(i-1,j+1)+a_{ij}\}

The answer is f(n,1)f(n,1).

Reference code
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int t = 0;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int64_t>> a(n, vector<int64_t>(m));
    for (auto &i : a)
      for (auto &j : i) cin >> j;
    vector<vector<int64_t>> f(n, vector<int64_t>(m));
    for (int i = 0; i < n; ++i)
      for (int j = m - 1; j >= 0; --j)
        f[i][j] =
            max({(i == 0 ? 0 : f[i - 1][j]), (j == m - 1 ? 0 : f[i][j + 1]),
                 (i == 0 || j == m - 1 ? 0 : f[i - 1][j + 1]) + a[i][j]});
    cout << f[n - 1][0] << '\n';
  }
  return 0;
}

Exercises

Applications in C++

See also: STL related to sorting — Basic algorithms.

The C++ STL algorithms and data structures requiring comparisons apply order theory. We often need to define custom comparators in C++; the STL requires them to be a strict weak order. Let << be a custom comparator; then we can define:

  • x>yx>y as y<xy<x;
  • x≤yx \leq y as y≮xy \nless x;
  • x≥yx \geq y as x≮yx \nless y;
  • x=yx=y as x≮y∧y≮xx \nless y\land y \nless x.

References and further reading

  1. Order theory - From Academic Kids
  2. Binary Relation - Wikipedia
  3. Order Theory - Wikipedia
  4. Hasse diagram - Wikipedia
  5. Directed set - Wikipedia
  6. Order Theory, Lecture Notes by Mark Dean for Decision Theory
  7. Kaicheng Lu, Huaming Lu, Combinatorics (3rd ed.), 2006
  8. List of Order Theory Topics - Wikipedia
  9. A discussion of applications of adjacent-swap sorting and points to note by ouuan
  10. One thing you should know about comparators—Strict Weak Ordering
  11. Dilworth's theorem - Wikipedia
  12. Dilworth's Theorem | Brilliant Math & Science Wiki
  13. Hall's marriage theorem - Wikipedia
  14. Hall's Marriage Theorem | Brilliant Math & Science Wiki
  15. Dilworth study notes - Selfish

This content comes from OI Wiki: Order theory. See the original for authors and revision history. AIOJ has adapted the formatting, in-site links, and resource paths.

Content is shared under CC BY-SA 4.0 and SATA license; additional terms are governed by the original notice. Thanks to the OI Wiki authors and contributors; per the SATA terms, please visit the OI Wiki repository and star it to show your support.