Let $f$ be a function with domain $A$ and codomain $B$.
It seems that there are two formal definitions of a function:
- As a set of ordered pairs: $f=S\subseteq A\times B$
- As an ordered triple: $f=(A,B,S)$.
Consider these two functions:
- $f:\mathbb \{0\} \rightarrow \mathbb R$ defined by $f(x)=1$
- $g:\mathbb \{0\} \rightarrow \mathbb R^+_0$ defined by $g(x)=1$
Under Definition 1, $f=g=\{(0,1)\}$.
But under Definition 2, $f \neq g$ because $f=(\{0\},\mathbb R,\{(0,1)\})$, while $g=(\{0\},\mathbb R^+_0,\{(0,1)\})$.
So, which is the "correct" definition that we should use?
You are misinterpreting your first definition. The function is not $S $, but $S $ as a subset of $A\times B $. And your $f $ and $g $ have different $B$.
The codomain is part of the definition of function. Functions with the same domain and "rule" (i,e., same formula or same $S $) but distinct codomains are not equal.