A common Calculus exercise I keep running upon is a variation of the following:
When $f(x) = \frac{p(x)}{q(x)}$, define $f(x_0)$ such as that $f$ is continuous at $x_0$.
Usually, $x_0$ is a common zero of both $p$ and $q$, so the question is asking the reader to factor out that common root and proceed by taking the limit of the now defined, continuous quotient. Then, for $f$ to be continuous at $x_0$, it's value must agree with the limit. My question is, before factoring out the common zero, was $f$ really undefined? If a function is a relation between sets, and we exchanged it's formula by an equivalent one, how comes this relation is changed? What exactly means to give a function by a formula?
I try to make sense of it this way: let $K$ be a field, and $K[X]$ it's polynomial ring. Then, a polinomial function $p(x)$ can be identified with an element in $K[X]$ that is simply evaluated at the morphism $X \mapsto x$. But rational functions, functions given by a formula which is a quotient of polynomials, must be identified with an element in the field of fractions of $K[X]$. But this field is a quotient set, and any proper morphism from it needs to be properly defined. One way to do so is to take the irreducible representation of each fraction. Then, we get rid of the common zero problem, and our function $f$ was never undefined at $x_0$ in the first place, as it's value is given by the irreducible version of the formula. Given that Calculus textbooks neglect this, how is this usually handled in the mainstream?
EDIT: While I understand and appreciate the comments so far on the topic, I think I haven't made the point of the question clear enough. I comprehend that a function is not only compromised by the relation itself, but also by the domain. Thus, if I take a real function given by a formula such as $f(x) = \frac{1}{x}$, then this function is characterized by the subset $f \subset \mathbb{R}\times\mathbb{R}$ defined by $f = \{(x, \frac{1}{x}) \mid x \neq 0\}$. Somewhat formally, a function defined by $g(x) = \frac{x+1}{x(x+1)}$ will be then different from $f$ because it's domain would explicitly exclude $-1$, but it's unique continuous extension will coincide with $f$.
This definition seems ok intuitively, but when I try to make it more rigorous is where I ran into the "problems" I described. First, it's necessary to define properly what a "formula" is, as a mathematical object. It's redundant to say that a formula is an expression, because "expression" would then need to be properly defined as a mathematical object and constructed. The very fact that the difference between $\frac{1}{x}$ and $\frac{x+1}{x(x+1)}$ is subtle shows that the concept of a "formula" deserves a proper, rigorous definition. Then, once defined what a formula $f^*(x)$ is (denoted with a $*$ to separate it from the function itself), we need to define what is it's "domain" $D(f^*)$, the set of points where it applies. Then, in the reals for example, the function will be the subset of $D(f^*)\times \mathbb{R}$ given by $f = \{(x, f^*(x))\}$.
In the paragraph before this edit, I argued in favor of a definition of "formula", at least for rational functions, in which $f^*$ and $g^*$ given as above wouldn't be different formulas, and would define the same function over the base field. Points in which I think it deserves credit are that it works over any base field, not only $\mathbb{R}$, and for transcendental formulas, it can be easily generalized to the algebraic set of power series over $K$, given that $K$ is a topological field and convergence questions are properly addressed. I understand that such approach must not be canon, given the usual terminology in textbooks and the comments on this topic so far - what I ask is, if this is not the usual definition of "formula", what is it then?
I'm inclined to think that, in the mainstream, a formula is simply a fraction in the congruence class of the fraction field of $K[X]$. Then, even equivalent fractions in the usual sense could wield different functions, so $f$ and $g$ above would be different. But this goes against the usual modus operandi in mathematics, where we normally take proper care in checking that a function from a quotient set is properly defined and doesn't depend on representatives, when this can be done, as it usually simplifies a problem. Why would we go against that current?
Let us examine the - interesting - questions you pose as follows:
Let us now, at first, rememeber the definition of a function between two sets $A$ and $B$:
So, let us now see two simple functions $f\subseteq\mathbb{R}\setminus\{1\}\times\mathbb{R}$ and $g\subseteq\mathbb{R}\times\mathbb{R}$, as follows: $$f=\{(x,x+1):x\in\mathbb{R}\setminus\{1\}\}$$ $$g=\{(x,x+1):x\in\mathbb{R}\}$$ So, $f$ consists of all the arranged pairs of the form $(x,x+1)$ except for the pair $(1,2)$ and $g$ consists of all the arranged pairs of the form $(x,x+1)$ - with no exceptions. Then, it is clear that, by definition, $f\neq g$ and, more precisely, $f\underset{\neq}{\subset} g$.
So, we could easily say that $$g(x)=x+1$$ But, what about $f$?
Well, we can write, "inspired" by its set definition: $$f(x)=x+1,\ x\neq1$$ But, since $x\neq1$ we directly see that $x-1\neq0$ so we can divide by $x-1$, with no fear. Actually, we can divide by $(x-1)^n$ for every $n=1,2,\dots$, and we can get, for $x\neq1$: $$f(x)=x+1=\frac{(x-1)^n(x+1)}{(x-1)^n}$$ for every $n=1,2,\dots$. So, if we set: $$f_n(x)=\frac{(x-1)^n(x+1)}{(x-1)^n}$$ we can easily see that $f_n\equiv f$, for every $n=1,2,\dots$
By the above example, it is made clear that $\displaystyle f(x)=\frac{x^2-1}{x-1}$ and $g(x)=x+1$ are not only different with respect to their formulas, but also with respect to their domain. It has to be made clear that a function is defined by both its formula and its domain. So, $f$ and $g$ are two different relations between two different sets! (actually, $f$ is a restriction of $g$ over $\mathbb{R}\setminus\{1\}$).
With respect to your last question, defining a function only by its formula means that we, of course give the general formula of $f(x)$, as well as the restrictions over the domain implied by the formula, in order to be well defined.
For instance, $f(x)=2\ln(x)$ and $g(x)=\ln(x^2)$ are two entirely different functions, since $f$ is defined over $(0,+\infty)$ but $g$ is defined over $(-\infty,0)\cup(0,+\infty)$. However, we can see that $$f(x)=2\ln x=\ln(x^2)=g(x)\mbox{, for }x>0$$ In terms of our set definition: $$f=\{(x,\ln(x^2)):x>0\}$$ and $$g=\{(x,\ln(x^2)):x\neq0\}$$ So, it is again clear that $f\neq g$.
Lastly, it is clear that we cannot identify the functions $\displaystyle f_n=\frac{(x-1)^n(x+1)}{(x-1)^n}$ and $g(x)=x+1$ for any $n=1,2,\dots$, since they have different domains. We can, however, identify $f_n$ with $f_m$ for every $n,m=1,2,\dots$.
Note: By all this discussion, I feel that the most important thing to remain, is that the domain of a function is part of its definition (it is exactly the set $A$, of the definition, as it is given in the beginning of this answer).
Hope this helped! :)