-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathBiased.agda
266 lines (216 loc) · 8.73 KB
/
Biased.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
------------------------------------------------------------------------
-- The Agda standard library
--
-- Ways to give instances of certain structures where some fields can
-- be given in terms of others. Re-exported via `Algebra`.
------------------------------------------------------------------------
{-# OPTIONS --cubical-compatible --safe #-}
open import Algebra.Core
open import Algebra.Consequences.Setoid
open import Data.Product.Base using (_,_; proj₁; proj₂)
open import Level using (_⊔_)
open import Relation.Binary.Core using (Rel)
open import Relation.Binary.Bundles using (Setoid)
open import Relation.Binary.Structures using (IsEquivalence)
module Algebra.Structures.Biased
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality relation
where
open import Algebra.Definitions _≈_
open import Algebra.Structures _≈_
------------------------------------------------------------------------
-- IsCommutativeMonoid
record IsCommutativeMonoidˡ (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identityˡ : LeftIdentity ε ∙
comm : Commutative ∙
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = isSemigroup
; identity = comm∧idˡ⇒id setoid comm identityˡ
}
; comm = comm
} where open IsSemigroup isSemigroup
open IsCommutativeMonoidˡ public
using () renaming (isCommutativeMonoid to isCommutativeMonoidˡ)
record IsCommutativeMonoidʳ (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identityʳ : RightIdentity ε ∙
comm : Commutative ∙
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = isSemigroup
; identity = comm∧idʳ⇒id setoid comm identityʳ
}
; comm = comm
} where open IsSemigroup isSemigroup
open IsCommutativeMonoidʳ public
using () renaming (isCommutativeMonoid to isCommutativeMonoidʳ)
------------------------------------------------------------------------
-- IsSemiringWithoutOne
record IsSemiringWithoutOne* (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isSemigroup : IsSemigroup *
distrib : * DistributesOver +
zero : Zero 0# *
isSemiringWithoutOne : IsSemiringWithoutOne + * 0#
isSemiringWithoutOne = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-cong = ∙-cong
; *-assoc = assoc
; distrib = distrib
; zero = zero
} where open IsSemigroup *-isSemigroup
open IsSemiringWithoutOne* public
using () renaming (isSemiringWithoutOne to isSemiringWithoutOne*)
------------------------------------------------------------------------
-- IsNearSemiring
record IsNearSemiring* (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
+-isMonoid : IsMonoid + 0#
*-isSemigroup : IsSemigroup *
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
isNearSemiring : IsNearSemiring + * 0#
isNearSemiring = record
{ +-isMonoid = +-isMonoid
; *-cong = ∙-cong
; *-assoc = assoc
; distribʳ = distribʳ
; zeroˡ = zeroˡ
} where open IsSemigroup *-isSemigroup
open IsNearSemiring* public
using () renaming (isNearSemiring to isNearSemiring*)
------------------------------------------------------------------------
-- IsSemiringWithoutAnnihilatingZero
record IsSemiringWithoutAnnihilatingZero* (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero + * 0# 1#
isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-cong = ∙-cong
; *-assoc = assoc
; *-identity = identity
; distrib = distrib
} where open IsMonoid *-isMonoid
open IsSemiringWithoutAnnihilatingZero* public
using () renaming (isSemiringWithoutAnnihilatingZero to isSemiringWithoutAnnihilatingZero*)
------------------------------------------------------------------------
-- IsCommutativeSemiring
record IsCommutativeSemiringˡ (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1#
isCommutativeSemiring = record
{ isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-cong = *.∙-cong
; *-assoc = *.assoc
; *-identity = *.identity
; distrib = comm∧distrʳ⇒distr +.setoid +.∙-cong *.comm distribʳ
}
; zero = comm∧zeˡ⇒ze +.setoid *.comm zeroˡ
}
; *-comm = *.comm
}
where
module + = IsCommutativeMonoid +-isCommutativeMonoid
module * = IsCommutativeMonoid *-isCommutativeMonoid
open IsCommutativeSemiringˡ public
using () renaming (isCommutativeSemiring to isCommutativeSemiringˡ)
record IsCommutativeSemiringʳ (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
distribˡ : * DistributesOverˡ +
zeroʳ : RightZero 0# *
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1#
isCommutativeSemiring = record
{ isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-cong = *.∙-cong
; *-assoc = *.assoc
; *-identity = *.identity
; distrib = comm∧distrˡ⇒distr +.setoid +.∙-cong *.comm distribˡ
}
; zero = comm∧zeʳ⇒ze +.setoid *.comm zeroʳ
}
; *-comm = *.comm
}
where
module + = IsCommutativeMonoid +-isCommutativeMonoid
module * = IsCommutativeMonoid *-isCommutativeMonoid
open IsCommutativeSemiringʳ public
using () renaming (isCommutativeSemiring to isCommutativeSemiringʳ)
------------------------------------------------------------------------
-- IsRing
record IsRing* (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isAbelianGroup : IsAbelianGroup + 0# -_
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
zero : Zero 0# *
isRing : IsRing + * -_ 0# 1#
isRing = record
{ +-isAbelianGroup = +-isAbelianGroup
; *-cong = ∙-cong
; *-assoc = assoc
; *-identity = identity
; distrib = distrib
} where open IsMonoid *-isMonoid
open IsRing* public
using () renaming (isRing to isRing*)
------------------------------------------------------------------------
-- Deprecated
------------------------------------------------------------------------
-- Version 2.0
-- We can recover a ring without proving that 0# annihilates *.
record IsRingWithoutAnnihilatingZero (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A)
: Set (a ⊔ ℓ) where
field
+-isAbelianGroup : IsAbelianGroup + 0# -_
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
module + = IsAbelianGroup +-isAbelianGroup
module * = IsMonoid *-isMonoid
open + using (setoid) renaming (∙-cong to +-cong)
open * using () renaming (∙-cong to *-cong)
zeroˡ : LeftZero 0# *
zeroˡ = assoc∧distribʳ∧idʳ∧invʳ⇒zeˡ setoid
+-cong *-cong +.assoc (proj₂ distrib) +.identityʳ +.inverseʳ
zeroʳ : RightZero 0# *
zeroʳ = assoc∧distribˡ∧idʳ∧invʳ⇒zeʳ setoid
+-cong *-cong +.assoc (proj₁ distrib) +.identityʳ +.inverseʳ
zero : Zero 0# *
zero = (zeroˡ , zeroʳ)
isRing : IsRing + * -_ 0# 1#
isRing = record
{ +-isAbelianGroup = +-isAbelianGroup
; *-cong = *.∙-cong
; *-assoc = *.assoc
; *-identity = *.identity
; distrib = distrib
}
open IsRingWithoutAnnihilatingZero public
using () renaming (isRing to isRingWithoutAnnihilatingZero)
{-# WARNING_ON_USAGE IsRingWithoutAnnihilatingZero
"Warning: IsRingWithoutAnnihilatingZero was deprecated in v2.0.
Please use the standard `IsRing` instead."
#-}
{-# WARNING_ON_USAGE isRingWithoutAnnihilatingZero
"Warning: isRingWithoutAnnihilatingZero was deprecated in v2.0.
Please use the standard `IsRing` instead."
#-}