<s>[INST] Compute $\int \frac {dx} {(a + b \cos x)^2} $ for $a > b.$ Let $a>b$ be real numbers. As the title suggests, I would like to compute $$\int \frac 1 {(a + b \cos x)^2} \, dx.$$
My attempt consisted of converting the cosine to half-angle tangents, substituting the half-angle tangent for $t$, and simplifying to $$\int \frac{2(1+t^2)}{[(a+b)+(a-b)t^2]^2} \, dt.$$
From here, I multiplied and divided the integrand by $(a-b)$, added an $(a+b)-2b$ to the numerator, and simplified it to $$\frac{4b}{a-b}\int {\left(\frac 1 {[(a+b)+(a-b)t^2]^2} + \frac{2t}{a-b} \right)} \, dt.$$
Now, just looking at the integral left, I substituted $t$ for $\sqrt{\frac{a+b}{a-b}} \tan\theta$, did some simplifying, converted the resulting $\cos^2\!\theta$ in the numerator to $1+\cos 2 \theta$, and wrapped up the integral, finishing up with $$\frac{2\tan \frac{x}{2}}{a-b}-\frac{2b}{(a^2-b^2)^{\frac{3}{2}}}{\left(\arctan \sqrt{\frac{a+b}{a-b}}\tan \frac{x}{2}+ \frac{\sqrt{ \frac{a+b}{a-b}}\tan 
 \frac{x}{2}}{1+{ \frac{a-b}{a+b}\tan^2 \frac{x}{2}}} \right)}$$
This is apparently wrong. Can someone help me with why?
 [/INST] Proceed as follows after half-angle substitution $t=\tan\frac{x}2$
\begin{align}
& \int \frac{2(1+t^2)}{[(a+b)+(a-b)t^2]^2} \, dt\\
=& \frac2{a^2-b^2} \int \frac{a[(a-b)t^2+(a+b)]+ b[(a-b)t^2-(a+b)] }{[(a+b)+(a-b)t^2]^2} \, dt \\
=& \frac2{a^2-b^2} \int \frac{a[(a-b)+\frac{a+b}{t^2} ]+ [b[(a-b)-\frac{a+b}{t^2}]}{[(a-b)t+\frac{a+b}t]^2}dt\\
=& \frac2{a^2-b^2} \left(a \int \frac{d[(a-b)t-\frac{a+b}{t}]}{[(a-b)t-\frac{a+b}t]^2+4(a^2-b^2)}
+b\int \frac{d[(a-b)t+\frac{a+b}{t}] }{[(a-b)t +\frac{a+b}t]^2}  \, \right)\\
=& \frac{a}{(a^2-b^2)^{3/2}} \tan^{-1} \frac{(a-b)t-\frac{a+b}{t}}{2\sqrt{a^2-b^2}}- \frac{2b}{a^2-b^2} 
\frac{1}{(a-b)t +\frac{a+b}t}\\
=& \frac{a}{(a^2-b^2)^{3/2}} \tan^{-1} \frac{(a-b)\tan^2\frac{x}2-(a+b)}{ 2\sqrt{a^2-b^2}\tan\frac{x}2 }- \frac{2b}{a^2-b^2} 
\frac{\tan\frac{x}2}{(a-b) \tan^2\frac{x}2 +(a+b)}
\end{align}
</s>