Martin Escardo 2011. \begin{code} {-# OPTIONS --without-K --exact-split --safe #-} module DecidableAndDetachable where open import SpartanMLTT open import Plus-Properties open import Two-Properties open import UF-Subsingletons open import UF-PropTrunc \end{code} We look at decidable propositions and subsets (using the terminogy "detachable" for the latter"). \begin{code} ¬¬-elim : {A : π€ Μ } β decidable A β ¬¬ A β A ¬¬-elim (inl a) f = a ¬¬-elim (inr g) f = π-elim(f g) empty-decidable : {X : π€ Μ } β is-empty X β decidable X empty-decidable = inr π-decidable : decidable (π {π€}) π-decidable = empty-decidable π-elim pointed-decidable : {X : π€ Μ } β X β decidable X pointed-decidable = inl \end{code} Digression: https://twitter.com/EgbertRijke/status/1429443868450295810 "decidable" is almost a monad, except that it is not even functorial: \begin{code} module EgbertRijkeTwitterDiscussion-22-August-2021-not-a-monad where open import UF-Equiv T : π€ Μ β π€ Μ T = decidable Ξ· : (X : π€ Μ ) β X β T X Ξ· X = pointed-decidable ΞΌ : (X : π€ Μ ) β T (T X) β T X ΞΌ X (inl Ξ΄) = Ξ΄ ΞΌ X (inr u) = inr (Ξ» x β u (inl x)) ΞΌΞ· : (X : π€ Μ ) β ΞΌ X β Ξ· (T X) βΌ id ΞΌΞ· X (inl x) = refl ΞΌΞ· X (inr u) = refl Ξ·ΞΌ : (X : π€ Μ ) β Ξ· (T X) β ΞΌ X βΌ id Ξ·ΞΌ X (inl (inl x)) = refl Ξ·ΞΌ X (inl (inr u)) = refl Ξ·ΞΌ X (inr u) = π-elim (u (inr (Ξ» x β u (inl x)))) ΞΌ-is-invertible : (X : π€ Μ ) β invertible (ΞΌ X) ΞΌ-is-invertible X = Ξ· (T X) , Ξ·ΞΌ X , ΞΌΞ· X ΞΌ-β : (X : π€ Μ ) β T (T X) β T X ΞΌ-β X = qinveq (ΞΌ X) (ΞΌ-is-invertible X) raw-T-algebras-are-non-empty : {X : π€ Μ } (Ξ± : T X β X) β is-nonempty X raw-T-algebras-are-non-empty Ξ± u = u (Ξ± (inr u)) retraction-of-Ξ·-is-section : {A : π€ Μ } (Ξ± : T A β A) β Ξ± β Ξ· A βΌ id β Ξ· A β Ξ± βΌ id retraction-of-Ξ·-is-section Ξ± h (inl a) = ap inl (h a) retraction-of-Ξ·-is-section Ξ± h (inr u) = π-elim (raw-T-algebras-are-non-empty Ξ± u) section-of-Ξ·-is-retraction : {A : π€ Μ } (Ξ± : T A β A) β Ξ· A β Ξ± βΌ id β Ξ± β Ξ· A βΌ id section-of-Ξ·-is-retraction Ξ± k a = inl-lc (k (inl a)) Ξ·β»ΒΉ : {A : π€ Μ } β is-nonempty A β (T A β A) Ξ·β»ΒΉ Ο (inl a) = a Ξ·β»ΒΉ Ο (inr u) = π-elim (Ο u) Ξ·β»ΒΉ-is-retraction : {A : π€ Μ } (Ο : is-nonempty A) β Ξ·β»ΒΉ Ο β Ξ· A βΌ id Ξ·β»ΒΉ-is-retraction Ο a = refl Ξ·β»ΒΉ-is-section : {A : π€ Μ } (Ο : is-nonempty A) β Ξ· A β Ξ·β»ΒΉ Ο βΌ id Ξ·β»ΒΉ-is-section Ο = retraction-of-Ξ·-is-section (Ξ·β»ΒΉ Ο) (Ξ·β»ΒΉ-is-retraction Ο) Ξ·-invertible-gives-non-empty : {X : π€ Μ } β invertible (Ξ· X) β is-nonempty X Ξ·-invertible-gives-non-empty (Ξ± , _ , _) = raw-T-algebras-are-non-empty Ξ± non-empty-gives-Ξ·-invertible : {X : π€ Μ } β is-nonempty X β invertible (Ξ· X) non-empty-gives-Ξ·-invertible {π€} {X} Ο = Ξ·β»ΒΉ Ο , Ξ·β»ΒΉ-is-retraction Ο , Ξ·β»ΒΉ-is-section Ο Ξ·-β : (X : π€ Μ ) β is-nonempty X β X β T X Ξ·-β X Ο = qinveq (Ξ· X) (non-empty-gives-Ξ·-invertible Ο) retractions-of-Ξ·-are-invertible : {A : π€ Μ } (Ξ± : T A β A) β Ξ± β Ξ· A βΌ id β invertible Ξ± retractions-of-Ξ·-are-invertible {π€} {A} Ξ± h = Ξ· A , retraction-of-Ξ·-is-section Ξ± h , h retractions-of-Ξ·-are-unique : {A : π€ Μ } (Ξ± : T A β A) β Ξ± β Ξ· A βΌ id β (Ο : is-nonempty A) β Ξ± βΌ Ξ·β»ΒΉ Ο retractions-of-Ξ·-are-unique Ξ± h Ο (inl a) = h a retractions-of-Ξ·-are-unique Ξ± h Ο (inr u) = π-elim (Ο u) is-proto-algebra : π€ Μ β π€ Μ is-proto-algebra A = Ξ£ Ξ± κ (T A β A) , Ξ± β Ξ· A βΌ id proto-algebras-are-non-empty : {A : π€ Μ } β is-proto-algebra A β is-nonempty A proto-algebras-are-non-empty (Ξ± , _) = raw-T-algebras-are-non-empty Ξ± nonempty-types-are-proto-algebras : {A : π€ Μ } β is-nonempty A β is-proto-algebra A nonempty-types-are-proto-algebras Ο = Ξ·β»ΒΉ Ο , Ξ·β»ΒΉ-is-retraction Ο \end{code} End of digression. \begin{code} π-decidable : decidable (π {π€}) π-decidable = pointed-decidable * Γ-preserves-decidability : {A : π€ Μ } {B : π₯ Μ } β decidable A β decidable B β decidable (A Γ B) Γ-preserves-decidability (inl a) (inl b) = inl (a , b) Γ-preserves-decidability (inl a) (inr v) = inr (Ξ» c β v (prβ c)) Γ-preserves-decidability (inr u) _ = inr (Ξ» c β u (prβ c)) +-preserves-decidability : {A : π€ Μ } {B : π₯ Μ } β decidable A β decidable B β decidable (A + B) +-preserves-decidability (inl a) _ = inl (inl a) +-preserves-decidability (inr u) (inl b) = inl (inr b) +-preserves-decidability (inr u) (inr v) = inr (cases u v) β-preserves-decidability : {A : π€ Μ } {B : π₯ Μ } β decidable A β decidable B β decidable (A β B) β-preserves-decidability d (inl b) = inl (Ξ» _ β b) β-preserves-decidability (inl a) (inr v) = inr (Ξ» f β v (f a)) β-preserves-decidability (inr u) (inr v) = inl (Ξ» a β π-elim (u a)) β-preserves-decidability' : {A : π€ Μ } {B : π₯ Μ } β (Β¬ B β decidable A) β decidable B β decidable (A β B) β-preserves-decidability' Ο (inl b) = inl (Ξ» _ β b) β-preserves-decidability' {π€} {π₯} {A} {B} Ο (inr v) = Ξ³ (Ο v) where Ξ³ : decidable A β decidable (A β B) Ξ³ (inl a) = inr (Ξ» f β v (f a)) Ξ³ (inr u) = inl (Ξ» a β π-elim (u a)) β-preserves-decidability'' : {A : π€ Μ } {B : π₯ Μ } β decidable A β (A β decidable B) β decidable (A β B) β-preserves-decidability'' {π€} {π₯} {A} {B} (inl a) Ο = Ξ³ (Ο a) where Ξ³ : decidable B β decidable (A β B) Ξ³ (inl b) = inl (Ξ» _ β b) Ξ³ (inr v) = inr (Ξ» f β v (f a)) β-preserves-decidability'' (inr u) Ο = inl (Ξ» a β π-elim (u a)) Β¬-preserves-decidability : {A : π€ Μ } β decidable A β decidable(Β¬ A) Β¬-preserves-decidability d = β-preserves-decidability d π-decidable which-of : {A : π€ Μ } {B : π₯ Μ } β A + B β Ξ£ b κ π , (b β‘ β β A) Γ (b β‘ β β B) which-of (inl a) = β , (Ξ» (r : β β‘ β) β a) , Ξ» (p : β β‘ β) β π-elim (zero-is-not-one p) which-of (inr b) = β , (Ξ» (p : β β‘ β) β π-elim (zero-is-not-one (p β»ΒΉ))) , (Ξ» (r : β β‘ β) β b) \end{code} The following is a special case we are interested in: \begin{code} boolean-value : {A : π€ Μ } β decidable A β Ξ£ b κ π , (b β‘ β β A) Γ (b β‘ β β Β¬ A) boolean-value = which-of \end{code} Notice that this b is unique (Agda exercise) and that the converse also holds. In classical mathematics it is posited that all propositions have binary truth values, irrespective of whether they have BHK-style witnesses. And this is precisely the role of the principle of excluded middle in classical mathematics. The following requires choice, which holds in BHK-style constructive mathematics: \begin{code} indicator : {X : π€ Μ } β {A B : X β π₯ Μ } β ((x : X) β A x + B x) β Ξ£ p κ (X β π) , ((x : X) β (p x β‘ β β A x) Γ (p x β‘ β β B x)) indicator {π€} {π₯} {X} {A} {B} h = (Ξ» x β prβ(lemmaβ x)) , (Ξ» x β prβ(lemmaβ x)) where lemmaβ : (x : X) β (A x + B x) β Ξ£ b κ π , (b β‘ β β A x) Γ (b β‘ β β B x) lemmaβ x = which-of lemmaβ : (x : X) β Ξ£ b κ π , (b β‘ β β A x) Γ (b β‘ β β B x) lemmaβ = Ξ» x β lemmaβ x (h x) \end{code} We again have a particular case of interest. Detachable subsets, defined below, are often known as decidable subsets. Agda doesn't allow overloading of terminology, and hence we gladly accept the slighly non-universal terminology. \begin{code} detachable : {X : π€ Μ } (A : X β π₯ Μ ) β π€ β π₯ Μ detachable A = β x β decidable(A x) characteristic-function : {X : π€ Μ } {A : X β π₯ Μ } β detachable A β Ξ£ p κ (X β π) , ((x : X) β (p x β‘ β β A x) Γ (p x β‘ β β Β¬ (A x))) characteristic-function = indicator co-characteristic-function : {X : π€ Μ } {A : X β π₯ Μ } β detachable A β Ξ£ p κ (X β π) , ((x : X) β (p x β‘ β β Β¬ (A x)) Γ (p x β‘ β β A x)) co-characteristic-function d = indicator(Ξ» x β +-commutative(d x)) decidable-closed-under-Ξ£ : {X : π€ Μ } {Y : X β π₯ Μ } β is-prop X β decidable X β ((x : X) β decidable (Y x)) β decidable (Ξ£ Y) decidable-closed-under-Ξ£ {π€} {π₯} {X} {Y} isp d e = g d where g : decidable X β decidable (Ξ£ Y) g (inl x) = h (e x) where Ο : Ξ£ Y β Y x Ο (x' , y) = transport Y (isp x' x) y h : decidable(Y x) β decidable (Ξ£ Y) h (inl y) = inl (x , y) h (inr v) = inr (contrapositive Ο v) g (inr u) = inr (contrapositive prβ u) \end{code} Notice that p is unique (Agda exercise - you will need function extensionality). Don't really have a good place to put this: \begin{code} module _ (pt : propositional-truncations-exist) where open PropositionalTruncation pt not-existsβ-implies-forallβ : {X : π€ Μ } (p : X β π) β Β¬ (β x κ X , p x β‘ β) β β (x : X) β p x β‘ β not-existsβ-implies-forallβ p u x = different-from-β-equal-β (not-Ξ£-implies-Ξ -not (u β β£_β£) x) forallβ-implies-not-existsβ : {X : π€ Μ } (p : X β π) β (β (x : X) β p x β‘ β) β Β¬ (β x κ X , p x β‘ β) forallβ-implies-not-existsβ {π€} {X} p Ξ± = β₯β₯-rec π-is-prop h where h : (Ξ£ x κ X , p x β‘ β) β π h (x , r) = zero-is-not-one (r β»ΒΉ β Ξ± x) \end{code}