Trait miden_processor::FieldElement [−]
pub trait FieldElement: Copy + Clone + Debug + Display + Default + Send + Sync + Eq + PartialEq<Self> + Add<Self, Output = Self> + Sub<Self, Output = Self> + Mul<Self, Output = Self> + Div<Self, Output = Self> + AddAssign<Self> + SubAssign<Self> + MulAssign<Self> + DivAssign<Self> + Neg<Output = Self> + From<Self::BaseField> + From<u128> + From<u64> + From<u32> + From<u16> + From<u8> + for<'a> TryFrom<&'a [u8]> + AsBytes + Randomizable + Serializable + Deserializable {
type PositiveInteger: Debug + Copy + PartialEq<Self::PositiveInteger> + PartialOrd<Self::PositiveInteger> + ShrAssign<Self::PositiveInteger> + Shl<u32> + Shr<u32> + BitAnd<Self::PositiveInteger> + From<u32> + From<u64>;
type BaseField: StarkField;
const ELEMENT_BYTES: usize;
const IS_CANONICAL: bool;
const ZERO: Self;
const ONE: Self;
fn inv(self) -> Self;
fn conjugate(&self) -> Self;
fn elements_as_bytes(elements: &[Self]) -> &[u8]ⓘ;
unsafe fn bytes_as_elements(
bytes: &[u8]
) -> Result<&[Self], DeserializationError>;
fn as_base_elements(elements: &[Self]) -> &[Self::BaseField]ⓘ;
fn double(self) -> Self { ... }
fn square(self) -> Self { ... }
fn cube(self) -> Self { ... }
fn exp(self, power: Self::PositiveInteger) -> Self { ... }
fn zeroed_vector(n: usize) -> Vec<Self, Global> { ... }
}Expand description
Defines an element in a finite field.
This trait defines basic arithmetic operations for elements in finite fields (e.g. addition subtraction, multiplication, division) as well as several convenience functions (e.g. double, square cube). Moreover, it defines interfaces for serializing and deserializing field elements.
The elements could be in a prime field or an extension of a prime field. Currently, only quadratic field extensions are supported.
Associated Types
type PositiveInteger: Debug + Copy + PartialEq<Self::PositiveInteger> + PartialOrd<Self::PositiveInteger> + ShrAssign<Self::PositiveInteger> + Shl<u32> + Shr<u32> + BitAnd<Self::PositiveInteger> + From<u32> + From<u64>
type PositiveInteger: Debug + Copy + PartialEq<Self::PositiveInteger> + PartialOrd<Self::PositiveInteger> + ShrAssign<Self::PositiveInteger> + Shl<u32> + Shr<u32> + BitAnd<Self::PositiveInteger> + From<u32> + From<u64>
A type defining positive integers big enough to describe a field modulus for
Self::BaseField with no loss of precision.
type BaseField: StarkField
type BaseField: StarkField
Base field type for this finite field. For prime fields, BaseField should be set
to Self.
Associated Constants
const ELEMENT_BYTES: usize
const ELEMENT_BYTES: usize
Number of bytes needed to encode an element
const IS_CANONICAL: bool
const IS_CANONICAL: bool
True if internal representation of the element is the same as its canonical representation.
const ZERO: Self
const ZERO: Self
The additive identity.
const ONE: Self
const ONE: Self
The multiplicative identity.
Required methods
fn inv(self) -> Self
fn inv(self) -> Self
Returns a multiplicative inverse of this field element. If this element is ZERO, ZERO is returned.
fn conjugate(&self) -> Self
fn conjugate(&self) -> Self
Returns a conjugate of this field element.
Converts a list of elements into a list of bytes.
The elements may be in the internal representation rather than in the canonical representation. This conversion is intended to be zero-copy (i.e. by re-interpreting the underlying memory).
Converts a list of bytes into a list of field elements.
The elements are assumed to encoded in the internal representation rather than in the canonical representation. The conversion is intended to be zero-copy (i.e. by re-interpreting the underlying memory).
Errors
An error is returned if:
- Memory alignment of
bytesdoes not match memory alignment of field element data. - Length of
bytesdoes not divide into whole number of elements.
Safety
This function is unsafe because it does not check whether underlying bytes represent valid field elements according to their internal representation.
Converts a list of field elements into a list of elements in the underlying base field.
For base STARK fields, the input and output lists are the same. For extension field, the output list will contain decompositions of each extension element into underlying base elements.
Provided methods
fn double(self) -> Self
fn double(self) -> Self
Returns this field element added to itself.
fn square(self) -> Self
fn square(self) -> Self
Returns this field element raised to power 2.
fn cube(self) -> Self
fn cube(self) -> Self
Returns this field element raised to power 3.
fn exp(self, power: Self::PositiveInteger) -> Self
fn exp(self, power: Self::PositiveInteger) -> Self
Exponentiates this field element by power parameter.
fn zeroed_vector(n: usize) -> Vec<Self, Global>
fn zeroed_vector(n: usize) -> Vec<Self, Global>
Returns a vector of length n initialized with all ZERO elements.
Specialized implementations of this function may be faster than the generic implementation.