Martin Escardo, 15th November 2023.

Lesser Limited Principle of Omniscience.

\begin{code}

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

module Taboos.LLPO where

open import CoNaturals.BothTypes
open import MLTT.Plus-Properties
open import MLTT.Spartan
open import MLTT.Two-Properties
open import Naturals.Parity
open import Naturals.Properties
open import Notation.CanonicalMap
open import Taboos.BasicDiscontinuity
open import Taboos.WLPO
open import UF.FunExt
open import UF.PropTrunc
open import UF.Subsingletons

open β„•βˆž-equivalence

private
 T : (β„• β†’ 𝟚) β†’ 𝓀₀ Μ‡
 T Ξ± = Ξ£ n κž‰ β„• , Ξ± n = ₁

 Β¬T : (β„• β†’ 𝟚) β†’ 𝓀₀ Μ‡
 Β¬T Ξ± = (n : β„•) β†’ Ξ± n = β‚€

private
 instance
  Canonical-Map-β„•-β„•βˆž' : Canonical-Map β„• β„•βˆž'
  ΞΉ {{Canonical-Map-β„•-β„•βˆž'}} = β„•-to-β„•βˆž'

 instance
  canonical-map-β„•βˆž'-β„•β†’πŸš : Canonical-Map β„•βˆž' (β„• β†’ 𝟚)
  ΞΉ {{canonical-map-β„•βˆž'-β„•β†’πŸš}} = β„•βˆž'-to-β„•β†’πŸš

\end{code}

The definition of LLPO uses _∨_ rather than _+_. We show that with
_+_, LLPO implies WLPO, but it is known that LLPO with _∨_ doesn't
(there are counter-models).

\begin{code}

untruncated-LLPO : 𝓀₀ Μ‡
untruncated-LLPO = (Ξ± : β„• β†’ 𝟚)
                 β†’ is-prop (T Ξ±)
                 β†’ ((n : β„•) β†’ Ξ± ( double n) = β‚€)
                 + ((n : β„•) β†’ Ξ± (sdouble n) = β‚€)

\end{code}

The following version is logically equivalent, which shows that
untruncated LLPO is an instance of De Morgan Law.

\begin{code}

untruncated-LLPO' : 𝓀₀ Μ‡
untruncated-LLPO' = (Ξ² Ξ³ : β„• β†’ 𝟚)
                  β†’ is-prop (T Ξ²)
                  β†’ is-prop (T Ξ³)
                  β†’ Β¬ (T Ξ² Γ— T Ξ³) β†’ Β¬ T Ξ² + Β¬ T Ξ³

untrucated-LLPO'-gives-untruncated-LLPO : untruncated-LLPO' β†’ untruncated-LLPO
untrucated-LLPO'-gives-untruncated-LLPO llpo' Ξ± h = III
 where
  Ξ² Ξ³ : β„• β†’ 𝟚
  Ξ² n = Ξ± ( double n)
  Ξ³ n = Ξ± (sdouble n)

  i : is-prop (T Ξ²)
  i (n , e) (n' , e') = to-T-= (double-lc (index-uniqueness α h e e'))

  j : is-prop (T Ξ³)
  j (n , e) (n' , e') = to-T-= (sdouble-lc (index-uniqueness α h e e'))

  I : Β¬ (T Ξ² Γ— T Ξ³)
  I ((k , e) , (k' , e')) = even-not-odd' k k' (index-uniqueness Ξ± h e e')

  II : Β¬ T Ξ² + Β¬ T Ξ³
  II = llpo' Ξ² Ξ³ i j I

  III : ((n : β„•) β†’ Ξ± (double n) = β‚€) + ((n : β„•) β†’ Ξ± (sdouble n) = β‚€)
  III = +functor not-T-gives-Β¬T not-T-gives-Β¬T II

untrucated-LLPO-gives-untruncated-LLPO' : untruncated-LLPO β†’ untruncated-LLPO'
untrucated-LLPO-gives-untruncated-LLPO' llpo Ξ² Ξ³ i j Ξ½ = III
 where
  f : (n : β„•) β†’ is-even' n + is-odd' n β†’ 𝟚
  f n (inl (k , _)) = Ξ² k
  f n (inr (k , _)) = Ξ³ k

  Ξ± : β„• β†’ 𝟚
  Ξ± n = f n (even-or-odd' n)

  Ξ±-Ξ² : (n : β„•) β†’ Ξ± (double n) = Ξ² n
  Ξ±-Ξ² n = a (even-or-odd' (double n))
   where
    a : (d : is-even' (double n) + is-odd' (double n)) β†’ f (double n) d = Ξ² n
    a (inl (k , e)) = ap Ξ² (double-lc e)
    a (inr (k , e)) = 𝟘-elim (even-not-odd' n k (e ⁻¹))

  Ξ±-Ξ³ : (n : β„•) β†’ Ξ± (sdouble n) = Ξ³ n
  Ξ±-Ξ³ n = a (even-or-odd' (sdouble n))
   where
    a : (d : is-even' (sdouble n) + is-odd' (sdouble n)) β†’ f (sdouble n) d = Ξ³ n
    a (inl (k , e)) = 𝟘-elim (even-not-odd' k n e)
    a (inr (k , e)) = ap Ξ³ (sdouble-lc e)

  I : is-prop (T Ξ±)
  I (n , e) (n' , e') = a (even-or-odd' n) (even-or-odd' n')
   where
    a : (d  : is-even' n  + is-odd' n )
        (d' : is-even' n' + is-odd' n')
      β†’ (n , e) =[ T Ξ± ] (n' , e')
    a (inl (k , refl)) (inl (k' , refl)) =
     to-T-= (ap  double (index-uniqueness Ξ² i ((Ξ±-Ξ² k)⁻¹ βˆ™ e) ((Ξ±-Ξ² k') ⁻¹ βˆ™ e')))
    a (inl (k , refl)) (inr (k' , refl)) =
     𝟘-elim (Ξ½ ((k  , ((Ξ±-Ξ² k )⁻¹ βˆ™ e )) , (k' , (( Ξ±-Ξ³ k')⁻¹ βˆ™ e'))))
    a (inr (k , refl)) (inl (k' , refl)) =
     𝟘-elim (Ξ½ ((k' , ((Ξ±-Ξ² k')⁻¹ βˆ™ e')) , (k  , (( Ξ±-Ξ³ k )⁻¹ βˆ™ e ))))
    a (inr (k , refl)) (inr (k' , refl)) =
     to-T-= (ap sdouble (index-uniqueness Ξ³ j ((Ξ±-Ξ³ k)⁻¹ βˆ™ e) ((Ξ±-Ξ³ k') ⁻¹ βˆ™ e')))

  II : ((n : β„•) β†’ Ξ± (double n) = β‚€) + ((n : β„•) β†’ Ξ± (sdouble n) = β‚€)
  II = llpo Ξ± I

  III : Β¬ T Ξ² + Β¬ T Ξ³
  III = +functor
         (Ξ» (ψ : (n : β„•) β†’ Ξ± ( double n) = β‚€)
               β†’ Β¬T-gives-not-T (Ξ» n β†’ (Ξ±-Ξ² n)⁻¹ βˆ™ ψ n))
         (Ξ» (ψ : (n : β„•) β†’ Ξ± (sdouble n) = β‚€)
               β†’ Β¬T-gives-not-T (Ξ» n β†’ (Ξ±-Ξ³ n)⁻¹ βˆ™ ψ n))
         II

\end{code}

Two more equivalent formulations of LLPO.

\begin{code}

untruncated-β„•βˆž-LLPO : 𝓀₀ Μ‡
untruncated-β„•βˆž-LLPO = (u v : β„•βˆž)
                    β†’ Β¬ (is-finite u Γ— is-finite v)
                    β†’ (u = ∞) + (v = ∞)

untruncated-β„•βˆž'-LLPO : 𝓀₀ Μ‡
untruncated-β„•βˆž'-LLPO = (u v : β„•βˆž')
                     β†’ Β¬ (is-finite' u Γ— is-finite' v)
                     β†’ (u = ∞') + (v = ∞')

untruncated-LLPO'-gives-untruncated-β„•βˆž'-LLPO : funextβ‚€
                                             β†’ untruncated-LLPO'
                                             β†’ untruncated-β„•βˆž'-LLPO
untruncated-LLPO'-gives-untruncated-β„•βˆž'-LLPO fe llpo u v ΞΌ = II I
 where
  I : Β¬ T (ΞΉ u) + Β¬ T (ΞΉ v)
  I = llpo (ΞΉ u) (ΞΉ v) (β„•βˆž'-to-β„•β†’πŸš-at-most-one-₁ u) (β„•βˆž'-to-β„•β†’πŸš-at-most-one-₁ v) ΞΌ

  II : type-of I β†’ (u = ∞') + (v = ∞')
  II (inl a) = inl (not-T-is-∞' fe u a)
  II (inr b) = inr (not-T-is-∞' fe v b)

untruncated-β„•βˆž'-LLPO-gives-untruncated-LLPO' : funextβ‚€
                                             β†’ untruncated-β„•βˆž'-LLPO
                                             β†’ untruncated-LLPO'
untruncated-β„•βˆž'-LLPO-gives-untruncated-LLPO' fe llpo Ξ± Ξ² a b ΞΌ = II I
 where
  I : ((α , a) = ∞') + ((β , b) = ∞')
  I = llpo (Ξ± , a) (Ξ² , b) (Ξ» (Ο• , Ξ³) β†’ ΞΌ (Ο• , Ξ³))

  II : type-of I β†’ Β¬ T Ξ± + Β¬ T Ξ²
  II (inl e) = inl (Β¬T-gives-not-T (Ξ» n β†’ ap (Ξ» - β†’ pr₁ - n) e))
  II (inr e) = inr (Β¬T-gives-not-T (Ξ» n β†’ ap (Ξ» - β†’ pr₁ - n) e))

untruncated-β„•βˆž-LLPO-gives-untruncated-β„•βˆž'-LLPO : funextβ‚€
                                               β†’ untruncated-β„•βˆž-LLPO
                                               β†’ untruncated-β„•βˆž'-LLPO
untruncated-β„•βˆž-LLPO-gives-untruncated-β„•βˆž'-LLPO fe llpo u v ΞΌ = II I
 where
  I : (β„•βˆž'-to-β„•βˆž fe u = ∞) + (β„•βˆž'-to-β„•βˆž fe v = ∞)
  I = llpo
        (β„•βˆž'-to-β„•βˆž fe u)
        (β„•βˆž'-to-β„•βˆž fe v)
        (Ξ» (a , b) β†’ ΞΌ (finite-gives-finite' fe u a ,
                        finite-gives-finite' fe v b))

  II : type-of I β†’ (u = ∞') + (v = ∞')
  II (inl d) = inl (∞-gives-∞' fe u d)
  II (inr e) = inr (∞-gives-∞' fe v e)

untruncated-β„•βˆž'-LLPO-gives-untruncated-β„•βˆž-LLPO : funextβ‚€
                                               β†’ untruncated-β„•βˆž'-LLPO
                                               β†’ untruncated-β„•βˆž-LLPO
untruncated-β„•βˆž'-LLPO-gives-untruncated-β„•βˆž-LLPO fe llpo u v ΞΌ = II I
 where
  I : (β„•βˆž-to-β„•βˆž' fe u = ∞') + (β„•βˆž-to-β„•βˆž' fe v = ∞')
  I = llpo
        (β„•βˆž-to-β„•βˆž' fe u)
        (β„•βˆž-to-β„•βˆž' fe v)
        (Ξ» (a , b) β†’ ΞΌ (finite'-gives-finite fe u a ,
                        finite'-gives-finite fe v b))

  II : type-of I β†’ (u = ∞) + (v = ∞)
  II (inl d) = inl (∞'-gives-∞ fe u d)
  II (inr e) = inr (∞'-gives-∞ fe v e)

untruncated-β„•βˆž-LLPO-gives-untruncated-LPO : funextβ‚€
                                          β†’ untruncated-β„•βˆž-LLPO
                                          β†’ untruncated-LLPO
untruncated-β„•βˆž-LLPO-gives-untruncated-LPO fe unllpo =
 untrucated-LLPO'-gives-untruncated-LLPO
  (untruncated-β„•βˆž'-LLPO-gives-untruncated-LLPO' fe
    (untruncated-β„•βˆž-LLPO-gives-untruncated-β„•βˆž'-LLPO fe unllpo))

untruncated-LLPO-gives-untruncated-β„•βˆž-LPO : funextβ‚€
                                          β†’ untruncated-LLPO
                                          β†’ untruncated-β„•βˆž-LLPO
untruncated-LLPO-gives-untruncated-β„•βˆž-LPO fe ullpo =
 untruncated-β„•βˆž'-LLPO-gives-untruncated-β„•βˆž-LLPO fe
  (untruncated-LLPO'-gives-untruncated-β„•βˆž'-LLPO fe
   (untrucated-LLPO-gives-untruncated-LLPO' ullpo))

\end{code}

The following result seems to be new (and I announced it years ago in
the constructivenews mailing list). The idea is to construct a
non-continuous function using untruncated LLPO, and then derive WLPO
from this. This proof was written here 15th November 2023, simplified
28th February 2023, for which we included the above β„•βˆž-versions of
LLPO and their equivalences.

\begin{code}

untruncated-β„•βˆž-LLPO-gives-WLPO : funextβ‚€ β†’ untruncated-β„•βˆž-LLPO β†’ WLPO
untruncated-β„•βˆž-LLPO-gives-WLPO fe llpo = wlpo
 where
  D : β„•βˆž β†’ β„•βˆž β†’ 𝓀₀ Μ‡
  D u v = (u = ∞) + (v = ∞)

  Ο• : (u v : β„•βˆž) β†’ D u v β†’ 𝟚
  Ο• u v (inl _) = β‚€
  Ο• u v (inr _) = ₁

  lβ‚€ : (u : β„•βˆž) β†’ D u ∞
  lβ‚€ u = llpo u ∞ (Ξ» (_ , ∞-is-finite) β†’ is-infinite-∞ ∞-is-finite)

  l₁ : (u : β„•βˆž) β†’ D ∞ u
  l₁ u = llpo ∞ u (Ξ» (∞-is-finite , _) β†’ is-infinite-∞ ∞-is-finite)

  l-∞-agreement : lβ‚€ ∞ = l₁ ∞
  l-∞-agreement = refl

  fβ‚€ f₁ : β„•βˆž β†’ 𝟚
  fβ‚€ u = Ο• u ∞ (lβ‚€ u)
  f₁ u = Ο• ∞ u (l₁ u)

  f-∞-agreement : fβ‚€ ∞ = f₁ ∞
  f-∞-agreement = refl

  Ο•β‚€-property : (u : β„•βˆž) (d : D u ∞) β†’ is-finite u β†’ Ο• u ∞ d = ₁
  Ο•β‚€-property .∞ (inl refl) ∞-is-finite = 𝟘-elim (is-infinite-∞ ∞-is-finite)
  Ο•β‚€-property u  (inr _)    _           = refl

  ϕ₁-property : (u : β„•βˆž) (d : D ∞ u) β†’ is-finite u β†’ Ο• ∞ u d = β‚€
  ϕ₁-property u  (inl _)    _           = refl
  ϕ₁-property .∞ (inr refl) ∞-is-finite = 𝟘-elim (is-infinite-∞ ∞-is-finite)

  fβ‚€-property : (u : β„•βˆž) β†’ is-finite u β†’ fβ‚€ u = ₁
  fβ‚€-property u = Ο•β‚€-property u (lβ‚€ u)

  f₁-property : (u : β„•βˆž) β†’ is-finite u β†’ f₁ u = β‚€
  f₁-property u = ϕ₁-property u (l₁ u)

  wlpoβ‚€ : fβ‚€ ∞ = β‚€ β†’ WLPO
  wlpoβ‚€ e = wlpo
   where
    gβ‚€ : β„•βˆž β†’ 𝟚
    gβ‚€ = complement ∘ fβ‚€

    bβ‚€ : (n : β„•) β†’ gβ‚€ (ΞΉ n) = β‚€
    bβ‚€ n = ap complement (fβ‚€-property (ΞΉ n) (β„•-to-β„•βˆž-is-finite n))

    b₁ : gβ‚€ ∞ = ₁
    b₁ = ap complement e

    wlpo : WLPO
    wlpo = basic-discontinuity-taboo fe gβ‚€ (bβ‚€ , b₁)

  wlpo₁ : f₁ ∞ = ₁ β†’ WLPO
  wlpo₁ b₁ = wlpo
   where
    bβ‚€ : (n : β„•) β†’ f₁ (ΞΉ n) = β‚€
    bβ‚€ n = f₁-property (ΞΉ n) (β„•-to-β„•βˆž-is-finite n)

    wlpo : WLPO
    wlpo = basic-discontinuity-taboo fe f₁ (bβ‚€ , b₁)

  wlpo : WLPO
  wlpo = Cases (𝟚-possibilities (fβ‚€ ∞))
          (Ξ» (a : fβ‚€ ∞ = β‚€)
                β†’ wlpoβ‚€ a)
          (Ξ» (b : fβ‚€ ∞ = ₁)
                β†’ Cases (𝟚-possibilities (f₁ ∞))
                   (Ξ» (c : f₁ ∞ = β‚€)
                         β†’ 𝟘-elim (zero-is-not-one
                                    (β‚€    =⟨ c ⁻¹ ⟩
                                     f₁ ∞ =⟨ f-∞-agreement ⟩
                                     fβ‚€ ∞ =⟨ b ⟩
                                     ₁    ∎)))
                   (Ξ» (d : f₁ ∞ = ₁)
                         β†’ wlpo₁ d))

\end{code}

Added 27th Feb 2024. The converse also holds with a simpler proof, and
so there isn't any difference between WLPO and untruncated LLPO.

\begin{code}

WLPO-gives-untruncated-LLPO : WLPO-traditional β†’ untruncated-LLPO
WLPO-gives-untruncated-LLPO wlpo Ξ± TΞ±-is-prop =
 Cases (wlpo (complement ∘ α ∘ double))
  (Ξ» (a : (n : β„•) β†’ complement (Ξ± (double n)) = ₁)
        β†’ inl (Ξ» n β†’ complement₁ (a n)))
  (Ξ» (b : Β¬ ((n : β„•) β†’ complement (Ξ± (double n)) = ₁))
        β†’ inr (Ξ» n β†’ 𝟚-equality-cases
                      (Ξ» (c : Ξ± (sdouble n) = β‚€)
                            β†’ c)
                      (Ξ» (d : Ξ± (sdouble n) = ₁)
                            β†’ 𝟘-elim
                               (b (Ξ» m β†’ ap
                                          complement
                                          (different-from-₁-equal-β‚€
                                            (Ξ» (p : Ξ± (double m) = ₁)
                                                  β†’ double-is-not-sdouble
                                                     (index-uniqueness
                                                       Ξ±
                                                       TΞ±-is-prop
                                                       p
                                                       d))))))))
\end{code}

End of 27th Feb 2024 addition.

We now formulate (truncated) LLPO.

\begin{code}

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

 open PropositionalTruncation pt

 LLPO : 𝓀₀ Μ‡
 LLPO = (Ξ± : β„• β†’ 𝟚)
      β†’ is-prop (Ξ£ n κž‰ β„• , Ξ± n = ₁)
      β†’ ((n : β„•) β†’ Ξ± (double n) = β‚€) ∨ ((n : β„•) β†’ Ξ± (sdouble n) = β‚€)

 LLPO' : 𝓀₀ Μ‡
 LLPO' = (Ξ² Ξ³ : β„• β†’ 𝟚)
       β†’ is-prop (T Ξ²)
       β†’ is-prop (T Ξ³)
       β†’ Β¬ (T Ξ² Γ— T Ξ³) β†’ Β¬ T Ξ² ∨ Β¬ T Ξ³

 β„•βˆž-LLPO : 𝓀₀ Μ‡
 β„•βˆž-LLPO = (u v : β„•βˆž) β†’ Β¬ (is-finite u Γ— is-finite v) β†’ (u = ∞) ∨ (v = ∞)

 β„•βˆž-LLPO' : 𝓀₀ Μ‡
 β„•βˆž-LLPO' = (u v : β„•βˆž) β†’ Β¬ ((u β‰  ∞) Γ— (v β‰  ∞)) β†’ (u = ∞) ∨ (v = ∞)

 β„•βˆž'-LLPO : 𝓀₀ Μ‡
 β„•βˆž'-LLPO = (u v : β„•βˆž') β†’ Β¬ (is-finite' u Γ— is-finite' v) β†’ (u = ∞') ∨ (v = ∞')

 untruncated-LLPO-gives-LLPO : untruncated-LLPO β†’ LLPO
 untruncated-LLPO-gives-LLPO ullpo α i = ∣ ullpo α i ∣

\end{code}

TODO. Show that all these variants are equivalent.

LLPO doesn't imply WLPO (there are published refereces - find and
include them here). One example seems to Johnstone's topological
topos, but this is unpublished as far as I know.

Added 17th July 2024. There is a proof by Chris Grossack here:
https://grossack.site/2024/07/03/topological-topos-3-bonus-axioms