Does a injective function need every element of the domain to map onto some element of the codomain? My question is, is it necessary for every element of the domain to map onto some element of the range for a function to be injective? For example, is
$$f(x) = x,\ f:\Bbb R \to \Bbb Z$$
one-to-one/injective, even though there are many elements of the reals that cannot map onto the integers? Obviously for every element that can map onto $\Bbb Z$, it is the only element that corresponds to its output, but I guess I'm wondering if this "overflow" of elements in $\Bbb R$ that don't map onto $\Bbb Z$ matter.
Another example, which is the reason I wanted to know the answer to this question:
$$f(x)= 1/x,\ f:\Bbb R \to \Bbb R \setminus \{0\}$$
So obviously, every element of the domain points to only $1$ element of the range in this function, but does it matter that when $x=0$ the function is undefined? Or does that not effect whether the function is one-to-one or not?
 A: This has nothing to do with being one-to-one but is rather the definition of a function from a domain to a codomain (but of course, to be a one-to-one function, you first have to be a function at all).  If $f$ is a function from $A$ to $B$, that means that for each $a\in A$, $f(a)$ is defined and is an element of $B$.  So $f(x)=x$ is not a function from $\mathbb{R}$ to $\mathbb{Z}$, since $f(x)\not\in\mathbb{Z}$ for some values of $x$.  And $f(x)=1/x$ is not a function from $\mathbb{R}$ to $\mathbb{R}\setminus\{0\}$, since $f(0)$ is not defined.
A: $f(x) = x$ where $f : \Bbb R \to \Bbb Z$ is not a function.
A function $f : A \to B$ is a set of ordered pairs $(a,b)$ with $a \in A$ and $b \in B$ such that for every $a \in A$ there is exactly one $b \in B$ that pairs with that $a$, that is $f(a)$ exists and $f(a) = b$. In set builder form,
$$f = \{(a,b) : a \in A,\ f(a) = b \in B\}$$
Injectivity requires the reverse, that each $b$ only pairs with one $a$.
Now, for your proposed $f$, you have a bunch of $a \in \Bbb R$ that don't get mapped anywhere. What would that look like as an ordered pair? $(a,)$? This doesn't make sense. Every element of your domain must get mapped somewhere or else it isn't a function.
A: No, it is not necessary every element of the domain to map onto some element in the codomain. A function that does not map all elements of its domain is called partial.
The function from you first example ($f(x)=x, f:\mathbb{R}\to\mathbb{Z}$) is partial and bijective. It is partial because there are arguments for which it is undefined ($f(1.5)$ is undefined). It is surjective because for every element $y$ in $\mathbb{Z}$ there is at least one element $x$ in $\mathbb{R}$ such that $f(x)=y$ as $\mathbb{Z}\subsetneq\mathbb{R}$. It is injective because every distinct element in $\mathbb{R}$ is mapped to a distinct element in $\mathbb{Z}$. It is bijective because it is both injective and surjective.
Similarly, the function from your second example ($f(x)=1/x, f:\mathbb{R}\to\mathbb{R}\setminus\{0\}$) is partial ($f(0)$ is undefined) and bijective.
In addition, function $f(x)=1/x, f:\mathbb{R}\setminus\{0\}\to\mathbb{R}\setminus\{0\}$ is total and bijective, while function $f(x)=1/x, f:\mathbb{R}\to\mathbb{R}$ is partial ($f(0)$ is undefined) and non-surjective (there is no $x$ such that $f(x)=0$).
