This crate implements traits and implementations for polynomials, FFT-friendly subsets of a field (dubbed "domains"), and FFTs for these domains.
Polynomials
The polynomial
module provides the following traits for defining polynomials in coefficient form:
Polynomial
: Requires implementors to support common operations on polynomials, such asAdd
,Sub
,Zero
, evaluation at a point, degree, etc, and defines methods to serialize to and from the coefficient representation of the polynomial.DenseUVPolynomial
: Specifies that aPolynomial
is actually a univariate polynomial.DenseMVPolynomial
: Specifies that aPolynomial
is actually a multivariate polynomial.
This crate also provides the following data structures that implement these traits:
univariate/DensePolynomial
: Represents degreed
univariate polynomials via a list ofd + 1
coefficients. This struct implements theDenseUVPolynomial
trait.univariate/SparsePolynomial
: Represents degreed
univariate polynomials via a list containing all non-zero monomials. This should only be used when most coefficients of the polynomial are zero. This struct implements thePolynomial
trait (but not theDenseUVPolynomial
trait).multivariate/SparsePolynomial
: Represents multivariate polynomials via a list containing all non-zero monomials.
This crate also provides the univariate/DenseOrSparsePolynomial
enum, which allows the user to abstract over the type of underlying univariate polynomial (dense or sparse).
Example
use ;
use Fq;
// Create a multivariate polynomial in 3 variables, with 4 terms:
// f(x_0, x_1, x_2) = 2*x_0^3 + x_0*x_2 + x_1*x_2 + 5
let poly = from_coefficients_vec;
assert_eq!;
Evaluations
The evaluations
module provides data structures to represent univariate polynomials in lagrange form.
univariate/Evaluations
Represents a univariate polynomial in evaluation form, which can be used for FFT.
The evaluations
module also provides the following traits for defining multivariate polynomials in lagrange form:
multivariate/multilinear/MultilinearExtension
Specifies a multilinear polynomial evaluated over boolean hypercube.
This crate provides some data structures to implement these traits.
-
multivariate/multilinear/DenseMultilinearExtension
Represents multilinear extension via a list of evaluations over boolean hypercube. -
multivariate/multilinear/SparseMultilinearExtension
Represents multilinear extension via a list of non-zero evaluations over boolean hypercube.
Example
use Fq;
use ;
use ;
use One;
// Create a multivariate polynomial in 3 variables:
// f(x_0, x_1, x_2) = 2*x_0^3 + x_0*x_2 + x_1*x_2
let f = from_coefficients_vec;
// g is the multilinear extension of f, defined by the evaluations of f on the Boolean hypercube:
// f(0, 0, 0) = 2*0^3 + 0*0 + 0*0 = 0
// f(1, 0, 0) = 2*1^3 + 0*0 + 0*0 = 2
// ...
// f(1, 1, 1) = 2*1^3 + 1*1 + 1*1 = 4
let g: = from_evaluations_vec;
// when evaluated at any point within the Boolean hypercube, f and g should be equal
let point_within_hypercube = &vec!;
assert_eq!;
// We can also define a MLE g'(x_0, x_1, x_2) by providing the list of non-zero evaluations:
let g_prime: = from_evaluations;
// at any random point (X0, X1, X2), g == g' with negligible probability, unless they are the same function
let random_point = &vec!;
assert_eq!;
Domains
TODO