An optimized polynomial multiplication

Overview
Polynomials in one variable are functions like x^3+16x^2-17 and x^4+4x^3+16x^2+4x+2. One algorithm often carried out with polynomials is to multiply them. This is done by taking the sum over all terms ax^i*bx^j where ax^i occurs in the first and bx^j in the second polynomial. For example, x^2+1 multiplied with x^3+x^2+8 is x^5+x^4+x^3+9x^2+8 where the 9x^2 is the sum of two terms x^2*8 and 1*x^2.
Mathematicians have investigated how to multiply polynomials under certain constraints. One of them is the assumption that multiplications of numbers are expensive while additions are cheap. This would in particluar be true for multidigit numbers, where the algorithm for multiplication is quadratic while the addition algorithm is linear, although here better algorithms than quadratic ones are known. For this reason, the following homework has the goal to multiply polynomials p and q such that The ideal algorithm assumes that all numerical operations are precise, this is of course not true and therefore this program contains some rounding at the end.

The implemented algorithm
The idea is the following: Task
The task is to complete the existing implementation such that the above outlined algorithm runs. Tests are carried out automatically on reloading the page.