# Is the piece-wise function with mapping $f: (\mathbb{Q^{+}_r} \cup \{0\}) \rightarrow \mathbb{Z^+}$ injective or surjective?

Let $f: (\mathbb{Q^{+}_r} \cup \{0\}) \rightarrow \mathbb{Z^+}$ by

$\begin{array}{cc}\Bigg \{&\begin{array}{cc} f(0)=1 \\ f(\frac{a}{b}) = a+b \end{array} \end{array}$

where $\mathbb{Q^{+}_r} = \big \{\frac{a}{b} \in \mathbb{Q} \big | a,b \in \mathbb{Z^+}, \frac{a}{b} \thinspace is \thinspace reduced \big \}$

Determine if f is surjective or injective.

Also, if all but one of the branches of a piece-wise defined function is injective, does that necessarily mean that the function is not injective, or does it mean that f is not injective under the certain condition?

• I am familiar with the terminology "a function that is defined piecewise" but not with "the piece of a function". Is this the restriction of fhe function to some subset of its domain? Have the "pieces" all the same codomain? Actually every partition of the domain induces a way to define a function piecewise. – drhab May 3 '15 at 15:24
• I edited the question to be more precise in what I'm asking. – Benedict Voltaire May 3 '15 at 15:56

From e.g. $\frac14\neq\frac23$ combined with: $$f\left(\frac14\right)=1+4=2+3=f\left(\frac23\right)$$ it follows immedeately that $f$ is not injective.
If it comes to surjectivity then the question is: can we find for every $n\in\mathbb Z_{>1}$ some coprime pair $a,b\in\mathbb Z^+$ with $a+b=n$?
Yes we can: take $a=1$ and $b=n-1$. So the $f$ in your example is surjective.
If a function $f:X\rightarrow Y$ is injective then every restriction of $f$ to a subset $A\subset X$ is injective. So conversely if you can find a subset $A$ such that $f\upharpoonleft A$ is not injective then $f$ is not injective.
If $f:A\cup B\rightarrow Y$ is defined piecewise then - as argued above - it can only be injective if $f\upharpoonleft A$ and $f\upharpoonleft B$ are injective. However injectivity of $f\upharpoonleft A$ and $f\upharpoonleft B$ does not guarantee that $f$ is injective. It can happen that $f(a)=f(b)$ for $a\in A$ and $b\in B$ with $a\neq b$.