<s>[INST] Computing $\int (1 - \frac{3}{x^4})\exp(-\frac{x^{2}}{2}) dx$ How does one compute
$$\int \left(1 - \frac{3}{x^4}\right)\exp\left(-\frac{x^{2}}{2}\right) dx?$$
Mathematica gives $(x^{-3} - x^{-1})\exp(-x^2/2)$ which indeed the correct answer, but how does one get there? 
Integration by parts gives $(y + y^{-3})e^{-y^2/2} + \int (y^2 + y^{-2})e^{-y^2/2} dy$, but I'm not sure what to do with the integral.
 [/INST] The integral is of the form 
\begin{equation*}
\int \left( 1-\frac{3}{x^{4}}\right) e^{\left( -\frac{x^{2}}{2}\right)
}dx=\int h(x)e^{g(x)}dx.
\end{equation*}
This form recalls the well-known formula
\begin{equation*}
\int \left( f^{\prime }(x)+g^{\prime }(x)f(x)\right) e^{\left( -\frac{x^{2}}{
2}\right) }dx=f(x)e^{\left( -\frac{x^{2}}{2}\right) }+C.
\end{equation*}
Its proof maybe found at
Proof for formula $\int e^{g(x)}[f'(x) + g'(x)f(x)] dx = f(x) e^{g(x)}+C$
So we are done if we find a function $f(x)$ such that
\begin{equation*}
h(x)=f^{\prime }(x)+g^{\prime }(x)f(x).
\end{equation*}
In what follows, I will show that $f(x)=x^{-3}-x^{-1},$ and therefore
\begin{equation*}
\int \left( 1-\frac{3}{x^{4}}\right) e^{\left( -\frac{x^{2}}{2}\right)
}dx=\left( x^{-3}-x^{-1}\right) e^{\left( -\frac{x^{2}}{2}\right) }+C.
\end{equation*}
$\color{red}{\bf Problem:}$ We want to write $1-\frac{3}{x^{4}}$ as $f^{\prime
}(x)+g^{\prime }(x)f(x)$ where $g(x)=-\frac{x^{2}}{2},$ $g^{\prime }(x)=-x$
and $f(x)$ is to be determined.  
First, it is easy to see that 
\begin{equation*}
-\frac{3}{x^{4}}=-3x^{-4}=(x^{-3})^{\prime }.
\end{equation*}
It follows that if we put $f_{1}(x)=x^{-3},$ then 
\begin{equation*}
f_{1}^{\prime }(x)+g^{\prime }(x)f_{1}(x)=\left( -\frac{3}{x^{4}}\right)
+\left( -x\right) \left( x^{-3}\right) =\left( -\frac{3}{x^{4}}-\frac{1}{%
x^{2}}\right) 
\end{equation*}
This suggests to add and to substract the term $-\frac{1}{x^{2}}$ as follows
\begin{equation*}
\left( 1-\frac{3}{x^{4}}\right) =\left( 1-\frac{3}{x^{4}}\right) -\frac{1}{
x^{2}}+\frac{1}{x^{2}}=\left( -\frac{3}{x^{4}}-\frac{1}{x^{2}}\right)
+\left( \frac{1}{x^{2}}+1\right) ,
\end{equation*}
Now let us find $f_{2}(x)$ such that : 
\begin{equation*}
\left( \frac{1}{x^{2}}+1\right) =f_{2}^{\prime }(x)+g^{\prime }(x)f_{2}(x).
\end{equation*}
It is easy to see that 
\begin{equation*}
\frac{1}{x^{2}}=x^{-2}=(-x^{-1})^{\prime }.
\end{equation*}
Then if we put $f_{2}(x)=-x^{-1},$ it follows that
\begin{equation*}
f_{2}^{\prime }(x)+g^{\prime }(x)f_{2}(x)=\left( -x^{-1}\right) ^{\prime
}-x(-x^{-1})=\frac{1}{x^{2}}-x\left( -x^{-1}\right) =\left( \frac{1}{x^{2}}
+1\right) .
\end{equation*}
It follows that
\begin{eqnarray*}
\left( 1-\frac{3}{x^{4}}\right)  &=&\left( -\frac{3}{x^{4}}-\frac{1}{x^{2}}
\right) +\left( \frac{1}{x^{2}}+1\right)  \\
&& \\
&=&\left( f_{1}^{\prime }(x)+g^{\prime }(x)f_{1}(x)\right) +\left(
f_{2}^{\prime }(x)+g^{\prime }(x)f_{2}(x)\right)  \\
&& \\
&=&\left( (f_{1}(x)+f_{2}(x))^{\prime }+g^{\prime
}(x)(f_{1}(x)+f_{2}(x))\right) 
\end{eqnarray*}
then, it suffices to take 
\begin{equation*}
f(x)=f_{1}(x)+f_{2}(x)=x^{-3}-x^{-1}.\ \ \ 
\color{red}
\blacksquare 
\end{equation*}
</s>