RC S0- .J C J. M. DS-03-7 BRICS BRICS Basic Research in Computer Science cao omlCluu o Categories for Calculus Formal A accamo: ´

A Formal Calculus for Categories

Mario JoseC´ accamo´

BRICS Dissertation Series DS-03-7 ISSN 1396-7002 June 2003 Copyright c 2003, Mario JoseC´ accamo.´ BRICS, Department of Computer Science University of Aarhus. All rights reserved.

Reproduction of all or part of this work is permitted for educational or research use on condition that this copyright notice is included in any copy.

See back inner page for a list of recent BRICS Dissertation Series publi- cations. Copies may be obtained by contacting:

BRICS Department of Computer Science University of Aarhus Ny Munkegade, building 540 DK–8000 Aarhus C Denmark Telephone: +45 8942 3360 Telefax: +45 8942 3255 Internet: [email protected]

BRICS publications are in general accessible through the World Wide Web and anonymous FTP through these URLs:

http://www.brics.dk ftp://ftp.brics.dk This document in subdirectory DS/03/7/ A Formal Calculus for Categories Mario Jos´eC´accamo

PhD Dissertation

Department of Computer Science University of Aarhus Denmark

A Formal Calculus for Categories

A Dissertation Presented to the Faculty of Science of the University of Aarhus in Partial Fulfilment of the Requirements for the PhD Degree

by Mario Jos´eC´accamo 6th July 2004

A toda mi familia, y en especial a Chola y Pora.

Abstract

This dissertation studies the logic underlying theory. In particular we present a formal calculus for reasoning about universal properties. The aim is to systematise judgements about functoriality and naturality central to categorical reasoning. The calculus is based on a language which extends the typed lambda calculus with new binders to represent universal constructions. The types of the languages are interpreted as locally small categories and the expressions represent . The logic supports a syntactic treatment of universality and . Contravari- ance requires a definition of universality generous enough to deal with functors of mixed variance. Ends generalise limits to cover these kinds of functors and moreover provide the basis for a very convenient algebraic manipulation of expressions. The equational theory of the lambda calculus is extended with new rules for the definitions of universal properties. These judgements express the existence of natural between functors. The isomorphisms allow us to formalise in the calculus results like the and Fubini theorem for ends. The definitions of limits and ends are given as representations for special -valued functors where Set is the and functions. This establishes the basis for a more calculational presentation of rather than the traditional diagrammatic one. The presence of structural rules as primitive in the calculus together with the rule for duality give rise to issues concerning the coherence of the system. As for every well-typed expression-in-context there are several possible derivations it is sensible to ask whether they result in the same interpretation. For the functoriality judge- ments the system is coherent up to natural . In the case of naturality judgements a simple example shows its incoherence. However in many situations to know there exists a natural isomorphism is enough. As one of the contributions in this dissertation, the calculus provides a useful tool to verify that a is continuous by just establishing the existence of a certain natural isomorphism. Finally, we investigate how to generalise the calculus to enriched categories. Here we lose the ability to manipulate contexts through weakening and contraction and conical limits are not longer adequate.

vii

Acknowledgements

In first place I would like to express my gratitude to my supervisor Glynn Winskel for his guidance. He has been a constant source of inspiration and I am indebted to him for so many discussions. I would also like to thank the staff of BRICS for having created such an excellent environment, in particular to Mogens Nielsen for his enthusiasm and encouragement. Many thanks as well to Janne Christensen, Uffe Engberg and Karen Møller. I am also grateful to the Centre of the Danish National Research Foundation for financial support. From my time in Arhus˚ I owe much to Daniel Fridlender; his help and support in the first two years of my studies have been fundamental to me. I would also like to thank my fellow PhD-students, in special to the members of the “casual category theory study ”. Many thanks to Ulrich Kohlenbach and Paulo Oliva for clarifying many issues on proof theory. I wish to thank the staff of the Computer Laboratory in Cambridge where I spent the second half of my studies. Special thanks to Marcelo Fiore for always providing positive feedback to my work, and Daniele Varacca for his friendship and enduring innumerable sessions of derivations and proofs. They have also read portions of this dissertation providing invaluable comments. I would also like to thank Federico Crazzolara, Giuseppe Milicia and Philip Matchett. I would like to thank Edmund Robinson and Lars Birkedal for accepting to evaluate this dissertation. Part of the work presented in this dissertation was inspired by a Cambridge Part III course on category theory taught by Martin Hyland, in particular its emphasis on and coend manipulation. Finally, I would like to thank Laura, Sof´ıa and my family for their love and support in all these years. I dedicate this dissertation to them.

Mario Jos´eC´accamo, Cambridge, 6th July 2004.

ix

Contents

Abstract vii

Acknowledgements ix

1 Introduction 1 1.1Motivation...... 1 1.2 Category Theory ...... 2 1.2.1 Categories, Functors and Natural Transformations ...... 2 1.2.2 Constructions on Categories ...... 3 1.3FunctorialityandNaturality...... 5 1.4 Universal Properties and Representables ...... 8 1.5 The Calculus ...... 9 1.5.1 Syntax...... 9 1.5.2 Semantics...... 10 1.6 Related Work and Applications ...... 11 1.7Synopsis...... 11

2 Representability 13 2.1 Universal Properties ...... 13 2.2Limits...... 15 2.2.1 Completeness and Parameters ...... 16 2.2.2 Colimits...... 18 2.2.3 InitialFunctors...... 19 2.2.4 PreservationofLimits...... 21 2.3Adjunctions...... 21 2.3.1 ExamplesofAdjunctions...... 24

3 Ends and Coends 27 3.1DinaturalTransformations...... 27 3.1.1 Dinaturality generalises naturality ...... 30 3.1.2 Wedges...... 30 3.1.3 Examples...... 31 3.2Ends...... 33 3.2.1 LimitsareEnds...... 34 3.2.2 EndsareLimits...... 34 3.2.3 Ends in Set ...... 35 3.2.4 (Di)NaturalityFormula...... 35 3.2.5 Iterated Ends: Fubini ...... 36 3.2.6 Ends in Functor Categories ...... 38 3.3Coends...... 39 3.4PowersandCopowers...... 39 3.5 Presheaf Categories ...... 41

xi 3.5.1 WeightedLimits...... 41 3.5.2 WeightedColimits...... 48 3.5.3 Density...... 50 3.5.4 Exponentials...... 52

4 Preservation of Limits 53 4.1LimitingCones...... 53 4.2PreservationofLimitingCones...... 55 4.3 Connected Diagrams ...... 57 4.4Products...... 60 4.5GeneralLimits...... 62 4.6SomeExamples...... 66 4.6.1 Adjunctionsandlimits...... 66 4.6.2 ...... 67

5 A Term Calculus for Functors 71 5.1TheLanguage...... 71 5.1.1 BasicTypes...... 71 5.1.2 SyntaxandTypeTheory...... 72 5.1.3 Substitution ...... 76 5.1.4 Examples...... 80 5.2ANormalFormforDerivations...... 82 5.2.1 W-normalDerivations...... 82 5.2.2 CW-normalDerivations...... 85 5.2.3 DCW-normalDerivations...... 87 5.3 Categorical Model ...... 89 5.3.1 TypesandContexts...... 89 5.3.2 InterpretationforDerivations...... 89 5.3.3 Example...... 92 5.3.4 Semantics of Substitution ...... 92 5.4Coherence...... 94 5.5WithoutDuality...... 98 5.6Products...... 100

6 Natural Isomorphisms 103 6.1 Isomorphism Judgements ...... 103 6.1.1 Equational Theory of the Lambda Calculus ...... 103 6.1.2 RepresentablesandEnds...... 106 6.1.3 Duality...... 109 6.1.4 Products...... 111 6.1.5 Examples...... 112 6.1.6 Limits...... 112 6.1.7 Density Formula and the Yoneda Lemma ...... 113 6.2Interpretation...... 114 6.2.1 Lambda Calculus ...... 114 6.2.2 Axioms...... 115 6.2.3 Representability and Duality ...... 116 6.2.4 LackofCoherence...... 116 6.3WeightedLimits...... 117 6.4 Another Approach to Contravariance ...... 120

xii 7 Towards a Calculus for Enrichment 123 7.1 Symmetric Monoidal Closed Categories ...... 123 7.2 -Categories, -Functors and -Naturality...... 125 V7.2.1 OppositeV -Category .V ...... 126 7.2.2 -Bifunctors...... V 127 7.2.3 TheV Underlying “Ordinary” Category ...... 128 7.3RepresentableFunctorsandUniversality...... 128 7.3.1 Functor -Categories and the Enriched Yoneda Lemma . . . 130 7.3.2 TensorsandCotensors...... V 132 7.3.3 ANotionofLimit...... 132 7.4 An Enriched Model for the Calculus ...... 133 7.4.1 ContextsandJudgements...... 134 7.4.2 Structural Rules, Limits and Dinaturalities ...... 135

8 Extensions and Applications 137

A The Calculus 141 A.1Syntax...... 141 A.2 Rules for Functoriality ...... 141 A.2.1Axioms...... 141 A.2.2 Structural Rules ...... 141 A.2.3 Logical Rules ...... 142 A.3Products...... 142 A.3.1Syntax...... 142 A.3.2 Rules ...... 143 A.4 Rules for Natural Isomorphisms ...... 143 A.4.1 Structural Rules ...... 143 A.4.2 Conversion Rules ...... 143 A.4.3 Equivalence Rules ...... 144 A.4.4 Congruence Rules ...... 144 A.4.5 Categorical Rules ...... 144 A.5 Rules for Weighted Limits ...... 145

Bibliography 147

xiii

Chapter 1

Introduction

At a first glance, a formalisation of category theory might appear as a formidable enterprise. Our goal here is less ambitious, we aim to model an expressive fragment: representable functors and their basic properties. This serves two purposes: firstly to develop a syntax where properties like functoriality are ensured by the form of the expressions; and secondly to provide a logic where we can formalise proofs about categorical statements. This logic is rich enough to capture the ingredients of the categorical reasoning like universality, duality and contravariance.

1.1 Motivation

Universal properties occur in mathematics and computer science under different forms: free constructions, join completions, least fixed points, most general unifiers, inductive definitions and so on. The presentation of these notions in an abstract setting is one of the main contributions of category theory. Much of the appealing nature of the theory rests on the fact that the properties of mathematical structures can be modelled in a unifying system whose language is based on diagrams of arrows and objects. Diagrams avoid the ambiguities of language and facilitates the communication and understanding of mathematical concepts. Over the last three decades category theory has become a important tool in many areas of computer science. The use of categories in computer science does not appear as a mere organisational language, but as a suitable formal model to understand complex notions of computation. In a more foundational aspect computer science helped to bridge the gap between logic and categories resulting in a whole new are: . Here the focus was traditionally set on the characterisation of logic constructors in terms of categorical ones. The best example is the categorical- theoretic model for intuitionistic logic provided by cartesian closed categories via the simply typed lambda-calculus [LS86,Jac99]. Other examples are the categorical models for linear logic [Amb92, Bie95]. In a pioneer work Szabo [Sza78] studied the logics obtained by considering dif- ferent instances of monoidal categories. In this dissertation we study the logic underlying the manipulation of universal properties. As we talk about logic we need to define a suitable syntax for the new notions and a proof method which supports a sound manipulation of the language. This requires a more algebraic pre- sentation of category theory rather than the usual one based on diagrams of objects and arrows. The approach relies on the theory of representables, special kinds of Set-valued functors, able to capture in a very compact way the notion of . The advantages of a language in which to carry out definitions are well-known

1 2 Chapter 1. Introduction in domain theory and denotational semantics. There the functions arising in giving semantics to programming languages need to be continuous, with a view to taking least fix points, a fact which holds automatically once the functions are expressed in the language. In the same spirit we aim to systematise judgements of the kind “an expression is functorial in its free parameters” or “two functors are natural isomorphic”.

1.2 Category Theory

In this section we revise the basic concepts in category theory and fix the notation used in the next chapters. For more detailed introductions to category theory refer to [Mac98,Bor94a,BW90].

1.2.1 Categories, Functors and Natural Transformations As observed by Eilenberg and Mac Lane: “Category has been defined in order to define functor, and functor has been defined in order to define natural transforma- tion”. A category consists of a collection of objects and for every pair a, b of objects there is a collectionC of arrows or , written as (a, b), where a is the domain and b the codomain. In a category the morphisms compose,C the composition is associative and has identities. We use calligraphic capital letters , , , ...to denote categories. Small letters from the beginning and the end of theA alphabetB C a,b,...,x,y,z denote objects while small letters from the middle of the alphabet f,g,h,...are reserved for morphisms. We write c to mean that c is an object in the category . To make domains and codomains∈C explicit a f in the collection (c, d)C is written as f :c d f C → or c /d. A category is locally small if for any pair c, d the collection (c, d)isaset, the so-called hom-setC . In particular if the collection∈C of objects is alsoC a set we say that the category is small.WeuseC,I,J,...to denote small categories. Henceforth we use the word category with the assumption that we are referring to a locally small category the only exception being chapter 7 where the notion of -category is introduced. V There are many example of categories in mathematics and computer science. In this dissertation the category Set of sets and functions plays an important role. As an exception objects in Set will be denoted by capital letters A,B,... as it is customary with sets. Functors are structure-preserving transformations between categories. A functor F from to , written as F : , is described by C D C→D a mapping F from objects in into the objects in ,and • C D for every pair c, d a • ∈C

Fc,d (c, d) / (F (c),F(d)) C D such that identities and compositions are preserved. We use capital letters from the middle of the alphabet F,G,H,... to denote functors. In particular when for each c, d the mapping Fc,d is surjective we say that F is full, and if Fc,d is injective the∈C functors is said to be faithful. As it is the usual practice we will omit the subscripts in the mappings defined by a functor. 1.2. Category Theory 3

As functors categories into categories it is sensible to ask which kind of prop- erties are transferred, or preserved, in that transformation. An direct consequence from the definition of functors, for instance, is that functors preserve isomorphisms or more general section-retraction pairs. In the opposite direction, one speaks of the properties in the codomain of a functor that are reflected into the domain. In the case of the isomorphisms we have that full and faithful functors reflect them. Let F, G: be functors. A α from F to G, written as α : F GC→D, is defined by a -indexed family of arrows ⇒ C αc :F (c) G(c) c h → i ∈C such that for any arrow f :c d in we have that → C αd F (f )=G(f) αc. ◦ ◦ This is graphically represented as the commutativity of the diagram

α F (c) c / G(c)

F (f) G(f)   α F (d) d / G(d), the so-called naturality square. Compatible natural transformation compose componentwise. For functors and natural transformations F

α   / G H C D  β H it is routine to verify that the family defined by the componentwise composition

βc αc c h ◦ i ∈C is a natural transformation as well. This new family is written as β α. This composition is associative, and for a functor F it has an identity defined◦ by the family idF (c) c . Locallyh smalli ∈C categories and functors between them form the category CAT, though a bigger one which is not locally small. Indeed because of the presence of natural transformations, this category has extra structure and classifies as a 2- category. In few words in a 2-category there are arrows between arrows satisfying certain axioms (refer to [KS74] for an introduction of 2-category theory).

1.2.2 Constructions on Categories Duality A category gives rise to another category by just reversing all the arrows. This new categoryC called the dual or opposite is denoted by op. The composition of the arrows in op can be expressed in terms of the arrows in Cby reading the composition in the reverseC order: g f in op uniquely correspondsC to f g in .Inthesame spirit, a functor F : ◦ canC be dualised to obtain a functor◦ FCop : op op. More generally a statementC→D S involving a category automatically givesC →D a dual statement Sop obtained by reversing all the arrows.C This is known as the duality principle. 4 Chapter 1. Introduction

Product of Categories Given categories and there is a . The collection of objects is given byC the cartesianD product of the collectionC×D of objects in and . C D The set of arrows from (c, d)to(c0,d0) is defined to be

((c, d)), (c0,d0)) = (c, c0) (d, d0). C×D C ×D Composition and identities are defined pairwise. By projecting on one object of a pair we obtain the projections functors

π : and π : . 1 C×D→C 2 C×D→D

Functor Categories

For functors F, G : the collection of the natural transformations from F C→D to G is denoted by the expression Nat F, G . The natural transformations in Nat F, G compose, this composition is associative and has identities. Thus there is a “category” where the functors from to are objects and natural transformations are arrows: the so-called functor categoryC Dwritten as [ , ]. C D For locally small categories and , the [ , ] is not necessary locally small and then may fallC outD of the universe consideredC D here (see [Mac98, Cro93] for examples). If the domain is small, say C, then the functor category [C, ] is indeed locally small and we can write [C, ](F, G), its hom-set, for Nat F, G D. D

Bifunctors Products of categories allows us to define functors of multiple arguments. It follows from the usual inductive argument and the associativity of products that it is enough to consider functors with two arguments, the so-called bifunctors. In this section we mention some basic yet important results related to bifunctors. With the introduction of functor categories for many of the interesting cases we could just work with one-argument functors. This has a precise categorical meaning that we postpone until adjunctions. By now it is enough to observe that for a bifunctor F : and for each a there is a functor A×B→C ∈A F a : B→C obtained by fixing a, what Kelly [Kel82] calls the partial functor. Some authors use the notation F (a, )forFa which may create confusion with the bifunctor F .The action of F a is defined as

a a F (b)=F(a, b)andF(g)=F(ida,g) for g :b b0 in . Similarly for every b there is a partial functor → B ∈B

Fb : . A→C The collection of partial functors alone is not enough to characterise the bifunctor F . There is an extra requirement, namely that for arrows f : a a0 in and → A g :b b0 in → B a0 a F (g) Fb(f)=Fb (f) F (g). ◦ 0 ◦ This justifies the use of a more compact notation F (a, g)andF(f,b) instead of F (ida,g)andF(f,idb) respectively when referring to the bifunctor F . 1.3. Functoriality and Naturality 5

This basically says that bifunctoriality can not be checked at each component. This contrasts with naturality, given a natural transformation α : F G where F, G: , by fixing an object a there is a partial natural transformation⇒ A×B → C ∈A a a αa, : F G ⇒ and similarly for an object b . The collection of all these partial natural trans- formations uniquely determine∈Bα. Then naturality as opposed to functoriality can be checked at each component separately.

1.3 Functoriality and Naturality

The internal structure of CAT suggest a language where the expressions are given by the constructors on categories above. Indeed most of these constructions give functors, or in other words they are functorial in their variables. These functors can be combined via composition to generate complex expressions still functorial in their variables. More formally, let x , ,xn n be objects and an expression 1 ∈C1 ··· ∈C

E(x , ,xn) 1 ··· denoting an object in .WesayEis functorial in x , ,xn if it defines an action C 1 ··· consistent with the definition of functor when x1,x2,...,xn stand for arrows instead of objects. Thus a functorial expression has two possible readings: as an object in when the free variables x1,x2,...,xn are interpreted as objects, and as an arrow inC when they are interpreted as arrows. C Given two expressions E (x , ,xn)andE (x , ,xn) functorial in the vari- 1 1 ··· 2 1 ··· ables x1, ,xn it is sensible to ask whether there is a natural family between them. In general··· we shall be interested in natural isomorphisms, in this case one says that there is an isomorphism

E (x , ,xn)=E (x , ,xn) 1 1 ··· ∼ 2 1 ··· natural in x1, ,xn. It is a usual··· practice in category theory to use diverse place-holders like and to indicate variables in a functorial expression. We use place-holders in the introductory chapters but in the more complex examples where confusion can arise we use lambda-notation to indicate parameters and their scope.

Hom-Functors For a category , the expression (c, d) defines the hom-functor C C ( , ): op Set C C ×C→ where the action on arrows is

cO d (c, d) C f g (f,g)=g f   C ◦ ◦ c d (c0,d0). 0 0 C The same example serves to see that not all possible expressions give rise to a functor. The expression (c, c) for a nontrivial category is non-functorial since there is no action over arrowsC matching the action over objects.C 6 Chapter 1. Introduction

Constant Functors and Diagonals For an object c there is a constant functor ∆c: . This functor just maps ∈C A→C any object in the category into c and any arrow into the identity idc. For a small category I,A the constant functors define the so-called “diagonal” functor ∆ : [I, ]. This functor maps an object c into the functor ∆c. C→ C ∈C Given an arrow f :c c0, the natural transformation ∆f is defined to be the arrow f at each component.→

Evaluation Functor Given a functor F : I andanobjecti Iwe can evaluate F at i to obtain F (i) . This extends→C to a functor ∈ ∈C eval:[I, ] I , C × →C the evaluation functor. The action of this functor on arrows is defined as

F i F (i)

α f G(f) αi=αj F (f)    ◦ ◦ G j G(j).

Functoriality as Naturality A functor F : defines for a pair c, d amap C→D ∈C F  (c, d) c,d / F (c),F(d) C D sending an arrow f :c d into F (f):F(c) F(d). This mapping is indeed natural → → in c and d, in the sense that the family Fc,d c,d op is a natural transformation from ( , ): op Set to (F ( )h,F( i)) :∈Cop×C Set. As naturality can C C ×C → D C ×C → be verified at each component: for an arrow h:d d0 the diagram → Fc,d (c, d) / (F (c),F(d)) C D h F (h) ◦   ◦ F c,d0 / (c, d0) (F (c),F(d0)) C C commutes since for f :c d we have → F (h) F (f )=F(h f) ◦ ◦ by functoriality of F . Naturality in d follows by a similar argument. Thus functo- riality is expressed here as a naturality condition.

Partial Functors

Let F : be a bifunctor. For objects a, a0 there are partial functors a a0A×B→C ∈A f F ,F : . An arrow f :a a0 gives rise to a family F = F (f,b):F(a, b) B→C → h → F (a0,b) b . Now, for an arrow g :b b0 the square i ∈B → F f (b) a / a0 F (b)=F(a, b) F (b)=F(a0,b)

a F (g) Fa0(g)   / Fa(b)=F(a, b ) a0 0 0 f F (b0)=F(a0,b0) F (b0) 1.3. Functoriality and Naturality 7 commutes since F is a bifunctor. Thus the family F f is a natural transformation from F a to F a0 .

Curried Functors and the Yoneda Embedding ForafunctorG: I where I is a small category, the family of partial functors defines a higher-orderA× →C functor: λ(G)=λx.Gx : [I, ] A→ C the curried version of G. In particular for a small category C, the hom-functor C( , ):Cop C Set can be curried into a functor × → λ(C( , )):Cop [C, Set]. → This is called the contravariant Yoneda functor and denoted by op. From the composition of the hom-functor with the functor swapping argumentsY we obtain the covariant Yoneda functor :C [Cop, Set]. Y → This functor acts by mapping an object c C into C( ,c) and over arrows ∈ c C( ,c) / f (f)= f c C   Y h ◦ i ∈ d C( ,d) By definition is injective over objects. As a direct consequence of the Yoneda lemma, this functorY is full and faithful and then an embedding.

Duality Revisited The operation taking a category into op can be extended to an endofunctor over CAT. Indeed op defines actionsC for objects,C functors and natural transformations given in reality a 2-functor. It acts over categories as follows:

op C C α +3 / ks αop F G F op Gop  Ó  Ó op DD op op op op where αc :G (c) F (c)in corresponds to the arrow αc :F (c) G(c)in . Then this functor→ is contravariantD with respect to natural transformations→ only. C By definition of for objects c, d there is an isomorphism of sets ∈C (F (c),G(d)) = op(Gop(d),Fop(c)). (1.1) D ∼ D These expressions are functorial in all variables and furthermore the isomorphism is natural in those variables as well. For natural transformations α : H F and ⇒ β : G K and morphisms f :c0 c and g :d d0 the diagram ⇒ → →  op op op F (c),G(d) = G (d),F (c) D ∼ D op op op op K(g) βd F(f) αc H (f) αc G (g) β ◦ ◦ ◦ ◦ 0 ◦ ◦ ◦ ◦ d0     op op op H(c0),K(d0) = K (c0),H (d0) D ∼ D commutes. 8 Chapter 1. Introduction

1.4 Universal Properties and Representables

Universal constructions appear in category theory under different flavours: limits, adjoints, Kan extensions and so on. There are several ways in which we can ex- pressed the properties defining these constructions. These definitions, however, are special instances of the most abstract notion of universal arrow. For a functor F : and an object d ,auniversal arrow from d to F consists of a pair (f,cC→D)wheref:d F(c) is an∈D arrow in such that for any other → D arrow g :d F (c0) there exists a unique arrow g :c c0 in making the diagram → → C f / d B F (c) BB BB BB F (g) g B  F (c0) commute. In the setting of locally small categories the definition of universal arrow is equivalent to universal element (see chapter 2). A functor F : op Set is said to be representable if it is isomorphic to a hom-functor C → θ ( ,c)=F C ∼ or in other words there is an isomorphism

θx (x, c) = F (x) C ∼ natural in x. The pair (c, θ) is called the representation for F . A fundamental result in category theory is that a universal construction determines and is determined by a representation for a Set-valued functor. Consider as an example the categorical definition of product. Given two objects a, b in a category , their product is defined to be an object a b equipped with C × morphisms π1 :a b a and π2 :a b b. The universal condition is that for any other object c × with→ arrows f : c× →a and g : c b there exists a unique arrow m:c a b such∈C that the triangles→ in the diagram→ → × c f g m Ô   o / a a b b π1 × π2 commute. In other words for each c there is an isomorphism ∈C (c, a b) = (c, a) (c, b). C × ∼ C ×C The commutativity of the diagram above implies that this isomorphism is natural in c, i.e. that the product defines a representation for the functor

( ,a) ( ,b): op Set. C ×C C → The same result generalises for the case of limits. Among a collection of objects satisfying certain property in a category a selects the universal one. A property is described as a diagram in , i.e. a functor with a small category as domain. Formally an object satisfies theC property defined by D : I if it is the vertex of for D.Alimit for a diagram D :I is a representation→C →C ( , lim D) = [I, ](∆ ,D). (1.2) C I ∼ C ←− 1.5. The Calculus 9

By duality we can define a couniversal arrow from a functor F : to an object d . In this case the couniversal arrow is given by a pairC→D (f,c)where ∈D f:F(c) din such that for any other arrow g :F (c0) d there exists a unique → D → arrow g :c0 c for which the diagram → f / F (c) > d O || || F (g) || || g F (c0) commutes. Couniversal arrows from F to d are in one-to-one correspondence with universal arrows from d to F op. This follows by applying the 2-functor ( )op to the diagram above. Limits as such do not account for contravariance, not at least in the categorical language present above. There are cases of functors, the typical example being the evaluation functor [Pow95, Str02], which demand a unified treatment of multiple variance. Ends are specialR kind of limits for functor of the form G:Iop I ,the × →C end of G is written as x G(x, x). Although ends and limits coincide, the former supports a convenient algebraic manipulation of functors over which we based our calculus for categories. In particular results like the Yoneda lemma can be expressed by an end expression. The hom-sets of functor categories correspond to end formulæ as well. Let F, G:C be functors. Then there is an isomorphism →D R [C, ](F (x),G(x)) = (F (x),G(x)). D ∼ x D Chapter 3 is devoted to the presentation of universal properties from the perspective of ends and its dual form coends.

1.5 The Calculus 1.5.1 Syntax The categorical constructions above induce the language of the calculus. It basically extends the simply typed lambda calculus with expressions for hom-sets and new binders for ends and its dual coends. The types of the language denote locally small categories and a typing judgement of the form

Γ E : ` C is read as the expression E being functorial in its free variables occurring in the context Γ. Of course not all well-formed sequents result in functorial expressions. The typing rules of the calculus determine which are the legal expressions of the language. The rules for lambda abstraction and application are basically the ones inherited from the lambda calculus with types, but already the rule for typing hom-sets poses an interesting example: Γ E : Γ E : 1 ` 1 C 2 ` 2 C Γop, Γ (E ,E ):Set 1 2 `C 1 2 it defines a bifunctor which is contravariant in the first argument. The modality op Γ1 indicates that the types in Γ1 are replaced by its dual form. This rule captures the usual practice in the manipulation of hom-expressions in category theory. 10 Chapter 1. Introduction

One of the important results of representables functors is that they can carry extra parameters in a functorial manner, the so-called parametrised representability. One consequence is that the introduction of an end binder over some parameters does not disturb the functoriality over the ones remaining free: Γ,y:Iop,z:I E(y,z): ` C R Γ E(x, x): . ` x C One of the novelties is the presence of duality explicitly as a rule Γ E : ` D op op Γ E∗ : . ` D The operation on expressions ( )∗ turns limits and ends into their dual forms co- limits and coends. The interaction of contravariant functors (as the hom-expression above) and duality forces a non-standard notion of substitution. In chapter 5 we show that despite these new ingredients the proof system is still closed under sub- stitution. The definition of limits and ends as representations supports an equational rea- soning which extends the one provided by the lambda calculus. The syntactic judgement Γ E = E : ` 1 ∼ 2 C is read as “the expressions E1 and E2 are naturally isomorphic in the free variables in Γ”. For instance the definition of limit would give the rule Γ,x:I E(x): ` C Γ,z: op (z,lim E(x)) = [I, ](∆z,E(x)):Set. C `C I ∼ C ←− 1.5.2 Semantics Types in the language are interpreted as locally small categories, and expressions correspond to functors. In this setting contexts are understood as the categorical product of types occurring in them. This interpretation is consistent with the structural rules for the manipulation of variables. The meaning of an expression in the language is defined by a derivation. Thus a derivation . . δ Γ E : ` C denotes a functor from the category denoted by Γ into . The presence of structural rules and special rules forC duality results in that the same final sequent can be obtained through different derivations. This calls for a coherence result, i.e. we need to verify that different derivations lead to the same interpretation. In chapter 5 we show that the syntax is coherent with respect to the semantics up to natural isomorphism. A derivation of an isomorphism judgement is interpreted as a natural isomor- phism between the functors determined by the expressions. In this case the interpre- tation is not coherent with respect to the syntax. Thus an isomorphisms judgement only expresses the existence of one or more natural isomorphisms. The choice for structural rules and restrictions on their use play an important role in the different aspects of the calculus. In the last chapter we study how to extend the calculus from the locally small categories to an enriched setting. Indeed, the 2-category obtained by putting together -categories, -functors and -natural isomorphisms gives rise to an interpretationV of a substructuralV version of theV calculus. 1.6. Related Work and Applications 11

1.6 Related Work and Applications

In categorical logic we encounter the classical references to the work initiated by Lambek about the relation between λ-calculus and cartesian-closed categories [LS86]. Asperti and Longo [AL91] give a detailed introduction to categorical semantics, al- though they prefer to elaborate on the sequent-based calculi instead of natural deduction. Crole in the book Types for Categories [Cro93] and later Pitts [Pit00] and Jacobs [Jac99] extended the work by Lambek and Scott to study the categorical models behind higher-order logics. The study of the logics behind categorical constructions is more recent. An ex- ample is the work by Cockett and Seely [CS01] on a deductive system for categories with finite products and . In a related work although from a more math- ematical perspective Freyd [Fre02] presents a cartesian logic where the associated language comes from the logic of unique existential assertions. Rydeheard and Burstall [RB88] formalised various universal constructions in the functional language ML. This inspired many of the later attempts to find a mechani- sation of the categorical reasoning although the seem to follow a somewhat different tack that the approach taken in this dissertation. In particular Takeyama [Tak95] presents a computer checked language with the goal of supplying a categorical frame- work for type theory. In a similar development Huet and Sa¨ıbi [HS00] implement a formalisation of category theory where the main ingredient is the representation of hom-sets as setoids. Category theory supplies an adequate abstract language for denotational se- mantics within the scope of different paradigms in computer science. Domain the- ory [AJ94, AC98], for example, has been traditionally studied under a categorical perspective. Recently this approach has been extended to enriched categories of domains, an example is the work by Fiore [Fio96]. One of our motivations is the increasing use of category theory in denotational semantics, often as categories as domains, where universal properties like limits and ends, and functors preserving those properties have a useful consequence [Cat99]. This approach begun with the work by Winskel and Nielsen [WN95] on the formalisation of operations over seemingly different models for concurrency like transition systems, Petri nets and event structures as instance of the same categorical constructions. These models embody a categorical definition of bisimulation in terms of open maps. Joyal et al. [JNW96] showed that spans of open maps in the category of transition sys- tems corresponds to Milner-Park bisimulation. Cattani and Winskel [Cat99, CW] extended this work by proposing a systematic treatment of bisimulation for con- current process languages like higher-order CCS and π-calculus. In a related work categories have been used to bridge the gap between the operational and deno- tational world [Tur96, TP97, FPT99]. It is interesting that in these applications presheaf categories play a central role in the theory. Under a different perspective an algebraic approach to categories would help the task of mechanising the theory in a theorem prover. The last decade has seen an impressive growth in this area where several formal theories have been mechanised, regrettably there is no satisfactory implementation of category theory yet.

1.7 Synopsis

Chapters 2 and 3 We present the basic categorical background from the view- point of representables. In particular we study the implications of parametrised representability in different scenarios like limits and adjoints. The goal of these two chapters is not to rewrite what can be found in a good introductory book; rather to present the theory by emphasising the results which are relevant to the calculus 12 Chapter 1. Introduction as well as giving examples of the kind of categorical reasoning supported.

Chapter 4 In this chapter we present a characterisation of continuous functors which can be formalised in the calculus. This presentation gives a fresh approach to the verification of continuity, and we consider is one of the original contributions in this dissertation.

Chapter 5 This chapter and the following present the syntax, semantics and equational theory of the calculus. Chapter 5 is devoted to functoriality. The main results in this chapter are the admissibility of substitution and the “coherence” of the interpretation for functorial judgements.

Chapter 6 This chapter focuses on the rules for natural isomorphisms and their interpretations. We show how the definitions of colimits and coends can be derived from their dual limits or ends plus a simple rule for opposite categories. At the end of this chapter we propose a syntax for weighted limits.

Chapter 7 We study how to generalise the calculus to cover the 2-category of - enriched categories for a suitable locally small category . The calculus is reducedV to a substructural version of the original one where theV rules for weakening and contraction of contexts are not longer present. This reflects the gap open in the model between ends and weighed limits, where the latter gives a more general definition.

Chapter 8 In the last chapter we give the conclusions and elaborate on possible extensions of this work. Chapter 2

Representability

We review the basic concepts of category theory such as limits and adjunctions from the perspective of representable functors. In particular we study different instances of parametrised representability which will be later used to justify the semantics of the calculus. Despite the fact that most of the results in this chapter and the next one are part of the folklore in category theory in some occasions we sketch their proofs to show the kind of reasoning we aim to formalise in the calculus.

2.1 Universal Properties

The notion of universal arrows reduces to that of universal element when considering locally small categories.

Definition 2.1.1 (Universal Element) Given a functor G: Set,auniversal element of G isapair(c, x)wherec and x G(c), such thatC→ for any other pair ∈C ∈ (c0,y)wherey G(c0) there exists a unique arrow f :c c0 in with y = G(f)(x). ∈ → C Given a functor F : and d we can define a functor (d, F ( )) : Set. The condition thatC→Dh:d F (c)∈D is universal is equivalent to sayingD that− (C→c, h) is a universal element of (d,→ F ( )). Conversely, a universal element x G(c)for a functor G: Set canD be regarded− as an arrow x:1 G(c). Thus the∈ condition that the elementC→x is universal is equivalent to saying that→ x:1 G(c) is universal. A couniversal arrow corresponds to a universal element for a→ contravariant Set- valued functor. The notion of universal arrow can be defined as the initial object of the x F . This expresses the general notion of universality in terms of a particular one.↓ Similarly, a universal element for G : Set may be defined as the initial element of the categories of elements of G.C→ Of course we replace initial object by final object when talking about couniversality.

Definition 2.1.2 () A functor F : op Set is repre- sentable if for some c there exists a natural isomorphism C → ∈C θ ( ,c)=F. C ∼

The pair (c, θ)isarepresentation for F and εc = θc(idc) F (c) is called its counit. The dual definition: a functor G: Set is representable∈ if there exists an object d and a natural isomorphism C→ ∈C β (d, ) = G. C ∼

13 14 Chapter 2. Representability

In this case ηd = βd(idd) is called the unit of the representation. By abuse of the language we refer to a representation by mentioning only the first component of the pair assuming the natural isomorphism is understood from the context. In some occasions to simplify the notation we omit the subindices of counits and units. The Yoneda lemma provides a close connection between representable functors and universal elements.

Theorem 2.1.3 (Yoneda Lemma) Given a functor F : op Set the mapping C → α αc(idc) 7→ defines an isomorphism  [ op, Set] ( ,c),F =F(c) C C ∼ natural in c and F . The inverse of the mapping above sends an element x F (c)forsomec to the natural transformation xe : ( ,c) F whose component∈ at d is ∈C C ⇒ xed(f)=F(f)(x). In particular if a functor F : op Set has a representation (c, θ) then the C → counit εc F (c) is a universal element of F since εec is an isomorphism for each c. Conversely,∈ if a functor F : op Set has a universal element (c, x)thenF is representable since xe is by definitionC → a natural isomorphism. In this case for an element y F (d) we say that the unique f such that ∈ y = F (f)(x) is the mediating arrow defined by y.

Theorem 2.1.4 Let F : op Set be a functor. F is representable if and only if it has a universal element.C → Proof. It follows from the discussion above. The most relevant part of the proof for the rest of this work is that the counit of a representation is a universal element. 

We shall say that an object satisfies a universal property when it is a representa- tion for a Set-valued functor. The Set-valued functor defines the kind of elements the property describes. An immediate corollary of the Yoneda lemma is that the Yoneda functor is full and faithful, this gives the following fundamental result:

Proposition 2.1.5 Representations are unique up to isomorphism: if (a, α)and (b, β) are both representations for a functor F : op Set then a = b in . C → ∼ C Terminal objects give an example of universal construction. A terminal object in a category is such that for any object a there is only one arrow from a to> : C ∈C > (a, ) = 1. C > ∼ In other words, the constant contravariant functor ∆1: op Set is representable. Similarly as exemplified in the introduction the categoricalC product→ can be expressed as a representation where the counit is the pair of projections (π1,π2). By considering Set-valued bifunctors we can generalise the notion of repre- sentable functors to carry extra arguments. 2.2. Limits 15

Theorem 2.1.6 (Parametrised Representability) Let F : op Set be a bifunctor such that for every a there exists a representationA×B (G[a],θ→a)forthe partial functor F a : op Set.∈A Then there is a unique extension of the mapping a G[a] to a functorB G→: such that 7→ A→B a  θb b, G(a) = F (a, b) (2.1) B ∼ is natural in a and b op. ∈A ∈B Proof. In this proof as in other examples we omit the subindices to indicate the components of the natural transformations to simplify the notation. Given an arrow f :a a0 there is a diagram → ( ,G[a]) θa F a B ∼=

a 1 f a f (θ 0 )− F θ F (2.2) ◦ ◦  a ( ,G[a0]) θ 0 F a0 . B ∼= Since the Yoneda functor is full and faithful there must exist a unique arrow, say G(f), such that

a0 1 f a ( ,G(f)) = (θ )− F θ . B ◦ ◦ It is now routine to verify that this definition gives a functor. 

A concrete definition of G(f) above can be obtain by chasing idG[a] around the commuting diagram (2.2):     a0 1 a a0 1 G(f)= (θ )− F(f,G[a]) θ (id )= (θ )− F(f,G[a]) (ε ). (2.3) ◦ ◦ G[a] ◦ G[a] We now review the notions of limits and adjoints at the light of this result.

2.2 Limits

A limit for a digram D :I is given by a universal cone. A cone from an object →C c to a diagram D is a family of arrows γi : c D(i) i I such that for every f :∈Ci j in I the corresponding triangle h → i ∈ → h3 D(i) γhi hhh hhhh hVh c VVVV D(f) VVVV  γ V+ j D(j) commutes. This is equivalent to saying that the family γ is a natural transformation from the constant functor ∆c to D. Aconeε:∆l Dis universal or a limiting if given any other cone γ :∆c D there exists a unique⇒ arrow m:c l such that the diagram of natural transforma-⇒ tions →

_∆_m_/ ∆c ∆l

γ ε (2.4)   D id D ∼= 16 Chapter 2. Representability commutes, i.e. for every i I the triangle ∈ _ _m_ _/ c B l BB BB BB εi γi B  D(i) commutes. We say that ε is a limit for D. This definition can be given as a representation for a special Set-valued functor.

Definition 2.2.1 (Limit) A limit for a diagram D :I is a representation (l, θ) for the functor [I, ](∆ ,D): op Set. The counit of→C this representation C C → ε = θl(idl) [I, ](∆l, D) ∈ C is a limiting cone. From the discussion above, the elements of [I, ](∆c, D) are the cones from c to D. From Theorem 2.1.4 the counit ε of the representationC (l, θ) is a universal element. Then for γ [I, ](∆c, D) there exists a unique arrow m :c l in such that ∈ C → C γ =[I, ](∆m, D)(ε)=ε ∆m. C ◦ By abuse of the language we call limit the object part of the representation. For a given diagram D there might be several representations for the functor above. By Proposition 2.1.5 all those limits give representations where the objects are isomorphic. This allows us to talk about “the limit” of D meaning a special choice for a limiting cone whose vertex is written as limID. ←− 2.2.1 Completeness and Parameters Terminal objects are limits for the empty diagram and products are limits for dia- grams whose domain is a discrete two-object category. More complicated universal constructions are equalisers and pullbacks. Not all categories have limits for ev- ery diagram. Categories with all limits, called complete categories, are of special interest. The category Set is complete: given a diagram D :I Set our canonical choice for the limit of D shall be →

limID = xi i I xi D(i) and for all f :i jxj=D(f)xi, {h i ∈ | ∈ → } ←− where xi i I is a tuple indexed by the elements in I. The limiting cone is given by the projections.h i ∈

Proposition 2.2.2 (Limits with Parameters) Let G: I be a bifunctor such that for each b the induced diagram Gb :I hasB× a limit→C in . Then the mapping b lim Gb∈Buniquely extends to a functor →C C 7→ I ←− λx.lim Gx : . I B→C ←− Proof. For every b the limit of Gb determines a representation ∈B  θb  , lim Gb = [I, ] ∆ ,Gb . C I ∼ C ←− The result follows by applying Theorem 2.1.6 to the bifunctor  λx, y.[I, ] ∆y,Gx : op Set. C B×C → 2.2. Limits 17



From (2.3) we have a concrete understanding of the action of λx.lim Gx : I B→C over arrows: given f :b b0 in ←− → B    f b0 1 b f b0 1 f lim G = (θ )− [I, ] ∆lim G ,G (ε)=(θ )− G ε I ◦ C I ◦ ←− ←− b f where ε is the limiting cone (or counit) associated to limIG . Thus limIG is the ←b−0 ←− unique arrow defined by the universal property of limIG with respect to the cone Gf ε : ∆lim Gb Gb0 . In other words lim Gf is the←− unique mediating arrow such ◦ I ⇒ I that the diagram←− of natural transformations←−

∆lim Gf I b / b0 ∆limIG ←− ∆limIG ←− ←− ε  Gb ε0

Gf   id b0 b0 G ∼= G

b0 b0 commutes where ε0 : ∆lim G G is limiting. I ⇒ An important special←− case arises by taking =[I, ]andGto be the evaluation functor eval:[I, ] I where has all limitsB for IC-indexed diagrams. For every diagram D [I,C ]× there→C is a representationC ∈ C   , lim evalD = [I, ] ∆ , evalD . C I ∼ C ←− By the result above and since evalD = D there is a functor

λx.lim evalx = lim :[I, ] , I I C →C ←− ←− the limit functor, such that

(y,lim D) = [I, ](∆y,D) C I ∼ C ←− natural in y and D [I, ]. Given a natural transformation α : D D0 the ∈ C ⇒ arrow limIα is just the mediating arrow associated with the cone resulting from the composition←− of the limiting cone ε : ∆lim D D with α. Thus lim α is the unique I ⇒ I arrow making the diagram of natural← transformations− ←−

∆lim α I / ∆limID ←− ∆limID0 ←− ←− ε  (2.5) D ε0

α   D id D 0 ∼= 0 commute, where ε0 : ∆lim D0 D0 is limiting. I ⇒ As functors preserve←− isomorphisms a direct corollary of this result is that for diagrams D, D0 :I →C D=D0 lim D = lim D0. ∼ ⇒ I ∼ I ←− ←− 18 Chapter 2. Representability

Remark 2.2.3 The definition of the limit functor gives in reality a family of func- tors. A specific limit functor depends on the choice for the limit of each D [I, ]. The limit functors, however, are isomorphic and we can talk about “the limit∈ func-C tor” with respect to some particular choice for the representations. Sometimes it is of interest to consider only a [I, ] of diagrams. If all diagrams in have limits in , i.e. is -complete,K⊆ we canC define a limit functor K C C K lim : . I K→C In this case a limit for a diagram D←− is a representation for ∈K (∆ ,D): op Set K C → and parametrised representability works as before. The full subcategory induced by all the diagrams in [I, ] with limit in is denoted by diag[I, ]. C C C 2.2.2 Colimits A cone from a diagram D : I to an object c , sometimes call cocone, is a natural transformation from→CD to ∆c. A colimit∈C for D is a universal cone η : D ∆c in the sense that for any other cone γ : D ∆a there exists a unique mediating⇒ arrow m:c a such that the diagram of natural⇒ transformations → D id D ∼= η γ (2.6)   / ∆c ∆a ∆m commutes. This condition can be expressed as a representation for a covariant functor.

Definition 2.2.4 (Colimit) A colimit for a diagram D :I is a representation (c, θ) for the functor [I, ](D, ∆ ): Set. The counit of→C this representation D D→ θc(idc)=η [I, ](D, ∆) ∈ D is a colimiting cone. By abuse of the language we call the object c the colimit of D and write it as limID or colimID. −→By duality we can define initial objects, coproducts and more generally colimits in a category as simply being terminal objects, products and limits in op.In2- categorical termsC the property illustrated by (2.6) can be translated to theC universal property of limits by applying the functor ( )op: − DOop id DOop ∼= ηop γop

(∆c)op o (∆a)op (∆m)op

Remember that ( )op reverses the direction of natural transformations only! This makes ηop a universal− cone, i.e. a limit for Dop :Iop op. Categories with colimits for all diagrams are said→C to be cocomplete. The category Set is cocomplete: given a diagram D :I Set our choice for the colimit of D is →] colimID = D(i)/ ∼ i I ∈ 2.2. Limits 19

U U where is the least equivalence relation on i I D(i) i I D(i) such that ∼ ∈ × ∈ (i, x) (j, y) f:i jin I (D(f))x = y. U ∼ ⇔∃ → For (i, x) i I D(i)welet[(i, x)] denote the equivalence of containing (i, x). The∈ colimiting∈ cone is given by∼ the collection of injection functions∼ x [(i, x)] . 7→ ∼ By the dual version of Theorem 2.1.6 for a -cocomplete category there is a colimit functor K C colimI : K→C for a subcategory [I, ]. K⊆ C 2.2.3 Initial Functors A functor H : is called initial if for each c the corresponding comma category H c B→Cis non-empty and connected. In other∈C words for each c there exists at least one↓ object b and an arrow H(b) c; and for any two such arrows ∈B → f :H(b) c, g :H(b0) c there are arrows → → f1 / o f2 f3 / ... fn / ofn+1 b e1 e2 en b0 in and arrows in to form a B C H(f ) H(f ) H(f ) H(f ) H(f ) W 1 / o 2 3 / ... n / o n+1 H(b) WWWWH(e1) SS H(e2)E H(en) kk H(b0) WWWWW SSS EE yy kkk WWWW SSS E y kkk WWWWWSSS EE yy kkk f WWWWSSS EE yykkk g WWWSWS)+" |yukkk c.

Proposition 2.2.5 Let D : I J and F : J be diagrams. If D is initial then we have → →C [I, ](∆c, F D) = [J, ](∆c, F ) C ◦ ∼ C natural in c.

Proof. For every j J pick one arrow hj :D(i) j; this is possible by initiality of D.Foraconeα:∆∈c F Dand for every j →J there is an arrow ⇒ ◦ ∈

α F (hj ) c i /F (D(i)) /F (j).

Now, for an arrow g : j j0 by initiality of D there is a sequence of arrows in J → connecting hj :D(i0) j0 with g hj such that they form a commutative diagram 0 → ◦ D(f1)/ Do (f2) D(f3)/ ...D(fn)/ Do (fn+1) D(i) VVVV D(e1) R D(e2) D(en) l D(i0) VVVV RRR BB { ll VVVV RRR BB {{ lll VVVV RRR BB {{ lll VVVVRRR B { lll g hj VVVRRB! }{{ll hj ◦ VVVR+( vll 0 j0. By applying F to this diagram and since α is a cone we have that the diagram

F (hj ) F (D(i)) / F (j) m6 αimm mmm c QQQ F (g) QQQ α (  i0 / F (D(i0)) F (j0) F (h ) j0 20 Chapter 2. Representability

commutes, and then the family αb = F (hj ) αi :c F (j) j J is a cone. Conversely,foraconeβ:∆c Fh we just◦ pre-compose→ i with∈ D to obtain a cone βD :∆c F D. We now check⇒ this is an isomorphism of sets: ⇒ ◦ For α :∆c F Dwe have • ⇒ ◦

(αDb )i = αb = F (h ) αi . D(i) D(i) ◦ 0

Notice that i0 might be different to i,andthenF(hD(i)) is not necessarily the identity but by initiality of D and since α is a cone the diagram

F (D(i )) 7 0 SF (h ) αi nn SS D(i) nn0 SSS) nnn c PP F (D(i)) PPP kk5 PP' kkkk αi F (id ) F (D(i)) D(i)

commutes, and then F (h ) αi = αi. D(i) ◦ 0 For β :∆c F we have • ⇒ d (βD)j = F(hj) β by definition of (b), ◦ D(i) = βj since β is a cone.

Now we can conclude βDd = β.

Naturality in c follows by simply verifying that for an arrow f :c c0 we have that → \ (α ∆f ) = F (hj ) αi f =(αb ∆f)j ◦ j ◦ ◦ ◦ for any j J.  ∈ Thus we can conclude the important result of this section:

Proposition 2.2.6 Let D : I J and F : J be diagrams. If D is initial and the limit for F D exists then→ the limit of F →Cexists and there is an isomorphism ◦ lim F = lim (F D). I ∼ I ◦ ←− ←− Proof. By the definition of limit and the proposition above

(c, lim F D) = [I, ](∆c, F D) = [J, ](∆c, F ) C I ◦ ∼ C ◦ ∼ C ←− natural in c. Then by uniqueness of universal properties

lim F = lim (F D). I ∼ I ◦ ←− ←− 

We shall use this result when showing the relation between the different flavours of universality in the next chapter. There we see an example of initial functors given by the defined by a special . In general we say that a subcategory of is initial when the inclusion functor is initial. For a simple non-initial categoryC considerD a discrete subcategory of a non-discrete cate- gory, clearly in this case the inclusion functor is not initial since the corresponding comma category is empty. 2.3. Adjunctions 21

2.2.4 Preservation of Limits Informally, a functor F : is said to preserve products if for c, d we have that C→D ∈C F (c d) = F (c) F (d). × ∼ × Despite this isomorphism ensures the object F (c d) indeed gives rise to a product it says nothing about the projections. If F does× not map the projections of c d into the projections for F (c d) the isomorphism above would not be natural.× Preservation of product in the× categorical sense requires that the projections are preserved as well.

Definition 2.2.7 (Preservation of Limits) Let D : I be a diagram. A functor G: preserves a limiting cone ε :∆c Dif the→C composition C→D ⇒ Gε :∆G(c) G D ⇒ ◦ is a limiting cone. A functor G : preserves any cone in but the definition above requires more: limiting conesC→D should be mapped into limitingC cones. We say that a functor is continuous when it preserves all limiting cones.

Proposition 2.2.8 For a category the hom-functor (a, ): Set is contin- uous. C C C→ Proof. Let D : I be a diagram and ε :∆c Da limiting cone. By applying (a, ) we obtain→C the cone ⇒ C

εi i I :∆ (a, c) (a, D( )). h ◦ i ∈ C ⇒C It is routine to verify that since ε is limiting and from our choice of limits in Set this is indeed a limiting cone. 

This proposition allows us to express a limit in an arbitrary category as a limit in Set since for a diagram D :I C we have C → (c, lim D) = lim (c, D( )). (2.7) C I ∼ IC ←− ←− A colimit in , however, corresponds to a limit in Set: C op op (colimIF, c) = (c, lim F ) by duality, C ∼ C Iop = lim ←op−(c, F op( )) since hom-functors preserve limits, ∼ Iop C = lim←− (F ( ),c) by duality (1.1). ∼ Iop C ←− Proving preservation of limits by closely following the definition above requires a concrete reasoning in terms of diagrams and limiting cones. This can be rather tedious and involve a fair amount of bookkeeping, something that in category theory is traditionally left implicit. In chapter 4 we study in which situations a more equa- tional approach can be taken when checking whether a functor preserves universal properties.

2.3 Adjunctions

The symmetry between universal and couniversal properties is captured by the notion of adjunction. 22 Chapter 2. Representability

Definition 2.3.1 (Adjunction) Let

F / o C G D be functors. An adjunction in which F is the left adjoint and G is the right adjoint consists of an isomorphism

ϕc,d (F (c),d) = (c, G(d)) (2.8) D ∼ C natural in c, d. When such a natural isomorphism exists we write ϕ : F G. a The bijection of arrows defined by an adjunction is sometimes represented as

f g F (c) /d c /G(d) and f g / c /G(d) F (c) d and then f = f and g = g. Notice that by naturality of the isomorphism (2.8) for h:c0 c in and k :d d0 in we have the following identities → C → D F (h) / f / k / h / g / G(k) / F (c0) F (c) d d0 c0 c G(d) G(d0) and h / f / G(k) / F (h) / g / k / c0 c G(d) G(d0) F (c0) F (c) d d0. The isomorphism (2.8) admits two readings: as a covariant representation by fixing c op or as a contravariant representation by fixing d . From∈C Theorem 2.1.6, to give a right adjoint to F : is∈D equivalent to giving for each d a representation C→D ∈D θd ( ,G[d]) = (F ( ),d). (2.9) C ∼ D − The mapping d G[d] induces a unique (up to isomorphism) functor G : such that 7→ D→C d θc (c, G(d)) = (F (c),d) C ∼ D natural in c, d. For every d the counit ε for the representation (2.9) is an arrow from ∈D G[d] F (G(d)) to d –asGis understood from the context we henceforth write εd instead of εG[d] when referring to the counit of an adjunction. From the definition of counit we have ε F (G(d)) d /d

idG(d) G(d) /G(d). By (2.3) from the proof of Theorem 2.1.6 we have that the action of the induced right adjoint G on g :d d0 is defined to be →  d0 1 d0 1 G(g)= (θ )− (F(G[d]),g) (εd)=(θ )− (g εd) ◦D ◦ that can be expressed as

G(g) / G(d) G(d0)

εd / g / F (G(d)) d d0. 2.3. Adjunctions 23

By universality of εd0 we have  g εd = F (G(g)),d0 (εd )=εd F(G(g)). ◦ D 0 0 ◦ Then the diagram εd / F (G(d)) d

F (G(g)) g   / F (G(d0)) ε d0 d0 commutes. Therefore the family of counits εd : F (G(d)) d d is a natural transformation from F G to the identity functor.h → i ∈D Counits are universal◦ elements, but from the discussion at the beginning of section 2.1 in this special case they can be regarded as universal arrows as well. Thus G(g) is the unique arrow from G(d)toG(d0) which corresponds to

g εd :F (G(d)) d0 ◦ → under the isomorphism defined by the adjunction. Dually, to give a left adjoint to a functor G : is equivalent to giving for each c a representation D→C ∈C ρc (F [c], ) = (c, G( )). D ∼ C

In this case the unit ηF [c] of the covariant representation is an arrow from c to G(F (c)) – we drop F and write ηc instead of ηF [c]. By definition of unit we have

η c c /G(F (c))

idF (c) F (c) /F (c) and for an arrow f :c c0 → F (f) / F (c) F (c0)

f η / c0 / c c0 G(F (c0)).

The family ηc : c G(F (c)) c is a natural transformation from the identity functor to Gh F . By→ Propositioni ∈C 2.1.5 we can conclude that left and right adjoints are unique up◦ to natural isomorphism. Left and right adjoint can carry extra parameters. It follows below the result for the left adjoint; there is of course a dual result for right adjoints.

Proposition 2.3.2 (Adjunction with Parameters) Let F : be a C×A→D bifunctor such that for each a the induced partial functor Fa : has a right adjoint Ga : via the∈A isomorphism C→D D→C a ϕc,d a (Fa(c),d) = (c, G (d)) D ∼ C natural in c and d. Then there is a unique extension of the mapping (a, d) Ga(d) to a bifunctor G: op such that 7→ A ×D→C a ϕc,d (F (c, a),d) = (c, G(a, d)) (2.10) D ∼ C natural in c, d and a. 24 Chapter 2. Representability

Proof. For fixed d and a there is a representation ∈D ∈A a 1 (ϕ )− a ( ,G (d)) = (Fa( ),d). C ∼ D Then from Theorem 2.1.6 applied to the Set-valued functor  op op λx, y, z. Fx(z),y : Set D A ×D×C → the mapping (a, d) Ga(d) uniquely extends to a bifunctor G: op where G(a, y)=Ga(y). 7→ A ×D →C 

op The action of the functor G : over arrows f : a0 a in and A ×D → C → A g :d d0 in is concretely given by → D   G(f,g)= ϕa0 F(G(a, d),f),g (εa)=ϕa0 g εa F(G(a, d),f) ◦D d ◦ d◦

a a0 a a0 where ε and ε are the counits defined by Fa G and Fa0 G respectively. This can be expressed as a a

G(f,g)/ G(a, d) G(a0,d0) (2.11) εa F(G(a,d),f) / d / g / F(G(a, d),a0) F (G(a, d),a) d d0.

2.3.1 Examples of Adjunctions Quoting Mac Lane: “Adjunctions arise everywhere”. It is not our intention here to enumerate examples of adjunctions. Instead we review some of the notions seen already and introduce exponentials as special case of adjunctions. Let be a . The limit functor lim :[I, ] forasmall C I C →C category I is such that ←− (c, lim D) = [I, ](∆c, D) C I ∼ C ←− natural in c and D [I, ]. Then the limit functor is a right adjoint to the diagonal functor where the counit∈ C is given by the collection of limiting cones and the unit at component c is the unique arrow from c to limI∆c. Similarly in a cocomplete category a colimit functor is a left adjoint to the←− diagonal functor. As a special case, a category has all binary products if the diagonal functor ∆ : 2 has right adjoint (whereA 2 is the with two objects), i.e. →A (a, lim D) = [2, ](∆a, D) A I ∼ C natural in a and D. The diagram←− D is a tuple selecting two objects in .The limit functor is in this case the product functor : . In aA similar way a terminal object can be given as a right adjoint× ofA×A→A the diagonal constant in 1. A category with all finite products, i.e. binary products and terminal object, is called a cartesian category. Some authors add to this definition the existence of equalisers, i.e. all finite limits [FS90, Joh02]. Given a cartesian category andanobjectb ,wesaybis exponentiable if there is a right adjoint to the partialC functor b∈C: ,i.e. an isomorphism × C→C

λa,b (a b, c) = (a, [b, c]) (2.12) C × ∼ C natural in a and c where [b, ]: is a functor. The object [b, c] is called the exponential. The counit of this adjunctionC→C is the evaluation morphism

b eval = εc :[b, c] b c c × → 2.3. Adjunctions 25 and the unit is given by ηa :a [b, (a b)]. → × By Proposition 2.3.2, if for every b we have the adjunction above, then the mapping b [b, ] uniquely extends∈C to a bifunctor 7→ [ , ]: op . C ×C→C

The action of [ ,c]overg:b0 bis defined as (see (2.11)) → [g,c] / [b, c] [b0,c] (2.13) [b,c] g evalb × / c / [b, c] b0 [b, c] b c. × × In this case the category is said to be cartesian closed. C Notation 2.3.3 In the special case of Set we have

Set(X Y,Z) = Set(X, Set(Y,Z)) × ∼ natural in X, Y, Z. We henceforth write [Y,Z]forSet(Y,Z). The category of locally small categories CAT is a cartesian category since prod- ucts are defined for every pair of categories where the empty product (or terminal object) is given by the singleton category. CAT is not cartesian closed, though, as functor categories are not always defined for arbitrary locally small categories. Exponentials exists, however, if the domain is a small category. Let I, J be a small categories. A bifunctor F :I J can be “curried” into a functor λ(F ):I [J, ]. This functor maps i I into× the→C partial functor F i :J , → C ∈ f →C and an arrow f :i i0 in I into the family F (f, )=F which from the discussion on partial functors→ in 1.3 is a natural transformation. This construction suggest§ an adjunction, one which falls outside the universe of locally small categories. The evaluation functor eval :[I, ] I is the counit of the “adjunction” C × →C λ CAT(I J, ) = CAT(I, [J, ]). (2.14) × C ∼ C From the result on counits and adjunctions above we have, as expected, that for F :I J × →C F =eval (λ(F ) J). ◦ ×

The exponentials which exists in CAT are important to our development. Ex- ponentials in a cartesian category essentially correspond to the arrow type in the lambda calculus [LS86,Tay99,Joh02]. Although in this case as CAT is not cartesian closed we shall need to restrict the introduction of the arrow type in the logic to the cases where the domain is small. 26 Chapter 2. Representability Chapter 3

Ends and Coends

As pointed by Street [Str02] category theory officially began with the definition of naturality. There are situations, however, where a more general notion of “natu- rality” is required as for example in the evaluation morphism for cartesian closed categories. Kelly [Kel65] first identified the so-called extraordinary natural trans- formations in the development of theory. This notion was later generalised by Dubuc and Street [DS70] to define the dinatural transformations. The notion of end arises as universal dinatural transformations of a special form. In the setting of locally small categories ends and limits coincide. Ends, however, support an algebraic manipulation of universal properties which lays the founda- tions for a formal language and logic for categories. In the first part of this chapter we introduce ends and its properties. In the second part we concentrate on presheaf categories and weighted limits giving a different approach to universality where the relevance of representable functors is made explicit through the notion of weight.

3.1 Dinatural Transformations

A family of evaluation morphisms in a cartesian C evalb :[b, c] b c (3.1) c × → is natural in c since it is the counit of b [b, ]. The expression [b, c] b is functorial in b as well. In fact we have a multivariance× a bifunctor: × [ ,c] : op . × C ×C→C Kelly [Kel65] identified the sense in which the family (3.1) can be considered natural in b calling the new notion “extraordinary naturality”. op For a multivariance functor F : a family αa : F (a, a) c a for A ×A→C h → i ∈A some c is natural in this sense if for every arrow f :a a0 the “wedge” ∈C → F9 (a0,aF0) ss FF F(a0,f)ss Fα ss FFa0 sss FF s F" F(a0,a)K x< c KK xx KKK xx KKK xx F (f,a) K% xx αa F(a, a)

b commutes. We can check evalc b satisfies this condition: for an arrow g :b b0 in h i ∈B → C

27 28 Chapter 3. Ends and Coends

[g,c] b evalb × / c / [b0,c] b [b, c] b c × × [g,c] // [b0,c] [b, c] b [b0,c] g eval 0 × / c / [b0,c] b [b0,c] b0 c, × × b where the first step follows from universality of evalc and the second by definition of [g,c]. Hence

b b0 eval ([g,c] b)=eval ([b0,c] g). c ◦ × c ◦ × Dubuc and Street [DS70] generalised the extraordinary naturality to define a special notion of transformation between functors with multivariance:

Definition 3.1.1 Let F, G : op be functors. A dinatural transformation C ×C →D α : F ¨ G consists of a family αa : F (a, a) G(a, a) a of arrows in such that for every→ arrow f :a b in theh diagram → i ∈C D → C α F (a, a) a / G(a, a) t: JJ tt JJ F (f,at)t JGJ(a,f) tt JJ tt J$ F (b, a) G(a, b) JJ t: JJ tt JJ tt JJ tt F(b,f) J$ tt G(f,b) F (b, b) / G(b, b) αb commutes.

Every ordinary natural transformation gives rise to a dinatural transformation. Given the natural transformation

F ' op β 7 C ×C  D G then the family of arrows βa,a :F (a, a) G(a, a) a is a dinatural transformation since for an arrow f :a hb there is a diagram→ i ∈C →

βa,a F (a, a) / G(a, a) t: t: JJ tt tt JJ F (f,at)t G(f,at)t JGJ(a,f) tt (1) tt JJ tt tt J$ βb,a / F (b, a) G(b, a) (3) G(a, b) JJ JJ t: JJ JJ tt JJ JJ tt JJ (2) JJ tt F(b,f) J$ G(b,f) J$ tt G(f,b) F (b, b) / G(b, b) βb,b where

(1) commutes since it is the naturality square associated with (f,ida),

(2) commutes since it is the naturality square associated with (idb,f), and

(3) commutes since G is a bifunctor, 3.1. Dinatural Transformations 29 and then the outermost hexagon commutes as well. As with natural transformations, dinaturality can be verified at each component independently. Let H, K : op op be functors. A family A ×A×B ×B→C

αa,b :H(a, a, b, b) K(a, a, b, b) a ,b h → i ∈A ∈B is dinatural if and only if the induced families

a,a a,a αa, = αa,b b from H to K for each a ,and h i ∈B ∈A

α ,b = αa,b a from Hb,b to Kb,b for each b h i ∈A ∈B are dinatural. This follows by considering the diagram

0 αa,b / H5 (a, a, b, b) K(a, a, b, b)S kkk SSSS kkkk SS) H5 (a0,a,b,bS) (1) K5 (a, a0,b,bR) lll SSSS kkk RRRR llll SS) kkkk RR) / H(a0,a,b0,b) H(a0,a0,b,b) K(a0,a0,b,b) K(a, a0,b,b0) RR k5 αa ,b SS l5 > RRR kk 0 SSS ll RR) kkkk SS) llll H(a0,a0,b0,bS) (2) K5(a0,a0,b,b0) SSSS kkk SS) kkkk . / H(a0,a0,b0,b0) α K(a0,a0,b0,b0) a0,b0 / / for arrows a a0 in and b b0 in . To simplify the diagram we just write a,a A B H (b, b)asH(a, a, b, b) and so on. The hexagon (1) commutes since αa,b a is a h i dinatural family, similarly the hexagon (2) commutes since αa0,b b is dinatural. The rest of the internal diagrams commute since H, K are functorsh ofi multiple variables. The most remarkable aspect of dinatural transformations is the failure of com- position. In general the attempt of merging two hexagons componentwise is fruitless (see 3.1.3). Therefore, we cannot regard dinatural transformation as arrows in a category.§ The situation, however, is not so negative since dinatural transformations do compose with natural transformations. Given α : F 0 F and β : F ¨ G (assume functors of the right type), the outermost hexagon in ⇒ →

αa,a β F (a, a) / F (a, a) a / G(a, a) w; 0 x< GG ww x G F 0(f,a)ww F (f,a)xx GG(a,f) ww (1) xx GG ww xx G# αb,a / F (b, a) F (b, a) (3) G(a, b) 0 GG F ; GG FF ww GG FF ww GG (2) FF ww F 0(b,f) G# F(b,f) F" ww G(f,b) / / F 0(b, b) F (b, b) G(b, b) . αb,b βb commutes for f :a b since → (1) and (2) commute from naturality of α,and

(3) commutes from dinaturality of β.

Similarly we can compose a natural transformation on the right. This composition gives rise to the bifunctor:  Dinat , :[ op , ]op [ op , ] Set C ×C D × C ×C D → 30 Chapter 3. Ends and Coends acting on functors and natural transformations as  FGKS Dinat F, G  η ϕ Dinat η,ϕ =ϕ η    ◦−◦ H K Dinat H, K .

3.1.1 Dinaturality generalises naturality A functor F : op is dummy in its first argument if there exists a functor F : suchC that×CF →Dis the composition 0 C→D π F op 2 / 0 / C ×C C D op where π2 : is the projection to the second argument. Analogously, we can defineC “dummy”×C →C in the second argument. Let F, G: op be functors dummy in their first argument and α : F ¨ G a dinatural transformation.C ×C →D Then for any f :a b in the diagram → → C αb / F (b, b)=F (b) G(b, b)=G (id ) l6 0 0RRRb llll RR F(b,fl )=F0(f) G(f,b)=GR0R(Rb) llll RR( F (b, a)=F (a) G(a, b)=G (b) 0RRR l6 0 RR llll F (f,a)=FR0R(Ra) G(a,fl )=G0(f) RR( llll / F(a, a)=F (ida) G(a, a)=G (a) 0 αa 0 commutes. Hence the diagram

αb / F0(O b) G0O(b)

F0(f) G0(f)

αa / F0(a) G0(a) commutes and α is a natural transformation from F0 to G0.

3.1.2 Wedges A special case of a dinatural transformation arises when one of the functors is constant. For instance a dinatural transformation θ :∆c¨Gis given by a family → θa :c G(a, a) a such that given a morphism f :a b the diagram h → i ∈A →

G< (a, a)J zz JJ θa z JJG(a,f) zz JJ zz JJ zz $ c D G(a, b) DD t: D tt DD tt DD tt θb D" tt G(b,f) G(b, b) commutes. This corresponds to the definition of extraordinary naturality above. 3.1. Dinatural Transformations 31

3.1.3 Examples Identities Cartesian close categories give another example of dinatural family. Let be a cartesian closed category. Take the constant functor ∆ where is the terminalC > > object of . The family uc : [c, c] c where uc is defined under the adjunc- tion (2.12)C as h >→ i u c /[c, c] > π c 2 /c >× is dinatural in c.Forf:c c0we need to verify the “wedge” condition, i.e. that the diagram → [= c, c]G { GG u {{ G[c,f] c { GG {{ GG {{ # C [; c, c0] > CC ww CC ww CC ww uc C w 0 ! w [f,c0] [c0,c0] commutes. This follows from

u [f,c0] c0 / / [c0,c0] [c, c0] > c0 u c [c0,c0] f eval c0 × / × / c0 / c [c0,c0] c [c0,c0] c0 r86 c ::KK p8 rr 0 >× :KK × pp (2) × r : K f uc c0 p r : >×KK 0×pp rr : KK (1) ppp rr : K p π2rr :: % p rr : rr π2 : c0 rr ::>× rr f : rr : (3) rr :: rr  rr c

uc / [c,f] / [c, c] [c, c0] > where first bar corresponds to (2.13) plus naturality, and (1) commutes since the product gives a bifunctor, • (2) by definition of uc and universality of eval,and • 0 (3) by the universal property of the product. • The last bar follows from the definition of uc and naturality. Hence [f,c0] uc = ◦ 0 [c, f] uc. The arrow uc is sometimes referred as “the name” of idc, in the special ◦ case of Set the arrow uX selects the identity from [X, X]=Set(X, X).

Dinaturals for Fixed-Point Operators [BFSS90, Mul90, Sim93] Consider a cartesian closed category where every set (x, y) comes equipped with a partial-order relation and for everyCc, d, e the compositionC ∈C / (d, e) (c, d) ◦ (c, e) C ×C C is monotonic. The elements ( ,c) are called the “global elements” of c and are interpreted as being the elementC > of a partially-ordered set. We also require the 32 Chapter 3. Ends and Coends functor ( , ) to be faithful. In this way the category can be concretely regarded as a fullC cartesian> closed subcategory of the categoryCPoset of partial-order sets and monotone functions. A fix-dinatural in is a family of arrows C Yd :[d, d] d → dinatural in d. The right-hand side functor is dummy on the contravariant argu- ment. Thus for an arrow f :d e the hexagon → Yd / [< d, d] d ; y ;; [f,d] yy ; yy ;f; yy ; y ; [e, d] A e (3.2) EE Ó EE ÓÓ EE ÓÓ EE Ó id [e,f] " ÓÓ [e, e] / e Ye commutes. For a global element

g /[e, d] > g / e=e d >× ∼ the commutativity of (3.2) can be rephrased by using a set-theoretic notation as

f (Yd(f g)) = Ye(g f). ◦ ◦ By taking e = d and g = idd we have

f (Yd(f )) = Yd(f) and thus Yd(f) (or more abstractly the global element Yd f) is a fixed point for f. ◦ An Example of Non-composition of Dinaturals Identities and fix-dinaturals give an example of dinatural transformations whose composition does not result in a dinatural transformation. Indeed, if the family Yd ud d in a category is dinatural then is trivial in the sense the set (c, c0) h ◦ i C C C is a singleton for any c, c0 . To explain this consider the diagram defined by the arrow f :d e in ∈C → C Y 0 [d, d] d / ud < E d < y E << [f,d] yy EE[d,f] < yy EE EE yy ÒÒ EE yy ÒÒ EE yy ÒÒ [e,f] " y [f,e] ÒÒ id ue / [e, e] / e. Ye The commutativity of the outermost hexagon can be expressed as

f (Yd(idd)) = Ye(ide).

If we take d = we have that any f : eis equal to Ye(ide), hence there is > >→ a unique global element for every e . In particular for any pair c, c0 there is a ∈C unique global element for [c, c0] which in a cartesian closed category is equivalent to having a unique mapping from c to c0. 3.2. Ends 33

Some Applications There are many examples in the literature where multivariant functorial expressions give rise to dinatural families. One example of dinatural family is given by traced monoidal categories introduced by Joyal, Street and Verity [JSV96]. In this setting a trace is a family of functions

u tx,y (x u, y u) / (x, y) C ⊗ ⊗ C natural in x, y and dinatural in u plus some axioms for a suitable tensor bifunctor u . From a computer science viewpoint the arrow tx,y(f) should be thought as⊗ a feedback along u giving a categorical interpretation to cyclic data structures. Indeed, Hyland and Hasegawa [Has97, Has02] independently observed a bijective correspondence between fixpoint operators and traces with finite products. An interesting example of the application of dinatural transformations in com- puter science is the work by Bainbridge et al. on models for parametric polymor- phism [BFSS90]. The key observation is that naturality fails to capture polymor- phisms in the presence of function spaces due to the occurrence of arguments in contravariant position. Then, dinaturality comes to the rescue. Blute [Blu91] in his PhD dissertation refines this work establishing connections with linear logic and deductive systems in general. Mulry [Mul90] first showed that the least-fixed-point operator is a dinatural transformation. Then Simpson [Sim93] established the necessary conditions on a subcategory of CPO, complete partial orders and continuous functions, for which the property of dinaturality completely characterises the least-fixed-point operator. This is of interest since it equationally determines the fixed-point operator in a purely categorical setting. For more examples of dinatural transformations arising in computer science refer to [Sco00].

3.2 Ends

An end for a multivariant diagram F :Iop I is given by a universal wedge for F , dinatural transformations allow us to× present→D this notions as a representation.

Definition 3.2.1 (End) An end for F : Iop I is a representation (e, θ)for the functor Dinat ∆ ,F : op Set. The× counit→D of this representation is a universal wedge ε :∆e¨F. D → → More concretely for any wedge γ :∆d¨F there exists a unique morphism h : d e such that for f :a b in I the triangles→ in → → 2 F (b, b) < JJ γb zz J z JJF (f,b) zz JJ zz εb JJ zz $ _ _ _h_ _ _/ d e D F(a, b) DD t: DD tt Dεa tt DD tt D" tt F (a,f) γa , F (a, a) commute. In other words, h is the unique arrow such that

γ = ε ∆h ◦ 34 Chapter 3. Ends and Coends where the right-hand side refers to the composition of the natural transformation ∆h with the dinatural transformation ε.1 As usual byR abuse of the language we call the object e the “end of F ” and is written as x F (x, x). The reasons for this notation are made explicit by exploring the properties of ends like point-wise computation and Fubini theorem. As limits or any other universal constructions there are special cases of the parametricity results for ends. Thus given a category with enough ends we can C Rdefine the “end functor” mapping a diagram F [Iop I, ] intoR an end object ∈ × D F (x, x). For a natural transformation α : F G the expression αx,x denotes x ⇒ x theR unique arrow defined by the wedge α ε where ε is the universal wedge associated ◦ to x F (x, x). By the definition of end as a representation Remark 2.2.3 applies to end functors as well.

3.2.1 Limits are Ends A diagram D : I gives rise to a multivariant diagram D : Iop I where 0 →C × →C the first argument is dummy. For c a natural transformations from ∆x to D0 uniquely corresponds to a dinatural∈C transformation from ∆x to D and then  [I, ](∆x, D )=Dinat ∆x, D . D 0 Hence, θ  (∆x, lim D ) = [I, ](∆x, D )=Dinat ∆x, D D I 0 ∼ D 0 ←−  natural inRx, i.e. (limIF0,θ) is a representationR for Dinat ∆ ,F and consequently lim F F (x, x←).− This justifies writing D (x) for lim D , the notation we shall I 0 ∼= x x 0 I 0 use←− later in the formal language. ←−

3.2.2 Ends are Limits Perhaps less intuitive at a first glance is that ends are limits. Let F : Iop I be a diagram whose end is given by the representation × →D

R θ  ( , F (x, x)) = Dinat ∆ ,F . D x ∼ op We construct a category I§ and a functor d§ :I§ I I such that → × R x F (x, x) = limI (F d§). ∼ § ◦ ←−

The category I§ is built from I as follows:

the objects of I§ are the objects and arrows of I,and •

the arrows of I§ are the identities and for every f :a b in I the arrows • → a UUUU UUUU UUU* jjj4 f jjjj jjjj b.

1Notice that this equation cannot be expressed as a commutative diagram of functors and natural transformations as in 2.4 for limits. 3.2. Ends 35

Observe that the only possible composition in I§ is with identities. Now, we define op the functor d§ :I§ I I acting on objects and arrows as → × a SS V SS (a, a) VVV a,f SSS V(VVV) SSSS VVV+ ) d§ / kk5 f h3 (a, b) kkk hhhh kkkk hhhh kk h f,b b (b, b) . ( )  The cones in [I§, ](∆x, F d§) are exactly the wedges in Dinat ∆x, F and hence D ◦ R θ  ( , F (x, x)) = Dinat ∆ ,F =[I§, ](∆ ,F d§) . D x ∼ D ◦ R Therefore x F (x, x) is a limit for F d§. As a consequence of these two results we can deduce that if has all limits then◦ has all ends and vice versa. We can also write the equationD (2.7) for ends as D R R (d, F (x, x)) = (d, F (x, x)). (3.3) D x ∼ x D 3.2.3 Ends in Set As Set is complete all multivariant Set-valued diagrams have ends. From the choice for limits in Set and the result linking the two notions we can deduce our choice for ends in Set. op For a multivariant functor F :I I Set there is a functor F d§ :I§ Set. × → ◦ → The limit of F d§ is given by the set ◦ I limI(F d§)= xa a I xa (F d§)(a) and for all u:a b in § xb =(F d§)(u)(xa) ◦ {h i ∈ § | ∈ ◦ → ◦ } ←− = xi i I xi F (i, i) and for all f :i j in I F (i, f)(xi)=F(f,j)(xj ) ∼ {h i ∈ | ∈ → } where the projections are the universal cone.

3.2.4 (Di)Naturality Formula Let I be a small category and a locally small category. For diagrams F, G:I D →D consider the family ρx :[I, ](F, G) (F(x),G(x)) x where ρx maps a natural h D →D i ∈D transformation α : F G into the component αx : F (x) G(x). For an arrow f :x y the diagram ⇒ → → (F (x),G(x))  Dnn6 QQQ nn QQ F (x),G(f) ρxnn DQQQ nnn QQQ nnn QQ( I [ , ](F, GP) (F6 (x),G(y)) D PPP mDmm PPP mmm PPP mmm  ρy PP mm ' m F(f),G(y) D F (y),G(y) D commutes since for α : F G ⇒

G(f) αx = αy F (f). ◦ ◦

Thus the family ρx x defines a wedge for h i  F ( ),G( ) :Iop I Set. D × → 36 Chapter 3. Ends and Coends

Moreover from our choice of ends in Set this is an end for this functor(where every natural transformations is interpreted as a tuple of components). Then there is an isomorphism R  [I, ](F, G) = F(x),G(x) . (3.4) D ∼ x D Furthermore as a consequence of parametrised representability if is complete enough the expression above gives rise to a functor D [I, ]( , ):[I, ]op [I, ] Set D D × D → and the isomorphism above is natural in F, G. Henceforth the isomorphism (3.4) is referred as the “naturality formula”. In a similar way dinaturalities can be regarded as ends. For multivariant functors H, K :Iop I the set Dinat H, K is an end for × →D  H( , ),K( , ) :Iop I Set D × → and thus  R  Dinat H, K = H(x, x),K(x, x) (3.5) ∼ x D natural in H, K. This isomorphism is called the “dinaturality formula”.

3.2.5 Iterated Ends: Fubini Dinaturality over functors with multiple variables can be verified componentwise. This property allows us to deduce a general result for the manipulation of “integrals” in expressions: the so-called Fubini theorem for ends.

Proposition 3.2.2 RLet G: Cop C Dop D be a functor. If for every pair D × × × →B Cop C d1,d2 the end x G(d1,d2)(x, x)existsin ,whereG(d1,d2) : is induced∈ by G, then there is an isomorphism B × →B R R R G(x, x, y, y) = G (x, x). (x,y) ∼ y x (y,y) Here we also mean that if one side of the isomorphism exists then so does the other. R Proof. Given a wedge α :∆b¨λd ,d . G (x, x) we can define for a pair → 1 2 x (d1,d2) c, d C D an arrow αec,d as the composition ∈ × R εd αd / c / b x G(d,d)(x, x) G(c, c, d, d) R d e where ε is the universal wedge defined by x G(d,d)(x, x). The family αc,d c,d is a wedge from ∆b into G, this can be verified at each variable apart: h i By fixing d D it is clear that the family • ∈ d εc αd c C h ◦ i ∈ d is a wedge since ε is itself a wedge and then for f :c c0 the corresponding diagram → G(c, c, d, d) n7 OO d nn OO ε nn OGO(c,f,d,d) nnc n OOO nnn OO R n O' αd / b G(d,d)(x, x) G(c, c0,d,d) x PPP oo7 PPP ooo PPP ooo d PP oo ε P( oo G(f,c0,d,d) c0 G(c0,c0,d,d) commutes. 3.2. Ends 37

By fixing c C and for g :d d0 in D the outer hexagon • ∈ →

R εd G (x, x) c / x 9 (d,d) Q G(c, c, d, d)T ss QQQ TTTT s R TGTT(c,c,d,g) αd ss TT s G(d,g)(Qx,x) (2) TT ss x QQQ TTT ss R ( T) s εc / K (1) G (x, x) G(c, c, d, d ) b KK x 6 (d,d0) 5 0 KK mmm jjjj KK R m jjjj KK G (x,x) (3) jj αd K x m(g,d0) jj 0 K mm jj R % m jj G(c,c,g,d0) G (x, x) / x (d0,d0) G(c, c, d0,d0) d0 εc

commutes since

(1) commutes because α is a wedge; R (2) commutes since by definition x G(d,g)(x, x) is the mediating arrow d defined by the wedge Gd,g ε (consequence of parametrised representabil- ity (2.3)); and ◦ R (3) commutes for the same reason as (2) but applied to the arrow x G(g,d)(x, x).

Conversely, given a wedge γ :∆b¨Gthe family γc,d c defines for a fixed d a → h di wedgeR from b to Gd,d, which in turn by universality of ε gives an arrow γd from b to x Gd,d(x, x). By using the universality property of the endsR it is routine to verify that the collection γd d forms a wedge from b to λd1,d2. x Gd1,d2 (x, x). Thus the mapping α h αei is a bijection and then there is an isomorphism 7→ R   Dinat ∆b, λd ,d . G (x, x) = Dinat ∆b, G 1 2 x (d1,d2) ∼ which is easily seen to be natural in b . Hence R R ∈B R  (b, G (x, x)) = Dinat ∆b, λd ,d . G (x, x) B y x (y,y) ∼ 1 2 x (d1,d2) ∼= DinatR ∆b, G = (b, G(x, x, y, y)) ∼ B (x,y) all natural in b.  R C (c1,c2) Analogously, if for every pair c1,c2 the end y G (y,y) is defined in ,then there is a canonical isomorphism ∈ B R R R G(x, x, y, y) = G(x,x)(y,y). (x,y) ∼ x y

CorollaryR 3.2.3 (Fubini) LetRG:Cop C Dop D be a functor such that × × × →B the ends G (x, x)and G(c1,c2)(y,y) exist for every pair d ,d D and x (d1,d2) y 1 2 ∈ c1,c2 C then there is a canonical isomorphism ∈ R R R R G(x,x)(y,y) G (x, x) x y ∼= y x (y,y) meaning that one side of the isomorphism exists if and only if so does the other. By parametrised representability the isomorphism above is natural in G.

As limits are ends over functors with “dummy” extra arguments Fubini works for limits as well. Thus, for a diagram D :I J we have × →C lim (λy.lim D ) lim D. J I y ∼= I J ←− ←− ←− × 38 Chapter 3. Ends and Coends

3.2.6 Ends in Functor Categories Ends in functor categories are computed pointwise. A functor F : Iop I [J, ] corresponds under (2.14) to a functor × → C

1 op G = λ− (F ):I I J . × × →C op For every j J the functor G induces a partial functor Gj :I I .Infactby definition ∈ × →C Gj (i1,i2)=F(i1,i2)(j).

Iop I J 1 Proposition 3.2.4 LetR F : [ , ] be a functorR and let G = λ− (F ). If J × → C J for each j the end x Gj (x, x) exists then the end x F (x, x)existsin[ , ]and there is an∈ isomorphism C R R F (x, x) λy. G (x, x). x ∼= x y Proof. R  R R [J, ] H, λy. Gy(x, x) = (H(y), Gy(x, x)) by naturality formula, C x ∼ Ry C x  = Dinat ∆H(y),G by definition of end, ∼ Ry R y = (H(y),Gy(x, x)) by dinaturality formula, ∼ Ry Rx C = (H(y),Gy(x, x)) by Fubini for ends, ∼ Rx y C = [J, ](H, λy.Gy(x, x)) by naturality formula, ∼ x C  = Dinat ∆H, λx ,x .λy.G (x ,x ) by dinaturality formula, ∼ 1 2 y 1 2 ∼= Dinat ∆H, F . 

Again as limits are ends the same result is valid for limits. For a diagram D :I [J, ] there is a canonical isomorphism → C lim D λx.lim K I ∼= I x ←− ←− where K :I J is the bifunctor defined by D under (2.14). A consequence× →C of pointwise computation of limits is that for a complete category the functor category [I, ] is complete as well. For instance, the category Set is completeC and so is a functorC category [I, Set]. If is not complete, then non-pointwise limits may exist. The following example is extractedC from [Kel82]. The category of arrows of is the functor category [ , ]where represents the category with two objectsC and one non-identity arrow.{→} C An object{→} in this category is just an arrow in , and a morphisms corresponds to a commuting square in . Now consider the categoryC of arrows of the category induced by the graph C f / / h / g where h f = h g. The square ◦ ◦ id /

id h  /  h 3.3. Coends 39 is not a pullback since f = g. On the other hand in the category of arrows the diagram 6 g id / g

id (f,h)   / g h (f,h) is trivially a pullback since there is no other arrow but the identity with g as codomain.

3.3 Coends

A coend for a diagram G:Iop I is given by a universal wedge η : G ¨ ∆c. This condition can be expressed as× a→D representation for a covariant Set-valued→ functor.

Definition 3.3.1 (Coend) A coend for a functor G:Iop I is a representation (c, θ) for the functor Dinat G, ∆ : Set. The unit× of→D this representation is a universal wedge η : G ¨ ∆c. D→ → R As usual we call the object c the “coend of G” and write it as x G(x, x). By duality we can translate the results for ends into the dual ones for coends. Thus colimits are instances of coends and coends can be expressed as colimits. ThisR gives us a choice for coends in Set, for a functor G : Iop I Set the coend x G(x, x)istheset × → ] colimI (G d§)= (G d§)(a)/ § ◦ ◦ ∼ a I ∈ § where is the least equivalence relation where ∼

(a, x) (b, y) u:a bin I§ such that (G d§)(u)(x)=y. ∼ ⇔∃ → ◦

By definition of I§ and d§ this can be rewritten as ] colimI (G d§)= G(i, i)/  § ◦ ∼ i I ∈ where  is given as the least equivalence relation where ∼ (i, x)  (i, y) f:i jin I such that G(i, f)(x)=G(f,j)(y). ∼ ⇔∃ → As with colimits, coends in a category are translated into ends in Set.Thus, forafunctorG:Iop I we have an isomorphismD × →DR R x ( G(x, x),d)= (G(x, x),d). (3.6) D ∼ x D 3.4 Powers and Copowers

When the factors of a product are all equal, say Πx Xb where b and X Set the product is called a power and is written [X, b]. So∈ there is an∈C isomorphism∈ Y Y (a, [X, b]) = (a, b) = (a, b)=[X, (a, b)] C C ∼ C C x X x X ∈ ∈ 40 Chapter 3. Ends and Coends natural in a .Thusapower[X, b] just gives a representation for the functor ∈C [X, ( ,b)]: op Set. C C → The counit of this representation is a function ε:X ([X, b],b) →C equivalent to a X-indexed family of projections. For an X-indexed family

fx :a b x X h → i ∈ there is a unique mediating morphism fx x X :a [X, b] such that the triangle h i ∈ → z a zz fx z z f zz x x X }zz  h i ∈ o [X, b] b εx commutes for each x X. Powers are fully alive∈ in the case = Set where Y C B = Set(X, B)=[X, B] x X ∈ and [X, B] is just the exponential justifying the notation. If a category has all powers the mapping X [X, b] extends to a functor C 7→ [ ,b]:Setop . →C This follows by applying parametrised representability (Theorem 2.1.6) to the bi- functor [ , ( ,b)]:Setop op Set. C ×C → CopowersP give the dual notion. Given a category ,asetXand an object b C ∈C a x X b called a copower and is written X b. More formally a copower is a representation∈ for the functor ⊗ [X, (b, )]: Set. C C→ The unit of this representation is a function η :X (b, X b), →C ⊗ i.e. a X-indexed family of injections. In the special case of = Set acopoweris C just a cartesian product X B = X B. × x X ∈ If a category has all copowers for every b then the mapping X X b uniquely extendsC to a functor ∈C 7→ ⊗ b:Set . ⊗ →C This follows by applying the dual of Theorem 2.1.6 to the bifunctor [ , (b, )]:Setop Set. C ×C→ In general as powers and copowers are special kind of limits they are computed pointwise in functor categories. Thus if is a complete category and F :C is a functor then D →D [A, F ](x) ∼= λx.[A, F (x)]. The dual result holds for copowers. 3.5. Presheaf Categories 41

3.5 Presheaf Categories

For a small category C, the category [Cop, Set] is called the category of presheaves over C. The dual construction [C, Set] is the category of covariant presheaves. Representables are objects of presheaf categories, therefore the properties of those categories are of the special interest. Presheaf categories are complete; this follows from the fact that Set is complete and limits are computed pointwise. In the case of presheaf categories the Yoneda lemma expresses as an end for a Set-valued functor. For a presheaf F :Cop Set we have → F (c) = [Cop, Set] ( ,c),F by the Yoneda lemma, ∼ R C = [ (x, c),F(x)] by naturality formula. ∼ x C Indeed the family

λx.F ( )(x):F(c) [C(c0,c),F(c0)] c C h → i 0∈ defines a wedge from F (c)to

[C( ,c),F( )]:Cop C Set. × → 3.5.1 Weighted Limits From the theory of representables and presheaf categories arises another approach to universality given by the notion of weighted limit. In the case of locally small categories weighted limits are showed to coincide with ends (and then with lim- its). Weighted limits, however, are particularly relevant to the manipulation of presheaves.

Definition 3.5.1 (Weighted Limit) Given the diagrams

I B G / BB BB D BB F B Set the limit of G weighted by F is a representation for the functor  [I, Set] F, λx. ( ,G(x)) : op Set, D D → i.e. an isomorphism

θy  (y,d) = [I,Set] F, λx. (y,G(x)) (3.7) D ∼ D natural in y for some object d . ∈D As usual by abuse of the language we called the object d the weighted limit and write it as lim G or F, G , in this dissertation we prefer the second. This F { } concept was first←− introduced by Borceux and Kelly [BK75] as a proposal for a notion of “limit” in the most general setting of enriched categories. Then Kelly in [Kel82] developed the theory in detail, we reproduce some of the results here. There the concept is referred as indexed limits, with the time the term “weighted limit” prevailed. As for limits and ends there is a more concrete understanding of the notion of weighted limits in terms of universal weighted cones. Given a natural transformation  α [I, ] F, (y,G( )) , ∈ D D 42 Chapter 3. Ends and Coends

acomponentαi is a function mapping elements in F (i)toelementsin (y,G(i)) such that for an arrow f :i j in I the square D → α F (i) i / (y,G(i)) D F (f) G(f)   ◦− αj F (j) / (y,G(j)) D commutes. Thus for every element x F (i) the triangle ∈ 4 G(i) αi(x) iii iiii iiii y UUUU G(f) (3.8) UUUU UUU*  αj (F (f)(x)) G(j) commutes. Then we say that α is a cone from y to G weighted by F .Inthe terminology used by Kelly [Kel82] this is a (F, y)-cylinder over G. The counit ε of the representation (3.7) is a universal weighted cone in the sense that for another cone τ from b to G weighted by F there is a unique mediating arrow h:b F, G such that for every i I and x F (i) the triangle →{ } ∈ ∈ H b HH HH HτHi(x) h HH  H$ F, G / G(i) { } εi(x) commutes. In other words, h is the unique morphism making the diagram of natural transformations F id F ∼= ε τ   ( F, G ,G( )) / (b, G( )) h D { } h ◦ i D commute.

“Conical” Limits and Weighted Limits Let G:I be a functor and ∆1:I Set be the constant functor over a singleton set. There→D is a bijection →   [I, ] ∆y,G = [I,Set] ∆1, (y,G( )) (3.9) D ∼  D natural in y.Givenaconeβ [I, ]∆y,G and a morphism f :i j the diagram ∈ D → i4 G(i) βi ii iiii iiii y UUUU G(f) UUUU UUU*  βj G(j) commutes. Take the family αi :1 (y,G(i)) i defined by αi( )=βi where is the unique element in 1. Thenh from→D the trianglei above we have that∗ the diagram∗

3 (y,G(i)) αgiggg ggggg D gWg 1 WWWWW G(f) WWWW+  ◦− α j (y,G(j)) D 3.5. Presheaf Categories 43 commutes and then α is a weighted cone. Conversely given a weighted cone  γ [I, Set] ∆1, λx. (y,G(x)) ∈ D the family γi( ) i is a cone from y to G. This is clearly a bijection. As the constructionh is∗ preservedi through pre-composition in the first argument it follows the naturality in y. Hence usual limits, called in this context conical limits, can be expressed as weighted limits:  ( , lim G) = [I, ](∆ ,G)=[I, ] ∆1, λx. ( ,G(x)) . D I ∼ D ∼ D D ←− To show that weighted limits can be expressed as conical limits we need to define the category of elements associated to a presheaf or weight F .

Definition 3.5.2 Given a functor F : I Set,thecategory of elements of F , written as els(F ), has: → the pairs (i, x)wherex F(i)asobjects,and • ∈ f:(i, x) (j, y) for every f :i j in I where y = F (f)(x) as arrows. • → → It can be easily checked that this definition indeed gives a category where compo- sition and identities are inherited from I. There is a forgetful functor UF :els(F ) I projecting on the first component of an object and acting on arrows accordingly.→ Given functors I B G / BB BB D BB F B Set there is a bijection   I [ , Set] F, (y,G( )) ∼= [els(F ), ] ∆y,G UF D D ◦  natural in y. For a weighted cone α [I, Set] F, (y,G( )) by definition of ∈ D the category els(F ) the family αi(x) (i,x) els(F ) is a cone from y to G UF (see h i ∈ ◦ the diagram (3.8)). For the inverse, given a cone β :∆y G UF the family ⇒ ◦ λx.β(i,x) i I is a natural transformation from F to (y,G( )). Again, as the hconstructioni ∈ is preserved through pre-composition the isomorphismD is natural in y. Hence  (y, F, G ) = [I, Set] F, (y,G( )) = [els(F ), ](∆y,G UF ) D { } ∼ D ∼ D ◦ natural in y and F, G = lim G UF . { } ∼ els(F ) ◦ ←− Ends and Weighted Limits A special case of categories of elements arises by considering the hom-functor I( , ):Iop I Set. × → The objects of els(I( , )) can be regarded as just the arrows of I. An arrow from f : i j to g : i0 j0 is a pair of arrows (h1 : i0 i, h2 : j j0)inIsuch that the diagram→ → → → f / iO j

h1 h2  / i0 g j0 44 Chapter 3. Ends and Coends commutes. Mac Lane [Mac98] calls els(I( , )) the twisted category of I.Givena multivariant functor G : Iop I the weighted limit I( , ),G is given by a representation × →D { }   y, I( , ),G =[Iop I, Set] I( , ), y,G( , ) D { } ∼ × D natural in y.Aconeαfrom y to G weighted by I( , ) is such that for the pair (idi :i i, f :i j) the diagram → → G(i, i) αi,i(idi)hh4 hhhhh hhhh y VVV G(i,f) VVVV VVV*  αi,j (f) G(i, j) commutes, and for the pair (f :i j, idj :j j) the diagram → → G(j, j) αj,j (idj )hh4 hhhh hhhh y VVV G(f,j) VVVVV VVV*  αi,j (f) G(i, j) commutes. Then by pasting these diagrams together we have that the outer diagram in G(i, i) = II zz II αi,i(idi)zz IGI(i,f) zz II zz I$ z αi,j (f) y _D ______/ G(i, j) DD u: D uu DD uu DD uu αj,j (idj ) D! uu G(f,j) G(j, j) commutes for f :i j and the family αi,i(idi):y G(i, i) i I is a wedge. Conversely, for→ a wedge β from y hto G and for→ a morphismi ∈ h : i j we can define the arrow → G(i, h) βi = G(h, j) βj. ◦ ◦ For arrows f :i0 i, g :j j0 and h:i j in I we have that → → →

G(f,g) G(i, h) βi = G(f,j0) G(i, g h) βi ◦ ◦ ◦ ◦ ◦ = G(f,j0) G(g h, j0) βj β is a wedge (applied to g h), ◦ ◦ ◦ 0 ◦ = G(g h f,j0) βj ◦ ◦ ◦ 0 = G(i0,g h f) βi β is a wedge (applied to g h f). ◦ ◦ ◦ 0 ◦ ◦ Then the diagram ffff2 G(i, j) fG(i,h) βi fffff ◦ y XXXXXX G(f,g)  G(i0,g h f) βXXiX ◦ ◦ ◦ 0 , G(i0,j0) commutes and the family

G(i, ) βi / I(i, j) ◦ (y,G(i, j)) i,j Iop I G( ,j) βj ∈ × h ◦ D i 3.5. Presheaf Categories 45 is a cone from y to G weighted by I( , ). It is straightforward to check that these two mappings between weighted cones and wedges give rise to a bijection of sets. Hence   [Iop I, Set] I( , ), (y,G( , )) = Dinat ∆y,G × D ∼ natural in y and then R I( , ),G = G(x, x). { }∼ x Naturality in the parameter y follows by observing that these constructions are preserved through pre-composition. At this point one might wonder if the twisted category gives a different way of linking the notions of limits and ends. The answer comes from expressing the weighted limit I( , ),G as a limit: { } R G(x, x) = I( , ),G = lim G U x ∼ { } ∼ els(I( , )) ◦ ←− where U :els(I( , )) Iop I is the corresponding forgetful functor. → × The category I§ (defined in 3.2.2) can be seen as a subcategory of the twisted § category of I. Remember that objects in I§ are the objects and arrows in I.The “inclusion”  ι / I I§ els( ( , )) maps i I to the identity idi and an arrow to itself. The action of this inclusion ∈ on the arrow i f (for f :i j in I) results in the pair (idi,f), dually the arrow −→ → j f is sent to the pair (f,idj). −→ In fact I§ is an “initial subcategory” of els(I( , )) (see 2.2.3) since for each arrow f :i j in I (i.e. an object in the twisted category): § →

there is at least the morphisms (f,idj):idj f and (idi,f):idi f in • els(I( , )), and → →

for any pair of arrows h f,h0 f in els(I( , )) there are arrows • → →

h / h0 / a ^< b = < g2 @ a0 b0 < == ÑÑ  << =Ñ=Ñ  <(1) g3 = (2)  g < ÑÑ =  g 1 < Ñ =  4 Ñ / i j f

in I where (1) and (2) commute by definition of els(I( , )); then there is a connection o /o /o /o / hbg2 jfig3 a0 h0

in I§ such that the diagrams o / o / o / o / WWW UU g2 O id f g3 gg h WWWidb UU O j idi o ii ida0 gg h0 WWWW UUU OOO ?? Ð ooo iiii ggggg WWWWW UUUU OO ?? ÐÐ oo iii ggggg WWWW UUU OOO ?? ÐÐ ooo iiiigggg WWWWUWUUUOO ? Ð oo iiiggggg (g1,g2) WWWUUUOO?  Ðooiiiggg (g3,g4)) WWWUWUO+*' sgtiwoÐoigiggg f

commute in els(I( , )). 46 Chapter 3. Ends and Coends

The general situation is illustrated by the diagram

I r d§ / Iop I G / §J O JJ × D JJ JJ U JJ ι J$ els(I( , )) where the triangle commutes. By putting all this information together it follows that

R (1) I x G(x, x) = limI G d§ = limI G U ι = lim I G U = ( , ),G . ∼ § ◦ ∼ § ◦ ◦ ∼ els( ( , )) ◦ ∼ { } ←− ←− ←− where the isomorphism (1) is the one defined by Proposition 2.2.5. Clearly as weighted limits are conical limits they are ends as well. If for all i I the power [F (i),G(i)] exists in there is an alternative way of expressing weighted∈ limits as ends. D

Proposition 3.5.3 Let G:I be a diagram and F :I Set a weight such that for each i I the power [F (i)→C,G(i)] exists. Then, there is→ an isomorphism ∈ R F, G = [F(x),G(x)] { } ∼ x meaning that one side of the isomorphism exists if and only if so does the other.

Proof. R R (c, [F (x),G(x)]) = (c, [F (x),G(x)]) since hom-functors preserve ends, C x ∼ Rx C  = F (x), (c, G(x)) by definition of powers, ∼ x C = [I, Set](F, (c, G( ))) by naturality formula. ∼ C 

Weighted Limits with Parameters As with conical limits the expression F, G is functorial in G [I, ] provided that has enough weighted limits. From{ parametrised} representability∈ D F, G is functorialD in F as well, in this case as a contravariant argument. This follows{ } by applying Theorem 2.1.6 to the functor  λF, y.[I, ] F, (y,G( )) :[I,Set]op op Set. D D ×D → That is if for every F [I, Set]op there is a representation ∈ θF  ( , F, G ) = [I, ] F, λx. ( ,G(x)) . D { } ∼ D D Then there is a unique extension of the mapping F F, G to a functor 7→ { } ,G :[I,Set]op . { } →D Concretely given a natural transformation α : F H where F, H :I Set by the proof of Theorem 2.1.6 we have ⇒ →

 1 α, G = θF − (γ α) { } ◦ 3.5. Presheaf Categories 47 where γ is the universal weighted cone defined by H, G . The composition { } γ α : F ( H, G ,G( )) ◦ ⇒D { } gives a cone from H, G to G weighted by F . Now by universality { } α, G : H, G F, G { } { }→{ } is the unique morphism making the diagram

F id F ∼= κ γ α   ◦ ( F, G ,G( )) / ( H, G ,G( )) α,G D { } h ◦{ }iD { } commutes where F κ = θ (id F,G ) { } is the universal weighted cone defined by F, G . Therefore, if is a complete category there is a bifunctor { } D

λG, F. F, G :[I, ] [I,Set]op . { } D × →D

Iterated Weighted Limits

As expected weighted limits of diagrams over functor categories are computed point- wise. Let H :I [J, ] be a functor such that for a weight F :I Set and for every → C → j J the limit F, Gj exists where Gj :I is the partial functor corresponding ∈ 1 { } →C to G = λ− (H). Then there is an isomorphism

F, H = λx. F, Gx . { } ∼ { } This follows since for K :J →C R [J, ](K, λx. F, Gx ) = (K(x), F, Gx ) by naturality formula, C { } ∼ Rx C { }  = [I, Set] F, (K(x),Gx( )) by definition of weighted limits, ∼ x R C = [I, Set](F, (K(x),Gx( ))) since hom-functors preserve ends, ∼ x C  = [I, Set] F, [J, ](K, H( )) by naturality formula. ∼ C As ends and limits, weighted limits can be iterated. First we need to state what an iterated weighted limit would mean. Let H : I [J, ] be a functor and F :I Set and F :J Set be weights. We define a combined→ C weight 1 → 2 → F F :I J Set 1 ⊗ 2 × → to be the functor which maps (i, j) I J into the copower F (i) F (j), which ∈ × 1 ⊗ 2 in this case is jut the product of sets F1(i) F2(j). If the limit F1,H exists pointwise in [J, ] then there is a canonical isomorphism× { } C F , F ,H = F F ,G { 2 { 1 }} ∼ { 1 ⊗ 2 } 48 Chapter 3. Ends and Coends

1 where G = λ− (H). This follows since for c  ∈C c, F , F ,H C { 2 { 1 }}  = [J, Set] F , (c, F ,H ( )) by definition of weighted limit, ∼ R  2 C { 1 }  = F (x), c, F ,H (x) by naturality formula, ∼ Rx  2 C { 1 }  = F (x), c, F ,Gx by pointwise computation, ∼ Rx  2 C { 1 }  = F (x), [I, Set] F , (c, Gx( )) by definition of weighted limit, ∼ Rx  2 R 1 C  = F (x), [F (y), (c, Gx(y))] by naturality formula, ∼ Rx R 2 y 1 C  = F (x), [F (y), (c, G(x, y))] since hom-functors preserve ends, ∼ Rx Ry 2 1 C = [F (y) F (x), (c, G(x, y))] by definition of tensor and symmetry, ∼ Rx y 1 ⊗ 2 C = [F1(y) F2(x), (c, G(x, y))] by Fubini, ∼ (x,y) ⊗ C  = [I J, Set] F F , (c, G( , )) by naturality formula. ∼ × 1 ⊗ 2 C 3.5.2 Weighted Colimits As covariant presheaves are weights for limits, contravariant presheaves are weights for colimits. A weighted colimit for a diagram D :I is nothing but a weighted limit for Dop :Iop op. →D →D Definition 3.5.4 Let D : I and F :Iop Set be diagrams. The colimit of D weighted by F is a representation→D for the functor→  [Iop, Set] F, λx. (D(x), ) : Set, D D→ i.e. an isomorphism

θy  (c, y) = [Iop, Set] F, (D( ),y) (3.10) D ∼ D natural in y.

We call the object c the the weighted colimit and it is written as ColimF D or F?D; in this dissertation we use the second. The unit η of the representation (3.10) is a universal weighted cone in the sense that for another weighted cone τ from D to b weighted by F there is a unique mediating arrow h : F?D bsuch that for every i I and x F (i) the triangle → ∈ ∈ ηi(x) / D(i)H F?D HH HH HH h τ x HH i( ) H#  b commutes. That is, h is the unique morphism making the diagram of natural transformations F id F ∼= η τ   (D( ),F ?D) / (D( ),b) h D h ◦ i D commute. By means of the natural isomorphism (1.1) we obtain the diagram F id F ∼= η τ   op((F?D)op,Dop( )) / op(b, Dop( )) hop D h ◦ i D 3.5. Presheaf Categories 49 which shows the expression (F?D)op as a weighted limit of Dop in op. By duality the properties of weighted limits are exported to the caseD of weighted colimits. Thus weighted colimits correspond to “conical” colimits and coends. For a functor G:I and a weight F :Iop Set we have →D →

F?G=colim G UF (3.11) ∼ els(F ) ◦ where els(F ) is the category of elements for the presheaf F and UF is the corre- sponding forgetful functor. For a contravariant presheaf F the definition of els(F ) needs a slight modification: the objects are pairs (i, x)wherex F(i) as before, but an arrow f :(i, x) (j, y)inels(F ) corresponds to an arrow f∈:i j in I where x = F (f)(y). → → ForafunctorG:Iop I , the coend of G can be expressed as a weighted × →D colimit: R x I G(x, x) ∼= ( , ) ?G. Now, the “inclusion” functor ι : I§ els(I( , )) is final instead. Finality here means that for every arrow f in I the→ comma category f ι is connected. Thus, from (3.11) and the dual form of Proposition 2.2.5 we have:↓ R x G(x, x) = colimI G d§ = colimI G U ι = colim I G U = I( , ) ?G. ∼ § ◦ ∼ § ◦ ◦ ∼ els( ( , )) ◦ ∼ Let G : I be a diagram and F : I Set a weight. From the dual of Proposition 3.5.3→C we have that if the copower→F (i) G(i)existsforeachi Ithen ⊗ ∈ there is an isomorphism R x F?G= F(x) G(x). ∼ ⊗ It is interesting to verify how the parametrised representability works for weighted colimits. Given a cocomplete category there is a bifunctor D λG, F.F ? G:[I, ] [Iop, Set] D × →D where differently to the weighted-limit case the expression is covariant in the pa- rameter for the weights. The following result relates contravariant with covariant presheaves.

Proposition 3.5.5 Given the functors F :Cop Set and G:C Set there is an isomorphism → → F?G∼=G?F Proof. ForasetZwe have

Cop [F?G,Z]∼=[R , Set](F, [G( ),Z]) by definition of weighted colimit, [F (x), [G(x),Z]] by naturality formula, ∼= Rx = [F (x) G(x),Z] by definition of copower, ∼ Rx ⊗ = [G(x) F (x),Z] by symmetry, ∼ Rx ⊗ = [G(x), [F (x),Z]] by definition of copower,, ∼ x  C ∼= [ , Set] G, [F ( ),Z] by naturality formula.  Thus by definition of weighted colimit we have F?G∼=G?F.

Corollary 3.5.6 For a diagram D : C [D, Set]andaweightF:C Set there is an isomorphism → → F?D∼=λd.(Gd ?F) 1 where Gd :D Set is the functor induced by the bifunctor G = λ− (D). → 50 Chapter 3. Ends and Coends

Proof.

F?D∼=λd.(F?Gd) pointwise computation, ∼= λd.(Gd ?F) by the Proposition above. 

3.5.3 Density  A subcategory C / is said to be a dense generator if each object in can be expressed as a colimit ofD objects in C. More generally a functor K :C Dis dense if for each d there is a canonical isomorphism →D ∈D P / K / d = colim(K d C ) ∼ ↓ D where P is the projection functor associated to the comma category K d.Here we show that for a category C the Yoneda embedding :C [Cop, Set] is↓ a dense functor. Y →

Proposition 3.5.7 ForapresheafF:Cop Set we have → F? =F. Y∼ Proof.  [Cop, Set] F? ,H Y  =[Cop, Set] F, λx.[Cop, Set]( (x),H) by definition of weighted colimit, ∼ R Y  = [Cop, Set] F, λx. [C(c, x),H(c)] by naturality formula, ∼  c Cop ∼= [ , Set] F, H by the Yoneda lemma.



This result is an important property which says that a presheaf F : Cop Set can always be expressed as a colimit of solely representables: →

F = F? =colim UF. ∼ Y∼ els(F )Y◦ From the Yoneda lemma we have that the the diagram of categories and functors

els(F ) = F ∼ Y↓

UF P   C id C ∼= commutes and then the Yoneda embedding is dense. By Corollary 3.5.6 there is another way of expressing a presheaf F : Cop Set as a weighted colimit (or “conical” colimit or coend) →

F = F? =λc.(C(c, ) ?F). ∼ Y∼ Since [Cop, Set] is cocomplete and then has all copowers we have R x F = F? = F(x) λy.C(y,x) by dual of Proposition 3.5.3, ∼ ∼ R Y x ⊗ = λy. F (x) C(y,x) pointwise computation. ∼ ⊗ 3.5. Presheaf Categories 51

This gives a third way of expressing a presheaf as a coend: R x F = λy. F (x) C(y,x) (3.12) ∼ ⊗ the so called density formula. For functors

C K / @@ @@ A @@ (3.13) F @ B a left of F along K is given by a “universal arrow”

(G: ,ε:F G K) A→B ⇒ ◦ from F to K :[ , ] [C, ]. In other words, for a pair (H : ,β : F H K) there◦ is a uniqueA B → naturalB transformation τ : G H such thatA→B ⇒ ◦ ⇒ β = Kτ ε. ◦ The following diagram illustrates the situation

K =E / C C Ó CC ε ÓÓÓ A CC ÓÓÓÓ CÓÓ τ +3 CC G H F CC C!  . B

Usually G is written as LanK F . By definition the mapping sending β into τ estab- lishes an isomorphism   Nat F, H K = Nat LanK F, H ◦ ∼ “natural” in H. Kan extensions, however, cannot be expressed as a representa- tion for a Set-valued functor simply because the category of functors [ , ]isnot necessarily locally small and we shall not develop their theory here. A B The most relevant fact to our work is that left Kan extensions can be computed pointwise as coend formulæ. If the copower (K(y),x) F(y0)existsin for every A ⊗ B x, y, y0 then R x LanK F = λy. (K(x),y) F(x)=λy. (K( ),y)?F. (3.14) A ⊗ ∼ A For instance by the Yoneda lemma the density formula (3.12) corresponds to the left Kan extension of F composed with the Yoneda embedding. There is of course a dual notion: for functors like in (3.13) the right Kan exten- sion of F along K, sometimes written RanK F , is given by an isomorphism   Nat H K, F = Nat H, RanK F ◦ ∼

“natural” in H.Ifthepower[ (x, K(y)),F(y0)] exists in for every x, y, y0 then A B R RanK F = λy. [ (y,K(x)),F(x)] = λy. (K( ),y),F . x A ∼ {A } For a proof of these facts refer to [Kel82,Mac98]. 52 Chapter 3. Ends and Coends

3.5.4 Exponentials The last property of presheaves we study here is their cartesian closed structure. As the category [Cop, Set] is complete we have all products, in fact they are computed pointwise (F G)(c) = F (c) G(c). × ∼ × The exponential [F, G] should satisfy

[F, G](c) = [Cop, Set]( (c), [F, G]) by the Yoneda lemma, ∼ Y = [Cop, Set]( (c) F, G) by the required adjunction, ∼ R Y × = [C(x, c) F (x),G(x)] by naturality formula and pointwise computation. ∼ x × Let us verify that R λy. [C(x, y) F (x),G(x)] x × is indeed an exponential: R [Cop, Set](H, [F, G]) = [H(y), [F, G](y)] by naturality formula, ∼ Ry R = [H(y), [C(x, y) F (x),G(x)]] by definition, ∼ Ry R x × = [H(y), [C(x, y) F (x),G(x)]] since hom-functors preserve ends, ∼ Ry Rx × = [H(y), [C(x, y) F (x),G(x)]] by Fubini result, ∼ Rx Ry × = [H(y), [C(x, y), [F (x),G(x)]]] since Set is closed, ∼ Rx Ry = [H(y) C(x, y), [F (x),G(x)]] since Set is closed, ∼ Rx Ry × y = [ H(y) C(x, y), [F (x),G(x)]] by (3.6), ∼ Rx × [H(x), [F (x),G(x)]] by density formula, ∼= Rx = [H(x) F (x),G(x)] since Set is closed, ∼ Rx × = [(H F )(x),G(x)] by pointwise computation, ∼ x × = [Cop, Set](H F, G) by naturality formula. ∼ × This gives another example of the power of the algebraic manipulation of ends and coends we exploit in this dissertation. Chapter 4

Preservation of Limits

Functors preserving limits and/or colimits play an important role in the applica- tions of category theory. A central result in [CW], for instance, is that cocontinuous functors between presheaf categories preserve open-map bisimulation. Another ex- ample arises in categorical logic [Jac99, Pit00] where a model for a simple type theory is defined to be a product-preserving functor with domain the corresponding classifying category. In general verifying that a functor preserves limits by following the definition can be tedious and rather involved. It seems to require a concrete reasoning in terms of cones. In this chapter we study how naturality may help to prove preservation of universal properties in a more “equational” manner. The main result of the chapter is that functors which preserve terminal objects and distribute over the limit functor up to natural isomorphism preserve limits. The presentation of this result constitutes one of the contributions of this dissertation and it is inti- mately related to the choice of rules for the calculus for categories presented in the subsequent chapters.

4.1 Limiting Cones

A cone from c to a diagram D : I is a natural transformation from ∆c to D. A limit for ∈CD is just a universal cone,→Ci.e. aconeε:∆c Dsuch that for any ⇒ other cone ε0 :∆c0 Dthere exists a unique mediating morphism m : c0 c for which the diagram ⇒ → ∆m / ∆c0 ∆c

ε0 ε   D id D ∼= commutes. Alternatively a limit for D is a representation for the set-valued functor

[I, ](∆ ,D): op Set C C → where the counit is the limiting cone (see 2.2). A pair of arrows s:c d, r :d c form a section-retraction pair (or s is a split → → monic) if the composition r s yields the identity idc and it is denoted by ◦ s / co C d. r

Proposition 4.1.1 Let D, D0 :I be small diagrams such that there are cones →C ε :∆c Dand ε0 :∆c0 D0 together with section-retraction pairs (s ,r )and ⇒ ⇒ 1 1

53 54 Chapter 4. Preservation of Limits

(s2,r2) such that the squares in the following diagram of natural transformations

∆s1 / C ∆c0 o ∆c ∆r1 ε0 ε  s2 /  C D0 o D r2 commute, i.e. ε ∆s = s ε0 and ε0 ∆r = r ε. (4.1) ◦ 1 2 ◦ ◦ 1 2 ◦ If ε is a limiting cone then also ε0 is a limiting cone.

Proof. We want to show ε 0 is universal, i.e. that for any cone κ :∆x D0 there ⇒ exists a unique factorisation of κ through ε0.

Existence: The composition s2 κ is a cone from x to D. Let m : x c be • the unique mediating arrow such◦ that → ε ∆m = s κ. (4.2) ◦ 2 ◦ Hence,

ε0 ∆r ∆m = r ε ∆m by (4.1), ◦ 1 ◦ 2 ◦ ◦ = r s κ by (4.2), 2 ◦ 2 ◦ = κ (s2,r2) is a section-retraction pair.

Uniqueness: Let h:x c0 be an arrow such that • → ε0 ∆h = κ. ◦ Hence,

ε ∆s ∆h = s ε0 ∆h by (4.1), ◦ 1 ◦ 2 ◦ ◦ = s κ by definition of ∆h. 2 ◦ By uniqueness of m m = s h, 1 ◦ and since (s1,r1) is a section-retraction pair r m = h. 1 ◦ 

Corollary 4.1.2 Let D : I be a diagram. Given a limiting cone ε :∆c D f →C ⇒ and an isomorphism c0 = c then ε ∆f :∆c0 Dis a limiting cone. ∼ ◦ ⇒ Proof. By direct application of the proposition above to

∆c ∆f ∆c 0 ∼= ε ∆f ε ◦   D id D. ∼=  4.2. Preservation of Limiting Cones 55

4.2 Preservation of Limiting Cones

Let G : be a functor. Given a cone γ :∆a Dfor a diagram D : I the naturalC→D transformation Gγ :∆G(a) G Dis⇒ a cone as well. Thus, given→C a limiting cone ε :∆d G Dthere is a⇒ unique◦ mediating morphism m : G(a) d such that the diagram⇒ ◦ → ∆m / ∆G(a) ∆d

Gγ ε   G D id G D ◦ ∼= ◦ commutes. The functor G preserves a limiting cone κ :∆c Dif the cone Gκ :∆G(c) G Dis limiting (see Definition 2.2.7). This is equivalent⇒ to requiring the mediating⇒ arrow◦ defined by Gκ to be an isomorphism. In fact many authors use this as the definition of preservation of limits (see [MM92]).

Proposition 4.2.1 Let D, D0 :I be small diagrams such that there are cones →C ε :∆c Dand ε0 :∆c0 D0 together with section-retraction pairs (s ,r )and ⇒ ⇒ 1 1 (s2,r2) making the squares in the diagram of natural transformations

∆s1 / C ∆c0 o ∆c ∆r1 ε0 ε  s2 /  C D0 o D r2 commute. If ε is a limiting cone and G : preservers it then G preserves the C→D limiting cone ε0. Proof. It follows by applying G to the diagram above and by Proposition 4.1.1. As Gε is limiting then Gε0 is limiting and the corresponding mediating arrow must be an isomorphism. Notice that the mediating arrow is not necessary ∆G(s1).  As an immediate corollary we have that if a functor G : preserves one limiting cone for a diagram D :I then it preserves any otherC→D limiting cone for D. We shall henceforth consider a chosen→C limiting cone when checking for preservation.

Proposition 4.2.2 Let F, G : be functors such that F ∼= G. For every limiting cone κ :∆c Dfor someC→D diagram D :I ⇒ →C F preserves κ if and only if G preserves κ. Proof. Assume F preserves κ,thenFκ is a limiting cone and from the commuta- tivity of the diagram

∆G(c) ∼= ∆F (c)

Gκ Fκ   G D = F D ◦ ∼ ◦ we conclude by Proposition 4.1.1 that Gκ is a limiting cone as well. 

An immediate corollary from this and Proposition 2.2.8 is that representable functors are continuous. In some cases we are interested in a subcategory of diagrams [I, ]. Then we talk about a functor preserving -limits or being -continuous.K⊆ TypicallyC we take K K 56 Chapter 4. Preservation of Limits of diagrams for which all limits exists in , i.e. is -complete, in such a way that we can talkK about a functor lim : Cas definedC K in 2.2.1. I K→C § In order to prove that a functor G : ←− preserves the limit of a diagram D :I is not enough to exhibit an isomorphismC→D →C G(lim D) = lim G D. I ∼ I ◦ ←− ←− Indeed, the action of G over arrows may result in a family that is not universal. As an example consider the category Count of countably infinite sets and functions. Clearly the objects of Count are all isomorphic. There is a functor +1:Count Count that acts over sets by adding a new element: given X Count then→ X +1=X X and given a function f :X Y , the function f +∈ 1 sends a X to f(a)and∪{X }to Y . There is an isomorphism→ ∈ { } { } (X Y )+1=(X+1) (Y +1), × ∼ × but this functor does not preserve products; the arrow πX +1:(X Y)+1 X+1 is not a projection. × → If the categories and have enough limits the expressions C D G(lim D) and lim (G D) I I ◦ ←− ←− are both functorial in D. For every D there is a mediating arrow mD defined by Gε where ε is the universal cone associated to lim D. The family mD D is natural, I h i this follows directly from the universality of←− the mediating arrows. Thus if G is -continuous there is a canonical isomorphism K G(lim D) = lim (G D) I ∼ I ◦ ←− ←− natural in D . ∈K This isomorphism is not always unique. Consider, for instance, the category 1 with one object, say ?, and the identity arrow. The functor category [1, 1]has only one object: the “constant” functor ∆?. The limit for this functor is the object ? itself where the limiting cone is the identity. We can extend 1 with an extra morphism  ι / id : ? id : ? d f where f is also an isomorphism, i.e. f f = id. The inclusion functor ι clearly preserves the limit of the diagram ∆?. The◦ mediating arrow is given by the identity on ? which is an isomorphism and trivially natural. The arrow f, however, gives another isomorphism  ι(lim ∆?) = lim ι ∆ ? , 1 ∼ 1 ◦ ←− ←− naturality here is trivial as well. Often checking the isomorphism between the limiting objects follows from a more-or-less direct calculation. To prove that a functor preserves a limiting cone by closely following the definition can be rather tedious and involve a fair amount of bookkeeping. In this chapter we study under which conditions an isomorphism

G(lim D) = lim G D I ∼ I ◦ ←− ←− is enough to ensure that G preserves the limit of D. 4.3. Connected Diagrams 57

4.3 Connected Diagrams

A category is connected if for any pair of objects a, b there is a chain of arrows E ∈E

a e e ... en b. → 1 ← 2 → → ← A smallP category I can be decomposed into its connected components. We write I I I I = k K k for this decomposition where k’s are the connected components of . The decomposition∈ can be described abstractly as the left adjoint of the discrete- category functor Dis:Set Cat. This functor takes a set X into the discrete small category with objects the→ elements of X and it has left and right adjoints:

Con Dis Obj. a a The functor Con:Cat Set takes a category I into the set of connected components → of I and the functor Obj:Cat Set actsP by mapping a small category into its set → K I I of objects. The indexing category in k K k is defined to be Dis(Con( )), i.e. the discrete category whose objects are identified∈ with the connected components of I [Par73,Par90]. A connected component Ik of I is a full subcategory and there is an inclusion functor ιk :Ik I. This functor defines by pre-composition the “restriction” functor →

ιk :[I, ] [Ik, ]. ◦ C → C A diagram whose index category is given by a unique connected component is called a connected diagram. We can characterise the set of natural transformations from ∆c to ∆d as

[I, ](∆c, ∆d) = [Con(I), (c, d)]. C ∼ C From the definition of the diagonal functor in 1.3 an arrow f : c d in defines a natural transformation ∆f :∆c ∆d. Observe§ that the diagonal→ functorC is faithful but not necessary full. If the⇒ category I is connected then we have

[I, ](∆c, ∆d) = (c, d) C ∼ C since (c, d) ∼= [1, (c, d)] and then the diagonal functor is full and faithful. ByC the definitionC of power

(c, [Con(I),d]) = [Con(I), (c, d)] = [I, ](∆c, ∆d) C ∼ C ∼ C natural in c which exhibits [Con(I),d] as the limit of ∆d:

lim ∆d [ (I),d]. (4.3) I ∼= Con ←− The counit of this representation

Con(I) / ([Con(I),d],d) C is the limiting cone. Then by definition of limit if I is connected the counit above is an isomorphism and any cone γ :∆x ∆dis limiting if and only if γ is an isomorphism. Moreover, ⇒ f as ∆ is full and faithful there exists a unique isomorphism x ∼= d such that γ =∆f. Another observation here is that if I is connected then has limits for all I-indexed constant diagrams. C

Lemma 4.3.1 Let J be a connected small category and D :J a diagram. For every limiting cone γ :∆c Dthe arrow lim γ is an isomorphism.→C ⇒ J ←− 58 Chapter 4. Preservation of Limits

Proof. By definition limJγ is the unique arrow making the diagram ←−

∆lim γ J / ∆limJ∆c ←− ∆limJD ←− ←− β κ   / ∆c γ D commute, where β and κ are the chosen limiting cones associated to limJ∆c and f ←− lim D respectively. As J is connected there is an isomorphism lim ∆c c such that J J ∼= ←β−=∆f.Asγand κ are limiting cones by Corollary 4.1.2 there←− is an isomorphism g : c = lim D such that γ = κ ∆g. Hence, ∼ J ◦ ←− κ ∆g ∆f = γ ∆f = κ ∆lim γ. ◦ ◦ ◦ ◦ J ←− Since κ is limiting and ∆ full and faithful

lim γ = g f. J ◦ ←−

Thus as f and g are isomorphisms it follows that limJγ is an isomorphism as well.  ←−

The following theorem establishes that a natural isomorphism is enough to en- sure preservation of limits of connected diagrams.

Theorem 4.3.2 Let J be a small category and , categories with all J-limits. If the functor G: preserves J-limits then C D C→D G(lim D) = lim (G D) J ∼ J ◦ ←− ←− natural in D [J, ]. Moreover, for J connected the converse also holds. ∈ C Proof. If G preserves limits then by definition the mediating arrow

G(lim D) lim (G D) J → J ◦ ←− ←− for each D [J, ] is an isomorphism and the family is a natural transformation. Let J be∈ a connectedC small category and assume there is an isomorphism

θD lim (G D) = G lim D J ◦ ∼ ◦ J ←− ←− natural in D. Given a diagram D : J and a limiting cone γ :∆c Dthere is a unique morphism m:G(c) lim G→CD such that the diagram ⇒ → J ◦ ←− ∆G(c) ∆m / ∆lim (G D) J ◦ ←− Gγ ε   G D id G D ◦ ∼= ◦ commutes, where ε is the chosen limiting cone for G D. We verify that m is an isomorphism as required. ◦ 4.3. Connected Diagrams 59

The limiting cone γ :∆c Dinduces the naturality square ⇒  θ ∼= / G limJ∆c limJ(∆G(c)) ←− ←− G(lim γ) lim Gγ J J ←−   ←− θ G(lim D) ∼= / lim (G D). J J ◦ ←− ←− J Since is connected by Lemma 4.3.1 the arrow limJγ is an isomorphism and ←− then G(limJγ) is an isomorphism as well. From the naturality square above we can ←− conclude limJGγ is an isomorphism. ←− By definition limJGγ is the unique mediating arrow making the diagram ←− ∆lim Gγ ∆lim (∆G(c)) J / ∆lim (G D) J ←− J ◦ ←− ←− ∆h ε   / ∆G(c) G D Gγ ◦ commute where ∆h is the chosen limiting cone associated to lim (G ∆c). Since J J ◦ is connected h is an isomorphism. Hence, ←−

1 Gγ = ε ∆lim Gγ (∆h)− ◦ J ◦ ←− and by uniqueness of the mediating arrow

1 m = lim Gγ h− J ◦ ←− and m is an isomorphism. Thus G preserves the limiting cone γ. 

This proof rests on the key fact that limIγ is an isomorphism, or equivalently that the diagonal functor ∆ is full and← faithful.− It is important to stress here that the Theorem above refers to any natural isomorphism and not necessarily to the canonical natural transformation defined by the limit. The theorem establishes that if there exists such a natural isomorphism then the canonical family is indeed a natural isomorphism as well. For some authors the isomorphism above implicitly refers to the canonical one stating a less general and straightforward result (for instance [Joh83, MM92]). We can relax the conditions of this theorem to consider the case where not all J-limits exist. Take instead a full subcategory [J, ] of diagrams whose limits exist in andsuchthat includes all constantK⊆ diagrams.C C K Corollary 4.3.3 Let J be a connected small category and be a full subcategory of [J, ] including all constant diagrams and such that is K-complete. Then G is -continuousC if and only if C K K 1. for every D ,G Dhas a limit in ;and ∈K ◦ D 2. there exists an isomorphism lim (G D) = G(lim D) natural in D . J ◦ ∼ J ∈K ←− ←− Proof. We use the proof of Theorem 4.3.2 within the subcategory . Notice that the expression lim D is functorial in D but the domain is insteadK of [J, ]. As J K C the indexing category←− J is connected the limits for constants diagrams exist in .  C 60 Chapter 4. Preservation of Limits

Connectivity represents a significant constraint on diagrams. There are, how- ever, many applications where connected limits (and colimits) are central and then the result above (and its dual) can be useful [Par90,Cat99,CW]. In general Theorem 4.3.2 does not hold when the indexing category is not con- nected. For an example consider the functor category [2, 1]were2is the two-objects discrete category. This functor category has a unique object: the constant diagram ∆?. Now consider the functor G : 1 Set selecting a countable infinite set, say the natural numbers N.As? ?=?→in 1, where the projections are given by the identity, we have × G(? ?) = G(?) G(?) × ∼ × natural in ? since N = N N. The pair (id , id ), however, is not a product! ∼ × N N 4.4 Products

Theorem 4.3.2 can not be applied to products since the index category in this case is discrete, an extreme example of lack of connectivity. Given a discrete category K a diagram D : K can be regarded as a tuple of objects xk k K in where →C h i ∈ C xk = D(k). A cone for this functor is any family of arrows fk :x xk k K for some object x. Notice that as the index category is discrete thereh is→ no commutativityi ∈ to check and naturality comes for free. We say that a family fk : x xk k K is a product when it is a limiting cone. In this section we studyh the conditions→ i ∈ for a functor to preserve products. In the next section we see how these conditions are enough to ensure preservation of limits in the general case. In a category with terminal object we use ! : c to denote the unique arrow from c to . > →> > Remark 4.4.1 In a category with a terminal object the pair C > (id :x x, !:x ) → →> defines a unique mediating arrow m:x x such that the diagrams → ×> m / m / x x x x ×> ×> id π˜x ! π˜     > x / x / id > id > commute where (˜πx, π˜ ) is the chosen product. It immediately follows that m is an isomorphism since > π˜x m = id ◦ by the left diagram, and then

π˜x m π˜x =˜πx ◦ ◦ which by uniqueness of the identity as mediating arrow implies

m π˜x = id. ◦ Thus by Corollary 4.1.2 and the squares above the pair

(id :x x, !:x ) → →> is a product. 4.4. Products 61

Proposition 4.4.2 Let , be categories with finite products. The functor G : preserves binary productsC D if C→D 1. G preserves terminal objects and 2. there is a section-retraction pair

sx,y / G(x y) o C G(x) G(y) × rx,y ×

natural in x, y (here we mean both s and r are natural). ∈C Proof. There is a morphism idx !:x y x in . This morphism defines the commuting squares in the diagram× × → ×> C

sx,y / G(x y) o C G(x) G(y) t × × MM tt rx,y MMπ G(πxt)t MMG(x) t G(idx !) G(idx) G(!) MM tt × × MM ty  sx, /  & o > / G(x) G(x )o C G(x) G( ) G(x). G(˜πx) π˜G(x) ×> rx, × > > The left triangle commutes since it is obtained by applying G to the commuting triangle x y yy × πx yy yy idx ! yy  × o|y x x . π˜x ×>

By Remark 4.4.1 the morphismπ ˜x is an isomorphism and then G(˜πx)isaniso- morphism as well. The right triangle commutes by similar reasons. By assumption G( ) is a terminal object and from Remark 4.4.1 the arrowπ ˜G(x) is an isomorphism. Thus> the compositions

1 1 s0 =˜πG(x) sx, G(˜πx)− and r0 = G(˜πx) rx, π˜− ◦ > ◦ ◦ > ◦ G(x) give a section-retraction pair such that the squares in

sx,y / G(x y) o C G(x) G(y) × rx,y ×

G(πx) πG(x)  s0 /  G(x) o C G(x)

r0 commute. We can follow the same argument with y instead of x. Then by Propo- sition 4.1.1 the pair (G(πx),G(πy)) is a product. Notice that the mediating arrow defined by (G(πx),G(πy)) is an isomorphism and does not necessarily coincide with sx,y.  An instance of this proposition is obtained by replacing the section-retraction pair by a natural isomorphism in x, y. In the example of the category Count of countable infinite sets there is no terminal object, moreover any choice for isomor- phisms would not give a natural family and then the result above cannot be applied. We generalise the last proposition to K-products where the naturality of the retract is required within a subcategory [K, ] of tuples. K⊆ C 62 Chapter 4. Preservation of Limits

Theorem 4.4.3 Let K be a discrete category and , be categories with terminal object. Let [K, ] be a full subcategory of K-tuplesC D such that for every tuple K⊆ C x = xk k K we have that all the K-tuples obtained by fixing one component h i ∈ ∈K of x,sayxi, and replacing the rest by are in . For example, for a K-tuple > K xk k then (x1, ,..., ) ,( ,x2,..., ) and so on. The functor Gh : i ∈Kpreserves K>-products> ∈K of tuples> in if > ∈K C→D Q K Q 1. whenever k K xk exists in where xk k then k K G(xk)existsin , ∈ C h i ∈K ∈ D 2. G preserves terminal objects and

3. there is a section-retraction pair

s x Q h kik / Q C G( k K xk) o k K G(xk) ∈ r x ∈ h kik

natural in xk k . h i ∈K Proof. This just generalises the proof of the proposition above to K-products of tuples within . It follows by fixing one component at a time and mapping all other componentsK to the terminal object .  > Observe that this result can be applied for the subcategory diag[K, ] [K, ]of tuples for which the product exists in . This follows from the fact thatC products⊆ C for C tuples of the form ( ,..., ,xi, ,..., )existin and then they are in diag[K, ] as required. In the> next section> > we use> this resultC in the special case where theC section-retraction pairs are natural isomorphisms.

4.5 General Limits

A limit can be expressed in terms of conceptually simpler ones as for instance a product of equalisers. Another way is based on the connected components of the index category. P I I I K Proposition 4.5.1 Let = k K k be a small category with k, k ,its connected components. There is an∈ isomorphism ∈  Y  [I, ] H, F = [Ik, ] H ιk,F ιk C ∼ C ◦ ◦ k K ∈ natural in H, F [I, ]whereιk:Ik Iis the inclusion functor. ∈ C → Proof. The isomorphism takes a natural transformation α : H F and splits it ⇒ in the natural transformations αιk : H ιk F ιk. Conversely a collection of ◦ ⇒ ◦ natural transformations βk : H ιk F ιk k K gives a natural transformation β : H F . This constructionh is clearly◦ ⇒ a bijection◦ i ∈ and it is preserved through pre- and post-composition⇒ and thus is natural in both variables. 

P I I I K Proposition 4.5.2 Let = k K k be a small category with k, k ,its connected components. Let D :I ∈ be a small diagram. There is an isomorphism∈ →C f Y limID = limI (D ιk) ∼ k ◦ ←− k K ←− ∈ 4.5. General Limits 63 such that the diagram Q f limID k K limI (D ιk) ∼= ∈ k ◦ ←− ←− πk  ε i limI (D ιk) k ◦ ←− k γi   D(i) id D(i) ∼= k commutes for every i Ik where ε is the limiting cone associated to lim D, γ is ∈ I the limit cone associated to limI (D ιk)andπk is the projection associated←− to the k ◦ product. ←− Proof. From Proposition 4.5.1 there is an isomorphism  Y  [I, ] ∆c, D = [Ik, ] ∆c, D ιk C ∼ C ◦ k K ∈ natural in c. Hence,  Y  [I, ] ∆c, D = [Ik, ] ∆c, D ιk C ∼ C ◦ k K Y∈  = c, limI (D ιk) by definition of limit, ∼ C k ◦ k K ←− ∈ Y  = c, limI (D ιk) since hom-functor preserves limits, ∼ C k ◦ k K ←− Q ∈ and thus k K limI (D ιk) is a limit for D. The commutativity of the diagram k ◦ follows by the∈ definition←− of the counit of this representation:

/ / k id πk k K γ ∆πk k . h i ∈ h ◦ i 

The task now is to combine the results on products (Theorem 4.4.3) and on connected diagrams (Theorem 4.3.2) to treat preservation of more general limits. In order to do so we need two embeddings of functor categories which preserve naturality. Assuming has terminal object , the first embedding is the right C > adjoint of ιk: ◦ ιk ◦ / [I, ] o [Ik, ] . (4.4) ⊥ C + C

+ Given H :Ik , the functor H :I is such that acts as H over the component →C →C Ik and as the constant functor ∆ otherwise. The unit of the adjunction above is defined for D [I, ]as > ∈ C( I idD(i) if i k (ηD) = ∈ i ! otherwise (the unique arrow from D(i)to ) > which is clearly universal.

Proposition 4.5.3 Let Ik be a connected component of I. Given categories and with terminal objects and a functor G : that preserves terminal objects.C D C→D For every connected component Ik of I: 64 Chapter 4. Preservation of Limits

1. there is an isomorphism lim H+ = lim H,and I ∼ Ik ←− ←− + 2. there is an isomorphism limIG H = limI G H. ◦ ∼ k ◦ ←− ←− In both cases we mean that if one side of the isomorphism exists then so does the other. The isomorphisms are natural in H for a subcategory [Ik, ]such that is -complete. ∈K K⊆ C C K Proof. For 1 consider the chain of isomorphisms  (c, lim H+) = [I, ] ∆c, H+ by definition of limit, C I ∼ C  ←− = [Ik, ] (∆c) ιk,H by the adjunction (4.4), ∼ C ◦ =[Ik, ] ∆c, H , C all natural in c and H . Then by definition lim H+ is a limit for H and then ∈K I there is an isomorphism ←− lim H+ = lim H I ∼ Ik that from parametrised representability←− (Theorem←− 2.1.6) is natural in H . For 2 observe that since G preserves the terminal objects it is possible∈K to define + + an adjunction as (4.4) with as codomain where G H ∼= (G H) .Thuswe have D ◦ ◦  (d, lim G H+) = [I, ] ∆d, G H+ by definition of limit, D I ◦ ∼ D ◦  ←− = [I, ] ∆d, (G H)+ ∼ D ◦  = [Ik, ] (∆d) ιk,G H by the adjunction (4.4), ∼ D ◦  ◦ =[Ik, ] ∆d, G H . D ◦ Then lim G H+ is a limit for G H and then there is an isomorphism I ◦ ◦ ←− + limIG H = limI G H ◦ ∼ k ◦ ←− ←− natural in H as well. 

There is a less obvious embedding ∆∆:[K, ] [I, ]whereKis the discrete category whose objects are identified with theC connected→ C components of I.Given a tuple xk k K, the functor ∆ xk k K : I acts as the constant ∆xk over the h i ∈ h i ∈ →C objects and arrows in Ik. P I I Proposition 4.5.4 Let G : be a functor and = k K k be a small C→D ∈ category with Ik, k K, its connected components: ∈ Q 1. there is an isomorphism limI∆ xk k K = k K xk,and h i ∈ ∼ ∈ ←− Q 2. there is an isomorphism limIG ∆ xk k K = k K G(xk). ◦ h i ∈ ∼ ∈ In both cases we mean that if← one− side of the isomorphism exists then so does the other. The isomorphisms are natural in xk k for a subcategory of K-tuples [K, ]suchthat is -complete. h i ∈K K⊆ C C K Proof. For 1  (c, lim ∆ xk k K) = [I, ] ∆c,∆ xk k K by definition of limit, C I h i ∈ ∼ YC h i ∈ ←−  = [Ik, ] ∆c ιk,∆ xk k K ιk by Proposition 4.5.1, ∼ C ◦ h i ∈ ◦ k K Y∈  = [Ik, ] ∆c, ∆I xk by definition of ∆∆, C k k K ∈  =[K, ] ∆c, xk k K . C h i ∈ 4.5. General Limits 65

Q Then lim ∆ xk k K is isomorphic to k K xk = lim xk k K and naturality follows I h i ∈ Kh i ∈ from parametrised←− representability. In a∈ similar← way− by using the identity G ∆x =∆G(x) ◦ we can prove 2. 

Theorem 4.5.5 Let , be complete categories. A functor G: is continu- ous if and only if for anyC D small category I there is an isomorphismC→D G(lim D) = lim (G D) (4.5) I ∼ I ◦ ←− ←− natural in D [I, ]. ∈ C Proof. The “only-if” follows as usual. Now for the “if” part first observe that G triviallyP preserves terminal objects: take I to be the empty category. Let I I I K = k K k be a non-empty small category with k, k , its connected com- ponents.∈ Given a diagram D : I and a limiting cone∈ ε : ∆lim D D from →C I ⇒ Proposition 4.5.2 there is an isomorphism ←−

f Y limID = limI (D ιk) ∼ k ◦ ←− k K ←− ∈ such that for every i I ∈ k εi = γ πk f i ◦ ◦ k where γ is the limiting cone associated to limI (D ιk). In order to prove that Gε k ◦ is limiting by Corollary 4.1.2 is enough to verify←− that the cone defined at component i Ik by the arrow ∈ k G(γ ) G(πk) i ◦ is limiting. This is equivalent to requiring that G(πk) k K is a product and that k h i ∈ for every Ik the natural transformation Gγ is a limiting cone. Given a family of arrows αk : xk xk0 k K (i.e. a natural transformation h → i ∈ α : xk k x0 k in [K, ]) there is a diagram h i ⇒h ki C Q Q o = = / = / G( x ) ∼ G(lim ∆ xk k) ∼ lim (G ∆ xk k) ∼ G(x ) k K k I h i I ◦ h i k K k ∈ ←− ←− ∈

G( αk k) (1) G(lim ∆α) (2) lim (G(∆∆α)) (3) G(αk) k h i I I h i Q  ←− ←−  Q  o = = / = / G( x ) ∼ G(lim ∆ x0 k) ∼ lim (G ∆ x0 k) ∼ G(x ) k K k0 I h ki I ◦ h ki k K k0 ∈ ←− ←− ∈ where (1) and (3) commute by Proposition 4.5.4 and (2) is a naturality square defined by (4.5). Thus by pasting the squares we have that there is an isomorphism Y Y G( xk) ∼= G(xk) k K k K ∈ ∈ natural in xk k. Then by Theorem 4.4.3 G preserves K-products and G(πk) k K above is a product.h i h i ∈ Given a natural transformation β : H K for functors H, K :Ik there is a diagram ⇒ →C

o ∼= + ∼= / + ∼= / G(limI H) G(lim H ) lim (G H ) limI (G H) k I I ◦ k ◦ ←− ←− ←− ←− G(lim β) + + lim Gβ I (1) G(lim β ) (2) lim (Gβ ) (3) I k I I k ←−  ←− ←−   ←− o ∼= + ∼= / + ∼= / G(limI K) G(lim K ) lim (G K ) limI (G K) k I I ◦ k ◦ ←− ←− ←− ←− 66 Chapter 4. Preservation of Limits where (1) and (3) commute by Proposition 4.5.3 and (2) is a naturality square defined by (4.5). Thus by pasting the squares we have that there is an isomorphism

limI (G H) = G(limI H) k ◦ ∼ k ←− ←− k natural in H [Ik, ]. Thus by Theorem 4.3.2 G preserves Ik-limits and G(γ ) ∈ C above is a is a limit for G(D ιk).  ◦ Consider the full subcategory of diagrams diag[I, ] [I, ] for which all limits C ⊆ C exist in . For every connected component Ik of I define k [Ik, ] to be the full C K ⊆ C subcategory induced by the diagrams of the form D ιk for some D diag[I, ]. Given a diagram D diag[I, ] by Proposition 4.5.2 there◦ is a isomorphism∈ K ∈ C Y

limID = limI (D ιk) ∼ k ◦ ←− k K ←− ∈ and thus D ιk has limit in andthenisanobjectofdiag[Ik, ]. Given a diagram ◦ C + C H diag[Ik, ] by Proposition 4.5.3 we have that H diag[I, ] and moreover +∈ C ∈ C H ιk = H. This correspondence is one-to-one and then there is an isomorphism of categories◦ k = diag[Ik, ]. K ∼ C Notice that probably not all K-products exist in , but by Proposition 4.5.2 we can ensure that at least the subcategory diag[K, ]ofC K-tuples whose product exist in includes the tuples needed to reconstruct theC limits for the diagrams in diag[I, C]. Then we can relax the completeness condition in Theorem 4.5.5: D P I I I K Theorem 4.5.6 Let = k K k be a small category with k, k , its connected components. A functor G: ∈ preserves the limits of the diagrams∈ in diag[I, ] if C→D C

1. G D has a limit in for every D diag[I, ], ◦ D ∈ C 2. G preserves terminal objects, and

3. lim (G D) = G(lim D) natural in D diag[I, ]. I ◦ ∼ I ∈ C ←− ←− Proof. The proof follows as in the Theorem 4.5.5 but within the categories diag[Ik, ] for each k K and diag[K, ]. Given that G preserves terminal objects we can applyC Propositions∈ 4.5.3 and 4.5.4.C 

4.6 Some Examples 4.6.1 Adjunctions and limits The relation between limits and adjunctions is determined by the preservation prop- erties of left and right adjoints.

Proposition 4.6.1 Given an adjunction and diagram H as in

F / o H o I. ⊥ C G D

If H has a limit in then the functor G H :I has a limit in . D ◦ →C C 4.6. Some Examples 67

Proof. The limit for G H is just given by G(lim H): ◦ I   ←− c, G(lim H) = F (c), lim H by the adjunction, C I ∼ D I  ←− = lim F←(c−),H( ) by Propositions 2.2.8 and pointwise computation, ∼ ID  = lim←− c, (G H)( ) by the adjunction, ∼ IC ◦  = ←−c, lim (G H)( ) by Propositions 2.2.8 and pointwise computation, ∼ C I ◦  = [I, ]←∆−c, G H by definition of limits, ∼ C ◦ all natural in c. 

Theorem 4.6.2 Right adjoints are continuous functors.

Proof. A direct consequence of the proof of the proposition above. The counit of the representation is given by / / / id ε γi ε G(γi) i ◦ h i where ε is the counit of the adjunction and γ is the universal cone associated to lim H. Observe that if has terminal object by Theorem 4.5.5 the proposition I C above←− is enough to prove the theorem since the chain of isomorphism is natural in H diag[I, ] as well.  ∈ C By duality the discussion on preservation of limits in this chapter exports to colimits. Of course the condition on preservation of terminal objects is substituted by the preservation of initial objects. The dual of Theorem 4.6.2 says that left adjoints preserve colimits. The Fubini theorem gives a sense for which the formation of limits preserve universal properties. In a category with enough limits there is limit functor, and the Fubini result establishes that this functor preserve limits. This is consistent with the definition of limits as a representation where for a complete category the isomorphism (c, lim D) = [I, ](∆c, D) C I ∼ C ←− is natural in c and D defining an adjunction ∆ lim . As a right adjoint the ` I functor limI preserves limits. By a dual argument← the− functor colimI preserves colimits.←−

4.6.2 Profunctors ForafunctorF:C where is cocomplete there is a functor →D D F :[Cop, Set] ! →D where F! is the left Kan extension of F along the Yoneda embedding, i.e. R F = λG. x[Cop, Set](C( ,x),G) F(x) by (3.14), ! R R ⊗ = λG. x [C(y,x),G(y)] F (x) by naturality formula, R y ⊗ = λG. x G(x) F (x) by the Yoneda lemma. ⊗ I The functor F! preservesR colimits: for a diagram D : Set for convenience we y → write colimID as D(y) where the contravariant argument is dummy. The result 68 Chapter 4. Preservation of Limits follows from R R R F ( y D(y)) = x( y D(y))(x) F (x) by definition of F , ! R R ! x y ⊗ = G (y) F (x) by pointwise computation where G = λ 1(D), ∼ R R x − y x ⊗ = Gx(y) F (x) by Fubini for coends, ∼ R ⊗ = y F (Gy) by definition of F , R ! ! y = F!(D(y)).

In fact the functor F! is a left adjoint where the right adjoint is given by

F ! = λy.λx. (F (x),y). D In the special case where is a presheaf the functor F ! has a right adjoint itself given by the right Kan extensionD of F . This is an example of geometric morphism between topoi [MM92,Joh02]. By the density formula there is an isomorphism R y F = λx. F (y) C(y,x) = F . ∼ ⊗ ∼ ! ◦Y op In fact F! is unique with this property exhibiting the category of presheaves [C , Set] as a concrete colimit completion of C. More formally, for any functor F : C →D where is a category with all colimits F! is the unique up to isomorphism colimit- preservingD functor such that the diagram

/ op C HHY [C , Set] HH HH HH F HH ! F H$  D commutes. It remains to check uniqueness. Suppose that H :[Cop, Set] is a Cop →D colimit-preserving functor such that H ∼=F.ThenforG: Set R ◦Y → x H(G) = H λy. G(x) C(y,x) by density formula, ∼ R  x ⊗ = H G(x) (x) by componentwise computation, ∼ R x ⊗Y = G(x) H( (x)) since H preserves colimits, ∼ R x ⊗ Y = G(x) F (x) since H =F ∼ ⊗ ◦Y ∼ ∼=F!(G) by definition of F!, then H ∼= F!. Presheaf categories can be organised themselves in a 2-category. The objects of this category are presheaves and since they are free cocompletions the obvious choices for the arrows are the cocontinuous functors and the two-cells are the cor- responding natural transformations. This category is referred in the literature as Cocont [Cat99, CW]. As presheaves are colimit completions, a functor

[Cop, Set] /[Dop, Set] corresponds to a functor C /[Dop, Set] and then to a functor C Dop /Set × 4.6. Some Examples 69 a so-called (distributor [Bor94a, B´en00], bimodule [Wag96]) from C to D. Profunctors are morphism of the category Prof where objects are small categories. The composition of profunctors is defined by the coend formula R G F = λc, i. x F (c, x) G(x, i). ◦ ⊗ Since universal properties are unique up to isomorphism from this definition the composition is not strictly associative. A categorical structure of this form is called a bicategory [B´en78, Lei]. If presheaves are often regarded as sets with extra structure, then profunctors correspond to relations [Law73,Bor94a]. In computer science there is another anal- ogy of Prof as a category of non-deterministic domains [Cat99, CW] which comes equipped with a built-in notion of bisimulation given by open maps [JNW96]. In this approach constructions on presheaves correspond to power domain construc- tions. A central result in this theory of domains for concurrency is that connected colimit-preserving functors between presheaves preserve open-map bisimulation. 70 Chapter 4. Preservation of Limits Chapter 5

A Term Calculus for Functors

In this chapter we present a typed language for categories based on the functorial expressions used along the previous chapters. The syntax for functors extends the simply typed lambda calculus with new binders for ends and coends and term constructors for hom-functors, powers and copowers. The types of the language correspond to locally small categories and a derivation for a well-typed expression is interpreted as a functor in CAT. The calculus supports a syntactic treatment of duality which allows us to derive a functor F from its dual version F op. This formalisation of duality results in a non-standard notion of substitution for terms. The proof system includes explicit structural rules to manipulate contexts. As a consequence well-typed expressions can be proved in the theory through different derivations. We show the syntax is coherent with respect to the interpretation up to natural isomorphism.

5.1 The Language

5.1.1 Basic Types Types in the language denote locally small categories. We consider a basic set of type constructors necessary to present the core syntax for terms. In the presentation of the language we deliberately confuse “types” with “categories”. There is a type Set to denote the category of sets and functions. Given the categories and C D the opposite category op is the category whose objects are the objects of • and whose arrows are theC arrows in reversed, i.e. op(a, b)= (b, a) for anyC pair of objects a, b;and C C C

the functor category [ , ] is the category of functors from to and the • natural transformationC betweenD them where must be small.C D C The syntax for types , ,... as locally small categories is C D , ,...::= Set op [ , ]. C D |C | C D In order to properly introduce functor categories we must be able to decide whether a category is small. Similarly the rules for limits and ends shall require to decide if a category is complete. We assume that when talking about types there are judgements of form small and complete. C D

71 72 Chapter 5. A Term Calculus for Functors

5.1.2 Syntax and Type Theory The language for expressions extends the simply typed λ-calculus `a la Church [Bar92] with new constructions and binders. The treatment of contravariance and duality determines a non-standard definition of substitution. The system is shown to be closed under substitution. Finally we define a normal form for derivations where the use of duality is permitted only in the essential cases. The raw expressions E ,E , of the language for functors are defined by 1 2 ···

E ::= x 1 λxC .E E E (E ,E ) [E ,E ] E E | | | 1 2 |C 1 2 | 1 2 | 1 ⊗ 2 | R R Cop C x ,y Cop C E E x ,y | where , are types, and x is drawn from a countably infinite set of variables. The constantC D 1 stands for the singleton set. The “integral” binders denote ends and coends as expected. There are also special syntactic constructors for hom- expressions, powers and copowers. Not all possible expressions in the language give rise to functors. Furthermore the formation of functor categories and the computation of ends are restricted to small categories. These constraints impose a discipline to determine the well-typed expressions, i.e. expressions which are functorial in their free variables. The syntactic judgement or sequent

x : , ,xn: n E: 1 C1 ··· C ` C says that the expression E of type is functorial in the free variables occurring in the C context x : , ,xn: n. In informal mathematical usage one says E(x , ,xn) 1 C1 ··· C 1 ··· is functorial in x1, ,xn. Thus an expression-in-context has two possible readings: as an object when the··· free variables are interpreted as objects, and as an arrow when the free variables are interpreted as arrows. Of course this is consistent with the definition of functor. A context is a finite sequence of variable declarations. The typing rules are given in a context-independent presentation [TS00, Remark 3.1.5], which simplifies the form for the rules which involve contravariance. As usual we assume that different contexts have a disjoint set of variables, and the notation Γ,z: assumes that the variable z is not in Γ. C

Basic Axioms

singleton

1:Set ` identity

x: x: C` C

Structural Rules

weakening x : , ,xn: n E: 1 C1 ··· C ` C x : , ,xn: n,xn : n E : 1 C1 ··· C +1 C +1 ` C 5.1. The Language 73

exchange x : , ,xi: i,xi : i , ,xn: n E: 1 C1 ··· C +1 C +1 ··· C ` C x : , ,xi : i ,xi: i, ,xn: n E: 1 C1 ··· +1 C +1 C ··· C ` C

contraction Γ,x: ,y: E: C C` D Γ,z: E[z/x,z/y]: C` D

The structural rules play an important role in the proof of coherence and later in the enriched setting. The expression E[z/x,z/y] in the rule contraction denotes the expression E where all occurrences of x and y are replaced by z with the usual treatment of bound variables. A special notion for substitution of terms for variables is later required for the most general case. The structural rules can be absorbed if the axioms above are replaced by

x: Γ C∈ and Γ x: Γ 1:Set, ` C ` (refer to [Gir87,TS00,RS92,Bar92]). In the case of exchange is enough to consider the contexts to be multisets of variables declarations instead of sequences.

Hom-sets and Powers

The type Set has a special role as the base type for hom-expressions: hom Γ E : Γ E : 1 ` 1 C 2 ` 2 C Γop, Γ (E ,E ):Set. 1 2 `C 1 2 In general Γop denotes the context obtained from Γ where each occurrence of a type is replaced by op. We insist, also in the syntax, that ( op)op = . For instance, givenC the contextC C C Γ=x: ,y: op C D we have Γop = x: op,y: . C D This rule captures the usual practice in category theory where the contravariance in the first argument of (E ,E ) is reflected in the free variables rather than dualising C 1 2 the expression E1. If is complete then it has all powers: C power Γ E :Set Γ E : complete 1 ` 1 2 ` 2 CC Γop, Γ [E ,E ]: . 1 2 ` 1 2 C This rule asserts that the power is functorial in all free variables. In the special case of the type Set we have both

. . . . Γ E : Set Γ E :Set 1 ` 1 2 ` 2 Γop, Γ Set(E ,E ):Set 1 2 ` 1 2 74 Chapter 5. A Term Calculus for Functors and . . . . Γ E :Set Γ E :Set Set complete 1 ` 1 2 ` 2 Γop, Γ [E ,E ]:Set 1 2 ` 1 2 to keep with practice we identify these two expressions in the syntax

Set(E1,E2)=[E1,E2].

Functor Categories The rule for lambda abstraction introduces functor categories: lambda Γ,x: E: small C` DC Γ λxC .E :[ , ]. ` C D The side condition “ small” ensures the new type stays in the realm of locally small categories. SometimesC in order to simplify the notation we write C to mean the category is proved to be small. In general the type [ , ] implicitly assumes that small. C D C There is a symmetric rule for eliminating functor categories: application Γ E :[ , ]Γ E: 1 ` 1 C D 2`2C Γ,Γ EE:. 1 2`1 2D Ends The “integral” binder captures two variables at once in the expression under its scope. In the terminology of binder signatures [Plo90, FPT99] the integral is an operation of arity 2 (whereas lambda abstraction has arity 1 ). end h i h i Γ,x: op,y: E: small complete C C` RDC D Γ op E : . ` xC ,yC D The orderR of the variablesR in the binder is immaterial, thus there is no difference between op E and op E. This notation for ends, a bit more formal that xC ,yC yC,xC the notation used in the previous chapters, allows us to keep track of variance and the type of the bound variables. The rule end says that the process of taking ends (or limits) does not disturb functoriality on the variables which remain free. The completeness requirement over ensures that for all instances of the free parameters D the end exists. The integral notation is alsoR used for denoting limits by omitting the dummy argument, we use for instance E. We could here introduce the rule yC for coends, instead we show how the rules above together with a simple rule for duality is enough to derive the formation for coends and copowers. From the point of view of the logic the rule end can be regarded as a structural rule since at the level of types it only involves the manipulation of the assumptions. On the other hand it introduces a new element in the syntax. A similarly situation is found in some linear calculus where the structural rules are represented explicitly in the syntax [BBdPH93,Bie95].

Duality Like reflection in a mirror, dualising affects our view of things and the way we describe them. Informally a judgement Γ E : denotes a functor whose dual is described by a dual form of judgement: ` D 5.1. The Language 75

dual Γ E : ` D op op Γ E∗ : ` D where E∗ is obtained by turning ends into coends and coends into ends in E,and similarly for prowers and copowers.

Definition 5.1.1 The meta-operation ( )∗ on raw expressions is defined induc- tively as follows:

x∗ = x (x is a variable) 1∗ =1 op (λxC .E)∗ = λxC .E∗ (E1E2)∗ = E1∗E2∗ (E ,E )∗ = (E∗,E∗) C 1 2 C 1 2 [E1,E2]∗ =E1 E2∗ (E1 E2)∗ =[E1,E2∗] R R ⊗op R op⊗ R yC ,xC xC ,yC ( op E)∗ = E∗ ( E)∗ = op E∗. xC ,yC yC ,xC

For example, taking the judgement R z : Cop C E : A` x ,y D the application of the rule dual yields

R Cop C op y ,x op z : E∗ : A ` D where E is an expression with free variables amongst x, y, z. For another example consider the judgement x: op,y: (x, y):Set C C`C by applying the rule dual we obtain x: ,y: op (x, y):Setop C C `C where the covariance of x and contravariance of y reflect the change of orientation of the morphisms in Setop.

Proposition 5.1.2 Given a raw expression E we have  E∗ ∗ = E. Proof. By induction on the structure of E. The two base cases, x and 1, are straightforward. The same goes for application and hom-expressions where the inductive hypothesis is applied directly. For lambda abstraction we need to adjust the type of the bound variable by using (Cop)op = C. For ends it follows that

R  R Cop C R y ,x ∗ ( xCop ,yC E)∗ =( E∗)∗ = xCop ,yC (E∗)∗.

By inductive hypothesis (E∗)∗ = E and R  R ∗ ( xCop ,yC E)∗ = xCop ,yC E. In a similar way the proposition is proved for coends, powers and copowers. 

A simpler aspect of duality involves assertions on types. As there is a judgement for “completeness”, by duality there is a judgement for “cocompleteness” and the rules: complete cocomplete D D op cocomplete op complete. D D 76 Chapter 5. A Term Calculus for Functors

Coends and Copowers

We can now derive the rule end∗ for typing coend expressions: Γ,x: op,y: E: cocomplete C C` D dual + exchange D op op op op Γ ,y: ,x: E∗: small complete C C` D R C D end op op Γ op E∗ : ` yC ,xC D dual R op Γ xC ,yC E : . Observe that in the last application` of dual weD use the identities

R  R Cop C op op op op x ,y (Γ ) =Γ ( ) = Cop C E∗ ∗ = E D D y ,x the last one justified by Proposition 5.1.2. Similarly we can derive the rule power∗ for copowers:

Γ2 E2 : cocomplete ` D dual D op op op Γ1 E1 :Set Γ2 E2∗ : D complete ` ` D power op op op Γ1 , Γ2 [E1,E2∗]: ` D dual Γ , Γ E E : . 1 2 ` 1 ⊗ 2 D

Through duality the derived rule power∗ respects the expected functorial behaviour on the free variables in E1 (see 3.4). This complete the typing rules for all the possible expressions.

5.1.3 Substitution The simply typed lambda calculus is closed under substitution. This result corre- sponds via the Curry-Howard correspondence [How90,SU99] to the cut-elimination for the minimal intuitionistic sequent calculus. In our setting due to contravariance substitution takes a novel definition. As an example let us consider the usual context-independent rule for substitution in lambda calculus (see [Bar92, VW01, TS00]):

Γ1,x: E1: Γ2 E2: C` D ` C (5.1) Γ,Γ E[E/x]: 1 2` 1 2 D where E1[E2/x] represents the expression E1 where all the occurrences of x are replaced by E2 (taking care of renaming of bound variables if necessary). As the following example shows this definition is not suitable in the presence of contravari- ance. Consider the following instances for the premises of the rule (5.1) R op op y : ,x: (x, y):Set Γ0 Dop D E : . C C `C ` z ,w C The corresponding conclusion is R y : , Γ0 ( Dop D E,y):Set. C `C z ,w Notice that this does not keep with practice in category theory where an expression occurring on the left of a hom-expression is implicitly dualised. Concretely, the sequent R Dop D w ,z y : , Γ0 ( E∗,y):Set C `C 5.1. The Language 77 conforms this view where the contravariance of the first argument is reflected by keeping the now contravariant context Γ0.

Definition 5.1.3 (Substitution) Given raw expressions E1 and E2 the expres- sion E1[E2/x] is defined inductively over the structure of E1 as follows:

x[E2/x]=E2 y[E /x]=yx=y, 2 6 1[E2/x]=1

(λxC .E)[E2/x]=λxC .E

(λyC.E)[E /x]=λxC .E[E /x] x = y, 2 2 6 (E E )[E /x]=(E[E /x])(E [E /x]) 0 00 2 0 2 00 2  (E0,E00)[E /x]= E0[E∗/x],E00[E /x] RC 2 CR 2 2 ( op E)[E2/x]= op Ex=wor x = y, RwC ,yC RwC ,yC ( op E)[E2/x]= op E[E2/x] x = w and x = y, wC ,yC wC ,yC 6 6 R op R op wC ,yC wC ,yC ( E)[E2/x]= Ex=wor x = y, R op R op ( wC ,yC E)[E /x]= wC ,yC E[E /x] x = w and x = y, 2 2 6 6 (E0 E00)[E /x]=E0[E /x] E00[E /x] ⊗ 2  2 ⊗ 2  ([E0,E00])[E2/x]= E0[E2∗/x],E00[E2/x]

The special cases are for hom-expressions and powers where the contravariance on the first argument is reflected by dualising the expression to be substituted in. This definition can be extended in the usual way to simultaneous substitution over multiple variables.

As a consequence of Proposition 5.1.2 the substitution E1[E2/x] replaces the occurrences of the free variable x on the left in an odd number of hom-expressions or powers by E2∗ and other occurrences by E2. For example

op op [Cop, Set](λyC .C(y,x),λyC .Cop(x, y))[E/x] op  =[Cop, Set] (λyC .C(y,x))[E /x], (λyC.Cop(x, y))[E/x] ∗  op Cop Cop op =[C , Set] λy .C(y,x[E∗/x]),λy .C (x[E∗/x],y) op Cop Cop op =[C , Set](λy .C(y,E∗),λy .C (E∗,y)) where both occurrences of x are on the left of a hom-expression once.1 Another interesting example is   [ (c, x),x][E/x]= (c, x)[E∗/x],x[E/x] C C =[ (c, x[E∗/x]),E] C =[ (c, E∗),E] C showing that different occurrences for the same variable can be substituted by dif- ferent expressions.

Proposition 5.1.4 Given raw expressions E1 and E2 we have  ∗ E1[E2/x] = E1∗[E2∗/x].

1The expression in this example does not type in the calculus, see page 81. 78 Chapter 5. A Term Calculus for Functors

Proof. By induction on the structure of E1. The base cases are given by 1 which follows trivially and by variables, the only interesting case being

(x[E2/x])∗ = E2∗ = x[E2∗/x]=x∗[E2∗/x]. For the inductive step we consider the special cases, i.e. hom-expressions, powers and integrals, for the other constructions the result follows in a similar manner:

E = (E0,E00) • 1 C      ∗ ∗ E0,E00 [E2/x] = E0[E2∗/x],E00[E2/x] C C  = (E0[E∗/x])∗, (E00[E /x])∗ C 2 2  = (E0)∗[E /x], (E00)∗[E∗/x] by hypothesis and Proposition 5.1.2, C 2  2 = (E0)∗, (E00)∗ [E∗/x] by Proposition 5.1.2, C  2 = (E0,E00) ∗[E∗/x] C 2

E =[E0,E00] • 1     ∗ ∗ [E0,E00][E2/x] = E0[E2∗/x],E00[E2/x]

= E0[E∗/x] (E00[E /x])∗ 2 ⊗ 2 = E0[E∗/x] (E00)∗[E∗/x] by hypothesis, 2 ⊗  2 = E0 (E00)∗ [E∗/x] ⊗ 2 =([E0,E00])∗[E2∗/x] by Proposition 5.1.2. R E Cop C E0 • 1 ≡ x ,y R  R  ∗ C ∗ ( wCop ,yC E0)[E2/x] = wCop,y E0[E2/x] R Cop C y ,w = (E0[E2/x])∗ R Cop C y ,w = (E0)∗[E2∗/x] by induction hypothesis, R Cop C =( y ,w (E ) )[E /x] R 0 ∗ 2∗ ∗ = wCop ,yC E0 [E2∗/x].

R Cop C x ,y Dually the proposition holds for E E0. 1 ≡ 

By Proposition 5.1.2 an immediate corollary is that   ∗ ∗ E1[E2∗/x] = E1∗[E2/x]and E1∗[E2/x] = E1[E2∗/x].

Theorem 5.1.5 The rule

Γ,x: ,Θ E : Ξ E : C ` 1 D ` 2 C Γ,Ξ,Θ E [E /x]: ` 1 2 D where E1[E2/x] is defined as in 5.1.3 is admissible inthetypetheory. 5.1. The Language 79

Proof. It follows along the lines the proof of cut-elimination for sequent calculus by Girard [Gir87]. The proof proceeds by propagating the use of substitution to- ward the axioms in a derivation by means of local transformations. This is done inductively on the derivation for the sequent

. . Γ,x: ,Θ E : . (5.2) C ` 1 D Thebasecaseisgivenbytheaxioms,foridentity the result is proved by the derivation . . Ξ E : ` 2 C since x[E2/x]=E2.Inthecaseofsingleton the result is trivial. For the induction step in most of the cases the hypothesis can be applied di- rectly. The exception is the rule for contraction, the standard procedure here is to strengthen the induction hypothesis to consider a multiple simultaneous sub- stitution or “multicut” [TS00, VW01] (for other solutions to this problem refer to [Bus98, vP01]). Let us concentrate on the novel rules. Consider the case where the last rule is

hom (and E = (E0,E00)) • 1 A

. . . .

∆1 E0 : ∆2 E00 : ` A ` A hom Γ,x: ,Θ (E0,E00):Set C `A where Γ,x: ,Θ=∆op, ∆ . Because the rule is context-independent there are C 1 2 only two cases to consider, either x is declared in ∆1 or in ∆2. In the first case there is a context ∆10 such that op op ∆ =Γ ,x: , ∆0 1 C 1 and by induction hypothesis there is a derivation

. . . . Ξ E2 : . ` C dual Γop,x: op, ∆ E : Ξop E : op . 10 0 2∗ . C ` A ` C substitution . op op Γ , Ξ , ∆10 E0[E2∗/x]: ∆2 E00 : ` A ` A hom op Γ, Ξ, (∆0 ) , ∆ (E0[E∗/x],E00):Set 1 2 `A 2 As x is not free in E00 we have that

E00 = E00[E2/x] and then

(E0[E∗/x],E00)= (E0[E∗/x],E00[E /x]) = (E0,E00)[E /x]=E [E /x]. A 2 A 2 2 A 2 1 2 The second case, i.e. x is declared in ∆2, follows similarly and in fact it is simpler since it does not require the use of dual. The case where the last rule is power is analogous. 80 Chapter 5. A Term Calculus for Functors

dual • . . op op op op Γ ,x: , Θ E1∗ : C ` D dual Γ,x: ,Θ E : . C ` 1 D This form for the derivation (5.2) is justified by Proposition 5.1.2. By induc- tion hypothesis there is a derivation

. . . . Ξ E2 : . ` C dual op op op op op op Γ ,x: , Θ E1∗ : Ξ E2∗ : C ` D ` C substitution op op op op Γ , Ξ , Θ E∗[E∗/x]: ` 1 2 D  dual Γ, Ξ, Θ E∗[E∗/x] ∗ : . ` 1 2 D As a corollary of Propositions 5.1.2 and 5.1.4 we have  ∗ E1∗[E2∗/x] = E1[E2/x].



5.1.4 Examples Informally the model of the calculus is that types represent locally small categories and expressions functors. This is enough to see that some of the raw expressions cannot represent functors and then, as expected, the type theory cannot give a derivation for them. The simplest example of a expression with no type is (x, x).2 Trying to produce a derivation for this term would fail in the applicationC of the rule to introduce the hom-expression since it would require x to be declare with a covariant and contravariant type at the same time. This is actually prevented by the context- independent presentation of the rule for hom-expressions. The Yoneda functor embeds a small category C into the presheaf category [Cop, Set]. An expression for this functor is derivable in the type theory:

identity identity y :C y :C x:C x:C ` ` hom + exchange x:C,y:Cop C(y,x):Set ` lambda x:C λyCop .C(y,x):[Cop, Set]. Limits are ends where` the extra contravariant argument is “dummy”. We shall be able to formalise this result in the calculus after introducing the natural isomor- phisms. The “dummy” argument can be modelled through weakening: Γ,x:C E: ` D weakening+exchange Γ,y:Cop,x:C E: R ` D end Γ Cop C E : ` y ,x D 2For a non-trivial category (see the section on products). C 5.1. The Language 81

whereR is complete and C is small. As y is a fresh variable we write this end as D just xC E to emphasise that is a limit. Now we show that the judgement and y :C,x:Cop [C(y,x),x]:Cop ` whose expression was used in previous examples is well-typed: identity identity y :C y :C w:C w:C ` ` hom identity y :Cop,w:C C(y,w):Set z :Cop z :Cop ` ` power (5.3) y :C,w:Cop,z:Cop [C(y,w),z]:Cop ` contraction y:C,x:Cop [C(y,x),x]:Cop. ` An example of a non-derivation is given by3 x:Iop [Iop, Set](λi.I(i, x),λi.Iop(x, i)):Set, ` an attempt to find a derivation yields

identity identity identity i:I i:I y :I y :I z :I z :Iop i:Iop i:Iop ` ` hom+exchange ` ` hom y :I,i:Iop I(i, y):Set z :Iop,i:Iop Iop(z,i):Set ` lambda ` lambda y :I λi.I(i, y):[Iop, Set] z :Iop λi.Iop(z,i):[Iop, Set] ` ` hom y :Iop,z:Iop [Iop, Set](λi.I(i, y),λi.Iop(z,i)):Set ` contraction x:Iop [Iop, Set](λi.I(i, x),λi.Iop(x, i)):Set ` where the judgement z :I z :Iop cannot be simplified further. From the last derivation` for the expression [C(y,x),x] and a derivation . . Γ E :Cop ` we obtain by means of substitution the sequent op x:C, Γ [C(y,E∗),E]:C . ` It is remarkable that in this example the substitution replaces x by different ex- pressions depending on the variance of the occurrence of x. It follows a derivation for the same sequent without using substitution. . . Γ E :Cop identity ` dual C C op C . y : y : Γ E∗ : . ` ` hom . op op op y :C , Γ C(y,E∗):Set Γ0 E0 :C ` ` power op op y :C , Γ, Γ0 [C(y,E∗),E0]:C ` contraction + exchange (many times) op op y:C , Γ [C(y,E∗),E]:C ` 3This was originally presented as a legal derivation in the calculus. Later, Philip Matchett implemented the calculus in the theorem prover Isabelle to find out that the derivation was incorrect. 82 Chapter 5. A Term Calculus for Functors

The context-independent presentation for rules forces us to work modulo renam- op ing of variables (α-conversion). In this example the sequent Γ0 E0 :C represents the sequent Γ E : Cop where free variables were rename to avoid` any clash. Ob- serve that in the` last part of the derivation we obtain the desired result by applying contraction many times. This apparent ad-hoc manipulation of contexts can be formalised by using indexes for variables at the cost of complicating the notation of sequents (see [Jac99]).

5.2 A Normal Form for Derivations

Due to the presence of structural rules and the rule for duality, the same sequent can be proved through different derivations. It is easy to see that by spurious use of the rule dual, for example, we can produce different proofs for any well-typed sequent. In this section we give a general form of derivation which is unique modulo the relative order of the application of the structural rules. This amounts to identifying the non-essential uses of duality and to restrict the use of the structural rules. Then we show that any derivation can be translated into that form. This conforms the syntactic side of the coherence result. We say that the applications of two rules in a derivation are adjacent if they are only separated by the occurrence of structural rules. The proofs in this section proceed inductively on the structure of derivations where we analyse the situation created by each possible rule. In most of the cases we shall neglect the occurrences of exchange. In this spirit we say that an occurrence of a rule is above or below the occurrence of another rule if they are only separated by applications of exchange. We sometimes use the same terminology to refer to blocks of rules.

5.2.1 W-normal Derivations A derivation is in W-normal form if the weakening’s occur in blocks above

1. the final sequent, or

2. the introduction of a binder (lambda or end) where the fresh variable is bound, for example . . Γ E : ` D weakening Γ,x:C E: ` D lambda Γ λxC.E :[C, ] ` D or in the introduction of a limit through an end with a dummy argument.

In this way any variable in the context which is not just introduced by an adjacent occurrence of weakening is either introduced by a use of contraction or can be traced to an axiom.

Proposition 5.2.1 Every derivation can be transformed into a derivation in W- normal form.

Proof. By means of local transformations we show how all the occurrences of the rule weakening violating the conditions above can be permuted below other rules 5.2. A Normal Form for Derivations 83 until they reach a legal position. This operation removes combinations of adja- cent weakening and contraction which are made redundant. To simplify the explanation we fix z of type to be the fresh variable. A contraction • There are two different cases:

1. z is contracted, then the derivation

. . γ Γ,w: E: A` D weakening Γ,w: ,z: E: A A` D contraction Γ,y: E[y/w,y/z]: A` D is converted to just . . γ[y/w] Γ,y: E[y/w]: A` D since z is new and not free in E (this final sequent is equal to the original modulo the renaming given by [y/w]); 2. z is not contracted, and then the derivation

. . Γ,x: ,y: E: C C` D weakening+exchange’s Γ,z: ,x: ,y: E: A C C` D contraction Γ,z: ,w: E[w/x, w/y]: A C` D is converted to

. . Γ,x: ,y: E: C C` D contraction Γ,w: E[w/x, w/y]: C` D weakening+exchange’s Γ,z: ,w: E[w/x, w/y]: . A C` D hom • There are two cases depending on which premise of the rule hom the occur- rence of weakening happens. We consider the case involving contravariance, the other is symmetric. The derivation

. . . Γ1 E1 : . ` C weakening . Γ1,z: E1: Γ2 E2 : A` C ` C hom Γop,z: op, Γ (E ,E ):Set 1 A 2 `C 1 2 84 Chapter 5. A Term Calculus for Functors

is converted to

. . . .

Γ1 E1 : Γ2 E2 : ` C ` C hom op Γ1 , Γ2 (E1,E2):Set `C weakening+exchange’s Γop,z: op, Γ (E ,E ):Set. 1 A 2 `C 1 2 The cases for the rules power and application are analogous. end • The derivation

. . Γ,x:Cop,y:C E: ` D weakening+exchange’s Γ,z: ,x:Cop,y:C E: A R ` D end Γ,z: Cop C E : A` x ,y D is converted to . . Γ,x:Cop,y:C E: R ` D end Γ Cop C E : ` x ,y D R weakening Γ,z: Cop C E : . A` x ,y D The cases where z = x or z = y comply with the definition of W-normal form and the weakening is not propagated. The case for lambda is analogous. dual • The derivation . . Γ E : ` D weakening Γ,z: E: A` D dual op op op Γ ,z: E∗ : A ` D is converted to . . Γ E : ` D dual op op Γ E∗ : ` D weakening op op op Γ ,z: E∗ : . A ` D 

Observe that by definition in a W-normal derivation all meaningless use of con- traction4 are removed. The definition of this normal form is inspired in the W- normal deductions for intuitionistic sequent calculus, the system G1i in [TS00].

4A variable introduced by a weakening than then is removed by a contraction. 5.2. A Normal Form for Derivations 85

5.2.2 CW-normal Derivations A derivation is in CW-normal form if it is in W-normal form and the contraction’s occur adjacent above

1. the final sequent, or

2. the introduction of a binder (lambda or end) where the new variable intro- duced by the contraction is bound, for example

. . Γ,x:C,y:C E: ` D contraction Γ,z:C E[z/x,z/y]: ` D lambda Γ λzC.E[z/x,z/y]:[C, ] ` D for another example consider the derivation (5.3) extended with an application of lambda.

In this way any variable in the context which is not introduced by an adjacent weakening or contraction can be traced to an axiom.

Proposition 5.2.2 Every derivation can be transformed into a derivation in CW- normal form.

Proof. First obtain the W-normal form. Then we show how every occurrence of contraction left which violates the conditions above can be permuted below other rules until it reaches a legal position.

weakening • This is dual to the case for contraction considered in the proof of Proposi- tion 5.2.1.

hom • As usual there are two cases to consider depending on which of the premises the contraction takes place. We show the transformation for the contravari- ant case, the other follows similarly. The derivation

. . . Γ1,x: ,y: E1: . A A` C contraction . Γ1,z: E1[z/x,z/y]: Γ2 E2 : A` C ` C hom Γop,z: op, Γ (E [z/x,z/y],E ):Set 1 A 2 `C 1 2 is converted to

. . . .

Γ1,x: ,y: E1: Γ2 E2: A A` C ` C hom+exchange’s op op op Γ1 , Γ2,x: ,y: (E1,E2):Set A A `C contraction+exchange’s Γop,z: op, Γ (E ,E )[z/x,z/y]:Set 1 A 2 `C 1 2 86 Chapter 5. A Term Calculus for Functors

and since x and y are not free in E2 we have (E ,E )[z/x,z/y]= (E [z/x,z/y],E ). C 1 2 C 1 2 The cases for the rules power and application are analogous. end • The derivation

. . Γ,w: ,z: ,x:Cop,y:C E: A A ` D contraction+exchange’s Γ,s: ,x:Cop,y:C E[s/w, s/z]: A ` D R end Γ,s: Cop C E[s/w, s/z]: A` x ,y D is converted to

. . Γ,w: ,z: ,x:Cop,y:C E: A A R ` D end Γ,w: ,z: Cop C E : A A` x ,y D R contraction Γ,s: ( Cop C E)[s/w, s/z]: . A` x ,y D As all variables in the sequents are different then R R ( xCop ,yC E)[s/w, s/z]= xCop ,yC E[s/w, s/z]. Thecaseforlambda is analogous. dual • The derivation

. . Γ,x: ,y: E: A A` D contraction Γ,z: E[z/x,z/y]: A` D dual op op op Γ ,z: (E[z/x,z/y])∗ : A ` D is converted to

. . Γ,x: ,y: E: A A` D dual op op op op Γ ,x: ,y: E∗ : A A ` D contraction op op op Γ ,z: E∗[z/x,z/y]: A ` D where by Proposition 5.1.4

(E[z/x,z/y])∗ = E∗[z∗/x, z∗/y]=E∗[z/x,z/y].  5.2. A Normal Form for Derivations 87

5.2.3 DCW-normal Derivations Every constructor in the syntax is introduced by a rule but the binder for coends and the binary operator for copowers. These two cases call for the use of the rule for duality in a type checking procedure. Thus coends become ends and copowers become powers. In general from Proposition 5.1.2 we have

R Cop C R x ,y E =( Cop C E∗)∗ and E E =([E ,E∗])∗. y ,x 1 ⊗ 2 1 2 Another less interesting example which demands the use of dual is in the derivation for a hom-expression of type Setop. As mentioned above we identify in the syntax a dual category ( op)op with the C category . From the definition of the meta-operation ( )∗ we need to identify as well a functorC category [C, ]op with [Cop, op]. This is justified by the derivation D D . . Γ,x:C E: ` D lambda Γ λxC.E :[C, ] ` D dual op Cop op op Γ λx .E∗ :[C , ]  ` D C Cop where by definition λx .E ∗ = λx .E∗. The following gives another derivation for the same sequent

. . Γ,x:C E: ` D dual (5.4) op op op Γ ,x:C E∗ : ` D lambda op Cop op op Γ λx .E∗ :[C , ]. ` D In this case with no implicit coercion on the types.

Definition 5.2.3 An application of dual in

. . Γ E : ` D dual op op Γ E∗ : ` D is essential if the outermost syntax constructor in E is 1, an end binder, a hom- expression or a power. For a non-example consider an instance of (5.4) where Γ is empty and E = x. Then the application of dual is not essential. Indeed the derivation

identity x:C x:C ` dual x:Cop x:Cop ` can be replaced by just identity x:Cop x:Cop. ` A derivation is in DCW-normal form if it is in CW-normal form and all the occurrences of the rule dual are essential. 88 Chapter 5. A Term Calculus for Functors

Proposition 5.2.4 Every derivation can be transformed into a derivation in DCW- normal form. Proof. We first obtain the CW-normal derivation. Then by means of local transfor- mations the non-essential occurrences of dual are permuted above other rules until they reach a legal position or encounter: another occurrence of the rule dual,or • an axiom (and then it is trivially solved). • By Proposition 5.1.2 double applications of the rule for duality can be safely re- moved. Thus a derivation . . Γ E : ` D dual op op Γ E∗ : ` D dual Γ E : ` D is converted to just . . Γ E : . ` D At the beginning of this section we show an example of how to permute the occurrences of dual above lambda. For the other cases: application • A derivation . . . .

Γ1 E1 :[C, ] Γ2 E2 :C ` D ` application Γ1,Γ2 E1E2 : ` D dual op op op Γ , Γ E∗E∗ : 1 2 ` 1 2 D is converted to ...... C Γ1 E1 :[ , ] Γ2 E2 :C ` D dual ` dual op Cop op op Cop Γ1 E1∗ :[ , ] Γ2 E2∗ : ` D ` application op op op Γ , Γ E∗E∗ : 1 2 ` 1 2 D whereweneedtouse[C, ]op =[Cop, op]. D D the cases for weakening and contraction are just dual to the cases in the • proofs of Propositions 5.2.1 and 5.2.2. The remaining rules produce essential occurrences of dual. 

In the DCW-normal form the use of weakening and contraction is delayed as much as possible whereas the use of dual is permitted only in the essential cases. The DCW-normal form of a derivation δ is unique up to the relative order of structural rules and renaming of variables. If indexes are used for variables then the DCW-normal form is in fact unique. Henceforth by “normal form” we mean the DCW-normal form. 5.3. Categorical Model 89

5.3 Categorical Model

A categorical model for a logic is a category where each derivation is interpreted as a morphism and where equations refer to commutative diagrams [Bie95]. In our setting a derivation . . δ Γ E : ` C is interpreted as a morphism in CAT, the category of locally small categories, i.e. as a functor   . . δ  . :[[Γ]] [[ ]] . Γ E : → C ` C 5.3.1 Types and Contexts Every type denotes a locally small category. The type Set is just the category of sets and functions. The notion of context is that of typed cartesian context [FPT99], this is reflected in the interpretation for the structural rules. A context

Γ=x : , ,xn: n 1 C1 ··· C denotes the product of categories

[[ Γ ]] = n. C 1 ×···×C The empty context is just the category 1. That a type ( op)op corresponds to can now be justified at the level of the interpretation. HereC we do not even needC to talk about isomorphism but just equality. Similarly for the modality taking a context Γ into Γop, it is clear that we can say op op op ( ... n) = ... C . C1 × ×C C1 × × n We understand the interpretation of contexts as an n-product which represents at once all possible isomorphic expressions obtained via associativity.

5.3.2 Interpretation for Derivations The interpretation for derivations is defined inductively by using the typing rules in 5.1.2. Each rule is interpreted as an operation taking the functors denoted by the premises§ into the functor denoted by the whole derivation. We write [[δ B Γ E : ]] for the interpretation of a derivation ` C

. . δ Γ E : . ` C To simplify the notation we omit the semantics brackets in most cases in particular when referring to categories and types. The derivation • singleton 1:Set ` is interpreted as 1 / 1 Set where 1 is the singleton category and the functor 1 selects the singleton (a chosen one) in the category of sets. 90 Chapter 5. A Term Calculus for Functors

The derivation • identity x: x: C` C is interpreted as id / C . C C The derivation • . . δ

Γ= 1, ,xn: n E: C ··· C ` C weakening , ,xn: n,xn : n E : C1 ··· C +1 C +1 ` C is interpreted as  π / [[ δ B Γ E : ]] / n n n ` C C1 ×···×C ×C +1 C1 ×···×C C

where π is the universal arrow π ,...,π n defined by the projections of h C1 C i ... n. C1 × ×C The derivation • . . δ

Γ=x1: 1, ,xi: i,xi+1 : i+1, ,xn: n E: C ··· C C ··· C ` C exchange x : , ,xi : i ,xi: i, ,xn: n E: 1 C1 ··· +1 C +1 C ··· C ` C is interpreted through the isomorphisms of categories

πΓ ,π +1,π ,πΓ [[ δ B Γ E : ]] h 1 Ci Ci 2 i / / Γ i i Γ Γ i i Γ = Γ ` C . 1 ×C+1 ×C × 2 1 ×C ×C+1 × 2 ∼ C The derivation • . . δ z }|∆ { Γ,x: ,y: E: C C` D contraction Γ,z: E[z/x,z/y]: C` D is interpreted as

B πΓ,π ,π / [[ δ ∆ E : ]] / Γ h C Ci Γ ` D ×C ×C×C D where πΓ,π ,π is the diagonal functor parametrised on Γ. h C Ci The derivation • . . . δ1 . δ2

Γ1 E1 : Γ2 E2 : ` C ` C hom Γop, Γ (E ,E ):Set 1 2 `C 1 2 is interpreted as

[[ δ B Γ E : ]] op [[ δ B Γ E : ]] ( , ) Γop Γ 1 1 ` 1 C × 2 2 ` 2 C / op C /Set. 1 × 2 C ×C Observe that contravariance on the first argument is modelled through the dualising 2-functor ( )op (see 1.3). § 5.3. Categorical Model 91

The derivation • . . . δ1 . δ2

Γ1 E1 :Set Γ2 E2 : ` ` C power Γop, Γ [E ,E ]: 1 2 ` 1 2 C is interpreted as

[[ δ B Γ E : Set]] op [[ δ B Γ E : ]] [ , ] Γop Γ 1 1 ` 1 × 2 2 ` 2 C / Setop / 1 × 2 ×C C where [ , ] is the power functor (see 3.4). § The derivation • . . δ Γ,x:C E: ` D lambda Γ λxC.E :[ , ] ` C D is interpreted as λ([[δBΓ,x:C E: ]] ) Γ ` D / [ C , ] D where λ is the isomorphism defined by (2.14).

The derivation • . . . δ1 . δ2

Γ1 E1 :[C, ] Γ2 E2 :C ` D ` application Γ ,Γ E E : 1 2 ` 1 2 D is interpreted as

B C B C [[ δ 1 Γ 1 E 1 :[ , ]]] [[ δ 2 Γ 2 E 2 : ]] eval Γ Γ ` D × ` / [ C , ] C / 1 × 2 D × D where eval is the counit of λ.

The derivation • . . δ Γ,x:Cop,y:C E: R ` D end Γ Cop C E : ` x ,y D is interpreted as R λr. F r (w,w) Γ w / D where F =[[δBΓ,x:Cop,y:C E: ]]:Γ Cop C . ` D × × →D By parametrised representability since is complete we can define a mapping R D γ F γ (w, w) 7→ w which extends to a functor. 92 Chapter 5. A Term Calculus for Functors

The derivation • . . δ Γ E : ` D dual op op Γ E∗ : ` D is interpreted as [[ δ B Γ E : ]] op Γop ` D / op. D This is obtained by applying the dualising 2-functor ( )op (see 1.3). § 5.3.3 Example In section 5.1.4 we show a derivation for the sequent

y :C,x:Cop [C(y,x),x]:Cop. ` The last rule in the derivation is

. . δ y :C,w:Cop,z:Cop [C(y,w),z]:Cop ` contraction y :C,x:Cop [C(y,x),x]:Cop. ` The interpretation for δ results in a functor

λy,w,z.[C(y,w),z]:C Cop Cop Cop × × → (f,g,h)/ whose action on a morphism (c, d, e) (c0,d0,e0) is the unique mediating arrow defined by the powers and the projections in Y [C(c, d),e]= e πg k f ◦ ◦ / e k C(c,d) ∈

h πg k f k C(c ,d ) h h ◦ ◦ ◦ i ∈ 0 0  Y  [C(c0,d0),e0]= e0 πk / e0. k C(c,d ) ∈ 0 0 The application of contraction in the last step of the derivation fixes g to be op h :e0 e in C. → 5.3.4 Semantics of Substitution As it is standard in categorical logic the derivable rule for substitution is interpreted as composition.

Proposition 5.3.1 The interpretation for a derivation

. . . δ1 . δ2

Γ,x: ,Θ E1: Ξ E2: (5.5) C ` D ` C substitution Γ,Ξ,Θ E [E /x]: ` 1 2 D 5.3. Categorical Model 93 is the functor

B B Γ [[ δ 2 Ξ E 2 : ]] Θ / [[ δ 1 Γ ,x: ,Θ E1: ]] / Γ Ξ Θ × ` C × Γ Θ C ` D × × ×C× D Proof. The proof proceeds as the proof of Theorem 5.1.5 by induction on the deriva- tion δ1. Here we only analyse the cases for hom and dual (as given in the proof of Theorem 5.1.5). The case for power is analogous to hom;thecaseforend follows as for lambda abstraction in a standard manner. hom • Here we consider the interpretation of (5.5) where δ1 is

. . . δ0 . δ00

∆1 E0 : ∆2 E00 : ` A ` A hom Γ,x: ,Θ (E0,E00):Set C `A

and x is defined in ∆1, i.e. there exists a context ∆10 such that op op ∆ =Γ ,x: , ∆0 . 1 C 1 From the proof of Theorem 5.1.5) by definition the interpretation of (5.5) is

op F [[ δ 00B∆ E00: ]] ( , ) op × 2` A / op A / Γ Ξ (∆0 ) ∆ Set × × 1 × 2 A ×A where the functor F is the composition

op op Γ [[ δ 2 B Ξ E 2 : ]] ∆0 [[ δ 0 B ∆ E 0 : ]] op op × ` C × 1 / op op 1 ` A / Γ Ξ ∆0 Γ ∆0 . × × 1 ×C × 1 A op op AsΘ=(∆10) , ∆2 we have by functoriality of ( ) that the triangles in

op F [[ δ 00B∆ E00: ]] ( , ) × 2` A / op A / Γ Ξ ΘS S ii 4 5 Set × × S S S iiiii A ×A B B op B Γ [[ δ 2 Ξ E 2S:SS]] Θ [[ δ 0 ∆ 1 E 0i: i ]] [[ δ 00 ∆2 E00: ]] × ` C S×S ) ii`ii A × ` A [[ δ 1 B Γ ,x: ,Θ E1:Set]] Γ Θ=∆ ∆ C ` ×C× 1× 2 commute. dual • The interpretation of (5.5) where δ1 is the derivation

. . δ0 op op op op Γ ,x: , Θ E1∗ : C ` D dual Γ,x: ,Θ E : C ` 1 D is by functoriality of ( )op and induction defined to be

op op op op op Γ [[ δ B Ξ E : ]] Θ [[ δ 0 B Γ ,x: ,Θ E∗: ]] Γ Ξ Θ × 2 ` 2 C × / Γ Θ C ` 1 D / × × ×C× D and by definition we have

op op op op op [[ δ B Γ ,x: ,Θ E : ]] = [[ δ 0 B Γ ,x: , Θ E∗ : ]] . 1 C ` 1 D C ` 1 D  94 Chapter 5. A Term Calculus for Functors

5.4 Coherence

We need to verify that all possible derivations for a judgement yield the same inter- pretation: a so-called “coherence” result. The importance of coherence is noticed for example by Breazu-Tannen, Coquand, Gunter and Scedrov [BTCGS91]. Coher- ence was an important issue in the effort to discover the syntax associated to linear logic [Blu91,Wad92b,BBdPH93]. In [Wad92a] Wadler discusses the incoherent sys- tem obtained by taking the Abramsky’s syntax for linear logic together with the semantics due to Seely. Due to the presence of limits and ends in the calculus, coherence amounts to showing that different derivations for the same judgement yield isomorphic functors in CAT. The cause for having different derivations are mainly the order of the application of the structural rules and duality. The application of these rules do not leave any trace in the terms and then the final sequent does not register the order in which they were applied. The syntax for expressions could be extended with constructors for the structural rules and duality in the spirit of [BBdPH93]. Then every well-typed term would uniquely encode a derivation. The main result in this section shows that this extreme solution is not really necessary. Proposition 5.2.4 shows that a well-typed sequent can always be proved through a derivation in a special form. The proof proceeds by showing how through local transformations a given derivation can be transformed into the normal form. Then it is enough to show that every transformation step preserves the interpretation (up to isomorphism) to conclude that the system is coherent with respect to the semantics defined in the previous section. This is basically the strategy used in [BTCGS91].

Permuting weakenings. Here we show that the local transformations in the proof of Proposition 5.2.1 permuting occurrences of weakening below other rules preserve the interpretation. As structural rules manipulate the contexts it is not surprising that most of the cases rely on the universal property of products and the fact that the ( )op preserve products.

contraction • For the first case we want to show that the functor

B πΓ,π ,π / π / [[ δ Γ ,w: E: ]] / Γ h A Ai Γ Γ A` D ×A ×A×A ×A D is just [[ δ B Γ ,w: E: ]] Γ A` D / . ×A D From the universal property of products it follows that the diagram

πΓ,π ,π / π / Γ h A Ai Γ 3Γ ×A ×A×A ×A id

commutes as required. For the second possibility we want to show that the functors

B πΓ,π ,π ,π / π / [[ δ Γ ,x: ,y: E: ]] / Γ h A C CiΓ Γ C C` D ×A×C ×A×C×C ×C×C D and

B π / πΓ,π ,π / [[ δ Γ ,x: ,y: E: ]] / Γ Γ h C Ci Γ C C` D ×A×C ×C ×C×C D 5.4. Coherence 95

are the same (we omit the isomorphisms related to the use of exchange). By the universal property of product we have that the diagram

π Γ / Γ ×A×C ×C

πΓ,π ,π ,π πΓ,π ,π h A  C Ci h C Ci / Γ Γ ×A×C×C π ×C×C commutes, and so the functors above are equal. hom • Since ( )op is a functor and moreover πop is indeed a projection we have that the functors

([[δ BΓ E : ]] π ) op [[ δ B Γ E : ]] ( , ) Γop op Γ 1 1` 1 C ◦ × 2 2 ` 2 C / op C /Set 1 ×A × 2 C ×C and

[[ δ B Γ E : ]] op [[ δ B Γ E : ]] ( , ) Γop op Γ π /Γop Γ 1 1 ` 1 C × 2 2 ` 2 C / op C /Set 1 ×A × 2 1 × 2 C ×C are equal. end • Forafunctor

F=[[δBΓ,x:Cop,y:C E: ]]:Γ Cop C ` D × × →D the transformation takes a functor R λr,s. Gr,s(w,w) w / Γ ×A D and yields the functor R λr. F r (w,w) Γ π /Γ w / ×A D where G is the composition

Γ Cop C π /Γ Cop C F / . ×A× × × × D By definition G is “dummy” in the argument of type . Then these functors are isomorphic since for r Γands A R ∈   ∈A R d, (λr. F r(w, w)) π (r, s) = (d, F r(w, w)) D w ◦ D w  = Dinat ∆d, F r ∼   = Dinat ∆d, (λr.F r) π (r, s, , )  ◦ = Dinat ∆d, Gr,s .

By parametrised representability the isomorphism obtained is natural in r, s. lambda • In the proof of Proposition 5.2.1 the case for lambda abstraction is not con- sidered explicitly since it is analogous to that for the end binder. The inter- pretation given to the application of lambda, however, is obtained through 96 Chapter 5. A Term Calculus for Functors

a different categorical construction. Here we want to show that the functors defined by λ(F) Γ /[C, ] ×A D where π [[ δ B Γ ,x:C E: ]] F =Γ C /Γ C ` D / ×A× × D and π λ([[δBΓ,x:C E: ]] ) Γ /Γ ` D / [ C , ] ×A D are actually the same. This follows from

λ([[δBΓ,x:C E: ]] ) Γ π /Γ ` D / [ C , ] ×A D π C / [[ δ B Γ ,x:C E: ]] / Γ C × Γ6 C ` D ×A× = × D π λ(F) Γ /[C, ]. ×A D Again we omit the isomorphism arising from the use of exchange. dual • As ( )op is a functor we need to verify that the functors

op [[ δ B Γ E : ]] op Γop π /Γop ` D / op ×C D and op π [[ δ B Γ E : ]] Γop /Γop ` D / op ×C D are equal. Indeed this follows by the observation that πop is the projection π.

Permuting contractions. The transformations in the proof of Proposition 5.2.2 permute occurrences of contraction below other rules. Here we show that each preserves the interpretation. As for W-normal derivations most of the cases follow from the universal property of products and that ( )op preserve products. weakening • This case is symmetric to the one in the previous section. hom • Given the functors F =[[δ BΓ ,x: ,y: E : ]]:Γ 1 1 A A` 1 C 1 ×A×A→C and G =[[δ BΓ E : ]]:Γ , 2 2 ` 2 C 2 →C it follows from the universal property of products and since ( )op preserves products that the diagram of functors

Γop op Γ 1 2WWW ×A × WWWWW π op ,π op ,π op ,πΓ op Γ A A 2 (F πΓ ,π ,π ,πWΓ ) G h 1 i 1 A A 2WWW  ◦h i W×WWW+ op op op / op Γ Γ2 1 F op G ×A ×A × × C ×C commutes as required. 5.4. Coherence 97

end • Given the interpretation F =[[δBΓ,w: ,z: ,x:Cop,y:C E: ]]:Γ Cop C A A ` D ×A×A× × →D we need to verify the functors R λr,s. Gr,s(w,w) Γ w / ×A D where op G = F πΓ,π ,π ,πCop ,πC :Γ C C ◦h A A i ×A× × →D and R λr,s,t. F r,s,t(w,w) πΓ,π ,π / w / Γ h A Ai Γ ×A ×A×A D are isomorphic. Thus for every r Γands we have R ∈ ∈A  R r,s,t r,s,s d, (λr,s,t. F (w, w)) πΓ,π ,π (r, s) = (d, F (w, w)) D w ◦h A Ai D w  = Dinat ∆d, F r,s,s ∼  = Dinat ∆d, Gr,s which by parametrised representability is natural in r, s.Thecaseforlambda is similar to the case for Proposition 5.2.1. dual • This follows by functoriality of ( )op and the fact that this functor preserves products. Thus we have that the functors

op B op πΓ,π ,π / [[ δ Γ ,x: ,y: E: ]] / Γop op h A Ai Γop op op A A` D op ×A ×A ×A D and

B op πΓop ,π op ,π op / [[ δ Γ ,x: ,y: E: ]] / Γop oph A A iΓop op op A A` D op ×A ×A ×A D are equal.

Removing non-essential duals. An occurrence of dual violating the condition defined by the normal form is permuted above occurrences of lambda, applica- tion, weakening and contraction until it reaches a legal position, meets another occurrence of dual or a sequent whose expression is a variable. That two applica- tions of dual one after the other are removed is justified in the semantics by the fact that the 2-functor ( )op is an involution by definition. The case for variables is a consequence of preservation of products. lambda • This follows from the adjoint property of λ (2.14) and the fact that the functor ( )op is full and faithful:

λ([[δBΓ,x:C E: ]] op) Γop ` D /[Cop, op] D [[ δ B Γ ,x:C E: ]] op Γop Cop ` D / op × D [[ δ B Γ ,x:C E: ]] Γ C ` D / × D λ ([[δBΓ,x:C E: ]] ) Γ ` D / [ C , ] D (λ([[δBΓ,x:C E: ]] ) ) op Γ op ` D /[Cop, op]. D 98 Chapter 5. A Term Calculus for Functors

application • This is justified by the fact that ( )op preserves products and the exponentials in CAT. Thus the functor evalop is in fact the counit for the adjunction defined by λ.

weakening and contraction • These cases are symmetric to the cases from Propositions 5.2.1 and 5.2.2 respectively.

By Proposition 5.2.4 a derivation δ B Γ E : can be translated into a deriva- ` D tion δ0 B Γ0 E0 : in the normal form where Γ0 and E0 indicate possible renaming of variables.` TheD renaming of variables in the context does not affect the interpre- tation, i.e. [[ Γ ]] = [[ Γ 0 ]]. Then from the discussion above the functors

[[ δ B Γ E : ]]:Γ and [[δ0 B Γ0 E0 : ]]:Γ ` D →D ` D →D are isomorphic. The syntactic structure of a well-typed judgement defines a set of derivations in normal form that differ only in the order of the application of the structural rules (and is free of spourious uses of duality). The interpretation for those derivations in normal form is not affected (up to isomorphism) by the application of structural rules including duality. Therefore, different derivations for a sequent yield the same interpretation up to isomorphism.

Theorem 5.4.1 The categorical interpretation is coherent up to isomorphism.

It is essential to interpret the types [Cop, op]and[C, ]op as the category of functors whose domain is Cop and codomain is Dop. In the syntaxD this is represented by the definition clause D C Cop (λx .E)∗ = λx .E∗ of the meta-operator ( )∗.

Remark 5.4.2 In general a particular interpretation of a well-typed sequent Γ E : assumes a derivation δ. Otherwise, if no derivation is mentioned, the canonical` oneD is assumed and taken to give the interpretation.

5.5 Without Duality

The typing rules for coends and powers are derived from the rules for ends and powers together with duality. That reflects a common practice in category theory. We could have introduced primitive rules for coends and copowers instead:

coend Γ,x: op,y: E: small cocomplete C C` DCR op D Γ xC ,yC E : ` D copower Γ E :Set Γ E : cocomplete 1 ` 1 2 ` 2 CC Γ , Γ E E : . 1 2 ` 1 ⊗ 2 C It is sensible to ask whether these rules are enough to absorb the rule dual. Because of the presence of the basic types like Set the answer is negative. Consider for 5.5. Without Duality 99 example the derivation . . . .

Γ1 E1 : Γ2 E2 : ` C ` C hom op Γ1 , Γ2 (E1,E2):Set `C dual op op Γ , Γ (E∗,E∗):Set 1 2 `C 1 2 where the application of dual provides the only way in which we can introduce Setop. In order to obtain a system closed under duality we need rules to introduce the dual forms of the basic types:

hom∗ Γ E : Γ E : 1 ` 1 C 2 ` 2 C op op Γ , Γ (E∗,E∗):Set 1 2 `C 1 2 singleton∗

1:Setop. ` Thus every essential occurrence of dual (as defined in 5.2.3) can be replaced by one of the new rules. For the non-essential occurrences they can be removed by following exactly the same procedure as in the proof for DCW-normal derivations. The definition of the operation ( )∗ over raw expressions may appear arbitrary for the case of hom-expressions. In fact it all amounts to defining a suitable syntax for the functor ( ( , ))op / op C Setop. C×C Consider the alternative definition

(E ,E )∗ = (E ,E ) (5.6) C 1 2 C 1 2 where the type Setop and the change of variance in the context breaks the ambiguity with the hom-expressions of type Set, for example . . . .

Γ1 E1 : Γ2 E2 : ` C ` C hom op Γ1 , Γ2 (E1,E2):Set `C dual Γ , Γop (E ,E ):Setop. 1 2 `C 1 2 In (5.6) the contravariant argument, the one on the right, is assumed to be du- alised. That contrasts with our original definition of ( )∗ where the contravariant argument takes the correct form while the covariant one is “implicitly” dualised. One disadvantage of (5.6) is that the definition of substitution over raw terms is not longer valid. To adjust substitution demands to know in advance the type of a hom-expression (i.e. Set or Setop) and then could not be carried out on raw expressions in general. In few words if the hom-expression is of type Setop the substitution should act as

(E ,E )[E/x]= (E [E/x],E [E∗/x]). C 1 2 C 1 2 To avoid this inconvenience we prefer

( (E ,E ))∗ = (E∗,E∗) C 1 2 C 1 2 as a syntax for ( , )op rather than (5.6). C 100 Chapter 5. A Term Calculus for Functors

5.6 Products

The cartesian structure of CAT is already present in the semantics of contexts. An expression-in-context corresponds to a functor with as many arguments as variables in the context. To fully incorporate functors with multiple variables into the calculus we need finite products for types

::= ... 1 C | |C1×C2 and the rules

small small C D small 1 small 1 complete. C×D The corresponding syntax and the rules for products are the usual ones from the typed lambda calculus with pairs:

unit

:1 `hi

pair Γ E : Γ E : 1 ` 1 C 2 ` 2 D Γ , Γ E ,E : 1 2 `h 1 2i C×D

first Γ E : ` C×D Γ fst C×D(E): ` C

second Γ E : ` C×D Γ snd C×D(E): ` D

Duality over a product type acts by dualising each factor, this is consistent with op the definition of Γ for a context Γ. The meta-operation ( )∗ acts over the new syntax as

( )∗ = hi hi E1,E2 ∗ = E1∗,E2∗ h i h op iop fst C×D(E)∗ = fst C ×D (E∗) op op snd C×D(E)∗ = snd C ×D (E∗).

This definition is justified in the semantics by the fact that the functor ( )op pre- serves products. By checking the cases introduced by these new rules we can verify that Propositions 5.1.2 and 5.1.4, and Theorem 5.1.5 are still valid. The proofs of Propositions 5.2.1, 5.2.2 and 5.2.4 related to the normal forms can be extended to contemplate the rules for products as well. The empty product defines a new basic type 1, we identify in the syntax 1op with 1. Thus the expression 5.6. Products 101

1(x, x) is well-typed

identity identity z :1 z :1 w:1 w:1 ` ` hom z :1,w:1 1(z,w):Set ` contraction x:1 1(x, x):Set. ` The interpretation for the new derivations is defined through the cartesian struc- ture of CAT as usual:

unit • The new type 1 represents the final object in CAT, i.e. the singleton category and the derivation

:1 `hi is just the unique endomorphism

id 1 /1.

pair • The derivation . . . δ1 . δ2

Γ1 E1 : Γ2 E2 : ` C ` D pair Γ , Γ E ,E : 1 2 `h 1 2i C×D is interpreted as

[[ δ B Γ E : ]] [[ δ B Γ E : ]] Γ Γ 1 1 ` 1 C × 2 2 ` 2 D / . 1 × 2 C×D

first • The derivation . . δ Γ E : ` C×D first Γ fst C×D(E): ` C is interpreted as [[ δ B Γ E : ]] Γ ` C×D / π / . C×D C Similarly for the rule second.

If there is a derivation for the expression-in-context

Γ ,x: ,y: ,Γ E: (5.7) 1 A B 2 ` D then there is a derivation for

Γ ,v: ,Γ E[fst A×B(v)/x, snd A×B(v)/y]: . 1 A×B 2 ` D 102 Chapter 5. A Term Calculus for Functors

This follows from substitution since from the rules above we have the necessary derivations

identity identity v : v: v : v: A×B` A×B first A×B` A×B second v : fst A×B(v): v : snd A×B(v): . A×B` A A×B` B In a more general setting this correspondence is a consequence of the relation be- tween the natural deduction systems and the intuitionistic sequent calculus (see [TD88, TS00]). As CAT is a bicartesian category, i.e. a category with both finite product and coproducts together with the obvious distributivity laws, we could extend the syntax with “disjoint unions” constructors. Indeed as CAT is complete and cocomplete we could be tempted to develop a richer theory for types where if not all limits and colimits are consider at least includes some kind of fixed point construction. This, however, escapes from the main focus of this dissertation and it is not developed further. Chapter 6

Natural Isomorphisms

We extend the language for functors with judgements for natural isomorphisms. A derivation for an isomorphism judgement is interpreted as a natural isomorphism between functors. As with the functoriality judgements this interpretation is defined by induction but in this case the system is not coherent. This theory of isomorphisms provides a formal presentation of the repertoire of natural isomorphism used in chapters 2 and 3. We also extend the syntax to represent weighted limits and show how under the assumption of completeness the new expressions is naturally isomorphic to an end formula (Proposition 3.5.3). At the end of this chapter we propose another approach to contravariance where the meta-operation ( )∗ becomes part of the syntax.

6.1 Isomorphism Judgements

The natural isomorphisms extend the equational theory of the lambda calculus with rules for Fubini, the naturality formula, the Yoneda Lemma and the definitions for end and power. There are also two rules for duality from which we derive rules for coends and copowers. As representability is the key concept in our reasoning most of the rules in fact formalise natural isomorphisms between expressions of type Set. The syntactic judgement

x : , ,xn: n E =E : 1 C1 ··· C ` 1 ∼ 2 C says that the expressions E1 and E2 are naturally isomorphic in the variables x , ,xn. The rules for isomorphisms shall ensure that in a derivation for the 1 ··· sequent above both E1 and E2 are functorial in those variables as well, i.e.

x : , ,xn: n E : and x : , ,xn: n E : 1 C1 ··· C ` 1 C 1 C1 ··· C ` 2 C are well-typed.

6.1.1 Equational Theory of the Lambda Calculus As the language for functors extend the syntax of the lambda calculus we inherit its equational theory [Bar84, Mit96]. These rules basically allow us to replace “equals for equals” in expressions.

Structural Rules As for the term-formation rules we need rules to manipulate contexts:

103 104 Chapter 6. Natural Isomorphisms

weakening x : , ,xn: n E =E : 1 C1 ··· C ` 1 ∼ 2 C x : , ,xn: n,xn : n E = E : 1 C1 ··· C +1 C +1 ` 1 ∼ 2 C

exchange x : , ,xi: i,xi : i , ,xn: n E =E : 1 C1 ··· C +1 C +1 ··· C ` 1 ∼ 2 C x : , ,xi : i ,xi: i, ,xn: n E =E : 1 C1 ··· +1 C +1 C ··· C ` 1 ∼ 2 C

contraction Γ,x: ,y: E =E : C C` 1 ∼ 2 D Γ,z: E[z/x,z/y] = E [z/x,z/y]: C` 1 ∼ 2 D

It is obvious from an inductive argument that the expressions in the conclusions are functorial if the premises are. In general we shall not bother to mention the use of these rules when reasoning about natural isomorphisms.

Conversion Rules To define the evaluation of functors we have:

β-conversion Γ ,x: E : Γ E : small 1 C` 1 D 2 ` 2 CC Γ , Γ (λxC .E )E = E [E /x]: 1 2 ` 1 2 ∼ 1 2 D where the substitution E1[E2/x] is defined as in 5.1.3. From the premises both expressions in the final sequent are well-typed. The left-hand side follows by using the rules lambda and application, and the right-hand side from Theorem 5.1.5. For extensionality of functors we have the rule:

η-conversion Γ E :[ , ] ` C D x is not free in E. Γ λxC .Ex = E :[ , ] ` ∼ C D

Notice that is necessary small. The expression E is functorial since is proved by C the premise of the rule. That the expression λxC .Ex is functorial follows from

identity Γ E :[ , ] x: x: ` C D C` C application Γ,x: Ex: C` D lambda Γ λxC .Ex:[ , ]. ` C D We sometimes refer to these rules under the general designation of conversion rules.

Equivalence Rules

The next rules make the relation ∼= an equivalence: 6.1. Isomorphism Judgements 105

reflexivity Γ E : ` D Γ E = E : ` ∼ D symmetry Γ E = E : ` 1 ∼ 2 D Γ E = E : ` 2 ∼ 1 D transitivity Γ E = E : Γ E = E : ` 1 ∼ 2 D ` 2 ∼ 3 D Γ E = E : . ` 1 ∼ 3 D Inthecaseofreflexivity is obvious that the expression E is functorial since it is required by the premise of the rule. For the rules symmetry and transitivity that the expressions involved are functorial follows by an inductive argument. The rule for transitivity plays an important role in the calculus since most of the proofs proceed by chaining together natural isomorphisms.

Congruence Rules

Now we extend the relation ∼= to be compatible with the construction of the differ- ent expressions in the language, this is achieve by the so-called congruence rules. Thus for every piece of syntax there is a corresponding congruence rule:

hom cong Γ E = E0 : Γ E = E0 : 1 ` 1 ∼ 1 C 2 ` 2 ∼ 2 C op Γ , Γ (E ,E )= (E0,E0):Set 1 2 `C 1 2 ∼C 1 2 power cong Γ E = E0 :Set Γ E = E0 : complete 1 ` 1 ∼ 1 2 ` 2 ∼ 2 CC op Γ , Γ [E ,E ]=[E0,E0]: 1 2 ` 1 2 ∼ 1 2 C ξ-conversion lambda Γ,x: E =E : small C` 1∼ 2 DC Γ λxC .E = λxC .E :[ , ] ` 1 ∼ 2 C D application cong Γ E = E0 :[ , ]Γ E=E0: 1 ` 1 ∼ 1 C D 2`2∼2C Γ,Γ EE=E0E0:[ , ] 1 2`12∼12 C D ξ-conversion end op Γ,x: ,y: E1 =E2: small complete C C`R ∼ DCR D Γ op E1 = op E2 : . ` xC ,yC ∼ xC ,yC D

It is obvious in all these rules that the expressions in the conclusions are indeed functorial if one assumes that the premises are. Because of the constraint on the formation of functor categories ξ-conversion for lambda abstraction is not enough to 106 Chapter 6. Natural Isomorphisms derive the other congruence rules (see [LS86]). For example the rule hom cong can not be derived from β-conversion if the type is not small (similarly for power cong). C This series is complete with the rule for duality introduced in the next section – but it cannot be consider a congruence rules since the ( )∗ is not part of the syntax. These rules justify to replace “equals for equals” in expressions regardless questions of bound variables [Bar84, Proposition 21.19]. To simplify the notation in the proofs we often do not mention the congruence rules, or just refer to them under the generic name of congruence.

6.1.2 Representables and Ends The following rule allows us to move from an arbitrary type into Set, the place where representable functors live: C

representable Γ,x: op (x, E ) = (x, E ):Set C `C 1 ∼ C 2 Γ E = E : . ` 1 ∼ 2 C Notice that from the assumption on the manipulation of contexts the variable x cannot be free in E1 or E2. From the judgement

Γ,x: op (x, E ) = (x, E ):Set C `C 1 ∼ C 2 we inductively have that both

Γ,x: op (x, E ):Set and Γ,x: op (x, E ):Set C `C 1 C `C 2 are derivable and then as x is not free in E1 or E2 we have that the sequents

Γ E : and Γ E : ` 1 C ` 2 C are derivable in the type theory. The rule representable can actually be read bottom-up as well, though that is derivable from the congruence rule for hom-expressions:

identity x: x: C` C reflexivity x: x∼=x: Γ E1 ∼= E2 : C` C ` C hom cong Γ,x: op (x, E ) = (x, E ):Set. C `C 1 ∼ C 1 Then we have the derivable rule

Γ E = E : ` 1 ∼ 2 C Γ,x: op (x, E ) = (x, E ):Set C `C 1 ∼ C 2 with the side condition that x is not free in E1 or E2. The following rule formalises the naturality formula:

nat formula Γ1,x: E1: Γ2,y: E2: small C` D C`R DC op Γ1 , Γ2 [ , ](λxC .E1,λyC.E2) = op (E1,E2):Set. ` C D ∼ xC ,yC D 6.1. Isomorphism Judgements 107

From the premises of this rule we have

Γ1,x: E1: Γ2,y: E2: C` D lambda C` D lambda Γ1 λxC .E1 :[ , ] Γ2 λyC .E2 :[ , ] ` C D ` C D hom op Γ , Γ [ , ](λxC .E ,λyC.E ):Set 1 2 ` C D 1 2 and

Γ1,x: E1: Γ2,y: E2: C` D C` D hom+exchange’s Γop, Γ ,x: op,y: (E,E ):Set 1 2 C C`D 1 2 R end op Γ1 , Γ2 op (E1,E2):Set. ` xC ,yC D The rule nat formula exemplifies the importance of the Church-style presenta- tion of the syntax. The variable x is bound by the lambda binder as covariant and by the integral binder as contravariant. This is a consequence of the assumption that the left argument of a hom-expression is implicitly dualised. We have previ- ously used this information in an informal manner, for instance in the last step of the proof of Proposition 3.5.5 where we informally write R  [G(x), [F (x),Z]] [C, Set] G, [F ( ),Z] . x ∼=

In order to define the functor category we need to keep track of the types of the occurrences of x. In the formal calculus there are different variables for the different occurrences of x in the expression above. For interchange of ends we have the rule:

Fubini op op Γ,x1: ,x2: ,y1: ,y2: E: small small complete C C R D R D` ECR R D E Γ x op ,x y op ,y E = y op ,y x op ,x E : ` 1C 2C 1D 2D ∼ 1D 2D 1C 2C E

The functoriality of both expressions follow from the premises by application of the rule end twice and the use of some exchange’s. Through representables we can give the definition of end as:

def end Γ,x: op,y: E: small complete C C`R DC R D op Γ,w: (w, op E) = op (w, E):Set D `D xC ,yC ∼ xC ,yC D where from the assumption on contexts w cannot be free in E. From the premises we have

Γ,x: op,y: E: identity CR C` D end w : w: Γ op E : D` D ` xC ,yC D R hom+exchange’s op Γ,w: (w, op E):Set D `D xC ,yC 108 Chapter 6. Natural Isomorphisms and

identity w: w: Γ,x: op,y: E: D` D C C` D hom w: op, Γ,x: op,y: (w, E):Set D C C`D R end+exchange’s op Γ,w: op (w, E):Set. D ` xC ,yC D

Similarly we can give the definition of power:

def power Γ E :Set Γ E : complete 1 ` 1 2 ` 2 DD Γop, Γ ,x: op (x, [E ,E ]) = [E , (x, E )]:Set 1 2 D `D 1 2 ∼ 1 D 2 where again x is not free in E. From the premises we have

Γ1 E1 :Set Γ2 E2 : identity ` ` D power op x: x: Γ1 , Γ2 [E1,E2]: D` D ` D hom+exchange’s Γop, Γ ,x: op (x, [E ,E ]):Set 1 2 D `D 1 2 and

identity x: x: Γ2 E2 : D` D ` D hom+exchange’s Γ E :Set Γ ,x: op (x, E ):Set 1 ` 1 2 D `D 2   power Γop, Γ ,x: op E , (x, E ) :Set. 1 2 D ` 1 D 2

In both cases, def end and def power, a universal property on an arbitrary com- plete category is expressed as the same universal property but in Set. D There is as well a definition for the singleton set:

def singleton Γ E : complete ` DD Γ [1,E]=E: ` ∼ D where functoriality of E follows from the premise and 1 is proved by the rule sin- gleton. The Yoneda lemma is given as an end by the rule:

Yoneda Γ,x: op E :Set small CR `  C  x, w are not free in E. op Γ,x: E = op (y,x),E[w/x] :Set C ` ∼ wC ,yC C

The left-hand side of the conclusion is functorial since it is just the premise. For 6.1. Isomorphism Judgements 109 the right-hand expression we have

identity identity x: x: y : y: C` C C` C hom x: op,y: (x, y):Set Γ,w: op E[w/x]:Set C C`C C `   power+exchange’s Γ,x: op,w: op,y: (y,x),E[w/x] :Set C C C` C R   end op Γ,x: op (y,x),E[w/x] :Set. C ` wC ,yC C The conclusion of the rule Yoneda says that the natural isomorphisms given by the Yoneda Lemma is natural in x. For a small category C the derivation

identity identity f :[Cop, Set] f :[Cop, Set] x:Cop x:Cop ` ` application f :[Cop, Set],x:Cop fx:Set ` R Yoneda op op f :[C , Set],x:C fx = Cop C [ (y,x),fw]:Set ` ∼ w ,y C gives the most general case where we have also naturality in f.

6.1.3 Duality The definitions for coend and copower are obtained from that one of end and power by using the rule which models the definition of opposite category (see 1.3): § opposite cat Γ E : Γ E : 1 ` 1 C 2 ` 2 C op op Γ , Γ (E ,E )= (E∗,E∗):Set 1 2 `C 1 2 ∼C 2 1 where the meta-operation ( )∗ is defined as in 5.1.1. The functoriality of the left- hand side follows by applying hom to the premises. For the right-hand side we have Γ2 E2 : Γ1 E1 : ` C dual ` C dual op op op op Γ2 E2∗ : Γ1 E1∗ : ` C ` C hom+exchange’s op op Γ , Γ (E∗,E∗):Set. 1 2 `C 2 1 Now we show how derive the rule for the definition of coends. Given a small category C, a cocomplete category and a judgement D Γ,x:Cop,y:C E: ` D we have Γ,x:Cop,y:C E: ` D end∗ R Cop C identity Γ x ,y E : w: w: ` D D` D opposite cat R Cop C R op x ,y op Γ ,w: ( E,w) = (w, Cop C E∗):Set. D`D ∼ D y ,x It follows through the chain of isomorphisms R R op op (w, Cop C E∗) = Cop C (w, E∗) def end D y ,x ∼ Ry ,x D = Cop (E,w) opposite cat+congruence. ∼ y ,xC D 110 Chapter 6. Natural Isomorphisms

Thus we have the derivable rule:

(def end)∗ Γ,x: op,y: E: small cocomplete C RC`op DC R D op xC ,yC Γ ,w: ( E,w) = op (E,w):Set. D`D ∼ yC ,xC D

Notice the adjustment in the type of the bound variables to reflect contravariance when moving outside of the left argument in a hom-expression. Similarly we can derive the rule for the definition of copowers. Given a cocom- plete category and judgements D Γ E :Set and Γ E : 1 ` 1 2 ` 2 D we have

Γ1 E1 : Set Γ2 E2 : ` ` D power∗ identity Γ1, Γ2 E1 E2 : w: w: ` ⊗ D D` D opposite cat op op op Γ , Γ ,w: (E E,w)= (w, [E ,E∗]):Set. 1 2 D`D 1⊗ 2 ∼D 1 2 The definition of copower is given by   op op (w, [E ,E∗]) = E , (w, E∗) def power D 1 2 ∼  1 D 2 = E , (E ,w) opposite cat+congruence. ∼ 1 D 2 Thus we have the derivable rule:

(def power)∗ Γ1 E1 :Set Γ2 E2 : cocomplete ` ` DD  Γop, Γop,w: (E E,w)= E , (E ,w) :Set 1 2 D`D 1⊗ 2 ∼ 1 D 2 where w is neither free in E1 nor E2. From the identity (Cop)op = C we obtain an instance of the rule Yoneda which deals with the covariant case: Γ,x:C E:Set ` R   Yoneda op Γ,x:C E = Cop C C (y,x),E[w/x] :Set, ` ∼ y ,w on the other hand we have the derivation

identity identity x:C x:C y :C y :C ` ` opposite cat x:Cop,y:C Cop(y,x) = C(x, y):Set ` ∼ and by congruence we can conclude R   R   op Γ,x:C Cop C C (y,x),E[w/x] = Cop C C(x, y),E[w/x] :Set. ` y ,w ∼ y ,w Finally by transitivity we obtain the derivable rule

Yoneda∗ Γ,x: E:Set small RC`  C  Γ,x: E= op (x, y),E[w/x] :Set. C` ∼ yC ,wC C 6.1. Isomorphism Judgements 111

The operation of duality respects natural isomorphisms, this is expressed by:

dual iso Γ E = E : ` 1 ∼ 2 C op op Γ E∗ = E∗ : . ` 1 ∼ 2 C

The functoriality judgements Γ E1 : and Γ E2 : are derivable by induction. By applying dual to both sequents` weC have that` the expressionsC in the conclusions of the rule are functorial as well. The rules opposite cat and dual iso allow us to derive the dual form of the rule representable. Given the judgement

Γ,x: (E,x)= (E ,x):Set C`C 1 ∼C 2 there are by definition functoriality judgements for E1 and E2 and then we can derive by using opposite cat

op op Γ,x: (E,x)= (x, E∗):Set and Γ,x: (E,x)= (x, E∗):Set. C`C 1 ∼C 1 C`C 2 ∼C 2 Then by transitivity we have

transitivity Γ,x: op(x, E ) op(x, E ):Set 1∗ ∼= 2∗ C`C C representable Γ E E : op 1∗ ∼= 2∗ ` C dual iso Γop E = E : . ` 1 ∼ 2 C Then we have the derivable rule

representable∗ Γ,x: (E,x)= (E ,x):Set C`C 1 ∼C 2 Γop E = E : . ` 1 ∼ 2 C Again the reverse reading of this rule is derivable from the congruence rule for hom-expressions. As for the functoriality judgements we can prove that the rule

substitution Γ ,x: E =E0: Γ E =E0: 1 C` 1 ∼ 1 D 2` 2∼ 2 C Γ,Γ E[E/x] = E0 [E0 /x]: 1 2` 1 2 ∼ 1 2 D is admissable in the calculus.

6.1.4 Products Associated to the rules in 5.6 we have the usual conversions from the lambda calculus with pairs §

unit iso Γ E :1 ` Γ E = :1 ` ∼ hi 112 Chapter 6. Natural Isomorphisms

β-conversion fst Γ E : Γ E : 1 ` 1 C 2 ` 2 C Γ , Γ fst C×D( E ,E )=E : 1 2 ` h 1 2i ∼ 1 D

β-conversion snd Γ E : Γ E : 1 ` 1 C 2 ` 2 D Γ , Γ snd C×D( E ,E )=E : 1 2 ` h 1 2i ∼ 2 D

η-conversion pair Γ E : ` C×D Γ fst C×D(E),snd C×D(E) = E: `h i ∼ D

together with the congruence rules not listed here. A novel rule arises from inter- nalising small products as domains of functor categories. Thus there is a rule for the adjunction (2.14):

Curry Γ1,x: E1: Γ2,y: E2: small ` C×D` ´ B C×D`` BC×D ´ op Γ , Γ2 [ , ] λx.E1,λy.E2 =[ ,[ , ]] λv.λw.E1[ v, w /x],λv.λw.E2[ v, w /y] :Set 1 ` C×D B ∼ C D B h i h i

where some types are omitted to simplify the notation. The “swapping” of arguments of bifunctors is derived from Curry as sketched by the chain of isomorphisms  [ , [ , ]] λv.λw.E [ v, w /x],λv.λw.E [ v, w /y] C D B R 1 h i 2 h i  = [ , ] λw.E1[ v1,w /x],λw.E2[ v2,w /y] nat formula ∼ Rv1,v2 RD B h i h i = E1[ v1,w1 /x],E2[ v2,w2 /y] nat formula ∼ Rv1,v2 Rw1,w2 B h i h i  = E1[ v1,w1 /x],E2[ v2,w2 /y] Fubini ∼ Rw1,w2 v1,v2 B h i h i  = [ , ] λv.E1[ v, w /x],λv.E2[ v, w /y] nat formula ∼ v1,v2 C B h i h i  [ , [ , ]] λw.λv.E [ v, w /x],λw.λv.E [ v, w /y] nat formula. D C B 1 h i 2 h i Thus from transitivity and Curry we have the derivable rule:

swap Γ1,x: E1: Γ2,y: E2: small ` C×D`´ B ` C×D` BC×D ´ op Γ , Γ2 [ , ] λx.E1,λy.E2 =[ , ] λv.E1[ snd (v), fst (v) /x],λw.E1[ snd (w), fst (w) /x] :Set. 1 ` C×D B ∼ D×C B h i h i

6.1.5 Examples 6.1.6 Limits

Limits are ends where the functor involved is extended with a “dummy” argument. The definition of limits as given by a representation is derived from the rule def end. Assume the judgements

Γ,y:C E: C small complete. ` D D 6.1. Isomorphism Judgements 113

We first derive

identity w: w: D` D weakening w: ,x:C w: Γ,y:C E: D ` D ` D R nat formula op C C Γ,w: [C, ](λx .w, λy .E) = Cop C (w, E):Set. D ` D ∼ x ,y D Then, . . Γ,y:C E: ` D weakening+exchange Γ,x:Cop,y:C E: ` D R R def end op Γ,w: Cop C (w, E) = (w, Cop C E):Set. D ` x ,y D ∼ D x ,y Finally by transitivity R op C C Γ,w: (w, Cop C E) = [C, ](λx .w, λy .E):Set. D `D x ,y ∼ D R As x does not occur free in E we just write yC E.

6.1.7 Density Formula and the Yoneda Lemma In 3.5.3 we show three different forms in which a presheaf can be expressed as a colimit.§ Here we formalise the proof for the density formula in the calculus and show that in fact their expression is (in some sense) the dual for the Yoneda lemma. The interpretation for a derivation . . δ . (6.1) Γ,x:Cop E :Set ` results in a functor [[δ B Γ,x:Cop E : Set]] : Γ C op Set, a presheaf with parameters. From (6.1) we can derive` the sequent × →

R Cop C Γ,x:Cop w ,y E[w/x] C(x, y) ` ⊗ the so-called density formula for E. Then we have the chain of isomorphisms

R Cop C  R   w ,y E[w/x] C(x, y),z = Cop C E[w/x] C(x, y),z (def end)∗ ⊗ ∼Ry ,w  ⊗  Cop C C(x, y), [E[w/x],z] (def power) + congruence ∼= y ,w ∗ ∼= [E,z] Yoneda∗ and then by transitivity there is a derivation

. . R Cop C  w ,y Γop,x:C,z:Set E[w/x] C(x, y),z =[E,z]:Set ` ⊗ ∼ representable∗ R Cop C w ,y Γ,x:Cop E[w/x] C(x, y) = E :Set. ` ⊗ ∼ Then by further use of symmetry and congruence we have the derivable rule 114 Chapter 6. Natural Isomorphisms

density

Γ,x: op E :Set small C ` C R op w ,y Γ,x: op E = C C (x, y) E[w/x]:Set C ` ∼ C ⊗ In order to derive density we need the Yoneda lemma in the calculus, but the relation goes beyond that. In fact the dual form of the density formula gives a form of the Yoneda lemma for Setop: Γ,x:C E:Setop ` dual op op Γ ,x:C E∗ :Set ` density R Cop C op op w ,y Γ ,x:C E∗ = C(x, y) E∗[w/x]:Set ` ∼ ⊗ R   dual iso op Γ,x:C E = Cop C C(x, y),E[w/x] :Set . ` ∼ y ,w 6.2 Interpretation

As proved in the presentation of the rules for natural isomorphisms a derivation

. . δ Γ E = E : ` 1 ∼ 2 D in turn determines derivations

. . . δ1 . δ2 Γ E : and Γ E : . ` 1 D ` 2 D An interpretation for δ is a natural isomorphism

[[ δ B Γ E = E : ]] : [[ δ B Γ E : ]] = [[ δ B Γ E : ]] . ` 1 ∼ 2 D 1 ` 1 D ∼ 2 ` 2 D We show how to build this natural isomorphism incrementally by considering the effect of each of the rules. The interpretation for natural isomorphisms is not coherent with respect to the syntax. Different derivations may produce different witnesses that two functors are naturally isomorphic. In general the judgement Γ E1 ∼= E2 : is understood as asserting that there is a derivation and thus the existence` of a naturalD isomorphisms between the corresponding functors. Notice that as a consequence of the coherence for functoriality this interpretation ensures the existence of a natural isomorphisms between any other interpretations of Γ E1 : and Γ E2 : , in particular between the functors obtained by the derivations` D in normal` form. D To simplify the notation we sometimes represent functorial judgements by just their expressions, where contexts and type information can be recovered from the isomorphism judgement.

6.2.1 Lambda Calculus The interpretation for the equational theory of the lambda calculus in a carte- sian closed category is well-known and studied elsewhere [Sza78,LS86,Cro93,AC98, 6.2. Interpretation 115

Jac99, Tay99, Pit00]. Here we just revise the theory for the particular case where the categorical model is giving by CAT. The semantics of the structural rules follow a similar pattern that the case for functoriality. For instance if the interpretation of the premise weakening yields the natural isomorphism

θ [[ Γ E : ]] = [[ Γ E : ]] ` 1 D ∼ ` 2 D then the interpretation of the complete derivation is

θ idπ [[ Γ ,x: E : ]] ◦= [[ Γ ,x: E : ]] C` 1 D ∼ C` 2 D where [[Γ,x: Ei: ]] = [[ Γ E i : ]] π (for i =1,2), π is the projection and C` D ` D ◦ idπ is the identity natural isomorphism associated. Similarly for exchange and contraction. For β -conversion we use the semantics of substitution (see 5.3.4) as compo- sition in CAT. Given a derivation §

. . . δ1 . δ2

Γ1,x:C E1: Γ2 E2: ` D ` C β-conversion Γ ,Γ (λxC.E )E = E [E /x]: 1 2 ` 1 2 ∼ 1 2 D as eval is the counit of the adjunction defined by λ (2.14) then the triangles in the diagram

λ ([[δ BΓ ,x:C E : ]] ) [[ δ B Γ E : C ]] Γ Γ 1 1 ` 1 D × 2 2 ` 2 / [ C , ] C eval 8 / 1 2 l 5 × llll D × D λ([[δ BΓ ,x:C E : ]] ) C 1 ll1l ` 1 D × B C l l B C Γ1 [[ δ 2 Γ 2 E 2 : ]]- [[ δ 1 Γ 1 ,x: E1: ]] × ` Γ C ` D 1 × commute. The lower composition is the semantics for the substitution. The natural isomorphism defined by η-conversion is just the one-to-one corre- spondence:

B C C [[ δ Γ 1 E :[ , ]]] eval Γ C ` D × /[C, ] C / × D × D [[ δ B Γ E :[C, ]]] Γ 1 ` D / D for some derivation δ. For the equivalence rules, reflexivity is interpreted as the identity natural trans- formation over the functor defined by the canonical derivation of E, symmetry reverses the natural isomorphism in the premise and transitivity is the result of composing the natural isomorphisms defined by the interpretation of the premises. Finally the congruence rules correspond to the application of a functor to an argu- ment. As all the expressions involved are functorial by construction, then we can ensure that the application of those expressions to particular isomorphic instances preserves the isomorphism: the slogan is “functors preserve isomorphisms”.

6.2.2 Axioms The rules used to model the definitions of end and power are indeed axioms at the level of isomorphism judgements. They are basically interpreted through a repre- 116 Chapter 6. Natural Isomorphisms sentation for a Set-valued functor. For instance the interpretation of a derivation

. . δ Γ,x:Cop,y:C E: ` D R R op Γ,w: (w, Cop C E) = Cop C (w, E):Set D `D x ,y ∼ x ,y D is a consequence of the definition for ends 3.2.1 together with the fact that repre- sentables preserve ends (Proposition 2.2.8). The situation is similar for the rules nat formula, Fubini and Yoneda.The first one introduces the isomorphism defined by the naturality formula (3.4), the second one is interpreted through the Fubini result for ends (see 3.2.5) and the last one is just the Yoneda Lemma as an end formula 2.1.3. The rule§ opposite cat is as well an axiom which basically captures the definition of opposite category (see 1.3). § 6.2.3 Representability and Duality For the remaining rules we have:

representable • The derivation

. . δ op Γ,x: (x, E1) ∼= (x, E2):Set C `C C representable Γ E = E : ` 1 ∼ 2 C is interpreted as θ [[ E 1 ]] ( id[[ E 1 ]] ) [[ E 1 ]] ∼= [[ E 2 ]] θ where [[ (x, E )]] = [[ ( x, E )]] (this follows from Proposition 2.1.5). C 1 ∼ C 2 dual iso • The derivation . . δ

Γ E1 ∼= E2 : ` C dual iso op op Γ E∗ = E∗ : ` 1 ∼ 2 C is interpreted as the action of the 2-functor ( )op over the natural isomorphism defined by δ op [[ δ B Γ E 1 = E 2 : ]] [[ E ]] ` ∼ C [[ E ]] . 1∗ ∼= 2∗

6.2.4 Lack of Coherence As with judgements for functoriality, for any derivable isomorphism sequent there are several derivations. In this case it is not just a consequence of the presence of structural rules and duality, and in fact there is no coherence result. As the example below shows different derivations for the same isomorphism sequent could yield different natural isomorphisms. 6.3. Weighted Limits 117

The interpretation for the derivation

identity identity x:Set x:Set y :Set y :Set ` ` power∗ x:Set,y:Set x y :Set ` ⊗ contraction w:Set w w:Set ` ⊗ reflexivity w :Set w w = w w:Set ` ⊗ ∼ ⊗ is the identity natural isomorphism. The copower over Set is just the cartesian product and then the interpretation corresponds to the componentwise identity. There is another derivation given by the definition of power. We first have the instances of copowers and powers definitions

identity identity x:Set x:Set y :Set y :Set ` `   (def power)∗ x:Setop,y:Setop,z:Set [x y,z] = x, [y,z] :Set ` ⊗ ∼

identity identity y :Set y :Set w:Set w:Set ` ` (6.2)     def power x:Setop,y:Setop,z:Set x, [y,z] = y,[x, w] :Set ` ∼

identity identity y :Set y :Set x:Set x:Set ` `   (def power)∗+symmetry x:Setop,y:Setop,z:Set y,[x, z] = [x y,z]:Set ` ∼ ⊗ and then by transitivity

. . x:Setop,y:Setop,z:Set [x y,z] = [y x, z]:Set ` ⊗ ∼ ⊗ representable∗ x:Set,y:Set x y ∼= y x:Set ` ⊗ ⊗ contraction w:Set w w = w w:Set. ` ⊗ ∼ ⊗ The interpretation for this derivation is the “twist” function acting as (a, b) (b, a). The core part of this interpretation is given by the semantics of (6.2). Then7→ there two different derivations for

w:Set w w = w w:Set ` ⊗ ∼ ⊗ which yield different natural isomorphisms.

6.3 Weighted Limits

When it comes to reasoning about presheaf categories it is more natural to approach universality through weighted limits. In principle weighted limits are no more than 118 Chapter 6. Natural Isomorphisms ordinary limits and they should be present already in the type theory. In this section we show that this is in fact the case. Let us first extend the syntax with two binders for weighted limits and colimits

H H op xC ,yC E ::= ... (E1,E2) (E2,E1). xC,yC | These binders are binary operations which capture one variable at each argument, i.e. they have arity 1, 1 (where the lambda abstraction is 1 andH the integral is h i h i 2 , see [Plo90,FPT99]). Notice that here the order of the variables in (E2,E1) xC,yC hdoesi matter. The following rule defines the typing for weighted limit expressions:

wlimit Γ1,x: E1:Set Γ2,y: E2: small complete C` HC` DC D op Γ1 , Γ2 (E1,E2): . ` xC ,yC D

Remember from the discussion in 3.5.1 that the weights are contravariant when § op thought as parameters, this is expressed by the dual context Γ1 . This induces the following definition for substitution H H (E1,E2)[E/x]= (E1[E∗/x],E2[E/x]) yC ,wC yC,wC for x = y and x = w. This is accompanied by a suitable definition for the meta- 6 6 operation ( )∗ to cover the new expressions:

H  H op H op  H xC,yC xC ,yC (E1,E2) ∗ = (E1,E∗) (E1,E2) ∗ = op op (E1,E∗). xC ,yC 2 xC ,yC 2 Then the typing rule for weighted colimits is derivable from the one for limits and duality. Given the sequents

Γ ,x:Cop E :Set Γ ,y:C E : C small cocomplete 1 ` 1 2 ` 2 D D we have the derivation

Γ2,y:C E2: . ` D dual op op op op Γ ,x:C E :Set Γ ,y:C E∗ : 1 ` 1 2 ` 2 D H wlimit op op op Γ , Γ Cop Cop (E ,E∗): 1 2 ` x ,y 1 2 D dual H Cop C Γ , Γ x ,y (E ,E ): . 1 2 ` 1 2 D That gives the derivable rule

wlimit∗ Γ ,x: op E :Set Γ ,y: E : small cocomplete 1 C ` 1 2 C` 2 DC D H op Γ , Γ xC ,yC (E ,E ): . 1 2 ` 1 2 D

Now we can give the definition of weighted limits as a representation:

def wlimit 6.3. Weighted Limits 119

Γ1,x: E1:Set Γ2,y: E2: small complete C` H C` DC D  op op Γ1 , Γ2,w: (w, (E1,E2)) = [ , Set] λxC .E1,λyC. (w, E2) :Set D `D xC,yC ∼ C D where the left-hand side is justified by

Γ1,x: E1:Set Γ2,y: E2: identity C` H C` D wlimit op w: w: Γ1 , Γ2 (E1,E2): D` D ` xC ,yC D H hom+exchange’s op op Γ1 , Γ2,w: (w, (E1,E2)):Set D `D xC,yC and the right-hand side by

identity w: w: Γ2,y: E2: D` D C` D hom+exchange’s op Γ1,x: E1:Set Γ2,w: ,y: (w, E2):Set C` lambda D C`D lambda op Γ λxC .E :[ ,Set] Γ ,w: λyC . (w, E ):[ ,Set] 1 ` 1 C 2 D ` D 2 C  hom op op Γ , Γ ,w: [ , Set] λxC.E ,λyC. (w, E ) :Set. 1 2 D ` C 1 D 2 As expected the definition for weighted colimits is derived from the one for weighted limits together with duality. Given the judgements

Γ ,x:Cop E :Set Γ ,y:C E : C small cocomplete (6.3) 1 ` 1 2 ` 2 D D there is a derivation Γ ,x:Cop E :Set Γ ,y:C E : 1 ` 1 2 ` 2 D H wlimit∗ identity Γ ,Γ Cop C (E ,E ): w: w: 1 2 ` x ,y 1 2 D D` D opposite cat H Cop C  H  op op x ,y op Γ , Γ ,w: (E ,E ),w = w, Cop Cop (E ,E∗) :Set. 1 2 D`D 1 2 ∼D x ,y 1 2 Then by transitivity we have H   op op Cop Cop op w, Cop Cop (E1,E∗) =[C , Set] λx .E1,λy . (w, E∗) def wlimit D x ,y 2 ∼ D 2 Cop Cop = [Cop, Set] λx .E ,λy . (E ,w) opposite cat + congruence. ∼ 1 D 2 We can formalise the proof of Proposition 3.5.3 in the calculus, but more in- teresting from the rule def singleton we can show that a weighted limit is just a limit. Given a functoriality judgement Γ,x:C E: ` D where is a complete category we can derive in the calculus the isomorphism D R H Γ C E = C C (1,E): (6.4) ` x ∼ y ,x D where y is not present in Γ. The heart of this proof is given by the chain of isomorphisms  R [C, ] λy.w, λx.E = Cop C (w, E) nat form D ∼ Ry ,x D  = Cop C 1, (w, E) def singleton + congruence ∼ y ,x D = [C, Set](λy.1, λx. (w, E)) nat form. ∼ D where y and w are not free in E. 120 Chapter 6. Natural Isomorphisms

6.4 Another Approach to Contravariance

The contravariance on the left-hand argument in hom-expressions has been mod- elled by dualising the type of the free variables. That forces a context-independent presentation for the rule

hom Γ E : Γ E : 1 ` 1 C 2 ` 2 C Γop, Γ (E ,E ):Set 1 2 `C 1 2 since we need to keep track of the free variables in E1. An alternative approach which avoids the modality ( )op acting on contexts is to require E to be of type op 1 C hom2 Γ E : op Γ E : ` 1 C ` 2 C Γ (E ,E ):Set. `C 1 2 This solution falls far from the usual practice in category theory, imagine for instance a calculus where the expression

x: op,y: op,z: (x y,z) = (x, z) (y,z) (6.5) C C C`C × ∼ C ×C holds (where x y : op). There is a compromised× C solution which consists of introducing the rule hom2 instead of hom but keeping an explicit track of the contravariance by adding a new constructor to the syntax: E ::= ... E∗. | Now the usual rule dual introduces the piece of syntax ( )∗. The judgement (6.5) would still hold, but the more natural

op op x: ,y: ,z: ((x y)∗,z)= (x, z) (y,z) C C C`C × ∼C ×C holds as well. Propositions 5.1.2 and 5.1.4 are not longer meaningful, and their effect is achieved via explicit isomorphism rules, like for instance

Γ,x:C E: ` D op C Cop op op Γ (λx .E)∗ = λx .E∗ :[C , ] ` ∼ D and so on for the other definition clauses in 5.1.1. Then from the congruence rules can be proved that the rule Γ E : ` D

Γ E = (E∗)∗ : ` ∼ D is admissable. The definition for substitution is simplified since there is no special case to consider, and then we can as well show that

Γ,x: E : Γ E : C` 1 D ` 2 C

Γ (E[E/x])∗ = (E∗[E∗]): ` 1 2 ∼ 1 2 D where E1[E2/x] is the usual substitution. 6.4. Another Approach to Contravariance 121

The definition of DCW-normal derivation does not make any sense in this ap- proach as duality is explicitly represented in the language. Now only the structural rules can lead to different derivations for the same functoriality judgement. Most of these features are indeed disadvantages of the approach since the inter- pretation will distinguish more than necessary and force us to carry on with if not useless at least redundant isomorphisms. This is worsened by the fact that expres- sions grow in complexity and proofs need to deal with a syntactic bookkeeping of ( )∗’s. 122 Chapter 6. Natural Isomorphisms Chapter 7

Towards a Calculus for Enrichment

In enriched category theory hom-expressions are interpreted as objects in a base category . In this chapter we show how the 2-category of -categories gives a model for a substructuralV version of the calculus. Most of theV constructions for locally small categories import to the enriched case smoothly but limits. In particular weighted limits are more general than ends and then take a prominent position. In the calculus this situation is reflected by the lack of structural rules for weakening and contraction. We introduce the basic concepts of enriched category theory by emphasising on the constructions modelled in the calculus. Most of the introductory material is extracted from “Basic Concepts of Enriched Category Theory” [Kel82], other references are [Dub70,Bor94b,BS00].

7.1 Symmetric Monoidal Closed Categories

A is a locally small category 0 equipped with a bifunctor : ,V an object e and natural isomorphismsV −⊗− V0 ×V0 →V0 ∈V0 ax,y,z (x y) z = x (y z) x,y,z •h ⊗ ⊗ ∼ ⊗ ⊗ i

lx e x=xx,and •h ⊗ ∼ i rx x e=xx •h ⊗ ∼ i such that the pentagon

(w x) (y z) kk5 SSS kkk ⊗ ⊗ ⊗ SSS kakk SaSS kkk SSS kkk SS) ((w x) y) z w (x (y z)) ⊗ O ⊗ ⊗ ⊗ ⊗O ⊗ a id id a ⊗ ⊗ (w (x y)) z / w ((x y) z) ⊗ ⊗ ⊗ a ⊗ ⊗ ⊗ commutes, called associativity coherence, and the triangle

(x e) y a / x (e y) ⊗ ⊗LL r⊗ ⊗ LLL rrr LLL rrr r id LL rr id l ⊗ & yr ⊗ x y ⊗

123 124 Chapter 7. Towards a Calculus for Enrichment commutes, called the identity coherence. As usual we omit the subscripts in the components of the natural transformations to simplify the notation. The bifunctor is called the tensor product of the monoidal category. The cele- brated “coherence⊗ theorem” on monoidal categories establishes that every diagram commutes. Here by diagram we mean the ones resulting from combining by means of instances of a, l, r, their inverses and identities (see [Mac98]). A simple exam- ple⊗ of monoidal category is given by categories with finite products: just take the product as inducing the tensor bifunctor and the terminal object as e; the pentagon and triangles follow from the universal property of product. A symmetric monoidal category extends the list of natural transformations a, l and r with a symmetry for the tensor

sx,y x y = y x x,y h ⊗ ∼ ⊗ i satisfying the axioms x y s / y x HH ⊗ HH ⊗ HH HH s id H$  x y ⊗ and (x y) w a / x (y w) s / (y w) x ⊗ ⊗ ⊗ ⊗ ⊗ ⊗ s id a ⊗   (y x) w / y (x w) / y (w x). a id s ⊗ ⊗ ⊗ ⊗ ⊗ ⊗ ⊗ A monoidal category is said to be closed if each induced functor V x: ⊗ V0 →V0 has a right adjoint x [x, ], ⊗ a i.e. there is an isomorphism

(w x, y) = (w, [x, y]) (7.1) V0 ⊗ ∼ V0 natural in w, y. As expected the counit of this adjunction is given by the evaluation morphisms eval:[x, y] x y. ⊗ → Remember from 2.3 that for an arrow f : w z the action [x, f] corresponds under the adjunction§ to → f [x, w] x eval /w /z. ⊗ If for each x 0 the induced partial functor x : 0 0 has as well a right adjoint we say that∈V is biclosed. It follows that if⊗ isV symmetric→V and closed then it is biclosed. In thisV case by Proposition 2.3.2 the expressionV [ ,x] is functorial in x as well giving rise to a bifunctor

[ , ]: op V0 ×V0 →V0 where for f : w z the arrow [f,x] corresponds under the adjunction (7.1) to the arrow → id f eval [z,x] w ⊗ /[z,x] z /x. ⊗ ⊗ 7.2. -Categories, -Functors and -Naturality 125 V V V 7.2 -Categories, -Functors and -Naturality V V V A monoidal category is enough to replace the role of the category Set in defining the structure of the hom-expression.V Then by adding more requirements on we can recover most of the categorical constructions. V Let be a monoidal category. A -category is defined by V V C a collection of objects (as usual we write x ), • ∈C an object (x, y)in for each pair x, y , • C V0 ∈C a composition arrow m: (y,z) (x, y) (x, z)foreachx, y, z ,and • C ⊗C →C ∈C an identity “element” jx :e (x, x) • →C such that for each x, y, w, z the diagram   (w, z) (y,w) (x, y) a / (w, z) (y,w) (x, y) C ⊗C ⊗C C ⊗ C ⊗C m id id m ⊗   ⊗ (y,z) (x,S y) (w, z) (x, w) C ⊗C SSS Ckkk ⊗C SSS kkk SSS kkk m SSS kkk m SS) ukkk (x, z) C commutes, called the associativity axiom, and the diagram

(y,y) (x, y) m / (x, y) o m (x, y) (x, x) O m6 hQQ O C ⊗C mmm C QQQ C ⊗C mmm QQQ j id mmm QQQ id j ⊗ mmm l r QQ ⊗ e (x, y) (x, y) e ⊗C C ⊗ commutes, called the identity axioms. If the collection of objects of is a set we say that is a small -category. C FromC -categoriesV it is not difficult to see how to give suitable definitions for the notionsV of -functors and -naturality. Let us play this enrichment game by revising the basicV categorical conceptsV in chapter 2 at the light of this more abstract notion of category. Given two -categories and ,a -functor F : consists of V A B V A→B a mapping F from the objects of to the objects of ,and • A B for every pair x, y there is an arrow • ∈A Fx,y : (x, y) (F(x),F(y)) A →B in such that for each x, y, w the diagram V0 j / e NNN (x, x) NNN A NNN NN F j NN&  (F (x),F(x)) B commutes, i.e. F preserves identities; and the square

(y,w) (x, y) m / (x, w) A ⊗A A F F F ⊗   (F (y),F(w)) (F(x),F(y)) / (F (x),F(w)) B ⊗B m B 126 Chapter 7. Towards a Calculus for Enrichment

commutes, i.e. F preserves compositions. For -functors F, G : (this of course carries that and are - categories),V a -natural transformationA→B α : F G is defined by aA family B V V ⇒

αx :e (F(x),G(x)) x h →B i of morphisms in such that for each x, y V0 G α / 7(x, y) e ⊗ (G(x),G(y)) (F(Vx),G(x)) oAo ⊗ B ⊗B VVVV 1 oo VVV r−oo VmVV oo VVVV ooo VVV* (x, y)O 4 (F (x),G(y)) A OO hhhhB OOO hhhh OO hhhh 1 OO hhh m l− O' hhh e (x, y) / (F (y),G(y)) (F(x),F(y)) α F ⊗A ⊗ B ⊗B commutes, i.e. the naturality square commutes. The collection of identity elements gives as expected a natural transformation defined componentwise as

j :e (F(x),F(x)) x . h →B i ∈A Compatible functors compose just by composing each of the arrows defining them, in the same spirit we can compose -natural transformations. Let α : F G and β : G H be -natural transformations.V The composition β α is defined⇒ at component⇒x to beV the arrow ◦

βx αx / m / e = (e e) ⊗ (G(x),H(x)) (F(x),G(x)) (F (x),H(x)) ∼ ⊗ B ⊗B B in 0. It is routine though tedious to verify that these definitions satisfy the required conditions.V Thus the collections of -categories, -functors and -natural transformations form a 2-category that we calledV here CATV . In particularV if = Set the category of -categories is just CAT. AnotherV example comes by takingV = CAT where weV recover the categories of 2-categories. Henceforth we use theV terms category, functor and natural transformation to mean the corresponding notion in the - enriched setting when there is not possibility of confusion. V

7.2.1 Opposite -Category V In order to be able to define opposite -categories we need to be a symmetric monoidal category. The opposite categoryV op has the sameV objects as and for each x, y the hom-object is defined as A A

op(x, y)= (y,x). A A

Remember that this refers to equality of objects in 0. The identity elements are those of . The symmetry of is required for the definitionV of composition. The compositionA arrow of op for objectsV x, y, w is A

(w, y) (y,x) s / (y,x) (w, y) mA / (w, x) A ⊗A A ⊗A A It is routine to verify that this definition gives indeed a -category. V 7.2. -Categories, -Functors and -Naturality 127 V V V

In fact there is a 2-functor over CAT with the expected behaviour. Given a functor F : , the opposite functorV F op : op op acts over objects as F and over hom-objectsA→B as A →B

op(x, y)= (y,x) F / (F(y),F(x)) = op(F (x),F(y)). A A B B Given a natural transformation α : F G the opposite αop : Gop F op is defined componentwise as ⇒ ⇒ α / e NNN (F (x),G(x)) NNN B NNN op NN α NN' op(Gop(x),Fop(x)). B Now as expected we call a functor F : op a contravariant functor. Still to be able to define hom-functors in the theoryA →B of -categories we need to support bifunctors. V

7.2.2 -Bifunctors V As it is the case for product in CAT, the tensor product of canbeextendedtoa tensor product in CAT. For categories and ,thetensorV product is the category where V A B A⊗B

the collection of objects is the cartesian product of the collection of objects of • and , A B the hom-objects are defined as •

((x, y), (x0,y0)) = (x, x0) (y,y0), A⊗B A ⊗B

a composition arrow m is •   m / (x0,x00) (y0,y00) (x, x0) (y,y0) 2 (x, x00) (y,y00) A ⊗B ⊗ A ⊗B fffffA ⊗B fffff ffffff middle four interchanged fffff  ffff mA mB   ⊗ (x0,x00) (x, x0) (y0,y00) (y,y0) A ⊗A ⊗ B ⊗B where middle four interchanged is obtained from a combination of instances of a and s;and

the identity element is the arrow • j j / e = (e e) ⊗ (x, x) (y,y). ∼ ⊗ A ⊗B

It is again routine though even more tedious to verify that this definition gives indeed a -category. Now functors with domains given by tensor categories, like F : V , correspond to the bifunctors. As in the case of CAT, F induces the A⊗B →C x partial -functors F : and Fy : . For our development is interesting to noticeV that indeed byB→C following the definitionA→C we can show ( )op= op op. A⊗B A ⊗B 128 Chapter 7. Towards a Calculus for Enrichment

7.2.3 The Underlying “Ordinary” Category

Let be a monoidal category. A global element a of x 0 is an arrow a : e x. NowV for a -category , the global elements of the object∈V (w, z) can be thought→ as the arrowsV from w toA z in . Indeed as is locally smallA the collection A V  e, (w, z) V0 A is a set. This allows us to define the underlying ordinary category 0 where the ob- jects are the ones from and arrows are just the global elements.A The composition of compatible “arrows”Ag and f is given by the global element

g f / m / e = (e e) ⊗ (y,z) (x, y) (x, z). ∼ ⊗ A ⊗A A In the same spirit we can define underlying functors and natural transformations. In fact those definitions give rise to an “underlying” 2-functor from CAT to CAT. V This constructions allows us to define the notion of isomorphism in a -category. Two object a, b are isomorphic if there is an isomorphisms a = b inV . ∈A ∼ A0

7.3 Representable Functors and Universality

Thus the last step towards the notion of representability in the theory of enrichment comes with the verification that itself can be seen as a -category. This requires to assume that is a symmetricV monoidal closed category.V V Then there is a -category where V the objects are those of , • V the hom-object for x, y is • ∈V (x, y)=[x, y], V

the composition morphism • [y,z] [x, y] m /[x, z] ⊗ corresponds under the adjunction (7.1) to the arrow   a / id eval/ eval / [y,z] [x, y] x [y,z] [x, y] x ⊗ [y,z] y z, ⊗ ⊗ ⊗ ⊗ ⊗

the identity element • j e /[x, x]

corresponds under (7.1) to

e x l /x. ⊗ Of course we should verify by checking some big diagrams that this in fact gives a -category. As an example it follows the proof that j and m above satisfy one of theV identity axioms: 7.3. Representable Functors and Universality 129

j id m e [x, y] ⊗ /[y,y] [x, y] /[x, y] ⊗ ⊗  (j id) id/ m / e [x, y] x ⊗ ⊗ [y,y] [x, y] x y< y ⊗ ⊗ ⊗ ⊗ yy yy a (1) a (2) yy yy eval     y e [x, y] x / [y,y] [x, y] x / [y,y] y j id id eval ⊗ ⊗ ⊗ ⊗ ⊗ ⊗ ⊗ l id id eval (3) id eval ⊗ (5)  ⊗  ⊗ / / l e y [y,y] y 84 y ⊗ j id ⊗ eval ⊗ (4) #  (6) l [x, y] x ⊗ eval e [x, y] l /[x, y] ⊗ where

(1) commutes by naturality of a,

(2) commutes by definition of m,

(3) commutes since is a bifunctor, ⊗ (4) commutes since from the adjunction (7.2) and definition of j

eval (j id)=j=l, ◦ ⊗ (5) commutes by coherence, and

(6) commutes by naturality of l.

It is straightforward to verify that the underlying “ordinary” category of as a -enriched one is . Then by definition every global element V V V0 f :e [x, y] → uniquely corresponds to an arrow f :x y. For a -category andanobject→x we can now define the representable -functorV (x, ): A mapping y ∈Ainto the hom-object (x, y) and acting Von hom-objectsA as definedA→V by (7.1) ∈A A

(x, ) (y,w) A /[ (x, y), (x, w)] A A A (y,w) (x, y) m / (x, w), A ⊗A A i.e. by post-composition. In a similar way we can define the contravariant repre- sentable functor ( ,z): op . Indeed (x, )and ( ,z) are the partial functors of the hom-functorA A →V A A

( , ): op . A A ⊗A→V This bifunctor acts on hom-objects as

 ( , ) op A / ( ) (y,w),(y0,w0) [ (y,w), (y0,w0)] A ⊗A A A  (id m) a ⊗ ◦ / m s / (y0,y) (w, w0) (y,w) (y0,y) (y,w0) ◦ (y0,w0). A ⊗A ⊗A A ⊗A A 130 Chapter 7. Towards a Calculus for Enrichment

It is cleat that in the case = the hom-functor coincide with [ , ]andthen have A V [x, [y,z]] = [x y,z] = [y x, z] = [y,[x, z]]. (7.2) ∼ ⊗ ∼ ⊗ ∼ As in the ordinary case a functor F : op is representable if there exists an isomorphism C →V θ ( ,c)=F C ∼ for some c . However, we find here the first divergence from the theory of locally small categories∈C in that there is no characterisation of -representability as the one given by Theorem 2.1.4. There is otherwise a parametrisedV representability result.

Proposition 7.3.1 Let F : op be a functor such that for each a the induced functor F a : Ahas⊗B→V a representation ∈A B→V θa (G[a], ) = F a. B ∼ Then for each x, y there is a unique arrow ∈A (x, y) / (G[x],G[y]) A B in which makes G a functor and then θ is natural in a as well. V The proof of this results is in [Kel82]. This is crucial for the semantics of the calculus since it allows us to model the interpretation of typing judgements as asserting -functoriality. V

7.3.1 Functor -Categories and the Enriched Yoneda Lemma V We also expect to recover the naturality formula and the Yoneda lemma to success- fully model the calculus in CAT. This leads first to the notion of extraordinary -naturality, or more informallyV the enriched wedges. V Let F : op be a bifunctor. A family of morphisms in A ⊗A→B V0

τx :e (a, F (x, x)) x h →B i ∈A is an extraordinary -natural transformation if for each x, y the diagram V ∈A  F (x, x),F(x, y) B nn7 RRRR x nn R Fnnn nn (τx,F (x,yRR))R nnn B RR( (x, y) (a, F (x, y)) PP l6 A PPP lllB PPP l PP (τly ,F (x,y)) F PP Bll y ' ll  F (y,y),F(x, y) B commutes. The arrow (τx,F(x, y)) is an abbreviation for the composition B

id τx / m / (F (x, x),F(x, y)) e ⊗ (F (x, x),F(x, y)) (a, F (x, x)) (a, F (x, y)) B ⊗ B ⊗B B

There is of course a symmetric definition for families σx :F (x, x) b x. h → i 7.3. Representable Functors and Universality 131

For the special case = the condition expressed by the diagram above can be rephrased as the commutativityB V of

F< (x, x)O z OOO zz OOf τxzz OOxO zz OOO zz  '  a DD (x,7 y),F(x, y) DD Aoo D ooo DD ooo τy D oo D" oo fy F (y,y).

This is a consequence of the isomorphism (7.2) where fx is the arrow which corre- sponds under the adjunction (7.1) to

s F x / F (x, x) (x, y) = (x, y) F (x, x) F (x, y). ⊗A ∼ A ⊗ A universal such a family is of course called the end of F and can be expressed as the in V0 Q f R Q x x / Q    τ / ∈A x F (x, x) x F (x, x) Q / x,y x, y ,F(x, y) . ∈A ∈A A y fy ∈A Given two categories and , then the “ordinary” category of -functors from to can be provided withA the structureB of a -category. The objectsV of the functor A-categoryB [ , ] are the -functors from Vto . For functors F, G : the VcorrespondingA hom-objectB V is defined to be theA endB A→B R [ , ](F, G)= (F(x),G(x)). A B xB From the concrete definition of end above and through a lengthly calculation we can verify that a global element

e α / [ , ](F, G) A B in fact corresponds to a -natural transformation from F to G. Notice that in order toV ensure the corresponding equaliser exists we require to be complete. As completeness here refers to “all small limits” the functor categoryV construction requires the domain to be small. Thus the naturality formula holds by definition in the theory of enriched categories. We can now state the Yoneda lemma for the enriched case:

Proposition 7.3.2 (Enriched Yoneda Lemma) Given a F : and a the morphism A→V ∈A (a, x) F /[F (a),F(x)] A corresponds under the adjunction (7.1) and symmetry to the morphism

ρ F (a) x /[ (a, x),F(x)]. A Then the pair (F (a),ρ)istheendof[ (a, ),F( )]: op . A A ⊗A→V The table below summarises the relation between the requirements on and the categorical constructions obtained in CAT V V 132 Chapter 7. Towards a Calculus for Enrichment

CAT V V monoidal categories, functors and natural transformation symmetric monoidal opposite categories and bifunctors symmetric monoidal closed hom-functors and representables complete symmetric monoidal closed functor categories Observe that we have not mentioned yet what is the notion of universality for the most general case. Ends so far are only defined for -valued functors, which in turn correspond to universal elements in the ordinary sense.V To define the right notion of limit in the enriched case is more subtle than the generalisations in the previous sections. Here the enrichment game ends abruptly justifying in first place the theory of enriched categories.

7.3.2 Tensors and Cotensors We can start by generalising the notions of power and copower which in this setting are called cotensor and tensor respectively. We just take the usual definition as a representation. For instance given a and x the cotensor is defined by ∈A  ∈V  ( , [x, a]) = x, ( ,a) . A ∼ A If admits all cotensor products we say that it is cotensored. for instance is clearlyA a cotensored category. V Similarly for a and x the tensor is defined by the representation ∈A ∈V (x c, ) = [x, (c, )]. A ⊗ ∼ A If has all tensor products we say that it is a tensored category. For the special A case = this definition recovers the tensor product in 0. We expect these definitionsA V to occur as special cases of the more general definitionV of limit.

7.3.3 A Notion of Limit In CAT a limit for a diagram D : I is given by a representation of the Set- valued functor →C [I, ](∆ ,D): op Set C C → where ∆ is the diagonal functor. For c the expression [I, ](∆c, D) denotes the set of “cones” from c to D (see 2.2). The∈C constant functor ∆Cc is define as the composition

∆c / I = @ == Ð == ÐÐ C == ÐÐ (7.3) ! = ÐÐ c 1 where 1 is the singleton category and c is the functor selecting c . In the enriched setting there is a counterpart of the singleton∈C category. The -category 1 has one object and 1( , )=ewhere j = id. This allows us to Vdefine for each object c a ∗-functor∗c∗:1 mapping to c and acting on the unique hom-object as ∈C V →C ∗ j 1( , )=e / (c, c). ∗ ∗ C Perhaps surprisingly there is no canonical -functor from I to 1. The obvious mapping x can not be matched by aV suitable action on hom-objects. For 7→ ∗ 7.4. An Enriched Model for the Calculus 133 instance if there is an arrow from I(x, x)to1( , )=ethere is no argument which ensures that the identity axiom for -functors∗ holds,∗ i.e. that the diagram V j e H / I HH (x, x) HH HH HH id H#  1( , )=e ∗ ∗ commutes. There is however a canonical functor from I to 1, the category with one element where 1( , )is the terminal object in . Notice that the terminal object exists since we∗ assume∗ > to be complete. It isV enough to have a section-retraction from to e to be ableV to define the enriched version of the constant functor. However, this> is not sufficient to express cotensors as instances of limits (for an example refer to [Kel82]). In any case for the most general case the notion of limit defined in terms of cones is not satisfiable. Borceux and Kelly [BK75] first introduced the weighted limits as attempt to find the suitable definition of limits for -categories. For functors V C G / @@ @@ D @@ F @ V the limit of G weighted by F is given by the enriched representation

(x, F, G ) = [C, ](F, (x, G( ))). D { } ∼ V D For examples of where usual conical limits and ends are defined in CAT we know they can be expressedV as weighted limits as well. Cotensor productsV are instances of weighted limits as required: given x and a ∈V ∈A [x, a]= x, a { } where a and x in the right-hand side are just the corresponding -functors V a / 1 ? ?? A ?? ?? x ? V which exists in CAT. Of course the dual construction for weighted colimits gives the tensors products.V All the properties in 3.5.1 about weighted limits can be rephrased for the enriched case. In particular§ the enriched version of Proposition 3.5.3 determines the definition of completeness for the most abstract case: a -category is complete is if it is cotensored and has all ends. V

7.4 An Enriched Model for the Calculus

Most of the rules for the calculus can be interpreted in the category CAT but the structural rules weakening and contraction. The absence of theseV rules reflect in the calculus the inability of defining limits as universal cones in the theory of enrichment. 134 Chapter 7. Towards a Calculus for Enrichment

7.4.1 Contexts and Judgements The basic type Set is now replaced by representing a complete symmetric monoidal closed category . At the level of expressionsV the singleton 1 is now written as e. Types in theV calculus denote -categories and expressions -functors. As tensors substitute products we need toV abandon the notion of cartesianV context and then some of the related structural rules. A context

Γ=x : , ,xn: n 1 C1 ··· C is interpreted by the tensor product of categories

[[ Γ ]] = n. C 1 ⊗···⊗C In this setting the empty context corresponds to the -category 1. This notion of context implies that the rule for weakeningV and contraction cannot be interpreted since there are not projection or diagonal functors associated to the tensor. The symmetry on , however, extends to a symmetry over the tensor product of categories providing anV interpretation for the rule exchange. A derivation . . δ Γ= ,... n E: C1 C ` C denotes a -functor V [[ δ B Γ E : ]] : ... n . ` C C 1 ⊗ ⊗C →C Although the rules for weakening and contraction are not longer present still the rule for duality produces different derivations for the same final sequent. The coherence result, however, is stronger since different derivation for the same final sequent result in the same functor. Remember that the only source of isomorphisms in the proof of coherence comes from the interaction of weakening and contraction with the rule for ends. An isomorphism judgement

. . δ Γ E = E ` 1 ∼ 2 denotes the existence of -natural isomorphisms between the functors [[E ]] a n d V 1 [[ E 2 ]]. Observe that some of the equations derivable in the calculus correspond to the natural transformations in the definition of . For instance the judgements V x: x e=x: and x: e x=x: V` ⊗ ∼ V V` ⊗ ∼ V are derivable in the calculus and denote the natural isomorphisms l and r respec- tively. The syntactic identification over types

( op)op = ( )op = op op [C, ]op =[Cop, op](1op)op = 1 C C A⊗B A ⊗B D D are by definition still valid in the enriched setting. Finally the identification of a hom-expression over with the cotensor product V (E ,E )=[E ,E ] V 1 2 1 2 corresponds to the definition of as a -category. V0 V 7.4. An Enriched Model for the Calculus 135

7.4.2 Structural Rules, Limits and Dinaturalities Limits are not equivalent to weighted limits in the enrichment case. This is reflected in the calculus by the impossibility to derive the isomorphism (3.9). Concretely as there is no rule for weakening then we can not derive the constant functor in the calculus. The attempt

w: ,y:C w: D ` D lambda w: λyC.w:[C, ] D` D cannot proceed into an axiom. On the other hand the lack of a rule for contraction leaves us without a deriva- tion for the diagonal functor. As a consequence of the context-independent presen- tation of the rules for a derivation

. . Γ (E ,E ): `C 1 2 V we can always split Γ in two disjoint contexts Γ1 and Γ2 such that the sequents

Γop E : and Γ E : 1 ` 1 C 2 ` 2 C are derivable. Another interesting fact of -enriched categories is that there is no notion of dinatural transformations. AlthoughV there is no explicit syntax for dinaturalities in the calculus they can be expressed as an end formula via the dinaturality for- mula (3.5). The corresponding expression, however, can only be derived with the use of contraction. For instance given the functoriality judgements

Γ ,x :Cop,y :C E : and Γ ,x :Cop,y :C E : 1 1 1 ` 1 D 2 2 2 ` 2 D we aim to derive the sequent R  op Γ , Γ Cop C E [y/x ,x/y ],E [x/x ,y/y ] : . 1 2 ` x ,y D 1 1 1 2 2 2 V This can be only obtained by the application of end over the sequent  Γop, Γ ,x:Cop,y:C E [y/x ,x/y ],E [x/x ,y/y ] : . 1 2 `D 1 1 1 2 2 2 V

Now the only possible way to identify the variables x1 with y2 and y1 with x2 is through contraction. 136 Chapter 7. Towards a Calculus for Enrichment Chapter 8

Extensions and Applications

We presented a typed language for category theory which formalises the notion of universal property. The logic is based on the presentation of universality as given by representations for suitable Set-valued functors. End for functors of multiple variance play a central role by providing the algebraic manipulation of expressions required. The calculus supports a syntactic treatment of duality which enforces a novel definition of substitution of raw terms. The model for the calculus is given by CAT, the category of locally small categories and functors. The types of the language represent categories and expressions are functors. In this interpretation the typing rules correspond to operations on functors. The calculus is encompassed with a theory for equations. The equational theory is based on that one for lambda calculus with new rules for ends, the Yoneda lemma and Fubini theorem among others. An equation-in-context in the theory asserts the existence of a natural isomorphisms between two functors. In the previous chapter we elaborated on the possibility of interpreting the cal- culus in a more abstract setting: the 2-category of enriched -categories CAT. As tensors replace products in the semantics for contexts thereV is no possibleV in- terpretation for weakening and contraction. These rules are key to prove the equivalence between limits, ends and weighted limits in the ordinary case. Indeed in the enriched setting the most general notion for universality is weighted limits where the other notions are special cases. We discuss below some possible extensions and further applications of the cal- culus.

Profunctors One of the original aims of our research was to give a formal framework to the categorical language which arose from the work done by Kelly, Borceux, Dubuc, Street, Day and others in enriched category theory. The main motivation is the use of functor categories and in particular presheaves in computer science. In recent years we have seen the development of domain-theoretic models for concurrency based on profunctors [Cat99, CW]. The manipulation of end formulæ advocated in this dissertation is central in this approach. Concrete models for concurrency as for instance labelled transitions systems can be interpreted more abstractly as presheaves over path categories. In this setting a path indicates a simple thread of execution. Thus functors between presheaves represent operations on models. The interest is focused on expressions denoting cocontinuous functors since they preserve the notion of equivalence. A future direction which would add value to the calculus as a tool for semantics consists of characterising the (co)continuous functors in the syntax. For instance,

137 138 Chapter 8. Extensions and Applications a direct consequence of Fubini is that coend expressions are cocontinuous in their variables whereas the tensor gives a simple counterexample since

x:Set x x:Set ` ⊗ is not cocontinuous in x. At a first glance a first measure to capture cocontinuity should constraint the use of contraction to avoid expressions as the one above.

Addressing the Lack of Coherence In order to be able to define a coherent equational theory we need to consider a more serious approach to types. In the presentation of the language and rules we left the issues concerning types deliberately aside. A proposal suggested by Glynn Winskel consists of adding to the logic a new form of judgement

! Γ E = E : ` 1 ∼ 2 C read as there is a unique natural isomorphisms between the functors interpreted by E1 and E2. Observe as a simple result that

! Γ E = E : ` 1 ∼ 1 C implies that for all E2

! Γ E = E : ΓE=E:. ` 1 ∼ 2 C⇒ `1∼2C Since the natural isomorphism represented by the left-hand side must be unique.

Richer Types As an attempt to obtain unique isomorphism judgements we extend the syntax for types with type variables. So far we use metavariables at the level of types which basically represented ground types. Now the syntax for types looks like

, ,...::= A,B,... op ... C1 C2 |C1 | where A,B,... are variable types for small categories. To keep track of the type variables in a judgement we extend the syntax with contexts for them: A ,...,Am; x : ,...,xn: n E : . | 1 {z } |1 C1 {z C} ` C ∆ Γ In this judgement all the free term-variables in E are in Γ and all the type variables in the type expressions 1,..., n, are in ∆. These kind of sequents denote a “dinatural” family of functors.C C IndeedC the context for term variables Γ and the type expression define functors C [[ ]] , [[Γ]]:(Catop)m Catm CAT. C × → Thus for every instance for the variables in ∆ the interpretation gives a functor. Exponentials in the type expressions require contravariant arguments. Consider for instance the judgement

A; f :[A, ],x:A f(x): D ` D where stands for given locally small category. The context gives rise to the functor D [ , ] / Catop Cat D × CAT. × 139 while the right-hand side expressions gives the constant functor over . The expres- sion f(x) is obviously interpreted as the evaluation functor which givesD a dinatural family. In this setting an isomorphism judgement

∆; Γ E = E : ` 1 ∼ 2 D should be interpreted as a “transformation” between the corresponding natural families. We borrow here some terminology from 2-categories and called those transformations of “di-modifications”. Glynn Winskel has shown that the lambda calculus fragment of the calculus can be interpreted in these higher-order semantics. Unfortunately already the hom-expressions fail to give a dinatural family.

Mechanisation in a Theorem Prover The calculus provides the basis for a mechanisation of category theory in a theorem prover. Our approach is based on an algebraic characterisation of universality which removes the usual set-theoretic issues. A draft of a possible implementation in the theorem prover Isabelle [Pau94] is described in [CW01]. The different syntactic components of the calculus are distributed in several user-defined theories which extend the initial theory Pure of the system. Basically, Pure gives the built-in higher-order logic [Pau88] on top of which we define the object-logic for categories. The judgements of the calculus correspond as usual to theorems in the meta-logic. 140 Chapter 8. Extensions and Applications Appendix A

The Calculus

A.1 Syntax

Types

, ,...::= Set op [ , ]. C D |C | C D

Expressions

E ,E ,...::= x 1 λxC .E E E (E ,E ) [E ,E ] E E 1 2 | | | 1 2 |C 1 2 | 1 2 | 1 ⊗ 2 | R R Cop C x ,y Cop C E E x ,y |

Syntactic Identities

( op)op = C C [C, ]op =[Cop, op] D op op D op ( ... n) = ... C1 × ×C C1 × ×Cn Set(E1,E2)=[E1,E2]

A.2 Rules for Functoriality

A.2.1 Axioms singleton

1:Set ` identity

x: x: C` C

A.2.2 Structural Rules weakening x : , ,xn: n E: 1 C1 ··· C ` C x : , ,xn: n,xn : n E : 1 C1 ··· C +1 C +1 ` C

141 142 Chapter A. The Calculus exchange x : , ,xi: i,xi : i , ,xn: n E: 1 C1 ··· C +1 C +1 ··· C ` C x : , ,xi : i ,xi: i, ,xn: n E: 1 C1 ··· +1 C +1 C ··· C ` C contraction Γ,x: ,y: E: C C` D Γ,z: E[z/x,z/y]: C` D

A.2.3 Logical Rules hom Γ E : Γ E : 1 ` 1 C 2 ` 2 C Γop, Γ (E ,E ):Set 1 2 `C 1 2 power Γ E :Set Γ E : complete 1 ` 1 2 ` 2 CC Γop, Γ [E ,E ]: 1 2 ` 1 2 C lambda Γ,x: E: small C` DC Γ λxC .E :[ , ] ` C D application Γ E :[ , ]Γ E: 1 ` 1 C D 2`2C Γ1,Γ2 E1E2: end ` D Γ,x: op,y: E: small complete C C` RDC D Γ op E : ` xC ,yC D dual Γ E : ` D op op Γ E∗ : where ( )∗ is defined in 5.1.1. ` D

A.3 Products

A.3.1 Syntax

Types

::= ... 1 C | |C1×C2

Expressions

E ::= ... E ,E fst C×D(E) snd C×D(E) |hi|h 1 2i| |

Syntactic Identity

1op = 1 A.4. Rules for Natural Isomorphisms 143

A.3.2 Rules unit

:1 `hi pair Γ E : Γ E : 1 ` 1 C 2 ` 2 D Γ , Γ E ,E : 1 2 `h 1 2i C×D

first Γ E : ` C×D Γ fst C×D(E): ` C second Γ E : ` C×D Γ snd C×D(E): ` D

A.4 Rules for Natural Isomorphisms

A.4.1 Structural Rules weakening x : , ,xn: n E =E : 1 C1 ··· C ` 1 ∼ 2 C x : , ,xn: n,xn : n E = E : 1 C1 ··· C +1 C +1 ` 1 ∼ 2 C exchange x : , ,xi: i,xi : i , ,xn: n E =E : 1 C1 ··· C +1 C +1 ··· C ` 1 ∼ 2 C x : , ,xi : i ,xi: i, ,xn: n E =E : 1 C1 ··· +1 C +1 C ··· C ` 1 ∼ 2 C contraction Γ,x: ,y: E =E : C C` 1 ∼ 2 D Γ,z: E[z/x,z/y] = E [z/x,z/y]: C` 1 ∼ 2 D

A.4.2 Conversion Rules

β-conversion Γ ,x: E : Γ E : small 1 C` 1 D 2 ` 2 CC Γ , Γ (λxC .E )E = E [E /x]: 1 2 ` 1 2 ∼ 1 2 D

η-conversion Γ E :[ , ] ` C D x is not free in E Γ λxC .Ex = E :[ , ] ` ∼ C D 144 Chapter A. The Calculus

A.4.3 Equivalence Rules reflexivity Γ E : ` D Γ E = E : ` ∼ D symmetry Γ E = E : ` 1 ∼ 2 D Γ E = E : ` 2 ∼ 1 D transitivity Γ E = E : Γ E = E : ` 1 ∼ 2 D ` 2 ∼ 3 D Γ E = E : ` 1 ∼ 3 D

A.4.4 Congruence Rules hom cong Γ E = E0 : Γ E = E0 : 1 ` 1 ∼ 1 C 2 ` 2 ∼ 2 C op Γ , Γ (E ,E )= (E0,E0):Set 1 2 `C 1 2 ∼C 1 2 power cong Γ E = E0 :Set Γ E = E0 : complete 1 ` 1 ∼ 1 2 ` 2 ∼ 2 CC op Γ , Γ [E ,E ]=[E0,E0]: 1 2 ` 1 2 ∼ 1 2 C ξ-conversion lambda Γ,x: E =E : small C` 1∼ 2 DC Γ λxC .E = λxC .E :[ , ] ` 1 ∼ 2 C D application cong Γ E = E0 :[ , ]Γ E=E0: 1 ` 1 ∼ 1 C D 2`2∼2C Γ,Γ EE=E0E0: 1 2`12∼1 2D ξ-conversion end op Γ,x: ,y: E1 =E2: small complete C C`R ∼ DCR D Γ op E1 = op E2 : ` xC ,yC ∼ xC ,yC D

A.4.5 Categorical Rules nat formula Γ1,x: E1: Γ2,y: E2: small C` D C`R DC op Γ1 , Γ2 [ , ](λxC .E1,λyC.E2) = op (E1,E2):Set ` C D ∼ xC ,yC D A.5. Rules for Weighted Limits 145

Fubini op op Γ,x1: ,x2: ,y1: ,y2: E: small small complete C C R D R D` ECR R D E Γ x op ,x y op ,y E = y op ,y x op ,x E : ` 1C 2C 1D 2D ∼ 1D 2D 1C 2C E def end Γ,x: op,y: E: small complete C C`R DC R D op Γ,w: (w, op E) = op (w, E):Set D `D xC ,yC ∼ xC ,yC D def power Γ E :Set Γ E : complete 1 ` 1 2 ` 2 DD Γop, Γ ,x: op (x, [E ,E ]) = [E , (x, E )]:Set 1 2 D `D 1 2 ∼ 1 D 2 def singleton Γ E : complete ` DD Γ [1,E]=E: ` ∼ D Yoneda Γ,x: op E :Set small CR `  C  op Γ,x: E = op (y,x),E[w/x] :Set C ` ∼ wC ,yC C opposite cat Γ E : Γ E : 1 ` 1 C 2 ` 2 C op op Γ , Γ (E ,E )= (E∗,E∗):Set 1 2 `C 1 2 ∼C 2 1 dual iso Γ E = E : ` 1 ∼ 2 C op op Γ E∗ = E∗ : ` 1 ∼ 2 C

A.5 Rules for Weighted Limits

Syntax

H H op xC ,yC E ::= ... (E1,E2) (E2,E1) xC,yC | Typing Rule wlimit Γ1,x: E1:Set Γ2,y: E2: small complete C` HC` DC D op Γ1 , Γ2 (E1,E2): ` xC ,yC D

Definition def wlimit Γ1,x: E1:Set Γ2,y: E2: small complete C` H C` DC D  op op Γ1 , Γ2,w: (w, (E1,E2)) = [ , Set] λxC .E1,λyC. (w, E2) :Set D `D xC,yC ∼ C D 146 Chapter A. The Calculus Bibliography

[AC98] Roberto M. Amadio and Pierre-Louis Curien. Domains and Lambda- Calculi, volume 46 of Cambridge Tracts in Theoretical Computer Sci- ence. Cambridge University Press, 1998.

[AJ94] Samson Abramsky and Achim Jung. Domain theory. In S. Abramsky, D. M. Gabbay, and T. S. E. Maibaum, editors, Handbook of Logic in Computer Science, Volume 3. Semantic Structures, chapter 1. Oxford University Press, 1994.

[AL91] Andrea Asperti and Giuseppe Longo. Categories, Types and Structures. An introduction to Category Theory for the working computer scientist. Foundations of Computing. The MIT press, 1991.

[Amb92] Simon John Ambler. First Order Linear Logic in Symmetric Monoidal Closed Categories. PhD thesis, Department of Computer Science - The University of Edinburgh, 1992.

[Bar84] Henk Barendregt. The Lambda Calculus. Its Syntax and Semantics. Studies in Logic and the Foundations of Mathematics. North Holland, 2 edition, 1984.

[Bar92] Henk Barendregt. Lambda calculi with types. In S. Abramsky, D. M. Gabbay, and T. S. E. Maibaum, editors, Handbook of Logic in Com- puter Science, Volume 2. Background: Computational Structures.Ox- ford University Press, 1992.

[BBdPH93] Nick Benton, Gavin Bierman, Valeria de Paiva, and Martin Hyland. A term calculus for intuitionistic linear logic. In First International Conference on Typed Lambda Calculus and Applications, volume 664 of Lecture Notes in Computer Science, pages 75–90, 1993.

[B´en78] Jean B´enabou. Introduction to . Lecture Notes in Mathe- matics, 47, 1978.

[B´en00] Jean B´enabou. Distributors at work, June 2000.

[BFSS90] E. S. Bainbridge, P. J. Freyd, A. Scedrov, and P. J. Scott. Functorial polymorphism. Theoretical Computer Science, 70, 1990.

[Bie95] Gavin M. Bierman. What is a categorical model of intuitionistic linear logic? In Second International Conference on Typed Lambda Calculi and Applications, volume 902, pages 73–93, 1995.

[BK75] Francis Borceux and Gregory Maxwell Kelly. A notion of limit for enriched categories. Bulletin of the Australian Mathematical Society, 12:49–72, 1975.

147 148 Bibliography

[Blu91] Richard Blute. Linear Logic, Coherence and Dinaturality. PhD thesis, University of Pennsylvania, 1991.

[Bor94a] Francis Borceux. Handbook of Categorical Algebra 1, volume 50 of En- cyclopedia of Mathematics and its Applications. Cambridge University Press, 1994.

[Bor94b] Francis Borceux. Handbook of Categorical Algebra 2, volume 51 of En- cyclopedia of Mathematics and its Applications. Cambridge University Press, 1994.

[BS00] Francis Borceux and Isar Stubbe. Short introduction to enriched cate- gories. In Current Research in Operational Quantum Logic: Algebras, Categories and Languages, pages 167–194. Kluwer Academic Publish- ers., 2000.

[BTCGS91] Val Breazu-Tannen, Thierry Coquand, Carl Gunter, and Andre Sce- drov. Inheritance as implicit coercion. Information and Computation, 1991.

[Bus98] Samuel Buss. An introduction to proof theory. In Samuel Buss, editor, Handbook of Proof Theory, chapter 1, pages 1–78. Elsevier, 1998.

[BW90] Michael Barr and Charles Wells. Category Theory for Computing Sci- ence. Prentice Hall, 1990.

[Cat99] Gian Luca Cattani. Presheaf Models for Concurrency. PhD thesis, BRICS - University of Aarhus, 1999.

[Cro93] Roy L. Crole. Categories for Types. Cambridge Mathematical Text- books. Cambridge University Press, 1993.

[CS01] J.R.B. Cockett and R.A.G. Seely. Finite sum-product logic. Theory and Applications of Categories, 8:63–99, 2001.

[CW] Gian Luca Cattani and Glynn Winskel. Profunctors, open maps and bisimulation. To appear.

[CW01] Mario C´accamo and Glynn Winskel. A higher-order logic for categories. In Richard Boulton and Paul Jackson, editors, Theorem Proving in Higher Order Logics, 14th International Conference, TPHOLs 2001, number 2152 in Lecture Notes in Computer Science, pages 136–153, September 2001.

[DS70] Eduardo Dubuc and Ross Street. Dinatural transformations. Lecture Notes in Mathematics, 137:126–137, 1970.

[Dub70] Eduardo Dubuc. Kan extensions in enriched category theory. Lecture Notes in Mathematics, 145, 1970.

[Fio96] Marcelo P. Fiore. Axiomatic Domain Theory in Categories of Partial Maps. Distinguished Dissertations in Computer Science. Cambridge University Press, 1996.

[FPT99] Marcelo P. Fiore, Gordon Plotkin, and Daniele Turi. Abstract syntax and variable binding. In Fourteenth Annual IEEE Symposioum on Logic in Computer Science, pages 193–202. IEEE Computer Society, 1999. Bibliography 149

[Fre02] Peter Freyd. Cartesian logic. Theoretical Computer Science, 278:3–21, 2002.

[FS90] Peter J. Freyd and Andre Scedrov. Categories, Allegories, volume 39 of North-Holland Mathematical Library. Elsevier, 1990.

[Gir87] Jean-Yves Girard. Proof Theory and Logical Complexity, volume 1 of Studies in Proof Theory. Bibliopolis, 1987.

[Has97] Masahito Hasegawa. Models of Sharing Graphs: A Categorical Seman- tics of let and letrec. PhD thesis, University of Edinburgh, 1997.

[Has02] Masahito Hasegawa. The uniformity principle on traced monoidal cat- egories. Electronic Notes in Theoretical Computer Science, 69, 2002.

[How90] W. A. Howard. The formulae-as-types notion of construction. In J. P. Seldin and J. R. Hindley, editors, To H. B. Curry: Essays on Combina- tory Logic, Lambda Calculus and Formalism, pages 479–490. Academic Press, 1990.

[HS00] G´erard Huet and Amokrane Sa¨ıbi. Constructive category theory. In Proof, Language, and Interaction: Essays in Honour of Robin Milner, Foundations of Computing, chapter 9. The MIT Press, 2000.

[Jac99] Bart Jacobs. Categorical Logic and Type Theory, volume 141 of Studies in Logic and the Foundations of Mathematics. Elsevier, 1999.

[JNW96] Andr´e Joyal, Mogens Nielsen, and Glynn Winskel. Bisimulation from open maps. Information and Computation, 127(2):164–185, 1996.

[Joh83] Peter T. Johnstone. Fibred categories. Notes taken by Paul Taylor of P. Johnstone’s course, 1983.

[Joh02] Peter T. Johnstone. Sketches of an Elephant: A Theory Com- pendium. Oxford University Press, 2002.

[JSV96] Andr´e Joyal, Ross Street, and D. Verity. Traced monoidal cate- gories. Mathematical Proceedings of the Cambridge Philosophical Soci- ety, 119(3):447–468, 1996.

[Kel65] Gregory Maxwell Kelly. Tensor products in categories. Journal of Algebra, 2:15–37, 1965.

[Kel82] Gregory Maxwell Kelly. Basic Concepts of Enriched Category Theory. Number 64 in London Mathematical Society Lecture Note. Cambridge University Press, 1982.

[KS74] Gregory Maxwell Kelly and Ross Street. Review of the elements of 2-categories. Lecture Notes in Mathematics, 420:75–103, 1974.

[Law73] F. William Lawvere. Metric spaces, generalized logic, and closed cat- egories. Rendiconti del Seminario Matematico e Fisico di Milano, XLIII:135–166, 1973.

[Lei] Tom Leinster. Basic bicategories. www.dpmms.cam.ac.uk/˜leinster.

[LS86] J. Lambek and P. J. Scott. Introduction to Higher Order Categori- cal Logic, volume 7 of Cambridge Studies in Advanced Mathematics. Cambridge University Press, 1986. 150 Bibliography

[Mac98] . Categories for the Working Mathematician,vol- ume 5 of Graduate Texts in Mathematics. Springer, 1998.

[Mit96] John C. Mitchell. Foundations of Programming Languages. Founda- tions of Computing. The MIT Press, 1996.

[MM92] Saunders Mac Lane and Ieke Moerdijk. Sheaves in Geometry and Logic: A First Introduction to Topos Theory. Springer-Verlag, 1992.

[Mul90] P. S. Mulry. Categorical fixed-point semantics. Theoretical Computer Science, 70:85–97, 1990.

[Par73] Robert Par´e. Connected components and colimits. Journal of Pure and Applied Algebra, 3:21–42, 1973.

[Par90] Robert Par´e. Simply connected limits. Canadian Journal of Mathe- matics, XLII(4):731–746, 90.

[Pau88] Lawrence Paulson. The foundation of a generic theorem prover. Jour- nal of Automated Reasoning, 5(3):363–397, 1988.

[Pau94] Lawrence Paulson. Isabelle: A Generic Theorem Prover, volume 828 of Lecture Notes in Computer Science. Springer-Verlag, 1994.

[Pit00] Andrew M. Pitts. Categorical logic. In S. Abramsky, D. M. Gabbay, and T. S. E. Maibaum, editors, Handbook of Logic in Computer Sci- ence, Volume 5. Algebraic and Logical Structures, chapter 2. Oxford University Press, 2000.

[Plo90] Gordon Plotkin. An illative theory of relations. In Situation Theory and its Applications, number 22 in CSLI Lecture Notes, pages 133–146. Stanford University, 1990.

[Pow95] John Power. Why ? Information and Computation, 120(2):251–262, 1995.

[RB88] D. Rydeheard and R. Burstall. Computational Category Theory.In- ternational Series in Computer Science. Prentice Hall, 1988.

[RS92] Mark Ryan and Martin Sadler. Valuation systems and consequence relations. In S. Abramsky, D. M. Gabbay, and T. S. E. Maibaum, editors, Handbook of Logic in Computer Science, volume 1, pages 1– 78. Oxford University Press, 1992.

[Sco00] Phill J. Scott. Some aspects of categories in computer science. In M. Hazewinkel, editor, Handbook of Algebra, volume 2. Elsevier, 2000.

[Sim93] Alex K. Simpson. A characterisation of the least-fixed-point operator by dinaturality. Theoretical Computer Science, 118(2):301–314, 1993.

[Str02] Ross Street. Functorial calculus in monoidal bicategories. Applied Categorial Structures, 2002. To appear.

[SU99] Morten Heine B. Sørensen and Pawel Urzyczyn. Lectures on the Curry- Howard Isomorphism. 11th European Summer School in Logic, Lan- guage and Information (ESSLLI), 1999.

[Sza78] M. E. Szabo. Algebra of Proofs, volume 88 of Studies in Logic and the Foundations of Mathematics. North Holland, 1978. Bibliography 151

[Tak95] M Takeyama. Universal Structure and a Categorical Framework for Type Theory. PhD thesis, The University of Edinburgh, 1995. [Tay99] Paul Taylor. Practical Foundations of Mathematics.Number59in Cambridge Studies in Advanced Mathematics. Cambridge University Press, 1999. [TD88] A. S. Troelstra and D. Van Dalen. Constructivism in Mathematics: Volume 2. Studies in Logic and the Foundations of Mathematics. North Holland, 1988. [TP97] Daniele Turi and Gordon Plotkin. Towards a mathematical operational semantics. In 12th Annual IEEE Symposioum on Logic in Computer Science, pages 280–293. IEEE Computer Society, 1997. [TS00] Anne S. Troelstra and Helmut Schwichtenberg. Basic Proof Theory. Number 43 in Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, second edition, 2000. [Tur96] Daniele Turi. Functorial Operational Semantics and Its Denotational Dual. PhD thesis, Free University Amsterdam, 1996. [vP01] Jan von Plato. A proof of Gentzen’s Hauptsatz without multicut. Archive for Mathematical Logic, 40:9–18, 2001. [VW01] Ren´e Vestergaard and Joe Wells. Cut rules and explicit substitutions. Mathematical Structures in Computer Science, 11(1):131–168, 2001. [Wad92a] Philip Wadler. A syntax for linear logic. In D. Schmidt, M. Mislove, A. Melton, M. Main, and S. Brookes, editors, Mathematical Founda- tions of Programming Semantics, 9th International Conference, volume 802 of Lecture Notes in Computer Science, pages 513–529, April 1992. [Wad92b] Philip Wadler. There’s no substitute for linear logic. In 8th Inter- national Workshop on the Mathematical Foundations of Programming Semantics, 1992. [Wag96] Kim Ritter Wagner. Some well-known facts about adjoint bimodules, 1996. [WN95] Glynn Winskel and Mogens Nielsen. Models for concurrency. In S. Abramsky, D. M. Gabbay, and T. S. E. Maibaum, editors, Hand- book of Logic in Computer Science, Volume 4. Semantic Modelling, volume 4, pages 1–148. Oxford University Press, 1995. Recent BRICS Dissertation Series Publications

DS-03-7 Mario JoseC´ accamo.´ A Formal Calculus for Categories. June 2003. PhD thesis. xiv+151. DS-03-6 Rasmus K. Ursem. Models for Evolutionary Algorithms and Their Applications in System Identification and Control Opti- mization. June 2003. PhD thesis. xiv+183 pp. DS-03-5 Giuseppe Milicia. Applying Formal Methods to Programming Language Design and Implementation. June 2003. PhD thesis. xvi+211. DS-03-4 Federico Crazzolara. Language, Semantics, and Methods for Security Protocols. May 2003. PhD thesis. xii+160. DS-03-3 Jirˇ´ıSrba. Decidability and Complexity Issues for Infinite-State Processes. 2003. PhD thesis. xii+171 pp. DS-03-2 Frank D. Valencia. Temporal Concurrent Constraint Program- ming. February 2003. PhD thesis. xvii+174. DS-03-1 Claus Brabrand. Domain Specific Languages for Interactive Web Services. January 2003. PhD thesis. xiv+214 pp. DS-02-5 Rasmus Pagh. Hashing, Randomness and Dictionaries. Octo- ber 2002. PhD thesis. x+167 pp. DS-02-4 Anders Møller. Program Verification with Monadic Second- Order Logic & Languages for Web Service Development. September 2002. PhD thesis. xvi+337 pp. DS-02-3 Riko Jacob. Dynamic Planar Convex hull. May 2002. PhD thesis. xiv+112 pp. DS-02-2 Stefan Dantchev. On Resolution Complexity of Matching Prin- ciples. May 2002. PhD thesis. xii+70 pp. DS-02-1 M. Oliver Moller.¨ Structure and Hierarchy in Real-Time Sys- tems. April 2002. PhD thesis. xvi+228 pp. DS-01-10 Mikkel T. Jensen. Robust and Flexible Scheduling with Evolu- tionary Computation. November 2001. PhD thesis. xii+299 pp. DS-01-9 Flemming Friche Rodler. Compression with Fast Random Ac- cess. November 2001. PhD thesis. xiv+124 pp. DS-01-8 Niels Damgaard. Using Theory to Make Better Tools. October 2001. PhD thesis.