pub struct SparsePolynomial<F: Field, T: Term> {
    pub num_vars: usize,
    pub terms: Vec<(F, T)>,
}
Expand description

Stores a sparse multivariate polynomial in coefficient form.

Fields

num_vars: usize

The number of variables the polynomial supports

terms: Vec<(F, T)>

List of each term along with its coefficient

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
The general deserialize method that takes in customization flags.
The general serialize method that takes in customization flags.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Returns the number of variables in self

Outputs an l-variate polynomial which is the sum of l d-degree univariate polynomials where each coefficient is sampled uniformly at random.

Constructs a new polynomial from a list of tuples of the form (coeff, Self::Term)

Examples
use ark_poly::{
    polynomial::multivariate::{SparsePolynomial, SparseTerm, Term},
    DenseMVPolynomial, Polynomial,
};
use ark_test_curves::bls12_381::Fq;

// Create a multivariate polynomial in 3 variables, with 4 terms:
// 2*x_0^3 + x_0*x_2 + x_1*x_2 + 5
let poly = SparsePolynomial::from_coefficients_vec(
    3,
    vec![
        (Fq::from(2), SparseTerm::new(vec![(0, 3)])),
        (Fq::from(1), SparseTerm::new(vec![(0, 1), (2, 1)])),
        (Fq::from(1), SparseTerm::new(vec![(1, 1), (2, 1)])),
        (Fq::from(5), SparseTerm::new(vec![])),
    ],
);

Returns the terms of a self as a list of tuples of the form (coeff, Self::Term)

The type of the terms of self
Constructs a new polynomial from a list of tuples of the form (coeff, Self::Term)
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Returns the total degree of the polynomial

Examples
use ark_poly::{
    polynomial::multivariate::{SparsePolynomial, SparseTerm},
    DenseMVPolynomial, Polynomial,
};
use ark_std::test_rng;
use ark_test_curves::bls12_381::Fq;

let rng = &mut test_rng();
// Create a multivariate polynomial of degree 7
let poly: SparsePolynomial<Fq, SparseTerm> = SparsePolynomial::rand(7, 2, rng);
assert_eq!(poly.degree(), 7);

Evaluates self at the given point in Self::Point.

Examples
use ark_poly::{
    polynomial::multivariate::{SparsePolynomial, SparseTerm, Term},
    DenseMVPolynomial, Polynomial,
};
use ark_ff::UniformRand;
use ark_std::test_rng;
use ark_test_curves::bls12_381::Fq;

let rng = &mut test_rng();
let poly = SparsePolynomial::rand(4, 3, rng);
let random_point = vec![Fq::rand(rng); 3];
// The result will be a single element in the field.
let result: Fq = poly.evaluate(&random_point);
The type of evaluation points for this polynomial.
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more

Returns the zero polynomial.

Checks if the given polynomial is zero.

Sets self to the additive identity element of Self, 0.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.