You are on page 1of 35

University of Luxembourg

BASI Mathematics
Experimental Mathematics Lab
Project

Visualising the distribution of primes


Authors: Supervisors:

Jim Barthel Prof. Gabor Wiese


Pietro Sgobba Dr. Panagiotis Tsaknias
Fa Zhu

Summer semester 2015


Contents
1 Introduction 2
2 The asymptotic distribution of prime numbers 4
2.1 The prime-counting function . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 The prime number theorem . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Approximation in terms of logarithmic integral . . . . . . . . . . . . . . . . 8
2.4 Probabilistic interpretation of the Prime number theorem . . . . . . . . . . 11
2.5 Estimate for the nth prime number . . . . . . . . . . . . . . . . . . . . . . 12
2.6 Frequencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3 Ulam spiral 15
3.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Our Ulam spiral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 Comparison with random distribution . . . . . . . . . . . . . . . . . . . . . 18
3.4 Lines of primes in the Ulam spiral . . . . . . . . . . . . . . . . . . . . . . . 19
4 Klauber triangle 26
4.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.2 Our Klauber triangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3 Comparison with random distribution . . . . . . . . . . . . . . . . . . . . . 29
4.4 Lines of primes in the Klauber triangle . . . . . . . . . . . . . . . . . . . . 30

1
1 Introduction
The aim of this project is to study the distribution of prime numbers. We are going to
observe how prime numbers are distributed in the set of natural numbers. At a rst look
of the rst prime numbers, e.g. prime numbers less then 100, one may think that their
distribution is random, although they tend to appear less frequently approaching 100.
However, if we observe prime numbers on a much greater scale, we can notice that the
apparently random distribution of primes follows some particular behaviours.
In this project we are going to analyse two phenomena. In the rst part, we will describe
the asymptotic behaviour of the prime-counting function π . In the second part, we will
introduce the Ulam spiral and the Klauber triangle, which are simple models to display
natural numbers and to notice some patterns of primes.
Let us start from the basic denition of a prime number.
Denition. A natural number p ∈ N is a prime number if p ≥ 2 and it has no positive
divisors other than 1 and p.
A rst question about prime numbers, which is also at the basis of our study, is whether
there are innitely many primes. The answer was already given by Euclid more than
2200 years ago in his famous Elements (Book 9, Proposition 20). Before proving Euclid's
theorem, let us state and prove the following lemma.
Lemma. Let n ≥ 2 be a natural number. Then there exist prime numbers p1 , p2 , . . . , pk
(which may be not all dierent) such that
n = p1 p2 · · · p k .

Proof. Let us assume that there exists a positive integer ≥ 2 which cannot be written as
a product of primes. Let n be the smallest such integer. Since n is obviously not prime, n
has a positive divisor d which is neither 1 nor n such that
n = md,

for some m ∈ N. Note that both d and m are ≥ 2 and < n. Because n is the smallest
positive integer which cannot be written as a product of primes and d and m are less than
n, we have that
m = p1 p2 · · · pk and d = q1 q2 · · · ql
for some prime numbers p1 , . . . , pk , q1 , . . . , ql . Therefore,
n = md = p1 p2 · · · pk q1 q2 · · · ql ,

i.e. n can be written as a product of some prime numbers. Hence, our assumption is
wrong.
We are now able to prove Euclid's theorem.

2
Theorem (Euclid's theorem). There exist innitely many primes.
Proof. Let us assume that there are nitely many primes, say p1 , p2 , p3 , . . . , pn . Consider
the positive integer
m := p1 p2 · · · pn + 1. (1)
Using the previous Lemma, every positive integer ≥ 2 can be written as a product of prime
numbers. Then, there is a prime which is a divisor of m, say pi , for some 1 ≤ i ≤ n. Now,
this contradicts equation (1), which shows that dividing m by pi we get 1 as reminder.
Hence, our assumption is wrong.

3
2 The asymptotic distribution of prime numbers
2.1 The prime-counting function

The goal of this section is to study the asymptotic distribution of prime numbers. Let us
start with the following denition.
Denition. The prime-counting function is the function π : R+ → N dened by
π(x) := #{p ∈ N | p is a prime number and p ≤ x}.

Prime numbers less than 100 are:


2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.

Therefore, π(10) = #{2, 3, 5, 7} = 4, and so on, as we see in the following table:

x π(x)
10 4
20 8
50 15
70 19
80 22
90 24
100 25

Table 1: Some values of π


Figure 1 shows the graph of π for 0 ≤ x ≤ 100. Of course, we are interested in the
asymptotic behaviour of this function. Table 2 gives values of π for powers of 10 up to 109
and Figure 2 shows the graph of π for x in this interval, i.e. 0 ≤ x ≤ 109 .

x π(x)
102 25
103 168
104 1229
105 9592
106 78498
107 664579
108 5761455
109 50847534

Table 2: Values of π for powers of 10

4
Figure 1: Graph of π for 0 ≤ x ≤ 100

Figure 2: Graph of π for 0 ≤ x ≤ 109

5
2.2 The prime number theorem

By Euclid's theorem we know that there exist innitely many primes. Of course, this
means that π is an increasing function and that π(x) → ∞ as x → ∞. Intuitively we
see that prime numbers appear to be more sporadic as they become larger, but we would
like to describe more precisely the asymptotic behaviour of π . This is formalized by the
following famous theorem.
Theorem (Prime number theorem). Let π be the prime counting function and log be the
natural logarithm. Then a good asymptotic approximation of π is given by the function
x
x 7−→ .
log x
This means that
π(x)
lim = 1.
x→∞ x/ log x

Equivalently, this can be written in the form


x
π(x) ∼ as x → ∞. (2)
log x
Near the end of the 18th century, the mathematicians Carl F. Gauss and Adrien-
Marie Legendre, through empirical considerations, conjectured equivalent statements to
(2). During the following century, Bernhard Riemann gave an important contribution to
the theory. Then the theorem was nally proven in 1896, independently by two mathe-
maticians, Jacques Hadamard and Charles J. de la Vallée-Poussin. In the 20th century,
simpler proofs were found by Atle Selberg and Paul Erd®s (1949) and later by Donald J.
Newman (1980).
We will not prove the theorem here, but we will analyse the approximation of π . We
have plotted both functions π and logx x on the same graph for x up to 109 (Figure 3).
Moreover, we have plotted the quotient π(x)/( logx x ), again for x up to 109 and we have
enlarged the graph for the interval 1 ≤ y ≤ 1.2 on the y -axis (Figure 4). As we can see,
the convergence to 1 is very slow.

6
Figure 3: Functions π(x) (-) and x
log x
(-) for x up to 109

Figure 4: Quotient π(x)/( logx x ) for x up to 109 , 1 ≤ y ≤ 1.2

7
In order to describe the convergence of the quotient π(x)/( logx x ), the following table
gives values illustrating this behaviour.
x
x π(x) log x
π(x)/( logx x )
10 4 4.34 0.92103
102 25 21.71 1.15129
103 168 144.76 1.16050
104 1229 1085.74 1.13195
105 9592 8685.89 1.10432
106 78498 72382.41 1.08449
107 664579 620420.69 1.07117
108 5761455 5428681.02 1.06130
109 50847534 48254942.43 1.05373

Table 3: Values concerning (2) for powers of 10

2.3 Approximation in terms of logarithmic integral

There exists a better asymptotic approximation of the prime-counting function than x


log x
.
For this, let us consider the Logarithmic integral function
Z x
dt
li(x) = , for x > 0, x 6= 1.
0 log t
Now, the Eulerian logarithmic integral function is dened as
Z x
dt
Li(x) = = li(x) − li(2), for x > 2.
2 log t
The Prime number theorem also states that the prime-counting function is asymptotically
equivalent to Li. Then (2) is equivalent to
π(x) ∼ Li(x) as x → ∞. (3)
We have plotted the functions π , Li and logx x in the same graph (Figure 5): π and Li
almost coincide. Moreover, it is sucient to plot the quotient π(x)/ Li(x) for x up to 105
(Figure 6). Indeed, we can see that the convergence to 1 is very quick. Figure 7 shows the
comparison between the two quotients π(x)/ Li(x) and π(x)/ logx x for x up to 109 .

8
Figure 5: Functions π(x) (-), Li(x) (-) and x
log x
(-) for x up to 109

Figure 6: Quotient π(x)/ Li(x) for x up to 105 , 0.8 ≤ y ≤ 1

9
Figure 7: Quotients π(x)/ logx x (-) and π(x)/ Li(x) (-) for x up to 109 , 0.8 ≤ y ≤ 1.2

Table 4 shows values concerning statement (3), while Table 5 compares them to the
respective results for the approximation by logx x (Table 3). The two gures together with
both tables clearly point out that the Li function is a much stronger approximation for π
than logx x .

x π(x) Li(x) π(x)/ Li(x)


10 4 5.12 0.78118
102 25 29.08 0.85967
103 168 176.56 0.95149
104 1229 1245.09 0.98708
105 9592 9628.76 0.99618
106 78498 78626.50 0.99837
107 664579 664918.00 0.99949
108 5761455 5762209.03 0.99987
109 50847534 50849234.70 0.99997

Table 4: Values concerning (3) for powers of 10

10
x
x π(x) Li(x) log x
π(x)/ Li(x) π(x)/( logx x )
10 4 5.12 4.34 0.78118 0.92103
102 25 29.08 21.71 0.85967 1.15129
103 168 176.56 144.76 0.95149 1.16050
104 1229 1245.09 1085.74 0.98708 1.13195
105 9592 9628.76 8685.89 0.99618 1.10432
106 78498 78626.50 72382.41 0.99837 1.08449
107 664579 664918.00 620420.69 0.99949 1.07117
108 5761455 5762209.03 5428681.02 0.99987 1.06130
109 50847534 50849234.70 48254942.43 0.99997 1.05373

Table 5: Comparison of values concerning (2) and (3) for powers of 10

2.4 Probabilistic interpretation of the Prime number theorem

The Prime number theorem can be also understood using a simple probabilistic approach.
Statement (2) is equivalent to
π(x) 1
∼ as x → ∞. (4)
x log x

The quotient π(x)/x represents the relative amount, i.e. the percentage, of how many prime
numbers one can nd in the interval [1, x]. Then, (4) says that this value is asymptoti-
cally equal to 1/ log x. We can interpret this statement as follows: for x very large, the
probability that k ∈ [1, x], where k ∈ N, is a prime can be approximated by 1/ log x.
Analogously, statement (3) is equivalent to
π(x) Li(x)
∼ as x → ∞. (5)
x x
Then, for x very large, a better approximation for the probability that k ∈ [1, x], k ∈ N, is
a prime is given by Li(x)/x.
Table 6 compares values concerning statements (4) and (5).
Note that a strong consequence of these observations is that in particular, the proba-
bility for a large integer n to be prime can be approximated by 1/ log n and even better by
Li(n)/n.

11
π(x) 1 Li(x)
x π(x) x log x x

10 4 0.4 0.43429 0.51204


102 25 0.25 0.21715 0.29081
103 168 0.168 0.14476 0.17656
104 1229 0.1229 0.10857 0.12451
105 9592 0.09592 0.086859 0.096288
106 78498 0.078498 0.072382 0.078627
107 664579 0.066458 0.062042 0.066492
108 5761455 0.057615 0.054287 0.057622
109 50847534 0.050848 0.048255 0.050849

Table 6: Values concerning (4) and (5) for powers of 10

2.5 Estimate for the nth prime number

An important consequence of the Prime number theorem is the asymptotic approximation


of the nth prime number.
Corollary. Let us denote by pn the nth prime number. Then the following statement holds:
pn ∼ n log n, as n → ∞.
Proof. If pn is the nth prime number and π is the prime-counting function, as above, we
have that π(pn ) = n. Now, the Prime number theorem implies that
pn
n∼ , as n → ∞. (6)
log pn
Let us prove the following claim
log pn ∼ log n, as n → ∞.
By the above we have
 
pn
log n ∼ log = log pn − log log pn , as n → ∞. (7)
log pn
Hence, if we call m := pn and use that m → ∞ if n → ∞, we have that
log n (7) log m − log log m log log m
lim = lim = lim 1 −
n→∞ log pn m→∞ log m m→∞ log m
1 1
log m m
· 1
= lim 1 − 1 = lim 1 − =1
m→∞
m
m→∞ log m
where we have used L'Hôpital's rule in the second last step. So the claim is proven.
Finally, using 6 and the claim we obtain
pn ∼ n log pn ∼ n log n, as n → ∞.

12
Figure 8 compares the two functions n 7→ pn and n log n.

Figure 8: pn (-) and n log n (-) for n up to 5·107

2.6 Frequencies

We have read the article An observation on the distribution of primes (1967) by the math-
ematicians Myron Stein and Stanislaw Ulam. In this article, they study the following
problem. For each positive integer k consider the interval
Ik := [k, k + 1 + E(log k)],
where E(log k) stands for the nearest integer to log k. One can count how many primes
are in that interval, e.g. for some k's there will be no prime in it, for some other k's there
will be exactly one prime in it, for other ones two primes, etc.
Let n be a positive integer. Consider all the intervals Ik , for 1 ≤ k ≤ n, and count how
many primes are in each interval. We now dene the functions
Γm (n) := #{k ≤ n | Ik contains m primes}, n ∈ N∗ , m = 0, 1, 2, 3, . . . .
So Γ0 (n) gives the number of intervals Ik , k ≤ n, containing no prime, Γ1 (n) gives the
number of intervals Ik , k ≤ n, containing exactly one prime, and so on.
Now, we consider the frequencies of these classes by taking the ratio to n of every Γm
and dene
Γm (n)
γm (n) := .
n
13
So γ0 , γ1 , γ2 , . . . will be our frequencies.
Here are the values that we computed for these frequencies for m = 0, 1, . . . , 7. Note
that in the computation we considered E as the oor function, i.e. the largest previous
integer to the real number at which it is evaluated, in our case log k.

n Γ0 (n) Γ1 (n) Γ2 (n) Γ3 (n) Γ4 (n) Γ5 (n) Γ6 (n) Γ7 (n)


103 148 536 288 28 0 0 0 0
104 2077 4597 2845 468 13 0 0 0
105 23478 44552 26369 5290 309 2 0 0
106 259878 433227 244340 57130 5280 145 0 0
107 2761344 4224400 2360157 587101 64248 2743 7 0
108 28524990 41692764 23011210 5989090 742677 38740 529 0
109 294665626 412188810 224294627 60056203 8233204 546966 14476 88

Table 7: Values of Γm

n γ0 (n) γ1 (n) γ2 (n) γ3 (n) γ4 (n) γ5 (n) γ6 (n) γ7 (n)


103 0.148 0.536 0.288 0.028 0 0 0 0
104 0.2077 0.4597 0.2845 0.0468 1.3e-3 0 0 0
105 0.23478 0.44552 0.26369 0.05290 3.09e-3 0.2e-4 0 0
106 0.25988 0.43323 0.24434 0.05713 5.28e-3 1.45e-4 0 0
107 0.27613 0.42244 0.23602 0.05871 6.4248e-3 2.743e-4 0.07e-5 0
2·107 0.27851 0.42157 0.23424 0.05877 6.6305e-3 2.7335e-4 0.165e-5 0
4·107 0.28088 0.41943 0.23279 0.05952 7.0505e-3 3.2965e-4 0.327e-5 0
6·107 0.28453 0.41873 0.23040 0.05892 7.0641e-3 3.4133e-4 0.412e-5 0
8·107 0.28496 0.41767 0.23024 0.05950 7.2762e-3 3.6615e-4 0.496e-5 0
108 0.28525 0.41693 0.23011 0.05989 7.4268e-3 3.8740e-4 0.529e-5 0
2·108 0.28938 0.41553 0.22755 0.05956 7.5483e-3 4.1829e-4 0.704e-5 2.5e-8
4·108 0.29198 0.41380 0.22601 0.05983 7.8906e-3 4.8049e-4 1.040e-5 7.0e-8
6·108 0.29306 0.41299 0.22531 0.06004 8.0748e-3 5.1396e-4 1.253e-5 8.0e-8
8·108 0.29345 0.41241 0.22509 0.06028 8.2177e-3 5.3910e-4 1.408e-5 8.2e-8
109 0.29467 0.41219 0.22429 0.06006 8.2332e-3 5.4697e-4 1.448e-5 8.8e-8

Table 8: Values of γm

Now every function taking values in [0, 1] can converge to some a ∈ [0, 1] or diverge by
uctuating in the interval. We cannot state that the γm 's have nite limits for n → ∞,
but by observing the data we can conjecture, as Ulam and Stein do in their article, that
they converge. If this is true, we would be able to predict to which probability a given
interval Ik , k ∈ N, contains a certain number m of prime numbers. This would be another
signicant characterization of the distribution of primes.

14
3 Ulam spiral
3.1 History

In 1963, the mathematician Stanislaw Ulam discovered a method to visualize prime num-
bers. Ulam put the integers on a spiral where 1 stands in the middle and the other integers
circle in some way around it. With this visualization, called today Ulam spiral, he noticed
that prime numbers seemed to appear mostly on some diagonal lines. He recognized that
these lines were given by some quadratic polynomials which indeed generate large numbers
of primes.
To produce a big picture of the spiral, Ulam with collaborators Myron Stein and Mark
Wells used MANIAC II at Los Alamos Scientic Laboratory and created a spiral up to
65000 numbers.
Martin Gardner rst wrote about the Ulam spiral in his Mathematical Games column
in Scientic American, and the spiral featured on the front cover of the magazine.

3.2 Our Ulam spiral

We have reproduced the Ulam spiral in Matlab in the following way. At rst we placed 1
in the centre of the spiral. Then we placed 2 on the right side of 1 and 3 above 2. Hence we
directed our spiral counter-clockwise, such that it ends at the right lower corner. Figure 9
shows the procedure we have used.

17 16 15 14
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
2122 23 24 25
Figure 9: Ulam spiral up to 25

Therefore we have plotted spirals with an odd number of elements on each side and
hence a total odd number of elements on the spiral. Indeed, if n is the number of integers
on each side, then the spiral contains N = n2 integers.
We have plotted several spirals with dierent size. One can reproduce every gure by
using the Matlab code "Ulam_spiral". Here, you can see some of our results, in which we
indicate the values of n and N as dened above.

15
Figure 10: Ulam spiral with n = 201 and N = 40401

Figure 11: Ulam spiral with n = 251 and N = 63001

16
Figure 12: Ulam spiral with n = 401 and N = 160801

17
3.3 Comparison with random distribution

In order to verify the pattern of the prime distribution in the Ulam spiral, we have created
a spiral with random values that are distributed with the same probability as the prime
numbers, which we will compare with our initial Ulam spiral.
We specify briey how we have established this random spiral. At rst we deleted every
even number to get at least some pattern in the spiral. Then we chose some numbers to
be highlighted such that the highlighted numbers have the same probability distribution
as the prime numbers. For this, we used for each number n the probability p = log2 n to be
highlighted. Indeed the probability for an integer 1 ≤ k ≤ n, and in particular for n, to
be prime can be approximated by log1 n . Moreover, this value has to be doubled since we
deleted all even numbers.
Figure 13 shows our result for the random spiral with 401 elements on the side.

Figure 13: Random spiral with n = 401 and N = 160801

18
In order to compare both spirals, Figure 14 shows the Ulam spiral on the left and the
random spiral on the right, both with the side length of 251 elements.

Figure 14: Comparison between the Ulam spiral (left) and the random spiral (right) with
n = 251 and N = 63001

We notice that the distribution in the random spiral is very chaotic, while in the Ulam
spiral prime numbers can be found mostly along diagonal lines, i.e. they seem to follow a
non-random distribution. In fact, one cannot predict a number to be prime or not by a
formula (until now) but the primes on those lines can be given by some quadratic functions.
One can reproduce a random spiral by using rst the Matlab code "Probability_vector_
of_primes" and then "Random_Ulam_Spiral".

3.4 Lines of primes in the Ulam spiral

As we have mentioned above, the lines of primes we have observed on the Ulam spiral can
be given by some functions, in particular some quadratic polynomials. We will now discuss
how we have found the functions for some of the most dense lines and we will describe
them.
We show here again Figure 9 as it will be useful to the reader in the following steps.

17 16 15 14
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
2122 23 24 25

19
We will rst notice some basic facts. Let us consider the Ulam spiral as a sequence of
squares one inside the other, which are numbered in the following way: n = 0 corresponds
to the small square containing 1, n = 1 corresponds to the square containing 1, . . . , 9, n = 2
corresponds to the square containing 1, . . . , 25, and so on.
Then the side of the nth square contains 2n + 1 elements. Indeed this is true for
n = 0, 1, 2 as one can see on the gure above, and by induction, if it is true for n, the side
of the (n + 1)st square contains the same amount of elements as the side of the nth square
and 2 more, i.e.
(2n + 1) + 2 = 2n + 3 = 2(n + 1) + 1.
Thus, this is true also for n + 1.
A direct consequence of this statement is that the nth square contains (2n+1)2 elements.
This means that the largest element in the nth square, i.e. the element in the right lower
corner, is the square of an odd number, in particular of the (n+1)st odd number. Moreover,
the diagonal line (in fact, the ray or half-line) starting at 1 and containing 9, 25, . . . is given
by the function
f (n) = (2n + 1)2 = 4n2 + 4n + 1, n ∈ N.
Now we can also nd the function for the diagonal line containing 1, 3, 13, . . ., in the
following way. Let us consider the largest integer of the (n − 1)st square, i.e. (2n − 1)2 , for
n = 1, 2, . . .. If we want to obtain the smallest following integer which lies on that line, we
need to add the number of elements corresponding to the side of the nth square minus 1,
i.e.
(2n − 1)2 + (2n + 1) − 1 = 4n2 − 4n + 1 + 2n = 4n2 − 2n + 1.
Thus, the integers on the line are given by the function
g(n) = 4n2 − 2n + 1, n ∈ N.

This line can be translated to the left by adding a positive constant to the function
g . In particular, one of the most prime-dense lines is given by adding 40 to g , a constant
which we computed manually. So we nally get one of the quadratic polynomials we were
looking for:
p1 (n) = 4n2 − 2n + 41, n ∈ N. (8)
Note that the translated line to the left will only start from the nth square such that the
integer p1 (n) = g(n) + 40 lies on the same horizontal side as g(n), i.e. from the nth square
such that 40 ≤ 2n ⇔ n ≥ 20. In other words, all the integers p1 (n) for n = 0, . . . , 19 do
not lie on that line.
Figure 15 shows where the primes generated by p1 are located in the spiral.

20
Figure 15: Prime numbers generated by p1 in the Ulam spiral with 200 squares (401
elements on each side)

21
The following table gives the integers generated by p1 for n = 0, . . . , 100, highlighting
in red non-prime numbers. As we can see most of the integers in the table are prime, while
21 among the 101 generated integers are not prime.

n p1 (n) n p1 (n) n p1 (n) n p1 (n) n p1 (n)


0 41
1 43 21 1763 41 6683 61 14803 81 26123
2 53 22 1933 42 7013 62 15293 82 26773
3 71 23 2111 43 7351 63 15791 83 27431
4 97 24 2297 44 7697 64 16297 84 28097
5 131 25 2491 45 8051 65 16811 85 28771
6 173 26 2693 46 8413 66 17333 86 29453
7 223 27 2903 47 8783 67 17863 87 30143
8 281 28 3121 48 9161 68 18401 88 30841
9 347 29 3347 49 9547 69 18947 89 31547
10 421 30 3581 50 9941 70 19501 90 32261
11 503 31 3823 51 10343 71 20063 91 32983
12 593 32 4073 52 10753 72 20633 92 33713
13 691 33 4331 53 11171 73 21211 93 34451
14 797 34 4597 54 11597 74 21797 94 35197
15 911 35 4871 55 12031 75 22391 95 35951
16 1033 36 5153 56 12473 76 22993 96 36713
17 1163 37 5443 57 12923 77 23603 97 37483
18 1301 38 5741 58 13381 78 24221 98 38261
19 1447 39 6047 59 13847 79 24847 99 39047
20 1601 40 6361 60 14321 80 25481 100 39841

Table 9: Integers generated by p1 for n = 0, . . . , 100. Non-prime numbers are highlighted


in red.

22
Another quadratic polynomial generating many prime numbers is given by adding 100
to g :
p2 (n) = 4n2 − 2n + 101, n ∈ N.
In this case, only the integers p2 (n) with n ≥ 50 lie on the line.

Figure 16: Prime numbers generated by p2 in the Ulam spiral with 200 squares (401
elements on each side)

23
Another prime-dense line corresponds to the parallel line to p1 in the lower part of the
spiral. In order to nd the corresponding function, we proceed in a similar way to p1 .
Consider the largest integer of the nth square, i.e. (2n + 1)2 . Then the integers on the
line starting at 1 and containing 7, 21, . . . are given by subtracting 2n from (2n + 1)2 . The
equation we get is
h(n) = 4n2 + 2n + 1, n ∈ N.
Now, we translate this line to the right by adding a positive constant to h. In our case,
the line we want to obtain is given by adding 40:
p3 (n) = 4n2 + 2n + 41, n ∈ N.

As we have discussed above, the integers lying on the line are generated for n ≥ 20.

Figure 17: Prime numbers generated by p3 in the Ulam spiral with 200 squares (401
elements on each side)

24
Finally, a last example of quadratic polynomial that we want to discuss concerns a line
in the lower part of the spiral which is parallel to the one described by f . Indeed we can
translate this line to the right by adding 58 to f and we get the polynomial
p4 (n) = 4n2 + 4n + 59, n ∈ N.

In this case, p4 describes the line we have considered if n ≥ 28.

Figure 18: Prime numbers generated by p4 in the Ulam spiral with 200 squares (401
elements on each side)

All pictures can be reproduced with the Matlab codes Ulam_Spiral_Lines_fα with
α=1,2,3,4.

25
4 Klauber triangle
4.1 History

Before Ulam, the American herpetologist Laurence M. Klauber proposed already in 1932
a triangle which visualizes the prime numbers. In the original version of this triangle, he
begins with 1 at the top and in every row he extends the number of elements by two, such
that the nth row contains the numbers (n − 1)2 + 1 to n2 .
As in the Ulam spiral, the Klauber triangle shows that when prime numbers are high-
lighted a specic pattern can be observed in their distribution. Indeed, they seem to appear
mostly on some lines.

4.2 Our Klauber triangle

We have produced a slightly modied Klauber triangle in Matlab. We placed the integers
1, 2 and 3 on the rst row. Then every consecutive row is extended by two elements.
Hence the nth row contains 2n + 1 elements, in particular the integers between n2 and
(n + 1)2 − 1. See the picture below:

123
4 5678
9101112131415
161718192021222324
Figure 19: Klauber triangle up to 24

We have plotted several triangles with dierent size. One can reproduce every gure
by using the Matlab code "Triangle". Here you can see some of our results:

26
Figure 20: Klauber triangle with 100 rows

Figure 21: Klauber triangle with 200 rows

27
Figure 22: Klauber triangle with 300 rows

28
4.3 Comparison with random distribution

Here again, we will check, as for the Ulam spiral, if there is a certain pattern in the Klauber
triangle. We used the same method as in the previous named comparison, briey said, a
random distribution of highlighted numbers with the same probability as the primes. The
triangle is then implemented in the same way as the Klauber triangle is.
One can reproduce a random triangle by using rst the Matlab code "Probability_vector
_of_primes" and then "Random_Triangle". This is our random triangle plotted up to
250 rows:

Figure 23: Random triangle with 250 rows

In order to compare both spirals, Figure 24 shows the Klauber triangle on the left and
the random triangle on the right, both with 200 rows.
Again we can see that prime numbers seem to follow a certain pattern in their distri-
bution. If we observe our Klauber triangle, we clearly see some straight lines, but in the
random triangle, we cannot recognize any precise distribution. Then one could again nd
some quadratic formulas describing the lines in our triangle.

29
Figure 24: Comparison between the Klauber triangle (left) and the random triangle (right)
with 200 rows

4.4 Lines of primes in the Klauber triangle

We have looked for quadratic polynomials, with integer input, to describe some of the lines
which can be seen in the triangle.
First of all, let us calculate the last number in each row, which corresponds to the total
number of elements in the triangle, up to that row. As the rst row begins with 3 elements
and then every row has two elements more than the previous one, the ith row contains
2i + 1 integers and the total number of elements for the triangle of n ≥ 1 rows is given by
n
X
(2i + 1).
i=1

Now, this formula can be simplied:

n n  
X X n(n + 1)
(2i + 1) = 2 i+n=2 +n
i=1 i=1
2
= n + 2n = n2 + 2n + 1 − 1
2

= (n + 1)2 − 1.

Hence, the last element of the nth row is given by (n + 1)2 − 1, as we have mentioned
while introducing the Klauber triangle. Then, it follows that the rst element of the nth
row, which is given by the last element of the previous row plus 1, is equal to n2 .
In order to get the integers on the middle line, we notice that the middle value of each
row is exactly the average of the rst and the last value of that row:
n2 + (n + 1)2 − 1 n2 + n2 + 2n + 1 − 1
= = n2 + n.
2 2
Hence the integers in the middle vertical line are given by the polynomial:
ϕ(n) = n2 + n, n ≥ 0.

30
Now, every vertical line of the triangle can be computed by shifting the middle line to the
right or to the left by adding a constant c ∈ Z to ϕ.
To get for example the line on the right side of the triangle which begins at the last
element of the row 41, going straight down, we choose the formula
q1 (n) = n2 + n + 41, n ≥ 0.

The coloured integers in Figure 25 are only the primes given by this function.

Figure 25: Prime numbers given by q1 in the Klauber triangle with 200 rows

One can see that this function does not only give the vertical line we wished to represent,
but also the diagonal line beginning at the second last element of the 14th row (i.e. at 223)
and ending at the rst element of the 41st row (i.e. at 1681). This diagonal line goes from
the beginning to the end always 2 elements left in the next row, which can be empirically
veried.
Indeed if we want to calculate the polynomial generating this line, we consider the
vertical line starting at the last element of the 13th row, i.e. n2 + n + 13, and we subtract
2(n − 14), i.e. every row we climb down from the 13th one, we go two integers left. Then

n2 + n + 13 − 2(n − 14) = n2 + n + 13 − 2n + 28 = n2 − n + 41,

and after a change of variables from n to n + 1, we get


(n + 1)2 − (n + 1) + 41 = n2 + 2n + 1 − n − 1 + 41 = n2 + n + 41,

31
which is exactly q1 for 13 ≤ n ≤ 40.
After these computations, one can observe that for every vertical line given by n2 +n+c,
where c ∈ Z is an odd number, we get one or more diagonal lines for n smaller than c.
Here one can see two other lines calculated in the same way as the rst example.
One is given by
q2 (n) = n2 + n − 107

Figure 26: Prime numbers given by q2 in the Klauber triangle with 200 rows

The other one is given by


q3 (n) = n2 + n − 167.
See Figure 27.

32
Figure 27: Prime numbers given by q3 in the Klauber triangle with 200 rows

At last, we want to represent a line which is not vertical and which cannot be con-
structed using the same method of the previous lines.
We choose a line which is parallel to the left side of the triangle. A line with this
property is easy to calculate as the distance between each elements on this line and the
rst element of the same row is constant. This kind of lines are given by n2 + d where d is
a positive integer. An example is
q4 (n) = n2 + 58,

which is less prime-dense than the lines we have already discussed, as q4 (2k) is even for
every k ∈ N.
See Figure 28.

33
Figure 28: Prime numbers given by q4 in the Klauber triangle with 200 rows

All pictures can be reproduced with the Matlab codes Triangle_Lines_fα with α=
1,2,3,4.

34

You might also like