Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to multiply several 1000s digits long integers as efficiently as possible in Python. The numbers are read from a file.

I am trying to implement the Schönhage-Strassen algorithm for integer multiplication, but I am stuck on understanding the definition and mathematics behind it, specially the Fast Fourier Transform.

Any help to understand this algorithm, like a practical example or some pseudo-code would be highly appreciated.

like image 905
JPCosta Avatar asked May 14 '09 07:05

JPCosta


2 Answers

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.

like image 111
schnaader Avatar answered Sep 18 '22 13:09

schnaader


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.

like image 38
Eric Bainville Avatar answered Sep 18 '22 13:09

Eric Bainville