Unsure how to resolve two contradicting identities in finding the residue of a complex function In my complex analysis class I was solving the integral:
$$I=\int_{-\infty}^\infty\frac{\sin(2x)}{x^2+x+1}dx$$
using contour integration. I initially tried the integral over the semicircle of radius $R\rightarrow\infty$ in the upper half plane with the function $f(z)=\frac{\sin(2z)}{z^2+z+1}$.
I then showed the above integral is:
$$I=2\pi i \text{Res}\left(f,\frac{1}{2}(-1+\sqrt3)\right)
=\frac{2 \pi}{\sqrt3}\sin(-1+\sqrt3i)$$
Then I evaluated the rhs of this by in the following way:
$$\sin(x+iy)=\frac{e^{i(x+iy)}-e^{-i(x+iy)}}{2i}=\dots=\sin(x)\cosh(y)-i\cos(x)\sinh(y)$$
The issue is that this doesn't give the right answer, in fact it gives a non-real value which cannot be the case. Instead the correct method would have been to choose the function $f(z)=\frac{e^{2iz}}{z^2+z+1}$ and compare the imaginary parts of the integrals, but by that reasoning I also came up with another identity for:
$$\sin(x+iy)=\Im(e^{i(x+iy)})=e^{-y}\Im(e^{ix})=e^{-y}\sin(x)$$
Which would've given me the correct value for the integral. I am not sure why these two identities give different values, my best guess is that it is something to do with the choice of $f(z)$ changing the value of the contour integral. My two questions are: 1) do these two identities for $\sin(x+iy)$ actually contradict each other or is one of them incorrect 2) in the case of the integral why is the latter choice of $f$ the "correct" choice?
 A: First, I believe you dropped a negative sign in your identity:
$$\sin(x+iy)=\sin(x)\cos(iy)+\sin(iy)\cos(x)=\sin(x)\cosh(y)-i\cos(x)\sinh(y)$$
as $\sinh(y)=-i\sin(iy)$. Second, the issue with your contour integral is that the semicircular component of the integral does not vanish as $R\to\infty$: $\sin(2z)$ grows exponentially in magnitude as $\Im z\to\infty$, which is much clearer when you use the exponential identity for $\sin$. In particular, this means that the integral is not just the residue; it has some funny error term that I don't know how to compute.
On the other hand, using the function involving $\exp(2iz)$ gives you the much-needed property that $f$ decays far up in the upper half-plane. With the $z^2+z+1$ term in the denominator, you can then argue that the semicircular component vanishes (I think) as you send $R\to\infty$, and only then can you get the desired relationship with $I$ and the residue.
In general, contour integrals involving $\sin$ or $\cos$ should be a sign to integrate $\exp$ instead and then look at the real or imaginary parts. As seen here, the exponential growth of $\sin$ and $\cos$ in both imaginary directions is not fun to work with, and using $\exp$ usually gives you some sort of decay you can take advantage of.
