Integral $\int_0^\infty\frac{\log(1+\cos x)}{1+e^x}\,dx=0$

In this question, the result $$\int_0^\infty\frac{\log\cos^2x}{1+e^{2x}}\,dx=-\frac{\log^22}2$$ was shown by writing $\log\cos^2x=2\log\cos x$.

The OP of the linked question attempted the integral as follows $$\int_0^\infty\frac{\log\cos^2x}{1+e^{2x}}\,dx=\frac12\int_0^\infty\frac{\log(1+\cos x)}{1+e^x}\,dx-\frac{\log^22}2$$ by writing $\log\cos^2x=\log(1+\cos2x)-\log2$.

Equating these two expressions yields $$\int_0^\infty\frac{\log(1+\cos x)}{1+e^x}\,dx=0.$$ Is there a direct way to prove this result (without writing $\log\cos^2x$ in two different ways to get there)?


Note that the integrand is absolutely integrable on $(0,\infty)$; this claim will let us do things like swap sums and integrals, and break up the region of integration.

Start by writing part of the integrand using a geometric series: \begin{align} I=\int_{0}^{\infty} \frac{\log(1+\cos(x))}{1+e^x}\,dx &= \int_{0}^{\infty}\log(1+\cos(x))\cdot \frac{1}{1-(-e^{-x})}\cdot e^{-x}\,dx\\&=\sum_{n=1}^{\infty}(-1)^{n+1}\int _0^{\infty} \log(1+\cos(x)) e^{-nx}\,dx\end{align}

Split up $(0,\infty)$ into blocks of length $2\pi$: $$ I=\sum_{n=1}^{\infty}(-1)^{n+1}\sum_{m=0}^{\infty}\int _{2\pi m}^{2\pi(m+1)} \log(1+\cos(x)) e^{-nx}\,dx $$ Change of variable to standardize the new region of integration to $(0,2\pi)$: $$ I=\sum_{n=1}^{\infty}(-1)^{n+1}\sum_{m=0}^{\infty}e^{-2mn\pi}\int _{0}^{2\pi} \log(1+\cos(x)) e^{-nx}\,dx $$This middle sum is a geometric series: $$ I=\sum_{n=1}^{\infty}(-1)^{n+1}\cdot\frac{1}{2}\left(1+\coth (\pi n)\right) \cdot \int _{0}^{2\pi} \log(1+\cos(x)) e^{-nx}\,dx $$Invoke the Fourier series for the log term on $(0,2\pi)$; this is the same as the Fourier series for $\log(1-\cos(x))$ on $(-\pi,\pi)$, if you'd prefer: \begin{align}I&=\sum_{n=1}^{\infty}(-1)^{n+1}\cdot\frac{1}{2}\left(1+\coth (\pi n)\right) \cdot \int _{0}^{2\pi}\left(-\log(2)+ \sum_{k=1}^{\infty}\frac{2\cos(k x)(-1)^{k+1}}{k}\right) e^{-nx}\,dx \\&=\small\sum_{n=1}^{\infty}(-1)^{n+1}\cdot\frac{1}{2}\left(1+\coth (\pi n)\right) \cdot\left( \int _{0}^{2\pi}-\log(2)e^{-nx}\,dx+\sum_{k=1}^{\infty} \frac{2(-1)^{k+1}}{k} \int _{0}^{2\pi}\cos(k x)e^{-nx}\,dx\right)\end{align} These new integrals are easily evaluated either directly or by integration by parts twice, and in fact cancel with the term from the middle sum: \begin{align} I&=\sum_{n=1}^{\infty}(-1)^{n+1}\left( \frac{-\log(2)}{n} + \sum_{k=1}^{\infty}\frac{2(-1)^{k+1}}{k}\cdot\frac{n}{n^2+k^2}\right) \\&=\log(2)\sum_{n=1}^{\infty}\frac{(-1)^{n}}{n} + \sum_{n=1}^{\infty}\sum_{k=1}^{\infty}\frac{2(-1)^{k+n}}{k}\cdot\frac{n}{n^2+k^2} \end{align} But the second sum can now be evaluated using the symmetry trick from the linked question and the value of the alternating harmonic series: \begin{align} I&=\log(2)\sum_{n=1}^{\infty}\frac{(-1)^{n}}{n} + \sum_{n=1}^{\infty}\sum_{k=1}^{\infty}\frac{(-1)^{k+n}}{nk} \\&=\log(2)\sum_{n=1}^{\infty}\frac{(-1)^{n}}{n} - \log(2)\sum_{n=1}^{\infty}\frac{(-1)^{n}}{n}\\&=0 \end{align}


Some remarks. My first thought was to use $\int_{-a}^a f(x)/(1+e^x)\,dx = \int_0^a f(x)\,dx$ if $f$ is even and integrable, but the shoe's on the wrong foot, so to speak. I also tried the residue theorem and some other substitutions but they didn't pan out. It was interesting to note the prevalence of $\log(2)^2$ throughout this problem; I tried (in vain!) to connect the integrals in this problem with Putnam 2017 B4, though perhaps there is a link. As mentioned in my comment, much of this follows from your linked question. Hope this is clear and helpful.


A shortcut: $$\begin{align} \int_0^\infty\frac{\log(2(1+\cos x))}{1+e^x}dx&= \int_0^\infty\frac{\log(1+e^{ix})+\log(1+e^{-ix})}{1+e^x}dx\\ &=\int_0^\infty\left[\sum_{k=1}^\infty(-1)^k\frac{e^{ikx}+e^{-ikx}}k\sum_{n=1}^\infty(-1)^n e^{-nx}\right]dx\\ &=\sum_{k=1}^\infty\sum_{n=1}^\infty\frac{(-1)^{k+n}}k\int_0^\infty \left[e^{-(n-ik)x}+e^{-(n+ik)x}\right]dx\\ &=\sum_{k=1}^\infty\sum_{n=1}^\infty\frac{(-1)^{k+n}}k \left[\frac1{n-ik}+\frac1{n+ik}\right]\\ &=2\sum_{k=1}^\infty\sum_{n=1}^\infty\frac{(-1)^{k+n}}k\frac n{n^2+k^2}\\ &=\log^22, \end{align}$$ where the last equality is proved by the same trick as in the linked answer: $$ 2S=2\sum_{k=1}^\infty\sum_{n=1}^\infty\frac{(-1)^{k+n}}{kn}=2\left[\sum_{k=1}^\infty\frac{(-1)^{k}}{k}\right]=2\log^22. $$

Finally the original integral is obtained by subtracting: $$\int_0^\infty\frac{\log2}{1+e^x}dx. $$