open import Cat.Functor.FullSubcategory
open import Cat.Diagram.Initial
open import Cat.Instances.Comma
open import Cat.Instances.Slice
open import Cat.Prelude

import Cat.Reasoning

module Cat.Diagram.Image where

module _ {o β} (C : Precategory o β) where
open Cat.Reasoning C
open Initial
open βObj
open βHom
open /-Obj
open /-Hom

private variable
a b : Ob
β' : Level


# Imagesπ

Let be an ordinary function between sets (or, indeed, arbitrary types). Its image can be computed as the subset but this description does not carry over to more general categories: More abstractly, we can say that the image embeds into and admits a map from (in material set theory, this is itself β structurally, it is called the corestriction of Furthermore, these two maps factor in that:

While these are indeed two necessary properties of an image, they fail to accurately represent the set-theoretic construction: Observe that, e.g.Β for we could take taking itself and This factoring clearly recovers as But by taking this as the image, weβve lost the information that lands in the evens!

We can refine the abstract definition by saying that, for a mono to be the image of it must be the smallest subobject of through which factors β given any other factoring of we must have in the proset of subobjects of i.e.Β there exists some such that

In general categories, monomorphisms of may be the wrong notion of βsubobjectβ to use. For example, in topology, weβd rather talk about the image which admits a subspace inclusion onto We may expand the definition above to work for an arbitrary subclass of the monomorphisms of by requiring that the of be the smallest through which factors.

Since keeping track of all the factorisations by hand would be fiddly, we formalise the idea of image here using comma categories, namely the idea of universal morphisms as in the construction of adjoints. Fix a morphism and consider it as an object of the slice category

For a given subclass of monomorphisms there is a full subcategory of spanned by those maps in β let us call it β admitting an evident fully faithful inclusion An of is a universal morphism from to

  Class-of-monos : β β β Type _
Class-of-monos β =
Ξ£[ M β (β {a b} β Hom a b β Type β) ]
(β {a b} {f : Hom a b} β M f β is-monic f)

M-image : β {a b} β Class-of-monos β' β Hom a b β Type _
M-image {a = a} {b} M f = Universal-morphism
(Forget-full-subcat
{C = Slice C b}
{P = (Ξ» o β M .fst (o .map))}) (cut f)


The image is the for = the class of all monomorphisms.

  Image : β {a b} β Hom a b β Type _
Image {b = b} f = Universal-morphism
(Forget-full-subcat {C = Slice C b} {P = is-monic β map})
(cut f)


## Friendly interfaceπ

Since this definition is incredibly abstract and indirect, we provide a very thin wrapper module over M-image which unpacks the definition into friendlier terms.

  module M-Image {a b} {M : Class-of-monos β'} {f : Hom a b} (im : M-image M f) where


The first thing to notice is that, being an initial object in the comma category we have an object β is the image object, and is the inclusion map:

    Im : Ob
Im = im .bot .y .fst .domain

Imβcodomain : Hom Im b
Imβcodomain = im .bot .y .fst .map


Furthermore, this map is both an inclusion (since is a class of monomorphisms), and an at that:

    Imβcodomain-is-M : M .fst Imβcodomain
Imβcodomain-is-M = im .bot .y .snd

Imβcodomain-is-monic : is-monic Imβcodomain
Imβcodomain-is-monic = M .snd Imβcodomain-is-M


So far, weβve been looking at the βcodomainβ part of the object in the comma category. We also have the βmorphismβ part, which provides our (universal) factoring of

    corestrict : Hom a Im
corestrict = im .bot .map .map

image-factors : Imβcodomain β corestrict β‘ f
image-factors = im .bot .map .commutes


This is also the smallest factorisation, which takes quite a lot of data to express. Letβs see it:

Suppose we have

• Some other object and,
• An and,
• A corestriction map such that

Then we have a map (written imβ€other-image in the code below), and the canonical inclusion factors through

    universal
: β {c} (m : Hom c b) (M-m : M .fst m) (i : Hom a c)
β m β i β‘ f
β Hom Im c
universal m M i p = im .hasβ₯ obj .centre .Ξ² .map where
obj : βObj _ _
obj .x = tt
obj .y = cut m , M
obj .map = record { map = i ; commutes = p }

universal-factors
: β {c} {m : Hom c b} {M : M .fst m} {i : Hom a c}
β {p : m β i β‘ f}
β m β universal m M i p β‘ Imβcodomain
universal-factors {m = m} {M} {i} {p} = im .hasβ₯ _ .centre .Ξ² .commutes

universal-commutes
: β {c} {m : Hom c b} {M : M .fst m} {i : Hom a c}
β {p : m β i β‘ f}
β universal m M i p β corestrict β‘ i
universal-commutes {m = m} {ism} {i} {p} =
M .snd ism _ _ (pulll universal-factors Β·Β· image-factors Β·Β· sym p)

  module Image {a b} {f : Hom a b} (im : Image f) = M-Image {M = is-monic , Ξ» x β x} im