Category Theory
Roy L. Crole University of Leicester, UK April 2015
MGS 2015, 7-11 April, University of Sheffield, UK 1/39
Category Theory Roy L. Crole University of Leicester, UK April - - PowerPoint PPT Presentation
Category Theory Roy L. Crole University of Leicester, UK April 2015 MGS 2015, 7-11 April, University of Sheffield, UK 1/39 Introductory Remarks Category Theory is a theory of abstraction (of algebraic structure). It had its origins in
MGS 2015, 7-11 April, University of Sheffield, UK 1/39
◮ Category Theory is a theory of abstraction (of algebraic
◮ 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 2015, 7-11 April, University of Sheffield, UK 2/39
◮ Connections with Computer Science were first made in the
◮ Some contributions (chosen by me . . . there are many many
◮ 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
◮ Categories for concurrent computation. ◮ Nominal categories as models of variable binding. MGS 2015, 7-11 April, University of Sheffield, UK 2/39
MGS 2015, 7-11 April, University of Sheffield, UK 3/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 4/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 5/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 5/39
◮ These operations are unitary
◮ and associative, that is given morphisms f : A → B,
MGS 2015, 7-11 April, University of Sheffield, UK 5/39
◮ 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,
◮ 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
MGS 2015, 7-11 April, University of Sheffield, UK 6/39
◮ A discrete category is one for which the only morphisms are
◮ A semigroup (S, b) is a set S together with an associative
◮ Addition on the natural numbers, (N, +, 0). ◮ Concatenation of finite lists over a set A, (list(A), ++, [ ]). MGS 2015, 7-11 April, University of Sheffield, UK 6/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 6/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 7/39
◮ We may define a functor F : Set → M
◮ Note that F(idA) = idFA
MGS 2015, 7-11 April, University of Sheffield, UK 7/39
◮ . . . and note that F(g ◦ f) = Fg ◦ F f
MGS 2015, 7-11 April, University of Sheffield, UK 7/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 8/39
◮ Given a set A, recall that the powerset P(A) is the set of
◮ f∗ is sometimes called the direct image of f.
MGS 2015, 7-11 April, University of Sheffield, UK 9/39
◮ We can define a contravariant powerset functor
◮ f ∗ is sometimes called the inverse image of f.
MGS 2015, 7-11 April, University of Sheffield, UK 9/39
MGS 2015, 7-11 April, University of Sheffield, UK 10/39
◮ Recall F : Set → M
MGS 2015, 7-11 April, University of Sheffield, UK 11/39
◮ Let C and D be categories and let F, G, H be functors from
MGS 2015, 7-11 April, University of Sheffield, UK 11/39
◮ Define a functor FX : Set → Set by
◮ (! Products) FX(A)
def
◮ (! Products) FX( f)
def
MGS 2015, 7-11 April, University of Sheffield, UK 11/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 12/39
◮ an object A × B of C, together with ◮ two projection morphisms πA : A × B → A and
MGS 2015, 7-11 April, University of Sheffield, UK 13/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 14/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 14/39
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 2015, 7-11 April, University of Sheffield, UK 15/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 16/39
◮ an object A1 + . . . + An (Σi∈IAi), together with ◮ insertion morphisms ιj : Aj → A1 + . . . + An,
MGS 2015, 7-11 April, University of Sheffield, UK 17/39
def
MGS 2015, 7-11 April, University of Sheffield, UK 17/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 18/39
◮ Given (X, ≤) and (Y, ≤) in ParSet, the binary product is
◮ An initial object 0 in a category C has the property that there
MGS 2015, 7-11 April, University of Sheffield, UK 18/39
◮ Suppose that we have ( fi : C → Ai | i ∈ { 1, 2 }) and
◮ Suppose that we have ( fi : Ai → C | i ∈ { 1, 2 })and
MGS 2015, 7-11 April, University of Sheffield, UK 19/39
◮ Suppose that f1 : A1 → B1 and f2 : A2 → B2. Then
◮ This notation is easily extended to finite families
MGS 2015, 7-11 April, University of Sheffield, UK 20/39
◮ Suppose that C has binary (co)products. The functors
MGS 2015, 7-11 April, University of Sheffield, UK 21/39
◮ Suppose that F1 and F2 are objects (that is, functors) of DC
MGS 2015, 7-11 April, University of Sheffield, UK 21/39
◮ An algebra for F is a morphism σ : FI → I in C. The algebra
◮ There is a category CF of algebras and algebra homomorphisms
MGS 2015, 7-11 April, University of Sheffield, UK 22/39
◮ 1 + (−): Set → Set has an initial algebra
MGS 2015, 7-11 April, University of Sheffield, UK 22/39
◮ EXAMPLE: the function (+n): N → N which adds n, for
◮ A monoid (M, b, e) is an algebra
MGS 2015, 7-11 April, University of Sheffield, UK 22/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 23/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 24/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 25/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 26/39
◮ Suppose that f : FX → X in Set. We have to prove that
MGS 2015, 7-11 April, University of Sheffield, UK 27/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 27/39
◮ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2015, 7-11 April, University of Sheffield, UK 27/39
◮ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2015, 7-11 April, University of Sheffield, UK 27/39
◮ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2015, 7-11 April, University of Sheffield, UK 27/39
◮ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2015, 7-11 April, University of Sheffield, UK 27/39
◮ Observe that for any T we have θT ◦ σT = FTθD, which follows
def
def
MGS 2015, 7-11 April, University of Sheffield, UK 27/39
◮ A pair of monotone functions
◮ We say that l is left adjoint to r and that r is right adjoint to
MGS 2015, 7-11 April, University of Sheffield, UK 28/39
◮ Let 1
MGS 2015, 7-11 April, University of Sheffield, UK 29/39
◮ Define ∆: X → X × X by ∆(x)
◮ This structure corresponds to X having binary products and
MGS 2015, 7-11 April, University of Sheffield, UK 30/39
◮ 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
◮ this bijection is natural in A and B: given morphisms
MGS 2015, 7-11 April, University of Sheffield, UK 31/39
◮ The forgetful functor U : M
MGS 2015, 7-11 April, University of Sheffield, UK 32/39
◮ This is given by
◮ Note that
MGS 2015, 7-11 April, University of Sheffield, UK 32/39
◮ For a fixed set A, the functor (−) × B: Set → Set has a
MGS 2015, 7-11 April, University of Sheffield, UK 32/39
◮ The diagonal functor ∆: Set → Set × Set taking a function
def
def
def
def
◮ If we replace Set by any category C with (co)products, defining
MGS 2015, 7-11 April, University of Sheffield, UK 32/39
MGS 2015, 7-11 April, University of Sheffield, UK 33/39
def
MGS 2015, 7-11 April, University of Sheffield, UK 33/39
MGS 2015, 7-11 April, University of Sheffield, UK 33/39
def
def
MGS 2015, 7-11 April, University of Sheffield, UK 33/39
MGS 2015, 7-11 April, University of Sheffield, UK 33/39
MGS 2015, 7-11 April, University of Sheffield, UK 33/39
MGS 2015, 7-11 April, University of Sheffield, UK 33/39
MGS 2015, 7-11 April, University of Sheffield, UK 33/39
◮ 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 2015, 7-11 April, University of Sheffield, UK 34/39
◮ Let D: ω → C; suppose that i ≤ i + 1 is a typical morphism
MGS 2015, 7-11 April, University of Sheffield, UK 34/39
◮ It is a fact that Set has all (small) colimits. ◮ It is a fact that a colimit for ∆: ω × ω → C exists if and only
MGS 2015, 7-11 April, University of Sheffield, UK 34/39
MGS 2015, 7-11 April, University of Sheffield, UK 35/39
MGS 2015, 7-11 April, University of Sheffield, UK 35/39
MGS 2015, 7-11 April, University of Sheffield, UK 35/39
MGS 2015, 7-11 April, University of Sheffield, UK 35/39
MGS 2015, 7-11 April, University of Sheffield, UK 35/39
MGS 2015, 7-11 April, University of Sheffield, UK 36/39
def
def
def
def
i+1
MGS 2015, 7-11 April, University of Sheffield, UK 36/39
def
i+ 1
i
MGS 2015, 7-11 April, University of Sheffield, UK 36/39
MGS 2015, 7-11 April, University of Sheffield, UK 37/39
MGS 2015, 7-11 April, University of Sheffield, UK 37/39
MGS 2015, 7-11 April, University of Sheffield, UK 37/39
MGS 2015, 7-11 April, University of Sheffield, UK 37/39
MGS 2015, 7-11 April, University of Sheffield, UK 37/39
MGS 2015, 7-11 April, University of Sheffield, UK 37/39
MGS 2015, 7-11 April, University of Sheffield, UK 38/39
◮ 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
◮ 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 2015, 7-11 April, University of Sheffield, UK 39/39