1
------------------------------------------------------------------------
2
-- Some algebraic structures (not packed up with sets, operations,
4
------------------------------------------------------------------------
6
open import Relation.Binary
8
module Algebra.Structures where
10
import Algebra.FunctionProperties as FunctionProperties
11
open FunctionProperties using (Op₁; Op₂)
12
import Relation.Binary.EqReasoning as EqR
13
open import Data.Function
14
open import Data.Product
17
------------------------------------------------------------------------
18
-- One binary operation
20
record IsSemigroup {A} (≈ : Rel A L.zero) (∙ : Op₂ A) : Set where
21
open FunctionProperties ≈
23
isEquivalence : IsEquivalence ≈
25
∙-cong : ∙ Preserves₂ ≈ ⟶ ≈ ⟶ ≈
27
open IsEquivalence isEquivalence public
29
record IsMonoid {A} (≈ : Rel A L.zero) (∙ : Op₂ A) (ε : A) : Set where
30
open FunctionProperties ≈
32
isSemigroup : IsSemigroup ≈ ∙
33
identity : Identity ε ∙
35
open IsSemigroup isSemigroup public
37
record IsCommutativeMonoid {A} (≈ : Rel A L.zero)
38
(∙ : Op₂ A) (ε : A) : Set where
39
open FunctionProperties ≈
41
isMonoid : IsMonoid ≈ ∙ ε
44
open IsMonoid isMonoid public
46
record IsGroup {A} (≈ : Rel A L.zero)
47
(_∙_ : Op₂ A) (ε : A) (_⁻¹ : Op₁ A) : Set where
48
open FunctionProperties ≈
51
isMonoid : IsMonoid ≈ _∙_ ε
52
inverse : Inverse ε _⁻¹ _∙_
53
⁻¹-cong : _⁻¹ Preserves ≈ ⟶ ≈
55
open IsMonoid isMonoid public
60
record IsAbelianGroup {A} (≈ : Rel A L.zero)
61
(∙ : Op₂ A) (ε : A) (⁻¹ : Op₁ A) : Set where
62
open FunctionProperties ≈
64
isGroup : IsGroup ≈ ∙ ε ⁻¹
67
open IsGroup isGroup public
69
isCommutativeMonoid : IsCommutativeMonoid ≈ ∙ ε
70
isCommutativeMonoid = record
75
------------------------------------------------------------------------
76
-- Two binary operations
78
record IsNearSemiring {A} (≈ : Rel A L.zero)
79
(+ * : Op₂ A) (0# : A) : Set where
80
open FunctionProperties ≈
82
+-isMonoid : IsMonoid ≈ + 0#
83
*-isSemigroup : IsSemigroup ≈ *
84
distribʳ : * DistributesOverʳ +
87
open IsMonoid +-isMonoid public
88
renaming ( assoc to +-assoc
90
; isSemigroup to +-isSemigroup
91
; identity to +-identity
94
open IsSemigroup *-isSemigroup public
96
renaming ( assoc to *-assoc
100
record IsSemiringWithoutOne {A} (≈ : Rel A L.zero)
101
(+ * : Op₂ A) (0# : A) : Set where
102
open FunctionProperties ≈
104
+-isCommutativeMonoid : IsCommutativeMonoid ≈ + 0#
105
*-isSemigroup : IsSemigroup ≈ *
106
distrib : * DistributesOver +
109
open IsCommutativeMonoid +-isCommutativeMonoid public
110
renaming ( assoc to +-assoc
112
; isSemigroup to +-isSemigroup
113
; identity to +-identity
114
; isMonoid to +-isMonoid
118
open IsSemigroup *-isSemigroup public
120
renaming ( assoc to *-assoc
124
isNearSemiring : IsNearSemiring ≈ + * 0#
125
isNearSemiring = record
126
{ +-isMonoid = +-isMonoid
127
; *-isSemigroup = *-isSemigroup
128
; distribʳ = proj₂ distrib
132
record IsSemiringWithoutAnnihilatingZero
133
{A} (≈ : Rel A L.zero) (+ * : Op₂ A) (0# 1# : A) : Set where
134
open FunctionProperties ≈
136
-- Note that these structures do have an additive unit, but this
137
-- unit does not necessarily annihilate multiplication.
138
+-isCommutativeMonoid : IsCommutativeMonoid ≈ + 0#
139
*-isMonoid : IsMonoid ≈ * 1#
140
distrib : * DistributesOver +
142
open IsCommutativeMonoid +-isCommutativeMonoid public
143
renaming ( assoc to +-assoc
145
; isSemigroup to +-isSemigroup
146
; identity to +-identity
147
; isMonoid to +-isMonoid
151
open IsMonoid *-isMonoid public
153
renaming ( assoc to *-assoc
155
; isSemigroup to *-isSemigroup
156
; identity to *-identity
159
record IsSemiring {A} (≈ : Rel A L.zero)
160
(+ * : Op₂ A) (0# 1# : A) : Set where
161
open FunctionProperties ≈
163
isSemiringWithoutAnnihilatingZero :
164
IsSemiringWithoutAnnihilatingZero ≈ + * 0# 1#
167
open IsSemiringWithoutAnnihilatingZero
168
isSemiringWithoutAnnihilatingZero public
170
isSemiringWithoutOne : IsSemiringWithoutOne ≈ + * 0#
171
isSemiringWithoutOne = record
172
{ +-isCommutativeMonoid = +-isCommutativeMonoid
173
; *-isSemigroup = *-isSemigroup
178
open IsSemiringWithoutOne isSemiringWithoutOne public
179
using (isNearSemiring)
181
record IsCommutativeSemiringWithoutOne
182
{A} (≈ : Rel A L.zero) (+ * : Op₂ A) (0# : A) : Set where
183
open FunctionProperties ≈
185
isSemiringWithoutOne : IsSemiringWithoutOne ≈ + * 0#
186
*-comm : Commutative *
188
open IsSemiringWithoutOne isSemiringWithoutOne public
190
record IsCommutativeSemiring
191
{A} (≈ : Rel A L.zero) (+ * : Op₂ A) (0# 1# : A) : Set where
192
open FunctionProperties ≈
194
isSemiring : IsSemiring ≈ + * 0# 1#
195
*-comm : Commutative *
197
open IsSemiring isSemiring public
199
*-isCommutativeMonoid : IsCommutativeMonoid ≈ * 1#
200
*-isCommutativeMonoid = record
201
{ isMonoid = *-isMonoid
205
isCommutativeSemiringWithoutOne :
206
IsCommutativeSemiringWithoutOne ≈ + * 0#
207
isCommutativeSemiringWithoutOne = record
208
{ isSemiringWithoutOne = isSemiringWithoutOne
212
record IsRing {A} (≈ : Rel A L.zero)
213
(_+_ _*_ : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set where
214
open FunctionProperties ≈
216
+-isAbelianGroup : IsAbelianGroup ≈ _+_ 0# -_
217
*-isMonoid : IsMonoid ≈ _*_ 1#
218
distrib : _*_ DistributesOver _+_
220
open IsAbelianGroup +-isAbelianGroup public
221
renaming ( assoc to +-assoc
223
; isSemigroup to +-isSemigroup
224
; identity to +-identity
225
; isMonoid to +-isMonoid
226
; inverse to -‿inverse
228
; isGroup to +-isGroup
230
; isCommutativeMonoid to +-isCommutativeMonoid
233
open IsMonoid *-isMonoid public
235
renaming ( assoc to *-assoc
237
; isSemigroup to *-isSemigroup
238
; identity to *-identity
242
zero = (zeroˡ , zeroʳ)
244
open EqR (record { isEquivalence = isEquivalence })
246
zeroˡ : LeftZero 0# _*_
248
0# * x ≈⟨ sym $ proj₂ +-identity _ ⟩
249
(0# * x) + 0# ≈⟨ refl ⟨ +-cong ⟩ sym (proj₂ -‿inverse _) ⟩
250
(0# * x) + ((0# * x) + - (0# * x)) ≈⟨ sym $ +-assoc _ _ _ ⟩
251
((0# * x) + (0# * x)) + - (0# * x) ≈⟨ sym (proj₂ distrib _ _ _) ⟨ +-cong ⟩ refl ⟩
252
((0# + 0#) * x) + - (0# * x) ≈⟨ (proj₂ +-identity _ ⟨ *-cong ⟩ refl)
255
(0# * x) + - (0# * x) ≈⟨ proj₂ -‿inverse _ ⟩
258
zeroʳ : RightZero 0# _*_
260
x * 0# ≈⟨ sym $ proj₂ +-identity _ ⟩
261
(x * 0#) + 0# ≈⟨ refl ⟨ +-cong ⟩ sym (proj₂ -‿inverse _) ⟩
262
(x * 0#) + ((x * 0#) + - (x * 0#)) ≈⟨ sym $ +-assoc _ _ _ ⟩
263
((x * 0#) + (x * 0#)) + - (x * 0#) ≈⟨ sym (proj₁ distrib _ _ _) ⟨ +-cong ⟩ refl ⟩
264
(x * (0# + 0#)) + - (x * 0#) ≈⟨ (refl ⟨ *-cong ⟩ proj₂ +-identity _)
267
(x * 0#) + - (x * 0#) ≈⟨ proj₂ -‿inverse _ ⟩
270
isSemiringWithoutAnnihilatingZero
271
: IsSemiringWithoutAnnihilatingZero ≈ _+_ _*_ 0# 1#
272
isSemiringWithoutAnnihilatingZero = record
273
{ +-isCommutativeMonoid = +-isCommutativeMonoid
274
; *-isMonoid = *-isMonoid
278
isSemiring : IsSemiring ≈ _+_ _*_ 0# 1#
280
{ isSemiringWithoutAnnihilatingZero =
281
isSemiringWithoutAnnihilatingZero
285
open IsSemiring isSemiring public
286
using (isNearSemiring; isSemiringWithoutOne)
288
record IsCommutativeRing {A}
290
(+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set where
291
open FunctionProperties ≈
293
isRing : IsRing ≈ + * - 0# 1#
294
*-comm : Commutative *
296
open IsRing isRing public
298
isCommutativeSemiring : IsCommutativeSemiring ≈ + * 0# 1#
299
isCommutativeSemiring = record
300
{ isSemiring = isSemiring
304
open IsCommutativeSemiring isCommutativeSemiring public
305
using (isCommutativeSemiringWithoutOne)
307
record IsLattice {A} (≈ : Rel A L.zero) (∨ ∧ : Op₂ A) : Set where
308
open FunctionProperties ≈
310
isEquivalence : IsEquivalence ≈
311
∨-comm : Commutative ∨
312
∨-assoc : Associative ∨
313
∨-cong : ∨ Preserves₂ ≈ ⟶ ≈ ⟶ ≈
314
∧-comm : Commutative ∧
315
∧-assoc : Associative ∧
316
∧-cong : ∧ Preserves₂ ≈ ⟶ ≈ ⟶ ≈
317
absorptive : Absorptive ∨ ∧
319
open IsEquivalence isEquivalence public
321
record IsDistributiveLattice {A} (≈ : Rel A L.zero)
322
(∨ ∧ : Op₂ A) : Set where
323
open FunctionProperties ≈
325
isLattice : IsLattice ≈ ∨ ∧
326
∨-∧-distribʳ : ∨ DistributesOverʳ ∧
328
open IsLattice isLattice public
330
record IsBooleanAlgebra {A}
332
(∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set where
333
open FunctionProperties ≈
335
isDistributiveLattice : IsDistributiveLattice ≈ ∨ ∧
336
∨-complementʳ : RightInverse ⊤ ¬ ∨
337
∧-complementʳ : RightInverse ⊥ ¬ ∧
338
¬-cong : ¬ Preserves ≈ ⟶ ≈
340
open IsDistributiveLattice isDistributiveLattice public