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 .ι₁ = inlᵖ
Posets-has-coproducts P Q .ι₂ = inrᵖ
Posets-has-coproducts P Q .has-is-coproduct .is-coproduct.[_,_] = matchᵖ
Posets-has-coproducts P Q .has-is-coproduct .[]∘ι₁ = trivial!
Posets-has-coproducts P Q .has-is-coproduct .[]∘ι₂ = trivial!
Posets-has-coproducts P Q .has-is-coproduct .unique α β = 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 λ ()