Semiring

Trait Semiring 

Source
pub trait Semiring: Algebra {
    // 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.

The algebra type Alg carries its scalar type via Alg::Scalar. This is the core algebra model — primitive-family trait bounds and einsum/linalg contracts are centered on Alg::Scalar.

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 (Standard<f64>):

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

Tropical (MaxPlus) semiring (in external crate):

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

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§

Source§

impl<T: Scalar + Zero + One> Semiring for Standard<T>

Standard arithmetic implements Semiring with + and *.

§Examples

use tenferro_algebra::{Semiring, Standard};

let z = <Standard<f64> as Semiring>::zero();
let o = <Standard<f64> as Semiring>::one();
assert_eq!(z, 0.0);
assert_eq!(o, 1.0);