# Some graphs about primes

Posted by Jason Polak on 29. November 2017 · Write a comment · Categories: number-theory · Tags: , ,

Lately I’ve been thinking about primes, and I’ve plotted a few graphs to illustrate some beautiful ideas involving primes. Even though you might not always associate with primes, they are always haunting quietly in the background.

## Abundance of primes in an arithmetic progression

Let’s start out with the oddest prime of all: 2. Get it? But after that, all the odd primes are either of the form $4k + 1$ or $4k + 3$. For fixed $x$, are there more primes less than $x$ of the form $4k + 1$ or the second form $4k + 3$? Let’s write $\pi(4k + r,x)$ for the number of primes less than or equal to $x$ of the form $4k + r$. Here is a graph of the difference $\pi(4k+3,x) – \pi(4k+1,x)$:

Pretty neat right? It looks like this difference is wildly erratic, reaching zero after a short while with a bit of a fight and then for a really good long while the primes of the form $4k +3$ win out. So you might be tempeted to think that primes of the form $4k + 3$ become more and more abundant as $x$ increases. That would be wrong. In fact, John E. Littlewood proved that $\pi(4k +3,x)-\pi(4k + 1,x)$ switches sign infinitely often!

Of course, that must mean there are infinitely many primes of both types, and that’s true and a special case of Dirichlet’s theorem: there are infinitely many primes in any arithmetic progression $ax + b$ whenever $a$ and $b$ are relatively prime.

## Twin primes

Ok, what about twin primes? These are primes pairs of the form $(p,p+2)$. How many are there of these? In this graph I write ${\rm twin}(x)$ for the number of twin pairs less than or equal to $x$:

Looks like there’s a steady increase of them. If you zoom out at look at $x$ up to $10^7$ you get something frighteningly regular:

Sort of like all the primes: Hadamard proved $\pi(x)$, the number of primes less than or equal to $x$, to be asymptotic to $x/\log(x)$. But while the primes obey this nice law and it’s easy to prove that there are infinitely many, no one knows whether there are infinitely many twin primes.

## Primes of the form $x^2 + 1$

We’ve already mentioned Dirichlet’s theorem: if $a$ and $b$ are relatively prime integers then the arithmetic sequence $ax + b$ contains infinitely many primes. For higher order polynomials, little is known. For example, no one knows whether there are infinitely many primes of the form $x^2 + 1$. Here are the first few primes of this form:

2, 5, 17, 37, 101, 197, 257, 401, 577, 677, 1297, 1601, 2917, 3137, 4357, …

After 5, they all end in 1 or 7, which are the only possibilities. If $x$ ends in 4 or 6, then $x^2 + 1$ ends in 7, whereas if $x$ ends in 0 then $x^2 + 1$ ends in 1. So if there is no funny business going on, you’d expect that primes of the form $x^2 + 1$ end in 7 about 2/3rds of the time, which is pretty close to the actual ratio. For example, if $x \lt 300000$ then there are 11898 $x^2 + 1$ primes that end in 7 and 17922 $x^2 + 1$ primes that end in 1 or 7, so the ones that end in 7 are about 66.388% of the total.

If you look at the naive density of the set $\{ x : x^2 + 1\text{~is prime~}\}$ you get:

Here, $\log(x)$ is on the $x$-axis rather than just $x$ in order to more easily illustrate the trend. Is it approaching some kind of nonzero limit as $x\to\infty$? Again, if you look at the pure counts of primes of the form $x^2 + 1$

then it looks like these primes following a similar prime-number-theorem-like trend but who knows?

Of course, once you ask about $x^2 + 1$, you might like to know about polynomials like $x^2 + x + 1$ or $x^3 + x + 1$. Here is a graph of the prime counting functions for primes of these forms:

Since there are infinitely many functions $f:\N\to\N$ you could ask infinitely many questions of the form, are there infinitely many primes of the form $f(x)$? Almost all of these questions will go answered as is the nature of mathematics. That’s ok though because as the functions get more complex, less people will care about the answers. The function $f(x) = x^2 + 1$ is held in high esteem: it has low degree and it is the irreducible polynomial in $\R[x]$ such that the quotient $\R[x]/(x^2 + 1)$ is isomorphic to the complex numbers. It also looks very nice. If you instead proved that there are infinitely many primes of the form
$$\lfloor e^{n/100}\rfloor$$
I think it would still be interesting but less so, given that by the time something like that is proved, many other similar results will have preceded it. By the way, this function does seem to assume quite a lot of primes like 3225937498101217 at $n = 3571$.