Skip to content

Commit 1e42bf4

Browse files
authored
Refactor Data.Sum.{to|from}Dec via move+deprecate in Relation.Nullary.Decidable.Core (#2405)
* fixes #2059 on the model of #2336 * fixed `import` dependencies * simplified `import` dependencies * final tweak * `CHANGELOG`
1 parent 3c6c47c commit 1e42bf4

File tree

8 files changed

+66
-39
lines changed

8 files changed

+66
-39
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ Deprecated names
113113
*-pres-∣ ↦ Data.Nat.Divisibility.*-pres-∣
114114
```
115115

116+
* In `Data.Sum`:
117+
```agda
118+
fromDec ↦ Relation.Nullary.Decidable.Core.toSum
119+
toDec ↦ Relation.Nullary.Decidable.Core.fromSum
120+
```
121+
116122
* In `IO.Base`:
117123
```agda
118124
untilRight ↦ untilInj₂
@@ -818,6 +824,8 @@ Additions to existing modules
818824
* Added new proof in `Relation.Nullary.Decidable.Core`:
819825
```agda
820826
recompute-constant : (a? : Dec A) (p q : A) → recompute a? p ≡ recompute a? q
827+
toSum : Dec A → A ⊎ ¬ A
828+
fromSum : A ⊎ ¬ A → Dec A
821829
```
822830

823831
* Added new proof in `Relation.Nullary.Decidable`:

src/Data/List/Fresh/Relation/Unary/Any.agda

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
module Data.List.Fresh.Relation.Unary.Any where
1010

1111
open import Level using (Level; _⊔_; Lift)
12-
open import Data.Empty
1312
open import Data.Product.Base using (∃; _,_; -,_)
1413
open import Data.Sum.Base using (_⊎_; [_,_]′; inj₁; inj₂)
1514
open import Function.Bundles using (_⇔_; mk⇔)
16-
open import Relation.Nullary.Negation using (¬_)
17-
open import Relation.Nullary.Decidable as Dec using (Dec; yes; no; _⊎-dec_)
15+
open import Relation.Nullary.Negation using (¬_; contradiction)
16+
open import Relation.Nullary.Decidable as Dec using (Dec; no; _⊎-dec_)
1817
open import Relation.Unary as U
1918
open import Relation.Binary.Core using (Rel)
2019

@@ -35,10 +34,10 @@ module _ {R : Rel A r} {P : Pred A p} {x} {xs : List# A R} {pr} where
3534

3635
head : ¬ Any P xs Any P (cons x xs pr) P x
3736
head ¬tail (here p) = p
38-
head ¬tail (there ps) = ⊥-elim (¬tail ps)
37+
head ¬tail (there ps) = contradiction ps ¬tail
3938

4039
tail : ¬ P x Any P (cons x xs pr) Any P xs
41-
tail ¬head (here p) = ⊥-elim (¬head p)
40+
tail ¬head (here p) = contradiction p ¬head
4241
tail ¬head (there ps) = ps
4342

4443
toSum : Any P (cons x xs pr) P x ⊎ Any P xs

src/Data/List/Relation/Unary/Any.agda

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ open import Data.List.Base as List using (List; []; [_]; _∷_; removeAt)
1313
open import Data.Product.Base as Product using (∃; _,_)
1414
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
1515
open import Level using (Level; _⊔_)
16-
open import Relation.Nullary using (¬_; yes; no; _⊎-dec_)
17-
import Relation.Nullary.Decidable as Dec
18-
open import Relation.Nullary.Negation using (contradiction)
16+
open import Relation.Nullary.Decidable.Core as Dec using (no; _⊎-dec_)
17+
open import Relation.Nullary.Negation using (¬_; contradiction)
1918
open import Relation.Unary using (Pred; _⊆_; Decidable; Satisfiable)
2019

2120
private

src/Data/List/Relation/Unary/First/Properties.agda

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ open import Data.List.Base as List using (List; []; _∷_)
1313
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
1414
open import Data.List.Relation.Unary.Any as Any using (here; there)
1515
open import Data.List.Relation.Unary.First
16-
import Data.Sum as Sum
17-
open import Function.Base using (_∘′_; _$_; _∘_; id)
16+
import Data.Sum.Base as Sum
17+
open import Function.Base using (_∘′_; _∘_; id)
1818
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_; refl; _≗_)
19+
import Relation.Nullary.Decidable.Core as Dec
20+
open import Relation.Nullary.Negation.Core using (contradiction)
1921
open import Relation.Unary using (Pred; _⊆_; ∁; Irrelevant; Decidable)
20-
open import Relation.Nullary.Negation using (contradiction)
2122

2223
------------------------------------------------------------------------
2324
-- map
@@ -80,14 +81,14 @@ module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
8081
module _ {a p} {A : Set a} {P : Pred A p} where
8182

8283
first? : Decidable P Decidable (First P (∁ P))
83-
first? P? xs = Sum.toDec
84-
$ Sum.map₂ (All⇒¬First contradiction)
85-
$ first (Sum.fromDec ∘ P?) xs
84+
first? P? = Dec.fromSum
85+
Sum.map₂ (All⇒¬First contradiction)
86+
first (Dec.toSum ∘ P?)
8687

8788
cofirst? : Decidable P Decidable (First (∁ P) P)
88-
cofirst? P? xs = Sum.toDec
89-
$ Sum.map₂ (All⇒¬First id)
90-
$ first (Sum.swap ∘ Sum.fromDec ∘ P?) xs
89+
cofirst? P? = Dec.fromSum
90+
Sum.map₂ (All⇒¬First id)
91+
first (Sum.swap ∘ Dec.toSum ∘ P?)
9192

9293
------------------------------------------------------------------------
9394
-- Conversion to Any

src/Data/Sum.agda

+10-14
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88

99
module Data.Sum where
1010

11-
open import Agda.Builtin.Equality
12-
13-
open import Data.Bool.Base using (true; false)
1411
open import Data.Unit.Polymorphic.Base using (⊤; tt)
1512
open import Data.Maybe.Base using (Maybe; just; nothing)
16-
open import Function.Base
1713
open import Level
18-
open import Relation.Nullary.Reflects using (invert)
19-
open import Relation.Nullary using (Dec; yes; no; _because_; ¬_)
14+
import Relation.Nullary.Decidable.Core as Dec
2015

2116
private
2217
variable
@@ -31,7 +26,7 @@ open import Data.Sum.Base public
3126
------------------------------------------------------------------------
3227
-- Additional functions
3328

34-
module _ {a b} {A : Set a} {B : Set b} where
29+
module _ {A : Set a} {B : Set b} where
3530

3631
isInj₁ : A ⊎ B Maybe A
3732
isInj₁ (inj₁ x) = just x
@@ -57,12 +52,13 @@ module _ {a b} {A : Set a} {B : Set b} where
5752
from-inj₂ (inj₁ _) = _
5853
from-inj₂ (inj₂ x) = x
5954

60-
-- Conversion back and forth with Dec
55+
------------------------------------------------------------------------
56+
-- DEPRECATED NAMES
57+
------------------------------------------------------------------------
58+
-- Please use the new names as continuing support for the old names is
59+
-- not guaranteed.
60+
61+
-- Version 2.1
6162

62-
fromDec : Dec A A ⊎ ¬ A
63-
fromDec ( true because [p]) = inj₁ (invert [p])
64-
fromDec (false because [¬p]) = inj₂ (invert [¬p])
63+
open Dec public using (fromDec; toDec)
6564

66-
toDec : A ⊎ ¬ A Dec A
67-
toDec (inj₁ p) = yes p
68-
toDec (inj₂ ¬p) = no ¬p

src/Data/Vec/Relation/Unary/Any.agda

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
module Data.Vec.Relation.Unary.Any {a} {A : Set a} where
1010

11-
open import Data.Empty
1211
open import Data.Fin.Base using (Fin; zero; suc)
1312
open import Data.Nat.Base using (ℕ; zero; suc; NonZero)
1413
open import Data.Sum.Base using (_⊎_; inj₁; inj₂; [_,_]′)
1514
open import Data.Vec.Base as Vec using (Vec; []; [_]; _∷_)
1615
open import Data.Product.Base as Product using (∃; _,_)
1716
open import Level using (Level; _⊔_)
1817
open import Relation.Nullary.Negation using (¬_; contradiction)
19-
open import Relation.Nullary.Decidable as Dec using (yes; no; _⊎-dec_)
18+
open import Relation.Nullary.Decidable as Dec using (no; _⊎-dec_)
2019
open import Relation.Unary
2120

2221
private
@@ -44,7 +43,7 @@ head ¬pxs (there pxs) = contradiction pxs ¬pxs
4443

4544
-- If the head does not satisfy the predicate, then the tail will.
4645
tail : {x} ¬ P x Any P (x ∷ xs) Any P xs
47-
tail ¬px (here px) = ⊥-elim (¬px px)
46+
tail ¬px (here px) = contradiction px ¬px
4847
tail ¬px (there pxs) = pxs
4948

5049
-- Convert back and forth with sum

src/Relation/Binary/Construct/Closure/Reflexive/Properties.agda

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ open import Relation.Binary.Definitions
2121
open import Relation.Binary.Construct.Closure.Reflexive
2222
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
2323
import Relation.Binary.PropositionalEquality.Properties as ≡
24-
open import Relation.Nullary
25-
import Relation.Nullary.Decidable as Dec
24+
open import Relation.Nullary.Negation.Core using (contradiction)
25+
open import Relation.Nullary.Decidable as Dec using (yes; no)
2626
open import Relation.Unary using (Pred)
2727

2828
private
@@ -79,7 +79,7 @@ module _ {_~_ : Rel A ℓ} where
7979
... | tri> _ _ c = inj₂ [ c ]
8080

8181
dec : DecidableEquality A Decidable _~_ Decidable _~ᵒ_
82-
dec ≡-dec ~-dec a b = Dec.map ⊎⇔Refl (≡-dec a b ⊎-dec ~-dec a b)
82+
dec ≡-dec ~-dec a b = Dec.map ⊎⇔Refl (≡-dec a b Dec.⊎-dec ~-dec a b)
8383

8484
decidable : Trichotomous _≡_ _~_ Decidable _~ᵒ_
8585
decidable ~-tri a b with ~-tri a b

src/Relation/Nullary/Decidable/Core.agda

+27-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
module Relation.Nullary.Decidable.Core where
1313

1414
open import Agda.Builtin.Equality using (_≡_)
15-
open import Level using (Level; Lift)
15+
open import Level using (Level)
1616
open import Data.Bool.Base using (Bool; T; false; true; not; _∧_; _∨_)
1717
open import Data.Unit.Polymorphic.Base using (⊤)
1818
open import Data.Product.Base using (_×_)
19-
open import Data.Sum.Base using (_⊎_)
19+
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
2020
open import Function.Base using (_∘_; const; _$_; flip)
2121
open import Relation.Nullary.Recomputable as Recomputable hiding (recompute-constant)
2222
open import Relation.Nullary.Reflects as Reflects hiding (recompute; recompute-constant)
@@ -103,6 +103,17 @@ _→-dec_ : Dec A → Dec B → Dec (A → B)
103103
does (a? →-dec b?) = not (does a?) ∨ does b?
104104
proof (a? →-dec b?) = proof a? →-reflects proof b?
105105

106+
------------------------------------------------------------------------
107+
-- Relationship with Sum
108+
109+
toSum : Dec A A ⊎ ¬ A
110+
toSum ( true because [p]) = inj₁ (invert [p])
111+
toSum (false because [¬p]) = inj₂ (invert [¬p])
112+
113+
fromSum : A ⊎ ¬ A Dec A
114+
fromSum (inj₁ p) = yes p
115+
fromSum (inj₂ ¬p) = no ¬p
116+
106117
------------------------------------------------------------------------
107118
-- Relationship with booleans
108119

@@ -201,3 +212,17 @@ excluded-middle = ¬¬-excluded-middle
201212
"Warning: excluded-middle was deprecated in v2.0.
202213
Please use ¬¬-excluded-middle instead."
203214
#-}
215+
216+
-- Version 2.1
217+
218+
fromDec = toSum
219+
{-# WARNING_ON_USAGE fromDec
220+
"Warning: fromDec was deprecated in v2.1.
221+
Please use Relation.Nullary.Decidable.Core.toSum instead."
222+
#-}
223+
224+
toDec = fromSum
225+
{-# WARNING_ON_USAGE toDec
226+
"Warning: toDec was deprecated in v2.1.
227+
Please use Relation.Nullary.Decidable.Core.fromSum instead."
228+
#-}

0 commit comments

Comments
 (0)