Tom de Jong, 1 November 2021.

We show that 𝟚 classifies decidable subsets.

We start by defining the type Ωᡈ 𝓀 of decidable propositions in a type
universe 𝓀 and we show that 𝟚 ≃ Ωᡈ 𝓀 (for any universe 𝓀).

Added 22 June 2024: 𝟚 ≃ Ξ© 𝓀 if and only if excluded middle (EM) holds in 𝓀.

\begin{code}

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

module NotionsOfDecidability.DecidableClassifier where

open import MLTT.Spartan

open import MLTT.Two-Properties

open import UF.DiscreteAndSeparated
open import UF.Equiv
open import UF.EquivalenceExamples
open import UF.FunExt
open import UF.Lower-FunExt
open import UF.Powerset
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.SubtypeClassifier

open import NotionsOfDecidability.Decidable

boolean-value' : {A : 𝓀 Μ‡ }
               β†’ is-decidable A
               β†’ Ξ£ b κž‰ 𝟚 , (b = β‚€ ↔ Β¬ A)
                         Γ— (b = ₁ ↔   A)
boolean-value' {𝓀} {A} (inl a ) = (₁ , Ο• , ψ)
 where
  Ο• : ₁ = β‚€ ↔ Β¬ A
  Ο• = (Ξ» p β†’ 𝟘-elim (one-is-not-zero p))
    , (Ξ» na β†’ 𝟘-elim (na a))
  ψ : ₁ = ₁ ↔ A
  ψ = (Ξ» _ β†’ a) , (Ξ» _ β†’ refl)
boolean-value' {𝓀} {A} (inr na) = β‚€ , Ο• , ψ
 where
  Ο• : β‚€ = β‚€ ↔ Β¬ A
  Ο• = (Ξ» _ β†’ na) , (Ξ» _ β†’ refl)
  ψ : β‚€ = ₁ ↔ A
  ψ = (Ξ» p β†’ 𝟘-elim (zero-is-not-one p))
    , (Ξ» a β†’ 𝟘-elim (na a))

inclusion-of-booleans : 𝟚 β†’ Ξ© 𝓀
inclusion-of-booleans β‚€ = 𝟘 , 𝟘-is-prop
inclusion-of-booleans ₁ = πŸ™ , πŸ™-is-prop

private
 Ωᡈ : (𝓀 : Universe) β†’ 𝓀 ⁺ Μ‡
 Ωᡈ 𝓀 = Ξ£ P κž‰ Ξ© 𝓀 , is-decidable (P holds)

 inclusion-of-decidable-props : Ωᡈ 𝓀 β†’ Ξ© 𝓀
 inclusion-of-decidable-props = pr₁

 ⟨_⟩ : Ωᡈ 𝓀 β†’ 𝓀 Μ‡
 ⟨ (P , i) , δ ⟩ = P

inclusion-of-booleans-into-decidable-props : 𝟚 β†’ Ωᡈ 𝓀
inclusion-of-booleans-into-decidable-props β‚€ = (𝟘 , 𝟘-is-prop) , 𝟘-is-decidable
inclusion-of-booleans-into-decidable-props ₁ = (πŸ™ , πŸ™-is-prop) , πŸ™-is-decidable

inclusion-of-booleans-∼ :
 inclusion-of-booleans {𝓀} ∼
 inclusion-of-decidable-props ∘ inclusion-of-booleans-into-decidable-props
inclusion-of-booleans-∼ β‚€ = refl
inclusion-of-booleans-∼ ₁ = refl

module _
        {𝓀 : Universe}
        (fe : funext 𝓀 𝓀)
        (pe : propext 𝓀)
       where

 to-Ωᡈ-= : (P Q : Ωᡈ 𝓀)
          β†’ (⟨ P ⟩ β†’ ⟨ Q ⟩)
          β†’ (⟨ Q ⟩ β†’ ⟨ P ⟩)
          β†’ P = Q
 to-Ωᡈ-= ((P , i) , δ) ((Q , j) , Ρ) α β =
  to-subtype-= Οƒ (to-subtype-= Ο„ (pe i j Ξ± Ξ²))
  where
   Οƒ : (P : Ξ© 𝓀) β†’ is-prop (is-decidable (P holds))
   Οƒ P = decidability-of-prop-is-prop (lower-funext 𝓀 𝓀 fe) (holds-is-prop P)
   Ο„ : (X : 𝓀 Μ‡ )β†’ is-prop (is-prop X)
   Ο„ _ = being-prop-is-prop fe

 𝟚-is-the-type-of-decidable-propositions : 𝟚 ≃ Ωᡈ 𝓀
 𝟚-is-the-type-of-decidable-propositions = qinveq f (g , η , Ρ)
  where
   f : 𝟚 β†’ Ωᡈ 𝓀
   f = inclusion-of-booleans-into-decidable-props
   g : Ωᡈ 𝓀 β†’ 𝟚
   g (P , Ξ΄) = pr₁ (boolean-value' Ξ΄)
   η : g ∘ f ∼ id
   Ξ· β‚€ = refl
   Ξ· ₁ = refl
   Ρ : f ∘ g ∼ id
   Ξ΅ P = 𝟚-equality-cases Ξ΅β‚€ Ρ₁
    where
     lemma : (g P = β‚€ ↔ Β¬ ⟨ P ⟩)
           Γ— (g P = ₁ ↔   ⟨ P ⟩)
     lemma = prβ‚‚ (boolean-value' (prβ‚‚ P))
     Ξ΅β‚€ : g P = β‚€
        β†’ (f ∘ g) P = P
     Ξ΅β‚€ e = to-Ωᡈ-= (f (g P)) P
             (Ξ» (q : ⟨ f (g P) ⟩) β†’ 𝟘-elim (transport (Ξ» b β†’ ⟨ f b ⟩) e q))
             (Ξ» (p : ⟨ P ⟩) β†’ 𝟘-elim (lr-implication (pr₁ lemma) e p))
     Ρ₁ : g P = ₁
        β†’ (f ∘ g) P = P
     Ρ₁ e = to-Ωᡈ-= (f (g P)) P
             (Ξ» _ β†’ lr-implication (prβ‚‚ lemma) e)
             (Ξ» _ β†’ transport⁻¹ (Ξ» (b : 𝟚) β†’ ⟨ f b ⟩) e ⋆)

\end{code}

The promised result now follows promptly using two general lemmas on
equivalences.

(Note that one direction of the equivalence Ξ Ξ£-distr-≃ is sometimes known as
"type-theoretic axiom of choice".)

\begin{code}

is-complemented-subset : {X : 𝓀 Μ‡ } β†’ (X β†’ Ξ© 𝓣) β†’ 𝓀 βŠ” 𝓣 Μ‡
is-complemented-subset {𝓀} {𝓣} {X} A = (x : X) β†’ is-decidable (x ∈ A)

module _
        (fe  : funext 𝓀 (𝓣 ⁺))
        (fe' : funext 𝓣 𝓣)
        (pe : propext 𝓣)
       where

 𝟚-classifies-decidable-subsets : {X : 𝓀 Μ‡ }
                                β†’ (X β†’ 𝟚)
                                ≃ (Ξ£ A κž‰ (X β†’ Ξ© 𝓣) , is-complemented-subset A)
 𝟚-classifies-decidable-subsets {X} =
  (X β†’ 𝟚)                                      β‰ƒβŸ¨ Ξ³          ⟩
  (X β†’ Ωᡈ 𝓣)                                   β‰ƒβŸ¨ Ξ Ξ£-distr-≃ ⟩
  (Ξ£ A κž‰ (X β†’ Ξ© 𝓣) , is-complemented-subset A) β– 
   where
    Ξ³ = β†’cong' fe (lower-funext 𝓀 (𝓣 ⁺) fe)
         (𝟚-is-the-type-of-decidable-propositions fe' pe)

 𝟚-classifies-decidable-subsets-values :
   {X : 𝓀 Μ‡ }
   (A : X β†’ Ξ© 𝓣)
   (Ξ΄ : is-complemented-subset A)
   (x : X)
   β†’ ((⌜ 𝟚-classifies-decidable-subsets ⌝⁻¹ (A , Ξ΄) x = β‚€) ↔ Β¬ (x ∈ A))
   Γ— ((⌜ 𝟚-classifies-decidable-subsets ⌝⁻¹ (A , Ξ΄) x = ₁) ↔   (x ∈ A))
 𝟚-classifies-decidable-subsets-values {X} A δ x = γ
  where
   Ο‡ : (Ξ£ A κž‰ (X β†’ Ξ© 𝓣) , is-complemented-subset A) β†’ (X β†’ 𝟚)
   Ο‡ = ⌜ 𝟚-classifies-decidable-subsets ⌝⁻¹
   Ξ³ : (Ο‡ (A , Ξ΄) x = β‚€ ↔ Β¬ (x ∈ A))
     Γ— (Ο‡ (A , Ξ΄) x = ₁ ↔   (x ∈ A))
   Ξ³ = prβ‚‚ (boolean-value' (Ξ΄ x))

\end{code}

Added 22 June 2024.

We record that Ω is equivalent to 𝟚 precisely when EM holds.

\begin{code}

open import UF.ClassicalLogic

module _
        {𝓀 : Universe}
        (fe : funext 𝓀 𝓀)
        (pe : propext 𝓀)
       where

\end{code}

Firstly, EM holds if and only if the inclusion Ωᡈ β†ͺ Ξ© of decidable propositions
into all propositions is an equivalence.

\begin{code}
 EM-gives-inclusion-of-decidable-props-is-equiv :
  EM 𝓀 β†’ is-equiv (inclusion-of-decidable-props)
 EM-gives-inclusion-of-decidable-props-is-equiv em =
  qinvs-are-equivs
   inclusion-of-decidable-props
   ((Ξ» 𝕑@(P , i) β†’ 𝕑 , em P i) ,
    (Ξ» P β†’ to-Ωᡈ-= fe pe _ P id id) ,
    Ξ» _ β†’ refl)

 inclusion-of-decidable-props-is-equiv-gives-EM :
  is-equiv (inclusion-of-decidable-props) β†’ EM 𝓀
 inclusion-of-decidable-props-is-equiv-gives-EM e P i = β„™-is-decidable
  where
   f : Ξ© 𝓀 β†’ Ωᡈ 𝓀
   f = inverse inclusion-of-decidable-props e
   β„™ : Ξ© 𝓀
   β„™ = (P , i)
   β„™' : Ξ© 𝓀
   β„™' = inclusion-of-decidable-props (f β„™)
   β„™'-is-decidable : is-decidable (β„™' holds)
   β„™'-is-decidable = prβ‚‚ (f β„™)
   β„™-is-decidable : is-decidable (β„™ holds)
   β„™-is-decidable =
    transport (Ξ» - β†’ is-decidable (- holds))
              (inverses-are-sections inclusion-of-decidable-props e β„™)
              β„™'-is-decidable

\end{code}

Since 𝟚 is equivalent to Ωᡈ, we get that EM holds if and only if the inclusion
𝟚 β†ͺ Ξ© of the booleans into all propositions is an equivalence.

\begin{code}

 EM-gives-inclusion-of-booleans-is-equiv :
  EM 𝓀 β†’ is-equiv (inclusion-of-booleans)
 EM-gives-inclusion-of-booleans-is-equiv em =
  equiv-closed-under-∼
   (inclusion-of-decidable-props ∘ inclusion-of-booleans-into-decidable-props)
   inclusion-of-booleans
   (∘-is-equiv
    (⌜⌝-is-equiv (𝟚-is-the-type-of-decidable-propositions fe pe))
    (EM-gives-inclusion-of-decidable-props-is-equiv em))
   inclusion-of-booleans-∼

 inclusion-of-booleans-is-equiv-gives-EM :
  is-equiv (inclusion-of-booleans) β†’ EM 𝓀
 inclusion-of-booleans-is-equiv-gives-EM e =
  inclusion-of-decidable-props-is-equiv-gives-EM
   (≃-2-out-of-3-right
    (⌜⌝-is-equiv (𝟚-is-the-type-of-decidable-propositions fe pe))
    (equiv-closed-under-∼ _ _ e (∼-sym inclusion-of-booleans-∼)))

\end{code}

In fact, EM holds if and only if we have any equivalence between 𝟚 and Ω,
because any such equivalence would prove that Ξ© is discrete which is equivalent
to EM.

\begin{code}

 EM-gives-𝟚-is-the-type-of-propositions : EM 𝓀 β†’ 𝟚 ≃ Ξ© 𝓀
 EM-gives-𝟚-is-the-type-of-propositions em =
  inclusion-of-booleans , EM-gives-inclusion-of-booleans-is-equiv em

 𝟚-is-the-type-of-propositions-gives-EM : 𝟚 ≃ Ξ© 𝓀 β†’ EM 𝓀
 𝟚-is-the-type-of-propositions-gives-EM e =
  Ω-discrete-gives-EM fe pe (equiv-to-discrete e 𝟚-is-discrete)

\end{code}