# 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?

• For an injective function, each element of the codomain must have at most 1 preimage in the domain. Commented Oct 12, 2016 at 6:27
• The condition you ask about is part of the definition of being a function in the first place. Commented Oct 12, 2016 at 7:07
• There does not seem to be a consensus in the answers below. By definition does a function map each element in the domain to the co-domain, or can a function partially map the elements in the domain? Maybe it depends on the context. The title should be changed to "Does a function need every element of the domain to map onto some element of the codomain?", since this question applies to all functions, not just injective functions.
– john
Commented Nov 19, 2019 at 20:49

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

• The answer above you disagrees. See partial function .
– john
Commented Nov 19, 2019 at 3:34
• @john The OP asked about functions, not partial functions. It's fine to mention partial functions, but functions are a struct subset of partial function and not the other way around. Commented Nov 24, 2019 at 1:37

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.

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

• I'd advise being more careful about how you phrase this. A "function" that does not map all elements of its domain is not a function but a more general object called a "partial function". In other words, a partial function is not a special type of function but, rather, the opposite is true; a function is a special type of partial function, sometimes called a "total function" in that context. Commented Nov 24, 2019 at 1:44