2026-07-31 Putting Everything in Order

A paper I have been reading through on recently (OxCaml) does some very clever things with the OCaml type system. The basic idea is to wrap OCaml function types with qualifiers to ensure memory access safety statically from within the type system.

I wanted to write down notes on parts of the paper but then thought of a different idea - start with the underlying structure that has been used to add qualifiers to the type system and go from there. And for that, I thought I would start, as much as possible, from the beginning with relations and orders.

The Basics - Relations #

To understand what a relation is, let’s start with a set. Relying on the definition of a set to be a collection of objects, a relation can be thought of as a:

Using the second definition, for any two sets X and Y, denoting X x Y as the set of all possible pairs with xXx \in X , yYy \in Y , a binary relation R is its subset i.e. the set containing pairs for R holds for x,yx,y . When both x,yXx, y \in X , R is a relation on X itself.

Properties of Relations #

Using the notation xRyxRy for (x,y)R(x,y) \in R , relations on a set X for all x,y,zXx,y,z \in X can be characterized as:

Type Notation Note
empty ¬(xRy)\neg(xRy) ¬\neg denotes negation; in an empty set, no relation can hold
reflexive xRxxRx
irreflexive ¬(xRx\neg(xRx )
identity xRyx=yxRy \to x = y
transitive xRyyRzxRzxRy \land yRz \to xRz \land denotes andand
symmetric xRyyRxxRy \to yRx
antisymmetric xRyyRxx=yxRy \land yRx \to x=y
asymmetric xRy¬(yRx)xRy \to \neg(yRx)

It always helps to work through examples for dry mathematical definitions, so let’s see some for each property listed above. Given x,y,zx,y,z \in a set XX :

There are two important points for each property described above where each:

The Sense in Relations #

With sets as a collections of elements and relations between such elements defined above, an idea of how we can use such relations to position elements within the set comes from the definitions of the relations themselves.

The original idea of using relations to determine relative positions of elements i.e. an order between them comes from a paper by Bertrand Russell titled “On the Notion of Order”. The crux of the paper is as follows:

A casual collection of terms may be ordered by counting, in which case they are correlated with the integers; by speech, in which case they are correlated with a series of times; or by writing, in which case they correlated with a series of places. But the order arises, in each case, from the intrinsic order of the integers, the times, or the places respectively. These have an order independent of our caprice-they form what I shall call independent or self-sufficient series. The casual terms correlated with them form, on the contrary, only a series by correlation. Series by correlation are generated from self-sufficient series as follows: If there be a self-sufficient series A, B, C, D, . . . a collection of terms α\alpha , β\beta … and a specific relation R which subsists between alphaalpha and A, and β\beta and B, etc., but not between α\alpha and B or C or D or etc. (with similar exclusions for β\beta …), then α\alpha , β\beta … acquire, by correlation with A, B, C, D, the order which belongs intrinsically to A, B, C, D. Thus all orders by correlation are logically dependent upon intrinsic orders. The latter alone will be considered in what follows.

Order depends fundamentally upon relations having what mathematicians call sense, i.e., such that the relation of A to B is different from that of B to A. Such are east and west, greater and less, before and after, etc. But if order is to arise, another condition is necessary. It must be possible for the same relation with opposite senses to attach to a given term. This excludes such relations as occupation of a place or a time. For though a time may be occupied by an event, there is nothing which the time itself can occupy; and similarly as regards a place. Where both conditions are satisfied, we in general have an order. That is, if there be any relation R, having two senses R1_{1} , R2_{2} ; and if a term B have the relation R1_{1} to A, while it has the relation R2_{2} to C, then B is between A and C, and the three terms have the, order ABC or CBA. Thus these two conditions are necessary for an intrinsic order of three terms, and become sufficient if we add that BR1_{1} A, BR2_{2} C are to imply the denial (emphasis mine) of AR1_{1} C”

The idea is that a “collection of terms” (a set) with binary relations between its elements has an “intrinsic” order where if R is a relation on elements x,y,zx, y, z \in set XX with the property of being:

then elements x,y,zx, y, z can be compared using relations such as “is derived from”, “is less than”, “is contained in”, “happened before (/after)”, “comes before”. The asymmetry ensures the transitivity of the relation occurs only in one direction, without which there would be no way to put elements from XX in any distinct, comparative order. This is the “sense” talked about in the paper and translates to the common sense notion of order we use in our thinking and everyday speech.

Types of Orders #

From the fundamental understanding of an order in the last section, let’s build the definitions by adding or slightly modifying properties of relations.

If we were to add:

then a relation RR on (x,y,zx, y, z \in ) set XX is a (strict) partial order. The “partial” signifies that the relation holds only for those elements in the set which can be related using RR implying that it is not necessary for each element in XX to be related to every other element. The “strict” ensures that elements in XX can only be related to other element, never to itself.

Modifying the above definition to:

defines a weak partial order and is denoted by (X,)(X, ≤) . The set with such a order is a (weakly) partially ordered set (or a poset). The “weak” signifies that elements can be related to themselves.

An interesting mathematical property is that a relation is asymmetric if and only if it is both antisymmetric and irreflexive. So the asymmetry property of the strict partial order subsumes both an irreflexive property (superfluous in the definition actually) and an antisymmetry property. Weakening the definition to make the relation reflexive means the asymmetry property can no longer hold i.e. now when xRyxRy , it is possible yRxyRx . With the addition of antisymmetry, this can only be true when x=yx = y . This ensures that two elements can only be related in “both directions” if they are the same, implying that the equivalent guarantees of the asymmetry property are maintained in the presence of reflexivity for weak partial orders.

To work through a very simple example of a poset, let’s take a set SS = {1,2,3} and its powerset P(SS ) = {\varnothing , {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1, 2, 3}}. With RR defined as \subseteq i.e. subset, RR is:

An poset XX is termed a chain or a linearly ordered set or a totally ordered set when any two elements of XX are comparable (x,yX,xRyyRx\forall x, y \in X, xRy \lor yRx ).

The book “Introduction to Lattices and Order” covers many more definitions and examples on orders. The next topic that arises from the study of relations and orders are lattices which I’ll write it up in my next blog post.

References: