# Univariate Polynomial Multiplication

 1 What algorithms does sage use for univariate polynomial multiplication? In particular, I am curious about the algorithm used for multiplication over finite fields and polynomials with coefficients in Z or Q. More generally, is there an easy way to look under the hood and trace down the exact functions being called in the event I have a question like this again? asked Jul 21 '11 Anonymous

 2 For integer polynomials, FLINT is used to do the multiplication. We look at the _mul_ method since in Sage, __mul__ is used to handle coercion and then dispatches to _mul_. sage: R. = ZZ[] sage: x._mul_?? ... cpdef RingElement _mul_(self, RingElement right): r""" Returns self multiplied by right. EXAMPLES:: sage: R. = PolynomialRing(ZZ) sage: (x - 2)*(x^2 - 8*x + 16) x^3 - 10*x^2 + 32*x - 32 """ cdef Polynomial_integer_dense_flint x = self._new() sig_on() fmpz_poly_mul(x.__poly, self.__poly, (right).__poly) sig_off() return x  You can do a similar check to see that FLINT's fmpq_poly_mul is used for polynomials over the rationals. The univariate polynomials over finite fields different based on the size of the field. For example, for small primes, FLINT is used: sage: R. = GF(next_prime(2^5))[] sage: type(x)  But for larger primes, NTL is used: sage: R. = GF(next_prime(2^64))[] sage: type(x)  To find out the exact algorithm / heuristics used, you'll need to delve into those packages. posted Jul 21 '11 Mike Hansen 3880 ● 23 ● 46 ● 84
 2 This is a pretty broad question, and I'm certainly not an expert in this area, but maybe I can get you pointed in the right direction. It's easy to look under the hood, but maybe (depending on your experience) not so easy to pin down exactly what's being called. Here's how I proceeded: sage: R. = PolynomialRing(ZZ) # make the kind of ring I want to check sage: f = R.random_element(); f # and an element 3*t^2 + t + 65  See what kind of objects they are: sage: type(R) sage: type(f)  You can browse these source files in your local sage install at \$SAGE_ROOT/devel/sage-main/sage/rings/polynomial, or you can browse them online (linked from the "Source Code" section of the main Sage Development page). Of course it helps if you know where to look; multiplication is implemented (often, including this case) by the _mul_ method, so you can check it directly with sage: f._mul_??  This will display the relevant part of the source code. There, you will see that this particular multiplication is implemented by fmpz_poly_mul -- this is a FLINT method, and you'd have to look at the FLINT source if you want to go further in this hunt . . . A similar procedure will, I think, get you started with finding the implementations of the other multiplication algorithms you mentioned. Good luck! posted Jul 21 '11 niles 3725 ● 7 ● 45 ● 104 http://nilesjohnson.net/ Oh, I shouldn't have taken so long to write this answer! niles (Jul 21 '11)
 0 Thank you for the quick help. This is exactly what I was looking for. posted Jul 21 '11 mathmajor 1 ● 1 ● 3