Need help integrating $\int e^x(\frac{x+2}{x+4})^2 dx $ I have simplified the problem a bit using integration by parts, with $u = e^x(x+2)^2$ and $v = 1/(x+4)^2$ but I'm then stuck with how to integrate this:
$$\int\frac{e^x(x^2+4x+8)}{x+4}dx. $$
I've considered substituting $t = e^x$, but this doesn't seem to make the problem any easier.
 A: HINT:
$$(x+2)^2=(x+4-2)^2=(x+4)^2-4(x+4)+4$$
$$\int e^x[f'(x)+f(x)]dx=e^xf(x)+K$$
Can you recognize $f(x)$ here?
A: \begin{align*}\int e^x\left(\frac{x+2}{x+4}\right)^2\,\mathrm dx&=\int\frac1{(x+4)^2}e^x(x+2)^2\,\mathrm dx\\&=-\frac{e^x(x+2)^2}{x+4}+\int e^x(x+2)\,\mathrm dx\\&=-\frac{e^x(x+2)^2}{x+4}+e^x(x+2)-\int e^x\,\mathrm dx\\&=-\frac{e^x(x+2)^2}{x+4}+e^x(x+1)\\&=\frac{xe^x}{x+4}.\end{align*}
A: Since 
\begin{align*}
\left(\frac{x+2}{x+4}\right)^2 &= \frac{x^2+4x+4}{(x+4)^2} \\
&= \frac{4}{(x+4)^2}+\frac{x(x+4)}{(x+4)^2} \\
&= \frac{4}{(x+4)^2}+\frac{x}{x+4} \\
&=f'(x)+f(x), \\ 
\end{align*}
let 
$$
\color{blue}{f(x)=\frac{x}{x+4}}.
$$  
Now for $C$ constant, since 
$$
\dfrac{d}{dx}(e^x f(x)+C) = (e^x f(x)+C)' = e^x f'(x)+e^x f(x), 
$$
we have 
$$
\int \left(e^x f'(x)+e^x f(x)\right)dx = e^x f(x)+C. 
$$
So for the above indefinite integral, 
$$
\begin{align*}
\color{green}{\int e^x\left(\frac{x+2}{x+4}\right)^2 dx} 
&= \int e^x \left(f'(x) + f(x)\right) dx  \\ 
&= \int \left(e^x f'(x)+e^x f(x)\right) dx \\
&= e^x f(x)+C \\ 
&= \color{green}{\frac{x\: e^x}{x+4} + C}.
\end{align*}
$$
