Polynomial

Struct Polynomial 

Source
pub struct Polynomial<F> {
    pub coefficients: Vec<F>,
}
Expand description

Represents a polynomial with coefficients of type F.

Fields§

§coefficients: Vec<F>

Coefficients of the polynomial, ordered from lowest to highest degree.

Implementations§

Source§

impl<F> Polynomial<F>
where F: Clone,

Source

pub fn new(coefficients: Vec<F>) -> Polynomial<F>

Creates a new polynomial from the provided coefficients.

Source§

impl<F> Polynomial<F>
where F: Sub<Output = F> + Mul<Output = F> + AddAssign + Zero + Div<Output = F> + Clone + Inverse,

Source

pub fn hadamard_mul(&self, other: &Polynomial<F>) -> Polynomial<F>

Multiplies two polynomials coefficient-wise (Hadamard multiplication).

Source

pub fn hadamard_div(&self, other: &Polynomial<F>) -> Polynomial<F>

Divides two polynomials coefficient-wise (Hadamard division).

Source

pub fn hadamard_inv(&self) -> Polynomial<F>

Computes the coefficient-wise inverse (Hadamard inverse).

Source§

impl<F> Polynomial<F>
where F: Zero + PartialEq + Clone,

Source

pub fn degree(&self) -> Option<usize>

Returns the degree of the polynomial.

Source

pub fn lc(&self) -> F

Returns the leading coefficient of the polynomial.

Source§

impl<F> Polynomial<F>
where F: Clone + Neg<Output = F> + MulAssign + AddAssign + Div<Output = F> + One + Sub<Output = F> + Zero + PartialEq,

The following implementations are specific to cyclotomic polynomial rings, i.e., F[ X ] / <X^n + 1>, and are used extensively in Falcon.

Source

pub fn reduce_by_cyclotomic(&self, n: usize) -> Polynomial<F>

Reduce the polynomial by X^n + 1.

Source

pub fn field_norm(&self) -> Polynomial<F>

Computes the field norm of the polynomial as an element of the cyclotomic ring F[ X ] / <X^n + 1 > relative to one of half the size, i.e., F[ X ] / <X^(n/2) + 1> .

Corresponds to formula 3.25 in the spec [1, p.30].

Source

pub fn lift_next_cyclotomic(&self) -> Polynomial<F>

Lifts an element from a cyclotomic polynomial ring to one of double the size.

Source

pub fn galois_adjoint(&self) -> Polynomial<F>

Computes the galois adjoint of the polynomial in the cyclotomic ring F[ X ] / < X^n + 1 > , which corresponds to f(x^2).

Source§

impl<F> Polynomial<F>
where F: Sub<Output = F> + Mul<Output = F> + AddAssign + Zero + Div<Output = F> + Clone,

Source

pub fn karatsuba(&self, other: &Polynomial<F>) -> Polynomial<F>

Multiply two polynomials using Karatsuba’s divide-and-conquer algorithm.

Source§

impl<F> Polynomial<F>
where F: Zero + Clone,

Source

pub fn shift(&self, shamt: usize) -> Polynomial<F>

Shifts the polynomial by the specified amount (adds leading zeros).

Source

pub fn constant(f: F) -> Polynomial<F>

Creates a constant polynomial with a single coefficient.

Source

pub fn map<G, C>(&self, closure: C) -> Polynomial<G>
where G: Clone, C: FnMut(&F) -> G,

Applies a function to each coefficient and returns a new polynomial.

Source

pub fn fold<G, C>(&self, initial_value: G, closure: C) -> G
where C: FnMut(G, &F) -> G + Clone,

Folds the coefficients using the provided function and initial value.

Source§

impl Polynomial<FalconFelt>

Source

pub fn norm_squared(&self) -> u64

Computes the squared L2 norm of the polynomial.

Source

pub fn to_elements(&self) -> Vec<BaseElement>

Returns the coefficients of this polynomial as field elements.

Source

pub fn mul_modulo_p( a: &Polynomial<FalconFelt>, b: &Polynomial<FalconFelt>, ) -> [u64; 1024]

Multiplies two polynomials over Z_p[x] without reducing modulo p. Given that the degrees of the input polynomials are less than 512 and their coefficients are less than the modulus q equal to 12289, the resulting product polynomial is guaranteed to have coefficients less than the Miden prime.

Note that this multiplication is not over Z_p[x]/(phi).

Source

pub fn reduce_negacyclic(a: &[u64; 1024]) -> Polynomial<FalconFelt>

Reduces a polynomial, that is the product of two polynomials over Z_p[x], modulo the irreducible polynomial phi. This results in an element in Z_p[x]/(phi).

Source§

impl Polynomial<BaseElement>

Source

pub fn to_elements(&self) -> Vec<BaseElement>

Returns the coefficients of this polynomial as Miden field elements.

Source§

impl Polynomial<i16>

Source

pub fn to_balanced_values(&self) -> Vec<i16>

Returns the balanced values of the coefficients of this polynomial.

Trait Implementations§

Source§

impl<F> Add for &Polynomial<F>
where F: Add<Output = F> + AddAssign + Clone,

Source§

type Output = Polynomial<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Polynomial<F>) -> <&Polynomial<F> as Add>::Output

Performs the + operation. Read more
Source§

impl<F> Add for Polynomial<F>
where F: Add<Output = F> + AddAssign + Clone,

Source§

type Output = Polynomial<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Polynomial<F>) -> <Polynomial<F> as Add>::Output

Performs the + operation. Read more
Source§

impl<F> AddAssign for Polynomial<F>
where F: Add<Output = F> + AddAssign + Clone,

Source§

fn add_assign(&mut self, rhs: Polynomial<F>)

Performs the += operation. Read more
Source§

impl<F> Clone for Polynomial<F>
where F: Clone,

Source§

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

Returns a duplicate 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<F> Debug for Polynomial<F>
where F: Debug,

Source§

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

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

impl<F> Default for Polynomial<F>
where F: Default,

Source§

fn default() -> Polynomial<F>

Returns the “default value” for a type. Read more
Source§

impl<F> Div for Polynomial<F>
where F: AddAssign + Clone + Mul<Output = F> + MulAssign + Div<Output = F> + Zero + Neg<Output = F> + One + Sub<Output = F> + PartialEq,

Source§

type Output = Polynomial<F>

The resulting type after applying the / operator.
Source§

fn div(self, denominator: Polynomial<F>) -> <Polynomial<F> as Div>::Output

Performs the / operation. Read more
Source§

impl From<&Polynomial<FalconFelt>> for Polynomial<BaseElement>

Source§

fn from(item: &Polynomial<FalconFelt>) -> Polynomial<BaseElement>

Converts to this type from the input type.
Source§

impl From<&Polynomial<i16>> for Polynomial<FalconFelt>

Source§

fn from(item: &Polynomial<i16>) -> Polynomial<FalconFelt>

Converts to this type from the input type.
Source§

impl From<&Vec<i16>> for Polynomial<FalconFelt>

Source§

fn from(item: &Vec<i16>) -> Polynomial<FalconFelt>

Converts to this type from the input type.
Source§

impl From<Polynomial<FalconFelt>> for Polynomial<BaseElement>

Source§

fn from(item: Polynomial<FalconFelt>) -> Polynomial<BaseElement>

Converts to this type from the input type.
Source§

impl From<Polynomial<FalconFelt>> for PublicKey

Source§

fn from(pk_poly: Polynomial<FalconFelt>) -> PublicKey

Converts to this type from the input type.
Source§

impl From<Polynomial<FalconFelt>> for SignaturePoly

Source§

fn from(pk_poly: Polynomial<FalconFelt>) -> SignaturePoly

Converts to this type from the input type.
Source§

impl From<Polynomial<i16>> for Polynomial<FalconFelt>

Source§

fn from(item: Polynomial<i16>) -> Polynomial<FalconFelt>

Converts to this type from the input type.
Source§

impl From<Vec<i16>> for Polynomial<FalconFelt>

Source§

fn from(item: Vec<i16>) -> Polynomial<FalconFelt>

Converts to this type from the input type.
Source§

impl<F> Mul<F> for &Polynomial<F>
where F: Add + Mul<Output = F> + Zero + Clone,

Source§

type Output = Polynomial<F>

The resulting type after applying the * operator.
Source§

fn mul(self, other: F) -> <&Polynomial<F> as Mul<F>>::Output

Performs the * operation. Read more
Source§

impl<F> Mul<F> for Polynomial<F>
where F: Add + Mul<Output = F> + Zero + Clone,

Source§

type Output = Polynomial<F>

The resulting type after applying the * operator.
Source§

fn mul(self, other: F) -> <Polynomial<F> as Mul<F>>::Output

Performs the * operation. Read more
Source§

impl<F> Mul for &Polynomial<F>
where F: AddAssign + Mul<Output = F> + Sub<Output = F> + Add + Zero + PartialEq + Clone,

Source§

type Output = Polynomial<F>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Polynomial<F>) -> <&Polynomial<F> as Mul>::Output

Performs the * operation. Read more
Source§

impl<F> Mul for Polynomial<F>
where F: Add + AddAssign + Mul<Output = F> + Zero + PartialEq + Clone,

Source§

type Output = Polynomial<F>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Polynomial<F>) -> <Polynomial<F> as Mul>::Output

Performs the * operation. Read more
Source§

impl<F> Neg for &Polynomial<F>
where F: Neg<Output = F> + Clone,

Source§

type Output = Polynomial<F>

The resulting type after applying the - operator.
Source§

fn neg(self) -> <&Polynomial<F> as Neg>::Output

Performs the unary - operation. Read more
Source§

impl<F> Neg for Polynomial<F>
where F: Neg<Output = F> + Clone,

Source§

type Output = Polynomial<F>

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Polynomial<F> as Neg>::Output

Performs the unary - operation. Read more
Source§

impl<F> One for Polynomial<F>
where F: Clone + One + PartialEq + Zero + AddAssign,

Source§

fn one() -> Polynomial<F>

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<F> PartialEq for Polynomial<F>
where F: Zero + PartialEq + Clone + AddAssign,

Source§

fn eq(&self, other: &Polynomial<F>) -> 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> Sub for &Polynomial<F>
where F: Clone + Neg<Output = F> + Sub<Output = F> + Add<Output = F> + AddAssign,

Source§

type Output = Polynomial<F>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Polynomial<F>) -> <&Polynomial<F> as Sub>::Output

Performs the - operation. Read more
Source§

impl<F> Sub for Polynomial<F>
where F: Clone + Neg<Output = F> + Sub<Output = F> + Add<Output = F> + AddAssign,

Source§

type Output = Polynomial<F>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Polynomial<F>) -> <Polynomial<F> as Sub>::Output

Performs the - operation. Read more
Source§

impl<F> SubAssign for Polynomial<F>
where F: Neg<Output = F> + Add<Output = F> + AddAssign + Clone + Sub<Output = F>,

Source§

fn sub_assign(&mut self, rhs: Polynomial<F>)

Performs the -= operation. Read more
Source§

impl<F> Zero for Polynomial<F>
where F: Zero + PartialEq + Clone + AddAssign,

Source§

fn zero() -> Polynomial<F>

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<F> Zeroize for Polynomial<F>
where F: Zeroize,

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<F> Eq for Polynomial<F>
where F: Zero + PartialEq + Clone + AddAssign,

Source§

impl<F> ZeroizeOnDrop for Polynomial<F>
where F: Zeroize,

Auto Trait Implementations§

§

impl<F> Freeze for Polynomial<F>

§

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

§

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

§

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

§

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

§

impl<F> UnwindSafe for Polynomial<F>
where F: 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, Rhs, Output> GroupOps<Rhs, Output> for T
where T: Add<Rhs, Output = Output> + Sub<Rhs, Output = Output> + AddAssign<Rhs> + SubAssign<Rhs>,