3
$\begingroup$

I need to perform some computations involving the Chebyshev function of the second kind (sometimes also called the summatory Von Mangoldt function) $\psi(x)$, defined as $$\psi(x) = \sum_{n\le x} \Lambda(n)$$

where $\Lambda(n)$ denotes the Von Mangoldt function. However, I am having trouble finding this function in Wolfram Mathematica* as well as in Wolfram Alpha, despite reading a large amount of documentation. Is this function included in the Wolfram language?


*I am using version 11.1

$\endgroup$
  • 1
    $\begingroup$ What's wrong with ψ[x_] := Sum[MangoldtLambda[n], {n, 2, x}]? $\endgroup$ – Carl Woll Aug 22 '17 at 7:41
  • $\begingroup$ @CarlWoll So there is no built-in function for it? $\endgroup$ – Klangen Aug 22 '17 at 7:44
  • $\begingroup$ Not that I'm aware of. $\endgroup$ – Carl Woll Aug 22 '17 at 7:45
  • $\begingroup$ @CarlWoll Then add it as an answer and I will accept it $\endgroup$ – Klangen Aug 22 '17 at 7:59
4
$\begingroup$

I don't believe the Chebyshev function you want is built-in to Mathematica. On the other hand, you can program it naively as:

ψ[x_] := Sum[MangoldtLambda[n], {n, 2, x}]

However, this function is rather slow. A much faster alternative is to use:

ψ2[x_] := Sum[Plus @@ Log[Prime @ Range @ PrimePi[x^(1/n)]], {n,Floor[N@Log[2, x]]}]

A speed comparison:

r1 = ψ[10^5]; //AbsoluteTiming
r2 = ψ2[10^5]; //AbsoluteTiming
r1 === r2

{4.6993, Null}

{0.059376, Null}

True

And, an example with an even larger argument:

ψ2[10^7]; //AbsoluteTiming

{7.49548, Null}

$\endgroup$
  • $\begingroup$ Thank you, that's the perfect answer $\endgroup$ – Klangen Aug 22 '17 at 8:32
  • 1
    $\begingroup$ You can replace Floor[N @ Log[2, x]] with IntegerLength[x, 2] - 1. $\endgroup$ – J. M. will be back soon Aug 22 '17 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.