I've been trying to solve this integral
$$\int \frac{1}{\sin^2(x)+\sin(x)+1} dx$$
First, use the Half-Angle Tangent/Weierstrass Substitution:
$$2\int \frac{1+t^2}{t^4+2t^3+6t^2+2t+1} dt$$
Factor the denominator:
$$2\int \frac{1+t^2}{(t^2+(1+\sqrt3i)t+1)(t^2+(1-\sqrt3i)t+1)} dt$$
Use Partial Fractions and split the integral:
$$\frac{i}{3}\int \frac{1}{t^2+(1+\sqrt3i)t+1} dt - \frac{i}{3}\int \frac{1}{t^2+(1-\sqrt3i)t+1} dt$$
Complete the square:
$$\frac{i}{3}\int \frac{1}{(t+0.5(1+\sqrt3i))^2+\frac{-\sqrt3i+3}{2}} dt - \frac{i}{3}\int \frac{1}{(t+0.5(1-\sqrt3i))^2+\frac{\sqrt3i+3}{2}} dt$$
Use Trigonometric Substitution. Substituting everything back in, the final answer is:
Which is wrong. What went wrong? The derivative should give $$\frac{1}{\sin^2(x)+\sin(x)+1}$$
It'd be simpler to express the integrand in terms of cosine's and then apply the Weierstrass Substitution. So, let $t=\frac\pi2-x$ and then substitute $\cos t =\frac{1-u^2}{1+u^2}$, along with $dt =\frac{2du}{1+u^2}$,
$$I=\int \frac{dx}{\sin^2x+\sin x+1}=-\int \frac{dt}{\cos^2t+\cos t+1}= -2\int \frac{u^2+1}{u^4+3} du$$
Then, decompose the integrand with $p=-1-\frac{1}{\sqrt3}$ and $q=-1+\frac{1}{\sqrt3}$,
$$I = p\int \frac{u^2+\sqrt3}{u^4+3}+q\int \frac{u^2-\sqrt3}{u^4+3}$$ $$=p\int \frac{d(u-\frac{\sqrt3}{u})}{(u-\frac{\sqrt3}{u})^2+2\sqrt3} +q\int \frac{d(u+\frac{\sqrt3}{u})}{(u+\frac{\sqrt3}{u})^2-2\sqrt3}$$ $$=-\frac{\sqrt3+1}{\sqrt{6\sqrt3}}\tan^{-1}\left(\frac{u^2-\sqrt3}{\sqrt{2\sqrt3}u}\right) +\frac{\sqrt3-1}{\sqrt{6\sqrt3}}\tanh^{-1}\left(\frac{u^2+\sqrt3}{\sqrt{2\sqrt3}u}\right)+C$$