the prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfadv...

16
Adv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function and its analytic approximations π ( x) and its approximations Tadej Kotnik Received: 25 May 2006 / Accepted: 24 November 2006 / Published online: 4 May 2007 © Springer Science + Business Media B.V. 2007 Abstract The paper describes a systematic computational study of the prime counting function π(x) and three of its analytic approximations: the logarithmic integral li(x) := x 0 dt log t , li(x) 1 2 li( x), and R(x) := k=1 μ(k)li(x 1/ k )/ k, where μ is the Möbius function. The results show that π(x)< li(x) for 2 x 10 14 , and also seem to support several conjectures on the maximal and average errors of the three approximations, most importantly |π(x) li(x)| < x 1/2 and 2 5 x 3/2 < x 2 (π(u) li(u))du < 0 for all x > 2. The paper concludes with a short discussion of prospects for further computational progress. Keywords Prime-counting function · Logarithmic integral · Riemann’s approximation Mathematics Subject Classifications (2000) 11A41 · 41A60 · 11Y35 · 65G99 1 Introduction The problem of approximating the prime-counting function π(x) (i.e. the number of primes x) by a smooth and fairly easily computable function has been studied in- tensively through the last two centuries. Already in 1792 or 1793, Gauss [6] observed that the logarithmic integral, li(x) := x 0 dt log t , approximates π(x) quite accurately. His later computations showed that li(x) slightly, yet consistently overestimates π(x) for Communicated by L. Reichel T. Kotnik (B ) Faculty of Electrical Engineering, University of Ljubljana, Tržaška 25, SI-1000 Ljubljana, Slovenia e-mail: [email protected]

Upload: others

Post on 07-Mar-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

Adv Comput Math (2008) 29:55–70DOI 10.1007/s10444-007-9039-2

The prime-counting function and its analyticapproximationsπ(x) and its approximations

Tadej Kotnik

Received: 25 May 2006 / Accepted: 24 November 2006 /Published online: 4 May 2007© Springer Science + Business Media B.V. 2007

Abstract The paper describes a systematic computational study of the primecounting function π(x) and three of its analytic approximations: the logarithmicintegral li(x) := ∫ x

0dt

log t , li(x) − 12 li(

√x), and R(x) := ∑∞

k=1 μ(k)li(x1/k)/k, where μ

is the Möbius function. The results show that π(x) < li(x) for 2 ≤ x ≤ 1014, andalso seem to support several conjectures on the maximal and average errorsof the three approximations, most importantly |π(x) − li(x)| < x1/2 and − 2

5 x3/2 <∫ x2 (π(u) − li(u))du < 0 for all x > 2. The paper concludes with a short discussion

of prospects for further computational progress.

Keywords Prime-counting function · Logarithmic integral ·Riemann’s approximation

Mathematics Subject Classifications (2000) 11A41 · 41A60 · 11Y35 · 65G99

1 Introduction

The problem of approximating the prime-counting function π(x) (i.e. the number ofprimes ≤ x) by a smooth and fairly easily computable function has been studied in-tensively through the last two centuries. Already in 1792 or 1793, Gauss [6] observedthat the logarithmic integral, li(x) := ∫ x

0dt

log t , approximates π(x) quite accurately. Hislater computations showed that li(x) slightly, yet consistently overestimates π(x) for

Communicated by L. Reichel

T. Kotnik (B)Faculty of Electrical Engineering, University of Ljubljana,Tržaška 25, SI-1000 Ljubljana, Sloveniae-mail: [email protected]

Page 2: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

56 T. Kotnik

2 ≤ x ≤ 3000000. Although Gauss does not seem to have conjectured explicitly thatπ(x) < li(x) holds for all x ≥ 2, this was widely believed to be true until 1914, whenLittlewood [12] proved that

π(x) − li(x) = �±(√

xlog log log x

log x

)

, (1)

from which it is clear that π(x) − li(x) changes sign infinitely often.Since then, several studies have focused on the smallest value of x with π(x) ≥

li(x), which will be denoted here by �. The first unconditional upper bound for � wasobtained in 1955 by Skewes [15], who showed that log10 log10 log10 log10 � < 3. Thiswas strengthened in 1966 by Lehman [11] to � < 1.65 × 101165, in 1987 by te Riele[16] to � < 6.69 × 10370, and in 2000 by Bays and Hudson [1] to � < 1.40 × 10316.The first lower bound for �, namely � > 3000000, followed from the computations ofGauss described above. This was improved in 1962 by Rosser and Schoenfeld [14] to� > 108, in 1975 by Brent [3] to � > 8 × 1010, and in 1993 by Odlyzko (unpublished)to � > 1.59 × 1013. In the present paper it is shown that � > 1014.

Another line of investigation focused on the order of magnitude of π(x) − li(x).To date, the strongest unconditional O-bound is

π(x) − li(x) = O(

x exp

(

−0.2098(log x)3/5

(log log x)1/5

))

,

which follows from a method developed in 1958 by Vinogradov [17] and Korobov[9], corrected in 1963 by Walfisz [20], and with the constant 0.2098 obtained in 2002by Ford [5]. Under the Riemann hypothesis, this can be strengthened considerably,and already in 1901 von Koch [18] showed that in this case

π(x) − li(x) = O(√

x log x) , (2)

which is still the strongest result of its kind. As (1) and (2) show, a proof of theRiemann hypothesis would bring the O- and �-bounds of π(x) − li(x) rather closetogether, but some space for improvements would remain. The results in the presentpaper suggest that (2) could be strengthened to at least O(

√x).

Alternative approximations of π(x) were also studied. In 1808, Legendre [10]observed that π(x) is approximated quite well by x

log x−B (he originally proposedB = 1.08366...), but de la Vallée Poussin [4] demonstrated in 1899 that with anyB, such approximations are inferior to li(x). Another alternative was proposed byRiemann [13], who in 1859 outlined a proof of an exact formula for π(x)

π(x) =∞∑

n=1

μ(n)

n

[

li(

x1n

)−

ρ

li(

n

)+

∫ ∞

x1/n

duu(u2 − 1) log u

]

, (3)

where μ is the Möbius function, and ρ runs through the nontrivial zeros of theRiemann zeta function. This formula, the proof of which was completed in 1895 byvon Mangoldt [19], suggested to Riemann that the series

R(x) :=∞∑

n=1

μ(n)

n li(

x1n

)= li(x) − 1

2li

(x

12

)− 1

3li

(x

13

)− 1

5li

(x

15

)+ 1

6li

(x

16

)− ...

Page 3: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

The prime-counting function and its analytic approximations 57

should be superior to li(x) in approximating π(x). Since π(x) − li(x) has zeros,it is nowadays clear that this cannot be the case for all x. Moreover, as− 1

2 li(x1/2) − 13 li(x1/3) − ... = O(

√x/ log x), which is smaller than the �-bound of

π(x) − li(x) in (1), it follows that π(x) − R(x) has this same �-bound. This impliesthat R(x) could at most be superior to li(x) on the average, in the sense that

∣∣∣∣

∫ x

2(π(u) − R(u))du

∣∣∣∣ <

∣∣∣∣

∫ x

2(π(u) − li(u))du

∣∣∣∣ for all sufficiently large x , (4)

but whether this is true remains to be resolved. It is, however, clear that even in thissense R(x) is no better than its first two terms alone, i.e. li(x) − 1

2 li(√

x), since in suchaveraging the role of the third and the following terms is asymptotically negligible(see [8], and the results in the present paper for some numerical evidence).

Finally, if (4) is false, li(x) could still be inferior to li(x) − 12 li(

√x) and R(x),

provided that

∫ x

2(π(u) − li(u))du < 0 for all x ≥ 2 , (5)

so that on the average li(x) would be biased strictly toward overestimating π(x). As-suming the Riemann hypothesis, Ingham [8] proved this inequality for all sufficientlylarge x, while its analogues for li(x) − 1

2 li(√

x) and R(x) are false, with the integralstaking both negative and positive values (see the results of this paper).

2 Methods of computation and processing

2.1 General

The program for computation and storage of the data was written in Delphi 6.0(Borland, Scotts Valley, CA, USA) and run on a PC with a 2.4 GHz Intel Pentium4 processor and 512 MB of RAM. All the integer variables were stored as 64-bitintegers (type Int64), and all the non-integer variables as 80-bit reals (type Extended,19-digit precision). The algorithms used for the computation of π(x), li(x), and R(x)

are described in Sections 2.2–2.4.As π(x) is constant between primes, and li(x) is strictly increasing, all local maxima

of π(x) − li(x) occur at primes. Thus, if π(x) − li(x) is negative at the start of aninterval and at all primes within it, then it is negative throughout this interval. Thismethod was used to verify the negativity of π(x) − li(x) for 2 ≤ x ≤ 1014.

Each decimal order of magnitude within the studied x-range was subdivided into2400 intervals of equal length on the logarithmic scale, i.e. into intervals Pk : xk ≤x < xk+1, with xk+1 := 101/2400xk. For the two x-values corresponding to the largestand the smallest value of π(x) − li(x) within each Pk, the values of li(x) − 1

2 li(√

x)

and R(x) were computed, and the set {x, π(x), li(x), li(x) − 12 li(

√x), R(x)} was

stored. The largest and the smallest values of∫ x

2 (π(u) − li(u) + 12 li(

√u))du and of∫ x

2 (π(u) − R(u))du within each Pk were also stored, while for∫ x

2 (π(u) − li(u))du,which is monotonic in the investigated x-range, the value at each xk was stored.

Page 4: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

58 T. Kotnik

2.2 The function π(x)

Computation of π(x) was based on an adaptation of the Eratosthenes sieve, withthe sieving interval partitioned into blocks of 2 × 3 × 5 × 7 × 11 × 13 × 17 × 19 =9699690 integers. Sieving of the first block with the primes ≤ 19 yielded the “small-prime variation” block that was used repeatedly as the initialization value forsubsequent blocks before sieving with the primes > 19. The computed π(x) wereperiodically checked with Mathematica 5.1 (Wolfram Research, Urbana, IL, USA)using the PrimePi routine, and no error was encountered.

2.3 The function li(x)

Computation of li(x) was based on the formula discovered by Ramanujan and provedin Berndt [2],

li(x) = γ + log log x + √x

∞∑

n=1

an logn x

where

an = (−1)n−1

n! 2n−1

�(n−1)/2�∑

m=0

1

2m + 1.

The values of li(x) were obtained by truncating the outer series at n = 75. Mathe-matica 5.1 was used to precompute the exact values of the coefficients a1, a2, .., a75,which were then rounded to 20-digit precision and stored in the program as constantsof type Extended. For x > 1010 linear interpolation was used in intervals [x, x + A],with A = 2310 up to x = 2 × 1012, A = 30030 up to x = 2 × 1013 , and A = 9699690up to x = 1014. Section A of the Appendix shows that in the computation of li(x)

using this algorithm, the absolute errors caused by truncation, interpolation, andfinite precision round-off are less than 6 × 10−11, 7 × 10−4, and 1.54 × 10−8√x ,respectively, everywhere in the range 2 ≤ x ≤ 1014.

2.4 The function R(x)

Computation of R(x) was based on the formula proved by Gram [7],

R(x) = 1 +∞∑

n=1

b n logn x

where

b n = 1

n! n ζ(n + 1)

with ζ denoting the Riemann zeta function. The values of R(x) were obtained bytruncating the series at n = 102. Mathematica 5.1 was used to precompute the valuesof the coefficients b 1, b 2, .., b 102, which were then rounded to 20-digit precision andstored in the program as constants of type Extended. Section B of the Appendixshows that in the computation of R(x) using this algorithm, the absolute errorscaused by truncation and finite precision round-off are less than 4 × 10−11 and1.22 × 10−3, respectively, everywhere in the range 2 ≤ x ≤ 1014.

Page 5: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

The prime-counting function and its analytic approximations 59

2.5 The integrals of π(x), li(x), and R(x)

For x ∈ N, x ≥ 3, we have

∫ x

2π(u)du =

x−1∑

n=2

π(n) ,

∫ x

2li(u)du = x li(x) − li(x2) − C1 ,

∫ x

2li(u1/2)du = x li(x1/2) − li(x3/2) − C2 ,

with C1 = −0.877257... and C2 = −2.209859... the values of the primitives at thelower limit of integration. The integrals of π(x), li(x), and li(x1/2) were computedusing these formulae and the algorithms described in Sections 2.2 and 2.3.

The series in Gram’s formula (see Section 2.4) can be integrated termwise, whichis justified by uniform convergence and continuity of the terms. Using

∫logn u du = n!u

n∑

m=0

(−1)n−m logm um!

this gives∫ x

2R(u)du = x

[

1 +∞∑

n=1

dn

n∑

m=0

(−1)n−m logm xm!

]

− C3 ,

where

dn = 1

n ζ(n + 1)

and C3 = 1.913594... is the value of the primitive at the lower limit of integration. Thevalues at the upper limit of integration were obtained by truncating the outer seriesat n = 102. Mathematica 5.1 was used to precompute the values of the coefficients d1,d2, .., d102, which were then rounded to 20-digit precision and stored in the program asconstants of type Extended. Section C of the Appendix shows that in the computationof

∫ x2 R(u)du using this algorithm, the absolute errors caused by truncation and finite

precision round-off are less than 3.27 × 10−11x and 1.90 × 10−15x2 (note that x2−ε =o(

∫ x2 R(u)du) for every ε > 0), respectively, everywhere in the range 2 ≤ x ≤ 1014.

3 Results and discussion

The computations show that π(x) < li(x) at all primes in the range 2 ≤ x ≤ 1014, fromwhich it follows (see Section 2.1) that � > 1014.

For convenience, we define

qN(x) := π(x) − ∑Nn=1

μ(n)

n li(x1/n)√x/ log x

.

Figures 1, 2, and 3 show q1(x), q2(x), and q∞(x), respectively, for 2 ≤ x ≤ 1014. Inthe strip at the bottom of Fig. 2, subintervals of [103, 1014] with |q2(x)| > |q1(x)| arepainted black. Similarly, in Fig. 3, subintervals of [103, 1014] with |q∞(x)| > |q1(x)|are marked in the upper strip, and those with |q∞(x)| > |q2(x)| in the lower strip.

Page 6: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

60 T. Kotnik

Fig. 1 q1(x) in the range 2 ≤ x ≤ 1014

The strips show that also in x-ranges where π(x) − li(x) is quite far from zero, li(x)

can be superior to li(x) − 12 li(

√x) and R(x), respectively, in approximating π(x).

Integrating by parts, we get

li(√

x) = 2√

xlog x

(

1 + O(

1

log x

))

,

so that

q1(x) − q2(x) = − li(√

x)/2√x/ log x

= −1 − O(

1

log x

)

Fig. 2 q2(x) in the range 2 ≤ x ≤ 1014

Page 7: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

The prime-counting function and its analytic approximations 61

Fig. 3 q∞(x) in the range 2 ≤ x ≤ 1014

and

q1(x) − q∞(x) = − li(√

x)/2 + O(x1/3/ log x)√x/ log x

= −1 − O(

1

log x

)

.

From the figures it appears that the nonoscillating component of q1(x) asymptoticallyapproaches −1, and those of q2(x) and q∞(x) asymptotically approach 0. Thebehavior of q1(x), q2(x), and q∞(x) also seems to suggest the following

Conjecture 1 For all x ≥ 2

|π(x) − li(x)| <√

x ,∣∣∣∣π(x) − li(x) + 1

2li(

√x)

∣∣∣∣ <

√x ,

|π(x) − R(x)| <√

x .

As x increases, the confinement of these three functions with respect to ±√x

(corresponding to the dashed lines in Figs. 1, 2 and 3) rapidly grows stronger, whichseems to suggest that their order is actually o(

√x), and perhaps even considerably

closer to Littlewood’s �-bound than to von Koch’s conditional O-bound, not tomention the Vinogradov–Korobov–Walfisz–Ford unconditional O-bound.

We now turn to the average errors of the three considered approximations. Inanalogy to the “normalization” used in qN(x), we define here

eN(x) :=1

x−2

∫ x2

(π(u) − ∑N

n=1μ(n)

n li(u1/n))

du√

x/ log x.

Figures 4, 5, and 6 show the plots of e1(x), e2(x), and e∞(x), respectively, in the range2 ≤ x ≤ 1014 (note that the vertical scale of Fig. 4 differs from those of Figs. 5 and 6).In the strip at the bottom of Fig. 6, subintervals of [103, 1014] with |e∞(x)| > |e2(x)|are painted black, showing that for x beyond billions, the average superiority of R(x)

Page 8: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

62 T. Kotnik

Fig. 4 e1(x) in the range 2 ≤ x ≤ 1014

over li(x) − 12 li(

√x) ceases to be the case. The two, however, appear to retain their

superiority over li(x), suggesting

Conjecture 2∣∣∣∣

∫ x

2(π(u) − li(u) + 1

2li(

√u))du

∣∣∣∣ <

∣∣∣∣

∫ x

2(π(u) − li(u))du

∣∣∣∣ for all x > 2.222 ,

∣∣∣∣

∫ x

2(π(u) − R(u))du

∣∣∣∣ <

∣∣∣∣

∫ x

2(π(u) − li(u))du

∣∣∣∣ for all x > 4.003 .

From the data it is also clear that∫ x

2 (π(u) − li(u))du remains negative for 2 ≤ x ≤1014, while

∫ x2 (π(u) − li(u) + 1

2 li(√

u))du and∫ x

2 (π(u) − R(u))du both take negative

Fig. 5 e2(x) in the range 2 ≤ x ≤ 1014

Page 9: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

The prime-counting function and its analytic approximations 63

Fig. 6 e∞(x) in the range 2 ≤ x ≤ 1014

and positive values; the former integral first becomes positive at x = 1.020... × 1011,and the latter at x = 1.201... × 102.

Assuming the Riemann hypothesis, it can be shown [8] that the unbounded oscilla-tions which contribute the factor �±(log log log x) in the integrands are smoothed outby the averaging, so that the oscillations in e1(x), e2(x), and e∞(x) are bounded. Thisis a key step in Ingham’s conditional proof that

∫ x2 (π(u) − li(u))du < 0 for sufficiently

large x (see Section 1), and from the data shown in Fig. 4 it appears that this mightwell be the case for all x ≥ 2. Together with the general behavior of e1(x), e2(x), ande∞(x), this suggests

Conjecture 3 For all x ≥ 2

−2

5x3/2 <

∫ x

2(π(u) − li(u))du < 0 ,

−1

5x3/2 <

∫ x

2(π(u) − li(u) + 1

2li(

√u))du <

1

5x3/2 ,

−1

5x3/2 <

∫ x

2(π(u) − R(u))du <

1

5x3/2 .

As x increases, the confinement of the integrals with respect to the conjecturedbounds (− 2

5 x3/2 corresponds to the dashed curve in Fig. 4, and the negative branchof ± 1

5 x3/2 to the dashed curves in Figs. 5 and 6) rapidly grows stronger.If the nonoscillating component of q1(x) asymptotically approaches −1 , it would

seem reasonable to assume that the nonoscillating component of e1(x) asymptoticallyapproaches − 2

3 . This also appears to be in agreement with the behavior of e1(x)

displayed in Fig. 4.

Page 10: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

64 T. Kotnik

4 Prospects for further progress

The computations presented in this paper took approximately six months to com-plete. The x-range covered turned out to be broad enough to provide specificexamples of several theoretically established properties of the three consideredapproximations of π(x), such as the values of x for which li(x) is closer to π(x)

than either li(x) − 12 li(

√x) or R(x), and the values of x for which the average

errors of li(x) − 12 li(

√x) and R(x) are positive. In principle, an extension to larger

x could shed additional light on the accuracy of certain tentative observations,such as the oscillations of e1(x) being asymptotically “centered” at − 2

3 , but forsubstantial improvements this extension would probably have to span far beyondthe computationally accessible x-range.

One of the rigorous results obtained in this paper, and from a certain perspectivealso its main finding, is the bound � > 1014. It is easy to envisage that usingmore powerful computers and/or distributing the computations among a number ofmachines, this aspect of the study could be extended by several orders of magnitude.Finding an x with π(x) > li(x) in this manner, however, does not appear very likely.Namely, the method used by Lehman [11], te Riele [16], and finally Bays and Hudson[1] in imposing upper bounds for � (see Section 1) can be used for generatingrough sketches of π(x) − li(x) forx -ranges far broader than those amenable to exactcomputation of π(x). Such sketches (see [1], p. 1291) suggest that � could perhapsbe in the vicinity of 10176, 10179, 10190, 10260, or 10298, but a smaller value seems quiteunlikely. A continuation of systematic computation of π(x) and li(x) at all primes canthus lead to improved lower bounds for �, but probably not to � itself. In view of theidle time on so many computers, this may still be a goal worth pursuing.

Acknowledgements I would like to thank Dr Jan van de Lune (Hallum, The Netherlands), ProfRichard P. Brent (Oxford University), and Prof Robert C. Vaughan FRS (Pennsylvania StateUniversity) for many instructive discussions and suggestions.

Appendix A: Error analysis for li(x)

A.1 The truncation error

Truncation of the exact formula

li(x) = γ + log log x + √x

∞∑

n=1

(−1)n−1 logn xn! 2n−1

�(n−1)/2�∑

m=0

1

2m + 1

at n = N results in an error E1(N, x) with

|E1(N, x)| <√

x∞∑

n=N+1

logn xn! 2n−1

�(n−1)/2�∑

m=0

1

2m + 1

(1)≤ √x

∞∑

n=N+1

logn x(n − 1)! 2n−1

(2)= 2t√

x∞∑

n=N+1

tn−1

(n − 1)!

Page 11: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

The prime-counting function and its analytic approximations 65

= 2t√

x∞∑

n=N

tn

n! = 2√

xtN+1

N!∞∑

n=0

tn N!(N + n)!

< 2√

xtN+1

N!∞∑

n=0

tn

(N + 1)n

(3)= 2√

xtN+1

N!1

1 − tN+1

=√

x logN+1 x2N N!

1

1 − log x2(N+1)

where in step (1) we used the fact that∑�(n−1)/2�

m=01

2m+1 ≤ n, in step (2) we wrote t :=log x

2 , and in step (3) we assumed that tN+1 < 1. With x ≤ 1014 and N = 75, this is the

case, and we get |E1(75, x)| < 5.84 × 10−11.

A.2 The interpolation error

Linear interpolation of the value of li(x) in the interval [x0, x0 + A] results in an error

U(x0, A, x) = li(x0) + li(x0 + A) − li(x0)

A(x − x0) − li(x) .

As li(x) is concave, U(x0, A, x) is convex everywhere and negative for x0 < x < x0 +A, and it clearly equals 0 at the endpoints of this interval. Thus the maximum of|U(x0, A, x)| in the interval [x, x2] is located at the only zero of the first derivative ofU(x1, x2, x), which is at

x = expA

li(x0 + A) − li(x0)

and hence

|U(x0, A, x)| ≤ −U(

x0, A, expA

li(x0 + A) − li(x0)

)

.

As x increases, the second derivative of li(x) approaches 0 monotonically, so that fora fixed A, the maximal error in the linear interpolation of li(x) decreases. Since inthis paper we used A1 = 2310 for x > 1010, A2 = 30030 for x > 2 × 1012, and A3 =9699690 for x > 2 × 1013, we obtain

|U(x0, A1, x)| ≤ −U(

1010, A1, expA1

li(1010 + A1) − li(1010)

)

< 1.3 × 10−7 for 1010 < x ≤ 2 × 1012,

|U(x0, A2, x)| ≤ −U(

2 × 1012, A2, expA2

li(2 × 1012 + A2) − li(2 × 1012)

)

< 7.1 × 10−8 for 2 × 1012 < x ≤ 2 × 1013,

|U(x0, A3, x)| ≤ −U(

2 × 1013, A3, expA3

li(2 × 1013 + A3) − li(2 × 1013)

)

< 6.3 × 10−4 for 2 × 1013 < x ≤ 1014.

Page 12: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

66 T. Kotnik

A.3 The round-off error

In this section, we use an underscore to indicate that the finite-precision valueobtained and/or stored by the computer is being considered. The absence of anunderscore will thus always mean that we are referring to the exact value. Thus ifa real number x is stored in a variable x with the precision of K digits, we have

(1 − 10−K+1)x < x < (1 + 10−K+1)x ,

as well as

(1 − 10−K+1)x < x < (1 + 10−K+1)x .

Since 80-bit reals have a precision of 19 digits, we may take K = 19 for all thenon-integer variables used in the computations presented here. As described inSection 2.3, the coefficients an in the sum

√x

75∑

n=1

an logn x

were precomputed and stored with 19-digit precision. Thus(1 − 10−18

) |an| < |an| <(1 + 10−18

) |an| .

For a term logn x, we have

(1 − 10−18

)2n (log

(1 − 10−18

)x)n

<(

log x)n

<(1 + 10−18)2n (

log(1 + 10−18) x

)n.

For the left-hand side of this inequality we have

(1 − 10−18

)2n (log

(1 − 10−18

)x)n

>(1 − 2n × 10−18

)(log x − 2 × 10−18)n

>(1 − 2n × 10−18

)(1 − 3 × 10−18)n logn x

>(1 − 2n × 10−18) (1 − 3n × 10−18) logn x

>(1 − 5n × 10−18) logn x ≥ (

1 − 3.75 × 10−16) logn x .

A similar result, with subtractions replaced by additions, follows for the right-handside of the same inequality. Therefore

∣∣∣∣∣an

(log x

)n − an logn x

∣∣∣∣∣< 3.77 × 10−16 |an| logn x ,

∣∣∣∣∣∣

75∑

n=1

an

(log x

)n −75∑

n=1

an logn x

∣∣∣∣∣∣< 3.77 × 10−16

75∑

n=1

|an| logn x .

Page 13: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

The prime-counting function and its analytic approximations 67

Also

∣∣∣√

x − √x∣∣∣ < 2 × 10−18√x

so that

∣∣∣∣∣∣∣

√x

75∑

n=1

an

(log x

)n − √x

75∑

n=1

an logn x

∣∣∣∣∣∣∣

< 3.8 × 10−16√x75∑

n=1

|an| logn x

≤ 3.8 × 10−16√x75∑

n=1

|an| logn 1014 < 1.54 × 10−8√x .

Appendix B: Error analysis for R(x)

B.1 The truncation error

Truncation of the exact formula

R(x) = 1 +∞∑

n=1

logn xn! n ζ(n + 1)

at n = N results in an error E2(N, x) > 0 with

E2(N, x) =∞∑

n=N+1

logn xn! n ζ(n + 1)

(1)<

∞∑

n=N+1

logn xn! n

=∞∑

n=N+1

logn xn2(n − 1)! <

1

(N + 1)2

∞∑

n=N+1

logn x(n − 1)!

= 1

(N + 1)2

∞∑

n=N

logn+1 xn! = logN+1 x

N! (N + 1)2

∞∑

n=0

logn x N!(N + n)!

<logN+1 x

N! (N + 1)2

∞∑

n=0

logn x(N + 1)n

(2)= logN+1 xN! (N + 1)2

1

1 − log xN+1

where in step (1) we used the fact that ζ(n + 1) > 1, and in step (2) we assumedthat log x

N+1 < 1. With x ≤ 1014 and N = 102, this is the case, and we get E2(102, x) <

3.27 × 10−11.

Page 14: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

68 T. Kotnik

B.2 The round-off error

As described in Section 2.4, the coefficients b n in the sum

102∑

n=1

b n logn x, where b n = 1

n! n ζ(n + 1)

were precomputed and stored with 19-digit precision. Proceeding similarly as inSection A.3 , we obtain

∣∣∣∣∣∣

102∑

n=1

b n

(log x

)n −102∑

n=1

b n logn x

∣∣∣∣∣∣< 3.77 × 10−16

102∑

n=1

b n logn x

< 3.77 × 10−16102∑

n=1

b n logn 1014 < 1.21 × 10−3 .

Appendix C: Error analysis for∫ x

2 R(u)du

C.1 The truncation error

Denote

RN(x) := 1 +N∑

n=1

logn xn! n ζ(n + 1)

.

Then∫ x

2R(u)du =

∫ x

2RN(u)du +

∫ x

2(R(u) − RN(u))du =

∫ x

2RN(u)du + E3(N, x) ,

where E3(N, x) > 0 and

E3(N, x) ≤∫ x

2|R(u) − RN(u)| du ≤ (x − 2) max

2≤u≤x|R(u) − RN(u)|

= (x − 2) E2(N, x) < x E2(N, x) .

From E2(102, x) < 3.27 × 10−11 it then follows that E3(102, x) < 3.27 × 10−11x.

C.2 The round-off error.

As described in Section 2.5, the coefficients dn in the sum

127∑

n=1

dn

n∑

m=0

(−1)n−m logm xm! , where dn = 1

n ζ(n + 1)

Page 15: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

The prime-counting function and its analytic approximations 69

were precomputed and stored with 19-digit precision, and the coefficients gm,n =(−1)n−m/m! were computed to the same precision. Proceeding similarly as inSection A.3, we obtain∣∣∣∣∣gm,n

(log x

)m − gm,n logm x

∣∣∣∣∣< 3.77 × 10−16 logm x

m! ,

∣∣∣∣∣∣

n∑

m=0

gm,n

(log x

)m−n∑

m=0

gm,n logm x

∣∣∣∣∣∣< 3.77×10−16

n∑

m=0

logm xm!

< 3.77 × 10−16∞∑

m=0

logm xm! = 3.77 × 10−16x ,

∣∣∣∣∣∣∣dn

n∑

m=0

gm,n

(log x

)m − dn

n∑

m=0

gm,n logm x

∣∣∣∣∣∣∣< 3.8 × 10−16dnx ,

∣∣∣∣∣∣∣∣

x127∑

n=1

dn

n∑

m=0

gm,n

(log x

)m − x127∑

n=1

dn

n∑

m=0

gm,n logm x

∣∣∣∣∣∣∣∣

< 3.8 × 10−16x2127∑

n=1

dn

< 1.9 × 10−15x2 .

References

1. Bays, C., Hudson, R.: A new bound for the smallest x with π(x) > li(x). Math. Comp. 69, 1285-1296 (2000)

2. Berndt, B.C.: Ramanujan’s Notebooks, Part IV. pp. 126–131. Springer, New York (1994)3. Brent, R.P.: Irregularities in the distribution of primes and twin primes. Math. Comp. 29, 43–56

(1975)4. de la Vallée Poussin, C.J.: Sur la fonction ζ(s) de Riemann et le nombre des nombres premiers

inférieurs à une limite donnée. Mem. Cour. Acad. Roy. Belg. 59, 1 (1899)5. Ford, K.: Vinogradov’s integral and bounds for the Riemann zeta function. Proc. London Math.

Soc. 85, 565–633 (2002)6. Gauss, C.F.: Werke, Vol. II. Königliche Gesellschaft der Wissenschaften zu Göttingen, pp. 444–

447 (1863)7. Gram, J.P.: Undersøgelser angående Mængden af Primtal under en given Grænse. Kong. Dansk.

Videnskab. Selsk. Skr. (VI) 2, 183–308 (1884)8. Ingham, A.E.: The distribution of prime numbers, pp. 105–106. Cambridge University Press, New

York (1932)9. Korobov, N.M.: Estimates of trigonometric sums and their applications. Usp. Mat. Nauk. 13,

185–192 (1958) (in Russian)10. Legendre, A.M.: Essai sur la théorie des nombres, 2ème dition, p.394. Courcier, Paris (1808)11. Lehman, R.S.: On the difference π(x) − li(x). Acta Arith. 11, 397–410 (1966)12. Littlewood, J.E.: Sur la distribution des nombres premiers. C. R. Acad. Sci. Paris 158, 1869–1872

(1914)13. Riemann, B.: Ueber die Anzahl der Primzahlen unter einer gegebenen Grösse. Monatsber.

Preuss. Akad. Wiss. 1859 671–680 (1859)14. Rosser, J.B., Schoenfeld, L.: Approximate formulas for some functions of prime numbers. Illinois

J. Math. 6, 64–94 (1962)15. Skewes, S.: On the difference π(x) − li(x). II. Proc. London Math. Soc. (3) 5, 48–70 (1955)

Page 16: The prime-counting function and its analytic approximationslbk.fe.uni-lj.si/pdfs/aicm2008.pdfAdv Comput Math (2008) 29:55–70 DOI 10.1007/s10444-007-9039-2 The prime-counting function

70 T. Kotnik

16. te Riele, H.J.J.: On the sign of the difference π(x) − li(x). Math. Comp. 48, 323–328 (1987)17. Vinogradov, I.M.: A new estimate for ζ(1 + it) [in Russian]. Izv. Akad. Nauk SSSR, Ser. Mat. 22,

161–164 (1958)18. von Koch, H.: Sur la distribution des nombres premiers. Acta Math. 24, 159–182 (1901)19. von Mangoldt, H.: Zu Riemann’s Abhandlung ‘Ueber die Anzahl der Primzahlen unter einer

gegebenen Grösse’. J. Reine Angew. Math. 114, 255–305 (1895)20. Walfisz, A.: Weylsche Exponentialsummen in der neueren Zahlentheorie, pp. 175-188. VEB

Deutscher Verlag, Berlin (1963)