 CC BY-NC-ND 0 0
Share paper
OECD Field of science
Keywords
{}

## Abstract of research paper on Computer and information sciences, author of scientific article — Neil Ghani, Christoph Lüth, Federico de Marchi, John Power

Abstract Whilst the relationship between initial algebras and monads is well-understood, the relationship between final coalgebras and comonads is less well explored. This paper shows that the problem is more subtle and that final coalgebras can just as easily form monads as comonads and dually, that initial algebras form both monads and comonads. In developing these theories we strive to provide them with an associated notion of syntax. In the case of initial algebras and monads this corresponds to the standard notion of algebraic theories consisting of signatures and equations: models of such algebraic theories are precisely the algebras of the representing monad. We attempt to emulate this result for the coalgebraic case by defining a notion cosignature and coequation and then proving the models of this syntax are precisely the coalgebras of the representing comonad.

## Similar topics of scientific paper in Computer and information sciences , author of scholarly article — Neil Ghani, Christoph Lüth, Federico de Marchi, John Power

﻿Electronic Notes in Theoretical Computer Science 44 No. 1 (2001) URL: http://www.elsevier.nl/locate/entcs/volume44.html 18 pages

Neil Ghani Christoph Lüthb'2 Federico de Marchia'3'5

John Powerc'4

a Department of Mathematics and Computer Science, University of Leicester

b FB 3 — Mathematik und Informatik, Universität Bremen c Laboratory for Foundations of Computer Science, University of Edinburgh

Abstract

Whilst the relationship between initial algebras and monads is well-understood, the relationship between final coalgebras and comonads is less well explored. This paper shows that the problem is more subtle and that final coalgebras can just as easily form monads as comonads and dually, that initial algebras form both monads and comonads.

In developing these theories we strive to provide them with an associated notion of syntax. In the case of initial algebras and monads this corresponds to the standard notion of algebraic theories consisting of signatures and equations: models of such algebraic theories are precisely the algebras of the representing monad. We attempt to emulate this result for the coalgebraic case by defining a notion cosignature and coequation and then proving the models of this syntax are precisely the coalgebras of the representing comonad.

1 Introduction

While the theory of coalgebras for an endofunctor is well-developed, less attention has been given to comonads. We feel this is a pity since the corresponding theory of monads on Set explains the key concepts of universal algebra such as signature, variables, terms, substitution, equations etc. Moreover, applications to base categories other than Set has proven fruitful in many situations, e.g. the study of multi-sorted algebraic theories as monads over SetA, order-sorted theories as monads over Pos, the study of categories with structure

1 Email: ng13@mcs.le.ac.uk

2 Email: cxl@informatik.uni-bremen.de

3 Email: fdm2@mcs.le.ac.uk

4 Email: ajp@dcs.ed.ac.uk

5 Research supported by EPSRC grant GRM96230/01: Categorical Rewriting: Monads and Modularity

using monads over Graph or Cat , the study of rewriting using monads over Pre or Cat [16,17] and the study of higher order abstract syntax using monads over SetF  (where F is the skeleton of the category of finite sets). We aim for a similar framework, based upon the theory of comonads, explaining the relationship between the coalgebraic duals of the above concepts, and laying the ground for applications in categories apart from Set. This paper is a first step in this direction.

Traditionally, one begins with a signature £ and then for each set of variables X, defines the term algebra Ts(X). Next one defines substitution and shows this associative with the variables acting as left and right units. Finally, given equations E, one also defines the quotient algebra Ts,E(X). Generalising this treatment of universal algebra to cover not just sets with extra structure but also algebraic structure over other mathematical objects can be achieved using a categorical reformulation of these ideas. In this categorical framework , one constructs from a signature £, an endofunctor FS (which can be thought of as sending an object X of variables to the terms of depth 1 with variables from X). The term algebra Ts can then be characterised as the the free monad over Fs. Being a monad gives Ts a well behaved notion of substitution, while being free captures the inductive nature of the term algebra. By interpreting the equations of an algebraic theory as pairs of monad morphisms between two free monads, the quotient algebra induced by the equations is modelled as their coequaliser. Crucially, the models of an algebraic theory are isomorphic to the Eilenberg-Moore category of algebras of the monad representing the algebraic theory.

Our aim is to dualise this categorical treatment of universal algebra and in particular derive coalgebraic duals of the key concepts described above. We therefore need to dualise firstly the construction of an endofunctor over a signature and secondly the free monad over an endofunctor. It turns out there is more than one possible dualisation and this is the subject matter of this paper. For example, given a finitary endofunctor F : A ^ A, one can consider the mapping sending an object X to the underlying object of the initial X + F-algebra, the mapping sending X to underlying object of the final X + F-coalgebra, the mapping sending X to underlying object of the initial X x F-algebra and the mapping sending X to underlying object of the final X x F-coalgebra. Each of these four mappings form either a monad or a comonad as described in Table 1. Thus, there is perhaps not one dualisation at play, but two possible, and orthogonal, dualisations giving four concepts worthy of our attention.

We do not claim that this paper provides complete answers to the questions raised above. However we do feel that the questions we address will be of fundamental importance to the CMCS audience and that our approach is novel in being more abstract than most. In particular, we hope that our notions of cosignature, coequations and the categorical representation of this syntax via comonads will be of general interest and stimulate further research.

Initial Algebras ¡iY. X + FY ¡iY. X X FY

Final Coalgebras vY. X + FY vY. X X FY

Table 1

The rest of this paper is structured as follows: Sect. 2 contains preliminary definitions. In Sect. 3, we briefly review the presentation of finitary monads which we seek to dualise in the rest of the paper (the upper left entry in Table 1). Sections 4 and 5 explore the different possibilities of dualisation, with Section 4 exploring the lower left of Table 1 and Section 5 containing our proposed coalgebraic syntax with associated representation and correctness results (the right side of Table 1).

2 Preliminary Definitions and Notation

We assume the reader is familiar with standard category theory as can be found in . In order to abstract away from the category Set we have had to employ certain constructions which some readers may not be completely familiar with. We give a short definition of these here; more details can be found in [18,3].

Locally Presentable and Accessible Categories: Let k be a regular cardinal. A diagram D is K-filtered iff every subcategory with less than k objects and morphisms has a compatible cocone in D. An object X of a category A is said to be K-presentable iff the hom-functor A(X, _) preserves K-filtered colimits. A category is locally K-presentable (abbreviated as Kp) if it is cocomplete and has, up to isomorphism, a set NK of K-presentable objects such that every object is a K-filtered colimit of objects from NK. A category is K-accessible providing it is Kp except that it only has K-filtered colimits rather than all colimits. A functor is K-accessible iff it preserves K-filtered colimits; we also say it has rank k. The discrete category on NK is denoted NK. The full subcategory of K-presentable objects is denoted AK. The inclusion functors are denoted JK : — AK and IK : AK — A. When A = Set, the set N^0 can be taken to be the natural numbers which we denote N.

Kan Extensions: Given a functor I : A — B and a category C, precom-position with F defines a functor _ o I : [B, C] — [A, C]. The problem of left and right Kan extensions is the problem of finding left and right adjoints to _ o I. More concretely, given a functor F : A — C, the left and right Kan

extensions satisfy the natural isomorphisms

[B, C](LaniF,H) = [A, C](F,H o I) [B, C](H, RaniF) = [A, C](H o I,F).

Kan extensions can be given pointwise using using colimits and limits, or more elegantly using ends and coends (see [18, Chapter X] for details).

We begin by recalling the well known equivalence between (finitary) monads on the category Set and universal algebra and the generalisation of this equivalence to locally presentable categories [14,21]. We illustrate these ideas with a specific example using Set as the base category — examples over other base categories can be found in [21,8].

A signature declares the operations from which the terms are constructed. Usually, a signature is given as a set of operations and a function assigning each operation an arity, but we can equivalently consider it as a function £ : N ^ Set, assigning to each arity the set of operations of that arity. In order to abstract away from the category of Set, we need a notion of arity appropriate for different categories. The key observation is that the usual arities in Set, i.e. the natural numbers N, represent the finitely presentable objects in Set. Hence a natural notion for arities in a Kp-category is the set NK. Hence, a signature is a function £ : NK ^|A|, which is equivalent to a functor £ : ^ A:

Definition 3.1 (Signature) Let A be a Kp category. A signature is a functor £ : ^ A, and the object of e-ary operations of £ is £e = £(e).

We now present two examples of such signatures, which we will later augment by the appropriate equations.

Example 3.2 (Monoids) The signature £M : N ^ Set for the theory of monoids is defined as £M(0) = {e}, £M(2) = {m}, £M(n) = 0 for all other n E N. Thus £M declares one operation e of arity 0 (a constant) and one binary operation m.

Example 3.3 (Categories with T) Categories with a terminal object can be seen as algebraic over Cat. The signature £t must declare the terminal object and for each object X, the unique map !X : X ^ T. Since the terminal object does not depend upon any data, its arity is the empty category 0. Since the map !X depends upon an object, its arity is the one object category 1. Thus £t(0) = 1, £t(1) = (o^o) (i.e. the category with two objects and one arrow) while £t(c) = 0 for all other finitely presentable categories c.

We now turn to the construction of an endofunctor over a signature £.

Working over Set, e.g. see , one defines a functor

Fe(X)= H Xn

f es(n)

which calculates the terms of depth 1 whose variables come from the set X. For example, given the signature of example 3.2, the associated endofunctor is FM(X) = 1+ X2. Such polynomial endofunctors (i.e. built from products and coproducts) are known to preserve all K-filtered colimits — this is an important property which later will ensure the free monad can be easily calculated. Unfortunately, it is unclear how to generalise it to categories other than Set and hence we take an alternative approach. Recall that by definition, left Kan extension is left adjoint to restriction Lan Jk_ ^ o JK : [NK, A] — [AK, A] and hence we define

FS(X ) = (Lanj E)X (1)

The standard formula for left Kan extensions shows that, in the case A = Set, both definitions of Fs agree, as in Example 3.2:

(LanEm)X = JJ SetHo(n,X) x Em(n) neN

= Set(0, X) x 1 + Set(2, X) x 1 = 1+ X2

Notice that the domain of Fs is AK and not A, and hence Fs is not an endofunctor. However, an endofunctor F : A — A is K-accessible iff it is (isomorphic to) the left Kan extension of its restriction to AK; hence there is an equivalence (2) between K-accessible endofunctors and functors AK — A and we can regard Fs as a K- accessible endofunctor.

- O Ik

[A, A]k T [AK, A] (2)

Lan/K-

To recap, we have presented an abstract definition of signature E over an lKp-category and a construction of the associated endofunctor Fs over the signature. In the case of Set, these definitions and constructions agree with the usual definitions. The associated term algebra Ts : A — A is then the free monad over the endofunctor Fs, constructed in a number of ways:

Lemma 3.4 Let F be a K-accessible endofunctor over a lKp-category A. Then the free monad T over F satisfies

(i) For every X in A, TX is the carrier of the initial X + F-algebra.

(ii) The forgetful functor U : F—Alg — A from the category of F-algebras to A has a left adjoint L, and T = UL

(iii) T is colimit colimi<KSi of the sequence Si where

So = J Sn+i = J + F o Sn S\ = colim Si (3)

and the composition of F,E : Af — A is given as F o E = (LanIF-E).

Proof. Most of the proofs are standard and can be found in [14,12]. However, note that in the last of the claims, to calculate the free monad we start forming the sequence of endofunctors Si and we do not need to go further than the ^-filtered colimit colimi<KSi because F is ^-filtered. Hence T is ^-accessible and thus shares the same rank as F. □

When we come to the dual of this construction in Sect. 5, a construction like the above will not be possible since one would be interested in the limit of co-chain, and there is no reason for an accessible endofunctor to preserve such limits. The effect is that the rank of the cofree comonad over an accessible endofunctor may increase. This change of rank underlies the technical difficulties which will arise in Sect. 5.

We obtain the two adjunctions in (4) which compose to give an adjunction F —| U between signatures and monads.

Lan jk _ H

[N, A] < ± [AK, A] < ± MonK(A) (4)

-o Jk V

The sequence Si in (3) in Lemma 3.4 is called the free algebra sequence  and can be seen as a uniform calculation of the initial X + F algebra. As an example of this construction, consider the signature £M. As we have seen LanJk £m (X) = 1 + X2. The free algebra sequence then specialises to SoX = X and

Sn+i(X) = X + ]J A(e, Sn(X)) x £m(e) = X + 1 + Sn(X)2 eeN

from which we can see Sn as defining the terms of depth at most n, e.g. S0(X) contains the variables X, and S1(X) contains the variables X, the canonical element of 1 representing the unit of the monoid and a pair of elements of S0(X) which can be thought of as the multiplication of these elements.

Within this framework, to give equations is to give another signature E and two natural transformations a,r : E — UFB. One should regard E as giving the shape of the equations and a' and t' as the actual equations.

Example 3.5 Given the monoids example, there are three equations we wish to assert: left unit, right unit (both unary) and associativity (ternary). Hence we set E(3) = {a}, E(1) = {l, r} and E(n) = 0 for all other n.

a and т define the left, and the right hand side of equations, respectively:

a(l) = m(e,x) a(r) = m(x,e) a (a) = m(x,m(y,z)) т (l) = x т (r) = x т (a) = m(m(x,y),z)

For example 3.3, one equation is needed to force the uniqueness of !X : X — T, i.e. !y .f =!x for all f : X — Y (see  for details).

The advantage of this definition of equations is that it allows an elegant derivation of the representing monad for an algebraic theory: given such a theory а,т : E — UFB, under adjunction (4) we have two monad morphisms a', т' whose coequaliser is the representing monad T. This construction makes sense, because the category of models of the algebraic theory is isomorphic to the Eilenberg-Moore-category of the representing monad.

In (4), both adjunctions are monadic and their composition is of descent type, which means that each component of the counit £B : FUB ^ B is a coequaliser. This means that every ^-accessible monad T = (T,n,l) on A is a coequaliser of two free monads over two signatures B,E : N — A in the category of ^-accessible monads over A, or every monad is represented by equations in this general sense.

Given a signature £ we have constructed an associated endofunctor Fs, which can be thought of as calculating the closed terms of depth 1. By closing Fs under composition, or more formally by considering the free monad over F^, we get the term algebra T^. Concretely T^X is the carrier of the initial X+ F^-algebra. In this section we investigate the map T^ sending an object X to the carrier of the final X + Fs-coalgebra, and apply our results to simplify some recent developments is the semantics of lazy datatypes in functional programming languages. A more general version of Lemma 4.2 appears in  and is implicit in .

In comparing ¡iY.X + FY with vY.X + FY, the first observation  is that the final coalgebra of a Set-endofunctor can be regarded as a Cauchy completion of the initial algebra. Thus, if F arises from a signature and hence ¡Y.X + FY is the usual term algebra, then vY.X + FY is the set of terms of finite and infinite depth. This result was extended to lfp categories in . The goal of this section is to ascertain the structure possessed by the map sending X to the carrier of the final X + Fs-coalgebra. Our answer is that this map also forms a monad. In proving this result we use the following result :

Lemma 4.1 Assume that A is lfp, that the unique map ! : 0 — 1 is a strong monomorphism, that F preserves monos and шар-chains and that there is a map p : 1 — F0. Then for each object X eA, A(X,iF) and A(X, vF) are metric spaces vnth the latter being the Cauchy completion of the former.

We use this result to prove our main lemma:

Lemma 4.2 Let F be a polynomial endofunctor and A satisfy the premises of lemma 4-1- Then the map Tx assigning an object X to the carrier of the final X + F-coalgebra carries the structure of a monad.

Proof. We actually prove the lemma for the case A = Set since the general case involves slightly clumsy reasoning with hom-sets but is entirely analogous. We prove that Tx is a monad by constructing a Kleisli structure for it, namely by defining the following operations: i) for each object X, an arrow nX : X ^ TxX; ii) for each pair of objects X,Y a function sX,Y : A(X, TxY) ^ A(T™X, TXY) such that

Sx , X (rjx) = X SX , Z (sy, Zg ◦ f) = Sy,zg ◦ SX,Y f Sx,Y (f) 0 Vx = f

Firstly define nX = eX ◦ nX where n is the unit of the free monad on F and tX is the unique comparison map between the initial X + F-algebra and the final X + F-coalgebra. 6 Next define sX,Y (f) as follows

s(f) =f

where h : FTXY — TxY is the obvious map derived from the structure map of TXY. Then [f, h] : X + FTXY — TXY endows TXY with an X + F-algebra structure and hence induces a unique map !f,h] : TX — TxY from the initial X + F-algebra. Diagram chasing shows that !f,h] is uniformly continuous with respect to the relevant metrics and hence by lemma 4.1 there is an extension !f. h] which can be taken to be sx,Y (f). The first equation follows since by uniqueness , h] = tx and the extension of tx is the identity. The equation sX,z (sY,zg ◦ f) = sY,zg ◦ sX,Y f holds if their restrictions via tX are the same which in turn holds if they arise from the same algebra structure on TxZ. This holds because the two algebra structures are both inherited from the map sY,Z(g) o f : X — TxZ. The last equation follows since sx,y (f) o nX = sx,y (f) o £x o nx =![f,h] o nx = f □

Unlike the monad T, the monad Tx has a larger rank than F:

Lemma 4.3 Let F be a polynomial endofunctor on Set. Then the monad TX has rank

Proof. The lemma can be proven directly using an interchange law between limits and filtered colimits. □

6 Actually applying Lemma 4.1 requires that X + F0 be non empty which is the case when X = 0. Thus the maps nOO and s0,Y and their properties must be established separately, but this all follows trivially from the initiality of 0

Notice that lemma 4.2 indicates that there is no need to develop a new syntax for the monad T^ since the canonical syntax should be the finite and infinite depth terms of the associated monad Ts. We finish this section with an application of this result to reasoning in functional programming.

4.1 The Generic Approximation Lemma

The generic approximation lemma  is a proof principle for reasoning about functions in a lazy functional programming language (such as Haskell). The approximation lemma itself pertains to lists and states that given a function

approx (n+1) [] = []

approx (n+1) (x:xs) = x:(approx n xs)

two lists xs and ys are equal iff Wn.approx n xs = approx n ys. Note the lack of a base case: approx 0 x is L (i.e., the denotation of undefined) in the denotational model, but because of non-strictness, approx n x (with n > 0) is defined. This principle can be applied to other datatypes such as trees:

data Tree a = Leaf a | Node Tree a Tree approx (n+1) (Leaf x) = Leaf x

approx (n+1) (Node l x r) = Node (approx n l) x (approx n r)

Two trees t1 and t2 are equal iff Wn. approx n t1 = approx n t2.  proves the generic approximation lemma using the standard denotational semantics of functional programming languages, where types are interpreted as cpo's, programs as continuous functions and recursive datatypes as least fixed points of functors. That is, the correctness of the proof principle depends upon the semantic category chosen; we have already seen the implicit use of L in the definition of approx.

We propose an alternative and, we believe, more natural derivation of the approximation lemma which is independent of the particular denotational model chosen. The definition of a polymorphic datatype is usually interpreted as the free monad Ts over its signature £. However, this does not capture laziness, since Ts consists of only finite terms. Instead, we model such a datatype by the monad T^. Since T^(X) is the final X + £-coalgebra and since Fs is a polynomial endofunctor, T^(X) can be calculated as the limit of the following wop-chain 1 ^ (X + F)1 ^ (X + F)21 ^^ • •. The universal property of the limit states that two elements x and y of this limit will be equal iff for each n, nn(x) = nn(y) where nn is the n-th projection. But these projections are precisely the approximation function for the datatype. Notice how the categorical argument replaces the semantic dependency on . with use of a co-chain beginning with 1. This establishes the correctness of the generic approximation lemma independently of any specific denotational model. More generally, a lazy functional language like Haskell combines aspects appropriately modelled by a monad (being finitely generated), while others are more appropriately captured by final semantics (laziness and non-termination).

We now turn to another possible dualisation of Sect. 3 based upon the idea of mapping an object X to the carrier of the final X x F-coalgebra for some ^-accessible functor F. The elegance of the monadic approach to algebraic theories suggests that we can apply these techniques to the development of coalgebraic syntax by dualising them apropriately.

5.1 Cosignatures and their Coalgebras

Recall that the heart of the categorical approach to universal algebra is adjunction (4). The dualisation outlined in this section can be summed up as replacing the left adjoint to U with a right adjoint and the replacement of monads with comonads. As a result, the definition of a cosignature turns out to be formally the same as that of a signature.

Definition 5.1 (Cosignature) Let A be a Kp-category with arities NK. A к-cosignature is a functor B : ^ A.

Recall that in Section 3, we constructed a к-accessible endofunctor from a signature by first taking a left Kan extension, and then used equivalence (2) to get a к-accessible endofunctor. Therefore, in this section we take the right Kan extension of a cosignature B to obtain a functor RanJk B : AK ^A, followed by the same equivalence to obtain a к-accessible endofunctor on A. The standard formula for the right Kan extension gives us

(RanjkB)(X) = П A(X,c) rt Bc

where U iti B is the U-fold product of B, or more formally the representing object for the functor [U, A(_, B)] : A ^ Set. When A = Set, then this operation is simply exponentiation, i.e. U iti B = [U, B].

Thus, although signatures and cosignatures are formally the same, the endofunctors they generate are very different. For example, note that while the default value for signatures is 0, if there is a single arity c such that B(c) = 0, then (RanJkB)(X) = 0. In fact, the default value for cosignatures is 1 since U iti 1 = 1 and hence if c is an arity such that B (c) = 1, then this arity will contribute nothing to the right Kan extension. Here are two example cosignatures which we will explore further below:

Example 5.2 Define the cosignature Bp by Bp(2) = 2 and Bp(c) = 1 for all other arities. Then RanjKBp(X) = [Set(X, 2), 2] = [[X, 2], 2].

Define the cosignature BPui (2) = и and BPui (c) = 1 for all other arities. Then (RanjKBpш)(X) = [Set(X, 2),и] = [[X, 2],и].

Recall that in order to turn a functor AK ^ A into a к-accessible endofunctor, one takes its left Kan extension. Given a cosignature B, we can thus consider coalgebras of the endofunctor Lan/K RanJk B. The following is

an important result from :

Lemma 5.3 Let F : A ^ A be an accessible endofunctor on a locally presentable category. Then F-coalg is locally presentable and the K-presentable objects of F-coalg are simply those coalgebras whose underlying object is k-presentable in A.

Proof. The proof uses the fact that the category of all (small) accessible categories has all weighted limits [19, Theorem 5.1.6]. Then the category F—coalg can be constructed as such a limit, namely the inserter  of 1

The second part of the lemma follows from the fact that colimits in F-coalg are formed pointwise. □

This result allows us to consider K-presentable LanlKRanJkB-coalgebras:

Lemma 5.4 Let B be a K-cosignature. A K-presentable LanlK RanJfiB-coal-gebra consists of a k presentable object X together with for every arity c, a function hc : A(X, c) ^ A(X, Bc).

Proof. Given any K-accessible endofunctor F, and K-presentable object X, LanlK F (X) = F (X). Hence coalgebras of the form mentioned are

A(X, (RanjkB)(X)) = A(X, ft^ A(X, c) rt Bc) = UceA^K A(X, A(X, c) rt Bc) = UceATK A(X, c), A(X, Bc)]

In the theory of monads, a crucial result states that the models of an algebraic presentation are isomorphic to the category of algebras of the theories representing monad. In order to emulate this result we require a notion of model (or co-model if you like) for a K-cosignature B, and Lemma 5.4 suggests this be LanlK RanJk B-coalgebra.

Example 5.5 A model of the cosignature Bp is (given by a finite set X together with a function Set(X, 2) ^ Set(X, 2). If we regard a map f : X ^ 2 as a subset of X, or a predicate over X, then such a model can be regarded as a map between predicates.

Similarly, a model for the cosignature BPu¡ consists of a finite set X and a function Set(X, 2) ^ Set(X, u). This is clearly related to the previous example if we think of it as mapping binary partitions of X to u-ary partitions.

5.2 The Representing Comonad of a Cosignature

Recall that in the algebraic case one starts with a signature, constructs an endofunctor, and then considers the free monad over the endofunctor. The second part of the dualisation is to consider the cofree comonad over an end-ofunctor. The following pair of results from  provides the framework for

this discussion:

Lemma 5.6 The following conditions on a functor F : A^A are equivalent:

(i) There is a cofree comonad on F.

(ii) The forgetful functor F-coalg ^ A is comonadic.

(iii) The forgetful functor F-coalg ^ A has a right adjoint

(iv) (If A has products) For every object X, the functor X x F has a final coalgebra.

Similar to the monadic case, only accessible endofunctors have a cofree comonad. For example, there is no final coalgebra for the powerset functor P : Set ^ Set, as such a coalgebra would be an isomorphism X = PX. The important result from [19,11] is the following:

Lemma 5.7 If A is locally presentable and F is accessible, then F-coalg is locally presentable and there is a cofree comonad over F.

Proof. Recall from lemma 5.3 that F-coalg is accessible. Cocompleteness of F-coalg follows since the forgetful functor creates colimits and A is co-complete. Since the forgetful functor is a colimit-preserving functor between locally presentable categories, it follows from the Special Adjoint Functor Theorem [18, Theorem V.8.1] that the forgetful functor has a right adjoint. By lemma 5.6, there is a cofree comonad over F. □

Let ComK(A) be the category of ^-accessible comonads on A, and further ACom(A) be the category of accessible comonads on A. For every к, ComK(A) is a full subcategory of ACom(A). Similarly, let [A, A]K be the category of endofunctors with rank к, and AEnd(A) be the category of accessible endofunctors. Piecing together the above results we have the following:

Lemma 5.8 The forgetful functor V : ACom(A) ^ AEnd(A) has a right adjoint R.

Proof. Given an accessible endofunctor F, let the right adjoint of the forgetful functor UF : F-coalg ^A be KF. Then choosing R(F) to be UFKF we can deduce that R(F) is accessible because UF is accessible (as a left adjoint, it preserves all colimits) and KF is accessible by [3, Proposition 1.66 on p. 52].

The action of the right adjoint on accessible endofunctors has already been given. Given a natural transformation a : F1 ^ F2, this induces a functor a* : F1-coalg ^ F2-coalg which commutes with the respective forgetful functors. Using the dual of [6, Theorem 3 on p. 128] and the comonadicity of these categories of coalgebras, this in turn induces a natural transformation R(a) : R(Fi) ^ R(F2). This defines the functor R : AEnd(A) ^ ACom(A). The fact that it is right adjoint to V is easily verified. □

As opposed to the monadic case, the cofree comonad RM on an endofunctor M : A^A of rank Л need not have rank A; as a simple counterexample, consider the endofunctor M : Set —> Set defined as MX == A x X for a

fixed set A, which clearly is finitary (has rank H0). We know that the value of RM for a set X is given by RM(X) = vY. X x MY = vY. X x A x Y which is the set of all infinite streams of elements of X x A. Now consider a countably infinite set Y, then RM(Y) contains a sequence with infinitely many different elements from Y. This sequence can not be given from any of the finite subsets Y0 C Y, which shows that RM has a rank larger than H0. As we saw in Sect. 4, in general calculating coalgebras of accessible endofunctors invariably seems to increase their rank — see  for an investigation of this phenomenon.

Using the equivalence between [AK, A] and [A, A]K, we now have the following functors, where _ o JK is the precomposition with JK and V is the forgetful U for comonads of rank k:

[Nk , A]

[Ak, A]

[A, A]K

We further define the composite functors

Vk : ComK(A) ^ [Nk, A] Rk : [Nk, A] ^ ACom(A)

= ( o Jk).V

ComK(A)

Rk = R. Ran JK

As we have seen, the rank of RKB may be greater than the rank of B, and hence the codomain of RK is not the domain of VK, but rather ACom(A). So although RK and VK can not be adjoint, there is the following isomorphism:

Lemma 5.9 For any K-accessible comonad G and K-cosignature B : NK ^ A there is an isomorphism

[Nk, A](VkGB) which is natural in G and B.

ACom(A)(G, RkB)

Proof. The isomorphism is shown by the following chain of natural isomorphisms provided by the two adjunctions in (5) and the full and faithful embedding of [A, A]k into AEnd(A):

[Nk, A](VkG, B) = [Nk, A](- o JkVG, B) - [Ak,A](VG, Ran Jk B) = AEnd(A)(VG, RanjkB) = ACom(A)(G,RRanjK B) = ACom(A)(G, RkB)

So given a ^-cosignature B we have constructed its representing comonad RKB. Note that by lemma 5.6, the category of coalgebras RKB—Coalg is isomorphic to the category LanlK Ranj B—coalg. Restricting ourselves to ^-presentable coalgebras, we have that the ^-presentable coalgebras of the representing comonad RKB are isomorphic to the ^-presentable models of the cosignature B as defined earlier. This is our partial dualisation of the result stating that the models of a signature are isomorphic to the Eilenberg-Moore category of the representing monad.

5.3 Coequational Presentations and their Representing Comonad

In this section, we continue the dualisation by defining coequational presentations, deriving a representing comonad for such a coequational presentation, and relating the coalgebras of the representing comonad to the models of the presentation. As we have seen above, equations are interpreted as a pair of monad morphisms between free monads; the representing monad for an equational presentation is then defined to be the coequaliser of these monad morphisms. Dualising this requires a coequational presentation to form a pair of comonad morphisms between cofree comonads and taking the representing comonad for the coequational presentation to be the equaliser of these comonad morphisms.

Definition 5.10 (Coequational Presentations) A coequational presentation is given by two cosignatures B: — A and E: N\ — A (where RKB is \-accessible), and two comonad morphisms a,r : RKB — R\E.

Under (6) the maps a, r : RKB — RXE are given by maps a',r' : V\RKB — E, which in turn are families a'c, r'c : RKBc — Ec of maps for c E N\. So, as opposed to the monadic case where an equation is given by a pair of terms, a coequation consists of two partitionings of the coterms; for example, if E(n) = 2, each of a and r partition RKB(n) into two subsets.

As mentioned above, given a coequational presentation, our intention is to define its representing comonad to be the equaliser of the comonad morphisms:

G-- RkB -r RXE (7)

Proving that these equalisers exist is made easier by our abstract categorical setting which provides us with an alternative definition of the coalgebras of a comonad. Recall that such coalgebras are given by an object x E A and a map a : x — Gx which commutes with the unit and counit of G. First, observe that an object x of A is given by a map X : 1 — A (where 1 is the one-object category). Further, the functor category [1, A] is isomorphic to A, and we have

A(x,Gx) = [1, A](X,G o X) = [A, A](LanXX,G), (8)

so to give a map x —^ Gx is equivalent to giving a natural transformation from LanxX ^ G. In fact. LanxX is a comonad:

Lemma 5.11 LanxX is a comonad. If X is K-presentable, then LanxX is K-accessible.

Proof. Using the standard formula for left Kan extensions, LanxX(a) = A(X, a) 0 X (where 0 is the tensor; e.g. in Set, it is given by the usual product). If X is K-presentable, then A(X, —) preserves all K-filtered colimits, as does — 0 X; hence LanxX is K-accessible.

To have a comonad structure, we need natural transformations LanxX ^ 1 and LanxX ^ LanxX o LanxX which satisfy the comonad laws. The first of these is given by the image of the identity transformation on X under the isomorphism [1, A](X,X) = [A, A](LanxX, 1^). The second is given by the image under the isomorphism [1, A](X, LanxX o LanxX o X) = [A, A](LanxX, LanxX o LanxX) of the transformation

X LanxX o X LaniXe LanxX o LanxX o X

where e is the canonical transformation X ^ LanxX o X. That the counit and comultiplication obey the comonad laws is easily verified. □

The fact that LanxX is a comonad allows us to strengthen equation (8) to obtain the promised characterisation of the coalgebras of a comonad.

Proposition 5.12 A coalgebra for a comonad G is given by an object X of A and a map LanxX ^ G in ACom(i).

Proof. We have already seen that the structure map of the coalgebra is precisely a natural transformation between the two functors. It is then routine to verify that the properties of the structure map of a coalgebra correspond to the laws of a comonad morphism. □

With Proposition 5.12, we can show the existence of equalisers:

Lemma 5.13 The category of accessible comonads ACom(A) has all equalisers.

Proof. Consider two comonad morphisms M ; E. We define the cate-

gory (M, E)—Coalg to be given by coalgebras a : LanxX — M of M such that a.a = t.a. Recall from the proof of lemma 5.4 how we constructed the category of coalgebras as a weighted limit; using a similar diagram called an equifier, we can construct (M, E)—Coalg as a weighted limit as well, making it accessible. With (M, E)—Coalg, M and E accessible, the forgetful functor from (M, E)—Coalg to A has a right adjoint; and post-composition of this right adjoint with the forgetful functor gives the equaliser of M and E. □

We finish by relating the models of a coequational presentation to the coalgebras of its representing comonad. If G is the representing comonad of the coequational presentation а, т : RKB — RxE, then a G-coalgebra is a map a : LanXX — G which by the universal property of equalisers is a map a' : LanXX — RKB such that а.a = т.a, or in other words a coalgebra for B which equalises а and т. In this case, we say that the coalgebra LanXX — RKB satisfies the coequational presentation а, т : RKB — RxE. Following the calculations above, if X is к-presentable the map a : LanXX — RKB, gives us two RxE-coalgebras, which by Lemma 5.4 are families а'' : A(X, c) — A(X, Ec) and т'' : A(X, c) — A(X, Ec) of maps for all c E Nx, which have to be equal if a : LanXX — RKB satisfies the presentation а, т : RKB — RxE.

6 Conclusions, Related and Further Work

This paper set out to analyse the essence of the categorical approach to universal algebra based upon the theory of accessible monads and then derive their coalgebraic counterparts. While still only work in progress, we feel we have made a definite contribution which will be of interest to the general coalgebra community. In particular, the derivation of the infinitary monad corresponding to the collection of final X + F-coalgebras seems to have ready applications in lazy functional programming. In addition, the derivation of the cofree comonad representing a cosignature and the interpretation of a co-equational presentation as an equaliser of cofree comonads are dualisations of the corresponding results in the standard theory. We have also related the coalgebras of the representing comonad to the models of the coequational presentations.

The major technical challenge was caused by the increase in rank when passing from a cosignature to its representing comonad. For example, this meant that the characterisation of coalgebras only holds for coalgebras up to a certain rank. In addition, this increase in rank makes it unlikely that every accessible comonad can be given as a coequational presentation (i.e. as an equaliser of cofree comonads), as is possible for finitary monads.

Of course there remains much to be done. Our approach has been very abstract and perhaps the most important next step is to make precise the relationship between our approach and others pursued in the community.

For example, Cirstea  defines an abstract cosignature as a functor F : C —► C where C has all finite limits and limits of uop-chains, and F preserves pullbacks and such limits. Then, an observer is given by a functor K : C — C and a natural transformation c : U — K. U, and a coequation by two observers (K, l) and (K, r). Thus, an observer is a family в : C — KC of maps for all F-coalgebras a : X — FX. This notion corresponds roughly with a comonad morphism RKB ^ RxE, since we always have the cofree coalgebra RKBX — RKBRKBX. However, the difference is the stronger assumption that the abstract cosignature F preserves limits of uop, which allows the con-

struction of a final coalgebra, and reasoning about it; in our more abstract setting all we have is the existence of a right adjoint and the corresponding weaker properties.

We have not as yet developed the logical calculus underlying the categorical constructions of the comonadic semantics. It seems this underlying logic will have a modal flavour, and hence research in this area, e.g. by Kurz , seems relevant. Finally the use of coequations in recent work on co-Birkhoff theorems [4,22] should be compared with our coequations.

References

 P. Aczel, J. Adamek, and J. Velebil. Iteration monads. In U. Montanari, editor, Proceedings CMCS'01, volume 44, 2001.

 J. Adamek. On final coalgebras of continuous functors. To appear.

 J. Adamek and J. Rosicky. Locally Presentable and Accessible Categories. Number 189 in London Mathematical Society Lecture Note Series. Cambridge University Press, 1994.

 S. Awodey and J. Hughes. The coalgebraic dual of birkhoffs variety theorem. http://www.contrib.andrew.cmu.edu/user/jesse/papers/CoBirkhoff.ps.gz, 2000.

 M. Barr. Terminal algebras in well-founded set theory. Theoretical Computer Science, 114:299- 315, 1993.

 M. Barr and C. Wells. Toposes, Triples and Theories. Number 278 in Grundlehren der mathematischen Wissenschaften. Springer Verlag, 1985.

 C. Cirstea. An algebra-coalgebra framework for system specification. In Proceedings CMCS 2000, volume 33 of Electronic Notes in Theoretical Computer Science, 2000.

 E. J. Dubuc and G. M. Kelly. A presentation of topoi as algebraic relative to categories or graphs. Journal for Algebra, 81:420-433, 1983.

 M. Fiore, G. Plotkin, and D. Turi. Abstract syntax and variable binding. In Proc. LICS'99, 1999.

 G. Hutton and J. Gibbons. The generic approximation lemma. Information Processing Letters, 2001. To appear.

 P. T. Johnstone, A. J. Power, T. Tsjujushita, H. Watanabe, and J. Worrell. The structure of categories of coalgebras, 1998.

 G. M. Kelly. A unified treatment of transfinite constructions for free algebras, free monoids, colimits, associated sheaves and so on. Bulletins of the Australian Mathematical Society, 22:1- 83, 1980.

 G. M. Kelly. Elementary observations on 2-categorical limits. Bulletins of the Australian Mathematical Society, 39:301-317, 1989.

 G. M. Kelly and A. J. Power. Adjunctions whose counits are coequalizers, and presentations of finitary monads. Journal for Pure and Applied Algebra, 89:163- 179, 1993.

 A. Kurz. Logics for Coalgebra and Applications to Computer Science. Dissertation, Ludwig-Maximilans-Universtität München, 2000.

 C. Lüth. Compositional term rewriting: An algebraic proof of Toyama's theorem. In H. Ganzinger, editor, Rewriting Techniques and Applications, 7th International Conference, number 1103 in LNCS, pages 261- 275. Springer Verlag, July 1996.

 C. Lüth and N. Ghani. Monads and modular term rewriting. In Category Theory in Computer Science CTCS'97, number 1290 in LNCS, pages 69- 86. Springer Verlag, September 1997.

 S. Mac Lane. Categories for the Working Mathematician, volume 5 of Graduate Texts in Mathematics. Springer Verlag, 1971.

 M. Makkai and R. Pare. Accessible Categories: The Foundations of Categorical Model Theory, volume 104 of Contemporary Mathematics. American Mathematical Society, 1989.

 L. Moss. Coalgebraic logic. Annals of Pure and Applied Logic, 96:277-317, 1999.

 E. Robinson. Variations on algebra: monadicity and generalisations of equational theories. Technical Report 6/94, Sussex Computer Science Technical Report, 1994.

 G. Rosu. Equational axiomatisability for coalgebra. Theoretical Computer Science, 260(1), 2000.

 D. Turi. Functorial Operational Semantics and its Denotational Dual. PhD thesis, Free University, Amsterdam, 1996.

 J. Worrell. Terminal sequences for accessible endofunctors. In Electronic Notes in Theoretical Computer Science, volume 19, 1999. Proceedings CMCS '99.