mathru/algebra/abstr/
group.rs

1//! Group
2use super::{
3    monoid::{Monoid, MonoidAdd, MonoidMul},
4    operator::{Addition, Multiplication, Operator},
5    Loop,
6};
7use std::ops::{Div, DivAssign, Neg, Sub, SubAssign};
8
9/// A Group is a triple $(\mathbb{M}, \circ, e)$, composed by a set
10/// $\mathbb{M}$ and a binary inner operation $\circ$ and the element $e
11/// \in \mathbb{M}$
12///
13/// ```math
14/// \circ: \mathbb{M} \times \mathbb{M} \rightarrow \mathbb{M} , (x, y) \mapsto x \circ y
15/// ```
16/// 1. associativity <br>
17///    $\forall x, y, z \in \mathbb{M}$: $x \circ (y \circ z) = (x \circ y)
18///    \circ z$ 2. $e$ neutral element(identity) <br>
19///    $\forall x \in \mathbb{M}$: $x \circ e = e \circ x = x$
20/// 3.
21///    $x^-1 \in \mathbb{M}: x^⁻1 \circ x = x \circ x^-1 ` = e$
22pub trait Group<O: Operator>: Loop<O> + Monoid<O> {}
23
24macro_rules! impl_group(
25    ($T:ty, $($S:ty),*) =>
26    {
27        $(
28        impl Group<$T> for $S
29        {
30        }
31        )*
32    }
33);
34
35impl_group!(Addition, i8, i16, i32, i64, i128, f32, f64);
36impl_group!(Multiplication, f32, f64);
37
38pub trait GroupAdd:
39    Group<Addition> + MonoidAdd + Sub<Self, Output = Self> + SubAssign<Self> + Neg<Output = Self>
40{
41}
42
43macro_rules! impl_groupadd
44(
45    ($($T:ty),*) =>
46    {
47        $(
48            impl GroupAdd for $T
49            {
50
51            }
52        )*
53    }
54);
55
56impl_groupadd!(i8, i16, i32, i64, i128, f32, f64);
57
58pub trait GroupMul:
59    Group<Multiplication> + MonoidMul + Div<Self, Output = Self> + DivAssign<Self>
60{
61}
62
63macro_rules! impl_groupmul
64(
65    ($($T:ty),*) =>
66    {
67        $(
68            impl GroupMul for $T
69            {
70
71            }
72        )*
73    }
74);
75
76impl_groupmul!(f32, f64);