[Math] Does a injective function need every element of the domain to map onto some element of the codomain

discrete mathematicselementary-set-theoryfunctions

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?

Best Answer

$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.