I'm looking for a way to convert 4 numbers into 1 number, then convert that 1 number back into the original inputs with no knowledge of said inputs.

  1. 4 Numbers
  2. Convert into 1 number (summing/multiplying/anything)
  3. Use the result to generate the original 4 numbers.


Four Original numbers: a = 2; b = 5; c = 10; d = 1;

Combined number: x = 2 + 5 + 10 + 1 x = 18

One function or 4 functions to generate original numbers only using x: f(x) --> a = 2; b = 5; c = 10; d = 1;

(9 numbers would also be appreciated if this problem is possible)

  • $\begingroup$ You would need to have restrictions to said numbers, otherwise you could be claiming to map R4 into R1. Also, keep the pigeon hole principle in mind, this is generally not possible without creating ambiguity. $\endgroup$ – Mefitico Apr 18 '19 at 16:23
  • $\begingroup$ Do you have a training dataset consisting of a large number of examples of the form $(x, y_1,y_2,y_3,y_4)$? You could treat this as a regression problem. $\endgroup$ – littleO Apr 18 '19 at 16:24
  • $\begingroup$ A similar problem, I'm attempting to use filtering to convert a 3x3 matrix into 1 value, that can then be converted back into the original 3x3 matrix. The issue I have is that I can't use any values outside of that 1 value. So this makes regression/curve fitting very difficult. $\endgroup$ – doraginuru92 Apr 18 '19 at 16:28
  • $\begingroup$ Oh I see, I had misunderstood your question. Gotcha. $\endgroup$ – littleO Apr 18 '19 at 16:34
  • $\begingroup$ @Mefitico Those two sets have the same cardinality, so that isn't a problem. In fact, the existence of space filling curves shows that such functions can be constructed unambiguously. $\endgroup$ – Servaes Apr 18 '19 at 21:00

If you four numbers are integers, then a classical approach would be to send the four numbers $a$, $b$, $c$ and $d$ to the single number $$f(a,b,c,d):=2^a3^b5^c7^d.$$ By unique factorization, you can get your four numbers back from this single number by factoring it.

Of course the same idea works for nine integers; simply throw in the next five prime numbers.

  • $\begingroup$ This sounds very similar to what I'm looking for, however, I think I'm struggling with the concept of how to get back the original (a,b,c,d). Would you be able to give me a complete example if possible? Also is it possible to use multiplication instead of to the power e.g. 2*a 3*b 5*c 7*d? $\endgroup$ – doraginuru92 Apr 18 '19 at 23:56

If the four numbers are integers that come from a reasonably small range, positional notation is your friend.

For example, if you know $a,b,c,d$ are all between $0$ and $999$ you can simply concatenate their three decimal digit representations, padding with $0$ as needed, so $$ f(2,5,10,1) = 002005010001 $$

This is the simplest example of a very general idea. If you want to store $k$ nonnegative integers each less than $b$ you can stuff them into a $k$ digit number in base $b$. That will produce an output less than $k^b$. The algorithms for packing and upacking numbers in arbitrary bases are easy and already implemented in most modern programming languages.


You could map the tuple $2,5,10,1$ to the character string 2,5,10,1 and then replace each digit with a pair of equal digits, resulting in 22,55,1100,11 and then replace the commas with a pair of unequal digits, resulting in (say) 2291559111009111.

And so on. This recipe is easy to implement on a computer but perhaps hard to write down with algebraic expressions.


Your Answer

