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>
impl<const N: usize, E: FieldScalar> Polynomial<N, E>
pub fn to_eval_form(&mut self)
pub fn to_coef_form(&mut self)
pub fn into_eval_form(self) -> Self
pub fn into_coef_form(self) -> Self
Sourcepub fn batch_mul(self, rhs: Vector<Self>) -> Vector<Self>
pub fn batch_mul(self, rhs: Vector<Self>) -> Vector<Self>
Multiply a single polynomial by a vector of polynomials.
Sourcepub fn split_root(root: E) -> Result<Self>
pub fn split_root(root: E) -> Result<Self>
Retrieve the product of monomial factors split by the provided root of unity.
pub fn coefs_slice_mut(&mut self) -> &mut [E; N]
Sourcepub fn coefs(&self) -> impl Iterator<Item = E> + ExactSizeIterator + Clone
pub fn coefs(&self) -> impl Iterator<Item = E> + ExactSizeIterator + Clone
Get an iterator over all coefficients.
TODO: coefs_nonzero ?
Sourcepub fn coefs_mut(&mut self) -> impl Iterator<Item = &mut E> + ExactSizeIterator
pub fn coefs_mut(&mut self) -> impl Iterator<Item = &mut E> + ExactSizeIterator
Get a mutable iterator over all coefficients.
Sourcepub fn norm_l2(&self) -> f64
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 ...)
Sourcepub fn sample_gaussian<R: Rng>(sigma: f64, rng: &mut R) -> Self
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>
impl<const N: usize, E: FieldScalar> Add for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> AddAssign for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> AddAssign for Polynomial<N, E>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<const N: usize, E: Clone + FieldScalar> Clone for Polynomial<N, E>
impl<const N: usize, E: Clone + FieldScalar> Clone for Polynomial<N, E>
Source§fn clone(&self) -> Polynomial<N, E>
fn clone(&self) -> Polynomial<N, E>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const N: usize, E: Debug + FieldScalar> Debug for Polynomial<N, E>
impl<const N: usize, E: Debug + FieldScalar> Debug for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> Default for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> Default for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> Display for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> Display for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> From<&Vector<E>> for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> From<&Vector<E>> for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> From<[E; N]> for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> From<[E; N]> for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> From<E> for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> From<E> for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> From<u128> for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> From<u128> for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> Into<u128> for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> Into<u128> for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> Mul<E> for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> Mul<E> for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> Mul for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> Mul for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> MulAssign<E> for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> MulAssign<E> for Polynomial<N, E>
Source§fn mul_assign(&mut self, rhs: E)
fn mul_assign(&mut self, rhs: E)
*= operation. Read moreSource§impl<const N: usize, E: FieldScalar> MulAssign for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> MulAssign for Polynomial<N, E>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl<const N: usize, E: PartialEq + FieldScalar> PartialEq for Polynomial<N, E>
impl<const N: usize, E: PartialEq + FieldScalar> PartialEq for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> Product for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> Product for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> RingElement for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> RingElement for Polynomial<N, E>
Source§fn sample_uniform<R: Rng>(rng: &mut R) -> Self
fn sample_uniform<R: Rng>(rng: &mut R) -> Self
Uniform randomly sample an element from the ring provided an RNG source.
const CARDINALITY: u128
fn as_le_bytes(&self) -> Vec<u8> ⓘ
const Q: u128 = Self::CARDINALITY
Source§impl<const N: usize, E: FieldScalar> Sub for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> Sub for Polynomial<N, E>
Source§impl<const N: usize, E: FieldScalar> SubAssign for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> SubAssign for Polynomial<N, E>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl<const N: usize, E: FieldScalar> Sum for Polynomial<N, E>
impl<const N: usize, E: FieldScalar> Sum for Polynomial<N, E>
impl<const N: usize, E: Copy + FieldScalar> Copy for Polynomial<N, E>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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