On the computation of $\int \frac{x^2-x+1}{e^x \sqrt{x^2+1}}dx$ At a mathematical competition in my country the following problem was proposed:    

Compute $\displaystyle I=\int \frac{x^2-x+1}{e^x \sqrt{x^2+1}}\,dx$ where $x\in \mathbb{R}$.     

I came up with the following solution, and this is also the solution presented in my book:   
\begin{align}
I
&= \int e^{-x}\sqrt{x^2+1}\,dx-\int e^{-x} \frac{x}{\sqrt{x^2+1}}\,dx\\
&= \int e^{-x}\sqrt{x^2+1}\,dx-\int e^{-x}\left(\sqrt{x^2+1}\right)'\,dx \\
&= \int e^{-x}\sqrt{x^2+1}\,dx-e^{-x}\sqrt{x^2+1}-\int e^{-x}\sqrt{x^2+1}\,dx \\
&=-e^{-x}{\sqrt{x^2+1}}+C.
\end{align}
At a first glance, this seemed all right because $\left(-e^{-x}{\sqrt{x^2+1}}\right)'=e^{-x}\,\frac{x^2-x+1}{\sqrt{x^2+1}}$, $\forall x \in \mathbb{R}$.
But then I thought that maybe it is not, because I am basically subtracting two antiderivatives, and as my topic from here shows (A "proof" for $0=1$ by integrating $\int \frac{dx}{x\ln x}$ by parts), this is not allowed.
I went on to plug in this indefinite integral into WolframAlpha and it said that no result could be found in terms of elementary functions.  
Yet, $(-e^{-x}{\sqrt{x^2+1}})'=e^{-x}\,\frac{x^2-x+1}{\sqrt{x^2+1}}$, $\forall x \in \mathbb{R}$ is true, so my antiderivative should be correct.
So, what I am asking is if the solution I presented is somehow correct, and if it is, then why it works, since to the best of my knowledge it shouldn't.
 A: I propose to divide in two the function's numerator:
$$\int\frac{x^2-x+1}{e^x\sqrt{x^2+1}}dx=\int\frac{x^2+1}{e^x\sqrt{x^2+1}}dx-\int\frac x{e^x\sqrt{x^2+1}}dx=$$
$$=\int e^{-x}\sqrt{x^2+1}\,dx-\int e^{-x}\frac x{\sqrt{x^2+1}}dx\stackrel{\text{IBP of 1st integral}}=$$
$$=-e^{-x}\sqrt{x^2+1}+\int e^{-x}\frac x{\sqrt{x^2+1}}dx-\int e^{-x}\frac x{\sqrt{x^2+1}}dx=-e^{-x}\sqrt{x^2+1}+C$$
and now perhaps it does look slightly less misterious...
And subtracting/adding two antiderivatives that are equal up to an additive constant just changes at most the constant...so no problem as we're interested only in primitive "functions"
A: Set $-x=y,$
$$I=-\int e^y\dfrac{y^2+y+1}{\sqrt{y^2+1}}dy$$
Now $\dfrac{d(e^yf(y))}{dy}=?$
Again $\dfrac{y^2+y+1}{\sqrt{y^2+1}}=\sqrt{y^2+1}+\dfrac y{\sqrt{y^2+1}}$
Observe that $f(y)=\sqrt{y^2+1}\implies \dfrac{df}{dy}=?$
A: The IBP example you mention doesn't ruin your strategy here because if you interpret an indefinite integral $\int f(x)dx$ as denoting the set of all antiderivatives of $f$ and adopt the defintion $c+S:=\{c+g|g\in S\}$, statements such as $\int\frac{dx}{x\ln x}=1+\int\frac{dx}{x\ln x}$ are true, so subtracting antiderivatives is allowed with that caveat.
If WA says it couldn't find an elementary result, it might just not be smart enough to find it.
