Struct lambdaworks_math::polynomial::Polynomial

source ·
pub struct Polynomial<FE> {
    pub coefficients: Vec<FE>,
}
Expand description

Represents the polynomial c_0 + c_1 * X + c_2 * X^2 + … + c_n * X^n as a vector of coefficients [c_0, c_1, ... , c_n]

Fields§

§coefficients: Vec<FE>

Implementations§

source§

impl<E: IsField> Polynomial<FieldElement<E>>

source

pub fn evaluate_fft<F: IsFFTField + IsSubFieldOf<E>>( poly: &Polynomial<FieldElement<E>>, blowup_factor: usize, domain_size: Option<usize>, ) -> Result<Vec<FieldElement<E>>, FFTError>

Returns N evaluations of this polynomial using FFT over a domain in a subfield F of E (so the results are P(w^i), with w being a primitive root of unity). N = max(self.coeff_len(), domain_size).next_power_of_two() * blowup_factor. If domain_size is None, it defaults to 0.

source

pub fn evaluate_offset_fft<F: IsFFTField + IsSubFieldOf<E>>( poly: &Polynomial<FieldElement<E>>, blowup_factor: usize, domain_size: Option<usize>, offset: &FieldElement<F>, ) -> Result<Vec<FieldElement<E>>, FFTError>

Returns N evaluations with an offset of this polynomial using FFT over a domain in a subfield F of E (so the results are P(w^i), with w being a primitive root of unity). N = max(self.coeff_len(), domain_size).next_power_of_two() * blowup_factor. If domain_size is None, it defaults to 0.

source

pub fn interpolate_fft<F: IsFFTField + IsSubFieldOf<E>>( fft_evals: &[FieldElement<E>], ) -> Result<Self, FFTError>

Returns a new polynomial that interpolates (w^i, fft_evals[i]), with w being a Nth primitive root of unity in a subfield F of E, and i in 0..N, with N = fft_evals.len(). This is considered to be the inverse operation of Self::evaluate_fft().

source

pub fn interpolate_offset_fft<F: IsFFTField + IsSubFieldOf<E>>( fft_evals: &[FieldElement<E>], offset: &FieldElement<F>, ) -> Result<Polynomial<FieldElement<E>>, FFTError>

Returns a new polynomial that interpolates offset (w^i, fft_evals[i]), with w being a Nth primitive root of unity in a subfield F of E, and i in 0..N, with N = fft_evals.len(). This is considered to be the inverse operation of Self::evaluate_offset_fft().

source§

impl<F: IsField> Polynomial<FieldElement<F>>

source

pub fn new(coefficients: &[FieldElement<F>]) -> Self

Creates a new polynomial with the given coefficients

source

pub fn new_monomial(coefficient: FieldElement<F>, degree: usize) -> Self

source

pub fn zero() -> Self

source

pub fn interpolate( xs: &[FieldElement<F>], ys: &[FieldElement<F>], ) -> Result<Self, InterpolateError>

Returns a polynomial that interpolates the points with x coordinates and y coordinates given by xs and ys. xs and ys must be the same length, and xs values should be unique. If not, panics.

source

pub fn evaluate<E>(&self, x: &FieldElement<E>) -> FieldElement<E>
where E: IsField, F: IsSubFieldOf<E>,

source

pub fn evaluate_slice(&self, input: &[FieldElement<F>]) -> Vec<FieldElement<F>>

source

pub fn degree(&self) -> usize

source

pub fn leading_coefficient(&self) -> FieldElement<F>

source

pub fn coefficients(&self) -> &[FieldElement<F>]

Returns coefficients of the polynomial as an array [c_0, c_1, c_2, …, c_n] that represents the polynomial c_0 + c_1 * X + c_2 * X^2 + … + c_n * X^n

source

pub fn coeff_len(&self) -> usize

source

pub fn ruffini_division_inplace(&mut self, b: &FieldElement<F>)

Computes quotient with x - b in place.

source

pub fn ruffini_division<L>( &self, b: &FieldElement<L>, ) -> Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source

pub fn long_division_with_remainder(self, dividend: &Self) -> (Self, Self)

Computes quotient and remainder of polynomial division.

Output: (quotient, remainder)

source

pub fn div_with_ref(self, dividend: &Self) -> Self

source

pub fn mul_with_ref(&self, factor: &Self) -> Self

source

pub fn scale<S: IsSubFieldOf<F>>(&self, factor: &FieldElement<S>) -> Self

source

pub fn scale_coeffs(&self, factor: &FieldElement<F>) -> Self

source

pub fn break_in_parts(&self, number_of_parts: usize) -> Vec<Self>

Returns a vector of polynomials [p₀, p₁, …, p_{d-1}], where d is number_of_parts, such that self equals p₀(Xᵈ) + Xp₁(Xᵈ) + … + X^(d-1)p_{d-1}(Xᵈ).

Example: if d = 2 and self is 3 X^3 + X^2 + 2X + 1, then poly.break_in_parts(2) returns a vector with two polynomials (p₀, p₁), where p₀ = X + 1 and p₁ = 3X + 2.

source

pub fn to_extension<L: IsField>(self) -> Polynomial<FieldElement<L>>
where F: IsSubFieldOf<L>,

Trait Implementations§

source§

impl<F, L> Add<&FieldElement<F>> for &Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, other: &FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<&FieldElement<F>> for Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, other: &FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<&Polynomial<FieldElement<L>>> for &FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, other: &Polynomial<FieldElement<L>>) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<&Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, a_polynomial: &Polynomial<FieldElement<L>>) -> Self::Output

Performs the + operation. Read more
source§

impl<F, L> Add<&Polynomial<FieldElement<L>>> for FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, other: &Polynomial<FieldElement<L>>) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<&Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add( self, a_polynomial: &Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<FieldElement<F>> for &Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, other: FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<FieldElement<F>> for Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, other: FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<Polynomial<FieldElement<L>>> for &FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, other: Polynomial<FieldElement<L>>) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add( self, a_polynomial: Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<Polynomial<FieldElement<L>>> for FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add(self, other: Polynomial<FieldElement<L>>) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<F, L> Add<Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the + operator.
source§

fn add( self, a_polynomial: Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the + operation. Read more
source§

impl<FE: Clone> Clone for Polynomial<FE>

source§

fn clone(&self) -> Polynomial<FE>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<FE: Debug> Debug for Polynomial<FE>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<F> Div for Polynomial<FieldElement<F>>
where F: IsField,

source§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the / operator.
source§

fn div( self, dividend: Polynomial<FieldElement<F>>, ) -> Polynomial<FieldElement<F>>

Performs the / operation. Read more
source§

impl<F, L> Mul<&FieldElement<F>> for &Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the * operator.
source§

fn mul(self, multiplicand: &FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the * operation. Read more
source§

impl<F, L> Mul<&FieldElement<F>> for Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the * operator.
source§

fn mul(self, multiplicand: &FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the * operation. Read more
source§

impl<F: IsField> Mul<&Polynomial<FieldElement<F>>> for &Polynomial<FieldElement<F>>

source§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul( self, factor: &Polynomial<FieldElement<F>>, ) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F: IsField> Mul<&Polynomial<FieldElement<F>>> for Polynomial<FieldElement<F>>

source§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul( self, factor: &Polynomial<FieldElement<F>>, ) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F, L> Mul<&Polynomial<FieldElement<L>>> for &FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the * operator.
source§

fn mul( self, multiplicand: &Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the * operation. Read more
source§

impl<F, L> Mul<&Polynomial<FieldElement<L>>> for FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the * operator.
source§

fn mul( self, multiplicand: &Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the * operation. Read more
source§

impl<F, L> Mul<FieldElement<F>> for &Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the * operator.
source§

fn mul(self, multiplicand: FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the * operation. Read more
source§

impl<F, L> Mul<FieldElement<F>> for Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the * operator.
source§

fn mul(self, multiplicand: FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the * operation. Read more
source§

impl<F: IsField> Mul<Polynomial<FieldElement<F>>> for &Polynomial<FieldElement<F>>

source§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul(self, factor: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F, L> Mul<Polynomial<FieldElement<L>>> for &FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the * operator.
source§

fn mul( self, multiplicand: Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the * operation. Read more
source§

impl<F, L> Mul<Polynomial<FieldElement<L>>> for FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the * operator.
source§

fn mul( self, multiplicand: Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the * operation. Read more
source§

impl<F: IsField> Mul for Polynomial<FieldElement<F>>

source§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul(self, factor: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F: IsField> Neg for &Polynomial<FieldElement<F>>

source§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn neg(self) -> Polynomial<FieldElement<F>>

Performs the unary - operation. Read more
source§

impl<F: IsField> Neg for Polynomial<FieldElement<F>>

source§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn neg(self) -> Polynomial<FieldElement<F>>

Performs the unary - operation. Read more
source§

impl<FE: PartialEq> PartialEq for Polynomial<FE>

source§

fn eq(&self, other: &Polynomial<FE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<F, L> Sub<&FieldElement<F>> for &Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub(self, other: &FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<&FieldElement<F>> for Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub(self, other: &FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<&Polynomial<FieldElement<L>>> for &FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Polynomial<FieldElement<L>>) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<&Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub( self, substrahend: &Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<&Polynomial<FieldElement<L>>> for FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Polynomial<FieldElement<L>>) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<&Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub( self, substrahend: &Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<FieldElement<F>> for &Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub(self, other: FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<FieldElement<F>> for Polynomial<FieldElement<L>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub(self, other: FieldElement<F>) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<Polynomial<FieldElement<L>>> for &FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub(self, other: Polynomial<FieldElement<L>>) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub( self, substrahend: Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<Polynomial<FieldElement<L>>> for FieldElement<F>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub(self, other: Polynomial<FieldElement<L>>) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<F, L> Sub<Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>
where L: IsField, F: IsSubFieldOf<L>,

source§

type Output = Polynomial<FieldElement<L>>

The resulting type after applying the - operator.
source§

fn sub( self, substrahend: Polynomial<FieldElement<L>>, ) -> Polynomial<FieldElement<L>>

Performs the - operation. Read more
source§

impl<FE: Eq> Eq for Polynomial<FE>

source§

impl<FE> StructuralPartialEq for Polynomial<FE>

Auto Trait Implementations§

§

impl<FE> Freeze for Polynomial<FE>

§

impl<FE> RefUnwindSafe for Polynomial<FE>
where FE: RefUnwindSafe,

§

impl<FE> Send for Polynomial<FE>
where FE: Send,

§

impl<FE> Sync for Polynomial<FE>
where FE: Sync,

§

impl<FE> Unpin for Polynomial<FE>
where FE: Unpin,

§

impl<FE> UnwindSafe for Polynomial<FE>
where FE: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.