When using solve
to compute the roots of a quadratic equation, SymPy returns expressions which could be simplified but I can't get it to simplify them. A minimal example looks like so:
from sympy import *
sqrt(-24-70*I)
Here, SymPy just returns sqrt(-24-70*I)
while Mathematica or Maple will answer with the equivalent of 5-7*I
.
I'm aware that there are two square roots, but this behavior entails that SymPy will, for example, return pretty complicated solutions from
z = symbols("z")
solve(z ** 2 + (1 + I) * z + (6 + 18 * I), z)
while, again, Maple and Mathematica will both happily give me the two Gaussian integers that solve this equation.
Is there an option or something that I'm missing?
Finding the square root of z is logically the same as solving the equation (x+I*y)**2 = z. So you can do just that:
The result is
[(-5, 7), (5, -7)]
For convenience, this can be wrapped as a function:
Now you can use
my_sqrt(-24-70*I)
and get-5 + 7*I
The same strategy helps in your example with a quadratic equation:
Output:
[(-3, 3), (2, -4)]