TITLE: When are algebraic expressions equivalent?
QUESTION [16 upvotes]: This question arose when I was going to determine the domain for $f \circ f(x)$.
Let $f(x) = \dfrac{1-x}{1+x}$.
$f \circ f(x) = x, \quad$ But the domain is not $\mathbb{R}$ because $f(x)$ is undefined for $x = -1$.  
This made sense to me after some thinking, $f \circ f(x)$ is only equivalent to $x$ if $x \neq -1$, so really one needs to specify the domain.   
So far so good, but then I started questioning the way I usually simplify algebraic expressions and solve equations. If I were to solve the equation
$p_1(x) = q_1(x)$
I might start simplifying both expressions and come up with a simpler equation:
$p_1(x) = q_1(x) \iff p_2(x) = q_2(x) \iff ... \iff p_n(x) = q_n(x)$
and here any $q_k(x)\iff q_t(x)\quad$ right?
So I tried to come up with cases when I felt I probably would not bother with specifying domains before simplifying an expression, but probably would if the expression was used in an equation, as an example:  
$\dfrac{1}{x} + x - \dfrac{1}{x} = 0$
So usually I feel like I have always just regarded the left hand side as equivalent to $x$, if just asked to simplify the left hand side as an expression. But the equation makes me confused. Obviously $\dfrac{1}{x}$ is not defined when $x = 0$, but then again $\dfrac{1}{x}$ and $-\dfrac{1}{x}$ cancel eachother out, so does it really matter that they are not defined when $x = 0$?
I tried to consult wolframalpha, but if I plug in $x = x + \dfrac{1}{x} - \dfrac{1}{x}$, it evaluates to true and if I plug in $x + \dfrac{1}{x} - \dfrac{1}{x} = 0$ it doesn't give an answer, as it does if $0$ is substituted for any real number. 
So now I feel like I've failed to understand a very fundamental concept of mathematics, that is when algebraic expressions really can be seen as equivalent and if it matters if they are used in equations or not?

REPLY [7 votes]: It is important to be aware that Wolfram Alpha is a machine, not a source of ultimate truth. You can usually trust its calculations, but for concepts and understanding of what you're doing, you're better off trusting your own understanding. In the particular case of $x+\frac1x-\frac1x$, Wolfram Alpha makes the guess that you're probably not interested in what happens at the isolated points where the original expression is not defined, so it presents a simplified expression that is equivalent to the original one when the original expression is defined. That doesn't represent any deeper mathematical truth; it is just what the programmers felt would probably be most useful for most users.
It is a fact that the left-hand side of $x+\frac1x-\frac1x=x$ cannot be evaluated when $x=0$, and so the equation is not true when $x=0$. The question is then, should you care? Only you can decide whether it's worth caring about, based on what use you're going to make of the equation and the result. In many cases the "removable singularity" at $x=0$ is completely irrelevant to what you're actually doing, and it is then reasonable to forget about it as quickly as possible. In other cases, it may be a sign that things are going to be hinky around $x=0$ -- perhaps some effects that you thought you could neglect when you came up with $x+\frac1x-\frac1x$ are actually not negligible for small $x$, and you need to go back to the drawing board and do a more careful analysis. It all depends on where the expression $x+\frac1x-\frac1x$ comes from.
If you're in a classroom setting and have been given the expression $x+\frac1x-\frac1x$ without any context and asked to simplify it, it is usually the case that you will be expected to pretend to care about the trouble at $x=0$, in the absence of any particular reason not to care. But note that this is a highly artificial situation -- when you actually use what you've learned there will always be some context that you should keep in mind to determine whether the non-definedness at $x=0$ is a relevant fact for you or not.