+ All Categories
Home > Documents > A compositional generalisation of logical relations

A compositional generalisation of logical relations

Date post: 18-Nov-2023
Category:
Upload: independent
View: 0 times
Download: 0 times
Share this document with a friend
15
Transcript

A compositional generalisation of logical relationsGordon Plotkin, John Power� and Don SannellaDivision of Informatics,University of Edinburgh,King's Buildings,Edinburgh EH9 3JZ,SCOTLAND.email: [email protected], [email protected] and [email protected] logical relations do not compose. So we generalise the notionof logical relation to one of lax logical relation, so that binary lax logicalrelations do compose. We give both a direct generalisation and a corres-ponding category theoretic formulation. We generalise the Basic Lemmafor logical relations to a Basic Lemma for lax logical relations. Finally,we give an axiomatic category theoretic analysis of our de�nition.1 IntroductionLogical relations have been useful in a number of areas of computer sciencesuch as abstract interpretation [1], modelling local variables [12], and generallyin characterising parametric polymorphism [16]. A standard text that discusseslogical relations is Mitchell's book [10]. One area that has evaded logical rela-tions to some extent, although a topic in which one would expect to use them,has been data re�nement. The reason is that, in general, binary logical rela-tions do not compose. So we seek to generalise the notion of logical relation toa notion that admits composition. In doing so, we wish to generalise the BasicLemma as that is the fundamental fact about logical relations that is essentialto their use. So that is the question we address in this paper.The central di�culty in composing binary logical relations lies with higherorder types. Consider a language L generated by a signature of base types andbase terms together with the �-calculus, and consider two set-theoretic modelsM and N of L. Given binary logical relations R from M to N and S fromN to P , the composite R � S is not logical as it need not satisfy the conditionthat f (R �S)�!� g if for all (x; y)�M��P� , if x (R �S)� y, then fx (R �S)� gy,�This work is supported by EPSRC grant GR/J84205: Frameworks for programming lan-guage semantics and logic. 1

although it does satisfy the converse. So we relax the de�nition of logical relationin order to avoid that condition.In order to retain a version of the Basic Lemma, we replace the conditionby several axioms all of the same form, such as the axiom that if f R(���)!� g,then Curry(f)R�!�!� Curry(g). In principle, we need one axiom for eachconstructor used to build terms of the language. In fact, using the axiomsof the �-calculus, that entails some redundancy, so a smaller list of axioms issu�cient. We call the resulting de�nition that of a binary lax logical relation.It is routine to extend from binary lax logical relations to lax logical relationsof any arity.The most compact way to express this general notion is in terms of categorytheory. To give a binary logical relation is equivalent to giving a functor, strictlypreserving cartesian closed structure, from the cartesian closed category freelygenerated by the given language into Rel, the category of binary relations, suchthat composition with the two projections to Set yields the given models. Togive a binary lax logical relation is exactly the same except that one weakensthe requirement that the functor strictly preserves cartesian closed structure tothe requirement that it strictly preserves �nite products. In fact, we take thatas our primary de�nition of binary lax logical relation, then characterise it inmore syntactic terms.There are several generalisations of the above analysis. We can generalisefrom set-theoretic models of a language to models in an arbitrary cartesianclosed category. We can then take our relations in an arbitrary category too,with a little extra data and conditions, this category generalising the category ofbinary relations, cf [8]. Also, we can extend from the simply typed �-calculus toother languages, for instance incorporating coproducts. In general, our notionof lax logical relation extends to any language extending the simply typed �-calculus and given by algebraic structure, in a sense we shall make precise. In thecategory theoretic spirit of our analysis, we can also de�ne a category theoreticequivalent of the notion of signature. We discuss the various generalisations inSection 4.Historically, there have been several attempts to resolve the lack of compos-itionality of logical relations, some of which have in uenced our analysis here.We address some speci�c proposals in Section 2. Most important to us here,Kinoshita, O'Hearn, Power, Takeyama and Tennent [4] gave a category theor-etic de�nition closely related to ours, and to some extent, this paper attemptsto explain the syntactical signi�cance of their main constructs. Their accountdi�ers from ours in a few signi�cant respects: they did not consider preserva-tion of �nite products, equivalently contexts, and they did not give a syntacticaccount of the Basic Lemma, which may be impossible at their level of gen-erality; but we avoid analysis of abstract data types, which were embedded intheir account. Hermida's thesis [3] gave a category theoretic account of logicalrelations in terms of �brations: his work gave rise to both Kinoshita et al's workand to ours. In the more usual syntactic terms, various people, in particularMoggi, have considered a possible generalisation of the notion of logical relationas we have it, but do not seem to have realised that it addresses the composition2

problem.The paper is organised as follows. In Section 2, we recall the de�nition oflogical relation and exhibit a category theoretic formulation, and we explain theproblem of composition and outline a partial solution. In Section 3, we giveour notion of lax logical relation, which we de�ne category theoretically andcharacterise more syntactically, and we generalise the Basic Lemma in thoseterms. In Section 4, we outline various generalisations of our analysis.2 Logical relationsMuch of this section appears in [3] and is implicit in [4], but we need a carefulaccount of it in order to generalise it later. Let � be a signature of basic typesand terms for the simply typed �-calculus with products, generating a languageL. Let � and � be any types in L. We denote the set of functions from a set Xto a set Y by [X;Y ].2.1 De�nition A model M of L in Set consists of� for each �, a set M�, such that M�!� = [M�;M� ], M��� = M� �M� ,and M1 = 1� for each base term c of � of type �, an element M(c) of M�.A model extends inductively to send each judgement � ` t : � of L to a functionfromM� toM�, whereM� is the evident �nite product in Set. Given a signature� and two interpretations, M and N , of the language L generated by �, we say2.2 De�nition A binary logical relation from M to N consists of, for eachtype � of L, a relation R� �M� �N�such that� for all f�M�!� and g�N�!� , we have fR�!�g if and only if for all(x; y)�M� �N�, if xR� y, then f(x)R� g(y)� for all (x0; x1)�M��M� and (y0; y1)�N��N� , we have (x0; x1)R��� (y0; y1)if and only if x0R� y0 and x1R� y1� 1R1 1, where 1 is the unique element of M1 = N1 = 1� M(c)R�N(c) for every base term c in � of type �.The data for a binary logical relation is completely determined by its behaviouron base types. The fundamental result about logical relations underlying all ofits applications is the Basic Lemma as follows.3

2.3 The Basic Lemma Let R be a binary logical relation. Then for anyterm t : � of L in context �, if xR� y, then M(� ` t)xR� N(� ` t)y.It is routine to de�ne n-ary logical relations for an arbitrary natural numbern, in the spirit of De�nition 2.1. The corresponding formulation of the BasicLemma holds for arbitrary n too.We now outline a category theoretic formulation of logical relations [3]. Thelanguage L generates a cartesian closed category, which we also denote by L,such that a model M of the language L in any cartesian closed category such asSet extends uniquely to a functor M : L �! Set that preserves cartesian closedstructure strictly [7]. We may therefore identify the notion of model of thelanguage L with that of a functor strictly preserving cartesian closed structurefrom L into Set.2.4 De�nition The category Rel2 is de�ned as follows: an object consists ofa pair (X;Y ) of sets and a binary relation R from X to Y ; a map from (X;R; Y )to (X 0; R0; Y 0) is a pair of functions (f : X �! X 0; g : Y �! Y 0) such that xR yimplies f(x)R0 g(y); composition is given by ordinary composition of functions.We denote the forgetful functor from Rel2 to Set � Set sending (X;R; Y ) to(X;Y ) by (�0; �1) : Rel2 �! Set� Set.It is folklore and routine to verify that the category Rel2 is cartesian closed,and the cartesian closed structure is preserved by (�0; �1). Despite possibleconfusion with the category of sets and relations, we typically abbreviateRel2 byRel when the context is clear. Obviously, one could equally de�ne the categoryReln of n-ary relations for an arbitrary natural number n; the category Reln iscartesian closed and the forgetful functor from Reln to Setn preserves cartesianclosed structure strictly.2.5 Proposition To give a binary logical relation from M to N is equivalentto giving a functor R : L �! Rel strictly preserving cartesian closed structure,such that (�0; �1)R = (M;N).Proof Given a binary logical relation, one immediately has the object functionof R : L �! Rel. The equation (�0; �1)R = (M;N) determines the behaviour ofR on arrows; the fact that (M(� ` t); N(� ` t)) satis�es the condition makingit an arrow in Rel from R� to R� , for any term t of type � in context �, followsfrom (and is equivalent to) the Basic Lemma. The converse construction is givenby taking the object part of a strict cartesian closed functor R : L �! Rel. Itis routine to verify that the two constructions are mutually inverse.Again, Proposition 2.5 generalises routinely to arbitrary n. This proposition isdeveloped and considerably extended in Hermida's thesis [3], giving a categorytheoretic treatment of logical relations in terms of �brations with structure.Given �, and given interpretations M , N and P of the generated languageL, and given logical relations R fromM to N and S from N to P , it is routine toverify that the pointwise composition of relations R �S need not yield a logical4

relation as the condition on higher order types fails. In terms of the categorytheoretic characterisation, the problem is that R and S preserve exponentialsbut R � S, although a functor that preserves �nite products strictly, need notpreserve exponentials. But if one is to study data re�nement, then one needs tocompose re�nements. So we seek an account of composition for logical relations.A more subtle approach, given the above data, is to take the composition ofrelations on base types, then extend that to relations on higher types. So de�neR�S by (R�S)� = R� � S� if � is of base type, and de�ne R�S inductively oncompound types as determined by the de�nition of logical relation. It is an easyexercise to verify2.6 Proposition If � is of no more than �rst order type, then (R � S)� �(R�S)�.The inclusion is strict, even if R and S are partial surjections; and there arenatural examples for which the proposition fails for second order types. So thisapproach also does not give the general account we seek if there are base termsof greater than �rst order type.So we generalise the notion of logical relation in order to accommodate anaccount of composition, with the fundamental feature of logical relations wewish to maintain being the Basic Lemma 2.3.3 Lax logical relationsIn this section, we generalise the notion of logical relation to what we call alax logical relation, so that applying the ordinary composition of relations toa pair of binary lax logical relations with compatible domain and codomaingives a binary lax logical relation, and a generalisation of the Basic Lemma stillapplies. It is more conceptual and compact to express this in category theoreticterms, then characterise the de�nition in more syntactic terms, extending butreversing Proposition 2.5. This section is an analysis of the leading example ofthe paper, and gives a paradigmatic theorem for the paper. The emphasis hereis somewhat di�erent to that of [4] in that we study syntax explicitly, our mainresult being about the relationship between syntax and semantics, but we avoiduse of data types.Given a signature � and the language L generated by �, and two models Mand N of L in Set, we say3.1 De�nition A binary lax logical relation from M to N is a functor R :L �! Rel strictly preserving �nite products such that (�0; �1)R = (M;N).Any �nite product preserving functor such as R between cartesian closed cat-egories induces a family of lax mapsR�!� �! [R� ; R� ];5

by taking the Currying in Set of the mapsR�!� �R� �! R(�!�)�� �! R�where the �rst map is determined by preservation of �nite products, and thesecond map is given by applying R to the evaluation map. This is an instance of(op)lax preservation of structure, speci�cally exponential structure, hence ourterminology for this generalisation of logical relations. Evidently, one can adaptthis de�nition to one for n-ary lax logical relations for arbitrary n.The notion of Henkin model is closely related to this de�nition. A Henkinmodel of simply typed �-calculus is a �nite product preserving functor from Lto Set such that the induced lax maps are injective. That is not quite the sameas giving a unary lax logical relation, but is a natural and useful generalisationof the notion of model we have used, and one to which our results routinelyextend: for this abstract, we save space by not making the extension formally.From the perspective of our de�nition, the Basic Lemma for lax logicalrelations is a triviality, as it amounts to the fact that a lax logical relationsends each arrow of the category L to an arrow in Rel. Moreover, we have3.2 Proposition If R and S are binary lax logical relations, then so is thecomposite of relations R � S.Proof We must show that if R : L �! Rel and S : L �! Rel strictly preserve�nite products, then so does R � S. But (x0; x1) (R � S)��� (y0; y1) if and onlyif there exists (z0; z1) such that (x0; x1)R��� (z0; z1) and (z0; z1)S��� (y0; y1),and that is so if and only if x0 (R � S)� y0 and x1 (R � S)� y1. The proof for aterminal object is trivial.Our de�nition of lax logical relation together with a desire to generaliseProposition 2.5 determine, modulo the equivalences in the de�nition of simplytyped �-calculus, a more syntactic de�nition of a lax logical relation. We expressit as follows.3.3 Theorem To give a lax logical relation from M to N is to give for eachtype � of L, a relation R� �M� �N�such that1. if f0R�!� g0 and f1R�!� g1, then (f0; f1)R�!(���) (g0; g1)2. �0R���!��0 and �1R���!� �13. if f R(���)!� g, then Curry(f)R�!�!� Curry(g)4. ev R(��(�!�))!� ev5. if f R�!� g and f 0R�!� g0, then f 0f R�!� g0g6. idR�!� id 6

7. xR� y if and only if xR1!� y8. M(c)R�N(c) for every base term c in � of type �.Proof For the forward direction, the relations R� are given by the objectpart of the functor. The conditions follow immediately from the fact of Rbeing a functor, thereby having an action on all maps, and from the fact thatit strictly preserves �nite products. For instance, there is a map in L from(� ! �) � (� ! �) to � ! (� � �), so that map is sent by R to a map in Rel,and R strictly preserves �nite products, yielding the �rst condition. So usingthe de�nition of a map in Rel, and the fact that (�0; �1)R = (M;N), and thefact that M and N are strict structure preserving functors, we have the result.For the converse, the family of relations gives the object part of the functorR. Observe that the axioms imply� (x0; x1)R��� (y0; y1) if and only if x0 R� y0 and x1 R� y1� 1R1 1, where 1 is the unique element of M1 = N1 = 1So, R strictly preserves �nite products providing it forms a functor. The datafor M and N and the coherence condition (�0; �1)R = (M;N) on the putativefunctor determine its behaviour on maps. It remains to check that the image ofevery map in L actually lies in Rel. But the conditions inductively de�ne theCurrying of every map in L, so unCurrying by the �fth and seventh conditions,the result follows. It is routine to verify that these constructions are mutuallyinverse.There are several variants on the statement of the theorem. We chose theabove because the �rst four conditions seem particularly natural from the per-spective of �-calculus, the following two, which are about substitution, are nat-ural category theoretic conditions, the seventh is mundane, and the last evident.The key point of the proof, to which we will return in the next section, is thatevery map in the category L is generated by the terms appearing in the aboveaxioms. So, for a correct statement, one just needs to �nd constructors withwhich all maps in the category L are generated.The Basic Lemma may be understood in terms of the characterisation ofTheorem 3.3. If we suppress the distinction between the two characterisations,then the assertion that our functor R acts on maps becomes3.4 The Basic Lemma Let R be a binary lax logical relation. Then for anyterm t of L of type � in context �, if xR� y, then M(� ` t)xR� N(� ` t)y.Theorem 3.3 and the Lax Basic Lemma generalise routinely to arbitrary n.4 An axiomatic viewWe seek to generalise the results of Section 3 in several ways. We want to gener-alise from the category Set to a broader class of categories and from considering7

all relations to constructs that need not be relations at all. We also wish togeneralise from the simply typed �-calculus. Thus we consider an axiomatictreatment.4.1 Generalising from the �-calculusIn Section 3, the fundamental facts that gave rise to our de�nition of lax lo-gical relation were the correspondence between the simply typed �-calculusand cartesian closed categories, and the fact that a signature � gave rise toa cartesian closed category L such that a model of � could be seen as a functorfrom L into Set that strictly preserved cartesian closed structure.So in generalising from the simply typed �-calculus, we generalise the latterfact. This may be done in terms of algebraic structure, or equivalently (�nit-ary) monads, on Cat. The central paper about that is Blackwell, Kelly andPower's [2]. We can avoid much of the subtlety here by restricting our attentionto maps that preserve structure strictly.A methodology for extending Theorem 3.3 is as follows. Algebraic structureon Cat is given by an equational presentation. That equational presentation hasoperations de�ning objects and arrows. For each operation de�ning an arrow,one adds an axiom to the list in the statement of Theorem 3.3 in the samespirit. For instance, to de�ne a monoidal structure, one has operations thatassign to each pair of maps (f; g), a map f g, and gives associative maps andtheir inverses, and left and right unit maps and their inverses. So one wouldadd axioms� if f0R�0!�0 g0 and f1R�1!�1 g1, then (f0 f1)R(�0�1)!(�0�1) (g0 g1)aR(��)�!�(��) a l R(�I)!� l r R(I�)!� ra�1R�(��)!(��)� a�1 l�1R�!(�I) l�1 r�1 R�!(I�) r�1The structure needed here is very similar to that in Meseguer's paper [9],but is most naturally seen in the context of this paper as a special instance ofalgebraic structure on Cat, as de�ned in [5] and [13]. Appendix A gives thede�nition of algebraic structure on Cat in general. Using the notation of theappendix, we consider a special class of algebraic structures.4.1 De�nition Algebraic structure (S;E) on Cat is discrete if S(c) = 0whenever c is not a discrete category, i.e., whenever c is not the discrete categoryon a �nite set.It follows from the de�nition that any discrete algebraic structure may bepresented by two families of operations: object operations, which have algebrasgiven by functors of the form Ck �! C, and arrow operations, which are givenby natural transformations between object operations. One may put equationsbetween these to obtain all operations of any discrete algebraic structure, whichare given by functors Ck �! CSk, where Sk is a small category.8

Assuming Set has (S;E)-structure for given discrete algebraic structure(S;E), amodel of an (S;E)-algebra in Set is just a functor that strictly preserves(S;E)-structure.4.2 De�nition Given discrete algebraic structure on Cat extending �niteproduct structure, and given a signature of base types and base terms in termsof the algebraic structure and exponentials, and considering the language gen-erated by the simply typed �-calculus, the signature, and the discrete algebraicstructure, a syntactic lax logical relation from a model M to a model N consistsof a family of relations R� �M� �N�such that� if f R(���)!� g, then Curry(f)R�!�!� Curry(g)� ev R(��(�!�))!� ev� if f0R�!� g0 and f1R�!� g1, then (f0; f1)R�!(���) (g0; g1)� �0R���!��0 and �1R���!� �1� if f R�!� g and f 0R�!� g0, then f 0f R�!� g0g� idR�!� id� xR� y if and only if xR1!� y� M(c)R�N(c) for every base term c in � of type �� for any k-ary object operation O, if fiR�i!�i gi for all 1 � i � k, thenO(f1; � � � ; fk)RO(�1;���;�k)!O(�1;���;�k)O(g1; � � � ; gk)� for any k-ary arrow operationO, we haveO(M�1; � � � ;M�k)R O(N�1; � � � ; N�k)where = (domO(�1; � � � ; �k)! codO(�1; � � � ; �k))� for any k-ary arrow operation O, if fiR�i!�i gi for all 1 � i � k, thendomO(f1; � � � ; fk)R� domO(g1; � � � ; gk), where � = (domO(�1; � � � ; �k) !domO(�1; � � � ; �k)), and similarly with dom systematically replaced by cod.The �nal two rules here may seem unfamiliar at �rst sight. An arrow operationtakes a k-ary family of objects to an arrow, so syntactically, takes a k-ary familyof types to an equivalence class of terms. That leads to our penultimate rule.That a k-ary arrow operation is functorial means that every k-ary family ofarrows is sent to a commutative square. So we need rules to the e�ect thatevery arrow in that square behaves as required. The penultimate rule aboveaccounts for two arrows of the square, and the �nal rule accounts for the othertwo, where the domain of the commutative square is the arrow of the squareuniquely determined by the de�nitions. We can now extend Theorem 3.3 to thissetting. 9

4.3 Theorem For any discrete algebraic structure on Cat extending �niteproduct structure, to give a syntactic lax logical relation is equivalent to giving afunctor R : L �! Rel2 strictly preserving �nite products, such that (�0; �1)R =(M;N) for models M and N .Proof Follow the proof of Theorem 3.3. The de�nition of syntactic logicalrelation shows inductively that for every arrow of the category freely generatedby the given discrete algebraic structure applied to the signature, one obtainsan arrow in Rel.As a corollary of this, we conclude, by functoriality in the de�nition of lax logicalrelation4.4 The Basic Lemma For any discrete algebraic structure, given a syntacticlogical relation R, if � ` t : �, then if xR� y, it follows thatM(� ` t)xR� N(� `t)y4.5 Examples Examples of discrete algebraic structure have models givenby small categories with �nite products, with �nite coproducts, with monoidalstructure, symmetric monoidal structure, a monad [11], an endofunctor, a nat-ural transformation between endofunctors, or any combination of the above.4.2 Generalising from SetThe work here is not substantially di�erent to that of [4], the main di�er-ence being in regard to preservation of �nite products. But we include it forcompleteness. Axiomatically, we generalise Set to an arbitrary small cartesianclosed category C (with smallness relative to some universe of arbitrary size).We generalise Rel and (�0; �1) : Rel �! Set � Set to a small category Ewith �nite products together with a strict �nite product preserving functor(�0; �1) : E �! C � C. This is in the same spirit as Ma and Reynolds' accountof logical relations in [8]. To generalise the notion of composition of relations,we have a functor comp : E �C E �! E strictly preserving �nite products,where E �C E is the pullbackE �C E 1 - EE 0 ? �1 - C�0?in the category Cat and�0 comp = �0 0 �1 comp = �1 110

We further add axioms to the e�ect that comp is associative and has a left andright identity, with the functor id : C �! E expressing the identity relationalso required to preserve �nite products strictly. Since pullbacks in the categoryFPs of small categories with �nite products and functors strictly preserving�nite products are given by pullbacks in Cat, the above is equivalent, modulosize, to giving a category object (C;E; comp; id) in the category FPs, such thatC is cartesian closed.Assume as before that we have a signature � for simply typed �-calculus,generating a language L.4.6 De�nition If M and N are models of the language L in the cartesianclosed category C, a binary lax logical relation from M to N is a functor R :L �! E that strictly preserves �nite products, such that (�0; �1)R = (M;N).The data allow us to de�ne a composite R � S for binary lax logical rela-tions with compatible domain and codomain: use the universal property of thepullback to obtain < R;S >: L �! E �C E, and compose with comp. Theassociative and identity axioms ensure that composition of lax logical relationsis associative with unit determined by id.4.7 Proposition If R and S are binary lax logical relations, then so is R �S.Proof Since R and S strictly preserve �nite products, so does < R;S >, andhence so does R � S.4.8 Example Put C = Set, E = Rel2, and let the functor (�0; �1) be given bythe projections from Rel2 to Set. Then an object of E �C E is given by a pairof relations ((X;R; Y ); (Y; S; Z)). Let comp : E �C E :�! E be given by theordinary composition of relations, and let id : C �! E be given by sending aset X to the identity relation on X . A binary lax logical relation as we have justde�ned it agrees with the de�nition in the previous section, and the compositionof two of them agrees with the usual composition too.For usual logical relations, if one adds the further condition to our axiomat-isation here that the functor (�0; �1) be a �bration, then one obtains a tighterconnection between the category theoretic structure and the logical structure,as the latter is given by the internal language of the former. That is exploredin Hermida's thesis [3]. It is not entirely clear yet how to extend our analysisof the Basic Lemma to this generality, but the concept of �bration may be thekey construct here. We may also need to restrict attention to the case in whicheach �bre is a poset.We can also axiomatise the notion of a signature �, doing so at the levelof generality of this section. That is the content of Kinoshita, Power, andTakeyama's work on sketches [6], summarised in [4].We hope to extend these results herein to account for more general structuressuch as premonoidal structure as used to model contexts in general [15, 14].11

References[1] S. Abramsky, Abstract interpretation, logical relations and Kan ex-tensions, J. Logic and Computation 1 (1990) 5{40.[2] R. Blackwell, G.M. Kelly, and A.J. Power, Two-dimensional monadtheory, J. Pure Appl. Algebra 59 (1989) 1{41.[3] C. A. Hermida, Fibrations, Logical Predicates and Indeterminates,Ph.D. thesis, Edinburgh (1993) available as ECS-LFCS-93-277.[4] Y. Kinoshita, P. O'Hearn, A.J. Power, M. Takeyama, and R.D.Tennent, An Axiomatic Approach to Binary Logical Relations withApplications to Data Re�nement, Proc TACS 97, Lecture Notesin Computer Science 1281, Abadi and Ito (eds.), Springer (1997)191{212.[5] G.M. Kelly and A.J. Power, Adjunctions whose counits are coequal-izers, and presentations of �nitary enriched monads, J. Pure Appl.Algebra[6] Y. Kinoshita, A.J. Power, and M. Takeyama, Sketches, J. PureAppl. Algebra (to appear).[7] J. Lambek and P.J. Scott, Introduction to Higher-Order CategoricalLogic, Cambridge Studies in Advanced Mathematics 7, CUP (1986).[8] Q. Ma and J.C. Reynolds, Types, abstraction and parametric poly-morphism 2, Math. Found. of Prog. Lang. Sem. Lecture Notes inComputer Science, Springer (1991).[9] J. Meseguer, Conditional rewriting logic as a uni�ed model of con-currency, Theoretical Computer Science 96 (1992) 73-155.[10] J. Mitchell, Foundations for programming languages, Foundationsof Computing Series, MIT Press (1996).[11] E. Moggi, Notions of computation and monads, Information andComputation 93 (1991) 55-92.[12] P.J. O'Hearn and R.D. Tennent, Relational parametricity and localvariables, Proc POPL 93, ACM (1993).[13] A.J. Power, Categories with algebraic structure, Proc CSL 97, Lec-ture Notes in Computer Science 1414, Neilsen and Thomas (eds.),Springer (1998) 389{405.[14] A.J. Power, Premonoidal categories as categories with algebraicstructure (submitted). 12

[15] A.J. Power and E.P. Robinson, Premonoidal categories and notionsof computation, Proc. LDPL 95, Math Structure in Computer Sci-ence (to appear).[16] J.C. Reynolds, Types, abstraction, and parametric polymorphism,Information Processing '93, R.E.A. Mason (ed.), North Holland(1983).A Algebraic Structure on CategoriesIn ordinary universal algebra, an algebra is a set X together with a family ofbasic operations � : Xn ! X , subject to equations between derived operations.In order to de�ne algebraic structure on categories, one must replace the set Xby a category A. One also replaces the �nite number n by a �nitely presentablecategory c. All �nite categories are �nitely presentable, and �nite categories arethe only �nitely presentable categories we need in this paper. One also allowsnot only functions from the set Cat(c; A) into the set of objects of A, but alsofunctions from the set Cat(c; A) into the set of arrows in A. These are subjectto equations between derived operations. It follows that the category of smallsuch categories with structure and functors that strictly preserve the structureis equivalent to the category of algebras, T -Alg, for a �nitary monad T on Cat.All structures relevant to this paper are instances of a slightly more restrictedsituation: that of Cat-enriched algebraic structure. So we shall restrict to Cat-enriched structures here. Let C denote the 2-category Cat of small categories.So C(A;B) denotes the category of functors from A to B. Let Cf denote thefull sub-2-category of C given by (isomorphism classes of) �nitely presentablecategories.A.1 De�nition A signature on C is a 2-functor S: obCf �! C, regardingobCf as a discrete 2-category.For each c 2 obCf , S(c) is called the category of basic operations of arity c.Using S, we construct S! : Cf �! C as follows: setS0 = J; the inclusion of Cf in CSn+1 = J + Xd2obCf C(d; Sn(�))� S(d);and de�ne�0 : S0 �! S1 to be inj : J �! J +Pd2obCf C(d; S0(�))� S(d)�n = J +Pd2obCf C(d; �n�1(�))� S(d) : Sn �! Sn+1S! = colimn<!Sn:The colimit exists because C is cocomplete, and it is a colimit in a functorcategory with base C. In many cases of interest, each �n is a monomorphism,13

so S! is the union of fSn gn<!. For each c, we call S!(c) the category of derivedc-ary operations.A signature is typically accompanied by equations between derived opera-tions. So we sayA.2 De�nition The equations of an algebraic theory with signature S aregiven by a 2-functor E : obCf �! C together with 2-natural transformations�1; �2 : E �! S!(K(�)), where K : obCf �! Cf is the inclusion.A.3 De�nition Algebraic structure on C consists of a signature S, togetherwith equations (E; �1; �2). We generally denote algebraic structure by (S;E),suppressing �1 and �2.We now de�ne the algebras for a given algebraic structure.A.4 De�nition Given a signature S, an S-algebra consists of a small categoryA together with a functor �c : C(c; A) �! C(S(c); A) for each c.So, an S-algebra consists of a carrier A and an interpretation of the basic oper-ations of the signature. This interpretation extends canonically to the derivedoperations, giving an S!(K(�))-algebra, as follows:�0 : C(c; A) �! C(S0(c); A) is the identity;to give �n+1 : C(c; A) �! C(Sn+1(c); A), using the fact that C(�; A) preservescolimits, is to give a functor C(c; A) �! C(c; A), which we will make the iden-tity, and for each d in obCf , a functorC(c; A) �! C(C(d; Sn(c)); C(S(d); A));or equivalently, C(c; A)�C(d; Sn(c)) �! C(S(d); A), which is given inductivelybyC(c;A)� C(d; Sn(c)) �n � id- C(Sn(c); A)� C(d; Sn(c)) comp- C(d;A) �- C(S(d); A)A.5 De�nition Given algebraic structure (S;E), an (S;E)-algebra is an S-algebra that satis�es the equations, i.e., an S-algebra (A; �) such that both legsof C(c; A) �!- C(S!(Kc); A) C(�1c; A)-C(�2c; A)- C(E(c); A)agree.14

Given (S;E)-algebras (A; �) and (B; �), we de�ne the homcategory(S;E){Alg((A; �); (B; �)) to be the equaliser in C ofC(A;B) fC(c;�) gc2 obCf - Yc C(C(c; A); C(c;B))Yc C(C(S(c); A); C(S(c); B))fC(S(c);�) gc2 obCf? Qc C(�c; C(S(c); B))- Yc C(C(c;A); C(S(c); B)):Qc C(C(c; A); �c? ) (1)This agrees with our usual universal algebraic understanding of the notion ofhomomorphism of algebras, internalising it to C. (S;E){Alg can then be madeinto a 2-category in which composition is induced by that in C. An arrow in(S;E){Alg is a functor F : A �! B such that for all �nitely presentable c,F�c(�) = �c(F�) : C(c; A) �! C(S(c); B), i.e., a functor that commutes withall basic c-ary operations for all c.A special case of the main result of [5] (see [13] for an account directedtowards a computer science readership) saysA.6 Theorem A 2-category is equivalent to (S;E){Alg for algebraic structure(S;E) on C if and only if there is a �nitary 2-monad T on C such that the 2-category is equivalent to T{Alg.

15


Recommended