Skip to content

Commit fe7e88e

Browse files
authored
[ add ] Relation.Nullary.Decidable.dec-yes-recompute (#2738)
* add: new lemma * add: corollary * add: sharper corollary; deprecate old version * fix: knock-ons * fix: clean-up * refactor: remove `rewrite` steps * fix: `CHANGELOG` note * fix: broken qualified `import` * fix: module paramater name * fix: lemma names * fix: lemma names * refactor: lift basic definitions and properties out of `Recomputable` into `Core` * refactor: propagate `import`s * fix: lemma name * refactor: remove deprecation; fix `CHANGELOG` * refactor: remove coupling with `Data.Fin.Permutation`
1 parent 915d81c commit fe7e88e

File tree

5 files changed

+72
-22
lines changed

5 files changed

+72
-22
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ New modules
174174

175175
* `Relation.Binary.Properties.PartialSetoid` to systematise properties of a PER
176176

177+
* `Relation.Nullary.Recomputable.Core`
178+
177179
Additions to existing modules
178180
-----------------------------
179181

@@ -389,10 +391,17 @@ Additions to existing modules
389391
<₋-wellFounded : WellFounded _<_ → WellFounded _<₋_
390392
```
391393

394+
* In `Relation.Nullary.Decidable`:
395+
```agda
396+
dec-yes-recompute : (a? : Dec A) → .(a : A) → a? ≡ yes (recompute a? a)
397+
```
398+
392399
* In `Relation.Nullary.Decidable.Core`:
393400
```agda
394401
⊤-dec : Dec {a} ⊤
395402
⊥-dec : Dec {a} ⊥
403+
recompute-irrelevant-id : (a? : Decidable A) → Irrelevant A →
404+
(a : A) → recompute a? a ≡ a
396405
```
397406

398407
* In `Relation.Unary`:
@@ -418,6 +427,7 @@ Additions to existing modules
418427
```agda
419428
⊤-reflects : Reflects (⊤ {a}) true
420429
⊥-reflects : Reflects (⊥ {a}) false
430+
```
421431

422432
* In `Data.List.Relation.Unary.AllPairs.Properties`:
423433
```agda

src/Relation/Nullary/Decidable.agda

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open import Relation.Binary.Definitions using (Decidable)
1818
open import Relation.Nullary.Irrelevant using (Irrelevant)
1919
open import Relation.Nullary.Negation.Core using (¬_; contradiction)
2020
open import Relation.Nullary.Reflects using (invert)
21-
open import Relation.Binary.PropositionalEquality.Core
21+
open import Relation.Binary.PropositionalEquality.Core as ≡
2222
using (_≡_; refl; sym; trans)
2323

2424
private
@@ -77,15 +77,19 @@ dec-false : (a? : Dec A) → ¬ A → does a? ≡ false
7777
dec-false (false because _ ) ¬a = refl
7878
dec-false (true because [a]) ¬a = contradiction (invert [a]) ¬a
7979

80+
dec-yes-recompute : (a? : Dec A) .(a : A) a? ≡ yes (recompute a? a)
81+
dec-yes-recompute a? a with yes _ a? | refl dec-true a? (recompute a? a) = refl
82+
83+
dec-yes-irr : (a? : Dec A) Irrelevant A (a : A) a? ≡ yes a
84+
dec-yes-irr a? irr a =
85+
trans (dec-yes-recompute a? a) (≡.cong yes (recompute-irrelevant-id a? irr a))
86+
8087
dec-yes : (a? : Dec A) A λ a a? ≡ yes a
81-
dec-yes a? a with yes a′ a? | refl dec-true a? a = a′ , refl
88+
dec-yes a? a = _ , dec-yes-recompute a? a
8289

8390
dec-no : (a? : Dec A) (¬a : ¬ A) a? ≡ no ¬a
8491
dec-no a? ¬a with no _ a? | refl dec-false a? ¬a = refl
8592

86-
dec-yes-irr : (a? : Dec A) Irrelevant A (a : A) a? ≡ yes a
87-
dec-yes-irr a? irr a with a′ , eq dec-yes a? a rewrite irr a a′ = eq
88-
8993
⌊⌋-map′ : t f (a? : Dec A) ⌊ map′ {B = B} t f a? ⌋ ≡ ⌊ a? ⌋
9094
⌊⌋-map′ t f a? = trans (isYes≗does (map′ t f a?)) (sym (isYes≗does a?))
9195

src/Relation/Nullary/Decidable/Core.agda

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ open import Data.Empty.Polymorphic using (⊥)
2222
open import Data.Product.Base using (_×_)
2323
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
2424
open import Function.Base using (_∘_; const; _$_; flip)
25-
open import Relation.Nullary.Recomputable as Recomputable
26-
hiding (recompute-constant)
25+
open import Relation.Nullary.Irrelevant using (Irrelevant)
26+
open import Relation.Nullary.Recomputable.Core as Recomputable
27+
using (Recomputable)
2728
open import Relation.Nullary.Reflects as Reflects
2829
hiding (recompute; recompute-constant)
2930
open import Relation.Nullary.Negation.Core
@@ -84,6 +85,9 @@ recompute = Reflects.recompute ∘ proof
8485
recompute-constant : (a? : Dec A) (p q : A) recompute a? p ≡ recompute a? q
8586
recompute-constant = Recomputable.recompute-constant ∘ recompute
8687

88+
recompute-irrelevant-id : (a? : Dec A) Irrelevant A (a : A) recompute a? a ≡ a
89+
recompute-irrelevant-id = Recomputable.recompute-irrelevant-id ∘ recompute
90+
8791
------------------------------------------------------------------------
8892
-- Interaction with negation, sum, product etc.
8993

src/Relation/Nullary/Recomputable.agda

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
module Relation.Nullary.Recomputable where
1010

11-
open import Agda.Builtin.Equality using (_≡_; refl)
1211
open import Data.Empty using (⊥)
1312
open import Data.Irrelevant using (Irrelevant; irrelevant; [_])
1413
open import Data.Product.Base using (_×_; _,_; proj₁; proj₂)
@@ -22,22 +21,10 @@ private
2221
B : Set b
2322

2423
------------------------------------------------------------------------
25-
-- Definition
26-
--
27-
-- The idea of being 'recomputable' is that, given an *irrelevant* proof
28-
-- of a proposition `A` (signalled by being a value of type `.A`, all of
29-
-- whose inhabitants are identified up to definitional equality, and hence
30-
-- do *not* admit pattern-matching), one may 'promote' such a value to a
31-
-- 'genuine' value of `A`, available for subsequent eg. pattern-matching.
32-
33-
Recomputable : (A : Set a) Set a
34-
Recomputable A = .A A
24+
-- Re-export
3525

36-
------------------------------------------------------------------------
37-
-- Fundamental property: 'promotion' is a constant function
26+
open import Relation.Nullary.Recomputable.Core public
3827

39-
recompute-constant : (r : Recomputable A) (p q : A) r p ≡ r q
40-
recompute-constant r p q = refl
4128

4229
------------------------------------------------------------------------
4330
-- Constructions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Recomputable types and their algebra as Harrop formulas
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible --safe #-}
8+
9+
module Relation.Nullary.Recomputable.Core where
10+
11+
open import Agda.Builtin.Equality using (_≡_; refl)
12+
open import Level using (Level)
13+
open import Relation.Nullary.Irrelevant using (Irrelevant)
14+
15+
private
16+
variable
17+
a : Level
18+
A : Set a
19+
20+
21+
------------------------------------------------------------------------
22+
-- Definition
23+
--
24+
-- The idea of being 'recomputable' is that, given an *irrelevant* proof
25+
-- of a proposition `A` (signalled by being a value of type `.A`, all of
26+
-- whose inhabitants are identified up to definitional equality, and hence
27+
-- do *not* admit pattern-matching), one may 'promote' such a value to a
28+
-- 'genuine' value of `A`, available for subsequent eg. pattern-matching.
29+
30+
Recomputable : (A : Set a) Set a
31+
Recomputable A = .A A
32+
33+
------------------------------------------------------------------------
34+
-- Fundamental properties:
35+
-- given `Recomputable A`, `recompute` is a constant function;
36+
-- moreover, the identity, if `A` is propositionally irrelevant.
37+
38+
module _ (recompute : Recomputable A) where
39+
40+
recompute-constant : (p q : A) recompute p ≡ recompute q
41+
recompute-constant _ _ = refl
42+
43+
recompute-irrelevant-id : Irrelevant A (a : A) recompute a ≡ a
44+
recompute-irrelevant-id irr a = irr (recompute a) a
45+

0 commit comments

Comments
 (0)