Martin Escardo, 25th August 2022,
written down in Agda 27th August 2022 while travelling back from
Thierry Coquand's 60th birthday celebration.

The type of ordinals is decomposable as a disjoint union of two
pointed types if and only if weak excluded middle holds (every negated
proposition is decidable, which is equivalent to De Morgan's Law).

Equivalently, there is a function f : Ordinal 𝓀 β†’ 𝟚 such that f Ξ± = 0
and f Ξ² = 1 for some ordinals Ξ± and Ξ² if and only if weak excluded
middle holds.

In other words, the type Ordinal 𝓀 has no non-trivial decidable
property unless weak excluded middle holds.

Further additions 3rd August 2023.

\begin{code}

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

open import UF.FunExt

module Taboos.Decomposability (fe : FunExt) where

open import MLTT.Spartan
open import MLTT.Two-Properties
open import Ordinals.Arithmetic fe
open import Ordinals.Equivalence
open import Ordinals.Maps
open import Ordinals.Type
open import Ordinals.Underlying
open import UF.Base
open import UF.ClassicalLogic
open import UF.Classifiers
open import UF.Equiv
open import UF.Equiv-FunExt
open import UF.EquivalenceExamples
open import UF.PropTrunc
open import UF.Size
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.SubtypeClassifier
open import UF.SubtypeClassifier-Properties
open import UF.Univalence

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

 ⇁_ : Ξ© 𝓀 β†’ Ξ© 𝓀
 ⇁_ = not fe'

\end{code}

A type X is decomposable if there are pointed types Xβ‚€ and X₁ with
X ≃ Xβ‚€ + X₁. Equivalently, X is decomposable if there is a
non-constant function f : X β†’ 𝟚, in the strong sense that there are xβ‚€
and x₁ in X that are mapped to respectively β‚€ and ₁ by f.

We first work with the type of all decompositions, in the above two
equivalent manifestations, and later we consider decomposability
defined as its propositional truncation.

\begin{code}

decomposition : 𝓀 Μ‡ β†’ 𝓀 Μ‡
decomposition X = Ξ£ f κž‰ (X β†’ 𝟚) , (Ξ£ xβ‚€ κž‰ X , f xβ‚€ = β‚€) Γ— (Ξ£ x₁ κž‰ X , f x₁ = ₁)

decomposition' : 𝓀 Μ‡ β†’ 𝓀 ⁺ Μ‡
decomposition' {𝓀} X = Ξ£ Y κž‰ (𝟚 β†’ 𝓀 Μ‡ ) , (Y β‚€ + Y ₁ ≃ X) Γ— Y β‚€ Γ— Y ₁

\end{code}

We remark that the above two decomposition types are equivalent, but
we don't use this fact anywhere for the moment, and we work with the
first one.

\begin{code}

decomposition-lemma : is-univalent 𝓀
                    β†’ (X : 𝓀 Μ‡ )
                    β†’ (Ξ£ Y κž‰ (𝟚 β†’ 𝓀 Μ‡ ) , (Y β‚€ + Y ₁ ≃ X))
                    ≃ (X β†’ 𝟚)
decomposition-lemma {𝓀} ua X =
 (Ξ£ Y κž‰ (𝟚 β†’ 𝓀 Μ‡ ) , (Y β‚€ + Y ₁ ≃ X))       β‰ƒβŸ¨ I ⟩
 (Ξ£ Y κž‰ (𝟚 β†’ 𝓀 Μ‡ ) , ((Ξ£ n κž‰ 𝟚 , Y n) ≃ X)) β‰ƒβŸ¨ II ⟩
 (X β†’ 𝟚)                                    β– 
 where
  I  = Ξ£-cong (Ξ» Y β†’ ≃-cong-left fe (≃-sym alternative-+))
  II = Ξ£-fibers-≃ ua fe'

decompositions-agree : is-univalent 𝓀
                     β†’ (X : 𝓀 Μ‡ )
                     β†’ decomposition X ≃ decomposition' X
decompositions-agree {𝓀} ua X =
 (Ξ£ f κž‰ (X β†’ 𝟚) , fiber f β‚€ Γ— fiber f ₁)                        β‰ƒβŸ¨ I ⟩
 (Ξ£ (Y , _) κž‰ (Ξ£ Y κž‰ (𝟚 β†’ 𝓀 Μ‡ ) , (Y β‚€ + Y ₁ ≃ X)) , Y β‚€ Γ— Y ₁)  β‰ƒβŸ¨ II ⟩
 (Ξ£ Y κž‰ (𝟚 β†’ 𝓀 Μ‡ ) , (Y β‚€ + Y ₁ ≃ X) Γ— Y β‚€ Γ— Y ₁)                β– 
 where
  I  = Ξ£-change-of-variable-≃ _ (≃-sym (decomposition-lemma ua X))
  II = Ξ£-assoc

WEM-gives-decomposition-of-two-pointed-types : WEM 𝓀
                                             β†’ (X : 𝓀 Μ‡ )
                                             β†’ has-two-distinct-points X
                                             β†’ decomposition X
WEM-gives-decomposition-of-two-pointed-types wem X ((xβ‚€ , x₁) , d) = Ξ³
 where
  g : (x : X) β†’ Β¬ (x β‰  xβ‚€) + ¬¬ (x β‰  xβ‚€) β†’ 𝟚
  g x (inl _) = β‚€
  g x (inr _) = ₁

  h : (x : X) β†’ Β¬ (x β‰  xβ‚€) + ¬¬ (x β‰  xβ‚€)
  h x = wem (x β‰  xβ‚€)

  f : X β†’ 𝟚
  f x = g x (h x)

  gβ‚€ : (Ξ΄ : Β¬ (xβ‚€ β‰  xβ‚€) + ¬¬ (xβ‚€ β‰  xβ‚€)) β†’ g xβ‚€ Ξ΄ = β‚€
  gβ‚€ (inl _) = refl
  gβ‚€ (inr u) = 𝟘-elim (three-negations-imply-one u refl)

  eβ‚€ : f xβ‚€ = β‚€
  eβ‚€ = gβ‚€ (h xβ‚€)

  g₁ : (Ξ΄ : Β¬ (x₁ β‰  xβ‚€) + ¬¬ (x₁ β‰  xβ‚€)) β†’ g x₁ Ξ΄ = ₁
  g₁ (inl Ο•) = 𝟘-elim (Ο• (β‰ -sym d))
  g₁ (inr _) = refl

  e₁ : f x₁ = ₁
  e₁ = g₁ (h x₁)

  Ξ³ : decomposition X
  Ξ³ = f , (xβ‚€ , eβ‚€) , (x₁ , e₁)

WEM-gives-decomposition-of-ordinals-type⁺ : WEM (𝓀 ⁺)
                                          β†’ decomposition (Ordinal 𝓀)
WEM-gives-decomposition-of-ordinals-type⁺ {𝓀} wem =
 WEM-gives-decomposition-of-two-pointed-types wem (Ordinal 𝓀)
  ((πŸ™β‚’ , πŸ˜β‚’) , (Ξ» (e : πŸ™β‚’ = πŸ˜β‚’) β†’ 𝟘-elim (idtofun πŸ™ 𝟘 (ap ⟨_⟩ e) ⋆)))

\end{code}

We can strengthen the hypothesis of the above implication to WEM 𝓀
using the fact that the type Ordinal 𝓀 Μ‡ is locally small.

\begin{code}

WEM-gives-decomposition-of-two-pointed-types⁺ : WEM 𝓀
                                              β†’ (X : 𝓀 ⁺ Μ‡ )
                                              β†’ is-locally-small X
                                              β†’ has-two-distinct-points X
                                              β†’ decomposition X
WEM-gives-decomposition-of-two-pointed-types⁺ {𝓀} wem X l ((xβ‚€ , x₁) , d) = Ξ³
 where
  g : (x : X) β†’ Β¬ (x β‰ βŸ¦ l ⟧ xβ‚€) + ¬¬ (x β‰ βŸ¦ l ⟧ xβ‚€) β†’ 𝟚
  g x (inl _) = β‚€
  g x (inr _) = ₁

  h : (x : X) β†’ Β¬ (x β‰ βŸ¦ l ⟧ xβ‚€) + ¬¬ (x β‰ βŸ¦ l ⟧ xβ‚€)
  h x = wem (x β‰ βŸ¦ l ⟧ xβ‚€)

  f : X β†’ 𝟚
  f x = g x (h x)

  gβ‚€ : (Ξ΄ : Β¬ (xβ‚€ β‰ βŸ¦ l ⟧ xβ‚€) + ¬¬ (xβ‚€ β‰ βŸ¦ l ⟧ xβ‚€)) β†’ g xβ‚€ Ξ΄ = β‚€
  gβ‚€ (inl _) = refl
  gβ‚€ (inr u) = 𝟘-elim (three-negations-imply-one u =⟦ l ⟧-refl)

  eβ‚€ : f xβ‚€ = β‚€
  eβ‚€ = gβ‚€ (h xβ‚€)

  g₁ : (Ξ΄ : Β¬ (x₁ β‰ βŸ¦ l ⟧ xβ‚€) + ¬¬ (x₁ β‰ βŸ¦ l ⟧ xβ‚€)) β†’ g x₁ Ξ΄ = ₁
  g₁ (inl Ο•) = 𝟘-elim (Ο• (β‰ -gives-β‰ βŸ¦ l ⟧ (β‰ -sym d)))
  g₁ (inr _) = refl

  e₁ : f x₁ = ₁
  e₁ = g₁ (h x₁)

  Ξ³ : decomposition X
  Ξ³ = f , (xβ‚€ , eβ‚€) , (x₁ , e₁)

WEM-gives-decomposition-of-ordinals-type : is-univalent 𝓀
                                         β†’ WEM 𝓀
                                         β†’ decomposition (Ordinal 𝓀)
WEM-gives-decomposition-of-ordinals-type {𝓀} ua wem =
 WEM-gives-decomposition-of-two-pointed-types⁺ wem (Ordinal 𝓀)
  (the-type-of-ordinals-is-locally-small ua fe')
  ((πŸ™β‚’ , πŸ˜β‚’) , (Ξ» (e : πŸ™β‚’ = πŸ˜β‚’) β†’ 𝟘-elim (idtofun πŸ™ 𝟘 (ap ⟨_⟩ e) ⋆)))

\end{code}

For the converse, we use the following notion, where Ξ© 𝓀 is the type
of truth values, or propositions, in the universe 𝓀. An Ξ©-path from x
to y in a type X is a function f κž‰ Ξ© π“₯ β†’ X that maps false to x and
true to y. We collect all such functions in a type Ξ©-Path π“₯ x y.

\begin{code}

Ξ©-Path : {X : 𝓀 Μ‡ } (π“₯ : Universe) β†’ X β†’ X β†’ 𝓀 βŠ” (π“₯ ⁺) Μ‡
Ξ©-Path {𝓀} {X} π“₯ x y = Ξ£ f κž‰ (Ξ© π“₯ β†’ X) , (f βŠ₯ = x) Γ— (f ⊀ = y)

\end{code}

The type of ordinals in any universe has Ξ©-paths between any two points.

\begin{code}

has-Ξ©-paths : (π“₯ : Universe) β†’ 𝓀 Μ‡ β†’ 𝓀 βŠ” (π“₯ ⁺) Μ‡
has-Ξ©-paths π“₯ X = (x y : X) β†’ Ξ©-Path π“₯ x y

type-of-ordinals-has-Ξ©-paths : is-univalent 𝓀
                             β†’ has-Ξ©-paths 𝓀 (Ordinal 𝓀)
type-of-ordinals-has-Ξ©-paths {𝓀} ua Ξ± Ξ² = f , Ξ³βŠ₯ , γ⊀
 where

  f : Ξ© 𝓀 β†’ Ordinal 𝓀
  f p = (Ξ©-to-ordinal (⇁ p) Γ—β‚’ Ξ±) +β‚’ (Ξ©-to-ordinal p Γ—β‚’ Ξ²)

  Ξ³βŠ₯ : f βŠ₯ = Ξ±
  Ξ³βŠ₯ = eqtoidβ‚’ ua fe' (f βŠ₯) Ξ± (u , o , e , p)
   where
    u : ⟨ f βŠ₯ ⟩ β†’ ⟨ Ξ± ⟩
    u (inl (x , a)) = a

    o : is-order-preserving (f βŠ₯) Ξ± u
    o (inl (x , a)) (inl (y , b)) (inl l) = l

    v : ⟨ Ξ± ⟩ β†’ ⟨ f βŠ₯ ⟩
    v a = inl (𝟘-elim , a)

    vu : v ∘ u ∼ id
    vu (inl (x , a)) = ap inl (to-Γ—-= (dfunext fe' (Ξ» z β†’ 𝟘-elim z)) refl)

    uv : u ∘ v ∼ id
    uv a = refl

    e : is-equiv u
    e = qinvs-are-equivs u (v , vu , uv)

    p : is-order-preserving Ξ± (f βŠ₯) v
    p a b l = inl l

  γ⊀ : f ⊀ = β
  γ⊀ = eqtoidβ‚’ ua fe' (f ⊀) Ξ² (u , o , e , p)
   where
    u : ⟨ f ⊀ ⟩ β†’ ⟨ Ξ² ⟩
    u (inl (f , _)) = 𝟘-elim (f ⋆)
    u (inr (⋆ , b)) = b

    o : is-order-preserving (f ⊀) β u
    o (inl (f , _)) y l = 𝟘-elim (f ⋆)
    o (inr (⋆ , _)) (inr (⋆ , _)) (inl l) = l

    v : ⟨ Ξ² ⟩ β†’ ⟨ f ⊀ ⟩
    v b = inr (⋆ , b)

    vu : v ∘ u ∼ id
    vu (inl (f , _)) = 𝟘-elim (f ⋆)
    vu (inr (⋆ , b)) = refl

    uv : u ∘ v ∼ id
    uv b = refl

    e : is-equiv u
    e = qinvs-are-equivs u (v , vu , uv)

    p : is-order-preserving β (f ⊀) v
    p b c l = inl l

decomposition-of-Ξ©-gives-WEM : propext 𝓀
                             β†’ decomposition (Ξ© 𝓀)
                             β†’ WEM 𝓀
decomposition-of-Ξ©-gives-WEM
  {𝓀} pe (f , (pβ‚€@(Pβ‚€ , iβ‚€) , eβ‚€) , (p₁@(P₁ , i₁) , e₁)) = V
 where
  g : Ξ© 𝓀 β†’ Ξ© 𝓀
  g (Q , j) = ((Pβ‚€ Γ— Q) + (P₁ Γ— Β¬ Q)) , k
   where
    k : is-prop ((Pβ‚€ Γ— Q) + (P₁ Γ— Β¬ Q))
    k = +-is-prop
         (Γ—-is-prop iβ‚€ j)
         (Γ—-is-prop i₁ (negations-are-props fe'))
         (Ξ» (pβ‚€ , q) (p₁ , Ξ½) β†’ Ξ½ q)

  Iβ‚€ : (q : Ξ© 𝓀) β†’ q holds β†’ f (g q) = β‚€
  Iβ‚€ q h = II
   where
    I : g q = pβ‚€
    I = to-subtype-=
          (Ξ» _ β†’ being-prop-is-prop fe')
          (pe (prβ‚‚ (g q)) iβ‚€
            (cases pr₁ (Ξ» (_ , n) β†’ 𝟘-elim (n h)))
            (Ξ» x β†’ inl (x , h)))

    II = f (g q) =⟨ ap f I ⟩
         f pβ‚€    =⟨ eβ‚€ ⟩
         β‚€       ∎

  I₁ : (q : Ξ© 𝓀) β†’ Β¬ (q holds) β†’ f (g q) = ₁
  I₁ q n = II
   where
    I : g q = p₁
    I = to-subtype-=
          (Ξ» _ β†’ being-prop-is-prop fe')
          (pe (prβ‚‚ (g q)) i₁
          (cases (Ξ» (_ , h) β†’ 𝟘-elim (n h)) pr₁)
          (Ξ» x β†’ inr (x , n)))

    II = f (g q) =⟨ ap f I ⟩
         f p₁    =⟨ e₁ ⟩
         ₁       ∎

  IIIβ‚€ : (q : Ξ© 𝓀) β†’ f (g q) = β‚€ β†’ Β¬ (q holds) + ¬¬ (q holds)
  IIIβ‚€ q e = inr (contrapositive (I₁ q) (equal-β‚€-different-from-₁ e))

  III₁ : (q : Ξ© 𝓀) β†’ f (g q) = ₁ β†’ Β¬ (q holds) + ¬¬ (q holds)
  III₁ q e = inl (contrapositive (Iβ‚€ q) (equal-₁-different-from-β‚€ e))

  IV : (Q : 𝓀  Μ‡ ) β†’ is-prop Q β†’ Β¬ Q + ¬¬ Q
  IV Q j = 𝟚-equality-cases (IIIβ‚€ (Q , j)) (III₁ (Q , j))

  V : (Q : 𝓀  Μ‡ ) β†’ Β¬ Q + ¬¬ Q
  V = WEM'-gives-WEM fe' IV

decomposition-of-type-with-Ξ©-paths-gives-WEM : propext π“₯
                                             β†’ {X : 𝓀 Μ‡ }
                                             β†’ decomposition X
                                             β†’ has-Ξ©-paths π“₯ X
                                             β†’ WEM π“₯
decomposition-of-type-with-Ξ©-paths-gives-WEM
  {π“₯} {𝓀} pe {X} (f , (xβ‚€ , eβ‚€) , (x₁ , e₁)) c = Ξ³
 where
  g : Ξ© π“₯ β†’ X
  g = pr₁ (c xβ‚€ x₁)

  gp : (g βŠ₯ = xβ‚€) Γ— (g ⊀ = x₁)
  gp = prβ‚‚ (c xβ‚€ x₁)

  Iβ‚€ = f (g βŠ₯) =⟨ ap f (pr₁ gp) ⟩
       f xβ‚€    =⟨ eβ‚€ ⟩
       β‚€       ∎

  I₁ = f (g ⊀) =⟨ ap f (prβ‚‚ gp) ⟩
       f x₁    =⟨ e₁ ⟩
       ₁       ∎

  Ξ³ : WEM π“₯
  Ξ³ = decomposition-of-Ξ©-gives-WEM pe (f ∘ g , (βŠ₯ , Iβ‚€) , (⊀ , I₁))

decomposition-of-ordinals-type-gives-WEM : is-univalent 𝓀
                                         β†’ decomposition (Ordinal 𝓀)
                                         β†’ WEM 𝓀
decomposition-of-ordinals-type-gives-WEM ua d =
 decomposition-of-type-with-Ξ©-paths-gives-WEM
  (univalence-gives-propext ua)
  d
  (type-of-ordinals-has-Ξ©-paths ua)

Ordinal-decomposition-iff-WEM : is-univalent 𝓀
                              β†’ decomposition (Ordinal 𝓀) ↔ WEM 𝓀
Ordinal-decomposition-iff-WEM ua =
 decomposition-of-ordinals-type-gives-WEM ua ,
 WEM-gives-decomposition-of-ordinals-type ua

\end{code}

We now assume that propositional truncations exist to define
decomposability as the truncation of the type of decompositions. It is
a corollary of the above development that the decomposability of the
type of ordinals gives a specific decomposition.

\begin{code}

module decomposability (pt : propositional-truncations-exist) where

 open PropositionalTruncation pt

 decomposable : 𝓀 Μ‡ β†’ 𝓀 Μ‡
 decomposable X = βˆ₯ decomposition X βˆ₯

 Ordinal-decomposable-iff-WEM : is-univalent 𝓀
                              β†’ decomposable (Ordinal 𝓀) ↔ WEM 𝓀
 Ordinal-decomposable-iff-WEM ua =
  βˆ₯βˆ₯-rec (WEM-is-prop fe) (decomposition-of-ordinals-type-gives-WEM ua) ,
  (Ξ» wem β†’ ∣ WEM-gives-decomposition-of-ordinals-type ua wem ∣)

 decomposability-gives-decomposition : is-univalent 𝓀
                                     β†’ decomposable (Ordinal 𝓀)
                                     β†’ decomposition (Ordinal 𝓀)
 decomposability-gives-decomposition ua Ξ΄ =
  WEM-gives-decomposition-of-ordinals-type ua
   (lr-implication (Ordinal-decomposable-iff-WEM ua) Ξ΄)

\end{code}

Notice that the formulation of this fact doesn't refer to WEM, but its
proof uses WEM, which follows from the hypothesis. Even though the
types decomposable (Ordinal 𝓀) and WEM are property, we get data out
of them if we are given a proof of decomposability.


Added 9th September 2022 by Tom de Jong (which is subsumed by a remark
below added 25th July 2024).

After a discussion with MartΓ­n on 8th September 2022, we noticed that
the decomposability theorem can be generalised from Ord 𝓀 to any
locally small 𝓀-sup-lattice with two distinct points. (This is indeed
a generalisation because Ord 𝓀 is a locally small 𝓀-sup-lattice, at
least in the presence of small set quotients or set replacement, see
Ordinals.OrdinalOfOrdinalsSuprema.)

One direction is still given by the lemma above:
  WEM-gives-decomposition-of-two-pointed-types⁺ :
      WEM 𝓀
    β†’ (X : 𝓀 ⁺ Μ‡ )
    β†’ is-locally-small X
    β†’ has-two-distinct-points X
    β†’ decomposition X

[NB. Predicatively, nontrivial 𝓀-sup-lattices necessarily have large
     carriers [dJE21,dJE22], so that the simpler lemma

     WEM-gives-decomposition-of-two-pointed-types :
         WEM 𝓀
       β†’ (X : 𝓀 Μ‡ )
       β†’ has-two-distinct-points X
       β†’ decomposition X

     is not sufficient.]

For the other we use

  decomposition-of-type-with-Ξ©-paths-gives-WEM :
      {X : 𝓀 Μ‡ }
    β†’ decomposition X
    β†’ has-Ξ©-paths π“₯ X
    β†’ WEM π“₯

The point is that every 𝓀-sup-lattice X has Ω𝓀-paths, because given x
y : X, we can define f : Ξ© 𝓀 β†’ X by mapping a proposition P to the
join of the family

  Ξ΄ : πŸ™ + P β†’ X
  Ξ΄(inl ⋆) = x;
  Ξ΄(inr p) = y.

The family Ξ΄ also plays a key role in [dJE21,dJE22] although we have
the restriction that x βŠ‘ y in those papers, because we consider a
broader collection of posets there that includes the 𝓀-sup-lattices,
but also 𝓀-bounded-complete posets and 𝓀-directed complete posets.

References
----------

[dJE21] Tom de Jong and MartΓ­n HΓΆtzel EscardΓ³.
        β€˜Predicative Aspects of Order Theory in Univalent Foundations’.
        In: 6th International Conference on Formal Structures for Computation and
        Deduction (FSCD 2021). Ed. by Naoki Kobayashi. Vol. 195.
        Leibniz International Proceedings in Informatics (LIPIcs).
        Schloss Dagstuhl–Leibniz-Zentrum fΓΌr Informatik, 2021, 8:1–8:18.
        doi: 10.4230/LIPIcs.FSCD.2021.8.

[dJE22] Tom de Jong and MartΓ­n HΓΆtzel EscardΓ³.
        β€˜On Small Types in Univalent Foundations’. Sept. 2022.
        arXiv: 2111.00482 [cs.LO]. Revised and expanded version of [dJE21b].
        Accepted pending minor revision to a special issue of Logical Methods in
        Computer Science on selected papers from FSCD 2021.

TODO. Implement the above thoughts.

Added 3rd August 2023 by Martin Escardo. Injective types are
decomposable iff WEM holds. This subsumes the above developement,
because the type of ordinals is injective.

\begin{code}

open import InjectiveTypes.Blackboard fe
open import InjectiveTypes.OverSmallMaps fe
open import Ordinals.Injectivity

open ordinals-injectivity fe

\end{code}

A naive application of injectivity gives the following:

\begin{code}

ainjective-types-have-Ξ©-Paths-naive : propext 𝓦
                                    β†’ (D : 𝓀 Μ‡ )
                                    β†’ ainjective-type D 𝓀₀ (𝓦 ⁺)
                                    β†’ has-Ξ©-paths 𝓦 D
ainjective-types-have-Ξ©-Paths-naive {𝓦} {𝓀} pe D D-ainj xβ‚€ x₁ = II I
 where
  f : 𝟚 β†’ D
  f β‚€ = xβ‚€
  f ₁ = x₁

  I : Ξ£ g κž‰ (Ξ© 𝓦 β†’ D) , g ∘ 𝟚-to-Ξ© ∼ f
  I = D-ainj 𝟚-to-Ω (𝟚-to-Ω-is-embedding fe' pe) f

  II : type-of I β†’ Ξ©-Path 𝓦 xβ‚€ x₁
  II (g , h) = g , h β‚€ , h ₁

\end{code}

But this is too weak for applications, as the universe 𝓦⁺ is higher
than we can obtain in practice.

This can be improved as follows, exploiting the fact that the map
𝟚-to-Ξ© : 𝟚 β†’ Ξ© 𝓀 has 𝓀-small fibers and that algebraic flabbiness
gives injectivity over embeddings with small fibers for lower
universes. The key point is that this allows to replace 𝓦⁺ by 𝓦 in the
above, so that we can apply this to the injectivity of the universe
and to that of the type of ordinals, and more examples like these.

\begin{code}

ainjective-types-have-Ξ©-Paths : propext π“₯
                              β†’ (D : 𝓀 Μ‡ )
                              β†’ ainjective-type D π“₯ 𝓦
                              β†’ has-Ξ©-paths π“₯ D
ainjective-types-have-Ξ©-Paths {π“₯} {𝓀} {𝓦} pe D D-ainj xβ‚€ x₁ = II I
 where
  f : 𝟚 β†’ D
  f β‚€ = xβ‚€
  f ₁ = x₁

  I : Ξ£ g κž‰ (Ξ© π“₯ β†’ D) , g ∘ 𝟚-to-Ξ© ∼ f
  I = ainjectivity-over-small-maps {𝓀₀} {π“₯ ⁺} {𝓀} {π“₯} {π“₯} {𝓦}
       D
       D-ainj
       𝟚-to-Ω
       (𝟚-to-Ω-is-embedding fe' pe)
       (𝟚-to-Ξ©-is-small-map {π“₯} fe' pe)
       f

  II : type-of I β†’ Ξ©-Path π“₯ xβ‚€ x₁
  II (g , h) = g , h β‚€ , h ₁

decomposition-of-ainjective-type-gives-WEM : propext π“₯
                                           β†’ (D : 𝓀 Μ‡ )
                                           β†’ ainjective-type D π“₯ 𝓦
                                           β†’ decomposition D
                                           β†’ WEM π“₯
decomposition-of-ainjective-type-gives-WEM
 {π“₯} {𝓀} {𝓦} pe D D-ainj D-decomp =
  decomposition-of-type-with-Ξ©-paths-gives-WEM
   pe
   D-decomp
   (ainjective-types-have-Ξ©-Paths {π“₯} {𝓀} {𝓦} pe D D-ainj)

\end{code}

Examples:

\begin{code}

decomposition-of-universe-gives-WEM : is-univalent 𝓀
                                    β†’ decomposition (𝓀 Μ‡ )
                                    β†’ WEM 𝓀
decomposition-of-universe-gives-WEM {𝓀} ua =
 decomposition-of-ainjective-type-gives-WEM {𝓀} {𝓀 ⁺} {𝓀}
  (univalence-gives-propext ua)
  (𝓀 Μ‡ )
  (universes-are-ainjective-Ξ  ua)

decomposition-of-ordinals-type-gives-WEM-bis : is-univalent 𝓀
                                             β†’ decomposition (Ordinal 𝓀)
                                             β†’ WEM 𝓀
decomposition-of-ordinals-type-gives-WEM-bis {𝓀} ua =
 decomposition-of-ainjective-type-gives-WEM {𝓀} {𝓀 ⁺} {𝓀}
  (univalence-gives-propext ua)
  (Ordinal 𝓀)
  (Ordinal-is-ainjective ua)

\end{code}

Added by Martin Escardo and Tom de Jong 18th July 2024. We generalize
a fact given above from ordinals to injective types.

\begin{code}

module decomposability-bis (pt : propositional-truncations-exist) where

 open PropositionalTruncation pt
 open decomposability pt

 ainjective-type-decomposable-iff-WEM
  : propext 𝓀
  β†’ (D : 𝓀 Μ‡ )
  β†’ ainjective-type D 𝓀 π“₯
  β†’ has-two-distinct-points D
  β†’ decomposable D ↔ WEM 𝓀
 ainjective-type-decomposable-iff-WEM pe D D-ainj htdp =
  βˆ₯βˆ₯-rec
   (WEM-is-prop fe)
   (decomposition-of-ainjective-type-gives-WEM pe D D-ainj) ,
  (Ξ» wem β†’ ∣ WEM-gives-decomposition-of-two-pointed-types wem D htdp ∣)

\end{code}

Added 25th July 2024 by Tom de Jong and Martin Escardo.

The previous theorem, however, doesn't capture our examples of injective types. Indeed, the assumption that D : 𝓀 is injective with respect to 𝓀
and π“₯ is a bit unnatural, as all known examples of injective types are
large, e.g. the universe 𝓀 is injective w.r.t 𝓀 and 𝓀, as are the
ordinals in 𝓀 and the propositions in 𝓀. In fact, in
InjectiveTypes.Resizing we showed that such injective types are
necessarily large unless ꪪ-resizing holds. Therefore, we now improve
and generalize the above theorem to a large, but locally small,
type, so that all known examples are captured.

\begin{code}

 ainjective-type-decomposable-iff-WEM⁺
  : propext 𝓀
  β†’ (D : 𝓀 ⁺ Μ‡ )
  β†’ is-locally-small D
  β†’ ainjective-type D 𝓀 π“₯
  β†’ has-two-distinct-points D
  β†’ decomposable D ↔ WEM 𝓀
 ainjective-type-decomposable-iff-WEM⁺ pe D D-ls D-ainj htdp =
  βˆ₯βˆ₯-rec
   (WEM-is-prop fe)
   (decomposition-of-ainjective-type-gives-WEM pe D D-ainj) ,
  (Ξ» wem β†’ ∣ WEM-gives-decomposition-of-two-pointed-types⁺ wem D D-ls htdp ∣)

\end{code}

End of addition.

Notice that the following doesn't mention WEM in its statement, but
its proof does. Although the proof is constructive, the assumption is
necessarily non-constructive.

\begin{code}

 ainjective-type-decomposability-gives-decomposition
  : propext 𝓀
  β†’ (D : 𝓀 Μ‡ )
  β†’ ainjective-type D 𝓀 π“₯
  β†’ has-two-distinct-points D
  β†’ decomposable D
  β†’ decomposition D
 ainjective-type-decomposability-gives-decomposition pe D D-ainj htdp Ξ΄ =
  WEM-gives-decomposition-of-two-pointed-types
   (lr-implication (ainjective-type-decomposable-iff-WEM pe D D-ainj htdp) Ξ΄)
   D
   htdp

\end{code}

Also added 25th July 2024 for the same reason given above:

\begin{code}

 ainjective-type-decomposability-gives-decomposition⁺
  : propext 𝓀
  β†’ (D : 𝓀 ⁺ Μ‡ )
  β†’ is-locally-small D
  β†’ ainjective-type D 𝓀 π“₯
  β†’ has-two-distinct-points D
  β†’ decomposable D
  β†’ decomposition D
 ainjective-type-decomposability-gives-decomposition⁺ pe D D-ls D-ainj htdp δ =
  WEM-gives-decomposition-of-two-pointed-types⁺
   (lr-implication (ainjective-type-decomposable-iff-WEM⁺ pe D D-ls D-ainj htdp) δ)
   D
   D-ls
   htdp

\end{code}

Added by Martin Escardo 10th June 2024. From any non-trivial,
totally separated, injective type we get the double negation of the
principle of weak excluded middle. Here by non-trivial we mean that
not all two elements are equal, which means that the type is not a
proposition.

(Of course, "Ξ£" in the hypothesis can be replaced by "βˆƒ" because the
type of the conclusion, being a negation, is a proposition.)

\begin{code}

open import UF.Hedberg using (wconstant)
open import TypeTopology.TotallySeparated

non-trivial-totally-separated-ainjective-type-gives-¬¬-WEM
 : propext π“₯
 β†’ (Ξ£ X κž‰ 𝓀 Μ‡ , ((Β¬ is-prop X) Γ— is-totally-separated X Γ— ainjective-type X π“₯ 𝓦))
 β†’ ¬¬ WEM π“₯
non-trivial-totally-separated-ainjective-type-gives-¬¬-WEM
  {π“₯} {𝓀} {𝓦} pe (X , X-is-not-prop , X-is-totally-separated , X-ainj) = V
 where
  I : Β¬ decomposition X β†’ (p : X β†’ 𝟚) β†’ wconstant p
  I Ξ΄ p xβ‚€ x₁ = h (p xβ‚€) (p x₁) refl refl
   where
    h : (bβ‚€ b₁ : 𝟚) β†’ p xβ‚€ = bβ‚€ β†’ p x₁ = b₁ β†’ p xβ‚€ = p x₁
    h β‚€ β‚€ eβ‚€ e₁ = eβ‚€ βˆ™ e₁ ⁻¹
    h β‚€ ₁ eβ‚€ e₁ = 𝟘-elim (Ξ΄ (p , (xβ‚€ , eβ‚€) , (x₁ , e₁)))
    h ₁ β‚€ eβ‚€ e₁ = 𝟘-elim (Ξ΄ (p , (x₁ , e₁) , (xβ‚€ , eβ‚€)))
    h ₁ ₁ eβ‚€ e₁ = eβ‚€ βˆ™ e₁ ⁻¹

  II : ((p : X β†’ 𝟚) β†’ wconstant p) β†’ is-prop X
  II w xβ‚€ x₁ = X-is-totally-separated (Ξ» p β†’ w p xβ‚€ x₁)

  III : Β¬ decomposition X β†’ is-prop X
  III = II ∘ I

  IV : ¬¬ decomposition X
  IV = contrapositive III X-is-not-prop

  V : ¬¬ WEM π“₯
  V = ¬¬-functor
       (decomposition-of-ainjective-type-gives-WEM pe X X-ainj)
       IV

\end{code}

Notice that Β¬ WEM 𝓀 is consistent and hence ¬¬ WEM 𝓀 is not
provable. But of course ¬¬ WEM 𝓀 is consistent as it follows from WEM 𝓀,
which in turn follows from EM 𝓀.

More examples are included in Iterative.Multisets-Addendum and
Iterative.Sets-Addendum.