# Is there any way to compress two or more numbers which I can get back without any errors?

I want to find out if there are any function $f$ which takes, lets say two numbers $a$, $b$ and outputs $x$, such that $f^{-1}(x)$ returns $a$ and $b$.

$$f(a,b) = x$$ $$f^{-1}(x) = a,b$$

I think this is not possible as there is information loss, but I want to know whether there are any methods that will approximate this.

• What are $a,b$? Integers? Real numbers? And can $f$ be totally arbitrary? – Ben Blum-Smith Dec 21 '17 at 13:08
• What sort of "numbers"? If just natural numbers, then pick your favorite two primes (like $2,3$) and write $f(a,b)=2^a\times 3^b$ or something like that. – lulu Dec 21 '17 at 13:09
• It strongly depends what kind of number we are talking about. If $a$ and $b$ are real and $x$ is complex, you can have $x=a+\mathrm ib$... – Tom-Tom Dec 21 '17 at 13:09
• If $a,b$ and $x$ are from the same domain, then the answer is "yes", as long as the domain is infinite (but it won't be pretty) You could even take this as a definition of "infinite set". – Arthur Dec 21 '17 at 13:12
• @Perseus14 You can pack triples together as $f(f(x,y),z)$, which is uniquely extracted to $f(x,y), z$, which is itself uniquely extracted to $x,y,z$. Keep going to pack more numbers into the tuple. – Patrick Stevens Dec 21 '17 at 13:17

Let me assume you want $a,b,x$ to be (nonnegative) real numbers. One solution is to:

Write decimal expansions of $a,b$, and then let $x$ be the number whose decimal expansion has $a$'s digits in the even powers of 10 and $b$'s digits in the odd powers of 10. (With $b$'s 1's place in the 10's place.) For example:

$a = 2.002\overline{4}$

$b = 337.99575$

$x = 303072.909052745\overline{40}$

Per Arthur's comment, what you want is an injective function from the set of pairs $\mathbb{R}\times\mathbb{R}$ to $\mathbb{R}$ (the set of real numbers). This exists because $\mathbb{R}$ is infinite. In general, if $A$ is an infinite set, there is an injective function from $A\times A$ to $A$.
For example, the function I just described is highly disconinuous. It fails to be continuous at values of the inputs that have 2 different decimal expansions like $0.399999... = 0.40000...$. It is not possible to give a continuous injective function from $\mathbb{R}\times\mathbb{R}$ to $\mathbb{R}$. (Proof, for those who know some point-set topology: Suppose $f$ were such an injection. Restrict $f$ to the unit disc. As the disc is compact and connected, its image is a compact connected subset of $\mathbb{R}$, i.e. a closed interval. Thus $f$ induces a continuous bijection from a disc to a closed interval. This is impossible because a continuous bijection between compact hausdorff spaces is a homeomorphism, but a disc is not homeomorphic to a line segment.)
Second addendum: This is getting a little afield of the OP, but, since I engaged with Arthur's comments in the first addendum, I should mention that I just looked for a reference to the claim that if $A$ is infinite, there is an injection from $A\times A$ to $A$ (equivalently, that $A\times A$ and $A$ have the same cardinality), and discovered to my surprise that the general statement of this fact requires the axiom of choice, and is actually equivalent to the axiom of choice in ZF! See here and here. (However, in the situation of $A=\mathbb{R}$, there is no need for it, as shown in the totally explicit map $\mathbb{R}^{\geq 0}\times\mathbb{R}^{\geq 0}\rightarrow\mathbb{R}^{\geq 0}$ described above.)