module Cat.Diagram.Colimit.Coproduct {o h} (C : Precategory o h) where

Coproducts are colimitsπŸ”—

We first establish the correspondence between binary coproducts and colimits over the functor out of which maps to and to dualising products as limits.

is-coproduct→is-colimit
  : βˆ€ {x} {F : Functor 2-object-category C} {eta : F => Const x}
  β†’ is-coproduct C (eta .Ξ· true) (eta .Ξ· false)
  β†’ is-colimit {C = C} F x eta
is-coproduct→is-colimit {x = x} {F} {eta} coprod =
  to-is-colimitp mc Ξ» where
    {true} β†’ refl
    {false} β†’ refl
  where
    module coprod = is-coproduct coprod
    open make-is-colimit

    mc : make-is-colimit F x
    mc .ψ j = eta .η j
    mc .commutes f = eta .is-natural _ _ _ βˆ™ idl _
    mc .universal eta _ = coprod.[ eta true , eta false ]
    mc .factors {true} eta _ = coprod.[]βˆ˜ΞΉβ‚
    mc .factors {false} eta _ = coprod.[]βˆ˜ΞΉβ‚‚
    mc .unique eta p other q = coprod.unique (q true) (q false)

is-colimit→is-coproduct
  : βˆ€ {a b} {K : Functor ⊀Cat C}
  β†’ {eta : 2-object-diagram a b => K F∘ !F}
  β†’ is-lan !F (2-object-diagram a b) K eta
  β†’ is-coproduct C (eta .Ξ· true) (eta .Ξ· false)
is-colimit→is-coproduct {a} {b} {K} {eta} colim = coprod where
  module colim = is-colimit colim

  D : Functor 2-object-category C
  D = 2-object-diagram a b

  copair
    : βˆ€ {y} β†’ Hom a y β†’ Hom b y
    β†’ βˆ€ (j : Bool) β†’ Hom (D .Fβ‚€ j) y
  copair p1 p2 true = p1
  copair p1 p2 false = p2

  copair-commutes
    : βˆ€ {y} {p1 : Hom a y} {p2 : Hom b y}
    β†’ {i j : Bool}
    β†’ (p : i ≑ j)
    β†’ copair p1 p2 j ∘ D .F₁ p ≑ copair p1 p2 i
  copair-commutes {p1 = p1} {p2 = p2} =
      J (Ξ» _ p β†’ copair p1 p2 _ ∘ D .F₁ p ≑ copair p1 p2 _)
        (elimr (D .F-id))

  coprod : is-coproduct C (eta .Ξ· true) (eta .Ξ· false)
  coprod .[_,_] f g = colim.universal (copair f g) copair-commutes
  coprod .[]βˆ˜ΞΉβ‚ {_} {p1'} {p2'} = colim.factors (copair p1' p2') copair-commutes
  coprod .[]βˆ˜ΞΉβ‚‚ {_} {p1'} {p2'} = colim.factors (copair p1' p2') copair-commutes
  coprod .unique p q = colim.unique _ _ _ Ξ» where
    true β†’ p
    false β†’ q

Coproductβ†’Colimit : βˆ€ {F : Functor 2-object-category C} β†’ Coproduct C (F # true) (F # false) β†’ Colimit F
Coproduct→Colimit coprod = to-colimit (is-coproduct→is-colimit {eta = 2-object-nat-trans _ _} (has-is-coproduct coprod))

Colimitβ†’Coproduct : βˆ€ {a b} β†’ Colimit (2-object-diagram a b) β†’ Coproduct C a b
Colimit→Coproduct colim .coapex = Colimit.coapex colim
Colimitβ†’Coproduct colim .ι₁ = Colimit.cocone colim .Ξ· true
Colimit→Coproduct colim .ι₂ = Colimit.cocone colim .η false
Colimit→Coproduct colim .has-is-coproduct =
  is-colimit→is-coproduct (Colimit.has-colimit colim)

Indexed coproducts as colimitsπŸ”—

Similarly to the product case, when is a groupoid, indexed coproducts correspond to colimits of discrete diagrams of shape

module _ {I : Type β„“'} (i-is-grpd : is-groupoid I) (F : I β†’ Ob) where
  open _=>_

  Injβ†’Cocone : βˆ€ {x} β†’ (βˆ€ i β†’ Hom (F i) x)
             β†’ Disc-adjunct {C = C} {iss = i-is-grpd} F => Const x
  Inj→Cocone inj .η i = inj i
  Inj→Cocone inj .is-natural i j p =
    J (Ξ» j p β†’ inj j ∘ subst (Hom (F i) βŠ™ F) p id ≑ id ∘ inj i)
      (elimr (transport-refl id) βˆ™ sym (idl _)) p

  is-indexed-coproduct→is-colimit
    : βˆ€ {x} {inj : βˆ€ i β†’ Hom (F i) x}
    β†’ is-indexed-coproduct C F inj
    → is-colimit (Disc-adjunct F) x (Inj→Cocone inj)
  is-indexed-coproduct→is-colimit {x = x} {inj} ic =
    to-is-colimitp mc refl
    where
      module ic = is-indexed-coproduct ic
      open make-is-colimit

      mc : make-is-colimit (Disc-adjunct F) x
      mc .ψ i = inj i
      mc .commutes {i} {j} p =
        J (Ξ» j p β†’ inj j ∘ subst (Hom (F i) βŠ™ F) p id ≑ inj i)
          (elimr (transport-refl id))
          p
      mc .universal eta p = ic.match eta
      mc .factors eta p = ic.commute
      mc .unique eta p other q = ic.unique eta q

  is-colimit→is-indexed-coprduct
    : βˆ€ {K : Functor ⊀Cat C}
    β†’ {eta : Disc-adjunct {iss = i-is-grpd} F => K F∘ !F}
    β†’ is-lan !F (Disc-adjunct F) K eta
    β†’ is-indexed-coproduct C F (eta .Ξ·)
  is-colimit→is-indexed-coprduct {K = K} {eta} colim = ic where
    module colim = is-colimit colim
    open is-indexed-coproduct hiding (eta)

    ic : is-indexed-coproduct C F (eta .Ξ·)
    ic .match k =
      colim.universal k
        (J (Ξ» j p β†’ k j ∘ subst (Hom (F _) βŠ™ F) p id ≑ k _)
           (elimr (transport-refl _)))
    ic .commute =
      colim.factors _ _
    ic .unique k comm =
      colim.unique _ _ _ comm

  IC→Colimit
    : Indexed-coproduct C F
    β†’ Colimit {C = C} (Disc-adjunct {iss = i-is-grpd} F)
  IC→Colimit ic =
    to-colimit (is-indexed-coproduct→is-colimit has-is-ic)
    where open Indexed-coproduct ic

  Colimit→IC
    : Colimit {C = C} (Disc-adjunct {iss = i-is-grpd} F)
    β†’ Indexed-coproduct C F
  Colimit→IC colim .Indexed-coproduct.ΣF = _
  Colimit→IC colim .Indexed-coproduct.ι = _
  Colimit→IC colim .Indexed-coproduct.has-is-ic =
    is-colimit→is-indexed-coprduct (Colimit.has-colimit colim)