<s>[INST] Integral $ \int_{-\infty}^\infty \frac{1}{x^2+1} \left( \tan^{-1} x + \tan^{-1}(a-x) \right) dx$ For $a\in\mathbb R$, I want to evaluate the integral
$$ I = \int_{-\infty}^\infty \frac{1}{x^2+1} \left( \tan^{-1} x + \tan^{-1}(a-x) \right) dx.$$
I tried to integration by parts by considering $\left( \tan^{-1}(x) \right)' = \frac{1}{x^2+1}$, so that
$$I = - \int_{-\infty}^\infty \tan^{-1}(x) \left(\frac{1}{1+x^2} - \frac{1}{1+(x-a)^2}\right).$$
However, I cannot proceed further. Mathematica cannot solve both integrals.
How to evaluate $I$?
 [/INST] Too long for a comment
In fact, the evaluation can be done by means of the complex integration method, and this evaluation is rather straightforward. Just one of the possible contours.
$$\int_{-\infty}^\infty \frac{1}{x^2+1} \left( \tan^{-1} x + \tan^{-1}(a-x) \right) dx=I_1+I_2$$
It is evident that $I_1=0$ (the integrand is odd). As for $I_2$
$$I_2=-\int_{-\infty}^\infty \frac{\tan^{-1}x}{(x+a)^2+1} dx$$
Using $1-ix=\sqrt{1+x^2}e^{-i\tan^{-1}x}\,\Rightarrow\,\ln(1-ix)=\frac{1}{2}\ln(1+x^2)-i\tan^{-1}x\,\Rightarrow\,\boxed{\,\tan^{-1}x=-\Im\ln(1-ix)\,}$
$$I_2=\Im\int_{-\infty}^\infty \frac{\ln(1-ix)}{(x+a)^2+1} dx=\Im\int_{-\infty}^\infty \frac{\ln(1-ix)}{(x+a-i)(x+a+i)} dx$$
Switching to the complex integration and closing the contour by a big circle of radius $R\to\infty$ in the upper half-plane (counterclockwise), taking into consideration that $\ln(1-ix)$ does not have branch points inside the contour, and that there is a singe simple pole at $z=-a+i$
$$I_2=\Im\,2\pi i\underset{z=-a+i}{\operatorname{Res}}\frac{\ln(1-iz)}{(z+a-i)(z+a+i)}=\pi\,\Im\ln(2+ia)=\pi\tan^{-1}\frac{a}{2}$$
$$I=I_1+I_2=\pi\tan^{-1}\frac{a}{2}$$
</s>