Tom de Jong, 1 and 4 April 2022.

\begin{code}

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

module Ordinals.Taboos where

open import MLTT.Plus-Properties
open import MLTT.Spartan hiding (𝟚 ; β‚€ ; ₁)
open import Ordinals.Equivalence
open import Ordinals.Maps
open import Ordinals.Notions
open import Ordinals.Type
open import Ordinals.Underlying
open import UF.DiscreteAndSeparated hiding (𝟚-is-discrete)
open import UF.Equiv
open import UF.EquivalenceExamples
open import UF.ClassicalLogic
open import UF.FunExt
open import UF.PropTrunc
open import UF.Size
open import UF.Subsingletons
open import UF.UA-FunExt
open import UF.Univalence

\end{code}

We show that two classically true statements about ordinals are constructively
unacceptable, because each of them implies excluded middle.

The first statement is that every discrete ordinal is trichotomous. Classically,
this is trivial, because every ordinal is trichotomous (and discrete).
Constructively, the converse (trichotomous implies discrete) *does* hold.

The second statement is that the supremum of a family of trichotomous ordinals
indexed by a discrete type is again discrete.

\begin{code}

Every-Discrete-Ordinal-Is-Trichotomous : (𝓀 : Universe) β†’ 𝓀 ⁺ Μ‡
Every-Discrete-Ordinal-Is-Trichotomous 𝓀 =
 ((Ξ± : Ordinal 𝓀) β†’ is-discrete ⟨ Ξ± ⟩
                  β†’ is-trichotomous-order (underlying-order Ξ±))

module suprema-of-ordinals-assumptions
        (pt : propositional-truncations-exist)
        (sr : Set-Replacement pt)
        (ua : Univalence)
       where

 open import Ordinals.OrdinalOfOrdinalsSuprema ua
 open suprema pt sr public

 Sups-Of-Discretely-Indexed-Trichotomous-Ordinals-Are-Discrete :
  (𝓀 : Universe) β†’ 𝓀 ⁺ Μ‡
 Sups-Of-Discretely-Indexed-Trichotomous-Ordinals-Are-Discrete 𝓀 =
  (I : 𝓀 Μ‡ ) β†’ is-discrete I β†’ (Ξ± : I β†’ Ordinal 𝓀)
             β†’ ((i : I) β†’ is-trichotomous-order (underlying-order (Ξ± i)))
             β†’ is-discrete ⟨ sup Ξ± ⟩

\end{code}

In showing that the first statement implies excluded middle, the two-element
type in some fixed but arbitrary universe 𝓀 will be useful.

\begin{code}

module _ {𝓀 : Universe} where

 𝟚 : 𝓀 Μ‡
 𝟚 = πŸ™ {𝓀} + πŸ™ {𝓀}

 pattern β‚€ = inl ⋆
 pattern ₁ = inr ⋆

 𝟚-is-discrete : is-discrete 𝟚
 𝟚-is-discrete = +-is-discrete πŸ™-is-discrete πŸ™-is-discrete

\end{code}

We now work towards proving that excluded middle follows from the assertion that
every discrete ordinal is trichotomous.

The outline of the proof is given here:
(1) Fix a type P and construct a transitive and well-founded relation β‰Ί on 𝟚
    involving P.
(2) If P is a proposition, then β‰Ί is prop-valued.
(3) If ¬¬ P holds, then β‰Ί is extensional.
(4) Hence, if P is a proposition such that ¬¬ P holds, then (𝟚 , β‰Ί) is a
    (discrete) ordinal.
(5) The order β‰Ί is trichotomous if and only if P holds.

Hence, if every discrete ordinal is trichotomous, then ¬¬ P β†’ P for every
proposition P, which is equivalent to excluded middle.

\begin{code}

module discrete-trichotomous-taboo-construction
        (P : 𝓀 Μ‡ )
       where

 _β‰Ί_ : 𝟚 {𝓀} β†’ 𝟚 {𝓀} β†’ 𝓀 Μ‡
 β‚€ β‰Ί β‚€ = 𝟘
 β‚€ β‰Ί ₁ = P
 ₁ β‰Ί β‚€ = 𝟘
 ₁ β‰Ί ₁ = 𝟘

 β‰Ί-is-prop-valued : is-prop P β†’ is-prop-valued _β‰Ί_
 β‰Ί-is-prop-valued i β‚€ β‚€ = 𝟘-is-prop
 β‰Ί-is-prop-valued i β‚€ ₁ = i
 β‰Ί-is-prop-valued i ₁ β‚€ = 𝟘-is-prop
 β‰Ί-is-prop-valued i ₁ ₁ = 𝟘-is-prop

 β‰Ί-is-transitive : transitive _β‰Ί_
 β‰Ί-is-transitive β‚€ ₁ β‚€ u v = v
 β‰Ί-is-transitive β‚€ ₁ ₁ u v = u
 β‰Ί-is-transitive ₁ β‚€ z u v = 𝟘-elim u
 β‰Ί-is-transitive ₁ ₁ z u v = 𝟘-elim u

 β‰Ί-well-founded-lemma : (y : 𝟚) β†’ y β‰Ί β‚€ β†’ is-accessible _β‰Ί_ y
 β‰Ί-well-founded-lemma β‚€ l = 𝟘-elim l
 β‰Ί-well-founded-lemma ₁ l = 𝟘-elim l

 β‰Ί-is-well-founded : is-well-founded _β‰Ί_
 β‰Ί-is-well-founded β‚€ = acc β‰Ί-well-founded-lemma
 β‰Ί-is-well-founded ₁ = acc Ξ³
  where
   Ξ³ : (y : 𝟚) β†’ y β‰Ί ₁ β†’ is-accessible _β‰Ί_ y
   Ξ³ β‚€ l = acc β‰Ί-well-founded-lemma

 β‰Ί-is-extensional : ¬¬ P β†’ is-extensional _β‰Ί_
 β‰Ί-is-extensional h β‚€ β‚€ u v = refl
 β‰Ί-is-extensional h ₁ ₁ u v = refl
 β‰Ί-is-extensional h β‚€ ₁ u v = 𝟘-elim (h Ξ³)
  where
   Ξ³ : Β¬ P
   Ξ³ p = 𝟘-elim (v β‚€ p)
 β‰Ί-is-extensional h ₁ β‚€ u v = 𝟘-elim (h Ξ³)
  where
   Ξ³ : Β¬ P
   Ξ³ p = 𝟘-elim (u β‚€ p)

 πŸšβ‰Ί-ordinal : is-prop P β†’ ¬¬ P β†’ Ordinal 𝓀
 πŸšβ‰Ί-ordinal i h = 𝟚 , _β‰Ί_ , β‰Ί-is-prop-valued i   , β‰Ί-is-well-founded
                          , β‰Ί-is-extensional h , β‰Ί-is-transitive

 β‰Ί-trichotomous-characterization : is-trichotomous-order _β‰Ί_ ↔ P
 β‰Ί-trichotomous-characterization = ⦅⇒⦆ , ⦅⇐⦆
  where
   ⦅⇐⦆ : P β†’ is-trichotomous-order _β‰Ί_
   ⦅⇐⦆ p β‚€ β‚€ = inr (inl refl)
   ⦅⇐⦆ p β‚€ ₁ = inl p
   ⦅⇐⦆ p ₁ β‚€ = inr (inr p)
   ⦅⇐⦆ p ₁ ₁ = inr (inl refl)
   ⦅⇒⦆ : is-trichotomous-order _β‰Ί_ β†’ P
   ⦅⇒⦆ t = lemma (t β‚€ ₁)
    where
     lemma : (β‚€ β‰Ί ₁) + (β‚€ = ₁) + (₁ β‰Ί β‚€) β†’ P
     lemma (inl p)       = p
     lemma (inr (inl e)) = 𝟘-elim (+disjoint e)
     lemma (inr (inr l)) = 𝟘-elim l

\end{code}

The above construction quickly yields the first promised result.

\begin{code}

DNE-if-Every-Discrete-Ordinal-Is-Trichotomous :
   Every-Discrete-Ordinal-Is-Trichotomous 𝓀
 β†’ DNE 𝓀
DNE-if-Every-Discrete-Ordinal-Is-Trichotomous h P P-is-prop not-not-P =
 lr-implication β‰Ί-trichotomous-characterization
                  (h (πŸšβ‰Ί-ordinal P-is-prop not-not-P) (𝟚-is-discrete))
  where
   open discrete-trichotomous-taboo-construction P

EM-if-Every-Discrete-Ordinal-Is-Trichotomous :
   funext 𝓀 𝓀₀
 β†’ Every-Discrete-Ordinal-Is-Trichotomous 𝓀
 β†’ EM 𝓀
EM-if-Every-Discrete-Ordinal-Is-Trichotomous fe h =
 DNE-gives-EM fe (DNE-if-Every-Discrete-Ordinal-Is-Trichotomous h)

\end{code}

It is somewhat more involved to get a taboo from the assertion that
discretely-indexed suprema of trichotomous ordinals are discrete.

The first step is fairly straightforward however and once again involves
constructing an ordinal that depends on a proposition P. What matters is that:
(1) the constructed ordinal is trichotomous;
(2) an initial segment of the ordinal is equivalent to P.

\begin{code}

module _
        (fe : FunExt)
       where

 open import Ordinals.Arithmetic fe
 open import Ordinals.WellOrderArithmetic

 module discrete-sup-taboo-construction-I
         (P : 𝓀 Μ‡ )
         (P-is-prop : is-prop P)
        where

  P' : Ordinal 𝓀
  P' = prop-ordinal P P-is-prop +β‚’ πŸ™β‚’

  P'-is-trichotomous : is-trichotomous-order (underlying-order P')
  P'-is-trichotomous = trichotomy-preservation (prop.trichotomous P P-is-prop)
                                               (prop.trichotomous πŸ™ πŸ™-is-prop)
   where
    open plus (prop.order P P-is-prop) (prop.order πŸ™ πŸ™-is-prop)

\end{code}

Next, we turn to the second part of our construction, which defines a
discretely-indexed family of trichotomous ordinals. To work with (suprema of)
ordinals, we need additional assumptions and imports.

\begin{code}

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

 open suprema-of-ordinals-assumptions pt sr ua

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

 open import NotionsOfDecidability.Decidable

 open import Ordinals.Arithmetic fe
 open import Ordinals.OrdinalOfOrdinals ua
 open import Ordinals.WellOrderArithmetic

 open import UF.Embeddings
 open import UF.ImageAndSurjection pt

 module discrete-sup-taboo-construction-II
          (P : 𝓀 Μ‡ )
          (P-is-prop : is-prop P)
         where

  open discrete-sup-taboo-construction-I fe P P-is-prop

  I : 𝓀 Μ‡
  I = 𝟚 {𝓀}

  Ξ± : I β†’ Ordinal 𝓀
  Ξ± β‚€ = P'
  Ξ± ₁ = πŸ™β‚’ +β‚’ πŸ™β‚’

  Ξ±-is-trichotomous : (i : I) β†’ is-trichotomous-order (underlying-order (Ξ± i))
  Ξ±-is-trichotomous β‚€ = P'-is-trichotomous
  Ξ±-is-trichotomous ₁ = trichotomy-preservation trichotomous trichotomous
   where
    open prop πŸ™ πŸ™-is-prop
    open plus (underlying-order πŸ™β‚’) (underlying-order πŸ™β‚’)

\end{code}

We will derive decidability of P from the assumption that the supremum of Ξ± is
discrete.

The idea of the proof is captured by NB₁ and NBβ‚‚ below. We will decide P by
deciding whether (Ξ± β‚€ ↓ inr ⋆) and (Ξ± ₁ ↓ inr ⋆) are equivalent ordinals.

This, in turn, is decidable, because both ordinals are images of an embedding
e : ⟨ sup Ξ± ⟩ β†’ Ordinal 𝓀 and ⟨ sup Ξ± ⟩ is discrete by assumption.

\begin{code}

  fact-I : ⟨ Ξ± β‚€ ↓ inr ⋆ ⟩ β†’ P
  fact-I (inl p , _) = p

  NB₁ : ⟨ Ξ± β‚€ ↓ inr ⋆ ⟩ ≃ P
  NB₁ = qinveq f (g , Ξ· , Ξ΅)
   where
    f : ⟨ Ξ± β‚€ ↓ ₁ ⟩ β†’ P
    f = fact-I
    g : P β†’ ⟨ Ξ± β‚€ ↓ ₁ ⟩
    g p = (inl p , ⋆)
    η : g ∘ f ∼ id
    Ξ· (inl p , _) = to-subtype-= (Ξ» x β†’ Prop-valuedness P' x ₁) refl
    Ρ : f ∘ g ∼ id
    Ξ΅ p = P-is-prop (f (g p)) p

  NBβ‚‚ : ⟨ Ξ± ₁ ↓ inr ⋆ ⟩ ≃ πŸ™{𝓀}
  NBβ‚‚ = singleton-≃-πŸ™ (x , c)
   where
    x : ⟨ Ξ± ₁ ↓ inr ⋆ ⟩
    x = (inl ⋆ , ⋆)
    c : is-central (⟨ Ξ± ₁ ↓ inr ⋆ ⟩) (β‚€ , ⋆)
    c (inl ⋆ , ⋆) = refl

  fact-II : P β†’ (Ξ± β‚€ ↓ inr ⋆) ≃ₒ (Ξ± ₁ ↓ inr ⋆)
  fact-II p = f , (f-order-pres , f-is-equiv , g-order-pres)
   where
    f : ⟨ Ξ± β‚€ ↓ inr ⋆ ⟩ β†’ ⟨ Ξ± ₁ ↓ inr ⋆ ⟩
    f _ = inl ⋆ , ⋆
    g : ⟨ Ξ± ₁ ↓ inr ⋆ ⟩ β†’ ⟨ Ξ± β‚€ ↓ inr ⋆ ⟩
    g _ = inl p , ⋆
    f-order-pres : is-order-preserving (Ξ± β‚€ ↓ inr ⋆) (Ξ± ₁ ↓ inr ⋆) f
    f-order-pres (inl p , _) (inl q , _) l = 𝟘-elim l
    g-order-pres : is-order-preserving (Ξ± ₁ ↓ inr ⋆) (Ξ± β‚€ ↓ inr ⋆) g
    g-order-pres (inl ⋆ , _) (inl ⋆ , _) l = 𝟘-elim l
    f-is-equiv : is-equiv f
    f-is-equiv = qinvs-are-equivs f (g , Ξ· , Ξ΅)
     where
      Ρ : f ∘ g ∼ id
      Ξ΅ (inl ⋆ , _) = refl
      η : g ∘ f ∼ id
      Ξ· (inl q , _) = to-subtype-= (Ξ» x β†’ Prop-valuedness P' x ₁)
                                   (ap inl (P-is-prop p q))

  fact-III : (Ξ± β‚€ ↓ inr ⋆) ≃ₒ (Ξ± ₁ ↓ inr ⋆) β†’ P
  fact-III e = fact-I (≃ₒ-to-fun⁻¹ (Ξ± β‚€ ↓ inr ⋆) (Ξ± ₁ ↓ inr ⋆) e (inl ⋆ , ⋆))

  decidability-if-sup-of-Ξ±-discrete : is-discrete ⟨ sup Ξ± ⟩ β†’ is-decidable P
  decidability-if-sup-of-Ξ±-discrete Ξ΄ = decidable-↔ (fact-III , fact-II) dec
   where
    r : image (sum-to-ordinals Ξ±) β†’ Ordinal 𝓀
    r = restriction (sum-to-ordinals Ξ±)
    c : (Ξ£ i κž‰ I , ⟨ Ξ± i ⟩) β†’ image (sum-to-ordinals Ξ±)
    c = corestriction (sum-to-ordinals Ξ±)

    Ο† : ⟨ sup Ξ± ⟩ ≃ image (sum-to-ordinals Ξ±)
    Ο† = sup-is-image-of-sum-to-ordinals Ξ±
    f : (Ξ£ i κž‰ I , ⟨ Ξ± i ⟩) β†’ ⟨ sup Ξ± ⟩
    f = ⌜ Ο† ⌝⁻¹ ∘ c
    e : ⟨ sup Ξ± ⟩ β†’ Ordinal 𝓀
    e = r ∘ ⌜ Ο† ⌝

    e-is-embedding : is-embedding e
    e-is-embedding =
     ∘-is-embedding (equivs-are-embeddings ⌜ Ο† ⌝ (⌜⌝-is-equiv Ο†))
                    (restrictions-are-embeddings (sum-to-ordinals Ξ±))
    e-after-f-lemma : e ∘ f ∼ sum-to-ordinals α
    e-after-f-lemma (i , x) =
     (r ∘ ⌜ Ο† ⌝ ∘ ⌜ Ο† ⌝⁻¹ ∘ c) (i , x) =⟨ h    ⟩
     r (c (i , x))                     =⟨refl⟩
     sum-to-ordinals α (i , x)         ∎
      where
       h = ap r (inverses-are-sections ⌜ Ο† ⌝ (⌜⌝-is-equiv Ο†) (c (i , x)))

    dec : is-decidable ((Ξ± β‚€ ↓ inr ⋆) ≃ₒ (Ξ± ₁ ↓ inr ⋆))
    dec = decidable-cong Ξ³ (Ξ΄ (f (β‚€ , inr ⋆)) (f (₁ , inr ⋆)))
     where
      Ξ³ = (f (β‚€ , inr ⋆)     =  f (₁ , inr ⋆))     β‰ƒβŸ¨ β¦…1⦆ ⟩
          (e (f (β‚€ , inr ⋆)) =  e (f (₁ , inr ⋆))) β‰ƒβŸ¨ β¦…2⦆ ⟩
          ((Ξ± β‚€ ↓ inr ⋆)     =  (Ξ± ₁ ↓ inr ⋆))     β‰ƒβŸ¨ β¦…3⦆ ⟩
          ((Ξ± β‚€ ↓ inr ⋆)     ≃ₒ (Ξ± ₁ ↓ inr ⋆))     β– 
       where
        β¦…1⦆ = ≃-sym (embedding-criterion-converse e e-is-embedding
                      (f (β‚€ , inr ⋆)) (f (₁ , inr ⋆)))
        β¦…2⦆ = =-cong _ _ (e-after-f-lemma (β‚€ , inr ⋆))
                         (e-after-f-lemma (₁ , inr ⋆))
        β¦…3⦆ = UAβ‚’-≃ (ua 𝓀) (fe _ _) (Ξ± β‚€ ↓ inr ⋆) (Ξ± ₁ ↓ inr ⋆)

\end{code}

Finally, we derive excluded middle from the assumption that discretely-indexed
suprema of trichotomous ordinals are discrete, as announced at the top of this
file.

\begin{code}

 EM-if-Sups-Of-Discretely-Indexed-Trichotomous-Ordinals-Are-Discrete :
  Sups-Of-Discretely-Indexed-Trichotomous-Ordinals-Are-Discrete 𝓀
  β†’ EM 𝓀
 EM-if-Sups-Of-Discretely-Indexed-Trichotomous-Ordinals-Are-Discrete h P i =
  decidability-if-sup-of-Ξ±-discrete Ξ³
   where
    open discrete-sup-taboo-construction-II P i
    γ : is-discrete ⟨ sup α ⟩
    γ = h 𝟚 𝟚-is-discrete α α-is-trichotomous

\end{code}