Tripos Integral Show that
$$\int_0^{\frac{\pi}{4}} \frac{\sin^2 x}{e^{2mx}(\cos x-m\sin x)^2}dx=\frac{1}{2m(1+m^2)}\left[\frac{1+m}{1-m}e^{-m\frac{\pi}{2}}-1\right]$$
This problem is from Edwards, Treatise on Integral Calculus II, pg.187.
It is a definite integral and is not likely to find the indefinite integral, at this point in the book Edwards has introduces the tricks of substituting $\frac{\pi}{4}-x$ for $x$, and expansion in series (and of course parts). Unfortunately, I haven't been able to make these tricks work out. My method has been to expand $\frac{\tan^2 x}{(1-m\tan x)^2}$ as a series in $m\tan x$, and integrate termwise but so far without success. Does anybody have any good ideas?
 A: Too long for a comment.
The idea of writing
$$\frac{\tan^2 (x)}{(1-m\tan (x))^2}=\sum_{n=2}^\infty (n-1)\, m^{n-2}\, \tan^n(x)$$ was appealing.
But the problem of
$$I_n=\int_0^{\frac \pi 4}e^{-2mx}\tan^n(x)\,dx$$ is a nightmare since $2 i^n I_n$ write
$$\frac{i \Gamma (i m) \Gamma (n+1) \, _2F_1(i m,n;i m+n+1;-1)}{\Gamma (i
   m+n+1)}-\frac{e^{-\frac{\pi  m}{2}} F_1(i m;n,-n;i m+1;-i,i)}{m}$$ where appear the gaussian hypergeometric function as well as the Appell hypergeometric function of two variables. I prefer not to think about the problem of the summation.
On the other hand, the antiderivative is quite nice
$$\int\frac{\sin^2 (x)}{e^{2mx}(\cos (x)-m\sin (x))^2}dx=\frac{e^{-2mx} }{2m(1+m^2)}\,\,\frac{\cos (x)+m \sin (x)}{\cos (x)-m \sin (x)}$$
A: Well the anti derivative exists. As pointed out by Claude Leibovici. I had just assumed that as it was a chapter on definite integrals, they would not give examples where the indefinite integral exists. Anyway here is a calculation of the anti derivative. The result on the last line.
\begin{equation*}
\begin{split}
\int e^{-2mx}\frac{\tan^2 x}{(1-m\tan x)^2}dx
&=\int e^{-2mx}\frac{\sec^2 x}{(1-m\tan x)^2}dx
-\int e^{-2mx}\frac{1}{(1-m\tan x)^2}dx\\
&=\frac{1}{m}\int e^{-2mx}d\frac{1}{(1-m\tan x)}
-\int e^{-2mx}\frac{1}{(1-m\tan x)^2}dx\\
&=e^{-2mx}\frac{1}{m(1-m\tan x)}+2\int e^{-2mx}\frac{1}{(1-m\tan x)}dx\\
&-\int e^{-2mx}\frac{1}{(1-m\tan x)^2}dx\\
&=e^{-2mx}\frac{1}{m(1-m\tan x)}+2\int e^{-2mx}\frac{1-m\tan x}{(1-m\tan x)^2}dx\\
&-\int e^{-2mx}\frac{1}{(1-m\tan x)^2}dx\\
&=e^{-2mx}\frac{1}{m(1-m\tan x)}+\int e^{-2mx}\frac{1-2m\tan x}{(1-m\tan x)^2}dx\\
&=e^{-2mx}\frac{1}{m(1-m\tan x)}+\int e^{-2mx}\frac{1-2m\tan x+m^2\tan^2 x}{(1-m\tan x)^2}dx\\
&-m^2\int e^{-2mx}\frac{\tan^2 x}{(1-m\tan x)^2}dx
\end{split}
\end{equation*}
So $$(1+m^2)\int e^{-2mx}\frac{\tan^2 x}{(1-m\tan x)^2}dx=
e^{-2mx}\frac{1}{m(1-m\tan x)}+\int e^{-2mx}dx$$
$$=
e^{-2mx}\frac{1}{m(1-m\tan x)}-\frac{1}{2m}e^{-2mx}$$
$$=
\frac{1}{2m}e^{-2mx}\frac{1+m\tan x}{1-m\tan x}$$
So finally,
$$\int e^{-2mx}\frac{\tan^2 x}{(1-m\tan x)^2}dx=
\frac{1}{2m(1+m^2)}e^{-2mx}\frac{1+m\tan x}{1-m\tan x}$$
A: It is actually not very difficult to obtain the correct antiderivative (for some reason i use $a$ for the integral parameter, not $m$).
The only non-trivial observation here is how to write the more compelx part of the integral as a derivative ($'$ denotes differentation w.r.t. $x$):
$$I = (2a)^{-1}\int \left(\frac{\cos(x)+a \sin(x)}{\cos(x)-a \sin(x)}\right)' \sin^2(x)e^{-2 a x}$$
integrating by parts, we can just cancel the annoying stuff:
$$
(2a)I = e^{-2 a x}\sin^2(x)\frac{\cos(x)+a \sin(x)}{\cos(x)-a \sin(x)} -\\
\int \left(\frac{\cos(x)+a \sin(x)}{\color{red}{\cos(x)-a \sin(x)}}\right)( \color{red}{\cos(x)-a \sin(x)}) \sin(x)e^{-2 a x} 
$$
the remaining integral is elementary:
$$
e^{2 a x}(2a)I =\sin^2(x)\frac{\cos(x)+a \sin(x)}{\cos(x)-a \sin(x)}+\frac{(\cos(x)+a \sin(x))^2}{a^2+1}
$$
this can be brought into the form indicated by @Claude Leibovici, but i don't have the right temper for stupid algebra like that at the moment
A: We'll first remove the trigonometric functions since it's easier to work with rational functions, but if you can see (without reverse engineering) how to split the integral in the original form then there's no need to do this.
$$I=\int_0^\frac{\pi}{4} \frac{\sin^2 x e^{-2mx}}{(m\sin x-\cos x)^2}dx\overset{\cot x \to x}=\int_1^\infty \frac{e^{-2m\cot^{-1}x}}{1+x^2}\frac{dx}{(m-x)^2}$$
Forcing a partial fraction to have $\frac{1}{1+x^2}$ and $\frac{1}{(m-x)^2}$ separately yields:
$$I=\frac{1}{1+m^2}\int_1^\infty e^{-2m\cot^{-1} x}\left(\color{blue}{\frac{1}{1+x^2}\frac{m+x}{m-x}}+\color{red}{\frac{1}{(m-x)^2}}\right)dx$$
Finally integrating by parts the first term gives:
$$\int_1^\infty \frac{e^{-2m\cot^{-1} x}}{\color{blue}{1+x^2}}\color{blue}{\frac{m+x}{m-x}}dx = \int_1^\infty \left(\frac{e^{-2m\cot^{-1} x}}{2m}\right)'\frac{m+x}{m-x}dx$$
$$=\frac{e^{-2m\cot^{-1} x}}{2m}\frac{m+x}{m-x}\bigg|_1^\infty -\int_1^\infty \frac{e^{-2m\cot^{-1} x}}{\color{red}{(m-x)^2}}dx$$
$$\Rightarrow I=\frac{1}{1+m^2}\frac{e^{-2m\cot^{-1} x}}{2m}\frac{m+x}{m-x}\bigg|_1^\infty=\frac{1}{2m(1+m^2)}\left(\frac{1+m}{1-m}e^{-m\pi/2}-1\right)$$
