# 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.

-

## 2 Answers

Here's Eric Weisstein's implementation from MathWorld:

````Primorial[0] := 1;
Primorial[1] := 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.♦ Apr 19 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
lang-mma
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 3, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.8941857218742371, "perplexity_flag": "middle"}