Debian Codegraph @

src/Algebra/Construct/Pointwise.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- For each `IsX` algebraic structure `S`, lift the structure to the
5 -- 'pointwise' function space `A → S`: categorically, this is the
6 -- *power* object in the relevant category of `X` objects and morphisms
7 --
8 -- NB the module is parametrised only wrt `A`
9 ------------------------------------------------------------------------
10
11 {-# OPTIONS --cubical-compatible --safe #-}
12
13 module Algebra.Construct.Pointwise {a} (A : Set a) where
14
15 open import Algebra.Bundles
16 open import Algebra.Core using (Op₁; Op₂)
17 open import Algebra.Structures
18 open import Data.Product.Base using (_,_)
19 open import Function.Base using (id; _∘′_; const)
20 open import Level using (Level; _⊔_)
21 open import Relation.Binary.Core using (Rel)
22 open import Relation.Binary.Bundles using (Setoid)
23 open import Relation.Binary.Structures using (IsEquivalence)
24
25 private
26
27 variable
28 c ℓ : Level
29 C : Set c
30 _≈_ : Rel C ℓ
31 ε 0# 1# : C
32 _⁻¹ -_ _⋆ : Op₁ C
33 _∙_ _+_ _*_ : Op₂ C
34
35 lift₀ : C → A → C
36 lift₀ = const
37
38 lift₁ : Op₁ C → Op₁ (A → C)
39 lift₁ = _∘′_
40
41 lift₂ : Op₂ C → Op₂ (A → C)
42 lift₂ _∙_ g h x = (g x) ∙ (h x)
43
44 liftRel : Rel C ℓ → Rel (A → C) (a ⊔ ℓ)
45 liftRel _≈_ g h = ∀ x → (g x) ≈ (h x)
46
47
48 ------------------------------------------------------------------------
49 -- Setoid structure: here rather than elsewhere? (could be imported?)
50
51 isEquivalence : IsEquivalence _≈_ → IsEquivalence (liftRel _≈_)
52 isEquivalence isEquivalence = record
53 { refl = λ {f} _ → refl {f _}
54 ; sym = λ f≈g _ → sym (f≈g _)
55 ; trans = λ f≈g g≈h _ → trans (f≈g _) (g≈h _)
56 }
57 where open IsEquivalence isEquivalence
58
59 ------------------------------------------------------------------------
60 -- Structures
61
62 isMagma : IsMagma _≈_ _∙_ → IsMagma (liftRel _≈_) (lift₂ _∙_)
63 isMagma isMagma = record
64 { isEquivalence = isEquivalence M.isEquivalence
65 ; ∙-cong = λ g h _ → M.∙-cong (g _) (h _)
66 }
67 where module M = IsMagma isMagma
68
69 isSemigroup : IsSemigroup _≈_ _∙_ → IsSemigroup (liftRel _≈_) (lift₂ _∙_)
70 isSemigroup isSemigroup = record
71 { isMagma = isMagma M.isMagma
72 ; assoc = λ f g h _ → M.assoc (f _) (g _) (h _)
73 }
74 where module M = IsSemigroup isSemigroup
75
76 isBand : IsBand _≈_ _∙_ → IsBand (liftRel _≈_) (lift₂ _∙_)
77 isBand isBand = record
78 { isSemigroup = isSemigroup M.isSemigroup
79 ; idem = λ f _ → M.idem (f _)
80 }
81 where module M = IsBand isBand
82
83 isCommutativeSemigroup : IsCommutativeSemigroup _≈_ _∙_ →
84 IsCommutativeSemigroup (liftRel _≈_) (lift₂ _∙_)
85 isCommutativeSemigroup isCommutativeSemigroup = record
86 { isSemigroup = isSemigroup M.isSemigroup
87 ; comm = λ f g _ → M.comm (f _) (g _)
88 }
89 where module M = IsCommutativeSemigroup isCommutativeSemigroup
90
91 isMonoid : IsMonoid _≈_ _∙_ ε → IsMonoid (liftRel _≈_) (lift₂ _∙_) (lift₀ ε)
92 isMonoid isMonoid = record
93 { isSemigroup = isSemigroup M.isSemigroup
94 ; identity = (λ f _ → M.identityˡ (f _)) , λ f _ → M.identityʳ (f _)
95 }
96 where module M = IsMonoid isMonoid
97
98 isCommutativeMonoid : IsCommutativeMonoid _≈_ _∙_ ε →
99 IsCommutativeMonoid (liftRel _≈_) (lift₂ _∙_) (lift₀ ε)
100 isCommutativeMonoid isCommutativeMonoid = record
101 { isMonoid = isMonoid M.isMonoid
102 ; comm = λ f g _ → M.comm (f _) (g _)
103 }
104 where module M = IsCommutativeMonoid isCommutativeMonoid
105
106 isGroup : IsGroup _≈_ _∙_ ε _⁻¹ →
107 IsGroup (liftRel _≈_) (lift₂ _∙_) (lift₀ ε) (lift₁ _⁻¹)
108 isGroup isGroup = record
109 { isMonoid = isMonoid M.isMonoid
110 ; inverse = (λ f _ → M.inverseˡ (f _)) , λ f _ → M.inverseʳ (f _)
111 ; ⁻¹-cong = λ f _ → M.⁻¹-cong (f _)
112 }
113 where module M = IsGroup isGroup
114
115 isAbelianGroup : IsAbelianGroup _≈_ _∙_ ε _⁻¹ →
116 IsAbelianGroup (liftRel _≈_) (lift₂ _∙_) (lift₀ ε) (lift₁ _⁻¹)
117 isAbelianGroup isAbelianGroup = record
118 { isGroup = isGroup M.isGroup
119 ; comm = λ f g _ → M.comm (f _) (g _)
120 }
121 where module M = IsAbelianGroup isAbelianGroup
122
123 isNearSemiring : IsNearSemiring _≈_ _+_ _*_ 0# →
124 IsNearSemiring (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#)
125 isNearSemiring isNearSemiring = record
126 { +-isMonoid = isMonoid M.+-isMonoid
127 ; *-cong = λ g h _ → M.*-cong (g _) (h _)
128 ; *-assoc = λ f g h _ → M.*-assoc (f _) (g _) (h _)
129 ; distribʳ = λ f g h _ → M.distribʳ (f _) (g _) (h _)
130 ; zeroˡ = λ f _ → M.zeroˡ (f _)
131 }
132 where module M = IsNearSemiring isNearSemiring
133
134 isSemiringWithoutOne : IsSemiringWithoutOne _≈_ _+_ _*_ 0# →
135 IsSemiringWithoutOne (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#)
136 isSemiringWithoutOne isSemiringWithoutOne = record
137 { +-isCommutativeMonoid = isCommutativeMonoid M.+-isCommutativeMonoid
138 ; *-cong = λ g h _ → M.*-cong (g _) (h _)
139 ; *-assoc = λ f g h _ → M.*-assoc (f _) (g _) (h _)
140 ; distrib = (λ f g h _ → M.distribˡ (f _) (g _) (h _)) , (λ f g h _ → M.distribʳ (f _) (g _) (h _))
141 ; zero = (λ f _ → M.zeroˡ (f _)) , (λ f _ → M.zeroʳ (f _))
142 }
143 where module M = IsSemiringWithoutOne isSemiringWithoutOne
144
145 isCommutativeSemiringWithoutOne : IsCommutativeSemiringWithoutOne _≈_ _+_ _*_ 0# →
146 IsCommutativeSemiringWithoutOne (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#)
147 isCommutativeSemiringWithoutOne isCommutativeSemiringWithoutOne = record
148 { isSemiringWithoutOne = isSemiringWithoutOne M.isSemiringWithoutOne
149 ; *-comm = λ f g _ → M.*-comm (f _) (g _)
150 }
151 where module M = IsCommutativeSemiringWithoutOne isCommutativeSemiringWithoutOne
152
153 isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero _≈_ _+_ _*_ 0# 1# →
154 IsSemiringWithoutAnnihilatingZero (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#) (lift₀ 1#)
155 isSemiringWithoutAnnihilatingZero isSemiringWithoutAnnihilatingZero = record
156 { +-isCommutativeMonoid = isCommutativeMonoid M.+-isCommutativeMonoid
157 ; *-cong = λ g h _ → M.*-cong (g _) (h _)
158 ; *-assoc = λ f g h _ → M.*-assoc (f _) (g _) (h _)
159 ; *-identity = (λ f _ → M.*-identityˡ (f _)) , λ f _ → M.*-identityʳ (f _)
160 ; distrib = (λ f g h _ → M.distribˡ (f _) (g _) (h _)) , λ f g h _ → M.distribʳ (f _) (g _) (h _)
161 }
162 where module M = IsSemiringWithoutAnnihilatingZero isSemiringWithoutAnnihilatingZero
163
164 isSemiring : IsSemiring _≈_ _+_ _*_ 0# 1# →
165 IsSemiring (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#) (lift₀ 1#)
166 isSemiring isSemiring = record
167 { isSemiringWithoutAnnihilatingZero = isSemiringWithoutAnnihilatingZero M.isSemiringWithoutAnnihilatingZero
168 ; zero = (λ f _ → M.zeroˡ (f _)) , λ f _ → M.zeroʳ (f _)
169 }
170 where module M = IsSemiring isSemiring
171
172 isCommutativeSemiring : IsCommutativeSemiring _≈_ _+_ _*_ 0# 1# →
173 IsCommutativeSemiring (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#) (lift₀ 1#)
174 isCommutativeSemiring isCommutativeSemiring = record
175 { isSemiring = isSemiring M.isSemiring
176 ; *-comm = λ f g _ → M.*-comm (f _) (g _)
177 }
178 where module M = IsCommutativeSemiring isCommutativeSemiring
179
180 isIdempotentSemiring : IsIdempotentSemiring _≈_ _+_ _*_ 0# 1# →
181 IsIdempotentSemiring (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#) (lift₀ 1#)
182 isIdempotentSemiring isIdempotentSemiring = record
183 { isSemiring = isSemiring M.isSemiring
184 ; +-idem = λ f _ → M.+-idem (f _)
185 }
186 where module M = IsIdempotentSemiring isIdempotentSemiring
187
188 isKleeneAlgebra : IsKleeneAlgebra _≈_ _+_ _*_ _⋆ 0# 1# →
189 IsKleeneAlgebra (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₁ _⋆) (lift₀ 0#) (lift₀ 1#)
190 isKleeneAlgebra isKleeneAlgebra = record
191 { isIdempotentSemiring = isIdempotentSemiring M.isIdempotentSemiring
192 ; starExpansive = (λ f _ → M.starExpansiveˡ (f _)) , λ f _ → M.starExpansiveʳ (f _)
193 ; starDestructive = (λ f g h i _ → M.starDestructiveˡ (f _) (g _) (h _) (i _))
194 , (λ f g h i _ → M.starDestructiveʳ (f _) (g _) (h _) (i _))
195 }
196 where module M = IsKleeneAlgebra isKleeneAlgebra
197
198 isQuasiring : IsQuasiring _≈_ _+_ _*_ 0# 1# →
199 IsQuasiring (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₀ 0#) (lift₀ 1#)
200 isQuasiring isQuasiring = record
201 { +-isMonoid = isMonoid M.+-isMonoid
202 ; *-cong = λ g h _ → M.*-cong (g _) (h _)
203 ; *-assoc = λ f g h _ → M.*-assoc (f _) (g _) (h _)
204 ; *-identity = (λ f _ → M.*-identityˡ (f _)) , λ f _ → M.*-identityʳ (f _)
205 ; distrib = (λ f g h _ → M.distribˡ (f _) (g _) (h _)) , λ f g h _ → M.distribʳ (f _) (g _) (h _)
206 ; zero = (λ f _ → M.zeroˡ (f _)) , λ f _ → M.zeroʳ (f _)
207 }
208 where module M = IsQuasiring isQuasiring
209
210 isRing : IsRing _≈_ _+_ _*_ -_ 0# 1# →
211 IsRing (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₁ -_) (lift₀ 0#) (lift₀ 1#)
212 isRing isRing = record
213 { +-isAbelianGroup = isAbelianGroup M.+-isAbelianGroup
214 ; *-cong = λ g h _ → M.*-cong (g _) (h _)
215 ; *-assoc = λ f g h _ → M.*-assoc (f _) (g _) (h _)
216 ; *-identity = (λ f _ → M.*-identityˡ (f _)) , λ f _ → M.*-identityʳ (f _)
217 ; distrib = (λ f g h _ → M.distribˡ (f _) (g _) (h _)) , λ f g h _ → M.distribʳ (f _) (g _) (h _)
218 }
219 where module M = IsRing isRing
220
221 isCommutativeRing : IsCommutativeRing _≈_ _+_ _*_ -_ 0# 1# →
222 IsCommutativeRing (liftRel _≈_) (lift₂ _+_) (lift₂ _*_) (lift₁ -_) (lift₀ 0#) (lift₀ 1#)
223 isCommutativeRing isCommutativeRing = record
224 { isRing = isRing M.isRing
225 ; *-comm = λ f g _ → M.*-comm (f _) (g _)
226 }
227 where module M = IsCommutativeRing isCommutativeRing
228
229 ------------------------------------------------------------------------
230 -- Bundles
231
232 magma : Magma c ℓ → Magma (a ⊔ c) (a ⊔ ℓ)
233 magma m = record { isMagma = isMagma (Magma.isMagma m) }
234
235 semigroup : Semigroup c ℓ → Semigroup (a ⊔ c) (a ⊔ ℓ)
236 semigroup m = record { isSemigroup = isSemigroup (Semigroup.isSemigroup m) }
237
238 band : Band c ℓ → Band (a ⊔ c) (a ⊔ ℓ)
239 band m = record { isBand = isBand (Band.isBand m) }
240
241 commutativeSemigroup : CommutativeSemigroup c ℓ → CommutativeSemigroup (a ⊔ c) (a ⊔ ℓ)
242 commutativeSemigroup m = record { isCommutativeSemigroup = isCommutativeSemigroup (CommutativeSemigroup.isCommutativeSemigroup m) }
243
244 monoid : Monoid c ℓ → Monoid (a ⊔ c) (a ⊔ ℓ)
245 monoid m = record { isMonoid = isMonoid (Monoid.isMonoid m) }
246
247 commutativeMonoid : CommutativeMonoid c ℓ → CommutativeMonoid (a ⊔ c) (a ⊔ ℓ)
248 commutativeMonoid m = record { isCommutativeMonoid = isCommutativeMonoid (CommutativeMonoid.isCommutativeMonoid m) }
249
250 group : Group c ℓ → Group (a ⊔ c) (a ⊔ ℓ)
251 group m = record { isGroup = isGroup (Group.isGroup m) }
252
253 abelianGroup : AbelianGroup c ℓ → AbelianGroup (a ⊔ c) (a ⊔ ℓ)
254 abelianGroup m = record { isAbelianGroup = isAbelianGroup (AbelianGroup.isAbelianGroup m) }
255
256 nearSemiring : NearSemiring c ℓ → NearSemiring (a ⊔ c) (a ⊔ ℓ)
257 nearSemiring m = record { isNearSemiring = isNearSemiring (NearSemiring.isNearSemiring m) }
258
259 semiringWithoutOne : SemiringWithoutOne c ℓ → SemiringWithoutOne (a ⊔ c) (a ⊔ ℓ)
260 semiringWithoutOne m = record { isSemiringWithoutOne = isSemiringWithoutOne (SemiringWithoutOne.isSemiringWithoutOne m) }
261
262 commutativeSemiringWithoutOne : CommutativeSemiringWithoutOne c ℓ → CommutativeSemiringWithoutOne (a ⊔ c) (a ⊔ ℓ)
263 commutativeSemiringWithoutOne m = record
264 { isCommutativeSemiringWithoutOne = isCommutativeSemiringWithoutOne (CommutativeSemiringWithoutOne.isCommutativeSemiringWithoutOne m) }
265
266 semiring : Semiring c ℓ → Semiring (a ⊔ c) (a ⊔ ℓ)
267 semiring m = record { isSemiring = isSemiring (Semiring.isSemiring m) }
268
269 commutativeSemiring : CommutativeSemiring c ℓ → CommutativeSemiring (a ⊔ c) (a ⊔ ℓ)
270 commutativeSemiring m = record { isCommutativeSemiring = isCommutativeSemiring (CommutativeSemiring.isCommutativeSemiring m) }
271
272 idempotentSemiring : IdempotentSemiring c ℓ → IdempotentSemiring (a ⊔ c) (a ⊔ ℓ)
273 idempotentSemiring m = record { isIdempotentSemiring = isIdempotentSemiring (IdempotentSemiring.isIdempotentSemiring m) }
274
275 kleeneAlgebra : KleeneAlgebra c ℓ → KleeneAlgebra (a ⊔ c) (a ⊔ ℓ)
276 kleeneAlgebra m = record { isKleeneAlgebra = isKleeneAlgebra (KleeneAlgebra.isKleeneAlgebra m) }
277
278 quasiring : Quasiring c ℓ → Quasiring (a ⊔ c) (a ⊔ ℓ)
279 quasiring m = record { isQuasiring = isQuasiring (Quasiring.isQuasiring m) }
280
281 ring : Ring c ℓ → Ring (a ⊔ c) (a ⊔ ℓ)
282 ring m = record { isRing = isRing (Ring.isRing m) }
283
284 commutativeRing : CommutativeRing c ℓ → CommutativeRing (a ⊔ c) (a ⊔ ℓ)
285 commutativeRing m = record { isCommutativeRing = isCommutativeRing (CommutativeRing.isCommutativeRing m) }