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.
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:
function between sets, for example:
sets of elements, where:
Using the second definition, for any two sets X and Y, denoting X x Y as the set of all possible pairs with , , a binary relation R is its subset i.e. the set containing pairs for R holds for . When both , R is a relation on X itself.
Using the notation for , relations on a set X for all can be characterized as:
| Type | Notation | Note |
|---|---|---|
| empty | denotes negation; in an empty set, no relation can hold | |
| reflexive | ||
| irreflexive | ) | |
| identity | ||
| transitive | denotes | |
| symmetric | ||
| antisymmetric | ||
| asymmetric |
It always helps to work through examples for dry mathematical definitions, so let’s see some for each property listed above. Given a set :
empty ( :
R = and denotes R has no pairs. All of the other properties become vacuously true (hold for the empty set) except for the reflexive one. Since R is empty, there isn’t a way to relate every to itself.
The one subtlety is that if both R = and , then the reflexive property holds along with all others (all elements of an empty set are related to themselves via an empty relation).
reflexive ( ):
The relation on the set of integers where R = (E.g. 1 1, 2 2, …)
The relation “is reachable from” for nodes in a graph. R =
irreflexive ( )): The relation on the set of integers .
R = = =
R = where are sets and elements of the powerset of set X. ( stands for “is a subset of and not equal to” and denotes a strict subset).
identity ( ):
The relation “is equal to” on the set of natural numbers R =
The relation “the result from an identity function” where R =
transitive ( ):
The relation on the set of integers where R = (1 2 and 2 3 1 3)
The relation “is an ancestor of” in a graph whose nodes form a set and i.e. node x is an ancestor to both y and z
symmetric ( ):
For X = i.e. the set of reals excluding 0, multiplicative inverses i.e.
For X = only, additive inverses i.e. $R =
For X be the set of all nodes in a graph with the depth of a node defined from its root. Then
are all symmetric
antisymmetric ( ):
For as the set of positive integers, xRy where R is “divides”. If x were to divide y and y x, then the only possibility is that x = y.
R = where are sets and elements of the powerset of set X. ( stands for “is a subset of”). Only if can hold
asymmetric ( ):
For X be the set of all nodes in a graph with R defined as “is the parent of”. R = Alternatively: R =
The relation on the set of integers where R =
There are two important points for each property described above where each:
holds for a relation R if and only if it holds of its converse R , defined by (courtesy of the duality principle)
extends to Boolean combinations of the above properties i.e. those formed using the boolean ‘and’ ( ), ‘or’ ( ) and ‘not’ ( ).
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 , … and a specific relation R which subsists between and A, and and B, etc., but not between and B or C or D or etc. (with similar exclusions for …), then , … 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 R , R ; and if a term B have the relation R to A, while it has the relation R 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 BR A, BR C are to imply the denial (emphasis mine) of AR 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 set with the property of being:
then elements 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 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.
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 on ( ) set is a (strict) partial order. The “partial” signifies that the relation holds only for those elements in the set which can be related using implying that it is not necessary for each element in to be related to every other element. The “strict” ensures that elements in can only be related to other element, never to itself.
Modifying the above definition to:
defines a weak partial order and is denoted by . 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 , it is possible . With the addition of antisymmetry, this can only be true when . 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 = {1,2,3} and its powerset P( ) = { , {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1, 2, 3}}. With defined as i.e. subset, is:
An poset is termed a chain or a linearly ordered set or a totally ordered set when any two elements of are comparable ( ).
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: