pub struct Poly<C>(/* private fields */);
Expand description
A polynomial that is using a scalar for the variable x and a generic element for the coefficients.
The coefficients must be able to multiply the type of the variable, which is always a scalar.
Implementations§
Source§impl<C: Element> Poly<C>
impl<C: Element> Poly<C>
Sourcepub fn commit(commits: Poly<Scalar>) -> Self
pub fn commit(commits: Poly<Scalar>) -> Self
Commits the scalar polynomial to the group and returns a polynomial over the group.
This is done by multiplying each coefficient of the polynomial with the group’s generator.
Sourcepub fn get(&self, i: u32) -> C
pub fn get(&self, i: u32) -> C
Returns the given coefficient at the requested index.
It panics if the index is out of range.
Sourcepub fn set(&mut self, index: u32, value: C)
pub fn set(&mut self, index: u32, value: C)
Set the given element at the specified index.
It panics if the index is out of range.
Sourcepub fn evaluate(&self, index: u32) -> Eval<C>
pub fn evaluate(&self, index: u32) -> Eval<C>
Evaluates the polynomial at the specified index (provided value offset by 1).
Sourcepub fn recover_with_weights<'a, I>(
weights: &BTreeMap<u32, Weight>,
evals: I,
) -> Result<C, Error>where
C: 'a,
I: IntoIterator<Item = &'a Eval<C>>,
pub fn recover_with_weights<'a, I>(
weights: &BTreeMap<u32, Weight>,
evals: I,
) -> Result<C, Error>where
C: 'a,
I: IntoIterator<Item = &'a Eval<C>>,
Recovers the constant term of a polynomial of degree less than t
using t
evaluations of the polynomial
and precomputed Barycentric Weights.
This function uses Lagrange interpolation to compute the constant term (i.e., the value of the polynomial at x=0
)
given at least t
distinct evaluations of the polynomial. Each evaluation is assumed to have a unique index,
which is mapped to a unique x-value as x = index + 1
.
§References
This implementation is based on J.-P. Berrut and L. N. Trefethen, “Barycentric Lagrange Interpolation,” SIAM Rev., vol. 46, no. 3, pp. 501–517, 2004.
§Warning
This function assumes that each evaluation has a unique index. If there are duplicate indices, the function may fail with an error when attempting to compute the inverse of zero.
Sourcepub fn recover<'a, I>(t: u32, evals: I) -> Result<C, Error>where
C: 'a,
I: IntoIterator<Item = &'a Eval<C>>,
pub fn recover<'a, I>(t: u32, evals: I) -> Result<C, Error>where
C: 'a,
I: IntoIterator<Item = &'a Eval<C>>,
Recovers the constant term of a polynomial of degree less than t
using at least t
evaluations of
the polynomial.
This function uses Lagrange interpolation to compute the constant term (i.e., the value of the polynomial at x=0
)
given at least t
distinct evaluations of the polynomial. Each evaluation is assumed to have a unique index,
which is mapped to a unique x-value as x = index + 1
.
§References
This implementation is based on J.-P. Berrut and L. N. Trefethen, “Barycentric Lagrange Interpolation,” SIAM Rev., vol. 46, no. 3, pp. 501–517, 2004.
§Warning
This function assumes that each evaluation has a unique index. If there are duplicate indices, the function may fail with an error when attempting to compute the inverse of zero.
Trait Implementations§
Source§impl<C: Element> EncodeSize for Poly<C>
impl<C: Element> EncodeSize for Poly<C>
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Source§impl<C: Element> Read for Poly<C>
impl<C: Element> Read for Poly<C>
impl<C: Eq> Eq for Poly<C>
impl<C> StructuralPartialEq for Poly<C>
Auto Trait Implementations§
impl<C> Freeze for Poly<C>
impl<C> RefUnwindSafe for Poly<C>where
C: RefUnwindSafe,
impl<C> Send for Poly<C>where
C: Send,
impl<C> Sync for Poly<C>where
C: Sync,
impl<C> Unpin for Poly<C>where
C: Unpin,
impl<C> UnwindSafe for Poly<C>where
C: 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> 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