Ask Your Question

Revision history [back]

First, you should notice that the factorization is done relative to the ring you considered. For example, since sqrt(2) is not integer nor rational, you will see that z^2-2 s already factorized in ZZ or QQ:

sage: realpoly.<z> = PolynomialRing(QQ)
sage: factor(z^2-2)
z^2 - 2
sage: realpoly.<z> = PolynomialRing(ZZ)
sage: factor(z^2-2)
z^2 - 2

Second, RR is a representation of real numbers by floating point approximation, hence, the factorization will be done here:

sage: realpoly.<z> = PolynomialRing(RR)
sage: factor(z^2-2)
(z - 1.41421356237310) * (z + 1.41421356237310)
sage: sol = z - factor(z^2-2)[0][0]
sage: sol
1.41421356237310
sage: sol in RR
True
sage: sol^2
2.00000000000000
sage: sol^2 == 2
False

The last equality is False because there is some very small rounding issue that make sol^2 not exactly equalt to 2 (but very close):

sage: RR(sol^2).exact_rational()
4503599627370497/2251799813685248

So, if you want to deal with exact values, you have to use exact rings. In your case, the appropriate one is the field of real algebraic numbers AA:

sage: realpoly.<z> = PolynomialRing(AA) sage: factor(z^2-2) (z - 1.414213562373095?) * (z + 1.414213562373095?) sage: sol = z - factor(z^2-2)[0][0] sage: sol^2 == 2 True sage: AA(sol) 1.414213562373095?

Here AA(sol) is a genuine (exact) algebraic number, the floating point approximation is only a way to show it on your screen, this is indicated by the ? at the end of the representation.

First, you should notice that the factorization is done relative to the ring you considered. For example, since sqrt(2) is not integer nor rational, you will see that z^2-2 s already factorized in ZZ or QQ:

sage: realpoly.<z> integerpoly.<z> = PolynomialRing(QQ)
sage: factor(z^2-2)
z^2 - 2
sage: realpoly.<z> rationalpoly.<z> = PolynomialRing(ZZ)
sage: factor(z^2-2)
z^2 - 2

Second, RR is a representation of real numbers by floating point approximation, hence, the factorization will be done here:

sage: realpoly.<z> = PolynomialRing(RR)
sage: factor(z^2-2)
(z - 1.41421356237310) * (z + 1.41421356237310)
sage: sol = z - factor(z^2-2)[0][0]
sage: sol
1.41421356237310
sage: sol in RR
True
sage: sol^2
2.00000000000000
sage: sol^2 == 2
False

The last equality is False because there is some very small rounding issue that make sol^2 not exactly equalt to 2 (but very close):

sage: RR(sol^2).exact_rational()
4503599627370497/2251799813685248

So, if you want to deal with exact values, you have to use exact rings. In your case, the appropriate one is the field of real algebraic numbers AA:

sage: realpoly.<z>

sage: algebraicpoly.<z> = PolynomialRing(AA)
sage: factor(z^2-2)
(z - 1.414213562373095?) * (z + 1.414213562373095?)
sage: sol = z - factor(z^2-2)[0][0]
sage: sol^2 == 2
True
sage: AA(sol)
1.414213562373095?

1.414213562373095?

Here AA(sol) is a genuine (exact) algebraic number, the floating point approximation is only a way to show it on your screen, this is indicated by the ? at the end of the representation.

First, you should notice that the factorization is done relative to the ring you considered. For example, since sqrt(2) is not integer nor rational, you will see that z^2-2 s already factorized in ZZ or QQ:

sage: integerpoly.<z> = PolynomialRing(QQ)
sage: factor(z^2-2)
z^2 - 2
sage: rationalpoly.<z> = PolynomialRing(ZZ)
sage: factor(z^2-2)
z^2 - 2

Second, RR is a representation of real numbers by floating point approximation, hence, the factorization will be done here:

sage: realpoly.<z> = PolynomialRing(RR)
sage: factor(z^2-2)
(z - 1.41421356237310) * (z + 1.41421356237310)
sage: sol = z - factor(z^2-2)[0][0]
sage: sol
1.41421356237310
sage: sol in RR
True
sage: sol^2
2.00000000000000
sage: sol^2 == 2
False

The last equality is False because there is some very small rounding issue that make sol^2 not exactly equalt to 2 (but very close):

sage: RR(sol^2).exact_rational()
4503599627370497/2251799813685248

So, if you want to deal with exact values, you have to use exact rings. In your case, the appropriate one is the field of real algebraic numbers AA:

sage: algebraicpoly.<z> = PolynomialRing(AA)
sage: factor(z^2-2)
(z - 1.414213562373095?) * (z + 1.414213562373095?)
sage: sol = z - factor(z^2-2)[0][0]
sage: sol^2 == 2
True
sage: AA(sol)
1.414213562373095?

Here AA(sol) is a genuine (exact) algebraic number, the floating point approximation is only a way to show it on your screen, this is indicated by the ? at the end of the representation.

There are plans to use some Galois theory to represent some algebraic numbers with radicals (to see sqrt(2) instead of 1.414213562373095?). But it is not done yet, see this trac ticket.