Improper integral $\int_0^\infty\frac{x^{2n+1}}{(1+x^2)^2(2+x^2)^N}dx,\ \ \ n\le N$ How can I evaluate this integral?
$$\int_0^\infty\frac{x^{2n+1}}{(1+x^2)^2(2+x^2)^N}dx,\ \ \ n\le N$$
Maybe there is a recurrence relation for the integral?
 A: Let $I_{n,N}$ denote the integral in question, where $n$ and $N$ are nonnegative integers such that $n\le N$. With the change of variables $y=2+x^2$ and then using the binomial expansion of $(y-2)^n$, we get
\begin{equation}
    2I_{n,N}=\int_2^\infty\frac{(y-2)^n\,dy}{(y-1)^2y^N}
    =\sum_{j=0}^n\binom nj (-2)^{n-j}J_{N-j},
\end{equation}
where
\begin{equation}
    J_k:=\int_2^\infty\frac{y^{-k}\,dy}{(y-1)^2}. 
\end{equation}
Integrating by parts, we get
\begin{equation}
    J_k=2^{-k}-kM_{k+1},
\end{equation}
where
\begin{equation}
    M_k:=\int_2^\infty\frac{y^{-k}\,dy}{y-1}=\int_0^{1/2}(1-t)^{-1}t^{k-1}\,dt,
\end{equation}
using $t=1/y$. Further,
\begin{align*}
    M_k&=\int_0^{1/2}[(1-t)+t](1-t)^{-1}t^{k-1}\,dt \\ 
    &=\int_0^{1/2}t^{k-1}\,dt+\int_0^{1/2}(1-t)^{-1}t^k\,dt  \\ 
    &=\frac1{k2^k}+M_{k+1}. 
\end{align*}
So,
\begin{align*}
    2I_{n,N}&=\sum_{j=0}^n\binom nj (-2)^{n-j}2^{j-N} \\ 
&   -\sum_{j=0}^n\binom nj (-2)^{n-j}(N-j)M_{N-j+1} \\ 
&   =2^{-N}1(n=0)-\sum_{j=0}^n\binom nj (-2)^{n-j}(N-j)M_{N-j+1}.
\end{align*}
Thus,
\begin{align*}
    I_{n,N}&=2^{-N-1}1(n=0)+\sum_{j=0}^n\binom nj (-2)^{n-j-1}(N-j)M_{N-j+1}, \tag{1}
\end{align*}
and the $M_k$'s are given by the simple recurrence
\begin{equation}
    M_{k+1}=M_k-\frac1{k2^k} \tag{2}
\end{equation}
for natural $k$,
with $M_1=\ln2$.

From this, one can also get a (double) recurrence for $I_{n,N}$. Indeed, by (1),
\begin{equation}
    I_{n,N}=2^{-N-1}1(n=0)+\sum_{j=0}^\infty a_{j,n}L_{N-j}, 
\end{equation}
where
\begin{equation}
    a_{j,n}:=\binom nj (-2)^{n-j-1},\quad L_k:=kM_{k+1}.
\end{equation}
From $\binom nj=\binom{n-1}{j-1}+\binom{n-1}j$, we get
\begin{equation}
    a_{j,n}=a_{j-1,n-1}-2a_{j,n-1}. 
\end{equation}
So,
\begin{align*}
    I_{n,N}&=\sum_{j=0}^\infty a_{j-1,n-1}L_{N-j}-2\sum_{j=0}^\infty a_{j,n-1}L_{N-j} \\  
    &=\sum_{i=-1}^\infty a_{i,n-1}L_{N-1-i}-2\sum_{j=0}^\infty a_{j,n-1}L_{N-j} \\  
    &=I_{n-1,N-1}-2I_{n-1,N} \tag{3}
\end{align*}
if $1\le n\le N$, and (by (1)) $I_{0,N}=2^{-N-1}-NM_{N+1}/2$, with the $M_k$'s given by recurrence (2).
This conclusion has been verified for a few pairs $(n,N)$.
A: One approach is to consider the sum
$$ J = \sum_{n,m=0}^\infty s^nt^mI_{n,n+m} = \int_{x=0}^\infty F\,dx, $$
where
$$ F = \sum_{n,m=0}^\infty s^nt^m \frac{x^{2n+1}}{(1+x^2)^2(2+x^2)^{n+m}} = 
 \frac{x(2+x^2)^2}{(1+x^2)^2(2+x^2-sx^2)(2+x^2-t)}
$$
This works out as
$$
 J = \frac{2s^2\ln(1-s)}{(1+s)^2(st-2s-t)} + 
  \frac{t^2\ln(1-t/2)}{2(1-t)^2(st-2s-t)} + 
  \frac{(2s-t-3st)\ln(2)}{2(1+s)^2(1-t)^2} + 
  \frac{1}{2(1+s)(1-t)} 
$$
In principle you could expand this as a power series and extract $I_{n,n+m}$ as the coefficient of $s^nt^m$.
A: Let us renumber $N=n+L$ and let $K_{n,L} = I_{n,n+L} = \frac{1}{2} \int_0^\infty \frac{y^n}{(1+y)^2 (2+y)^{n+L}} \, dy$, which is the desired integral after the variable change $y=x^2$. Let $K(s,t) = \sum_{L=0}^\infty \sum_{n=0}^\infty K_{n,L} s^L t^n$. For small enough $s$ and $t$, the integrands converge uniformly over the interval of integration, so we can exchange the summation with the integration to get
\begin{align*}
  K(s,t) &= \frac{1}{2} \int_0^\infty \frac{(2+y)^2}{(1+y)^2 (2-s+y) (2+(1-t)y)} \, dy \\
  &= \frac{1}{2\pi i} \frac{1}{2} \oint_\gamma \frac{\log(-y) (2+y)^2}{(1+y)^2 (2-s+y) (2+(1-t)y)} \, dy,
\end{align*}
where the complex contour $\gamma$ tightly encircles the positive real line clockwise. Deforming the contour to counter-clockwise encircle the poles at $y=-1,-2+s,-2/(1-t)$, we get
\begin{align*}
  K(s,t) &= \sum_{z=-1,-2+s,-\frac{2}{(1-t)}} \operatorname{Res}_{y=z}
    \frac{1}{2} \frac{\log(-y) (2+y)^2}{(1+y)^2 (2-s+y) (2+(1-t)y)} \\
  &= \frac{1}{2} \frac{1}{(1-s)(1+t)}
    + \frac{1}{2} \frac{s^2 \log(2-s)}{(1-s)^2 (s+2t-st)}
    - \frac{1}{2} \frac{4t^2 \log(\frac{2}{1-t})}{(1+t)^2 (s+2t-st)} \\
  &= \frac{1}{2} \frac{1}{(1-s)(1+t)}
\\ & \quad {}
    + \frac{1}{2(1-t)(s+\frac{2t}{1-t})} \left( \frac{s^2 \log(2-s)}{(1-s)^2}
      - \frac{(\frac{2t}{1-t})^2 \log(2+\frac{2t}{1-t})}{(1+\frac{2t}{1-t})^2} \right) .
\end{align*}
Note that the last term is of the form $(f(x)-f(y))/(x-y)$ for $x=s$ and $y=-\frac{2t}{1-t}$, so that this ratio is expressible as some $g(x,y)$ that is analytic at $x=y$, which tells you how an expansion in $s$ and $t$ is possible despite the pesky factor of $1/(s+\frac{2t}{1-t})$.
This answer is the same as Neil Strickland's. But he didn't specify how to do the expansion in the presence of the pesky denominator mentioned above.
A: Recurrence (3) in my other answer on this page also follows immediately from the same recurrence for the respective integrands! :-)
Concerning the case $n=0$: the recurrence for the $M_k$'s follows immediately from the definition of $M_k$ and the trivial identity $y^{-k}-y^{-k-1}=y^{-k-1}(y-1)$.

To make this answer independent of the previous one, note that for the integral in question we have
\begin{equation*}
    I_{n,N}=\int_0^\infty K_{n,N}(x)\,dx,
\end{equation*}
where
\begin{equation*}
    K_{n,N}(x):=\frac{x^{2n+1}}{(1+x^2)^2(2+x^2)^N}. 
\end{equation*}
Note next that $K_{n,N}=K_{n-1,N-1}-2K_{n-1,N}$ and hence
\begin{equation*}
    I_{n,N}=I_{n-1,N-1}-2I_{n-1,N} \quad \text{if $1\le n\le N$}.\tag{1}
\end{equation*}
Also,
\begin{equation*}
    2I_{0,N}=J_N:=\int_0^\infty\frac{2x\,dx}{(1+x^2)^2(2+x^2)^N}
    =\int_2^\infty\frac{y^{-N}\,dy}{(y-1)^2}.
\end{equation*}
Next,
\begin{align*}
    J_{N-1}-2J_N+J_{N+1}&=\int_2^\infty\frac{y^{-N+1}-2y^{-N}+y^{-N-1}}{(y-1)^2}\,dy \\ 
    &=\int_2^\infty y^{-N-1}\,dy=\frac1{N2^N}. 
\end{align*}
So,
\begin{equation*}
    I_{0,N+1}=2I_{0,N}-I_{0,N-1}+\frac1{N2^{N+1}}\quad\text{for $N\ge1$}, \tag{2}
\end{equation*}
with
\begin{equation*}
\text{$I_{0,0}=1/2$ and $I_{0,1}=(1-\ln2)/2$.} \tag{3}  
\end{equation*}
Formulas (1), (2), (3) provide the desired recurrence relations for $I_{n,N}$.
