<s>[INST] Find steps to solve : $\int_0^t \frac{x \cos u - x^2}{1 - 2x \cos u + x^2} \, du $ $$ \int_0^t \frac{x \cos u - x^2}{1 - 2x \cos u + x^2} \, du\quad\text{with}\quad x \in ]-1,1[ $$

 $$ \int_0^t \frac{x \cos u - x^2}{1 - 2x \cos u  + x^2} \, du = \arctan \left( \frac{x \sin t}{1- x \cos t} \right) $$

I have this integral with a known result. The "proof" the book gives is :

"We recognize that the fraction is $\dfrac{h'(u)}{1+h(u)^2}$ with $h(u) = \dfrac{x \sin u}{1- x \cos u } $"

But it's not that easy to spot, and I would like to know how to find this result without guessing that out of nowhere and without knowing it beforehand.
I've tried substitutions but I can't find a way to make it work.
Any idea on how to solve this ? Thanks !
 [/INST] I'm not sure this helps but ...
\begin{align}\mathcal{I}&=\displaystyle\int \frac{x\cos u-x^2}{(-2x)\cos u+(x^2+1)}\mathrm du\\&=\underbrace{\displaystyle\int \frac{x\cos u}{-2x\cos u+(x^2+1)}\mathrm du}_{\mathcal{I_1}}-x^2\overbrace{\displaystyle\int \frac{\mathrm du}{-2x\cos u+(x^2+1)}}^{\mathcal{I_2}}\end{align}

\begin{align}\mathcal{I_2}&=\displaystyle\int \frac{\mathrm du}{-2x\cos u+(x^2+1)}\\&=\displaystyle\int \frac{1}{\frac{1-t^2}{1+t^2}(-2x)+x^2+1}\left(\frac{2\mathrm dt}{1+t^2}\right)\, \text{ ,via substituting $t=\tan(u/2)$}\\&=2\displaystyle\int \frac{\mathrm dt}{(t(x+1))^2+(x-1)^2}\\&=\frac{2}{x^2-1}\arctan\left(\frac{(x+1)t}{x-1}\right)\, \text{ ,using the formula $\displaystyle\int \frac{dx}{a^2x^2+b^2}=\frac{1}{ab}\arctan(ax/b)$}\\&=\frac{2}{x^2-1}\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)\end{align}

\begin{align}\mathcal{I_1}&=\displaystyle\int \frac{x\cos u}{-2x\cos u+x^2+1}\, \mathrm du\\&=-x\displaystyle\int\left(\frac{1}{2x}+\frac{x^2+1}{2x(2x\cos u-x^2-1)}\right)\, \mathrm du\\&=\frac{-u}{2}-\frac{x^2+1}{2}\displaystyle\int\frac{\mathrm du}{2x\cos u-x^2-1}\\&=\frac{-u}{2}+\frac{(x^2+1)}{(x^2-1)}\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)\, \text{ ,using $\mathcal{I_2}$}\end{align}

Therefore,
\begin{align}\mathcal{I}&=-\frac{u}{2}+\frac{x^2+1}{x^2-1}\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)-\frac{2x^2}{x^2-1}\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)\\&=\frac{-u}{2}-\arctan\left(\frac{(x+1)\tan(u/2)}{x-1}\right)\end{align}
Now, you can put the limits.
Footnotes
Weierstrass Substitution
</s>