In SAGE, what function factors a polynomial whose coefficients are parameters?

2k Views Asked by At

In SAGE the function "factor" will factorize elementary polynomials with coefficients in $\Bbb Q$. For example:

x,y = var('x,y')

poly = x^3-y^2*x

factor(poly)

SAGE: x*(x-y)*(x+y)

Apparently, "factor" will also handle any univariate polynomial with roots in $\Bbb Q$ (I applied factor to things like $\prod_{i\in I}(x-i)$, for subsets $I\subset \Bbb Q$ with cardinality up to 10.) I assume the function factor just clears the denominators and then tries any factor of the constant coefficient as a root, for as soon as I wrote some algebraic number like $\sqrt 3$ for one of the $i$'s, "factor" refused to do anything to my expanded expression. To be precise, it still factored $(x-1)(x-\sqrt 3)$, but neither $x^2-2$ nor $(x-1)(x-\sqrt 3)(x-2)$.

This is very frustrating since very often I have some small degree polynomial that I want to factor whose coefficients depend on several parameters. Is there another function in SAGE that will just plug these other parameters into the well-known formulas for the roots of quadratic, cubic and quartic and factor my polynomial for me? I know the alternative of using solve, but it has the draw back that I need to copy and paste each one of the roots and rewrite my polynomial.

1

There are 1 best solutions below

1
On

In maxima (the algebra/calculus motor in SAGE) what I've done is to collect the roots in an array and then redo the polynomial as the product of its factors. This is messy to write as a function, but then you can just use it.