Semiring

Trait Semiring 

Source
pub trait Semiring {
    type Scalar: Scalar;

    // Required methods
    fn zero() -> Self::Scalar;
    fn one() -> Self::Scalar;
    fn add(a: Self::Scalar, b: Self::Scalar) -> Self::Scalar;
    fn mul(a: Self::Scalar, b: Self::Scalar) -> Self::Scalar;
}
Expand description

Semiring trait for algebra-generic operations.

Defines the four fundamental operations needed for tensor contractions under a given algebra:

  • zero(): Additive identity
  • one(): Multiplicative identity
  • add(a, b): Semiring addition (e.g., + for Standard, max for MaxPlus)
  • mul(a, b): Semiring multiplication (e.g., * for Standard, + for MaxPlus)

§Examples

Standard arithmetic:

  • zero() = 0, one() = 1, add = +, mul = *

Tropical (MaxPlus) semiring (in external crate):

  • zero() = -∞, one() = 0, add = max, mul = +

Required Associated Types§

Source

type Scalar: Scalar

The scalar type for this semiring.

Required Methods§

Source

fn zero() -> Self::Scalar

Additive identity element.

Source

fn one() -> Self::Scalar

Multiplicative identity element.

Source

fn add(a: Self::Scalar, b: Self::Scalar) -> Self::Scalar

Semiring addition.

Source

fn mul(a: Self::Scalar, b: Self::Scalar) -> Self::Scalar

Semiring multiplication.

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§