pub struct MultilinearExtension<F: Field> {
pub f: Evaluations<F>,
}Expand description
Stores a function \tilde{f}: F^n -> F, the unique Multilinear Extension
(MLE) of a given function f: {0, 1}^n -> F:
\tilde{f}(x_0, ..., x_{n-1})
= \sum_{b_0, ..., b_{n-1} \in {0, 1}^n}
\tilde{beta}(x_0, ..., x_{n-1}, b_0, ..., b_{n-1})
* f(b_0, ..., b_{n-1}).where \tilde{beta} is the MLE of the equality function:
\tilde{beta}(x_0, ..., x_{n-1}, b_0, ..., b_{n-1})
= \prod_{i = 0}^{n-1} ( x_i * b_i + (1 - x_i) * (1 - b_i) )Internally, f is represented as a list of evaluations of f on the
boolean hypercube. The n variables are indexed from 0 to n-1
throughout the lifetime of the object even if n is modified by fixing a
variable to a constant value.
Fields§
§f: Evaluations<F>The bookkeeping table with the evaluations of f on the hypercube.
Implementations§
Source§impl<F: Field> MultilinearExtension<F>
impl<F: Field> MultilinearExtension<F>
Sourcepub fn new(evals_vec: Vec<F>) -> Self
pub fn new(evals_vec: Vec<F>) -> Self
Create a new MultilinearExtension from a Vec<F> of evaluations.
Sourcepub fn new_from_evals(evals: Evaluations<F>) -> Self
pub fn new_from_evals(evals: Evaluations<F>) -> Self
Generate a new MultilinearExtension from a representation evals of a
function f.
Sourcepub fn new_sized_zero(num_vars: usize) -> Self
pub fn new_sized_zero(num_vars: usize) -> Self
Creates a new mle which is all zeroes of a specific num_vars. In this case the size of the evals and the num_vars will not match up
Sourcepub fn iter(&self) -> EvaluationsIterator<'_, F> ⓘ
pub fn iter(&self) -> EvaluationsIterator<'_, F> ⓘ
Returns an iterator accessing the evaluations defining this MLE in “big-endian” order.
Sourcepub fn is_fully_bound(&self) -> bool
pub fn is_fully_bound(&self) -> bool
Returns true if the MLE has not free variables. Equivalent to checking whether that Self::num_vars is equal to zero.
Sourcepub fn first(&self) -> F
pub fn first(&self) -> F
Returns the first element of the bookkeeping table of this MLE, corresponding to the value of the MLE when all varables are set to zero. This operation never fails (see Evaluations::first).
Sourcepub fn value(&self) -> F
pub fn value(&self) -> F
If self represents a fully-bound MLE (i.e. on zero variables), it
returns its value. Otherwise panics.
Sourcepub fn new_zero() -> Self
pub fn new_zero() -> Self
Generates a representation for the MLE of the zero function on zero variables.
Sourcepub fn get(&self, idx: usize) -> Option<F>
pub fn get(&self, idx: usize) -> Option<F>
Returns the idx-th element, if idx is in the range [0, 2^self.num_vars).
Sourcepub fn evaluate_at_point(&self, point: &[F]) -> F
pub fn evaluate_at_point(&self, point: &[F]) -> F
Evaluate \tilde{f} at point \in F^n.
§Panics
If point does not contain exactly self.num_vars() elements.
Sourcepub fn fix_variable_at_index(&mut self, var_index: usize, point: F)
pub fn fix_variable_at_index(&mut self, var_index: usize, point: F)
Fix the 0-based var_index-th bit of \tilde{f} to an arbitrary field
element point \in F by destructively modifying self.
§Params
var_index: A 0-based index of the input variable to be fixed.point: The field element to setx_{var_index}equal to.
§Example
If self represents a function \tilde{f}: F^3 -> F,
self.fix_variable_at_index(1, r) fixes the middle variable to r \in F. After the invocation, self represents a function \tilde{g}: F^2 -> F defined as the multilinear extension of the following function:
g(b_0, b_1) = \tilde{f}(b_0, r, b_1).
§Panics
if var_index is outside the interval [0, self.num_vars()).
Sourcepub fn fix_variable(&mut self, point: F)
pub fn fix_variable(&mut self, point: F)
Sourcepub fn stack_mles(mles: Vec<MultilinearExtension<F>>) -> MultilinearExtension<F>
pub fn stack_mles(mles: Vec<MultilinearExtension<F>>) -> MultilinearExtension<F>
Stacks the MLEs into a single MLE, assuming they are stored in a “big endian” fashion.
Sourcepub fn convert_into_u8_vec(&self) -> Vec<u8> ⓘ
pub fn convert_into_u8_vec(&self) -> Vec<u8> ⓘ
Convert a MultilinearExtension into a vector of u8s. Every element is padded to contain 8 bits.
Sourcepub fn convert_into_u16_vec(&self) -> Vec<u16>
pub fn convert_into_u16_vec(&self) -> Vec<u16>
Convert a MultilinearExtension into a vector of u16s. Every element is padded to contain 16 bits.
Sourcepub fn convert_into_u32_vec(&self) -> Vec<u32>
pub fn convert_into_u32_vec(&self) -> Vec<u32>
Convert a MultilinearExtension into a vector of u32s. Every element is padded to contain 32 bits.
Sourcepub fn convert_into_u64_vec(&self) -> Vec<u64>
pub fn convert_into_u64_vec(&self) -> Vec<u64>
Convert a MultilinearExtension into a vector of u64s. Every element is padded to contain 64 bits.
Sourcepub fn convert_into_u128_vec(&self) -> Vec<u128>
pub fn convert_into_u128_vec(&self) -> Vec<u128>
Convert a MultilinearExtension into a vector of u128s. Every element is padded to contain 128 bits.
Trait Implementations§
Source§impl<F: Clone + Field> Clone for MultilinearExtension<F>
impl<F: Clone + Field> Clone for MultilinearExtension<F>
Source§fn clone(&self) -> MultilinearExtension<F>
fn clone(&self) -> MultilinearExtension<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug + Field> Debug for MultilinearExtension<F>
impl<F: Debug + Field> Debug for MultilinearExtension<F>
Source§impl<'de, F> Deserialize<'de> for MultilinearExtension<F>where
F: Field,
impl<'de, F> Deserialize<'de> for MultilinearExtension<F>where
F: Field,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<F: PartialEq + Field> PartialEq for MultilinearExtension<F>
impl<F: PartialEq + Field> PartialEq for MultilinearExtension<F>
Source§impl<F> Serialize for MultilinearExtension<F>where
F: Field,
impl<F> Serialize for MultilinearExtension<F>where
F: Field,
Source§impl<F: Field> Zeroize for MultilinearExtension<F>
impl<F: Field> Zeroize for MultilinearExtension<F>
impl<F: Field> StructuralPartialEq for MultilinearExtension<F>
Auto Trait Implementations§
impl<F> Freeze for MultilinearExtension<F>where
F: Freeze,
impl<F> RefUnwindSafe for MultilinearExtension<F>where
F: RefUnwindSafe,
impl<F> Send for MultilinearExtension<F>
impl<F> Sync for MultilinearExtension<F>
impl<F> Unpin for MultilinearExtension<F>where
F: Unpin,
impl<F> UnwindSafe for MultilinearExtension<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.