open import Cat.Instances.Elements.Properties
open import Cat.Instances.Presheaf.Colimits
open import Cat.Functor.Adjoint.Continuous
open import Cat.Functor.Adjoint.Reflective
open import Cat.Diagram.Coproduct.Copower
open import Cat.Diagram.Coproduct.Indexed
open import Cat.Instances.Presheaf.Limits
open import Cat.Diagram.Colimit.Terminal
open import Cat.Instances.Shape.Terminal
open import Cat.Functor.Adjoint.Colimit
open import Cat.Instances.Sets.Complete
open import Cat.Diagram.Colimit.Base
open import Cat.Functor.Hom.Coyoneda
open import Cat.Functor.Equivalence
open import Cat.Functor.Kan.Adjoint
open import Cat.Functor.Hom.Yoneda
open import Cat.Functor.Kan.Unique
open import Cat.Instances.Discrete
open import Cat.Instances.Elements
open import Cat.Instances.Functor
open import Cat.Diagram.Terminal
open import Cat.Functor.Constant
open import Cat.Diagram.Initial
open import Cat.Functor.Adjoint
open import Cat.Functor.Compose
open import Cat.Functor.Final
open import Cat.Functor.Base
open import Cat.Prelude hiding (J)

import Cat.Diagram.Colimit.Coproduct
import Cat.Functor.Reasoning
import Cat.Morphism
module Cat.Total {o β„“} (C : Precategory o β„“) where
open import Cat.Functor.Hom C
private
  open module C = Precategory C
  variable
    o' β„“' : Level
    E : Precategory o' β„“'
    J : Precategory o' β„“'

Total precategoriesπŸ”—

A precategory is total if its Yoneda embedding has a left adjoint. We call this adjoint さ(sa), a reading for ε·¦, which means β€œleft”.

record is-total : Type (o βŠ” lsuc β„“) where
  field
    {さ} : Functor Cat[ C ^op , Sets β„“ ] C
    has-γ‚ˆ-adj : さ ⊣ γ‚ˆ
  open module さ = Cat.Functor.Reasoning さ using () renaming
    (Fβ‚€ to さ₀; F₁ to さ₁) public

MotivationπŸ”—

Total categories represent a particularly nice site in which to do logic, as they are a reflective subcategory of their category of presheaves. In particular, total categories are cocomplete with many useful limits. However, a category being total is a slightly weaker requirement than a category being a topos, as all topoi are both total and cototal.

Free objects relative to γ‚ˆπŸ”—

Before we investigate the properties of a total category, it’s worth considering the action of such a functor on objects, if it exists. Given some presheaf an object could be if it is free with respect to

module _ (F : Functor (C ^op) (Sets β„“)) (c : Free-object γ‚ˆ F) where
  open Free-object c
  private

Since is a presheaf, it can be written as a colimit of representable functors by the coyoneda lemma.

    F-is-colimit : is-colimit (γ‚ˆ F∘ Ο€β‚š C F) F _
    F-is-colimit = coyoneda _ F

As left adjoints preserve colimits, we can imagine that a partial left adjoint (a free object) of a colimit should also be a colimit. Indeed this is true as is fully faithful.

We call a free object with respect to a realising object for

  free-is-colimit : is-colimit (Ο€β‚š C F) free _
  free-is-colimit =
    free-objectβ†’is-colimit γ‚ˆ γ‚ˆ-is-fully-faithful (to-colimit F-is-colimit) c
module Total (C-total : is-total) where
  open module C-total = is-total C-total public
  open Cat.Morphism C public

  γ•βˆ˜γ‚ˆβ‰…βΏid : さ F∘ γ‚ˆ ≅ⁿ Id
  γ•βˆ˜γ‚ˆβ‰…βΏid = is-reflectiveβ†’counit-iso has-γ‚ˆ-adj γ‚ˆ-is-fully-faithful

  private
    γ•βˆ˜γ‚ˆβˆ˜F≅ⁿF : βˆ€ {F : Functor J C} β†’ さ F∘ γ‚ˆ F∘ F ≅ⁿ F
    γ•βˆ˜γ‚ˆβˆ˜F≅ⁿF = ni-assoc βˆ™ni (γ•βˆ˜γ‚ˆβ‰…βΏid β—‚ni _) βˆ™ni pathβ†’iso F∘-idl

さ on valuesπŸ”—

For each yields a free value on relative to As we have proved, this is a colimit.

  さ₀-is-colimit : (F : ⌞ PSh β„“ C ⌟) β†’ is-colimit (Ο€β‚š C F) (さ₀ F) _
  さ₀-is-colimit F = free-is-colimit F $ left-adjointβ†’free-objects has-γ‚ˆ-adj F

CocompletenessπŸ”—

Thus, all total categories are cocomplete as their colimits can be computed in

  cocomplete : is-cocomplete β„“ β„“ C
  cocomplete F = natural-isoβ†’colimit γ•βˆ˜γ‚ˆβˆ˜F≅ⁿF
    $ left-adjoint-colimit has-γ‚ˆ-adj
    $ PSh-cocomplete β„“ C (γ‚ˆ F∘ F)

Terminal objectπŸ”—

Total categories also have many limits. For example, the terminal presheaf has a realisation in Furthermore, the projection functor from the category of elements of the terminal presheaf is an equivalence. A colimit of an equivalence is equivalent to a colimit of the identityβ€”i.e., a terminal object.

  β˜… : C.Ob
  β˜… = さ.β‚€ (⊀PSh _ _)

  private
    β˜…-is-colimit-id : is-colimit (Id {C = C}) β˜… _
    β˜…-is-colimit-id = extend-is-colimit _
      (right-adjoint-is-final (elements-terminal-is-equivalence.F⁻¹⊣F {s = β„“})) _
      col' where
        open is-equivalence
        col : is-colimit (Ο€β‚š C $ ⊀PSh _ _) β˜… _
        col = さ₀-is-colimit _

        col' : is-colimit (Id F∘ Ο€β‚š C (⊀PSh _ _)) β˜… _
        col' = natural-iso-ext→is-lan
          (left-adjoint-is-cocontinuous (Id-is-equivalence .F⊣F⁻¹) col)
          (!const-isoⁿ id-iso)

  total-terminal : Terminal C
  total-terminal = Id-colimitβ†’Terminal $ to-colimit β˜…-is-colimit-id
  module total-terminal = Terminal total-terminal

CopowersπŸ”—

As C is cocomplete, it has all set-indexed coproducts and is thus copowered.

  open Cat.Diagram.Colimit.Coproduct C
  has-set-indexed-coproducts : (S : Set β„“) β†’ has-coproducts-indexed-by C ∣ S ∣
  has-set-indexed-coproducts S F = Colimit→IC F (cocomplete $ Disc-adjunct F)
  open Copowers has-set-indexed-coproducts public
  open Consts total-terminal has-set-indexed-coproducts public