Struct lambdaworks_math::field::element::FieldElement
source · pub struct FieldElement<F: IsField> { /* private fields */ }
Expand description
A field element with operations algorithms defined in F
Implementations§
source§impl<F: IsField> FieldElement<F>
impl<F: IsField> FieldElement<F>
pub fn inplace_batch_inverse(numbers: &mut [Self])
source§impl<F> FieldElement<F>where
F: IsField,
impl<F> FieldElement<F>where F: IsField,
FieldElement general implementation
Most of this is delegated to the trait F
that
implements the field operations.
sourcepub fn pow<T>(&self, exponent: T) -> Selfwhere
T: IsUnsignedInteger,
pub fn pow<T>(&self, exponent: T) -> Selfwhere T: IsUnsignedInteger,
Returns self
raised to the power of exponent
source§impl<F: IsPrimeField> FieldElement<F>
impl<F: IsPrimeField> FieldElement<F>
pub fn representative(&self) -> F::RepresentativeType
pub fn sqrt(&self) -> Option<(Self, Self)>
pub fn legendre_symbol(&self) -> LegendreSymbol
source§impl<M, const NUM_LIMBS: usize> FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where
M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,
impl<M, const NUM_LIMBS: usize> FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,
sourcepub const fn from_hex_unchecked(hex: &str) -> Self
pub const fn from_hex_unchecked(hex: &str) -> Self
Creates a FieldElement
from a hexstring. It can contain 0x
or not.
Panics
Panics if value is not a hexstring
sourcepub fn from_hex(hex: &str) -> Result<Self, CreationError>
pub fn from_hex(hex: &str) -> Result<Self, CreationError>
Creates a FieldElement
from a hexstring. It can contain 0x
or not.
Returns an CreationError::InvalidHexString
if the value is not a hexstring
source§impl<Q> FieldElement<QuadraticExtensionField<Q>>where
Q: Clone + Debug + HasQuadraticNonResidue,
impl<Q> FieldElement<QuadraticExtensionField<Q>>where Q: Clone + Debug + HasQuadraticNonResidue,
source§impl FieldElement<Stark252PrimeField>
impl FieldElement<Stark252PrimeField>
sourcepub fn to_bytes_le(&self) -> [u8; 32]
pub fn to_bytes_le(&self) -> [u8; 32]
No std version of to_bytes_le
from ByteConversion
trait
This follows the convention used by
Starkware and Lambdaclass Cairo VM It’s the same as ByteConversion to_bytes_le.
Trait Implementations§
source§impl<F> Add<&FieldElement<F>> for &FieldElement<F>where
F: IsField,
impl<F> Add<&FieldElement<F>> for &FieldElement<F>where F: IsField,
Addition operator overloading for field elements
§type Output = FieldElement<F>
type Output = FieldElement<F>
+
operator.source§impl<F: IsField> Add<&FieldElement<F>> for &Polynomial<FieldElement<F>>
impl<F: IsField> Add<&FieldElement<F>> for &Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
+
operator.source§fn add(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>
fn add(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>
+
operation. Read moresource§impl<F> Add<&FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Add<&FieldElement<F>> for FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
+
operator.source§impl<F: IsField> Add<&FieldElement<F>> for Polynomial<FieldElement<F>>
impl<F: IsField> Add<&FieldElement<F>> for Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
+
operator.source§fn add(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>
fn add(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>
+
operation. Read moresource§impl<F: IsField> Add<&Polynomial<FieldElement<F>>> for &FieldElement<F>
impl<F: IsField> Add<&Polynomial<FieldElement<F>>> for &FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
+
operator.source§fn add(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
fn add(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
+
operation. Read moresource§impl<F: IsField> Add<&Polynomial<FieldElement<F>>> for FieldElement<F>
impl<F: IsField> Add<&Polynomial<FieldElement<F>>> for FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
+
operator.source§fn add(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
fn add(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
+
operation. Read moresource§impl<F> Add<FieldElement<F>> for &FieldElement<F>where
F: IsField,
impl<F> Add<FieldElement<F>> for &FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
+
operator.source§impl<F: IsField> Add<FieldElement<F>> for &Polynomial<FieldElement<F>>
impl<F: IsField> Add<FieldElement<F>> for &Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
+
operator.source§fn add(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>
fn add(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>
+
operation. Read moresource§impl<F> Add<FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Add<FieldElement<F>> for FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
+
operator.source§impl<F: IsField> Add<FieldElement<F>> for Polynomial<FieldElement<F>>
impl<F: IsField> Add<FieldElement<F>> for Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
+
operator.source§fn add(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>
fn add(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>
+
operation. Read moresource§impl<F: IsField> Add<Polynomial<FieldElement<F>>> for &FieldElement<F>
impl<F: IsField> Add<Polynomial<FieldElement<F>>> for &FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
+
operator.source§fn add(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
fn add(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
+
operation. Read moresource§impl<F: IsField> Add<Polynomial<FieldElement<F>>> for FieldElement<F>
impl<F: IsField> Add<Polynomial<FieldElement<F>>> for FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
+
operator.source§fn add(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
fn add(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
+
operation. Read moresource§impl<F> AddAssign<FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> AddAssign<FieldElement<F>> for FieldElement<F>where F: IsField,
AddAssign operator overloading for field elements
source§fn add_assign(&mut self, rhs: FieldElement<F>)
fn add_assign(&mut self, rhs: FieldElement<F>)
+=
operation. Read moresource§impl ByteConversion for FieldElement<Degree2ExtensionField>
impl ByteConversion for FieldElement<Degree2ExtensionField>
source§fn to_bytes_be(&self) -> Vec<u8>
fn to_bytes_be(&self) -> Vec<u8>
source§fn to_bytes_le(&self) -> Vec<u8>
fn to_bytes_le(&self) -> Vec<u8>
source§fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>where
Self: Sized,
fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>where Self: Sized,
source§fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>where
Self: Sized,
fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>where Self: Sized,
source§impl<M, const NUM_LIMBS: usize> ByteConversion for FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where
M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,
impl<M, const NUM_LIMBS: usize> ByteConversion for FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,
source§fn to_bytes_be(&self) -> Vec<u8>
fn to_bytes_be(&self) -> Vec<u8>
source§fn to_bytes_le(&self) -> Vec<u8>
fn to_bytes_le(&self) -> Vec<u8>
source§fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>
fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>
source§fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>
fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>
source§impl<F: Clone + IsField> Clone for FieldElement<F>where
F::BaseType: Clone,
impl<F: Clone + IsField> Clone for FieldElement<F>where F::BaseType: Clone,
source§fn clone(&self) -> FieldElement<F>
fn clone(&self) -> FieldElement<F>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<F> Default for FieldElement<F>where
F: IsField,
impl<F> Default for FieldElement<F>where F: IsField,
source§impl<const MODULUS: u64> Deserializable for FieldElement<U64PrimeField<MODULUS>>
impl<const MODULUS: u64> Deserializable for FieldElement<U64PrimeField<MODULUS>>
fn deserialize(bytes: &[u8]) -> Result<Self, DeserializationError>where Self: Sized,
source§impl<M, const NUM_LIMBS: usize> Display for FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where
M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,
impl<M, const NUM_LIMBS: usize> Display for FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,
source§impl<F> Div<&FieldElement<F>> for &FieldElement<F>where
F: IsField,
impl<F> Div<&FieldElement<F>> for &FieldElement<F>where F: IsField,
Division operator overloading for field elements*/
§type Output = FieldElement<F>
type Output = FieldElement<F>
/
operator.source§impl<F> Div<&FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Div<&FieldElement<F>> for FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
/
operator.source§impl<F> Div<FieldElement<F>> for &FieldElement<F>where
F: IsField,
impl<F> Div<FieldElement<F>> for &FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
/
operator.source§impl<F> Div<FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Div<FieldElement<F>> for FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
/
operator.source§impl<F> From<&<F as IsField>::BaseType> for FieldElement<F>where
F::BaseType: Clone,
F: IsField,
impl<F> From<&<F as IsField>::BaseType> for FieldElement<F>where F::BaseType: Clone, F: IsField,
From overloading for field elements
source§impl<F> Mul<&FieldElement<F>> for &FieldElement<F>where
F: IsField,
impl<F> Mul<&FieldElement<F>> for &FieldElement<F>where F: IsField,
Multiplication operator overloading for field elements*/
§type Output = FieldElement<F>
type Output = FieldElement<F>
*
operator.source§impl<F: IsField> Mul<&FieldElement<F>> for &Polynomial<FieldElement<F>>
impl<F: IsField> Mul<&FieldElement<F>> for &Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
*
operator.source§fn mul(self, multiplicand: &FieldElement<F>) -> Polynomial<FieldElement<F>>
fn mul(self, multiplicand: &FieldElement<F>) -> Polynomial<FieldElement<F>>
*
operation. Read moresource§impl<F> Mul<&FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Mul<&FieldElement<F>> for FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
*
operator.source§impl<F: IsField> Mul<&FieldElement<F>> for Polynomial<FieldElement<F>>
impl<F: IsField> Mul<&FieldElement<F>> for Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
*
operator.source§fn mul(self, multiplicand: &FieldElement<F>) -> Polynomial<FieldElement<F>>
fn mul(self, multiplicand: &FieldElement<F>) -> Polynomial<FieldElement<F>>
*
operation. Read moresource§impl<F: IsField> Mul<&Polynomial<FieldElement<F>>> for &FieldElement<F>
impl<F: IsField> Mul<&Polynomial<FieldElement<F>>> for &FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
*
operator.source§fn mul(
self,
multiplicand: &Polynomial<FieldElement<F>>
) -> Polynomial<FieldElement<F>>
fn mul( self, multiplicand: &Polynomial<FieldElement<F>> ) -> Polynomial<FieldElement<F>>
*
operation. Read moresource§impl<F: IsField> Mul<&Polynomial<FieldElement<F>>> for FieldElement<F>
impl<F: IsField> Mul<&Polynomial<FieldElement<F>>> for FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
*
operator.source§fn mul(
self,
multiplicand: &Polynomial<FieldElement<F>>
) -> Polynomial<FieldElement<F>>
fn mul( self, multiplicand: &Polynomial<FieldElement<F>> ) -> Polynomial<FieldElement<F>>
*
operation. Read moresource§impl<F> Mul<FieldElement<F>> for &FieldElement<F>where
F: IsField,
impl<F> Mul<FieldElement<F>> for &FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
*
operator.source§impl<F: IsField> Mul<FieldElement<F>> for &Polynomial<FieldElement<F>>
impl<F: IsField> Mul<FieldElement<F>> for &Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
*
operator.source§fn mul(self, multiplicand: FieldElement<F>) -> Polynomial<FieldElement<F>>
fn mul(self, multiplicand: FieldElement<F>) -> Polynomial<FieldElement<F>>
*
operation. Read moresource§impl<F> Mul<FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Mul<FieldElement<F>> for FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
*
operator.source§impl<F: IsField> Mul<FieldElement<F>> for Polynomial<FieldElement<F>>
impl<F: IsField> Mul<FieldElement<F>> for Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
*
operator.source§fn mul(self, multiplicand: FieldElement<F>) -> Polynomial<FieldElement<F>>
fn mul(self, multiplicand: FieldElement<F>) -> Polynomial<FieldElement<F>>
*
operation. Read moresource§impl<F: IsField> Mul<Polynomial<FieldElement<F>>> for &FieldElement<F>
impl<F: IsField> Mul<Polynomial<FieldElement<F>>> for &FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
*
operator.source§fn mul(
self,
multiplicand: Polynomial<FieldElement<F>>
) -> Polynomial<FieldElement<F>>
fn mul( self, multiplicand: Polynomial<FieldElement<F>> ) -> Polynomial<FieldElement<F>>
*
operation. Read moresource§impl<F: IsField> Mul<Polynomial<FieldElement<F>>> for FieldElement<F>
impl<F: IsField> Mul<Polynomial<FieldElement<F>>> for FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
*
operator.source§fn mul(
self,
multiplicand: Polynomial<FieldElement<F>>
) -> Polynomial<FieldElement<F>>
fn mul( self, multiplicand: Polynomial<FieldElement<F>> ) -> Polynomial<FieldElement<F>>
*
operation. Read moresource§impl<F> Neg for &FieldElement<F>where
F: IsField,
impl<F> Neg for &FieldElement<F>where F: IsField,
Negation operator overloading for field elements*/
source§impl<F> Neg for FieldElement<F>where
F: IsField,
impl<F> Neg for FieldElement<F>where F: IsField,
source§impl<F> PartialEq<FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> PartialEq<FieldElement<F>> for FieldElement<F>where F: IsField,
Equality operator overloading for field elements
source§fn eq(&self, other: &FieldElement<F>) -> bool
fn eq(&self, other: &FieldElement<F>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<const MODULUS: u64> Serializable for FieldElement<U64PrimeField<MODULUS>>
impl<const MODULUS: u64> Serializable for FieldElement<U64PrimeField<MODULUS>>
source§impl<F> Sub<&FieldElement<F>> for &FieldElement<F>where
F: IsField,
impl<F> Sub<&FieldElement<F>> for &FieldElement<F>where F: IsField,
Subtraction operator overloading for field elements*/
§type Output = FieldElement<F>
type Output = FieldElement<F>
-
operator.source§impl<F: IsField> Sub<&FieldElement<F>> for &Polynomial<FieldElement<F>>
impl<F: IsField> Sub<&FieldElement<F>> for &Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
-
operator.source§fn sub(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>
fn sub(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>
-
operation. Read moresource§impl<F> Sub<&FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Sub<&FieldElement<F>> for FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
-
operator.source§impl<F: IsField> Sub<&FieldElement<F>> for Polynomial<FieldElement<F>>
impl<F: IsField> Sub<&FieldElement<F>> for Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
-
operator.source§fn sub(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>
fn sub(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>
-
operation. Read moresource§impl<F: IsField> Sub<&Polynomial<FieldElement<F>>> for &FieldElement<F>
impl<F: IsField> Sub<&Polynomial<FieldElement<F>>> for &FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
-
operator.source§fn sub(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
fn sub(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
-
operation. Read moresource§impl<F: IsField> Sub<&Polynomial<FieldElement<F>>> for FieldElement<F>
impl<F: IsField> Sub<&Polynomial<FieldElement<F>>> for FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
-
operator.source§fn sub(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
fn sub(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
-
operation. Read moresource§impl<F> Sub<FieldElement<F>> for &FieldElement<F>where
F: IsField,
impl<F> Sub<FieldElement<F>> for &FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
-
operator.source§impl<F: IsField> Sub<FieldElement<F>> for &Polynomial<FieldElement<F>>
impl<F: IsField> Sub<FieldElement<F>> for &Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
-
operator.source§fn sub(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>
fn sub(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>
-
operation. Read moresource§impl<F> Sub<FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Sub<FieldElement<F>> for FieldElement<F>where F: IsField,
§type Output = FieldElement<F>
type Output = FieldElement<F>
-
operator.source§impl<F: IsField> Sub<FieldElement<F>> for Polynomial<FieldElement<F>>
impl<F: IsField> Sub<FieldElement<F>> for Polynomial<FieldElement<F>>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
-
operator.source§fn sub(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>
fn sub(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>
-
operation. Read moresource§impl<F: IsField> Sub<Polynomial<FieldElement<F>>> for &FieldElement<F>
impl<F: IsField> Sub<Polynomial<FieldElement<F>>> for &FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
-
operator.source§fn sub(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
fn sub(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
-
operation. Read moresource§impl<F: IsField> Sub<Polynomial<FieldElement<F>>> for FieldElement<F>
impl<F: IsField> Sub<Polynomial<FieldElement<F>>> for FieldElement<F>
§type Output = Polynomial<FieldElement<F>>
type Output = Polynomial<FieldElement<F>>
-
operator.source§fn sub(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
fn sub(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>
-
operation. Read moresource§impl<F> Sum<FieldElement<F>> for FieldElement<F>where
F: IsField,
impl<F> Sum<FieldElement<F>> for FieldElement<F>where F: IsField,
Sum operator for field elements