Struct miden_core::Felt
source · [−]pub struct Felt(_);
Expand description
Represents base field element in the field.
Internal values are stored in the range [0, 2^64). The backing type is u64
.
Implementations
sourceimpl BaseElement
impl BaseElement
sourcepub const fn new(value: u64) -> BaseElement
pub const fn new(value: u64) -> BaseElement
Creates a new field element from the provided value
. If the value is greater than or
equal to the field modulus, modular reduction is silently performed.
Trait Implementations
sourceimpl Add<BaseElement> for BaseElement
impl Add<BaseElement> for BaseElement
type Output = BaseElement
type Output = BaseElement
The resulting type after applying the +
operator.
sourcefn add(self, rhs: BaseElement) -> BaseElement
fn add(self, rhs: BaseElement) -> BaseElement
Performs the +
operation. Read more
sourceimpl AddAssign<BaseElement> for BaseElement
impl AddAssign<BaseElement> for BaseElement
sourcefn add_assign(&mut self, rhs: BaseElement)
fn add_assign(&mut self, rhs: BaseElement)
Performs the +=
operation. Read more
sourceimpl AsBytes for BaseElement
impl AsBytes for BaseElement
sourceimpl Clone for BaseElement
impl Clone for BaseElement
sourcefn clone(&self) -> BaseElement
fn clone(&self) -> BaseElement
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for BaseElement
impl Debug for BaseElement
sourceimpl Default for BaseElement
impl Default for BaseElement
sourcefn default() -> BaseElement
fn default() -> BaseElement
Returns the “default value” for a type. Read more
sourceimpl Deserializable for BaseElement
impl Deserializable for BaseElement
sourcefn read_from<R>(source: &mut R) -> Result<BaseElement, DeserializationError> where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<BaseElement, DeserializationError> where
R: ByteReader,
Reads a sequence of bytes from the provided source
, attempts to deserialize these bytes
into Self
, and returns the result. Read more
sourcefn read_batch_from<R>(
source: &mut R,
num_elements: usize
) -> Result<Vec<Self, Global>, DeserializationError> where
R: ByteReader,
fn read_batch_from<R>(
source: &mut R,
num_elements: usize
) -> Result<Vec<Self, Global>, DeserializationError> where
R: ByteReader,
Reads a sequence of bytes from the provided source
, attempts to deserialize these bytes
into a vector with the specified number of Self
elements, and returns the result. Read more
sourceimpl Display for BaseElement
impl Display for BaseElement
sourceimpl Div<BaseElement> for BaseElement
impl Div<BaseElement> for BaseElement
type Output = BaseElement
type Output = BaseElement
The resulting type after applying the /
operator.
sourcefn div(self, rhs: BaseElement) -> BaseElement
fn div(self, rhs: BaseElement) -> BaseElement
Performs the /
operation. Read more
sourceimpl DivAssign<BaseElement> for BaseElement
impl DivAssign<BaseElement> for BaseElement
sourcefn div_assign(&mut self, rhs: BaseElement)
fn div_assign(&mut self, rhs: BaseElement)
Performs the /=
operation. Read more
sourceimpl ExtensibleField<2> for BaseElement
impl ExtensibleField<2> for BaseElement
Defines a quadratic extension of the base field over an irreducible polynomial x2 - x + 2. Thus, an extension element is defined as α + β * φ, where φ is a root of this polynomial, and α and β are base field elements.
sourcefn mul(a: [BaseElement; 2], b: [BaseElement; 2]) -> [BaseElement; 2]
fn mul(a: [BaseElement; 2], b: [BaseElement; 2]) -> [BaseElement; 2]
Returns a product of a
and b
in the field defined by this extension.
sourcefn mul_base(a: [BaseElement; 2], b: BaseElement) -> [BaseElement; 2]
fn mul_base(a: [BaseElement; 2], b: BaseElement) -> [BaseElement; 2]
Returns a product of a
and b
in the field defined by this extension. b
represents
an element in the base field. Read more
sourcefn frobenius(x: [BaseElement; 2]) -> [BaseElement; 2]
fn frobenius(x: [BaseElement; 2]) -> [BaseElement; 2]
Returns Frobenius automorphisms for x
in the field defined by this extension.
sourcefn is_supported() -> bool
fn is_supported() -> bool
Returns true if this extension is supported for the underlying base field.
sourceimpl ExtensibleField<3> for BaseElement
impl ExtensibleField<3> for BaseElement
Defines a cubic extension of the base field over an irreducible polynomial x3 - x - 1. Thus, an extension element is defined as α + β * φ + γ * φ^2, where φ is a root of this polynomial, and α, β and γ are base field elements.
sourcefn mul(a: [BaseElement; 3], b: [BaseElement; 3]) -> [BaseElement; 3]
fn mul(a: [BaseElement; 3], b: [BaseElement; 3]) -> [BaseElement; 3]
Returns a product of a
and b
in the field defined by this extension.
sourcefn mul_base(a: [BaseElement; 3], b: BaseElement) -> [BaseElement; 3]
fn mul_base(a: [BaseElement; 3], b: BaseElement) -> [BaseElement; 3]
Returns a product of a
and b
in the field defined by this extension. b
represents
an element in the base field. Read more
sourcefn frobenius(x: [BaseElement; 3]) -> [BaseElement; 3]
fn frobenius(x: [BaseElement; 3]) -> [BaseElement; 3]
Returns Frobenius automorphisms for x
in the field defined by this extension.
sourcefn is_supported() -> bool
fn is_supported() -> bool
Returns true if this extension is supported for the underlying base field.
sourceimpl FieldElement for BaseElement
impl FieldElement for BaseElement
type PositiveInteger = u64
type PositiveInteger = u64
A type defining positive integers big enough to describe a field modulus for
Self::BaseField
with no loss of precision. Read more
type BaseField = BaseElement
type BaseField = BaseElement
Base field type for this finite field. For prime fields, BaseField
should be set
to Self
. Read more
sourceconst ZERO: BaseElement = Self::new(0)
const ZERO: BaseElement = Self::new(0)
The additive identity.
sourceconst ONE: BaseElement = Self::new(1)
const ONE: BaseElement = Self::new(1)
The multiplicative identity.
sourceconst ELEMENT_BYTES: usize = 8usize
const ELEMENT_BYTES: usize = 8usize
Number of bytes needed to encode an element
sourceconst IS_CANONICAL: bool = false
const IS_CANONICAL: bool = false
True if internal representation of the element is the same as its canonical representation.
sourcefn exp(
self,
power: <BaseElement as FieldElement>::PositiveInteger
) -> BaseElement
fn exp(
self,
power: <BaseElement as FieldElement>::PositiveInteger
) -> BaseElement
Exponentiates this field element by power
parameter.
sourcefn inv(self) -> BaseElement
fn inv(self) -> BaseElement
Returns a multiplicative inverse of this field element. If this element is ZERO, ZERO is returned. Read more
sourcefn conjugate(&self) -> BaseElement
fn conjugate(&self) -> BaseElement
Returns a conjugate of this field element.
sourcefn elements_as_bytes(elements: &[BaseElement]) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
fn elements_as_bytes(elements: &[BaseElement]) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Converts a list of elements into a list of bytes. Read more
sourceunsafe fn bytes_as_elements(
bytes: &[u8]
) -> Result<&[BaseElement], DeserializationError>
unsafe fn bytes_as_elements(
bytes: &[u8]
) -> Result<&[BaseElement], DeserializationError>
Converts a list of bytes into a list of field elements. Read more
sourcefn zeroed_vector(n: usize) -> Vec<BaseElement, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn zeroed_vector(n: usize) -> Vec<BaseElement, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns a vector of length n
initialized with all ZERO elements. Read more
sourcefn as_base_elements(
elements: &[BaseElement]
) -> &[<BaseElement as FieldElement>::BaseField]
fn as_base_elements(
elements: &[BaseElement]
) -> &[<BaseElement as FieldElement>::BaseField]
Converts a list of field elements into a list of elements in the underlying base field. Read more
sourceimpl From<[u8; 8]> for BaseElement
impl From<[u8; 8]> for BaseElement
sourcefn from(bytes: [u8; 8]) -> BaseElement
fn from(bytes: [u8; 8]) -> BaseElement
Converts the value encoded in an array of 8 bytes into a field element. The bytes are assumed to encode the element in the canonical representation in little-endian byte order. If the value is greater than or equal to the field modulus, modular reduction is silently performed.
sourceimpl From<u128> for BaseElement
impl From<u128> for BaseElement
sourcefn from(value: u128) -> BaseElement
fn from(value: u128) -> BaseElement
Converts a 128-bit value into a field element. If the value is greater than or equal to the field modulus, modular reduction is silently performed.
sourceimpl From<u16> for BaseElement
impl From<u16> for BaseElement
sourcefn from(value: u16) -> BaseElement
fn from(value: u16) -> BaseElement
Converts a 16-bit value into a field element.
sourceimpl From<u32> for BaseElement
impl From<u32> for BaseElement
sourcefn from(value: u32) -> BaseElement
fn from(value: u32) -> BaseElement
Converts a 32-bit value into a field element.
sourceimpl From<u64> for BaseElement
impl From<u64> for BaseElement
sourcefn from(value: u64) -> BaseElement
fn from(value: u64) -> BaseElement
Converts a 64-bit value into a field element. If the value is greater than or equal to the field modulus, modular reduction is silently performed.
sourceimpl From<u8> for BaseElement
impl From<u8> for BaseElement
sourcefn from(value: u8) -> BaseElement
fn from(value: u8) -> BaseElement
Converts an 8-bit value into a field element.
sourceimpl Mul<BaseElement> for BaseElement
impl Mul<BaseElement> for BaseElement
type Output = BaseElement
type Output = BaseElement
The resulting type after applying the *
operator.
sourcefn mul(self, rhs: BaseElement) -> BaseElement
fn mul(self, rhs: BaseElement) -> BaseElement
Performs the *
operation. Read more
sourceimpl MulAssign<BaseElement> for BaseElement
impl MulAssign<BaseElement> for BaseElement
sourcefn mul_assign(&mut self, rhs: BaseElement)
fn mul_assign(&mut self, rhs: BaseElement)
Performs the *=
operation. Read more
sourceimpl Neg for BaseElement
impl Neg for BaseElement
type Output = BaseElement
type Output = BaseElement
The resulting type after applying the -
operator.
sourcefn neg(self) -> BaseElement
fn neg(self) -> BaseElement
Performs the unary -
operation. Read more
sourceimpl PartialEq<BaseElement> for BaseElement
impl PartialEq<BaseElement> for BaseElement
sourceimpl Randomizable for BaseElement
impl Randomizable for BaseElement
sourceconst VALUE_SIZE: usize = 8usize
const VALUE_SIZE: usize = 8usize
Size of Self
in bytes. Read more
sourcefn from_random_bytes(bytes: &[u8]) -> Option<BaseElement>
fn from_random_bytes(bytes: &[u8]) -> Option<BaseElement>
Returns Self
if the set of bytes forms a valid value, otherwise returns None.
sourceimpl Serializable for BaseElement
impl Serializable for BaseElement
sourcefn write_into<W>(&self, target: &mut W) where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W) where
W: ByteWriter,
Serializes self
into bytes and writes these bytes into the target
.
sourcefn to_bytes(&self) -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn to_bytes(&self) -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Serializes self
into a vector of bytes.
sourcefn write_batch_into<W>(source: &[Self], target: &mut W) where
W: ByteWriter,
fn write_batch_into<W>(source: &[Self], target: &mut W) where
W: ByteWriter,
Serializes all elements of the source
and writes these bytes into the target
. Read more
sourcefn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
Returns an estimate of how many bytes are needed to represent self. Read more
sourceimpl StarkField for BaseElement
impl StarkField for BaseElement
sourceconst MODULUS: <BaseElement as FieldElement>::PositiveInteger = {transmute(0xffffffff00000001): <winter_math::fields::f64::BaseElement as winter_math::FieldElement>::PositiveInteger}
const MODULUS: <BaseElement as FieldElement>::PositiveInteger = {transmute(0xffffffff00000001): <winter_math::fields::f64::BaseElement as winter_math::FieldElement>::PositiveInteger}
sage: MODULUS = 2^64 - 2^32 + 1
sage: GF(MODULUS).is_prime_field()
True
sage: GF(MODULUS).order()
18446744069414584321
sourceconst GENERATOR: BaseElement = Self::new(7)
const GENERATOR: BaseElement = Self::new(7)
sage: GF(MODULUS).primitive_element()
7
sourceconst TWO_ADICITY: u32 = 32u32
const TWO_ADICITY: u32 = 32u32
sage: is_odd((MODULUS - 1) / 2^32)
True
sourceconst TWO_ADIC_ROOT_OF_UNITY: BaseElement = Self::new(G)
const TWO_ADIC_ROOT_OF_UNITY: BaseElement = Self::new(G)
sage: k = (MODULUS - 1) / 2^32
sage: GF(MODULUS).primitive_element()^k
1753635133440165772
sourceconst MODULUS_BITS: u32 = 64u32
const MODULUS_BITS: u32 = 64u32
The number of bits needed to represents Self::MODULUS
.
sourcefn get_modulus_le_bytes() -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn get_modulus_le_bytes() -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns byte representation of the field modulus in little-endian byte order.
sourcefn as_int(&self) -> <BaseElement as FieldElement>::PositiveInteger
fn as_int(&self) -> <BaseElement as FieldElement>::PositiveInteger
Returns a canonical integer representation of this field element.
sourcefn get_root_of_unity(n: u32) -> Self
fn get_root_of_unity(n: u32) -> Self
Returns the root of unity of order 2^n
. Read more
sourceimpl Sub<BaseElement> for BaseElement
impl Sub<BaseElement> for BaseElement
type Output = BaseElement
type Output = BaseElement
The resulting type after applying the -
operator.
sourcefn sub(self, rhs: BaseElement) -> BaseElement
fn sub(self, rhs: BaseElement) -> BaseElement
Performs the -
operation. Read more
sourceimpl SubAssign<BaseElement> for BaseElement
impl SubAssign<BaseElement> for BaseElement
sourcefn sub_assign(&mut self, rhs: BaseElement)
fn sub_assign(&mut self, rhs: BaseElement)
Performs the -=
operation. Read more
sourceimpl<'a> TryFrom<&'a [u8]> for BaseElement
impl<'a> TryFrom<&'a [u8]> for BaseElement
sourcefn try_from(
bytes: &[u8]
) -> Result<BaseElement, <BaseElement as TryFrom<&'a [u8]>>::Error>
fn try_from(
bytes: &[u8]
) -> Result<BaseElement, <BaseElement as TryFrom<&'a [u8]>>::Error>
Converts a slice of bytes into a field element; returns error if the value encoded in bytes is not a valid field element. The bytes are assumed to encode the element in the canonical representation in little-endian byte order.
type Error = DeserializationError
type Error = DeserializationError
The type returned in the event of a conversion error.
impl Copy for BaseElement
impl Eq for BaseElement
Auto Trait Implementations
impl RefUnwindSafe for BaseElement
impl Send for BaseElement
impl Sync for BaseElement
impl Unpin for BaseElement
impl UnwindSafe for BaseElement
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more