Is there a function that makes the binary relation between a bounded set of bounded sequences and $\{0, 1, 2, \dots, 2^{64}\}$ injective?

38 Views Asked by At

Given the set $S$ of all possible sequences within bounds $[1, 31]$ with $n$ elements (where $n$ is constant and $ 1 < n < 32$) and a set $L \subset \{0, 1, 2, \dots, 2^{64}\}$ where $|L| = |S|$, does there exist a function $f$, so that the binary relation $R: S \times L$ is injective?

Actual use case (computer science):

I have a non-strict weak ordered list of constant length $1 < n < 32$ with integers in range $[1, 31]$. I want to know if it's possible to unqiuely map each list to a 64 bit integer. The mapping is one-way only, so I don't need to map an integer back to a list.

2

There are 2 best solutions below

2
On BEST ANSWER

If $\mathbf a = (a_0,a_1,\ldots, a_{n-1})$ is a non-decreasing sequence of non-negative integers, we can defined $$f(\mathbf a)=\sum_{i=0}^{n-1}2^{a_i+i}.$$ With this definition, $\mathbf a\ne\mathbf b$ implies $f(\mathbf a)\ne f(\mathbf b)$. Additionally, $$ 2^n-1\le f(\mathbf a)<2^{n+a_n}.$$ With your constraints, this means $f(\mathbf a)<2^{64}$, as desired.

1
On

First of all $|S|$ is bigger than you think. If we treat each sequence $(n_1,n_2,\ldots, n_{32})$ as the map $$\{1,2,\ldots,32\} \to \{0,1,\ldots,31\} \qquad i \mapsto n_i$$ between sets of cardinality $32$ then by definition there are $32^{32}$ elements. Now write

$$32^{32} = (2^5)^{32} = 2^{4 \cdot 32} = 2^{160}.$$

So $|S| = 2^{160}$ in fact.

To get a bijection from $S$ to $\{1,2,\ldots, 2^{160}\}$ express each integer in the list in binary and then remove the commas. For example

$(1,2,5,\ldots,8) \mapsto (00001,00010,00101,\ldots,00100) \mapsto 000010001000101 \ldots00100$