Skip to main content

MultilinearPoly

Struct MultilinearPoly 

Source
pub struct MultilinearPoly<F: Field> { /* private fields */ }
Expand description

A multilinear polynomial represented by its evaluation table.

The table has 2^num_vars entries in big-endian bit order: the first variable is the most significant bit. For a 2-variable polynomial f(x0, x1):

Indexx0x1Value
000evals[0]
101evals[1]
210evals[2]
311evals[3]

§Examples

use field_cat::F101;
use proof_cat_core::MultilinearPoly;

// f(x0, x1): f(0,0)=1, f(0,1)=2, f(1,0)=3, f(1,1)=4
let poly = MultilinearPoly::from_evals(vec![
    F101::new(1), F101::new(2), F101::new(3), F101::new(4),
])?;

assert_eq!(poly.num_vars().count(), 2);

// Sum over the Boolean hypercube: 1 + 2 + 3 + 4 = 10
assert_eq!(poly.sum_over_boolean_hypercube(), F101::new(10));

// Evaluate at a Boolean point: f(1, 0) = 3
let val = poly.evaluate(&[F101::new(1), F101::new(0)])?;
assert_eq!(val, F101::new(3));

Implementations§

Source§

impl<F: Field> MultilinearPoly<F>

Source

pub fn from_evals(evals: Vec<F>) -> Result<Self, Error>

Construct from an evaluation table.

The table length must be a power of two (including 1).

§Errors

Returns Error::NotPowerOfTwo if evals.len() is not a power of two or is zero.

§Examples
use field_cat::F101;
use proof_cat_core::MultilinearPoly;

// A 1-variable polynomial: f(0) = 3, f(1) = 7.
let poly = MultilinearPoly::from_evals(vec![
    F101::new(3), F101::new(7),
])?;
assert_eq!(poly.num_vars().count(), 1);

// Non-power-of-two lengths are rejected.
let err = MultilinearPoly::<F101>::from_evals(vec![
    F101::new(1), F101::new(2), F101::new(3),
]);
assert!(err.is_err());
Source

pub fn num_vars(&self) -> NumVars

The number of variables.

Source

pub fn evals(&self) -> &[F]

The evaluation table.

Source

pub fn sum_over_boolean_hypercube(&self) -> F

Sum of all evaluations on the Boolean hypercube.

This equals sum_{x in {0,1}^n} f(x).

Source

pub fn evaluate(&self, point: &[F]) -> Result<F, Error>

Evaluate the multilinear extension at an arbitrary point.

Uses iterated partial evaluation: for each variable i, the table is split in half and each pair (lo, hi) is interpolated as lo * (1 - r_i) + hi * r_i. After n rounds a single value remains.

§Errors

Returns Error::DimensionMismatch if point.len() != num_vars.

§Examples
use field_cat::F101;
use proof_cat_core::MultilinearPoly;

// f(x) = 3*(1-x) + 7*x = 3 + 4x
let poly = MultilinearPoly::from_evals(vec![
    F101::new(3), F101::new(7),
])?;

// f(0) = 3, f(1) = 7, f(2) = 11
assert_eq!(poly.evaluate(&[F101::new(0)])?, F101::new(3));
assert_eq!(poly.evaluate(&[F101::new(1)])?, F101::new(7));
assert_eq!(poly.evaluate(&[F101::new(2)])?, F101::new(11));
Source

pub fn bind_first_var(&self, r: &F) -> Result<Self, Error>

Bind the first variable to r, producing a polynomial with one fewer variable.

The resulting table has 2^(n-1) entries where each entry j is evals[2j] * (1 - r) + evals[2j+1] * r.

§Errors

Returns Error::DimensionMismatch if the polynomial has zero variables.

Trait Implementations§

Source§

impl<F: Clone + Field> Clone for MultilinearPoly<F>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + Field> Debug for MultilinearPoly<F>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F> Freeze for MultilinearPoly<F>

§

impl<F> RefUnwindSafe for MultilinearPoly<F>
where F: RefUnwindSafe,

§

impl<F> Send for MultilinearPoly<F>
where F: Send,

§

impl<F> Sync for MultilinearPoly<F>
where F: Sync,

§

impl<F> Unpin for MultilinearPoly<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for MultilinearPoly<F>

§

impl<F> UnwindSafe for MultilinearPoly<F>
where F: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.