Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The first thing to realize is that the form the factorization should take depends on the base field for the polynomial. The classical example is the polynomial x^2+1. It can be factorized as (x+i)(x-i) but only over the complex numbers. It seems that most of the symbolic mathematics software chooses to work over the real numbers and does not factorize x^2+1. This is of course an arbitrary choice and is not what Sage is doing. This is one reason why you must specify a base field when defining a polynomial.

In your case, the answer is not exact because the field RR is not exact. Here's what the documentation for RR (obtainable by typing RR?) says:

An approximation to the field of real numbers using floating point numbers with any specified precision. Answers derived from calculations in this approximation may differ from what they would be if those calculations were performed in the true field of real numbers. This is due to the rounding errors inherent to finite precision calculations.

Instead of using RR, you could use the algebraic numbers QQbar.

realpoly.<z> = PolynomialRing(QQbar)
(z - 1.414213562373095?) * (z + 1.414213562373095?)

Notice the question mark in the decimal expansion. It indicates that the expansion continues but since it may be very long or infinite can not be fully displayed.

The first thing to realize is that the form the factorization should take depends on the base field for the polynomial. The classical example is the polynomial x^2+1. It can be factorized as (x+i)(x-i) but only over the complex numbers. It seems that most of the symbolic mathematics software chooses to work over the real numbers and does not factorize x^2+1. This is of course an arbitrary choice and is not what Sage is doing. This is one reason why you must specify a base field when defining a polynomial.

In your case, the answer is not exact because the field RR is not exact. Here's what the documentation for RR (obtainable by typing RR?) says:

An approximation to the field of real numbers using floating point numbers with any specified precision. Answers derived from calculations in this approximation may differ from what they would be if those calculations were performed in the true field of real numbers. This is due to the rounding errors inherent to finite precision calculations.

Instead of using RR, you could use the algebraic numbers QQbar.

realpoly.<z> = PolynomialRing(QQbar)
(z - 1.414213562373095?) * (z + 1.414213562373095?)

Notice the question mark in the decimal expansion. It indicates that the expansion continues but since it may be very long or infinite can not be fully displayed.

I'm not completely sure how to make Sage show the output you would like to get, but of course this is only going to work in simple situations where the roots of the polynomials can be written using radicals. The vast majority of algebraic numbers are not of this type.

Maybe Sage should have a field of numbers which can be written using radicals, then you could factor your polynomial over that field which, it seems to me, is what you would like to get. It seems to me like this might be a good field to have, but it doesn't seem to be implemented at this point.