Primes and the Zeta Function

Math 242 Modern Computational Mathematics

The Riemann Zeta Function

The Riemann zeta function is one of the most important functions in number theory, with deep connections to π — in fact, deep connections the prime counting function π(x) and to the circle constant π=3.14159.... The zeta function is defined:

ζ(s)=(∑_(n=1)^∞)(1/(n^s))

Note that this function has the form of a p-series, which you may remember from Calculus II. Although the series above only converges for s>1, the zeta function can be extended to the complex plane via analytic continuation, resulting in the Riemann zeta function.

Computing values of ζ(s)

Let's start with ζ(2). That is, we want to compute (1/(1^2))+(1/(2^2))+(1/(3^2))+(1/(4^2))+….  Computing this sum is known as the Basel Problem, first posed in 1650 and solved by Euler in 1734.

The function zeta[s] below approximates ζ(s) by adding up the first one million terms of the sum . To do this quickly, we’ll use the N (“numeric”) function to convert each fraction to a decimal with 40 digits of precision.

zeta[s_]:=Sum[N[n^(-s),40],{n,1,1000000}]

Try it out, approximating ζ(2):

zeta[2]

Exercise 1

Find an exact value for the number ζ(2). Here is one approach: type its first few digits of the approximation into the Online Encyclopedia of Integer Sequences. For example, enter the digits 1, 6, 4, 4, 9, 3 and click Search. What number do you think is equal to ζ(2)?

Now try ζ(3). Can you find an exact value for this?

Compute values of ζ(n) for positive integers n up to n=10 or so? Do you see any patterns?

Values in the Complex Plane

The function ζ(s) can be extended to the entire complex plane by the process of analytic continuation. This means that there is another function defined on the complex plane, that agrees with (∑_(n=1)^∞)(1/(n^s)) for s>1, and that is complex differentiable in a neighborhood of every point in the complex plane (except s=1).

In Mathematica, the Rieman zeta function is implemented as Zeta[s], where s can be any complex number.

The Riemann zeta function has many interesting values. For example, what is ζ((1/2))? Find out:

Zeta[0]

Exercise 2

What are the values of ζ(s) when s is a negative integer? Do you notice any patterns? If you find a negative integer s such that ζ(s)=0, then you have found a “trivial” zero of the Riemann zeta function.

Visualizing ζ(s)

It is tough to visualize graphs of complex-valued functions. Since the domain and range each have two real dimensions, plotting the graph of a complex-valued function would require four dimensions! Since we don’t have four spatial dimensions, we’ll have to do something else.

Domain Coloring

One common approach for visualizing a function f:ℂ→ℂ is to color each point z of the complex plane according to the value of f(z). For example, if f(z)=r (e^(i θ)), we could color z such that θ determines the hue of the color and r determines the brightness of the color.

The next plot shows the complex plane colored according to this scheme. First, we define a “paint” function, and then we produce the plot.

paint[z_]:=Module[{},
color=Hue[Rescale[Arg[-z],{-Pi,Pi}]];
shade=Exp[-Abs[z]]/1.3;
Darker[color,shade]
]

ParametricPlot[{x,y},{x,-5,5},{y,-5,5},ColorFunction->Function[{x,y},paint[x+y I]],ColorFunctionScaling->False,PlotPoints->{100,100},PlotRangePadding->0,ImageSize->250,Axes->False,FrameLabel->{"real","imaginary"}]

Note that in this plot, the positive real numbers are red (■) and negative real numbers are cyan (■). Numbers on the positive imaginary axis are green (■), and numbers on the negative imaginary axis are purple (■). Darker colors mean that the number is closer to zero (that is, smaller in absolute value). Points very close to the origin are almost black.

Domain coloring the Riemann zeta function

Now we will color the complex plane by the values of the Riemann zeta function.

ParametricPlot[{x,y},{x,-20,20},{y,-30,30},ColorFunction->Function[{x,y},paint[Zeta[x+y I]]],ColorFunctionScaling->False,PlotPoints->{200,300},PlotRangePadding->0,ImageSize->300,Axes->False,FrameLabel->{"real","imaginary"}] // Quiet

From the plot, we can see the trivial zeros on the negative real axis. We can also see the “pole” of the function, where the function blows up to infinity, at (1,0). These features are easier to see if we zoom in:

ParametricPlot[{x,y},{x,-24,4},{y,-4,4},ColorFunction->Function[{x,y},paint[Zeta[x+y I]]],ColorFunctionScaling->False,PlotPoints->{280,80},PlotRangePadding->0,ImageSize->500,Axes->False,FrameLabel->{"real","imaginary"}] // Quiet

The Riemann hypothesis says that the non-trivial zeros of ζ(s) all have real part (1/2). This is considered to be one of the greatest unsolved problems in mathematics. More than 1 trillion nontrivial zeros of ζ(s) have been computed numerically, and so far they all have real part (1/2). The hypothesis appears to be true, but no one has found a proof.

In our domain coloring, we can see some nontrivial zeros on the line Re(s)=(1/2). Again, zoom in:

ParametricPlot[{x,y},{x,-4,6},{y,-2,28},ColorFunction->Function[{x,y},paint[Zeta[x+y I]]],ColorFunctionScaling->False,PlotPoints->{100,300},PlotRangePadding->0,ImageSize->200,Axes->False,FrameLabel->{"real","imaginary"}] // Quiet

Exercise 3

Modify the code above to produce a domain coloring of the sine function on the complex plane. Where are the zeros of the sine function? Confirm that the domain coloring agrees with what you know about the sine function on the real line.

Nontrivial Zeros of ζ(s)

Computing the nontrivial zeros of ζ(s) is challenging. (Shall we say it’s “nontrivial”?) Fortunately, Mathematica provides a built-in function, ZetaZero[k], that gives the (k^th) nontrivial zero of the Riemann zeta function. For example:

N[ZetaZero[1]]

As expected, the real part of this zero is 0.5. The imaginary part is about 14.1347. Does this agree with the location of a zero in the domain coloring plot above?

We can also ask Mathematica for a bunch of nontrivial zeros:

ZetaZero /@Range[10] //N

Do these zeros agree with what you observe in the domain coloring plot?

For one further visualization, we can plot the real and imaginary parts of ζ(s) along the line Re(s)=(1/2).

Plot[{Re[Zeta[1/2+I*t]],Im[Zeta[1/2+I*t]]},{t,0,50},PlotLegends->{"real","imaginary"},AspectRatio->1/3]

The zeros occur where the real and imaginary parts are simultaneously equal to zero. Confirm that the location of zeros given by the plot above agree with the values returned by ZetaZero.

Connection to Primes

One connection between the Riemann zeta function and prime numbers is given by Euler’s product formula:

ζ(s)=(∑_(n=1)^∞)(1/(n^s))=(∏_(p prime))(1/(1-(p^(-s))))

Is this a surprising formula?

Exercise 4

Compute an approximation of the infinite product above using the first k primes. (You decide what values of k to use, but try several different numbers.) Do your approximations agree with ζ(s)? Try several values of s.

Another approximation of the prime-counting function

The following function, which involves the Riemann zeta function, is a very good approximation to the prime-counting function:

R(x)=1+(∑_(k=1)^∞)((((ln x))^k)/(k k! ζ(k+1)))

Since we can’t actually add infinitely many terms of a sum, we will define the function with a finite sum and a parameter m that determines how many terms are in the sum:

r[x_,m_]:=1+Sum[Log[x]^k/(k*k!*Zeta[k+1]),{k,1,m}]

Plot the prime counting function and the approximation:

n=100;
countPlot=Plot[ PrimePi[x], {x,0,n} ];
rPlot=Plot[ r[x,20],{x,1,n},PlotStyle->Red];
Show[countPlot,rPlot]

A very cool approximation

The second Chebyshev function ψ(x) is a variant on the prime counting function. It counts not only primes, but prime powers. The function is:

ψ(x)=(∑_((p^k)≤ x))ln(p)=(∑_(p≤x))⌊(Subscript[log, p])(x)⌋ln(p)

The first sum above is over all prime powers not exceeding x; the second sum is over all primes not exceeding x. We will define the function for Mathematica and make a plot:

ψ[x_]:=Sum[ If[PrimeQ[p],Floor[Log[x]/Log[p]]Log[p],0],{p,2,x}];
n=50;
psiPlot=Plot[ψ[x],{x,0,n},PlotStyle->Orange]

Notice that the second Chebyshev function is not continuous. However, it can be approximated by a continuous function that involves the nontrivial zeros of the Riemann zeta function! The approximation function is:

(Subscript[ψ, 0])(x)=x-ln(2π)-(∑_ρ)((x^ρ)/ρ)-(1/2)ln(1-(x^(-2)))

Here, the sum is over all nontrivial zeros ρ of the Riemann zeta function. Since we can’t sum over infinitely many zeros, we will define (Subscript[ψ, 0]) in Mathematica using a finite sum, with a parameter m that determines how many zeros we use. Note that we are using ZetaZero to obtain values of the zeros.

ψ0[x_,m_]:= x-Sum[2*Re[(x^ZetaZero[k])/ZetaZero[k]],{k,1,m}]-Log[2Pi]-Log[1-x^(-2)]/2

Here is a plot, with (Subscript[ψ, 0]) evaluated using 20 zeros of the Riemann zeta function:

Plot[ψ0[x,20],{x,0,50},PlotStyle->Purple]

The function (Subscript[ψ, 0]) converges remarkably to ψ as we increase the number of terms in the sum. Here is an interactive window with a slider that controls the number of terms in the sum:

Manipulate[ Show[psiPlot, Plot[ψ0[x,m],{x,0,50},PlotStyle->Purple]], {m,0,100,1}]

Incredible! As we include more and more zeros of the Riemann zeta function, the continuous function (Subscript[ψ, 0]) converges to the prime-counting function ψ!

Consequences of the Riemann Hypothesis

Mathematicians have produced many propositions that depend on the Riemann hypothesis. If the Riemann hypothesis is true, then all of these propositions are true as well. These propositions have to do with the error term in the prime number theorem, gaps between primes, counting primes mod k, and much more. Wikipedia has a list of some consequences of the Riemann hypothesis here.

One intriguing result

We previously encountered the prime-counting function π(x), which gives the number of primes less than or equal to x. We also observed that π(x) is approximated quite well by the logarithmic integral function Li(x).

Plot[{PrimePi[x],LogIntegral[x]},{x,1,100},PlotLegends->{"π(x)", "Li(x)"}]

From the graph above we see that π(x)<Li(x) when 0<x<100. In fact, it is known that π(x)<Li(x) for x up to (10^23). However, in 1914, Littlewood proved that the difference π(x)-Li(x) changes sign infinitely many times.

Littlewood' s proof involves two cases: he proved that the theorem is true assuming that the Riemann hypothesis is true, and he also proved that the theorem is true assuming that the Riemann hypothesis is false! Thus, Littlewood’s theorem is true regardless of the Riemann hypothesis.

Interestingly, Littlewood’s proof does not provide a specific number x such that π(x) > Li(x). In 1933, Skewes proved that if the Riemann hypothesis is true, there exists a number x such that π(x)>Li(x) less than

(10^(10^(10^34))).

If the Riemann hypothesis is true, there exists an x such that that π(x)>Li(x) less than

(10^(10^(10^964))).

More recent work has shown that π(x)>Li(x) for some x less than 1.4×(10^316).

Bonus Questions

Does the sum of the reciprocals of primes converge? In other words, is the sum

(∑_(p prime))(1/p) = (1/2)+(1/3)+(1/5)+(1/7)+(1/11)+...

convergent or divergent?

Does the sum of the reciprocals of twin primes converge? In other words, is the sum

(∑_(p : p, p+2 prime))((1/p)+(1/(p+2))) = ((1/3)+(1/5))+((1/5)+(1/7))+((1/11)+(1/13))+...

convergent or divergent?