|
| 1 | +Require Import init.imports. |
| 2 | + |
| 3 | +Section Definitions. |
| 4 | + |
| 5 | + Definition isdecider {X : UU} (p : X → hProp) (f : X → bool) : UU := ∏ (x : X), (p x) <-> (f x = true). |
| 6 | + |
| 7 | + Definition decider {X : UU} (p : X → hProp) : UU := ∑ (f : X → bool), (isdecider p f). |
| 8 | + |
| 9 | + Definition deptypeddecider {X : UU} (p : X → hProp) : UU := ∏ (x : X), decidable (p x). |
| 10 | + |
| 11 | + Definition decidable_pred {X : UU} : UU := ∑ (p : X → hProp), (deptypeddecider p). |
| 12 | +End Definitions. |
| 13 | + |
| 14 | +Section Properties. |
| 15 | + Lemma isapropisdecider {X : UU} (p : X → hProp) (f : X → bool) : isaprop (isdecider p f). |
| 16 | + Proof. |
| 17 | + apply impred_isaprop. |
| 18 | + intro t. |
| 19 | + apply isapropdirprod; apply isapropimpl. |
| 20 | + - induction (f t). |
| 21 | + + apply isapropifcontr. |
| 22 | + use iscontrloopsifisaset. |
| 23 | + exact isasetbool. |
| 24 | + + apply isapropifnegtrue. |
| 25 | + exact nopathsfalsetotrue. |
| 26 | + - apply propproperty. |
| 27 | + Qed. |
| 28 | + |
| 29 | + Lemma isapropdeptypeddecider {X : UU} (p : X → hProp) : isaprop (deptypeddecider p). |
| 30 | + Proof. |
| 31 | + apply impred_isaprop. |
| 32 | + intro t. |
| 33 | + apply isapropdec. |
| 34 | + apply propproperty. |
| 35 | + Qed. |
| 36 | + |
| 37 | + Lemma decidertodeptypeddecider {X : UU} (p : X → hProp) : (decider p) → (deptypeddecider p). |
| 38 | + Proof. |
| 39 | + intros [f isdec] x. |
| 40 | + destruct (isdec x) as [isdec1 isdec2]. |
| 41 | + induction (f x). |
| 42 | + - left. |
| 43 | + apply isdec2, idpath. |
| 44 | + - right; intro px. |
| 45 | + apply nopathsfalsetotrue, isdec1. |
| 46 | + exact px. |
| 47 | + Qed. |
| 48 | + |
| 49 | + Lemma deptypeddecidertodecider {X : UU} (p : X → hProp) : (deptypeddecider p) → (decider p). |
| 50 | + Proof. |
| 51 | + intros dpd. |
| 52 | + use tpair. |
| 53 | + - intro x. |
| 54 | + induction (dpd x). |
| 55 | + + exact true. |
| 56 | + + exact false. |
| 57 | + - simpl. |
| 58 | + intro x. |
| 59 | + induction (dpd x); split. |
| 60 | + + intro px. |
| 61 | + apply idpath. |
| 62 | + + intro; exact a. |
| 63 | + + intro; contradiction. |
| 64 | + + intro. |
| 65 | + apply fromempty, nopathsfalsetotrue. |
| 66 | + exact X0. |
| 67 | + Qed. |
| 68 | + |
| 69 | + |
| 70 | + Lemma pathsbetweendeciders {X : UU} (p : X → hProp) (f g : X → bool) (isdecf : isdecider p f) (isdecg : isdecider p g) : f = g. |
| 71 | + Proof. |
| 72 | + apply funextsec. |
| 73 | + intro x. |
| 74 | + destruct (isdecf x) as [fa fb]. |
| 75 | + destruct (isdecg x) as [ga gb]. |
| 76 | + induction (g x). |
| 77 | + - set (px := gb (idpath true)). |
| 78 | + exact (fa px). |
| 79 | + - induction (f x). |
| 80 | + + apply fromempty, nopathsfalsetotrue, ga, fb. |
| 81 | + exact (idpath true). |
| 82 | + + exact (idpath false). |
| 83 | + Qed. |
| 84 | + |
| 85 | + Lemma isapropdecider {X : UU} (p : X → hProp) : isaprop (decider p). |
| 86 | + Proof. |
| 87 | + apply invproofirrelevance. |
| 88 | + intros [f isdecf] [g isdecg]. |
| 89 | + induction (pathsbetweendeciders p f g isdecf isdecg). |
| 90 | + assert (eq : isdecf = isdecg). |
| 91 | + - apply proofirrelevance. |
| 92 | + exact (isapropisdecider p f). |
| 93 | + - induction eq. |
| 94 | + exact (idpath (f,, isdecf)). |
| 95 | + Qed. |
| 96 | + |
| 97 | + Lemma isweqdecidertodeptypeddecider {X : UU} (p : X → hProp) : (decider p) ≃ (deptypeddecider p). |
| 98 | + Proof. |
| 99 | + use make_weq. |
| 100 | + - exact (decidertodeptypeddecider p). |
| 101 | + - apply (isweqimplimpl). |
| 102 | + + exact (deptypeddecidertodecider p). |
| 103 | + + exact (isapropdecider p). |
| 104 | + + exact (isapropdeptypeddecider p). |
| 105 | + Qed. |
| 106 | + |
| 107 | +End Properties. |
| 108 | + |
| 109 | +Section ClosureProperties. |
| 110 | + |
| 111 | + Lemma decidabledisj {X : UU} (p q : X → hProp) : (deptypeddecider p) → (deptypeddecider q) → (deptypeddecider (λ (x : X), (p x) ∨ (q x))). |
| 112 | + Proof. |
| 113 | + intros decp decq x. |
| 114 | + induction (decp x). |
| 115 | + - left. apply hinhpr. |
| 116 | + left. exact a. |
| 117 | + - induction (decq x). |
| 118 | + + left. apply hinhpr. |
| 119 | + right. exact a. |
| 120 | + + right. intro. |
| 121 | + use squash_to_prop. |
| 122 | + * exact ((p x) ⨿ (q x)). |
| 123 | + * exact X0. |
| 124 | + * exact isapropempty. |
| 125 | + * exact (sumofmaps b b0). |
| 126 | + Qed. |
| 127 | + |
| 128 | + Lemma decidableconj {X : UU} (p q : X → hProp) : (deptypeddecider p) → (deptypeddecider q) → (deptypeddecider (λ (x : X), (p x) ∧ (q x))). |
| 129 | + Proof. |
| 130 | + intros decp decq x. |
| 131 | + induction (decp x), (decq x). |
| 132 | + - left. exact (a,,h). |
| 133 | + - right. intros [pp qq]. exact (n qq). |
| 134 | + - right. intros [pp qq]. exact (b pp). |
| 135 | + - right. intros [pp qq]. exact (b pp). |
| 136 | + Qed. |
| 137 | + |
| 138 | + Lemma decidableneg {X : UU} (p q : X → hProp) : (deptypeddecider p) → (deptypeddecider (λ (x : X), hneg (p x))). |
| 139 | + Proof. |
| 140 | + intros decp x. |
| 141 | + induction (decp x). |
| 142 | + - right. intros f. exact (f a). |
| 143 | + - left. exact b. |
| 144 | + Qed. |
| 145 | + |
| 146 | +End ClosureProperties. |
| 147 | + |
| 148 | +Section EqualityDeciders. |
| 149 | + |
| 150 | + Definition iseqdecider (X : UU) (f : X → X → bool) : UU := ∏ (x1 x2 : X), x1 = x2 <-> f x1 x2 = true. |
| 151 | + |
| 152 | + Definition eqdecider (X : UU) := ∑ (f : X → X → bool), (iseqdecider X f). |
| 153 | + |
| 154 | + Definition make_eqdecider {X : UU} {f : X → X → bool} : (iseqdecider X f) → eqdecider (X) := (λ is : (iseqdecider X f), (f,, is)). |
| 155 | + |
| 156 | + Lemma eqdecidertodeptypedeqdecider (X : UU) : (eqdecider X) → (isdeceq X). |
| 157 | + Proof. |
| 158 | + intros [f is] x y. |
| 159 | + destruct (is x y) as [impl1 impl2]. |
| 160 | + induction (f x y). |
| 161 | + - left; apply impl2; apply idpath. |
| 162 | + - right. intros eq. apply nopathsfalsetotrue. exact (impl1 eq). |
| 163 | + Qed. |
| 164 | + |
| 165 | + Lemma deptypedeqdecidertoeqdecider (X : UU) : (isdeceq X) → (eqdecider X). |
| 166 | + Proof. |
| 167 | + intros is. |
| 168 | + use tpair. |
| 169 | + - intros x y. |
| 170 | + induction (is x y). |
| 171 | + + exact true. |
| 172 | + + exact false. |
| 173 | + - intros x y. |
| 174 | + induction (is x y); simpl; split. |
| 175 | + + exact (λ a : (x = y), (idpath true)). |
| 176 | + + exact (λ b : (true = true), a). |
| 177 | + + intros; apply fromempty; exact (b X0). |
| 178 | + + intros; apply fromempty; exact (nopathsfalsetotrue X0). |
| 179 | + Qed. |
| 180 | + |
| 181 | + Lemma eqdecidertoisapropeq (X : UU) (f : eqdecider X) : ∏ (x y : X) ,(isaprop (x = y)). |
| 182 | + Proof. |
| 183 | + intros x. |
| 184 | + apply isaproppathsfromisolated. |
| 185 | + intros y. |
| 186 | + set (dec := eqdecidertodeptypedeqdecider X f). |
| 187 | + apply (dec x). |
| 188 | + Qed. |
| 189 | + |
| 190 | + Lemma isapropiseqdecider (X : UU) (f : X → X → bool) : (isaprop (iseqdecider X f)). |
| 191 | + Proof. |
| 192 | + apply isofhlevelsn. |
| 193 | + intros is. |
| 194 | + repeat (apply impred_isaprop + intros). |
| 195 | + apply isapropdirprod; apply isapropimpl. |
| 196 | + - induction (f t). |
| 197 | + + apply isapropifcontr. |
| 198 | + use iscontrloopsifisaset. |
| 199 | + exact isasetbool. |
| 200 | + + apply isapropifnegtrue. |
| 201 | + exact nopathsfalsetotrue. |
| 202 | + - apply eqdecidertoisapropeq. |
| 203 | + use make_eqdecider. |
| 204 | + + exact f. |
| 205 | + + exact is. |
| 206 | + Qed. |
| 207 | + |
| 208 | + Lemma pathseqdeciders (X : UU) (f g : X → X → bool) (isf : iseqdecider X f) (isg : iseqdecider X g) : f = g. |
| 209 | + Proof. |
| 210 | + apply funextsec; intros x. |
| 211 | + apply funextsec; intros y. |
| 212 | + destruct (isf x y) as [implf1 implf2]. |
| 213 | + destruct (isg x y) as [implg1 implg2]. |
| 214 | + induction (g x y). |
| 215 | + - apply implf1; apply implg2. |
| 216 | + apply idpath. |
| 217 | + - induction (f x y). |
| 218 | + + apply fromempty, nopathsfalsetotrue, implg1, implf2. |
| 219 | + exact (idpath true). |
| 220 | + + exact (idpath false). |
| 221 | + Qed. |
| 222 | + |
| 223 | + Lemma isapropeqdecider (X : UU) : (isaprop (eqdecider X)). |
| 224 | + Proof. |
| 225 | + apply invproofirrelevance. |
| 226 | + intros [f isf] [g isg]. |
| 227 | + induction (pathseqdeciders X f g isf isg). |
| 228 | + assert (eq : isf = isg). |
| 229 | + - apply proofirrelevance. |
| 230 | + apply isapropiseqdecider. |
| 231 | + - induction eq. |
| 232 | + apply idpath. |
| 233 | + Qed. |
| 234 | + |
| 235 | + Lemma weqisdeceqiseqdecider (X : UU) : (isdeceq X) ≃ (eqdecider X). |
| 236 | + Proof. |
| 237 | + use make_weq. |
| 238 | + - exact (deptypedeqdecidertoeqdecider X). |
| 239 | + - apply isweqimplimpl. |
| 240 | + + exact (eqdecidertodeptypedeqdecider X). |
| 241 | + + exact (isapropisdeceq X). |
| 242 | + + exact (isapropeqdecider X). |
| 243 | + Qed. |
| 244 | +End EqualityDeciders. |
| 245 | + |
| 246 | +Section ChoiceFunction. |
| 247 | + |
| 248 | +End ChoiceFunction. |
0 commit comments