#![doc(include = "../../doc/references.md")]
use crate::group::*;
use crate::numeric::*;
pub trait MulComGroup: MulGroup {}
pub trait MulComGroupLaws: MulComGroup {
fn commutivity(&self, x: &Self) -> bool {
self.mul(x) == x.mul(self)
}
}
impl<G: MulComGroup> MulComGroupLaws for G {}
pub trait NumMulComGroupLaws: NumEq + MulComGroup {
fn num_commutivity(&self, x: &Self, eps: &Self::Eps) -> bool {
self.mul(x).num_eq(&x.mul(self), eps)
}
}
impl<G: NumEq + MulComGroup> NumMulComGroupLaws for G {}
macro_rules! float_mul_com_group {
($type:ty) => {
impl MulComGroup for $type {}
};
($type:ty, $($others:ty),+) => {
float_mul_com_group! {$type}
float_mul_com_group! {$($others),+}
};
}
float_mul_com_group! {
f32, f64
}
impl MulComGroup for () {}
impl<A: MulComGroup> MulComGroup for (A,) {}
impl<A: MulComGroup, B: MulComGroup> MulComGroup for (A, B) {}
impl<A: MulComGroup, B: MulComGroup, C: MulComGroup> MulComGroup for (A, B, C) {}
macro_rules! array_mul_com_group {
($size:expr) => {
impl<T: Copy + MulComGroup> MulComGroup for [T; $size] {}
};
($size:expr, $($others:expr),+) => {
array_mul_com_group! {$size}
array_mul_com_group! {$($others),+}
};
}
array_mul_com_group! {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
}
#[cfg(test)]
mod tests;