Skip to content

Commit 84dcc85

Browse files
Deprecate Algebra.Operations.Ring and refactor Tactics.RingSolver (#1396)
1 parent ffeb1cb commit 84dcc85

33 files changed

+430
-258
lines changed

CHANGELOG.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,14 @@ Deprecated modules
8787
complete. The new definitions are parameterised by raw bundles instead of bundles
8888
meaning they are much more flexible to work with.
8989

90-
* The module `Algebra.Operations.CommutativeMonoid` has been deprecated. The definition
91-
of multiplication and the associated properties have been moved to
92-
`Algebra.Properties.CommutativeMonoid.Multiplication`. The definition of summation
93-
which was defined over the deprecated `Data.Table` has been redefined in terms of
94-
`Data.Vec.Functional` and been moved to `Algbra.Properties.CommutativeMonoid.Summation`.
95-
The properties of summation in `Algebra.Properties.CommutativeMonoid` have likewise
96-
been deprecated and moved to `Algebra.Properties.CommutativeMonoid.Summation`.
97-
98-
* The module `Algebra.Operations.Semiring` has been deprecated. The contents has
99-
been moved to `Algebra.Properties.Semiring.(Multiplication/Exponentiation)`.
90+
* All modules in the folder `Algebra.Operations` have been deprecated, as their design
91+
a) was inconsistent, some are parameterised over the raw bundle and some over the normal bundle
92+
b) prevented definitions from being neatly inherited by super-bundles.
93+
94+
These problems have been fixed with a redesign: definitions of the operations can be found in
95+
`Algebra.Definitions.(RawMagma/RawMonoid/RawSemiring)` and their properties can be found in
96+
`Algebra.Properties.(Magma/Semigroup/Monoid/CommutativeMonoid/Semiring).(Sum/Mult/Exp)`.
97+
The latter also export the definition, and so most users will only need to import the latter.
10098

10199
Deprecated names
102100
----------------
@@ -200,29 +198,33 @@ New modules
200198
Algebra.Definitions.RawSemiring
201199
```
202200

201+
* Setoid equality over vectors:
202+
```
203+
Data.Vec.Functional.Relation.Binary.Equality.Setoid
204+
```
205+
203206
* Properties of generic definitions over algebraic structures (divisibility, multiplication etc.):
204207
```
205208
Algebra.Properties.Magma.Divisibility
206-
207209
Algebra.Properties.Semigroup.Divisibility
208-
209210
Algebra.Properties.CommutativeSemigroup.Divisibility
210211
211-
Algebra.Properties.Monoid.Summation
212-
Algebra.Properties.Monoid.Multiplication
212+
Algebra.Properties.Monoid.Sum
213+
Algebra.Properties.Monoid.Mult
213214
Algebra.Properties.Monoid.Divisibility
214215
215-
Algebra.Properties.CommutativeMonoid.Summation
216+
Algebra.Properties.CommutativeMonoid.Sum
217+
Algebra.Properties.CommutativeMonoid.Mult
216218
217-
Algebra.Properties.Semiring.Multiplication
218-
Algebra.Properties.Semiring.Exponentiation
219-
Algebra.Properties.Semiring.GCD
220219
Algebra.Properties.Semiring.Divisibility
221-
```
222-
223-
* Setoid equality over vectors:
224-
```
225-
Data.Vec.Functional.Relation.Binary.Equality.Setoid
220+
Algebra.Properties.Semiring.Exp
221+
Algebra.Properties.Semiring.Exp.TCOptimised
222+
Algebra.Properties.Semiring.GCD
223+
Algebra.Properties.Semiring.Mult
224+
Algebra.Properties.Semiring.Mult.TCOptimised
225+
226+
Algebra.Properties.CommutativeSemiring.Exp
227+
Algebra.Properties.CommutativeSemiring.Exp.TCOptimised
226228
```
227229

228230
* Heterogeneous relation characterising a list as an infix segment of another:

src/Algebra/Bundles.agda

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,22 @@ record RawRing c ℓ : Set (suc (c ⊔ ℓ)) where
783783
0# : Carrier
784784
1# : Carrier
785785

786+
rawSemiring : RawSemiring c ℓ
787+
rawSemiring = record
788+
{ _≈_ = _≈_
789+
; _+_ = _+_
790+
; _*_ = _*_
791+
; 0# = 0#
792+
; 1# = 1#
793+
}
794+
795+
open RawSemiring rawSemiring public
796+
using
797+
( _≉_
798+
; +-rawMagma; +-rawMonoid
799+
; *-rawMagma; *-rawMonoid
800+
)
801+
786802
+-rawGroup : RawGroup c ℓ
787803
+-rawGroup = record
788804
{ _≈_ = _≈_
@@ -791,13 +807,6 @@ record RawRing c ℓ : Set (suc (c ⊔ ℓ)) where
791807
; _⁻¹ = -_
792808
}
793809

794-
*-rawMonoid : RawMonoid c ℓ
795-
*-rawMonoid = record
796-
{ _≈_ = _≈_
797-
; _∙_ = _*_
798-
; ε = 1#
799-
}
800-
801810
record Ring c ℓ : Set (suc (c ⊔ ℓ)) where
802811
infix 8 -_
803812
infixl 7 _*_

src/Algebra/Definitions/RawMonoid.agda

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ infixl 8 _×′_
5555
_×′_ : Carrier Carrier
5656
0 ×′ x = 0#
5757
1 ×′ x = x
58-
suc n ×′ x = x + n ×′ x
58+
suc n ×′ x = n ×′ x + x
59+
60+
{-# INLINE _×′_ #-}
5961

6062
------------------------------------------------------------------------
6163
-- Summation

src/Algebra/Definitions/RawSemiring.agda

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
open import Algebra.Bundles using (RawSemiring)
1010
open import Data.Sum.Base using (_⊎_)
11+
open import Data.Nat using (ℕ)
1112
open import Level using (_⊔_)
1213
open import Relation.Binary.Core using (Rel)
1314

@@ -20,15 +21,15 @@ open RawSemiring M renaming (Carrier to A)
2021

2122
open import Algebra.Definitions.RawMonoid +-rawMonoid public
2223
using
23-
( _×_
24-
; _×′_
25-
; sum
24+
( _×_ -- : ℕ → A → A
25+
; _×′_ -- : ℕ → A → A
26+
; sum -- : Vector A n → A
2627
)
2728

2829
------------------------------------------------------------------------
2930
-- Definitions over _*_
3031

31-
open import Algebra.Definitions.RawMonoid *-rawMonoid public
32+
open import Algebra.Definitions.RawMonoid *-rawMonoid as Mult public
3233
using
3334
( _∣_
3435
; _∤_
@@ -37,8 +38,24 @@ open import Algebra.Definitions.RawMonoid *-rawMonoid public
3738
( sum to product
3839
)
3940

41+
-- Unlike `sum` to `product`, can't simply rename multiplication to
42+
-- exponentation as the argument order is reversed.
43+
44+
-- Standard exponentiation
45+
46+
infixr 8 _^_
47+
_^_ : A A
48+
x ^ n = n Mult.× x
49+
50+
-- Exponentiation optimsed for type-checking
51+
52+
infixr 8 _^′_
53+
_^′_ : A A
54+
x ^′ n = n Mult.×′ x
55+
{-# INLINE _^′_ #-}
56+
4057
------------------------------------------------------------------------
41-
-- Coprimality
58+
-- Primality
4259

4360
Coprime : Rel A (a ⊔ ℓ)
4461
Coprime x y = {z} z ∣ x z ∣ y z ∣ 1#

src/Algebra/Operations/CommutativeMonoid.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Algebra.Operations.CommutativeMonoid
2424

2525
{-# WARNING_ON_IMPORT
2626
"Algebra.Operations.CommutativeMonoid was deprecated in v1.5.
27-
Use Algebra.Properties.CommutativeMonoid.(Summation/Multiplication/Multiplication.TCOptimised) instead."
27+
Use Algebra.Properties.CommutativeMonoid.(Sum/Mult/Exp)(.TCOptimised) instead."
2828
#-}
2929

3030
open CommutativeMonoid CM

src/Algebra/Operations/Ring.agda

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
11
------------------------------------------------------------------------
22
-- The Agda standard library
33
--
4-
-- Some defined operations over Rings
4+
-- This module is DEPRECATED.
55
------------------------------------------------------------------------
66

77
{-# OPTIONS --without-K --safe #-}
88

9-
-- This module gives the definition of _^_ which is used throughout
10-
-- the library. It's a little different from the normal definition:
11-
--
12-
-- x ^ zero = 1#
13-
-- x ^ suc i = x * x ^ i
14-
--
15-
-- This is for two reasons. First, we want to avoid unnecessarily
16-
-- multiplying by 1# if possible:
17-
--
18-
-- Standard definition: x ^ 2 = x * x * 1#
19-
-- Our definition: x ^ 2 = x * x
20-
--
21-
-- This speeds up typechecking and makes for much more readable
22-
-- proofs.
23-
--
24-
-- Secondly, we want to associate to the left:
25-
--
26-
-- Standard definition: x ^ 3 = x * (x * (x * 1#))
27-
-- Our definition: x ^ 2 = (x * x) * x
28-
--
29-
-- As counterintuitive as it may seem, this also speeds up
30-
-- typechecking.
31-
329
open import Algebra
3310

3411
module Algebra.Operations.Ring
3512
{ℓ₁ ℓ₂} (ring : RawRing ℓ₁ ℓ₂)
3613
where
3714

15+
{-# WARNING_ON_IMPORT
16+
"Algebra.Operations.Ring was deprecated in v1.5.
17+
Use Algebra.Properties.Semiring.Exp(.TCOptimised) instead."
18+
#-}
19+
3820
open import Data.Nat.Base as ℕ using (ℕ; suc; zero)
3921

4022
open RawRing ring

src/Algebra/Operations/Semiring.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Algebra.Operations.Semiring {s₁ s₂} (S : Semiring s₁ s₂) where
1717

1818
{-# WARNING_ON_IMPORT
1919
"Algebra.Operations.Semiring was deprecated in v1.5.
20-
Use Algebra.Properties.Semiring.(Multiplication/Exponentiation) instead."
20+
Use Algebra.Properties.Semiring.(Mult/Exp) instead."
2121
#-}
2222

2323
open Semiring S
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Multiplication over a monoid (i.e. repeated addition)
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
open import Algebra.Bundles using (CommutativeMonoid)
10+
open import Data.Nat.Base as ℕ using (ℕ; zero; suc)
11+
12+
module Algebra.Properties.CommutativeMonoid.Mult
13+
{a ℓ} (M : CommutativeMonoid a ℓ) where
14+
15+
-- View of the monoid operator as addition
16+
open CommutativeMonoid M
17+
renaming
18+
( _∙_ to _+_
19+
; ∙-cong to +-cong
20+
; ∙-congʳ to +-congʳ
21+
; ∙-congˡ to +-congˡ
22+
; identityˡ to +-identityˡ
23+
; identityʳ to +-identityʳ
24+
; assoc to +-assoc
25+
; ε to 0#
26+
)
27+
28+
open import Relation.Binary.Reasoning.Setoid setoid
29+
open import Algebra.Properties.CommutativeSemigroup commutativeSemigroup
30+
31+
------------------------------------------------------------------------
32+
-- Re-export definition and properties for monoids
33+
34+
open import Algebra.Properties.Monoid.Mult monoid public
35+
36+
------------------------------------------------------------------------
37+
-- Properties of _×_
38+
39+
×-distrib-+ : x y n n × (x + y) ≈ n × x + n × y
40+
×-distrib-+ x y zero = sym (+-identityˡ 0# )
41+
×-distrib-+ x y (suc n) = begin
42+
x + y + n × (x + y) ≈⟨ +-congˡ (×-distrib-+ x y n) ⟩
43+
x + y + (n × x + n × y) ≈⟨ +-assoc x y (n × x + n × y) ⟩
44+
x + (y + (n × x + n × y)) ≈⟨ +-congˡ (x∙yz≈y∙xz y (n × x) (n × y)) ⟩
45+
x + (n × x + suc n × y) ≈⟨ x∙yz≈xy∙z x (n × x) (suc n × y) ⟩
46+
suc n × x + suc n × y ∎
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Multiplication over a monoid (i.e. repeated addition) optimised for
5+
-- type checking.
6+
------------------------------------------------------------------------
7+
8+
{-# OPTIONS --without-K --safe #-}
9+
10+
open import Algebra.Bundles using (CommutativeMonoid)
11+
open import Data.Nat.Base as ℕ using (ℕ; zero; suc)
12+
open import Relation.Binary.Core using (_Preserves_⟶_; _Preserves₂_⟶_⟶_)
13+
open import Relation.Binary.PropositionalEquality as P using (_≡_)
14+
15+
module Algebra.Properties.CommutativeMonoid.Mult.TCOptimised
16+
{a ℓ} (M : CommutativeMonoid a ℓ) where
17+
18+
open CommutativeMonoid M renaming
19+
( _∙_ to _+_
20+
; ∙-cong to +-cong
21+
; ∙-congˡ to +-congˡ
22+
; ∙-congʳ to +-congʳ
23+
; identityˡ to +-identityˡ
24+
; identityʳ to +-identityʳ
25+
; assoc to +-assoc
26+
; ε to 0#
27+
)
28+
29+
open import Algebra.Properties.CommutativeMonoid.Mult M as U
30+
using () renaming (_×_ to _×ᵤ_)
31+
32+
open import Relation.Binary.Reasoning.Setoid setoid
33+
34+
------------------------------------------------------------------------
35+
-- Re-export definition and properties for monoids
36+
37+
open import Algebra.Properties.Monoid.Mult.TCOptimised monoid public
38+
39+
------------------------------------------------------------------------
40+
-- Properties
41+
42+
×-distrib-+ : x y n n × (x + y) ≈ n × x + n × y
43+
×-distrib-+ x y n = begin
44+
n × (x + y) ≈˘⟨ ×ᵤ≈× n (x + y) ⟩
45+
n ×ᵤ (x + y) ≈⟨ U.×-distrib-+ x y n ⟩
46+
n ×ᵤ x + n ×ᵤ y ≈⟨ +-cong (×ᵤ≈× n x) (×ᵤ≈× n y) ⟩
47+
n × x + n × y ∎

src/Algebra/Properties/CommutativeMonoid/Summation.agda renamed to src/Algebra/Properties/CommutativeMonoid/Sum.agda

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open import Function.Equality using (_⟨$⟩_)
1818
open import Relation.Binary.PropositionalEquality as P using (_≡_)
1919
open import Relation.Nullary.Negation using (contradiction)
2020

21-
module Algebra.Properties.CommutativeMonoid.Summation
21+
module Algebra.Properties.CommutativeMonoid.Sum
2222
{a ℓ} (M : CommutativeMonoid a ℓ) where
2323

2424
open CommutativeMonoid M
@@ -40,7 +40,7 @@ open import Relation.Binary.Reasoning.Setoid setoid
4040
------------------------------------------------------------------------
4141
-- Re-export summation over monoids
4242

43-
open import Algebra.Properties.Monoid.Summation monoid public
43+
open import Algebra.Properties.Monoid.Sum monoid public
4444

4545
------------------------------------------------------------------------
4646
-- Properties

0 commit comments

Comments
 (0)