@@ -24,9 +24,8 @@ open import Relation.Nullary.Negation.Core
2424
2525private 
2626  variable 
27-     p q  :  Level
28-     P  :  Set  p
29-     Q  :  Set  q
27+     a b  :  Level
28+     A B  :  Set  a
3029
3130------------------------------------------------------------------------ 
3231-- Definition. 
@@ -41,68 +40,81 @@ private
4140
4241infix  2  _because_
4342
44- record  Dec  {p} (P  :  Set  p ) :  Set  p  where 
43+ record  Dec  (A  :  Set  a ) :  Set  a  where 
4544  constructor  _because_ 
4645  field 
4746    does   :  Bool
48-     proof  :  Reflects P  does
47+     proof  :  Reflects A  does
4948
5049open  Dec  public 
5150
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 ⊤
5466
5567------------------------------------------------------------------------ 
5668-- Recompute 
5769
5870-- Given an irrelevant proof of a decidable type, a proof can 
5971-- 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 )
6375
6476------------------------------------------------------------------------ 
6577-- Interaction with negation, sum, product etc. 
6678
6779infixr  1  _⊎-dec_
6880infixr  2  _×-dec_ _→-dec_
6981
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 ?)
7385
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 ?
7789
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 ?
8193
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 ?
8597
8698------------------------------------------------------------------------ 
8799-- Relationship with booleans 
88100
89101-- `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 
91103-- unification. This is useful when we are using the decision procedure 
92104-- for proof automation. 
93105
94- isYes  :  Dec P  →  Bool
106+ isYes  :  Dec A  →  Bool
95107isYes (true  because _) =  true
96108isYes (false because _) =  false
97109
98- isNo  :  Dec P  →  Bool
110+ isNo  :  Dec A  →  Bool
99111isNo =  not ∘ isYes
100112
101- True  :  Dec P  →  Set 
102- True Q  =  T (isYes Q) 
113+ True  :  Dec A  →  Set 
114+ True =  T ∘ isYes 
103115
104- False  :  Dec P  →  Set 
105- False Q  =  T (isNo Q) 
116+ False  :  Dec A  →  Set 
117+ False =  T ∘ isNo 
106118
107119-- The traditional name for isYes is ⌊_⌋, indicating the stripping of evidence. 
108120⌊_⌋ =  isYes
@@ -111,77 +123,72 @@ False Q = T (isNo Q)
111123-- Witnesses 
112124
113125-- 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  _ } ()
117129
118130-- 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 ]
122134
123135-- 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]
131139
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 _
133143
134144-- If a decision procedure returns "yes", then we can extract the 
135145-- 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 _ ) =  _
144149
145150-- If a decision procedure returns "no", then we can extract the proof 
146151-- 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   _ ) =  _
155155
156156------------------------------------------------------------------------ 
157157-- Maps 
158158
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 )
163163
164164------------------------------------------------------------------------ 
165165-- Relationship with double-negation 
166166
167167-- Decidable predicates are stable. 
168168
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 )
172172
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 ?)
175175
176176-- A double-negation-translated variant of excluded middle (or: every 
177177-- nullary relation is decidable in the double-negation monad). 
178178
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 )))
181181
182- excluded-middle  :  DoubleNegation (Dec P)
183- excluded-middle =  ¬¬-excluded-middle
184182
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
185192{-# WARNING_ON_USAGE excluded-middle 
186193"Warning: excluded-middle was deprecated in v2.0. 
187194Please use ¬¬-excluded-middle instead." 
0 commit comments