<<

An Introduction to Theory Lecture 1

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Syllabus

■ categories: examples of abstract and concrete categories, categories, );

■ basic constructions: limits and colimits, , subobject classifiers;

and natural transformations: Yoneda lemma, presheaves, representable functors, categories;

■ adjunctions: definition and examples

(2 of 189) Texts

Slides and supporting material:

■ All the course material is on the website: http://wp.me/P1rYpC-8W

Textbooks:

■ [Borceux] F. Borceux, Handbook of Categorical Algebra I: Basic , Cambridge University Press (1994). ISBN: 978-0521061193 The lectures are mainly based on this book

■ [MacLane] S. Mac Lane, Categories for the Working Mathematician, 2nd edition, Springer-Verlag (1998). ISBN: 978-0387984032

■ [Goldblatt] R. Goldblatt, Topoi: The categorical analysis of logic, Elsevier (1984). ISBN: 978-0444867117 This book has been republished at a nicer price by Dover (2009). ISBN: 978-0486450261.

(3 of 189) Examination

The final examination for this course will be a seminar. The topic has to be decided together with the teacher, and it should expand a part of the course, possibly following the interests of the student.

(4 of 189) Some points of history

■ Eilenberg and Mac Lane, 1942–1958: starting from algebraic topology, they abstracted a collection of concepts, and a new language to speak of them. Soon, it was clear that algebraic topology was just an application of a more general theory.

■ Grothendieck, 1957: Abelian categories. This is the starting point of Grothendieck’s work in algebraic geometry, which, as a by-product, will deliver the fundamental concept of .

■ Kan, 1958: . This was a fundamental result which lies behind the general and abstract treatment category theory allows.

■ Lawvere, 1963: category theory as a foundation for mathematics. Elementary topoi as the universe of mathematics, since they are, at the same time, a logical system, a mathematical theory, an algebraic framework, a space, . . .

(5 of 189) Today

■ Entire branches of mathematics are described using, to various extents, category theory as the elected language: algebra, algebraic topology, algebraic geometry, and large parts of logic, just to name a few.

■ Since the development of denotational semantics by Scott, category theory has become a fundamental tool to describe, understand and research the meaning of computation. A fundamental part of theoretical computer science, semantics of programming languages, is strictly dominated by the categorical approach.

■ Functional programming uses, in real programming languages, categorical structures, e.g., monads in Haskell. And type theory can be really understood only within a categorical framework.

■ In contemporary research, Voevodosky launched Homotopy Type Theory, an interpretation of mathematics in a computational world, where algebraic topology is the founding basis. It uses in a fundamental way category theory and .

(6 of 189) Categorical style

Category theory appears to be abstract and difficult. Although this is true, to some extent, the impression arises because it is, in the first place, a revolutionary approach.

It is based on a few principles which are pushed to their extreme:

■ Looking systems from outside: objects have no meaning or nature, but what determines their behaviour is just the way they interact with other objects.

■ Theories have their own natural environment: it is wrong and deviating to study a theory in a framework which does not naturally and completely exploit the information in the theory.

■ Computation is a structure: computation has nothing to do with machines, but captures a fundamental property of the mathematical description of the world.

■ Mathematics talks about structures: and it does so by means of the way they are mutually related.

(7 of 189) References and hints

Every lesson is concluded with references to texts which may be useful to study and to get a better understanding of the content.

Sometimes, reference to additional material is also given, so that the interested student has an hint where to find more information. These references, when present, are, of course, not exhaustive but just a possible starting point.

In the present case, an excellent exposition on the history and philosophy of category theory can be found in J-P. Marquis, From a Geometrical Point of View, Logic, Epistemology, and the Unity of Science, 14, Springer-Verlag (2009). ISBN: 978-1-4020-9383-8

CC BY: $\ C Dr Marco Benini 2014

(8 of 189) An Introduction to Category Theory Lecture 2

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Categories I

Definition 2.1 (Category)

A category C is a structure C O,Hom, ,1 such that = 〈 ◦ 〉 ■ O is a of objects, denoted as ObjC.

■ Hom is an operation assigning to each pair A, B of objects a Hom(A,B), sometimes denoted as C(A,B), of arrows or . Given an arrow f Hom(A,B), we say and write that A is the domain of f (dom(f ) dom ∈f A), B is the of f (cod(f ) cod f B), = = = = and we usually write f : A B instead of f Hom(A,B). → ∈ ■ is a partial operation, called composition, assigning to each pair of arrows◦ f and g such that cod f dom g, an arrow g f such that dom(g f ) dom f and cod(g =f ) cod g. ◦ ◦ = ◦ = , →

(10 of 189) Categories II

, (Category) →

■ Moreover, satisfies the associative law: for any arrows f , g, h such that the following◦ compositions are defined, h (g f ) (h g) f . ◦ ◦ = ◦ ◦ ■ 1 is an operation, called identity, assigning to each object P an arrow 1P such that dom(1P ) P cod(1P ). = = Moreover, 1P satisfies the identity law: for any arrow f : P Q, ■ → 1Q f f f 1P . ◦ = = ◦ Definition 2.2 Given a category C O,Hom, ,1 , we say that C is small if O is a set. = 〈 ◦ 〉 Sometimes, the definition of category is relaxed, requiring that Hom(A,B) is just a class for every A,B ObjC. In this case, the categories satisfying our previous definition are called∈ locally small, while the relaxed categories are called large.

(11 of 189) Categories III

A substantial point in the definition of categories is that objects have no nature by themselves: what really defines a category is the way objects are linked to each other through arrows.

In fact, it is possible to define categories without requiring objects at all.

Moreover, arrows have no nature either. They are just links between objects.

As far as we are able to render a mathematical structure S through these basic entities, and to reduce the fundamental properties to of arrows, S can be effectively described in categorical terms. It is a fact that most mathematical entities can be reduced in this way, and in many cases this description is a deep and powerful one.

(12 of 189) Concrete categories I

Concrete categories are, generally speaking, based on sets.

Example 2.3 (Set) The category Set has sets as objects and (total) functions between them as arrows. Specifically, Set O,Hom, ,1 and = 〈 ◦ 〉 ■ O is the proper class of all sets;

■ Hom(D,C) is the set of total functions from D to C;

■ is the usual composition of functions: given f : D E and g : E C, g◦ f : D C is (g f )(x) g(f (x)), for all x D; → → ◦ → ◦ = ∈ 1P : P P is the identity on P, i.e., for all x P, 1P (x) x. ■ → ∈ = It is immediate to see that the associative and the identity laws both hold.

[Exercise] Prove it.

(13 of 189) Concrete categories II

There is a subtlety in the definition of Set: each corresponds to many arrows in Set, in fact, given f : D C and g : D E such that for all x D, f (x) g(x), it does not follow that→ f g, unless→C E. ∈ = = = Arrows are defined along with their domain and codomain, as we did. Also, most of the times, composition and identities are obvious from the context; in these cases, it is customary to define the category specifying only the objects and the arrows. Sometimes, when also the arrows (objects) are clear from the context, just the objects (arrows) are specified.

(14 of 189) Concrete categories III

Definition 2.4 (Poset)

A preorder is a pair P, P such that P is a binary relation on P which is reflexive and transitive.〈 ≤ 〉 ≤ A or poset is a preorder P, P where the relation is also anti-symmetric. 〈 ≤ 〉 An order preserving function or monotone function from the poset (preorder) P, P to the poset (preorder) Q, Q is a function f : P Q such that, if 〈 ≤ 〉 〈 ≤ 〉 → p P p0, then f (p) Q f (p0). ≤ ≤ Posets and preorders are an example of algebraic structure, that is, a set, the universe, plus a number of operations acting on the universe.

(15 of 189) Concrete categories IV

Example 2.5 (Poset) The category Poset has all the posets as objects and all the monotone functions between them as arrows.

Example 2.6 (Preorder) The category Preorder has all the preorders as objects and all the monotone functions between them as arrows.

[Exercise] Check that Poset and Preorder are categories.

(16 of 189) Concrete categories V

Example 2.7 (Mon) The category Mon has all the as objects and their homomorphisms as arrows. Thus, an object of Mon has the form M, M ,eM , where M is a 〈 · 〉 · binary operation on M, and eM M, such that (i) M is associative and ∈ · (ii) eM is the unit of M . An arrow f : M, M ,eM N, N ,eN of Mon is a function f : M N preserving· the product〈 · and the〉 → unit, 〈 · i.e., 〉 → (i) f (x M y) f (x) N f (y) for all x,y M, and (ii) f (eM ) eN . · = · ∈ =

Example 2.8 (Grp) The category Grp has all groups as objects and their homomorphisms as arrows. A is a with an inverse operation, and group homomorphisms are the monoid homomorphisms preserving inverses.

(17 of 189) Concrete categories VI

All the previous examples are composed by objects which are sets with some additional structure, and arrows which are functions preserving the structure. In general, this pattern gives rise to a category which is called concrete. Examples of concrete categories are: Category Objects Arrows Set sets total functions Pfn sets partial functions FinSet finite sets total functions Mon monoids homomorphisms Grp groups homomorphisms Poset posets monotone functions Rng rings homomorphisms Vect vector spaces linear transformations Top topologies continuous functions

(18 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 1.

It is very important to fully understand the definition of category and to remember the examples we have presented: they will often recur.

CC BY: $\ C Dr Marco Benini 2014

(19 of 189) An Introduction to Category Theory Lecture 3

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Abstract categories I

Abstract categories are not necessarily based on sets. Example 3.1 (0) The category 0 has no objects and no arrows.

Example 3.2 (1) The category 1 has a single object and only one arrow, the identity.

Example 3.3 (2) The category 2 has two objects and three arrows: the two identities and an arrow from one object to the second one.

(21 of 189) Abstract categories II

Example 3.4 (Discrete categories) A discrete category is such that its arrows are just the identities.

Note that 0 and 1 are discrete categories. Note also that every set or class is a discrete category whose objects are its elements.

Thus, categories are extensions of sets. This is a first intuitive way of thinking to categories: they are sets extended by links. But one should be aware that this interpretation, although useful, can be very misleading: it is just an hint of how one may synthesise some categorical descriptions from their usual presentation.

(22 of 189) Abstract categories III

Example 3.5 (Preorder categories)

A preorder P, P can be seen as a category P whose set of objects is P 〈 ≤ 〉 and whose arrows are defined as follows: whenever p,q P and p P q, then there is a unique arrow p q. By reflexivity and transitivity,∈ it follows≤ that P is a category. →

Note that every poset, being a preorder, gives rise to a category.

This example provides an alternative interpretation of categories: a category is a net of objects, whose arrows are the relating structure. Again, this interpretation is useful, but partial and potentially misleading.

(23 of 189) Abstract categories IV

Example 3.6 (Monoid categories)

A monoid M, M ,eM can be seen as a category M whose set of objects is a , and〈 · whose〉 set of arrows is M. Composition is the monoid product M and the identity is the monoid unit eM . · Since all groups are monoids, every group can be thought to as a category.

Again, this example provides a third way to interpret categories: each category is a collection of inter-related monoids. The same warnings as before apply.

It is worth remarking that the category Set, as most of the concrete categories, is not small. All the examples we have seen of abstract categories are small.

(24 of 189) Categories in Computer Science I

Example 3.7 (Functional programming) A typed programming language operates on a family of datatypes D. Each datatype d D is a set of possible values for a datum having that type. In a functional programming∈ language, programs take an input x d, for some ∈ datatype d D, and produce an output f (x) d 0 for some other datatype ∈ ∈ d 0 D. The key restriction is that the program f does not have side effects: each∈ execution of f on input x will yield the very same result f (x).

A simple way to represent this programming language as a category C is to set its objects to D, and its arrows as the possible programs. Since the sequential execution of two programs is a program, we naturally get a composition law; also, since a program which outputs its input, is always possible to write, it will act as the identity arrow. The associative law follows immediately because of the absence of side effects. , →

(25 of 189) Categories in Computer Science II

, (Functional programming) → Despite its simplicity, the category C so constructed is very rich, and it allows for a deep modelling of the programming language.

For example, admitting a type A B, which stands for the programs taking their input from A and producing→ an output in B, one can model infinite data structures and really compute on them. Of course, to obtain this result — and to know how to effectively write a program that manipulate infinitary data structures — one needs a bit more of knowledge about category theory.

(26 of 189) Categories in Computer Science III

Example 3.8 (Ω-algebras) Let Ω be a set of operator symbols, equipped with a mapping ar from elements of Ω to natural numbers: for each ω Ω, ar(ω) is the of ω. ∈ An Ω-algebra A is a set A, the carrier, and for each operator ω Ω, a ar(ω) ∈ function αω : A A, the interpretation of ω, mapping of elements of A into A. →

An Ω-homomorphism from an Ω-algebra A to another Ω-algebra B is a function h: A B between the carriers such that, for each ω Ω and → ∈ x ,...,x A, the following equation holds: 1 ar(ω) ∈ h(α (x ,...,x )) β (h(x ),...,h(x )) , ω 1 ar(ω) = ω 1 ar(ω) with α and β the interpretations in A and B, respectively. , →

(27 of 189) Categories in Computer Science IV

, (Ω-algebras) → The category Ω-Alg has Ω-algebras as objects and Ω-homomorphisms as arrows. This construction can be refined by adding a set E of equations between expressions built from elements of Ω and a set of variables. Then, the Ω-algebras for which the equations in E are satisfied under all assignments of elements of the carrier to the variable symbols, form the objects of a category (Ω,E)-Alg.

For example, if

Ω { ,1} = · ar( ) 2 · = ar(1) 0 = E ©(x y) z x (y z),1 x x,x 1 xª = · · = · · · = · = then (Ω,E)-Alg is just Mon. , →

(28 of 189) Categories in Computer Science V

, (Ω-algebras) → Ω-algebras can be understood as abstract data structures described by the set Ω of constructors, and interpreted in some concrete representation A, which acts as the carrier of the algebra.

Lists, enumerations, records, Booleans, and many others data types can be described in this way, and they can be interpreted in some machine oriented representation, e.g., modular numbers as bytes.

Some other data types, e.g., integers, or floating point numbers require some equation to be properly defined. But again, they will be represented in the computer memory by means of some interpretation.

The categories allows to abstract over the machine, retaining the need for a concrete representation, which is exactly what a data structure designer wants to obtain.

(29 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 1.

One should notice how sets (discrete categories), poset categories, and monoid categories are structured: in a way, they contain the design principles which are followed to construct more complex categories.

The examples about computer science recurs, in various forms, in all the literature about functional programming. A good starting point for a computer scientist is B.C. Pierce, Types and Programming Languages, The MIT Press (2002). ISBN: 978-0-262-16209-8. A more mathematical-oriented presentation can be found in Section 4.7 of P. Taylor, Practical Foundations of Mathematics, Cambridge Studies in Advanced Mathematics 59, Cambridge University Press (1999). ISBN: 0-521-63107-6. To have an in-depth presentation of the same examples, Sections D.4.2 and D.4.3 of P. Johnstone, Sketches of an Elephant: A Topos Theory Compendium, volume 2, Oxford Logic Guides 44, Oxford University Press (2002). ISBN: 978-0-19-851598-2 provide the definitive guide.

CC BY: $\ C Dr Marco Benini 2014

(30 of 189) An Introduction to Category Theory Lecture 4

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 I

Definition 4.1 (Opposite category) Given a category C, the opposite or category Cop has the same objects as C, but its arrows are the opposites of the arrows of C: if f : A B is an → arrow of C, then f : B A is an arrow of Cop. Composition and identities → are defined from C in the obvious way.

(32 of 189) Opposite category II

The dual category provides a duality principle: any statement S about a category C can be transformed into a dual statement Sop by exchanging the words “domain” and “codomain”, and replacing each composite g f by ◦ f g. If the statement S holds in C, then Sop holds in Cop. Since ◦ (Cop)op C, if a statement S is true in any category, then so is Sop. Moreover,= any construction x can be “dualised”: the dual construction, whose arrows are reverted, is usually called co-x.

(33 of 189) Functors I

Definition 4.2 (Functor) Let C and D be categories. A functor F : C D is formed by → a map F : ObjC ObjD; ■ → a family of maps F : HomC(A,B) HomD(F (A),F (B)), one for each pair ■ → of objects A,B ObjC; ∈ such that

F (1A) 1 for all A ObjC; ■ = F (A) ∈ F (g f ) F (g) F (f ) for all f HomC(A,B), g HomC(B,C). ■ ◦ = ◦ ∈ ∈

Definition 4.3 (Presheaf) Any functor F : Cop Set is called a presheaf. →

(34 of 189) Functors II

Example 4.4 (Forgetful functors) Let U : Mon Set defined as → for M, ,e ObjMon, U( M, ,e ) M; ■ 〈 ∗ 〉 ∈ 〈 ∗ 〉 = for f : M, ,e M0, 0,e0 , U(f ) f : M M0; ■ 〈 ∗ 〉 → 〈 ∗ 〉 = → where the homomorphism f is thought to as a function.

Functors like the previous one, which forget about some structure of the source category, are called forgetful functors. The name is “traditional” and it is used to convey a meaning which should be obvious given the source and target of a functor.

Oppositely, the usual set-oriented presentation of monoids can be understood as the result of looking an object of Mon through the forgetful functor. In this provocative view, monoids are not sets equipped with an operation, but rather purely abstract entities that can be interpreted as sets with an operation because of the presence of the forgetful functor.

(35 of 189) Functors III

Example 4.5 (Identity functor)

For any category C, the identity functor, 1C : C C is defined as 1C(A) A → = for A ObjC, and 1C(f ) f for f HomC(A,B). ∈ = ∈ Evidently, the identity functor behaves like the identity arrow among categories.

(36 of 189) Functors IV

Example 4.6 (Constant functor) Given two categories A, B, and a fixed B ObjB, the constant functor ∈ ∆B : A B is defined as ∆B(A) B for each A ObjA, and ∆B(f ) 1B for → = ∈ = any f of A.

(37 of 189) Functors V

Definition 4.7 (Functor composition) Let F : C D and G : D E be functors. Then, their composition G F is a functor defined→ as → ◦ for A ObjC, (G F )(A) G(F (A)); ■ ∈ ◦ = for f HomC(A,B), (G F )(f ) G(F (f )): G(F (A)) G(F (B)). ■ ∈ ◦ = → It is immediate to check that functor composition is associative and that the identity functor acts like a unit.

(38 of 189) Functors VI

Definition 4.8 (Cat) The category Cat has all small categories as objects, and all the functors between them as arrows.

We cannot form a category of large categories since it would be too big, leading to an analogous of the Russell’s paradox.

(39 of 189) Functors VII

Definition 4.9 (Contravariant functor) A contravariant functor F : C D is the same thing as the functor → F : Cop D. → A contravariant functor is a useful concept when dealing with presheaves, since it operates like a normal (covariant) functor on objects, but it reverses the direction of arrows.

(40 of 189) Functors VIII

Example 4.10 (Hom functors) Let C be a category. Then, each A ObjC determines a pair of functors ∈ Hom(A, ): C Set and Hom( ,A): Cop Set − → − → for B ObjC, ■ ∈

Hom(A, )(B) HomC(A,B) and Hom( ,A)(B) HomC(B,A); − = − =

■ for f HomC(B,C), Hom(A, ): HomC(A,B) HomC(A,C) and ∈ − g → f g 7→ ◦ Hom( ,A): HomC(C,A) HomC(B,A) . − g → g f 7→ ◦ Notice how Hom( ,A) is a contravariant functor. −

(41 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 1.

The definition of functor is central, and the examples we have presented have an importance on their own.

In general, functors should be thought of both as transformations between categories, and as a “pair of glasses” allowing to look at a category from a different point of view — compare with the notion of forgetful functor, for example.

CC BY: $\ C Dr Marco Benini 2014

(42 of 189) An Introduction to Category Theory Lecture 5

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Subcategories I

Definition 5.1 () A category C is a subcategory of a category D, notation C D if ⊆ ObjC ObjD; ■ ⊆ for all A,B ObjC, HomC(A,B) HomD(A,B); ■ ∈ ⊆ ■ composites and identities in C are the same as in D. Moreover, C is full if, for all A,B ObjC, HomC(A,B) HomD(A,B). ∈ = The notion of subcategory generalises the notion of . In fact, every subset A B is a full subcategory A of the discrete category B. Also, every subgroup⊆S G is a non-necessarily full subcategory of the group category G. In general,⊆ the notion of subcategory coincides with the notion of substructure when dealing with the categorical representation of an algebraic structure.

(44 of 189) Subcategories II

Definition 5.2 (Inclusion functor)

A functor F : C D is an inclusion functor, notation F : C , D, if, for all → → A ObjC, F (A) A, and, for all f HomC(A,B), F (f ) f . ∈ = ∈ = If F : C D is an inclusion functor, then C is a subcategory of D. Vice versa, → if C D, then there is an obvious inclusion functor i : C , D. ⊆ → So, the notion of subcategory can be describe functorially.

For example Poset is a full subcategory of Preorder; similarly, Grp is a full subcategory of Mon; evidently, also FinSet is a full subcategory of Set. But Set is a subcategory of Pfn which is not full.

(45 of 189) Diagrams

Definition 5.3 (Diagram) A diagram in a category is a directed multi-graph whose vertexes are objects and whose edges are arrows. A diagram is said to commute if, for every pair of paths with a common origin and target, the compositions of arrows along the paths yield the same result.

For example, saying that the following diagram commutes

f A / B k h g   C / D i means that g f k i h. ◦ = = ◦

(46 of 189) Natural transformations I

Definition 5.4 ()

Let C and D be categories and let F ,G : C D be functors. A natural → . transformation α from F to G, notation α: F G, is a family of arrows −→ © ª C αA : F (A) G(A) A ObjC, indexed by the objects of such that, for any → ∈ f HomC(A,B), the following diagram commutes in D: ∈

αA F (A) / G(A)

F (f ) G(f )   F (B) / G(B) αB

The collection of all natural transformations from F to G is denoted by Nat(F ,G). It is a set when D is small.

(47 of 189) Natural transformations II

Example 5.5 (Identity transformation) n o Let F : C D be a functor, then ι 1F (A) is an evident natural → = A ObjC transformation, called the identity transformation∈ .

(48 of 189) Natural transformations III

Example 5.6 . Given two categories C, D, and f : A B in D, we define ∆f : ∆A ∆B, the → −→ constant natural tranformation on f , by (∆f )C f for every C ObjC. = ∈

(49 of 189) References and hints

This lesson is based on Chapter 1 of [Borceux].

The shown examples are important as part of the tools of a ‘working mathematician’ in Category Theory.

Natural transformations are not immediately intuitive. In fact, they become evident in the appropriate context, which is strictly related to algebraic topology. This is beyond the scope of the present course, so it is left as a note.

The fundamental use of natural transformations in this course will be in the definition of adjunctions. In this context, they get a proper meaning which makes them first-class actors in the theatre of category theory.

CC BY: $\ C Dr Marco Benini 2014

(50 of 189) An Introduction to Category Theory Lecture 6

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Natural transformations IV

Definition 6.1 (Vertical composition) . Let C and D be categories, and let F ,G,H : C D be functors. If σ: F G . → . −→ and τ: G H are natural transformations, then (τ σ): F H is the −→ ◦ −→ natural transformation defined as (τ σ)A τA σA. ◦ = ◦ It is simple to check that the (vertical) composition is associative and that the identity transformation is a unit for it. There is also a notion of horizontal composition which will not be used in this course, and thus not introduced, and this fact justifies the name.

(52 of 189) Natural transformations V

Proposition 6.2 Let A be a small category and B be an arbitrary category. The functors from A to B with natural transformations as arrows, form a category Fun(A,B). This category is small as long as B is small. Proof.

Since HomFun(A,B)(F ,G) is Nat(F ,G) and composition is associative and has the identity transformation as unit, the result is evident.

These categories are known as functor categories. In the case B is Set, Fun(Aop,Set) is called the category of presheaves on A and it has a special role in category theory, being the easiest example of a Grothendieck topos.

(53 of 189) Natural transformations VI

Example 6.3 Consider a category C and f : A B in C. We obtain a natural → . transformation Hom(f , ): Hom(B, ) Hom(A, ) by posing − − −→ − Hom(f , )C (g) g f for each C ObjC and each g Hom(B,C). − = ◦ ∈ ∈ Generally, one writes Hom(f ,C) instead of Hom(f , )C . −

(54 of 189) Natural transformations VII

Example 6.4 Consider a category C and f : A B in C. We obtain a natural → . transformation Hom( ,f ): Hom( ,A) Hom( ,B) by posing − − −→ − Hom( ,f )C (h) f h for each C ObjC and each h Hom(C,A). − = ◦ ∈ ∈ Generally, one writes Hom(C,f ) instead of Hom( ,f )C . −

(55 of 189) Non-natural transformations I

Example 6.5 ( of a torus) The homotopy groups of a product space are the product of the homotopy groups of the components, πn((X,x0) (Y ,y0)) ∼ πn((X,x0)) πn((Y ,y0)), with the given by projection× onto the= two factors.× However, the torus T is abstractly a product of two circles, and thus has fundamental group isomorphic to Z2:

1 1 ³ 2´ π1(T ,t0) π1(S ,x0) π1(S ,y0) Z Z Z . ≈ × =∼ × = This abstract isomorphism with a product is not natural, as some of T do not preserve the product.

Naturality is a categorical notion, and requires being very precise about exactly what data is given — the torus as a space that happens to be a product (in the category of spaces and continuous maps) is different from the torus presented as a product (in the category of products of two spaces and continuous maps between the respective components).

(56 of 189) Non-natural transformations II

Example 6.6 (Dual of a finite-dimensional vector space) The dual space of a finite-dimensional vector space is again a finite-dimensional vector space of the same dimension, and these are thus isomorphic, since dimension is the only invariant of finite-dimensional vector spaces over a given field. However, in the absence of additional data (such as a basis), there is no given map from a space to its dual, and thus such an isomorphism requires a choice, and is “not natural”. On the category of finite-dimensional vector spaces and linear maps, one can choose an isomorphism for each space (say, by choosing a basis for every vector space and taking the corresponding isomorphism), but this will not define a natural transformation. Intuitively this is because it required a choice, rigorously because any such choice of isomorphisms will not commute with all linear maps.

(57 of 189) References and hints

This lesson is based on Chapter 1 of [Borceux].

The shown examples are important as part of the tools of a ‘working mathematician’ in Category Theory.

The complexity of the counterexamples shows how the notion of natural transformation is rather sophisticated and delicate. The key point lies in the fact that a natural transformation depends on the objects only.

CC BY: $\ C Dr Marco Benini 2014

(58 of 189) An Introduction to Category Theory Lecture 7

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Yoneda lemma I

When we consider presheaveas, i.e., functors from some category to Set, we can characterise natural transformations.

Theorem 7.1 (Yoneda lemma) Let F : C Set be a functor from a category C, and let A ObjC. Then, there is a→ bijective correspondence ∈

θF ,A : Nat(Hom(A, ),F ) F (A) . − =∼ Proof. (i) . For a given natural transformation α: Hom(A, ) F , we define − −→ θF A αA(1A). Moreover, given a F (A), for each B ObjC, , = ∈ ∈ τ(a)B : HomC(A,B) F (B) is defined as τ(a)B(f ) F (f )(a), with → = f HomC(A,B). , ∈ →

(60 of 189) Yoneda lemma II

, Proof. (ii) → This class of mappings defines a natural transformation . τ(a): Hom(A, ) F since, for every g HomC(B,C) and f HomC(A,B), − −→ ∈ ∈ (F (g) τ(a)B)(f ) F (g)(τ(a)B(f )) ◦ = = F (g)(F (f )(a)) (F (g) F (f ))(a) F (g f )(a) τ(a)C (g f ) = = ◦ = ◦ = ◦ = τ(a)C (Hom(A,g)(f )) (τ(a)C Hom(A,g))(f ). In a diagram: = = ◦

τ(a)B HomC(A,B) / F (B)

Hom(A,g) g F (g) = ◦−   HomC(A,C) / F (C) τ(a)C

, →

(61 of 189) Yoneda lemma III

, Proof. (iii) → But, θF A and τ are inverses to each other. In fact, letting a F (A), , ∈ (θF ,A τ)(a) θF ,A(τ(a)) τ(a)A(1A) F (1A)(a) 1F (A)(a) a. ◦ = . = = = = Also, if α: Hom(A, ) F and f HomC(A,B), (τ θF A)(αB(f )) − −→ ∈ ◦ , = τ(θF A(α))B(f ) τ(αA(1A))B(f ) F (f )(αA(1A)) = , = = = αB(Hom(A,f )(1A)) αB(f 1A) αB(f ). = = ◦ =

(62 of 189) Yoneda lemma IV

Corollary 7.2

The bijections θF ,A of the Yoneda lemma are natural in A. Moreover, if C is small, they are also natural in F .

Proof. (i) Consider the functor N : C Set defined as: → for each A ObjC, N(A) Nat(HomC(A, ),F ); ■ ∈ = − for each f HomC(A,B), ■ ∈ N(f ): Nat(HomC(A, ),F ) Nat(HomC(B, ),F ) such that − → − N(f )(α) α HomC(f , ). = ◦ − . We are claiming the existence of a natural transformation η: N F defined −→ by ηA θF A. , = , →

(63 of 189) Yoneda lemma V

, Proof. (ii) → In fact, (ηB N(f ))(α) θF B(α HomC(f , )) (α HomC(f , ))B(1B) αB(f ). ◦ = , ◦ − = ◦ − = And (F (f ) ηA)(α) (F (f ) θF A)(α) F (f )(αA(1A)) ◦ = ◦ , = = (αB HomC(A,f ))(1a) αB(f ). ◦ = Moreover, when C is small, it makes sense to consider the category Fun(C,Set). For a fixed A ObjC, we consider the functor ∈ M : Fun(C,Set) Set defined as → ■ for each F Fun(C,Set), M(F ) Nat(HomC(A, ),F ); ∈ . = − for each γ: F G, with G : C Set, ■ −→ → M(γ): Nat(HomC(A, ),F ) Nat(HomC(A, ),G) where − → − M(γ)(α) γ α. = ◦ , →

(64 of 189) Yoneda lemma VI

, Proof. (iii) → Consider also, for each A ObjC the functors ²A : Fun(C,Set) Set, ∈ → defined by ²A(F ) FA and ²A(γ) γA. = =

We claim to have a natural transformation µ: M ²A defined by µF θF A. → = , In fact, (θG A M(γ))(α) θG A(γ α) (γ α)A(1A) γA(αA(1A)) , ◦ = , ◦ = ◦ = = (²A(γ) θF A)(α). ◦ ,

(65 of 189) Yoneda embedding I

Definition 7.3 (Yoneda functors)

The functor Y: Cop Fun(C,Set), defined as → for each A ObjC, Y(A) HomC(A, ); ■ ∈ = − ■ for each f HomC(A,B), ∈ . Y(f ) Hom(f , ): HomC(B, ) HomC(A, ); = − − −→ − is called the (contravariant) Yoneda functor. Its dual, Y: C Fun(Cop,Set), is the (covariant) Yoneda functor: → for every A ObjC,Y(A) HomC( ,A); ■ ∈ = − for every f HomC(A,B), ■ ∈ . Y(f ) Hom( ,f ): HomC( ,A) HomC( ,B). = − − −→ −

(66 of 189) Yoneda embedding II

Definition 7.4 (Full and faithful functors) Given a functor F : C D, we say → F is faithful if F : HomC(A,B) HomD(F (A),F (B)) is injective for all ■ → A,B ObjC; ∈ F is full if F : HomC(A,B) HomD(F (A),F (B)) is surjective for all ■ → A,B ObjC; ∈ F is surjective if F : ObjC ObjD is surjective; ■ → ■ F is an isomorphism of categories if F is full and faithful, and it induces a bijection on the classes of objects;

■ F is essentially surjective if, for every D ObjD, there is a C ObjC such that D F (C), i.e., D is isomorphic to F∈(C). ∈ =∼

(67 of 189) Yoneda embedding III

Proposition 7.5 The Yoneda functors are full and faithful. Proof. Direct consequence of the Yoneda lemma.

(68 of 189) Yoneda embedding IV

The importance of the Yoneda functors lies in the fact that, given any small category C, we can “complete” it. In fact, the of C through Y is an isomorphic copy of C, with no extra arrows, being Y full and faithful.

But the category Fun(Cop,Set) is a topos, so it has all the finite limits and co-limits, as well as exponentials and a subobject classifier. So, we can think of C as a full subcategory of Fun(Cop,Set), and we can work in the larger category; in this way, we are “adding” to C the finite categorical constructions it may lack.

(69 of 189) References and hints

This lesson is based on Chapter 1 of [Borceux].

In this lesson, for the sake of completeness, we anticipated a few notions we will introduce later. Specifically, we used the notion of isomorphism to define essentially surjective functors, and the notions of topos, , co-limit, exponential, subobject classifier to justify the main application of Yoneda functors.

Of course, all these concepts will be introduced soon.

CC BY: $\ C Dr Marco Benini 2014

(70 of 189) An Introduction to Category Theory Lecture 8

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Monics and epics I

Definition 8.1 () An arrow f : B C in a category C is a monomorphism, or monic, or is → mono, if, for every pair g,h: A B of arrows in C, f g f h implies g h. → ◦ = ◦ = f In a diagram, a monomorphism f is denoted as / / .

(72 of 189) Monics and epics II

Proposition 8.2 In a category C: 1. identities are ; 2. the composite of two monomorphisms is mono; 3. if k f is mono, so is f . ◦ Proof. The first statement is obvious. If f and k are mono, then (k f ) h (k f ) g implies f h f g, by associativity of composition and◦ k◦ being= ◦ mono.◦ But f is mono◦ = too,◦ so h g, proving the second statement. = If k f is mono then f g f h implies k f g k f h, and so g h, proving◦ the third statement.◦ = ◦ ◦ ◦ = ◦ ◦ =

(73 of 189) Monics and epics III

Definition 8.3 A functor F : C D preserves monomorphisms when, for every f morphism → in C, if f is mono then so is F f . A functor F : C D reflects monomorphisms when, for every f morphism in → C, if F f is mono then so is f .

(74 of 189) Monics and epics V

Proposition 8.4 A faithful functor reflects monomorphisms. Proof.

Let F : C D be a faithful functor, and let f : A A0 be an arrow of C such → → that F f is mono. Let g,h: A00 A in C be such that f g f h. Then F (f g) F f F g F f →F h F (f h), since F preserves◦ = ◦ composition. But F f is◦ mono,= so◦F g =F h.◦ Now,= F is◦ faithful, so we deduce g h, i.e., f is mono. = =

(75 of 189) Monics and epics VI

Dualising the notion of monomorphism, we obtain Definition 8.5 () An arrow f : A B in a category C is an epimorphism, or epic, or is epi, if, → for every pair g,h: B C of arrows in C, g f h f implies g h. → ◦ = ◦ = f In a diagram, an epimorphism f is denoted as / / .

[Exercise] Reformulate the previous propositions on monic arrows in their dual form for epimorhisms.

(76 of 189) Monics and epics VII

In Set, it is easy to verify that monomorphisms are exactly the injective functions, and that are exactly the surjective functions. In most concrete categories, this is true as well. [Exercise] Check it, but see next slide first.

In general, many categorical notions are built by abstraction over the relevant notions of Set, or some other interesting category. This abstraction process takes place by trying to express the concepts in terms of objects and arrows only.

So, this abstraction process leads to very general notions, which may behave unexpectedly.

(77 of 189) Monics and epics VIII

Example 8.6 Both Z, ,0 and N, ,0 are objects in Mon. Consider 〈 + 〉 〈 + 〉 i : N, ,0 Z, ,0 〈 + n〉 → 〈n + 〉 7→ Being an injection, i is mono. But it is also epi, although not surjective. In fact, let f ,g : Z, ,0 M, ,e such that f i g i, and let z Z. If z 0 then f (z) 〈 f (+i(z))〉 →g 〈 (i(∗z))〉 g(z). ◦ = ◦ ∈ If≥z 0, then f (=z) f (z)=e f (z)= g(0) f (z) g( z z) f (z)< g( z) g(z)= f (z)∗ g=(i( z))∗ g(z=) f (z∗) f−(i(+z))= g(z) f (z) ∗ f (−z) ∗g(z) =f (z ∗ z) −g(z)∗ f (0)= g(z)∗ e −g(z)∗ g(z)=. So f g∗. − ∗ = + − ∗ = ∗ = ∗ = =

(78 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 1.

For an explicit construction of monomorphisms and epimorphisms in the , see [Goldblatt].

Introducing this notions, we avoided examples from Computer Science: the reason is simply that they are either elementary, reducing to injective or surjective functions, or rather complex, showing deep aspects of computing. The latter examples are interesting, but beyond the scope of this course.

CC BY: $\ C Dr Marco Benini 2014

(79 of 189) An Introduction to Category Theory Lecture 9

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Isomorphisms I

Definition 9.1 (Isomorphism) An arrow f : A B is an isomorphism, or is iso, if there is an arrow 1 → 1 1 f − : B A, the inverse of f , such that f − f 1A and f f − 1B. In this case,→ A is said to be isomorphic to B◦, notation= A ◦B. = =∼ 1 It is easy to prove that, if it exists, f − is unique, and the “being isomorphic” relation is an equivalence.

As one would expect, in Set, isomorphisms are exactly the bijective functions. Also, in concrete categories, isomorphisms are the usual invertible homomorphisms. Notice that, in Mon, by the previous example, an arrow which is mono and epi does not need to be iso.

(81 of 189) Isomorphisms II

Proposition 9.2 In a category C, 1. every identity is iso; 2. the composite of two isomorphisms, is iso; 3. an isomorphism is both mono and epi; 4. every functor preserves isomorphisms; 5. a full and faithful functor reflects isomorphisms. Proof. Statements 1, 4 and 5 are obvious. 1 1 1 Statement 2 reduces to prove that (f g)− g − f − . Statement 3 follows from direct calculation.◦ = ◦

[Exercise] Complete the details.

(82 of 189) Subobjects I

Definition 9.3 (Factor through) Given f : A B and g : C B, we say that g factors through f when there is h: C A→such that f h→ g. Also, given f : A B and g : A C, we say that g factors→ through f◦when= there is h: B C →such that h f→ g. → ◦ = The above notion induces a preorder relation among arrows having the same (co)domain: f g when g factors through f , whose meaning is that f is “closer” to the≤ (co)domain.

(83 of 189) Subobjects II

In general, Category Theory considers objects and arrows up to iso’s, meaning that isomorphic objects are considered indistinguishable.

Definition 9.4 (Subobject) Let f : A B be a monomorphism in the category C. We say that g : C B is equivalent→ to f when g factors through f via an isomorphism. Each → equivalence class generated by this relation is called a subobject of B. Usually, by abuse of notation, we say that f itself is a subobject of B.

In Set, subobjects denote , up to isomorphisms. In fact, if A B ⊆ then the canonical injection i : A , B is mono and, thus, i is a subobject of B. Its image, i(A), is identical to→A, so it is also isomorphic to A. Consider f : A  B, its image, f (A) ∼ A and it is a subset of B, so “A through f ” is a subset of B corresponding= to the domain of the monic arrow, modulo an isomorphism.

(84 of 189) Natural isomorphisms

Definition 9.5 (Natural isomorphism) . A natural transformation α: F G is a natural isomorphism if each −→ component αA : F (A) G(A) is an isomorphism. In this case, we would write F G saying that→F and G are naturally isomorphic. =∼ . [Exercise] Prove that α: F G is a natural iso iff it is an isomorphism in the category of functors (Assume−→ the domain and codomain of F and G are small).

(85 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 1.

The notion of subobject plays a fundamental role in topos theory, and the concept of natural isomorphisms is essential to understand adjunctions.

CC BY: $\ C Dr Marco Benini 2014

(86 of 189) An Introduction to Category Theory Lecture 10

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Limits and colimits I

Definition 10.1 () ³ ´ D C © ª Given a functor F : , a cone on F is a pair C, pD : C FD D ObjD → → ∈ such that C ObjD and, for every d HomD(D,D0), pD F d pD. ∈ ∈ 0 = ◦ Consider the category D as a diagram: a cone becomes an object C ObjC ∈ which is the domain of a family of arrows pD, usually called projections, whose codomain is FD such that the image of the “diagram” D commutes with all the projections.

(88 of 189) Limits and colimits II

Definition 10.2 (Limit) ¡ © ª ¢ Given a functor F : D C, a limit for F is a cone L, pD : L FD D D on → ¡ © ª ¢ → ∈ F with the property that, if C, qD : C FD D D is a cone on F , then → ∈ there is a unique arrow m: C L such that, for every D D, qD pD m. → ∈ = ◦ A limit is minimal among the cones on F . In fact, every cone projection factorises through an unique morphism m, giving exactly the corresponding limit projection.

(89 of 189) Limits and colimits III

Proposition 10.3 When a functor F : D C admits a limit, it is unique up to isomorphisms. → Proof. ¡ © ª ¢ ¡ © ª ¢ Suppose L1 L1, pD : L FD D D and L2 L2, qD : L FD D D are two limits on=F . → ∈ = → ∈ Since L is a limit, there is a unique m : L L such that qD pD m for 1 1 2 → 1 = ◦ 1 each D ObjD. Since L is a limit, there is a unique m : L L such that ∈ 2 2 1 → 2 pD qD m for each D ObjD. So, pD pD (m m ) and = ◦ 2 ∈ = ◦ 1 ◦ 2 qD qD (m m ) for every D ObjD. = ◦ 2 ◦ 1 ∈ But, since L and L are limits, there are two unique arrows e : L L 1 2 1 1 → 1 and e : L L such that pD pD e and qD qD e for every D ObjD. 2 2 → 2 = ◦ 1 = ◦ 2 ∈ Evidently, e 1L and e 1L . 1 = 1 2 = 2 So, by uniqueness of e and e , m m e 1L and m m e 1L , 1 2 1 ◦ 2 = 1 = 1 2 ◦ 1 = 2 = 2 i.e., m1 and m2 are isomorphisms and they are inverse to each other.

(90 of 189) Limits and colimits IV

Corollary 10.4 ¡ © ª ¢ If L, pD : L FD D D is the limit of the functor F : D C, two morphisms → ∈ → f ,g : M L are equal as long as pD f pD g for each D ObjD. → ◦ = ◦ ∈ Proof. ³ © ª ´ Consider M M, pD f D ObjD . For every d HomD(D,E), = ◦ ∈ ∈ pE f F d pD f , because pE F d pE . So, M is a cone on F , and there is unique◦ = arrow◦ M◦ L which must= be◦f . But g satisfies the same conditions, so f g→. =

(91 of 189) Limits and colimits V

Dualising the notion of limit, we obtain the concept of colimit.

Definition 10.5 (Cocone) ³ ´ D C © ª Given a functor F : , a cocone on F is a pair C, pD : FD C D ObjD → → ∈ such that C ObjD and, for every d HomD(D0,D), pD pD F d. ∈ ∈ 0 = ◦

Definition 10.6 (Colimit) ¡ © ª ¢ Given a functor F : D C, a colimit for F is a cocone L, pD : FD L D D → ¡ © ª ¢ → ∈ on F with the property that, if C, qD : FD C is a cocone on F , → D D then there is a unique arrow m: L C such that, for∈ every D D, → ∈ qD m pD. = ◦

(92 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 2.

Notably, we anticipated the general notion of limit and colimit, and then we will introduce their special instances, reverting what has been done in the textbook.

CC BY: $\ C Dr Marco Benini 2014

(93 of 189) An Introduction to Category Theory Lecture 11

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Products and I

Definition 11.1 (Product) Given a functor F : D C where D is a discrete category, the limit ³ → ´ Q F i,©p : Q F i F iª for F is called product in C. i ObjD i i ObjD i ObjD ∈ ∈ → ∈ Q When convenient, we will write F 0 F 1 (or similar) instead of i {0,1} F i. × ∈ In this case, we will denote with q0,q1 the unique arrow from the cone ³ © ª ´ 〈 〉 X, qi i {0,1} to the product. ∈ Also, each arrow pi is called the i-th projection of the product.

(95 of 189) Products and coproducts II

Definition 11.2 () Given a functor F : D C where D is a discrete category, the colimit ³ → ´ ` F i,©p : ` F i F iª for F is called coproduct in C. i ObjD i i ObjD i ObjD ∈ ∈ → ∈ ` When convenient, we will write F 0 F 1 (or similar) instead of i {0,1} F i. + ∈ Also, each arrow pi is called the i-th injection of the coproduct. P ` Sometimes we will write i I F i in place of i I F i. ∈ ∈

(96 of 189) Products and coproducts III

In Set, the product A B is just the , with π1 and π2 the canonical projections;× the coproduct object A B is the disjoint union A B + t and i1, i2 are its canonical injections.

In a poset category P, the product object A B, when it exists, is the greatest lower bound of A and B, while, symmetrically,× A B is the least upper bound of A and B. +

(97 of 189) Products and coproducts IV

A category where, for any collection U of objects, there exists the product QU, is said to have arbitrary products. If the property holds only when U is finite, the category is said to have finite products. Dually, for coproducts.

For example, Set has arbitrary products and coproducts.

A poset category P having finite products and coproducts is a bounded lattice; if it has arbitrary products and coproducts, it is a complete and bounded lattice.

(98 of 189) Products and coproducts V

Definition 11.3 (Product functors) Let C be a category with binary products. Then, each A ObjC determines ∈ a pair of functors ( A): C C, the right product functor, and − × → (A ): C C, the left product functor, such that × − → for B ObjC, ( A)(B) B A and (A )(B) A B; ■ ∈ − × = × × − = × for f HomC(B,C), ( A)(f ) f ,1A and (A )(f ) 1A,f . ■ ∈ − × = 〈 〉 × − = 〈 〉

(99 of 189) Initial and terminal objects I

Definition 11.4 (Terminal and initial object) Given the functor C from the empty category to some category C, its limit, if it exists, is; called → terminal object and it is denoted by 1, while its colimit, if it exists, is called initial object, and it is denoted by 0.

The properties of these objects when they exists are that, for every A ObjC, there is a unique arrow !: A 1 and there is a unique arrow !: 0 A∈. → → A notational convention denotes unique arrows by !.

(100 of 189) Initial and terminal objects II

In Set, is the unique initial object, while any singleton is a terminal object. For this; reason, an arrow f : 1 A is said to be a (global) element of a category. In Set, this amounts→ to say that, if f is an element, then its image, f (1), is a singleton, thus f denotes a unique member (element) of the set A.

In a preorder category P, if it exists, the initial object is the minimum, and the terminal object is the maximum.

In Grp, any trivial group T containing just the unit, is the initial object, as well as the terminal object. An object which is both initial and terminal is said to be a . Notice that, in Grp, this phenomenon can be spelt out as 0 1! = Notice how the empty product is a terminal object, while the empty co-product is an initial object.

(101 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 2.

Products are an essential component of Computer Science: for example, the usual Cartesian product used in databases, has to be really understood as a categorical product. In fact, it is NOT represented as a set of pairs, but by a much more complex data structure which allows for efficient searching. Technically, this means that the product which is really adopted is not the plain Cartesian product, but, up to isomorphisms, the chosen representation behaves like if it would be.

CC BY: $\ C Dr Marco Benini 2014

(102 of 189) An Introduction to Category Theory Lecture 12

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Equalisers and coequalisers I

Definition 12.1 ( and co-equaliser) Consider the category D:

α / 1A A B 1B 9 / f β

The equaliser is the limit of a functor F : D C. The co-equaliser is the colimit of F . →

(104 of 189) Equalisers and coequalisers II

Example 12.2 Let f ,g : A B in Set, and let X ©x A: f (x) g(x)ª. Then, the → = ∈ = inclusion e : X A is an equaliser of f ,g. → Also, let S ©(f (x),g(x)): x Aª A B and let R be the minimal = ∈ ⊆ × equivalence relation containing S. Call [y]R the equivalence class containing y B. Then, the map fR : B B/R given by b [b]R is the coequaliser of ∈ → 7→ f ,g.

(105 of 189) Equalisers and coequalisers III

Proposition 12.3 Every equaliser is monic. Proof. Suppose i : E A equalises f ,g : A B. Let i j i l where j,l : C E and let h: C A be→ h i j. We have f→h f i ◦j =g ◦i j g h and→ so there is a unique→ k : C =E ◦with i k h.◦ But=h ◦ i ◦ j,= so ◦k ◦must= be◦ j. However, i l i j h, so →k l, and j◦ l=. = ◦ ◦ = ◦ = = =

Corollary 12.4 Every coequaliser is epic.

(106 of 189) Pullbacks and pushouts I

Definition 12.5 (Pullback) The pullback is the limit of a functor from the following category:

B 1B f g  1A A / C 1A 9 f f

(107 of 189) Pullbacks and pushouts II

Definition 12.6 (Pushout) The pushout is the colimit of a functor from the following category:

g 1A C / B 1B 8 f f  1A A 9

(108 of 189) Pullbacks and pushouts III

Example 12.7 In Set, the following is a pullback which defines intersection:

A B ⊆ / B ∩

⊆ ⊆   A / C ⊆

(109 of 189) Pullbacks and pushouts IV

Example 12.8 In Set, let f : A C and let g : B C. Then, → → P ©(a,b) A B : f (a) g(b)ª = ∈ × = is the pullback object, while its projections are πf : P B, (a,b) b, and → 7→ πg : P A, (a,b) a. → 7→

(110 of 189) Pullbacks and pushouts V

Example 12.9 In any category with a terminal object, the following is a pullback:

π A B 2 / B × π1 !   A / 1 !

(111 of 189) Pullbacks and pushouts VI

Example 12.10 In any category, if e X / A

e g   A / B f is a pullback, then e is an equaliser of f ,g.

(112 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 2.

Equalisers and pullbacks, as well as their dual counterparts, are typical constructions in Category Theory. Differently from products, initial and terminal objects, they sound unfamiliar to set-theoretic reasoning. Take some effort to understand them and their manipulation.

CC BY: $\ C Dr Marco Benini 2014

(113 of 189) An Introduction to Category Theory Lecture 13

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Existence of limits I

Proposition 13.1 Consider a category C such that, for every category D and every functor F : D C, the limit of F exists. Then, C is a preordered category. → Proof.

Suppose there are f ,g : C1 C2 distinct. Because all limits exists, there is Q → an object P k C , the product of k copies of C , where k is the = 2 2 of the set of arrows in C. k Thus, we can construct 2 distinct cones (C1,{C1 C2}k ) by combining f and g in every possible way. Thus, we have 2k distinct→ factorizations C1 P, being P a product. These factorizations are arrows, so we have that 2k →k, contradicting Cantor’s Theorem. ≤

(115 of 189) Existence of limits II

The proof is valid even if C is small or finite.

We implicitly assumed that the collection of arrows forms a set. This is always true, as Category Theory is developed inside a set-theoretic universe. Then, the collection of arrows is a set, maybe outside the universe if the category is large. Developing Category Theory without a universe leads to foundational problems (we don’t want to discuss them in this course).

The result says that it makes little sense to consider categories which have all limits, for every “size” of the diagram category.

(116 of 189) Existence of limits III

Definition 13.2 A category C is complete when every functor F : D C with D a small category, has a limit. → A category C is finitely complete when every functor F : D C with D a finite category, has a limit. →

By duality one gets the notion of (finitely) co-.

Notice that “large limits” may exists: for example, the product of all sets exists and it is just the .

(117 of 189) Existence of limits IV

Theorem 13.3 (Limit) A category C is complete precisely when each family (a set-indexed collection) of objects has a product and each pair of arrows has an equaliser.

Corollary 13.4 The following conditions are equivalent: 1. C is finitely complete; 2. C has a terminal object, binary products, and equalisers; 3. C has a terminal object and pullbacks.

(118 of 189) Limits in Computer Science I

Example 13.5 Consider a database and the set of all possible SQL queries on it. It is immediate to see that the collection of results, a set of tables, together with the generating queries, form a category.

Given two views V1 and V2 and two queries q1 : V1 T and q2 : V2 T producing the same result T but starting from the two→ views, the pullback→

p2 P / V1

p1 q1   V2 / T q2 constructs the table P, together with the projections queries p1 and p2, which is the minimal part of the database which should be exposed to allow q1 and q2 extracting the information in T from V1 and V2. This fact provides a minimal way to model privacy and security of information.

(119 of 189) Limits in Computer Science II

Example 13.6 Consider the category of graphs and their partial homomorphisms, i.e., partial functions preserving adjacency. A graph rewriting rule r is an arrow r : L R and it is intended to operate on a graph G by identifying a match of L →in G and appropriately substituting that match with R.

A concrete and precise definition is somewhat hard to develop, but a categorical definition of this rewriting operation is immediate: a match is just an arrow M : L G in the category, and the result W is calculated as the following pushout→ r L / R

m   G / W

(120 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 2.

The examples about Computer Science application have been designed by Dr Benini from his past experience.

CC BY: $\ C Dr Marco Benini 2014

(121 of 189) An Introduction to Category Theory Lecture 14

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Limit Preserving Functors I

Definition 14.1 A functor F : A B preserves limits when, for every small category D and → every functor G : D A, if the limit (L,(pD)D ObjD) of G exists, then → ∈ (FL,(F pD)D ObjD) is the limit of F G. ∈ ◦

Definition 14.2 A functor F : A B reflects limits when, for every small category D and → every functor G : D A, if (FL,(F pD)D ObjD) is the limit of F G, then → ∈ ◦ (L,(pD)D ObjD) is the limit of G. ∈

(123 of 189) Limit Preserving Functors II

Proposition 14.3 Let A a (finitely) complete category and B an arbitrary category. A functor F : A B preserves (finite) limits when it preserves (finite) products and equalisers.→ Proof. Immediate consequence of Theorem 13.3.

(124 of 189) Limits in functor categories I

Proposition 14.4 Let C,D be small categories and A a category, let F : D Fun(C,A). If, for → every C ObjC, the functor F ( )(C): D A has a limit, then F has a limit as well and∈ this is computed pointwise.− → The proof is not difficult, but long and somewhat complex.

Computed pointwise means that the limit in Fun(C,A) can be expressed as: µ ¶ lim FD (C) lim (F (D)(C)) . D ObjD = D ObjD ∈ ∈

(125 of 189) Limits in functor categories II

Theorem 14.5 Consider a complete category A and a small category C. Then, the Fun(C,A) is complete and limits in it are computed pointwise.

Proof. Immediate consequence of Proposition 14.4.

The Theorem is particularly important when A is Set. In this cases, we get that the category of presheaves is complete and co-complete.

(126 of 189) Subobject classifiers I

Definition 14.6 (Subobject classifier)

In a category C with a terminal object 1, a subobject classifier is an object Ω with an arrow : 1 Ω satisfying the Ω-axiom: for each subobject > → f : A B, there is a unique χf : B Ω, the characteristic arrow, such that  → f A / / B

! χf   1 / Ω > is a pullback square

It is easy to show that the subobject classifier, when it exists, is unique up to isomorphisms, and that the characteristic arrow is monic.

(127 of 189) Subobject classifiers II

Definition 14.7 (Subobject functor) Let C be a category with pullbacks. Then C determines a contravariant functor Sub: Cop Set defined as → for A ObjC, Sub(A) ©B ObjC: B is a subobject ofAª; ■ ∈ = ∈ for f HomC(A,B), Sub(f ): Sub(B) Sub(A) which assigns to ■ ∈ → g : C  B the arrow h: D  A defined by the following pullback:

h D / / A

f   C / g / B

(128 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 2.

Subobject classifiers are illustrated in Section 4.2 of [Goldblatt].

CC BY: $\ C Dr Marco Benini 2014

(129 of 189) An Introduction to Category Theory Lecture 15

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Exponentiation I

Definition 15.1 (Exponentiation)

A category C with products has exponentiation if, for any A,B ObjC, there ∈ is BA ObjC, the , and ev: BA A B, the evaluation ∈ × → arrow, such that, for any C ObjC and g : C A B, there is a unique h: C BA, the exponential∈ transpose, making× the→ following diagram to commute:→ BA A ×O ev " h,1A B 〈 〉 ;

g C A ×

(131 of 189) Exponentiation II

Since g ev h,1A , from g we can construct h and vice versa, it follows = ◦〈 〉 A that Hom(C A,B) ∼ Hom(C,B ). Hence, the interpretation of having exponentiation× is that= the category allows currying of its arrows.

Definition 15.2 (Cartesian ) A finitely complete category with exponentiation is said to be Cartesian closed.

(132 of 189) Exponentiation III

Example 15.3 The category Set is Cartesian closed since it is finitely complete and BA Hom(A,B). It is also complete and co-complete. =

Example 15.4 The category Grp is finitely complete, since it has all products and a terminal object, but it does not admit exponentiation, thus is it not Cartesian closed.

(133 of 189) Exponentiation IV

Definition 15.5 (Evaluation)

Let C be a category with exponentiation, and let A ObjC. Then FA : C C A ∈ → defined as FA(B) B A for each B ObjC, and FA(f ) (f ),1A for = × ∈ = 〈 ◦ − 〉 each f HomC(B,C), is a functor. ∈ . Thus, ev: FA 1C, the evaluation transformation, is a natural transformation,−→ since the following diagram commutes for every g : C B: →

A evC FA(C) C A / C 1C(C) = × =

FA(g) (g ),1A g 1C(g) =〈 ◦− 〉 =  A  FA(B) B A / B 1C(B) = × evB =

(134 of 189) Exponentiation V

Theorem 15.6 The category Cat is Cartesian closed. Proof. The category 1 is a terminal object in Cat; it has binary products, so it has all the finite products, as well; also, it has equalisers, as it is easy to verify. Exponentiation is given by the functor category.

(135 of 189) Topoi I

Definition 15.7 (Topos) An elementary topos, usually abbreviated in topos, is a category E such that

■ E is finitely complete;

■ E is finitely co-complete;

■ E has exponentiation;

■ E has a subobject classifier.

It can be shown, by means of a very technical proof, that being finitely co-complete is implied by the other conditions, so a topos is a Cartesian closed category with a subobject classifier.

(136 of 189) Topoi II

Example 15.8 Set is a topos since it is Cartesian closed and its subobject classifier is the set Ω {0,1} with : 1 Ω defined by (x) 1. In fact,= let A B, thus> i→: A B with i(x>) x=: ⊆ → = i A / / B

! χi   1 / Ω > ½ 1 if x A with χi (x) ∈ . = 0 otherwise

Notice that FinSet is a topos too, because of the same argument.

(137 of 189) References and hints

This lesson has been adapted from Section 3.16 of [Goldblatt].

Cartesian closed categories are the fundamental notion to provide a denotational semantics to simply typed theories: the λ-abstraction is rendered by the exponentiation construction.

CC BY: $\ C Dr Marco Benini 2014

(138 of 189) An Introduction to Category Theory Lecture 16

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Adjunctions I

Definition 16.1 (Reflection) Let F : A B be a functor and let B ObjB.A reflection of B along F is a → ∈ pair (RB,ηB), with RB ObjA and ηB HomB(B,FRB), such that, for every ∈ ∈ (A,b) with A ObjA and b HomB(B,FA), there exists a unique ∈ ∈ a HomA(RB,A) such that F a ηB b. ∈ ◦ =

We may think that the reflection (RB,ηB) is the “best choice” of an object in A and an arrow ηB : B FRB. Here “best” means that any other choice factors uniquely through the→ reflection. In other words, it is the minimal choice we can make, with respect to factorisation.

(140 of 189) Adjunctions II

Proposition 16.2 Let F : A B be a functor and let B ObjB. When the reflection of B along F exists,→ it is unique up to isomorphisms.∈ Proof.

Consider two reflections (RB,ηB) and (RB0 ,η0B). By definition, we have a: RB R0 and a0 : R0 RB such that → B B →

F a ηB η0 and F a0 η0 ηB ◦ = B ◦ B = So, F (a a0) η0 F a ηB η0 F 1R η0 ◦ ◦ B = ◦ = B = B0 ◦ B and F (a0 a) ηB F a0 η0 ηB F 1R ηB . ◦ ◦ = ◦ B = = B ◦ By uniqueness of the factorisation, a a0 1R and a0 a 1R . ◦ = B0 ◦ = B

(141 of 189) Adjunctions III

Proposition 16.3 Consider a functor F : A B and assume that, for every B ObjB, there → ∈ exists a fixed reflection (RB,ηB) of B along F . Then, there is a unique functor R : B A such that R B RB and (ηB :(F R)B)B ObjB is a natural → . = ◦ ∈ transformation η: 1B F R. −→ ◦ Proof. (i) Let b Hom (B B ). Then, the pairs (R ) and (R ) determine a B 0 B,ηB B0 ,ηB0 unique∈ a Hom →(R R ) such that F a b. We put R b a and A B, B0 ηB ηB0 we claim ∈R is a functor. ◦ = ◦ = Consider the composite b0 b, with b0 : B0 B00: it holds that ◦ →

F (R b0 R b) ηB (F R)b0 (F R)b ηB (F R)b0 ηB b ◦ ◦ = ◦ ◦ ◦ ◦ = ◦ ◦ 0 ◦ = ηB b0 b (F R)(b0 b) ηB . = 00 ◦ ◦ = ◦ ◦ ◦ , →

(142 of 189) Adjunctions IV

, Proof. (ii) → Thus, R(b0 b) R b0 R b by uniqueness of the factorisation. ◦ = ◦ Similarly, since F (R idB) ηB F 1RB ηB, by uniqueness of the ◦ = ◦ factorisation, R 1B 1R . = B By the definition of R, it follows immediately that (ηB :(F R)B)B ObjB is a natural transformation as claimed. ◦ ∈

(143 of 189) Adjunctions V

Definition 16.4 (Left adjoint) A functor R : A A is left adjoint to the functor F : A B when there exists → . → a natural transformation η : 1B F R, called the unit of the adjunction, −→ ◦ such that, for every B ObjB, (RB,ηB) is a reflection of B along F . ∈ Dualising the previous definitions and results, we get the notion of co-reflection , of right adjoint and of co-unit.

(144 of 189) Adjunctions VI

Theorem 16.5 Let F : A B and G : B A. The following conditions are equivalent: → → 1. G is left adjoint to F ;

2. there exist bijections θA,B : HomA(GB,A) ∼ HomB(B,FA) for every A ObjA,B ObjB and those bijections are= natural both in A and in B; ∈ ∈ 3. F is right adjoint to G. Because of (3), we shall write G F to denote that F is right adjoint to G and G is left adjoint to F . a

(145 of 189) Adjunctions VII

Example 16.6 The forgetful functor U : Mon Set has a left adjoint F : Set Mon. For a given set X, FX is the free monoid→ on X. → The same holds for groups, so the left adjoint of the forgetful functor is the functor that builds the free group over a given set.

Example 16.7 Consider a fixed set I and the functor I : Set Set. This functor has a right adjoint given by ( )I : Set Set−. So× exponentiation→ is just the right adjoint of the product functor,− as→ above. The same holds in any category which has exponentiation.

(146 of 189) Adjunctions VIII

Example 16.8 In Cat, the category of small categories, the forgetul functor Obj mapping a category into the set of its objects, has both a right and a left adjoint. For a given set X, the left adjoint gives the discrete category having X as its objects; the right adjoint gives the category having X as its objects and one single arrow from each object to each object.

(147 of 189) Adjunctions IX

Proposition 16.9 Consider the following situation:

G K o o A / B / C F H where G F and K H. Then G K H F a a ◦ a ◦ Proof. Evident, considering the canonical bijections

HomA(GKC,A) HomB(KC,FA) HomC(C,HF : A) =∼ =∼ for every A ObjA and C ObjC. ∈ ∈

(148 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 3. All the omitted proofs can be found in that text.

The notion of adjunction models the idea of canonical construction of a minimal/maximal object.

CC BY: $\ C Dr Marco Benini 2014

(149 of 189) An Introduction to Category Theory Lecture 17

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Adjunctions X

Theorem 17.1 If the functor F : A B has a left adjoint G, then F preserves all the limits → which turn out to exist in A. Proof. (i)

Let (L,(pD)D ObjD) be the limit of H : D A. ∈ → We must prove that (FL,(F pD)D ObjD) is the limit of F H. Clearly, it is a cone, being the image∈ of a cone. ◦ Consider a cone (B,(qD)D ObjD) on F H. By adjointness, to ∈ ◦ qB : B FHD corresponds rD : GD HD in A. , → → →

(151 of 189) Adjunctions XI

, Proof. (ii) → Given d : D D0 in D, the naturality of the adjoint bijections θA,B implies that → 1 rD θ− (qD ) 0 HD0,B 0 =1 = θ− (F H d qD) = HD0,B ◦ = ³ 1 ´ θ− HomB(1B,F H d) (qD) = HD0,B ◦ = ³ 1 ´ HomA(1GB,H d) θ− (qD) = ◦ HD0,B = HomA(1GB,H d)(rD) = = H d rD . = ◦ So (GB,(rD)D ObjD) is a cone on H and r : GB L is the unique ∈ → factorisation such that, for each D ObjD, pD r rD. ∈ ◦ = Let s θL B(r): B FL in B. Using again the naturality of the bijections = , → θA,B, we have that F pD s qD. Since the θA,B are bijections, s is unique. ◦ =

(152 of 189) Adjunctions XII

Given A, B and C, with C small, and a functor F : A B, we define → F : Fun(C,A) Fun(C,B) ∗ H → F H 7→ ◦

Proposition 17.2 Consider F : A B with left adjoint G : B A. If C is any small category, then G is left→ adjoint to F . → ∗ ∗

(153 of 189) Adjunctions XIII

Definition 17.3 A functor F : A B satisifes the solution set condition with respect to → B ObjB when there is a set (not a proper class) SB ObjA such that, for ∈ ⊆ every A ObjA, b HomB(B,FA), there are A0 SB, a HomA(A,A0), ∈ ∈ ∈ ∈ b0 HomB(B,FA0) such that F a b0 b. ∈ ◦ = Notice how, when A is small, the condition above is automatically satisfied for every object, taking SB ObjA. =

Notice also that, when B admits a reflection along F , the set SB becomes just the singleton {RB}. So the solution set condition is much weaker than requiring the existence of reflections for all objects.

(154 of 189) Adjunctions XIV

Theorem 17.4 (Adjoint Functor) Let A be a complete category and let F : A B. Then F has a left adjoint if and only if F preserves all small limits and F→ satisfies the solution set condition for every B ObjB. ∈ In particular, if A is small, “F has a left adjoint” is the same as “F preserves all small limits”.

(155 of 189) Equivalence I

Proposition 17.5 . . Consider G F with F : A B, and let η: 1B F G and ε: G F 1A be the correspondinga unit and→ co-unit, respectively.−→ ◦ ◦ −→ Then, F is full and faithful if and only if ε is iso.

(156 of 189) Equivalence II

Proposition 17.6 Given F : A B, the following conditions are equivalent: → 1. F is full and faithful and has a full and faithful left adjoint G; 2. F has a left adjoint G and the unit and co-unit of the adjunction are isomorphisms;

3. there exists G : B A and two natural isomorphisms 1B F G and → =∼ ◦ G F 1A; ◦ =∼ 4. the dual of condition (1); 5. the dual of condition (2).

(157 of 189) Equivalence III

Definition 17.7 (Equivalence) A functor F : A B which satisfies the conditions of Proposition 17.6, is → called an equivalence between the categories A and B.

It is immediate to see that equivalence of categories is an equivalence relation.

(158 of 189) Equivalence IV

Proposition 17.8 Consider an equivalence of categories F : A B. If A is (finitely) → (co-)complete, so is B.

(159 of 189) References and hints

This lesson has been adapted from [Borceux], Chapter 3. All the omitted proofs can be found in that text.

CC BY: $\ C Dr Marco Benini 2014

(160 of 189) An Introduction to Category Theory Lecture 18

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Denotational semantics I

Usually, an expression e in a programming language gets its meaning by associating to e the computation it produces on some fixed machine. For example, the meaning of an assignment x 1; in the C programming language is that the value 1, represented as= a 32-bit word, is stored in memory cell whose name is x in the current context of execution.

A different way to assign a meaning to e is to associate it with a mathematical structure which represents the (collection of) computations that e may give rise to. For example, to a program we may associate a Turing machine, or a RAM program, or a partial recursive function, we seen in the course of Theoretical Computer Science.

(162 of 189) Denotational semantics II

For many reasons, it is simpler to associate mathematical entities to functional programs: in fact, a procedural programming language has a state, which is an hidden piece of information, which is essential to describe the meaning of most programming constructions.

In the following, we will consider a very simple functional programming language, and we will assign to its expressions a meaning in Cartesian categories.

(163 of 189) Typed λ-calculus I

First, we define the typed λ-calculus we want to model.

Definition 18.1 (Types) Given a set K of type constant, types are defined as each k K is a type; ■ ∈ ■ 1 is a type, informally denoting the empty product; if A and B are types, then so is A B; ■ × if A and B are types, then so is A B. ■ →

Usually, the programming language we are going to model is called simple theory of types, and it is considered the prototypical example of functional programming.

(164 of 189) Typed λ-calculus II

Definition 18.2 (Terms) Given a class of types, a set V of typed variables such that there is a denumerable quantity of them for each type, and a set F of typed constants, terms and the set of free variables in them are defined as if x :A V then x :A and FV(x) {x }; ■ ∈ = if f :A B F and t :A is a term, then f (t):B and FV(f (t)) FV(t); ■ → ∈ = :1 is a term and FV( ) ; ■ ∗ ∗ = ; if s :A and t :B are terms, then s,t :A B is a term and ■ 〈 〉 × FV( s,t ) FV(s) FV(t); 〈 〉 = ∪ ■ if t :A B is a term then fst(t):A and snd(t):B are terms and FV(fst×(t)) FV(snd(t)) FV(t); = = , →

(165 of 189) Typed λ-calculus III

, (Terms) → if t :B is a term and x :A V then (λx :A.t):A B is a term and ■ ∈ → FV(λx :A.t) FV(t) \{x }; = ■ if s :A B and t :A are terms, then (s t):B is a term and FV(s t)→ FV(s) FV(t). = ∪ There is a subtlety in the definition: for formal purposes, which will be clear later, it is useful to distinguish between application of a function symbol to a term, and application of a term to a term.

(166 of 189) Typed λ-calculus IV

Informally, types denote collections of possible values, while terms denote values.

The constant types K are the scalar datatypes, the ones which are implemented in the language: for example, integers or charactes or Booleans.

The product type represents vectors, arrays and records.

The arrow type represents programs: each term of type A B is a function that transforms its argument of type A into an output of type→ B.

The main feature of a functional programming language is that functions are pieces of data, and they can be explicitly passed as arguments, and they can be the result of a calculation.

(167 of 189) Typed λ-calculus V

The operations the language provide to deal with the product type are the constructor, and the corresponding destructors, usually called projections.

The operations to deal with the function type are application, which calculates what is the result of a function, given an argument, and abstraction, which builds a function from a term by considering a variable as a parameter.

The operations on the basic types are all in the set F .

(168 of 189) Typed λ-calculus VI

The simple theory of types operates by reducing each expression to a simpler one. The reduction rules will be shown in the next lecture: what matters is that the final result is an irreducible term.

The purpose of what we want to do, is to associate to each type, term and reduction rule a meaning, which will be a “piece” of a Cartesian closed category, in such a way that the categorical framework allows to interpret types, terms and reductions in a consistent way.

(169 of 189) References and hints

This lesson is adapted from Chapter D.4.2 of P. Johnstone, Sketches of an Elephant: A Topos Theory Compendium, volume 2, Oxford Logic Guides 44, Oxford University Press (2002). ISBN: 978-0198515982

Johnstone’s text is the last reference work on Topos Theory and it contains almost everything which is known on this fascinating topic. It is also a very difficult book, although very well written, in a crystal-clear style, requiring a mature mathematical attitude before approaching.

A much simpler description of the simple theory of types, which is better suited for programming, can be found in B.C. Pierce, Types and Programming Languages, The MIT Press (2002). ISBN: 978-0-262-16209-8.

CC BY: $\ C Dr Marco Benini 2014

(170 of 189) An Introduction to Category Theory Lecture 19

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Typed λ-calculus I

Definition 19.1 (Equality)

The only formulae we allow in the formation of a λ-theory, which is a set of formulae, are equalities in a context: X.t A s, where t :A and s :A are terms, and the context X V is a finite set= of variables such that FV(t) FV(s) X. ⊆ ∪ ⊆

Equalities are the axioms of a λ-theory. Often, we do not write contexts explicitly: in those cases, it is assumed to be the canonical one, that is, FV(t) FV(s). ∪

(172 of 189) Typed λ-calculus II

Definition 19.2 (Calculus)

The rules of inference of the λ-calculus are:

■ X.s t = (subst1) ; Y .s[r/x] t[r/x] = ■ (refl) ; X.x x = ■ X.x y = (sym) ; X.y x = ■ X.x y X.y z = = (trans) ; X.x z = , →

(173 of 189) Typed λ-calculus III

, (Calculus) → ■ X.s t = (subst2) ; Y .r[s/x] r[t/x] = ■ (unit) ; X.x =1 ∗ ■ (fst) ; X.fst( x,y ) x 〈 〉 = ■ (snd) ; X.snd( x,y ) y 〈 〉 = ■ (pair) ; X. fst(z),snd(z) z 〈 〉 = , →

(174 of 189) Typed λ-calculus IV

, (Calculus) → ■ (β) , X.(λy :A.s)t s[t/y] = where y FV(t); 6∈ ■ (η) , X.λy :A.t y t = where y FV(t); 6∈ ■ X,y :A.s B t = (λ) . X.(λy :A.s) (λy :A.t) =

(175 of 189) Interpretation I

Definition 19.3 (λ-structure)

Let C be a Cartesian closed category. A λ-structure M in C is defined by a function M : K ObjC mapping the type constants to objects of C; ■ → ■ a function M from F , the set of function symbols, to the arrows of C such that M(f : A B): MA MB. → → The function M : K ObjC is extended to arbitrary types as → M 1 1C, the terminal object of C; ■ = M(A B) MA C MB, the product of C; ■ × = × M(A B) (MB)MA, the exponential object of C. ■ → = We omit subscripts, for clarity.

(176 of 189) Interpretation II

Definition 19.4 (Interpretation)

If M is a λ-structure in a Cartesian closed category C, we assign to each term in a context X.t :B an interpretation

[[X.t]]M : MA MAn MB 1 × ··· × → where X {x1 : A1,...,xn :An }, and MA abbreviates MA1 MAn in the following= way: × ··· ×

if t xi then [[X.t]] πi , the i-th projection; ■ ≡ = if t f (t0) then [[X.t]] M f [[X.t0]]; ■ ≡ = ◦ if t then [[X.t]] is the unique morphism MA MB; ■ ≡ ∗ → if t t0,t00 and B B B then ■ ≡ 〈 〉 ≡ 1 × 2 [[X.t]] [[X.t0]],[[X.t00]] : MA MB MB ; = 〈 〉 → 1 × 2 , →

(177 of 189) Interpretation III

, (Interpretation) → if t fst(t0) then [[X.t]] π [[X.t0]]; ■ ≡ = 1 ◦ if t snd(t0) then [[X.t]] π [[X.t0]]; ■ ≡ = 2 ◦ if t λx : C.t0, where we assume z : C X, and B C D then ■ ≡ 6∈ ≡ → [[X.t]] h with h: MA (MB)MC defined as the exponential transpose in the following= evaluation→ diagram:

(MB)MC MC O × ev h,1MC 〈 〉 & MA MC / D ; × [[X,z:A.t0]]

, →

(178 of 189) Interpretation IV

, (Interpretation) → if t t0 t00 then [[X.t]] ev [[X.t0]],[[X.t00]] . ■ ≡ = ◦〈 〉 Moreover, [[X.t A t0]] is the equaliser =

[[X.t]] [[X.t A t0]] / / MA / MB . = [[X.t0]]

(179 of 189) Interpretation V

Definition 19.5 (Validity)

An equality X.s A t is valid in a λ-structure M in a Cartesian closed = category C iff [[X.s A t]] 1MA MAn with X {x1 :A1,...,xn :An }. = = 1×···× =

Definition 19.6 (Model)

A λ-structure M in a Cartesian closed category C is a model for a λ-theory T iff each axiom X.t A s in T is valid in M. =

(180 of 189) References and hints

This lesson follows the treatment as given in Chapter D.4.2 of P. Johnstone, Sketches of an Elephant: A Topos Theory Compendium, volume 2, Oxford Logic Guides 44, Oxford University Press (2002). ISBN: 978-0198515982.

CC BY: $\ C Dr Marco Benini 2014

(181 of 189) An Introduction to Category Theory Lecture 20

Dr Marco Benini

[email protected]

Dottorato di Ricerca in Informatica e Matematica del Calcolo Università degli Studi dell’Insubria

2014 Soundness

Theorem 20.1 (Soundness)

If X.s A t is derivable in a λ-theory T , then it is valid in all models for T in every Cartesian= closed category. Proof. We need to check that the rules of the λ-calculus preserve validity:

■ the axioms (refl), (sym), (unit) and the rule (trans) are obvious;

■ rules (subst1) and (subst2) are proved to preserve validity by a trivial induction which shows that [[X : t[s/y]] [[Y .t]] [[X.s]]; = ◦ ■ rules (fst), (snd) and (pair) are straightforward from the definition of interpretation and the properties of product;

■ rules (β) and (η) are straightforward from the definition of interpretation and the properties of evaluation. [Exercise] Fill the details.

(183 of 189) Completeness I

Definition 20.2 (Syntactic category)

Let T be a λ-theory. We define a category CT as follows:

■ the objects of CT are the types of the language of T ;

■ the arrows of CT are equivalence classes [x : A.t] of terms in contexts where [x.s] [x.t] iff x.t s is provable in T , or [x.t] [y.t[y/x]]. The substitution= and equality rules= ensure that this definition= does not depend on the choice of t; the identity morphism is [x.x]: A A; ■ → composition is given by substitution: given [x.t]: A B and ■ → [y.s]: B C, [y.s] [x.t] [z.s[t/y]]. → ◦ = Note that we do not need contexts with more that one variable, having product types.

(184 of 189) Completeness II

Proposition 20.3

The category CT is Cartesian closed. Proof.

■ the terminal object is the type 1 and, for each object A, the unique arrow A 1 is [x :A. ]; → ∗ the product of A and B is the type A B, with projections [z.fst(z)] and ■ × [z.snd(z)], and the morphism C A B induced by [w.s]: C A and → × → [w.t]: C B is [w. s,t ]; → 〈 〉 the exponential BA is the type A B, with evaluation map ■ → (A B) A B defined as [w.fst(w)snd(w)], and, given any → × → [z.t]: C A B, its exponential transpose C (A B) is × → → → [w.λx :A.t[ w,x /z]]. 〈 〉

(185 of 189) Completeness III

Theorem 20.4 (Completeness)

The Cartesian closed category CT contains a λ-structure M which validates exactly the equalities derivable form the λ-theory T . Moreover, for any Cartesian closed category D, there is a bijection between natural isomorphisms classes of Cartesian closed functors CT D and isomorphisms → classes of T -models in D. Proof. (i)

The structure MT sends types to themselves and each primitive function symbol f : A B to [x :A.f (x)]. By an easy induction we get that → [[x.t]]M [x.t]. Hence, the equalities in a context valid in MT are exactly T = those provable in T . , →

(186 of 189) Completeness IV

, Proof. (ii) → Given a model N in D, the corresponding functor FN : CT D sends A to → NA for each type A, and [x.t] to [[x.t]]N . It is clear that FN is a Cartesian closed functor and that FN (MT ) N. = In the opposite direction, since any Cartesian closed functor F : CT D must preserve interpretations of arbitrary terms in a context, it is easily→ seen to be naturally isomorphic to FN where N F (MT ). =

(187 of 189) References and hints

Theorems and proofs of this lesson follow the treatment as given in Chapter D4.2 of P. Johnstone, Sketches of an Elephant: A Topos Theory Compendium volume 2, Oxford University Press (2002). ISBN: 978-0198515982.

CC BY: $\ C Dr Marco Benini 2014

(188 of 189) The

Tramonto, Rodi — © Marco Benini (2012)

(189 of 189)