Evaluating this integral for different values of a constant As you helped me so well last time, I might as well ask a final question!
Today I'm trying to prove this:
$$
\int_0^\infty \frac{x^{p}}{ 1+x^{2}}dx = \frac{\pi}{2}\cos\left(p\frac{\pi}{2}\right)
$$
For $-1 < p < 1$.
I have no idea how to handle the varying $p$. I've been able to prove the relationship in the case  $p = 0$. So now I could try showing this for $-1 < p < 0$ and $0 < p < 1$ but both of those seem to be tricky. 
Any tips on dealing with the non-constant $p$?
There are poles at $x = i$ and $x = -i$, and if $p < 0$ also at $x = 0$.
I think the best approach would be a semicircle in the top half, maybe with a small inner radius as well in the case $p<0$?
Or should I not be trying to prove the relationship for these separate parts but is there a general way to do it?
 A: Let 
$$
I:(-1,1) \to \mathbb{R},\ I(p)=\int_0^\infty\frac{x^p}{1+x^2}dx.
$$
For every $p \in (-1,0]$ one has $-p \in [0,1)$, and setting $t=x^{-1}$ one gets that
$$
I(-p)=\int_0^\infty\frac{x^{-p}}{1+x^2}dx=\int_0^\infty\frac{t^{p-2}}{1+t^{-2}}dt=\int_0^\infty\frac{t^p}{1+t^2}=I(p).
$$
It is therefore enough to compute $I(p)$ for $p \in [0,1)$. 
We have
$$
I(0)=\int_0^\infty\frac{1}{1+x^2}dx=\arctan x\big|_0^\infty=\frac{\pi}{2}.
$$
From now on $0<p<1$. Denote by $g: \mathbb{C} \to \mathbb{C}$ the principal value of the multiple-valued function $\mathbb{C} \to \mathbb{C}, z \mapsto z^p$, and define
$$
f: \mathbb{C} \to \mathbb{C},\ f(z)=\frac{g(z)}{1+z^2}.
$$
Let $D_R=\{z=x+iy \in \mathbb{C}:\ |z| \le R,\ y \ge 0\}$ with $R>1$. Thanks to the Residue Theorem we have
$$\tag{1}
\int_{\partial D_R}f(z)dz=2i\pi\text{Res}(f,i)=\pi g(i)=\pi e^{ip\pi/2}.
$$
Since $R>1$, setting $\partial D_R=[-R,R]\times0\cup C_R$, we have
$$
\left|\int_{C_R}f(z)dz\right|\le \int_0^\pi R|f(Re^{i\theta})|d\theta \le \pi\frac{R^{p+1}}{R^2-1},
$$
and so
$$\tag{2}
\lim_{R\to \infty}\int_{C_R}f(z)dz=0.
$$
Since
$$
\int_{-R}^Rf(z)dz=\int_0^Rf(x)dx+\int_0^Rf(-z)dz=(1+e^{ip\pi})\int_0^Rf(x)dx,
$$
it follows from (1) that
$$
\int_0^Rf(x)dx=(1+e^{ip\pi})^{-1}\int_{-R}^Rf(z)dz=(1+e^{ip\pi})^{-1}\left[\pi e^{ip\pi/2}-\int_{C_R}f(z)dz\right].
$$
In virtue of (2) we get
$$
I(p)=\pi\frac{e^{ip\pi/2}}{1+e^{ip\pi}}=\frac{\pi}{2\cos(p\pi/2)}.
$$
A: This is a special case of this question to which I gave this answer which says
$$
\int_0^\infty\frac{x^n}{1+x^m}\,\mathrm{d}x=\frac{\pi}{m}\csc\left(\pi\frac{n+1}{m}\right)
$$
for all real $m>0$ and $-1<n<m-1$.
A: If we put
$$I:=\int_0^\infty\frac{x^p}{1+x^2}dx$$
making the following variable change we get
$$x=-u\Longrightarrow dx=-du\Longrightarrow \int_{-\infty}^0\frac{x^p}{1+x^2}dx=\int_\infty^0\frac{(-1)^pu^p}{1+u^2}(-du)=(-1)^pI$$
so that
$$\int_{-\infty}^\infty\frac{x^p}{1+x^2}dx=\left(1+(-1)^p\right)I=\left(1+e^{p\pi i}\right)I\Longleftrightarrow$$
$$\Longleftrightarrow \,\,(***)\,\,\,I=\Re\left(\frac{1}{1+e^{p\pi i}}\right)\int_{-\infty}^\infty\frac{x^p}{1+x^2}dx=\frac{1}{2}\int_{-\infty}^\infty\frac{x^p}{1+x^2}dx$$
For $\,p\geq 0\,$ let us try the following contour, with $\,1<R\in\Bbb R\,$:
$$C:=[-R,R]\cup\left(\gamma_R:=\left\{z\in\Bbb C\;:\;z=Re^{it}\,\,,0\leq t\leq\pi\right\}\right)$$
Putting 
$$f(z):=\frac{z^p}{1+z^2}\Longrightarrow Res_{z=i}(f)=\lim_{z\to i}(z-i)f(z)=\frac{i^p}{2i}=\frac{e^{p\pi i/2}}{2i}$$
so by CIT we get
$$\oint_Cf(z)\,dz=2\pi i\frac{1}{2i}e^{p\pi i/2}=\pi \left(\cos\frac{p\pi}{2}+i\sin\frac{p\pi}{2}\right)$$
Now, by the estimation lemma, we get
$$\left|\int_{\gamma_R}f(z)\,dz\right|\leq \max_{z\in\gamma_R}\frac{|z|^p}{|1+z^2|}R\pi\leq \frac{\pi R^{p+1}}{1-R^2}\xrightarrow [R\to\infty]{} 0\,\,,\,\text{since}\,\,p+1<2$$
Thus, taking the limit above, we get
$$(@@@)\,\,\,\pi \left(\cos\frac{p\pi}{2}+i\sin\frac{p\pi}{2}\right)=\lim_{R\to\infty}\oint_Cf(z)dz=\int_{-\infty}^\infty\frac{x^p}{1+x^2}dx\Longrightarrow$$
$$\int_{-\infty}^\infty\frac{x^p}{1+x^2}dx=\pi\cos\frac{p\pi}{2}\Longleftrightarrow$$
$$\stackrel{\text{from (***) above}}\Longleftrightarrow I=\frac{\pi\cos p\frac{\pi}{2}}{2}\,\,\,\,\,Q.E.D.$$
Now, for $\,-1< p<0\,$ all the above remains mutatis mutandi but there's also the matter of the pole at $\,z=0\,$ ,which I can't handle as I can't manage to find out what is this pole's multiplicity. Yet I'm almost sure the residue here is zero, but can't prove it.
Added: As did proposes in a comment below, let's use the following change of variables:
$$x=\frac{1}{u}\Longrightarrow dx=-\frac{du}{u^2}\Longrightarrow I(p):=\int_\infty^0\frac{u^{-p}}{1+\frac{1}{u^2}}\left(-\frac{du}{u^2}\right)=:I(-p)$$
so that all we did above indeed remains valid when $-1< p<0\,$
Added trying to address Joriki's point in the comments below: We got, 3 lines before $\,(***)\,$, that
$$\int_{-\infty}^0\frac{x^p}{1+x^2}dx=e^{ip\pi}I\Longrightarrow \int_{-\infty}^\infty\frac{x^p}{1+x^2}dx=\int_{-\infty}^0\frac{x^p}{1+x^2}dx+\int_0^\infty\frac{x^p}{1+x^2}dx=$$
$$=(1+e^{ip\pi})I$$
and as Joriki remarks from this it follows
$$I=\frac{1}{1+e^{ip\pi}}\int_{-\infty}^\infty\frac{x^p}{1+x^2}dx$$ 
without taking the real part in the RHS , and thus in $\,(@@@)\,$ we actually have
$$\int_{-\infty}^\infty\frac{x^p}{1+x^2}dx=\pi\left(\cos p\frac{\pi}{2}+i\sin p\frac{\pi}{2}\right)=\pi e^{ip\pi}$$
and from here we get the same result as Mercy got below:
$$I=\frac{\pi e^{ip\pi}}{1+e^{ip\pi}}=\frac{\pi}{2}\sec p\frac{\pi}{2}$$
