Comment by bloak
2 days ago
The Python code seems to be a kind of arithmetic decoder with the assumption that each prime is less than twice the previous prime. That seems to be a special case of Bertrand's Postulate, but probably there's a lower bound one could use to get a more efficient encoding: https://en.wikipedia.org/wiki/Prime_gap#Upper_bounds
Of course, another way of making this a more efficient encoding would be to take account of the fact that primes tend to be odd: if p is an odd prime then the next prime is one of the (p - 1)/2 values p + 2, p + 4, ..., 2p - 1.