[OC] Do Prime Numbers have “memory”? I analyzed the first 37 Billion primes (up to 1 Trillion) to visualize the bias in their last digits

Posted by anotherFranc

20 Comments

  1. The Context: We are often told that prime numbers behave pseudo-randomly. If you look at the last digit of a prime (in base 10), it can be 1, 3, 7, or 9. You’d expect a 25% chance for each, and a 25% chance for the next prime to end in any digit.

    The Visualization: I wanted to verify the Lemke Oliver & Soundararajan (2016) discovery on a massive scale. This heatmap visualizes the probability that a prime ending in digit Y (Y-axis) follows a prime ending in digit X (X-axis).

    Key Findings:

    – The Diagonal Repulsion: Look at the dark diagonal line. Primes “hate” repeating their last digit immediately.

    – If a prime ends in 1, there is only a ~19.7% chance the next one ends in 1 (instead of 25%).

    – This bias persists even after scanning 37 billion primes.

    Technical Analysis: I built a custom high-performance database containing all 37,607,912,018 prime numbers up to 1 Trillion and counted every transition.

    Data Snippet (Deviation from Randomness):

    1 -> 1: -5.35% (Strong Repulsion) 3 -> 3: -5.74% 7 -> 7: -5.74% 9 -> 9: -5.35%

    Source: Computed myself using a custom binary bitmap database (Mod 20 Wheel Factorization). Tools: Python (computation), Matplotlib/Seaborn (visualization).

  2. You appear to have not made any attempt to display this data beautifully. These are very basic plots with bad colors, bad font sizes, bad labels and no way to understand what is being displayed by just looking at the visualizations.

    This does not belong here until some additional effort is put into the visuals

  3. This looks great, and maybe I’m totally wrong, but wouldn’t two repeating last digits indicate a higher probability, that the whole number is divisible by 11 or something?

    Essentially, the definition of a prime would directly lead to this result?

    (I might be totally wrong on this, I’m not that deep into math.)

    EDIT: Ooops, and I misunderstood that OP is looking at consecutive primes. My bad.

  4. Why would we expect the ones digit of the next prime to be equally likely to be 1, 3, 7, or 9? Especially repeating the next digit seems unlikely cause it has to “miss” 3 other candidates to get there.

  5. experimental1212 on

    Wow look at the narrow spread on that ~19.5% chance to repeat the last digit. I wonder if these values look much different of you slice the range of primed you sample differently.

    Right now you do 1 to 1 trillion. What about 1 to 500 billion vs 500 billion to 1 trillion, etc. the narrow spread is so interesting when the other transitions are all over the place.

  6. Consistent-Annual268 on

    Would be great to see this same analysis in multiple other bases than 10. Especially interesting would be to looks at prime bases vs highly composite ones to see if there are any discernible differences.

  7. The first diagram seems to be symmetric on the bottom-left – top-right axis. Indeed the “Resolution” is very low, because of in base 10 there are only like 4 different possible endings.

    What if you converted the primes in your db into a base where there are way more possible endings. I assume the diagram would look the same, but with a higher resolution. Should you use a base large enough, the finer structure of the map would be revealed, which could help us better understand the causes.

    At the moment we are looking at a map that has a resolution of 4×4, but what intricate structure it could show if it had e.g. 40×40 or 400×400 resolution?

    Or it may turn out to have a different structure in other bases, which again could tell us a lot about why and what exactly is going on.

  8. This seems like a big deal. But I am just a layman. Can someone please eli5 the significance, implications, and possible realworld applications of these findings?

    Nice work op. I don’t fully understand the implications, but anyone who builds a clean visualization from a TRILLION INTEGER data sample deserves a high-motherfucking-five in my book

  9. intellectual_punk on

    This is really neat! I’m guessing you’re not willing to share the code yet?

    I’d be very interested to see the results u/KibbledJiveElkZoo and u/dimonoid123 asked about.

  10. SuperWeapons2770 on

    It would be neat to see this in some base that is large to look and see a more granular result

  11. Dimsdaledimmadome on

    The Humans by Matt Haig is a Novel about a scientist figuring out the pattern of prime numbers and aliens sending one of there own to kill him and anyone who he told. Watch out OP

  12. Very strange that it isn’t symmetric. So transition probability of 1->9 is not equal to 9->1, even though the difference obviously is symmetric.