# For this integral: $\int_0^{\frac{\pi}{4}} x \tan(x) dx$

For the following integral: $$\int_0^{\frac{\pi}{4}} x \tan(x) dx=\frac{G}{2}-\frac{\pi\ln(2)}{8}$$ where $$G$$ is Catalan's constant. After integrating by parts, it is equivalent to compute $$\int_0^{\pi/4} \ln(\cos(x)) dx$$. How can I proceed further?

• There is an infinite series representation for $\log(\cos(x))$ in this post, does that give you enough to solve the problem? math.stackexchange.com/questions/292326/…
– Joe
Nov 20, 2021 at 13:17
• @Joe That can also be used to evaluate this integral. Nov 20, 2021 at 13:19

We want to evaluate the definite integral $$\mathcal{I} = \displaystyle \int_0^{\frac{\pi}{4}} \ln( \cos x ) \ \mathrm dx$$

We note that \begin{align} \ln(\cos{x}) &=\frac12\Big( ( \ln(\sin{x}) + \ln(\cos{x}) ) -(\ln(\sin{x}) -\ln(\cos{x}))\Big) \\ &= \frac12 \ln \Big( \frac{\sin(2x)}{2}\Big) -\frac12\ln(\tan{x}) \\ &= \frac12\ln(\sin(2x)) -\frac12 \ln(2) - \frac12\ln(\tan{x}) \end{align}

Using this, the integrand simplifies to

$$\mathcal{I} =\frac12 \displaystyle \int_0^{\frac{\pi}{4}} \ln(\sin(2x))\ \mathrm dx - \frac12 \int_0^{\frac{\pi}{4}} \ln(\tan{x})\ \mathrm dx -\frac12\int_0^{\frac{\pi}{4}} \ln{2} \ \mathrm dx$$

Starting with the second integral, it is a well known result.

$$\int_0^{\frac{\pi}{4}} \ln(\tan{x})\ \mathrm dx = -G$$

$$G$$ denotes Catalan's constant.

For the first integral, the substitution $$2x=t$$ gives $$\dfrac{1}{2}\int_0^{\frac{\pi}{2}} \ln(\sin{x})\ \mathrm dx$$ This integral just equals $$- \dfrac{\pi}{4}\ln{2}$$, by using the well known result

$$\int_0^{\frac{\pi}{2}} \ln(\sin{x})\ \mathrm dx = - \dfrac{\pi}{2}\ln{2}$$

The third integral is trivial and equals $$\frac{\pi}{4}\ln{2}$$.

Summing up the values of the 3 integrals, our original integral equals

$$\boxed{\boxed{\int_0^{\frac\pi4}\ln(\cos x )\,\mathrm dx =\frac G2 - \dfrac{\pi}{4}\ln{2}}}$$

And using integration by parts,

\begin{align}\int_0^{\frac\pi4}x\tan x\,\mathrm dx &= \frac\pi8\ln2+\int_0^{\frac\pi4}\ln(\cos x)\,\mathrm dx \\ &= \frac G2-\frac\pi8\ln2\end{align} Which matches the result given in the OP.

EDIT

As people had problems with the second integral, here is solution.

The Catalan's constant is defined as

$$G=\beta(2)= \sum_{k=0}^\infty\frac{(-1)^k}{(2k+1)^2}$$

Here $$\beta(\cdot)$$ denotes the Dirichlet's beta function.

In our integral, we substitute $$\tan x = t$$.

\begin{align}\int_0^{\frac\pi4}\ln \tan x\,\mathrm dx &= \int_0^1 \frac{\ln t}{1+t^2}\,\mathrm dt \\ &= \sum_{k=0}^\infty(-1)^k \int_0^1 x^{2k}\ln x\,\mathrm dx \\ &= -\sum_{k=0}^\infty \frac{(-1)^k}{(2k+1)^2}\\ &= -G\end{align}

• This is a nice answer. Do you have a reference for the `well known' log sin and log tan integrals?
– Joe
Nov 20, 2021 at 13:23
• @Joe The log tan integral is provided in the "Integral representations" section of the Wikipedia page of Catalan's constant. The log sin integral is given here. Nov 20, 2021 at 13:29
• @Joe Thank you! But how to achieve that series expansion formula? Nov 20, 2021 at 13:39
• @LaxmiNarayanBhandari Thank you. My question is how to get that G, actually I got these steps, and convert from that log(tan) to log(cos), then I stuck at log(cos) .... Nov 20, 2021 at 13:43
• @Laxmi Narayan Bhandari thank you, I like the derivation of the log sin integral. Unfortunately that Wikipedia page on G only lists the log tan integral, and doesn't derive it
– Joe
Nov 20, 2021 at 13:46

Using the complex definition of cosine,

\begin{align}\ln\cos x&= \ln\Big(\frac{e^{ix}+e^{-ix}}2\Big) \\ &= ix+\ln(1+e^{-2ix})-\ln2 \\ &= -ix+\ln(1+e^{2ix})-\ln2 \\ \implies \ln\cos x &= -\ln 2 +\frac12(\ln(1+e^{2ix})+\ln(1+e^{-2ix})) \\ &= -\ln 2 -\frac12 \sum_{k=1}^\infty (-1)^k\frac1k(e^{2ikx}+e^{-2ikx}) \\ \ln\cos x&= -\ln2-\sum_{k=1}^\infty \frac{(-1)^k}k\cos(2kx) \end{align}

This is the Fourier series of $$\ln\cos x$$. Using this result,

\begin{align}I =\int_0^{\pi/4}\ln\cos x\,\mathrm dx &= \int_0^{\pi/4}-\ln2 -\sum_{k=1}^\infty\frac{(-1)^k}k \cos(2k x)\,\mathrm dx \\ &= -\frac\pi4\ln2-\sum_{k=1} ^\infty \frac{(-1)^k}k\int_0^{\pi/4}\cos(2kx)\,\mathrm dx \\ &= -\frac\pi4\ln2-\frac12\sum_{k=1}^\infty \frac{(-1)^k}{k^2} \sin\Big(\frac{k\pi}2\Big) \end{align}

Now, we note that for $$k\in\mathbb Z$$

$$\sin(k\pi) =0 , \quad \sin\Big(\frac{(2k+1)\pi}2\Big) = (-1)^k$$

Using this, we re-index our sum.

\begin{align}I &= -\frac\pi4\ln2-\frac12\sum_{k=0}^\infty\frac{(-1)^{2k+1}(-1)^k}{(2k+1)^2} \\ &= -\frac\pi4\ln2+\frac12\sum_{k=0}^\infty \frac{(-1)^k}{(2k+1)^2} \\ I &= \frac G2-\frac\pi4\ln2 \end{align}

To the nice solutions - just to add another approach (which does not use the trigonometry): $$I=\int_0^{\pi/4}x\tan xdx=(x=\tan^{-1}t)\,\,\int_0^1\tan^{-1}t\frac{tdt}{1+t^2}$$ $$= (IBP)\,\,\,\,\frac{\pi\ln2}{8}\ln2-\frac{1}{2}\int_0^1\frac{\ln(1+t^2)}{1+t^2}dt$$ Making change $$x=1/t$$ $$\int_0^1\frac{\ln(1+t^2)}{1+t^2}dt=\int_1^\infty\frac{\ln(1+x^2)}{1+x^2}dx-2\int_1^\infty\frac{\ln x}{1+x^2}dx$$ $$2\int_0^1\frac{\ln(1+t^2)}{1+t^2}dt=\int_0^\infty\frac{\ln(1+x^2)}{1+x^2}dx-2G$$ The last integral it is easy to evaluate via complex integration: $$\int_0^\infty\frac{\ln(1+x^2)}{1+x^2}dx=\Re\int_{-\infty}^\infty\frac{\ln(1-ix)}{1+x^2}dx$$ Closing the contour in the upper half-plane (where we have one simple pole and no branch points for the chosen integrand) $$\int_{-\infty}^\infty\frac{\ln(1-ix)}{1+x^2}dx=2\pi i\operatorname{Res}_{x=i}\frac{\ln(1-ix)}{1+x^2}=2\pi i\frac{\ln2}{2i}=\pi\ln2$$ Taking all together $$I=\frac{\pi\ln2}{8}-\frac{\pi\ln2}{4}+\frac{G}{2}=\frac{G}{2}-\frac{\pi\ln2}{8}$$

By integration by parts, we have

\begin{aligned} \int_{0}^{\frac{\pi}{4}} x \tan x d x &=-\int_{0}^{\frac{\pi}{4}} x d(\ln (\cos x)) \\ &=-\left[ x \ln (\cos x)\right]_{0}^{\frac{\pi}{4}}+\int_{0}^{\frac{\pi}{4}} \ln (\cos x) d x\\&= -\frac{\pi}{4} \ln \left(\frac{1}{\sqrt{2}}\right)+\int_{0}^{\frac{\pi}{4}} \ln (\cos x) d x \end{aligned}

By my post in Quora,

$$\int_{0}^{\frac{\pi}{4}} \ln (\cos x) dx =-\frac{\pi}{4} \ln 2+\frac{G}{2},\tag*{}$$ $$\textrm{where G is the Catalan's constant.}$$

Hence we can conclude that

\begin{aligned}\int_{0}^{\frac{\pi}{4}} x \tan x d x &= -\frac{\pi}{4} \ln \left(\frac{1}{\sqrt{2}}\right) -\frac{\pi}{4} \ln 2+\frac{G}{2}\\&= -\frac{\pi}{8} \ln 2+\frac{G}{2}\end{aligned}

Rewrite the integral as \begin{align} \int_{0}^{\frac{\pi}{4}} x \tan x d x &=-\int_{0}^{\frac{\pi}{4}} x d[\ln (2\cos x)] \overset{ibp}= -\frac{\pi}{8} \ln2 +I \end{align} where $$I=\int_{0}^{\frac{\pi}{4}} \ln (2\cos x) dx$$, along with $$J=\int_{0}^{\frac{\pi}{4}} \ln (2\sin x) dx$$. Note \begin{align} I-J&=-\int_0^{\frac\pi4}\ln (\tan x )dx=G\\ I+J &= \int_{0}^{\frac{\pi}{4}} \ln (2\sin 2x) dx \overset{x\to\frac\pi4 -x}= \int_{0}^{\frac{\pi}{4}} \ln (2\cos 2x) dx\\ &=\frac12 \int_{0}^{\frac{\pi}{4}} \ln (4\sin 2x\cos2x) dx \overset{2x\to x}= \frac14 \int_{0}^{\frac{\pi}{2}} \ln (2\sin 2x) dx\\ &= \frac12 (I+J)=0 \end{align} which leads to $$I=\frac12G$$ and $$\int_{0}^{\frac{\pi}{4}} x \tan x d x = \frac12G -\frac{\pi}{8} \ln2$$

• Nice substitutions. (+1) Jan 29 at 11:18

Another way, \begin{align}J&=\int_0^{\frac{\pi}{4}}t\tan t dt\\ &\overset{x=\tan t}=\int_0^1 \frac{x\arctan x}{1+x^2}dx\\ &=\int_0^1 \frac{x}{1+x^2}\left(\underbrace{\int_0^x \frac{1}{1+u^2}du}_{z=\frac{u}{x}}\right)dx\\ &=\int_0^1 \int_0^1 \frac{x^2}{(1+x^2)(1+x^2z^2)}dxdz\\ &=\int_0^1 \int_0^1 \left(\frac{1}{(1-z^2)(1+x^2z^2)}-\frac{1}{(1-z^2)(1+x^2)}\right)dxdz\\ &=\int_0^1 \int_0^1 \frac{1}{z(1-z^2)}\left(\frac{z}{1+x^2z^2}-\frac{z}{1+x^2}\right)dxdz\\ &=\int_0^1 \frac{1}{z(1-z^2)}\left(\left(\underbrace{\int_0^1 \frac{z}{1+x^2z^2}dx}_{u=xz}\right)-z\int_0^1\frac{1}{1+x^2}dx\right)dz\\ &=\int_0^1 \frac{1}{z(1-z^2)}\left(\left(\int_0^z \frac{1}{1+u^2}du\right)-\frac{\pi z}{4}\right)dz\\ &\overset{\text{IBP}}=\underbrace{\left[\left(\ln z-\frac{1}{2}\ln(1-z^2)\right)\left(\left(\int_0^z \frac{1}{1+u^2}du\right)-\frac{\pi z}{4}\right)\right]_0^1}_{=0}-\\&\int_0^1 \left(\ln z-\frac{1}{2}\ln(1-z^2)\right)\left(\frac{1}{1+z^2}-\frac{\pi}{4}\right)dz\\ &=-\int_0^1 \frac{\ln z}{1+z^2}dz+\frac{\pi}{4}\int_0^1 \ln z dz+\frac{1}{2}\int_0^1 \frac{\ln(1-z^2)}{1+z^2}dz-\frac{\pi}{8}\int_0^1 \ln(1-z^2)dz\\ &=\text{G}-\frac{\pi}{4}+\frac{1}{2}\int_0^1 \frac{\ln(1-z^2)}{1+z^2}dz-\frac{\pi}{8}\underbrace{\left[x\ln(1-x^2)-\ln\left(\frac{1-x}{1+x}\right)-2x\right]_0^1}_{=2\ln 2-2}\\ &=\text{G}+\frac{1}{2}\underbrace{\int_0^1 \frac{\ln(1-z^2)}{1+z^2}dz}_{y=\frac{1-z}{1+z}}-\frac{1}{4}\pi\ln 2\\ &=\text{G}+\frac{1}{2}\int_0^1 \frac{\ln\left(\frac{4y}{(1+y)^2}\right)}{1+y^2}dy-\frac{1}{4}\pi\ln 2\\ &=\text{G}+\int_0^1 \frac{\ln 2}{1+y^2}dy+\frac{1}{2}\int_0^1 \frac{\ln y}{1+y^2}dy-\int_0^1 \frac{\ln(1+y)}{1+y^2}dy-\frac{1}{4}\pi\ln 2\\ &=\frac{1}{2}\text{G}-\underbrace{\int_0^1 \frac{\ln(1+y)}{1+y^2}dy}_{=\text{K}}\\ \text{K}&\overset{z=\frac{1-y}{1+y}}=\int_0^1 \frac{\ln\left(\frac{2}{1+z}\right)}{1+z^2}dz=\frac{1}{4}\pi\ln 2-\text{K}\\ \text{K}&=\frac{1}{8}\pi\ln 2\\ J&=\boxed{\frac{1}{2}\text{G}-\frac{1}{8}\pi\ln 2} \end{align}