Martin Escardo 2011. \begin{code} {-# OPTIONS --without-K --exact-split --safe --auto-inline #-} module NotionsOfDecidability.Decidable where open import MLTT.Spartan open import MLTT.Plus-Properties open import MLTT.Two-Properties open import UF.Subsingletons ¬¬-elim : {A : π€ Μ } β decidable A β ¬¬ A β A ¬¬-elim (inl a) f = a ¬¬-elim (inr g) f = π-elim(f g) map-decidable : {A : π€ Μ } {B : π₯ Μ } β (A β B) β (B β A) β decidable A β decidable B map-decidable f g (inl x) = inl (f x) map-decidable f g (inr h) = inr (Ξ» y β h (g y)) map-decidable-corollary : {A : π€ Μ } {B : π₯ Μ } β (A β B) β (decidable A β decidable B) map-decidable-corollary (f , g) = map-decidable f g , map-decidable g f map-decidable' : {A : π€ Μ } {B : π₯ Μ } β (A β Β¬ B) β (Β¬ A β B) β decidable A β decidable B map-decidable' f g (inl x) = inr (f x) map-decidable' f g (inr h) = inl (g h) 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 π-decidable : decidable (π {π€}) π-decidable = pointed-decidable β 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) Γ-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: s \begin{code} indicator : {X : π€ Μ } {A : X β π₯ Μ } {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}