| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Structures for types of functions |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- The contents of this file should usually be accessed from `Function`. |
| 8 |
|
| 9 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 10 |
|
| 11 |
open import Relation.Binary.Core using (Rel) |
| 12 |
open import Relation.Binary.Bundles using (Setoid) |
| 13 |
open import Relation.Binary.Structures using (IsEquivalence) |
| 14 |
|
| 15 |
module Function.Structures {a b ℓ₁ ℓ₂} |
| 16 |
{A : Set a} (_≈₁_ : Rel A ℓ₁) -- Equality over the domain |
| 17 |
{B : Set b} (_≈₂_ : Rel B ℓ₂) -- Equality over the codomain |
| 18 |
where |
| 19 |
|
| 20 |
open import Data.Product.Base as Product using (∃; _×_; _,_) |
| 21 |
open import Function.Base |
| 22 |
open import Function.Definitions |
| 23 |
open import Level using (_⊔_) |
| 24 |
|
| 25 |
------------------------------------------------------------------------ |
| 26 |
-- One element structures |
| 27 |
------------------------------------------------------------------------ |
| 28 |
|
| 29 |
record IsCongruent (to : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 30 |
field |
| 31 |
cong : Congruent _≈₁_ _≈₂_ to |
| 32 |
isEquivalence₁ : IsEquivalence _≈₁_ |
| 33 |
isEquivalence₂ : IsEquivalence _≈₂_ |
| 34 |
|
| 35 |
module Eq₁ where |
| 36 |
|
| 37 |
setoid : Setoid a ℓ₁ |
| 38 |
setoid = record |
| 39 |
{ isEquivalence = isEquivalence₁ |
| 40 |
} |
| 41 |
|
| 42 |
open Setoid setoid public |
| 43 |
|
| 44 |
module Eq₂ where |
| 45 |
|
| 46 |
setoid : Setoid b ℓ₂ |
| 47 |
setoid = record |
| 48 |
{ isEquivalence = isEquivalence₂ |
| 49 |
} |
| 50 |
|
| 51 |
open Setoid setoid public |
| 52 |
|
| 53 |
|
| 54 |
record IsInjection (to : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 55 |
field |
| 56 |
isCongruent : IsCongruent to |
| 57 |
injective : Injective _≈₁_ _≈₂_ to |
| 58 |
|
| 59 |
open IsCongruent isCongruent public |
| 60 |
|
| 61 |
|
| 62 |
record IsSurjection (f : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 63 |
field |
| 64 |
isCongruent : IsCongruent f |
| 65 |
surjective : Surjective _≈₁_ _≈₂_ f |
| 66 |
|
| 67 |
open IsCongruent isCongruent public |
| 68 |
|
| 69 |
strictlySurjective : StrictlySurjective _≈₂_ f |
| 70 |
strictlySurjective x = Product.map₂ (λ v → v Eq₁.refl) (surjective x) |
| 71 |
|
| 72 |
|
| 73 |
record IsBijection (f : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 74 |
field |
| 75 |
isInjection : IsInjection f |
| 76 |
surjective : Surjective _≈₁_ _≈₂_ f |
| 77 |
|
| 78 |
open IsInjection isInjection public |
| 79 |
|
| 80 |
bijective : Bijective _≈₁_ _≈₂_ f |
| 81 |
bijective = injective , surjective |
| 82 |
|
| 83 |
isSurjection : IsSurjection f |
| 84 |
isSurjection = record |
| 85 |
{ isCongruent = isCongruent |
| 86 |
; surjective = surjective |
| 87 |
} |
| 88 |
|
| 89 |
open IsSurjection isSurjection public |
| 90 |
using (strictlySurjective) |
| 91 |
|
| 92 |
|
| 93 |
------------------------------------------------------------------------ |
| 94 |
-- Two element structures |
| 95 |
------------------------------------------------------------------------ |
| 96 |
|
| 97 |
record IsLeftInverse (to : A → B) (from : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 98 |
field |
| 99 |
isCongruent : IsCongruent to |
| 100 |
from-cong : Congruent _≈₂_ _≈₁_ from |
| 101 |
inverseˡ : Inverseˡ _≈₁_ _≈₂_ to from |
| 102 |
|
| 103 |
open IsCongruent isCongruent public |
| 104 |
renaming (cong to to-cong) |
| 105 |
|
| 106 |
strictlyInverseˡ : StrictlyInverseˡ _≈₂_ to from |
| 107 |
strictlyInverseˡ x = inverseˡ Eq₁.refl |
| 108 |
|
| 109 |
isSurjection : IsSurjection to |
| 110 |
isSurjection = record |
| 111 |
{ isCongruent = isCongruent |
| 112 |
; surjective = λ y → from y , inverseˡ |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
record IsRightInverse (to : A → B) (from : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 117 |
field |
| 118 |
isCongruent : IsCongruent to |
| 119 |
from-cong : Congruent _≈₂_ _≈₁_ from |
| 120 |
inverseʳ : Inverseʳ _≈₁_ _≈₂_ to from |
| 121 |
|
| 122 |
open IsCongruent isCongruent public |
| 123 |
renaming (cong to to-cong) |
| 124 |
|
| 125 |
strictlyInverseʳ : StrictlyInverseʳ _≈₁_ to from |
| 126 |
strictlyInverseʳ x = inverseʳ Eq₂.refl |
| 127 |
|
| 128 |
|
| 129 |
record IsInverse (to : A → B) (from : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 130 |
field |
| 131 |
isLeftInverse : IsLeftInverse to from |
| 132 |
inverseʳ : Inverseʳ _≈₁_ _≈₂_ to from |
| 133 |
|
| 134 |
open IsLeftInverse isLeftInverse public |
| 135 |
|
| 136 |
isRightInverse : IsRightInverse to from |
| 137 |
isRightInverse = record |
| 138 |
{ isCongruent = isCongruent |
| 139 |
; from-cong = from-cong |
| 140 |
; inverseʳ = inverseʳ |
| 141 |
} |
| 142 |
|
| 143 |
open IsRightInverse isRightInverse public |
| 144 |
using (strictlyInverseʳ) |
| 145 |
|
| 146 |
inverse : Inverseᵇ _≈₁_ _≈₂_ to from |
| 147 |
inverse = inverseˡ , inverseʳ |
| 148 |
|
| 149 |
|
| 150 |
------------------------------------------------------------------------ |
| 151 |
-- Three element structures |
| 152 |
------------------------------------------------------------------------ |
| 153 |
|
| 154 |
record IsBiEquivalence |
| 155 |
(to : A → B) (from₁ : B → A) (from₂ : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 156 |
field |
| 157 |
to-isCongruent : IsCongruent to |
| 158 |
from₁-cong : Congruent _≈₂_ _≈₁_ from₁ |
| 159 |
from₂-cong : Congruent _≈₂_ _≈₁_ from₂ |
| 160 |
|
| 161 |
open IsCongruent to-isCongruent public |
| 162 |
renaming (cong to to-cong₁) |
| 163 |
|
| 164 |
|
| 165 |
record IsBiInverse |
| 166 |
(to : A → B) (from₁ : B → A) (from₂ : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 167 |
field |
| 168 |
to-isCongruent : IsCongruent to |
| 169 |
from₁-cong : Congruent _≈₂_ _≈₁_ from₁ |
| 170 |
from₂-cong : Congruent _≈₂_ _≈₁_ from₂ |
| 171 |
inverseˡ : Inverseˡ _≈₁_ _≈₂_ to from₁ |
| 172 |
inverseʳ : Inverseʳ _≈₁_ _≈₂_ to from₂ |
| 173 |
|
| 174 |
open IsCongruent to-isCongruent public |
| 175 |
renaming (cong to to-cong) |
| 176 |
|
| 177 |
|
| 178 |
------------------------------------------------------------------------ |
| 179 |
-- Other |
| 180 |
------------------------------------------------------------------------ |
| 181 |
|
| 182 |
-- See the comment on `SplitSurjection` in `Function.Bundles` for an |
| 183 |
-- explanation of (split) surjections. |
| 184 |
record IsSplitSurjection (f : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where |
| 185 |
field |
| 186 |
from : B → A |
| 187 |
isLeftInverse : IsLeftInverse f from |
| 188 |
|
| 189 |
open IsLeftInverse isLeftInverse public |