@@ -24,9 +24,8 @@ open import Relation.Nullary.Negation.Core
24
24
25
25
private
26
26
variable
27
- p q : Level
28
- P : Set p
29
- Q : Set q
27
+ a b : Level
28
+ A B : Set a
30
29
31
30
------------------------------------------------------------------------
32
31
-- Definition.
@@ -41,68 +40,81 @@ private
41
40
42
41
infix 2 _because_
43
42
44
- record Dec {p} (P : Set p ) : Set p where
43
+ record Dec (A : Set a ) : Set a where
45
44
constructor _because_
46
45
field
47
46
does : Bool
48
- proof : Reflects P does
47
+ proof : Reflects A does
49
48
50
49
open Dec public
51
50
52
- pattern yes p = true because ofʸ p
53
- pattern no ¬p = false because ofⁿ ¬p
51
+ pattern yes a = true because ofʸ a
52
+ pattern no ¬a = false because ofⁿ ¬a
53
+
54
+ ------------------------------------------------------------------------
55
+ -- Flattening
56
+
57
+ module _ {A : Set a} where
58
+
59
+ From-yes : Dec A → Set a
60
+ From-yes (true because _) = A
61
+ From-yes (false because _) = Lift a ⊤
62
+
63
+ From-no : Dec A → Set a
64
+ From-no (false because _) = ¬ A
65
+ From-no (true because _) = Lift a ⊤
54
66
55
67
------------------------------------------------------------------------
56
68
-- Recompute
57
69
58
70
-- Given an irrelevant proof of a decidable type, a proof can
59
71
-- be recomputed and subsequently used in relevant contexts.
60
- recompute : ∀ {a} {A : Set a} → Dec A → .A → A
61
- recompute (yes x ) _ = x
62
- recompute (no ¬p) x = ⊥-elim (¬p x )
72
+ recompute : Dec A → .A → A
73
+ recompute (yes a ) _ = a
74
+ recompute (no ¬a) a = ⊥-elim (¬a a )
63
75
64
76
------------------------------------------------------------------------
65
77
-- Interaction with negation, sum, product etc.
66
78
67
79
infixr 1 _⊎-dec_
68
80
infixr 2 _×-dec_ _→-dec_
69
81
70
- ¬? : Dec P → Dec (¬ P )
71
- does (¬? p ?) = not (does p ?)
72
- proof (¬? p ?) = ¬-reflects (proof p ?)
82
+ ¬? : Dec A → Dec (¬ A )
83
+ does (¬? a ?) = not (does a ?)
84
+ proof (¬? a ?) = ¬-reflects (proof a ?)
73
85
74
- _×-dec_ : Dec P → Dec Q → Dec (P × Q )
75
- does (p ? ×-dec q ?) = does p ? ∧ does q ?
76
- proof (p ? ×-dec q ?) = proof p ? ×-reflects proof q ?
86
+ _×-dec_ : Dec A → Dec B → Dec (A × B )
87
+ does (a ? ×-dec b ?) = does a ? ∧ does b ?
88
+ proof (a ? ×-dec b ?) = proof a ? ×-reflects proof b ?
77
89
78
- _⊎-dec_ : Dec P → Dec Q → Dec (P ⊎ Q )
79
- does (p ? ⊎-dec q ?) = does p ? ∨ does q ?
80
- proof (p ? ⊎-dec q ?) = proof p ? ⊎-reflects proof q ?
90
+ _⊎-dec_ : Dec A → Dec B → Dec (A ⊎ B )
91
+ does (a ? ⊎-dec b ?) = does a ? ∨ does b ?
92
+ proof (a ? ⊎-dec b ?) = proof a ? ⊎-reflects proof b ?
81
93
82
- _→-dec_ : Dec P → Dec Q → Dec (P → Q )
83
- does (p ? →-dec q ?) = not (does p ?) ∨ does q ?
84
- proof (p ? →-dec q ?) = proof p ? →-reflects proof q ?
94
+ _→-dec_ : Dec A → Dec B → Dec (A → B )
95
+ does (a ? →-dec b ?) = not (does a ?) ∨ does b ?
96
+ proof (a ? →-dec b ?) = proof a ? →-reflects proof b ?
85
97
86
98
------------------------------------------------------------------------
87
99
-- Relationship with booleans
88
100
89
101
-- `isYes` is a stricter version of `does`. The lack of computation
90
- -- means that we can recover the proposition `P` from `isYes P ?` by
102
+ -- means that we can recover the proposition `P` from `isYes a ?` by
91
103
-- unification. This is useful when we are using the decision procedure
92
104
-- for proof automation.
93
105
94
- isYes : Dec P → Bool
106
+ isYes : Dec A → Bool
95
107
isYes (true because _) = true
96
108
isYes (false because _) = false
97
109
98
- isNo : Dec P → Bool
110
+ isNo : Dec A → Bool
99
111
isNo = not ∘ isYes
100
112
101
- True : Dec P → Set
102
- True Q = T (isYes Q)
113
+ True : Dec A → Set
114
+ True = T ∘ isYes
103
115
104
- False : Dec P → Set
105
- False Q = T (isNo Q)
116
+ False : Dec A → Set
117
+ False = T ∘ isNo
106
118
107
119
-- The traditional name for isYes is ⌊_⌋, indicating the stripping of evidence.
108
120
⌊_⌋ = isYes
@@ -111,77 +123,72 @@ False Q = T (isNo Q)
111
123
-- Witnesses
112
124
113
125
-- Gives a witness to the "truth".
114
- toWitness : {Q : Dec P } → True Q → P
115
- toWitness {Q = true because [p ]} _ = invert [p ]
116
- toWitness {Q = false because _ } ()
126
+ toWitness : {a? : Dec A } → True a? → A
127
+ toWitness {a? = true because [a ]} _ = invert [a ]
128
+ toWitness {a? = false because _ } ()
117
129
118
130
-- Establishes a "truth", given a witness.
119
- fromWitness : {Q : Dec P } → P → True Q
120
- fromWitness {Q = true because _ } = const _
121
- fromWitness {Q = false because [¬p ]} = invert [¬p ]
131
+ fromWitness : {a? : Dec A } → A → True a?
132
+ fromWitness {a? = true because _ } = const _
133
+ fromWitness {a? = false because [¬a ]} = invert [¬a ]
122
134
123
135
-- Variants for False.
124
- toWitnessFalse : {Q : Dec P} → False Q → ¬ P
125
- toWitnessFalse {Q = true because _ } ()
126
- toWitnessFalse {Q = false because [¬p]} _ = invert [¬p]
127
-
128
- fromWitnessFalse : {Q : Dec P} → ¬ P → False Q
129
- fromWitnessFalse {Q = true because [p]} = flip _$_ (invert [p])
130
- fromWitnessFalse {Q = false because _ } = const _
136
+ toWitnessFalse : {a? : Dec A} → False a? → ¬ A
137
+ toWitnessFalse {a? = true because _ } ()
138
+ toWitnessFalse {a? = false because [¬a]} _ = invert [¬a]
131
139
132
- module _ {p} {P : Set p} where
140
+ fromWitnessFalse : {a? : Dec A} → ¬ A → False a?
141
+ fromWitnessFalse {a? = true because [a]} = flip _$_ (invert [a])
142
+ fromWitnessFalse {a? = false because _ } = const _
133
143
134
144
-- If a decision procedure returns "yes", then we can extract the
135
145
-- proof using from-yes.
136
-
137
- From-yes : Dec P → Set p
138
- From-yes (true because _) = P
139
- From-yes (false because _) = Lift p ⊤
140
-
141
- from-yes : (p : Dec P) → From-yes p
142
- from-yes (true because [p]) = invert [p]
143
- from-yes (false because _ ) = _
146
+ from-yes : (a? : Dec A) → From-yes a?
147
+ from-yes (true because [a]) = invert [a]
148
+ from-yes (false because _ ) = _
144
149
145
150
-- If a decision procedure returns "no", then we can extract the proof
146
151
-- using from-no.
147
-
148
- From-no : Dec P → Set p
149
- From-no (false because _) = ¬ P
150
- From-no (true because _) = Lift p ⊤
151
-
152
- from-no : (p : Dec P) → From-no p
153
- from-no (false because [¬p]) = invert [¬p]
154
- from-no (true because _ ) = _
152
+ from-no : (a? : Dec A) → From-no a?
153
+ from-no (false because [¬a]) = invert [¬a]
154
+ from-no (true because _ ) = _
155
155
156
156
------------------------------------------------------------------------
157
157
-- Maps
158
158
159
- map′ : (P → Q ) → (Q → P ) → Dec P → Dec Q
160
- does (map′ P→Q Q→P p ?) = does p ?
161
- proof (map′ P→Q Q→P (true because [p ])) = ofʸ (P→Q (invert [p ]))
162
- proof (map′ P→Q Q→P (false because [¬p ])) = ofⁿ (invert [¬p ] ∘ Q→P )
159
+ map′ : (A → B ) → (B → A ) → Dec A → Dec B
160
+ does (map′ A→B B→A a ?) = does a ?
161
+ proof (map′ A→B B→A (true because [a ])) = ofʸ (A→B (invert [a ]))
162
+ proof (map′ A→B B→A (false because [¬a ])) = ofⁿ (invert [¬a ] ∘ B→A )
163
163
164
164
------------------------------------------------------------------------
165
165
-- Relationship with double-negation
166
166
167
167
-- Decidable predicates are stable.
168
168
169
- decidable-stable : Dec P → Stable P
170
- decidable-stable (yes p ) ¬¬p = p
171
- decidable-stable (no ¬p ) ¬¬p = ⊥-elim (¬¬p ¬p )
169
+ decidable-stable : Dec A → Stable A
170
+ decidable-stable (yes a ) ¬¬a = a
171
+ decidable-stable (no ¬a ) ¬¬a = ⊥-elim (¬¬a ¬a )
172
172
173
- ¬-drop-Dec : Dec (¬ ¬ P ) → Dec (¬ P )
174
- ¬-drop-Dec ¬¬p ? = map′ negated-stable contradiction (¬? ¬¬p ?)
173
+ ¬-drop-Dec : Dec (¬ ¬ A ) → Dec (¬ A )
174
+ ¬-drop-Dec ¬¬a ? = map′ negated-stable contradiction (¬? ¬¬a ?)
175
175
176
176
-- A double-negation-translated variant of excluded middle (or: every
177
177
-- nullary relation is decidable in the double-negation monad).
178
178
179
- ¬¬-excluded-middle : DoubleNegation (Dec P )
180
- ¬¬-excluded-middle ¬h = ¬h (no (λ p → ¬h (yes p )))
179
+ ¬¬-excluded-middle : DoubleNegation (Dec A )
180
+ ¬¬-excluded-middle ¬?a = ¬?a (no (λ a → ¬?a (yes a )))
181
181
182
- excluded-middle : DoubleNegation (Dec P)
183
- excluded-middle = ¬¬-excluded-middle
184
182
183
+ ------------------------------------------------------------------------
184
+ -- DEPRECATED NAMES
185
+ ------------------------------------------------------------------------
186
+ -- Please use the new names as continuing support for the old names is
187
+ -- not guaranteed.
188
+
189
+ -- Version 2.0
190
+
191
+ excluded-middle = ¬¬-excluded-middle
185
192
{-# WARNING_ON_USAGE excluded-middle
186
193
"Warning: excluded-middle was deprecated in v2.0.
187
194
Please use ¬¬-excluded-middle instead."
0 commit comments