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$ ?

we have $$\frac{x^2-1}{x-1}=\frac{(x-1)(x+1)}{x-1}=x+1$$ if $x \ne 1$
