Skip to content

Commit 9beefe0

Browse files
[ refactor ] straightening out the Algebra hierarchy (agda#535)
1 parent 7fe9441 commit 9beefe0

File tree

18 files changed

+816
-336
lines changed

18 files changed

+816
-336
lines changed

CHANGELOG.md

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,29 @@ Splitting up `Data.Maybe` into the standard hierarchy.
4545

4646
#### Changes to the algebra hierarchy
4747

48+
* Over time the algebra inheritance hierarchy has become a little
49+
wonky due to poorly structured additions. This attempts to straighten
50+
the hierarchy out and new policies have been put in place so that
51+
the need for additional such changes will be minimised in the future.
52+
4853
* Added `Magma` and `IsMagma` to the algebra hierarchy.
4954

50-
* The name `RawSemigroup` in `Algebra` has been deprecated in favour of `RawMagma`.
55+
* The name `RawSemigroup` in `Algebra` has been deprecated in favour
56+
of `RawMagma`.
57+
58+
* The fields `isEquivalence` and `∙-cong` in `IsSemigroup` have been
59+
replaced with `isMagma`.
60+
61+
* The fields `isEquivalence`, `∨-cong`, `∨-assoc`, `∨-comm`, `∧-cong`,
62+
`∧-assoc` and `∧-comm` in `IsLattice` have been replaced with
63+
`∨-isSemilattice` and `∧-isSemilattice`.
64+
65+
* The record `Lattice` now exports proofs of `∨-idem` and `∧-idem` directly.
66+
Therefore `∨-idempotence` and `∧-idempotence` in `Algebra.Properties.Lattice`
67+
have been deprecated.
68+
69+
* The record `BooleanAlgebra` now exports `∨-isSemigroup`, `∧-isSemigroup`
70+
directly so `Algebra.Properties.BooleanAlgebra` no longer does so.
5171

5272
#### Relaxation of ring solvers requirements
5373

@@ -143,6 +163,23 @@ Other minor additions
143163
lookup-iterate-identity : lookup n (iterate f a) ≡ fold a f n
144164
```
145165

166+
* Added new proofs to `Data.Bool.Properties`:
167+
```agda
168+
∧-isMagma : IsMagma _∧_
169+
∨-isMagma : IsMagma _∨_
170+
∨-isBand : IsBand _∨_
171+
∨-isSemilattice : IsSemilattice _∨_
172+
∧-isBand : IsBand _∧_
173+
∧-isSemilattice : IsSemilattice _∧_
174+
175+
∧-magma : Magma 0ℓ 0ℓ
176+
∨-magma : Magma 0ℓ 0ℓ
177+
∨-band : Band 0ℓ 0ℓ
178+
∧-band : Band 0ℓ 0ℓ
179+
∨-semilattice : Semilattice 0ℓ 0ℓ
180+
∧-semilattice : Semilattice 0ℓ 0ℓ
181+
```
182+
146183
* Added new function to `Data.Fin.Base`:
147184
```agda
148185
cast : m ≡ n → Fin m → Fin n
@@ -153,6 +190,36 @@ Other minor additions
153190
toℕ-cast : toℕ (cast eq k) ≡ toℕ k
154191
```
155192

193+
* Added new proofs to `Data.Fin.Subset.Properties`:
194+
```agda
195+
∩-isMagma : IsMagma _∩_
196+
∪-isMagma : IsMagma _∪_
197+
∩-isBand : IsBand _∩_
198+
∪-isBand : IsBand _∪_
199+
∩-isSemilattice : IsSemilattice _∩_
200+
∪-isSemilattice : IsSemilattice _∪_
201+
202+
∩-magma : Magma _ _
203+
∪-magma : Magma _ _
204+
∩-band : Band _ _
205+
∪-band : Band _ _
206+
∩-semilattice : Semilattice _ _
207+
∪-semilattice : Semilattice _ _
208+
```
209+
210+
* Added new proofs to `Data.Integer.Properties`:
211+
```agda
212+
+-isMagma : IsMagma _+_
213+
*-isMagma : IsMagma _*_
214+
215+
+-magma : Magma 0ℓ 0ℓ
216+
*-magma : Magma 0ℓ 0ℓ
217+
+-semigroup : Semigroup 0ℓ 0ℓ
218+
*-semigroup : Semigroup 0ℓ 0ℓ
219+
+-0-monoid : Monoid 0ℓ 0ℓ
220+
*-1-monoid : Monoid 0ℓ 0ℓ
221+
```
222+
156223
* Added new operations to `Data.List.All`:
157224
```agda
158225
zipWith : P ∩ Q ⊆ R → All P ∩ All Q ⊆ All R
@@ -203,11 +270,19 @@ Other minor additions
203270

204271
* Added new proofs to `Data.List.Properties`:
205272
```agda
206-
length-%= : length (xs [ k ]%= f) ≡ length xs
207-
length-∷= : length (xs [ k ]∷= v) ≡ length xs
208-
map-∷= : map f (xs [ k ]∷= v) ≡ map f xs [ cast eq k ]∷= f v
209-
length-─ : length (xs ─ k) ≡ pred (length xs)
210-
map-─ : map f (xs ─ k) ≡ map f xs ─ cast eq k
273+
++-isMagma : IsMagma _++_
274+
275+
length-%= : length (xs [ k ]%= f) ≡ length xs
276+
length-∷= : length (xs [ k ]∷= v) ≡ length xs
277+
map-∷= : map f (xs [ k ]∷= v) ≡ map f xs [ cast eq k ]∷= f v
278+
length-─ : length (xs ─ k) ≡ pred (length xs)
279+
map-─ : map f (xs ─ k) ≡ map f xs ─ cast eq k
280+
```
281+
282+
* Added new proofs to `Data.List.Relation.Permutation.Inductive.Properties`:
283+
```agda
284+
++-isMagma : IsMagma _↭_ _++_
285+
++-magma : Magma _ _
211286
```
212287

213288
* Added new proofs to `Data.Maybe.All`:
@@ -259,6 +334,33 @@ Other minor additions
259334
_<∣>_ : Maybe A → Maybe A → Maybe A
260335
```
261336

337+
* Added new proofs to `Data.Nat.Properties`:
338+
```agda
339+
+-isMagma : IsMagma _+_
340+
*-isMagma : IsMagma _*_
341+
⊔-isMagma : IsMagma _⊔_
342+
⊓-isMagma : IsMagma _⊓_
343+
⊔-isBand : IsBand _⊔_
344+
⊓-isBand : IsBand _⊓_
345+
⊔-isSemilattice : IsSemilattice _⊔_
346+
⊓-isSemilattice : IsSemilattice _⊓_
347+
348+
+-magma : Magma 0ℓ 0ℓ
349+
*-magma : Magma 0ℓ 0ℓ
350+
⊔-magma : Magma 0ℓ 0ℓ
351+
⊓-magma : Magma 0ℓ 0ℓ
352+
⊔-band : Band 0ℓ 0ℓ
353+
⊓-band : Band 0ℓ 0ℓ
354+
⊔-semilattice : Semilattice 0ℓ 0ℓ
355+
⊓-semilattice : Semilattice 0ℓ 0ℓ
356+
```
357+
358+
* Added new proofs to `Data.Sign.Properties`:
359+
```agda
360+
*-isMagma : IsMagma _*_
361+
*-magma : Magma 0ℓ 0ℓ
362+
```
363+
262364
* Added new functions to `Data.Sum.Base`:
263365
```agda
264366
fromDec : Dec P → P ⊎ ¬ P
@@ -280,6 +382,15 @@ Other minor additions
280382
toAny : x ∈ xs → P x → Any P xs
281383
```
282384

385+
* Added new proofs to `Function.Related.TypeIsomorphisms`:
386+
```agda
387+
×-isMagma : ∀ k ℓ → IsMagma (Related ⌊ k ⌋) _×_
388+
⊎-isMagma : ∀ k ℓ → IsMagma (Related ⌊ k ⌋) _⊎_
389+
390+
⊎-magma : Symmetric-kind → (ℓ : Level) → Semigroup _ _
391+
×-magma : Symmetric-kind → (ℓ : Level) → Magma _ _
392+
```
393+
283394
* Added new proofs to `Relation.Binary.Consequences`:
284395
```agda
285396
wlog : Total _R_ → Symmetric Q → (∀ a b → a R b → Q a b) → ∀ a b → Q a b

src/Algebra.agda

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ record Band c ℓ : Set (suc (c ⊔ ℓ)) where
7373

7474
open Semigroup semigroup public using (magma; rawMagma)
7575

76+
77+
record Semilattice c ℓ : Set (suc (c ⊔ ℓ)) where
78+
infixr 7 _∧_
79+
infix 4 _≈_
80+
field
81+
Carrier : Set c
82+
_≈_ : Rel Carrier ℓ
83+
_∧_ : Op₂ Carrier
84+
isSemilattice : IsSemilattice _≈_ _∧_
85+
86+
open IsSemilattice isSemilattice public
87+
88+
band : Band c ℓ
89+
band = record { isBand = isBand }
90+
91+
open Band band public using (rawMagma; magma; semigroup)
92+
7693
------------------------------------------------------------------------
7794
-- Monoids
7895

@@ -536,22 +553,6 @@ record CommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
536553
------------------------------------------------------------------------
537554
-- Lattices and boolean algebras
538555

539-
record Semilattice c ℓ : Set (suc (c ⊔ ℓ)) where
540-
infixr 7 _∧_
541-
infix 4 _≈_
542-
field
543-
Carrier : Set c
544-
_≈_ : Rel Carrier ℓ
545-
_∧_ : Op₂ Carrier
546-
isSemilattice : IsSemilattice _≈_ _∧_
547-
548-
open IsSemilattice isSemilattice public
549-
550-
band : Band c ℓ
551-
band = record { isBand = isBand }
552-
553-
open Band band public using (rawMagma; magma; semigroup)
554-
555556
record Lattice c ℓ : Set (suc (c ⊔ ℓ)) where
556557
infixr 7 _∧_
557558
infixr 6 _∨_
@@ -565,8 +566,27 @@ record Lattice c ℓ : Set (suc (c ⊔ ℓ)) where
565566

566567
open IsLattice isLattice public
567568

568-
setoid : Setoid _ _
569-
setoid = record { isEquivalence = isEquivalence }
569+
∨-semilattice : Semilattice c ℓ
570+
∨-semilattice = record { isSemilattice = ∨-isSemilattice }
571+
572+
open Semilattice ∨-semilattice public
573+
using () renaming
574+
( rawMagma to ∨-rawMagma
575+
; magma to ∨-magma
576+
; semigroup to ∨-semigroup
577+
; band to ∨-band
578+
)
579+
580+
∧-semilattice : Semilattice c ℓ
581+
∧-semilattice = record { isSemilattice = ∧-isSemilattice }
582+
583+
open Semilattice ∧-semilattice public
584+
using () renaming
585+
( rawMagma to ∧-rawMagma
586+
; magma to ∧-magma
587+
; semigroup to ∧-semigroup
588+
; band to ∧-band
589+
)
570590

571591
record DistributiveLattice c ℓ : Set (suc (c ⊔ ℓ)) where
572592
infixr 7 _∧_
@@ -584,7 +604,11 @@ record DistributiveLattice c ℓ : Set (suc (c ⊔ ℓ)) where
584604
lattice : Lattice _ _
585605
lattice = record { isLattice = isLattice }
586606

587-
open Lattice lattice public using (setoid)
607+
open Lattice lattice public
608+
using
609+
( ∧-rawMagma; ∧-magma; ∧-semigroup; ∧-band; ∧-semilattice
610+
; ∨-rawMagma; ∨-magma; ∨-semigroup; ∨-band; ∨-semilattice
611+
)
588612

589613
record BooleanAlgebra c ℓ : Set (suc (c ⊔ ℓ)) where
590614
infix 8 ¬_
@@ -604,12 +628,14 @@ record BooleanAlgebra c ℓ : Set (suc (c ⊔ ℓ)) where
604628
open IsBooleanAlgebra isBooleanAlgebra public
605629

606630
distributiveLattice : DistributiveLattice _ _
607-
distributiveLattice =
608-
record { isDistributiveLattice = isDistributiveLattice }
631+
distributiveLattice = record { isDistributiveLattice = isDistributiveLattice }
609632

610633
open DistributiveLattice distributiveLattice public
611-
using (setoid; lattice)
612-
634+
using
635+
( ∧-rawMagma; ∧-magma; ∧-semigroup; ∧-band; ∧-semilattice
636+
; ∨-rawMagma; ∨-magma; ∨-semigroup; ∨-band; ∨-semilattice
637+
; lattice
638+
)
613639

614640
------------------------------------------------------------------------
615641
-- DEPRECATED NAMES

src/Algebra/Properties/BooleanAlgebra.agda

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
open import Algebra
88

99
module Algebra.Properties.BooleanAlgebra
10-
{b₁ b₂} (B : BooleanAlgebra b₁ b₂)
11-
where
10+
{b₁ b₂} (B : BooleanAlgebra b₁ b₂)
11+
where
1212

1313
open BooleanAlgebra B
1414
import Algebra.Properties.DistributiveLattice
@@ -18,8 +18,7 @@ private
1818
hiding (replace-equality)
1919
open import Algebra.Structures _≈_
2020
open import Algebra.FunctionProperties _≈_
21-
open import Algebra.FunctionProperties.Consequences
22-
record {isEquivalence = isEquivalence}
21+
open import Algebra.FunctionProperties.Consequences setoid
2322
open import Relation.Binary.EqReasoning setoid
2423
open import Relation.Binary
2524
open import Function
@@ -68,7 +67,7 @@ open import Data.Product
6867
∧-identityʳ : RightIdentity ⊤ _∧_
6968
∧-identityʳ x = begin
7069
x ∧ ⊤ ≈⟨ refl ⟨ ∧-cong ⟩ sym (∨-complementʳ _) ⟩
71-
x ∧ (x ∨ ¬ x) ≈⟨ proj₂ absorptive _ _ ⟩
70+
x ∧ (x ∨ ¬ x) ≈⟨ ∧-absorbs-∨ _ _ ⟩
7271
x ∎
7372

7473
∧-identityˡ : LeftIdentity ⊤ _∧_
@@ -80,7 +79,7 @@ open import Data.Product
8079
∨-identityʳ : RightIdentity ⊥ _∨_
8180
∨-identityʳ x = begin
8281
x ∨ ⊥ ≈⟨ refl ⟨ ∨-cong ⟩ sym (∧-complementʳ _) ⟩
83-
x ∨ x ∧ ¬ x ≈⟨ proj₁ absorptive _ _ ⟩
82+
x ∨ x ∧ ¬ x ≈⟨ ∨-absorbs-∧ _ _ ⟩
8483
x ∎
8584

8685
∨-identityˡ : LeftIdentity ⊥ _∨_
@@ -117,20 +116,6 @@ open import Data.Product
117116
∨-zero : Zero ⊤ _∨_
118117
∨-zero = ∨-zeroˡ , ∨-zeroʳ
119118

120-
∨-isSemigroup : IsSemigroup _∨_
121-
∨-isSemigroup = record
122-
{ isEquivalence = isEquivalence
123-
; assoc = ∨-assoc
124-
; ∙-cong = ∨-cong
125-
}
126-
127-
∧-isSemigroup : IsSemigroup _∧_
128-
∧-isSemigroup = record
129-
{ isEquivalence = isEquivalence
130-
; assoc = ∧-assoc
131-
; ∙-cong = ∧-cong
132-
}
133-
134119
∨-⊥-isMonoid : IsMonoid _∨_ ⊥
135120
∨-⊥-isMonoid = record
136121
{ isSemigroup = ∨-isSemigroup
@@ -146,23 +131,23 @@ open import Data.Product
146131
∨-⊥-isCommutativeMonoid : IsCommutativeMonoid _∨_ ⊥
147132
∨-⊥-isCommutativeMonoid = record
148133
{ isSemigroup = ∨-isSemigroup
149-
; identityˡ = ∨-identityˡ
150-
; comm = ∨-comm
134+
; identityˡ = ∨-identityˡ
135+
; comm = ∨-comm
151136
}
152137

153138
∧-⊤-isCommutativeMonoid : IsCommutativeMonoid _∧_ ⊤
154139
∧-⊤-isCommutativeMonoid = record
155140
{ isSemigroup = ∧-isSemigroup
156-
; identityˡ = ∧-identityˡ
157-
; comm = ∧-comm
141+
; identityˡ = ∧-identityˡ
142+
; comm = ∧-comm
158143
}
159144

160145
∨-∧-isCommutativeSemiring : IsCommutativeSemiring _∨_ _∧_ ⊥ ⊤
161146
∨-∧-isCommutativeSemiring = record
162147
{ +-isCommutativeMonoid = ∨-⊥-isCommutativeMonoid
163148
; *-isCommutativeMonoid = ∧-⊤-isCommutativeMonoid
164-
; distribʳ = proj₂ ∧-∨-distrib
165-
; zeroˡ = ∧-zeroˡ
149+
; distribʳ = proj₂ ∧-∨-distrib
150+
; zeroˡ = ∧-zeroˡ
166151
}
167152

168153
∨-∧-commutativeSemiring : CommutativeSemiring _ _
@@ -530,13 +515,18 @@ module XorRing
530515
((¬ x ∨ ¬ y) ∨ z) ∧
531516
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ∎
532517

533-
⊕-isSemigroup : IsSemigroup _⊕_
534-
⊕-isSemigroup = record
518+
⊕-isMagma : IsMagma _⊕_
519+
⊕-isMagma = record
535520
{ isEquivalence = isEquivalence
536-
; assoc = ⊕-assoc
537521
; ∙-cong = ⊕-cong
538522
}
539523

524+
⊕-isSemigroup : IsSemigroup _⊕_
525+
⊕-isSemigroup = record
526+
{ isMagma = ⊕-isMagma
527+
; assoc = ⊕-assoc
528+
}
529+
540530
⊕-⊥-isMonoid : IsMonoid _⊕_ ⊥
541531
⊕-⊥-isMonoid = record
542532
{ isSemigroup = ⊕-isSemigroup

0 commit comments

Comments
 (0)