Fredrik Nordvall Forsberg, 13 November 2023.
In collaboration with Tom de Jong, Nicolai Kraus and Chuangjie Xu.

Minor updates 9 and 11 September 2024.

We prove several properties of ordinal multiplication, including that it
preserves suprema of ordinals and that it enjoys a left-cancellation property.

\begin{code}

{-# OPTIONS --safe --without-K --lossy-unification #-}

open import UF.Univalence

module Ordinals.MultiplicationProperties
       (ua : Univalence)
       where

open import UF.Base
open import UF.Equiv
open import UF.FunExt
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.UA-FunExt

private
 fe : FunExt
 fe = Univalence-gives-FunExt ua

 fe' : Fun-Ext
 fe' {𝓀} {π“₯} = fe 𝓀 π“₯

open import MLTT.Spartan

open import Ordinals.Arithmetic fe
open import Ordinals.Equivalence
open import Ordinals.Maps
open import Ordinals.OrdinalOfOrdinals ua
open import Ordinals.Type
open import Ordinals.Underlying
open import Ordinals.AdditionProperties ua

Γ—β‚’-πŸ˜β‚’-right : (Ξ± : Ordinal 𝓀) β†’ Ξ± Γ—β‚’ πŸ˜β‚’ {π“₯} = πŸ˜β‚’
Γ—β‚’-πŸ˜β‚’-right Ξ± = ⊴-antisym _ _
                 (to-⊴ (Ξ± Γ—β‚’ πŸ˜β‚’) πŸ˜β‚’ (Ξ» (a , b) β†’ 𝟘-elim b))
                 (πŸ˜β‚’-least-⊴ (Ξ± Γ—β‚’ πŸ˜β‚’))

Γ—β‚’-πŸ˜β‚’-left : (Ξ± : Ordinal 𝓀) β†’ πŸ˜β‚’ {π“₯} Γ—β‚’ Ξ± = πŸ˜β‚’
Γ—β‚’-πŸ˜β‚’-left Ξ± = ⊴-antisym _ _
                (to-⊴ (πŸ˜β‚’ Γ—β‚’ Ξ±) πŸ˜β‚’ (Ξ» (b , a) β†’ 𝟘-elim b))
                (πŸ˜β‚’-least-⊴ (πŸ˜β‚’ Γ—β‚’ Ξ±))

πŸ™β‚’-left-neutral-Γ—β‚’ : (Ξ± : Ordinal 𝓀) β†’ πŸ™β‚’ {𝓀} Γ—β‚’ Ξ± = Ξ±
πŸ™β‚’-left-neutral-Γ—β‚’ {𝓀} Ξ± = eqtoidβ‚’ (ua _) fe' _ _
                            (f , f-order-preserving ,
                             f-is-equiv , g-order-preserving)
 where
  f : πŸ™ Γ— ⟨ Ξ± ⟩ β†’ ⟨ Ξ± ⟩
  f = prβ‚‚

  g : ⟨ Ξ± ⟩ β†’ πŸ™ Γ— ⟨ Ξ± ⟩
  g = ( ⋆ ,_)

  f-order-preserving : is-order-preserving (πŸ™β‚’ {𝓀} Γ—β‚’ Ξ±) Ξ± f
  f-order-preserving x y (inl p) = p

  f-is-equiv : is-equiv f
  f-is-equiv = qinvs-are-equivs f (g , (Ξ» _ β†’ refl) , (Ξ» _ β†’ refl))

  g-order-preserving : is-order-preserving Ξ± (πŸ™β‚’ {𝓀} Γ—β‚’ Ξ±) g
  g-order-preserving x y p = inl p

πŸ™β‚’-right-neutral-Γ—β‚’ : (Ξ± : Ordinal 𝓀) β†’ Ξ± Γ—β‚’ πŸ™β‚’ {𝓀} = Ξ±
πŸ™β‚’-right-neutral-Γ—β‚’ {𝓀} Ξ± = eqtoidβ‚’ (ua _) fe' _ _
                             (f , f-order-preserving ,
                              f-is-equiv , g-order-preserving)
 where
  f : ⟨ Ξ± ⟩ Γ— πŸ™ β†’ ⟨ Ξ± ⟩
  f = pr₁

  g : ⟨ Ξ± ⟩ β†’ ⟨ Ξ± ⟩ Γ— πŸ™
  g = (_, ⋆ )

  f-order-preserving : is-order-preserving (Ξ± Γ—β‚’ πŸ™β‚’ {𝓀}) Ξ± f
  f-order-preserving x y (inr (refl , p)) = p

  f-is-equiv : is-equiv f
  f-is-equiv = qinvs-are-equivs f (g , (Ξ» _ β†’ refl) , (Ξ» _ β†’ refl))

  g-order-preserving : is-order-preserving Ξ± (Ξ± Γ—β‚’ πŸ™β‚’ {𝓀}) g
  g-order-preserving x y p = inr (refl , p)

\end{code}

Because we use --lossy-unification to speed up typechecking we have to
explicitly mention the universes in the lemma below; using them as variables (as
usual) results in a unification error.

\begin{code}

Γ—β‚’-assoc : {𝓀 π“₯ 𝓦 : Universe}
           (Ξ± : Ordinal 𝓀) (Ξ² : Ordinal π“₯) (Ξ³ : Ordinal 𝓦)
         β†’ (Ξ± Γ—β‚’ Ξ²) Γ—β‚’ Ξ³ = Ξ± Γ—β‚’ (Ξ² Γ—β‚’ Ξ³)
Γ—β‚’-assoc Ξ± Ξ² Ξ³ =
 eqtoidβ‚’ (ua _) fe' ((Ξ±  Γ—β‚’ Ξ²) Γ—β‚’ Ξ³) (Ξ±  Γ—β‚’ (Ξ² Γ—β‚’ Ξ³))
  (f , order-preserving-reflecting-equivs-are-order-equivs
   ((Ξ±  Γ—β‚’ Ξ²) Γ—β‚’ Ξ³) (Ξ±  Γ—β‚’ (Ξ² Γ—β‚’ Ξ³))
   f f-equiv f-preserves-order f-reflects-order)
  where
   f : ⟨ (Ξ± Γ—β‚’ Ξ²) Γ—β‚’ Ξ³ ⟩ β†’ ⟨ Ξ± Γ—β‚’ (Ξ² Γ—β‚’ Ξ³) ⟩
   f ((a , b) , c) = (a , (b , c))

   g : ⟨ Ξ± Γ—β‚’ (Ξ² Γ—β‚’ Ξ³) ⟩ β†’ ⟨ (Ξ± Γ—β‚’ Ξ²) Γ—β‚’ Ξ³ ⟩
   g (a , (b , c)) = ((a , b) , c)

   f-equiv : is-equiv f
   f-equiv = qinvs-are-equivs f (g , (Ξ» x β†’ refl) , (Ξ» x β†’ refl))

   f-preserves-order : is-order-preserving  ((Ξ±  Γ—β‚’ Ξ²) Γ—β‚’ Ξ³) (Ξ±  Γ—β‚’ (Ξ² Γ—β‚’ Ξ³)) f
   f-preserves-order _ _ (inl p) = inl (inl p)
   f-preserves-order _ _ (inr (r , inl p)) = inl (inr (r , p))
   f-preserves-order _ _ (inr (r , inr (u , q))) = inr (to-Γ—-= u r , q)

   f-reflects-order : is-order-reflecting ((Ξ±  Γ—β‚’ Ξ²) Γ—β‚’ Ξ³) (Ξ±  Γ—β‚’ (Ξ² Γ—β‚’ Ξ³)) f
   f-reflects-order _ _ (inl (inl p)) = inl p
   f-reflects-order _ _ (inl (inr (r , q))) = inr (r , (inl q))
   f-reflects-order _ _ (inr (refl , q)) = inr (refl , (inr (refl , q)))

\end{code}

The lemma below is as general as possible in terms of universe parameters
because addition requires its arguments to come from the same universe, at least
at present.

\begin{code}

Γ—β‚’-distributes-+β‚’-right : (Ξ± : Ordinal 𝓀) (Ξ² Ξ³ : Ordinal π“₯)
                        β†’ Ξ± Γ—β‚’ (Ξ² +β‚’ Ξ³) = (Ξ± Γ—β‚’ Ξ²) +β‚’ (Ξ± Γ—β‚’ Ξ³)
Γ—β‚’-distributes-+β‚’-right Ξ± Ξ² Ξ³ = eqtoidβ‚’ (ua _) fe' _ _
                                 (f , f-order-preserving ,
                                  f-is-equiv , g-order-preserving)
 where
  f : ⟨ Ξ± Γ—β‚’ (Ξ² +β‚’ Ξ³) ⟩ β†’ ⟨ (Ξ± Γ—β‚’ Ξ²) +β‚’ (Ξ± Γ—β‚’ Ξ³) ⟩
  f (a , inl b) = inl (a , b)
  f (a , inr c) = inr (a , c)

  g : ⟨ (Ξ± Γ—β‚’ Ξ²) +β‚’ (Ξ± Γ—β‚’ Ξ³) ⟩ β†’ ⟨ Ξ± Γ—β‚’ (Ξ² +β‚’ Ξ³) ⟩
  g (inl (a , b)) = a , inl b
  g (inr (a , c)) = a , inr c

  f-order-preserving : is-order-preserving _ _ f
  f-order-preserving (a , inl b) (a' , inl b') (inl p) = inl p
  f-order-preserving (a , inl b) (a' , inr c') (inl p) = ⋆
  f-order-preserving (a , inr c) (a' , inr c') (inl p) = inl p
  f-order-preserving (a , inl b) (a' , inl .b) (inr (refl , q)) = inr (refl , q)
  f-order-preserving (a , inr c) (a' , inr .c) (inr (refl , q)) = inr (refl , q)

  f-is-equiv : is-equiv f
  f-is-equiv = qinvs-are-equivs f (g , Ξ· , Ξ΅)
   where
    η : g ∘ f ∼ id
    Ξ· (a , inl b) = refl
    Ξ· (a , inr c) = refl

    Ρ : f ∘ g ∼ id
    Ξ΅ (inl (a , b)) = refl
    Ξ΅ (inr (a , c)) = refl

  g-order-preserving : is-order-preserving _ _ g
  g-order-preserving (inl (a , b)) (inl (a' , b')) (inl p) = inl p
  g-order-preserving (inl (a , b)) (inl (a' , .b)) (inr (refl , q)) =
   inr (refl , q)
  g-order-preserving (inl (a , b)) (inr (a' , c')) p = inl ⋆
  g-order-preserving (inr (a , c)) (inr (a' , c')) (inl p) = inl p
  g-order-preserving (inr (a , c)) (inr (a' , c')) (inr (refl , q)) =
   inr (refl , q)

\end{code}

The following characterizes the initial segments of a product and is rather
useful when working with simulations between products.

\begin{code}

Γ—β‚’-↓ : (Ξ± Ξ² : Ordinal 𝓀)
     β†’ {a : ⟨ Ξ± ⟩} {b : ⟨ Ξ² ⟩}
     β†’ (Ξ± Γ—β‚’ Ξ²) ↓ (a , b) = (Ξ± Γ—β‚’ (Ξ² ↓ b)) +β‚’ (Ξ± ↓ a)
Γ—β‚’-↓ Ξ± Ξ² {a} {b} = eqtoidβ‚’ (ua _) fe' _ _ (f , f-order-preserving ,
                                           f-is-equiv , g-order-preserving)
 where
  f : ⟨ (Ξ± Γ—β‚’ Ξ²) ↓ (a , b) ⟩ β†’ ⟨ (Ξ± Γ—β‚’ (Ξ² ↓ b)) +β‚’ (Ξ± ↓ a) ⟩
  f ((x , y) , inl p) = inl (x , (y , p))
  f ((x , y) , inr (r , q)) = inr (x , q)

  g : ⟨ (Ξ± Γ—β‚’ (Ξ² ↓ b)) +β‚’ (Ξ± ↓ a) ⟩ β†’ ⟨ (Ξ± Γ—β‚’ Ξ²) ↓ (a , b) ⟩
  g (inl (x , y , p)) = (x , y) , inl p
  g (inr (x , q)) = (x , b) , inr (refl , q)

  f-order-preserving : is-order-preserving _ _ f
  f-order-preserving ((x , y) , inl p) ((x' , y') , inl p') (inl l) = inl l
  f-order-preserving ((x , y) , inl p) ((x' , _)  , inl p') (inr (refl , l)) =
   inr ((ap (y ,_) (Prop-valuedness Ξ² _ _ p p')) , l)
  f-order-preserving ((x , y) , inl p) ((x' , y') , inr (r' , q')) l = ⋆
  f-order-preserving ((x , y) , inr (refl , q)) ((x' , y') , inl p') (inl l) =
   𝟘-elim (irrefl β y (Transitivity β _ _ _ l p'))
  f-order-preserving ((x , y) , inr (refl , q))
                     ((x' , _)  , inl p') (inr (refl , l)) = 𝟘-elim
                                                              (irrefl Ξ² y p')
  f-order-preserving ((x , y) , inr (refl , q))
                     ((x' , _)  , inr (refl , q')) (inl l) = 𝟘-elim
                                                              (irrefl Ξ² y l)
  f-order-preserving ((x , y) , inr (refl , q))
                     ((x' , _)  , inr (refl , q')) (inr (_ , l)) = l

  f-is-equiv : is-equiv f
  f-is-equiv = qinvs-are-equivs f (g , Ξ· , Ξ΅)
   where
    η : g ∘ f ∼ id
    Ξ· ((x , y) , inl p) = refl
    Ξ· ((x , y) , inr (refl , q)) = refl

    Ρ : f ∘ g ∼ id
    Ξ΅ (inl (x , y)) = refl
    Ξ΅ (inr x) = refl

  g-order-preserving : is-order-preserving _ _ g
  g-order-preserving (inl (x , y , p)) (inl (x' , y' , p')) (inl l) = inl l
  g-order-preserving (inl (x , y , p)) (inl (x' , y' , p')) (inr (refl , l)) =
   inr (refl , l)
  g-order-preserving (inl (x , y , p)) (inr (x' , q')) _ = inl p
  g-order-preserving (inr (x , q))     (inr (x' , q')) l = inr (refl , l)

\end{code}

We now prove several useful facts about (bounded) simulations between products.

\begin{code}

Γ—β‚’-increasing-on-right : (Ξ± Ξ² Ξ³ : Ordinal 𝓀)
                       β†’ πŸ˜β‚’ ⊲ Ξ±
                       β†’ Ξ² ⊲ Ξ³
                       β†’ (Ξ± Γ—β‚’ Ξ²) ⊲ (Ξ± Γ—β‚’ Ξ³)
Γ—β‚’-increasing-on-right Ξ± Ξ² Ξ³ (a , p) (c , q) = (a , c) , I
 where
  I = Ξ± Γ—β‚’ Ξ²                    =⟨ πŸ˜β‚’-right-neutral (Ξ± Γ—β‚’ Ξ²) ⁻¹ ⟩
      (Ξ± Γ—β‚’ Ξ²) +β‚’ πŸ˜β‚’            =⟨ apβ‚‚ (Ξ» -₁ -β‚‚ β†’ (Ξ± Γ—β‚’ -₁) +β‚’ -β‚‚) q p ⟩
      (Ξ± Γ—β‚’ (Ξ³ ↓ c)) +β‚’ (Ξ± ↓ a) =⟨ Γ—β‚’-↓ Ξ± Ξ³ ⁻¹ ⟩
      (Ξ± Γ—β‚’ Ξ³) ↓ (a , c)        ∎

Γ—β‚’-right-monotone-⊴ : (Ξ± : Ordinal 𝓀) (Ξ² Ξ³ : Ordinal π“₯)
                    β†’ Ξ² ⊴ Ξ³
                    β†’ (Ξ± Γ—β‚’ Ξ²) ⊴ (Ξ± Γ—β‚’ Ξ³)
Γ—β‚’-right-monotone-⊴ Ξ± Ξ² Ξ³ (g , sim-g) = f , f-initial-segment ,
                                            f-order-preserving
 where
   f : ⟨ Ξ± Γ—β‚’ Ξ² ⟩ β†’ ⟨ Ξ± Γ—β‚’ Ξ³ ⟩
   f (a , b) = a , g b

   f-initial-segment : is-initial-segment (Ξ± Γ—β‚’ Ξ²) (Ξ± Γ—β‚’ Ξ³) f
   f-initial-segment (a , b) (a' , c') (inl l) = (a' , b') , inl k , ap (a' ,_) q
    where
     I : Ξ£ b' κž‰ ⟨ Ξ² ⟩ , b' β‰ΊβŸ¨ Ξ² ⟩ b Γ— (g b' = c')
     I = simulations-are-initial-segments Ξ² Ξ³ g sim-g b c' l
     b' = pr₁ I
     k = pr₁ (prβ‚‚ I)
     q = prβ‚‚ (prβ‚‚ I)
   f-initial-segment (a , b) (a' , c') (inr (refl , q)) =
    (a' , b) , inr (refl , q) , refl

   f-order-preserving : is-order-preserving (Ξ± Γ—β‚’ Ξ²) (Ξ± Γ—β‚’ Ξ³) f
   f-order-preserving (a , b) (a' , b') (inl p) =
    inl (simulations-are-order-preserving Ξ² Ξ³ g sim-g b b' p)
   f-order-preserving (a , b) (a' , b') (inr (refl , q)) = inr (refl , q)

Γ—β‚’-β‰Ό-left : (Ξ± : Ordinal 𝓀) (Ξ² : Ordinal π“₯)
            {a a' : ⟨ α ⟩} {b : ⟨ β ⟩}
          β†’ a β‰ΌβŸ¨ Ξ± ⟩ a'
          β†’ (a , b) β‰ΌβŸ¨ Ξ± Γ—β‚’ Ξ² ⟩ (a' , b)
Γ—β‚’-β‰Ό-left Ξ± Ξ² p (aβ‚€ , bβ‚€) (inl r) = inl r
Γ—β‚’-β‰Ό-left Ξ± Ξ² p (aβ‚€ , bβ‚€) (inr (eq , r)) = inr (eq , p aβ‚€ r)

\end{code}

To prove that multiplication is left cancellable, we require the following
technical lemma: if Ξ± > 𝟘, then every simulation from Ξ± Γ—β‚’ Ξ² to Ξ± Γ—β‚’ Ξ³
decomposes as the identity on the first component and a function Ξ² β†’ Ξ³ on the
second component, viz. one that is independent of the first component.

\begin{code}

simulation-product-decomposition
 : (Ξ± : Ordinal 𝓀) (Ξ² Ξ³ : Ordinal π“₯)
   ((aβ‚€ , aβ‚€-least) : πŸ˜β‚’ ⊲ Ξ±)
   ((f , _) : (Ξ± Γ—β‚’ Ξ²) ⊴ (Ξ± Γ—β‚’ Ξ³))
 β†’ (a : ⟨ Ξ± ⟩) (b : ⟨ Ξ² ⟩) β†’ f (a , b) = (a , prβ‚‚ (f (aβ‚€ , b)))
simulation-product-decomposition {𝓀} {π“₯} Ξ± Ξ² Ξ³ (aβ‚€ , aβ‚€-least)
                                 (f , sim@(init-seg , order-pres)) a b = I
 where
  f' : ⟨ Ξ± Γ—β‚’ Ξ² ⟩ β†’ ⟨ Ξ± Γ—β‚’ Ξ³ ⟩
  f' (a , b) = (a , prβ‚‚ (f (aβ‚€ , b)))

  P : ⟨ Ξ± Γ—β‚’ Ξ² ⟩ β†’ 𝓀 βŠ” π“₯ Μ‡
  P (a , b) = (f (a , b)) = f' (a , b)

  I : P (a , b)
  I = Transfinite-induction (Ξ± Γ—β‚’ Ξ²) P II (a , b)
   where
    II : (x : ⟨ Ξ± Γ—β‚’ Ξ² ⟩)
       β†’ ((y : ⟨ Ξ± Γ—β‚’ Ξ² ⟩) β†’ y β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ² ⟩ x β†’ P y)
       β†’ P x
    II (a , b) IH = Extensionality (Ξ± Γ—β‚’ Ξ³) (f (a , b)) (f' (a , b)) III IV
     where
      III : (u : ⟨ Ξ± Γ—β‚’ Ξ³ ⟩) β†’ u β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f (a , b) β†’ u β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f' (a , b)
      III (a' , c') p = transport (Ξ» - β†’ - β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f' (a , b)) IIIβ‚‚ (III₃ p')
       where
        III₁ : Ξ£ (a'' , b') κž‰ ⟨ Ξ± Γ—β‚’ Ξ² ⟩ , (a'' , b') β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ² ⟩ (a , b)
                                         Γ— (f (a'' , b') = a' , c')
        III₁ = init-seg (a , b) (a' , c') p
        a'' = pr₁ (pr₁ III₁)
        b' = prβ‚‚ (pr₁ III₁)
        p' = pr₁ (prβ‚‚ III₁)
        eq : f (a'' , b') = (a' , c')
        eq = prβ‚‚ (prβ‚‚ III₁)

        IIIβ‚‚ : f' (a'' , b') = (a' , c')
        IIIβ‚‚ = IH (a'' , b') p' ⁻¹ βˆ™ eq

        III₃ : (a'' , b') β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ² ⟩ (a , b)
             β†’ f' (a'' , b') β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f' (a , b)
        III₃ (inl q) = h (order-pres (aβ‚€' , b') (aβ‚€ , b) (inl q))
         where
          aβ‚€' : ⟨ Ξ± ⟩
          aβ‚€' = pr₁ (f (aβ‚€ , b))

          ih : (f (aβ‚€' , b')) = f' (aβ‚€' , b')
          ih = IH (aβ‚€' , b') (inl q)

          h : f  (aβ‚€' , b') β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f  (aβ‚€ , b)
            β†’ f' (a'' , b') β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f' (a , b)
          h (inl r) = inl (transport (Ξ» - β†’ - β‰ΊβŸ¨ Ξ³ ⟩ prβ‚‚ (f (aβ‚€ , b)))
                                     (ap prβ‚‚ ih) r)
          h (inr (_ , r)) = 𝟘-elim (irrefl Ξ± aβ‚€' (transport (Ξ» - β†’ - β‰ΊβŸ¨ Ξ± ⟩ aβ‚€')
                                                            (ap pr₁ ih) r))
        III₃ (inr (e , q)) = inr (ap (Ξ» - β†’ prβ‚‚ (f (aβ‚€ , -))) e , q)

      IV : (u : ⟨ Ξ± Γ—β‚’ Ξ³ ⟩) β†’ u β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f' (a , b) β†’ u β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f  (a , b)
      IV (a' , c') (inl p) = lβ‚‚ (a' , c') (inl p)
       where
        l₁ : aβ‚€ β‰ΌβŸ¨ Ξ± ⟩ a
        l₁ x p = 𝟘-elim (transport ⟨_⟩ (aβ‚€-least ⁻¹) (x , p))
        lβ‚‚ : f (aβ‚€ , b) β‰ΌβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f (a , b)
        lβ‚‚ = simulations-are-monotone _ _
              f sim (aβ‚€ , b) (a , b) (Γ—β‚’-β‰Ό-left Ξ± Ξ² l₁)
      IV (a' , c') (inr (r , q)) =
       transport (Ξ» - β†’ - β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ³ ⟩ f  (a , b)) eq
                 (order-pres (a' , b) (a , b) (inr (refl , q)))
        where
         eq = f  (a' , b)             =⟨ IH (a' , b) (inr (refl , q)) ⟩
              f' (a' , b)             =⟨ refl ⟩
              (a' , prβ‚‚ (f (aβ‚€ , b))) =⟨ ap (a' ,_) (r ⁻¹) ⟩
              (a' , c')               ∎

\end{code}

The following result states that multiplication for ordinals can be cancelled on
the left. Interestingly, Andrew Swan [Swa18] proved that the corresponding
result for sets is not provable constructively already for α = 𝟚: there are
toposes where the statement

  𝟚 Γ— X ≃ 𝟚 Γ— Y β†’ X ≃ Y

is not true for certain objects X and Y in the topos.

[Swa18] Andrew Swan
        On Dividing by Two in Constructive Mathematics
        2018
        https://arxiv.org/abs/1804.04490

\begin{code}

Γ—β‚’-left-cancellable : (Ξ± Ξ² Ξ³ : Ordinal 𝓀)
                    β†’ πŸ˜β‚’ ⊲ Ξ±
                    β†’ (Ξ± Γ—β‚’ Ξ²) = (Ξ± Γ—β‚’ Ξ³)
                    β†’ Ξ² = Ξ³
Γ—β‚’-left-cancellable {𝓀} Ξ± Ξ² Ξ³ (aβ‚€ , aβ‚€-least) =
 transfinite-induction-on-OO P II Ξ² Ξ³
  where
   P : Ordinal 𝓀 β†’ 𝓀 ⁺ Μ‡
   P Ξ² = (Ξ³ : Ordinal 𝓀) β†’ (Ξ± Γ—β‚’ Ξ²) = (Ξ± Γ—β‚’ Ξ³) β†’ Ξ² = Ξ³

   I : (Ξ² Ξ³ : Ordinal 𝓀)
     β†’ (Ξ± Γ—β‚’ Ξ²) = (Ξ± Γ—β‚’ Ξ³)
     β†’ (b : ⟨ Ξ² ⟩) β†’ Ξ£ c κž‰ ⟨ Ξ³ ⟩ , (Ξ± Γ—β‚’ (Ξ² ↓ b) = Ξ± Γ—β‚’ (Ξ³ ↓ c))
   I Ξ² Ξ³ e b = c , eq
    where
     𝕗 : (Ξ± Γ—β‚’ Ξ²) ⊴ (Ξ± Γ—β‚’ Ξ³)
     𝕗 = ≃ₒ-to-⊴ (Ξ± Γ—β‚’ Ξ²) (Ξ±Β Γ—β‚’ Ξ³) (idtoeqβ‚’ _ _ e)
     f : ⟨ Ξ± Γ—β‚’ Ξ² ⟩ β†’ ⟨ Ξ± Γ—β‚’ Ξ³ ⟩
     f = [ Ξ± Γ—β‚’ Ξ² , Ξ± Γ—β‚’ Ξ³ ]⟨ 𝕗 ⟩

     c : ⟨ γ ⟩
     c = prβ‚‚ (f (aβ‚€ , b))

     eq = Ξ± Γ—β‚’ (Ξ² ↓ b)                =⟨ πŸ˜β‚’-right-neutral (Ξ± Γ—β‚’ (Ξ² ↓ b)) ⁻¹ ⟩
          (Ξ± Γ—β‚’ (Ξ² ↓ b)) +β‚’ πŸ˜β‚’        =⟨ ap ((Ξ± Γ—β‚’ (Ξ² ↓ b)) +β‚’_) aβ‚€-least ⟩
          (Ξ± Γ—β‚’ (Ξ² ↓ b)) +β‚’ (Ξ± ↓ aβ‚€)  =⟨ Γ—β‚’-↓ Ξ± Ξ² ⁻¹ ⟩
          (Ξ± Γ—β‚’ Ξ²) ↓ (aβ‚€ , b)         =⟨ eq₁ ⟩
          (Ξ± Γ—β‚’ Ξ³) ↓ (aβ‚€' , c)        =⟨ eqβ‚‚ ⟩
          (Ξ± Γ—β‚’ Ξ³) ↓ (aβ‚€ , c)         =⟨ Γ—β‚’-↓ Ξ± Ξ³ ⟩
          (Ξ± Γ—β‚’ (Ξ³ ↓ c)) +β‚’ (Ξ± ↓ aβ‚€)  =⟨ ap ((Ξ± Γ—β‚’ (Ξ³ ↓ c)) +β‚’_) (aβ‚€-least ⁻¹) ⟩
          (Ξ± Γ—β‚’ (Ξ³ ↓ c)) +β‚’ πŸ˜β‚’        =⟨ πŸ˜β‚’-right-neutral (Ξ± Γ—β‚’ (Ξ³ ↓ c)) ⟩
          Ξ± Γ—β‚’ (Ξ³ ↓ c)                ∎
      where
       aβ‚€' : ⟨ Ξ± ⟩
       aβ‚€' = pr₁ (f (aβ‚€ , b))

       eq₁ = simulations-preserve-↓ (Ξ± Γ—β‚’ Ξ²) (Ξ± Γ—β‚’ Ξ³) 𝕗 (aβ‚€ , b)
       eqβ‚‚ = ap ((Ξ± Γ—β‚’ Ξ³) ↓_)
                (simulation-product-decomposition Ξ± Ξ² Ξ³ (aβ‚€ , aβ‚€-least) 𝕗 aβ‚€ b)

   II : (Ξ² : Ordinal 𝓀) β†’ ((b : ⟨ Ξ² ⟩) β†’ P (Ξ² ↓ b)) β†’ P Ξ²
   II Ξ² IH Ξ³ e = Extensionality (OO 𝓀) Ξ² Ξ³ (to-β‰Ό III) (to-β‰Ό IV)
    where
     III : (b : ⟨ Ξ² ⟩) β†’ (Ξ² ↓ b) ⊲ Ξ³
     III b = let (c , eq) = I Ξ² Ξ³  e     b in (c , IH b (Ξ³ ↓ c) eq)
     IV  : (c : ⟨ Ξ³ ⟩) β†’ (Ξ³ ↓ c) ⊲ Ξ²
     IV  c = let (b , eq) = I Ξ³ Ξ² (e ⁻¹) c in (b , (IH b (Ξ³ ↓ c) (eq ⁻¹) ⁻¹))

\end{code}

Finally, multiplication satisfies the expected recursive equations (which
classically define ordinal multiplication): zero is fixed by multiplication
(this is Γ—β‚’-πŸ˜β‚’-right above), multiplication for successors is repeated addition
and multiplication preserves suprema.

\begin{code}

Γ—β‚’-successor : (Ξ± Ξ² : Ordinal 𝓀) β†’ Ξ± Γ—β‚’ (Ξ² +β‚’ πŸ™β‚’) = (Ξ± Γ—β‚’ Ξ²) +β‚’ Ξ±
Γ—β‚’-successor Ξ± Ξ² =
  Ξ± Γ—β‚’ (Ξ² +β‚’ πŸ™β‚’)          =⟨ Γ—β‚’-distributes-+β‚’-right Ξ± Ξ² πŸ™β‚’ ⟩
  ((Ξ± Γ—β‚’ Ξ²) +β‚’ (Ξ± Γ—β‚’ πŸ™β‚’)) =⟨ ap ((Ξ± Γ—β‚’ Ξ²) +β‚’_) (πŸ™β‚’-right-neutral-Γ—β‚’ Ξ±)  ⟩
  (Ξ± Γ—β‚’ Ξ²) +β‚’ Ξ±           ∎

open import UF.PropTrunc
open import UF.Size

module _ (pt : propositional-truncations-exist)
         (sr : Set-Replacement pt)
       where

 open import Ordinals.OrdinalOfOrdinalsSuprema ua
 open suprema pt sr
 open PropositionalTruncation pt

 Γ—β‚’-preserves-suprema : (Ξ± : Ordinal 𝓀) {I : 𝓀 Μ‡ } (Ξ² : I β†’ Ordinal 𝓀)
                      β†’ Ξ± Γ—β‚’ sup Ξ² = sup (Ξ» i β†’ Ξ± Γ—β‚’ Ξ² i)
 Γ—β‚’-preserves-suprema {𝓀} Ξ± {I} Ξ² = ⊴-antisym (Ξ± Γ—β‚’ sup Ξ²) (sup (Ξ» i β†’ Ξ± Γ—β‚’ Ξ² i)) β¦…1⦆ β¦…2⦆
  where
   β¦…2⦆ : sup (Ξ» i β†’ Ξ± Γ—β‚’ Ξ² i) ⊴ (Ξ± Γ—β‚’ sup Ξ²)
   β¦…2⦆ = sup-is-lower-bound-of-upper-bounds (Ξ» i β†’ Ξ± Γ—β‚’ Ξ² i) (Ξ± Γ—β‚’ sup Ξ²)
          (Ξ» i β†’ Γ—β‚’-right-monotone-⊴ Ξ± (Ξ² i) (sup Ξ²) (sup-is-upper-bound Ξ² i))

   β¦…1⦆ : (Ξ± Γ—β‚’ sup Ξ²) ⊴ sup (Ξ» i β†’ Ξ± Γ—β‚’ Ξ² i)
   β¦…1⦆ = β‰Ό-gives-⊴ (Ξ± Γ—β‚’ sup Ξ²) (sup (Ξ» i β†’ Ξ± Γ—β‚’ Ξ² i)) β¦…1⦆-I
    where
     β¦…1⦆-I : (Ξ³ : Ordinal 𝓀) β†’ Ξ³ ⊲ (Ξ± Γ—β‚’ sup Ξ²) β†’ Ξ³ ⊲ sup (Ξ» i β†’ Ξ± Γ—β‚’ Ξ² i)
     β¦…1⦆-I _ ((a , y) , refl) = β¦…1⦆-III
      where
       β¦…1⦆-II : (Ξ£ i κž‰ I , Ξ£ b κž‰ ⟨ Ξ² i ⟩ , sup Ξ² ↓ y = (Ξ² i) ↓ b)
              β†’ ((Ξ± Γ—β‚’ sup Ξ²) ↓ (a , y)) ⊲ sup (Ξ» j β†’ Ξ± Γ—β‚’ Ξ² j)
       β¦…1⦆-II (i , b , e) = Οƒ (a , b) , eq
        where
         Οƒ : ⟨ Ξ± Γ—β‚’ Ξ² i ⟩ β†’ ⟨ sup (Ξ» j β†’ Ξ± Γ—β‚’ Ξ² j) ⟩
         Οƒ = [ Ξ± Γ—β‚’ Ξ² i , sup (Ξ» j β†’ Ξ± Γ—β‚’ Ξ² j) ]⟨ sup-is-upper-bound _ i ⟩

         eq = (Ξ± Γ—β‚’ sup Ξ²) ↓ (a , y)           =⟨ Γ—β‚’-↓ Ξ± (sup Ξ²) ⟩
              (Ξ± Γ—β‚’ (sup Ξ² ↓ y)) +β‚’ (Ξ± ↓ a)    =⟨ eq₁ ⟩
              (Ξ± Γ—β‚’ (Ξ² i ↓ b)) +β‚’ (Ξ± ↓ a)      =⟨ Γ—β‚’-↓ Ξ± (Ξ² i) ⁻¹ ⟩
              (Ξ± Γ—β‚’ Ξ² i) ↓ (a , b)             =⟨ eqβ‚‚ ⟩
              sup (Ξ» j β†’ Ξ± Γ—β‚’ Ξ² j) ↓ Οƒ (a , b) ∎
          where
           eq₁ = ap (Ξ» - β†’ ((Ξ± Γ—β‚’ -) +β‚’ (Ξ± ↓ a))) e
           eqβ‚‚ = (initial-segment-of-sup-at-component
                  (Ξ» j β†’ Ξ± Γ—β‚’ Ξ² j) i (a , b)) ⁻¹

       β¦…1⦆-III : ((Ξ± Γ—β‚’ sup Ξ²) ↓ (a , y)) ⊲ sup (Ξ» i β†’ Ξ± Γ—β‚’ Ξ² i)
       β¦…1⦆-III = βˆ₯βˆ₯-rec (⊲-is-prop-valued _ _) β¦…1⦆-II
                  (initial-segment-of-sup-is-initial-segment-of-some-component
                    Ξ² y)

\end{code}

11 September 2024, added by Tom de Jong following a question by Martin Escardo.

The equations for successor and suprema uniquely specify the multiplication
operation even though they are not constructively sufficient to define it.

\begin{code}

 private
  successor-equation : (Ordinal 𝓀 β†’ Ordinal 𝓀 β†’ Ordinal 𝓀) β†’ 𝓀 ⁺ Μ‡
  successor-equation {𝓀} _βŠ—_ =
   (Ξ± Ξ² : Ordinal 𝓀) β†’ Ξ± βŠ— (Ξ² +β‚’ πŸ™β‚’) = (Ξ± βŠ— Ξ²) +β‚’ Ξ±

  suprema-equation : (Ordinal 𝓀 β†’ Ordinal 𝓀 β†’ Ordinal 𝓀) β†’ 𝓀 ⁺ Μ‡
  suprema-equation {𝓀} _βŠ—_ =
   (Ξ± : Ordinal 𝓀) (I : 𝓀 Μ‡  ) (Ξ² : I β†’ Ordinal 𝓀)
    β†’ Ξ± βŠ— (sup Ξ²) = sup (Ξ» i β†’ Ξ± βŠ— Ξ² i)

  recursive-equation : (Ordinal 𝓀 β†’ Ordinal 𝓀 β†’ Ordinal 𝓀) β†’ 𝓀 ⁺ Μ‡
  recursive-equation {𝓀} _βŠ—_ =
   (Ξ± Ξ² : Ordinal 𝓀) β†’ Ξ± βŠ— Ξ² = sup (Ξ» b β†’ (Ξ± βŠ— (Ξ² ↓ b)) +β‚’ Ξ±)

  successor-and-suprema-equations-give-recursive-equation
   : (_βŠ—_ : Ordinal 𝓀 β†’ Ordinal 𝓀 β†’ Ordinal 𝓀)
   β†’ successor-equation _βŠ—_
   β†’ suprema-equation _βŠ—_
   β†’ recursive-equation _βŠ—_
  successor-and-suprema-equations-give-recursive-equation
   _βŠ—_ βŠ—-succ βŠ—-sup Ξ± Ξ² = Ξ± βŠ— Ξ²                           =⟨ I   ⟩
                          (Ξ± βŠ— sup (Ξ» b β†’ (Ξ² ↓ b) +β‚’ πŸ™β‚’)) =⟨ II  ⟩
                          sup (Ξ» b β†’ Ξ± βŠ— ((Ξ² ↓ b) +β‚’ πŸ™β‚’)) =⟨ III ⟩
                          sup (Ξ» b β†’ (Ξ± βŠ— (Ξ² ↓ b)) +β‚’ Ξ±)  ∎
    where
     I   = ap (Ξ± βŠ—_) (supremum-of-successors-of-initial-segments pt sr Ξ²)
     II  = βŠ—-sup Ξ± ⟨ Ξ² ⟩ (Ξ» b β†’ (Ξ² ↓ b) +β‚’ πŸ™β‚’)
     III = ap sup (dfunext fe' (Ξ» b β†’ βŠ—-succ Ξ± (Ξ² ↓ b)))

 Γ—β‚’-recursive-equation : recursive-equation {𝓀} _Γ—β‚’_
 Γ—β‚’-recursive-equation =
  successor-and-suprema-equations-give-recursive-equation
    _Γ—β‚’_ Γ—β‚’-successor (Ξ» Ξ± _ Ξ² β†’ Γ—β‚’-preserves-suprema Ξ± Ξ²)

 Γ—β‚’-is-uniquely-specified'
  : (_βŠ—_ : Ordinal 𝓀 β†’ Ordinal 𝓀 β†’ Ordinal 𝓀)
  β†’ recursive-equation _βŠ—_
  β†’ (Ξ± Ξ² : Ordinal 𝓀) β†’ Ξ± βŠ— Ξ² = Ξ± Γ—β‚’ Ξ²
 Γ—β‚’-is-uniquely-specified' {𝓀} _βŠ—_ βŠ—-rec Ξ± =
  transfinite-induction-on-OO (Ξ» - β†’ (Ξ± βŠ— -) = (Ξ± Γ—β‚’ -)) I
   where
    I : (Ξ² : Ordinal 𝓀)
      β†’ ((b : ⟨ Ξ² ⟩) β†’ (Ξ± βŠ— (Ξ² ↓ b)) = (Ξ± Γ—β‚’ (Ξ² ↓ b)))
      β†’ (Ξ± βŠ— Ξ²) = (Ξ± Γ—β‚’ Ξ²)
    I Ξ² IH = Ξ± βŠ— Ξ²                            =⟨ II  ⟩
             sup (Ξ» b β†’ (Ξ± βŠ— (Ξ² ↓ b)) +β‚’ Ξ±)   =⟨ III ⟩
             sup (Ξ» b β†’ (Ξ± Γ—β‚’ (Ξ² ↓ b)) +β‚’ Ξ±)  =⟨ IV  ⟩
             Ξ± Γ—β‚’ Ξ²                           ∎
     where
      II  = βŠ—-rec Ξ± Ξ²
      III = ap sup (dfunext fe' (Ξ» b β†’ ap (_+β‚’ Ξ±) (IH b)))
      IV  = Γ—β‚’-recursive-equation Ξ± Ξ² ⁻¹

 Γ—β‚’-is-uniquely-specified
  : βˆƒ! _βŠ—_ κž‰ (Ordinal 𝓀 β†’ Ordinal 𝓀 β†’ Ordinal 𝓀) ,
     (successor-equation _βŠ—_) Γ— (suprema-equation _βŠ—_)
 Γ—β‚’-is-uniquely-specified {𝓀} =
  (_Γ—β‚’_ , (Γ—β‚’-successor , (Ξ» Ξ± _ Ξ² β†’ Γ—β‚’-preserves-suprema Ξ± Ξ²))) ,
  (Ξ» (_βŠ—_ , βŠ—-succ , βŠ—-sup) β†’
   to-subtype-=
    (Ξ» F β†’ Γ—-is-prop (Ξ β‚‚-is-prop fe'
                       (Ξ» _ _ β†’ underlying-type-is-set fe (OO 𝓀)))
                     (Π₃-is-prop fe'
                       (Ξ» _ _ _ β†’ underlying-type-is-set fe (OO 𝓀))))
    (dfunext fe'
      (Ξ» Ξ± β†’ dfunext fe'
       (Ξ» Ξ² β†’
        (Γ—β‚’-is-uniquely-specified' _βŠ—_
          (successor-and-suprema-equations-give-recursive-equation
            _βŠ—_ βŠ—-succ βŠ—-sup)
        α β) ⁻¹))))

\end{code}

The above should be contrasted to the situation for addition where we do not
know how to prove such a result since only *inhabited* suprema are preserved by
addition.