Evaluation of $\int\frac{1}{(\sin x+a\sec x)^2}dx$ 
Evaluation of $$\int\frac{1}{(\sin x+a\sec x)^2}dx$$

Try: Let $$I=\int\frac{1}{(\sin x+a\sec x)^2}dx=\int\frac{\sec^2 x}{(\tan x+a\sec^2 x)^2}dx$$
put $\tan x=t$ and $dx=\sec^2 tdt$
So $$I=\int\frac{1}{(a+at^2+t)^2}dt$$
Could some help me how to solve above Integral , thanks in advance.
 A: Hint: $\sin x = \dfrac{\tan x}{\sec x}$ and $\sec^2x = 1 + \tan^2x$.
$$\begin{align}
\dfrac1{(\sin x+a\sec x)^2} &= \dfrac1{\left(\dfrac{\tan x}{\sec x}+a\sec x\right)^2} \\
&= \dfrac{\sec^2x}{(\tan x + a\sec^2x)^2} \\
&= \dfrac{\sec^2x}{\tan^2x + 2a\tan x\sec^2x + a^2\sec^4x} \\
&= \dfrac{\sec^2x}{\tan^2x + 2a\tan x(1 + \tan^2x)+ a^2(1 + \tan^2x)^2}
\end{align}$$
Therefore,
$$\int\dfrac1{(\sin x+a\sec x)^2}\,\mathrm dx = \int\dfrac{\sec^2x}{\tan^2x + 2a\tan x(1 + \tan^2x)+ a^2(1 + \tan^2x)^2}\,\mathrm dx$$
Substitute $u = \tan x$, $\implies\mathrm du = \sec^2x\,\mathrm dx$. Now,
$$\begin{align}\int\dfrac{\sec^2x}{\tan^2x + 2a\tan x(1 + \tan^2x)+ a^2(1 + \tan^2x)^2}\,\mathrm dx &= \int \dfrac1{u^2 + 2au(1 + u^2) + a^2(1 + u^2)^2}\,\mathrm du\end{align}$$
From here onward, you would need to factor the denominator and perform partial fraction decomposition. Then, you will be able to apply linearity to integrate individual fractions. Finally, undo substitution to get the final result.
Edit # 1:
$$\begin{align}
u^2 + 2au(1 + u^2) + a^2(1 + u^2)^2 &\equiv u^2 + 2\cdot (u)\cdot\left(a(1 + u^2)\right) + \left(a(1 + u^2)\right)^2 \\
&= \left(u + a(1 + u^2)\right)^2
\end{align}$$
Factorising $u + a(1 + u^2)$:
$$u + a(1 + u^2) \equiv au^2 + u + a$$
Completing square,
$$\begin{align}
au^2 + u + a &= au^2 + u + \dfrac1{4a} - \dfrac1{4a} + a \\
&= \left(\sqrt{a}u + \dfrac1{2\sqrt{a}}\right)^2 - \dfrac1{4a} + a \\
&= \dfrac{(2au + 1)^2}{4a} - \dfrac{1 - 4a^2}{4a} \\
&= \dfrac{(2au + 1)^2 - \left(\sqrt{1 - 4a^2}\right)^2}{4a} \\
&= \dfrac{\left(2au + 1 + \sqrt{1 - 4a^2}\right)\left(2au + 1 - \sqrt{1 - 4a^2}\right)}{4a}
\end{align}$$
Therefore,
$$\begin{align}
\int \dfrac1{u^2 + 2au(1 + u^2) + a^2(1 + u^2)^2}\,\mathrm du &= \operatorname{\large\int} \dfrac1{\left(au^2 + u + a\right)^2}\,\mathrm du\\
&= \operatorname{\Large\int} \dfrac{1}{\left(\left(2au + 1 + \sqrt{1 - 4a^2}\right)\left(2au + 1 - \sqrt{1 - 4a^2}\right)/4a\right)^2}\,\mathrm du \\
&= \operatorname{\Large\int} \dfrac{16a^2}{\left(2au + 1 + \sqrt{1 - 4a^2}\right)^2\left(2au + 1 - \sqrt{1 - 4a^2}\right)^2}\,\mathrm du
\end{align}$$
A: HINT
Let
$$b=\dfrac1{2a},\quad y=t+b,\tag1$$
then
$$I=4b^2\int\dfrac{dt}{(t^2+2bt+1)^2} = 4b^2\int\dfrac{dy}{(y^2+1-b^2)^2} = \dfrac{4b^2}{1-b^2}\int\dfrac{(y^2+1-b^2)-y^2}{(y^2+1-b^2)^2}\,dy,$$
$$I=\dfrac{4b^2}{1-b^2}(I_1+I_2),\tag2$$
where
$$I_1=\int\dfrac{dy}{y^2+1-b^2} = const + 
\begin{cases}\dfrac1{\sqrt{1-b^2}}\arctan\dfrac{y}{\sqrt{1-b^2}},\text{ if } b<1\\[4pt]
-\dfrac1y,\text{ if }b=1\\[4pt]
\dfrac1{2\sqrt{b^2-1}}\ln\left|\dfrac{y-\sqrt{b^2-1}}{y+\sqrt{b^2-1}}\right|, \text{ if }b>1, 
\end{cases}\tag3$$
$$I_2 = -\int\dfrac{y^2dy}{(y^2+1-b^2)^2} = \dfrac12\int y\cdot d\left(\dfrac{1}{y^2+1-b^2}\right) = \dfrac12\dfrac{y}{y^2+1-b^2} - \dfrac {I_1}2.\tag4$$
A: You can write 
$$
\frac{1}{(a+t+at^2)^2}=-\frac{1-2a^2+2at+2a^2t^2}{(-1+4a^2)(a+t+at^2)^2}+\frac{2a}{(-1+4a^2)(a+t+at^2)}.
$$
Also is
$$
-\int\frac{1-2a^2+2at+2a^2t^2}{(-1+4a^2)(a+t+at^2)^2}dt =\frac{1+2at}{(-1+4a^2)(a+t+at^2)}
$$
and
$$
\int \frac{2a}{(-1+4a^2)(a+t+at^2)}dt=\frac{4a}{(-1+4a^2)^{3/2}}\arctan\left(\frac{1+2at}{\sqrt{-1+4a^2}}\right).
$$
Hence
$$
\int \frac{1}{(a+t+a t^2)^2}dt=
$$
$$
=\frac{1+2at}{(-1+4a^2)(a+t+a t^2)}+\frac{4a}{(-1+4 a^2)^{3/2}}\arctan\left(\frac{1+2at}{\sqrt{-1+4a^2}}\right).
$$
Where we have used
$$
\int\frac{1}{1+t^2}dt=\arctan(t)+c
$$
In general holds
$$
\int\frac{dt}{(t^2+at+b)^2}=\frac{2t+a}{(-a^2+4b)(t^2+at+b)}+\frac{4\arctan\left(\frac{2t+a}{\sqrt{-a^2+4b}}\right)}{(-a^2+4b)^{3/2}}.
$$
QED
