Determine whether the function is onto function

The function $$f: \{ 0,1,2,3... \} \to B$$ where $$f(n)=\left \lfloor \frac{n-1}{2} \right \rfloor$$.Prove that it is an onto function if the codomain is $$\{-1,0,1,2,3,...\}$$ .

My work:

I use the flooring property but I am stuck.

Lets $$\left \lfloor \frac{n-1}{2} \right \rfloor$$=b,

$$b ≤ \frac{n-1}{2} < b+1$$

$$2b+1 ≤ n <2b+2$$

$$n∈[2b+1,2b+2)$$

Then how to determine $$n=2b+1$$ or $$n=2b+2$$ should i take to substitute to $$\left \lfloor \frac{n-1}{2} \right \rfloor$$ to prove that it is an onto function. Are there have a method can prove onto function strictly?

• Hint: $f(2n)=n-1$ Mar 20, 2020 at 11:28
• @PeterForeman How does it help?
– user743730
Mar 20, 2020 at 11:32

What is $$B$$? Assuming $$B$$ to be the range/codomain of $$f$$ I have an answer.

Let the codomain $$B=\{-1,0,1,2,...\}$$ then for each $$m\in B$$ and $$m>0$$ choose $$n=2m+1$$ then $$f(n)=\left \lfloor\frac{n-1}{2}\right \rfloor=\left \lfloor\frac{2m+1-1}{2}\right \rfloor=m$$. So $$f$$ is onto in this case.

For zero we have $$1$$ as it's preimage (Trivially visible).

For $$-1$$ simply take zero.

Thus for all elements m in the codomain which is $B={-1,0,1,2,...}$ we have an element from the domain $n$ so that $f(n)=m$. Thus $f$ is onto if the codomain is ${-1,0,1,2,...}$

• Can we take 2b+2? then we will have underfloor(b+1/2)=b,so that means we can take 2b+1 or 2b+2 trivially?
– user743730
Mar 20, 2020 at 11:38