Skip to content

Commit d0d71c1

Browse files
authored
Some more properties of algebraic bundles
1 parent 747351e commit d0d71c1

File tree

11 files changed

+191
-29
lines changed

11 files changed

+191
-29
lines changed

CHANGELOG.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ Deprecated names
140140
New modules
141141
-----------
142142

143-
* Added `Data.Maybe.Relation.Binary.Connected`, a variant of the `Pointwise`
144-
relation where `nothing` is also related to `just`.
143+
* Properties of cancellative commutative semirings
144+
```
145+
Algebra.Properties.CancellativeCommutativeSemiring
146+
```
145147

146148
* Specifications for min and max operators
147149
```
@@ -169,6 +171,9 @@ New modules
169171
Data.List.Sort.MergeSort
170172
```
171173

174+
* Added `Data.Maybe.Relation.Binary.Connected`, a variant of the `Pointwise`
175+
relation where `nothing` is also related to `just`.
176+
172177
* Linear congruential pseudo random generators for ℕ.
173178
/!\ NB: LCGs must not be used for cryptographic applications
174179
/!\ NB: the example parameters provided are not claimed to be good
@@ -224,6 +229,45 @@ New modules
224229
Other minor additions
225230
---------------------
226231

232+
* Added new proofs to `Algebra.Consequences.Setoid`:
233+
```agda
234+
comm+almostCancelˡ⇒almostCancelʳ : AlmostLeftCancellative e _•_ → AlmostRightCancellative e _•_
235+
comm+almostCancelʳ⇒almostCancelˡ : AlmostRightCancellative e _•_ → AlmostLeftCancellative e _•_
236+
```
237+
238+
* Added new proofs in `Algebra.Properties.Magma.Divisibility`:
239+
```agda
240+
∣∣-sym : Symmetric _∣∣_
241+
∣∣-respʳ-≈ : _∣∣_ Respectsʳ _≈_
242+
∣∣-respˡ-≈ : _∣∣_ Respectsˡ _≈_
243+
∣∣-resp-≈ : _∣∣_ Respects₂ _≈_
244+
```
245+
246+
* Added new proofs in `Algebra.Properties.Semigroup.Divisibility`:
247+
```agda
248+
∣∣-trans : Transitive _∣∣_
249+
```
250+
251+
* Added new proofs in `Algebra.Properties.CommutativeSemigroup.Divisibility`:
252+
```agda
253+
x∣y∧z∣x/y⇒xz∣y : ((x/y , _) : x ∣ y) → z ∣ x/y → x ∙ z ∣ y
254+
x∣y⇒zx∣zy : x ∣ y → z ∙ x ∣ z ∙ y
255+
```
256+
257+
* Added new proofs in `Algebra.Properties.Monoid.Divisibility`:
258+
```agda
259+
∣∣-refl : Reflexive _∣∣_
260+
∣∣-reflexive : _≈_ ⇒ _∣∣_
261+
∣∣-isEquivalence : IsEquivalence _∣∣_
262+
```
263+
264+
* Added new proofs in `Algebra.Properties.CancellativeCommutativeSemiring`:
265+
```agda
266+
xy≈0⇒x≈0∨y≈0 : Decidable _≈_ → x * y ≈ 0# → x ≈ 0# ⊎ y ≈ 0#
267+
x≉0∧y≉0⇒xy≉0 : Decidable _≈_ → x ≉ 0# → y ≉ 0# → x * y ≉ 0#
268+
xy∣x⇒y∣1 : x ≉ 0# → x * y ∣ x → y ∣ 1#
269+
```
270+
227271
* Added new function in `Data.Char.Base`:
228272
```agda
229273
_≈ᵇ_ : (c d : Char) → Bool

src/Algebra/Bundles.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ record CancellativeCommutativeSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
763763
; _≉_
764764
)
765765

766+
766767
------------------------------------------------------------------------
767768
-- Bundles with 2 binary operations, 1 unary operation & 2 elements
768769
------------------------------------------------------------------------

src/Algebra/Consequences/Setoid.agda

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@
99

1010
open import Relation.Binary using (Rel; Setoid; Substitutive; Symmetric; Total)
1111

12-
module Algebra.Consequences.Setoid
13-
{a ℓ} (S : Setoid a ℓ) where
12+
module Algebra.Consequences.Setoid {a ℓ} (S : Setoid a ℓ) where
1413

1514
open Setoid S renaming (Carrier to A)
16-
1715
open import Algebra.Core
1816
open import Algebra.Definitions _≈_
1917
open import Data.Sum.Base using (inj₁; inj₂)
2018
open import Data.Product using (_,_)
19+
open import Function.Base using (_$_)
2120
import Relation.Binary.Consequences as Bin
2221
open import Relation.Binary.Reasoning.Setoid S
2322
open import Relation.Unary using (Pred)
2423

2524
------------------------------------------------------------------------
2625
-- Re-exports
2726

28-
-- Export base lemmas that don't require the setoidd
27+
-- Export base lemmas that don't require the setoid
2928

3029
open import Algebra.Consequences.Base public
3130

@@ -34,19 +33,19 @@ open import Algebra.Consequences.Base public
3433

3534
module _ {_•_ : Op₂ A} (comm : Commutative _•_) where
3635

37-
comm+cancelˡ⇒cancelʳ : LeftCancellative _•_ RightCancellative _•_
38-
comm+cancelˡ⇒cancelʳ cancelˡ {x} y z eq = cancelˡ x (begin
36+
comm+cancelˡ⇒cancelʳ : LeftCancellative _•_ RightCancellative _•_
37+
comm+cancelˡ⇒cancelʳ cancelˡ {x} y z eq = cancelˡ x $ begin
3938
x • y ≈⟨ comm x y ⟩
4039
y • x ≈⟨ eq ⟩
4140
z • x ≈⟨ comm z x ⟩
42-
x • z ∎)
41+
x • z ∎
4342

4443
comm+cancelʳ⇒cancelˡ : RightCancellative _•_ LeftCancellative _•_
45-
comm+cancelʳ⇒cancelˡ cancelʳ x {y} {z} eq = cancelʳ y z (begin
44+
comm+cancelʳ⇒cancelˡ cancelʳ x {y} {z} eq = cancelʳ y z $ begin
4645
y • x ≈⟨ comm y x ⟩
4746
x • y ≈⟨ eq ⟩
4847
x • z ≈⟨ comm x z ⟩
49-
z • x ∎)
48+
z • x ∎
5049

5150
------------------------------------------------------------------------
5251
-- Monoid-like structures
@@ -77,6 +76,24 @@ module _ {_•_ : Op₂ A} (comm : Commutative _•_) {e : A} where
7776
x • e ≈⟨ zeʳ x ⟩
7877
e ∎
7978

79+
comm+almostCancelˡ⇒almostCancelʳ : AlmostLeftCancellative e _•_
80+
AlmostRightCancellative e _•_
81+
comm+almostCancelˡ⇒almostCancelʳ cancelˡ-nonZero {x} y z x≉e yx≈zx =
82+
cancelˡ-nonZero y z x≉e $ begin
83+
x • y ≈⟨ comm x y ⟩
84+
y • x ≈⟨ yx≈zx ⟩
85+
z • x ≈⟨ comm z x ⟩
86+
x • z ∎
87+
88+
comm+almostCancelʳ⇒almostCancelˡ : AlmostRightCancellative e _•_
89+
AlmostLeftCancellative e _•_
90+
comm+almostCancelʳ⇒almostCancelˡ cancelʳ-nonZero {x} y z x≉e xy≈xz =
91+
cancelʳ-nonZero y z x≉e $ begin
92+
y • x ≈⟨ comm y x ⟩
93+
x • y ≈⟨ xy≈xz ⟩
94+
x • z ≈⟨ comm x z ⟩
95+
z • x ∎
96+
8097
------------------------------------------------------------------------
8198
-- Group-like structures
8299

src/Algebra/Definitions/RawMagma.agda

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@
1111
{-# OPTIONS --without-K --safe #-}
1212

1313
open import Algebra.Bundles using (RawMagma)
14-
open import Data.Product using (∃; _×_; _,_)
14+
open import Data.Product using (_×_; )
1515
open import Level using (_⊔_)
16-
open import Relation.Binary
16+
open import Relation.Binary.Core
1717
open import Relation.Nullary using (¬_)
1818

1919
module Algebra.Definitions.RawMagma
2020
{a ℓ} (M : RawMagma a ℓ)
2121
where
2222

2323
open RawMagma M renaming (Carrier to A)
24-
open import Algebra.Definitions _≈_
2524

2625
------------------------------------------------------------------------
2726
-- Divisibility
@@ -44,8 +43,11 @@ x ∣ʳ y = ∃ λ q → (q ∙ x) ≈ y
4443
_∤ʳ_ : Rel A (a ⊔ ℓ)
4544
x ∤ʳ y = ¬ x ∣ʳ y
4645

47-
-- _∣ˡ_ and _∣ʳ_ are only equivalent in the commutative case. In this
48-
-- case we take the right definition to be the primary one.
46+
-- General divisibility
47+
48+
-- The relations _∣ˡ_ and _∣ʳ_ are only equivalent when _∙_ is
49+
-- commutative. When that is not the case we take `_∣ʳ_` to be the
50+
-- primary one.
4951

5052
_∣_ : Rel A (a ⊔ ℓ)
5153
_∣_ = _∣ʳ_
@@ -54,15 +56,18 @@ _∤_ : Rel A (a ⊔ ℓ)
5456
x ∤ y = ¬ x ∣ y
5557

5658
------------------------------------------------------------------------
57-
-- Mutual divisibility
59+
-- Mutual divisibility.
5860

59-
-- When in a cancellative monoid, elements related by _∣∣_ are called
60-
-- associated and if x ∣∣ y then x and y differ by an invertible factor.
61+
-- In a monoid, this is an equivalence relation extending _≈_.
62+
-- When in a cancellative monoid, elements related by _∣∣_ are called
63+
-- associated, and `x ∣∣ y` means that `x` and `y` differ by some
64+
-- invertible factor.
6165

62-
infix 5 _∣∣_ _∤∤_
66+
-- Example: for ℕ this is equivalent to x ≡ y,
67+
-- for ℤ this is equivalent to (x ≡ y or x ≡ - y).
6368

6469
_∣∣_ : Rel A (a ⊔ ℓ)
6570
x ∣∣ y = x ∣ y × y ∣ x
6671

6772
_∤∤_ : Rel A (a ⊔ ℓ)
68-
x ∤∤ y = ¬ x ∣∣ y
73+
x ∤∤ y = ¬ x ∣∣ y

src/Algebra/Definitions/RawSemiring.agda

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,3 @@ record Prime (p : A) : Set (a ⊔ ℓ) where
7171
field
7272
p≉0 : p ≉ 0#
7373
split-∣ : {x y} p ∣ x * y p ∣ x ⊎ p ∣ y
74-
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Some properties of operations in CancellativeCommutativeSemiring.
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
open import Algebra using (CancellativeCommutativeSemiring)
10+
open import Algebra.Definitions using (AlmostRightCancellative)
11+
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
12+
open import Relation.Binary using (Decidable)
13+
open import Relation.Nullary using (yes; no)
14+
open import Relation.Nullary.Negation using (contradiction)
15+
16+
module Algebra.Properties.CancellativeCommutativeSemiring
17+
{a ℓ} (R : CancellativeCommutativeSemiring a ℓ)
18+
where
19+
20+
open CancellativeCommutativeSemiring R
21+
open import Algebra.Consequences.Setoid setoid
22+
open import Relation.Binary.Reasoning.Setoid setoid
23+
24+
*-almostCancelʳ : AlmostRightCancellative _≈_ 0# _*_
25+
*-almostCancelʳ = comm+almostCancelˡ⇒almostCancelʳ *-comm *-cancelˡ-nonZero
26+
27+
xy≈0⇒x≈0∨y≈0 : Decidable _≈_ {x y} x * y ≈ 0# x ≈ 0# ⊎ y ≈ 0#
28+
xy≈0⇒x≈0∨y≈0 _≟_ {x} {y} xy≈0 with x ≟ 0# | y ≟ 0#
29+
... | yes x≈0 | _ = inj₁ x≈0
30+
... | no _ | yes y≈0 = inj₂ y≈0
31+
... | no x≉0 | no y≉0 = contradiction y≈0 y≉0
32+
where
33+
xy≈x*0 = trans xy≈0 (sym (zeroʳ x))
34+
y≈0 = *-cancelˡ-nonZero y 0# x≉0 xy≈x*0
35+
36+
x≉0∧y≉0⇒xy≉0 : Decidable _≈_ {x y} x ≉ 0# y ≉ 0# x * y ≉ 0#
37+
x≉0∧y≉0⇒xy≉0 _≟_ x≉0 y≉0 xy≈0 with xy≈0⇒x≈0∨y≈0 _≟_ xy≈0
38+
... | inj₁ x≈0 = x≉0 x≈0
39+
... | inj₂ y≈0 = y≉0 y≈0

src/Algebra/Properties/CommutativeSemigroup/Divisibility.agda

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
{-# OPTIONS --without-K --safe #-}
88

99
open import Algebra using (CommutativeSemigroup)
10+
open import Data.Product using (_,_)
11+
import Relation.Binary.Reasoning.Setoid as EqReasoning
1012

1113
module Algebra.Properties.CommutativeSemigroup.Divisibility
12-
{a ℓ} (CM : CommutativeSemigroup a ℓ)
14+
{a ℓ} (CS : CommutativeSemigroup a ℓ)
1315
where
1416

15-
open CommutativeSemigroup CM
17+
open CommutativeSemigroup CS
18+
open import Algebra.Properties.CommutativeSemigroup CS using (x∙yz≈xz∙y; x∙yz≈y∙xz)
19+
open EqReasoning setoid
1620

1721
------------------------------------------------------------------------------
1822
-- Re-export the contents of divisibility over semigroups
@@ -24,3 +28,19 @@ open import Algebra.Properties.Semigroup.Divisibility semigroup public
2428

2529
open import Algebra.Properties.CommutativeMagma.Divisibility commutativeMagma public
2630
using (x∣xy; xy≈z⇒x∣z; ∣-factors; ∣-factors-≈)
31+
32+
------------------------------------------------------------------------------
33+
-- New properties
34+
35+
x∣y∧z∣x/y⇒xz∣y : {x y z} ((x/y , _) : x ∣ y) z ∣ x/y x ∙ z ∣ y
36+
x∣y∧z∣x/y⇒xz∣y {x} {y} {z} (x/y , x/y∙x≈y) (p , pz≈x/y) = p , (begin
37+
p ∙ (x ∙ z) ≈⟨ x∙yz≈xz∙y p x z ⟩
38+
(p ∙ z) ∙ x ≈⟨ ∙-congʳ pz≈x/y ⟩
39+
x/y ∙ x ≈⟨ x/y∙x≈y ⟩
40+
y ∎)
41+
42+
x∣y⇒zx∣zy : {x y} z x ∣ y z ∙ x ∣ z ∙ y
43+
x∣y⇒zx∣zy {x} {y} z (q , qx≈y) = q , (begin
44+
q ∙ (z ∙ x) ≈⟨ x∙yz≈y∙xz q z x ⟩
45+
z ∙ (q ∙ x) ≈⟨ ∙-congˡ qx≈y ⟩
46+
z ∙ y ∎)

src/Algebra/Properties/Magma/Divisibility.agda

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{-# OPTIONS --without-K --safe #-}
88

99
open import Algebra using (Magma)
10-
open import Data.Product using (_×_; _,_; ∃; map)
10+
open import Data.Product using (_×_; _,_; ∃; map; swap)
1111
open import Relation.Binary.Definitions
1212

1313
module Algebra.Properties.Magma.Divisibility {a ℓ} (M : Magma a ℓ) where
@@ -37,3 +37,18 @@ x∣yx x y = y , refl
3737

3838
xy≈z⇒y∣z : x y {z} x ∙ y ≈ z y ∣ z
3939
xy≈z⇒y∣z x y xy≈z = ∣-respʳ xy≈z (x∣yx y x)
40+
41+
------------------------------------------------------------------------
42+
-- Properties of mutual divisibility _∣∣_
43+
44+
∣∣-sym : Symmetric _∣∣_
45+
∣∣-sym = swap
46+
47+
∣∣-respʳ-≈ : _∣∣_ Respectsʳ _≈_
48+
∣∣-respʳ-≈ y≈z (x∣y , y∣x) = ∣-respʳ y≈z x∣y , ∣-respˡ y≈z y∣x
49+
50+
∣∣-respˡ-≈ : _∣∣_ Respectsˡ _≈_
51+
∣∣-respˡ-≈ x≈z (x∣y , y∣x) = ∣-respˡ x≈z x∣y , ∣-respʳ x≈z y∣x
52+
53+
∣∣-resp-≈ : _∣∣_ Respects₂ _≈_
54+
∣∣-resp-≈ = ∣∣-respʳ-≈ , ∣∣-respˡ-≈

src/Algebra/Properties/Monoid/Divisibility.agda

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,19 @@ open import Algebra.Properties.Semigroup.Divisibility semigroup public
4343
∣-preorder = record
4444
{ isPreorder = ∣-isPreorder
4545
}
46+
47+
------------------------------------------------------------------------
48+
-- Properties of mutual divisibiity
49+
50+
∣∣-refl : Reflexive _∣∣_
51+
∣∣-refl = ∣-refl , ∣-refl
52+
53+
∣∣-reflexive : _≈_ ⇒ _∣∣_
54+
∣∣-reflexive x≈y = ∣-reflexive x≈y , ∣-reflexive (sym x≈y)
55+
56+
∣∣-isEquivalence : IsEquivalence _∣∣_
57+
∣∣-isEquivalence = record
58+
{ refl = λ {x} ∣∣-refl {x}
59+
; sym = λ {x} {y} ∣∣-sym {x} {y}
60+
; trans = λ {x} {y} {z} ∣∣-trans {x} {y} {z}
61+
}

src/Algebra/Properties/Semigroup/Divisibility.agda

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ open Semigroup S
2121
open import Algebra.Properties.Magma.Divisibility magma public
2222

2323
------------------------------------------------------------------------
24-
-- Additional properties
24+
-- Properties of _∣_
2525

2626
∣-trans : Transitive _∣_
2727
∣-trans (p , px≈y) (q , qy≈z) =
2828
q ∙ p , trans (assoc q p _) (trans (∙-congˡ px≈y) qy≈z)
29+
30+
------------------------------------------------------------------------
31+
-- Properties of _∣∣_
32+
33+
∣∣-trans : Transitive _∣∣_
34+
∣∣-trans (x∣y , y∣x) (y∣z , z∣y) = ∣-trans x∣y y∣z , ∣-trans z∣y y∣x

0 commit comments

Comments
 (0)