What happens to a function when it is undefined? If I have the function
$$f(x) = {x^2 - 2 \over    x + \sqrt 2}$$ 
this is undefined for $x = -\sqrt 2$, am I correct? Since the denominator would be zero.
But the numerator is a difference of squares $x^2-2=(x - \sqrt 2)(x+\sqrt 2)$.
Now the second factor is equal to my denominator, so those cancel and I am left with $(x - \sqrt 2)$, and this is defined at $x=-\sqrt 2$, is it not? If I put $x = -\sqrt 2$, the result is simply $-\sqrt 2 - \sqrt 2=-2\sqrt 2$. What am I doing wrong here? 
 A: When you cancel a factor from the numerator with one in the denominator, you are saying that the ratio of the two is the same as the number one.  This is true unless the two factors you happen to be cancelling are both zero.  In this case the ratio is not one, it is undefined.  So technically the ratio you obtain is $x-\sqrt{2}$ if $x \ne -\sqrt{2}$.
A: It is important to realise what you are doing when we say that a common factor "cancels" from the numerator and denominator. We are actually dividing both the numerator and denominator by that common factor. As you have already pointed out: you can't divide by zero. 
It is true that
$$\frac{x^2-2}{x+\sqrt{2}} \equiv \frac{(x-\sqrt{2})(x+\sqrt{2})}{x+\sqrt{2}}$$
Neither the left hand side, nor the right hand side are defined when $x=-\sqrt{2}$. Both are indeterminate forms. However, if we assume that $x\neq -\sqrt{2}$ then we may divide both the numerator and the denominator by $x+\sqrt{2}$ to give
$$\frac{x^2-2}{x+\sqrt{2}} = \frac{(x-\sqrt{2})(x+\sqrt{2})}{x+\sqrt{2}} = x-\sqrt{2}$$
The next step to understand this is the idea of the limit. If we take the limit as $x$ tends to $-\sqrt{2}$, we assume that $x \neq-\sqrt{2}$, but that it gets closer and closer. Even though the original function is not defined when $x = -\sqrt{2}$, we can look what happens to its value as $x \to -\sqrt{2}$. In that case we have
$$\lim_{x \to -\sqrt{2}}\left(\frac{x^2-2}{x+\sqrt{2}}\right) = \lim_{x \to -\sqrt{2}}\left(\frac{(x-\sqrt{2})(x+\sqrt{2})}{x+\sqrt{2}}\right) = \lim_{x \to -\sqrt{2}}\left(x-\sqrt{2}\right) = -2\sqrt{2}$$
A: The first answer: functions are never undefined. It's kind of a loaded word: don't talk about something undefined, because, then what are we talking about? What is undefined is an expression in $x$'s and $y$'s that tell you about a function; an expression that doesn't know how to define a function everywhere.
So we need to talk about how to go from an expression like $\frac{xy^2}{3xy}$ to a function.
And the actual, honest answer is there's a couple ways to do that. Mathematics educators picked one, and that's the one you're learning, but congratulate yourself: you got confused exactly where they were brushing something under the rug. That actually makes you pretty sharp, it's like knowing what you don't know better than anyone else.
To be rigorous, since mathematicians like making everything rigorous:


*

*recall from a seemingly irrelevant chapter in your algebra textbook that a relation is a set of points $(x,y)$ where $x$ and $y$ are real numbers (they can be anything, and $x$ and $y$ don't even have to be the same kind of thing, but in high school algebra or calculus you probably mean real numbers). We say $\mathbb{R}^2$ to mean ordered pairs of real numbers. For instance, the set containing $(1,2)$ is a relation, and the set of all points $\{(x,y) \in \mathbb{R}^2: y = 2x\}$ is a relation (The colon may be read "where", "such that", "having", "with", etc. $\in$ means "in").

*A function is a relation where if $(x, y_0)$ and $(x, y_1)$ are two points in the relation (with the same $x$!), then $y_0 = y_1$. This is the vertical line test. So if you draw a graph, it's a relation since it specifies a set of points. It's a function if it satisfies the vertical line test.

*So now if we have a relation that happens to be a function, that relation will have a domain $D$ defined as the set $\{t: \exists(x,y) \in R$ where $x=t\}$. If you draw line segment from left to right on a graph, the domain will be all the values from the leftmost point to the rightmost point.

*Given a relation $R$ that is a function, and a point $x$ in its domain, we can write $R(x)$ to mean "the unique $y$ value in the relation with that $x$ value".


So this is all a bunch of mathematical garble, but it's really relevant to this. So my question is: What does a function like $f(x) = 2x$ have to do with the above explanation?
When you write $$f(x) = 2x$$
You are saying:


*

*there is a relation where each $y$ value is $x$. Or $\{(x,y): y = 2x\}$. The domain is then all of $\mathbb{R}$, since for every $x \in \mathbb{R}$, there is a point $y$ that puts $(x,y)$ smack in that relation.

*You're also saying that that relation is a function. But you believe that if $a = b$ then $2a = 2b$, so it's pretty obvious that it is.


Yes, that is a lot of mumbo jumbo for one short equation, but in math sometimes if you get confused you have to think about what is figuratively going on here.
If you write
$$f(x) = \pm \sqrt{x}$$
Then you have just defined a relation that is $not$ a function. $f(4) = \pm 2$, which we read as "or". Since $f(4)$ can give you one thing or the other thing, you're talking about a relation that fails the vertical line test, not a function.
Now for your example: what about something like $$f(x) = 1/x$$ This would mean $\{(x,y): y = 1/x\}$. If you have a $y$ where $y = 1/x$, in particular you may multiply each side by $x$ to determine that $xy = 1$. So $x$ is definitely $not$ zero, because $1 \neq 0$. That means the domain of this function does $not$ include 0.
Next up: $f(x) = x/x$. This is a little trickier, because there's actually two perfectly valid things you could do here, and the mathematics where you just cancel first is the mathematics of $\mathbb{R}[x]$, which many mathematicians find very interesting.
In your class we do something backwards:


*

*See an expression like $f(x)/g(x)$.

*Admit it's actually rude to write something down like $x/y$ on paper, without even talking when we plan to do that division, since $y$ might be zero. 

*Try to backpedal out of our offensiveness, and say you only meant that when $g(x) \neq 0$.

*Agree that is the function we are talking about.


So when you try to cancel in a function like $x/x$, Figure out the function you meant first, because that's the rule. I sort of hate this because I think it's confusing to talk about "defining" something then figuring out where it's "defined". That's why I'm encouraging you to think of starting with an expression (To be rigorous? A rational polynomial, $\in \mathbb{R}(x)$) and figuring out what function we have, by convention, decided that expression refers to.
I can think of at least four other options.


*

*Cancel everything first, then figure out the domain. This is what you are proposing. It is much more similar to what an algebraic geometer would do. It's perfectly valid mathematically. It's just a different convention than you use. I will tell you though: the reason this works is very deep and relies on the fact you can factor polynomials uniquely much like you can factor numbers like $70=2*5*7$ uniquely.

*The calculus perspective: do it the long way above, then replace any replaceable discontinuities. For deep reasons this is the same as (1).

*The projective geometry perspective: just admit that dividing by zero is totally reasonable, and it gives you $\infty$. ($\pm \infty$ are the same things of course, because the world lives on a sphere, to a projective geometer.)

*All of these methods yield a function. Why not just define the mostly equivalent relation $\{(x,y) : x*g(x) = f(x)\}$? In particular $f(x) = x/x$ would turn to $\{(x,y): xy=x\}$, where if $x = 0$, $y$ throws a party. (Exercise: graph this relation. See that it fails the vertical line test).


After studying algebra in college, I actually think worrying about the domain first is stupid. To me, the numerator and denominators are both polynomials and can be multiplied and divided as freely as numbers can. I would prefer to cancel then see where it makes sense to talk about a function. In other words I would like to do it your way. But it's wrong to argue about with your teacher which way to do it, and right to learn both ways and stick to the way you're taught while in the classroom or taking an AP exam. When you get to a graduate algebra course, be prepared to switch gears.
