mathru/algebra/abstr/abeliangroup.rs
1//! AbelianGroup
2use super::{Addition, Group, GroupAdd, GroupMul, Multiplication, Operator};
3
4/// An Abelian group is a commutative group.
5///
6/// A Group is a triple $(\mathbb{A}, \circ, e)$, composed by a set
7/// $\mathbb{A}$ and a binary inner operation $\circ$ and the element $e
8/// \in \mathbb{A}$
9///
10/// # Definition
11/// ```math
12/// \circ: \mathbb{A} \times \mathbb{A} \rightarrow \mathbb{A} , (x, y) \mapsto x \circ y
13/// ```
14/// 1. Closure
15/// $\forall x, y \in \mathbb{A},: x \circ y \in \mathbb{A}$
16/// 2. associativity <br>
17/// $\forall x, y, z \in \mathbb{A}$: $x \circ (y \circ z) = (x \circ y)
18/// \circ z$ 3. $e$ neutral element(identity) <br>
19/// $\forall x \in \mathbb{A}$: $x \circ e = e \circ x = x$
20/// 4. Inverse element
21/// $x^{-1} \in \mathbb{A}: x^{-1} \circ x = x \circ x^{-1} = e$
22/// 5. Commutativity
23/// $\forall x, y, \in \mathbb{A}: x \circ y = y \circ x$
24pub trait AbelianGroup<O: Operator>: Group<O> {}
25
26macro_rules! impl_abeliangroup(
27 ($T:ty, $($S:ty),*) =>
28 {
29 $(
30 impl AbelianGroup<$T> for $S
31 {
32 }
33 )*
34 }
35);
36
37impl_abeliangroup!(Addition, i8, i16, i32, i64, i128, f32, f64);
38impl_abeliangroup!(Multiplication, f32, f64);
39
40pub trait AbelianGroupAdd: AbelianGroup<Addition> + GroupAdd {}
41
42macro_rules! impl_abeliangroupadd
43(
44 ($($T:ty),*) =>
45 {
46 $(
47 impl AbelianGroupAdd for $T
48 {
49
50 }
51 )*
52 }
53);
54
55impl_abeliangroupadd!(i8, i16, i32, i64, i128, f32, f64);
56
57pub trait AbelianGroupMul: AbelianGroup<Multiplication> + GroupMul {}
58
59macro_rules! impl_abeliangroupmul
60(
61 ($($T:ty),*) =>
62 {
63 $(
64 impl AbelianGroupMul for $T
65 {
66
67 }
68 )*
69 }
70);
71
72impl_abeliangroupmul!(f32, f64);