Polynomial

Struct Polynomial 

Source
pub struct Polynomial<const N: usize, E: FieldScalar> { /* private fields */ }
Expand description

Univariate negacyclic polynomial ring (modulus X^N + 1). Accelerated with number theoretic transforms and lazy moves between coefficient and eval representation.

Implementations§

Source§

impl<const N: usize, E: FieldScalar> Polynomial<N, E>

Source

pub fn to_eval_form(&mut self)

Source

pub fn to_coef_form(&mut self)

Source

pub fn into_eval_form(self) -> Self

Source

pub fn into_coef_form(self) -> Self

Source

pub fn evaluate(&self, x: E) -> E

Evaluate the polynomial at a point.

Source

pub fn batch_mul(self, rhs: Vector<Self>) -> Vector<Self>

Multiply a single polynomial by a vector of polynomials.

Source

pub fn split_root(root: E) -> Result<Self>

Retrieve the product of monomial factors split by the provided root of unity.

Source

pub fn coefs_slice_mut(&mut self) -> &mut [E; N]

Source

pub fn coefs(&self) -> impl Iterator<Item = E> + ExactSizeIterator + Clone

Get an iterator over all coefficients.

TODO: coefs_nonzero ?

Source

pub fn coefs_mut(&mut self) -> impl Iterator<Item = &mut E> + ExactSizeIterator

Get a mutable iterator over all coefficients.

Source

pub fn norm_l2(&self) -> f64

The l2 norm of the polynomial. Represents the magnitude.

The distance of each coefficient from zero is squared and then summed. The square root of the sum is returned.

sqrt(x[0]^2 + x[1]^2 + x[2]^2 ...)

Source

pub fn sample_gaussian<R: Rng>(sigma: f64, rng: &mut R) -> Self

Sample a polynomial with coefficients in a gaussian distribution with standard deviation sigma.

Internally uses a statically cached distribution table for each stddev initialized on first call.

Trait Implementations§

Source§

impl<const N: usize, E: FieldScalar> Add for Polynomial<N, E>

Source§

type Output = Polynomial<N, E>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: usize, E: FieldScalar> AddAssign for Polynomial<N, E>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const N: usize, E: Clone + FieldScalar> Clone for Polynomial<N, E>

Source§

fn clone(&self) -> Polynomial<N, E>

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<const N: usize, E: Debug + FieldScalar> Debug for Polynomial<N, E>

Source§

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

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

impl<const N: usize, E: FieldScalar> Default for Polynomial<N, E>

Source§

fn default() -> Self

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

impl<const N: usize, E: FieldScalar> Display for Polynomial<N, E>

Source§

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

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

impl<const N: usize, E: FieldScalar> From<&Vector<E>> for Polynomial<N, E>

Source§

fn from(coefs: &Vector<E>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize, E: FieldScalar> From<[E; N]> for Polynomial<N, E>

Source§

fn from(coefs: [E; N]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize, E: FieldScalar> From<E> for Polynomial<N, E>

Source§

fn from(coef: E) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize, E: FieldScalar> From<u128> for Polynomial<N, E>

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize, E: FieldScalar> Into<u128> for Polynomial<N, E>

Source§

fn into(self) -> u128

Converts this type into the (usually inferred) input type.
Source§

impl<const N: usize, E: FieldScalar> Mul<E> for Polynomial<N, E>

Source§

type Output = Polynomial<N, E>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, E: FieldScalar> Mul for Polynomial<N, E>

Source§

type Output = Polynomial<N, E>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize, E: FieldScalar> MulAssign<E> for Polynomial<N, E>

Source§

fn mul_assign(&mut self, rhs: E)

Performs the *= operation. Read more
Source§

impl<const N: usize, E: FieldScalar> MulAssign for Polynomial<N, E>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<const N: usize, E: PartialEq + FieldScalar> PartialEq for Polynomial<N, E>

Source§

fn eq(&self, other: &Polynomial<N, E>) -> 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<const N: usize, E: FieldScalar> Product for Polynomial<N, E>

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<const N: usize, E: FieldScalar> RingElement for Polynomial<N, E>

Source§

fn sample_uniform<R: Rng>(rng: &mut R) -> Self

Uniform randomly sample an element from the ring provided an RNG source.

Source§

const CARDINALITY: u128

Source§

fn as_le_bytes(&self) -> Vec<u8>

Source§

const Q: u128 = Self::CARDINALITY

Source§

fn is_zero(&self) -> bool

Is the element the additive identity?
Source§

fn one() -> Self

Multiplicative identity.
Source§

fn negone() -> Self

Multiplicatively flips a value in centered representation. Additive inverse of the multiplicative identity. (Negative one)
Source§

fn zero() -> Self

Additive identity.
Source§

impl<const N: usize, E: FieldScalar> Sub for Polynomial<N, E>

Source§

type Output = Polynomial<N, E>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: usize, E: FieldScalar> SubAssign for Polynomial<N, E>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<const N: usize, E: FieldScalar> Sum for Polynomial<N, E>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<const N: usize, E: Copy + FieldScalar> Copy for Polynomial<N, E>

Source§

impl<const N: usize, E: FieldScalar> StructuralPartialEq for Polynomial<N, E>

Auto Trait Implementations§

§

impl<const N: usize, E> Freeze for Polynomial<N, E>
where E: Freeze,

§

impl<const N: usize, E> RefUnwindSafe for Polynomial<N, E>
where E: RefUnwindSafe,

§

impl<const N: usize, E> Send for Polynomial<N, E>

§

impl<const N: usize, E> Sync for Polynomial<N, E>

§

impl<const N: usize, E> Unpin for Polynomial<N, E>
where E: Unpin,

§

impl<const N: usize, E> UnwindSafe for Polynomial<N, E>
where E: 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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