tl;dr: Inspect the last image below and check out gap-density.R.

I just discovered something that made me smile: As I looked at the density plots of increasing numbers of prime gaps, a fractal emerged.

Allow me to explain.

First I get the prime gaps (basically, the distance between primes) with this perl code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/usr/bin/env perl # gaps-simple: Print the gaps between primes use strict; use warnings; use Math::Prime::XS qw(primes); my $limit = shift || 100; my @primes = primes($limit); my $n = 0; while ( $n < @primes - 1 ) { my $prime = $primes[$n]; my $greater = $primes[ $n + 1 ]; my $gap = $greater - $prime; print "$gap\n"; $n++; } |

This returns a list like this:

1 2 3 4 5 6 7 8 9 10 11 |
1 2 2 4 2 4 2 4 6 2 6... |

Then, I say, “perl gaps-simple 10 > gaps-simple-10.txt” to get all the prime gaps below the number 10 into a text file.

Next I inspect this in R (the statistical programming environment – r-project.org), as such:

1 2 3 4 |
gaps <- read.table( 'gaps-simple-10.txt' ) png( file = 'gaps-simple-10.png' ) plot( density( gaps$V1 ), xlab = 'prime gaps', main = 'Below 10' ) dev.off() |

For increasing numbers of gaps (shown to 100_000_000), this results in the following graphs. You can see the self-similar, fractal nature emerge: