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

Function poly_from_given_updates

vb_accumulator/src/batch_utils.rs:43–59  ·  view source on GitHub ↗

Create a polynomial with given points in `updates` as: `(updates[0]-x) * (updates[1]-x) * (updates[2] - x)...(updates[last] - x)`

(updates: &[F])

Source from the content-addressed store, hash-verified

41/// Create a polynomial with given points in `updates` as:
42/// `(updates[0]-x) * (updates[1]-x) * (updates[2] - x)...(updates[last] - x)`
43fn poly_from_given_updates<F: PrimeField>(updates: &[F]) -> DensePolynomial<F> {
44 if updates.is_empty() {
45 return DensePolynomial::zero();
46 }
47
48 let minus_one = -F::one();
49
50 // [(updates[0]-x), (updates[1]-x), (updates[2] - x), ..., (updates[last] - x)]
51 let terms = cfg_into_iter!(updates)
52 .map(|i| DensePolynomial::from_coefficients_slice(&[*i, minus_one]))
53 .collect::<Vec<_>>();
54
55 // Product (updates[0]-x) * (updates[1]-x) * (updates[2] - x)...(updates[last] - x)
56 multiply_many_polys(terms)
57 // Note: Using multiply operator from ark-poly is orders of magnitude slower than naive multiplication
58 // x_i.into_iter().reduce(|a, b| &a * &b).unwrap()
59}
60
61// Polynomials as described in section 3 of the paper
62

Callers 2

generateMethod · 0.85

Calls 3

multiply_many_polysFunction · 0.85
mapMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected