Invertible function that takes four digits and generates one number

46 Views Asked by At

I'm trying to understand if there's a function (or a series of functions) that takes 4 digits (positive integers between 0 and 9) (a, b, c, d) and outputs a single number (i.e. e) where f(a,b,c,d)=e.

This function, or functions, must be reversible.

I don't know if this is possible and if it actually has a solution and what are called these functions (if they actually exist).

1

There are 1 best solutions below

1
On BEST ANSWER

To start with, there is nothing stopping you from defining a function however you want to. For example, you can define a function with finite domain by explicitly listing out all of its inputs and outputs. For example, we can write a function $f: \{0, 1\}^2 \rightarrow \{0, 1, 2, 3\}$ as:

$$\begin{eqnarray} f(0, 0) & = & 0 \\ f(1, 0) & = & 1 \\ f(0, 1) & = & 2 \\ f(1, 1) & = & 3 \end{eqnarray}$$

this fully defines the function $f$ even though we haven't applied any kind of normal operations. With that said, we can also write $f(a, b) = a + 2b$.

As it happens, $f$ is also invertible. We can similarly write $f^{-1}$ in terms of its cases, as:

$$\begin{eqnarray} f^{-1}(0) & = & (0, 0) \\ f^{-1}(1) & = & (1, 0) \\ f^{-1}(2) & = & (0, 1) \\ f^{-1}(3) & = & (1, 1) \end{eqnarray}$$

but if you want to write it more compactly, we can make use of things like the floor function - which returns the largest integer equal to or less than its argument, so $\lfloor 2 \rfloor = 2$, $\lfloor \pi \rfloor = 3$, $\lfloor -\pi \rfloor = 4$ and so on. We can also use the mod function, which returns the remainder of a number after dividing by some value - so $\mod(14, 3) = 2$ since $14 = 4 \times 3 + 2$. So one way to write $f^{-1}$ would be to write $f^{-1}(m) = (\mod(m, 2), \lfloor \frac{m}{2} \rfloor)$.

Similarly, if we took $f: \{0, \ldots, 9\}^4 \rightarrow \mathbb{Z}$ as $f(a, b, c, d) = a + 10b + 100c + 1000d$, then one option for writing its inverse would be to apply a bunch of mod and floor functions to extract each digit from a given number and return them. In a mathematical context, though, I'm pretty sure the standard thing to do would be to write something like "$f^{-1}(\overline{dcba}) = (a, b, c, d)$, where $\overline{dcba}$ is the four-digit number formed by concatenating those digits together".