A strange integral: $\int_{-\infty}^{+\infty} {dx \over 1 + \left(x + \tan x\right)^2} = \pi.$ While browsing on Integral and Series, I found a strange integral posted by @Sangchul Lee. His post doesn't have a response for more than a month, so I decide to post it here. I hope he doesn't mind because the integral looks very interesting to me. I hope for you too. :-)

$$\mbox{How does one prove}\quad
\int_{-\infty}^{\infty}
{{\rm d}x \over 1 + \left[\,x + \tan\left(\, x\,\right)\,\right]^{2}} = \pi\quad
{\large ?}
$$
Please don't ask me, I really have no idea how to prove it. I hope users here can find the answer to prove the integral. I'm also interested in knowing any references related to this integral. Thanks in advance.
 A: Here is an approach.
We may use the following result, which goes back to G. Boole (1857) :

$$
\int_{-\infty}^{+\infty}f\left(x-\frac{a_1}{x-\lambda_1}-\cdots-\frac{a_n}{x-\lambda_n}\right)\mathrm{d}x=\int_{-\infty}^{+\infty} f(x)\: \mathrm{d}x  \tag1
$$

with $a_i>0, \lambda_i \in \mathbb{R}$ and $f$ sufficiently 'regular'.
Observe that, for $x\neq n\pi$, $n=0,\pm1,\pm2,\ldots$, we have $$ \cot x = \lim_{N\to +\infty} \left(\frac1x+\frac1{x+\pi}+\frac1{x-\pi}+\cdots+\frac1{x+N\pi}+\frac1{x-N\pi}\right)$$ leading to (see Theorem 10.3 p. 14 here and see achille's answer giving a route to prove it)

$$
\int_{-\infty}^{+\infty}f\left(x-\cot x\right)\mathrm{d}x=\int_{-\infty}^{+\infty} f(x)\: \mathrm{d}x  \tag2
$$ 

with $\displaystyle f(x)=\frac{1}{1+\left(\small{\dfrac\pi2 -x }\right)^2}$.
On the one hand, from $(2)$,
$$
\begin{align}
\int_{-\infty}^{+\infty}f\left(x-\cot x\right)\mathrm{d}x& =\int_{-\infty}^{+\infty} f(x)\: \mathrm{d}x  \\\\
&=\int_{-\infty}^{+\infty}\frac{1}{1+\left(\small{\dfrac\pi2 -x }\right)^2}\: \mathrm{d}x\\\\
&=\int_{-\infty}^{+\infty}\frac{1}{1+x^2}\: \mathrm{d}x\\\\
& =\pi \tag3
\end{align}
$$ 
On the other hand, with the change of variable $x \to  \dfrac\pi2 -x$,
$$
\begin{align}
\int_{-\infty}^{+\infty}\!\!\!f\left(x-\cot x\right)\mathrm{d}x & =\int_{-\infty}^{+\infty} \!\!\!f\left(\dfrac\pi2-x-\tan x\right)\mathrm{d}x \\\\
 &  =\int_{-\infty}^{+\infty}\frac{1}{1+\left(x+ \tan x \right)^2} \mathrm{d}x \tag4
\end{align}
$$ 
Combining $(3)$ and $(4)$ gives 

$$
\int_{-\infty}^{+\infty}\frac{1}{1+\left(x+ \tan x \right)^2} \mathrm{d}x=\pi. 
$$ 

A: Please view this as an supplement of Olivier's answer. 
I will derive a sufficient condition on the meromorphic function involved which
allow one to apply a result similar to that in Olivier's answer.
Let $\phi(z)$ be any meromorphic function over $\mathbb{C}$ which


*

*preserve the extended real line $\mathbb{R}^* = \mathbb{R} \cup \{ \infty \}$ in the sense:
$$\begin{cases}\phi(\mathbb{R}) \subset \mathbb{R}^*\\ \phi^{-1}(\mathbb{R}) \subset \mathbb{R}\end{cases}
\quad\implies\quad
P \stackrel{def}{=} \phi^{-1}(\infty) = \big\{\, p \in \mathbb{C} : p \text{ poles of }\phi(z)\,\big\} \subset \mathbb{R}
$$

*Split $\mathbb{R} \setminus P$ as a countable union of its connected components $\,\bigcup\limits_{n} ( a_n, b_n )\,$. Each connected component is an open interval $(a_n,b_n)$
and on such an interval, $\phi(z)$ increases from $-\infty$ at $a_n^{+} $ to $\infty$ 
at $b_n^{-}$.

*There exists an ascending chain of Jordan domains $D_1, D_2, \ldots$ that cover $\mathbb{C}$,
$$\{ 0 \} \subset D_1 \subset D_2 \subset \cdots
\quad\text{ with }\quad \bigcup_{k=1}^\infty D_k = \mathbb{C}
$$
whose boundaries $\partial D_k$ are "well behaved", "diverge" to infinity and $| z - \phi(z)|$ is bounded on the boundaries. More precisely, let
$$
\begin{cases}
R_k &\stackrel{def}{=}& \inf \big\{\, |z| : z \in \partial D_k \,\big\}\\
L_k &\stackrel{def}{=}& \int_{\partial D_k} |dz| < \infty\\
M_k &\stackrel{def}{=}& \sup \big\{\, |z - \phi(z)| : z \in \partial D_k \,\big\}
\end{cases}
\quad\text{ and }\quad
\begin{cases}
\lim\limits_{k\to\infty} R_k = \infty\\
\lim\limits_{k\to\infty} \frac{L_k}{R_k^2} = 0\\
M = \sup_k M_k < \infty
\end{cases}
$$

Given such a meromorphic function $\phi(z)$ and any Lebesgue integrable function $f(x)$ on $\mathbb{R}$, we have following identity: $$
\int_{-\infty}^\infty f(\phi(x)) dx = \int_{-\infty}^\infty f(x) dx \tag{*1}
$$

In order to prove this, we split our integral into a sum over the connected components
of $\mathbb{R} \setminus P$.
$$\int_\mathbb{R} f(\phi(x)) dx
= \int_{\mathbb{R} \setminus P} f(\phi(x)) dx
= \sum_n \int_{a_n}^{b_n} f(\phi(x)) dx
$$ 
For any connected component $( a_n, b_n )$ of $\mathbb{R} \setminus P$ and $y \in \mathbb{R}$, consider the roots of the equation $\phi(x) = y$.
Using properties $(1)$ and $(2)$ of $\phi(z)$, we find there is a unique root
for the equation $y = \phi(x)$ over $( a_n, b_n )$. Let we call this root as $r_n(y)$.
Change variable to $y = \phi(x)$, the integral becomes
$$\sum_n \int_{-\infty}^\infty f(y) \frac{d r_n(y)}{dy} dy
= \int_{-\infty}^\infty f(y) \left(\sum_n \frac{d r_n(y)}{dy}\right) dy
$$
We can use the obvious fact $\frac{d r_n(y)}{dy} \ge 0$ and dominated convergence theorem to justify the switching of order of summation and integral. 
This means to prove $(*1)$, one only need to show
$$\sum_n \frac{d r_n(y)}{dy} \stackrel{?}{=} 1\tag{*2}$$
For any $y \in \mathbb{R}$, let $R(y) = \phi^{-1}(y) \subset \mathbb{R}$ be the collection of roots of the equation $\phi(z) = y$.
Over any Jordan domain $D_k$, we have following expansion
$$\frac{\phi'(z)}{\phi(z) - y} = \sum_{r \in R(y) \cap D_k} \frac{1}{z - r} - \sum_{p \in P \cap D_k} \frac{1}{z - p} + \text{something analytic}$$
This leads to
$$\sum_{r \in R(y)\cap D_k} r - \sum_{ p \in P \cap D_k} p 
= \frac{1}{2\pi i}\int_{\partial D_k} z \left(\frac{\phi'(z)}{\phi(z) - y}\right) dz$$
As long as $R(y) \cap \partial D_k = \emptyset$, we can differentiate both sides and get
$$\begin{align}
\sum_{r_n(y) \in D_k} \frac{dr_n(y)}{dy} 
&= 
\frac{1}{2\pi i}\int_{\partial D_k} z \left(\frac{\phi'(z)}{(\phi(z) - y)^2}\right) dz
= -\frac{1}{2\pi i}\int_{\partial D_k} z \frac{d}{dz}\left(\frac{1}{\phi(z)-y}\right) dz\\
&= \frac{1}{2\pi i}\int_{\partial D_k}\frac{dz}{\phi(z) - y}
\end{align}
$$
For those $k$ large enough such that $R_k > 2(M+|y|)$, we can expand the integrand in last line as
$$\frac{1}{\phi(z) - y} = \frac{1}{z - (y + z - \phi(z))} 
= \frac{1}{z} + \sum_{j=1}^\infty \frac{(y + z - \phi(z))^j}{z^{j+1}}$$
and obtain a bound
$$\left|\left(\sum_{r_n(y) \in D_k} \frac{dr_n(y)}{dy} \right) - 1\right|
\le \frac{1}{2\pi}\sum_{j=1}^\infty \int_{\partial D_k} \frac{(|y| + |z-\phi(z)|)^j}{|z|^{j+1}} |dz|\\
\le \frac{(M + |y|)L_k}{2\pi R_k^2}\sum_{j=0}^\infty\left(\frac{M+|y|}{R_k}\right)^j
\le \frac{M + |y|}{\pi}\frac{L_k}{R_k^2}
$$
Since $\lim\limits_{k\to\infty} \frac{L_k}{R_k^2} = 0$, this leads to
$$\sum_n \frac{dr_n(y)}{dy} = \lim_{k\to\infty} \sum_{r_n(y) \in  D_k} \frac{dr_n(y)}{dy} = 1$$
This justifies $(*2)$ and hence $(*1)$ is proved. Notice all the $\frac{dr_n(y)}{dy}$ are positive, there is no issue in rearranging the order of summation in last line.
Back to the original problem of evaluating
$$\int_{-\infty}^\infty \frac{1}{1+(x+\tan x)^2} dx$$
One can take $\phi(z)$ as $z + \tan z$ and $f(x)$ as $\frac{1}{1+x^2}$.
It is easy to see $\phi(z)$ satisfies:


*

*Condition $(1)$ - For any $y \in \mathbb{R}$ and $u + iv \in \mathbb{C} \setminus \mathbb{R}$, we have
$$\begin{align}
\Im (\phi(u + iv) - y ) 
&= v + \Im\tan(u+iv) = v + \Im\frac{\tan u + i\tanh v}{1 - i\tan u\tanh v}\\
&= v + \tanh v\frac{1 + \tan^2 u}{1 + \tan^2 u\tanh^2 v} \ne 0
\end{align}$$

*Condition $(2)$ - obvious.

*Condition $(3)$. - Let $D_k$ to be the square
$$D_k  = \big\{\, u + v i \in \mathbb{C} : |u|, |v| \le k \pi \,\big\}$$
It is not hard to show $|z - \phi(z)| = |\tan z|$ is bounded above by $\frac{1}{\tanh k\pi}$ on $\partial D_k$. 
Combine these, we can apply $(*1)$ and deduce
$$ \int_{-\infty}^\infty \frac{1}{1+(x+\tan x)^2} dx
= \int_{-\infty}^\infty \frac{1}{1+x^2} dx 
= \pi
$$
A: The Inverse Function Theorem gives us
$$
\int_{-\infty}^{+\infty}f(g(x))\,\mathrm{d}x=\int_{-\infty}^{+\infty}\sum_{g(x)=\alpha}\frac1{\left|g'(x)\right|}\,f(\alpha)\,\mathrm{d}\alpha\tag{1}
$$
If we integrate along squares, centered at the origin, whose sides are parallel to the $x$ and $y$ axes with length $2k\pi$, as $k\to\infty$, we get
$$
\begin{align}
\sum_{x+\tan(x)=\alpha}\frac1{1+\sec^2(x)}
&=\frac1{2\pi i}\oint\frac{\mathrm{d}z}{z+\tan(z)-\alpha}\\[6pt]
&=1\tag{2}
\end{align}
$$
Letting $g(x)=x+\tan(x)$, $(1)$ and $(2)$ give
$$
\int_{-\infty}^{+\infty}f(x+\tan(x))\,\mathrm{d}x=\int_{-\infty}^{+\infty}f(x)\,\mathrm{d}x\tag{3}
$$
Therefore, applying $(3)$ to $f(x)=\frac1{1+x^2}$ yields
$$
\begin{align}
\int_{-\infty}^{+\infty}\frac{\mathrm{d}x}{1+(x+\tan(x))^2}
&=\int_{-\infty}^{+\infty}\frac{\mathrm{d}x}{1+x^2}\\[6pt]
&=\pi\tag{4}
\end{align}
$$
A: This integral can also be evaluated by standard contour integration.
Denote $f(z)=i+ \tan z + z$, using the identity:
$$\tan(x+yi) = \frac{\sin(2x)}{\cosh(2y)+\cos(2x)} + \frac{\sinh(2y)}{\cosh(2y)+\cos(2x)}i $$
it can be seen that $f(z) = 0$ has no root in the upper half plane.
Take $R$ to be a large half-integer (to avoid poles of $\tan x$), then $$\tag{1}\int_{-R}^R \frac{1}{f(x)} dx + \int_{C(R)} \frac{1}{f(z)} dz = 0$$
here $C(R)$ is a large semi-circle in upper-half plane with radius $R$. It is a nice exercise to show there exists an absolute constant $C$ such that $|\tan z| < C$ on all $C(R)$, so $$\lim_{R\to \infty} \int_{C(R)} \frac{1}{f(z)} dz = \lim_{R\to \infty} \int_{C(R)} \frac{1}{z} dz = \pi i$$
Taking imaginary parts of $(1)$:
$$\lim_{R\to \infty} \int_{-R}^R \frac{-1}{1+(x+\tan x)^2} dx +\pi = 0$$
this concludes the proof.
