# Algorithm to polynomial multiplication

I need to create algorithm to polynomial multiplication , but I don't know how to do it. Please for help.

edit retag close merge delete

1

Some questions:

1. How is that related to SageMath?
2. What have you tried so far?
3. Did you notice that SageMath already has algorithms for polynomial multiplication?
4. Is that homework?

I know that SageMath has algorithms for polynomial multiplication, but I must write it myself. Yes, it is my homework I wrote something like this, but in the end should be showed polynomial, not only factors. I don't know how to do it. Could you help me? Please

W1=[1,2,3,4] W2=[5,4,3,2,1] W3=[]

for i in range(0,len(W1)+len(W2)-1): W3.append(0)

for i in range(0,len(W1)): for j in range(0,len(W2)): W3[i+j]=W3[i+j]+W1[i]*W2[j]

print(W3)

Your algorithm is fine for multiplying the polynomials. What you get is the list of coefficients. (I don't know what you mean by "factors".) If you want a polynomial from this list, you have to build a polynomial ring and get the polynomial from the list of coefficients in the following way:

sage: R = PolynomialRing(ZZ, 'x')
sage: L = [1, 2, 3, 4, 5]
sage: p = R(L)
sage: p
5*x^4 + 4*x^3 + 3*x^2 + 2*x + 1