What is the principal value of the integral $$\int \limits _0^\infty \left( \frac {1}{x^2}\frac{\cot(x)}{x} \right) dx ?$$ Maple finds $PV \int_0^\infty \tan(x)/x dx = \pi/2.$ Such integrals arise in physics. I unsuccessfully asked it in SE.

formula 3.749.2 from Gradshteyn & Ryzhik gives: $$\int_0^{\infty}\frac{1x\;{\rm cotan}x}{x^2+\epsilon^2}dx=\frac{\pi}{2\epsilon}\frac{\pi}{e^{2\epsilon}1}\quad{\rm for}\quad \epsilon>0.$$ taking the limit $\epsilon\downarrow 0$ gives your $\pi/2$; G&R do not explicitly say that their formula is a principal value integral, but it's the only sensible way to avoid the poles of the cotangent at $\pi,2\pi,...$; note that there is no singularity at $x=0$, so the limit $\epsilon\downarrow 0$ gives no ambiguity. Here's the derivation by contour integration, as promised. The integral over $1/(x^2+\epsilon^2)$ is elementary, so I only do the one involving the cotangent: $${\cal P}\int_{0}^{\infty}dx\frac{x\;{\rm cotan}x}{x^2+\epsilon^2}= \frac{1}{4}\lim_{\delta\rightarrow 0}\left(\int_{\infty+i\delta}^{\infty+i\delta}dx\frac{x\;{\rm cotan}x}{x^2+\epsilon^2}+ \int_{\inftyi\delta}^{\inftyi\delta}dx\frac{x\;{\rm cotan}x}{x^2+\epsilon^2}\right)$$ $$=\frac{1}{4}\lim_{\delta\rightarrow 0}\left(\int_{\infty+i\delta}^{\infty+i\delta}\frac{dx}{\sin x}\frac{x\;e^{ix}}{x^2+\epsilon^2}+ \int_{\inftyi\delta}^{\inftyi\delta}\frac{dx}{\sin x}\frac{x\;e^{ix}}{x^2+\epsilon^2}\right)$$ $$=\frac{1}{4}\lim_{\delta\rightarrow 0}\left(\int_{\infty+i\delta}^{\infty+i\delta}\frac{dx}{\sin x}\frac{x\;e^{ix}}{x^2+\epsilon^2}+ \int_{\inftyi\delta}^{\inftyi\delta}\frac{dx}{\sin x}\frac{x\;e^{ix}}{x^2+\epsilon^2}\right)$$ $$=\frac{1}{4}\left(\int_{C_+}\frac{dz}{zi\epsilon}\frac{z\;e^{iz}}{(z+i\epsilon)\sin z}+ \int_{C_}\frac{dz}{z+i\epsilon}\frac{z\;e^{iz}}{(zi\epsilon)\sin z}\right)$$ $$=\frac{1}{4}\times 2\pi i\times\left(\lim_{z\rightarrow i\epsilon}\frac{z\;e^{iz}}{(z+i\epsilon)\sin z} \lim_{z\rightarrow i\epsilon}\frac{z\;e^{iz}}{(zi\epsilon)\sin z}\right)$$ $$=\frac{1}{4}\times 2\pi i\times 2\times \frac{1}{\sin i\epsilon}\frac{i\epsilon\;e^{\epsilon}}{2i\epsilon}$$ $$=\frac{\pi}{e^{2\epsilon}1}$$ In the first equality I inserted the definition of principal value; in the second equality I used that $xe^{\pm ix}/\sin x = x\;{\rm cotan}x\pm ix$ and the second term vanishes upon integration because it is an odd function of $x$; in the third and following equalities I have closed the contour in the upper half of the complex plane for the first integral (contour $C_+$, picking up the pole at $z=i\epsilon$), and in the lower half of the complex plane for the second integral (contour $C_$, pole at $z=i\epsilon$). And so I arrive at the answer from Gradshteyn & Ryzhik, confirming that theirs was indeed a principal value result. 


Yes the value $\pi/2$ can be obtained like this. Let $$ f(x):=\frac {1}{x^2}\frac{\cot(x)}{x} $$ We may compute $$ \int_0^{\pi/2} f(x)\;dx + \sum_{k=1}^\infty \int_0^{\pi/2}\big(f(k\pi+x)+f(k\pix)\big)\;dx=\frac{\pi}{2} \tag{1}$$ and this converges. We can think of (1) as a "rearrangement" of the required integral. But the integrands in (1) are positive: Use $\cot x > 0$ for $0 < x < \pi/2$ and $\cot(k\pi+x) = \cot x$ and $\cot(k\pix) = \cot x$. Also $(1/x)  \cot x$ increases from $0$ on $(0,\pi/2)$, so $f(x) >0$ on $(0,\pi/2)$. Next $$ f(k\pi+x)+f(k\pix) = \left(\frac{1}{(k\pi+x)^2}+\frac{1}{(k\pix)^2}\right) + \left(\frac{1}{k\pi+x}+\frac{1}{k\pix}\right)\cot x $$ and each of the two halves is positive on $(0,\pi/2)$. Recall $$ \sum_{k=1}^\infty \left(\frac{1}{(k\pi+x)^2}+\frac{1}{(k\pix)^2}\right) = \csc^2 x  \frac{1}{x^2} $$ $$ \sum_{k=1}^\infty\left(\frac{1}{k\pi+x}+\frac{1}{k\pix}\right)=\frac{1}{x}\cot x $$ $$ \sum_{k=1}^\infty\left(\frac{1}{k\pi+x}+\frac{1}{k\pix}\right)\cot x=\frac{\cot x}{x}\cot^2 x $$ Our answer is the sum of three integrals: $$ \int_0^{\pi/2} \left[\left(\frac{1}{x^2}\frac{\cot x}{x}\right)+\left(\csc^2 x\frac{1}{x^2}\right)+\left(\frac{\cot x}{x}\cot^2 x\right)\right]dx = \int_0^{\pi/2} 1\;dx = \frac{\pi}{2} $$ 


There exists still another way to calculate this integral. Namely, let (the principal values are assumed) $I_1=\int\limits_0^\infty \left (\frac{1}{x^2}\frac{\cot{x}}{x}\right )dx$ and $I_2=\int\limits_0^\infty \frac{\tan{x}}{x}dx$. Then $$I_1+I_2=\int\limits_0^\infty \left (\frac{1}{x^2}2\frac{\cot{(2x)}}{x} \right )dx=2I_1.$$ This shows that $I_1=I_2$, so let's concentrate on $I_2$. That follows is (somewhat elaborated) calculations of Daryl McCullough from http://mathforum.org/kb/message.jspa?messageID=5667982 We have ($\epsilon\to 0$ limit is assumed) $$I_2=\sum\limits_{n=0}^\infty\left [ \int\limits_{n\pi}^{n\pi+\pi/2\epsilon}\frac{\tan{x}}{x}dx+\int\limits_{n\pi+\pi/2+\epsilon}^{(n+1)\pi}\frac{\tan{x}}{x}dx \right ]=\sum\limits_{n=0}^\infty\left [ \int\limits_0^{\pi/2\epsilon}\frac{\tan{(x+n\pi)}}{x+n\pi}dx+\int\limits_{\pi/2+\epsilon}^{\pi}\frac{\tan{(x+n\pi)}}{x+n\pi}dx \right ].$$ But for integer $n$, $\tan{(x+n\pi)}=\tan{x}$, and after the substitution $y=\pix$ in the second integral, we get $$I_2=\sum\limits_{n=0}^\infty\int\limits_0^{\pi/2\epsilon}\tan{x}\left[\frac{1}{x+n\pi}+\frac{1}{x(n+1)\pi}\right ] dx=\int\limits_0^{\pi/2\epsilon}\frac{\tan{x}}{x}+$$ $$\sum\limits_{n=1}^\infty\int\limits_0^{\pi/2\epsilon}\tan{x}\left[\frac{1}{x+n\pi}+\frac{1}{xn\pi}\right ] dx.$$ But $\frac{1}{x+n\pi}+\frac{1}{xn\pi}=\frac{2x}{x^2n^2\pi^2}$ are all negative for $n=1,2,\ldots$ and $x\in(0,\pi/2)$. Therefore we can use Tonelli's theorem to justify changing the order of the summation and integration in the second term. Hence $$I_2=\int\limits_0^{\pi/2\epsilon}\tan{x}\left [\frac{1}{x}+\sum\limits_{n=1}^\infty\left (\frac{1}{x+n\pi}+\frac{1}{xn\pi}\right)\right ]dx.$$ It remains to recall the Euler's formula for $\cot{x}$: $$\cot(x)=\frac{1}{x}+\sum\limits_{n=1}^\infty\left (\frac{1}{x+n\pi}+\frac{1}{xn\pi}\right),$$ and the result $I_2=\frac{\pi}{2}$ follows immediately (because $\tan{x}\cot{x}=1$). 

