<s>[INST] How can this integral be solved? I am trying to solve (by hand) the integral:$$\int_0^∞\frac1x\left(\frac{(x+a)^2}{((x+a)^2+b)^{3/2}}-\frac{(x-a)^2}{((x-a)^2+b)^{3/2}}\right)\,\mathrm dx,$$
where $a$ and $b$ are real and positive. Mathematica actually generates the answer, but I am stumped on how to solve it by hand and quite curious. Answer:
$$\frac{2a\left(\sqrt{a^2+b}-a\cdot\operatorname{arctanh}\left(\frac{a}{\sqrt{a^2+b}}\right)\right)}{\left(a^2+b\right)^{3/2}}.$$
Is there a (reasonably) nice way to solve something like this? Any tips on how to proceed?
 [/INST] Let $I$ denote the integral. By a simple substitution, we find that
$$ I
= \mathrm{PV}\!\int_{-\infty}^{\infty} \frac{1}{x-a} \frac{x^2}{(x^2+b)^{3/2}} \, \mathrm{d}x
= \operatorname{Re}\left( \int_{-\infty + i\epsilon}^{\infty+i\epsilon} \frac{1}{z-a} \frac{z^2}{(z^2+b)^{3/2}} \, \mathrm{d}z \right), $$
where the path of integration in the last step denotes any straight line $\operatorname{Im}(z)=\epsilon \in (0, \sqrt{b})$ oriented to the right, and the principal branch cut is adopted for $(z^2+b)^{3/2}$. Taking integration by parts,
$$ I
= - \operatorname{Re}\left( \int_{-\infty + i\epsilon}^{\infty+i\epsilon} \frac{a}{(z-a)^2} \frac{1}{\sqrt{z^2+b}} \, \mathrm{d}z \right). $$
We notice that its branch-cut in the upper-half plane is $i[\sqrt{b},\infty)$. So, by deforming the contour to wrap this branch-cut, we have
$$ I
= \operatorname{Re}\left( \int_{\sqrt{b}}^{\infty} \frac{2a}{(y+ia)^2\sqrt{y^2-b}} \, \mathrm{d}y \right)
= \int_{\sqrt{b}}^{\infty} \frac{2a(y^2-a^2)}{(y^2+a^2)^2\sqrt{y^2-b}} \, \mathrm{d}y. $$
As for further simplification, substitute $p = b/a^2$ and $y = \sqrt{\frac{b}{1-s}}$. Then
\begin{align*}
I
&= \frac{1}{a} \int_{0}^{1} \frac{p-1+s}{(p+1-s)^2\sqrt{s}} \, \mathrm{d}s \\
&= \frac{1}{a} \left[ \frac{2p\sqrt{s}}{(p+1)(p+1-s)} - \frac{2}{(p+1)^{3/2}}\operatorname{arctanh}\left(\sqrt{\frac{s}{p+1}}\right) \right]_{0}^{1} \\
&= \frac{2}{a} \frac{\sqrt{p+1} - \operatorname{arctanh}\left(\sqrt{\frac{1}{p+1}}\right)}{(p+1)^{3/2}}.
\end{align*}
Plugging $p = b/a^2$ back shows that this expression coincides with the answer provided in OP, and so, the desired equality is proved.
</s>