#![doc(include = "../../doc/references.md")]
use crate::ring::*;
use crate::numeric::*;
pub trait ComRing: Ring {}
pub trait ComRingLaws: ComRing {
fn commutivity(&self, x: &Self) -> bool {
self.mul(x) == x.mul(self)
}
}
impl<R: ComRing> ComRingLaws for R {}
pub trait NumComRingLaws: NumEq + ComRing {
fn num_commutivity(&self, x: &Self, eps: &Self::Eps) -> bool {
self.mul(x).num_eq(&x.mul(self), eps)
}
}
impl<R: NumEq + ComRing> NumComRingLaws for R {}
macro_rules! numeric_com_ring {
($type:ty) => {
impl ComRing for $type {}
};
($type:ty, $($others:ty),+) => {
numeric_com_ring! {$type}
numeric_com_ring! {$($others),+}
};
}
numeric_com_ring! {
i8, i16, i32, i64, i128, isize, f32, f64
}
impl ComRing for () {}
impl<A: ComRing> ComRing for (A,) {}
impl<A: ComRing, B: ComRing> ComRing for (A, B) {}
impl<A: ComRing, B: ComRing, C: ComRing> ComRing for (A, B, C) {}
macro_rules! array_com_ring {
($size:expr) => {
impl<T: Copy + ComRing> ComRing for [T; $size] {}
};
($size:expr, $($others:expr),+) => {
array_com_ring! {$size}
array_com_ring! {$($others),+}
};
}
array_com_ring! {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
}
#[cfg(test)]
mod tests;