Understanding Schönhage-Strassen algorithm (huge integer multiplication)

匆匆过客 提交于 2019-12-03 07:08:07

Chapter 4.3.3 of Knuth's TAOCP describes it and also has some FFT pseudocode in other chapters that could be used for this.

1000 digits is "small" for Schönhage-Strassen to be really worth using. You may have a look at the Toom Cook multiplication. gmpy is a Python wrapper to gmp providing these functions.

Don't reinvent the wheel. GMP has an excellent high-performance implementation of this algorithm and any algorithm written in pure Python will be at least 100 times slower, simply because Python is an interpreted language. Use gmpy to call out to GMP from your Python application. I'm also curious what application you're working on that requires multiplication of such large numbers - there might be a simpler way to handle your problem.

Also, as mentioned by other answers, "several 1000s digits long" is not nearly long enough to justify Schönhage-Strassen (you'd have to have at least 10000 decimal digits, probably more). Some variant of Toom-Cook like Toom-3 is normally used in this range. Again, don't write this yourself in Python - GMP's implementation is very carefully optimized.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!