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
//! AbelianGroup
use super::{Addition, Group, GroupAdd, GroupMul, Multiplication, Operator};

/// An Abelian group is a commutative group.
///
/// A Group is a triple $`(\mathbb{A}, \circ, e)`$, composed by a set
/// $`\mathbb{A}`$ and a binary inner operation $`\circ`$ and the element $`e
/// \in \mathbb{A}`$
///
/// # Definition
/// ```math
/// \circ: \mathbb{A} \times \mathbb{A} \rightarrow \mathbb{A} , (x, y) \mapsto x \circ y
/// ```
/// 1. Closure
/// $`\forall x, y \in \mathbb{A},: x \circ y \in \mathbb{A}`$
/// 2. associativity <br>
/// $`\forall x, y, z \in \mathbb{A}`$: $`x \circ (y \circ z) = (x \circ y)
/// \circ z`$ 3. $`e`$ neutral element(identity) <br>
/// $`\forall x \in \mathbb{A}`$: $`x \circ e = e \circ x = x`$
/// 4. Inverse element
/// $`x^{-1} \in \mathbb{A}: x^{-1} \circ x = x \circ x^{-1} = e`$
/// 5. Commutativity
/// $`\forall x, y, \in \mathbb{A}: x \circ y = y \circ x`$
pub trait AbelianGroup<O: Operator>: Group<O>
{
}

macro_rules! impl_abeliangroup(
    ($T:ty, $($S:ty),*) =>
    {
        $(
        impl AbelianGroup<$T> for $S
        {
        }
        )*
    }
);

impl_abeliangroup!(Addition, i8, i16, i32, i64, i128, f32, f64);
impl_abeliangroup!(Multiplication, f32, f64);

pub trait AbelianGroupAdd: AbelianGroup<Addition> + GroupAdd
{
}

macro_rules! impl_abeliangroupadd
(
    ($($T:ty),*) =>
    {
        $(
            impl AbelianGroupAdd for $T
            {

            }
        )*
    }
);

impl_abeliangroupadd!(i8, i16, i32, i64, i128, f32, f64);

pub trait AbelianGroupMul: AbelianGroup<Multiplication> + GroupMul
{
}

macro_rules! impl_abeliangroupmul
(
    ($($T:ty),*) =>
    {
        $(
            impl AbelianGroupMul for $T
            {

            }
        )*
    }
);

impl_abeliangroupmul!(f32, f64);