[][src]Type Definition free_algebra::MonoidRing

type MonoidRing<R, M> = ModuleString<R, M, MulRule>;

A FreeModule over some monoid, but with a multiplication between elements given using the monoid operation

Examples

use maths_traits::algebra::*;
use free_algebra::MonoidRing;

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum SplitComplexUnit { One, J }

impl MulAssociative for SplitComplexUnit {}
impl MulCommutative for SplitComplexUnit {}
impl Mul for SplitComplexUnit {
    type Output = Self;
    fn mul(self, rhs:Self) -> Self {
        match self {
            One => rhs,
            J => match rhs {
                One => J,
                J => One,
            }
        }
    }
}

impl maths_traits::algebra::One for SplitComplexUnit {
    fn one() -> Self { One }
    fn is_one(&self) -> bool { if let One=self { true } else { false } }
}

use SplitComplexUnit::*;
type SplitComplex<R> = MonoidRing<R,SplitComplexUnit>;

let x = SplitComplex::one() * 2.5 + SplitComplex::one() * (3.0, J);
let y = SplitComplex::one() * 4.0 + SplitComplex::one() * (2.0, J);

assert_eq!([x[&One], x[&J]], [2.5, 3.0]);
assert_eq!([y[&One], y[&J]], [4.0, 2.0]);

let z = x * y;
assert_eq!([z[&One], z[&J]], [16.0, 17.0]);