Skip to main content

yui_core/abst/
r_mod.rs

1//! Module over a [`Ring`]: an [`AddGrp`] equipped with scalar multiplication `r · m` by `R`.
2//!
3//! See: <https://en.wikipedia.org/wiki/Module_(mathematics)>
4
5use std::ops::{Mul, MulAssign};
6use crate::abst::{AddGrp, AddGrpOps, Ring, RingOps};
7
8/// Helper trait bundling [`AddGrpOps`] with scalar multiplication by `R`
9/// (both `T * R` and `T * &R`) so [`RMod`] can require them via one HRTB.
10pub trait RModOps<R, T>:
11    AddGrpOps<T> +
12    Mul<R, Output = T> +
13    for<'a> Mul<&'a R, Output = T>
14where
15    R: Ring, for<'x> &'x R: RingOps<R>
16{}
17
18/// A (left) module over a ring `R = Self::R`: an [`AddGrp`] with a distributive,
19/// associative scalar action `r · m` (for `r ∈ R`, `m ∈ Self`).
20///
21/// See: <https://en.wikipedia.org/wiki/Module_(mathematics)>
22pub trait RMod:
23    AddGrp +
24    RModOps<Self::R, Self> +
25    MulAssign<Self::R> +
26    for<'a> MulAssign<&'a Self::R>
27where
28    Self::R: Ring, for<'x> &'x Self::R: RingOps<Self::R>,
29    for<'a> &'a Self: RModOps<Self::R, Self>,
30{
31    /// The scalar ring.
32    type R;
33}
34