pub struct DenseMultilinearExtension<F: Field> {
pub evaluations: Vec<F>,
pub num_vars: usize,
}
Expand description
Stores a multilinear polynomial in dense evaluation form.
Fields§
§evaluations: Vec<F>
The evaluation over {0,1}^num_vars
num_vars: usize
Number of variables
Implementations§
Source§impl<F: Field> DenseMultilinearExtension<F>
impl<F: Field> DenseMultilinearExtension<F>
Sourcepub fn from_evaluations_slice(num_vars: usize, evaluations: &[F]) -> Self
pub fn from_evaluations_slice(num_vars: usize, evaluations: &[F]) -> Self
Construct a new polynomial from a list of evaluations where the index
represents a point in {0,1}^num_vars
in little endian form. For
example, 0b1011
represents P(1,1,0,1)
Sourcepub fn from_evaluations_vec(num_vars: usize, evaluations: Vec<F>) -> Self
pub fn from_evaluations_vec(num_vars: usize, evaluations: Vec<F>) -> Self
Construct a new polynomial from a list of evaluations where the index
represents a point in {0,1}^num_vars
in little endian form. For
example, 0b1011
represents P(1,1,0,1)
.
§Example
use ark_test_curves::bls12_381::Fr;
use ark_poly::{MultilinearExtension, Polynomial, DenseMultilinearExtension};
// Construct a 2-variate MLE, which takes value 1 at (x_0, x_1) = (0, 1)
// (i.e. 0b01, or index 2 in little endian)
// f1(x_0, x_1) = x_1*(1-x_0)
let mle = DenseMultilinearExtension::from_evaluations_vec(
2, vec![0, 0, 1, 0].iter().map(|x| Fr::from(*x as u64)).collect()
);
let eval = mle.evaluate(&vec![Fr::from(-2), Fr::from(17)]); // point = (x_0, x_1)
assert_eq!(eval, Fr::from(51));
Sourcepub fn relabel_in_place(&mut self, a: usize, b: usize, k: usize)
pub fn relabel_in_place(&mut self, a: usize, b: usize, k: usize)
Relabel the point in place by switching k
scalars from position a
to
position b
, and from position b
to position a
in vector.
This function turns P(x_1,...,x_a,...,x_{a+k - 1},...,x_b,...,x_{b+k - 1},...,x_n)
to P(x_1,...,x_b,...,x_{b+k - 1},...,x_a,...,x_{a+k - 1},...,x_n)
Sourcepub fn iter(&self) -> Iter<'_, F>
pub fn iter(&self) -> Iter<'_, F>
Returns an iterator that iterates over the evaluations over {0,1}^num_vars
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, F>
pub fn iter_mut(&mut self) -> IterMut<'_, F>
Returns a mutable iterator that iterates over the evaluations over {0,1}^num_vars
Sourcepub fn concat(polys: impl IntoIterator<Item = impl AsRef<Self>> + Clone) -> Self
pub fn concat(polys: impl IntoIterator<Item = impl AsRef<Self>> + Clone) -> Self
Concatenate the evaluation tables of multiple polynomials. If the combined table size is not a power of two, pad the table with zeros.
§Example
use ark_test_curves::bls12_381::Fr;
use ark_poly::{MultilinearExtension, Polynomial, DenseMultilinearExtension};
use ark_ff::One;
// Construct a 2-variate multilinear polynomial f1
// f1(x_0, x_1) = 2*(1-x_1)*(1-x_0) + 3*(1-x_1)*x_0 + 2*x_1*(1-x_0) + 6*x_1*x_0
let mle_1 = DenseMultilinearExtension::from_evaluations_vec(
2, vec![2, 3, 2, 6].iter().map(|x| Fr::from(*x as u64)).collect()
);
// Construct another 2-variate MLE f2
// f2(x_0, x_1) = 1*x_1*x_0
let mle_2 = DenseMultilinearExtension::from_evaluations_vec(
2, vec![0, 0, 0, 1].iter().map(|x| Fr::from(*x as u64)).collect()
);
let mle = DenseMultilinearExtension::concat(&[&mle_1, &mle_2]);
// The resulting polynomial is 3-variate:
// f3(x_0, x_1, x_2) = (1 - x_2)*f1(x_0, x_1) + x_2*f2(x_0, x_1)
// Evaluate it at a random point (1, 17, 3)
let point = vec![Fr::one(), Fr::from(17), Fr::from(3)];
let eval_1 = mle_1.evaluate(&point[..2].to_vec());
let eval_2 = mle_2.evaluate(&point[..2].to_vec());
let eval_combined = mle.evaluate(&point);
assert_eq!(eval_combined, (Fr::one() - point[2]) * eval_1 + point[2] * eval_2);
Trait Implementations§
Source§impl<'a, 'b, F: Field> Add<&'a DenseMultilinearExtension<F>> for &'b DenseMultilinearExtension<F>
impl<'a, 'b, F: Field> Add<&'a DenseMultilinearExtension<F>> for &'b DenseMultilinearExtension<F>
Source§type Output = DenseMultilinearExtension<F>
type Output = DenseMultilinearExtension<F>
+
operator.Source§impl<F: Field> Add for DenseMultilinearExtension<F>
impl<F: Field> Add for DenseMultilinearExtension<F>
Source§type Output = DenseMultilinearExtension<F>
type Output = DenseMultilinearExtension<F>
+
operator.Source§fn add(self, other: DenseMultilinearExtension<F>) -> Self
fn add(self, other: DenseMultilinearExtension<F>) -> Self
+
operation. Read moreSource§impl<'a, F: Field> AddAssign<&'a DenseMultilinearExtension<F>> for DenseMultilinearExtension<F>
impl<'a, F: Field> AddAssign<&'a DenseMultilinearExtension<F>> for DenseMultilinearExtension<F>
Source§fn add_assign(&mut self, other: &'a DenseMultilinearExtension<F>)
fn add_assign(&mut self, other: &'a DenseMultilinearExtension<F>)
+=
operation. Read moreSource§impl<'a, F: Field> AddAssign<(F, &'a DenseMultilinearExtension<F>)> for DenseMultilinearExtension<F>
impl<'a, F: Field> AddAssign<(F, &'a DenseMultilinearExtension<F>)> for DenseMultilinearExtension<F>
Source§fn add_assign(&mut self, (f, other): (F, &'a DenseMultilinearExtension<F>))
fn add_assign(&mut self, (f, other): (F, &'a DenseMultilinearExtension<F>))
+=
operation. Read moreSource§impl<F: Field> AddAssign for DenseMultilinearExtension<F>
impl<F: Field> AddAssign for DenseMultilinearExtension<F>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moreSource§impl<F: Field> AsRef<DenseMultilinearExtension<F>> for DenseMultilinearExtension<F>
impl<F: Field> AsRef<DenseMultilinearExtension<F>> for DenseMultilinearExtension<F>
Source§fn as_ref(&self) -> &DenseMultilinearExtension<F>
fn as_ref(&self) -> &DenseMultilinearExtension<F>
Source§impl<F: Field> CanonicalDeserialize for DenseMultilinearExtension<F>
impl<F: Field> CanonicalDeserialize for DenseMultilinearExtension<F>
Source§fn deserialize_with_mode<R: Read>(
reader: R,
compress: Compress,
validate: Validate,
) -> Result<Self, SerializationError>
fn deserialize_with_mode<R: Read>( reader: R, compress: Compress, validate: Validate, ) -> Result<Self, SerializationError>
fn deserialize_compressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_compressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_uncompressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_uncompressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
Source§impl<F: Field> CanonicalSerialize for DenseMultilinearExtension<F>
impl<F: Field> CanonicalSerialize for DenseMultilinearExtension<F>
Source§fn serialize_with_mode<W: Write>(
&self,
writer: W,
compress: Compress,
) -> Result<(), SerializationError>
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress, ) -> Result<(), SerializationError>
fn serialized_size(&self, compress: Compress) -> usize
fn serialize_compressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
fn compressed_size(&self) -> usize
fn serialize_uncompressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
fn uncompressed_size(&self) -> usize
Source§impl<F: Clone + Field> Clone for DenseMultilinearExtension<F>
impl<F: Clone + Field> Clone for DenseMultilinearExtension<F>
Source§fn clone(&self) -> DenseMultilinearExtension<F>
fn clone(&self) -> DenseMultilinearExtension<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<F: Field> Debug for DenseMultilinearExtension<F>
impl<F: Field> Debug for DenseMultilinearExtension<F>
Source§impl<F: Default + Field> Default for DenseMultilinearExtension<F>
impl<F: Default + Field> Default for DenseMultilinearExtension<F>
Source§fn default() -> DenseMultilinearExtension<F>
fn default() -> DenseMultilinearExtension<F>
Source§impl<F: Field> Index<usize> for DenseMultilinearExtension<F>
impl<F: Field> Index<usize> for DenseMultilinearExtension<F>
Source§impl<F: Field> Mul<F> for DenseMultilinearExtension<F>
impl<F: Field> Mul<F> for DenseMultilinearExtension<F>
Source§impl<'a, F: Field> MulAssign<&'a F> for DenseMultilinearExtension<F>
impl<'a, F: Field> MulAssign<&'a F> for DenseMultilinearExtension<F>
Source§fn mul_assign(&mut self, scalar: &'a F)
fn mul_assign(&mut self, scalar: &'a F)
*=
operation. Read moreSource§impl<F: Field> MulAssign<F> for DenseMultilinearExtension<F>
impl<F: Field> MulAssign<F> for DenseMultilinearExtension<F>
Source§fn mul_assign(&mut self, scalar: F)
fn mul_assign(&mut self, scalar: F)
*=
operation. Read moreSource§impl<F: Field> MultilinearExtension<F> for DenseMultilinearExtension<F>
impl<F: Field> MultilinearExtension<F> for DenseMultilinearExtension<F>
Source§fn fix_variables(&self, partial_point: &[F]) -> Self
fn fix_variables(&self, partial_point: &[F]) -> Self
Return the MLE resulting from binding the first variables of self
to the values in partial_point
(from left to right).
Note: this method can be used in combination with relabel
or
relabel_in_place
to bind variables at arbitrary positions.
use ark_test_curves::bls12_381::Fr;
// Constructing the two-variate multilinear polynomial x_0 + 2 * x_1 + 3 * x_0 * x_1
// by specifying its evaluations at [00, 10, 01, 11]
let mle = DenseMultilinearExtension::from_evaluations_vec(
2, vec![0, 1, 2, 6].iter().map(|x| Fr::from(*x as u64)).collect()
);
// Bind the first variable of the MLE, x_0, to the value 5, resulting in
// a new polynomial in one variable: 5 + 17 * x
let bound = mle.fix_variables(&[Fr::from(5)]);
assert_eq!(bound.to_evaluations(), vec![Fr::from(5), Fr::from(22)]);
}
Source§fn rand<R: Rng>(num_vars: usize, rng: &mut R) -> Self
fn rand<R: Rng>(num_vars: usize, rng: &mut R) -> Self
l
-variate multilinear extension where value of evaluations
are sampled uniformly at random.Source§fn relabel(&self, a: usize, b: usize, k: usize) -> Self
fn relabel(&self, a: usize, b: usize, k: usize) -> Self
k
scalars from positions a..a+k
to
positions b..b+k
, and from position b..b+k
to position a..a+k
in vector. Read moreSource§fn to_evaluations(&self) -> Vec<F>
fn to_evaluations(&self) -> Vec<F>
Source§impl<F: Field> Neg for DenseMultilinearExtension<F>
impl<F: Field> Neg for DenseMultilinearExtension<F>
Source§impl<F: PartialEq + Field> PartialEq for DenseMultilinearExtension<F>
impl<F: PartialEq + Field> PartialEq for DenseMultilinearExtension<F>
Source§fn eq(&self, other: &DenseMultilinearExtension<F>) -> bool
fn eq(&self, other: &DenseMultilinearExtension<F>) -> bool
self
and other
values to be equal, and is used by ==
.Source§impl<F: Field> Polynomial<F> for DenseMultilinearExtension<F>
impl<F: Field> Polynomial<F> for DenseMultilinearExtension<F>
Source§fn evaluate(&self, point: &Self::Point) -> F
fn evaluate(&self, point: &Self::Point) -> F
Evaluate the dense MLE at the given point
§Example
use ark_test_curves::bls12_381::Fr;
// The two-variate polynomial p = x_0 + 3 * x_0 * x_1 + 2 evaluates to [2, 3, 2, 6]
// in the two-dimensional hypercube with points [00, 10, 01, 11]:
// p(x_0, x_1) = 2*(1-x_1)*(1-x_0) + 3*(1-x_1)*x_0 + 2*x_1*(1-x_0) + 6*x_1*x_0
let mle = DenseMultilinearExtension::from_evaluations_vec(
2, vec![2, 3, 2, 6].iter().map(|x| Fr::from(*x as u64)).collect()
);
// By the uniqueness of MLEs, `mle` is precisely the above polynomial, which
// takes the value 54 at the point (x_0, x_1) = (1, 17)
let eval = mle.evaluate(&[Fr::one(), Fr::from(17)].into());
assert_eq!(eval, Fr::from(54));
Source§impl<'a, 'b, F: Field> Sub<&'a DenseMultilinearExtension<F>> for &'b DenseMultilinearExtension<F>
impl<'a, 'b, F: Field> Sub<&'a DenseMultilinearExtension<F>> for &'b DenseMultilinearExtension<F>
Source§type Output = DenseMultilinearExtension<F>
type Output = DenseMultilinearExtension<F>
-
operator.Source§impl<F: Field> Sub for DenseMultilinearExtension<F>
impl<F: Field> Sub for DenseMultilinearExtension<F>
Source§type Output = DenseMultilinearExtension<F>
type Output = DenseMultilinearExtension<F>
-
operator.Source§fn sub(self, other: DenseMultilinearExtension<F>) -> Self
fn sub(self, other: DenseMultilinearExtension<F>) -> Self
-
operation. Read moreSource§impl<'a, F: Field> SubAssign<&'a DenseMultilinearExtension<F>> for DenseMultilinearExtension<F>
impl<'a, F: Field> SubAssign<&'a DenseMultilinearExtension<F>> for DenseMultilinearExtension<F>
Source§fn sub_assign(&mut self, other: &'a DenseMultilinearExtension<F>)
fn sub_assign(&mut self, other: &'a DenseMultilinearExtension<F>)
-=
operation. Read moreSource§impl<F: Field> SubAssign for DenseMultilinearExtension<F>
impl<F: Field> SubAssign for DenseMultilinearExtension<F>
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-=
operation. Read moreSource§impl<F: Field> Valid for DenseMultilinearExtension<F>
impl<F: Field> Valid for DenseMultilinearExtension<F>
fn check(&self) -> Result<(), SerializationError>
fn batch_check<'a>(
batch: impl Iterator<Item = &'a Self> + Send,
) -> Result<(), SerializationError>where
Self: 'a,
Source§impl<F: Field> Zero for DenseMultilinearExtension<F>
impl<F: Field> Zero for DenseMultilinearExtension<F>
impl<F: Eq + Field> Eq for DenseMultilinearExtension<F>
impl<F: Field> StructuralPartialEq for DenseMultilinearExtension<F>
Auto Trait Implementations§
impl<F> Freeze for DenseMultilinearExtension<F>
impl<F> RefUnwindSafe for DenseMultilinearExtension<F>where
F: RefUnwindSafe,
impl<F> Send for DenseMultilinearExtension<F>
impl<F> Sync for DenseMultilinearExtension<F>
impl<F> Unpin for DenseMultilinearExtension<F>where
F: Unpin,
impl<F> UnwindSafe for DenseMultilinearExtension<F>where
F: 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> CanonicalSerializeHashExt for Twhere
T: CanonicalSerialize,
impl<T> CanonicalSerializeHashExt for Twhere
T: CanonicalSerialize,
fn hash<H>(&self) -> GenericArray<u8, <H as OutputSizeUser>::OutputSize>where
H: Digest,
fn hash_uncompressed<H>(
&self,
) -> GenericArray<u8, <H as OutputSizeUser>::OutputSize>where
H: Digest,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)