Struct DenseMultilinearPolynomial

Source
pub struct DenseMultilinearPolynomial<F: IsField>
where <F as IsField>::BaseType: Send + Sync,
{ /* private fields */ }
Expand description

Represents a multilinear polynomial as a vector of evaluations (FieldElements) in Lagrange basis.

Implementations§

Source§

impl<F: IsField> DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Source

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.

Source

pub fn num_vars(&self) -> usize

Returns the number of variables.

Source

pub fn evals(&self) -> &Vec<FieldElement<F>>

Returns a reference to the evaluations vector.

Source

pub fn len(&self) -> usize

Returns the total number of evaluations (2^num_vars).

Source

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.

Source

pub fn evaluate_with( evals: &[FieldElement<F>], r: &[FieldElement<F>], ) -> Result<FieldElement<F>, MultilinearError>

Evaluates a slice of evaluations with the given point r.

Source

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))

Source

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.

Source

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.

Source

pub fn scalar_mul(&self, scalar: &FieldElement<F>) -> Self

Multiplies the polynomial by a scalar.

Source

pub fn extend(&mut self, other: &DenseMultilinearPolynomial<F>)

Extends this DenseMultilinearPolynomial by concatenating another polynomial of the same length.

Source

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.

Source

pub fn from_u64(evals: &[u64]) -> Self

Constructs a DenseMultilinearPolynomial from a slice of u64 values.

Trait Implementations§

Source§

impl<F: IsField> Add for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Adds two DenseMultilinearPolynomials. Assumes that both polynomials have the same number of variables.

Source§

type Output = Result<DenseMultilinearPolynomial<F>, &'static str>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<F: Clone + IsField> Clone for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Source§

fn clone(&self) -> DenseMultilinearPolynomial<F>

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<F: Debug + IsField> Debug for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Source§

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

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

impl<F: IsField> From<(usize, Vec<FieldElement<F>>)> for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Source§

fn from((num_vars, evaluations): (usize, Vec<FieldElement<F>>)) -> Self

Converts to this type from the input type.
Source§

impl<F: IsField> Index<usize> for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Source§

type Output = FieldElement<F>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &FieldElement<F>

Performs the indexing (container[index]) operation. Read more
Source§

impl<F: IsField> Mul<&FieldElement<F>> for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Source§

type Output = DenseMultilinearPolynomial<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &FieldElement<F>) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: IsField> Mul<FieldElement<F>> for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Source§

type Output = DenseMultilinearPolynomial<F>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<F: PartialEq + IsField> PartialEq for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Source§

fn eq(&self, other: &DenseMultilinearPolynomial<F>) -> 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<F: IsField> StructuralPartialEq for DenseMultilinearPolynomial<F>
where <F as IsField>::BaseType: Send + Sync,

Auto Trait Implementations§

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, 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.