Von Mangoldt function

5

3

Can anybody evaluate the following sum for me

$$ \sum\limits_{n=2}^\infty(-1)^n\left(\frac{\psi(n)}{n}-\frac{\Lambda(n)}{2n}\right) $$

where $\psi(n)$ is the Chebyshev function and $\Lambda(n)$ is the von Mangoldt function. Is there any efficient algorithm to evaluate such sum? I used the following code

f[n_]=Sum[MangoldtLambda[i],{i,1,n}];

Sum[(-1)^n(f[n]/n-MangoldtLambda[n]/(2n)),{n,2,Infinity}]

Surya

Posted 2013-11-14T08:42:38.037

Reputation: 81

What precisely is your problem? – Sjoerd C. de Vries – 2013-11-14T08:51:23.277

@stefan I expect the OP to say something like "I expect to get ..., because ... but I get ..." or "I get such and such error". – Sjoerd C. de Vries – 2013-11-14T08:56:45.680

As posted the code defined f as the product of two sums. I take it that was not your intention and I split the code in a definition part and a separate sum, which I suppose demonstrates your problem in some (still to explained) way. – Sjoerd C. de Vries – 2013-11-14T09:01:49.673

@stefan it is difficult to infer if that was the problem. If the OP had those lines of code in separate cells they probably would have worked. – Sjoerd C. de Vries – 2013-11-14T09:03:27.243

so if you want a ChebyshevPsi function you should got with: Log[LCM@@Range[n]] – Stefan – 2013-11-14T09:16:12.980

Answers

14

Number theory questions are always a huge accumulator for up votes. :)

From my experience I can say that the builtin MangoldtLambda function is pretty slow.

So let's define a Mangoldt function on our own. The Mangoldt function is defined by:

$\Lambda(n) \equiv \left\{ \begin{array}{1 1} \ln\ p & \quad \text{if n = $p^k$ for p a prime}\\ 0 & \quad \text{otherwise} \end{array} \right.$

This can be implemented as follows:

MangoldtΔ[n_] := If[Length[#] === 1, Log[#[[1, 1]]], 0] &[FactorInteger[n]]

Let's check some identities, if this implementation is correct:

$\sum_{d | n} \Lambda(d) = \ln\ n$

If we check this for n = 13:

Plus @@ (MangoldtΔ[#] & /@ Divisors[13])

==> Log[13]

Which is correct. Another identity is the following:

$\sum_{d | n} \mu(d)\ \ln(d) = -\Lambda(n)$ where $\mu$ is the Möbius function which is defined by:

$\mu(n) \equiv \left\{ \begin{array}{1 1} 0 & \quad \text{if $n$ has one or more repeated prime factors}\\ 1 & \quad \text{if $n=1$}\\ (-1)^k & \quad \text{if $n$ is a product of $k$ distinct primes} \end{array} \right.$

The first clause says nothing else but that n has to be square free:

MySquareFreeQ[n_] := Max[Last /@ FactorInteger[n]] < 2

(There is a SquareFreeQ function in Mathematica, so this is just if you're interested in how to implement such an algorithm)

Although there is a MobiusMu function in Mathematica we can define our own as well:

Moebiusμ[n_ /; MySquareFreeQ[n] == False] := 0
Moebiusμ[1] := 1
Moebiusμ[n_] := (-1)^Length@FactorInteger[n]

Now we can check this identity:

Plus @@ (Moebiusμ[n/#] Log[#] & /@ Divisors[13])

=> Log[13]

which is again correct.

Now let's do some timings with our new MangoldtΔ function:

Timing[Sum[MangoldtLambda[n], {n, 10^4}] // N]
=> {0.187940, 10013.4}

Timing[Sum[MangoldtΔ[n], {n, 10^4}] // N]
=> 0.065199, 10013.4}

We can see some improvement over time with our own implementation, but can we do better?

There is another identity with the Mangoldt which says:

$\psi(x) = \sum_{n \leq x} \Lambda(n)$

where $\psi(x)$ denotes the Chebyshev function. In my comments I already mentioned this function:

Chebyshevψ[x_] := Log[LCM @@ Range[x]]

Let's use the Chebyshevψ instead of Sum[Mangoldt...]:

Timing[ChebyshevPsi[10^4] // N]
=> {0.011974, 10013.4}

even better.

Equipped with these definitions and the proof of their correctness we can implement now your summation formula quite efficient:

Func[i_] := With[{iter = i}, 
    Sum[(-1)^n ((Chebyshevψ[n]/n) - (MangoldtΔ[n]/(2 n))), {n, 2, iter}]]


ListLinePlot[Table[Func[n], {n, 100}]]

Edit: Thank you Artes for pointing out the bug in (MangoldtΔ[n]/2 n)). Now this looks quite different.

enter image description here

Stefan

Posted 2013-11-14T08:42:38.037

Reputation: 5 207

Can you tell me the numerical value – Surya – 2013-11-14T13:44:21.887

@Surya of what upper bound? – Stefan – 2013-11-14T14:04:16.243

Upper bound is infinity. – Surya – 2013-11-14T14:10:44.040

@Surya then there is no numerical value, only a symbolic one. Infinity does not work for e.g. Range. i'm sorry but my solution does not work for infinity and this will be so as long as there is no lazy Range in Mathematica... – Stefan – 2013-11-14T14:16:29.803

@Stefan Not necessarily memoization, but whatever can avoid calculating the same values many times, e.g. computing Func[100] you compute Func for all smaller arguments so I guess memeoization might be a real improvement. – Artes – 2013-11-14T14:27:29.280

@Stefan Try e.g. Func[2] := (-1)^2 ((Chebyshevψ[2]/ 2) - (MangoldtΔ[2]/4)); Func[i_Integer] /; i >= 3 := Func[i] = Func[i - 1] + (-1)^ i ((Chebyshevψ[i]/i) - (MangoldtΔ[i]/(2 i))) and compare it computing ListLinePlot[Table[Func[n], {n, 1000}]] with your earlier Func. – Artes – 2013-11-14T14:29:43.113

@Artes Thank you! Now my laptop is burning! :) Please feel invited to edit my post and introduce your improvement and of course with your credits. I pretty much enjoy if others are interested too, especially with such valuable comments. – Stefan – 2013-11-14T14:38:27.680

@Stefan I upvoted your answer, but if you find another possible improvements you can use my proposal of Func or any better definition. I guess it would be better to edit an aswer only e few times to avoid making it community-wiki. – Artes – 2013-11-14T14:45:50.623

@Artes hmmm. understand. community-wiki? nevertheless. Thank's for the upvote. – Stefan – 2013-11-14T14:48:01.557

@Stefan +1 I found Max[FactorInteger[n][[All, 2]]] < 2 to be a faster definition for MySquareFreeQ when checking millions of n. Thanks for your definition of the Chebyshev function, much faster than my old code. – KennyColnago – 2013-11-14T16:25:04.417

@KennyColnago thanks for the upvote and your faster square free check...which makes absolutely sense. – Stefan – 2013-11-14T17:09:59.063