Struct twenty_first::shared_math::mpolynomial::MPolynomial
source · [−]pub struct MPolynomial<T: PrimeField> {
pub variable_count: usize,
pub coefficients: HashMap<Vec<u64>, T>,
}
Fields
variable_count: usize
coefficients: HashMap<Vec<u64>, T>
Implementations
sourceimpl<PFElem: PrimeField> MPolynomial<PFElem>
impl<PFElem: PrimeField> MPolynomial<PFElem>
pub fn zero(variable_count: usize) -> Self
pub fn is_zero(&self) -> bool
sourcepub fn from_constant(element: PFElem, variable_count: usize) -> Self
pub fn from_constant(element: PFElem, variable_count: usize) -> Self
Returns an MPolynomial
instance over variable_count
variables
that evaluates to element
everywhere.
I.e.
P(x,y..,z) = element
Note that in this encoding P(x,y) == P(x,w) but P(x,y) != P(x,y,z).
sourcepub fn variables(variable_count: usize, one: PFElem) -> Vec<Self>
pub fn variables(variable_count: usize, one: PFElem) -> Vec<Self>
Returns a vector of multivariate polynomials that each represent a
function of one indeterminate variable to the first power. For example,
let p = variables(3, 1.into())
represents the functions
p[0] =
$f(x,y,z) = x$p[1] =
$f(x,y,z) = y$p[2] =
$f(x,y,z) = z$
and let p = variables(5, 1.into())
represents the functions
p[0] =
$p(a,b,c,d,e) = a$p[1] =
$p(a,b,c,d,e) = b$p[2] =
$p(a,b,c,d,e) = c$p[3] =
$p(a,b,c,d,e) = d$p[4] =
$p(a,b,c,d,e) = e$
pub fn precalculate_symbolic_exponents(
mpols: &[Self],
point: &[Polynomial<PFElem>],
exponents_memoization: &mut HashMap<Vec<u64>, Polynomial<PFElem>>
) -> Result<(), Box<dyn Error>>
pub fn evaluate(&self, point: &[PFElem]) -> PFElem
pub fn extract_exponents_list(
mpols: &[Self]
) -> Result<Vec<Vec<u64>>, Box<dyn Error>>
sourcepub fn precalculate_scalar_mod_pows(
limit: u64,
point: &[PFElem]
) -> HashMap<(usize, u64), PFElem>
pub fn precalculate_scalar_mod_pows(
limit: u64,
point: &[PFElem]
) -> HashMap<(usize, u64), PFElem>
Get a hash map with precalculated values for point[i]^j Only exponents 2 and above are stored.
pub fn precalculate_scalar_exponents(
point: &[PFElem],
precalculated_mod_pows: &HashMap<(usize, u64), PFElem>,
exponents_list: &[Vec<u64>]
) -> Result<HashMap<Vec<u64>, PFElem>, Box<dyn Error>>
pub fn evaluate_with_precalculation(
&self,
point: &[PFElem],
intermediate_results: &HashMap<Vec<u64>, PFElem>
) -> PFElem
pub fn evaluate_symbolic_with_memoization_precalculated(
&self,
point: &[Polynomial<PFElem>],
exponents_memoization: &mut HashMap<Vec<u64>, Polynomial<PFElem>>
) -> Polynomial<PFElem>
pub fn evaluate_symbolic_with_memoization(
&self,
point: &[Polynomial<PFElem>],
mod_pow_memoization: &mut HashMap<(usize, u64), Polynomial<PFElem>>,
mul_memoization: &mut HashMap<(Polynomial<PFElem>, (usize, u64)), Polynomial<PFElem>>,
exponents_memoization: &mut HashMap<Vec<u64>, Polynomial<PFElem>>
) -> Polynomial<PFElem>
pub fn evaluate_symbolic(
&self,
point: &[Polynomial<PFElem>]
) -> Polynomial<PFElem>
pub fn lift(
univariate_polynomial: Polynomial<PFElem>,
variable_index: usize,
variable_count: usize
) -> Self
pub fn scalar_mul(&self, factor: PFElem) -> Self
pub fn scalar_mul_mut(&mut self, factor: PFElem)
pub fn mod_pow(&self, pow: BigInt, one: PFElem) -> Self
pub fn square(&self) -> Self
sourcepub fn max_exponent(&self) -> u64
pub fn max_exponent(&self) -> u64
Return the highest number present in the list of list of exponents
For P(x,y) = x^4*y^3
, 4
would be returned.
sourcepub fn degree(&self) -> Degree
pub fn degree(&self) -> Degree
Calculate the “total degree” of a multivariate polynomial.
The total degree is defined as the highest combined degree of any term where the combined degree is the sum of all the term’s variable exponents.
As a convention, the polynomial f(x) = 0 has degree -1.
sourcepub fn symbolic_degree_bound(&self, max_degrees: &[i64]) -> Degree
pub fn symbolic_degree_bound(&self, max_degrees: &[i64]) -> Degree
During symbolic evaluation, i.e., when substituting a univariate polynomial for one of the
variables, the total degree of the resulting polynomial can be upper bounded. This bound
is the total_degree_bound
, and can be calculated across all terms. Only the constant
zero polynomial P(x,..) = 0
has a negative degree and it is always -1. All other
constant polynomials have degree 0.
max_degrees
: the max degrees for each of the univariate polynomials.total_degree_bound
: the max resulting degree from the substitution.
Trait Implementations
sourceimpl<PFElem: PrimeField> Add<MPolynomial<PFElem>> for MPolynomial<PFElem>
impl<PFElem: PrimeField> Add<MPolynomial<PFElem>> for MPolynomial<PFElem>
type Output = MPolynomial<PFElem>
type Output = MPolynomial<PFElem>
The resulting type after applying the +
operator.
sourceimpl<PFElem: PrimeField> AddAssign<MPolynomial<PFElem>> for MPolynomial<PFElem>
impl<PFElem: PrimeField> AddAssign<MPolynomial<PFElem>> for MPolynomial<PFElem>
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the +=
operation. Read more
sourceimpl<T: PrimeField> Clone for MPolynomial<T>
impl<T: PrimeField> Clone for MPolynomial<T>
sourceimpl<T: PrimeField> Debug for MPolynomial<T>
impl<T: PrimeField> Debug for MPolynomial<T>
sourceimpl<PFElem: PrimeField> Display for MPolynomial<PFElem>
impl<PFElem: PrimeField> Display for MPolynomial<PFElem>
sourceimpl<PFElem: PrimeField> Mul<MPolynomial<PFElem>> for MPolynomial<PFElem>
impl<PFElem: PrimeField> Mul<MPolynomial<PFElem>> for MPolynomial<PFElem>
type Output = MPolynomial<PFElem>
type Output = MPolynomial<PFElem>
The resulting type after applying the *
operator.
sourceimpl<PFElem: PrimeField> MulAssign<MPolynomial<PFElem>> for MPolynomial<PFElem>
impl<PFElem: PrimeField> MulAssign<MPolynomial<PFElem>> for MPolynomial<PFElem>
sourcefn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the *=
operation. Read more
sourceimpl<PFElem: PrimeField> Neg for MPolynomial<PFElem>
impl<PFElem: PrimeField> Neg for MPolynomial<PFElem>
type Output = MPolynomial<PFElem>
type Output = MPolynomial<PFElem>
The resulting type after applying the -
operator.
sourceimpl<PFElem: PrimeField> PartialEq<MPolynomial<PFElem>> for MPolynomial<PFElem>
impl<PFElem: PrimeField> PartialEq<MPolynomial<PFElem>> for MPolynomial<PFElem>
sourceimpl<PFElem: PrimeField> Sub<MPolynomial<PFElem>> for MPolynomial<PFElem>
impl<PFElem: PrimeField> Sub<MPolynomial<PFElem>> for MPolynomial<PFElem>
type Output = MPolynomial<PFElem>
type Output = MPolynomial<PFElem>
The resulting type after applying the -
operator.
sourceimpl<PFElem: PrimeField> Sum<MPolynomial<PFElem>> for MPolynomial<PFElem>
impl<PFElem: PrimeField> Sum<MPolynomial<PFElem>> for MPolynomial<PFElem>
impl<PFElem: PrimeField> Eq for MPolynomial<PFElem>
Auto Trait Implementations
impl<T> RefUnwindSafe for MPolynomial<T> where
T: RefUnwindSafe,
impl<T> Send for MPolynomial<T>
impl<T> Sync for MPolynomial<T>
impl<T> Unpin for MPolynomial<T> where
T: Unpin,
impl<T> UnwindSafe for MPolynomial<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more