views:

802

answers:

2

Hi, 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.

+2  A: 

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.

Eric Bainville
+1, although I hope the OP is aware of that. The wikipedia entry he linked to explains this very early ("starts to outperform older methods [...] (10,000 to 40,000 decimal digits").
schnaader
sorry, i am aware of that, i meant to ask "several 1000s digit long". I will edit the question.
JPCosta
+2  A: 

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.

schnaader