When are we permitted to multiply or divide both sides of an equation by a variable? As it is said in the mathematics books (at least the one I have), we are not permitted to divide or multiply both sides of an equation by a variable, because it is possible to lose some answers. For example, in the following equation
$$x^2=x$$
if we divide both sides by $x$, we would have $x = 1$, but the original equation has two answers, $0$ and $1$, and we've lost $x = 0$ by dividing it by a variable.
But in the same book, in order to solve a rational equation, the author multiplies both sides of the equation by $x(x-2)$, solving the equation:
$$\begin{align*}
\frac {x+2}{x-2} - \frac1x &= \frac{2}{x(x-2)}\\\\
x(x-2)\frac {x+2}{x-2} - x(x-2)\frac 1x &= x(x-2)\frac{2}{x(x-2)}\\\\
x(x+2)-(x-2)&=2\\\\
x^2+x&=0\\\\
x(x+1)&=0\\\\
x&=0\\
x&=-1
\end{align*}$$
Can someone please explain when we are allowed to do this and when we are not? I got a bit confused!
 A: When dividing by any quantity,
or when canceling out two quantities in a ratio
(for example, canceling $x$ and $x$ to find that $\frac xx=1$),
you need to be aware of what assumptions you have to make so
that the division or canceling makes sense,
and remember that those assumptions apply to any results you get.
For example, with
$$x^2 = x,$$
$x \neq 0$ then you can divide by $x$.
One way to keep track of your assumptions is to work out different
"cases" of the solution:
Case $x = 0$: Then the equation becomes $0^2 = 0$, which is true,
so $x = 0$ is a solution.
Case $x \neq 0$: Then since $x \neq 0$, you can divide by $x$,
so $x^2 = x$ implies $x = 1$. This is consistent with the assumptions
(namely that $x\neq 0$), so $x = 1$ is a solution.
If you look at all possible cases (and here, since $x$ either is or isn't zero,
we have already covered all possible cases),
the complete solution set consists of all solutions you find in all those cases;
that is, for this problem the solution set is $x=\{0,1\}$
(in other words, $x=0$ or $x=1$).
Now consider the example from the book:
$$\frac {x+2}{x-2} - \frac1x = \frac{2}{x(x-2)}.$$
Two equal quantities multiplied by the same quantity
are two equal quantities (even if we multiply both by zero!),
so we know that
$$x(x-2)\frac {x+2}{x-2} - x(x-2)\frac 1x = x(x-2)\frac{2}{x(x-2)}.$$
The tricky part is what comes next. It looks like the multiplier $x-2$
on the right-hand side should cancel the divisor $x-2$,
that is, $\frac {x-2}{x-2} = 1.$ But this is true only if $x-2 \neq 0$;
if $x - 2 = 0$ then $\frac {x-2}{x-2} = \frac 00,$ which is undefined.
Similarly, we can only cancel $x$ and $x$ on the right-hand side if $x \neq 0$.
So again we have two cases:
Case $x - 2 = 0$ or $x = 0$: In this case, the term on the right-hand
side of the equation evaluates to $\frac 20$, which is undefined,
so there are no solutions in this case.
Case $x - 2 \neq 0$ and $x \neq 0$:
In this case we can cancel $x-2$ with $x-2$ and cancel $x$ with $x$,
so we have
$$\begin{eqnarray}
x(x+2) - (x-2) &=& 2.\\
x^2 + x &=& 0.\\
x(x+1) &=& 0.
\end{eqnarray}$$
Now, remembering that we are still working out the case where
$x - 2 \neq 0$ and $x \neq 0$, we can divide both sides by $x$:
$$\begin{eqnarray}
x+1 &=& 0. \\
x &=& -1.
\end{eqnarray}$$
So $x = -1$ is the only solution in this case.
(Alternatively, if we used $x(x+1)=0$ to conclude that "$x=0$ or $x+1=0$",
we would still be working under the assumption that $x\neq 0$,
and from those facts we could conclude simply that $x+1=0$.)
Since there were no solutions from the other case, 
$x = -1$ is altogether the only solution of the equation.
Note that this method did not identify $x=0$ as a solution.
That's because I do not accept that it is a solution:
if you set $x=0$ in $\frac {x+2}{x-2} - \frac1x = \frac{2}{x(x-2)},$
you get a term of $\frac 10$ on the left and you get $\frac 20$
on the right, and both of those are undefined.
I hope that (eventually) the book agrees with this.
A: You can multiply or divide both sides of an equation by a variable whenever you want, but you need to keep two things in mind after your algebraic manipulations:


*

*Did I introduce additional solutions that do not make any sense?

*Did I lose or miss some solutions by making some algebraic manipulations?


This Wiki link on extraneous and missing solutions may prove to be useful for you, but see if you can follow the example below to see where you can run into issues.

Problem: The following steps appear to give equivalent equations, which seem to prove that $1=0$. Try to find the error.
Proof.
\begin{array}{rcl}
x & = & 1\\[0.5em]
x^2 &= & x\\[0.5em]
x^2-x &= & 0\\[0.5em]
x(x-1) &= & 0\\[0.5em]
\frac{x(x-1)}{x-1}&= &\frac{0}{x-1}\\[0.5em]
x& =& 0\\[0.5em]
1&= & 0
\end{array}
Did you spot the flaw? Here it is:

 When we multiplied by $x$, we introduced $x=0$ as a solution. When we divided by $x-1$, we are really dividing by $0$, since $x=1\iff x-1=0$.

A: It's not so much that you are categorically not permitted to do such a thing, but that you must be aware of the consequences of doing it, such as losing or gaining a solution.
This happens in other fields, too.  In kinematics, there is the notion of equivalence, in the sense that two bodies may be considered equivalent if they respond to identically applied forces in the same way.  That does not necessarily mean that the objects are identical.  For the purposes of any particular problem, that may not matter.  But one should be aware of the consequences.
It's good to ask such questions, for there are cases where the inclusion of spurious solutions or the exclusion of valid ones is not as obvious as in the example you give, and people often lose track of them.
ETA: To answer your last question more directly, there isn't unfortunately any sure-fire recipe for detecting such situations.  But as you've discovered, cases where you multiply or divide by something that might be zero, or raise something to a power (especially an even one), or in general apply functions that are not nice continuous one-to-one, are situations where care must be taken.
A: When $c\ne0$, $a=b$ and $ac=bc$ are equivalent, that's about all you need to know.

Applications:


*

*$x^2=x$ is equivalent to $x=1$ when $x\ne0$. Obviously, $0^2=0$ so that $x=0$ is also a solution (and there are no others).

*$\dfrac {x+2}{x-2} - \dfrac1x = \dfrac{2}{x(x-2)}$ and $x(x+2) - (x-2)= 2$ are equivalent when $x(x-2)\ne0$. Then $x=0$ and $x=2$ are known not to be solutions, as the expressions are undefined for them. So if they appear later in the computation as possible roots, these must be discarded.
