Integrate $$\int \exp\left(-\frac{z^2}{2}\right) \frac{z^4+2z^2-1}{(z^2+1)^2}dz$$
This function has exponential factor and rational factor.
I know already that the solution is
$$-\frac{z\exp\left(-\frac{z^2}{2}\right)}{z^2+1} + C$$
But I have no idea on what method should I use to find it.
$$I=\int e^{\large-\frac{z^2}{2}}\, \frac{z^4+2z^2-1}{(z^2+1)^2}dz$$ With some algebra we have: $$z^4+z^2+z^2-1=z^2(z^2+1) +z^2-1$$ $$\Rightarrow \frac{z^4+2z^2-1}{(z^2+1)^2}=\frac{z^2}{z^2+1}+\frac{z^2-1}{(z^2+1)^2}$$ $$\Rightarrow I= \color{blue}{\int e^{-\frac{z^2}{2}}\frac{z^2}{z^2+1}dz}+\color{red}{\int e^{-\frac{z^2}{2}} \frac{z^2-1}{(z^2+1)^2}dz}$$ Now since we have similarly to here:$$\int \frac{z^2-1}{(z^2+1)^2}dz=-\frac{z}{z^2+1}+C$$ Integrating by parts the second integral gives us: $$\int e^{-\frac{z^2}{2}} \, \frac{z^2-1}{(z^2+1)^2}dz=\color{red}{-e^{-\frac{z^2}{2}}\frac{z}{z^2+1}-\int e^{-\frac{z^2}{2}}\frac{z^2}{z^2+1}dz}$$ $$\require{cancel}\Rightarrow I= \cancel{\color{blue}{\int e^{-\frac{z^2}{2}}\frac{z^2}{z^2+1}dz}}\color{red}{-e^{-\frac{z^2}{2}}\frac{z}{z^2+1}-\cancel{\int e^{-\frac{z^2}{2}}\frac{z^2}{z^2+1}dz}}$$ $$\Rightarrow \int e^{\large-\frac{z^2}{2}}\, \frac{z^4+2z^2-1}{(z^2+1)^2}dz=-e^{-\frac{z^2}{2}}\frac{z}{z^2+1}+C$$