<s>[INST] How is the integral calculator finding this $\int_{0}^{a}\frac{a^2-x^2}{(a^2+x^2)^2}dx$ while I get an undefined expression? My book's attempt:
$$\int_{0}^{a}\frac{a^2-x^2}{(a^2+x^2)^2}dx$$
Let us find the antiderivative first:
$$\int\frac{a^2-x^2}{(a^2+x^2)^2}dx$$
$$=\int\frac{x^2(\frac{a^2}{x^2}-1)}{(x(\frac{a^2}{x}+x))^2}dx\tag{1}$$
$$=\int\frac{x^2(\frac{a^2}{x^2}-1)}{x^2(\frac{a^2}{x}+x)^2}dx$$
$$=\int\frac{(\frac{a^2}{x^2}-1)}{(\frac{a^2}{x}+x)^2}dx\tag{2}$$
$$=-\int\frac{1}{(\frac{a^2}{x}+x)^2}d(\frac{a^2}{x}+x)$$
$$=\frac{1}{(\frac{a^2}{x}+x)}+C\tag{3}$$
$$=\frac{x}{a^2+x^2}+C\tag{4}$$

$$\left[\frac{1}{(\frac{a^2}{x}+x)}\right]_{0}^{a}=\text{undefined}$$
$$\left[\frac{x}{a^2+x^2}\right]_{0}^{a}=\frac{1}{2a}\tag{5}$$
$(5)$ gives the correct answer according to this integral-calculator.

Both $(3)$ and $(4)$ should be perfectly valid antiderivatives, as we have completed the integration process before $(3)$. However, I found that only $(4)$ is a usable antiderivative, and $(3)$ gives an undefined expression.
Question:

*

*Why do we get an undefined expression using $(3)$?

My hunch:
My book's attempt of finding the antiderivative is wrong in that my book did $\frac{0}{0}=1$ multiple times throughout its working (for example, in lines $(1)$ and $(2)$). We should expect $(3)$ not to work since the process was wrong. When going from $(3)$ to $(4)$, the book did $\frac{0}{0}=1$ again. I am surprised that the book somehow managed to land at the correct antiderivative for our domain given that the process was wrong, and going from $(3)$ to $(4)$ is wrong as well.
 [/INST] You could say:
$$\left[\cfrac{1}{\left(\frac{a^2}{x}+x\right)}\right]_0^a=\frac{1}{a+a}-\lim_{x\to0^+}\frac{1}{\frac{a^2}{x}+x}=\frac1{2a}$$
so you get the same result either way. We can make this assumption since the domain of the integral is $[0,a]$ and so we know that $0$ is approached from above.
</s>