curv icon indicating copy to clipboard operation
curv copied to clipboard

suggested additions to Polynomial

Open omershlo opened this issue 4 years ago • 2 comments

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

omershlo avatar Sep 26 '21 14:09 omershlo

Great suggestions, @omershlo!

  1. Polynomial multiplication could be easily added. I assume FFT is not difficult to implement.
  2. What if I expose this method:
    impl<E> Polynomial<E> { 
        pub fn coefficients_mut(&mut self) -> &mut [Scalar<E>] { ... }
    }
    
    Would this allow to achieve what you want? Basically, you can sample a random polynomial Polynomial::sample_exact(), and then you can overwrite its coefficients, eg. : polynomial.coefficients_mut()[3] = Scalar::from(4)
  3. That's a reasonable suggestion. To allow construction from bigints, I would change from_coefficients constructor to be:
    impl<E> Polynomial<E> { 
        pub fn from_coefficients<S>(coefficients: impl IntoIterator<Item = S>) -> Self
        where Scalar<E>: From<S>
        { ... }
    }
    
    So this method will work with both Vec<Scalar<E>> and Vec<Bigint>. But this changes public API and requires major version bump. For now, it may be sufficient to add constructor from_bigint_coefficients that takes Vec<Bigint>.

survived avatar Sep 27 '21 07:09 survived

more:

  • return a coefficient in a specific index
  • trim leading zero coefficients
  • compute a % b for a, b polynomials
  • compute polynomial division

omershlo avatar Oct 03 '21 14:10 omershlo