Difference between anti-derivative and indefinite integral My teacher gave me the following integral to evaluate:
$$\int \frac{x^2}{(x\sin(x)+\cos(x))^2}dx$$
After half an hour of uselessly fumbling around with trig identities I gave up and plugged it into an integral calculator: https://www.integral-calculator.com/. However I am confused: it displayed ANTIDERIVATIVE COMPUTED BY MAXIMA as $$-\dfrac{\left(2x^2-2\right)\sin\left(2x\right)+4x\cos\left(2x\right)}{\left(x^2+1\right)\sin^2\left(2x\right)+4x\sin\left(2x\right)+\left(x^2+1\right)\cos^2\left(2x\right)+\left(2-2x^2\right)\cos\left(2x\right)+x^2+1}+C$$ and I pressed the simplify button to obtain $$-\dfrac{\left(x^2-1\right)\cos\left(x\right)\sin\left(x\right)+2x\cos^2\left(x\right)-x}{\left(x^2-1\right)\sin^2\left(x\right)+2x\cos\left(x\right)\sin\left(x\right)+1}+C$$ However the "MANUALLY" COMPUTED ANTIDERIVATIVE displayed the following $$\dfrac{\sin\left(x\right)-x\cos\left(x\right)}{x\sin\left(x\right)+\cos\left(x\right)}+C$$ Which was computed by the following method:
$$\int \frac{x^2}{(x\sin(x)+\cos(x))^2}dx= \int \Bigg(\frac{x\sin(x)}{x\sin(x)+cos(x)}-\frac{x\cos(x)(\sin(x)-x\cos(x))}{(x\sin(x)+\cos(x))^2}\Bigg) dx$$
Using integration by parts
$$ \int \frac{x\cos(x)(\sin(x)-x\cos(x))}{(x\sin(x)+\cos(x))^2} dx= \dfrac{\sin\left(x\right)-x\cos\left(x\right)}{x\sin\left(x\right)+\cos\left(x\right)}+ \int\frac{x\sin(x)}{x\sin(x)+cos(x)}dx$$
$$\Rightarrow \int \frac{x^2}{(x\sin(x)+\cos(x))^2}dx=\dfrac{\sin\left(x\right)-x\cos\left(x\right)}{x\sin\left(x\right)+\cos\left(x\right)}+ \int\frac{x\sin(x)}{x\sin(x)+cos(x)}dx-\int\frac{x\sin(x)}{x\sin(x)+cos(x)}dx=\dfrac{\sin\left(x\right)-x\cos\left(x\right)}{x\sin\left(x\right)+\cos\left(x\right)}+C $$
My question is: why do I get different results from computing the anti-derivative and the indefinite integral? I simplified the anti-derivative so shouldn't it be simplified to the indefinite integral above? Are these two equations equal? Are functions for anti-derivatives and indefinite integrals vastly different? Any help will be appreciated
 A: For example, because $$\begin{align*}&(x^2-1)\sin^2x+2x\sin{x}\cos{x}+1\\&=(x^2-1)\sin^2x+2x\sin{x}\cos{x}+\sin^2x+\cos^2x\\&=x^2\sin^2x+2x\sin{x}\cos{x}+\cos^2x\\&=(x\sin{x}+\cos{x})^2.\end{align*}$$
Now, what does happen in the numerator?
We have the following:
$$\begin{align*}&(x^2-1)\cos{x}\sin{x}+2x\cos^2x-x\\&=(x^2-1)\cos{x}\sin{x}+2x\cos^2x-x\sin^2x-x\cos^2x\\&=x\cos^2x+(x^2-1)\cos{x}\sin{x}-x\sin^2x\\&=(x\sin{x}+\cos{x})(x\cos{x}-\sin{x}).\end{align*}$$
I hope now it's clear.
A: Computing the Indefinite Integral
$$
\begin{align}
&\int\frac{x^2}{(x\sin(x)+\cos(x))^2}\,\mathrm{d}x\\
&=\int\frac{x^2}{(x\sin(x)+\cos(x))^2}\frac{\mathrm{d}(x\sin(x)+\cos(x))}{x\cos(x)}\tag1\\
&=-\int\frac{x}{\cos(x)}\,\mathrm{d}\frac1{x\sin(x)+\cos(x)}\tag2\\
&=-\frac{x}{\cos(x)}\frac1{x\sin(x)+\cos(x)}+\int\frac1{x\sin(x)+\cos(x)}\,\mathrm{d}\frac{x}{\cos(x)}\tag3\\
&=-\frac{x}{\cos(x)}\frac1{x\sin(x)+\cos(x)}+\int\frac1{x\sin(x)+\cos(x)}\frac{\cos(x)+x\sin(x)}{\cos^2(x)}\,\mathrm{d}x\tag4\\[1pt]
&=\tan(x)-\frac{x}{\cos(x)}\frac1{x\sin(x)+\cos(x)}+C\tag5\\[2pt]
&=\frac{\sin(x)-x\cos(x)}{x\sin(x)+\cos(x)}+C\tag6
\end{align}
$$
Explanation:
$(1)$: $\mathrm{d}(x\sin(x)+\cos(x))=x\cos(x)\,\mathrm{d}x$
$(2)$: $\frac1{u^2}\mathrm{d}u=-\mathrm{d}\frac1u$
$(3)$: integrate by parts
$(4)$: $\mathrm{d}\frac{x}{\cos(x)}=\frac{\cos(x)+x\sin(x)}{\cos^2(x)}\,\mathrm{d}x$
$(5)$: $\sec^2(x)=\frac{\mathrm{d}}{\mathrm{d}x}\tan(x)$
$(6)$: $\tan(x)=\frac{\sin(x)}{\cos(x)}$ and simplify

The Integrals are the Same
$$
\begin{align}
&-\frac{\left(x^2-1\right)\cos(x)\sin(x)+2x\cos^2(x)-x}{\left(x^2-1\right)\sin^2(x)+2x\cos(x)\sin(x)+1}+C\\
&=-\frac{(x\sin(x)+\cos(x))(x\cos(x)-\sin(x))}{(x\sin(x)+\cos(x))^2}+C\tag7\\
&=\frac{\sin(x)-x\cos(x)}{x\sin(x)+\cos(x)}+C\tag8
\end{align}
$$
Explanation:
$(7)$: multiply and use $\cos^2(x)-\sin^2(x)=2\cos^2(x)-1$
$(8)$: cancel common factors
