TITLE: Functions with different codomain the same according to my book?
QUESTION [14 upvotes]: My book gives the following definition:

A function $f$ from $A$ to $B$ is defined as $f\subseteq A\times B$ such that if $(a,b)\in f$ and $(a,b_1)\in f$ then $b=b_1$ and there exists a $(a,b)\in f$ for each $a \in A$ .

Now according to this definition, the function would be the same even if the codomains are different. Is it true?

REPLY [3 votes]: This really depends on how you formally define "the same".  In mathematics, this is done by specifying an equivalence relation giving rise to equivalence classes of functions.  It is possible to specify an equivalence relation between functions that requires them to have the same codomain in order to be considered "the same" (i.e., functions with different codomain are not the same), and it is possible to specify an equivalence relation  that ignores the codomain (i.e., functions can be the same even if they have different codomains).
Formally, functions with specified codomains are triples $(\mathcal{X}, \mathcal{Y}, \mathscr{G})$ containing a domain $\mathcal{X}$, a codomain $\mathcal{Y}$, and a graph $\mathscr{G} \equiv \{ (x,f(x)) | x \in \mathcal{X} \}$.  You can define the equivalence relations $\sim$ and $\overset{*}{\sim}$ respectively by:
$$\begin{matrix}
f_0 \sim f_1 & & \iff & & (\mathcal{X}_0, \mathcal{Y}_0, \mathscr{G}_0) = (\mathcal{X}_1, \mathcal{Y}_1, \mathscr{G}_1), \\[6pt]
f_0 \overset{*}{\sim} f_1 & & \iff & & (\mathcal{X}_0, \mathscr{G}_0) = (\mathcal{X}_1, \mathscr{G}_1). \\[6pt]
\end{matrix}$$
The first equivalence relation requires equivalence of the codomains of the two functions, whereas the second does not.  Both give a well-defined notion of when two functions are "the same".
So, the real question here is, which of these two equivalence relations is more useful?  Well, it turns out that the codomain isn't really important for most properties of functions.  Indeed, the "meat" of a function is given by the graph $\mathscr{G}$ that shows all pairs of values (i.e., all the combinations of a value in the domain and the value it maps to).  (However, for some cases where the codomain is important, see here.)  Consequently, we tend to adopt the convention that two functions are considered "the same" if they have the same domain and graph, but we do not require the same codomain.  This means that we adopt the above equivalence relation $\sim$ as specifying when two functions are "the same".