Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9db6707

Browse files
committedOct 13, 2023
Modernise Relation.Nullary code (#2110)
1 parent a95e78a commit 9db6707

File tree

9 files changed

+220
-225
lines changed

9 files changed

+220
-225
lines changed
 

‎CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,11 @@ Deprecated names
15551555
invPreorder ↦ converse-preorder
15561556
```
15571557

1558+
* In `Relation.Nullary.Decidable.Core`:
1559+
```
1560+
excluded-middle ↦ ¬¬-excluded-middle
1561+
```
1562+
15581563
### Renamed Data.Erased to Data.Irrelevant
15591564

15601565
* This fixes the fact we had picked the wrong name originally. The erased modality

‎src/Codata/Musical/Colist.agda

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ take (suc n) [] = Vec≤.[]
6767
take (suc n) (x ∷ xs) = x Vec≤.∷ take n (♭ xs)
6868

6969

70-
module ¬¬Monad {p} where
71-
open RawMonad (¬¬-Monad {p}) public
70+
module ¬¬Monad {a} where
71+
open RawMonad (¬¬-Monad {a}) public
7272
open ¬¬Monad -- we don't want the RawMonad content to be opened publicly
7373

7474
------------------------------------------------------------------------

‎src/Data/Nat/InfinitelyOften.agda

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ open import Relation.Binary.PropositionalEquality
2020
open import Relation.Nullary.Negation using (¬_)
2121
open import Relation.Nullary.Negation using (¬¬-Monad; call/cc)
2222
open import Relation.Unary using (Pred; _∪_; _⊆_)
23-
open RawMonad (¬¬-Monad {p = 0ℓ})
23+
24+
open RawMonad (¬¬-Monad {a = 0ℓ})
2425

2526
private
2627
variable

‎src/Relation/Nullary/Decidable.agda

+32-41
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@ module Relation.Nullary.Decidable where
1111
open import Level using (Level)
1212
open import Data.Bool.Base using (true; false; if_then_else_)
1313
open import Data.Empty using (⊥-elim)
14-
open import Data.Product.Base as Prod hiding (map)
15-
open import Data.Sum.Base as Sum hiding (map)
14+
open import Data.Product.Base using (∃; _,_)
1615
open import Function.Base
1716
open import Function.Bundles using
1817
(Injection; module Injection; module Equivalence; _⇔_; _↔_; mk↔ₛ′)
1918
open import Relation.Binary.Bundles using (Setoid; module Setoid)
2019
open import Relation.Binary.Definitions using (Decidable)
2120
open import Relation.Nullary
22-
open import Relation.Nullary.Negation
2321
open import Relation.Nullary.Reflects using (invert)
2422
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong′)
2523

2624
private
2725
variable
28-
p q r : Level
29-
P Q R : Set p
26+
a b ℓ₁ ℓ₂ : Level
27+
A B : Set a
3028

3129
------------------------------------------------------------------------
3230
-- Re-exporting the core definitions
@@ -36,56 +34,49 @@ open import Relation.Nullary.Decidable.Core public
3634
------------------------------------------------------------------------
3735
-- Maps
3836

39-
map : PQ Dec P Dec Q
40-
map P⇔Q = map′ to from
41-
where open Equivalence P⇔Q
37+
map : AB Dec A Dec B
38+
map A⇔B = map′ to from
39+
where open Equivalence A⇔B
4240

43-
module _ {a₁ a₂ b₁ b₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂}
44-
(inj : Injection A B)
45-
where
46-
47-
open Injection inj
48-
open Setoid A using () renaming (_≈_ to _≈A_)
49-
open Setoid B using () renaming (_≈_ to _≈B_)
50-
51-
-- If there is an injection from one setoid to another, and the
52-
-- latter's equivalence relation is decidable, then the former's
53-
-- equivalence relation is also decidable.
54-
55-
via-injection : Decidable _≈B_ Decidable _≈A_
56-
via-injection dec x y =
57-
map′ injective cong (dec (to x) (to y))
41+
-- If there is an injection from one setoid to another, and the
42+
-- latter's equivalence relation is decidable, then the former's
43+
-- equivalence relation is also decidable.
44+
via-injection : {S : Setoid a ℓ₁} {T : Setoid b ℓ₂}
45+
(inj : Injection S T) (open Injection inj)
46+
Decidable Eq₂._≈_ Decidable Eq₁._≈_
47+
via-injection inj _≟_ x y = map′ injective cong (to x ≟ to y)
48+
where open Injection inj
5849

5950
------------------------------------------------------------------------
6051
-- A lemma relating True and Dec
6152

62-
True-↔ : (dec : Dec P) Irrelevant P True decP
63-
True-↔ (true because [p]) irr = mk↔ₛ′ (λ _ invert [p]) _ (irr (invert [p])) cong′
64-
True-↔ (false because ofⁿ ¬p) _ = mk↔ₛ′ (λ ()) (invert (ofⁿ ¬p)) (⊥-elim ∘ ¬p) λ ()
53+
True-↔ : (a? : Dec A) Irrelevant A True a?A
54+
True-↔ (true because [a]) irr = mk↔ₛ′ (λ _ invert [a]) _ (irr (invert [a])) cong′
55+
True-↔ (false because ofⁿ ¬a) _ = mk↔ₛ′ (λ ()) (invert (ofⁿ ¬a)) (⊥-elim ∘ ¬a) λ ()
6556

6657
------------------------------------------------------------------------
6758
-- Result of decidability
6859

69-
isYes≗does : (P? : Dec P) isYes P? ≡ does P?
60+
isYes≗does : (a? : Dec A) isYes a? ≡ does a?
7061
isYes≗does (true because _) = refl
7162
isYes≗does (false because _) = refl
7263

73-
dec-true : (p? : Dec P) P does p? ≡ true
74-
dec-true (true because _ ) p = refl
75-
dec-true (false because [¬p]) p = ⊥-elim (invert [¬p] p)
64+
dec-true : (a? : Dec A) A does a? ≡ true
65+
dec-true (true because _ ) a = refl
66+
dec-true (false because [¬a]) a = ⊥-elim (invert [¬a] a)
7667

77-
dec-false : (p? : Dec P) ¬ P does p? ≡ false
78-
dec-false (false because _ ) ¬p = refl
79-
dec-false (true because [p]) ¬p = ⊥-elim (¬p (invert [p]))
68+
dec-false : (a? : Dec A) ¬ A does a? ≡ false
69+
dec-false (false because _ ) ¬a = refl
70+
dec-false (true because [a]) ¬a = ⊥-elim (¬a (invert [a]))
8071

81-
dec-yes : (p? : Dec P) P λ p′ p? ≡ yes p′
82-
dec-yes p? p with dec-true p? p
83-
dec-yes (yes p′) p | refl = p′ , refl
72+
dec-yes : (a? : Dec A) A λ a a? ≡ yes a
73+
dec-yes a? a with dec-true a? a
74+
dec-yes (yes a′) a | refl = a′ , refl
8475

85-
dec-no : (p? : Dec P) (¬p : ¬ P) p? ≡ no ¬p
86-
dec-no p? ¬p with dec-false p? ¬p
76+
dec-no : (a? : Dec A) (¬a : ¬ A) a? ≡ no ¬a
77+
dec-no a? ¬a with dec-false a? ¬a
8778
dec-no (no _) _ | refl = refl
8879

89-
dec-yes-irr : (p? : Dec P) Irrelevant P (p : P) p? ≡ yes p
90-
dec-yes-irr p? irr p with dec-yes p? p
91-
... | p′ , eq rewrite irr p p= eq
80+
dec-yes-irr : (a? : Dec A) Irrelevant A (a : A) a? ≡ yes a
81+
dec-yes-irr a? irr a with dec-yes a? a
82+
... | a′ , eq rewrite irr a a= eq

‎src/Relation/Nullary/Decidable/Core.agda

+79-72
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ open import Relation.Nullary.Negation.Core
2424

2525
private
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

4241
infix 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

5049
open 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

6779
infixr 1 _⊎-dec_
6880
infixr 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 (PQ)
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 (AB)
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
95107
isYes (true because _) = true
96108
isYes (false because _) = false
97109

98-
isNo : Dec P Bool
110+
isNo : Dec A Bool
99111
isNo = 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.
187194
Please use ¬¬-excluded-middle instead."

‎src/Relation/Nullary/Negation.agda

+30-38
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; [_,_])
1616
open import Function.Base using (flip; _∘_; const; _∘′_)
1717
open import Level using (Level)
1818
open import Relation.Nullary.Decidable.Core using (Dec; yes; no; ¬¬-excluded-middle)
19-
open import Relation.Unary using (Universal)
19+
open import Relation.Unary using (Universal; Pred)
2020

2121
private
2222
variable
23-
a p q r w : Level
24-
A : Set a
25-
P : Set p
26-
Q : Set q
27-
R : Set r
23+
a b c d p w : Level
24+
A B C D : Set a
25+
P : Pred A p
2826
Whatever : Set w
2927

3028
------------------------------------------------------------------------
@@ -35,38 +33,35 @@ open import Relation.Nullary.Negation.Core public
3533
------------------------------------------------------------------------
3634
-- Quantifier juggling
3735

38-
module _ {P : A Set p} where
36+
∃⟶¬∀¬ : ∃ P ¬ ( x ¬ P x)
37+
∃⟶¬∀¬ = flip uncurry
3938

40-
∃⟶¬∀¬ : ∃ P ¬ ( x ¬ P x)
41-
∃⟶¬∀¬ = flip uncurry
39+
∀⟶¬∃¬ : ( x P x) ¬ λ x ¬ P x
40+
∀⟶¬∃¬ ∀xPx (x , ¬Px) = ¬Px (∀xPx x)
4241

43-
∀⟶¬∃¬ : ( x P x) ¬ ∃ λ x ¬ P x
44-
∀⟶¬∃¬ ∀xPx (x , ¬Px) = ¬Px (∀xPx x)
42+
¬∃⟶∀¬ : ¬ ∃ (λ x P x) x ¬ P x
43+
¬∃⟶∀¬ = curry
4544

46-
¬∃⟶∀¬ : ¬ ∃ (λ x P x) x ¬ P x
47-
¬∃⟶∀¬ = curry
45+
∀¬⟶¬∃ : ( x ¬ P x) ¬ ∃ (λ x P x)
46+
∀¬⟶¬∃ = uncurry
4847

49-
∀¬⟶¬∃ : ( x ¬ P x) ¬ ∃ (λ x P x)
50-
∀¬⟶¬∃ = uncurry
51-
52-
∃¬⟶¬∀ : ∃ (λ x ¬ P x) ¬ ( x P x)
53-
∃¬⟶¬∀ = flip ∀⟶¬∃¬
48+
∃¬⟶¬∀ : ∃ (λ x ¬ P x) ¬ ( x P x)
49+
∃¬⟶¬∀ = flip ∀⟶¬∃¬
5450

5551
------------------------------------------------------------------------
5652
-- Double Negation
5753

5854
-- Double-negation is a monad (if we assume that all elements of ¬ ¬ P
5955
-- are equal).
6056

61-
¬¬-Monad : RawMonad {p} DoubleNegation
57+
¬¬-Monad : RawMonad {a} DoubleNegation
6258
¬¬-Monad = mkRawMonad
6359
DoubleNegation
6460
contradiction
6561
(λ x f negated-stable (¬¬-map f x))
6662

67-
¬¬-push : {Q : P Set q}
68-
DoubleNegation Π[ Q ] Π[ DoubleNegation ∘ Q ]
69-
¬¬-push ¬¬P⟶Q P ¬Q = ¬¬P⟶Q (λ P⟶Q ¬Q (P⟶Q P))
63+
¬¬-push : DoubleNegation Π[ P ] Π[ DoubleNegation ∘ P ]
64+
¬¬-push ¬¬∀P a ¬Pa = ¬¬∀P (λ ∀P ¬Pa (∀P a))
7065

7166
-- If Whatever is instantiated with ¬ ¬ something, then this function
7267
-- is call with current continuation in the double-negation monad, or,
@@ -77,26 +72,25 @@ module _ {P : A → Set p} where
7772
-- that case this function can be used (with Whatever instantiated to
7873
-- ⊥).
7974

80-
call/cc : ((P Whatever) DoubleNegation P) DoubleNegation P
81-
call/cc hyp ¬p = hyp (λ p ⊥-elim (¬p p)) ¬p
75+
call/cc : ((A Whatever) DoubleNegation A) DoubleNegation A
76+
call/cc hyp ¬a = hyp (λ a ⊥-elim (¬a a)) ¬a
8277

8378
-- The "independence of premise" rule, in the double-negation monad.
84-
-- It is assumed that the index set (Q) is inhabited.
79+
-- It is assumed that the index set (A) is inhabited.
8580

86-
independence-of-premise : {R : Q Set r}
87-
Q (P Σ Q R) DoubleNegation (Σ[ x ∈ Q ] (P R x))
88-
independence-of-premise {P = P} q f = ¬¬-map helper ¬¬-excluded-middle
81+
independence-of-premise : A (B Σ A P) DoubleNegation (Σ[ x ∈ A ] (B P x))
82+
independence-of-premise {A = A} {B = B} {P = P} q f = ¬¬-map helper ¬¬-excluded-middle
8983
where
90-
helper : Dec P _
84+
helper : Dec B Σ[ x ∈ A ] (B P x)
9185
helper (yes p) = Prod.map₂ const (f p)
9286
helper (no ¬p) = (q , ⊥-elim ∘′ ¬p)
9387

9488
-- The independence of premise rule for binary sums.
9589

96-
independence-of-premise-⊎ : (P QR) DoubleNegation ((P Q) ⊎ (P R))
97-
independence-of-premise-⊎ {P = P} f = ¬¬-map helper ¬¬-excluded-middle
90+
independence-of-premise-⊎ : (A BC) DoubleNegation ((A B) ⊎ (A C))
91+
independence-of-premise-⊎ {A = A} {B = B} {C = C} f = ¬¬-map helper ¬¬-excluded-middle
9892
where
99-
helper : Dec P _
93+
helper : Dec A (A B) ⊎ (A C)
10094
helper (yes p) = Sum.map const const (f p)
10195
helper (no ¬p) = inj₁ (⊥-elim ∘′ ¬p)
10296

@@ -106,12 +100,10 @@ private
106100
-- independence-of-premise (for simplicity it is assumed that Q and
107101
-- R have the same type here):
108102

109-
corollary : {Q R : Set q}
110-
(P Q ⊎ R) DoubleNegation ((P Q) ⊎ (P R))
111-
corollary {P = P} {Q} {R} f =
112-
¬¬-map helper (independence-of-premise
113-
true ([ _,_ true , _,_ false ] ∘′ f))
103+
corollary : {B C : Set b} (A B ⊎ C) DoubleNegation ((A B) ⊎ (A C))
104+
corollary {A = A} {B = B} {C = C} f =
105+
¬¬-map helper (independence-of-premise true ([ _,_ true , _,_ false ] ∘′ f))
114106
where
115-
helper : ∃ (λ b P if b then Q else R) (P Q) ⊎ (P R)
107+
helper : ∃ (λ b A if b then B else C) (A B) ⊎ (A C)
116108
helper (true , f) = inj₁ f
117109
helper (false , f) = inj₂ f

‎src/Relation/Nullary/Negation/Core.agda

+29-30
Original file line numberDiff line numberDiff line change
@@ -9,68 +9,67 @@
99
module Relation.Nullary.Negation.Core where
1010

1111
open import Data.Bool.Base using (not)
12-
open import Data.Empty using (⊥)
13-
open import Data.Empty.Irrelevant using (⊥-elim)
14-
open import Data.Product.Base using (_×_; _,_; proj₁; proj₂)
12+
open import Data.Empty using (⊥; ⊥-elim)
1513
open import Data.Sum.Base using (_⊎_; [_,_]; inj₁; inj₂)
1614
open import Function.Base using (flip; _$_; _∘_; const)
1715
open import Level
1816

1917
private
2018
variable
2119
a p q w : Level
22-
A : Set a
23-
P : Set p
24-
Q : Set q
20+
A B C : Set a
2521
Whatever : Set w
2622

2723
------------------------------------------------------------------------
2824
-- Negation.
2925

3026
infix 3 ¬_
3127
¬_ : Set a Set a
32-
¬ P = P
28+
¬ A = A
29+
30+
------------------------------------------------------------------------
31+
-- Stability.
3332

3433
-- Double-negation
35-
DoubleNegation : Set p Set p
36-
DoubleNegation P = ¬ ¬ P
34+
DoubleNegation : Set a Set a
35+
DoubleNegation A = ¬ ¬ A
3736

3837
-- Stability under double-negation.
39-
Stable : Set p Set p
40-
Stable P = ¬ ¬ P P
38+
Stable : Set a Set a
39+
Stable A = ¬ ¬ A A
4140

4241
------------------------------------------------------------------------
43-
-- Relationship to product and sum
42+
-- Relationship to sum
4443

4544
infixr 1 _¬-⊎_
46-
_¬-⊎_ : ¬ P ¬ Q ¬ (PQ)
45+
_¬-⊎_ : ¬ A ¬ B ¬ (AB)
4746
_¬-⊎_ = [_,_]
4847

4948
------------------------------------------------------------------------
5049
-- Uses of negation
5150

52-
contradiction : P ¬ P Whatever
53-
contradiction p ¬p = ⊥-elim (¬p p)
54-
55-
contradiction₂ : P ⊎ Q ¬ P ¬ Q Whatever
56-
contradiction₂ (inj₁ p) ¬p ¬q = contradiction p ¬p
57-
contradiction₂ (inj₂ q) ¬p ¬q = contradiction q ¬q
51+
contradiction : A ¬ A Whatever
52+
contradiction a ¬a = ⊥-elim (¬a a)
5853

59-
contraposition : (P Q) ¬ Q ¬ P
60-
contraposition f ¬q p = contradiction (f p) ¬q
54+
contradiction₂ : A ⊎ B ¬ A ¬ B Whatever
55+
contradiction₂ (inj₁ a) ¬a ¬b = contradiction a ¬a
56+
contradiction₂ (inj₂ b) ¬a ¬b = contradiction b ¬b
6157

62-
-- Note also the following use of flip:
63-
private
64-
note : (P ¬ Q) Q ¬ P
65-
note = flip
58+
contraposition : (A B) ¬ B ¬ A
59+
contraposition f ¬b a = contradiction (f a) ¬b
6660

6761
-- Everything is stable in the double-negation monad.
68-
stable : ¬ ¬ Stable P
69-
stable ¬[¬¬p→p] = ¬[¬¬p→p] (λ ¬¬p ⊥-elim (¬¬p (¬[¬¬p→p] ∘ const)))
62+
stable : ¬ ¬ Stable A
63+
stable ¬[¬¬a→a] = ¬[¬¬a→a] (λ ¬¬a ⊥-elim (¬¬a (¬[¬¬a→a] ∘ const)))
7064

7165
-- Negated predicates are stable.
72-
negated-stable : Stable (¬ P)
73-
negated-stable ¬¬¬P P = ¬¬¬P (λ ¬P ¬P P)
66+
negated-stable : Stable (¬ A)
67+
negated-stable ¬¬¬a a = ¬¬¬a (_$ a)
7468

75-
¬¬-map : (P Q) ¬ ¬ P ¬ ¬ Q
69+
¬¬-map : (A B) ¬ ¬ A ¬ ¬ B
7670
¬¬-map f = contraposition (contraposition f)
71+
72+
-- Note also the following use of flip:
73+
private
74+
note : (A ¬ B) B ¬ A
75+
note = flip

‎src/Relation/Nullary/Reflects.agda

+40-40
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ open import Relation.Nullary.Negation.Core
2121

2222
private
2323
variable
24-
p q : Level
25-
P Q : Set p
24+
a : Level
25+
A B : Set a
2626

2727
------------------------------------------------------------------------
2828
-- `Reflects` idiom.
2929

30-
-- The truth value of P is reflected by a boolean value.
31-
-- `Reflects P b` is equivalent to `if b then P else ¬ P`.
30+
-- The truth value of A is reflected by a boolean value.
31+
-- `Reflects A b` is equivalent to `if b then A else ¬ A`.
3232

33-
data Reflects {p} (P : Set p) : Bool Set p where
34-
ofʸ : ( p : P) Reflects P true
35-
ofⁿ :p : ¬ P) Reflects P false
33+
data Reflects (A : Set a) : Bool Set a where
34+
ofʸ : ( a : A) Reflects A true
35+
ofⁿ :a : ¬ A) Reflects A false
3636

3737
------------------------------------------------------------------------
3838
-- Constructors and destructors
@@ -41,57 +41,57 @@ data Reflects {p} (P : Set p) : Bool → Set p where
4141
-- that the `if` expressions have already been evaluated away.
4242
-- In this case, `of` works like the relevant constructor (`ofⁿ` or
4343
-- `ofʸ`), and `invert` strips off the constructor to just give either
44-
-- the proof of `P` or the proof of `¬ P`.
44+
-- the proof of `A` or the proof of `¬ A`.
4545

46-
of : {b} if b then P else ¬ P Reflects P b
47-
of {b = false} ¬p = ofⁿ ¬p
48-
of {b = true } p = ofʸ p
46+
of : {b} if b then A else ¬ A Reflects A b
47+
of {b = false} ¬a = ofⁿ ¬a
48+
of {b = true } a = ofʸ a
4949

50-
invert : {b} Reflects P b if b then P else ¬ P
51-
invert (ofʸ p) = p
52-
invert (ofⁿ ¬p) = ¬p
50+
invert : {b} Reflects A b if b then A else ¬ A
51+
invert (ofʸ a) = a
52+
invert (ofⁿ ¬a) = ¬a
5353

5454
------------------------------------------------------------------------
5555
-- Interaction with negation, product, sums etc.
5656

57-
-- If we can decide P, then we can decide its negation.
58-
¬-reflects : {b} Reflects P b Reflects (¬ P) (not b)
59-
¬-reflects (ofʸ p) = ofⁿ (_$ p)
60-
¬-reflects (ofⁿ ¬p) = ofʸ ¬p
57+
-- If we can decide A, then we can decide its negation.
58+
¬-reflects : {b} Reflects A b Reflects (¬ A) (not b)
59+
¬-reflects (ofʸ a) = ofⁿ (_$ a)
60+
¬-reflects (ofⁿ ¬a) = ofʸ ¬a
6161

62-
-- If we can decide P and Q then we can decide their product
62+
-- If we can decide A and Q then we can decide their product
6363
infixr 2 _×-reflects_
64-
_×-reflects_ : {a b} Reflects P a Reflects Q b
65-
Reflects (P × Q) (a ∧ b)
66-
ofʸ p ×-reflects ofʸ q = ofʸ (p , q)
67-
ofʸ p ×-reflects ofⁿ ¬q = ofⁿ (¬q ∘ proj₂)
68-
ofⁿ ¬p ×-reflects _ = ofⁿ (¬p ∘ proj₁)
64+
_×-reflects_ : {a b} Reflects A a Reflects B b
65+
Reflects (A × B) (a ∧ b)
66+
ofʸ a ×-reflects ofʸ b = ofʸ (a , b)
67+
ofʸ a ×-reflects ofⁿ ¬b = ofⁿ (¬b ∘ proj₂)
68+
ofⁿ ¬a ×-reflects _ = ofⁿ (¬a ∘ proj₁)
6969

7070

7171
infixr 1 _⊎-reflects_
72-
_⊎-reflects_ : {a b} Reflects P a Reflects Q b
73-
Reflects (PQ) (a ∨ b)
74-
ofʸ p ⊎-reflects _ = ofʸ (inj₁ p)
75-
ofⁿ ¬p ⊎-reflects ofʸ q = ofʸ (inj₂ q)
76-
ofⁿ ¬p ⊎-reflects ofⁿ ¬q = ofⁿ (¬p ¬-⊎ ¬q)
72+
_⊎-reflects_ : {a b} Reflects A a Reflects B b
73+
Reflects (AB) (a ∨ b)
74+
ofʸ a ⊎-reflects _ = ofʸ (inj₁ a)
75+
ofⁿ ¬a ⊎-reflects ofʸ b = ofʸ (inj₂ b)
76+
ofⁿ ¬a ⊎-reflects ofⁿ ¬b = ofⁿ (¬a ¬-⊎ ¬b)
7777

7878
infixr 2 _→-reflects_
79-
_→-reflects_ : {a b} Reflects P a Reflects Q b
80-
Reflects (P Q) (not a ∨ b)
81-
ofʸ p →-reflects ofʸ q = ofʸ (const q)
82-
ofʸ p →-reflects ofⁿ ¬q = ofⁿ (¬q ∘ (_$ p))
83-
ofⁿ ¬p →-reflects _ = ofʸ (⊥-elim ∘ ¬p)
79+
_→-reflects_ : {a b} Reflects A a Reflects B b
80+
Reflects (A B) (not a ∨ b)
81+
ofʸ a →-reflects ofʸ b = ofʸ (const b)
82+
ofʸ a →-reflects ofⁿ ¬b = ofⁿ (¬b ∘ (_$ a))
83+
ofⁿ ¬a →-reflects _ = ofʸ (⊥-elim ∘ ¬a)
8484

8585
------------------------------------------------------------------------
8686
-- Other lemmas
8787

88-
fromEquivalence : {b} (T b P) (P T b) Reflects P b
88+
fromEquivalence : {b} (T b A) (A T b) Reflects A b
8989
fromEquivalence {b = true} sound complete = ofʸ (sound _)
9090
fromEquivalence {b = false} sound complete = ofⁿ complete
9191

9292
-- `Reflects` is deterministic.
93-
det : {b b′} Reflects P b Reflects P b′ b ≡ b′
94-
det (ofʸ p) (ofʸ p′) = refl
95-
det (ofʸ p) (ofⁿ ¬p′) = ⊥-elim (¬p′ p)
96-
det (ofⁿ ¬p) (ofʸ p′) = ⊥-elim (¬p p′)
97-
det (ofⁿ ¬p) (ofⁿ ¬p′) = refl
93+
det : {b b′} Reflects A b Reflects A b′ b ≡ b′
94+
det (ofʸ a) (ofʸ _) = refl
95+
det (ofʸ a) (ofⁿ ¬a) = contradiction a ¬a
96+
det (ofⁿ ¬a) (ofʸ a) = contradiction a ¬a
97+
det (ofⁿ ¬a) (ofⁿ _) = refl

‎src/Relation/Nullary/Universe.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ sequence {AF = AF} A extract-⊥ sequence-⇒ = helper
116116
-- Some lemmas about double negation.
117117

118118
private
119-
open module M {p} = RawMonad (¬¬-Monad {p = p})
119+
open module M {a} = RawMonad (¬¬-Monad {a = a})
120120

121121
¬¬-pull : {p} (F : PropF p) {P}
122122
⟦ F ⟧ (¬ ¬ P) ¬ ¬ ⟦ F ⟧ P

0 commit comments

Comments
 (0)
Please sign in to comment.