I have done some calculations in sympy, and the result is in the end a set of constants. One of them is inserted directly into the snippet below:
from sympy import *
expr = (18**(Rational(1, 3))/(6*(3 + sqrt(3)*I)**(Rational(1, 3)))
+ 12**(Rational(1, 3))*(3 + sqrt(3)*I)**(Rational(1, 3))/12)
print(expr.evalf())
print(expr.simplify())
This returns
0.56857902130163 + 0.e-22*I
18**(1/3)/(6*(3 + sqrt(3)*I)**(1/3)) + (36 + 12*sqrt(3)*I)**(1/3)/12
so the expression appears to be a real number, yet sympy cannot simplify it further. With pen and paper, I have simplified this to
cos(pi/18) / sqrt(3)
which agrees with the numerical value returned by evalf()
.
I have tried many of the different simplification functions, but none seem to be able to reduce the expression any further. Using substitutions like
expr.subs(3 + sqrt(3)*I, sqrt(12) * exp(I*pi/6))
improves the expression, but still sympy is unable to conclude that it is real. Using Euler's formula for substitution,
expr.subs(3 + sqrt(3)*I, sqrt(12) * (cos(pi/6) + I*sin(pi/6)))
sympy is finally able to conclude that the expression is real, but the expression itself explodes in size when printed (even if I attempt simplify
after the substitution).
Is there a better way to try to reduce this? I have many similar expressions for complex constants that I would like to know for sure are real (or not).
expr.conjugate().conjugate().simplify().trigsimp()
, which manages to output the result directly. However, for more complicated expressions this conjugate method does not work all that well, but it's still useful. – Initiatory