What is the right way to define a function?

Most authors define functions this way:

Given the sets $A$ and $B$. A relation is a subset of $A\times B$. Then given a relation $R$, we define $Dom_R=\{x|(x,y)\in R\}$ and $Img_R=\{x|(y,x)\in R\}$.

Then a function from $A$ to $B$, $f:A\rightarrow B$, is a relation with the property that each element of the domain is related to exactly one element of the image, such that $Dom_f=A$ and $Img_f\subseteq B$.

Well, if we accept those definitions, functions are just special sets of ordered pairs (remember, functions are relations and, as far as I know, this is emphasized in most books). Specifying the set of inputs and the set of outputs is just necessary when describing functions using the axiom of replacement of ZFC, but what really dictates which set is which is its elements. Thus, for example, the function \begin{align}f:\{0,1\}&\rightarrow \mathbb{R}\\0&\mapsto2\\1&\mapsto 3\end{align} and the function \begin{align}g:\{0,1\}&\rightarrow \{2,3\}\\0&\mapsto2\\1&\mapsto 3\end{align} are the same, since both are the set $\{(0,2),(1,3)\}$. The thing is that $g$ is considered a surjection while $f$ is not. And this is really a problem.

Furthermore, the concept of a graph of a function $Gr(f)$, which is the set $\{(x,f(x))|x\in Dom_f\}$, loses its sense, since the graph would be the function itself.

Wouldn't be much better to define the function as an ordered triple $(A,B,f)$, where $A$ is the domain, $B$ the codomain and $f$ the relation with the properties described above? It's different, since $f$ itself would not be a function, but only the ordered triple would. Then we could define $Gr((A,B,f)):=f$. In this case, the graph of the function would be a relation instead of the function. Also, the notation $f:A\rightarrow B$ could still be used to describe $(A,B,f)$.

To force the function to be a relation, we would have to define relation the same way: the relation would also be an ordered triple $(A,B,R)$, where $R \subseteq A\times B$. But in this case, the relation is not a set of ordered pairs, but the 'graph of the relation' is.

The third and last option is to define both relation and function as a set of ordered pairs, as usually. But although injectivity is a property of a function, surjectivity would rather be a relation between a function $f$ and another given set $B$ called codomain.

Am I getting it right? If so, what is the best way to define a function? Define a function not as a relation but a triple or define a relation not as a set of ordered pairs but a triple? Or another option?


One way to proceed is the following, starting from the concept of ordered couple, defined set-theoretically in the usual way.

We define when a set is a relation :

$R \text { is a relation } \ ↔ ∀z(z \in R → ∃x \ ∃y \ (z = \langle x,y \rangle \ ))$.

Thus, a relation is a set of ordered couples.

As usual, we write $xRy$ for $\langle x,y \rangle \in R$.

We define :

$\mathcal {Dom}_R = \{ x : \exists y \ (x R y) \}$

and :

$\mathcal {Img}_R = \{ y : \exists x \ (x R y) \}$.

Then we define when a relation is a function :

$f \text { is a function } ↔ f \text { is a relation } \land ∀x \ ∀y \ ∀z \ (xfy ∧ xfz → y=z)$.

Up to now, no "$A$s" nor "$B$s".

Then we say :

$f \text { is a function from } A \text { into } B \leftrightarrow f \text { is a function } \land \mathcal {Dom}_f=A \land \mathcal {Img}_f \subseteq B$;

$f \text { is a function from } A \text { onto } B \leftrightarrow f \text { is a function } \land \mathcal {Dom}_f=A \land \mathcal {Img}_f = B$.


See : Patrick Suppes, Axiomatic set theory (1960), page 88.

See also : Kenneth Kunen, The Foundations of Mathematics (2009), page 24-25.


Regarding your example, with this approach we have that $f=g$, where $f$ is a function from $\{ 0,1 \}$ into $\mathbb R$, while $g$ is a function from $\{ 0,1 \}$ onto $\{ 2,3 \}$.

In this case, surjectivity is not an "intrinsic" property of $g$; the applicability of the word "onto" depends both on $g$ and on the set $B$, not just on $g$.


A different approach is possible, of course; see :

  • Robert Goldblatt, Topoi : The Categorial Analysis of Logic (2ed - 1984) , page 19 :

modify the definition of function in the following way. Firstly for sets $A$ and $B$ we define the product set or Cartesian product of $A$ and $B$ to be the set of all ordered pairs whose first elements are in $A$ and second elements in $B$. This is denoted $A \times B$, and so

$$A \times B = \{ \langle x, y \rangle : x \in A \land y \in B \}.$$

A function is now defined as a triple $f = \langle A, B, R \rangle$, where $R \subseteq A \times B$ is a relation from $A$ to $B$ (the graph of $f$), such that for each $x \in A$ there is one and only one $y \in B$ for which $\langle x, y \rangle \in R$. Thus the domain ($A$) and codomain ($B$) are incorporated in the definition of a function from the outset.


With this approach, the two "objects $\langle \{ 0,1 \}, \mathbb R, f \rangle$ and $\langle \{ 0,1 \}, \{ 2,3 \}, f \rangle$ are not the "same" function.

In this second case, surjectivity is an "intrinsic" property of $\langle \{ 0,1 \}, \{ 2,3 \}, f \rangle$.