# How do I do this integral $\int_{-\pi}^{\pi}\frac{\cos^2(x)}{1+a^x}dx, a>0$?

$$\int_{-\pi}^{\pi}\frac{\cos^2(x)}{1+a^x}dx, a>0$$ I've tried doing $$z = e^{ix}$$ and evaluating the resulting contour integral, but this introduced a branch cut that goes through the contour ($$a^x$$ becomes $$a^{-i\log(z)})$$.

The answer is $$\frac{\pi}{2}$$ (independent of $$a$$), but I don't know how one would get to that answer.

Could anyone help me with this integral?

Hint: what is $$\frac{1}{1+a^x}+\frac{1}{1+a^{-x}}$$?
• I’m not sure actually. I “felt” like $(1+a^x)^{-1}$ term destroyed all attempts at finding a closed form antiderivative, integrate by parts or change variables. So I wondered if there might be a way to recombine the integral differently. Given that $\cos$ is even, this sum was the first thing to try. – Mindlack May 15 '19 at 22:38
Using the reflection property: $$\int_{a}^{b}f(x)\mathrm dx=\int_{a}^{b}f(a+b-x)\mathrm dx$$ $$x\mapsto -x \implies \mathrm I =\int_{-\pi}^{\pi}\dfrac{a^x\cos^2 x}{1+a^x}\mathrm dx$$
Add the initial integral to the transformed integral to get $$2\mathrm I$$ and consequently the value of the integral at hand. $$2\mathrm I=\int_{-\pi}^{\pi}\dfrac{1+a^x}{1+a^x}\cdot\cos^2x\mathrm dx=2\int_{0}^{\pi}\dfrac{1+\cos 2x}{2}\mathrm dx \implies \mathrm I=\pi/2$$