The notation CC
(as well for RR
) is misleading: CC
does not corresponds to genuine complex numbers (unlike for NN
, ZZ
, QQ
, AA
, QQbar
), but only refers to floating-point approximation of complex numbers.
In your case, if you want exact computations, you should work on the algebraic field QQbar
instead of CC
:
sage: QQbar
Algebraic Field
sage: realpoly.<x> = PolynomialRing(QQbar)
sage: factor(x^2-2,x)
(x - 1.414213562373095?) * (x + 1.414213562373095?)
This looks the same, but you should notice the question mark after 1.414213562373095
, which means that 1.414213562373095?
is only a representation of some algebraic number. You can check that it is really sqrt(2)
as follows:
sage: s2 = x-factor(x^2-2,x)[0][0]
sage: s2
1.414213562373095?
sage: s2 == sqrt(QQbar(2))
True
sage: QQbar(s2).as_number_field_element()
(Number Field in a with defining polynomial y^2 - 2,
a,
Ring morphism:
From: Number Field in a with defining polynomial y^2 - 2
To: Algebraic Real Field
Defn: a |--> 1.414213562373095?)