how to show $\int_{-\pi}^{\pi} \frac{\cos^2(x)}{1+a^x} dx= \frac{\pi}{2}$ -Let $a\neq 0$ then  how to show $$\int_{-\pi}^{\pi} \frac{\cos^2(x)}{1+a^x}  dx= \frac{\pi}{2}$$
I have tried $a=1$ to get that answer is $\int_{0}^{\pi} \cos^2(x) dx$ and it seems correct. now I can't go on with general answer. I think it may use Feynmans Trick.
 A: I used Kellener's good comments, $x\to -x$
$$I =\int_{-\pi}^{\pi} \frac{\cos^2(x)}{1+a^x} dx =\int_{-\pi}^{\pi} \frac{a^x\cos^2(x)}{1+a^x} dx $$
therefore on addition, $$2I = \int_{-\pi}^{\pi}\cos^2(x)dx = \int_{0}^{\pi} 1+\cos(2x) dx = \pi$$
Again get answer again as $\frac{\pi}{2}$. Thanks a lot to Kellener.
A: First, let $I$ be your integral. You can use that for all $a >0$
$$
\int_{-\pi}^{\pi}\frac{\text{d}x}{1+a^{x}}=\pi-\frac{\ln\left(1+a^\pi\right)}{\ln\left(a\right)}-\left(-\pi-\frac{\ln\left(1+a^{-\pi}\right)}{\ln\left(a\right)}\right)=2\pi-\pi=\pi
$$
Then introduce its twin integral $J$ defined by
$$
J=\int_{-\pi}^{\pi}\frac{\sin^2\left(x\right)}{1+a^{x}}\text{d}x
$$
Then
$$
I+J=\int_{-\pi}^{\pi}\frac{\text{d}x}{1+a^{x}}=\pi$$
Now let's go to the original and tricky part,
$$
I-J=\int_{-\pi}^{\pi}\frac{\cos\left(2x\right)}{1+a^{x}}\text{d}x=\int_{-\pi}^{0}\frac{\cos\left(2x\right)}{1+a^{x}}\text{d}x+\int_{0}^{\pi}\frac{\cos\left(2x\right)}{1+a^{x}}\text{d}x
$$
with $u=-x$ you have $\text{d}x=-\text{d}u$ and
$$
\int_{-\pi}^{0}\frac{\cos\left(2x\right)}{1+a^{x}}\text{d}x=\int_{0}^{\pi}\frac{a^x\cos(2x)}{a^x+1}\text{d}x$$
summing the two gives you
$$
I-J=\int_{0}^{\pi}\cos\left(2x\right)\text{d}x=0
$$
Hence
$$
I+J=\pi \ \text{ and } I=J
$$
You finally have

$$
I=\frac{\pi}{2}
$$

A: for $a\neq 0$ we let  $$I(a) = \int_{-\pi}^{\pi} \frac{\cos^2(x)}{1+a^x}  dx\implies I'(a) = -\int_{-\pi}^{\pi} \frac{xa^{x-1}\cos^2(x)}{(1+a^x)^2}  dx $$
letting $x= -t$ gives $$I'(a) = \int_{-\pi}^{\pi} \frac{ta^{-t-1}\cos^2(t)}{(1+a^{-t})^2}  dt  = \int_{-\pi}^{\pi} \frac{ta^{2t}a^{-t-1}\cos^2(t)}{(a^{t}+1)^2}  dt =\int_{-\pi}^{\pi} \frac{ta^{t-1}\cos^2(t)}{(a^{t}+1)^2}  dt =-I'(a)$$

Hence $2I'(a) = 0$ $$ I'(a) = 0\implies I(a) =I(1) = \frac{1}{2}\int_{-\pi}^{\pi}  \cos^2(x) dx =\frac{\pi}{2}$$

