Skip to content

Commit 10a4d2f

Browse files
authored
Decidablity of dependent products (#1211)
1 parent beaa3f2 commit 10a4d2f

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

CHANGELOG/v1.4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ Other minor additions
4141
---------------------
4242

4343
* Added the decidablitity functions `_<‴?_`, `_≤‴?_`, `_≥‴?_`, and `_>‴?_` for deciding `≤‴` in `Data.Nat.Properties`.
44+
45+
* Moved `≡-dec` from `Data.Product.Properties.WithK` to `Data.Product.Properties`. The proof has been changed so that is uses that decidability implies UIP and no longer uses axiom K. Functions `injectiveʳ-≡` and `injectiveʳ-UIP` have also been added to `Data.Product.Properties`. Aliases have been added to `Data.Product.Properties.WithK` though there could be clashes in code which imports both modules.

src/Data/Product/Properties.agda

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
module Data.Product.Properties where
1010

11+
open import Axiom.UniquenessOfIdentityProofs
1112
open import Data.Product
12-
open import Function using (_∘_)
13-
open import Relation.Binary using (Decidable)
13+
open import Function using (_∘_;_∋_)
14+
open import Relation.Binary using (DecidableEquality)
1415
open import Relation.Binary.PropositionalEquality
1516
open import Relation.Nullary.Product
1617
import Relation.Nullary.Decidable as Dec
18+
open import Relation.Nullary using (Dec; yes; no)
1719

1820
------------------------------------------------------------------------
1921
-- Equality (dependent)
@@ -23,7 +25,17 @@ module _ {a b} {A : Set a} {B : A → Set b} where
2325
,-injectiveˡ : {a c} {b : B a} {d : B c} (a , b) ≡ (c , d) a ≡ c
2426
,-injectiveˡ refl = refl
2527

26-
-- See also Data.Product.Properties.WithK.,-injectiveʳ.
28+
,-injectiveʳ-≡ : {a b} {c : B a} {d : B b} UIP A (a , c) ≡ (b , d) (q : a ≡ b) subst B q c ≡ d
29+
,-injectiveʳ-≡ {c = c} u refl q = cong (λ x subst B x c) (u q refl)
30+
31+
,-injectiveʳ-UIP : {a} {b c : B a} UIP A (Σ A B ∋ (a , b)) ≡ (a , c) b ≡ c
32+
,-injectiveʳ-UIP u p = ,-injectiveʳ-≡ u p refl
33+
34+
≡-dec : DecidableEquality A ( {a} DecidableEquality (B a))
35+
DecidableEquality (Σ A B)
36+
≡-dec dec₁ dec₂ (a , x) (b , y) with dec₁ a b
37+
... | no [a≢b] = no ([a≢b] ∘ ,-injectiveˡ)
38+
... | yes refl = Dec.map′ (cong (a ,_)) (,-injectiveʳ-UIP (Decidable⇒UIP.≡-irrelevant dec₁)) (dec₂ x y)
2739

2840
------------------------------------------------------------------------
2941
-- Equality (non-dependent)
@@ -35,8 +47,3 @@ module _ {a b} {A : Set a} {B : Set b} where
3547

3648
,-injective : {a c : A} {b d : B} (a , b) ≡ (c , d) a ≡ c × b ≡ d
3749
,-injective refl = refl , refl
38-
39-
≡-dec : Decidable {A = A} _≡_ Decidable {A = B} _≡_
40-
Decidable {A = A × B} _≡_
41-
≡-dec dec₁ dec₂ (a , b) (c , d) =
42-
Dec.map′ (uncurry (cong₂ _,_)) ,-injective (dec₁ a c ×-dec dec₂ b d)

src/Data/Product/Properties/WithK.agda

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,17 @@
88

99
module Data.Product.Properties.WithK where
1010

11-
open import Data.Bool.Base
1211
open import Data.Product
13-
open import Data.Product.Properties using (,-injectiveˡ)
1412
open import Function
15-
open import Relation.Binary using (Decidable)
1613
open import Relation.Binary.PropositionalEquality
17-
open import Relation.Nullary.Reflects
18-
open import Relation.Nullary using (Dec; _because_; yes; no)
19-
open import Relation.Nullary.Decidable using (map′)
2014

2115
------------------------------------------------------------------------
2216
-- Equality
2317

24-
module _ {a b} {A : Set a} {B : Set b} where
25-
26-
,-injective : {a c : A} {b d : B} (a , b) ≡ (c , d) a ≡ c × b ≡ d
27-
,-injective refl = refl , refl
18+
-- These exports are deprecated from v1.4
19+
open import Data.Product.Properties using (,-injective; ≡-dec) public
2820

2921
module _ {a b} {A : Set a} {B : A Set b} where
3022

3123
,-injectiveʳ : {a} {b c : B a} (Σ A B ∋ (a , b)) ≡ (a , c) b ≡ c
3224
,-injectiveʳ refl = refl
33-
34-
-- Note: this is not an instance of `_×-dec_`, because we need `x` and `y`
35-
-- to have the same type before we can test them for equality.
36-
≡-dec : Decidable _≡_ ( {a} Decidable {A = B a} _≡_)
37-
Decidable {A = Σ A B} _≡_
38-
≡-dec dec₁ dec₂ (a , x) (b , y) with dec₁ a b
39-
... | false because [a≢b] = no (invert [a≢b] ∘ ,-injectiveˡ)
40-
... | yes refl = map′ (cong (a ,_)) ,-injectiveʳ (dec₂ x y)

0 commit comments

Comments
 (0)