# Proving $f(x)=|x|$ is onto

I've been working on proving that this is a onto function:

$$f$$ : $$\mathbb R$$ $$\to$$ $$\mathbb R^{\geq0}$$ is defined by $$f(x)=|x|$$

My proof so far: Let $$y\in\mathbb R$$.

Rough work: $$|x|=y \Rightarrow \sqrt {x^2}=y \Rightarrow n^2=y^2 \Rightarrow \pm x=\pm y$$

Suppose $$f(\pm y)=|\pm y|=y$$.

I know that this function is definitely onto given the co-domain of $$\mathbb R^{\geq0}$$, but I feel like my proof is flawed. Am I supposed to individually account for the $$-x$$ and the $$+x$$ from $$\pm x=\pm y$$ when trying to solve $$f(x) = y$$?

Thanks!

• Let $a\in \mathbb R ^{\geq 0}$. Then by definition, $|a|=a$. Therefore, $a$ is in the image of $f:x\mapsto |x|$. – Arrow Mar 24 at 15:23
• You proof is wrong from the beginning. You need to assume y is in the nonnegative reals and show you can find a real x that maps to it. – symplectomorphic Mar 24 at 15:24

In order to show that the function is onto (surjective) it is enough to argue that for each $$y$$ in the codomain there is at least one $$x$$ in the domain that maps to it.

You seem to be trying to find all of the $$x$$ such that $$f(x)=y$$, which is more work than you need to do and creates a rather large detour.

You could just say:

Let $$y\in\mathbb R^{\ge 0}$$ be given. Then $$f(y)=|y|=y$$, so by setting $$x=y$$ we find an $$x\in\mathbb R$$ such that $$f(x)=y$$. Since $$y$$ was arbitrary this proves that $$f$$ is surjective.

(Even this is more verbose than it really needs to be, but in exercises at this elementary level it is good to be explicit about the details, to show that you know what you're doing).

• (+1) Because this is a vey pedagogical answer. – José Carlos Santos Mar 24 at 15:33

Am I supposed to individually account for the -x and the +x from ±x=±y when trying to solve f(x)=y?

No.

You are simply supposed to show that for any general arbitrary $$y \in \mathbb R^{\ge 0}$$ that there is, at least (you don't have to find them all), one $$x\in \mathbb R$$ so that $$|x| = y$$.

As $$|y| = y$$ this is very easy. And you are done.

The proof is two lines:

1) Let $$y \in \mathbb R^{\ge 0}$$.

2) $$f(y) = |y| = y$$.

You should not start with $$y\in\mathbb R$$ but rather with $$y\in\mathbb{R}^{\geqslant0}$$. Then $$y=f(y)$$. Since this happens for every $$y\in\mathbb{R}^{\geqslant 0}$$, $$f$$ is onto.

Well, you want to show that $$f$$ is onto. So take an arbitrary element $$y\in{\Bbb R}_{\geq 0}$$ from the image set and find a preimage. Here a preimage is $$y$$ itself or even $$-y$$, since $$|-y|=y$$.

More generally, If $$B \subseteq A$$ and $$f: A \rightarrow B$$ is a continuous mapping with $$f(b) = b$$ for all $$b \in B$$ then $$f$$ is called a retraction of $$A$$ onto $$B$$. It is trivial that any such $$f$$ is onto since $$f(b) = b$$ for all $$b \in B$$ immediately implies that all such $$b$$ are in the range. Note that continuity really plays no role in this. Thinking of $$|x|$$ as a retraction is perhaps overkill, but shows that the proof that it is onto the nonnegative reals is a special case of a more general (and equally easy to prove) result.