pub struct DenseMultilinearPolynomial<F: IsField>{ /* private fields */ }
Expand description
Represents a multilinear polynomial as a vector of evaluations (FieldElements) in Lagrange basis.
Implementations§
Source§impl<F: IsField> DenseMultilinearPolynomial<F>
impl<F: IsField> DenseMultilinearPolynomial<F>
Sourcepub fn new(evals: Vec<FieldElement<F>>) -> Self
pub fn new(evals: Vec<FieldElement<F>>) -> Self
Constructs a new multilinear polynomial from a collection of evaluations. Pads non-power-of-2 evaluations with zeros.
Sourcepub fn evals(&self) -> &Vec<FieldElement<F>>
pub fn evals(&self) -> &Vec<FieldElement<F>>
Returns a reference to the evaluations vector.
Sourcepub fn evaluate(
&self,
r: Vec<FieldElement<F>>,
) -> Result<FieldElement<F>, MultilinearError>
pub fn evaluate( &self, r: Vec<FieldElement<F>>, ) -> Result<FieldElement<F>, MultilinearError>
Evaluates self
at the point r
(a vector of FieldElements) in O(n) time.
r
must have a value for each variable.
Sourcepub fn evaluate_with(
evals: &[FieldElement<F>],
r: &[FieldElement<F>],
) -> Result<FieldElement<F>, MultilinearError>
pub fn evaluate_with( evals: &[FieldElement<F>], r: &[FieldElement<F>], ) -> Result<FieldElement<F>, MultilinearError>
Evaluates a slice of evaluations with the given point r
.
Sourcepub fn fix_last_variable(
&self,
r: &FieldElement<F>,
) -> DenseMultilinearPolynomial<F>
pub fn fix_last_variable( &self, r: &FieldElement<F>, ) -> DenseMultilinearPolynomial<F>
Fixes the last variable to the given value r
and returns a new DenseMultilinearPolynomial
with one fewer variable.
Evaluations are ordered so that the first half corresponds to the last variable = 0,
and the second half corresponds to the last variable = 1.
Combines each pair of evaluations as: new_eval = a + r * (b - a) This reduces the polynomial by one variable, allowing it to later be collapsed into a univariate polynomial by summing over the remaining variables.
Example (2 variables): evaluations ordered as:
[f(0,0), f(0,1), f(1,0), f(1,1)]
Fixing the second variable y = r
produces evaluations of a 1-variable polynomial:
[f(0,r), f(1,r)]
computed explicitly as:
f(0,r) = f(0,0) + r*(f(0,1)-f(0,0)),
f(1,r) = f(1,0) + r*(f(1,1)-f(1,0))
Sourcepub fn to_evaluations(&self) -> Vec<FieldElement<F>>
pub fn to_evaluations(&self) -> Vec<FieldElement<F>>
Returns the evaluations of the polynomial on the Boolean hypercube ({0,1}^n). Since we are in Lagrange basis, this is just the elements stored in self.evals.
Sourcepub fn to_univariate(&self) -> Polynomial<FieldElement<F>>
pub fn to_univariate(&self) -> Polynomial<FieldElement<F>>
Collapses the last variable by fixing it to 0 and 1, sums the evaluations, and returns a univariate polynomial (as a Polynomial) of the form: sum0 + (sum1 - sum0) * x.
Sourcepub fn scalar_mul(&self, scalar: &FieldElement<F>) -> Self
pub fn scalar_mul(&self, scalar: &FieldElement<F>) -> Self
Multiplies the polynomial by a scalar.
Sourcepub fn extend(&mut self, other: &DenseMultilinearPolynomial<F>)
pub fn extend(&mut self, other: &DenseMultilinearPolynomial<F>)
Extends this DenseMultilinearPolynomial by concatenating another polynomial of the same length.
Sourcepub fn merge(
polys: &[DenseMultilinearPolynomial<F>],
) -> DenseMultilinearPolynomial<F>
pub fn merge( polys: &[DenseMultilinearPolynomial<F>], ) -> DenseMultilinearPolynomial<F>
Merges a series of DenseMultilinearPolynomials into one polynomial. Zero-pads the final merged polynomial to the next power-of-two length if necessary.
Trait Implementations§
Source§impl<F: IsField> Add for DenseMultilinearPolynomial<F>
Adds two DenseMultilinearPolynomials.
Assumes that both polynomials have the same number of variables.
impl<F: IsField> Add for DenseMultilinearPolynomial<F>
Adds two DenseMultilinearPolynomials. Assumes that both polynomials have the same number of variables.
Source§impl<F: Clone + IsField> Clone for DenseMultilinearPolynomial<F>
impl<F: Clone + IsField> Clone for DenseMultilinearPolynomial<F>
Source§fn clone(&self) -> DenseMultilinearPolynomial<F>
fn clone(&self) -> DenseMultilinearPolynomial<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<F: IsField> From<(usize, Vec<FieldElement<F>>)> for DenseMultilinearPolynomial<F>
impl<F: IsField> From<(usize, Vec<FieldElement<F>>)> for DenseMultilinearPolynomial<F>
Source§impl<F: IsField> Index<usize> for DenseMultilinearPolynomial<F>
impl<F: IsField> Index<usize> for DenseMultilinearPolynomial<F>
Source§type Output = FieldElement<F>
type Output = FieldElement<F>
Source§impl<F: IsField> Mul<&FieldElement<F>> for DenseMultilinearPolynomial<F>
impl<F: IsField> Mul<&FieldElement<F>> for DenseMultilinearPolynomial<F>
Source§type Output = DenseMultilinearPolynomial<F>
type Output = DenseMultilinearPolynomial<F>
*
operator.Source§impl<F: IsField> Mul<FieldElement<F>> for DenseMultilinearPolynomial<F>
impl<F: IsField> Mul<FieldElement<F>> for DenseMultilinearPolynomial<F>
Source§type Output = DenseMultilinearPolynomial<F>
type Output = DenseMultilinearPolynomial<F>
*
operator.Source§impl<F: PartialEq + IsField> PartialEq for DenseMultilinearPolynomial<F>
impl<F: PartialEq + IsField> PartialEq for DenseMultilinearPolynomial<F>
Source§fn eq(&self, other: &DenseMultilinearPolynomial<F>) -> bool
fn eq(&self, other: &DenseMultilinearPolynomial<F>) -> bool
self
and other
values to be equal, and is used by ==
.impl<F: IsField> StructuralPartialEq for DenseMultilinearPolynomial<F>
Auto Trait Implementations§
impl<F> Freeze for DenseMultilinearPolynomial<F>
impl<F> RefUnwindSafe for DenseMultilinearPolynomial<F>
impl<F> Send for DenseMultilinearPolynomial<F>
impl<F> Sync for DenseMultilinearPolynomial<F>
impl<F> Unpin for DenseMultilinearPolynomial<F>
impl<F> UnwindSafe for DenseMultilinearPolynomial<F>
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