module Order.Instances.Coproduct where

Coproducts of posetsπŸ”—

If we’re given two partially ordered sets then there is a universal way of equipping their coproduct (at the level of sets) with a partial order, which results in the categorical coproduct in the category

The ordering is defined by recursion, and it’s uniquely specified by saying that it is the coproduct of orders, and that each coprojection is an order embedding. We compute:

    sum-≀ : ⌞ P ⌟ ⊎ ⌞ Q ⌟ β†’ ⌞ P ⌟ ⊎ ⌞ Q ⌟ β†’ Type (β„“ βŠ” β„“')
    sum-≀ (inl x) (inl y) = Lift β„“' (x P.≀ y)
    sum-≀ (inl x) (inr y) = Lift _ βŠ₯
    sum-≀ (inr x) (inl y) = Lift _ βŠ₯
    sum-≀ (inr x) (inr y) = Lift β„“ (x Q.≀ y)
A very straightforward case-bash shows that this is actually a partial order. After we’ve established that everything is in a particular summand, each obligation is something we inherit from the underlying orders and
    abstract
      sum-≀-thin : βˆ€ {x y} β†’ is-prop (sum-≀ x y)
      sum-≀-thin {inl x} {inl y} = hlevel 1
      sum-≀-thin {inr x} {inr y} = hlevel 1

      sum-≀-refl : βˆ€ {x} β†’ sum-≀ x x
      sum-≀-refl {inl x} = lift P.≀-refl
      sum-≀-refl {inr x} = lift Q.≀-refl

      sum-≀-trans : βˆ€ {x y z} β†’ sum-≀ x y β†’ sum-≀ y z β†’ sum-≀ x z
      sum-≀-trans {inl x} {inl y} {inl z} (lift p) (lift q) = lift (P.≀-trans p q)
      sum-≀-trans {inr x} {inr y} {inr z} (lift p) (lift q) = lift (Q.≀-trans p q)

      sum-≀-antisym : βˆ€ {x y} β†’ sum-≀ x y β†’ sum-≀ y x β†’ x ≑ y
      sum-≀-antisym {inl x} {inl y} (lift p) (lift q) = ap inl (P.≀-antisym p q)
      sum-≀-antisym {inr x} {inr y} (lift p) (lift q) = ap inr (Q.≀-antisym p q)
  _βŠŽα΅–_ : Poset (o βŠ” o') (β„“ βŠ” β„“')
  _βŠŽα΅–_ .Poset.Ob        = P.Ob ⊎ Q.Ob
  _βŠŽα΅–_ .Poset._≀_       = sum-≀
  _βŠŽα΅–_ .Poset.≀-thin    = sum-≀-thin
  _βŠŽα΅–_ .Poset.≀-refl    = sum-≀-refl
  _βŠŽα΅–_ .Poset.≀-trans   = sum-≀-trans
  _βŠŽα΅–_ .Poset.≀-antisym = sum-≀-antisym

  infixr 15 _βŠŽα΅–_

As usual, we have two (monotone) coprojections and and, if we have maps and we can define a map out of the coproduct by cases:

  inlα΅– : Monotone P (P βŠŽα΅– Q)
  inlα΅– .hom        = inl
  inlα΅– .pres-≀ x≀y = lift x≀y

  inrα΅– : Monotone Q (P βŠŽα΅– Q)
  inrα΅– .hom        = inr
  inrα΅– .pres-≀ x≀y = lift x≀y

  matchα΅– : βˆ€ {o β„“} {R : Poset o β„“} β†’ Monotone P R β†’ Monotone Q R β†’ Monotone (P βŠŽα΅– Q) R
  matchα΅– f g .hom (inl x) = f # x
  matchα΅– f g .hom (inr x) = g # x
  matchα΅– f g .pres-≀ {inl x} {inl y} (lift Ξ±) = f .pres-≀ Ξ±
  matchα΅– f g .pres-≀ {inr x} {inr y} (lift Ξ²) = g .pres-≀ Ξ²

A straightforward calculation shows that this really is the coproduct in

Posets-has-coproducts : βˆ€ {o β„“} β†’ has-coproducts (Posets o β„“)
Posets-has-coproducts P Q .coapex = P βŠŽα΅– Q
Posets-has-coproducts P Q .inβ‚€ = inlα΅–
Posets-has-coproducts P Q .in₁ = inrα΅–
Posets-has-coproducts P Q .has-is-coproduct .is-coproduct.[_,_] = matchα΅–
Posets-has-coproducts P Q .has-is-coproduct .inβ‚€βˆ˜factor = trivial!
Posets-has-coproducts P Q .has-is-coproduct .inβ‚βˆ˜factor = trivial!
Posets-has-coproducts P Q .has-is-coproduct .unique other Ξ± Ξ² = ext Ξ» where
  (inl x) β†’ Ξ± #β‚š x
  (inr x) β†’ Ξ² #β‚š x

As a related fact, we can show that the empty poset is the initial object in

Posets-initial : βˆ€ {o β„“} β†’ Initial (Posets o β„“)
Posets-initial .bot = πŸ˜α΅–
Posets-initial .hasβŠ₯ P .centre .hom    ()
Posets-initial .hasβŠ₯ P .centre .pres-≀ ()
Posets-initial .hasβŠ₯ P .paths f = ext Ξ» ()