Inverse of function containing modulation and flooring

76 Views Asked by At

I have a function $f: \mathbb{N} \rightarrow \mathbb{N}$ defined as: $$f(x) = ((x \bmod 9) + 1) \cdot 10^{\lfloor \frac{x}{9} \rfloor}$$

It seems to be injective, but I'm not sure about it being surjective on $\mathbb{N}$. Regardless, is there an inverse of this function that maps elements from its image to its domain?

1

There are 1 best solutions below

0
On BEST ANSWER

Assuming that your number is $9p + q$, where $0 \le q \le 8$, we have $f(x) = (q + 1) \cdot 10^p$. This isn't hard to invert because $q + 1$ is between $1$ and $9$.

Assuming that we have $f(x) = m$. Then the largest power of $10$ that divides $x$ is $\lfloor \log m \rfloor$ - thats the value of $p$. Then, we have $q + 1 = \dfrac{m}{10^{\lfloor \log m \rfloor}} \rightarrow q = \dfrac{m}{10^{\lfloor \log m \rfloor}} - 1$.

Thus, we may express the inverse function as $$ f^{-1}(m) = 9 \cdot \lfloor \log m \rfloor + \dfrac{m}{10^{\lfloor \log m \rfloor}} - 1$$