pub trait IsField: Debug + Clone {
type BaseType: Clone + Debug + Unpin + ByteConversion + Default;
Show 14 methods
// Required methods
fn add(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType;
fn mul(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType;
fn sub(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType;
fn neg(a: &Self::BaseType) -> Self::BaseType;
fn inv(a: &Self::BaseType) -> Result<Self::BaseType, FieldError>;
fn div(
a: &Self::BaseType,
b: &Self::BaseType,
) -> Result<Self::BaseType, FieldError>;
fn eq(a: &Self::BaseType, b: &Self::BaseType) -> bool;
fn one() -> Self::BaseType;
fn from_u64(x: u64) -> Self::BaseType;
fn from_base_type(x: Self::BaseType) -> Self::BaseType;
// Provided methods
fn double(a: &Self::BaseType) -> Self::BaseType { ... }
fn square(a: &Self::BaseType) -> Self::BaseType { ... }
fn pow<T>(a: &Self::BaseType, exponent: T) -> Self::BaseType
where T: IsUnsignedInteger { ... }
fn zero() -> Self::BaseType { ... }
}
Expand description
Trait to add field behaviour to a struct.
Required Associated Types§
Required Methods§
Sourcefn mul(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType
fn mul(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType
Returns the multiplication of a
and b
.
Sourcefn sub(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType
fn sub(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType
Returns the subtraction of a
and b
.
Sourcefn inv(a: &Self::BaseType) -> Result<Self::BaseType, FieldError>
fn inv(a: &Self::BaseType) -> Result<Self::BaseType, FieldError>
Returns the multiplicative inverse of a
.
Sourcefn div(
a: &Self::BaseType,
b: &Self::BaseType,
) -> Result<Self::BaseType, FieldError>
fn div( a: &Self::BaseType, b: &Self::BaseType, ) -> Result<Self::BaseType, FieldError>
Returns the division of a
and b
.
Sourcefn eq(a: &Self::BaseType, b: &Self::BaseType) -> bool
fn eq(a: &Self::BaseType, b: &Self::BaseType) -> bool
Returns a boolean indicating whether a
and b
are equal or not.
Sourcefn from_u64(x: u64) -> Self::BaseType
fn from_u64(x: u64) -> Self::BaseType
Returns the element x * 1
where 1 is the multiplicative neutral element.
Sourcefn from_base_type(x: Self::BaseType) -> Self::BaseType
fn from_base_type(x: Self::BaseType) -> Self::BaseType
Takes as input an element of BaseType and returns the internal representation of that element in the field.
Provided Methods§
Sourcefn pow<T>(a: &Self::BaseType, exponent: T) -> Self::BaseTypewhere
T: IsUnsignedInteger,
fn pow<T>(a: &Self::BaseType, exponent: T) -> Self::BaseTypewhere
T: IsUnsignedInteger,
Returns the power of a
to the T
, a^T
Uses the square and multiply algorithm, which takes O(log2(T)) steps
This is a non-constant time implementation!
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl IsField for lambdaworks_math::elliptic_curve::short_weierstrass::curves::bls12_377::field_extension::Degree2ExtensionField
impl IsField for lambdaworks_math::elliptic_curve::short_weierstrass::curves::bls12_377::field_extension::Degree2ExtensionField
type BaseType = [FieldElement<MontgomeryBackendPrimeField<BLS12377FieldModulus, 6>>; 2]
Source§impl IsField for lambdaworks_math::elliptic_curve::short_weierstrass::curves::bls12_381::field_extension::Degree2ExtensionField
impl IsField for lambdaworks_math::elliptic_curve::short_weierstrass::curves::bls12_381::field_extension::Degree2ExtensionField
type BaseType = [FieldElement<MontgomeryBackendPrimeField<BLS12381FieldModulus, 6>>; 2]
Source§impl IsField for lambdaworks_math::elliptic_curve::short_weierstrass::curves::bn_254::field_extension::Degree2ExtensionField
impl IsField for lambdaworks_math::elliptic_curve::short_weierstrass::curves::bn_254::field_extension::Degree2ExtensionField
type BaseType = [FieldElement<MontgomeryBackendPrimeField<BN254FieldModulus, 4>>; 2]
Source§impl IsField for Degree4BabyBearU32ExtensionField
We implement directly the degree four extension for performance reasons, instead of using
the default quadratic extension provided by the library
impl IsField for Degree4BabyBearU32ExtensionField
We implement directly the degree four extension for performance reasons, instead of using the default quadratic extension provided by the library