Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to let sympy simplify root(-1, 3) to -1?

Tags:

python

sympy

root(-1, 3).simplify()
(-1)**(1/3)//Output

This is not what I want, any way to simplify this to -1?

like image 728
Michael Yuxi Dong Avatar asked Feb 06 '23 05:02

Michael Yuxi Dong


1 Answers

Try

real_root(-1, 3)

It's referred to in the doc string of the root function too.

The reason is simple: sympy, like many symbolic algebra systems, takes the complex plane into account when calculating "the root". There are 3 complex numbers that, when raised to the power of 3, result in -1. If you're just interested in the real-valued root, be as explicit as you can.

like image 87
Oliver W. Avatar answered Feb 09 '23 00:02

Oliver W.