Home > Back-end >  Sagemath: Is there a simple way to factor a polynomial over C & have the roots appear in radical ins
Sagemath: Is there a simple way to factor a polynomial over C & have the roots appear in radical ins

Time:04-23

In Mathematica, if I do the following

Roots[x^3 - 2 == 0, x]

I get

x=(-1)^(2/3) 2^(1/3) || x=(-2)^(1/3) || x = 2^(1/3)

I want to do something similar in Sagemath

sage: F1.<x> = PolynomialRing(CC)
sage: f=x^3 - 2
sage: f.roots()
[(1.25992104989487, 1),
 (-0.629960524947437 - 1.09112363597172*I, 1),
 (-0.629960524947437   1.09112363597172*I, 1)]

Is there a way in sagemath to see it either as radicals or as ^(1/n) or something similar?

CodePudding user response:

Is there a reason you need this computation to take place within a complex polynomial ring? I'm not an expert in computer algebra and I'm sure I'm oversimplifying or something, but I believe that is the root of this behavior; Sage treats the complex numbers as an inexact field, meaning that it stores the coefficients a and b in a b*I as (default 53-bit) floats rather than as symbolic constants. Basically, what you are asking for is a type error, any object defined over the ComplexField (or ComplexDoubleField, or presumably any inexact field) will have floats as its coefficients. On the other hand, the corresponding behavior in the symbolic ring (where the token x lives by default) seems to be exactly what you are looking for; more specifically, evaluating var("t"); solve(t^3-2==0,t) returns [t == 1/2*I*sqrt(3)*2^(1/3) - 1/2*2^(1/3), t == -1/2*I*sqrt(3)*2^(1/3) - 1/2*2^(1/3), t == 2^(1/3)].

  • Related