I'm trying to prove the bijectivity of some function and already have the injective proof down, but am having trouble with the surjectivity. I have to prove the following function, $f$, is surjective to the positive odd integers.
For some function $f(r,m) = 2^{r+1}m + \frac{2^{r}(5+(-1)^{\left\lceil\frac{r+2}{2}\right\rceil}+3(-1)^{\left\lfloor\frac{r+2}{2}\right\rfloor})-1}{5}$, $r \in \mathbb{Z^{+}}$ and $m \in \mathbb{N}$
Prove $f(r,m): \mathbb{Z^{+}} \times \mathbb{N} \rightarrow 2\mathbb{N}+1$
It seems like at each r-value the function produces odds that are a subset of the positive odd integers, but I can't find a way to prove surjectivity to the positive odds. I have a map of some values below so you can see how it jumps back and forth.
$f$ to odd integers">
Unless I'm missing some completely elegant solution, I believe the key idea of solving this problem is to observe the pattern in what $f$ gives when $m = 0$, in base $2$. I define the additive factor for some $r$ as $2^{r+1}$, as for a fixed $r$, $f(r,m)$ just serves as a linear function with common difference $2^{r+1}$.
\begin{array}{|c|c|r|} \hline r & f(r,0) & f(r,0) \text{ in base $2$, and additive factor} \\ \hline 1 & 1 & 00\color{blue}{0001}\\ & & 000100 \\ \hline 2 & 7 & 00\color{blue}{0111} \\ & & 001000 \\ \hline 3 & 11 & 00\color{blue}{1011} \\ & & 010000 \\ \hline 4 & 3 & 00\color{blue}{0011} \\ & & 100000 \\ \hline 5 & 19 & 0\color{blue}{0001}\color{red}{0011} \\ & & 0001000000 \\ \hline 6 & 115 & 00\color{blue}{0111}\color{red}{0011} \\ & & 0010000000 \\ \hline 7 & 179 & 00\color{blue}{1011}\color{red}{0011} \\ & & 0100000000 \\ \hline 8 & 51 & 00\color{blue}{0011}\color{red}{0011} \\ & & 1000000000 \\ \hline 9 & 307 & 00\color{blue}{0001}\color{red}{0011}\color{red}{0011} \\ & & 00010000000000 \\ \hline 10 & 1843 & 00\color{blue}{0111}\color{red}{0011}\color{red}{0011} \\ & & 00100000000000 \\ \hline \end{array} Whatever numbers on the right (i.e. when $m > 0$) would just be $f(r,0)$ plus some multiple of the additive factor. This motivates us to prove the following statements:
Proof. We simply exhaust all possible cases of $n$. Since $n$ is odd, the last digit must be $1$.
$\blacksquare$
Note that the "exactly once" part is part of the conclusion that $f$ is injective, so you don't need to prove that. With this, you should be able to extend the lemma inductively to prove the following:
Finally, you want to show that the pattern that we see in the table indeed holds. Formally, you want to show the following:
Proof. We have already verified that this is true for $p = 0$. For $p > 0$, we can re-express these expressions in base $10$, and for the first case this would be the result: \begin{align*} 0001\underbrace{\color{red}{00110011 \dots 0011}}_{p \text{ blocks total}} &= 2^{4p} + 3(2^{4p-4} + 2^{4p-8} + \cdots + 2^4 + 2^0) \\ &= 2^{4p} + 3\left(\frac{2^{4p} - 1}{2^4 - 1}\right) \\ &= 2^{4p} + \frac{2^{4p} - 1}{5} \\ &= \frac{3(2^{r}) - 1}{5} \end{align*}
We can conclude similarly that, for the next three cases, we have: \begin{align*} \frac{9(2^{r}) - 1}{5}, \;\frac{7(2^{r}) - 1}{5}, \; \frac{2^{r} - 1}{5} \end{align*}
It remains to check that $f(r,0)$ indeed yields these expressions. To do this, split $r$ in the 4 cases (modulo $4$), and conclude what are the possible values of $\left((-1)^{\left\lceil\frac{r+2}{2}\right\rceil}, (-1)^{\left\lfloor\frac{r+2}{2}\right\rfloor}\right)$. $\blacksquare$
With Proposition #1 and #2, we can then conclude that $f$ is surjective.