Calculating $\int_0^\infty \frac{1}{(x^2+1)^n}dx$ I am trying to determine a closed form expression of the integral $I_n := \int_0^\infty \frac{1}{(x^2+1)^n}dx$, where $n \in \mathbb{N}$. I'd like to use residue calculus to solve this problem. I have come up with the following:
Let $f_n(x) := \frac{1}{(x^2+1)^n}$. Since $f_n$ is an even function, we have
$$
2I_n = \int_\mathbb{R}\frac{1}{(x^2+1)^n}dx.
$$
Next, consider the function $f_n$ with a complex argument $z \in \mathbb{C}$. This gives us
$$
f_n(z) = \frac{1}{(z^2+1)^n} = \frac{1}{(z+i)^n(z-i)^n}.
$$
Let $r>0$, $t \in [0,\pi]$ and define the contour $\Gamma := [-r,r] \cup \gamma_r$, i.e. $\Gamma$ consists of the straight line from $-r$ to $r$ along the real axis, and then the half circle $\gamma_r$ (counterclockwise, with radius $r$) from $r$ to $-r$, i.e. $\gamma_r(t) := re^{it}$. Then, by the residue theorem:
$$
\oint_\Gamma f_n(z)\,dz = \int_{-r}^rf_n(z)\,dz + \int_{\gamma_r}f_n(z)\,dz = 2\pi i \text{Res}(f_n,i),
$$
since $i$ lies within the contour $\Gamma$. We see that $\lim_{r\to\infty}\int_{\gamma_r}f_n(z)\,dz = 0$, since
\begin{align}
\left|\int_{\gamma_r}f_n(z)\,dz\right| &= \left| \int_0^\pi f_n(\gamma_r(t))\gamma_r'(t)\,dt \right|\\
&= \left| \int_0^\pi \frac{rie^{it}}{(r^2e^{2it}+1)^n}dt \right|\\
&\leq r \int_0^\pi \frac{1}{|r^2e^{2it}+1|^n}dt\\
&\leq r \int_0^\pi \frac{1}{|r^2-1|^n}dt = \frac{\pi r}{|r^2-1|^n} \xrightarrow{\;r \to \infty\;} 0.
\end{align}
Hence, we get that
$$
2I_n = \lim_{r\to\infty}\oint_\Gamma f_n(z)\,dz = 2\pi i \text{Res}(f_n,i) \implies I_n = \pi i \text{Res}(f_n,i).
$$
Now, we calculate $\text{Res}(f_n,i)$. Since $i$ is a pole of order $n$ of $f_n$, we can write
$$
\text{Res}(f_n,i) = \frac{1}{(n-1)!}\lim_{z\to i} \frac{\partial^{n-1}}{\partial z^{n-1}}[(z-i)^nf_n(z)] = \frac{1}{(n-1)!}\lim_{z\to i} \frac{\partial^{n-1}}{\partial z^{n-1}} \left[ \frac{1}{(z+i)^n} \right].
$$
Then, we see that
\begin{align}
\frac{\partial^{n-1}}{\partial z^{n-1}} \left[ \frac{1}{(z+i)^n} \right] &= n(n+1)(n+2)\cdots(2n-3)(2n-2)\frac{p(n-1)}{(z+i)^{2n-1}} \qquad\qquad (*)
\end{align}
where $p$ denotes the "parity-function" defined by
$$
p : \mathbb{N} \to \{-1,1\}, \qquad n \mapsto 
\begin{cases}
1 & n \text{ even}\\
-1 & n \text{ odd}
\end{cases}.
$$
Then, we get
\begin{align}
\frac{1}{(n-1)!}n(n+1)(n+2)\cdots(2n-3)(2n-2)\frac{p(n-1)}{(z+i)^{2n-1}}
=\frac{(2n-2)!}{((n-1)!)^2}\frac{z+i}{(z+i)^{2n}}p(n-1),
\end{align}
and finally, by letting $z \to i$, we obtain
$$
\text{Res}(f_n,i) = \frac{(2n-2)!}{((n-1)!)^2}\frac{2i}{(2i)^{2n}}p(n-1) = -\frac{(2n-2)!}{((n-1)!)^2}\frac{2i}{4^n},
$$
where the last equality follows from comparing the signs of $p(n-1)$ and $(2i)^{2n} = (-4)^n$ for different $n \in \mathbb{N}$. Since $I_n = \pi i \text{Res}(f_n,i)$, we get
$$
I_n = \frac{(2n-2)!}{((n-1)!)^2}\frac{2\pi}{4^n}.
$$
My questions are:

*

*Is this formula for $I_n$ correct? Are there any flaws in my proof?

*I'm not sure that equation $(*)$ is correct. I simply calculated the derivative for $n=1,2, 3$ and then loosely used an inductive argument for the general case. Is there a mistake here?

 A: let $x = \tan t, dx = \sec^2 t dt$, then
$$I_n = \int_{0}^{\frac{\pi}{2}} \frac{1}{(\tan^2 t + 1)^{n-2}} dt$$ $$ = \int_{0}^{\frac{\pi}{2}} {\cos^{n-2} t dt} = C_{n-2}$$
and there is a reduction formula here :
https://en.wikipedia.org/wiki/Wallis'_integrals
A: Recall that $x^2+1=(x+i)(x-i)$ so that we have
$$\frac{1}{(x^2+1)^n}=\frac{1}{(x+i)^n(x-i)^n}$$
By symmetry
$$\int_{[0,\infty)}\frac{1}{(1+x^2)^n}dx=\lim_{R \to \infty}\color{blue}{\frac{1}{2}}\int_{[-R,R]}\frac{1}{(1+x^2)^n}dx$$
Consider the upper half circle $C_R$ with radius $R$ and the integral
$$\int_{C_R}\frac{1}{(1+z^2)^n}dz=\int_{C_R}f_n(z)dz$$
We have that $f_n$ has an $n$-th order pole at $z_0=i$ so
$$\textrm{Res}\bigg(\frac{1}{(1+z^2)^n},i\bigg)=\frac{1}{(n-1)!}\lim_{z \to i}\frac{d^{n-1}}{dz^{n-1}}(z-i)^n\frac{1}{(z+i)^n(z-i)^n}=\\
=\frac{1}{(n-1)!}\lim_{z \to i}\frac{d^{n-1}}{dz^{n-1}}(z+i)^{-n}=\frac{1}{(n-1)!}\lim_{z \to i}(-1)^{n-1}n(n+1)...(n+(n-2))\frac{1}{(z+i)^{2n-1}}=\\
=\frac{(2n-2)!}{((n-1)!)^2}\frac{(-1)^{n-1}}{(2i)^{2n-1}}=\frac{(2n-2)!}{((n-1)!)^2}\frac{(-1)^{n-1}}{(2)^{2n-1}(-1)^{n}i^{-1}}=-i\frac{(2n-2)!}{((n-1)!)^2}\frac{1}{2^{2n-1}}$$
Thus
$$\int_{C_R}\frac{1}{(1+z^2)^n}dz=\pi\frac{(2n-2)!}{((n-1)!)^2}\frac{1}{4^{n-1}}$$
