mod dense;
mod sparse;
pub use dense::DenseMultilinearExtension;
pub use sparse::SparseMultilinearExtension;
use ark_std::{
fmt::Debug,
hash::Hash,
ops::{Add, AddAssign, Index, Neg, SubAssign},
vec::*,
};
use ark_ff::{Field, Zero};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::rand::Rng;
use crate::Polynomial;
#[cfg(all(
target_has_atomic = "8",
target_has_atomic = "16",
target_has_atomic = "32",
target_has_atomic = "64",
target_has_atomic = "ptr"
))]
type DefaultHasher = ahash::AHasher;
#[cfg(not(all(
target_has_atomic = "8",
target_has_atomic = "16",
target_has_atomic = "32",
target_has_atomic = "64",
target_has_atomic = "ptr"
)))]
type DefaultHasher = fnv::FnvHasher;
pub trait MultilinearExtension<F: Field>:
Sized
+ Clone
+ Debug
+ Hash
+ PartialEq
+ Eq
+ Add
+ Neg
+ Zero
+ CanonicalSerialize
+ CanonicalDeserialize
+ for<'a> AddAssign<&'a Self>
+ for<'a> AddAssign<(F, &'a Self)>
+ for<'a> SubAssign<&'a Self>
+ Index<usize>
+ Polynomial<F, Point = Vec<F>>
{
fn num_vars(&self) -> usize;
fn rand<R: Rng>(num_vars: usize, rng: &mut R) -> Self;
fn relabel(&self, a: usize, b: usize, k: usize) -> Self;
fn fix_variables(&self, partial_point: &[F]) -> Self;
fn to_evaluations(&self) -> Vec<F>;
}
pub(crate) fn swap_bits(x: usize, a: usize, b: usize, n: usize) -> usize {
let a_bits = (x >> a) & ((1usize << n) - 1);
let b_bits = (x >> b) & ((1usize << n) - 1);
let local_xor_mask = a_bits ^ b_bits;
let global_xor_mask = (local_xor_mask << a) | (local_xor_mask << b);
x ^ global_xor_mask
}