Category Theory
Roy L. Crole University of Leicester, UK April 2018
MGS 2018, 9-13 April, University of Nottingham, UK 1/48
Category Theory Roy L. Crole University of Leicester, UK April - - PowerPoint PPT Presentation
Category Theory Roy L. Crole University of Leicester, UK April 2018 MGS 2018, 9-13 April, University of Nottingham, UK 1/48 Introductory Remarks A theory of abstraction (of algebraic structure). It had its origins in Algebraic Topology
MGS 2018, 9-13 April, University of Nottingham, UK 1/48
▶ A theory of abstraction (of algebraic structure). ▶ It had its origins in Algebraic Topology with the work of
▶ It provides tools and techniques which allow the formulation
▶ We can discover new relationships between things that are
▶ Category theory concentrates on how things behave and not on
▶ As such, category theory can clarify and simplify our ideas—and
MGS 2018, 9-13 April, University of Nottingham, UK 2/48
▶ Connections with Computer Science were first made in the
▶ Some contributions (chosen by me . . . there are many many
▶ Categories for Types by Roy L. Crole. CUP. ▶ Cartesian closed categories as models of pure functional
▶ The use of strong monads to model notions of computation
▶ Precise correspondences between categorical structures and
▶ The categorical solution of domain equations as models of
▶ Nominal categories as models of variable binding. MGS 2018, 9-13 April, University of Nottingham, UK 2/48
MGS 2018, 9-13 April, University of Nottingham, UK 2/48
MGS 2018, 9-13 April, University of Nottingham, UK 3/48
OHP A category C is specified by the following data:
▶ A collection ob C of entities called objects. An object will
▶ For any two objects A and B, a collection C(A, B) of entities
▶ If f ∈ C(A, B) then A is called the source of f, and B is the
MGS 2018, 9-13 April, University of Nottingham, UK 4/48
▶ There is an operation assigning to each object A of C an
▶ There is an operation
▶ Such morphisms f and g, with a common source and target B,
MGS 2018, 9-13 April, University of Nottingham, UK 4/48
▶ These operations are unitary
▶ and associative, that is given morphisms f : A → B,
MGS 2018, 9-13 April, University of Nottingham, UK 4/48
▶ The collection of all sets and all functions
▶ Each set has an identity function; functions compose;
▶ The collection of all elements of a preorder and all instances of
▶ Each element has an identity relationship (reflexivity);
▶ The collection of all elements of a singleton { ∗ } (!) and any
▶ ∗ has an identity term x0; terms compose (substitution);
MGS 2018, 9-13 April, University of Nottingham, UK 5/48
▶ The category Part with ob Part all sets and morphisms
▶ The identity function idA is a partial function! ▶ Given f : A → B, g : B → C, then for each element a of A,
▶
OHP Given a category C, the opposite category Cop has ▶ ob Cop def
▶ The identity on an object A in Cop is defined to be idop
A .
▶ If f op : A → B and gop : B → C are morphisms in Cop, then
▶ * Opposite categories can have surprising structure. The
MGS 2018, 9-13 April, University of Nottingham, UK 6/48
▶ A discrete category is one for which the only morphisms are
▶ A semigroup (S, b) is a set S together with an associative
▶ Concrete examples are
▶ Addition on the natural numbers, (N, +, 0). ▶ OHP Concatenation of finite lists over a set A, (list(A), ++, [ ]). MGS 2018, 9-13 April, University of Nottingham, UK 6/48
▶
OHP M
▶ PreSet has objects preorders and morphisms the monotone
▶ The category of relations Rel has objects sets and morphisms
▶ The category of lattices L
▶ The category CL
▶ The category Grp of groups and homomorphisms.
MGS 2018, 9-13 April, University of Nottingham, UK 6/48
▶ A morphism f : A → B is an isomorphism if there is some
▶ g is an inverse for f and vise versa. ▶ A is isomorphic to B, A ∼
▶ Bijections in Set are isomorphisms. There are typically many
▶ In the category determined by a partially ordered set, the only
MGS 2018, 9-13 April, University of Nottingham, UK 7/48
OHP
▶ an operation taking objects A in C to objects FA in D, and ▶ an operation sending morphisms f : A → B in C to morphisms
▶ F(idA) = idFA, and ▶ F(g ◦ f) = Fg ◦ F f provided g ◦ f is defined. MGS 2018, 9-13 April, University of Nottingham, UK 8/48
▶ Let C be a category. The identity functor idC : C → C is
▶ Let (X, ≤X) and (Y, ≤Y) be categories and m: X → Y a
MGS 2018, 9-13 April, University of Nottingham, UK 9/48
▶ We may define a functor F : Set → M
▶ Note that F(idA) = idFA
MGS 2018, 9-13 April, University of Nottingham, UK 9/48
▶ . . . and note that F(g ◦ f) = Fg ◦ F f
MGS 2018, 9-13 April, University of Nottingham, UK 9/48
▶ Given a set A, recall that the powerset P(A) is the set of
▶ f∗ is sometimes called the direct image of f.
MGS 2018, 9-13 April, University of Nottingham, UK 10/48
▶ We can define a contravariant powerset functor
▶ f −1 is sometimes called the inverse image of f (and
MGS 2018, 9-13 April, University of Nottingham, UK 10/48
MGS 2018, 9-13 April, University of Nottingham, UK 11/48
▶ Recall F : Set → M
MGS 2018, 9-13 April, University of Nottingham, UK 12/48
▶ Let C and D be categories and let F, G, H be functors from
▶
OHP This yields a category DC with objects functors from C to
▶ Exercise: α is an isomorphism in DC just in case each αA is an
▶ We will use SetSet when we model the Haskell datatype.
MGS 2018, 9-13 April, University of Nottingham, UK 12/48
▶ See slide 22 and OHP on CCCs. ▶ Define a functor FX : Set → Set by
▶ (! Products) FX(A)
def
▶ (! Products) FX( f)
def
MGS 2018, 9-13 April, University of Nottingham, UK 13/48
MGS 2018, 9-13 April, University of Nottingham, UK 14/48
OHP A binary product of objects A and B in C is specified by
▶ an object A × B of C, together with ▶ two projection morphisms πA : A × B → A and
MGS 2018, 9-13 April, University of Nottingham, UK 15/48
▶ Let (X, ≤) be a preorder. l ∈ X is a lower bound of
▶ x ∈ S ⊆ X is greatest in S if (∀s ∈ S)(s ≤ x) and is least
▶ In a preorder a greatest lower bound x ∧ y of x and y (if it
MGS 2018, 9-13 April, University of Nottingham, UK 16/48
▶ The binary product of A and B in Set has
▶ In any C, if pi : P → Ai is any product of A1 and A2 then
MGS 2018, 9-13 April, University of Nottingham, UK 16/48
def
▶ an object A1 × . . . × An (or Πi∈IAi) in C, and ▶ for every j ∈ I, a morphism πj : A1 × . . . × An → Aj in C called
def
MGS 2018, 9-13 April, University of Nottingham, UK 17/48
▶ A finite product of (A1, . . . , An) ≡ (Ai | i ∈ I) in Set is
▶ In a preorder (X, ≤), a finite product x1 × . . . × xn, if it
▶ A terminal object 1 in a category C has the property that
MGS 2018, 9-13 April, University of Nottingham, UK 18/48
OHP A coproduct of a non-empty family of objects (Ai | i ∈ I) in C,
▶ an object A1 + . . . + An (Σi∈IAi), together with ▶ insertion morphisms ιj : Aj → A1 + . . . + An,
MGS 2018, 9-13 April, University of Nottingham, UK 19/48
def
MGS 2018, 9-13 April, University of Nottingham, UK 19/48
▶ In Set the binary coproduct of sets A1 and A2 is given by their
▶ Let preorder (X, ≤) have top and bottom elements and all
MGS 2018, 9-13 April, University of Nottingham, UK 20/48
▶
OHP Given (X, ≤) and (Y, ≤) in PreSet, the binary product is
▶ An initial object 0 in a category C has the property that there
MGS 2018, 9-13 April, University of Nottingham, UK 20/48
▶ Suppose that we have ( fi : C → Ai | i ∈ { 1, 2 }) and
▶ Suppose that we have ( fi : Ai → C | i ∈ { 1, 2 })and
MGS 2018, 9-13 April, University of Nottingham, UK 21/48
▶ Suppose that f1 : A1 → B1 and f2 : A2 → B2. Then
▶ This notation is easily extended to finite families
MGS 2018, 9-13 April, University of Nottingham, UK 22/48
MGS 2018, 9-13 April, University of Nottingham, UK 23/48
MGS 2018, 9-13 April, University of Nottingham, UK 23/48
▶ A pair of monotone functions
▶ We say that l is left adjoint to r and that r is right adjoint to
MGS 2018, 9-13 April, University of Nottingham, UK 24/48
▶ Let 1
MGS 2018, 9-13 April, University of Nottingham, UK 25/48
▶ Define ∆: X → X × X by ∆(x)
▶ This structure corresponds to X having binary products and
MGS 2018, 9-13 April, University of Nottingham, UK 26/48
▶ Let L: C → D and R: D → C be functors. L is left adjoint
▶ a bijection between morphisms LA → B in D and A → RB
▶ OHP this bijection is natural in A and B: given morphisms
MGS 2018, 9-13 April, University of Nottingham, UK 27/48
▶ The forgetful functor U : M
OHP MGS 2018, 9-13 April, University of Nottingham, UK 28/48
▶ This is given by
▶ Note that
MGS 2018, 9-13 April, University of Nottingham, UK 28/48
▶
OHP The diagonal functor ∆: C → C × C taking a function
▶ where the bijection for Π is
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 28/48
▶ An algebra for F is a morphism σ : FA → A in C. The
OHP
▶ Given any other algebra f : FX → X and h: A → X, then h
▶ There is a category CF of algebras and algebra homomorphisms. ▶ An initial object σ : FI → I is called an initial algebra. If
MGS 2018, 9-13 April, University of Nottingham, UK 29/48
▶ Suppose that C has binary (co)products. The functors
▶ One can also define functors (−) × (−) and (−) + (−) . . .
MGS 2018, 9-13 April, University of Nottingham, UK 30/48
▶
OHP 1 + (−): Set → Set has an initial algebra
MGS 2018, 9-13 April, University of Nottingham, UK 31/48
▶ The function (+n): N → N which adds n, for any n ∈ N,
▶ A monoid (M, b, e) is an algebra
MGS 2018, 9-13 April, University of Nottingham, UK 31/48
MGS 2018, 9-13 April, University of Nottingham, UK 32/48
MGS 2018, 9-13 April, University of Nottingham, UK 32/48
▶ For every object A and B of C there is a natural transformation
▶ ρ determines a morphism in θ ∈ C(A, B) such that
▶ In fact any θ ∈ C(A, B) determines a natural transformation
def
▶ These processes are inverses: This is the (Mini) Yoneda Lemma.
MGS 2018, 9-13 April, University of Nottingham, UK 32/48
MGS 2018, 9-13 April, University of Nottingham, UK 32/48
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 32/48
▶ We define a Cartesian Closed Category (CCC) OHP ▶ Show that Set is a CCC. OHP ▶ Show that Set CCC structure has the properties of an
▶ Show that any CCC can be defined equivalently in terms of an
MGS 2018, 9-13 April, University of Nottingham, UK 33/48
MGS 2018, 9-13 April, University of Nottingham, UK 34/48
MGS 2018, 9-13 April, University of Nottingham, UK 35/48
def
MGS 2018, 9-13 April, University of Nottingham, UK 35/48
MGS 2018, 9-13 April, University of Nottingham, UK 35/48
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 35/48
MGS 2018, 9-13 April, University of Nottingham, UK 35/48
MGS 2018, 9-13 April, University of Nottingham, UK 35/48
MGS 2018, 9-13 April, University of Nottingham, UK 35/48
MGS 2018, 9-13 April, University of Nottingham, UK 35/48
▶ Define a Haskell (recursive) datatype grammar. ▶ Show that any datatype declaration D gives rise to a functor
▶ Demonstrate that D can be modelled by an initial algebra
▶ Show that the functor F preserves colimits of diagrams of the
▶ and (hence) that F must have an initial algebra for purely
MGS 2018, 9-13 April, University of Nottingham, UK 36/48
▶ A set of type patterns T is defined by
▶ A datatype is specified by the statement
▶ A collection of type assignments is defined inductively by the
MGS 2018, 9-13 April, University of Nottingham, UK 37/48
MGS 2018, 9-13 April, University of Nottingham, UK 38/48
OHP
▶ The functor F is defined (as a coproduct in SetSet) by
▶ Functors FT : Set → Set are defined by recursion on the
▶ FD
def
▶ FUnit(g : U → V)
def
▶ FInt(g : U → V)
def
▶ FT1×T2
def
MGS 2018, 9-13 April, University of Nottingham, UK 39/48
▶
OHP We set I
▶ σD(E ∈ I)
def
▶ σUnit(∗ ∈ 1)
def
▶ σInt(z ∈ Z)
def
▶ σT1×T2((e1, e2) ∈ FT1I × FT2I)
def
▶ It may be useful to note that σ(ιi(ei ∈ FTiI)) = Ki σTi(ei).
MGS 2018, 9-13 April, University of Nottingham, UK 40/48
▶
OHP Suppose that f : FX → X in Set. We have to prove that
MGS 2018, 9-13 April, University of Nottingham, UK 41/48
▶ Note f : ExpD → FDX; we will define f
▶ θD(Ki Ei ∈ ExpD)
def
▶ θUnit(() ∈ ExpUnit)
def
▶ θInt(z ∈ ExpInt)
def
▶ θT1×T2((E1, E2) ∈ ExpT1×T2)
def
MGS 2018, 9-13 April, University of Nottingham, UK 41/48
▶ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 41/48
▶ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 41/48
▶ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 41/48
▶ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 41/48
▶ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 41/48
▶ Define the notion of a colimit; examine the special case of
▶ Show that any left adjoint preserves colimits ∗. ▶ Prove that any functor F that preserves chain-colimits must
▶ Prove that the datatype functor F preserves chain-colimits
MGS 2018, 9-13 April, University of Nottingham, UK 42/48
▶ Given a diagram D: I → C, a colimit for D is given by an object
▶ Binary coproducts arise from the discrete category I def
MGS 2018, 9-13 April, University of Nottingham, UK 43/48
▶ Let D: ω → C; suppose that i ≤ i + 1 is a typical morphism
MGS 2018, 9-13 April, University of Nottingham, UK 43/48
▶ It is a fact that Set has all (small) colimits. ▶ It is a fact that a colimit for ∆: ω × ω → C exists if and only
MGS 2018, 9-13 April, University of Nottingham, UK 43/48
MGS 2018, 9-13 April, University of Nottingham, UK 44/48
MGS 2018, 9-13 April, University of Nottingham, UK 44/48
MGS 2018, 9-13 April, University of Nottingham, UK 44/48
MGS 2018, 9-13 April, University of Nottingham, UK 44/48
MGS 2018, 9-13 April, University of Nottingham, UK 44/48
MGS 2018, 9-13 April, University of Nottingham, UK 45/48
def
def
def
def
MGS 2018, 9-13 April, University of Nottingham, UK 45/48
def
+1
MGS 2018, 9-13 April, University of Nottingham, UK 45/48
MGS 2018, 9-13 April, University of Nottingham, UK 46/48
MGS 2018, 9-13 April, University of Nottingham, UK 46/48
MGS 2018, 9-13 April, University of Nottingham, UK 46/48
MGS 2018, 9-13 April, University of Nottingham, UK 46/48
MGS 2018, 9-13 April, University of Nottingham, UK 46/48
MGS 2018, 9-13 April, University of Nottingham, UK 46/48
MGS 2018, 9-13 April, University of Nottingham, UK 47/48
▶ Steve Awodey. Category Theory, Oxford Logic Guides, Oxford
▶ Roy L Crole. Categories for Types, Cambridge University Press,
▶ P.J. Freyd and A. Scedrov. Categories, Allegories, Elsevier
▶ T. Leinster. Basic Category Theory, CUP, 2014. Available
▶ S. Mac Lane. Categories for the Working Mathematician,
▶ Benjamin C. Pierce. Basic Category Theory for Computer
▶ Andrew M. Pitts. Nominal Sets, Cambridge University Press,
▶ Harold Simmons. An Introduction to Category Theory,
MGS 2018, 9-13 April, University of Nottingham, UK 48/48