Skip to content

Commit 4099f61

Browse files
authored
Add generic divisibility for magma and monoid-like structures
1 parent cdffecb commit 4099f61

File tree

10 files changed

+389
-51
lines changed

10 files changed

+389
-51
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ New modules
8181
* Added `Reflection.DeBruijn` with weakening, strengthening and free variable operations
8282
on reflected terms.
8383

84+
* Generic divisibility over algebraic structures
85+
```
86+
Algebra.Divisibility
87+
Algebra.Properties.Magma.Divisibility
88+
Algebra.Properties.Semigroup.Divisibility
89+
Algebra.Properties.Monoid.Divisibility
90+
Algebra.Properties.CommutativeSemigroup.Divisibility
91+
```
92+
8493
Other major changes
8594
-------------------
8695

@@ -100,6 +109,7 @@ Other minor additions
100109

101110
* Added new records to `Algebra.Bundles`:
102111
```agda
112+
CommutativeMagma c ℓ : Set (suc (c ⊔ ℓ))
103113
RawNearSemiring c ℓ : Set (suc (c ⊔ ℓ))
104114
RawLattice c ℓ : Set (suc (c ⊔ ℓ))
105115
CancellativeCommutativeSemiring c ℓ : Set (suc (c ⊔ ℓ))
@@ -134,6 +144,7 @@ Other minor additions
134144

135145
* Added new record to `Algebra.Structures`:
136146
```agda
147+
IsCommutativeMagma (• : Op₂ A) : Set (a ⊔ ℓ)
137148
IsCancellativeCommutativeSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ)
138149
```
139150

src/Algebra/Bundles.agda

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,40 @@ record Magma c ℓ : Set (suc (c ⊔ ℓ)) where
4848
using (_≉_)
4949

5050

51+
record SelectiveMagma c ℓ : Set (suc (c ⊔ ℓ)) where
52+
infixl 7 _∙_
53+
infix 4 _≈_
54+
field
55+
Carrier : Set c
56+
_≈_ : Rel Carrier ℓ
57+
_∙_ : Op₂ Carrier
58+
isSelectiveMagma : IsSelectiveMagma _≈_ _∙_
59+
60+
open IsSelectiveMagma isSelectiveMagma public
61+
62+
magma : Magma c ℓ
63+
magma = record { isMagma = isMagma }
64+
65+
open Magma magma public using (rawMagma)
66+
67+
68+
record CommutativeMagma c ℓ : Set (suc (c ⊔ ℓ)) where
69+
infixl 7 _∙_
70+
infix 4 _≈_
71+
field
72+
Carrier : Set c
73+
_≈_ : Rel Carrier ℓ
74+
_∙_ : Op₂ Carrier
75+
isCommutativeMagma : IsCommutativeMagma _≈_ _∙_
76+
77+
open IsCommutativeMagma isCommutativeMagma public
78+
79+
magma : Magma c ℓ
80+
magma = record { isMagma = isMagma }
81+
82+
open Magma magma public using (rawMagma)
83+
84+
5185
record Semigroup c ℓ : Set (suc (c ⊔ ℓ)) where
5286
infixl 7 _∙_
5387
infix 4 _≈_
@@ -101,6 +135,9 @@ record CommutativeSemigroup c ℓ : Set (suc (c ⊔ ℓ)) where
101135
open Semigroup semigroup public
102136
using (_≉_; magma; rawMagma)
103137

138+
commutativeMagma : CommutativeMagma c ℓ
139+
commutativeMagma = record { isCommutativeMagma = isCommutativeMagma }
140+
104141

105142
record Semilattice c ℓ : Set (suc (c ⊔ ℓ)) where
106143
infixr 7 _∧_
@@ -120,23 +157,6 @@ record Semilattice c ℓ : Set (suc (c ⊔ ℓ)) where
120157
using (_≉_; rawMagma; magma; semigroup)
121158

122159

123-
record SelectiveMagma c ℓ : Set (suc (c ⊔ ℓ)) where
124-
infixl 7 _∙_
125-
infix 4 _≈_
126-
field
127-
Carrier : Set c
128-
_≈_ : Rel Carrier ℓ
129-
_∙_ : Op₂ Carrier
130-
isSelectiveMagma : IsSelectiveMagma _≈_ _∙_
131-
132-
open IsSelectiveMagma isSelectiveMagma public
133-
134-
magma : Magma c ℓ
135-
magma = record { isMagma = isMagma }
136-
137-
open Magma magma public
138-
using (_≉_; rawMagma)
139-
140160
------------------------------------------------------------------------
141161
-- Bundles with 1 binary operation & 1 element
142162
------------------------------------------------------------------------
@@ -202,6 +222,9 @@ record CommutativeMonoid c ℓ : Set (suc (c ⊔ ℓ)) where
202222
commutativeSemigroup : CommutativeSemigroup _ _
203223
commutativeSemigroup = record { isCommutativeSemigroup = isCommutativeSemigroup }
204224

225+
open CommutativeSemigroup commutativeSemigroup public
226+
using (commutativeMagma)
227+
205228

206229
record IdempotentCommutativeMonoid c ℓ : Set (suc (c ⊔ ℓ)) where
207230
infixl 7 _∙_
@@ -219,7 +242,10 @@ record IdempotentCommutativeMonoid c ℓ : Set (suc (c ⊔ ℓ)) where
219242
commutativeMonoid = record { isCommutativeMonoid = isCommutativeMonoid }
220243

221244
open CommutativeMonoid commutativeMonoid public
222-
using (_≉_; rawMagma; magma; semigroup; rawMonoid; monoid)
245+
using
246+
( _≉_; rawMagma; magma; commutativeMagma; semigroup; commutativeSemigroup
247+
; rawMonoid; monoid
248+
)
223249

224250

225251
-- Idempotent commutative monoids are also known as bounded lattices.
@@ -305,7 +331,7 @@ record AbelianGroup c ℓ : Set (suc (c ⊔ ℓ)) where
305331
commutativeMonoid = record { isCommutativeMonoid = isCommutativeMonoid }
306332

307333
open CommutativeMonoid commutativeMonoid public
308-
using (commutativeSemigroup)
334+
using (commutativeMagma; commutativeSemigroup)
309335

310336

311337
------------------------------------------------------------------------
@@ -328,6 +354,7 @@ record RawLattice c ℓ : Set (suc (c ⊔ ℓ)) where
328354
∧-rawMagma : RawMagma c ℓ
329355
∧-rawMagma = record { _≈_ = _≈_; _∙_ = _∧_ }
330356

357+
331358
record Lattice c ℓ : Set (suc (c ⊔ ℓ)) where
332359
infixr 7 _∧_
333360
infixr 6 _∨_
@@ -409,6 +436,7 @@ record RawNearSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
409436
; _∙_ = _*_
410437
}
411438

439+
412440
record NearSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
413441
infixl 7 _*_
414442
infixl 6 _+_
@@ -481,7 +509,10 @@ record SemiringWithoutOne c ℓ : Set (suc (c ⊔ ℓ)) where
481509
+-commutativeMonoid = record { isCommutativeMonoid = +-isCommutativeMonoid }
482510

483511
open CommutativeMonoid +-commutativeMonoid public
484-
using () renaming (commutativeSemigroup to +-commutativeSemigroup)
512+
using () renaming
513+
( commutativeMagma to +-commutativeMagma
514+
; commutativeSemigroup to +-commutativeSemigroup
515+
)
485516

486517

487518
record CommutativeSemiringWithoutOne c ℓ : Set (suc (c ⊔ ℓ)) where
@@ -584,6 +615,7 @@ record SemiringWithoutAnnihilatingZero c ℓ : Set (suc (c ⊔ ℓ)) where
584615
using (_≉_) renaming
585616
( rawMagma to +-rawMagma
586617
; magma to +-magma
618+
; commutativeMagma to +-commutativeMagma
587619
; semigroup to +-semigroup
588620
; commutativeSemigroup to +-commutativeSemigroup
589621
; rawMonoid to +-rawMonoid
@@ -626,7 +658,7 @@ record Semiring c ℓ : Set (suc (c ⊔ ℓ)) where
626658
open SemiringWithoutAnnihilatingZero
627659
semiringWithoutAnnihilatingZero public
628660
using
629-
( _≉_; +-rawMagma; +-magma; +-semigroup; +-commutativeSemigroup
661+
( _≉_; +-rawMagma; +-magma; +-commutativeMagma; +-semigroup; +-commutativeSemigroup
630662
; *-rawMagma; *-magma; *-semigroup
631663
; +-rawMonoid; +-monoid; +-commutativeMonoid
632664
; *-rawMonoid; *-monoid
@@ -661,7 +693,7 @@ record CommutativeSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
661693

662694
open Semiring semiring public
663695
using
664-
( _≉_; +-rawMagma; +-magma; +-semigroup; +-commutativeSemigroup
696+
( _≉_; +-rawMagma; +-magma; +-commutativeMagma; +-semigroup; +-commutativeSemigroup
665697
; *-rawMagma; *-magma; *-semigroup
666698
; +-rawMonoid; +-monoid; +-commutativeMonoid
667699
; *-rawMonoid; *-monoid
@@ -670,16 +702,17 @@ record CommutativeSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
670702
; rawSemiring
671703
)
672704

673-
*-commutativeSemigroup : CommutativeSemigroup _ _
674-
*-commutativeSemigroup = record
675-
{ isCommutativeSemigroup = *-isCommutativeSemigroup
676-
}
677-
678705
*-commutativeMonoid : CommutativeMonoid _ _
679706
*-commutativeMonoid = record
680707
{ isCommutativeMonoid = *-isCommutativeMonoid
681708
}
682709

710+
open CommutativeMonoid *-commutativeMonoid public
711+
using () renaming
712+
( commutativeMagma to *-commutativeMagma
713+
; commutativeSemigroup to *-commutativeSemigroup
714+
)
715+
683716
commutativeSemiringWithoutOne : CommutativeSemiringWithoutOne _ _
684717
commutativeSemiringWithoutOne = record
685718
{ isCommutativeSemiringWithoutOne = isCommutativeSemiringWithoutOne
@@ -701,6 +734,21 @@ record CancellativeCommutativeSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
701734

702735
open IsCancellativeCommutativeSemiring isCancellativeCommutativeSemiring public
703736

737+
commutativeSemiring : CommutativeSemiring c ℓ
738+
commutativeSemiring = record
739+
{ isCommutativeSemiring = isCommutativeSemiring
740+
}
741+
742+
open CommutativeSemiring commutativeSemiring public
743+
using
744+
( +-rawMagma; +-magma; +-commutativeMagma; +-semigroup; +-commutativeSemigroup
745+
; *-rawMagma; *-magma; *-commutativeMagma; *-semigroup; *-commutativeSemigroup
746+
; +-rawMonoid; +-monoid; +-commutativeMonoid
747+
; *-rawMonoid; *-monoid; *-commutativeMonoid
748+
; nearSemiring; semiringWithoutOne
749+
; semiringWithoutAnnihilatingZero
750+
; rawSemiring
751+
)
704752

705753
------------------------------------------------------------------------
706754
-- Bundles with 2 binary operations, 1 unary operation & 2 elements
@@ -762,7 +810,7 @@ record Ring c ℓ : Set (suc (c ⊔ ℓ)) where
762810

763811
open Semiring semiring public
764812
using
765-
( _≉_; +-rawMagma; +-magma; +-semigroup; +-commutativeSemigroup
813+
( _≉_; +-rawMagma; +-magma; +-commutativeMagma; +-semigroup; +-commutativeSemigroup
766814
; *-rawMagma; *-magma; *-semigroup
767815
; +-rawMonoid; +-monoid ; +-commutativeMonoid
768816
; *-rawMonoid; *-monoid
@@ -812,8 +860,8 @@ record CommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
812860

813861
open CommutativeSemiring commutativeSemiring public
814862
using
815-
( +-rawMagma; +-magma; +-semigroup; +-commutativeSemigroup
816-
; *-rawMagma; *-magma; *-semigroup; *-commutativeSemigroup
863+
( +-rawMagma; +-magma; +-commutativeMagma; +-semigroup; +-commutativeSemigroup
864+
; *-rawMagma; *-magma; *-commutativeMagma; *-semigroup; *-commutativeSemigroup
817865
; +-rawMonoid; +-monoid; +-commutativeMonoid
818866
; *-rawMonoid; *-monoid; *-commutativeMonoid
819867
; nearSemiring; semiringWithoutOne

src/Algebra/Divisibility.agda

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Definition of divisibility
5+
------------------------------------------------------------------------
6+
7+
-- You're unlikely to want to use this module directly. Instead you
8+
-- probably want to be importing the appropriate module from
9+
-- `Algebra.Properties.(Magma/Semigroup/...).Divisibility`
10+
11+
{-# OPTIONS --without-K --safe #-}
12+
13+
open import Algebra.Core
14+
open import Data.Product using (∃; _×_; _,_)
15+
open import Level using (_⊔_)
16+
open import Relation.Binary
17+
open import Relation.Nullary using (¬_)
18+
19+
module Algebra.Divisibility
20+
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ) (_∙_ : Op₂ A)
21+
where
22+
23+
open import Algebra.Definitions _≈_
24+
25+
------------------------------------------------------------------------
26+
-- Definitions
27+
28+
-- Divisibility
29+
30+
infix 5 _∣_ _∤_ _∣∣_ _¬∣∣_
31+
32+
_∣_ : Rel A (a ⊔ ℓ)
33+
x ∣ y =λ q (q ∙ x) ≈ y
34+
35+
_∤_ : Rel A (a ⊔ ℓ)
36+
x ∤ y = ¬ x ∣ y
37+
38+
-- Mutual divisibility.
39+
40+
-- When in a cancellative monoid, elements related by _∣∣_ are called
41+
-- associated and if x ∣∣ y then x and y differ by an invertible factor.
42+
43+
_∣∣_ : Rel A (a ⊔ ℓ)
44+
x ∣∣ y = x ∣ y × y ∣ x
45+
46+
_¬∣∣_ : Rel A (a ⊔ ℓ)
47+
x ¬∣∣ y = ¬ x ∣∣ y
48+
49+
------------------------------------------------------------------------
50+
-- Properties
51+
52+
∣-refl : {ε} LeftIdentity ε _∙_ Reflexive _∣_
53+
∣-refl {ε} idˡ {x} = ε , idˡ x
54+
55+
∣-reflexive : Transitive _≈_ {ε} LeftIdentity ε _∙_ _≈_ ⇒ _∣_
56+
∣-reflexive trans {ε} idˡ x≈y = ε , trans (idˡ _) x≈y
57+
58+
∣-trans : Transitive _≈_ LeftCongruent _∙_ Associative _∙_ Transitive _∣_
59+
∣-trans trans congˡ assoc {x} {y} {z} (p , px≈y) (q , qy≈z) =
60+
q ∙ p , trans (assoc q p x) (trans (congˡ px≈y) qy≈z)
61+
62+
∣-respʳ : Transitive _≈_ _∣_ Respectsʳ _≈_
63+
∣-respʳ trans y≈z (q , qx≈y) = q , trans qx≈y y≈z
64+
65+
∣-respˡ : Symmetric _≈_ Transitive _≈_ LeftCongruent _∙_ _∣_ Respectsˡ _≈_
66+
∣-respˡ sym trans congˡ x≈z (q , qx≈y) = q , trans (congˡ (sym x≈z)) qx≈y
67+
68+
∣-resp : Symmetric _≈_ Transitive _≈_ LeftCongruent _∙_ _∣_ Respects₂ _≈_
69+
∣-resp sym trans cong = ∣-respʳ trans , ∣-respˡ sym trans cong
70+
71+
∣-min : {ε} RightIdentity ε _∙_ Minimum _∣_ ε
72+
∣-min {ε} idʳ x = x , idʳ x
73+
74+
∣-max : {ε} LeftZero ε _∙_ Maximum _∣_ ε
75+
∣-max {ε} zeˡ x = ε , zeˡ x
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Properties of divisibility over commutative magmas
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
open import Algebra using (CommutativeMagma)
10+
open import Data.Product using (_×_; _,_; map)
11+
12+
module Algebra.Properties.CommutativeMagma.Divisibility
13+
{a ℓ} (CM : CommutativeMagma a ℓ)
14+
where
15+
16+
open CommutativeMagma CM
17+
18+
open import Relation.Binary.Reasoning.Setoid setoid
19+
20+
------------------------------------------------------------------------------
21+
-- Re-export the contents of semigroup
22+
23+
open import Algebra.Properties.Magma.Divisibility magma public
24+
25+
------------------------------------------------------------------------------
26+
-- Further properties
27+
28+
x∣xy : x y x ∣ x ∙ y
29+
x∣xy x y = y , comm y x
30+
31+
xy≈z⇒x∣z : x y {z} x ∙ y ≈ z x ∣ z
32+
xy≈z⇒x∣z x y xy≈z = ∣-respʳ xy≈z (x∣xy x y)
33+
34+
∣-factors : x y (x ∣ x ∙ y) × (y ∣ x ∙ y)
35+
∣-factors x y = x∣xy x y , x∣yx y x
36+
37+
∣-factors-≈ : x y {z} x ∙ y ≈ z x ∣ z × y ∣ z
38+
∣-factors-≈ x y xy≈z = xy≈z⇒x∣z x y xy≈z , xy≈z⇒y∣z x y xy≈z
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Properties of divisibility over commutative semigroups
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
open import Algebra using (CommutativeSemigroup)
10+
11+
module Algebra.Properties.CommutativeSemigroup.Divisibility
12+
{a ℓ} (CM : CommutativeSemigroup a ℓ)
13+
where
14+
15+
open CommutativeSemigroup CM
16+
17+
------------------------------------------------------------------------------
18+
-- Re-export the contents of divisibility over semigroups
19+
20+
open import Algebra.Properties.Semigroup.Divisibility semigroup public
21+
22+
------------------------------------------------------------------------------
23+
-- Re-export the contents of divisibility over commutative magmas
24+
25+
open import Algebra.Properties.CommutativeMagma.Divisibility commutativeMagma public
26+
using (x∣xy; xy≈z⇒x∣z; ∣-factors; ∣-factors-≈)

0 commit comments

Comments
 (0)