Difficult integral from general relativity $\int_{a}^{0} \frac{1+mu}{\sqrt{u-a} \sqrt{b-u}} \,du$ When solving for the angular deflection of a light ray passing close to a star in general relativity, one needs to compute an elliptic integral. By some clever factoring and application of a relevant approximation, one reduces the problem to
$$\Delta \phi = -2\int_{a}^{0} \frac{1+mu}{\sqrt{u-a} \sqrt{b-u}} \,du$$
I know (and have verified with Mathematica) that this has exact solution
$$\Delta \phi = 2m\sqrt{-ab}+[4+2m(a+b)]\arctan\left(-\sqrt\frac{a}{b}\right),$$
but do not see how to replicate this solution. I've tried reverse engineering this in the case integration by parts was used but can't quite figure it out. Also, is there a complex contour integration approach - perhaps on the dogbone contour? Any hint or point to relevant literature would be appreciated. Thanks.
 A: Hmm. We have
\begin{align*}
-2\int_{a}^{0} \frac{1+mu}{\sqrt{u-a} \sqrt{b-u}} \,du
&=2\int_{0}^{a} \frac{1+mu}{\sqrt{(u-a)(b-u)}} \,du \\
&=2\int_{0}^{a} \frac{1+mu}{\sqrt{-(u^2-u(b+a)+ab)}} \,du \\
&=2\int_{0}^{a} \frac{1+mu}{\sqrt{-\left(\left(u-\frac{b+a}{2}\right)^{\!2}-\frac{(b-a)^2}{4}\right)}} \,du \\
&=2\int_{0}^{a} \frac{1+mu}{\sqrt{\frac{(b-a)^2}{4}-\left(u-\frac{b+a}{2}\right)^{\!2}}} \,du.
\end{align*}
From here, it seems advisable to substitute
\begin{align*}
v&=u-\frac{b+a}{2}\\
dv&=du
\end{align*}
to obtain
\begin{align*}
\Delta\phi
&=2\int_{-(b+a)/2}^{(a-b)/2} \frac{1+m(v+(b+a)/2)}{\sqrt{\frac{(b-a)^2}{4}-v^2}} \,dv \\
&=2\int_{-(b+a)/2}^{(a-b)/2} \frac{(1+m(a+b)/2)+mv}{\sqrt{\frac{(b-a)^2}{4}-v^2}} \,dv \\
&=(2+m(a+b))\int_{-(b+a)/2}^{(a-b)/2} \frac{1}{\sqrt{\frac{(b-a)^2}{4}-v^2}} \,dv+2m\int_{-(b+a)/2}^{(a-b)/2} \frac{v}{\sqrt{\frac{(b-a)^2}{4}-v^2}} \,dv.
\end{align*}
The antiderivative of the first gives you the $\arctan$ function via trigonometric substitution, and the second is the square root function via substitution.
A: Substitute $u=\frac{b y^2+a}{1+y^2}$ to remove the square-root in the denominator
\begin{align}
\Delta \phi =& -2\int_{a}^{0} \frac{1+mu}{\sqrt{u-a} \sqrt{b-u}} \,du\\
=& -4\int_0^{\sqrt{\frac{-a}b}}\frac{(bm+1)y^2+(am+1)}{(1+y^2)^2}dy\\
=&\ \bigg(\frac{2(b-a)my}{1+y^2}-[2(a+b)m+4]\tan^{-1} y\bigg)\bigg|_0^{\sqrt{\frac{-a}b}}\\
= &\ 2m\sqrt{-ab}-[2m(a+b)+4]\tan^{-1}\sqrt{\frac{-a}b}
\end{align}
(Note that the result cited in the post is incorrect.)
