# Plotting Chebyshev's theta function $\vartheta(x)$

The function I would like to plot is defined as $\sum\limits_{p\leq x}\log p.$ The following gives me I think a plot of the points of interest, but the function is defined for all $x > 0$ and so it's basically a step function between primes. Is there a way to augment the following to include the "steps?"

a8 = Table[Sum[Log[Prime[i]], {i, 1, j}], {j, 1, 10}];

a7 = Table[Prime[i], {i, 1, 10}];

a9 = Table[{a7[[i]], a8[[i]]}, {i, 1, 10}];

ListPlot[a9]


Thanks for any suggestions.

Here's Eric Weisstein's implementation from MathWorld:

Primorial := 1;
Primorial := 2;
Primorial[n_] := Primorial[n] = Prime[n] Primorial[n - 1];
ChebyshevTheta[n_] := Log[Primorial[PrimePi[n]]]

Plot[ChebyshevTheta[x], {x, 0, 100}] Many MathWorld pages have attached notebooks linked near the top of the page. That's where this came from.

• Thank you I had seen this but did not realize there was code to be found. – daniel Dec 12 '12 at 21:48
• @daniel Yes, the code is the best part of the answer! – Mark McClure Dec 12 '12 at 21:49
• You might need some more PlotPoints in there to get rid of that wee glitch in the middle. – wxffles Dec 13 '12 at 0:52
• It might be more prudent to just add logarithms directly instead of multiplying a bunch of primes before taking the logarithm. – J. M.'s discontentment Apr 19 '13 at 16:39

Trying to stay as close to your definitions as possible, one may actually want to avoid Plot because it will have trouble when the number of discontinuities is too large to be properly resolved for a given choice of PlotPoints. Instead, as you already started out doing, one can use a list plot. But to get lines, you should use ListLinePlot and define the corners of the step functions:

n = 50;

a8 = Table[Sum[Log[Prime[i]], {i, 1, j}], {j, 1, n}];

a7 = Table[Prime[i], {i, 1, 50}];

a9 = Transpose[{a7, a8}];

a10 = Transpose[{Rest[a7], Most[a8]}];

ListLinePlot[Riffle[a9, a10]] This guarantees all steps to be nicely rectangular. Here, the number of jumps is given by n = 50.

What I did is to simplify your definition of a9 without changing it, and then adding a list a10 where all the x-values are shifted to the right in order to define the right side of each horizontal segment. These two lists a9 and a10 are then combined with Riffle so that elements from each list alternate, giving the desired line.

You can increase n without having to worry about the PlotPoints option in Plot.

• Thank you, I hadn't seen "Riffle" before. This is a nice idea and I did notice for large n a lot of error messages before the Weisstein implementation actually displayed the graph. +1 – daniel Dec 13 '12 at 15:49