# surjectivity of a piece-wise function defined as follows

Define a function $$f:\Bbb Z \to \Bbb Z$$ by $$\begin{equation*} f(x) = \begin{cases} x, & \text{if x is even}\\ x+1, & \text{if x is odd} \end{cases} \end{equation*}$$ for all $$x \in \Bbb Z$$. Find a right inverse of $$f$$ if it exists.

Attempt: $$f$$ has a right inverse iff $$f$$ is surjective, so we must check that $$f$$ is whether surjective or not. Let $$y=f(x)$$. Then, $$\begin{equation*} x = \begin{cases} y, & \text{if y is even}\\ y-1, & \text{if y is odd} \end{cases} \end{equation*}$$ for all $$x,y \in \Bbb Z$$. Now, consider \begin{align*} f(x) &= \begin{cases} f(y), & \text{if y is even}\\ f(y-1), & \text{if y is odd} \end{cases}\\ &= \begin{cases} y, & \text{if y is even}\\ (y-1)+1,& \text{if y is odd} \end{cases} \end{align*} Hence, we see that $$f(x) = y$$ for all $$x \in \Bbb Z$$. Thus, $$f$$ is surjective and therefore, $$f$$ has a right inverse.

Am I true?

• The image is of $f$ is only even numbers, so $f$ is not surjective Jan 4, 2021 at 16:55
• Oh, I see. The odd numbers doesn't have preimage in $\Bbb Z$, right? Jan 4, 2021 at 16:56
• Right, the odd numbers don't have pre-images in $\Bbb Z$; by the way, your function is not injective either, because $f(1)=f(2)$ but $1\ne2$ Jan 4, 2021 at 16:57

No; the image of $$f:\Bbb Z\to\Bbb Z$$ as you have defined it consists of only even numbers --
$$y=f(x)$$ is always even --
so $$f$$ is not surjective -- odd numbers do not have pre-images in $$\Bbb Z$$ --
so $$f$$ does not have a right inverse.
By the way, $$f$$ is not injective either, because $$f(1)=f(2)$$, but $$1\ne2$$.