Available online at www.sciencedirect.com

ScienceDirect

Electronic Notes in Theoretical Computer Science 218 (2008) 295-311

www.elsevier.com/locate/entcs

Tensors of Comodels and Models for Operational Semantics

Gordon Plotkin1

School of Informatics, University of Edinburgh, Edinburgh EH9 3JZ, UK

John Power2

Department of Computer Science, University of Bath,, Bath, BA2 7AY, UK

Abstract

In seeking a unified study of computational effects, one must take account of the coalgebraic structure of state in order to give a general operational semantics agreeing with the standard one for state. Axiomatically, one needs a countable Lawvere theory L, a comodel C, typically the final one, and a model M, typically free; one then seeks a tensor C 0 M of the comodel with the model that allows operations to flow between the two. We describe such a tensor implicit in the abstract category theoretic literature, explain its significance for computational effects, and calculate it in leading classes of examples, primarily involving state.

Keywords: Countable Lawvere theory, model, comodel, global state, arrays, free cocompletion, tensor.

1 Introduction

Over the past decade, in collaboration with a number of other researchers, and following Eugenio Moggi's seminal monadic approach to notions of computation [9], we have been developing an algebraic theory of computational effects. This theory emphasises the operations that give rise to the effects at hand, and the equations that hold between them: see [13] for an overview.

One goal of this project was to give an axiomatic account of the various methods of combining of effects [3,4,5]. Another, indeed the focus of the first paper of the series [10], was to develop a unified theory of structural operational semantics for effects; unfortunately, however, the axiomatics of [10] had the severe limitation of not accounting for the example of state, or for any combination of effects including

1 Supported by EPSRC grant GR/586372/01 and a Royal Society-Wolfson Award Fellowship.

2 Supported by EPSRC grant GR/586372/01.

1571-0661/$ - see front matter © 2008 Elsevier B.V. All rights reserved. doi:10.1016/j.entcs.2008.10.018

state. More recently, we have begun to appreciate the importance of coalgebra in understanding the dynamics of state [15] and in this paper we start to rectify the situation by developing the combination of algebra and coalgebra which we believe will be needed.

In modelling state, one typically has assignment and dereferencing constructors, := and !, with typing rules of the form

M : loc N : val M : loc

(M := N) : 1 !M : val

where loc is a type to be modelled by a finite set of locations Loc and val is the type of values, modelled by a set V. The structural operational semantics of state typically involves transition systems of the form:

(1) {s,M) > {s',M')

where M and M' are closed terms of the same type, a say, and s and s' are states, i.e., elements of S =def VLoc. (We reverse the usual order to fit in better with the tensor introduced below.)

The transitions can be generated by such rules as:

(2) {s,E[l := v])-^{s[v/l],E[*])

(3) {s, E[!l]) > {s, E[s(l)])

where E[ ] is an evaluation context. An adequate denotational semantics must, in some way, identify the two sides of these transitions. For example, using Moggi's state monad Ts =def (S x -)S the denotation [M] of M of type a is in Ts([a]]), where [[a]] is the denotation of a, and one has:

(4) [ M ](s) = [M'](s')

However, applying the general operational semantics of [10] to the case of state yields transitions applied to a term M only, with no state parameter.

Analysis of equation (4) in the cases of rules (2) and (3) shows it has a specific form. Assignment and dereferencing are modelled by evident maps:

g~ : Loc x V —► Ts(t) cj\ : Loc —► TS{V)

Now, as we recall in detail in Section 2, the countable Lawvere theory Ls for global state is generated by two operations:

a : 1 —► Loc xV d : V —► Loc

subject to seven equations [11,15]. These operations yield two algebraic operations, viz families of maps, natural in the Kleisli category:

ars(X) : Ts(X) Ts(X)LocxV drs(x) : Ts(X)V Ts(X)Loc

and g:= and g\ appear as the corresponding generic effects [12].

Next, as we recall in Section 3, a comodel of Ls, i.e., a countable coproduct preserving functor from Lo£ to Set, amounts to a set Y together with functions:

aY : (Loc x V) x Y —► Y dY : Loc x Y —► V x Y

subject, appropriately interpreted, to the same seven equations; the category of such coalgebras is, in turn, equivalent to the category of arrays in the sense of [15], cf [2,17]. Modulo a transposition, the generic effects provide the final such coalgebra on the set of states S.

Let us now consider equation (4) in the case of Rule (2). One can show that [E[l := v]] = aT([oj)((l,v), [E[*]]) and with this the equation becomes:

ar (W) ((l,v),[E MJ)(s) = [E M](as ((l,v),s))

We see that the equation swaps the coalgebra map as for the algebra map aT([oj). The same holds, albeit a little less obviously, for rule (3) with respect to ds and d?([o-j). This swapping of an algebra map with a coalgebra map is characteristic of the bilinear maps ® involved in tensors, for example the tensor of two bimodules. In our case ® is application, so we would write the above equation as:

s ® a?(W)((l, v), [EMJ) = as((l, v),s) ® [EMl

with the idea that:

S ® Ts([a]) = S x V In general, given an algebra A and coalgebra C we seek the universal map:

C x A C ® A such that for every operation f : I ^ J, we have:

s ® fA(Y)(j) = s ® Y(i)

for every s E C, y E A1 and j E J, where {i,s') = fc(j,s). Axiomatically this involves a countable Lawvere theory L, a model M : L —► Set, and a comodel C : Lop —► Set. It turns out that the tensor can be equivalently seen as factoring the sum of all pairs Ma x Ca by allowing the swapping of the image Mf of a map f in L with the image Cf of f, while respecting the countable product structure of the countable Lawvere theory L. It is constructed using a countable coproduct-respecting variant of the theorem that the free cocompletion of a small category D is given by the Yoneda embedding Y : D —► [Dop,Set].

We explore the relevant abstract mathematics in Section 4 and show that for an arbitrary L-comodel C, the tensor C ® Tl(X) of C with the free L-model on a set X is C1 x X. This result confirms and generalises the above informal discussion of state; it also applies to read-only state in combination with other effects. In Section 5, we give general results allowing the calculation of the tensor C ® M in two other cases: the combination of global state or monoid actions with other effects. But what about a combination of co-models, for instance having both readonly and global state? In order to account for these, in Section 6 we give a suitable operation C o C' on comodels and a formula for (C o C') ® M in terms of formulae

involving C and C' individually. The Appendix gives a bicategorical view of the tensor: while we have no application for it yet, it is mathematically very natural.

We have expressed ourselves here, and we continue to express ourselves through the course of the paper, in terms of ordinary countable Lawvere theories, models in Set, and comodels in Set. But all the abstract work in the paper generalises routinely to Lawvere V-theories [14] for those V that are locally countably presentable as cartesian closed categories, as does all the concrete work except for Example 6.3 and succeeding, where further work remains to be done. So we include uCpo, often used to account for recursion [3,4]; here one simply includes the lifting monad among the effects not involving co-models. For background definitions and results about enrichment, see [6].

2 Models of Countable Lawvere Theories

In this section, we briefly recall the definitions of countable Lawvere theory and model, focusing on the countable Lawvere theory for global state; details are implicit in [11] and explicit in [15]. Let denote a skeleton of the full subcategory of Set of the countable sets. So, up to equivalence, it contains one object n for each natural number, together with an object to represent a countable set. It has countable coproducts.

Definition 2.1 A countable Lawvere theory consists of a category L with countable products and an identity-on-objects strict countable product preserving functor J : —► L. A model of L in a category C with countable products is a countable product preserving functor from L to C.

The models of L in a category C with countable products form a category Mod(L,C), whose arrows are given by all natural transformations.

Theorem 2.2 For any countable Lawvere theory L and any locally presentable category C, the forgetful functor U : Mod(L, C) —► C exhibits Mod(L, C) as monadic over C. In the case that C = Set, the induced monads Tl are precisely the countably presentable monads on Set.

For global state, we assume we are given a finite set Loc of locations and a countable set V of values. We identify Loc with the natural number given by its cardinality, and we identify V with

Definition 2.3 The countable Lawvere theory Ls for global state is the theory freely generated by maps

d : V —► Loc a : 1 —► Loc x V

subject to the commutativity of seven diagrams, expressible as equations between infinitary terms as follows:

(i) di((ai>v(x))v) = x

(ii) di((di((x vv' Jv J )v' ) = di ((x vv )v)

(iii) ai,v(ai,v'(x)) = ai,v'(x)

(iv) ai,v (di((xv )v )) — ai,v (xv)

(v) di ((di> ((xvv' )v' ))v) = di' ((di ((xvv' )v ))v') where l = l'

(vi) ai,v (ai' (x)) (ai,v(x)) where l = l

(vii) ai,v(di>((xv')v')) = di'((ai,v(xv>))v') where l = l'.

An equivalent version of the equations in terms of commutative diagrams appears in [15]. The definition implies an equation (viii):

di((x)v) = x

The following theorem, stated in slightly different but equivalent terms, is the first main theorem of [11].

Theorem 2.4 For any category C with countable products and countable coprod-ucts, the forgetful functor U : Mod(Ls,C) —► C exhibits the category Mod(Ls,C) as monadic over C, with monad (S ® -)S, where S is the set VLoc and S ® X is the coproduct of S copies of X.

Theorem 2.4 explains why we refer to Ls as the countable Lawvere theory for global state: taking C = Set, the induced monad is the monad for global state or side-effects proposed by Moggi [9,11].

Proposition 2.5 The left adjoint of the forgetful functor U : Mod(Ls,C) —► C sends an object X of C to the object (S ® X)S together with the maps

u : (S ® X)S ((S ® X)S)Locxy

determined, modulo an isomorphism, by composition with the function

Loc x V x VLoc —► VLoc

that, given (loc, v, a), "updates" a : Loc —► V by replacing its value at loc by v and

l :((S ® X)S)y ((S ® X)S)Loc

determined, modulo an isomorphism, by composition with the function

Loc x VLoc —► V x VLoc

that, given (loc, a), "lookups" loc in a : Loc —> V to determine its value, and is given by the projection into VLoc.

More generally, for any countable Lawvere theory L, one can consider the tensor product L ® Ls [3,4]. The monad induced by L ® Ls on Set is Tl(S x —)S. And the Ls-model structure of Proposition 2.5 extends from (S x X)S to Tl(S x X)S to give the Ls-model structure on the free (L <g) Ls)-model Tl(S x X)S on any set X: the key point is that the model structure is determined entirely in terms of the exponent S.

Example 2.6 Let Lr denote the countable Lawvere theory for read-only state. It is freely generated by a map r : S —► 1 subject to the commutativity of two diagrams, which, expressed as infinitary equations, become:

(i) r((x)s) = x

(ii) r((r((xss' )s )) s' ) r((xss)s)

The induced monad on Set is (-)S.

The free Lr-model on a set X is XS, with the Lr-model structure on XS given by precomposition with the diagonal

(Xs)S = xSxS X t xs

So again, the model structure is determined entirely in terms of the exponent S. And again, that extends to tensor products L & Lr, the free (L & Lr)-model on a set X being given by (TlX)s. We note finally that in the case where S = VLoc, the theory Lr can, alternately, be presented by an operation d : V ^ Loc subject to equations (ii), (v) and (viii) above.

The final example of a countable Lawvere theory of primary importance to us here is that of a monoid action; it has several computational applications.

Example 2.7 Given a monoid M, the countable Lawvere theory Lm induces the monad M x- on Set; the theory is generated by M unary operations fm, respecting the monoid structure of M, i.e., fe = id where e is the unit of M, and fmfm' = fmm' where the multiplication of M is denoted by juxtaposition. The category of models of Lm in Set is the category of left M-sets. For an arbitrary countable Lawvere theory L, the tensor product of L with Lm generates the monad Tl(M x -) on Set [4].

One use of this theory is for resources, e.g., timed processes [4,8]; there the monoid is typically the positive reals, or the natural numbers, with addition. Another is write-only memory, where for example, one takes the theory generated by an operation a : 1 ^ Loc x V and equations (iii) and (vi) above; in this case the monoid has carrier lc Loc VL.

3 Comodels of Countable Lawvere Theories

In this section, we briefly recall from [15] the notion of a comodel of an arbitrary countable Lawvere theory, focusing upon the example Ls of global state in Section 2. The abstract results of this section again enrich routinely to categories that are locally countably presentable as cartesian closed categories.

Definition 3.1 A comodel of a countable Lawvere theory L in a category C with countable coproducts is a countable coproduct preserving functor from Lop to C.

Comodels of L in a category C with countable coproducts form a category Comod(L,C), whose arrows are given by all natural transformations. So, almost

by definition, for any category C with countable coproducts, we have the following:

Comod(L, C) = Mod(L, Cop)op

It follows from Theorem 2.2 that for any countable Lawvere theory L and any category C for which Cop is locally presentable, the forgetful functor U : Comod(L,C) —► C has a right adjoint, exhibiting Comod(L,C) as comonadic over C. But Setop is not locally presentable, so this fact is of no help in regard to our leading example of a base category.

Nevertheless, the following is true, as shown in [15].

Theorem 3.2 For any countable Lawvere theory L, the forgetful functor

U : Comod(L, Set) —► Set has a right adjoint, exhibiting Comod(L, Set) as comonadic over Set.

The central fact yielding the proof is the cartesian closedness of Set, specifically the fact that the tensor of an object a of L, i.e., a countable set, with X has the universal property of a product. It follows that one can extend the result to categories such as Poset, uCpo, and Cat, and that it generalises to enrichment in any category that is locally countably presentable as a cartesian closed category, such as Poset, uCpo, or Cat.

The main theorem of [15] asserted that the category of comodels of the countable Lawvere theory Ls is given by a category of arrays. So we now recall the category of arrays as defined in [15]. The axiomatic definition of an array follows and mildly generalises the approach to arrays in [2,17].

Definition 3.3 Given a finite set Loc of locations and a countable set V of values, a (Loc,V)-array consists of a set A together with functions

sel : A x Loc —► V

upd : A x Loc x V —► A

subject to four axioms written in equational form as follows: for l and l' in Loc, for v and v' in V, and for a in A

(i) sel(upd(a,l,v),l) = v

(ii) upd(a, l, sel(a, l)) = a

(iii) upd(upd(a, l, v),l, v') = upd(a, l, v')

(iv) upd(upd(a, l, v),l',v') = upd(upd(a, l',v'),l, v) where l = l'

There is an evident notion of a map of arrays, yielding a category (Loc,V)-Array. The relationship between the definition of an array and the countable Lawvere theory Ls is not entirely trivial. The most obvious dissimilarity is that the former has four axioms while the latter has seven, and the next most obvious dissimilarity is that, if one thinks about duals for u and l, it is clear that u matches upd but that l does not match sel. On the other hand, the four array axioms are remarkably similar to four of the global state axioms, and to give a function

sel : A x Loc —► V is equivalent to giving a function sel' : A x Loc —► A x V subject to the axioms

The central technical result of [15] was as follows.

Theorem 3.4 The forgetful functor from (Loc,V)-Array to Set is comonadic over Set, with comonad given by (-)vLoc x VLoc.

The category Setop has countable products and countable coproducts, with products given by the coproducts of Set and with coproducts given by the products of Set. So, combining Theorem 2.4 with Theorem 3.4, we reached the desired conclusion as follows.

Corollary 3.5 Let Ls be the countable Lawvere theory for global state. Then Comod(Ls,Set) is equivalent to (Loc,V)-Array.

It follows from Theorem 3.4 and Corollary 3.5 that the final Ls-comodel is given by the set S of states with its canonical lookup and update structure. Corollary 3.5 enriches routinely, assuming one uses the evident definition of enriched (Loc,V)-array.

Our next two classes of examples are read-only state, extending Example 2.6, and a monoid action, extending Example 2.7.

Example 3.6 A priori, to give a comodel for Lr is to give a set X together with a function X —► S x X subject to two axioms. But the unit axiom simply asserts that the projection to X yields the identity, and the composition axiom is trivial. So a comodel is just a function X —► S, i.e., an object of the slice category Set/S. The maps work similarly. The final comodel is therefore given by the set S together with the identity map. In the enriched setting, one generalises from Set/S to V/S: an object of a slice V-category C/X is defined to be an arrow with codomain X in the V0-category C.

Example 3.7 For a monoid M, the Lawvere theory Lm is generated by unary operations subject to axioms that dualise: the duality is given by swapping left with right in M. So, to give a comodel of Lm is equivalent to giving a model of Lm but with the order of multiplication reversed, making Comod(LM,Set) the category of right M-sets. The final comodel is 1, but a more interesting comodel Cm is given by the set M with action determined by the multiplication of M together with a twist. This example also enriches routinely.

Finally, we note that if a theory contains a constant or a commutative binary operation then its only comodel in Set is the trivial, with empty carrier. We there-

fore do not expect coalgebra to play any direct role in such computational effects as exceptions or ordinary or probabilistic nondeterminism.

4 The Tensor of a Comodel with a Model

In this section, for any countable Lawvere theory L, we describe a tensor C ® M of an arbitrary comodel C with an abitrary model M and calculate it in several cases. At the heart of our category theoretic analysis is the fundamental theorem that asserts that the Yoneda embedding expresses the presheaf category [Dop,Set] as the free cocompletion of any small category D:

Theorem 4.1 Let D be a small category. Then for any locally small cocomplete category E, composition with the Yoneda embedding

Y : D —► [Dop,Set]

induces an equivalence of categories

Cocomp([Dop ,S et] ,E) = [D,E]

where, for any locally small cocomplete category E', the category Cocomp(E',E) is the category of colimit preserving functors from E' to E and all natural transformations between them.

A proof of this appears in the enriched setting in Kelly's book [6], in which it plays a central r(o)le. The inverse equivalence sends a functor H : D —► E to its left Kan extension LanyH, which can be described in more elementary terms as follows:

(5) (LanyH)(F) = J Hd x Fd

This is a coend, so is given by factoring the sum EdeD(Hd x Fd) by dinaturality: H is covariant in D and F is contravariant in D, so any map f : d' —► d generates two functions

(Hf x Fd), (Hd' x Ff) : Hd' x Fd —► Hd x Fd

and one factors the sum Ed(Hd x Fd) by the equivalence relation — generated by all such pairs of functions, yielding

(6) J Hd x Fd = (EdeD(Hd x Fd))/ -

So Theorem 4.1 asserts that every colimit preserving functor from [Dop,Set] to E is isomorphic to one that sends F in [Dop,Set] to (Ed(Fd x Hd))/ — for some functor H : D —► E, uniquely up to coherent isomorphism.

The theorem says a little more than that in that the fully faithfulness part of being an equivalence says that natural transformations are respected by the constructs too. One can make a slightly stronger statement. All colimit preserving functors from [Dop,Set] to E have right adjoints, and those adjoints can be described

as follows: for any functor H : D —► E, the functor sending an object X of E to E(H—,X) : Dop —► Set is the right adjoint to LanYH.

There are numerous refinements of Theorem 4.1. A refinement in the direction we need appears in [7] and tells us the following.

Theorem 4.2 Let D be a small category with countable coproducts. Then for any locally small cocomplete category E, composition with the Yoneda embedding

Y : D —► CP(Dop,Set)

induces an equivalence of categories

Cocomp(CP(Dop,Set),E) ^ CC(D, E)

where CP(Dop,Set) denotes the full subcategory of [Dop,Set] determined by the countable product preserving functors from Dop to Set, and CC(D,E) denotes the category of countable coproduct preserving functors from D to E.

There are a number of subtleties implicit in the statement of Theorem 4.2. First, for any small category D with countable coproducts, the Yoneda embedding

Y : D —► [Dop,Set]

factors through CP(Dop,Set): that part is easy. Second, the restricted variant of the Yoneda embedding, i.e., the Yoneda embedding regarded as having codomain CP(Dop,Set), preserves countable coproducts: that follows from the Yoneda lemma. Third, the category CP(Dop,Set) is cocomplete: that is a substantial result, the colimits not being given pointwise in general.

The proof of the theorem is not difficult. Moreover, the formula for the inverse equivalence is identical to that for Theorem 4.1, i.e., a countable coproduct preserving functor H : D —► E corresponds to the colimit preserving functor from CP(Dop,Set) to E given by restricting LanyH from [Dop,Set] to CP(Dop,Set), thus sending F in CP(Dop,Set) to the coend 5. The right adjoint also restricts, with the same formula as in the classical case.

Observe that a countable Lawvere theory L is a small category with countable products, the category Mod(L, Set) is exactly CP(L, Set), and the category CC(Lop,E) is the category of comodels of L in E. Thus we have:

Corollary 4.3 Let L be a countable Lawvere theory. Then for any cocomplete category E, the Yoneda embedding

Y: Lop —► Mod(L, Set)

induces an equivalence of categories

Cocomp(Mod(L, Set),E) = Comod(L, E)

The above analysis gives a formula for the inverse equivalence, i.e., (5), more explicitly (6), as well as a right adjoint E —> Mod(L, Set).

Given a comodel C and a model M of L, we now write C ® M for LanyC(M).

Thus, by (5), we have the following formula.

(7) C & M = J Ca x Ma

It follows from its definition that the construction C & M is bifunctorial.

The objects of L are exactly the natural numbers together with Ko. So each object a is a countable coproduct in Ki, equivalently a countable product in L, of a copies of 1. Since C preserves countable coproducts and M preserves countable products, we have:

Ca x Ma = a x C1 x M 1a Next, by the Yoneda lemma, the coend

J a x CJ1 x MJ1a

is C1 x M1, and so C & M is given by further coequalising C1 x M1 with respect to arbitrary maps in L yielding the universal map

&c,m : C1 x M1 —► C1 & M1

discussed in the introduction; see too the discussion just before Theorem 6.2.

Given a comodel C : Lop —► Set of L in Set, as we know, the right adjoint to C & — sends a set Y to the composite

(8) L-* Setop-- Set

necessarily a model of L in Set. This 'exponential' construction of a model from a comodel was exemplified in Section 2 for state and read-only state.

This adjointness yields a general formula for the tensor of an arbitrary comodel C of an arbitrary countable Lawvere theory L with any free model TlX of L on a set X as follows.

Theorem 4.4 For any countable Lawvere theory L, comodel C of L and set X, the tensor C & TlX of C with the free model TlX of L on X is given by the product C1 x X.

Proof. This follows directly from the properties of adjoints: to give a function from C & TlX to Y is equivalent to giving a map of models from the free model TlX on X to Set(C-,Y), which is equivalent to giving a function from X to Set(C 1,Y), which, by cartesian closedness of Set, is equivalent to giving a function from C1 x X to Y, all natural in Y. □

So the tensor is indeed the familiar S x X considered in the introduction. Indeed, as the reader may check, all the the other examples of tensor we calculate also accord with the usual practise in operational semantics.

Our next example is read-only state. By Example 2.6, the free (L & Lr)-model M of L & Lr on a set X is given by (TLX)S, which is also the free Lr-model on the set TlX. Thus Theorem 4.4 applies, making C & (TlX)s = C1 x TlX. One usually combines exceptions with other effects by considering the sum of theories

L' + Le. This corresponds to the monad Tl> (—+ E) on Set. So the theorem also applies if we add exceptions as the monad induced by (L & Lr) + Le is given by (Tl(X + -))S.

5 Further Calculations of the Tensor

In this section, we calculate the tensor for two other examples: global state and monoid actions. As in the case of read-only state we are interested in combinations with other theories, by tensor, and with exceptions, by sum [4]. Our calculations again enrich without fuss.

First consider Ls. If Y is any set and C is any comodel of Ls in Set, using the composite (8), we can consider the coend JaeLs Ca x YCa. Recall that the final comodel of Ls in Set sends a in Ls to a x S.

Theorem 5.1 For any set Y, if C is the final comodel of Ls, evaluation generates an isomorphism of sets

I (Ca x YCa) —► Y

Proof. This follows from a mild strengthening of a form of the Yoneda embedding to account for the density of the functor C, equivalently of the full subcategory of Set given by those sets of the form a x S [6]. Alternatively, one can prove the result directly: for any element y of Y, consider constant functions at y and use the fullness of the functor C. □

The tensor product L & Ls, with L a countable Lawvere theorem, generates the monad Tl(S x -)S [3,4]. As remarked in Section 2, the Ls-model structure on Tl(S x X)S smoothly generalises that on (S x X)S, i.e., it is determined by the final comodel structure of the exponent S. So Theorem 5.1 yields:

Corollary 5.2 For any countable Lawvere theory L and any set X, if C is the final comodel of Ls and M is the free (L & Ls)-model on X, the tensor C & M is the set Tl(S x X).

We can squeeze a little more value out of Theorem 5.1 to obtain the formula Tl(Sx(X+E)) for the tensor of the final comodel of Ls with the free ((L&Ls)+Le)-model on any set X.

For monoid actions Lm, our primary interest lies not in the trivial final comodel, but rather in the monoid M treated as the comodel Cm.

Theorem 5.3 For any countable Lawvere theory L and any set X, if M' is the free (L & Lm)-model on X, the tensor Cm & M' is the set Tl(M x X).

Proof. Since Ki is included in Lm, there is a canonical function

aeHc°p anLM

I (M x a) x (Tl(M x X ))M xa —> J Cm a x M'a

The Yoneda lemma applied to Ki implies the following, for any set Y:

Y = J (a x Ya)

Given X, putting Y = (Tl(M x X))M, using cartesian closedness of Set and the formula (7) for tensor, the above two displays yield a function

M x TL(M x X) —► CM & M'

exhibiting CM & M' as a quotient of M x TL(M x X).

The quotient is generated by the identification of (m, rj(e, x)) with (e, n(m, x)) for any m in M, where e is the unit of M. That routinely yields the result, the coprojections being given by the canonical strength of Tl together with the multiplication of M. □

Theorem 5.3 yields the formula Tl(M x (X + E)) for the tensor of Cm and the free ((L & Lm) + Le)-model on a set X.

6 Combining Comodels

In previous sections, we have considered comodels of three main theories: LS, Lr and Lm . But one may have more than one of these acting at once, for instance employing triples (s, t, M) consisting of a state s, a time t and a term M. So in this section, we consider a tensorial combination of comodels and its interaction with the tensor with models.

Observe that, since Set is cartesian closed, for any pair of comodels C of L and C' of L' in Set, the functor

Lop x L'op-- Set x Set-- Set

preserves countable coproducts in each argument separately, i.e., for every aeL, the functor Ca x C' (—) preserves countable coproducts, and dually. By the universal property of the tensor product of countable Lawvere theories, the composite thus yields a comodel of L & L' in Set, which we shall denote by C o C'; we have (C o C')1 = C1 x C'1.

Theorem 4.4 immediately yields a formula as follows.

Corollary 6.1 For any countable Lawvere theories L and L' with comodels C and C' respectively in Set, if M is the free (L & L')-model on a set X, the tensor (C o C') & M is given by C1 x C'1 x X.

We next consider models that need not be free (L & L')-models on a set X. Given countable Lawvere theories L and L', denote the coprojections from L and L' into L & L' by J and J' respectively. So, for any model M of L & L', it follows that MJ is a model of L and MJ' is a model of L'.

Theorem 6.2 For any countable Lawvere theories L and L', comodels C of L and C' of L', and model M of L & L', the tensor (C o C') & M is the pushout in Set

given as follows:

s x M1 , C'1 x<g>c mj C1 x C'1 x M1-- C'1 x C1 x M1-cmj C1 x (C ® MJ)

C1 x ®c>,mj'

C1 x (C' ® MJ')

(C ◦ C') ® M

Proof. The following formulae are consequences of formula (7) together with cartesian closedness of Set:

J (a x C1 x C'1 x (Ml)a) = C1 x C'1 x M1

J (a x C1 x C'1 x (M 1)a) = C'1 x (C & MJ)

J (a x C1 x C'1 x (M 1)a) = C1 x (C' & MJ')

atL®L'

J (a x C1 x C'1 x (M 1)a) = (C 1 o C') & M

Every map in L & L' is a composite of a map in L with a map in L'. The result follows by an elementary colimit calculation. □

Evidently, one can consider more than two countable Lawvere theories and their comodels. But our analysis here has only involved routine manipulation of colimits and the cartesian closedness of Set. So we leave it to the reader to formulate associativity results and the like.

Example 6.3 Let C and C' be the final comodels S and S' for state and read-only state respectively, and let M be the free (Ls ® Lr ® L)-model Tl(S x X)SxS' on a set X. Then, putting Y = Tl(S x X) and suppressing the canonical twist map, the tensor (C o C') & M is the pushout

SxS'x YS*S' S' x eVs. S'x YS'

S x (ns' ,evs')

S S' YS

We need therefore only show that the commutative diagram obtained by replacing P by S' x Y satisfies the universal property of a pushout. So let so be a chosen element of S. Given (s',h) and (s',h') in S' x YS' such that h(s') = h'(s'), consider

the two elements of S x S' x (YS')S determined by s0, s', and the constants at h and h' respectively. Suppressing a canonical isomorphism, the function S x (ns' ,evs') identifies those two elements. So p0 must identify (s',h) with (s',h'). So the pushout is indeed given by S' x Y. Thus (C o C') & M is S' x Tl(S x X).

It is routine to extend Example 6.3 to incorporate an M'-action, yielding the following formula:

(S o S' o M') & Tl(S x M' x X)SxS' = S' x Tl(S x M' x X)

for global state S and read-only state S'.

References

[1] R. Blackwell et al, Two-dimensional monad theory, JPAA 59 (1989) 1—41.

[2] M. Hofmann & B. C. Pierce, Positive Subtyping, Inf. & Comp. 126 (1996) 11-33.

[3] M. Hyland et al, Combining Algebraic Effects with Continuations, TCS 375(1) (2007) 20-40.

[4] M. Hyland et al, Combining effects: sum and tensor, TCS 357 (2006) 70-99.

[5] M. Hyland & A. J. Power, Discrete Lawvere Theories and Computational Effects, TCS 366 (2006) 144-162.

[6] G. M. Kelly, Basic Concepts of Enriched Category Theory, CUP (1982).

[7] G. M. Kelly, Structures Defined by Finite Limits in the Enriched Context I, Cahiers de Topologie et Geometrie Différentielle 23 (1982) 3-42.

[8] M. Kick et al, Coalgebraic Semantics for Timed Processes, Inf. & Comp. 204 (2006) 588-609.

[9] E. Moggi, Notions of Computation and Monads, Inf. & Comp. 93 (1991) 55-92.

[10] G. D. Plotkin & A. J. Power, Adequacy for Algebraic Effects, Proc. FOSSACS 2001, LNCS 2030 (2001) 1-24.

[11] G. D. Plotkin, & A. J. Power, Notions of Computation Determine Monads, Proc. FOSSACS 2002, LNCS 2303 (2002).

[12] G. D. Plotkin & A. J. Power Algebraic Operations and Generic Effects, Applied Categorical Structures 11(1) (2003) 69-94.

[13] G. D. Plotkin & A. J. Power Computational Effects and Operations: an Overview, Proc. Workshop on Domains, ENTCS 73 (2004) 149-163.

[14] A. J. Power, Enriched Lawvere Theories, Theo. and Apps. of Categories (2000).

[15] A. J. Power & O. Shkaravska, From Comodels to Coalgebras: State and Arrays, Proc. CMCS 2004, ENTCS 106 (2004) 297-314.

[16] R. H. Street, Fibrations in Bicategories, Cahiers de Topologie et Geometrie Différentielle 21 (1980) 111-160.

[17] A. Stump et al, A Decision Procedure for an Extensional Theory of Arrays, Proc. 16th LICS (2001).

310 G. Plotkin, J. Power / Electronic Notes in Theoretical Computer Science 218 (2008) 295-311

Appendix: Model-Comodel Biactions

One can give a more general setting for our construction of the tensor C & M of a comodel C with a model M that allows a form of iteration of the process. The tensor C & M can be seen as an instance of composition in a naturally existing bicategory: for any set A with both an L-model structure and an L'-comodel structure on it, subject to natural coherence axioms, and any set B with an L'-model structure and an L''-comodel structure subject to similar coherence conditions, one can build a composite A & B that factors out the L'-structures while inheriting the L-structure of A and the L''-structure of B.

We do not yet have any application of this compositional generalisation of tensor, but as it is mathematically relevant and substantial, we include analysis of it in this section of the paper. We should perhaps mention that, for the enriched setting, one needs a notion of enriched bicategory here that is routine to formulate, but goes beyond the currently standard literature.

Definition 6.4 Let CC denote the 2-category for which

• 0-cells are small categories with countable coproducts

• 1-cells are functors that preserve countable coproducts

• 2-cells are all natural transformations with the evident composition.

The forgetful 2-functor U : CC —► Cat has a left biadjoint F, meaning F is essentially a left adjoint but adjusted to deal with non-identity isomorphisms and with 2-cells [1].

Passing over size concerns, which can be treated by recourse to Section 2 of [6] for example, it follows from Theorem 4.2 that the construction that sends a small category with countable coproducts D to CP(Dop,Set) extends canonically to a pseudo-monad Tcoc on CC. Consider the bicategory Kl(Tcoc). In particular, consider two 0-cells of it. One of them is F1, the free category with countable coproducts on 1. So F1 is equivalent to Nat, but we shall not use that fact here. The other is Lop for any countable Lawvere theory L seen as a small category with countable products as in Corollary 4.3.

Straightforward calculations show the following.

Proposition 6.5 In the bicategory Kl(Tcoc)

(i) to give a 1-cell from F1 to Lop is equivalent to giving a model of L in Set

(ii) to give a 1-cell from Lop to F1 is equivalent to giving a comodel of L in Set

(iii) to give a 1-cell in Kl(Tcoc) from F1 to F1 is equivalent to giving a set.

The discussion after Theorem 4.2 may be rephrased as the statement that composition in Kl(Tcoc) is calculated pointwise, i.e., the inclusions

CP (Dop,Set) —► [Dop,Set]

generate a 2-functor from Kl(Tcoc) to Prof, the 2-category of small categories,

profunctors, and natural transformations, where composition is calculated as follows: given H : D x D'op —► Set and K : D' x D''op —► Set, the composite H & K : D x D''op —► Set sends (x, y) to the coend

I H(x,z) x K(z,y)

Thus, applying Proposition 6.5, given a model M : L —► Set and a comodel C : Lop —► Set of a countable Lawvere theory L, the composite in Kl(Tcoc) yields the set faeL Ca x Ma, recovering the tensor formula (7).

To give a 1-cell in Prof from D to D' is equivalent to giving a functor H : D x D'op —► Set, which is equivalent to giving a 1-cell in Prof from D'op to Dop. This fact has proved to be of considerable value in the abstract theory of categories, supporting Street's study of two-sided fibrations [16]. Unfortunately, the 2-category Kl(Tcoc) does not allow such symmetry. For to give a countable coproduct preserving functor from D to CP(D'op,Set) is not equivalent to giving a functor from D x D'op to Set that preserves countable coproducts in its first argument and countable products in its second. Moreover, we cannot see any malleable formulation of the 1-cells of Kl(Tcoc) in such terms. So we see no malleable way in which to treat the 1-cells of Kl(Tcoc) in terms of two-sided fibrations [16] satisfying natural conditions related to preservation of products and coproducts.