Induction, Coinduction, and Adjoints
Total Page:16
File Type:pdf, Size:1020Kb
Electronic Notes in Theoretical Computer Science 69 (2003) URL: http://www.elsevier.nl/locate/entcs/volume69.html 19 pages Induction, Coinduction, and Adjoints Robin Cockett 1 Department of Computer Science, University of Calgary [email protected] Luigi Santocanale 2 LaBRI, Universit´e Bordeaux 1 [email protected] Abstract We investigate the reasons for which the existence of certain right adjoints implies the existence of some final coalgebras, and vice-versa. In particular we prove and discuss the following theorem which has been partially available in the literature: let F G be a pair of adjoint functors, and suppose that an initial algebra F(X) of the functor H(Y )=X + F (Y ) exists; then a right adjoint G(X)toF(X) exists if and only if a final coalgebra Gˇ(X) of the functor K(Y )=X × G(Y ) exists. Motivated by the problem of understanding the structures that arise from initial algebras, we show the following:if F is a left adjoint with a certain commutativity property, then an initial algebra of H(Y )=X + F (Y ) generates a subcategory of functors with inductive types where the functorial composition is constrained to be a Cartesian product. 1 Introduction One goal of this paper is to explain why the set N ⇒ X of sequences with values in X has two distinct and apparently unrelated characterizations: on the one hand, this set is the object part of a well known functor that is deter- mined up to unique natural isomorphism as the right adjoint to the functor N × X; on the other hand, this set carries the structure of a final coalgebra of the functor KX (Y )=X ×Y and, as such, it is again determined up to unique isomorphism. Here N is used to denote the set of natural numbers. 1 Research partially supported by NSERC, Canada. 2 Research supported by Canada’s NSERC and the Pacific Institute for the Mathematical Sciences. The research was carried at the Department of Computer Science, University of Calgary. The author also aknowledges financial support from the European Community through a Marie Curie Individual Fellowship. c 2003 Published by Elsevier Science B. V. 101 Cockett and Santocanale The results that we are going to present in this paper are therefore meant to illustrate how two different paradigms of computation are related. One is the paradigm of functional programming that has developed from the theory of the λ-calculus and its extensions with inductive types, see for example [1]; here the Cartesian closed structure is taken as primitive together with certain initial algebras of functors. The second paradigm of programming develops from the theory of objects and of interactive computation, where coinductive methods are the basic ingredients. Thus, categorically, the basic ingredients are here final coalgebras of functors. As a final coalgebra of the functor KX (Y )= X × Y ,thesetN ⇒ X is usually called the set of streams over X; in [2,3] the mathematical ideas arising from coinduction have been proposed as primitives for computation with objects of analysis. Also it is worth remembering that a Cartesian closed category with inductive and coinductive types can be used directly as a basic of a programming language (e.g. Charity [4,5]); with the algebraic results that we are going to present, we mean to suggest correct program transformations and shed some lights on the topic of equivalence of programs. It should be noticed at this stage that the set N × X has also a double algebraic characterization: it is the product of two sets as well as the initial algebra of the functor HX (Y )=X +Y . The categorical structure arising from the assumption that an initial algebra of this functor exists for each object X was investigated in [6]. There it was also observed that, in a topos C with a natural number object N, the Cartesian product N × X is an initial algebra of HX (Y ) and the exponential N ⇒ X is a final coalgebra of KX (Y ). Similar observations arise by substituting the natural number object N with the free monoid A∗ over a set A.ThesetsA∗ × X and A∗ ⇒ X have a similar double algebraic description: the first emphasizes the fact that one is a Cartesian product of two sets and the other is its right adjoint; the second the fact that one is the parameterized initial algebra of HX (Y )=X +(A×Y ) and the other the parameterized final coalgebra of KX (Y )=X × (A ⇒ Y ). It should be remarked how this double perspective is useful: for example, the latter description allows us to build the free monoid over A in an asymmetric way as the set of lists over an alphabet. Similarly, we are now acquainted to think of the set of infinite A-branching trees with X-data at each node as greatest solution of the functorial equation Y = X × (A ⇒ Y ); however the concrete representation of this solution by means of the set of functions from the free monoid is the basic tool to describe further kinds of infinite trees and to find explicit representations of other coinductive datatypes [7,8]. It might be asked what are the assumptions on a category C that are needed to derive a theorem of the above kind, stating that an adjoint has to be isomorphic to a final coalgebra. That is, how far can the hypothesis that C be a topos, as noted in [6], be relaxed? In fact, the purpose of this paper is to show that the assumptions needed on C are no more than what is required in order to express the problem. We prove the following theorem: if F G is pair of 102 Cockett and Santocanale adjoint functors, if an initial algebra F(X) of the functor HX (Y )=X +F (Y ) exists for each X,andifF(X) is a left adjoint with right adjoint G(X),then the latter is a final coalgebra of the functor KX (Y )=X × G(Y ). It should be observed that the proof of this theorem depends on the fact that the functor F(X) can also be characterized as the free F -algebra over X. This theorem is usefully paired with the observation that if a category is monoidal closed, then an initial algebra F(X) of the above functor can be computed as F(I) ⊗ X where I is the unit object of the monoidal structure. These two theorems can be used to show that in a monoidal closed category the presence of some inductive types imply the existence of some (dual) coinductive types. We shall describe how this theorem may be applied in some non standard situations. The converse of this theorem is also true: if F G is pair of adjoint functors, if an initial algebra F (X) of the functor HX (Y )=X + F (Y ) exists for each X, if a final coalgebra Gˇ(X) of the functor KX (Y )=X ×G(Y ) exists for each X,thenF Gˇ is an adjoint pair. This statement actually follows from the observations developed in [9] for input-output categorical machines in a straightforward way, but its consequences are worth noticing. For example, the statement implies that as soon as the coinductive type of streams is added to the basic setting of a Cartesian category with a natural number object in the sense of [10], then the Ackermann function becomes definable. Thus the arithmetic of these categories is more than primitive recursive. This raises questions about the power of the arithmetic that can be ex- pressed in settings where the inductive and coinductive data, rather than the closed structure, are fundamental. For example in µ-bicomplete categories [11,12] the product, in general, does not distribute over the coproduct and yet this result guarantees the presence of certain adjoints. In particular, for a fixed finite set A,thepowerA ∗ X –theA-fold coproduct of X –isadjointto the copower (−)A –theA-fold product of X, and this result can be used to generate a family of adjoint functors. Relying on observations of Burroni [6] and Par´e and Roman [13], we show that the same process by which a family of adjoint functors is generated is also responsible for generating a nonstan- dard Cartesian structure with inductive types. Hence, in these settings, it becomes possible to code all the primitive recursive functions. It remains an open question, however, as to whether any other total recursive function can be represented. The paper is structured as follows: in section 2 we settle our discussion on initial algebras and final coalgebras in a 2-categorical context and introduce the notions of an F -list 1-cell and of a G-tree 1-cell in a 2-category; we provide some examples and discuss their basic properties. In section 3 we analyze the theorem that relates the existence of adjoints to the existence of final coalgebras, whenever the dual initial algebra is assumed to exists. In section 4 we show that the theory of natural number objects developed by Burroni, Par´e and Roman, can be lifted to encompass F -list 1-cells, whenever F is a left adjoint and has a certain commutativity property. 103 Cockett and Santocanale 2 Definitions 2.1 Notation. We settle our discussion in a 2-category C, as this will be enough to export our results to bicategories, by the well known theorem that states that every bicategory is biequivalent to a 2-category. We use juxtaposition to denote the horizontal composition of 1-cells, thus GF stands for the composition of G : C ✛ D and F : D ✛ E.