In the present section, we will show that inverse categories with countable joins are intrinsically \(\mathbf {CPO}\)-enriched. This observation leads to two properties that are highly useful for modelling reversible functional programming, namely the existence of fixed points for both morphism schemes for recursion (that is, continuous endomorphisms on hom-objects) and for locally continuous functors. The former can be applied to model reversible recursive functions, and the latter to model recursive data types [3]. Further, we will show that the partial inverse of the fixed point of a morphism scheme for recursion can be computed as the fixed point of an adjoint morphism scheme, giving a style of recursion similar to the reversible functional programming language rfun [39].
Recall that a category \(\mathscr {C}\) is \(\mathbf {CPO}\)-enriched (or simply a \(\mathbf {CPO}\)-category) if all \(\mathrm{{Hom}_\mathscr {C}}(A,B)\) are pointed \(\omega \)-complete partial orders (i.e., they have a least element and satisfy that each \(\omega \)-chain has a supremum), and composition is monotone, continuous and strict. To begin, we will need the lemma below.
Lemma 1
Let \(\mathscr {C}\) be an inverse category and \(f,g : A \rightarrow B\) be parallel morphisms of \(\mathscr {C}\). If \(f \le g\) then \(f \asymp g\).
This lemma allows us to show \(\mathbf {CPO}\)-enrichment of join inverse categories:
Theorem 1
Every inverse category \(\mathscr {C}\) with countable joins is \(\mathbf {CPO}\)-enriched.
Proof
Let A, B be objects of \(\mathscr {C}\), and let \(\{f_i\}_{i \in \omega }\) be an \(\omega \)-chain in \(\mathrm{{Hom}_\mathscr {C}}(A,B)\) with respect to the canonical partial ordering. By Lemma 1, all \(f_i\) and \(f_j\) for \(i,j \in \omega \) of this chain are inverse compatible, so the set \(F = \{f_i \mid i \in \omega \}\) is an inverse compatible subset of \(\mathrm{{Hom}_\mathscr {C}}(A,B)\). But then we can form the supremum of \(\{f_i\}_{i \in \omega }\) by
$$\begin{aligned} \sup \{f_i\}_{i \in \omega } = \bigvee _{f \in F} f \end{aligned}$$
which is the supremum of this chain directly by definition of the join.
Let \(f,g : A \rightarrow B\) and \(F = \{f_i \mid i \in \omega \}\). Monotony of compositions holds in all restriction categories, not just inverse categories with countable joins: Supposing \(f \le g\) then \(g \circ \overline{f} = f\), and for \(h : B \rightarrow X\),
$$\begin{aligned} h \circ g \circ \overline{h \circ f} = h \circ g \circ \overline{h \circ g \circ \overline{f}} = h \circ g \circ \overline{h \circ g} \circ \overline{f} = h \circ g \circ \overline{f} = h \circ f \end{aligned}$$
so \(h \circ f \le h \circ g\) in \(\mathrm {Hom}_\mathscr {C}(A,X)\); the argument is analogous for postcomposition. That composition is continuous follows directly by definition of joins, as we have
$$\begin{aligned} h \circ \sup \{f_i\}_{i \in \omega } = h \circ \bigvee _{f \in F} f = \bigvee _{f \in F} (h \circ f) = \sup \{h \circ f_i\}_{i \in \omega } \end{aligned}$$
for all \(h : B \rightarrow X\), and analogously for postcomposition. That composition is strict follows by the fact that the zero map \(0_{A,B} : A \rightarrow B\) is least in \(\mathrm{{Hom}_\mathscr {C}}(A,B)\), and that \(g \circ 0_{A,B} = 0_{A,X}\) for all \(g : B \rightarrow X\) by the universal mapping property of the zero object, and likewise for postcomposition. \(\square \)
Recall that a functor \(F : \mathscr {C} \rightarrow \mathscr {D}\) between \(\mathbf {CPO}\)-categories is locally continuous iff each \(F_{A,B} : \mathrm{{Hom}_\mathscr {C}}(A,B) \rightarrow \mathrm {Hom}_\mathscr {D}(FA,FB)\) is monotone and continuous. Note that since all restriction functors preserve the partial order on hom-sets, and since suprema are defined in terms of joins, join restriction functors are in particular locally continuous.
3.1 Reversible Fixed Points of Morphism Schemes
In the following, let \(\mathscr {C}\) be an inverse category with countable joins. We will use the term morphism scheme to refer to a monotone and continuous function \(f : \mathrm{{Hom}_\mathscr {C}}(A,B) \rightarrow \mathrm {Hom}_\mathscr {C}(X,Y)\) – note that such schemes are morphisms of \(\mathbf {CPO}\) and not of the inverse category \(\mathscr {C}\), so they are specifically not required to have inverses. Enrichment in \(\mathbf {CPO}\) then has the following immediate corollary by Kleene’s fixed point theorem:
Corollary 1
Every morphism scheme of the form \(\mathrm{{Hom}_\mathscr {C}}(A,B) \xrightarrow {f} \mathrm{{Hom}_\mathscr {C}}(A,B)\) has a least fixed point \(\text {fix}~f : A \rightarrow B\) in \(\mathscr {C}\).
Proof
Define \(\text {fix}~f = \sup \{f^n(0_{A,B})\}\); that this is the least fixed point follows by Kleene’s fixed point theorem, as \(0_{A,B}\) is least in \(\mathrm{{Hom}_\mathscr {C}}(A,B)\). \(\square \)
Morphism schemes on their own are useful for modelling parametrized reversible functions, i.e., functions that take other functions given at compile-time as parameters to produce new, first-order reversible functions. Since higher-order reversible functional programming is yet to be well-understood, parametrized functions (as implemented in, e.g., Theseus [25]) allow for a higher degree of abstraction and code reuse, as we know it from higher-order functional irreversible programming. With this in mind, recursive reversible functions can be seen as least fixed points of self-parametrized functions.
Given that we can thus model reversible recursive functions via least fixed points of morphism schemes, a prudent question to ask is if the inverse of a least fixed point can be computed as the least fixed point of another morphism scheme. We will answer this in the affirmative, but to do this, we need to show that the induced dagger functor is locally continuous.
Lemma 2
The canonical dagger functor \(\dagger : \mathscr {C}^\mathrm{{op}} \rightarrow \mathscr {C}\) is locally continuous.
Proof
Let \(f,g : A \rightarrow B\). For monotony, suppose \(f \le g\), i.e., \(g \circ \overline{f} = f\). Then
$$\begin{aligned} g^\dagger \circ \overline{f^\dagger }&= g^\dagger \circ f \circ f^\dagger = g^\dagger \circ g \circ \overline{f} \circ f^\dagger = \overline{g} \circ \overline{f} \circ f^\dagger = \overline{g \circ \overline{f}} \circ f^\dagger \\&= \overline{f} \circ f^\dagger = f^\dagger \circ f \circ f^\dagger = f^\dagger \circ \overline{f^\dagger } = f^\dagger \end{aligned}$$
so \(f^\dagger \le g^\dagger \) as well, as desired. For continuity, let \(\{f_i\}_{i \in \omega }\) be an \(\omega \)-chain in \(\mathrm{{Hom}_\mathscr {C}}(A,B)\), and let \(F = \{f_i \mid i \in \omega \}\) be the corresponding set for this chain. Since \(f \le \bigvee _{f \in F} f\) for each \(f \in F\) by Definition 11, we have \(f^\dagger \le \left( \bigvee _{f \in F} f\right) ^\dagger \) for all \(f \in F\) by monotony of \(\dagger \), and so
$$\begin{aligned} \sup \{f_i^\dagger \}_{i \in \omega } = \bigvee _{f \in F} f^\dagger \quad \le \quad \left( \bigvee _{f \in F} f\right) ^\dagger = \sup \{f_i\}^\dagger _{i \in \omega } \end{aligned}$$
by Definition 11. In the other direction, we have \(f^\dagger \le \bigvee _{f \in F} f^\dagger \) for all \(f \in F\) by Definition 11, so by monotony of \(\dagger \), \(f = f^{\dagger \dagger } \le \left( \bigvee _{f \in F} f^\dagger \right) ^\dagger \) for all \(f \in F\). But then \(\bigvee _{f \in F} f \le \left( \bigvee _{f \in F} f^\dagger \right) ^\dagger \) by Definition 11, and so by monotony of \(\dagger \), we finally get
$$\begin{aligned} \sup \{f_i\}^\dagger _{i \in \omega } = \left( \bigvee _{f \in F} f\right) ^\dagger \quad \le \quad \left( \bigvee _{f \in F} f^\dagger \right) ^{\dagger \dagger } = \bigvee _{f \in F} f^\dagger = \sup \{f_i^\dagger \}_{i \in \omega } \end{aligned}$$
as desired. \(\square \)
With this lemma, we are able to show that the inverse of a least fixed point of a morphism scheme can be computed as the least fixed point of an adjoint morphism scheme:
Theorem 2
Every morphism scheme of the form \(\mathrm{{Hom}_\mathscr {C}}(A,B) \xrightarrow {f} \mathrm{{Hom}_\mathscr {C}}(A,B)\) has an adjoint morphism scheme \( \mathrm {Hom}_\mathscr {C}(B,A) \xrightarrow {f_\ddagger } \mathrm {Hom}_\mathscr {C}(B,A)\) such that \((\text {fix}~f)^\dagger = \text {fix}~f_\ddagger \).
Proof
Let \(\iota _{A,B} : \mathrm{{Hom}_\mathscr {C}}(A,B) \rightarrow \mathrm {Hom}_\mathscr {C}(B,A)\) denote the family of functions defined by \(\iota _{A,B}(f) = f^\dagger \); each of these are monotone and continuous by Lemma 2, and an isomorphism (with inverse \(\iota _{B,A}\)) by \(f^{\dagger \dagger } = f\). Given a morphism scheme \(f : \mathrm{{Hom}_\mathscr {C}}(A,B) \rightarrow \mathrm{{Hom}_\mathscr {C}}(A,B)\), we define \(f_\ddagger = \iota _{A,B} \circ f \circ \iota _{B,A}\) – this is monotone and continuous since it is a (monotone and continuous) composition of monotone and continuous functions. But since
$$\begin{aligned} f_\ddagger ^n = (\iota _{A,B} \circ f \circ \iota _{B,A})^n = \iota _{A,B} \circ f^n \circ \iota _{B,A} \end{aligned}$$
by \(\iota _{B,A}\) an isomorphism with inverse \(\iota _{A,B}\), and since \(0_{A,B}^\dagger = 0_{B,A}\) by the universal mapping property of the zero object, we get
$$\begin{aligned} \text {fix}~f_\ddagger&= \sup \{f_\ddagger ^n(0_{B,A})\} = \sup \{(\iota _{A,B} \circ f^n \circ \iota _{B,A})(0_{B,A})\} = \sup \{f^n(0_{B,A}^\dagger )^\dagger \} \\&= \sup \{f^n(0_{A,B})^\dagger \} = \sup \{f^n(0_{A,B})\}^\dagger = (\text {fix}~f)^\dagger \end{aligned}$$
as desired. \(\square \)
In modelling recursion in reversible functional programming, this theorem states precisely that the partial inverse of a recursive reversible functions is, itself, a recursive reversible function, and that it can be obtained by inverting the function body and replacing recursive calls with recursive calls to the thus constructed inverse: Coincidentally, this is precisely the inverse semantics of recursive reversible functions in rfun [39].
3.2 Algebraic \(\omega \)-compactness for Free!
A pleasant property of \(\mathbf {CPO}\)-categories is that algebraic \(\omega \)-compactness – the property that every locally continuous functor has a canonical fixed point – is relatively easy to check for, thanks to the fixed point theorem due to Adámek [3] and Barr [5]:
Theorem 3
(Adámek & Barr). Let \(\mathscr {C}\) be a \(\mathbf {CPO}\)-category with an initial object. If \(\mathscr {C}\) has colimits of \(\omega \)-sequences of embeddings, then \(\mathscr {C}\) is algebraically \(\omega \)-compact over \(\mathbf {CPO}\).
Canonical fixed points of functors are of particular interest in modelling functional programming, since they can be used to provide interpretations for recursive data types. In the following, we will couple this theorem with a join-completion theorem for restriction categories to show that every inverse category can be faithfully embedded in an algebraically \(\omega \)-compact inverse category with joins. That this succeeds rests on the following lemmas:
Lemma 3
If an inverse category \(\mathscr {C}\) embeds faithfully in a restriction category \(\mathscr {D}\), it also embeds faithfully in Inv
\((\mathscr {D})\).
Proof
We notice that \(\text{ Inv }: \mathbf {rCat} \rightarrow \mathbf {invCat}\) is right adjoint to the forgetful functor \(U : {\mathbf {invCat} \rightarrow \mathbf {rCat}}\), with each component of the counit \(\epsilon : U \circ \text{ Inv }\rightarrow 1_\mathbf {rCat}\) given by the faithful inclusion functor \(\epsilon _\mathscr {C} : U(\text {Inv}(\mathscr {C})) \rightarrow \mathscr {C}\) (that this is an adjunction follows by an argument entirely analogous to \(\text {Core}: \mathbf {Cat} \rightarrow \mathbf {Grpd}\) being right adjoint to \(U : \mathbf {Grpd} \rightarrow \mathbf {Cat}\)). That faithful restriction functors are preserved follows readily since restriction functors preserve partial isomorphisms, and every restriction functor out of an inverse category factors through Inv-inclusion by this adjunction. \(\square \)
Lemma 4
The functor Inv \(: \mathbf {rCat} \rightarrow \mathbf {invCat}\) takes join restriction categories to join inverse categories (and preserves join restriction functors).
The latter of these lemmas was shown by Guo [17, Lemma 3.1.27]. To ease presentation of the completion theorem for join restriction categories due to Cockett and Guo [8, 17], we make the following notational shorthand:
Convention 12
For a restriction category \(\mathscr {C}\), let \(\overline{\mathscr {C}}\) denote the category of pre-sheaves \(\mathbf {Set}^\mathrm{{Total}(\mathrm {Split}(\mathscr {C}))^\mathrm{{op}}}\).
Note in particular that \(\overline{\mathscr {C}}\) is cocomplete and all colimits are stable under pullback (since colimits in \(\overline{\mathscr {C}}\) are constructed object-wise in \(\mathbf {Set}\)).
Theorem 4
(Cockett & Guo). Every restriction category \(\mathscr {C}\) can be faithfully embedded in a join restriction category of the form \(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}})\).
The stable system of monics \(\widehat{\mathcal {M}_{\text {gap}}}\) relates to the join-completion for restriction categories via \(\mathcal {M}\)-gaps (see Cockett [8] or Guo [17, Sect. 3.2.2] for details). We can now show the algebraic \(\omega \)-compactness theorem for restriction categories:
Theorem 5
If \(\mathscr {C}\) is a restriction category then \(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}})\) is algebraically \(\omega \)-compact for \(\mathbf {CPO}\); so for join restriction functors.
Proof
Let \(\mathscr {C}\) be a restriction category. By Theorem 4, \(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}})\) is join restriction category. By Adámek & Barr’s fixed point theorem and the fact that join restriction categories are \(\mathbf {CPO}\)-enriched (by Theorem 1) and have a restriction zero object (which is specifically initial) by definition, it suffices to show that \(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}})\) has colimits of \(\omega \)-diagrams of embeddings. Let \(D : \omega \rightarrow \mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}})\) be such a diagram of embeddings. This corresponds to the diagram
in \(\overline{\mathscr {C}}\). Since \(\overline{\mathscr {C}}\) is cocomplete, this diagram has a colimiting cocone \(\alpha : D \Rightarrow \text {colim}~D\) such that
commutes. Further, since colimits in \(\overline{\mathscr {C}}\) are constructed object-wise in \(\mathbf {Set}\), this colimit is stable under pullbacks, so composition in \(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}})\), corresponding to pullbacks in \(\overline{\mathscr {C}}\), commutes with this colimit. Thus, the family of morphisms \(\{(m_i, \alpha _{D(i+1)} \circ f_i)\}_{i \in \omega }\) is a colimiting cocone for D in \(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}})\). \(\square \)
Finally, using this machinery, we can show how this theorem extends to inverse categories.
Corollary 2
Every inverse category can be faithfully embedded in a join inverse category that is algebraically \(\omega \)-compact for join restriction functors.
Proof
Let \(\mathscr {C}\) be an inverse category. Since \(U(\mathscr {C})\) is the exact same category viewed as a restriction category, \(U(\mathscr {C})\) embeds faithfully in \(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}})\), which is a join restriction category by Theorem 4, and algebraically \(\omega \)-compact by Theorem 5. But then it follows by Lemma 3 that \(\mathscr {C}\) embeds faithfully in \(\text {Inv}(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}}))\), which is a join inverse category by Lemma 4, and is algebraically \(\omega \)-compact for join restriction functors (which are specifically locally monotone and continuous) since fixed points of functors are (total) isomorphisms, so preserved in \(\text {Inv}(\mathrm {Par}(\overline{\mathscr {C}}, \widehat{\mathcal {M}_{\text {gap}}}))\). \(\square \)