lettuce 0.1.3

Healthy lattice consructions in pure Rust.
Documentation
use super::*;
use crate::*;

/// An element of a commutative ring.
///
/// See also: [`FieldScalar`], [`Polynomial`]
pub trait RingElement:
    Sized
    + Copy
    + Clone
    + Default
    + Display
    + Add<Output = Self>
    + AddAssign
    + Sub<Output = Self>
    + SubAssign
    + Mul<Output = Self>
    + MulAssign
    + PartialEq
    + From<u128>
    + Sum
    + Product
    + Sync
    + Send
{
    const CARDINALITY: u128;
    const Q: u128 = Self::CARDINALITY;

    /// Is the element the additive identity?
    fn is_zero(&self) -> bool {
        *self == Self::default()
    }

    /// Multiplicative identity.
    fn one() -> Self {
        Self::from(1u128)
    }

    /// Multiplicatively flips a value in centered representation.
    /// Additive inverse of the multiplicative identity.
    /// (Negative one)
    fn negone() -> Self {
        Self::from(Self::Q - 1)
    }

    /// Additive identity.
    fn zero() -> Self {
        Self::default()
    }

    /// Uniform randomly sample an element from the ring provided an RNG source.
    fn sample_uniform<R: Rng>(rng: &mut R) -> Self {
        Self::from(rng.random::<u128>())
    }

    fn as_le_bytes(&self) -> Vec<u8>;
}