Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster polynomial multiplication #45

Open
jonasvanderschaaf opened this issue Aug 1, 2021 · 3 comments
Open

Faster polynomial multiplication #45

jonasvanderschaaf opened this issue Aug 1, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@jonasvanderschaaf
Copy link

The current polynomial multiplication has a runtime of O(n^2). This is fine for some cases (especially lower degree polynomials), but is suboptimal, as it is relatively easy to reduce the runtime using a Fast Fourier Transformation to O(n log n). This would be a considerable speedup for higher degree polynomials.

I think it would be best to perhaps use the currrent algorithm for polynomials of low degree, as it is undoubtedly faster for these kinds, but for higher degree polynomials switch to the more complex, but asymptotically faster FFT. The switching point should of course be determined by the implementation details.

If this is something worth considering, I think there would be three ways to go about using this method:

  1. Use an existing FFT crate which is significantly faster than what would be used in this crate, which in turn significantly improve the runtime of many things using polynomials.
  2. Create a custom implementation of the FFT algorithm. This would mean that the crate has less dependencies, and would therefore be more portable.
  3. You could also possibly use a feature flag to indicate use of an external FFT library, which would include the best of both worlds: It would allow for people who need an efficient implementation to use the external library for the multiplication, and those who care more about portability to use the slower version.

If you think that the second option sounds appealing, I would be willing to write an implementation of the algorithm.

@Axect
Copy link
Owner

Axect commented Aug 2, 2021

@jonasvanderschaaf Thanks for great suggestion!
I did not consider an effective algorithm for polynomial multiplication. Thank you again for your good point.
I think the second idea is really attractive if possible. If you implement such an algorithm, than I'll definitely merge it with the next version.

@Axect Axect added the enhancement New feature or request label Aug 2, 2021
@Axect Axect added this to the Ver 0.30 milestone Aug 2, 2021
@jonasvanderschaaf
Copy link
Author

To implement a Fast Fourier Transform, I would need to have access to some implementation of complex numbers. This would probably mean that the addition of this feature would have to be moved to version 0.31, as #35 (complex number support) is also scheduled for this version.

@Axect Axect modified the milestones: Ver 0.30, Ver 0.31 Aug 3, 2021
@Axect
Copy link
Owner

Axect commented Aug 3, 2021

Oh, sorry for my mistake. I fixed it.

@Axect Axect removed this from the Ver 0.31 milestone Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants