# IntegrateChangeVariables producing incorrect result

ClearAll[f];
f[x_]:=x^2;


Now let's set up the two identical integrals:

integrals={
IntegrateChangeVariables[Inactive[Integrate][f[x],{x,-a,0}],u,u==-x],
Inactive[Integrate][f[x],{x,-a,0}]
}


$$\left\{\int _0^a-u^2du,\int _{-a}^0x^2dx\right\}$$

But I was expecting:

$$\left\{\int _0^au^2du,\int _{-a}^0x^2dx\right\}$$

Now let's evaluate to get the result:

Activate@integrals


$$\left\{-\frac{a^3}{3},\frac{a^3}{3}\right\}$$

Am I using the IntegrateChangeVariables incorrectly or there is a bug here?

Yes, it is bug. The integral should be $$\int_{a}^{0}-u^{2}du$$ And not $$\int_{0}^{a}-u^{2}du$$

Proof:

Integrating $$\int_{-a}^{0}x^{2}dx$$ using change of variable $$u=-x$$. Hence $$\frac{du}{dx}=-1$$ or $$dx=-du$$. When $$x=-a$$ then $$u=a$$. When $$x=0$$ then $$u=0$$. And $$x^{2}$$ becomes $$u^{2}$$.

Hence the new integral becomes

\begin{align*} \int_{-a}^{0}x^{2}dx & =\int_{a}^{0}u^{2}\left( -du\right) \\ & =-\int_{a}^{0}u^{2}du\\ & =-\left[ \frac{u^{3}}{3}\right] _{a}^{0}\\ & =-\left( 0-\frac{a^{3}}{3}\right) \\ & =-\left( -\frac{a^{3}}{3}\right) \\ & =\frac{a^{3}}{3} \end{align*} And not $$-\frac{a^{3}}{3}$$ as Mathematica says.