TITLE: How to find $\int_0^{{\pi}/{2}} (\pi x-4x^2)\log(1+\tan x)\mathrm dx$
QUESTION [14 upvotes]: How do you find the integral of
  $$
\int_0^{\pi/2}\left(\pi x - 4x^{2}\right)
\log\left(1 + \tan\left(x\right)\right)\,\mathrm{d}x
$$

The integral can be simplified to
$$
\int_0^{\pi/2}x\left(4x + {\pi}\right)
\ln\left(1 - \dfrac{\mathrm{i}\left[\mathrm{e}^{\mathrm{i}x}-\mathrm{e}^{-\mathrm{i}x}\right]}{\mathrm{e}^{\mathrm{i}x}+\mathrm{e}^{-\mathrm{i}x}}\right)
\,\mathrm{d}x$$

REPLY [3 votes]: For $~ \displaystyle -\frac{\pi}{4} < x < \frac{\pi}{2} ~$ and $~\displaystyle e^{i\frac{\pi}{2}}=i ~$ it’s 
$$\ln(1+\tan x) = \ln\left(\sqrt{2}~\frac{\sin\left(x+\frac{\pi}{4}\right)}{\cos x}\right) = \frac{\ln 2}{2} - i\frac{\pi}{4} + \text{Li}_1(-e^{-i2x}) - \text{Li}_1(-ie^{-i2x}) $$
and with $~m,n\in\mathbb{N}_0~$ we have the following integral recursion:
$$\int x^n \text{Li}_m(ae^{bx}) dx = \frac{x^n}{b} \text{Li}_{m+1}(ae^{bx}) - \frac{n}{b} \int x^{n-1} \text{Li}_{m+1}(ae^{bx}) dx $$ 
This recursion leads directly to the following formula:
$$\int x^n\ln(1+\tan x)dx =$$
$$ =\frac{x^{n+1}}{n+1}\left(\frac{\ln 2}{2}-i\frac{\pi}{4}\right) - \sum\limits_{k=0}^n \frac{n!}{(n-k)!}\frac{x^{n-k}}{(i2)^{k+1}}\left(\text{Li}_{ k+2}\left(-e^{-i2x}\right)-\text{Li}_{ k+2}\left(-ie^{-i2x}\right)\right) + C $$
Note: $~~$ It answers also the question here . 
For the given problem, means: $x\in\{0,\frac{\pi}{2}\}$, it only remains to express the series of $~\text{Li}_m(z)$ 
with $~z\in\{1,-1,i,-i\}~$ by other symbols:
$\displaystyle \text{Li}_m(1)~|_{m\in\mathbb{N}\setminus\{1\}} =\zeta(m)\hspace{4.8cm}$ ( $\zeta(s)$ is the Riemann $\zeta$-function )
$\displaystyle \text{Li}_m(-1)~|_{m\in\mathbb{N}} =-\eta(m)\equiv\left(2^{1-m}-1\right)\zeta(m)\hspace{1cm}$ ( $\eta(s)$ is the Dirichlet $\eta$-function )
$\displaystyle \text{Li}_m(i)~|_{m\in\mathbb{N}} =-\frac{1}{2^m}\eta(m)+i\beta(m)\hspace{2.9cm}$ ( $\beta(s)$ is the Dirichlet $\beta$-function )
$\displaystyle \text{Li}_m(-i)~|_{m\in\mathbb{N}} = (-1)^{m+1}\text{Li}_m(i)-\frac{(i2\pi)^m}{m!}B_m\left(\frac{3}{4}\right) \enspace$ ( $B_m(x)$ is the Bernoulli polynomial )  
E.g. for $~n\in\{0,1,2,3,4\}~$ we get:
$\displaystyle \int\limits_0^{\frac{\pi}{2}} \ln(1+\tan x) dx = \frac{\pi}{4}\ln 2 + \beta(2)$
$\displaystyle \int\limits_0^{\frac{\pi}{2}} x\ln(1+\tan x) dx = \frac{\pi^2}{16}\ln 2 + \frac{\pi}{4}\beta(2) + \frac{7}{16}\zeta(3)$
$\displaystyle \int\limits_0^{\frac{\pi}{2}} x^2\ln(1+\tan x) dx = \frac{\pi^3}{48}\ln 2 + \frac{\pi^2}{8}\beta(2) + \frac{35\pi}{128}\zeta(3) - \frac{1}{2}\beta(4)$
$\displaystyle \int\limits_0^{\frac{\pi}{2}} x^3\ln(1+\tan x) dx = \frac{\pi^4}{128}\ln 2 + \frac{\pi^3}{16}\beta(2) + \frac{105\pi^2}{512}\zeta(3) - \frac{3\pi}{8}\beta(4) - \frac{93}{128}\zeta(5)$
$\displaystyle \int\limits_0^{\frac{\pi}{2}} x^4\ln(1+\tan x) dx = $
$\hspace{2cm}\displaystyle = \frac{\pi^5}{320}\ln 2 + \frac{\pi^4}{32}\beta(2) + \frac{35\pi^3}{256}\zeta(3) - \frac{3\pi^2}{8}\beta(4) - \frac{1581\pi}{2048}\zeta(5) + \frac{3}{2}\beta(6)$
$\enspace$
The above formula provides for $~n\in\mathbb{N}_0~$ :
$\displaystyle \int\limits_0^{\frac{\pi}{2}}x^n\ln(1+\tan x)\,dx = \frac{\pi^{n+1}\ln 2}{2^{n+2}(n+1)}+ $
$\hspace{0.5cm}\displaystyle + \frac{n!}{2^{3n+4}}\sum\limits_{\,k=0 \\ k~\text{odd}}^{n-1}\frac{(4\pi)^{n-k}}{(n-k)!} \left(\sin\frac{\pi k}{2}\right) (2^{2k+3}+2^{k+1}-1)\zeta(k+2) $
$\hspace{0.5cm}\displaystyle + \frac{n!}{2^{n+1}}\sum\limits_{\,\,k=0 \\ k~\text{even}}^{n-1}\frac{\pi^{n-k}}{(n-k)!} \left(\cos\frac{\pi k}{2}\right)\beta(k+2) $
$\hspace{0.5cm}\displaystyle + \frac{n!}{2^{3n+4}} \left(\sin\frac{\pi n}{2}\right) (2^{2n+4}-(1-(-1)^n)2^{n+1}-1-(-1)^n)\zeta(n+2)$ 
$\hspace{0.5cm}\displaystyle +\frac{n!}{2^{n+1}}(1+(-1)^n)\left(\cos\frac{\pi n}{2}\right)\beta(n+2) $

$(\text{A})~$ Hint.
For a better understanding of the first formula (of my answer) we can also write:
$\displaystyle \ln(1+\tan x) = \int\limits_0^x\frac{1+\tan^2 t}{1+\tan t}dt =  \int\limits_0^x \left(\tan t - \tan\left(t-\frac{\pi}{4}\right)\right)dt$
$\hspace{1cm}\displaystyle = -i2 \int\limits_0^x \left(\text{Li}_0\left(-e^{-i2t}\right) - \text{Li}_0\left(-ie^{-i2t}\right)\right) dt = \left(\text{Li}_1\left(-e^{-i2t}\right) - \text{Li}_1\left(-ie^{-i2t}\right)\right)|_0^x$
with $\displaystyle \enspace \left(\text{Li}_1\left(-e^{-i2t}\right) - \text{Li}_1\left(-ie^{-i2t}\right)\right)|_{t=0} = \text{Li}_1(-1) - \text{Li}_1(-i) = -\frac{\ln 2}{2} + i\frac{\pi}{4} $
The transformation $\displaystyle\enspace \frac{1+\tan^2 t}{1+\tan t} = \tan t - \tan\left(t-\frac{\pi}{4}\right) \enspace$ comes from 
$$\tan(x+y) = \frac{\tan x + \tan y}{1 - \tan x \tan y}\enspace\enspace \text{with}  \enspace x:=t\enspace\enspace  \text{and} \enspace\enspace  y:=\frac{\pi}{4}-t$$ 
And the basic connection of $~\tan~$ with $~\text{Li}_0~$ is 
$$\tan t + i2\,\text{Li}_0\left(-e^{-i2t}\right) = -i = \tan\left(t-\frac{\pi}{4}\right) + i2\,\text{Li}_0\left(-ie^{-i2t}\right) ~ .$$ 

$(\text{B})~$ About the generating function, mentioned by Dr. Wolfgang Hintze.
We need the following formula:
$$\int e^{tx}\text{Li}_{\,m}(ae^{bx})dx = e^{tx}\sum\limits_{k=1}^\infty\frac{(ae^{bx})^k}{k^m(kb+t)}+C = $$
$$=\sum\limits_{k=0}^\infty\frac{(tx)^k}{k!}\cdot\sum\limits_{k=0}^\infty\frac{(-t)^k}{b^{k+1}}\text{Li}_{m+k+1}(ae^{bx})+C$$
$$=\sum\limits_{n=0}^\infty t^n\sum\limits_{k=0}^n\frac{x^{n-k}}{(n-k)!}\frac{(-1)^k}{b^{k+1}}\text{Li}_{m+k+1}(ae^{bx})+C$$ 
With $\displaystyle\enspace\ln(1+\tan x) = \frac{\ln 2}{2} - i\frac{\pi}{4} + \text{Li}_1(-e^{-i2x}) - \text{Li}_1(-ie^{-i2x}) \enspace $ we get a formula for  
$~\displaystyle\int x^n\ln(1+\tan x)dx = n!~[t^n]\int e^{tx}\ln(1+\tan x)dx~. \hspace{1cm}$ (it's the same as above)

$(\text{C})~$ An additional note: $~$The case $~n=-1~$ has no "closed form".
$\displaystyle f~:~\mathbb{R}\to \mathbb{R}\enspace,\enspace f’(x):=\frac{ \text{Li}_1(-e^{-i2x}) - \text{Li}_1(-1)}{x}-i\enspace , \enspace f(0):=0$
$\displaystyle g~:~\mathbb{R}\to \mathbb{R}\enspace,\enspace g’(x):=\frac{ \text{Li}_1(-ie^{-i2x}) - \text{Li}_1(-i)}{x}-i\enspace , \enspace g(0):=0$
It follows: 
$\displaystyle \int\frac{\ln(1+\tan x)}{x}dx = f(x) - g(x) + C$
Special values: 
$\displaystyle f\left(\frac{\pi}{2}\right)\approx 0.9412376742877 , ~g\left(\frac{\pi}{2}\right)\approx -0.7215715580242$