module Cat.Diagram.Coproduct.Indexed {o β„“} (C : Precategory o β„“) where

Indexed coproductsπŸ”—

Indexed coproducts are the dual notion to indexed products, so see there for motivation and exposition.

record is-indexed-coproduct (F : Idx β†’ C.Ob) (ΞΉ : βˆ€ i β†’ C.Hom (F i) S)
  : Type (o βŠ” β„“ βŠ” level-of Idx) where
  no-eta-equality
  field
    match   : βˆ€ {Y} β†’ (βˆ€ i β†’ C.Hom (F i) Y) β†’ C.Hom S Y
    commute : βˆ€ {i} {Y} {f : βˆ€ i β†’ C.Hom (F i) Y} β†’ match f C.∘ ΞΉ i ≑ f i
    unique  : βˆ€ {Y} {h : C.Hom S Y} (f : βˆ€ i β†’ C.Hom (F i) Y)
            β†’ (βˆ€ i β†’ h C.∘ ΞΉ i ≑ f i)
            β†’ h ≑ match f

  eta : βˆ€ {Y} (h : C.Hom S Y) β†’ h ≑ match (Ξ» i β†’ h C.∘ ΞΉ i)
  eta h = unique _ Ξ» _ β†’ refl

  hom-iso : βˆ€ {Y} β†’ C.Hom S Y ≃ (βˆ€ i β†’ C.Hom (F i) Y)
  hom-iso = (Ξ» z i β†’ z C.∘ ΞΉ i) , is-isoβ†’is-equiv Ξ» where
    .is-iso.inv β†’ match
    .is-iso.rinv x β†’ funext Ξ» i β†’ commute
    .is-iso.linv x β†’ sym (unique _ Ξ» _ β†’ refl)

A category C\mathcal{C} admits indexed coproducts (of level ℓ\ell) if, for any type I:Type ℓI : \mathrm{Type}\ \ell and family F:I→CF : I \to \mathcal{C}, there is an indexed coproduct of FF.

record Indexed-coproduct (F : Idx β†’ C.Ob) : Type (o βŠ” β„“ βŠ” level-of Idx) where
  no-eta-equality
  field
    {Ξ£F}      : C.Ob
    ΞΉ         : βˆ€ i β†’ C.Hom (F i) Ξ£F
    has-is-ic : is-indexed-coproduct F ΞΉ
  open is-indexed-coproduct has-is-ic public

has-indexed-coproducts : βˆ€ β„“ β†’ Type _
has-indexed-coproducts β„“ = βˆ€ {I : Type β„“} (F : I β†’ C.Ob) β†’ Indexed-coproduct F

As colimitsπŸ”—

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

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

  Injβ†’Cocone : βˆ€ {x} β†’ (βˆ€ i β†’ C.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 C.∘ subst (C.Hom (F i) βŠ™ F) p C.id ≑ C.id C.∘ inj i)
      (C.elimr (transport-refl C.id) βˆ™ sym (C.idl _)) p

  is-indexed-coproduct→is-colimit
    : βˆ€ {x} {inj : βˆ€ i β†’ C.Hom (F i) x}
    β†’ is-indexed-coproduct 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 C.∘ subst (C.Hom (F i) βŠ™ F) p C.id ≑ inj i)
          (C.elimr (transport-refl C.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}
    β†’ {eps : Disc-adjunct {iss = i-is-grpd} F => K F∘ !F}
    β†’ is-lan !F (Disc-adjunct F) K eps
    β†’ is-indexed-coproduct F (eps .Ξ·)
  is-colimit→is-indexed-coprduct {K = K} {eps} colim = ic where
    module colim = is-colimit colim
    open is-indexed-coproduct

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

  IC→Colimit
    : Indexed-coproduct 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 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)

Disjoint coproductsπŸ”—

An indexed coproduct βˆ‘F\sum F is said to be disjoint if every one of its inclusions Fiβ†’βˆ‘FF_i \to \sum F is monic, and, for unequal iβ‰ ji \ne j, the square below is a pullback with initial apex. Since the maps Fiβ†’βˆ‘F←FjF_i \to \sum F \leftarrow F_j are monic, the pullback below computes the intersection of FiF_i and FjF_j as subobjects of βˆ‘F\sum F, hence the name disjoint coproduct: If βŠ₯\bot is an initial object, then Fi∩Fj=βˆ…F_i \cap F_j = \emptyset.

record is-disjoint-coproduct (F : Idx β†’ C.Ob) (ΞΉ : βˆ€ i β†’ C.Hom (F i) S)
  : Type (o βŠ” β„“ βŠ” level-of Idx) where
  field
    is-coproduct         : is-indexed-coproduct F ΞΉ
    injections-are-monic : βˆ€ i β†’ C.is-monic (ΞΉ i)
    summands-intersect   : βˆ€ i j β†’ Pullback C (ΞΉ i) (ΞΉ j)
    different-images-are-disjoint
      : βˆ€ i j β†’ Β¬ i ≑ j β†’ is-initial C (summands-intersect i j .Pullback.apex)

Initial objects are disjointπŸ”—

We prove that if βŠ₯\bot is an initial object, then it is also an indexed coproduct β€” for any family βŠ₯β†’C\bot \to \mathcal{C} β€” and furthermore, it is a disjoint coproduct.

is-initial→is-disjoint-coproduct
  : βˆ€ {βˆ…} {F : βŠ₯ β†’ C.Ob} {i : βˆ€ i β†’ C.Hom (F i) βˆ…}
  β†’ is-initial C βˆ…
  β†’ is-disjoint-coproduct F i
is-initial→is-disjoint-coproduct {F = F} {i = i} init = is-disjoint where
  open is-indexed-coproduct
  is-coprod : is-indexed-coproduct F i
  is-coprod .match _ = init _ .centre
  is-coprod .commute {i = i} = absurd i
  is-coprod .unique {h = h} f p i = init _ .paths h (~ i)

  open is-disjoint-coproduct
  is-disjoint : is-disjoint-coproduct F i
  is-disjoint .is-coproduct = is-coprod
  is-disjoint .injections-are-monic i = absurd i
  is-disjoint .summands-intersect i j = absurd i
  is-disjoint .different-images-are-disjoint i j p = absurd i