While prime numbers are a central part of number theory and attract much attention, they do not appear to be critical for the analytic orientation of this website. For that reason this presentation is relegated to the diversions section: prime numbers are fun for play just like LEGOs!

# Prime Number Sieve

The ancient algorithm for locating all primes, which goes by the name of Eratosthenes, is surprisingly simple to code. It only requires these few lines:

The function `generateSieve()` updates the array `sieve` to indicate which integers less than or equal to the input argument are of the indicated type. The array is padded to allow direct indexing of integers, so that it is simple to implement a function to check whether a given number is prime:

With this simple apparatus one can easily generate a list of small(ish) primes:

The first three lines can be compared to A000040 to confirm accuracy.

The main drawback to implementing primes in JavaScript is that the entire data set must remain in active memory, since there is no way to save data to disk without user interaction. Still, this works well enough to provide a decent playground for testing relationships.

# Prime Factorization

The main reason for introducing the idea of primes is naturally for factoring composite numbers. With a list of primes in hand this is straightforward. The factorizations of integers up to one thousand are

It is simple to check these results by direct multiplication.

# Goldbach Pairs

The so-called strong form of Goldbach’s conjecture states that every even number greater than two is the sum of two primes. Other than four, which is two plus two, even numbers can be decomposed into two odd primes, often in multiple ways. It is straightforward with the existing apparatus to check all possible decompositions as to whether both terms are prime or not.

The result for even numbers up to one hundred is

The number of decompositions into primes can be compared to A045917 for accuracy. A related set of integers is A002375 which differs only in the second term.

While there is no apparent pattern to the number of decompositions, one is tempted to ask about the minimum or maximum distance between the primes in each pair. This is not difficult to determine: first the minimum differences, which is A066285,

followed by the maximum differences, which is A303603 offset by one term:

Unfortunately plots of these two lists of integers reveal no apparent patterns. Schade!

Here is another way to think about Goldbach’s conjecture: if every even number greater than two is the sum of two primes, every integer greater than one is the average of two primes. This means

$2n=p1 +p2 → n=p1 +p22 → n±Δ =(p1, p2)$

It is interesting to tabulate the values $\Delta \left(n\right)$ for each integer:

Curiouser and curiouser...

# Twin Primes

A pair of primes are twin if they differ by two. These too are simple to determine with existing apparatus:

Without the parentheses this is A077800. Other than the first pair, the even integer centered between the twins is

Since these integers occur in a string of three numbers, where the first and last are prime, they must also be divisible by three. Dividing the set by six gives