How do we evaluate the closed form for $\int_{-\infty}^{+\infty}{(-1)^{n+1}x^{2n}+2n+1\over (1+x^2)^2}\cdot e^{-x^2}\mathrm dx?$

Here is a way forward that provides a solution in terms of a finite double summation.

Let $f(a)$ be defined by

$$f(a)=\int_{-\infty}^\infty \frac{e^{-ax^2}}{(1+x^2)^2}\,dx=\sqrt{\pi a}-\frac{\pi}{2}(2a-1)e^a \text{erfc}(\sqrt {a}) \tag 1$$

Then, the $n$'th derivative of $f(a)$ can be written

$$f^{(n)}(a)=\int_{-\infty}^\infty \frac{(-1)^nx^{2n}e^{-ax^2}}{(1+x^2)^2}\,dx\tag 2$$

Using $(1)$ and $(2)$ reveals

$$\int_{-\infty}^\infty \frac{(-1)^{n+1}x^{2n}+(2n+1)}{(1+x^2)^2}e^{-x^2}\,dx=(2n+1)f(1)-f^{(n)}(1)\tag 3$$

We can then use $(1)$ and $(2)$ to generate evaluated at $1$ to evaluate the integral of interest in $(3)$.


First, it is trivial to see that

$$(2n+1)f(1)=(2n+1)\sqrt{\pi}-(2n+1)\frac{e\pi}2 \,\text{erfc}(1)\tag 4$$

Second, it is straightforward to show that

$$\left.\left(\frac{d^n }{da^n}\sqrt{\pi a}\right)\right|_{a=1}=\frac{(-1)^{n-1}\sqrt{\pi}(2n-3)!!}{2^n} \tag5$$

Third, using the General Leibniz's Rule for the n'th derivative of a product of two functions, we have

$$\begin{align} -\frac\pi2\left.\left(\frac{d^n }{da^n}\left( (2a-1)e^a\text{erfc}(\sqrt a)\right)\right)\right|_{a=1}&=-\frac\pi2\left.\left(\sum_{k=0}^n\binom{n}{k}\frac{d^k}{da^k}\left(\text{erfc}(\sqrt{a})\right)\,\frac{d^{n-k}}{da^{n-k}}\left((2a-1)e^a\right) \right)\right|_{a=1}\\\\ &=-\frac\pi2\sum_{k=0}^n\binom{n}{k}\left.\left(\frac{d^k}{da^k}\left(\text{erfc}(\sqrt{a})\right)\right)\right|_{a=1}\,\left(2(n-k)+1)e\right) \\\\ &=-(2n+1)\frac{e\pi}2 \,\text{erfc}(1)\\\\ &-\frac\pi2\sum_{k=1}^n\binom{n}{k}\left.\left(\frac{d^k}{da^k}\left(\text{erfc}(\sqrt{a})\right)\right)\right|_{a=1}\,\left(2(n-k)+1)e\right) \tag6 \end{align}$$

Using $(4)$, $(5)$, and $(6)$ in $(3)$ yields

$$\begin{align} \int_{-\infty}^\infty \frac{(-1)^{n+1}x^{2n}+(2n+1)}{(1+x^2)^2}e^{-x^2}\,dx&=(2n+1)\sqrt{\pi}+\frac{(-1)^{n}\sqrt{\pi}}{2^n}(2n-3)!!\\\\ &+\frac\pi2\sum_{k=1}^n\binom{n}{k}\left.\left(\frac{d^k}{da^k}\left(\text{erfc}(\sqrt{a})\right)\right)\right|_{a=1}\,\left(2(n-k)+1)e\right)\tag 7 \end{align}$$


Evaluating that derivative(s) in $(7)$, $\frac{d^k}{da^k}\left(\text{erfc}(\sqrt{a})\right)$, we find

$$\begin{align} \frac{d^k}{da^k}\left(\text{erfc}(\sqrt{a})\right)&=-\frac{1}{\sqrt{\pi}}\frac{d^{k-1}}{da^{k-1}}\left(a^{-1/2}e^{-a}\right)\\\\ &=-\frac{1}{e\sqrt{\pi}}\sum_{m=0}^{k-1}\binom{k-1}{m}\left(\frac{(-1)^{k-1}(2m-1)!!}{2^m}\right)\tag 8 \end{align}$$

Finally, substituting $(8)$ into $(7)$ we have

$$\begin{align} \int_{-\infty}^\infty \frac{(-1)^{n+1}x^{2n}+(2n+1)}{(1+x^2)^2}e^{-x^2}\,dx&=(2n+1)\sqrt{\pi}+\frac{(-1)^{n}\sqrt{\pi}}{2^n}(2n-3)!!\\\\ &-\frac{\sqrt {\pi}}{2}\sum_{k=1}^n\binom{n}{k}\,(2(n-k)+1)\sum_{m=0}^{k-1}\binom{k-1}{m}\left(\frac{(-1)^{k-1}(2m-1)!!}{2^m}\right) \end{align}$$


This is not answer since the result was just obtained using a CAS.

The first amazing thing I noticed is that $F(6)=F(5)=63$.

Then, using a CAS (which is cheating), I arrived, for $F(n)$, to the surprising result $$-\frac{2^{n-3} \left(\sqrt{\pi } \left(e \sqrt{\pi } \text{erfc}(1)-2\right) (2 n+1)+(-1)^n \left(e(2 n+1) E_{n-\frac{1}{2}}(1)-2\right) \Gamma \left(n-\frac{1}{2}\right)\right)}{\sqrt{\pi }}$$ I produced below a few values $$\left( \begin{array}{cc} n & F(n) \\ 1 & 1 \\ 2 & 3 \\ 3 & 9 \\ 4 & 21 \\ 5 & 63 \\ 6 & 63 \\ 7 & 945 \\ 8 & -6867 \\ 9 & 103887 \\ 10 & -1584009 \\ 11 & 27707841 \\ 12 & -537561675 \\ 13 & 11488232511 \\ 14 & -268130966481 \\ 15 & 6787376784657 \\ 16 & -185236015672323 \\ 17 & 5422189783801455 \\ 18 & -169469080764615513 \\ 19 & 5633094788569182753 \\ 20 & -198432839999364578811 \end{array} \right)$$


$\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

$\ds{\mc{J}_{n} \equiv \int_{-\infty}^{\infty}{\pars{-1}^{n + 1}x^{2n} + 2n + 1 \over \pars{1 + x^{2}}^{2}}\expo{-x^{2}}\,\dd x = {\root{\pi} \over 2^{n - 2}}\,\mrm{F}\pars{n}\,,\qquad n \in \mathbb{N}_{\ \geq\ 1}.\quad\mrm{F}\pars{n}:\ {\large ?}}$.

\begin{align} \mc{J}_{n} & = 2\int_{0}^{\infty}{\pars{-1}^{n + 1}x^{2n} + 2n + 1 \over \pars{1 + x^{2}}^{2}}\expo{-x^{2}}\,\dd x \,\,\,\stackrel{x^{2}\ \mapsto\ x}{=}\,\,\, \int_{0}^{\infty}{\pars{-1}^{n + 1}x^{n -1/2} + \pars{2n + 1}x^{-1/2} \over \pars{1 + x}^{2}}\expo{-x}\,\dd x \\[5mm] & = \int_{0}^{\infty}\bracks{% \pars{-1}^{n + 1}x^{n -1/2} + \pars{2n + 1}x^{-1/2}}\expo{-x} \bracks{\int_{0}^{\infty}t\expo{-\pars{1 + x}t}\,\dd t}\dd x \\[5mm] & = \int_{0}^{\infty}t\expo{-t}\int_{0}^{\infty} \bracks{\pars{-1}^{n + 1}x^{n -1/2}\expo{-\pars{1 +t}x} + \pars{2n + 1}x^{-1/2}\expo{-\pars{1 + t}x}} \dd x\,\dd t \\[5mm] & = \int_{0}^{\infty}t\expo{-t}\bracks{% {\pars{-1}^{n + 1}\,\Gamma\pars{n + 1/2} \over \pars{1 + t}^{n + 1/2}} + {\pars{2n + 1}\Gamma\pars{1/2} \over \pars{1 + t}^{1/2}}}\,\dd t \\[5mm] & = \pars{-1}^{n + 1}\,\Gamma\pars{n + {1 \over 2}}a_{n} + \pars{2n + 1}\root{\pi}a_{0} \end{align}

where

\begin{align} a_{n} & \equiv \int_{0}^{\infty}{t\expo{-t} \over \pars{t + 1}^{n + 1/2}}\,\dd t \,\,\,\stackrel{t + 1\ \mapsto\ t}{=}\,\,\, \int_{1}^{\infty}{\pars{t - 1}\expo{-\pars{t - 1}} \over t^{n + 1/2}}\,\dd t \\[5mm] & = \expo{}\pars{\int_{1}^{\infty}{\expo{-t} \over t^{n - 1/2}}\,\dd t - \int_{1}^{\infty}{\expo{-t} \over t^{n + 1/2}}}\,\dd t = \expo{}\bracks{\mrm{E}_{n - 1/2}\pars{1} - \,\mrm{E}_{n + 1/2}\pars{1}} \end{align}

$\ds{\,\mrm{E}_{p}}$ is the Generalized Exponential Integral.

\begin{align} \mc{J}_{n} & \equiv \int_{-\infty}^{\infty}{\pars{-1}^{n + 1}x^{2n} + 2n + 1 \over \pars{1 + x^{2}}^{2}}\expo{-x^{2}}\,\dd x \\[5mm] & = \expo{}\left\{\vphantom{\LARGE A}\pars{-1}^{n + 1}\,\Gamma\pars{n + {1 \over 2}} \bracks{\mrm{E}_{n - 1/2}\pars{1} - \,\mrm{E}_{n + 1/2}\pars{1}}\right. \\[5mm] & \left.\phantom{\expo{}\braces{}}+ \pars{2n + 1}\root{\pi}\bracks{\mrm{E}_{-1/2}\pars{1} - \,\mrm{E}_{1/2}\pars{1}}\vphantom{\LARGE A}\right\} = {\root{\pi} \over 2^{n - 2}}\,\mrm{F}\pars{n} \end{align}