# Where is the Chebyshev function of the second kind in Mathematica/Alpha?

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

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

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}

• Thank you, that's the perfect answer Aug 22, 2017 at 8:32
• You can replace Floor[N @ Log[2, x]] with IntegerLength[x, 2] - 1. Aug 22, 2017 at 8:54