5

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}]
mmal
  • 3,508
  • 2
  • 18
  • 38
Surya
  • 81
  • 5

1 Answers1

15

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

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Stefan
  • 5,347
  • 25
  • 32
  • Can you tell me the numerical value – Surya Nov 14 '13 at 13:44
  • @Surya of what upper bound? – Stefan Nov 14 '13 at 14:04
  • Upper bound is infinity. – Surya Nov 14 '13 at 14:10
  • @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 Nov 14 '13 at 14:16
  • @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 Nov 14 '13 at 14:27
  • @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 Nov 14 '13 at 14:29
  • @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 Nov 14 '13 at 14:38
  • @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 Nov 14 '13 at 14:45
  • @Artes hmmm. understand. community-wiki? nevertheless. Thank's for the upvote. – Stefan Nov 14 '13 at 14:48
  • @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 Nov 14 '13 at 16:25
  • @KennyColnago thanks for the upvote and your faster square free check...which makes absolutely sense. – Stefan Nov 14 '13 at 17:09