MCPcopy Create free account
hub / github.com/docknetwork/crypto / multiply_poly

Function multiply_poly

utils/src/poly.rs:10–23  ·  view source on GitHub ↗

Naive multiplication (n^2) of 2 polynomials defined over prime fields Note: Using multiply operator from ark-poly is orders of magnitude slower than naive multiplication

(
    left: &DensePolynomial<F>,
    right: &DensePolynomial<F>,
)

Source from the content-addressed store, hash-verified

8/// Naive multiplication (n^2) of 2 polynomials defined over prime fields
9/// Note: Using multiply operator from ark-poly is orders of magnitude slower than naive multiplication
10pub fn multiply_poly<F: Field>(
11 left: &DensePolynomial<F>,
12 right: &DensePolynomial<F>,
13) -> DensePolynomial<F> {
14 let mut product = (0..(left.degree() + right.degree() + 1))
15 .map(|_| F::zero())
16 .collect::<Vec<_>>();
17 for i in 0..=left.degree() {
18 for j in 0..=right.degree() {
19 product[i + j] += left.coeffs[i] * right.coeffs[j];
20 }
21 }
22 DensePolynomial::from_coefficients_vec(product)
23}
24
25/// Multiply given polynomials together
26pub fn multiply_many_polys<F: Field>(polys: Vec<DensePolynomial<F>>) -> DensePolynomial<F> {

Callers 3

generateMethod · 0.85
multiply_many_polysFunction · 0.85

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected