Let $b$ be any prime. Consider a set of $b-1$ buckets. Consider all prime numbers (except $b$) up to some $N$. Let us do the simple hash wherein each prime $x$ less than $N$ is assigned to the $x \bmod b$-th bucket.
- It is found that as $N$ increases, the number of primes getting assigned to the $b-1$ buckets get very close to each other very rapidly. Can this rapid reduction in the range of numbers of primes hashing to each bucket be quantified as a function of $N$ and $b$?
Note: If $b$ is not a prime, then, some of the buckets do not receive any of the primes (for example, if $b = 8$, for any prime $x$, $x \bmod 8$ can never be $2$ and bucket number $2$ remains empty) but even then, those buckets with non-zero numbers of primes tend to have very nearly equal numbers of primes (from the comment below from Pedraig O'Cathain, I understand, the numbers of primes in each bucket getting close follows from the 'prime number theorem for arithmetic progressions').
- Consider the special case $b =7$ and a specific value of the remainder, say $3$. Only for those primes that gave hash value (remainder) $3$, we looked at the buckets into which the next higher prime would go. It was found that for primes immediately greater than those that hash to $3$, their distribution among the buckets is always uneven (i.e., if a prime hashes to $3$, the next prime is not equally likely to hash to each possible value $1$ to $6$) and never seems to equalize among the buckets even if we go to very large $N$. If bucket $b_i$ gets more primes than bucket $b_j$ for some value of $N$, then $b_i$ continues to get more primes for larger values of $N$; however, the ratio of number of primes in $b_i$ to number in $b_j$ reduces with $N$ but never quite gets to $1$ it seems. Have these phenomena been quantified?
Note: Also checked numerically the buckets to which the second prime after a prime that hashes to bucket 3 goes. Now, the range of probabilities among the 6 possible buckets is much reduced but for even fairly large N, they don't quite equalize.
- Is there some hash function for primes that has the property: if any prime hashes to a particular bucket, the next higher prime is equally likely to hash to any of the buckets?
They explain many details of the behaviour of these 'prime races'. Some buckets are fuller than others most of the time, as you have observed. They can quantify by how much some buckets lead, and how often. The tie all this to the Riemann hypothesis - it's a really nice paper.
– Padraig Ó Catháin Mar 20 '24 at 18:50