In the theory of action-angle variables, you wind up having to solve integrals with a characteristic square-root behavior near the endpoints to express the action in terms of the orbital quantities. For the Kepler potential, this integral is
$$
I = \int\_{a}^{b}{\sqrt{\left(r - a\right)\left(b - r\right)} \over r}\,{\rm d}r
$$


I believe from external sources that this works out to
$$ I = \pi [ \frac{a+b}{2} - \sqrt{a b}] $$
In other words, proportional to the difference of the arithmetic
and geometric means.


However, apparently I suck at doing integrals, so I'm unable to figure out why. I suspect that there is a transformation that would be useful in solving this integral, and quite possibly some similar integrals arising from other potentials. Such a transformation might also be useful in numerically calculating integrals for potentials where you can't solve it analytically. I'd like to try several alternate potentials that are more realistic than Kepler
for a problem I have where action-angle theory is useful. But all of the transformations I've tried have run up blind alleys. Can someone explain to me how to derive this? Thanks in advance.



Action Integral
There are multiple ways of going about the evaluation of this integral and different methods are appropriate depending on what you need and how you intend to generalize the integrand.


If you are only interested in the numerical value for fixed parameters $a$ and $b$. Then this integral can be handled essentially "out of the box" by any computer algebra or numerical software package. The reason is that the integrand is very smooth, with not too much variation over the integration domain. Look up the QAGS routine if you want finer control of how the integration is done close to the square-root singularities at the boundary. This will work for a large class of similar integrands as well.


Another very useful technique is contour integration. Namely, imagine that $C$ is a tight clockwise contour about the segment $[a,b]$ in the complex $z$ plane. Then you have the identity
$$ I = \frac{1}{2i}\int\_C \frac{\sqrt{-(z-a)(b-z)}}{z} \mathrm{d}z , $$
where the principal branch of the square root is used, with the branch cut on $[a,b]$. The reason for the identity is that this contour picks up the difference between the values of the square root on either side of the branch cut, which is precisely $2i\sqrt{(z-a)(b-z)}$. The integral can now be evaluated using residues, which is easier after the substitution $z=w^{-1}+(a+b)/2$:
$$
 I = -\frac{1}{2i}\int\_{C'} \frac{\sqrt{(w+\frac{2}{b-a})(\frac{2}{b-a}-w)}}{w^2(w+\frac{2}{a+b})} \mathrm{d}w ,
$$
where again the principal square root branch is used, with the branch cut on the real line excluding $(-\frac{2}{b-a},\frac{2}{b-a})$, and the integration contour $C'$ is now counter-clocwise and encircles the poles at $w=0$ and $w=-2/(a+b)$. These residues contribute respectively $2\pi i (a+b)/2/(-2i)$ and $-2\pi i\sqrt{ab}/(-2i)$, which shows that I'm a minus sign off from your answer. (Finding the sign mistake is left as an exercise to the reader. :-) This method will still work if the functions in the denominator and under the square root are replaced by a large class of analytic functions.


Another method uses the fact that the integrand is rational in $s=\sqrt{(r-a)(b-r)}$ and $r$, while these two expressions satisfy the equation $s^2+(r-\frac{a+b}{2})^2 = (\frac{b-a}{2})^2$. This equation defines a circle in the $rs$-plane and hence has a rational parametrization
$$
 s(t) = \frac{b-a}{2}\frac{2t}{1+t^2} \quad\text{and}\quad
 r(t) = \frac{b-a}{2}\frac{1-t^2}{1+t^2} + \frac{a+b}{2} .
$$
This remarkable fact means that the integrand becomes rational as well (no square roots) upon the substitution $r=r(t)$. Any rational expression can be integrated using partial fractions. In this form, the integral is
$$
 I = \int\_0^\infty\left[
 -\frac{2ab}{at^2+b}+\frac{2b}{t^2+1}-\frac{2(b-a)}{(t^2+1)^2}
 \right]
 = -\pi\sqrt{ab} + \pi b - \pi\frac{b-a}{2} ,
$$
which agrees with your expression. This method works only when the integral is a rational in two expressions $s$ and $r$, which are linked by rationally parametrizable curve in the $rs$-plane. This last method is a souped up version of the Euler substitution mentioned in the comment by Américo Tavares.


These three methods work in cases of roughly decreasing generality.


