curv
curv copied to clipboard
suggested additions to Polynomial
I am working with Polynomial. As part of my work I am required to manipulate them in certain ways. Here are a few suggestions for new functions to add to Polynomial (If I will have more ideas as I continue working I will add them here):
- polynomial multiplication : requires fft
- generate a Polynomial of some degree N (provided as input) from a partial set of coefficients (the rest are zero) given at a specific locations
- allow to define a polynomial from a vector of BigInts
Great suggestions, @omershlo!
- Polynomial multiplication could be easily added. I assume FFT is not difficult to implement.
- What if I expose this method:
Would this allow to achieve what you want? Basically, you can sample a random polynomialimpl<E> Polynomial<E> { pub fn coefficients_mut(&mut self) -> &mut [Scalar<E>] { ... } }Polynomial::sample_exact(), and then you can overwrite its coefficients, eg. :polynomial.coefficients_mut()[3] = Scalar::from(4) - That's a reasonable suggestion. To allow construction from bigints, I would change
from_coefficientsconstructor to be:
So this method will work with bothimpl<E> Polynomial<E> { pub fn from_coefficients<S>(coefficients: impl IntoIterator<Item = S>) -> Self where Scalar<E>: From<S> { ... } }Vec<Scalar<E>>andVec<Bigint>. But this changes public API and requires major version bump. For now, it may be sufficient to add constructorfrom_bigint_coefficientsthat takesVec<Bigint>.
more:
- return a coefficient in a specific index
- trim leading zero coefficients
- compute
a % bfora, bpolynomials - compute polynomial division