Tricky elementary integral $\int_{0}^{\frac{\pi}{2}}x\cot(x)dx$. 
$$\int_{0}^{\frac{\pi }{2}}x\cot(x)dx$$

I tried integration by parts and got $\dfrac{1}{2}\int_{0}^{\frac{\pi }{2}}x^{2} \csc^{2}x dx$ which doesn't help at all. I don't really know what to do. Any help will be greatly appreciated.
 A: Another way to do this integral:
$$I=\int_0^{\pi/2}x\cot(x)\,dx=\int_0^{\pi/2}(\pi/2-x)\tan(x)\,dx\\ \Rightarrow 2I=\int_0^{\pi/2}\frac{2x\cos^2(x)+2(\pi/2-x)\sin^2(x)}{2\sin(x)\cos(x)}\, dx\\=\int_0^{\pi/2}\frac{2x\cos(2x)+\frac{\pi}{2}(1-\cos(2x))}{\sin(2x)}\,dx\\\Rightarrow 4I=\int_0^{\pi}\frac{x\cos(x)+\frac{\pi}{2}(1-\cos(x))}{\sin(x)}\, dx\\=\int_0^{\pi/2}x\cot(x)\,dx+\frac{\pi}{2}\int_0^{\pi/2}\csc(x)-\cot(x)\,dx+\int_{\pi/2}^\pi (x-\pi)\cot(x)\,dx+\frac{\pi}{2}\int_{\pi/2}^\pi\csc(x)+\cot(x)\,dx\\=2I+\pi\int_0^{\pi/2}\csc(x)-\cot(x)\,dx\\=2I-\pi\log|1+\cos(x)|]^{\pi/2}_0\\\Rightarrow I=\frac{\pi}{2}\log(2).$$
A: A concise approach
$$\int_{0}^{\frac{\pi }{2}}x\cot x\ dx
= \int_{0}^{\frac{\pi }{2}}\int_0^1
\frac {\cot^2 x}{y^2 +\cot^2x}dy\  dx=\frac\pi2\int_0^1 \frac1{1+y}dy=\frac\pi2\ln2
$$
A: The integral is due to Leonhard Euler.
$$I=\int_0^{\pi/2}x\cot xdx=\int_0^{\pi/2}x(\ln\sin x)^\prime dx=-\int_0^{\pi/2}\ln\sin xdx$$
Take $x=\pi/2-u$, we have
$$I=-\int_0^{\pi/2}\ln\cos udu$$
Therefore
$$2I=-\int_0^{\pi/2}(\ln\sin x+\ln\cos x)dx=\frac\pi2\ln2-\int_0^{\pi/2}\ln\sin2xdx$$
The later integral could be transformed:
$$J=\int_0^{\pi/2}\ln\sin2xdx=\frac12\int_0^\pi\ln\sin xdx=\int_0^{\pi/2}\ln\sin xdx=-I$$
since $\sin x=\sin(\pi-x)$, thus
$$J=\frac\pi2\ln2$$

As an extra exercise, try to calculate
$$I(r)=\int_0^\pi\ln(1-2r\cos x+r^2)dx$$ where $\lvert r\rvert\neq1$. (due to S.D. Poisson)
A: A handy formula when integrating a polynomial times cot or csc.
It can be shown that:
$\displaystyle \int_{a}^{b}p(x)\cot(x)dx=2\sum_{k=1}^{\infty}\int_{a}^{b}p(x)\sin(2kx)dx$
So, you have $\displaystyle 2\sum_{k=1}^{\infty}\int_{0}^{\frac{\pi}{2}}x\sin(2kx)dx$ 
$=\displaystyle \sum_{k=1}^{\infty}\left(\frac{\sin(k\pi)}{2k^{2}}-\frac{\pi\cos(k\pi)}{2k}\right)$
Note that $\displaystyle \sin(\pi k)=0, \;\ \cos(\pi k)=(-1)^{k}$.  
So, it reduces to:
$\displaystyle \frac{\pi}{2}\sum_{k=1}^{\infty}\frac{(-1)^{k+1}}{k}$
$=\displaystyle \frac{\pi}{2}\ln(2)$
The above formula is satisfied as long as sin(x/2) or cos(x/2) is not zero in [a,b].
Try it with other upper limits like $\frac{\pi}{4}$ or $p(x)=x^{2}$.
If you're familiar with Zeta sums and the Catalan constant(which may pop up) you can integrate these functions easier. 
There is an analogous formula for csc:
$\displaystyle \int_{a}^{b}p(x)csc(x)dx=2\sum_{k=0}^{\infty}\int_{a}^{b}p(x)\sin(2k+1)x dx$
A: that is a great question  but there is a splendid Q , I will post for knowlodge
$$I=∫_{0}^{\frac{π }{4}}x^2 \cot xdx\ \ \ \ \ \ \ \ \ by\ parts\ we\ have\\
\\
I=x^2\ln(\sin x)\tfrac{\frac{π }{4}}{0}-2∫_{0}^{\frac{π }{4}}x\ln(\sin(x))dx\\
\\
=-\frac{π ^{2}\ln(2)}{32}+∫_{0}^{\frac{π }{4}}(2\ln(2)+2∑_{k=1}^{\infty }\frac{\cos(2kx)}{k})xdx\\
\\
=\frac{-π ^{2}\ln(2)}{32}+2\ln(2)∫_{0}^{\frac{π }{4}}xdx+2∑_{k=1}^{\infty }\frac{1}{k}∫_{0}^{\frac{π }{4}}x\cos(2kx)dx\\
\\
\\
but\ ∫ x\cos(2kx)=\frac{x\sin(2kx)}{2k}+\frac{\cos(2kx)}{4k^2}+c\\
\\
\therefore ∫_{0}^{\frac{π }{4}}x\cos(2kx)dx=\frac{π \sin(\frac{kπ }{2})}{8k}+\frac{\cos(\frac{π k}{2})}{4k^2}-\frac{1}{4k^2}\\
\\$$
$$\therefore I=\frac{-π ^{2}\ln(2)}{32}+\ln(2)x^2\tfrac{\frac{π }{4}}{0}+2∑_{k=1}^{\infty }(\frac{π \sin(\frac{π k}{2})}{8k^2}+\frac{\cos(\frac{π k}{2})}{4k^3}-\frac{1}{4k^3})\\
\\
=\frac{-π ^{2}}{32}\ln(2)+\frac{π ^{2}}{16}\ln(2)-\frac{1}{2}∑_{k=1}^{\infty }\frac{1}{k^3}+\frac{1}{2}∑_{k=1}^{\infty }(\frac{\cos(π k)}{8k^3})+\frac{π }{4}∑_{k=1}^{\infty }\frac{(-1)^{k-1}}{(2k-1)^2}\\
\\
=\frac{π ^{2}}{32}\ln(2)+\frac{π G}{4}-\frac{1}{2}\zeta (3)-\frac{3}{64}\zeta (3)\\
\\
\\
\therefore I=∫_{0}^{\frac{π }{4}}x^2.\cot(xdx=\frac{π ^{2}}{32}.\ln(2)-\frac{35}{64}\zeta (3)+\frac{π G}{4}\\$$
A: Using Integration by Parts, we have
$$
\begin{aligned}
I &=\int_{0}^{\frac{\pi}{2}} x d(\ln (\sin x)) \\
&=[x \ln (\sin x)]_{0}^{\frac{\pi}{2}}-\int_{0}^{\frac{\pi}{2}} \ln (\sin x) d x
\end{aligned}
$$
By my post in Quora, $$\int_{0}^{\frac{\pi}{2}} \ln (\sin x) d x=-\frac{\pi}{2} \ln 2\tag*{}
$$
Now we can conclude that
$$\boxed{I=\frac{\pi}{2} \ln 2}
$$
