# How to evaluate $\int_{0}^{\pi/2}\int_{0}^{x} \frac{1}{1 + \cot\left(t\right)}\,\mathrm{d}t \,\mathrm{d}x$?

• I am stuck in a problem $$\int_{0}^{\pi/2}\int_{0}^{x} \frac{1}{1 + \cot\left(t\right)}\,\mathrm{d}t \,\mathrm{d}x$$

• Using the convolution theorem I changed the double integral into a single integral \begin{align} &\int_\limits 0^{\pi/2} \left(\frac{\pi}{2}-x\right)\frac{\sin\left(x\right)} {\sin\left(x\right) + \cos\left(x\right)}\,\mathrm{d}x = \int_{0}^{\pi/2}\frac{x\cos\left(x\right)} {\sin\left(x\right) +\cos\left(x\right)}\,\mathrm{d}x \\[3mm] = &\ \int_{0}^{\pi/2}\frac{x}{1 + \tan\left(x\right)}\,\mathrm{d}x = \int_{0}^\infty\frac{\tan^{-1}\left(\theta\right)}{\left(1 + \theta\right)\left(1 + \theta^{2}\right)}\,\mathrm{d}\theta \end{align}

• [Substituted $$\tan\left(x\right) = \theta$$]. Using integration by part $$v =\frac{\tan^{-1}\left(\theta\right)}{1+\theta^2} \quad\mbox{and}\quad u=\frac{1}{1+\theta},$$ I got the following integral as $$\displaystyle\frac{1}{2}\int_{0}^\infty \left[\frac{\tan^{-1}\left(\theta\right)}{1 + \theta}\right]^{2}\,\mathrm{d}\theta$$.

I am not able to evaluate that.

• Pleased to hear! And feel free to accept an answer as you see fit. Commented Dec 20, 2020 at 15:52
• Hi! It's been a while. I hope you're staying safe and healthy during the pandemic. I've reached out to contact you a few times, but am unsure whether you've received the notes? If you would, please let me know how I can improve my answer. I really want to give you the best answer I can. And feel free to up vote an answer as you see fit. ;-) Commented Feb 28, 2021 at 19:57

\begin{align} \int_0^{\pi/2}\int_0^x \frac1{1+\cot(t)}\,dt\,dx&=\int_0^{\pi/2} \frac{\pi/2-t}{1+\cot(t)}\,dt\tag1\\\\ &=\int_0^{\pi/2}\frac{(\pi/2-t) \sin(t)}{\sin(t)+\cos(t)}\,dt\tag2\\\\ &=\int_0^{\pi/2}\frac{(\pi/2-t)\sin(t)}{\sqrt{2}\cos(t-\pi/4)}\,dt\tag3\\\\ &=\int_{-\pi/4}^{\pi/4}\frac{(\pi/4-t)\sin(t+\pi/4)}{\sqrt{2}\cos(t)}\,dt\tag4\\\\ &=\frac12\int_{-\pi/4}^{\pi/4}\frac{(\pi/4-t)\left(\sin(t)+\cos(t)\right)}{\cos(t)}\,dt\tag5\\\\ &=\frac12 \int_{-\pi/4}^{\pi/4}\left(\frac\pi4 -t\tan(t)\right)\,dt\tag6\\\\ &=\frac{\pi^2}{16}-\int_0^{\pi/4}t\tan(t)\,dt\tag7\\\\ &=\frac{\pi^2}{16}-\left(\frac12 G-\frac{\pi}{8}\log(2)\right)\tag8 \end{align}

where $$G$$ is Catalan's Constant.

NOTES:

1. Changed order of integration and carried out the resulting inner integral.
2. Used the equality $$\frac1{1+\cot(t)}=\frac{\sin(t)}{\sin(t)+\cos(t)}$$.
3. Used the identity $$\sin(t)+\cos(t)=\sqrt{2}\cos(t-\pi/4)$$.
4. Enforced the substitution $$t\mapsto t+\pi/4$$.
5. Expanded $$\sin(t+\pi/4)=\frac{\sqrt 2}{2}(\sin(t)+\cos(t))$$.
6. Exploited even and odd symmetries of integrand.
7. Carried out integral of $$\pi/4$$

To arrive at $$(8)$$, we integrate by parts with $$u=t$$ and $$v=-\log(\cos(t))$$ to find

$$\int_0^{\pi/4}t\tan(t)\,dt=\frac\pi8+\int_0^{\pi/4}\log(\cos(t))\,dt\tag9$$

Next using the Fourier series $$\log(\cos(t))=-\log(2)+\sum_{k=1}^\infty \frac{(-1)^{k-1}\cos(2kt)}{k}$$ in $$(9)$$ and integrating term by term reveals

\begin{align} \int_0^{\pi/4}\log(\cos(t))\,dt&=-\frac\pi4 \log(2)+\frac12\sum_{k=1}^\infty \frac{(-1)^{k-1}}{(2k-1)^2}\\\\ &=-\frac\pi4 \log(2)+\frac12 G\tag{10} \end{align}

Substituting $$(10)$$ into $$(9)$$, we find that

$$\int_0^{\pi/4}t\tan(t)\,dt=-\frac\pi8+\frac12 G$$

Putting it all together yields the coveted result

$$\int_0^{\pi/2}\int_0^x \frac1{1+\cot(t)}\,dt\,dx=\frac{\pi^2}{16}-\left(\frac12 G-\frac{\pi}{8}\log(2)\right)$$

• @Amaan Hi! It's been a while. I hope you're staying safe and healthy during the pandemic. I've reached out to contact you a few times, but am unsure whether you've received the notes? If you would, please let me know how I can improve my answer. I really want to give you the best answer I can. And feel free to up vote an answer as you see fit. ;-) Commented Feb 28, 2021 at 19:57

Since on $$[0,\frac\pi 2]$$ we have $$\sin(x)+\cos(x)=\sqrt{2}\sin(x+\frac\pi 4)\ge 0$$ then:

\displaystyle \begin{align}\int_0^{\frac \pi 2}\int_0^x\frac {\sin(t)}{\sin(t)+\cos(t)}\,dt\,dx&=\frac 12\int_0^{\frac \pi 2}\bigg(x-\ln(\sin(x)+\cos(x))\bigg)\,dx\\\\&=\frac{\pi^2}{16}-\frac 12\frac\pi 2\ln(\sqrt{2})-\frac 12\int_0^{\frac \pi 2}\ln(\sin(x+\frac\pi 4))\,dx\\\\&=\frac{\pi^2}{16}-\frac{\pi\ln(2)}{8}-\int_0^{\frac \pi 4}\ln(\cos(x))\,dx\end{align}

Last one is obtained by change $$x-\frac\pi 4$$ and then parity of $$\cos(x)$$, and its value is: $$\frac K2-\frac{\pi\ln(2)}4$$.

• Hey, I was trying to answer the question and I was using the same approach as you and I managed to get to the last step. Could you elaborate on how you calculated the last integral? Commented Oct 14, 2020 at 23:16
• @mathswizard See my posted solution, which provides an answer to your question. Commented Oct 15, 2020 at 13:22
• @MathsWizzard The text in blue (value of the integral) is actually a link to the post where it is calculated.
– zwim
Commented Oct 15, 2020 at 18:21
• \tan^{-1}(\TJx) Commented Jun 21 at 19:59

$$\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\on}[1]{\operatorname{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$$ \begin{align} &\bbox[5px,#ffd]{\int_{0}^{\pi/2}\int_{0}^{x} {\dd t\,\dd x \over 1 + \cot\pars{t}}} = \int_{0}^{\pi/2}{1 \over 1 + \cot\pars{t}}\int_{t}^{\pi/2} \dd x\,\dd t \\[5mm] = &\ \int_{0}^{\pi/2}{\pi/2 - t \over 1 + \cot\pars{t}}\,\dd t \,\,\,\stackrel{t\ \mapsto\ \pi/2 - t}{=}\,\,\, \int_{0}^{\pi/2}{t \over 1 + \tan\pars{t}}\,\dd t \\[5mm] = &\ \int_{-\pi/4}^{\pi/4}{t + \pi/4 \over 1 + \bracks{\tan\pars{t} + 1}/\bracks{1 - \tan\pars{t}}}\,\dd t \\[5mm] = &\ {1 \over 2}\int_{-\pi/4}^{\pi/4}\pars{t + {\pi \over 4}} \bracks{1 -\tan\pars{t}}\,\dd t \\[5mm] = &\ -\,\ \underbrace{{1 \over 2}\int_{-\pi/4}^{\pi/4}t\tan\pars{t}\,\dd t} _{\ds{{1 \over 2}\,G - {1 \over 8}\,\pi\ln\pars{2}}}\ +\ \underbrace{{1 \over 2}\int_{-\pi/4}^{\pi/4}{\pi \over 4}\,\dd t} _{\ds{\pi^{2} \over 16}} \\[5mm] = &\ \bbx{-\,{1 \over 2}\,G + {1 \over 8}\,\pi\ln\pars{2} + {\pi^{2} \over 16}} \\ & \end{align}

User $${\tt @Mark Viola}$$ already evaluated the last integral.

• Thank you, Everyone... that Helped me much. Commented Oct 15, 2020 at 8:05
• @Amaan You’re welcome. Thanks. Commented Oct 15, 2020 at 15:42

A bit late

$$\displaystyle I\int_{0}^{\pi/2}\int_{0}^{x} \frac{1}{1 + \cot\left(t\right)}\,\mathrm{d}t \,\mathrm{d}x =\frac{1}{2}\int_{0}^\infty \left[\frac{\tan^{-1}\left(\theta\right)}{1 + \theta}\right]^{2}\,\mathrm{d}\theta.$$

Via integration by parts, we have \begin{aligned} I & =-\frac{1}{2} \int_0^{\infty}\left(\tan ^{-1} \theta\right)^2 d\left(\frac{1}{1+\theta}\right) \\ & =- \underbrace{ \frac{1}{2}\left[\frac{\left(\tan ^{-1} \theta\right)^2}{1+\theta}\right]_0^{\infty}}_{=0} +\int_0^{\infty} \frac{\tan ^{-1} \theta}{(1+\theta)\left(1+\theta^2\right)} d \theta \end{aligned} Let $$\theta=\tan x$$, then $$I=\int_0^{\frac{\pi}{2}} \frac{x}{1+\tan x} d x$$ Observing that \begin{aligned} \int \frac{1}{1+\tan x} d x = & \frac{1}{2} \int \frac{(\cos x+\sin x)+(\cos x-\sin x)}{\cos x+\sin x} d x \\ = & \frac{1}{2}\left[\int d x+\int \frac{d(\sin x+\cos x)}{\cos x+\sin x}\right] \\ = & \frac{1}{2}[1+\ln (\cos x+\sin x)]+C \end{aligned} Via integration by parts again, we get \begin{aligned} I =&\frac{1}{2} \int_0^{\frac{\pi}{2}} x d(x+\ln (\sin x+\cos x)) \\ = & \frac{1}{2}\left([x(x+\ln (\sin x+\cos x))]_0^{\frac{\pi}{2}}-\int_0^{\frac{\pi}{2}}[x+\ln (\sin x+\cos x)] d x\right) \\ = & \frac{1}{2}\left[\frac{\pi^2}{8}-\int_0^{\frac{\pi}{2}} \ln (\sin x+\cos x) d x\right]\\=& =\frac{1}{2}\left[\frac{\pi^2}{8}-\left(G-\frac{\pi}{4} \ln 2\right)\right]\cdots (*)\\=& \frac{\pi^2}{16}-\frac{G}{2}+\frac{\pi}{8} \ln 2 \end{aligned} Note of (*)

\begin{aligned} \int_0^{\frac{\pi}{2}} \ln (\sin x+\cos x) d x = & \frac{1}{2} \int_0^{\frac{\pi}{2}} \ln (1+\sin 2 x) d x \\ = & \frac{1}{4} \int_0^\pi \ln (1+\sin x) d x\\=&G-\frac{\pi}{4} \ln 2 \end{aligned}

where the last step using the result.

• Wish people would not use notation such as $\tan^{-1}(\theta)$ because of it's confusion with\\ the rather common text book , though possibly very old text books , use of it denoting angle whose tangent is $\theta$ \\ Better to use $({\tan(\theta)})^{-1}$ or better yet $\frac 1{\tan(\theta)}$\\ Or if u really do mean angle whose tangent is x then write arctan(x) Commented Jun 23 at 18:28

To evaluate $$\int_0^{\pi/2} \int_0^{x} \frac 1 {1+\cot(t)}\,dt \,dx$$ first work with only the inner integral in $$t$$, $$\int_0^x \frac 1 {1+\cot(t)}dt=\int_0^x \frac {\tan(t)}{1+\tan(t)}dt$$. Change integration variable to $$y$$ where $$y=\tan(t)$$ and using $$\frac {dt}{d\,\tan(t)}=\frac 1 {(\frac{d\,tan(t)}{dt})}=\frac 1 {1+\tan(t)^2}= \frac 1{1+y^2}$$ the inner integral equals $$\int_{\tan(0)}^{\tan(x)} \frac y {(y+1)(y^2+1)}dy$$. Expanding into partial fractions the general integral is found by solving for $$A,B,C$$ in $$\frac y{(1+y)(1+y^2)}= A/(y+1)+B/(y+i)+C/(y-i)$$ or $$y=A(y^2+1)+B(y-i)(y+1)+C(y+i)(y+1)$$ where $$i$$ is the positive imaginary $$\sqrt{-1}$$. We find $$\frac y {(1+y)(1+y^2)}=\frac {-1}{2(y+1)}+\frac 1{2(1-i)(y+i)} +\frac 1{2(1+i)(y-i)}$$. Recombining the complex parts obtain $$\frac {-1}{2(y+1)} +\frac{y+1}{2(y^2+1)}$$. So to find the inner integral over the limits, integrate this with respect to $$y$$ and evaluate at $$y=\tan(x)$$ and subtract that at $$y=\tan(0)=0$$ (which is $$0$$) and obtain $$\int_{\tan(0)}^{\tan(x)}\!\! \left ( \frac {-1}{2(y\!+\!1)}\!+\!\frac{y\!+\!1}{2(y^2\!+\!1)}\right)\!dy\!=\!-\frac {\ln(\tan(x)\!+\!1)} {2}+ \frac {\ln(\tan(x)^2\!+\!1)} {4}\!+\!\frac{\arctan(\tan(x))} 2$$. So for the whole double integral we put this inner integral into the outer integral which is integrate over $$x$$ from $$0$$ to $$\pi/2$$. With help of maxima , which is known to be rather 'flaky' at times, the integral is rather difficult but most of the infinite parts cancel and can also save some effort by taking the real part since we know the integral must be real. The result of the general integral is $$\frac{imagpart(Li_2(i \exp(2ix)))+x\ln(2)+x^2 } 4$$
where $$Li_2(z)$$ is the so called Dilogarithm , a special case of the polylogarithm and defined by $$\int_z^{0} \frac {\ln(1-t)} {t} dt = \sum_{k=1}^{\infty} \frac {z^k}{k^2}$$. Evaluation of the integral at $$x=\frac \pi 2$$ and subtracting that at $$x=0$$ gives $$-\frac{ imagpart(Li_2(i))} 2+\frac {\pi \ln(2)} 8 +\frac {\pi^2}{16}$$ where have used $$imagpart(Li_2(-it))=-imagpart(Li_2(it))$$ where $$t$$ is real. For evaluation of $$-imagpart(Li_2(i))$$ used $$-\sum_{k=0}^\infty (-1)^k/(2k+1)^2$$. For practical use of course had to replace the upper limit at $$\infty$$ by a sufficiently large enough integer according to precision desired. Also a numerical integral estimate was done by double romberg that is romberg(romberg(....) integration and agreed with the above to within 8 decimal places or more , the numerical result estimate being $$0.431065739$$.

Let's evaluate the inner integral first. For this, let $$I_1=\int_0^x\frac{1}{1+\cot(t)}~\mathrm dt=\int_0^x\frac{\sin(t)}{\sin(t)+\cos(t)}~\mathrm dt;~I_2=\int_0^x\frac{\cos(t)}{\sin(t)+\cos(t)}~\mathrm dt\tag{1}$$ Clearly, $$I_1+I_2=x$$. And, $$I_1-I_2=-\int_0^x\frac{\cos(t)-\sin(t)}{\sin(t)+\cos(t)}~\mathrm dt=-\int_0^x\frac{1}{\sin(t)+\cos(t)}~\mathrm d\left(\sin t+\cos t\right)=-\ln\left(\sin (x)+\cos( x)\right)$$

So, $$I_1=\int_0^x\frac{1}{1+\cot(t)}~\mathrm dt=\frac12\left(x-\ln\left(\sin(x)+\cos(x)\right)\right)=\frac x2-\frac12\ln\left(\sqrt2\sin\left(x+\frac\pi4\right)\right)\tag{2}$$

The outer integral of the log sine term reminds me of the Clausen function of order $$2$$. So, let's evaluate it by substituting $$u=2\left(x+\frac\pi4\right)$$ so that $$2~\mathrm dx=\mathrm du$$ and $$u=\frac\pi2$$ to $$\frac{3\pi}2$$ as $$x=0$$ to $$\frac\pi2$$.

\begin{aligned}\int_0^{\frac\pi2}\ln\left(\sqrt2\sin\left(x+\frac\pi4\right)\right)~\mathrm dx&=\int_0^{\frac\pi2}\ln\left(\frac{1}{\sqrt2}\cdot2\sin\left(x+\frac\pi4\right)\right)\\&=-\frac12\ln2\cdot\frac\pi2+\frac12\int_{\frac\pi2}^{\frac{3\pi}2}\ln\left(2\sin\frac u2\right)~\mathrm du\\&=-\frac{\pi}{4}\ln2-\frac12\operatorname{Cl}_2\left(\frac{3\pi}2\right)+\frac12\operatorname{Cl}_2\left(\frac\pi2\right)\qquad\text{Clausen function}\\&=-\frac{\pi}4\ln2+\frac G2+\frac G2\qquad\text{relation to Catalan's constant}~ G\\&=G-\frac\pi4\ln2 \end{aligned}

Now, \begin{aligned}\int_{0}^{\frac\pi2}\int_{0}^{x} \frac{1}{1 + \cot\left(t\right)}\,\mathrm{d}t \,\mathrm{d}x&=\frac12\int_0^{\frac\pi2}x~\mathrm dx-\frac12\int_0^{\frac\pi2}\ln\left(\sqrt2\sin\left(x+\frac\pi4\right)\right)~\mathrm dx\\&=\frac12\cdot\frac12\left(\frac\pi2\right)^2+\frac\pi8\ln2-\frac G2\\&=\frac{\pi^2}{16}+\frac\pi8\ln2-\frac G2 \end{aligned}

Hence, $$\color{blue}{\boxed{~\int_{0}^{\frac\pi2}\int_{0}^{x} \frac{1}{1 + \cot\left(t\right)}\,\mathrm{d}t \,\mathrm{d}x=\frac{\pi^2}{16}+\frac\pi8\ln2-\frac G2=\frac1{16}\left(\pi^2+2\pi\ln2-8G\right)~}}$$

where $$G=0.915965594\ldots$$ is Catalan's constant.