Why does this $u$-substitution zero out my integral? Here's how I understand $u$-substitution working for an integral. Essentially, it involves substitution of differential expressions, allowing you to cancel out terms of the integrand.
When we change the limits of integration, we essentially evaluate $u(x)$ to make sure the value stays the same.
$$
\begin{gather*}
\int_{x=0}^{x=2} \frac{x}{\sqrt{1 + x^2}} \, dx \\
\text{let $u = 1 + x^2$ so $du = 2x \, dx$ and $dx = \frac{1}{2} du / x$} \\
\int_{u=1}^{u=5} \frac{\color{red}{x}}{\sqrt{u}} \, \left( \frac{1}{2\color{red}{x}} du \right) \\
\frac{1}{2} \int_{u=1}^{u=5} u^{-1/2} \, du \\
\frac{1}{2} \left( \left. 2\sqrt{u} \  \right|_{u=1}^{u=5} \right) \\
\sqrt{5} - 1.
\end{gather*}
$$
That's all well and good. But I can choose anything for my $u$-expression. What if I wanted to let $u = (x)(x - 2)$? Then the limits of integration are $$\int_{u=(0)(0-2)}^{u=(2)(2-2)} \implies \int_{u=0}^{u=0}$$
and so the whole integral becomes zero.
Clearly this is invalid. The correct result for the integral is indeed $\sqrt{5} - 1$. But what am I missing here? Why can't I set the integral up like this?
My thoughts:


*

*This is a definite integral, so there's no "$+ C$" constant of integration business going on. (Right?)

*Even if you end up having some $x$s in your expression because the $u$-substitution doesn't cancel them out, that doesn't matter because you're still integrating over an empty domain. (Right?) Plus, I can also get this to "work" with $\int_{y=-r}^{y=r} (r^2-y^2)^{-1/2}y^2\,dy$ with $u = r^2-y^2$, and that can be expressed as $\int_{u=0}^{u=0} u^{-1/2}\sqrt{r^2-u} \, du$, which is completely in terms of $u$. (I think?)

*Does it have something to do with the multiple solutions of quadratic equations?

*How do I know when I'm doing this by mistake? It seems like it could be pretty subtle.

 A: You certainly have the right to make any change of variable you want.  The problem with using $u=x(x-2)$ is that you have to solve for $x$ as a function of $u$:
$$u=x^2-2 x \implies x = 1 \pm \sqrt{1+u} \implies dx = \pm \frac{du}{2 \sqrt{1+u}} $$
Because $u(x)$ is a quadratic, $x(u)$ is multivalued with two branches.  (This is why you were able to get zero in the lower and upper limits.)  You would sub differently along each branch.  Thus,
$$\int_0^2 dx \frac{x}{\sqrt{1+x^2}}  = \frac12 \int_0^{-1} du \frac{1-(1+u)^{-1/2}}{\sqrt{3+u-2 \sqrt{1+u}}} + \frac12 \int_{-1}^0 \frac{1+(1+u)^{-1/2}}{\sqrt{3+u+2 \sqrt{1+u}}}$$
..and take it from there.
A: The wrong output is due to the illegitimate choice of change of variable function $\phi(x)=x(x-2)$. There are different formulations of the substitution formula for integration, but usually injectivity of $\phi$ is a requirement.
Challenge Change the lower bound of integration from $0$ to $-1$. Now the function $\phi(x)=x^2+1$ is no longer injective over this interval. The challenge question is whether you can still use the substitution $u=x^2+1$ to find the right answer.
