pub struct Dense<F: PrimeField, const N: usize, const D: usize> { /* private fields */ }
Expand description
Represents a multivariate polynomial of degree less than D
in N
variables.
The representation is dense, i.e., all coefficients are stored.
The polynomial is represented as a vector of coefficients, where the index
of the coefficient corresponds to the index of the monomial.
A mapping between the index and the prime decomposition of the monomial is
stored in normalized_indices
.
Implementations§
source§impl<F: PrimeField, const N: usize, const D: usize> Dense<F, N, D>
impl<F: PrimeField, const N: usize, const D: usize> Dense<F, N, D>
pub fn new() -> Self
pub fn iter(&self) -> impl Iterator<Item = &F>
pub fn dimension() -> usize
pub fn from_coeffs(coeff: Vec<F>) -> Self
pub fn number_of_variables(&self) -> usize
pub fn maximum_degree(&self) -> usize
sourcepub fn compute_normalized_indices() -> Vec<usize>
pub fn compute_normalized_indices() -> Vec<usize>
Output example for N = 2 and D = 2:
- 0 -> 1
- 1 -> 2
- 2 -> 3
- 3 -> 4
- 4 -> 6
- 5 -> 9
pub fn increase_degree<const D_PRIME: usize>(&self) -> Dense<F, N, D_PRIME>
Trait Implementations§
source§impl<F: PrimeField, const N: usize, const D: usize> MVPoly<F, N, D> for Dense<F, N, D>
impl<F: PrimeField, const N: usize, const D: usize> MVPoly<F, N, D> for Dense<F, N, D>
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.
In addition to that, zeroes coefficients are added one every 10 monomials to be sure we do have some sparcity in the polynomial.
For now, the function is only used for testing.
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.
fn is_constant(&self) -> bool
fn double(&self) -> Self
fn mul_by_scalar(&self, c: 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
.