# For a non-surjective function, $f : \Bbb{R} \to \Bbb{R}^+$ is better than $f : \Bbb{R} \to \Bbb{R}$?

Example: From this we can tell no negative real number can be the image of any element of the domain. Thus not surjective because the range is not equal to the codomain, which means the function associates a any real number to a positive real number only. Is it better to write it this way $$f : \Bbb{R} \to \Bbb{R}^+$$ then?

• The choice of codomain is often somewhat arbitrary. As I see it, a key point of the concept is simply to fix a context without necessarily identifying the range a function. It can be difficult to identify the range of a function (e.g. for a something like an even-degree polynomial $\mathbb{R} \to \mathbb{R}$ it can be clear that it maps real numbers to real numbers but can be difficult, and perhaps pointless for some purposes, to identify its minimal or maximum value, which you are kind of doing in your example but might not be able to do absolutely every time you want to define a function). Feb 21, 2021 at 4:37
• Consider for example if you'd want to use the quadratic formula absolutely every time you decide to consider a quadratic polynomial as a function. These polynomials are never going to map $\mathbb{R}$ surjectively onto $\mathbb{R}$. You certainly could adjust their codomains so that they are surjective, but why would you always want to? Feb 21, 2021 at 4:45
• In fact, we can easily define functions with co-domain $\{0,1\}$, but where the range is yet unknown! Feb 21, 2021 at 4:45
• $0$ is not a member of $\Bbb R^+$ but $f(0)=0$. Feb 21, 2021 at 4:56
• @DanielWainfleet Different conventions whether $\mathbb{R}^+$ means positive reals or nonnegative reals. Feb 21, 2021 at 5:08

It depends on the context, but you're right that writing $$f : \Bbb{R} \to \Bbb{R}^+$$ contains superior information about the rule $$x \mapsto |x|$$. There are a few reasons why you might choose to write a more general codomain than what is called for, for example:
• Sometimes a definition will tie you to a codomain. For example, the definition of function composition takes a function $$f : A \to B$$ and $$g : B \to C$$ and produces a function $$g \circ f : A \to C$$, defined by $$(g \circ f)(x) := g(f(x))$$. Now, if we take, for example, $$g : \Bbb{R} \to \Bbb{R} : x \mapsto x^3 - x$$, then we can only really compose with $$f$$ it is has codomain $$\Bbb{R}$$, to match the domain of $$g$$. Of course, it's a simple thing to do to extend a codomain (or even limit the domain of $$g$$ to $$\Bbb{R}^+$$), but one or the other should be done in order to make the composition kosher.
• Sometimes the codomain is easy, but the range is unknown. As per Hagen von Eitzen's suggestion, we can take any object conjectured to exist (but whose existence is unknown) and turn it into a function to $$\{0, 1\}$$ with unknown range. For example: $$f : \Bbb{N} \to \{0, 1\} : n \mapsto \begin{cases} 1 & \text{if n is an odd perfect number} \\ 0 & \text{otherwise.} \end{cases}$$ Nobody knows the range of this function, but we do know the codomain is $$\{0, 1\}$$.
If you use the Bourbaki definition (i.e., $$f\colon A\to B$$ is $$\{(a,f(a))\mid a\in A\}\subseteq A\times B$$ and the Kuratowski ordered pair $$(a,b)=\{\{a\},\{a,b\}\}$$), then the codomain $$B$$ cannot be recovered from $$f$$.
On the other hand, if you build the codomain into the function as in source-target predicate, then you get the absolute value $$\mathbb{R}\to\mathbb{R}$$ and $$\mathbb{R}\to\mathbb{R}^+$$ are two different functions (which are related by the inclusion $$\mathbb{R}^+\to\mathbb{R}$$), which may or may not be what you want.