Struct twenty_first::shared_math::mpolynomial::MPolynomial
source · pub struct MPolynomial<T: FiniteField> {
pub variable_count: usize,
pub coefficients: HashMap<Vec<u8>, T>,
}
Fields
variable_count: usize
coefficients: HashMap<Vec<u8>, T>
Implementations
sourceimpl<FF: FiniteField> MPolynomial<FF>
impl<FF: FiniteField> MPolynomial<FF>
pub fn zero(variable_count: usize) -> Self
pub fn is_zero(&self) -> bool
pub fn is_one(&self) -> bool
sourcepub fn from_constant(element: FF, variable_count: usize) -> Self
pub fn from_constant(element: FF, 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) -> Vec<Self>
pub fn variables(variable_count: usize) -> 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<FF>],
exponents_memoization: &mut HashMap<Vec<u8>, Polynomial<FF>>
) -> Result<(), Box<dyn Error>>
pub fn evaluate(&self, point: &[FF]) -> FF
pub fn extract_exponents_list(
mpols: &[Self]
) -> Result<Vec<Vec<u8>>, Box<dyn Error>>
sourcepub fn precalculate_scalar_mod_pows(
limit: u8,
point: &[FF]
) -> HashMap<(usize, u8), FF>
pub fn precalculate_scalar_mod_pows(
limit: u8,
point: &[FF]
) -> HashMap<(usize, u8), FF>
Get a hash map with precalculated values for point[i]^j Only exponents 2 and above are stored.
pub fn precalculate_scalar_exponents(
point: &[FF],
precalculated_mod_pows: &HashMap<(usize, u8), FF>,
exponents_list: &[Vec<u8>]
) -> Result<HashMap<Vec<u8>, FF>, Box<dyn Error>>
pub fn evaluate_with_precalculation(
&self,
point: &[FF],
intermediate_results: &HashMap<Vec<u8>, FF>
) -> FF
pub fn evaluate_symbolic_with_memoization_precalculated(
&self,
point: &[Polynomial<FF>],
exponents_memoization: &mut HashMap<Vec<u8>, Polynomial<FF>>
) -> Polynomial<FF>
pub fn evaluate_symbolic_with_memoization(
&self,
point: &[Polynomial<FF>],
mod_pow_memoization: &mut HashMap<(usize, u8), Polynomial<FF>>,
mul_memoization: &mut HashMap<(Polynomial<FF>, (usize, u8)), Polynomial<FF>>,
exponents_memoization: &mut HashMap<Vec<u8>, Polynomial<FF>>
) -> Polynomial<FF>
pub fn evaluate_symbolic(&self, point: &[Polynomial<FF>]) -> Polynomial<FF>
sourcepub fn lift(
univariate_polynomial: Polynomial<FF>,
variable_index: usize,
variable_count: usize
) -> Self
pub fn lift(
univariate_polynomial: Polynomial<FF>,
variable_index: usize,
variable_count: usize
) -> Self
lift Creates a multivariate polynomial from a univariate one.
pub fn scalar_mul(&self, factor: FF) -> Self
pub fn scalar_mul_mut(&mut self, factor: FF)
pub fn pow(&self, pow: u8) -> Self
pub fn square(&self) -> Self
sourcepub fn max_exponent(&self) -> u8
pub fn max_exponent(&self) -> u8
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<FF: FiniteField> Add<MPolynomial<FF>> for MPolynomial<FF>
impl<FF: FiniteField> Add<MPolynomial<FF>> for MPolynomial<FF>
type Output = MPolynomial<FF>
type Output = MPolynomial<FF>
+
operator.sourceimpl<FF: FiniteField> AddAssign<MPolynomial<FF>> for MPolynomial<FF>
impl<FF: FiniteField> AddAssign<MPolynomial<FF>> for MPolynomial<FF>
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresourceimpl<T: FiniteField> Clone for MPolynomial<T>
impl<T: FiniteField> Clone for MPolynomial<T>
sourceimpl<T: FiniteField> Debug for MPolynomial<T>
impl<T: FiniteField> Debug for MPolynomial<T>
sourceimpl<FF: FiniteField> Display for MPolynomial<FF>
impl<FF: FiniteField> Display for MPolynomial<FF>
sourceimpl<FF: FiniteField> Hash for MPolynomial<FF>
impl<FF: FiniteField> Hash for MPolynomial<FF>
sourceimpl<FF: FiniteField> Mul<MPolynomial<FF>> for MPolynomial<FF>
impl<FF: FiniteField> Mul<MPolynomial<FF>> for MPolynomial<FF>
type Output = MPolynomial<FF>
type Output = MPolynomial<FF>
*
operator.sourceimpl<FF: FiniteField> MulAssign<MPolynomial<FF>> for MPolynomial<FF>
impl<FF: FiniteField> MulAssign<MPolynomial<FF>> for MPolynomial<FF>
sourcefn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresourceimpl<FF: FiniteField> Neg for MPolynomial<FF>
impl<FF: FiniteField> Neg for MPolynomial<FF>
type Output = MPolynomial<FF>
type Output = MPolynomial<FF>
-
operator.sourceimpl<FF: FiniteField> PartialEq<MPolynomial<FF>> for MPolynomial<FF>
impl<FF: FiniteField> PartialEq<MPolynomial<FF>> for MPolynomial<FF>
sourceimpl<FF: FiniteField> Sub<MPolynomial<FF>> for MPolynomial<FF>
impl<FF: FiniteField> Sub<MPolynomial<FF>> for MPolynomial<FF>
type Output = MPolynomial<FF>
type Output = MPolynomial<FF>
-
operator.