Trait risc0_core::field::Elem

source ·
pub trait Elem: Mul<Output = Self> + MulAssign + Add<Output = Self> + AddAssign + Neg + Sub<Output = Self> + SubAssign + PartialEq + Eq + Clone + Copy + Sized + Pod + Default + Clone + Copy + Send + Sync + Debug + 'static {
    const INVALID: Self;
    const ZERO: Self;
    const ONE: Self;
    const WORDS: usize;
Show 13 methods // Required methods fn inv(self) -> Self; fn random(rng: &mut impl RngCore) -> Self; fn from_u64(val: u64) -> Self; fn to_u32_words(&self) -> Vec<u32>; fn from_u32_words(val: &[u32]) -> Self; fn is_valid(&self) -> bool; // Provided methods fn pow(self, exp: usize) -> Self { ... } fn valid_or_zero(&self) -> Self { ... } fn ensure_valid(&self) -> &Self { ... } fn as_u32_slice(elems: &[Self]) -> &[u32] { ... } fn as_u32_slice_unchecked(elems: &[Self]) -> &[u32] { ... } fn from_u32_slice(u32s: &[u32]) -> &[Self] { ... } fn from_u32_slice_unchecked(u32s: &[u32]) -> &[Self] { ... }
}
Expand description

Subfield elements that can be compared, copied, and operated on via multiplication, addition, and subtraction

Required Associated Constants§

source

const INVALID: Self

Invalid, a value that is not a member of the field. This should only be used with the “is_valid” or “unwrap_or_zero” methods.

source

const ZERO: Self

Zero, the additive identity.

source

const ONE: Self

One, the multiplicative identity.

source

const WORDS: usize

How many u32 words are required to hold a single element

Required Methods§

source

fn inv(self) -> Self

Compute the multiplicative inverse of x (or 1 / x in finite field terms).

source

fn random(rng: &mut impl RngCore) -> Self

Returns a random valid field element.

source

fn from_u64(val: u64) -> Self

Import a number into the field from the natural numbers.

source

fn to_u32_words(&self) -> Vec<u32>

Represent a field element as a sequence of u32s

source

fn from_u32_words(val: &[u32]) -> Self

Interpret a sequence of u32s as a field element

source

fn is_valid(&self) -> bool

Returns true if this element is not INVALID. Unlike most methods, this may be called on an INVALID element.

Provided Methods§

source

fn pow(self, exp: usize) -> Self

Return an element raised to the given power.

source

fn valid_or_zero(&self) -> Self

Returns 0 if this element is INVALID, else the value of this element. Unlike most methods, this may be called on an INVALID element.

source

fn ensure_valid(&self) -> &Self

Returns this element, but checks to make sure it’s valid.

source

fn as_u32_slice(elems: &[Self]) -> &[u32]

Interprets a slice of these elements as u32s. These elements may not be INVALID.

source

fn as_u32_slice_unchecked(elems: &[Self]) -> &[u32]

Interprets a slice of these elements as u32s. These elements may potentially be INVALID.

source

fn from_u32_slice(u32s: &[u32]) -> &[Self]

Interprets a slice of u32s as a slice of these elements. These elements may not be INVALID.

source

fn from_u32_slice_unchecked(u32s: &[u32]) -> &[Self]

Interprets a slice of u32s as a slice of these elements. These elements may be INVALID.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Elem for risc0_core::field::baby_bear::Elem

source§

const INVALID: Self = _

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

const WORDS: usize = 1usize

source§

impl Elem for risc0_core::field::baby_bear::ExtElem

source§

const INVALID: Self = _

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

const WORDS: usize = 4usize

source§

impl Elem for risc0_core::field::goldilocks::Elem

source§

const INVALID: Self = _

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

const WORDS: usize = 2usize

source§

impl Elem for risc0_core::field::goldilocks::ExtElem

source§

const INVALID: Self = _

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

const WORDS: usize = 4usize