Skip to content

Commit 586bca1

Browse files
MatthewDaggittandreasabel
authored andcommitted
Add Function.Consequences.Setoid (#2191)
* Add Function.Consequences.Setoid * Fix comment * Fix re-export bug * Finally fixed bug I hope * Removed rogue comment * More tidying up
1 parent fd3cac8 commit 586bca1

File tree

7 files changed

+136
-81
lines changed

7 files changed

+136
-81
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ Non-backwards compatible changes
752752
of these under the names `strictlySurjective`, `strictlyInverseˡ` and
753753
`strictlyInverseʳ`,
754754
- Conversion functions have been added in both directions to
755-
`Function.Consequences(.Propositional)`.
755+
`Function.Consequences(.Propositional/Setoid)`.
756756
757757
### New `Function.Strict`
758758
@@ -2028,6 +2028,8 @@ New modules
20282028
* Properties of various types of functions:
20292029
```
20302030
Function.Consequences
2031+
Function.Consequences.Setoid
2032+
Function.Consequences.Propositional
20312033
Function.Properties.Bijection
20322034
Function.Properties.RightInverse
20332035
Function.Properties.Surjection

src/Data/Product/Function/Dependent/Setoid.agda

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ open import Data.Product.Base using (map; _,_; proj₁; proj₂)
1515
open import Data.Product.Relation.Binary.Pointwise.Dependent as Σ
1616
open import Level using (Level)
1717
open import Function
18-
open import Function.Consequences
18+
open import Function.Consequences.Setoid
1919
open import Function.Properties.Injection using (mkInjection)
2020
open import Function.Properties.Surjection using (mkSurjection; ↠⇒⇔)
2121
open import Function.Properties.Equivalence using (mkEquivalence; ⇔⇒⟶; ⇔⇒⟵)
@@ -176,7 +176,7 @@ module _ where
176176
to∘to⁻ I↠J j , IndexedSetoid.trans B (to∘to⁻ A↠B _) (cast-eq B (to∘to⁻ I↠J j))
177177

178178
surj : Surjective (Func.Eq₁._≈_ func) (Func.Eq₂._≈_ func) (Func.to func)
179-
surj = strictlySurjective⇒surjective (trans (J ×ₛ B)) (Func.cong func) strictlySurj
179+
surj = strictlySurjective⇒surjective (I ×ₛ A) (J ×ₛ B) (Func.cong func) strictlySurj
180180

181181
------------------------------------------------------------------------
182182
-- LeftInverse
@@ -199,7 +199,7 @@ module _ where
199199
strictlyInvʳ (i , x) = strictlyInverseʳ I↪J i , IndexedSetoid.trans A (strictlyInverseʳ A↪B _) (cast-eq A (strictlyInverseʳ I↪J i))
200200

201201
invʳ : Inverseʳ (_≈_ (I ×ₛ A)) (_≈_ (J ×ₛ B)) (Equivalence.to equiv) (Equivalence.from equiv)
202-
invʳ = strictlyInverseʳ⇒inverseʳ {f⁻¹ = Equivalence.from equiv} (trans (I ×ₛ A)) (Equivalence.from-cong equiv) strictlyInvʳ
202+
invʳ = strictlyInverseʳ⇒inverseʳ (I ×ₛ A) (J ×ₛ B) (Equivalence.from-cong equiv) strictlyInvʳ
203203

204204

205205
------------------------------------------------------------------------
@@ -238,7 +238,7 @@ module _ where
238238
(cast-eq B (strictlyInverseˡ I↔J i))
239239

240240
invˡ : Inverseˡ (_≈_ (I ×ₛ A)) (_≈_ (J ×ₛ B)) to′ from′
241-
invˡ = strictlyInverseˡ⇒inverseˡ {≈₁ = _≈_ (I ×ₛ A)} {f⁻¹ = from′} (trans (J ×ₛ B)) to′-cong strictlyInvˡ
241+
invˡ = strictlyInverseˡ⇒inverseˡ (I ×ₛ A) (J ×ₛ B) to′-cong strictlyInvˡ
242242

243243
lem : {i j} i ≡ j {x : IndexedSetoid.Carrier B (to I↔J i)} {y : IndexedSetoid.Carrier B (to I↔J j)}
244244
IndexedSetoid._≈_ B x y
@@ -250,5 +250,5 @@ module _ where
250250
IndexedSetoid.trans A (lem (strictlyInverseʳ I↔J _) (cast-eq B (strictlyInverseˡ I↔J _))) (strictlyInverseʳ A↔B _)
251251

252252
invʳ : Inverseʳ (_≈_ (I ×ₛ A)) (_≈_ (J ×ₛ B)) to′ from′
253-
invʳ = strictlyInverseʳ⇒inverseʳ {f⁻¹ = from′} (trans (I ×ₛ A)) from′-cong strictlyInvʳ
253+
invʳ = strictlyInverseʳ⇒inverseʳ (I ×ₛ A) (J ×ₛ B) from′-cong strictlyInvʳ
254254

src/Function/Consequences.agda

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ private
2828
------------------------------------------------------------------------
2929
-- Injective
3030

31-
contraInjective : Injective ≈₁ ≈₂ f
31+
contraInjective : (≈₂ : Rel B ℓ₂) Injective ≈₁ ≈₂ f
3232
{x y} ¬ (≈₁ x y) ¬ (≈₂ (f x) (f y))
33-
contraInjective inj p = contraposition inj p
33+
contraInjective _ inj p = contraposition inj p
3434

3535
------------------------------------------------------------------------
3636
-- Inverseˡ

src/Function/Consequences/Propositional.agda

+25-63
Original file line numberDiff line numberDiff line change
@@ -7,85 +7,47 @@
77

88
{-# OPTIONS --cubical-compatible --safe #-}
99

10-
module Function.Consequences.Propositional where
10+
module Function.Consequences.Propositional
11+
{a b} {A : Set a} {B : Set b}
12+
where
1113

14+
open import Relation.Binary.PropositionalEquality.Core using (_≡_; _≢_; cong)
15+
open import Relation.Binary.PropositionalEquality.Properties
16+
using (setoid)
1217
open import Function.Definitions
13-
open import Level
1418
open import Relation.Nullary.Negation.Core using (contraposition)
15-
open import Relation.Binary.PropositionalEquality.Core
16-
using (_≡_; _≢_; refl; sym; trans; cong)
1719

18-
import Function.Consequences as C
19-
20-
private
21-
variable
22-
a b ℓ₁ ℓ₂ : Level
23-
A B : Set a
24-
f f⁻¹ : A B
25-
26-
------------------------------------------------------------------------
27-
-- Injective
28-
29-
contraInjective : Injective _≡_ _≡_ f
30-
{x y} x ≢ y f x ≢ f y
31-
contraInjective inj p = contraposition inj p
32-
33-
------------------------------------------------------------------------
34-
-- Inverseˡ
35-
36-
inverseˡ⇒surjective : Inverseˡ _≡_ _≡_ f f⁻¹ Surjective _≡_ _≡_ f
37-
inverseˡ⇒surjective = C.inverseˡ⇒surjective _≡_
38-
39-
------------------------------------------------------------------------
40-
-- Inverseʳ
41-
42-
inverseʳ⇒injective : f
43-
Inverseʳ _≡_ _≡_ f f⁻¹
44-
Injective _≡_ _≡_ f
45-
inverseʳ⇒injective f = C.inverseʳ⇒injective _≡_ f refl sym trans
20+
import Function.Consequences.Setoid (setoid A) (setoid B) as Setoid
4621

4722
------------------------------------------------------------------------
48-
-- Inverseᵇ
23+
-- Re-export setoid properties
4924

50-
inverseᵇ⇒bijective : Inverseᵇ _≡_ _≡_ f f⁻¹ Bijective _≡_ _≡_ f
51-
inverseᵇ⇒bijective = C.inverseᵇ⇒bijective _≡_ refl sym trans
25+
open Setoid public
26+
hiding
27+
( strictlySurjective⇒surjective
28+
; strictlyInverseˡ⇒inverseˡ
29+
; strictlyInverseʳ⇒inverseʳ
30+
)
5231

5332
------------------------------------------------------------------------
54-
-- StrictlySurjective
33+
-- Properties that rely on congruence
5534

56-
surjective⇒strictlySurjective : Surjective _≡_ _≡_ f
57-
StrictlySurjective _≡_ f
58-
surjective⇒strictlySurjective =
59-
C.surjective⇒strictlySurjective _≡_ refl
35+
private
36+
variable
37+
f : A B
38+
f⁻¹ : B A
6039

6140
strictlySurjective⇒surjective : StrictlySurjective _≡_ f
6241
Surjective _≡_ _≡_ f
6342
strictlySurjective⇒surjective =
64-
C.strictlySurjective⇒surjective trans (cong _)
65-
66-
------------------------------------------------------------------------
67-
-- StrictlyInverseˡ
68-
69-
inverseˡ⇒strictlyInverseˡ : Inverseˡ _≡_ _≡_ f f⁻¹
70-
StrictlyInverseˡ _≡_ f f⁻¹
71-
inverseˡ⇒strictlyInverseˡ =
72-
C.inverseˡ⇒strictlyInverseˡ _≡_ _≡_ refl
43+
Setoid.strictlySurjective⇒surjective (cong _)
7344

74-
strictlyInverseˡ⇒inverseˡ : f
75-
StrictlyInverseˡ _≡_ f f⁻¹
45+
strictlyInverseˡ⇒inverseˡ : f StrictlyInverseˡ _≡_ f f⁻¹
7646
Inverseˡ _≡_ _≡_ f f⁻¹
7747
strictlyInverseˡ⇒inverseˡ f =
78-
C.strictlyInverseˡ⇒inverseˡ trans (cong f)
79-
80-
------------------------------------------------------------------------
81-
-- StrictlyInverseʳ
82-
83-
inverseʳ⇒strictlyInverseʳ : Inverseʳ _≡_ _≡_ f f⁻¹
84-
StrictlyInverseʳ _≡_ f f⁻¹
85-
inverseʳ⇒strictlyInverseʳ = C.inverseʳ⇒strictlyInverseʳ _≡_ _≡_ refl
48+
Setoid.strictlyInverseˡ⇒inverseˡ (cong _)
8649

87-
strictlyInverseʳ⇒inverseʳ : f
88-
StrictlyInverseʳ _≡_ f f⁻¹
50+
strictlyInverseʳ⇒inverseʳ : f StrictlyInverseʳ _≡_ f f⁻¹
8951
Inverseʳ _≡_ _≡_ f f⁻¹
90-
strictlyInverseʳ⇒inverseʳ {f⁻¹ = f⁻¹} _ =
91-
C.strictlyInverseʳ⇒inverseʳ trans (cong f⁻¹)
52+
strictlyInverseʳ⇒inverseʳ f =
53+
Setoid.strictlyInverseʳ⇒inverseʳ (cong _)

src/Function/Consequences/Setoid.agda

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Relationships between properties of functions where the equality
5+
-- over both the domain and codomain are assumed to be setoids.
6+
------------------------------------------------------------------------
7+
8+
{-# OPTIONS --cubical-compatible --safe #-}
9+
10+
open import Relation.Binary.Bundles using (Setoid)
11+
12+
module Function.Consequences.Setoid
13+
{a b ℓ₁ ℓ₂}
14+
(S : Setoid a ℓ₁)
15+
(T : Setoid b ℓ₂)
16+
where
17+
18+
open import Function.Definitions
19+
open import Relation.Nullary.Negation.Core
20+
21+
import Function.Consequences as C
22+
23+
private
24+
open module S = Setoid S using () renaming (Carrier to A; _≈_ to ≈₁)
25+
open module T = Setoid T using () renaming (Carrier to B; _≈_ to ≈₂)
26+
27+
variable
28+
f : A B
29+
f⁻¹ : B A
30+
31+
------------------------------------------------------------------------
32+
-- Injective
33+
34+
contraInjective : Injective ≈₁ ≈₂ f
35+
{x y} ¬ (≈₁ x y) ¬ (≈₂ (f x) (f y))
36+
contraInjective = C.contraInjective ≈₂
37+
38+
------------------------------------------------------------------------
39+
-- Inverseˡ
40+
41+
inverseˡ⇒surjective : Inverseˡ ≈₁ ≈₂ f f⁻¹ Surjective ≈₁ ≈₂ f
42+
inverseˡ⇒surjective = C.inverseˡ⇒surjective ≈₂
43+
44+
------------------------------------------------------------------------
45+
-- Inverseʳ
46+
47+
inverseʳ⇒injective : f Inverseʳ ≈₁ ≈₂ f f⁻¹ Injective ≈₁ ≈₂ f
48+
inverseʳ⇒injective f = C.inverseʳ⇒injective ≈₂ f T.refl S.sym S.trans
49+
50+
------------------------------------------------------------------------
51+
-- Inverseᵇ
52+
53+
inverseᵇ⇒bijective : Inverseᵇ ≈₁ ≈₂ f f⁻¹ Bijective ≈₁ ≈₂ f
54+
inverseᵇ⇒bijective = C.inverseᵇ⇒bijective ≈₂ T.refl S.sym S.trans
55+
56+
------------------------------------------------------------------------
57+
-- StrictlySurjective
58+
59+
surjective⇒strictlySurjective : Surjective ≈₁ ≈₂ f
60+
StrictlySurjective ≈₂ f
61+
surjective⇒strictlySurjective =
62+
C.surjective⇒strictlySurjective ≈₂ S.refl
63+
64+
strictlySurjective⇒surjective : Congruent ≈₁ ≈₂ f
65+
StrictlySurjective ≈₂ f
66+
Surjective ≈₁ ≈₂ f
67+
strictlySurjective⇒surjective =
68+
C.strictlySurjective⇒surjective T.trans
69+
70+
------------------------------------------------------------------------
71+
-- StrictlyInverseˡ
72+
73+
inverseˡ⇒strictlyInverseˡ : Inverseˡ ≈₁ ≈₂ f f⁻¹
74+
StrictlyInverseˡ ≈₂ f f⁻¹
75+
inverseˡ⇒strictlyInverseˡ = C.inverseˡ⇒strictlyInverseˡ ≈₁ ≈₂ S.refl
76+
77+
strictlyInverseˡ⇒inverseˡ : Congruent ≈₁ ≈₂ f
78+
StrictlyInverseˡ ≈₂ f f⁻¹
79+
Inverseˡ ≈₁ ≈₂ f f⁻¹
80+
strictlyInverseˡ⇒inverseˡ = C.strictlyInverseˡ⇒inverseˡ T.trans
81+
82+
------------------------------------------------------------------------
83+
-- StrictlyInverseʳ
84+
85+
inverseʳ⇒strictlyInverseʳ : Inverseʳ ≈₁ ≈₂ f f⁻¹
86+
StrictlyInverseʳ ≈₁ f f⁻¹
87+
inverseʳ⇒strictlyInverseʳ = C.inverseʳ⇒strictlyInverseʳ ≈₁ ≈₂ T.refl
88+
89+
strictlyInverseʳ⇒inverseʳ : Congruent ≈₂ ≈₁ f⁻¹
90+
StrictlyInverseʳ ≈₁ f f⁻¹
91+
Inverseʳ ≈₁ ≈₂ f f⁻¹
92+
strictlyInverseʳ⇒inverseʳ = C.strictlyInverseʳ⇒inverseʳ S.trans

src/Function/Properties/Inverse.agda

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ open import Relation.Binary.Structures using (IsEquivalence)
1919
open import Relation.Binary.PropositionalEquality.Core as P using (_≡_)
2020
import Relation.Binary.PropositionalEquality.Properties as P
2121
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
22-
open import Function.Consequences
22+
import Function.Consequences.Setoid as Consequences
2323

2424
import Function.Construct.Identity as Identity
2525
import Function.Construct.Symmetry as Symmetry
@@ -77,25 +77,25 @@ fromFunction I = record { to = from ; cong = from-cong }
7777
where open Inverse I
7878

7979
Inverse⇒Injection : Inverse S T Injection S T
80-
Inverse⇒Injection I = record
80+
Inverse⇒Injection {S = S} {T = T} I = record
8181
{ to = to
8282
; cong = to-cong
83-
; injective = inverseʳ⇒injective Eq₂._≈_ to Eq₂.refl Eq₁.sym Eq₁.trans inverseʳ
84-
} where open Inverse I
83+
; injective = inverseʳ⇒injective to inverseʳ
84+
} where open Inverse I; open Consequences S T
8585

8686
Inverse⇒Surjection : Inverse S T Surjection S T
8787
Inverse⇒Surjection {S = S} {T = T} I = record
8888
{ to = to
8989
; cong = to-cong
90-
; surjective = inverseˡ⇒surjective (_≈_ T) inverseˡ
91-
} where open Inverse I; open Setoid
90+
; surjective = inverseˡ⇒surjective inverseˡ
91+
} where open Inverse I; open Consequences S T
9292

9393
Inverse⇒Bijection : Inverse S T Bijection S T
94-
Inverse⇒Bijection I = record
94+
Inverse⇒Bijection {S = S} {T = T} I = record
9595
{ to = to
9696
; cong = to-cong
97-
; bijective = inverseᵇ⇒bijective Eq₂._≈_ Eq₂.refl Eq₁.sym Eq₁.trans inverse
98-
} where open Inverse I
97+
; bijective = inverseᵇ⇒bijective inverse
98+
} where open Inverse I; open Consequences S T
9999

100100
Inverse⇒Equivalence : Inverse S T Equivalence S T
101101
Inverse⇒Equivalence I = record

src/Function/Structures.agda

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module Function.Structures {a b ℓ₁ ℓ₂}
2020
open import Data.Product.Base as Product using (∃; _×_; _,_)
2121
open import Function.Base
2222
open import Function.Definitions
23-
open import Function.Consequences
2423
open import Level using (_⊔_)
2524

2625
------------------------------------------------------------------------

0 commit comments

Comments
 (0)