module Cat.Instances.Coalgebras.Cartesian
  {o } {C : Precategory o } {F : Functor C C} (W : Comonad-on F)
  (fc : Finitely-complete C) (lex : is-lex F)
  where

Finite limits in categories of coalgebras🔗

If is an arbitrary comonad on a category there’s not much we can say about general limits in the category of -coalgebras. Indeed, precisely dualising the case for categories of algebras over a monad, where limits are inherited from the base category but colimits are onerous, for colimits come easily but limits are onerous. However, if preserves a certain class of limits, then the forgetful functor preserves and reflects those same limits.

In this module, we’re interested in the specific case where is a left exact functor, i.e., it preserves finite limits. Accordingly, will have all finite limits, and they will be computed as in The more general computation can be found in Cat.Instances.Coalgebras.Limits.

We start by showing that reflects pullbacks, since that’s what we’ll use to construct pullbacks in

  is-pullback-coalgebra
    :  {(P , π) : Coalgebras.Ob W}
        {π₁ : Coalgebras.Hom W (P , π) (A , α')}
        {π₂ : Coalgebras.Hom W (P , π) (B , β')}
     is-pullback C (π₁ .hom) (f .hom) (π₂ .hom) (g .hom)
     is-pullback (Coalgebras W) π₁ f π₂ g
  is-pullback-coalgebra {P , π'} {π₁} {π₂} pb = pb' where

To be precise, we’re showing that, if a square

is sent by to a pullback in it must already have been a pullback in

Since preserves pullbacks, is a pullback as well. If we are given a coalgebra together with a span of homomorphisms

satisfying hence also there is a unique factorisation

which we can compose with the counit to give a morphism satisfying and as shown in the formalisation below.

      abstract
        wit' : W₁ (f .hom)  α  p1 .hom  W₁ (g .hom)  β  p2 .hom
        wit' = W₁ (f .hom)  α  p1 .hom   ≡⟨ pulll (f .preserves) 
               (ξ  f .hom)  p1 .hom      ≡⟨ pullr wit 
               ξ  g .hom  p2 .hom        ≡⟨ extendl (sym (g .preserves)) 
               W₁ (g .hom)  β  p2 .hom   

      ν : Hom Q P
      ν = counit.ε _  p'.universal wit'

      abstract
        comm₁ : π₁ .hom  ν  p1 .hom
        comm₁ =
          π₁ .hom  ν                                    ≡⟨ pulll (sym (counit.is-natural _ _ _)) 
          (counit.ε _  W₁ (π₁ .hom))  p'.universal _  ≡⟨ pullr p'.p₁∘universal 
          counit.ε _  α  p1 .hom                       ≡⟨ cancell α.ρ-counit 
          p1 .hom                                        

Since equality of morphisms in is entirely tested downstairs in if extends to a coalgebra homomorphism, then it is precisely the factorisation we’re seeking for the square to be a pullback in That’s because, since it’s induced by the universal property of as a pullback, it automatically satisfies the commutativity and uniqueness requirements.

It therefore remains to show that is Since these are both maps into a pullback, namely we can do so componentwise. Therefore, we calculate

      step₁ : W₁ (π₁ .hom)  W₁ ν  χ  α  p1 .hom
      step₁ =
        W₁ (π₁ .hom)  W₁ ν  χ                    ≡⟨ pulll (W.weave (pulll (sym (counit.is-natural _ _ _))  pullr p'.p₁∘universal)) 
        (W₁ (counit.ε _)  W₁ (α  p1 .hom))  χ   ≡⟨ pullr (ap₂ _∘_ (W-∘ _ _) refl  pullr (p1 .preserves)) 
        W₁ (counit.ε _)  W₁ α  α  p1 .hom       ≡⟨ W.cancell α.ρ-counit 
        α  p1 .hom                                

and

      step₂ : W₁ (π₁ .hom)  π  ν  α  p1 .hom
      step₂ = W₁ (π₁ .hom)  π  ν ≡⟨ pulll (π₁ .preserves) 
              (α  π₁ .hom)  ν    ≡⟨ pullr comm₁ 
              α  p1 .hom          

with very similar, but symmetric, proofs for the second projection — so was indeed the map we were looking for!

    pb' : is-pullback (Coalgebras W) π₁ f π₂ g
    pb' .square = ext p.square
    pb' .universal {p₁' = p₁'} {p₂'} x = factor p₁' p₂' (ap hom x)
    pb' .p₁∘universal {p₁' = p₁'} {p₂'} {p} = ext $ comm₁ p₁' p₂' (ap hom p)
    pb' .p₂∘universal {p₁' = p₁'} {p₂'} {p} = ext $ comm₂ p₁' p₂' (ap hom p)
    pb' .unique {p₁' = p₁'} {p₂'} {p} q r = ext $ p.unique₂
      {p = ap hom p} (ap hom q) (ap hom r)
      (comm₁ p₁' p₂' (ap hom p)) (comm₂ p₁' p₂' (ap hom p))
  Coalgebra-on-pullback
    : (p : Pullback C (f .hom) (g .hom))
     Coalgebra-on W (Pullback.apex p)
  Coalgebra-on-pullback p = coalg where

Suppose now that we have a pullback

and we want to equip with a structure. We must come up with a map but since preserves pullbacks, it will suffice to come up with a map Since that is a pullback, we can write such a map as given and as long as we have

We define (resp. to be the composite (resp. and a short calculation shows that this indeed satisfies the aforementioned compatibility condition.

    abstract
      wit : W₁ (f .hom)  α  p.p₁  W₁ (g .hom)  β  p.p₂
      wit = W₁ (f .hom)  α  p.p₁  ≡⟨ pulll (f .preserves) 
            (ξ  f .hom)  p.p₁     ≡⟨ pullr p.square 
            ξ  g .hom  p.p₂       ≡⟨ extendl (sym (g .preserves)) 
            W₁ (g .hom)  β  p.p₂  

    coalg : Coalgebra-on W p.apex
    coalg .ρ = p'.universal wit

It remains to show that this factorisation is compatible with counit and comultiplication. We start with the former: we must show that is the identity. Since equality of maps into pullbacks is determined by their composition with the projections, it will suffice to show that

is and respectively for but we can calculate

where the first step is by naturality, the second is computation, and the third is because is a To show compatibility with the comultiplication, we perform a similar calculation: it will suffice to show that

and

are both In the former case this is immediate, but in the latter case it requires naturality of and compatibility of with the comultiplication:

Since putting the above paragraphs together into an actual formalised proof is a bit annoying, it’s hidden in this <details> tag.
    coalg .ρ-counit =
      p.unique₂
        {p = pulll (sym (counit.is-natural _ _ _))
          ·· pullr wit
          ·· extendl (counit.is-natural _ _ _)}
        (pulll (sym (counit.is-natural _ _ _))  pullr p'.p₁∘universal)
        (pulll (sym (counit.is-natural _ _ _))  pullr p'.p₂∘universal)
        (idr _  sym (cancell α.ρ-counit))
        (idr _  sym (cancell β.ρ-counit))
    coalg .ρ-comult =
      is-pullback.unique₂ rem₂
        {p = W.extendl (f .preserves)
          ·· ap₂ _∘_ refl wit
          ·· W.extendl (sym (g .preserves))}
        (pulll (W.weave p'.p₁∘universal)  pullr p'.p₁∘universal)
        (pulll (W.weave p'.p₂∘universal)  pullr p'.p₂∘universal)
        (pulll (sym (comult.is-natural _ _ _)) ·· pullr p'.p₁∘universal ·· extendl (sym α.ρ-comult))
        (  pulll (sym (comult.is-natural _ _ _))
        ·· pullr p'.p₂∘universal
        ·· extendl (sym β.ρ-comult))
Pullback-coalgebra
  : {(A , α) (B , β) (X , ξ) : Coalgebras.Ob W}
    (f : Coalgebras.Hom W (A , α) (X , ξ))
    (g : Coalgebras.Hom W (B , β) (X , ξ))
   Pullback (Coalgebras W) f g

The case of the terminal object is infinitely simpler: since preserves the terminal object, we have We equip it with its (necessarily unique) cofree coalgebra structure, and since there is an isomorphism

the former is contractible if the latter is.

Terminal-coalgebra : Terminal (Coalgebras W)
Terminal-coalgebra .top = _
Terminal-coalgebra .has⊤ (A , α) = Equiv→is-hlevel 0
  (Equiv.inverse (_ , L-adjunct-is-equiv (Forget⊣Cofree W)))
  (terminal .has⊤ A)

Since we have a terminal object and pullbacks, we have arbitrary finite limits, too.

Coalgebras-finitely-complete : Finitely-complete (Coalgebras W)
Coalgebras-finitely-complete = with-pullbacks (Coalgebras W)
  Terminal-coalgebra
  Pullback-coalgebra