exponential to triangulation transformation in SymPy when simplified – a stubborn expression
I’ve been trying to simplify
exp(2*I*N) - 1)**2/((exp(2*I*N) - 1)**2 - 4*exp(2*I*N)*cos(N)**2)
The answer should be (sin N)^2, but the output is the same as the input.
I
tried .rewrite(cos)
and then simplification, trigsimp, extensions, and pretty much anything I could quickly spot from the help resources.
Solution
It would be more helpful to rewrite with exp
instead of cos
:
expr.rewrite(exp).simplify()
Returns -cos(2*N)/2
+ 1/
2, which is obviously equivalent to sin(N)**2
. Clean it up with
it
expr.rewrite(exp).simplify().trigsimp()
Get sin(N)**2
The old answer, which may still have value: you might think N
is true, so let’s declare it this way.
Given the complex mix of exponential and trigonometric functions, using as_real_imag()
may help separate the real and imaginary parts. Direct apps don’t do much other than put re(…) and im(…), so it is recommended to first rewrite and expand the square/product exponentially:
N = symbols('N', real=True)
expr = (exp(2*I*N) - 1)**2/((exp(2*I*N) - 1)**2 - 4*exp(2*I*N)*cos(N)**2)
result = [a.trigsimp() for a in expr.rewrite(cos).expand().as_real_imag()]
Result: [sin(N)**2, 0],
representing the real and imaginary parts of the expression. It can be recombined into an expression with result[0] + I*result[1].