pub struct Evaluations<F: Field> {
evals: BitPackedVector<F>,
num_vars: usize,
zero: F,
}Expand description
Stores a boolean function f: {0, 1}^n -> F represented as a list of up to
2^n evaluations of f on the boolean hypercube. The n variables are
indexed from 0 to n-1 throughout the lifetime of the object.
Fields§
§evals: BitPackedVector<F>To understand how evaluations are stored, let’s index f’s input bits
as follows: f(b_0, b_1, ..., b_{n-1}). Evaluations are ordered using
the bit-string b_0b_1...b_{n-2}b_{n-1} as key. This ordering is
sometimes referred to as “big-endian” due to its resemblance to
big-endian byte ordering. A suffix of contiguous evaluations all equal
to F::ZERO may be omitted in this internal representation but this
struct is not responsible for maintaining this property at all times.
§Example
- The evaluations of a 2-dimensional function are stored in the
following order:
[ f(0, 0), f(0, 1), f(1, 0), f(1, 1) ]. - The evaluation table
[ 1, 0, 5, 0 ]may be stored as[1, 0, 5]by omitting the trailing zero. Note that both representations are valid.
num_vars: usizeNumber of input variables to f. Invariant: 0 <= evals.len() <= 2^num_vars. The length can be less than 2^num_vars due to suffix
omission.
zero: FTODO(Makis): Is there a better way to handle this?? When accessing an element of the bookkeping table, we return a reference to a field element. In case the element is stored implicitly as a missing entry, we need someone to own the “zero” of the field. If I make this a const, I’m not sure how to initialize it.
Implementations§
Source§impl<F: Field> Evaluations<F>
impl<F: Field> Evaluations<F>
Sourcepub fn new_zero() -> Self
pub fn new_zero() -> Self
Returns a representation of the constant function on zero variables
equal to F::ZERO.
Sourcepub fn new(num_vars: usize, evals: Vec<F>) -> Self
pub fn new(num_vars: usize, evals: Vec<F>) -> Self
Builds an evaluation representation for a function f: {0, 1}^num_vars -> F from a vector of evaluations in big-endian order (see
documentation comment for Self::evals for explanation).
§Example
For a function f: {0, 1}^2 -> F, an evaluations table may be built as:
Evaluations::new(2, vec![ f(0, 0), f(0, 1), f(1, 0), f(1, 1) ]).
An example of suffix omission is when f(1, 0) == f(1, 1) == F::ZERO.
In that case those zero values may be omitted and the following
statement generates an equivalent representation: Evaluations::new(2, vec![ f(0, 0), f(0, 1) ]).
Sourcepub fn new_from_little_endian(num_vars: usize, evals: &[F]) -> Self
pub fn new_from_little_endian(num_vars: usize, evals: &[F]) -> Self
Builds an evaluation representation for a function f: {0, 1}^num_vars -> F from a vector of evaluations in little-endian order (see
documentation comment for Self::evals for explanation).
§Example
For a function f: {0, 1}^2 -> F, an evaluations table may be built as:
Evaluations::new_from_little_endian(2, vec![ f(0, 0), f(1, 0), f(0, 1), f(1, 1) ]).
Sourcepub fn is_fully_bound(&self) -> bool
pub fn is_fully_bound(&self) -> bool
Returns true if the boolean function 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. This operation
should always be successful because even in the case that
Self::num_vars is zero, there is a non-zero number of vertices on the
boolean hypercube and hence there’s at least one evaluation stored in
the bookkeeping table, either explicitly as a value inside
Self::evals, or implicitly if it’s a F::ZERO that has been pruned as
part of a zero suffix.
Sourcepub fn value(&self) -> F
pub fn value(&self) -> F
If self represents a fully-bound boolean function (i.e.
Self::num_vars is zero), it returns its value. Otherwise panics.
Sourcepub fn iter(&self) -> EvaluationsIterator<'_, F> ⓘ
pub fn iter(&self) -> EvaluationsIterator<'_, F> ⓘ
Returns an iterator that traverses the evaluations in “big-endian” order.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Temporary function returning the length of the internal representation.
Sourcepub fn get(&self, idx: usize) -> Option<F>
pub fn get(&self, idx: usize) -> Option<F>
Temporary function for accessing a the idx-th element in the internal
representation.
Sourcefn equiv_repr(evals1: &BitPackedVector<F>, evals2: &BitPackedVector<F>) -> bool
fn equiv_repr(evals1: &BitPackedVector<F>, evals2: &BitPackedVector<F>) -> bool
Checks whether its arguments correspond to equivalent representations of
the same list of evaluations. Two representations are equivalent if
omitting the longest contiguous suffix of F::ZEROs from each results
in the same vectors.
Sourcepub fn flip_endianess(num_bits: usize, values: &[F]) -> Vec<F>
pub fn flip_endianess(num_bits: usize, values: &[F]) -> Vec<F>
Sorts the elements of values by their 0-based index transformed by
mirroring the num_bits LSBs. This operation effectively flips the
“endianess” of the index ordering. If values.len() < 2^num_bits, the
missing values are assumed to be zeros. The resulting vector is always
of size 2^num_bits.
§Example
use remainder::mle::evals::Evaluations;
use shared_types::Fr;
assert_eq!(Evaluations::flip_endianess(
2,
&[Fr::from(1), Fr::from(2), Fr::from(3), Fr::from(4)]),
vec![ Fr::from(1), Fr::from(3), Fr::from(2), Fr::from(4) ]
);
assert_eq!(Evaluations::flip_endianess(
2,
&[ Fr::from(1), Fr::from(2) ]),
vec![ Fr::from(1), Fr::from(0), Fr::from(2), Fr::from(0) ]
);Trait Implementations§
Source§impl<F: Clone + Field> Clone for Evaluations<F>
impl<F: Clone + Field> Clone for Evaluations<F>
Source§fn clone(&self) -> Evaluations<F>
fn clone(&self) -> Evaluations<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 Evaluations<F>
impl<F: Debug + Field> Debug for Evaluations<F>
Source§impl<'de, F> Deserialize<'de> for Evaluations<F>where
F: Field,
impl<'de, F> Deserialize<'de> for Evaluations<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 Evaluations<F>
impl<F: PartialEq + Field> PartialEq for Evaluations<F>
Source§impl<F> Serialize for Evaluations<F>where
F: Field,
impl<F> Serialize for Evaluations<F>where
F: Field,
Source§impl<F: Field> Zeroize for Evaluations<F>
impl<F: Field> Zeroize for Evaluations<F>
impl<F: Field> StructuralPartialEq for Evaluations<F>
Auto Trait Implementations§
impl<F> Freeze for Evaluations<F>where
F: Freeze,
impl<F> RefUnwindSafe for Evaluations<F>where
F: RefUnwindSafe,
impl<F> Send for Evaluations<F>
impl<F> Sync for Evaluations<F>
impl<F> Unpin for Evaluations<F>where
F: Unpin,
impl<F> UnwindSafe for Evaluations<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.