<s>[INST] About integration of $\frac{1}{(1+a^2 x^2)(1+x^2)}$ in differentiation under integral sign Consider the function $F(a)=\int_0^{+\infty} \frac{\arctan(ax)}{x(1+x^2)} dx$. I assumed $a \ge 0$ because $F$ is odd, I applied the theorem of differentiation under the integral sign and arrive to $F'(a)=\int_0^{+\infty} \frac{1}{(1+a^2 x^2)(1+x^2)}dx$; while doing the partial fraction decomposition of $\frac{1}{(1+a^2 x^2)(1+x^2)}$, I get
$$\frac{1}{(1+a^2 x^2)(1+x^2)}=\frac{A}{1+a^2 x^2}+\frac{B}{1+x^2}=\frac{A+Ax^2+B+Ba^2 x^2}{(1+a^2 x^2)(1+x^2)}$$
$$=\frac{A+B+(A+Ba^2)x^2}{(1+a^2 x^2)(1+x^2)}$$
So
$$\begin{cases} A+B=1 \\ A+Ba^2=0 \end{cases} \iff \begin{cases} A=1-B \\ 1-B+Ba^2=0 \end{cases} \iff \begin{cases} A=1-B \\ B(1-a^2)=1 \end{cases} \iff \begin{cases} A=-\frac{a^2}{1-a^2} \\ B=\frac{1}{1-a^2} \\ a \ne 1\end{cases}$$
I assumed $a \ne 1$ because I divided by $1-a^2$ (and not $a \ne -1$ too, because I'm working with $a \ge 0$). So I obtain the same result of the question I linked above, that is $F'(a)=\frac{\pi}{2(1+a)}$ and so $F(a)=\frac{\pi}{2}\log(1+a)$ for $a \ge 0$, by oddity then for $a<0$ it is $F(a)=-\frac{\pi}{2} \log (1-a)$.
The question is: what about $a=1$ and $a=-1$? To obtain the antiderivative with the partial fraction decomposition I divided by $1-a^2$, so I believe that I can't use the same expression when $a=1$ (or $a=-1$ by oddity), however the value of the integral for $a=1$ or $a=-1$ is respectively $\frac{\pi}{2} \log 2$ and $-\frac{\pi}{2}\log 2$, so it is coherent with the result $F(a)=\text{sgn}(a)\frac{\pi}{2} \log(1+|a|)$ even if $a=1$ or $a=-1$. I don't understand why this works even if, at some step, I divided by something that could be $0$ and still get the right result. Moreover, I can't fix $a=1$ or $a=-1$ to do the partial fraction decomposition of $\frac{1}{(1+x^2)^2}$ because all the point of differentiation under the integral sign is having an parameter to fix appropriately at the end and get the desired value of the integral; so fixing it makes all this senseless (moreover, $1/(1+x^2)^2$ is already decomposed).
I searched other answers and no one seems to consider this possibility of dividing by $0$ when using partial fraction decomposition, so I assume that I am missing something about partial fractions decomposition theory or somewhere else. What am I missing?
Edit. I tried, failing, to see if $F(1)$ was integrable with some tricks typical of definite integrals, like trying to use the substitution $t=\frac{1}{x}$ and using the identity $\arctan\frac{1}{t}=\pi/2-\arctan t$ valid for $t>0$, but it doesn't seem to help. So I'm still stuck.
 [/INST] The short idea of the story below is to use a further deformation parameter, $b$, and avoid the denominator $(a^2-1)$ which makes problems in $a=\pm1$ by  having instead $(a^2-b^2)$. The deformation used is continuous in $b$. Everything transposes on the computational side.

In order to exchange the order of differentiating w.r.t. $a$ and integrating w.r.t. $x$ we really need a "dominated convergence" argument to estimate the expression under the integral, so let us do this first. We assume $a$ lives in some bounded interval like $[-M,M]$. Then
$$
\begin{aligned}
\int_0^\infty \frac{\arctan(ax)}{x(1+x^2)}\; dx
&=
a\int_0^\infty \frac{\arctan(ax)}{ax(1+x^2)}\; dx
\\
&\le 
M\int_0^\infty \frac{1}{1+x^2}\; dx =\frac 12M\pi<\infty
\ .
\end{aligned}
$$
We have used $0\le u\le \tan u$ for $u$ from $0$ to $\pi/2$.
Similar dominance estimations can be used for the integrals below.
To get rid of the problems presented in the question for $a=\pm1$, we will introduce a new parameter, $b>0$.
We may and do assume that $a\ge 0$, so that only $a=1$ remains. So let us consider:
$$
\begin{aligned}
J(a,b)
&:=
\int_0^\infty \frac{\arctan(ax)}{x(1+b^2x^2)}\; dx\ ,
\text{ so that}
\\
J(0,b) &=0\ ,\\
J'_a(a,b)
&=
\int_0^\infty \frac{1}{(1+a^2x^2)(1+b^2x^2)}\; dx\ ,
\\
&=
\int_0^\infty 
\frac 1{a^2-b^2}
\left(
\frac {a^2}{1+a^2x^2}
-
\frac{b^2}{1+b^2x^2}
\right)\;
dx
\\
&=\frac 12\pi\cdot\frac {a-b}{a^2-b^2}
\\
&=\frac 12\pi\cdot\frac 1{a+b}\ .
\end{aligned}
$$
The above computations are valid for all parameters $a,b$ with $a\ne b$. We restrict to the case $0\le a<b$, integrate and obtain the equality:
$$
J(a,b) := \int_0^\infty \frac{\arctan(ax)}{x(1+b^2x^2)}\; dx
=
\frac 12\pi(\log (a+b)-\log b)\ .
$$
Now we can easily cover the case $a=1$. Just set it so, and let $b>1$ converge to $1$, and use the continuity of $J(1,b)$ as function of $b$.
</s>