5

I can see that Wolfram Alpha can compute this, but I would like to understand how. The integrand has a poles at $\pm i\pi$ but because of the square at the bottom of the fraction, I cannot quite see how to apply residues here. The integral is also related to moments of logistic distribution https://en.wikipedia.org/wiki/Logistic_distribution (indeed this is how I got here), but cannot quite follow how the moments evaluate to results that depend on Bernoulli numbers. It would seem I am missing some transformation that would bring it into useful form. Can you please suggest how to proceed?

Thanks

Cryo
  • 778

4 Answers4

6

\begin{align} \int^{\infty}_{-\infty} \frac{x^2 e^{-x}}{(1+e^{-x})^2}dx \overset{t=e^{-x}}=&\int_0^\infty\frac{\ln^2t}{(1+t)^2}dt =2 \int_0^1 \frac{\ln^2t}{(1+t)^2}dt\\ =& \ 2\int_0^1 \ln^2t \ d\left(\frac{t}{1+t}\right) \overset{ibp}=-4 \int_0^1\frac{\ln t}{1+t}dt\\ =& -4\cdot \left(-\frac{\pi^2}{12}\right)=\frac{\pi^2}3 \end{align} where $\int_0^1\frac{\ln t}{1+t}dt=-\frac{\pi^2}{12}$.

Quanto
  • 97,352
  • 1
    see $$ \int_{-\infty}^\infty \frac{x^2 , e^{-x}}{(1+e^{-x})^2} , \mathrm{d}x = \int_0^\infty \frac{2 , x^2 , e^{-x}}{(1+e^{-x})^2} , \mathrm{d}x $$ And now we can use Binomial Expansion of $$ (1+e^{-x})^{-2} = 1 - 2,e^{-x} + 3,e^{-2x} -4,e^{-3x} + \cdots = \sum_{n=0}^\infty (-1)^n , (n+1) , e^{-nx} $$ which is very cool though..... I thought like this because we can directly use gamma function here XD. – Lucky Chouhan Mar 10 '23 at 12:06
  • Really appreciate your help, thanks – Cryo Mar 10 '23 at 21:45
4

Integration by parts may help. Functions of the type $\int x^n f(x) \, \mathrm{d}x$ somewhat beg for it, and $\int e^{-x}\,\mathrm{d}x/(1+e^{-x})^2 $ seems easily handled.

Using the DI method to organize our work, we see that

enter image description here

gives us

$$\int_{-\infty} \frac{x^2 e^{-x} \, \mathrm{d}x}{(1+e^{-x})^2} = x^2 h(x) \bigg|_{-\infty}^\infty - 2x g(x) \bigg|_{-\infty}^\infty + 2 f(x) \bigg|_{-\infty}^\infty$$

where $h,g,f$ are the successive antiderivatives of $e^{-x}/(1+e^{-x})^2$.

To find $h$, firstly, I would suggest using the $u$-substitution $u=1+e^{-x}$.

To find $g$, integrate the result of the previous. Try $u=e^x$, and use partial fraction decomposition.

The antiderivative that yields $f$ is going to reference polylogarithms ($\text{Li}_2$ specifically), which have asymptotic expansions referencing Bernoulli numbers; as seen here, for $|z| \gg 1$,

$$ \operatorname{Li}_s(z) = \sum_{k=0}^\infty (-1)^k (1-2^{1-2k}) (2\pi)^{2k} {B_{2k} \over (2k)!} {[\ln(-z)]^{s-2 k} \over \Gamma(s+1-2k)} $$

and

$$\operatorname{Li}_s(z) = {\pm i\pi \over \Gamma(s)} [\ln(-z) \pm i\pi]^{s-1} - \sum_{k = 0}^\infty (-1)^k (2\pi)^{2k} {B_{2k} \over (2k)!} {[\ln(-z) \pm i\pi]^{s-2 k} \over \Gamma(s+1-2k)}$$

Apparently for non-negative integers $s$, this breaks off after finitely many terms.

PrincessEev
  • 43,815
4

In fact, using $$ \frac1{(1-x)^2} =\sum_{n=1}^\infty (-1)^{n-1}nx^{n-1},\int_0^\infty x^2e^{-ax}=\frac{2}{a^3}$$ one has \begin{align} &\int^{\infty}_{-\infty} \frac{x^2 e^{-x}}{(1+e^{-x})^2}dx=2\int^{\infty}_{0} \frac{x^2 e^{-x}}{(1+e^{-x})^2}dx\\ =&2\int_0^\infty \sum_{n=1}^\infty (-1)^{n-1}nx^2e^{nx}dx\\ =&2 \sum_{n=1}^\infty (-1)^{n-1}n\int_0^\infty x^2e^{nx}dx\\ =&4\sum_{n=1}^\infty (-1)^{n-1}\frac{1}{n^2}\\ =&\frac{\pi^2}3 \end{align} where $$ \sum_{n=1}^\infty (-1)^{n-1}\frac{1}{n^2}=\frac{\pi^2}{12}. $$

xpaul
  • 44,000
  • Thanks! The first step in reducing domain of integration to $0\dots\infty$ was not clear at first, but I get it now. For me this is the best answer since it relies least on special functions. The end sum to get to $\pi$ is disappointing, but would seem that there is no simpler way to get the closed form. Really appreciate your help, thanks – Cryo Mar 10 '23 at 21:44
3

Here is an alternate and probably over-the-top method of evaluating this integral using complex analysis.

Let $I$ be the integral in question. Note that $\displaystyle \int_{-\infty}^{\infty}\frac{x^{2}e^{-x}}{\left(1+e^{-x}\right)^{2}}dx = \int_{-\infty}^{\infty}\frac{x^{2}e^{x}}{\left(1+e^{x}\right)^{2}}dx$. Let $\displaystyle f(z) = \frac{z^{3}e^{z}}{\left(1+e^{z}\right)^{2}}$. Its set of poles is $\left\{z \in \mathbb{C} : z = \pi i (2n+1)\right\}$ for all $n \in \mathbb{Z}$, but the only pole we will concern ourselves with is $z=\pi i$. Traversing counterclockwise, define a rectangular contour $C := \left\{z \in \mathbb{C} : \Re(z) \in [-R,R] \text{ } \wedge \text{ } \Im(z) \in [0,2\pi]\right\}$ visualized below.

RECTANGULAR CONTOUR

By Cauchy's Residue Theorem, we can rewrite $\displaystyle \oint_{C} f(z)dz$ as

$$2\pi i \operatorname{Res}(f(z), z = i\pi) = \left(\int_{-R}^{R}+\int_{R}^{R+2\pi i}+\int_{R+2\pi i}^{-R+2\pi i}+\int_{-R+2\pi i}^{-R}\right)f(z)dz.$$

We can prove that the integrals over the vertical line segments go to $0$ as $R \to \infty$. (I can type out a proof if someone wants me to.)

We evaluate the residue by transforming $f(z)$ as its Laurent expansion centered at its pole $z=i\pi$ like this:

$$2\pi i \operatorname{Res}\left(\frac{i\pi^{3}}{\left(z-i\pi\right)^{2}}+\frac{3\pi^{2}}{z-i\pi}-\frac{i\pi}{12}\left(36+\pi^{2}\right)-\left(1-\frac{\pi^{2}}{4}\right)\left(z-i\pi\right)+O\left(\left(z-i\pi\right)^{2}\right)\right) = 2\pi i \cdot 3\pi^2.$$

Evaluating $\displaystyle\lim_{R\to\infty}\oint_{C} f(z)dz$, we get $$ \begin{align} 2\pi i \cdot 3\pi^2 &= \lim_{R\to\infty}\left(\int_{-R}^{R}+\int_{R}^{R+2\pi i}+\int_{R+2\pi i}^{-R+2\pi i}+\int_{-R+2\pi i}^{-R}\right)f(z)dz \\ &= \lim_{R\to\infty}\int_{-R}^{R}f(z)dz + 0 + \lim_{R\to\infty}\int_{R+2\pi i}^{-R+2\pi i}f(z)dz + 0 \\ \lim_{R\to\infty}\int_{-R}^{R}f(z)dz &= 6\pi^3 i + \lim_{R\to\infty}\int_{-R+2\pi i}^{R+2\pi i}f(z)dz \\ &= 6\pi^3 i + \lim_{R\to\infty}\int_{-R}^{R}f(x+2\pi i)d(x + 2\pi i) \\ &= 6\pi^{3}i+\lim_{R\to\infty}\int_{-R}^{R}\frac{\left(x+2\pi i\right)^{3}e^{x+2\pi i}}{\left(1+e^{x+2\pi i}\right)^{2}}dx. \\ \end{align} $$

That integral on the right side is

$$\int_{-R}^{R}\frac{x^{3}e^{x}}{\left(1+e^{x}\right)^{2}}dx+6\pi i\int_{-R}^{R}\frac{x^{2}e^{x}}{\left(1+e^{x}\right)^{2}}dx-12\pi^{2}\int_{-R}^{R}\frac{xe^{x}}{\left(1+e^{x}\right)^{2}}dx-8\pi^{3}i\int_{-R}^{R}\frac{e^{x}}{\left(1+e^{x}\right)^{2}}dx.$$

The third integral above vanishes because its integrand is an odd function. Hopefully, it is trivial to prove that $\displaystyle \int_{-\infty}^{\infty}\frac{e^{x}}{\left(1+e^{x}\right)^{2}}dx = 1$.

Going back to $\displaystyle\lim_{R\to\infty}\oint_{C} f(z)dz$, we get

$$ \begin{align} \lim_{R\to\infty}\int_{-R}^{R}f(z)dz &= 6\pi^3 i + \lim_{R\to\infty}\int_{-R}^{R}f(x)dx + 6\pi i I - 12\pi^2 (0) - 8\pi^3 i (1). \\ \end{align} $$

In conclusion, the integral $I$ is $\displaystyle \frac{\pi^2}{3}$, and we are finished!

Accelerator
  • 4,923
  • 1
    This is great! A derivation that does not rely on any special functions. I was seeking a path through contour integration, but my residue calculus was so rusty I got put off by quadratic pole and forgot it evaluates to zero. Indeed there is also a 1/z pole in there which does give a way forward. Really made me think, and this knowledge is re-usable. Many great answers in this question, but this is my new favorite. – Cryo Mar 11 '23 at 11:36
  • 1
    Is there a typo in your final line? $I=\pi^2/3$, I think – Cryo Mar 11 '23 at 11:42
  • @Cryo You're right. I accidentally typed a 4 on my keyboard. ‍♂️ – Accelerator Mar 11 '23 at 16:38
  • 1
    @Cryo Thank you very much for catching my error. The rest of the answer should be correct after double-checking. I think the main thing to take away from this answer is that if you see an integral over $(-\infty, \infty)$ that has in the denominator only $e^x$ and some constants, constructing a rectangular contour like the screenshot I have in the post could be a good idea because $e^{x + 2\pi i} = e^x$. But what do you mean by a quadratic pole evaluating to $0$ and there's a $1/z$ pole there? – Accelerator Mar 11 '23 at 16:52
  • By quadratic pole I meant that the Laurent series include $1/\left(z-i\pi\right)^2$ and $1/\left(z-i\pi\right)$. Very familiar with the latter, what I forgot is that contour integral around the former is zero. I have repeated your derivation end-to-end - it all makes sense now – Cryo Mar 12 '23 at 22:05