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

Function poly_from_roots

utils/src/poly.rs:59–71  ·  view source on GitHub ↗

Create a polynomial from given `roots` as `(x-roots[0])*(x-roots[1])*(x-roots[2])*..`

(roots: &[F])

Source from the content-addressed store, hash-verified

57
58/// Create a polynomial from given `roots` as `(x-roots[0])*(x-roots[1])*(x-roots[2])*..`
59pub fn poly_from_roots<F: Field>(roots: &[F]) -> DensePolynomial<F> {
60 if roots.is_empty() {
61 return DensePolynomial::zero();
62 }
63
64 // [(x-roots[0]), (x-roots[1]), (x-roots[2]), ..., (x-roots[last])]
65 let terms = cfg_into_iter!(roots)
66 .map(|i| DensePolynomial::from_coefficients_slice(&[-*i, F::one()]))
67 .collect::<Vec<_>>();
68
69 // Product (x-roots[0]) * (x-roots[1]) * (x-roots[2]) * ... * (x-roots[last])
70 multiply_many_polys(terms)
71}

Callers 4

open_subset_uncheckedMethod · 0.85
verifyMethod · 0.85
characteristic_polyFunction · 0.85

Calls 3

multiply_many_polysFunction · 0.85
mapMethod · 0.80
is_emptyMethod · 0.45

Tested by 1

characteristic_polyFunction · 0.68