The composition of $R$ and $S$ is the relation $S\mathbin {\diamond }R$ defined in one of three equivalent ways:
Let $A$, $B$, and $C$ be sets and let $R\colon A\mathrel {\rightarrow \kern -9.5pt\mathrlap {|}\kern 6pt}B$ and $S\colon B\mathrel {\rightarrow \kern -9.5pt\mathrlap {|}\kern 6pt}C$ be relations.
The composition of $R$ and $S$ is the relation $S\mathbin {\diamond }R$ defined in one of three equivalent ways:
Viewing relations from $A$ to $C$ as subsets of $A\times C$, we define
Viewing relations as functions $A\times B\to \{ \mathsf{true},\mathsf{false}\} $, we define
where the join $\bigvee $ is taken in the poset $(\{ \mathsf{true},\mathsf{false}\} ,\preceq )$ of Chapter 3: Sets, Definition 3.2.2.1.3.
Viewing relations as functions $A\to \mathcal{P}(B)$, we define
for each $V\in \mathcal{P}(B)$, so we have1
for each $a\in A$.
Omitted.
You might wonder what happens if we instead define an alternative composition of relations $\mathord {\mathbin {\diamond }'}$ via right Kan extensions. In this case, we would take the right Kan extension of $S$ along the dual characteristic embedding $B\hookrightarrow \mathcal{P}(B)^{\mathsf{op}}$:
This alternative composition turns out to actually be a different kind of structure: it’s an internal right Kan extension in $\boldsymbol {\mathsf{Rel}}$, namely $\operatorname {\mathrm{Ran}}_{R^{\dagger }}(S)$ — see Section 8.5.17.
Here are some examples of composition of relations.
Composing Less/Greater Than Equal With Greater/Less Than Equal Signs. Let $A=B=C=\mathbb {R}$. We have
Composing Less/Greater Than Equal Signs With Less/Greater Than Equal Signs. Let $A=B=C=\mathbb {R}$. We have
Let $R\colon A\mathrel {\rightarrow \kern -9.5pt\mathrlap {|}\kern 6pt}B$, $S\colon B\mathrel {\rightarrow \kern -9.5pt\mathrlap {|}\kern 6pt}C$, and $T\colon C\mathrel {\rightarrow \kern -9.5pt\mathrlap {|}\kern 6pt}D$ be relations.
Functoriality. The assignments $R,S,(R,S)\mapsto S\mathbin {\diamond }R$ define functors
In particular, given relations
Associativity. We have
That is, we have
for each $a\in A$.
Unitality. We have
That is, we have
for each $a\in A$.
Relation to Apartness Composition of Relations. We have
where $(-)^{\textsf{c}}$ is the complement functor of Chapter 4: Constructions With Sets, Section 4.3.11. In particular, $\mathord {\mathbin {\diamond }}$ is a special case of apartness composition of relations, as we have
This is also compatible with units, as we have $\Delta ^{\textsf{c}}_{A}=\nabla _{A}$.
Linear Distributivity. We have inclusions of relations
That is, we have
or, unwinding the expression for $S(R(a))$, we have
for each $a\in A$.
Interaction With Converses. We have
Interaction With Ranges and Domains. We have
This finishes the proof.
In the language of relations, given $a\in A$ and $d\in D$, the stated equality witnesses the equivalence of the following two statements:
We have $a\sim _{(T\mathbin {\diamond }S)\mathbin {\diamond }R}d$, i.e. there exists some $b\in B$ such that:
We have $a\sim _{R}b$;
We have $b\sim _{T\mathbin {\diamond }S}d$, i.e. there exists some $c\in C$ such that:
We have $b\sim _{S}c$;
We have $c\sim _{T}d$;
We have $a\sim _{T\mathbin {\diamond }(S\mathbin {\diamond }R)}d$, i.e. there exists some $c\in C$ such that:
We have $a\sim _{S\mathbin {\diamond }R}c$, i.e. there exists some $b\in B$ such that:
We have $a\sim _{R}b$;
We have $b\sim _{S}c$;
We have $c\sim _{T}d$;
both of which are equivalent to the statement
on the one hand and
on the other, so we want to prove an equality of the form
This then follows from an application of Chapter 4: Constructions With Sets, Item 2 of Proposition 4.3.6.1.2 in which we consider $X=D$, consider $\mathcal{P}(\mathcal{P}(\mathcal{P}(D)))$, take $U=U_{c}=T(c)$, take $A$ to be
and then finally take
Indeed, we have
and
This finishes the proof.
and
In the language of relations, given $a\in A$ and $b\in B$:
The equality
witnesses the equivalence of the following two statements:
We have $a\sim _{b}B$.
There exists some $b'\in B$ such that:
We have $a\sim _{R}b'$
We have $b'\sim _{\Delta _{B}}b$, i.e. $b'=b$.
The equality
witnesses the equivalence of the following two statements:
There exists some $a'\in A$ such that:
We have $a\sim _{\Delta _{B}}a'$, i.e. $a=a'$.
We have $a'\sim _{R}b$
We have $a\sim _{b}B$.
and
This finishes the proof.