TITLE: Evaluate $ \int_{0}^{\frac{\pi}2}\frac1{(1+x^2)(1+\tan x)}\:\mathrm dx$
QUESTION [262 upvotes]: Evaluate the following integral
$$
\tag1\int_{0}^{\frac{\pi}{2}}\frac1{(1+x^2)(1+\tan x)}\,\mathrm dx
$$

My Attempt:
Letting $x=\frac{\pi}{2}-x$ and using the property that
$$
\int_{0}^{a}f(x)\,\mathrm dx = \int_{0}^{a}f(a-x)\,\mathrm dx
$$
we obtain
$$
\tag2\int_{0}^{\frac{\pi}{2}}\frac{\tan x}{\left(1+\left(\frac{\pi}{2}-x\right)^2\right)(1+\tan x)}\,\mathrm dx
$$
Now, add equation $(1)$ and $(2)$. After that I do not understand how I can proceed further.

REPLY [7 votes]: Let us try to understand the computer-based answer of Oliver Oloa.
Rational decomposition.
Is known the rational decomposition of the trigonometric functions in the forms of
$$\tan z = \sum\limits_{n=0}^\infty\dfrac{8z}{\pi^2\left(2n+1\right)^2 - 4z^2},\tag{R1}$$
$$\sec z = \sum\limits_{n=0}^\infty (-1)^n\dfrac{4\pi(2n+1)}{\pi^2\left(2n+1\right)^2 - 4z^2},\tag{R2}$$
with the corollaries
$$\tanh z =-i\tan(iz) = \sum\limits_{n=0}^\infty\dfrac{8z}{\pi^2\left(2n+1\right)^2 + 4z^2},\tag{R3}$$
$$\operatorname{sech}z = \sec(iz) = \sum\limits_{n=0}^\infty (-1)^n\dfrac{4\pi(2n+1)}{\pi^2\left(2n+1\right)^2 + 4z^2}.\tag{R4}$$
Preparation.
$$I=\int\limits_0^{\Large^\pi/_2}\dfrac{\text dx}{(1+x^2)(1+\tan x)}
=\dfrac12\int\limits_0^{\Large^\pi/_2}\left(\dfrac{1+\tan x}{1+\tan x}
-\dfrac{\tan x-1}{1+\tan x}\right)\,\dfrac{\text dx}{1+x^2}$$
$$=\dfrac12\int\limits_0^{\Large^\pi/_2}\dfrac{\text dx}{1+x^2}
-\dfrac12\int\limits_0^{\Large^\pi/_2}\tan\left(x-\dfrac\pi4\right)\,\dfrac{\text dx}{1+x^2},$$
$$I=\dfrac12\int\limits_0^{\Large^\pi/_2}\dfrac{\text dx}{1+x^2}
-\dfrac12\int\limits_0^{\Large^\pi/_2}\sum\limits_{n=0}^\infty g_n(x)\,\text dx,\tag1$$
where, taking in account $(R1),$
$$g_n(x)=\dfrac{2x-\large\frac\pi2}{\pi^2\left(n+\large\frac12\right)^2 - \left(x-\large\frac\pi4\right)^2}\cdot\dfrac1{1+x^2}.\tag2$$
Partial fractions.
The functions $\;g_n(x)\;$ allow decomposition in the form of
$$g_n(x)=\dfrac{A_nx+B_n}{1+x^2} + \dfrac {C_n}{\pi n+\frac34\pi-x} + \dfrac {D_n}{\pi n+\frac14\pi+x}.\tag3$$
Then
$$C_n=\lim_{\large x\to \pi n+\frac34\pi}\, \left(\pi n+\frac34\pi-x\right)g_n(x)
= \dfrac{16}{(4 n\pi+3\pi)^2 +16},$$
$$D_n=\lim_{\large x\to -\pi n-\frac14\pi}\, \left(\pi n+\frac14\pi+x\right)g_n(x)
= -\dfrac{16}{(4n\pi+\pi)^2 +16},$$
$$A_n-C_n+D_n=\lim_{\large x\to \infty}\, x g_n(x) = 0,\quad A_n=C_n-D_n,$$
$$B_n+ \dfrac {C_n}{\pi n+\frac34\pi} + \dfrac {D_n}{\pi n+\frac14\pi} =g_n(0) = -\dfrac8{\pi(16n^2+16n+3)},$$
$$B_n = \dfrac4{4\pi n+3\pi} -\dfrac4{4\pi n+\pi} -  \dfrac {4C_n}{4\pi n+3\pi} - \dfrac {4D_n}{4\pi n+\pi}.$$
$$B_n = 4(4\pi n+3\pi)C_n + 4(4\pi n+\pi)D_n.$$
Let
$$U_k = \dfrac{16}{(2k\pi+\pi)^2+16},$$
then, taking in account $(R3)-(R4),$
$$D_n = -U_{2n},\quad C_n=U_{2n+1},\;$$
$$\sum\limits_{n=0}^\infty A_n = \sum\limits_{n=0}^\infty U_n = \tanh2,\tag4$$
$$\sum\limits_{n=0}^\infty B_n = \sum\limits_{n=0}^\infty (-1)^{n+1}4\pi(2n+1)U_n
= -\operatorname{sech}2.\tag5$$
Integration.
$$I=\dfrac12\int\limits_0^{\Large^\pi/_2}\dfrac{\text dx}{1+x^2}
-\dfrac12\int\limits_0^{\Large^\pi/_2}\sum\limits_{n=0}^\infty g_n(x)\,\text dx$$
$$ = \dfrac12 \arctan \,\dfrac\pi2-\dfrac12\sum\limits_{n=0}^\infty \left(\dfrac12 A_n \ln\left(\dfrac{\pi^2}4+1\right) +B_n \arctan \,\dfrac\pi2+(C_n+D_n) \ln\dfrac{4n + 3}{4n+1}\right),$$
$$I=-\dfrac14\tanh 2\ln\left(\dfrac{\pi^2}4+1\right) + \dfrac{1+\operatorname{sech}2}2 \arctan \,\dfrac\pi2-\dfrac12 I_1,\tag6$$
where
$$I_1=\sum\limits_{n=0}^\infty (C_n+D_n) \ln\dfrac{4n + 3}{4n+1},\tag7$$
with the representations
$$I_1=\sum\limits_{n=0}^\infty \dfrac{128\pi^2(2n+1)}{\pi^4((4n+2)^2-1)^2 +32\pi^2((4n+2)^2+1)+256}\,\ln\dfrac{4n+3}{4n+1}\tag{7a}$$


and
$$I_1=\sum\limits_{n=0}^\infty \Im\left(-\dfrac4{4\pi n+3\pi+4i}+\dfrac4{4\pi n+\pi+4i}\right) \ln\dfrac{4n + 3}{4n+1}.\tag{7b}$$
The poly-Stieltjes constants using.
The poly-Stieltjjes constants do not belong to the standard special functions, but they are defined in the Oliver Oloa answer as the known specific functions.
In particular, from $(7b)$ and the given definition in the form of
$$\gamma_1(a,b) = \lim\limits_{N\to\infty}\left(\sum\limits_{n=1}^N \dfrac{\ln(n+a)}{n+b} - \dfrac{\ln N^2}2\right)\tag{$\large\diamond$}$$
should
$$\begin{align}
&I_1= \dfrac{16}{16+9\pi^2}\,\ln3 - \dfrac1\pi \Im\left(\gamma_1\left(\small\dfrac34,\frac34+\frac i\pi\right) 
- \gamma_1\left(\small\dfrac14,\frac34+\frac i\pi\right) \right)\\[4pt]
&-\dfrac{16}{16+\pi^2}\,\ln3 + \dfrac1\pi \Im\left(\gamma_1\left(\small\dfrac34,\frac14+\frac i\pi\right) 
- \gamma_1\left(\small\dfrac14,\frac14+\frac i\pi\right) \right),
\end{align}\tag8$$
$$\begin{align}
&I=-\dfrac14\tanh 2\ln\left(\dfrac{\pi^2}4+1\right) + \dfrac{1+\operatorname{sech}2}2 \arctan \,\dfrac\pi2
+\dfrac{64\pi^2}{(16+\pi^2)(16+9\pi^2)}\\[4pt]
&+\dfrac1{2\pi}\Im\left(\gamma_1\left(\small\dfrac34,\frac34+\frac i\pi\right) 
- \gamma_1\left(\small\dfrac14,\frac34+\frac i\pi\right) \right)\\[4pt]
&- \dfrac1{2\pi} \Im\left(\gamma_1\left(\small\dfrac34,\frac14+\frac i\pi\right) 
- \gamma_1\left(\small\dfrac14,\frac14+\frac i\pi\right) \right).
\end{align}\tag9$$
Formula $(9)$ gives the closed-form representation, which cannot be used in the popular package Wolfram Alpha.
Results.

Obtained the alternatiive notation of the poly-Stieltjes closed form $(9)$ for the given integral.
Obtained the calculating formulas $(6),(7a)$ via the elementary functions series. Evaluated value



corresponds to the numerical calculations of the given integral
.