1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Copyright 2013-2014 The Algebra Developers.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Fundamental algebraic structures.
//!
//! ~~~notrust
//! |(• ◡•)|ノ〵(❍ᴥ❍⋃) - "ALGEBRAIC!!!"
//! ~~~
//!
//! For most applications requiring an abstraction over the reals, `FieldApprox`
//! should be sufficient.
//!
//! # Fundamental algebraic structures
//!
//! Most of these traits also come in an approximate flavor for types that do
//! not satisfy the required properties exactly, but would still benefit from
//! abstractions over the structure in question.
//!
//! ## Algebraic properties
//!
//! The goal of algebraic structures is to allow elements of sets to be combined together using one
//! or several operators. The number and properties of those operators characterize the algebraic
//! structure. Abstract operators are usually noted `∘`, `+`, or `×`. The last two are preferred
//! when their behavior conform with the usual meaning of addition and multiplication of reals.
//! Let `Self` be a set. Here is a list of the most common properties those operator may fulfill:
//!
//! ~~~notrust
//! (Closure) a, b ∈ Self ⇒ a ∘ b ∈ Self,
//! (Divisibility) ∀ a, b ∈ Self, ∃! r, l ∈ Self such that l ∘ a = b and a ∘ r = b
//! (Invertibility) ∃ e ∈ Self, ∀ a ∈ Self, ∃ r, l ∈ Self such that l ∘ a = a ∘ r = e
//! If the right and left inverse are equal they are usually noted r = l = a⁻¹.
//! (Associativity) ∀ a, b, c ∈ Self, (a ∘ b) ∘ c = a ∘ (b ∘ c)
//! (Neutral Elt.) ∃ e ∈ Self, ∀ a ∈ Self, e ∘ a = a ∘ e = a
//! (Commutativity) ∀ a, b ∈ Self, a ∘ b = b ∘ a
//! ~~~
//!
//! When one works with inexact arithmetic, e.g. using floating point numbers, those properties
//! cannot possibly be satisfied due to the discrete nature of our computing tools. Thus a looser,
//! *approximate*, version is available. Note that fulfilling a property listed above implies that
//! its approximate version is fulfilled as well.
//!
//! ```notrust
//! (Approx. Closure) a, b ∈ Self ⇒ ∃ c ≈ a ∘ b such that c ∈ Self,
//! (Approx. Div.) ∀ a, b ∈ Self, ∃ r, l ∈ Self such that l ∘ a ≈ b and a ∘ r ≈ b
//! (Approx. Inv.) ∃ e ∈ Self, ∀ a ∈ Self, ∃ r, l ∈ Self such that l ∘ a ≈ e and a ∘ r ≈ e
//! (Approx. Assoc.) ∀ a, b, c ∈ Self, (a ∘ b) ∘ c ≈ a ∘ (b ∘ c)
//! (Approx. Neutr.) ∃ e ∈ Self, ∀ a ∈ Self, e ∘ a ≈ a and a ∘ e ≈ a
//! (Approx. Commut.) ∀ a, b ∈ Self, a ∘ b ≈ b ∘ a
//! ```
//!
//! ## Identity elements
//!
//! Two traits are provided that allow the definition of the additive and
//! multiplicative identity elements:
//!
//! - `IdentityAdditive`
//! - `IdentityMultiplicative`
//!
//! ## Group-like structures
//!
//! These structures are provided for both the addition and multiplication.
//!
//! ~~~notrust
//! Magma
//! |
//! _______/ \______
//! / \
//! divisibility associativity
//! | |
//! V V
//! Quasigroup Semigroup
//! | |
//! identity identity
//! | |
//! V V
//! Loop Monoid
//! | |
//! associativity invertibility
//! \______ _______/
//! \ /
//! |
//! V
//! Group
//! |
//! commutativity
//! |
//! V
//! AbelianGroup
//! ~~~
//!
//! The following traits are provided:
//!
//! - `Closure`(`Additive`|`Multiplicative`)(`Approx`)?
//! - `Magma`(`Additive`|`Multiplicative`)(`Approx`)?
//! - `Quasigroup`(`Additive`|`Multiplicative`)(`Approx`)?
//! - `Loop`(`Additive`|`Multiplicative`)(`Approx`)?
//! - `Semigroup`(`Additive`|`Multiplicative`)(`Approx`)?
//! - `Monoid`(`Additive`|`Multiplicative`)(`Approx`)?
//! - `Group`(`Additive`|`Multiplicative`)(`Approx`)?
//! - `AbelianGroup`(`Additive`|`Multiplicative`)(`Approx`)?
//!
//! ## Ring-like structures
//!
//! ~~~notrust
//! GroupAdditiveAbelian MonoidMultiplicative
//! \________ ________/
//! \ /
//! |
//! V
//! Ring
//! |
//! commutativity_of_mul
//! |
//! V
//! RingCommutative GroupMultiplicativeAbelian
//! \_______ ___________/
//! \ /
//! |
//! V
//! Field
//! ~~~
//!
//! The following traits are provided:
//!
//! - `Ring`(`Approx`)?
//! - `RingCommutative`(`Approx`)?
//! - `Field`(`Approx`)?
//!
//! ## Module-like structures
//!
//! ~~~notrust
//! GroupAdditiveAbelian RingCommutative
//! \______ _____/
//! \ /
//! | |
//! V V
//! Module<Scalar> Field
//! \______ _____/
//! \ /
//! | |
//! V V
//! VectorSpace<Scalar>
//! ~~~
//!
//! The following traits are provided:
//!
//! - `Module`(`Approx`)?
//! - `VectorSpace`(`Approx`)?
//!
//! # Quickcheck properties
//!
//! Functions are provided to test that algebraic properties like
//! assciociativity and commutativity hold for a given set of arguments.
//!
//! For example:
//!
//! ~~~
//! # use algebra::structure::SemigroupMultiplicativeApprox;
//! #[quickcheck]
//! fn prop_mul_is_associative_approx(args: (i32, i32, i32)) -> bool {
//! SemigroupMultiplicativeApprox::prop_mul_is_associative_approx(args)
//! }
//! ~~~
pub use MagmaApprox;
pub use Magma;
pub use QuasigroupApprox;
pub use Quasigroup;
pub use LoopApprox;
pub use Loop;
pub use SemigroupApprox;
pub use Semigroup;
pub use MonoidApprox;
pub use Monoid;
pub use GroupApprox;
pub use Group;
pub use GroupAbelianApprox;
pub use GroupAbelian;
pub use RingApprox;
pub use Ring;
pub use RingCommutativeApprox;
pub use RingCommutative;
pub use FieldApprox;
pub use Field;
pub use ModuleApprox;
pub use Module;
pub use VectorSpaceApprox;
pub use VectorSpace;