pub struct Poly<K> { /* private fields */ }Expand description
A polynomial, with coefficients in K.
Implementations§
Source§impl<K> Poly<K>
impl<K> Poly<K>
Sourcepub fn degree(&self) -> u32
pub fn degree(&self) -> u32
The degree of this polynomial.
Technically, this is only an upper bound on the degree, because this method does not inspect the coefficients of a polynomial to check if they’re non-zero.
Because of this, it’s possible that two polynomials considered equal have different degrees.
For that behavior, see Self::degree_exact.
Sourcepub fn required(&self) -> NonZeroU32
pub fn required(&self) -> NonZeroU32
Return the number of evaluation points required to recover this polynomial.
In other words, Self::degree + 1.
Sourcepub fn constant(&self) -> &K
pub fn constant(&self) -> &K
Return the constant value of this polynomial.
I.e. the first coefficient.
Sourcepub fn translate<L>(&self, f: impl Fn(&K) -> L) -> Poly<L>
pub fn translate<L>(&self, f: impl Fn(&K) -> L) -> Poly<L>
Translate the coefficients of this polynomial.
This applies some kind of map to each coefficient, creating a new polynomial.
Sourcepub fn eval<R>(&self, r: &R) -> Kwhere
K: Space<R>,
pub fn eval<R>(&self, r: &R) -> Kwhere
K: Space<R>,
Evaluate a polynomial at a particular point.
For
p(X) := a_0 + a_1 X + a_2 X^2 + ...
this returns:
a_0 + a_1 r + a_2 r^2 + ...
This can work for any type which can multiply the coefficients of this polynomial.
For example, if you have a polynomial consistent of elements of a group, you can evaluate it using a scalar over that group.
Sourcepub fn eval_msm<R: Ring>(&self, r: &R) -> Kwhere
K: Space<R>,
pub fn eval_msm<R: Ring>(&self, r: &R) -> Kwhere
K: Space<R>,
Like Self::eval, but using Space::msm.
This method uses more scratch space, and requires cloning values of
type R more, but should be better if Space::msm has a better algorithm
for K.
Source§impl<K: Random> Poly<K>
impl<K: Random> Poly<K>
pub fn new(rng: impl CryptoRngCore, degree: u32) -> Self
Sourcepub fn new_with_constant(
rng: impl CryptoRngCore,
degree: u32,
constant: K,
) -> Self
pub fn new_with_constant( rng: impl CryptoRngCore, degree: u32, constant: K, ) -> Self
Returns a new scalar polynomial with a particular value for the constant coefficient.
This does the same thing as Poly::new otherwise.
Source§impl<K: Additive> Poly<K>
impl<K: Additive> Poly<K>
Sourcepub fn degree_exact(&self) -> u32
pub fn degree_exact(&self) -> u32
Like Self::degree, but checking for zero coefficients.
This method is slower, but reports exact results in case there are zeros.
This will return 0 for a polynomial with no coefficients.
Trait Implementations§
Source§impl<'a, K: Additive> AddAssign<&'a Poly<K>> for Poly<K>
impl<'a, K: Additive> AddAssign<&'a Poly<K>> for Poly<K>
Source§fn add_assign(&mut self, rhs: &'a Poly<K>)
fn add_assign(&mut self, rhs: &'a Poly<K>)
+= operation. Read moreSource§impl<K: EncodeSize> EncodeSize for Poly<K>
impl<K: EncodeSize> EncodeSize for Poly<K>
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Source§impl<'a, R, K: Space<R>> MulAssign<&'a R> for Poly<K>
impl<'a, R, K: Space<R>> MulAssign<&'a R> for Poly<K>
Source§fn mul_assign(&mut self, rhs: &'a R)
fn mul_assign(&mut self, rhs: &'a R)
*= operation. Read moreSource§impl<K: Additive> PartialEq for Poly<K>
An equality test taking into account high 0 coefficients.
impl<K: Additive> PartialEq for Poly<K>
An equality test taking into account high 0 coefficients.
Without this behavior, the additive test suite does not past, because
x - x may result in a polynomial with extra 0 coefficients.
Source§impl<K: Read> Read for Poly<K>
impl<K: Read> Read for Poly<K>
Source§impl<'a, K: Additive> SubAssign<&'a Poly<K>> for Poly<K>
impl<'a, K: Additive> SubAssign<&'a Poly<K>> for Poly<K>
Source§fn sub_assign(&mut self, rhs: &'a Poly<K>)
fn sub_assign(&mut self, rhs: &'a Poly<K>)
-= operation. Read moreimpl<K: Additive> Eq for Poly<K>
impl<K: Additive> Object for Poly<K>
Auto Trait Implementations§
impl<K> Freeze for Poly<K>
impl<K> RefUnwindSafe for Poly<K>where
K: RefUnwindSafe,
impl<K> Send for Poly<K>where
K: Send,
impl<K> Sync for Poly<K>where
K: Sync,
impl<K> Unpin for Poly<K>where
K: Unpin,
impl<K> UnwindSafe for Poly<K>where
K: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> Encode for Twhere
T: Write + EncodeSize,
impl<T> Encode for Twhere
T: Write + EncodeSize,
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