Suppose you have some finite set $S$ of positive integers, and a finite sequence $A$ which can only use values in $S$. I am curious about whether you can specify $S$ such that no two sequences will sum to the same value using the function
$$\begin{array}\\ f(A)&:=1 + a_1 a_2 a_3\cdots a_k + a_2 a_3 \cdots a_k + \ldots + a_{k-1}a_k+a_k \\ &=1+a_k(1+a_{k-1}(\ldots+a_2(1+a_1)\ldots)). \end{array}$$
A couple of toy examples to clarify:
Let $S=\{1,2\}$.
- $A=\{2\} \rightarrow f(A)=1+a_1=1+(2)=3$
- $A=\{1,2,1\} \rightarrow f(A)=1+a_1a_2a_3+a_2a_3+a_3=1+(1)(2)(1)+(2)(1)+(1)=6$
- $A=\{1,1\} \rightarrow f(A)=1+a_1a_2+a_2=1+(1)(1)+(1)=3$
Since the first and third cases are different $A$ sequences but yield the same sum for $f(A)$, we see that $\{1,2\}$ is a bad choice for $S$.
A good choice seems to be something more like squared primes. Using the following Mathematica code (should be fine to paste and try yourself, tweak first line as desired)...
s = {2, 3, 5, 7, 11}^2; num = 7;
z = <||>; c = 0;
f[s_, n_: 1] :=
Module[{r = {n}}, Do[AppendTo[r, Last[r] p + 1], {p, s}]; Last@r];
Do[
c++;
t = f[tup];
z[t] = Append[Lookup[z, t, {}], tup];
, {tup, Join @@ (Tuples[s, #] & /@ Range[num])}]
z = KeySort[z];
dupes = Select[z, Length@# > 1 &];
Column[Table[
Row[{"A=", z[k][[1]], " gives f(A)=", k}], {k,
Keys[z][[;; UpTo[10]]]}]]
Print["Out of ", c, " combinations, there were ",
Plus @@ Length /@ Values@dupes, " dupes across ",
Length[dupes], " values:\n",
Column[Table[
Row[{"f(A)=", k, " is given by:", dupes[k][[;; UpTo[5]]]}], {k,
Keys[dupes][[;; UpTo[10]]]}]]]
...we see that $S=\{2^2,3^2,5^2,7^2,11^2\}$ gives a unique $f$ for many small values, meaning all possible combinations up to length 7 except for one collision:
A={4} gives f(A)=5
A={9} gives f(A)=10
A={4,4} gives f(A)=21
A={25} gives f(A)=26
A={9,4} gives f(A)=41
A={4,9} gives f(A)=46
A={49} gives f(A)=50
A={4,4,4} gives f(A)=85
A={9,9} gives f(A)=91
A={25,4} gives f(A)=105
Out of 97655 combinations, there were 2 dupes across 1 values:
f(A)=4278151 is given by:{{4,121,4,4,49,9},{4,4,9,9,4,25,25}}
From the few tests I ran, $S=\{2^1,2^2,2^3,\ldots\}$ seemed to work perfectly though. Even if that holds up, I'm curious whether it can be improved upon (i.e. smaller $S$ values).
So my question is: is there a finite set $S$ such that you can have an arbitrarily long sequence $A$ without ever having a duplicate sum $f(A)$? If not, is there an infinite set $S$ that works (e.g. something like $\mathbb P$)?
In case it helps, the motivation here is to encode a sequence of numbers and retain ordering information without fail. And yes, I realize there are plenty of ways to do that more efficiently (a plain old base-$|S|$ number comes to mind), so please, no suggestions along those lines$-$just curious whether this one could be viable, or reveals any interesting properties along the way. Thanks!