Ask Your Question

Revision history [back]

It depends what you mean by "same": There are 3 complex cube roots of -1, and when you input something like (-1)^(1/3), sage chooses one of them:

sage: CC((-1)^(1/3))
0.500000000000000 + 0.866025403784439*I
sage: CC(-1^(1/3))
-1.00000000000000

sage: var('t')
t
sage: p = (t^(3) + 1)
sage: p.roots()
[(1/2*I*(-1)^(1/3)*sqrt(3) - 1/2*(-1)^(1/3), 1), (-1/2*I*(-1)^(1/3)*sqrt(3) - 1/2*(-1)^(1/3), 1), ((-1)^(1/3), 1)]
sage: p.roots(ring=CC)
[(-1.00000000000000, 1), (0.500000000000000 - 0.866025403784439*I, 1), (0.500000000000000 + 0.866025403784439*I, 1)]
sage: p.roots(ring=RR)
[(-1.00000000000000, 1)]

So this is probably the reason your comparison returns False:

sage: CC((-2)^(1/3))
0.629960524947437 + 1.09112363597172*I
sage: CC(-2^(1/3))
-1.25992104989487

Of course if you choose the Real cube root of -1, then your comparison should return True. How you decide to work with this probably depends on the problem you have in mind -- can you update with some more details?

It depends what you mean by "same": There are 3 complex cube roots of -1, and when you input something like (-1)^(1/3), sage chooses one of them:

sage: CC((-1)^(1/3))
0.500000000000000 + 0.866025403784439*I
sage: CC(-1^(1/3))
-1.00000000000000

sage: var('t')
t
sage: p = (t^(3) + 1)
sage: p.roots()
[(1/2*I*(-1)^(1/3)*sqrt(3) - 1/2*(-1)^(1/3), 1), (-1/2*I*(-1)^(1/3)*sqrt(3) - 1/2*(-1)^(1/3), 1), ((-1)^(1/3), 1)]
sage: p.roots(ring=CC)
[(-1.00000000000000, 1), (0.500000000000000 - 0.866025403784439*I, 1), (0.500000000000000 + 0.866025403784439*I, 1)]
sage: p.roots(ring=RR)
[(-1.00000000000000, 1)]

So this is probably the reason your comparison returns False:

sage: CC((-2)^(1/3))
0.629960524947437 + 1.09112363597172*I
sage: CC(-2^(1/3))
-1.25992104989487

Of course if you choose the Real cube root of -1, then your comparison should return True. How you decide to work with this probably depends on the problem you have in mind -- can you update with some more details?

For example, could you take absolute values before taking fractional powers, and then check whether or not the signs agree?

sage: m = 2
sage: n = -2
sage: (abs(m))^(1/3) == (abs(n))^(1/3) and -1*sgn(m) == sgn(n)