Solving $\int_{-\infty}^{\infty}\frac{x^2e^x}{(1+e^x)^2}dx$ I am attempting to use residues to solve $\int_{-\infty}^{\infty}\frac{x^2e^x}{(1+e^x)^2}dx$; the answer is $\frac{\pi^2}{3}$. I have tried to split $\frac{x^2e^x}{(1+e^x)^2}$ into two parts
$$\frac{x^2}{e^x+1}-\frac{x^2}{\left(e^x+1\right)^2},$$
however no progress was to be made. I could not solve
$$
\int_{-\infty}^{\infty}\frac{z^2}{e^z+1}-\frac{z^2}{\left(e^z+1\right)^2}dz.
$$
any easier than the problem at hand. As a matter of fact neither of these two integrals converge individually. The way I approached the problem was by finding the singularities, namely when $e^z=-1$. So I got, when we let $z=x+iy$, that $z_k=i\pi+2\pi k$ for $k\in\mathbb{Z}$. This is my attempt,
$$
\int_{C}\frac{z^2e^{z}}{(e^z+1)^2}=2i\pi\sum_{\forall n}(Res(f,z_n)).
$$
Since $\{-1\}$ is a second order pole, our residue is given by
$$
\lim_{z\to z_k}\frac{d}{dz}[(z-z_k)^2\frac{z^2e^{z}}{(e^z+1)^2}].
$$
I found these with the aid of Mathematica. However if we were to calculate all the residues we would get an alternating sequence, if arranged properly. It becomes more apparent when we solve the equation that is split. For instance if we take $z_{-4}$ we get 
$$
2 \pi  i \left(\lim_{z\to z_{-4}} \, \frac{z^2 (z-z_{-4})}{e^z+1}\right)\ \text{and}\ 2 \pi  i \left(\lim_{z\to z_{-4}} \, \frac{\partial }{\partial z}\frac{\left(z-z_{-4}\right){}^2 \left(-z^2\right)}{\left(e^z+1\right)^2}\right)
$$
or,
$$
98i\pi^3 \text{ and } 14 i (-7 \pi +2 i) \pi ^2.
$$
So the total contribution would be $-28 \pi ^2$. Were as if we take $z_4$ we would get
$$
162 i \pi ^3 \text{ and } -18 i \pi ^2 (9 \pi +2 i)
$$
and the contribution would be $36 \pi ^2$.
One dilemma is finding the summation of all these residues. Is my work flawed? Is there a better contour to make this problem work? Thank you for the assistance.
 A: $\newcommand{\+}{^{\dagger}}%
 \newcommand{\angles}[1]{\left\langle #1 \right\rangle}%
 \newcommand{\braces}[1]{\left\lbrace #1 \right\rbrace}%
 \newcommand{\bracks}[1]{\left\lbrack #1 \right\rbrack}%
 \newcommand{\dd}{{\rm d}}%
 \newcommand{\isdiv}{\,\left.\right\vert\,}%
 \newcommand{\ds}[1]{\displaystyle{#1}}%
 \newcommand{\equalby}[1]{{#1 \atop {= \atop \vphantom{\huge A}}}}%
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}%
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}%
 \newcommand{\ic}{{\rm i}}%
 \newcommand{\imp}{\Longrightarrow}%
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}%
 \newcommand{\pars}[1]{\left( #1 \right)}%
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}%
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,#2\,}\,}%
 \newcommand{\sech}{\,{\rm sech}}%
 \newcommand{\sgn}{\,{\rm sgn}}%
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}%
 \newcommand{\verts}[1]{\left\vert #1 \right\vert}%
 \newcommand{\yy}{\Longleftrightarrow}$
This integral is an usual one in Statistical Mechanics $\pars{~\mbox{the integrand is an}\ {\large\tt\mbox{even}}\ \mbox{function}~}$:
\begin{align}\color{#0000ff}{\large%
\int_{-\infty}^{\infty}\!\!{x^{2}\expo{x}\,\dd x \over \pars{\expo{x} + 1}^{2}}}
&=
-2\int_{0}^{\infty}x^{2}\,\totald{}{x}\pars{1 \over \expo{x} + 1}\,\dd x
=
4\int_{0}^{\infty}{x \over \expo{x} + 1}\,\dd x
\\[3mm]&=
4\int_{0}^{\infty}x\pars{{1 \over \expo{x} + 1} - {1 \over \expo{x} - 1}}\,\dd x
+
4\int_{0}^{\infty}{x \over \expo{x} - 1}\,\dd x
\\[3mm]&=
-8\int_{0}^{\infty}{x \over \expo{2x} - 1}\,\dd x
+
4\int_{0}^{\infty}{x \over \expo{x} - 1}\,\dd x
\\[3mm]&=
-2\int_{0}^{\infty}{x \over \expo{x} - 1}\,\dd x
+
4\int_{0}^{\infty}{x \over \expo{x} - 1}\,\dd x
=
2\int_{0}^{\infty}x\expo{-x}\,{1 \over 1 - \expo{-x}}\,\dd x
\\[3mm]&=
2\int_{0}^{\infty}x\expo{-x}\sum_{\ell = 0}^{\infty}\expo{-\ell x}\,\dd x
=
2\sum_{\ell = 0}^{\infty}\int_{0}^{\infty}x\expo{-\pars{\ell + 1}x}\,\dd x
\\[3mm]&=
2\sum_{\ell = 0}^{\infty}{1 \over \pars{\ell + 1}^{2}}\
\overbrace{\int_{0}^{\infty}x\expo{-x}\,\dd x}^{=\ 1}
=
2\ \overbrace{\sum_{\ell = 1}^{\infty}{1 \over \ell^{2}}}^{\ds{=\,\pi^{2}/6}}
=
\color{#0000ff}{\large{\pi^{2} \over 3}}
\end{align}
A: Expanding on my comment, your problem is that you're encompassing infinitely many poles.  Pick a curve that encompasses finitely many, instead.  In particular, try integrating over the rectangle with vertices $(-R,0),(R,0),(-R,2\pi i), (R,2\pi i)$.  Be a little careful over the top part of the rectangle.  For $f(z) = \frac{z^2 e^z}{(1+e^z)^2}$ you have $$f(z+2\pi i) = \frac{(z+2\pi i)^2 e^z}{(1+e^z)^2} = f(z) -4\pi^2 \frac{e^z}{(1+e^z)^2} +4\pi i \frac{z e^z}{(1+e^z)^2}.$$
In particular, if you tried to just evaluate the integral using that single encompassed pole's residue right away you wouldn't get the correct answer.  The middle term has a contribution as well, but the third term contributes nothing.
A: Another approach, using $(1+y)^{-2}=\sum_{n\ge 0}(-1)^n(n+1)y^n$ from the binomial theorem: $$\int_{\Bbb R}\frac{x^2 e^{-x}dx}{(1+e^{-x})^2}=2\sum_{n\ge 0}(-1)^n(n+1)\int_0^\infty x^2e^{-(n+1)x}dx=4\sum_{k\ge 1}\frac{(-1)^{k-1}}{k^2}.$$Since $\sum_k\frac{1}{k^2}=\frac{\pi^2}{6}$, the even-$k$ terms sum to a quarter of this and we can subtract these out twice to get $\sum_{k\ge 1}\frac{(-1)^{k-1}}{k^2}=\frac{\pi^2}{6}(1-2\times\frac14)$, and we're done.
