G
G
Griboks2017-08-18 10:19:52
Mathematics
Griboks, 2017-08-18 10:19:52

Polynomial multiplication?

It is necessary to multiply two polynomials of the form a0*b^0+a1*b^1+... in C#. They can be of arbitrary length. Stored as an array of coefficients. The coefficients themselves can be from 1 to ulong.MaxValue (sharp does not allow more) - integers. You can also use only system and collections.
The problem is that if you multiply stupidly, memory overflow is possible.
How to multiply polynomials without memory error and what is the fastest algorithm?
Ps
This is not homework or term paper!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sakhno, 2017-08-18
@Punk_Joker

May help
https://habrahabr.ru/post/207754/

X
x67, 2017-08-18
@x67

(a1+a2+...+an)*(b1+b2+...+bm)=b1*(a1+...+an)+b2*(a1+...+an)+...+bm*(a1+...+an)

in a polynomial an=kn*x^n, for example, then:
bm*an=kbm*kan*x^(n+m)is the simplest cell of the operation, so to speak. bm*(a1+...+an)consists of n such cells, and their sum will be a cell of the second level. There will be m cells of the second level , and their sum is your result, let's call it a cell of the third level. Actually, you need to incrementally count the cell of the second level, and then incrementally add it to the cell of the third level. Then the limit of the required memory will tend not to m*n+c , but to c , where c is a constant

V
Vladimir Olohtonov, 2017-08-18
@sgjurano

The Fast Fourier Transform will do this in O(nlogn).
https://m.habrahabr.ru/post/113642/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question