pub struct Sparse<F: PrimeField, const N: usize, const D: usize> {
pub monomials: HashMap<[usize; N], F>,
}
Expand description
Represents a multivariate polynomial in N
variables with coefficients in
F
. The polynomial is represented as a sparse polynomial, where each
monomial is represented by a vector of N
exponents.
Fields§
§monomials: HashMap<[usize; N], F>
Trait Implementations§
source§impl<const N: usize, const D: usize, F: PrimeField> Add<&Sparse<F, N, D>> for &Sparse<F, N, D>
impl<const N: usize, const D: usize, F: PrimeField> Add<&Sparse<F, N, D>> for &Sparse<F, N, D>
source§impl<const N: usize, const D: usize, F: PrimeField> Add<&Sparse<F, N, D>> for Sparse<F, N, D>
impl<const N: usize, const D: usize, F: PrimeField> Add<&Sparse<F, N, D>> for Sparse<F, N, D>
source§impl<const N: usize, const D: usize, F: PrimeField> Add<Sparse<F, N, D>> for &Sparse<F, N, D>
impl<const N: usize, const D: usize, F: PrimeField> Add<Sparse<F, N, D>> for &Sparse<F, N, D>
source§impl<F: PrimeField, const N: usize, const D: usize, const M: usize> From<Sparse<F, N, D>> for Result<Sparse<F, M, D>, String>
impl<F: PrimeField, const N: usize, const D: usize, const M: usize> From<Sparse<F, N, D>> for Result<Sparse<F, M, D>, String>
source§impl<const N: usize, const D: usize, F: PrimeField> MVPoly<F, N, D> for Sparse<F, N, D>
impl<const N: usize, const D: usize, F: PrimeField> MVPoly<F, N, D> for Sparse<F, N, D>
source§unsafe fn degree(&self) -> usize
unsafe fn degree(&self) -> usize
Returns the degree of the polynomial.
The degree of the polynomial is the maximum degree of the monomials that have a non-zero coefficient.
Safety
The zero polynomial as a degree equals to 0, as the degree of the
constant polynomials. We do use the unsafe
keyword to warn the user
for this specific case.
source§fn eval(&self, x: &[F; N]) -> F
fn eval(&self, x: &[F; N]) -> F
Evaluate the polynomial at the vector point x
.
This is a dummy implementation. A cache can be used for the monomials to speed up the computation.
source§unsafe fn random<RNG: RngCore>(rng: &mut RNG, max_degree: Option<usize>) -> Self
unsafe fn random<RNG: RngCore>(rng: &mut RNG, max_degree: Option<usize>) -> Self
Generate a random polynomial of maximum degree max_degree
.
If None
is provided as the maximum degree, the polynomial will be
generated with a maximum degree of D
.
Safety
Marked as unsafe to warn the user to use it with caution and to not necessarily rely on it for security/randomness in cryptographic protocols. The user is responsible for providing its own secure polynomial random generator, if needed.
For now, the function is only used for testing.
fn is_constant(&self) -> bool
fn double(&self) -> Self
fn mul_by_scalar(&self, scalar: F) -> Self
source§fn from_variable<Column: Into<usize>>(
var: Variable<Column>,
offset_next_row: Option<usize>
) -> Self
fn from_variable<Column: Into<usize>>( var: Variable<Column>, offset_next_row: Option<usize> ) -> Self
x_i
from the variable i
.
The conversion into the type usize
is unspecified by this trait. It
is left to the trait implementation.
For instance, in the case of crate::prime, the output must be a prime
number, starting at 2
. crate::utils::PrimeNumberGenerator can be
used.
For crate::monomials, the output must be the index of the variable,
starting from 0
. Read moresource§fn is_homogeneous(&self) -> bool
fn is_homogeneous(&self) -> bool
D
).
As a reminder, a polynomial is homogeneous if all its monomials have the
same degree.source§fn homogeneous_eval(&self, x: &[F; N], u: F) -> F
fn homogeneous_eval(&self, x: &[F; N], u: F) -> F
x
and the extra variable
u
using its homogeneous form of degree D.source§fn add_monomial(&mut self, exponents: [usize; N], coeff: F)
fn add_monomial(&mut self, exponents: [usize; N], coeff: F)
coeff * x_1^{e_1} * ... * x_N^{e_N}
to the
polynomial, where e_i
are the values given by the array exponents
. Read moresource§fn compute_cross_terms(
&self,
eval1: &[F; N],
eval2: &[F; N],
u1: F,
u2: F
) -> HashMap<usize, F>
fn compute_cross_terms( &self, eval1: &[F; N], eval2: &[F; N], u1: F, u2: F ) -> HashMap<usize, F>
source§fn modify_monomial(&mut self, exponents: [usize; N], coeff: F)
fn modify_monomial(&mut self, exponents: [usize; N], coeff: F)
coeff
.source§fn is_multilinear(&self) -> bool
fn is_multilinear(&self) -> bool
fn from_constant<ChallengeTerm: Clone>( op: Operations<ConstantExprInner<F, ChallengeTerm>> ) -> Self
source§fn from_expr<Column: Into<usize>, ChallengeTerm: Clone>(
expr: Expr<ConstantExpr<F, ChallengeTerm>, Column>,
offset_next_row: Option<usize>
) -> Self
fn from_expr<Column: Into<usize>, ChallengeTerm: Clone>( expr: Expr<ConstantExpr<F, ChallengeTerm>, Column>, offset_next_row: Option<usize> ) -> Self
source§impl<const N: usize, const D: usize, F: PrimeField> PartialEq<Sparse<F, N, D>> for Sparse<F, N, D>
impl<const N: usize, const D: usize, F: PrimeField> PartialEq<Sparse<F, N, D>> for Sparse<F, N, D>
Equality is defined as equality of the monomials.