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

Minor updates 9 and 11 September, 1 November 2024 and 15 July 2025.

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
open import UF.ClassicalLogic

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

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

open import MLTT.Spartan
open import MLTT.Plus-Properties

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

Γ—β‚’-πŸ˜β‚’-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-order-preserving x y (inr (e , q)) = 𝟘-elim q

  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 (inl p)          = 𝟘-elim p
  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-order-preserving (a , inl b) (a' , inr c') (inr (e , q)) =
   𝟘-elim (+disjoint e)
  f-order-preserving (a , inr c) (a' , inl b') (inl p) = 𝟘-elim p
  f-order-preserving (a , inr c) (a' , inl b') (inr (e , q)) =
   𝟘-elim (+disjoint' e)

  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)) (inl b')        p       = 𝟘-elim p
  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))     (inl y')        l = 𝟘-elim l
  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 π“₯) (Ξ³ : 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}

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 (i.e. it is continuous).

\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 import Ordinals.SupremaPreservation ua pt sr
 open suprema pt sr
 open PropositionalTruncation pt

 Γ—β‚’-is-continuous : (Ξ± : Ordinal 𝓀) β†’ is-continuous (Ξ± Γ—β‚’_)
 Γ—β‚’-is-continuous {𝓀} Ξ± {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}

In OperationsByCases, it is shown that the equations for successor and suprema
uniquely specify the multiplication operation and lead to a definition by
transfinite recursion.

Added 17 September 2024 by Fredrik Nordvall Forsberg:

Multiplication being monotone in the left argument is a constructive taboo.

Addition 22 November 2024: monotonicity in the left argument is
equivalent to Excluded Middle.

\begin{code}

Γ—β‚’-minimal : (Ξ± : Ordinal 𝓀) (Ξ² : Ordinal π“₯) (aβ‚€ : ⟨ Ξ± ⟩) (bβ‚€ : ⟨ Ξ² ⟩)
           β†’ is-least Ξ± aβ‚€ β†’ is-least Ξ² bβ‚€ β†’ is-minimal (Ξ± Γ—β‚’ Ξ²) (aβ‚€ , bβ‚€)
Γ—β‚’-minimal Ξ± Ξ² aβ‚€ bβ‚€ aβ‚€-least bβ‚€-least (a , b) (inl l)
 = irrefl Ξ² b (bβ‚€-least b b l)
Γ—β‚’-minimal Ξ± Ξ² aβ‚€ bβ‚€ aβ‚€-least bβ‚€-least (a , b) (inr (refl , l))
 = irrefl Ξ± a (aβ‚€-least a a l)

Γ—β‚’-least : (Ξ± : Ordinal 𝓀) (Ξ² : Ordinal π“₯) (aβ‚€ : ⟨ Ξ± ⟩) (bβ‚€ : ⟨ Ξ² ⟩)
         β†’ is-least Ξ± aβ‚€ β†’ is-least Ξ² bβ‚€ β†’ is-least (Ξ± Γ—β‚’ Ξ²) (aβ‚€ , bβ‚€)
Γ—β‚’-least Ξ± Ξ²  aβ‚€ bβ‚€ aβ‚€-least bβ‚€-least =
 minimal-is-least (Ξ± Γ—β‚’ Ξ²) (aβ‚€ , bβ‚€) (Γ—β‚’-minimal Ξ± Ξ² aβ‚€ bβ‚€ aβ‚€-least bβ‚€-least)

Γ—β‚’-left-monotonicity-implies-EM
  : ((Ξ± Ξ² : Ordinal 𝓀) (Ξ³ : Ordinal π“₯) β†’ Ξ± ⊴ Ξ² β†’ Ξ± Γ—β‚’ Ξ³ ⊴ Ξ² Γ—β‚’ Ξ³)
  β†’ EM 𝓀
Γ—β‚’-left-monotonicity-implies-EM hyp P isprop-P = III (f (⋆ , inr ⋆)) refl
 where
  Ξ± = πŸ™β‚’
  Pβ‚’ = prop-ordinal P isprop-P
  Ξ² = πŸ™β‚’ +β‚’ Pβ‚’
  Ξ³ = πŸšβ‚’

  I : α ⊴ β
  I = β‰Ό-gives-⊴ Ξ± Ξ²
       (transport
         (_β‰Ό Ξ²)
         (πŸ˜β‚’-right-neutral πŸ™β‚’)
         (+β‚’-right-monotone πŸ™β‚’ πŸ˜β‚’ Pβ‚’
         (πŸ˜β‚’-least Pβ‚’)))

  II : (Ξ± Γ—β‚’ Ξ³) ⊴ (Ξ² Γ—β‚’ Ξ³)
  II = hyp Ξ± Ξ² Ξ³ I

  f = pr₁ II
  f-sim = prβ‚‚ II

  f-preserves-least : f (⋆ , inl ⋆) = (inl ⋆ , inl ⋆)
  f-preserves-least = simulations-preserve-least (Ξ± Γ—β‚’ Ξ³) (Ξ² Γ—β‚’ Ξ³)
                        (⋆ , inl ⋆)
                        (inl ⋆ , inl ⋆)
                        f f-sim
                        (Γ—β‚’-least Ξ± Ξ³ ⋆ (inl ⋆)
                          ⋆-least
                          (left-preserves-least πŸ™β‚’ πŸ™β‚’ ⋆ ⋆-least))
                        (Γ—β‚’-least Ξ² Ξ³ (inl ⋆) (inl ⋆)
                         (left-preserves-least πŸ™β‚’ Pβ‚’ ⋆ ⋆-least)
                         (left-preserves-least πŸ™β‚’ πŸ™β‚’ ⋆ ⋆-least))
   where
    ⋆-least : is-least (πŸ™β‚’ {𝓀}) ⋆
    ⋆-least ⋆ ⋆ = 𝟘-elim

  III : (x : ⟨ Ξ² Γ—β‚’ Ξ³ ⟩) β†’ f (⋆ , inr ⋆) = x β†’ P + Β¬ P
  III (inl ⋆ , inl ⋆) r = 𝟘-elim (+disjoint' IIIβ‚‚)
   where
    III₁ = f (⋆ , inr ⋆)   =⟨ r ⟩
           (inl ⋆ , inl ⋆) =⟨ f-preserves-least ⁻¹ ⟩
           f (⋆ , inl ⋆)   ∎
    IIIβ‚‚ : inr ⋆ = inl ⋆
    IIIβ‚‚ = ap prβ‚‚ (simulations-are-lc _ _ f f-sim III₁)
  III (inl ⋆ , inr ⋆) r = inr (Ξ» p β†’ 𝟘-elim (+disjoint (III₆ p)))
   where
    III₃ : (p : P)
         β†’ Ξ£ x κž‰ ⟨ πŸ™β‚’ Γ—β‚’ πŸšβ‚’ ⟩ ,
             (x β‰ΊβŸ¨ πŸ™β‚’ Γ—β‚’ πŸšβ‚’ ⟩ (⋆ , inr ⋆)) Γ— (f x = (inr p , inl ⋆))
    III₃ p = simulations-are-initial-segments (Ξ± Γ—β‚’ Ξ³) (Ξ² Γ—β‚’ Ξ³) f f-sim
               (⋆ , inr ⋆) (inr p , inl ⋆)
               (transport⁻¹ (Ξ» - β†’ (inr p , inl ⋆) β‰ΊβŸ¨ Ξ² Γ—β‚’ Ξ³ ⟩ - ) r (inl ⋆))
    IIIβ‚„ : (p : P)
         β†’ Ξ£ x κž‰ ⟨ πŸ™β‚’ Γ—β‚’ πŸšβ‚’ ⟩ ,
             (x β‰ΊβŸ¨ πŸ™β‚’ Γ—β‚’ πŸšβ‚’ ⟩ (⋆ , inr ⋆)) Γ— (f x = (inr p , inl ⋆))
         β†’ f (⋆ , inl ⋆) = (inr p , inl ⋆)
    IIIβ‚„ p ((⋆ , inl ⋆) , l , q) = q
    IIIβ‚„ p ((⋆ , inr ⋆) , l , q) = 𝟘-elim (irrefl (πŸ™β‚’ Γ—β‚’ πŸšβ‚’) (⋆ , inr ⋆) l)

    IIIβ‚… : (p : P) β†’ (inl ⋆ , inl ⋆) = (inr p , inl ⋆)
    IIIβ‚… p = (inl ⋆ , inl ⋆) =⟨ f-preserves-least ⁻¹ ⟩
             f (⋆ , inl ⋆)   =⟨ IIIβ‚„ p (III₃ p) ⟩
             (inr p , inl ⋆) ∎

    III₆ : (p : P) β†’ inl ⋆ = inr p
    III₆ p = ap pr₁ (IIIβ‚… p)

  III (inr p , c) r = inl p

EM-implies-Γ—β‚’-left-monotonicity
 : EM (𝓀 βŠ” π“₯)
 β†’ (Ξ± Ξ² : Ordinal 𝓀) (Ξ³ : Ordinal π“₯) β†’ Ξ± ⊴ Ξ² β†’ (Ξ± Γ—β‚’ Ξ³) ⊴ (Ξ² Γ—β‚’ Ξ³)
EM-implies-Γ—β‚’-left-monotonicity em Ξ± Ξ² Ξ³ (g , g-sim)
 = β‰Ό-gives-⊴ (Ξ± Γ—β‚’ Ξ³) (Ξ² Γ—β‚’ Ξ³)
             (EM-implies-order-preserving-gives-β‰Ό em (Ξ± Γ—β‚’ Ξ³)
                                                     (Ξ² Γ—β‚’ Ξ³)
                                                     (f , f-order-preserving))
  where
   f : ⟨  Ξ± Γ—β‚’ Ξ³ ⟩ β†’ ⟨ Ξ² Γ—β‚’ Ξ³ ⟩
   f (a , c) = (g a , c)

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

EM-implies-induced-⊴-on-Γ—β‚’ : EM 𝓀
                           β†’ (Ξ± Ξ² Ξ³ Ξ΄ : Ordinal 𝓀)
                           β†’ Ξ± ⊴ Ξ³ β†’ Ξ² ⊴ Ξ΄ β†’ (Ξ± Γ—β‚’ Ξ²) ⊴ (Ξ³ Γ—β‚’ Ξ΄)
EM-implies-induced-⊴-on-Γ—β‚’ em Ξ± Ξ² Ξ³ Ξ΄ 𝕗 π•˜ =
 ⊴-trans (Ξ± Γ—β‚’ Ξ²) (Ξ± Γ—β‚’ Ξ΄) (Ξ³ Γ—β‚’ Ξ΄)
         (Γ—β‚’-right-monotone-⊴ Ξ± Ξ² Ξ΄ π•˜)
         (EM-implies-Γ—β‚’-left-monotonicity em Ξ± Ξ³ Ξ΄ 𝕗)

\end{code}

To prove that multiplication is left cancellable, we require the following
technical lemma: if Ξ± > 𝟘, then every simulation from Ξ± Γ—β‚’ Ξ² to Ξ± Γ—β‚’ Ξ³ + Ξ± ↓ a₁
firstly never hits the second summand, and secondly, in the first component, it
decomposes as the identity on the first component and a function Ξ² β†’ Ξ³ on the
second component, viz. one that is independent of the first component. The
inspiration for this lemma is the lemma simulation-product-decomposition below,
which only deals with simulations f : Ξ± Γ—β‚’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ³ (ie, with Ξ± ↓ a₁ = πŸ˜β‚’ in
the context of the current lemma). However the more general statement seems to
be necessary for proving left cancellability with respect to ⊴, rather than
just with respect to =.

\begin{code}

simulation-product-decomposition-generalized
 : (Ξ± : Ordinal 𝓀)
 β†’ πŸ˜β‚’ ⊲ Ξ±
 β†’ (Ξ² Ξ³ : Ordinal 𝓀)
 β†’ (a₁ : ⟨ Ξ± ⟩)
 β†’ ((f , _) : Ξ± Γ—β‚’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁))
 β†’ Ξ£ g κž‰ (⟨ Ξ² ⟩ β†’ ⟨ Ξ³ ⟩) , ((a : ⟨ Ξ± ⟩) (b : ⟨ Ξ² ⟩) β†’ f (a , b) = inl (a , g b))
simulation-product-decomposition-generalized {𝓀} Ξ± (aβ‚€ , aβ‚€-least) = II
 where
  P : Ordinal 𝓀 β†’ 𝓀 ⁺ Μ‡
  P Ξ² =   (Ξ³ : Ordinal 𝓀) (a₁ : ⟨ Ξ± ⟩)
          ((f , _) : Ξ± Γ—β‚’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁))
        β†’ (b : ⟨ Ξ² ⟩) β†’ Ξ£ c κž‰ ⟨ Ξ³ ⟩ , ((a : ⟨ Ξ± ⟩) β†’ f (a , b) = inl (a , c))

  Pβ‚€ : Ordinal 𝓀 β†’ 𝓀 ⁺ Μ‡
  Pβ‚€ Ξ² =   (a₁ : ⟨ Ξ± ⟩) (Ξ³ : Ordinal 𝓀)
           ((f , _) : Ξ± Γ—β‚’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁))
           (b : ⟨ β ⟩)
           (x : ⟨ (Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁) ⟩)
         β†’ f (aβ‚€ , b) = x
         β†’ Ξ£ c κž‰ ⟨ Ξ³ ⟩ , f (aβ‚€ , b) = inl (aβ‚€ , c)

  I : (Ξ² Ξ³ : Ordinal 𝓀) (a₁ : ⟨ Ξ± ⟩)
      ((f , _) : Ξ± Γ—β‚’ Ξ² ⊴ (Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁))
      (b : ⟨ β ⟩)
    β†’ Ξ± Γ—β‚’ (Ξ² ↓ b) = Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ f (aβ‚€ , b)
  I Ξ² Ξ³ a₁ 𝕗@(f , f-sim) b =
   Ξ± Γ—β‚’ (Ξ² ↓ b)                      =⟨ I₁ ⟩
   Ξ± Γ—β‚’ (Ξ² ↓ b) +β‚’ (Ξ± ↓ aβ‚€)          =⟨ Γ—β‚’-↓ Ξ± Ξ² ⁻¹ ⟩
   Ξ± Γ—β‚’ Ξ² ↓ (aβ‚€ , b)                 =⟨ Iβ‚‚ ⟩
   Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ f (aβ‚€ , b)   ∎
    where
     I₁ = πŸ˜β‚’-right-neutral
             (Ξ± Γ—β‚’ (Ξ² ↓ b)) ⁻¹ βˆ™ ap (Ξ± Γ—β‚’ (Ξ² ↓ b) +β‚’_)
             aβ‚€-least
     Iβ‚‚ = simulations-preserve-↓ _ _ 𝕗 (aβ‚€ , b)

  π•˜β‚ : (Ξ² : Ordinal 𝓀)
     β†’ ((b : ⟨ Ξ² ⟩) β†’ P (Ξ² ↓ b))
     β†’ Pβ‚€ Ξ²
  π•˜β‚ Ξ² IH a₁ Ξ³ 𝕗@(f , _) b (inl (a' , c)) e = c , III
    where
     eq = Ξ± Γ—β‚’ (Ξ² ↓ b)                      =⟨ I Ξ² Ξ³ a₁ 𝕗 b ⟩
          Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ f (aβ‚€ , b)   =⟨ ap ((Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁)) ↓_) e ⟩
          Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ inl (a' , c) =⟨ +β‚’-↓-left (a' , c) ⁻¹ ⟩
          Ξ± Γ—β‚’ Ξ³ ↓ (a' , c)                 =⟨ Γ—β‚’-↓ Ξ± Ξ³ ⟩
          Ξ± Γ—β‚’ (Ξ³ ↓ c) +β‚’ (Ξ± ↓ a')          ∎

     𝕗' :  Ξ± Γ—β‚’ (Ξ² ↓ b) ⊴ Ξ± Γ—β‚’ (Ξ³ ↓ c) +β‚’ (Ξ± ↓ a')
     f' = Idtofunβ‚’ eq
     𝕗' = f' , Idtofunβ‚’-is-simulation eq

     𝕗'⁻¹ : Ξ± Γ—β‚’ (Ξ³ ↓ c) +β‚’ (Ξ± ↓ a') ⊴ Ξ± Γ—β‚’ (Ξ² ↓ b)
     f'⁻¹ = Idtofunβ‚’ (eq ⁻¹)
     𝕗'⁻¹ = f'⁻¹ , Idtofunβ‚’-is-simulation (eq ⁻¹)

     II : a' = aβ‚€
     II = Extensionality Ξ± a' aβ‚€
           (Ξ» x l β†’ 𝟘-elim (II₁ x l))
           (Ξ» x l β†’ 𝟘-elim (transport⁻¹ ⟨_⟩ aβ‚€-least (x , l)))
      where
       II₁ : (x : ⟨ Ξ± ⟩) β†’ Β¬ (x β‰ΊβŸ¨ Ξ± ⟩ a')
       II₁ x l = +disjoint IIβ‚‚
        where
         y : ⟨ Ξ± Γ—β‚’ (Ξ² ↓ b) ⟩
         y = f'⁻¹ (inr (x , l))
         y₁ = pr₁ y
         yβ‚‚ = prβ‚‚ y

         z : ⟨ Ξ³ ↓ c ⟩
         z = pr₁ (IH b (Ξ³ ↓ c) a' 𝕗' yβ‚‚)

         IIβ‚‚ = inl (y₁ , z)            =⟨ prβ‚‚ (IH b (Ξ³ ↓ c) a' 𝕗' yβ‚‚) y₁ ⁻¹ ⟩
               f' (f'⁻¹ (inr (x , l))) =⟨ Idtofunβ‚’-retraction eq (inr (x , l)) ⟩
               inr (x , l)             ∎

     III = f (aβ‚€ , b)   =⟨ e ⟩
           inl (a' , c) =⟨ ap (Ξ» - β†’ inl (- , c)) II ⟩
           inl (aβ‚€ , c) ∎

  π•˜β‚ Ξ² _ a₁ Ξ³ 𝕗@(f , f-sim) b (inr (x , p)) e = 𝟘-elim (Ξ½ (a₁ , refl))
   where
    eq-I = Ξ± Γ—β‚’ (Ξ² ↓ b)                     =⟨ I Ξ² Ξ³ a₁ 𝕗 b ⟩
           Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ f (aβ‚€ , b)  =⟨ ap ((Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁)) ↓_) e ⟩
           Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ inr (x , p) =⟨ +β‚’-↓-right (x , p) ⁻¹ ⟩
           Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁ ↓ (x , p))     =⟨ eq-I₁ ⟩
           Ξ± Γ—β‚’ Ξ³  +β‚’ (Ξ± ↓ x)               ∎
     where
      eq-I₁ = ap ((Ξ± Γ—β‚’ Ξ³) +β‚’_) (iterated-↓  Ξ± a₁ x p)

    eq-II = Ξ± Γ—β‚’ Ξ³ +β‚’ ((Ξ± ↓ x) +β‚’ Ξ±) =⟨ +β‚’-assoc (Ξ± Γ—β‚’ Ξ³) (Ξ± ↓ x) Ξ± ⁻¹ ⟩
            Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ x) +β‚’ Ξ±   =⟨ ap (_+β‚’ Ξ±) eq-I ⁻¹ ⟩
            Ξ± Γ—β‚’ (Ξ² ↓ b) +β‚’ Ξ±        =⟨ Γ—β‚’-successor Ξ± (Ξ² ↓ b) ⁻¹ ⟩
            Ξ± Γ—β‚’ ((Ξ² ↓ b) +β‚’ πŸ™β‚’)      ∎

    ineq-I : Ξ± Γ—β‚’ Ξ³ +β‚’ ((Ξ± ↓ x) +β‚’ Ξ±) ⊴ Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁)
    ineq-I = transport⁻¹
              (Ξ» - β†’ - ⊴ Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁))
              eq-II
              (⊴-trans
               (Ξ± Γ—β‚’ ((Ξ² ↓ b) +β‚’ πŸ™β‚’))
               (Ξ± Γ—β‚’ Ξ²)
               (Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁))
               (Γ—β‚’-right-monotone-⊴ Ξ± ((Ξ² ↓ b) +β‚’ πŸ™β‚’) Ξ²
                 (upper-bound-of-successors-of-initial-segments Ξ² b))
               𝕗)

    ineq-II : (Ξ± ↓ x) +β‚’ Ξ± ⊴ Ξ± ↓ a₁
    ineq-II = +β‚’-left-reflects-⊴ (Ξ± Γ—β‚’ Ξ³) ((Ξ± ↓ x) +β‚’ Ξ±) (Ξ± ↓ a₁) ineq-I

    h : ⟨ Ξ± ⟩ β†’ ⟨ Ξ± ↓ a₁ ⟩
    h a = [ (Ξ± ↓ x) +β‚’ Ξ± ,  Ξ± ↓ a₁ ]⟨ ineq-II ⟩ (inr a)

    h-order-preserving : is-order-preserving Ξ± (Ξ± ↓ a₁) h
    h-order-preserving a a' l =
     simulations-are-order-preserving
      ((Ξ± ↓ x) +β‚’ Ξ±)
      (Ξ± ↓ a₁)
      [ (Ξ± ↓ x) +β‚’ Ξ± ,  Ξ± ↓ a₁ ]⟨ ineq-II ⟩
      ([ (Ξ± ↓ x) +β‚’ Ξ± ,  Ξ± ↓ a₁ ]⟨ ineq-II ⟩-is-simulation)
      (inr a) (inr a') l

    Ξ½ : Β¬ (Ξ± ↓ a₁ ⊲ Ξ±)
    Ξ½ = order-preserving-gives-not-⊲ Ξ± (Ξ± ↓ a₁)
         (h , h-order-preserving)

  π•˜β‚‚ : (Ξ² : Ordinal 𝓀)
     β†’ ((b : ⟨ Ξ² ⟩) β†’ P (Ξ² ↓ b))
     β†’ P Ξ²
  π•˜β‚‚ Ξ² IH Ξ³ a₁ 𝕗@(f , f-sim) b = c , c-satisfies-equation
   where
    c : ⟨ γ ⟩
    c = pr₁ (π•˜β‚ Ξ² IH a₁ Ξ³ 𝕗 b (f (aβ‚€ , b)) refl)

    c-spec : f (aβ‚€ , b) = inl (aβ‚€ , c)
    c-spec = prβ‚‚ (π•˜β‚ Ξ² IH a₁ Ξ³ 𝕗 b (f (aβ‚€ , b)) refl)

    c-satisfies-equation : (a : ⟨ Ξ± ⟩) β†’ f (a , b) = inl (a , c)
    c-satisfies-equation a = ↓-lc (Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁)) _ _ eq-II
     where
      eq-I = Ξ± Γ—β‚’ (Ξ² ↓ b)                      =⟨ I Ξ² Ξ³ a₁ 𝕗 b ⟩
             Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ f (aβ‚€ , b)   =⟨ eq-I₁ ⟩
             Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ inl (aβ‚€ , c) =⟨ +β‚’-↓-left (aβ‚€ , c) ⁻¹ ⟩
             Ξ± Γ—β‚’ Ξ³ ↓ (aβ‚€ , c)                 =⟨ Γ—β‚’-↓ Ξ± Ξ³ ⟩
             Ξ± Γ—β‚’ (Ξ³ ↓ c) +β‚’ (Ξ± ↓ aβ‚€)          =⟨ eq-Iβ‚‚ ⟩
             Ξ± Γ—β‚’ (Ξ³ ↓ c)                      ∎
       where
        eq-I₁ = ap (((Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁)) ↓_) c-spec
        eq-Iβ‚‚ = ap ((Ξ± Γ—β‚’ (Ξ³ ↓ c)) +β‚’_) aβ‚€-least ⁻¹
                βˆ™ πŸ˜β‚’-right-neutral (Ξ± Γ—β‚’ (Ξ³ ↓ c))

      eq-II = Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ f (a , b)   =⟨ eq-II₁ ⟩
              Ξ± Γ—β‚’ Ξ² ↓ (a , b)                 =⟨ Γ—β‚’-↓ Ξ± Ξ² ⟩
              Ξ± Γ—β‚’ (Ξ² ↓ b) +β‚’ (Ξ± ↓ a)          =⟨ ap (_+β‚’ (Ξ± ↓ a)) eq-I ⟩
              Ξ± Γ—β‚’ (Ξ³ ↓ c) +β‚’ (Ξ± ↓ a)          =⟨ Γ—β‚’-↓ Ξ± Ξ³ ⁻¹ ⟩
              Ξ± Γ—β‚’ Ξ³ ↓ (a , c)                 =⟨ +β‚’-↓-left (a , c) ⟩
              Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁) ↓ inl (a , c) ∎
       where
        eq-II₁ = (simulations-preserve-↓ _ _ 𝕗 (a , b)) ⁻¹

  π•˜ : (Ξ² : Ordinal 𝓀) β†’ P Ξ²
  π•˜ = transfinite-induction-on-OO P π•˜β‚‚

  II : (Ξ² Ξ³ : Ordinal 𝓀)
     β†’ (a₁ : ⟨ Ξ± ⟩)
     β†’ ((f , _) : Ξ± Γ—β‚’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a₁))
     β†’ Ξ£ g κž‰ (⟨ Ξ² ⟩ β†’ ⟨ Ξ³ ⟩) ,
        ((a : ⟨ Ξ± ⟩) (b : ⟨ Ξ² ⟩) β†’ f (a , b) = inl (a , g b))
  II Ξ² Ξ³ a₁ 𝕗 = (Ξ»   b β†’ pr₁ (π•˜ Ξ² Ξ³ a₁ 𝕗 b)) ,
                (Ξ» a b β†’ prβ‚‚ (π•˜ Ξ² Ξ³ a₁ 𝕗 b) a)

Γ—β‚’-left-cancellable-⊴-generalized : (Ξ± Ξ² Ξ³ : Ordinal 𝓀) (a₁ : ⟨ Ξ± ⟩)
                                  β†’ πŸ˜β‚’ ⊲ Ξ±
                                  β†’ Ξ± Γ—β‚’ Ξ² ⊴ (Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁)
                                  β†’ Ξ² ⊴ Ξ³
Γ—β‚’-left-cancellable-⊴-generalized Ξ± Ξ² Ξ³ a₁ p@(aβ‚€ , aβ‚€-least) 𝕗@(f , f-sim) =
 (g , g-is-initial-segment , g-is-order-preserving)
 where
  g : ⟨ Ξ² ⟩ β†’ ⟨ Ξ³ ⟩
  g = pr₁ (simulation-product-decomposition-generalized Ξ± p Ξ² Ξ³ a₁ 𝕗)

  g-property : (a : ⟨ Ξ± ⟩) (b : ⟨ Ξ² ⟩) β†’ f (a , b) = inl (a , g b)
  g-property = prβ‚‚ (simulation-product-decomposition-generalized Ξ± p Ξ² Ξ³ a₁ 𝕗)

  g-is-order-preserving : is-order-preserving Ξ² Ξ³ g
  g-is-order-preserving b b' l = III II
   where
    I : f (aβ‚€ , b) β‰ΊβŸ¨ (Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁) ⟩ f (aβ‚€ , b')
    I = simulations-are-order-preserving _ _ f f-sim (aβ‚€ , b) (aβ‚€ , b') (inl l)

    II : inl (aβ‚€ , g b) β‰ΊβŸ¨ (Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁) ⟩ inl (aβ‚€ , g b')
    II = transportβ‚‚ (Ξ» x y β†’ x β‰ΊβŸ¨ ((Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁))⟩ y)
                    (g-property aβ‚€ b)
                    (g-property aβ‚€ b')
                    I

    III : (aβ‚€ , g b) β‰ΊβŸ¨ (Ξ± Γ—β‚’ Ξ³) ⟩ (aβ‚€ , g b') β†’ g b β‰ΊβŸ¨ Ξ³ ⟩ g b'
    III (inl p) = p
    III (inr (r , q)) = 𝟘-elim (irrefl Ξ± aβ‚€ q)

  g-is-initial-segment : is-initial-segment Ξ² Ξ³ g
  g-is-initial-segment b c l = b' , II k , III
   where
    l₁ : inl (aβ‚€ , c) β‰ΊβŸ¨ (Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁) ⟩ inl (aβ‚€ , g b)
    l₁ = inl l

    lβ‚‚ : inl (aβ‚€ , c) β‰ΊβŸ¨ (Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁) ⟩ f (aβ‚€ , b)
    lβ‚‚ = transport⁻¹ (Ξ» - β†’ inl (aβ‚€ , c) β‰ΊβŸ¨ ((Ξ± Γ—β‚’ Ξ³) +β‚’ (Ξ± ↓ a₁))⟩ -)
                     (g-property aβ‚€ b)
                     l₁

    Οƒ : Ξ£ y κž‰ ⟨ Ξ± Γ—β‚’ Ξ² ⟩ , (y β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ² ⟩ (aβ‚€ , b)) Γ— (f y = (inl (aβ‚€ , c)))
    Οƒ = simulations-are-initial-segments _ _ f f-sim (aβ‚€ , b) (inl (aβ‚€ , c)) lβ‚‚
    a' = pr₁ (pr₁ Οƒ)
    b' = prβ‚‚ (pr₁ Οƒ)
    k  = pr₁ (prβ‚‚ Οƒ)
    e  = prβ‚‚ (prβ‚‚ Οƒ)

    II : (a' , b') β‰ΊβŸ¨ Ξ± Γ—β‚’ Ξ² ⟩ (aβ‚€ , b) β†’ b' β‰ΊβŸ¨ Ξ² ⟩ b
    II (inl p) = p
    II (inr (r , q)) = 𝟘-elim (Idtofunβ‚’ (aβ‚€-least ⁻¹) (a' , q))

    III : g b' = c
    III = ap prβ‚‚ (inl-lc (inl (a' , g b') =⟨ g-property a' b' ⁻¹ ⟩
                          f (a' , b')     =⟨ e ⟩
                          inl (aβ‚€ , c)    ∎))

Γ—β‚’-left-cancellable-⊴ : (Ξ± Ξ² Ξ³ : Ordinal 𝓀)
                      β†’ πŸ˜β‚’ ⊲ Ξ±
                      β†’ (Ξ± Γ—β‚’ Ξ²) ⊴ (Ξ± Γ—β‚’ Ξ³)
                      β†’ Ξ² ⊴ Ξ³
Γ—β‚’-left-cancellable-⊴ Ξ± Ξ² Ξ³ p@(aβ‚€ , aβ‚€-least) 𝕗 =
 Γ—β‚’-left-cancellable-⊴-generalized Ξ± Ξ² Ξ³ aβ‚€ p
  (transport (Ξ± Γ—β‚’ Ξ² ⊴_)
             (Ξ± Γ—β‚’ Ξ³             =⟨ πŸ˜β‚’-right-neutral (Ξ± Γ—β‚’ Ξ³) ⁻¹ ⟩
              Ξ± Γ—β‚’ Ξ³ +β‚’ πŸ˜β‚’       =⟨ ap ((Ξ± Γ—β‚’ Ξ³) +β‚’_) aβ‚€-least ⟩
              Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ aβ‚€) ∎)
             𝕗)

\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 {𝓀 = 𝓀} Ξ± Ξ² Ξ³ p e = ⊴-antisym Ξ² Ξ³ (f Ξ² Ξ³ e) (f Ξ³ Ξ² (e ⁻¹))
 where
  f : (Ξ² Ξ³ : Ordinal 𝓀) β†’ (Ξ± Γ—β‚’ Ξ²) = (Ξ± Γ—β‚’ Ξ³) β†’ Ξ² ⊴ Ξ³
  f Ξ² Ξ³ e = Γ—β‚’-left-cancellable-⊴ Ξ± Ξ² Ξ³ p (≃ₒ-to-⊴ (Ξ± Γ—β‚’ Ξ²) (Ξ± Γ—β‚’ Ξ³)
                                                   (idtoeqβ‚’ (Ξ± Γ—β‚’ Ξ²) (Ξ± Γ—β‚’ Ξ³) e))

\end{code}

As mentioned above, the generalized decomposition lemma for simulation from a
product was inspired by the following less general lemma for which we give both
an indirect and a direct proof (with more general universe levels).

\begin{code}

simulation-product-decomposition' : (Ξ± Ξ² Ξ³ : Ordinal 𝓀)
                                    ((aβ‚€ , aβ‚€-least) : πŸ˜β‚’ ⊲ Ξ±)
                                    ((f , _) : (Ξ± Γ—β‚’ Ξ²) ⊴ (Ξ± Γ—β‚’ Ξ³))
                                    (a : ⟨ α ⟩) (b : ⟨ β ⟩)
                                  β†’ f (a , b) = (a , prβ‚‚ (f (aβ‚€ , b)))
simulation-product-decomposition' Ξ± Ξ² Ξ³ (aβ‚€ , aβ‚€-least) 𝕗@(f , f-sim) a = III
  where
   𝕗' : Ξ± Γ—β‚’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a)
   𝕗' = ⊴-trans (Ξ± Γ—β‚’ Ξ²) (Ξ± Γ—β‚’ Ξ³) (Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a))
                𝕗
                (+β‚’-left-⊴ (Ξ± Γ—β‚’ Ξ³) (Ξ± ↓ a))
   f' = [ Ξ± Γ—β‚’ Ξ² , Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a) ]⟨ 𝕗' ⟩

   I : Ξ£ g κž‰ (⟨ Ξ² ⟩ β†’ ⟨ Ξ³ ⟩) ,
        ((a' : ⟨ Ξ± ⟩) (b : ⟨ Ξ² ⟩) β†’ f' (a' , b) = inl (a' , g b))
   I = simulation-product-decomposition-generalized Ξ± (aβ‚€ , aβ‚€-least) Ξ² Ξ³ a 𝕗'

   g = pr₁ I
   g-property = prβ‚‚ I

   II : (b : ⟨ Ξ² ⟩) β†’ g b = prβ‚‚ (f (aβ‚€ , b))
   II b = ap prβ‚‚ (inl-lc (inl (aβ‚€ , g b)   =⟨ (g-property aβ‚€ b) ⁻¹ ⟩
                          f' (aβ‚€ , b)      =⟨refl⟩
                          inl (f (aβ‚€ , b)) ∎))

   III : (b : ⟨ β ⟩)
       β†’ f (a , b) = a , prβ‚‚ (f (aβ‚€ , b))
   III b =
    inl-lc (inl (f (a , b))            =⟨ g-property a b ⟩
            inl (a , g b)              =⟨ ap (Ξ» - β†’ inl (a , -)) (II b) ⟩
            inl (a , prβ‚‚ (f (aβ‚€ , b))) ∎)

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}

Using similar techniques, we can also prove that multiplication is
left cancellable with respect to ⊲.

\begin{code}

simulation-product-decomposition-leftover-empty
 : (Ξ± Ξ² Ξ³ : Ordinal 𝓀)
 β†’ πŸ˜β‚’ ⊲ Ξ±
 β†’ (a : ⟨ Ξ± ⟩)
 β†’ (Ξ± Γ—β‚’ Ξ²) = (Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a))
 β†’ (Ξ± Γ—β‚’ Ξ²) = (Ξ± Γ—β‚’ Ξ³)
simulation-product-decomposition-leftover-empty Ξ± Ξ² Ξ³ (aβ‚€ , p) a e = II
 where
  a-least : (x : ⟨ Ξ± ⟩) β†’ Β¬ (x β‰ΊβŸ¨ Ξ± ⟩ a)
  a-least x l = +disjoint (ν ⁻¹)
   where
    𝕗 : Ξ± Γ—β‚’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a)
    f = Idtofunβ‚’ e
    𝕗 = f , Idtofunβ‚’-is-simulation e

    𝕗⁻¹ : Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a) ⊴ Ξ± Γ—β‚’ Ξ²
    f⁻¹ = Idtofunβ‚’ (e ⁻¹)
    𝕗⁻¹ = f⁻¹ , Idtofunβ‚’-is-simulation (e ⁻¹)

    f-decomposition
     : Ξ£ g κž‰ (⟨ Ξ² ⟩ β†’ ⟨ Ξ³ ⟩) ,
        ((a : ⟨ Ξ± ⟩) (b : ⟨ Ξ² ⟩) β†’ f (a , b) = inl (a , g b) )
    f-decomposition =
      simulation-product-decomposition-generalized Ξ± (aβ‚€ , p) Ξ² Ξ³ a 𝕗

    g = pr₁ f-decomposition

    Ξ½ = (inr (x , l))         =⟨ (Idtofunβ‚’-retraction e (inr (x , l))) ⁻¹ ⟩
        f (f⁻¹ (inr (x , l))) =⟨ prβ‚‚ (f-decomposition) x' y' ⟩
        inl (x' , g y')       ∎
     where
      x' = pr₁ (f⁻¹ (inr (x , l)))
      y' = prβ‚‚ (f⁻¹ (inr (x , l)))

  I : a = aβ‚€
  I = Extensionality Ξ± a aβ‚€ (Ξ» x l β†’ 𝟘-elim (a-least x l))
                            (Ξ» x l β†’ 𝟘-elim (Idtofunβ‚’ (p ⁻¹) (x , l)))

  II = Ξ± Γ—β‚’ Ξ²            =⟨ e ⟩
       Ξ± Γ—β‚’ Ξ³ +β‚’ (Ξ± ↓ a) =⟨ ap ((Ξ± Γ—β‚’ Ξ³) +β‚’_) (ap (Ξ± ↓_) I βˆ™ p ⁻¹) ⟩
       Ξ± Γ—β‚’ Ξ³ +β‚’ πŸ˜β‚’      =⟨ πŸ˜β‚’-right-neutral (Ξ± Γ—β‚’ Ξ³) ⟩
       Ξ± Γ—β‚’ Ξ³            ∎

Γ—β‚’-left-cancellable-⊲ : (Ξ± Ξ² Ξ³ : Ordinal 𝓀)
                      β†’ πŸ˜β‚’ ⊲ Ξ±
                      β†’ Ξ± Γ—β‚’ Ξ² ⊲ Ξ± Γ—β‚’ Ξ³
                      β†’ Ξ² ⊲ Ξ³
Γ—β‚’-left-cancellable-⊲ Ξ± Ξ² Ξ³ Ξ±-positive ((a , c) , p) = c , III
 where
  I : Ξ± Γ—β‚’ Ξ² = Ξ± Γ—β‚’ (Ξ³ ↓ c) +β‚’ (Ξ± ↓ a)
  I = p βˆ™ Γ—β‚’-↓ Ξ± Ξ³

  II : Ξ± Γ—β‚’ Ξ² = Ξ± Γ—β‚’ (Ξ³ ↓ c)
  II = simulation-product-decomposition-leftover-empty Ξ± Ξ² (Ξ³ ↓ c) Ξ±-positive a I

  III : Ξ² = Ξ³ ↓ c
  III = Γ—β‚’-left-cancellable Ξ± Ξ² (Ξ³ ↓ c) Ξ±-positive II

\end{code}

Added 15 July 2025 by Tom de Jong.

Updated 6 October 2026 by Tom de Jong to reflect that we can even restrict to
ordinals with a trichotomous least element.

\begin{code}

Γ—β‚’-as-large-as-right-factor-implies-EM'
 : ((Ξ± Ξ² : Ordinal 𝓀) β†’ has-trichotomous-least-element Ξ±
                      β†’ has-trichotomous-least-element Ξ²
                      β†’ πŸ˜β‚’ ⊲ Ξ± β†’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ²)
 β†’ EM 𝓀
Γ—β‚’-as-large-as-right-factor-implies-EM' hyp P P-is-prop = IV (f (inr ⋆)) refl
 where
  Pβ‚’ = prop-ordinal P P-is-prop
  Ξ± = πŸ™β‚’ +β‚’ Pβ‚’
  Ξ² = πŸšβ‚’
  𝕗 : Ξ² ⊴ Ξ± Γ—β‚’ Ξ²
  𝕗 = hyp Ξ± Ξ²
          (decomposable-to-trichotomous-least Ξ± (Pβ‚’ , refl))
          (decomposable-to-trichotomous-least Ξ² (πŸ™β‚’ , refl))
          (inl ⋆ , (πŸ™β‚’-↓ ⁻¹ βˆ™ +β‚’-↓-left ⋆))
  f = [ Ξ² , Ξ± Γ—β‚’ Ξ² ]⟨ 𝕗 ⟩
  f-is-sim : is-simulation Ξ² (Ξ± Γ—β‚’ Ξ²) f
  f-is-sim = [ Ξ² , Ξ± Γ—β‚’ Ξ² ]⟨ 𝕗 ⟩-is-simulation

  I : (p : P) β†’ f (inr ⋆) = (inr p , inl ⋆)
  I p = ↓-lc (Ξ± Γ—β‚’ Ξ²) (f (inr ⋆)) (inr p , inl ⋆) e
   where
    e = (Ξ± Γ—β‚’ Ξ²) ↓ f (inr ⋆)            =⟨ e₁ ⟩
        Ξ² ↓ inr ⋆                       =⟨ eβ‚‚ ⟩
        πŸ™β‚’                              =⟨ e₃ ⟩
        Ξ± ↓ inr p                       =⟨ eβ‚„ ⟩
        Ξ± Γ—β‚’ πŸ˜β‚’ +β‚’ (Ξ± ↓ inr p)          =⟨ eβ‚… ⟩
        Ξ± Γ—β‚’ (Ξ² ↓ inl ⋆) +β‚’ (Ξ± ↓ inr p) =⟨ Γ—β‚’-↓ Ξ± Ξ² ⁻¹ ⟩
        (Ξ± Γ—β‚’ Ξ²) ↓ (inr p , inl ⋆)      ∎
     where
      e₁ = (simulations-preserve-↓ Ξ² (Ξ± Γ—β‚’ Ξ²) 𝕗 (inr ⋆)) ⁻¹
      eβ‚‚ = +β‚’-↓-right ⋆ ⁻¹ βˆ™ ap (πŸ™β‚’ +β‚’_) πŸ™β‚’-↓ βˆ™ πŸ˜β‚’-right-neutral πŸ™β‚’
      e₃ = (πŸ˜β‚’-right-neutral πŸ™β‚’) ⁻¹
           βˆ™ ap (πŸ™β‚’ +β‚’_) ((prop-ordinal-↓ P-is-prop p) ⁻¹) βˆ™ +β‚’-↓-right p
      eβ‚„ = (ap (_+β‚’ (Ξ± ↓ inr p)) (Γ—β‚’-πŸ˜β‚’-right Ξ±)
           βˆ™ πŸ˜β‚’-left-neutral (Ξ± ↓ inr p)) ⁻¹
      eβ‚… = ap (Ξ» - β†’ Ξ± Γ—β‚’ - +β‚’ (Ξ± ↓ inr p)) (πŸ™β‚’-↓ ⁻¹ βˆ™ +β‚’-↓-left ⋆)
  II : (x : ⟨ Ξ± ⟩) β†’ f (inr ⋆) = (x , inr ⋆) β†’ Β¬ P
  II x e p = +disjoint (ap prβ‚‚ ((I p) ⁻¹ βˆ™ e))
  III : f (inr ⋆) β‰  (inl ⋆ , inl ⋆)
  III h = +disjoint (simulations-are-lc Ξ² (Ξ± Γ—β‚’ Ξ²) f f-is-sim (e βˆ™ h ⁻¹))
   where
    e : f (inl ⋆) = (inl ⋆ , inl ⋆)
    e = simulations-preserve-least
         Ξ² (Ξ± Γ—β‚’ Ξ²) (inl ⋆) (inl ⋆ , inl ⋆) f f-is-sim
         Ξ²-least
         (Γ—β‚’-least Ξ± Ξ² (inl ⋆) (inl ⋆) (+β‚’-least πŸ™β‚’ Pβ‚’ ⋆ πŸ™β‚’-least) Ξ²-least)
     where
      Ξ²-least : is-least Ξ² (inl ⋆)
      Ξ²-least = +β‚’-least πŸ™β‚’ πŸ™β‚’ ⋆ πŸ™β‚’-least
  IV : (x : ⟨ Ξ± Γ—β‚’ Ξ² ⟩) β†’ f (inr ⋆) = x β†’ P + Β¬ P
  IV (inl ⋆ , inl ⋆) e = 𝟘-elim (III e)
  IV (inr p , inl ⋆) e = inl p
  IV (inl ⋆ , inr ⋆) e = inr (II (inl ⋆) e)
  IV (inr p , inr ⋆) e = inl p

Γ—β‚’-as-large-as-right-factor-implies-EM
 : ((Ξ± Ξ² : Ordinal 𝓀) β†’ πŸ˜β‚’ ⊲ Ξ± β†’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ²) β†’ EM 𝓀
Γ—β‚’-as-large-as-right-factor-implies-EM  hyp =
 Γ—β‚’-as-large-as-right-factor-implies-EM' (Ξ» Ξ± Ξ² _ _ β†’ hyp Ξ± Ξ²)

EM-implies-Γ—β‚’-as-large-as-right-factor
 : EM 𝓀
 β†’ (Ξ± Ξ² : Ordinal 𝓀) β†’ πŸ˜β‚’ ⊲ Ξ± β†’ Ξ² ⊴ Ξ± Γ—β‚’ Ξ²
EM-implies-Γ—β‚’-as-large-as-right-factor em Ξ± Ξ² (aβ‚€ , _) =
 β‰Ό-gives-⊴ Ξ² (Ξ± Γ—β‚’ Ξ²)
             (EM-implies-order-preserving-gives-β‰Ό em Ξ² (Ξ± Γ—β‚’ Ξ²) (f , I))
  where
   f : ⟨ Ξ² ⟩ β†’ ⟨ Ξ± Γ—β‚’ Ξ² ⟩
   f b = (aβ‚€ , b)
   I : is-order-preserving Ξ² (Ξ± Γ—β‚’ Ξ²) f
   I b b' l = inl l

\end{code}

Added in September 2025 by Fredrik Nordvall Forsberg.
Moved here from ArithmeticReflection by Tom de Jong in October 2025.

Some special cases of multiplication by Ο‰.

\begin{code}

πŸ™β‚’Γ—β‚’Ο‰-is-Ο‰ : πŸ™β‚’ Γ—β‚’ Ο‰ = Ο‰
πŸ™β‚’Γ—β‚’Ο‰-is-Ο‰ = πŸ™β‚’-left-neutral-Γ—β‚’ Ο‰

πŸšβ‚’Γ—β‚’Ο‰-is-Ο‰ : πŸšβ‚’ Γ—β‚’ Ο‰ = Ο‰
πŸšβ‚’Γ—β‚’Ο‰-is-Ο‰ = eqtoidβ‚’ (ua _) fe' (πŸšβ‚’ Γ—β‚’ Ο‰) Ο‰ h
 where
  open import Naturals.Addition hiding (_+_)
  open import Naturals.Division
  open import Naturals.Order
  open import Naturals.Double

  f : ⟨ πŸšβ‚’ ⟩ Γ— β„• β†’ β„•
  f (inl ⋆ , n) = double n
  f (inr ⋆ , n) = sdouble n

  g' : (n : β„•) β†’ division-theorem n 1 β†’ ⟨ πŸšβ‚’ ⟩ Γ— β„•
  g' n (k , 0 , p , l) = inl ⋆ , k
  g' n (k , 1 , p , l) = inr ⋆ , k
  g' n (k , succ (succ j) , p , l) = 𝟘-elim l

  g : β„• β†’ ⟨ πŸšβ‚’ ⟩ Γ— β„•
  g n = g' n (division n 1)

  f-equiv : is-equiv f
  f-equiv = qinvs-are-equivs f (g , (Ξ· , Ο΅))
   where
    Ξ·' : (x : ⟨ πŸšβ‚’ ⟩ Γ— β„•)(m : β„•) β†’ m = f x β†’ (d : division-theorem m 1)
       β†’ g' m d = x
    Ξ·' (inl ⋆ , n) m r (k , 0 , p , l) = ap (inl ⋆ ,_) (double-lc Ο„)
     where
      Ο„ : double k = double n
      Ο„ = double-is-self-addition k βˆ™ p ⁻¹ βˆ™ r
    Ξ·' (inr ⋆ , n) m r (k , 0 , p , l) = 𝟘-elim (double-is-not-sdouble Ο„)
     where
      Ο„ : double k = sdouble n
      Ο„ = double-is-self-addition k βˆ™ p ⁻¹  βˆ™ r
    Ξ·' (inl ⋆ , n) m r (k , 1 , p , l) = 𝟘-elim (double-is-not-sdouble Ο„)
     where
      Ο„ : double n = sdouble k
      Ο„ = r ⁻¹ βˆ™ p βˆ™ ap succ (double-is-self-addition k ⁻¹)
    Ξ·' (inr ⋆ , n) m r (k , 1 , p , l) = ap (inr ⋆ ,_) (sdouble-lc Ο„)
     where
      Ο„ : sdouble k = sdouble n
      Ο„ = ap succ (double-is-self-addition k) βˆ™ p ⁻¹ βˆ™ r

    Ξ·' (inl ⋆ , n) m r (k , succ (succ j) , p , l) = 𝟘-elim l
    Ξ·' (inr ⋆ , n) m r (k , succ (succ j) , p , l) = 𝟘-elim l

    Ξ· : (Ξ» x β†’ g (f x)) ∼ id
    Ξ· x = Ξ·' x (f x) refl (division (f x) 1)

    Ο΅' : (n : β„•) β†’ (d : division-theorem n 1) β†’ f (g' n d) = n
    Ο΅' n (k , 0 , refl , l) = double-is-self-addition k
    Ο΅' n (k , 1 , refl , l) = ap succ (double-is-self-addition k)
    ϡ' n (k , succ (succ j) , p , l) = 𝟘-elim l

    Ο΅ : (Ξ» n β†’ f (g n)) ∼ id
    Ο΅ n = Ο΅' n (division n 1)

  f-preserves-order : (x y : ⟨ πŸšβ‚’ ⟩ Γ— β„•) β†’ x β‰ΊβŸ¨ πŸšβ‚’ Γ—β‚’ Ο‰ ⟩ y β†’ f x β‰ΊβŸ¨ Ο‰ ⟩ f y
  f-preserves-order (inl ⋆ , x) (inl ⋆ , y) (inl p) =
   transport₂⁻¹ (Ξ» - β†’ succ - ≀ℕ_)
                (double-is-self-addition x)
                (double-is-self-addition y)
                (≀-adding x y (succ x) y (≀-trans x (succ x) y (≀-succ x) p) p)
  f-preserves-order (inl ⋆ , x) (inr ⋆ , y) (inl p) =
   transport₂⁻¹ _≀ℕ_ (double-is-self-addition x) (double-is-self-addition y)
    (≀-adding x y x y (≀-trans x (succ x) y (≀-succ x) p)
                      (≀-trans x (succ x) y (≀-succ x) p))
  f-preserves-order (inr ⋆ , x) (inl ⋆ , y) (inl p) =
   transport₂⁻¹ (Ξ» - β†’ succ - ≀ℕ_)
                (ap succ (double-is-self-addition x) βˆ™ succ-left x x ⁻¹)
                (double-is-self-addition y)
                (≀-adding (succ x) y (succ x) y p p)
  f-preserves-order (inr ⋆ , x) (inr ⋆ , y) (inl p) =
   transport₂⁻¹ (Ξ» - β†’ succ - ≀ℕ_)
                (double-is-self-addition x)
                (double-is-self-addition y)
                (≀-adding x y (succ x) y (≀-trans x (succ x) y (≀-succ x) p) p)
  f-preserves-order (inl ⋆ , x) (inl ⋆ , y) (inr (refl , q)) = 𝟘-elim q
  f-preserves-order (inl ⋆ , x) (inr ⋆ , x) (inr (refl , _)) = ≀-refl _
  f-preserves-order (inr ⋆ , x) (inl ⋆ , x) (inr (refl , q)) = 𝟘-elim q
  f-preserves-order (inr ⋆ , x) (inr ⋆ , x) (inr (refl , q)) = 𝟘-elim q

  f-reflects-order : (x y : ⟨ πŸšβ‚’ ⟩ Γ— β„•) β†’ f x β‰ΊβŸ¨ Ο‰ ⟩ f y β†’ x β‰ΊβŸ¨ πŸšβ‚’ Γ—β‚’ Ο‰ ⟩ y
  f-reflects-order (inl ⋆ , x) (inl ⋆ , y) p = inl (double-reflects-< p)
  f-reflects-order (inl ⋆ , x) (inr ⋆ , y) p = Ο„ (<-trichotomous x y)
   where
    Ο„ : (x <β„• y) + (x = y) + (y <β„• x) β†’ (x <β„• y) + (x = y) Γ— πŸ™
    Ο„ (inl l) = inl l
    Ο„ (inr (inl e)) = inr (e , ⋆)
    Ο„ (inr (inr g)) =
     𝟘-elim (less-than-not-equal y y (<-≀-trans y x y g (double-reflects-≀ p)) refl)
  f-reflects-order (inr ⋆ , x) (inl ⋆ , y) p = inl (double-reflects-≀ p)
  f-reflects-order (inr ⋆ , x) (inr ⋆ , y) p = inl (double-reflects-< p)

  h : (πŸšβ‚’ Γ—β‚’ Ο‰) ≃ₒ Ο‰
  h = f , order-preserving-reflecting-equivs-are-order-equivs (πŸšβ‚’ Γ—β‚’ Ο‰) Ο‰ f
           f-equiv f-preserves-order f-reflects-order

\end{code}