Semiring

Trait Semiring 

Source
pub trait Semiring:
    Copy
    + Clone
    + Send
    + Sync
    + 'static {
    type Scalar: Scalar;

    // Required methods
    fn zero() -> Self;
    fn one() -> Self;
    fn add(self, rhs: Self) -> Self;
    fn mul(self, rhs: Self) -> Self;
    fn from_scalar(s: Self::Scalar) -> Self;
    fn to_scalar(self) -> Self::Scalar;
    fn is_zero(&self) -> bool;
}
Expand description

A semiring defines two binary operations (⊕, ⊗) with identities.

§Semiring Laws

For a semiring (S, ⊕, ⊗, 0, 1):

  • (S, ⊕, 0) is a commutative monoid
  • (S, ⊗, 1) is a monoid
  • ⊗ distributes over ⊕
  • 0 annihilates: a ⊗ 0 = 0 ⊗ a = 0

§Examples

Semiring01
Standard+×01
MaxPlusmax+-∞0
MinPlusmin++∞0
MaxMulmax×01

Required Associated Types§

Source

type Scalar: Scalar

The underlying scalar type

Required Methods§

Source

fn zero() -> Self

Additive identity (zero element for ⊕)

Source

fn one() -> Self

Multiplicative identity (one element for ⊗)

Source

fn add(self, rhs: Self) -> Self

Addition operation (⊕)

Source

fn mul(self, rhs: Self) -> Self

Multiplication operation (⊗)

Source

fn from_scalar(s: Self::Scalar) -> Self

Create from scalar value

Source

fn to_scalar(self) -> Self::Scalar

Extract scalar value

Source

fn is_zero(&self) -> bool

Check if this is the zero element

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Scalar + Zero + One + PartialEq + Add<Output = T> + Mul<Output = T>> Semiring for Standard<T>