Skip to content

Commit cc14b28

Browse files
alexariceMatthewDaggitt
authored andcommitted
Change Function.Definitions to use strict inverses (#1156)
1 parent e894c1b commit cc14b28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+636
-484
lines changed

CHANGELOG.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Non-backwards compatible changes
272272
* Added new aliases `Is(Meet/Join)(Bounded)Semilattice` for `Is(Bounded)Semilattice`
273273
which can be used to indicate meet/join-ness of the original structures.
274274

275-
#### Function hierarchy
275+
#### Removal of the old function hierarchy
276276

277277
* The switch to the new function hierarchy is complete and the following definitions
278278
now use the new definitions instead of the old ones:
@@ -345,9 +345,41 @@ Non-backwards compatible changes
345345
* `Relation.Nullary.Decidable`
346346
* `map`
347347

348-
* The names of the fields in the records of the new hierarchy have been
349-
changed from `f`, `g`, `cong₁`, `cong₂` to `to`, `from`, `to-cong`, `from-cong`.
350348

349+
#### Changes to the new function hierarchy
350+
351+
* The names of the fields in `Function.Bundles` have been
352+
changed from `f`, `g`, `cong₁` and `cong₂` to `to`, `from`, `to-cong`, `from-cong`.
353+
354+
* The module `Function.Definitions` no longer has two equalities as module arguments, as
355+
they did not interact as intended with the re-exports from `Function.Definitions.(Core1/Core2)`.
356+
The latter have been removed and their definitions folded into `Function.Definitions`.
357+
358+
* In `Function.Definitions` the types of `Surjective`, `Injective` and `Surjective`
359+
have been changed from:
360+
```
361+
Surjective f = ∀ y → ∃ λ x → f x ≈₂ y
362+
Inverseˡ f g = ∀ y → f (g y) ≈₂ y
363+
Inverseʳ f g = ∀ x → g (f x) ≈₁ x
364+
```
365+
to:
366+
```
367+
Surjective f = ∀ y → ∃ λ x → ∀ {z} → z ≈₁ x → f z ≈₂ y
368+
Inverseˡ f g = ∀ {x y} → y ≈₁ g x → f y ≈₂ x
369+
Inverseʳ f g = ∀ {x y} → y ≈₂ f x → g y ≈₁ x
370+
```
371+
This is for several reasons: i) the new definitions compose much more easily, ii) Agda
372+
can better infer the equalities used.
373+
374+
To ease backwards compatibility:
375+
- the old definitions have been moved to the new names `StrictlySurjective`,
376+
`StrictlyInverseˡ` and `StrictlyInverseʳ`.
377+
- The records in `Function.Structures` and `Function.Bundles` export proofs
378+
of these under the names `strictlySurjective`, `strictlyInverseˡ` and
379+
`strictlyInverseʳ`,
380+
- Conversion functions have been added in both directions to
381+
`Function.Consequences(.Propositional)`.
382+
351383
#### Proofs of non-zeroness/positivity/negativity as instance arguments
352384

353385
* Many numeric operations in the library require their arguments to be non-zero,
@@ -2206,6 +2238,9 @@ Other minor changes
22062238
* Added a new proof to `Data.Nat.Binary.Properties`:
22072239
```agda
22082240
suc-injective : Injective _≡_ _≡_ suc
2241+
toℕ-inverseˡ : Inverseˡ _≡_ _≡_ toℕ fromℕ
2242+
toℕ-inverseʳ : Inverseʳ _≡_ _≡_ toℕ fromℕ
2243+
toℕ-inverseᵇ : Inverseᵇ _≡_ _≡_ toℕ fromℕ
22092244
```
22102245

22112246
* Added a new pattern synonym to `Data.Nat.Divisibility.Core`:

src/Algebra/Consequences/Setoid.agda

+12-25
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ open import Algebra.Core
1919
open import Algebra.Definitions _≈_
2020
open import Data.Sum.Base using (inj₁; inj₂)
2121
open import Data.Product.Base using (_,_)
22-
open import Function.Base using (_$_)
23-
import Function.Definitions as FunDefs
22+
open import Function.Base using (_$_; id; _∘_)
23+
open import Function.Definitions
2424
import Relation.Binary.Consequences as Bin
2525
open import Relation.Binary.Reasoning.Setoid S
2626
open import Relation.Unary using (Pred)
@@ -67,45 +67,32 @@ module _ {_•_ : Op₂ A} (cong : Congruent₂ _•_) where
6767
y • x ∎
6868

6969
------------------------------------------------------------------------
70-
-- Involutive/SelfInverse functions
71-
72-
module _ {f : Op₁ A} (inv : Involutive f) where
73-
74-
open FunDefs _≈_ _≈_
75-
76-
involutive⇒surjective : Surjective f
77-
involutive⇒surjective y = f y , inv y
70+
-- SelfInverse
7871

7972
module _ {f : Op₁ A} (self : SelfInverse f) where
8073

8174
selfInverse⇒involutive : Involutive f
8275
selfInverse⇒involutive = reflexive+selfInverse⇒involutive _≈_ refl self
8376

84-
private
85-
86-
inv = selfInverse⇒involutive
87-
88-
open FunDefs _≈_ _≈_
89-
90-
selfInverse⇒congruent : Congruent f
77+
selfInverse⇒congruent : Congruent _≈_ _≈_ f
9178
selfInverse⇒congruent {x} {y} x≈y = sym (self (begin
92-
f (f x) ≈⟨ inv x ⟩
79+
f (f x) ≈⟨ selfInverse⇒involutive x ⟩
9380
x ≈⟨ x≈y ⟩
9481
y ∎))
9582

96-
selfInverse⇒inverseᵇ : Inverseᵇ f f
97-
selfInverse⇒inverseᵇ = inv , inv
83+
selfInverse⇒inverseᵇ : Inverseᵇ _≈_ _≈_ f f
84+
selfInverse⇒inverseᵇ = self ∘ sym , self ∘ sym
9885

99-
selfInverse⇒surjective : Surjective f
100-
selfInverse⇒surjective = involutive⇒surjective inv
86+
selfInverse⇒surjective : Surjective _≈_ _≈_ f
87+
selfInverse⇒surjective y = f y , self ∘ sym
10188

102-
selfInverse⇒injective : Injective f
89+
selfInverse⇒injective : Injective _≈_ _≈_ f
10390
selfInverse⇒injective {x} {y} x≈y = begin
10491
x ≈˘⟨ self x≈y ⟩
105-
f (f y) ≈⟨ inv y ⟩
92+
f (f y) ≈⟨ selfInverse⇒involutive y ⟩
10693
y ∎
10794

108-
selfInverse⇒bijective : Bijective f
95+
selfInverse⇒bijective : Bijective _≈_ _≈_ f
10996
selfInverse⇒bijective = selfInverse⇒injective , selfInverse⇒surjective
11097

11198
------------------------------------------------------------------------

src/Algebra/Lattice/Morphism/Construct/Composition.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ module _ {L₁ : RawLattice a ℓ₁}
5757
IsLatticeIsomorphism L₁ L₃ (g ∘ f)
5858
isLatticeIsomorphism f-iso g-iso = record
5959
{ isLatticeMonomorphism = isLatticeMonomorphism F.isLatticeMonomorphism G.isLatticeMonomorphism
60-
; surjective = Func.surjective (_≈_ L₁) _ _ ≈₃-trans G.⟦⟧-cong F.surjective G.surjective
60+
; surjective = Func.surjective _ _ (_≈_ L₃) F.surjective G.surjective
6161
} where module F = IsLatticeIsomorphism f-iso; module G = IsLatticeIsomorphism g-iso

src/Algebra/Lattice/Morphism/Construct/Identity.agda

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ open import Algebra.Lattice.Morphism.Structures
1313
using ( module LatticeMorphisms )
1414
open import Data.Product.Base using (_,_)
1515
open import Function.Base using (id)
16+
import Function.Construct.Identity as Id
1617
open import Level using (Level)
1718
open import Relation.Binary.Morphism.Construct.Identity using (isRelHomomorphism)
1819
open import Relation.Binary.Definitions using (Reflexive)
@@ -40,5 +41,5 @@ module _ (L : RawLattice c ℓ) (open RawLattice L) (refl : Reflexive _≈_) whe
4041
isLatticeIsomorphism : IsLatticeIsomorphism id
4142
isLatticeIsomorphism = record
4243
{ isLatticeMonomorphism = isLatticeMonomorphism
43-
; surjective = _, refl
44+
; surjective = Id.surjective _
4445
}

src/Algebra/Lattice/Morphism/Structures.agda

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open import Algebra.Morphism
1212
open import Algebra.Lattice.Bundles
1313
import Algebra.Morphism.Definitions as MorphismDefinitions
1414
open import Level using (Level; _⊔_)
15-
import Function.Definitions as FunctionDefinitions
15+
open import Function.Definitions
1616
open import Relation.Binary.Morphism.Structures
1717
open import Relation.Binary.Core
1818

@@ -44,7 +44,6 @@ module LatticeMorphisms (L₁ : RawLattice a ℓ₁) (L₂ : RawLattice b ℓ₂
4444
module = MagmaMorphisms ∧-rawMagma₁ ∧-rawMagma₂
4545

4646
open MorphismDefinitions A B _≈₂_
47-
open FunctionDefinitions _≈₁_ _≈₂_
4847

4948

5049
record IsLatticeHomomorphism (⟦_⟧ : A B) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
@@ -71,7 +70,7 @@ module LatticeMorphisms (L₁ : RawLattice a ℓ₁) (L₂ : RawLattice b ℓ₂
7170
record IsLatticeMonomorphism (⟦_⟧ : A B) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
7271
field
7372
isLatticeHomomorphism : IsLatticeHomomorphism ⟦_⟧
74-
injective : Injective ⟦_⟧
73+
injective : Injective _≈₁_ _≈₂_ ⟦_⟧
7574

7675
open IsLatticeHomomorphism isLatticeHomomorphism public
7776

@@ -94,7 +93,7 @@ module LatticeMorphisms (L₁ : RawLattice a ℓ₁) (L₂ : RawLattice b ℓ₂
9493
record IsLatticeIsomorphism (⟦_⟧ : A B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
9594
field
9695
isLatticeMonomorphism : IsLatticeMonomorphism ⟦_⟧
97-
surjective : Surjective ⟦_⟧
96+
surjective : Surjective _≈₁_ _≈₂_ ⟦_⟧
9897

9998
open IsLatticeMonomorphism isLatticeMonomorphism public
10099

src/Algebra/Module/Morphism/Construct/Composition.agda

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module _
5151
IsLeftSemimoduleIsomorphism M₁ M₃ (g ∘ f)
5252
isLeftSemimoduleIsomorphism f-iso g-iso = record
5353
{ isLeftSemimoduleMonomorphism = isLeftSemimoduleMonomorphism F.isLeftSemimoduleMonomorphism G.isLeftSemimoduleMonomorphism
54-
; surjective = Func.surjective (_≈ᴹ_ M₁) _ _ (≈ᴹ-trans M₃) G.⟦⟧-cong F.surjective G.surjective
54+
; surjective = Func.surjective _ _ (_≈ᴹ_ M₃) F.surjective G.surjective
5555
} where module F = IsLeftSemimoduleIsomorphism f-iso; module G = IsLeftSemimoduleIsomorphism g-iso
5656

5757
module _
@@ -85,7 +85,7 @@ module _
8585
IsLeftModuleIsomorphism M₁ M₃ (g ∘ f)
8686
isLeftModuleIsomorphism f-iso g-iso = record
8787
{ isLeftModuleMonomorphism = isLeftModuleMonomorphism F.isLeftModuleMonomorphism G.isLeftModuleMonomorphism
88-
; surjective = Func.surjective (_≈ᴹ_ M₁) _ _ (≈ᴹ-trans M₃) G.⟦⟧-cong F.surjective G.surjective
88+
; surjective = Func.surjective _ _ (_≈ᴹ_ M₃) F.surjective G.surjective
8989
} where module F = IsLeftModuleIsomorphism f-iso; module G = IsLeftModuleIsomorphism g-iso
9090

9191
module _
@@ -119,7 +119,7 @@ module _
119119
IsRightSemimoduleIsomorphism M₁ M₃ (g ∘ f)
120120
isRightSemimoduleIsomorphism f-iso g-iso = record
121121
{ isRightSemimoduleMonomorphism = isRightSemimoduleMonomorphism F.isRightSemimoduleMonomorphism G.isRightSemimoduleMonomorphism
122-
; surjective = Func.surjective (_≈ᴹ_ M₁) _ _ (≈ᴹ-trans M₃) G.⟦⟧-cong F.surjective G.surjective
122+
; surjective = Func.surjective _ _ (_≈ᴹ_ M₃) F.surjective G.surjective
123123
} where module F = IsRightSemimoduleIsomorphism f-iso; module G = IsRightSemimoduleIsomorphism g-iso
124124

125125
module _
@@ -153,7 +153,7 @@ module _
153153
IsRightModuleIsomorphism M₁ M₃ (g ∘ f)
154154
isRightModuleIsomorphism f-iso g-iso = record
155155
{ isRightModuleMonomorphism = isRightModuleMonomorphism F.isRightModuleMonomorphism G.isRightModuleMonomorphism
156-
; surjective = Func.surjective (_≈ᴹ_ M₁) _ _ (≈ᴹ-trans M₃) G.⟦⟧-cong F.surjective G.surjective
156+
; surjective = Func.surjective _ _ (_≈ᴹ_ M₃) F.surjective G.surjective
157157
} where module F = IsRightModuleIsomorphism f-iso; module G = IsRightModuleIsomorphism g-iso
158158

159159
module _
@@ -189,7 +189,7 @@ module _
189189
IsBisemimoduleIsomorphism M₁ M₃ (g ∘ f)
190190
isBisemimoduleIsomorphism f-iso g-iso = record
191191
{ isBisemimoduleMonomorphism = isBisemimoduleMonomorphism F.isBisemimoduleMonomorphism G.isBisemimoduleMonomorphism
192-
; surjective = Func.surjective (_≈ᴹ_ M₁) _ _ (≈ᴹ-trans M₃) G.⟦⟧-cong F.surjective G.surjective
192+
; surjective = Func.surjective _ _ (_≈ᴹ_ M₃) F.surjective G.surjective
193193
} where module F = IsBisemimoduleIsomorphism f-iso; module G = IsBisemimoduleIsomorphism g-iso
194194

195195
module _
@@ -225,7 +225,7 @@ module _
225225
IsBimoduleIsomorphism M₁ M₃ (g ∘ f)
226226
isBimoduleIsomorphism f-iso g-iso = record
227227
{ isBimoduleMonomorphism = isBimoduleMonomorphism F.isBimoduleMonomorphism G.isBimoduleMonomorphism
228-
; surjective = Func.surjective (_≈ᴹ_ M₁) _ _ (≈ᴹ-trans M₃) G.⟦⟧-cong F.surjective G.surjective
228+
; surjective = Func.surjective _ _ (_≈ᴹ_ M₃) F.surjective G.surjective
229229
} where module F = IsBimoduleIsomorphism f-iso; module G = IsBimoduleIsomorphism g-iso
230230

231231
module _
@@ -258,7 +258,7 @@ module _
258258
IsSemimoduleIsomorphism M₁ M₃ (g ∘ f)
259259
isSemimoduleIsomorphism f-iso g-iso = record
260260
{ isSemimoduleMonomorphism = isSemimoduleMonomorphism F.isSemimoduleMonomorphism G.isSemimoduleMonomorphism
261-
; surjective = Func.surjective (_≈ᴹ_ M₁) _ _ (≈ᴹ-trans M₃) G.⟦⟧-cong F.surjective G.surjective
261+
; surjective = Func.surjective _ _ (_≈ᴹ_ M₃) F.surjective G.surjective
262262
} where module F = IsSemimoduleIsomorphism f-iso; module G = IsSemimoduleIsomorphism g-iso
263263

264264
module _
@@ -291,5 +291,5 @@ module _
291291
IsModuleIsomorphism M₁ M₃ (g ∘ f)
292292
isModuleIsomorphism f-iso g-iso = record
293293
{ isModuleMonomorphism = isModuleMonomorphism F.isModuleMonomorphism G.isModuleMonomorphism
294-
; surjective = Func.surjective (_≈ᴹ_ M₁) _ _ (≈ᴹ-trans M₃) G.⟦⟧-cong F.surjective G.surjective
294+
; surjective = Func.surjective _ _ (_≈ᴹ_ M₃) F.surjective G.surjective
295295
} where module F = IsModuleIsomorphism f-iso; module G = IsModuleIsomorphism g-iso

src/Algebra/Module/Morphism/Construct/Identity.agda

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ open import Algebra.Module.Morphism.Structures
2323
open import Algebra.Morphism.Construct.Identity
2424
open import Data.Product.Base using (_,_)
2525
open import Function.Base using (id)
26+
import Function.Construct.Identity as Id
2627
open import Level using (Level)
2728

2829
private
@@ -48,7 +49,7 @@ module _ {semiring : Semiring r ℓr} (M : LeftSemimodule semiring m ℓm) where
4849
isLeftSemimoduleIsomorphism : IsLeftSemimoduleIsomorphism id
4950
isLeftSemimoduleIsomorphism = record
5051
{ isLeftSemimoduleMonomorphism = isLeftSemimoduleMonomorphism
51-
; surjective = _, ≈ᴹ-refl
52+
; surjective = Id.surjective _
5253
}
5354

5455
module _ {ring : Ring r ℓr} (M : LeftModule ring m ℓm) where
@@ -70,7 +71,7 @@ module _ {ring : Ring r ℓr} (M : LeftModule ring m ℓm) where
7071
isLeftModuleIsomorphism : IsLeftModuleIsomorphism id
7172
isLeftModuleIsomorphism = record
7273
{ isLeftModuleMonomorphism = isLeftModuleMonomorphism
73-
; surjective = _, ≈ᴹ-refl
74+
; surjective = Id.surjective _
7475
}
7576

7677
module _ {semiring : Semiring r ℓr} (M : RightSemimodule semiring m ℓm) where
@@ -92,7 +93,7 @@ module _ {semiring : Semiring r ℓr} (M : RightSemimodule semiring m ℓm) wher
9293
isRightSemimoduleIsomorphism : IsRightSemimoduleIsomorphism id
9394
isRightSemimoduleIsomorphism = record
9495
{ isRightSemimoduleMonomorphism = isRightSemimoduleMonomorphism
95-
; surjective = _, ≈ᴹ-refl
96+
; surjective = Id.surjective _
9697
}
9798

9899
module _ {ring : Ring r ℓr} (M : RightModule ring m ℓm) where
@@ -114,7 +115,7 @@ module _ {ring : Ring r ℓr} (M : RightModule ring m ℓm) where
114115
isRightModuleIsomorphism : IsRightModuleIsomorphism id
115116
isRightModuleIsomorphism = record
116117
{ isRightModuleMonomorphism = isRightModuleMonomorphism
117-
; surjective = _, ≈ᴹ-refl
118+
; surjective = Id.surjective _
118119
}
119120

120121
module _ {R-semiring : Semiring r ℓr} {S-semiring : Semiring s ℓs} (M : Bisemimodule R-semiring S-semiring m ℓm) where
@@ -137,7 +138,7 @@ module _ {R-semiring : Semiring r ℓr} {S-semiring : Semiring s ℓs} (M : Bise
137138
isBisemimoduleIsomorphism : IsBisemimoduleIsomorphism id
138139
isBisemimoduleIsomorphism = record
139140
{ isBisemimoduleMonomorphism = isBisemimoduleMonomorphism
140-
; surjective = _, ≈ᴹ-refl
141+
; surjective = Id.surjective _
141142
}
142143

143144
module _ {R-ring : Ring r ℓr} {S-ring : Ring r ℓr} (M : Bimodule R-ring S-ring m ℓm) where
@@ -160,7 +161,7 @@ module _ {R-ring : Ring r ℓr} {S-ring : Ring r ℓr} (M : Bimodule R-ring S-ri
160161
isBimoduleIsomorphism : IsBimoduleIsomorphism id
161162
isBimoduleIsomorphism = record
162163
{ isBimoduleMonomorphism = isBimoduleMonomorphism
163-
; surjective = _, ≈ᴹ-refl
164+
; surjective = Id.surjective _
164165
}
165166

166167
module _ {commutativeSemiring : CommutativeSemiring r ℓr} (M : Semimodule commutativeSemiring m ℓm) where
@@ -181,7 +182,7 @@ module _ {commutativeSemiring : CommutativeSemiring r ℓr} (M : Semimodule comm
181182
isSemimoduleIsomorphism : IsSemimoduleIsomorphism id
182183
isSemimoduleIsomorphism = record
183184
{ isSemimoduleMonomorphism = isSemimoduleMonomorphism
184-
; surjective = _, ≈ᴹ-refl
185+
; surjective = Id.surjective _
185186
}
186187

187188
module _ {commutativeRing : CommutativeRing r ℓr} (M : Module commutativeRing m ℓm) where
@@ -202,5 +203,5 @@ module _ {commutativeRing : CommutativeRing r ℓr} (M : Module commutativeRing
202203
isModuleIsomorphism : IsModuleIsomorphism id
203204
isModuleIsomorphism = record
204205
{ isModuleMonomorphism = isModuleMonomorphism
205-
; surjective = _, ≈ᴹ-refl
206+
; surjective = Id.surjective _
206207
}

0 commit comments

Comments
 (0)