How can we say two algebraic expressions are "equal" if one is undefined at certain points and the other isn't? I'm trying to understand why it is that we can say $\frac{x^2-1}{x-1} = \frac{(x-1)(x+1)}{(x-1)} = x+1$ but then have it also be the case that the two functions $f(x) = \frac{x^2-1}{x-1}$ and $g(x)=x+1$ are not equal, since $f$ is undefined when $x=1$.
That is, if it is true that $\frac{x^2-1}{x-1} = x+1$ then why can we not just simplify and say that $f(x)=x+1$ so that $f(1) = (1) + 1 = 2$ ?
 A: In function theory, we say that functions $f$ and $g$ are equal if and only if $f(x)=g(x)$ for all $x$ in the domain of $f$ and the domains of $f$ and $g$ are equal.
However, the Precalculus book I recently taught from (Precalculus from Glencoe McGraw Hill) defines an identity as an equality where for both sides the domains are equal except for finitely many values of $x$ and the sides are equal when both sides are defined.
So in the function sense, $\frac{x^2-1}{x-1}=x+1$ is not true, but in the Precalculus sense that is indeed an identity. The strict definition of "equality" depends on the context. This inconsistency is probably allowed so trigonometry identities can be allowed without bothering students at that stage with the details of domains.
A: Let $f(x) = \frac{x^2-1}{x-1}$.  The domain of $f(x)$ is $x \in \mathbb{R}-\{1\}$.
Actually, $$\frac{x^2 -1}{x-1} = x+1,$$ for all $x \neq 1$. 
Hence, $f(x) \neq x+1$, because $1$ is in the domain of $x+1$. 
A: A lot of these kinds of issues clear up if we go that extra step by making our assumptions clear. For example:

Consider $x \in \mathbb{R}$ such that $x \neq 1$. Then:
$$\frac{x^2-1}{x-1}=\frac{(x-1)(x+1)}{x-1}=x+1$$
Hence, the following functions are equal.
$$x \in (\mathbb{R}\setminus \{1\}) \mapsto \frac{x^2-1}{x-1} \in \mathbb{R} \qquad x \in (\mathbb{R}\setminus \{1\}) \mapsto x+1 \in \mathbb{R}$$

(Please comment if you do not know what this notation means.)
As you can no doubt see, this is a little messy. A sleek modern way to avoid this messiness is by working syntactically; we view rational expressions, not as functions, but as elements of $\mathbb{Q}(x)$, which consists of equivalence classes of formal expressions, and forms a field in its own right. See also, polynomial ring and field of fractions. If you've never seen these ideas before, the wikipedia articles probably won't make a lot of sense, so maybe try googling for some PDF's, or take a look on youtube. Keep at it till you "get" it! Try to understand the following terms, in this order:


*

*Commutative ring (with unity, although this is often left implicit)

*Field

*Polynomial ring and the notation $\mathbb{Q}[x]$

*Field of fractions and the notation $\mathbb{Q}(x)$.


By the way, the "solution" to this messiness mentioned in Rory Daulton's answer could perhaps be made to work, but as its given, it really doesn't. I quote:

However, the Precalculus book I recently taught from (Precalculus from
  Glencoe McGraw Hill) defines an identity as an equality where for both
  sides the domains are equal except for finitely many values of $x$ and
  the sides are equal when both sides are defined.

The problem is that, for example, $x=x$ is a true under this definition, but $xyy^{-1}=x$ is not, since the left-hand-side is ill-defined for infinitely many points $(x,y)$. Contrast this with what happens in $\mathbb{Q}(x,y)$, where both $x=x$ and $xyy^{-1}=x$ are genuinely true. Nonetheless, I think a variant on this idea could be made to work; please comment, dear reader, if you have any thoughts on the issue.
A: we have $$\frac{x^2-1}{x-1}=\frac{(x-1)(x+1)}{x-1}=x+1$$ if $x \ne 1$
