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.
 A: The reason your integration by parts is not working good directly here, is that you do not want to let the constant $1$ and the $3/x^4$ take the same role in the integration by parts (i.e. raise or lower both of them), since then you will just keep going. It is better to "move them towards each other":
For one part:
$$
\int -\frac{3}{x^4}e^{-x^2/2}\,dx=\frac{1}{x^3}e^{-x^2/2}+\int \frac{1}{x^3}xe^{-x^2/2}\,dx
$$
For the other part, we don't see a primitive of $e^{-x^2/2}$, so we write the $1$ as $1=\frac{1}{x}x$, and then integrate by parts
$$
\begin{aligned}
\int e^{-x^2/2}\,dx &= \int \frac{1}{x} xe^{-x^2/2}\,dx\\
&=-\frac{1}{x}e^{-x^2/2}-\int\frac{1}{x^2}e^{-x^2/2}\,dx 
\end{aligned}
$$
The "funny" thing now is that the integrals that are left just cancel (this is lucky, and the exercise is made so that this should happen, in the general case one would meet error functions). Adding, we find that
$$
\int \Bigl(1-\frac{3}{x^4}\Bigr)e^{-x^2/2}\,dx=\Bigl(\frac{1}{x^3}-\frac{1}{x}\Bigr)e^{-x^2/2}+C.
$$
A: i tired integration by parts to show to OP but i think it doesn't work
Let's compute this integral :
$$\int \left(1 - \frac{3}{x^4}\right)\exp\left(-\frac{x^{2}}{2}\right) dx?$$
indeed,
$$ u=e^{\dfrac{-x^{2}}{2}},dv = (1 - 3/x^4)\qquad du=-e^{-\dfrac{x^2}{2}}x,\, v=\frac{1}{x^3}+x $$
\begin{align}
\int \left(1 - \frac{3}{x^4}\right)\exp\left(-\frac{x^{2}}{2}\right)\,dx&=(e^{\dfrac{-x^{2}}{2}} )(\frac{1}{x^3}+x)\biggl|-\int (\frac{1}{x^3}+x)( -e^{-\dfrac{x^2}{2}}x)\,dx \\
&=\frac{x^4+1}{e^{\frac{x^2}{2}}x^3}\biggl|-\int (\frac{1}{x^3}+x)( -e^{-\dfrac{x^2}{2}}x)\,dx\\
&=\frac{x^4+1}{e^{\frac{x^2}{2}}x^3}\biggl|-\int (\frac{1}{x^3}+x)( -e^{-\dfrac{x^2}{2}}x)\,dx
\end{align}
let's calculate $$\int (\frac{1}{x^3}+x)( -e^{-\dfrac{x^2}{2}}x)\,dx$$
$$ u=e^{\dfrac{-x^{2}}{2}},dv = \frac{1}{x^3}+x\qquad du=-e^{-\dfrac{x^2}{2}}x,\, v=-\frac{1}{2x^2}+\frac{x^2}{2} $$
\begin{align}
\int (\frac{1}{x^3}+x)( -e^{-\dfrac{x^2}{2}}x)\,dx&=-(e^{\dfrac{-x^{2}}{2}})(-\frac{1}{2x^2}+\frac{x^2}{2})\biggl|-\int (-\frac{1}{2x^2}+\frac{x^2}{2})( -e^{-\dfrac{x^2}{2}}x)\,dx\\
&=
\end{align}
A: 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*}
