Given a set of many variables $S=\{x\_1,x\_2, ...., x\_i\}$, and any subset $S'$ of $S$, I need a function $f$ which maps $S'$ to a value $x$ and a function $f'$ which maps $x$ back to set $S'$.


I know my question can be solved with [Gödel\_numbering](https://en.wikipedia.org/wiki/G%C3%B6del_numbering), but it will consume a lot of space and the computation cost is quite high when the size of $S'$ is big.


Is there any relationship the values in $S$ can satisfy such that we can make function $f$ and $f'$ very easy?


I tried making all values in S to be even, odd or prime and function f as sum. But it clearly does not work.



Encoding numbers with relationship into one and back
This is inspired by answers in the other linked threads. You can let $f(S') = \sum\_{x\_j \in S'} 2^{j-1}$.


If you let your set only contain powers of 2, i.e. $S = \{ 1, 2, 4, 8, \ldots , 2^i\}$, then $f(S') = \sum\_{x\_j \in S'} x\_j$, the sum of all numbers in $S'$.


Note that this is the same as interpreting $S'$ as a length $i$ binary number where the $j$th bit is 1 if $x\_j \in S'$ and 0 otherwise. Note that there are $2^i$ different subsets of $S$ so you need a binary number of length at least $i$ to be able to represent all possible subsets.


