9
$\begingroup$

I run this sum and get the symbolic answer below :

Sum[ (1/(k^2 - k) - 1/k^2), {k, 2, Infinity}]

$2 - \frac{\pi^2}{6}$

I look up the sequence on OEIS and find these digits:

RealDigits[ N[ 2 - Pi^2/6, 105]]

{{3, 5, 5, 0, 6, 5, 9, 3, 3, 1, 5, 1, 7, 7, 3, 5, 6, 3, 5, 2, 7, 5, 8, 4, 8, 3, 3, 3, 5, 3, 9, 7, 4, 8, 1, 0, 7, 8, 1, 0, 5, 0, 0, 9, 8, 7, 9, 3, 2, 0, 1, 5, 6, 2, 2, 6, 4, 4, 4, 1, 7, 7, 0, 6, 2, 9, 9, 9, 2, 5, 2, 9, 5, 9, 6, 7, 9, 9, 1, 2, 6, 1, 6, 6, 3, 7, 1, 0, 9, 9, 3, 8, 0, 2, 4, 1, 2, 9, 4, 6, 9, 5, 9, 9, 5}, 0}

When I try to replicate those digits, I get some differences at the 27th digit.

RealDigits[ NSum[ (1/(k^2 - k) - 1/k^2), {k, 2, Infinity},
WorkingPrecision -> 105]]

{{3, 5, 5, 0, 6, 5, 9, 3, 3, 1, 5, 1, 7, 7, 3, 5, 6, 3, 5, 2, 7, 5, 8, 4, 8, 3, 2, 1, 5, 3, 5, 8, 4, 4, 8, 1, 8, 6, 0, 5, 0, 6, 9, 8, 9, 7, 9, 3, 3, 4, 8, 2, 1, 4, 0, 3, 2, 9, 8, 8, 0, 8, 5, 6, 2, 7, 0, 3, 0, 0, 8, 1, 8, 8, 4, 1, 0, 2, 5, 2, 8, 6, 3, 7, 0, 7, 4, 1, 8, 9, 3, 1, 3, 7, 3, 4, 0, 4, 0, 3, 0, 3, 2, 3, 5}, 0}

So, which is correct ? The symbolic sum or the NSum?

Edit I tried with a plus between the two sums, which returns Zeta[2] and I get the same variances starting at the $28$-th digit.

$\endgroup$
1
  • $\begingroup$ @NasserM.Abbasi, thanks for that effort. I think I have a bug. I'm in v.8 $\endgroup$ Commented Dec 28, 2012 at 11:43

2 Answers 2

8
$\begingroup$

One needn't wrap a number in N since we can get the same with RealDigits, e.g. :

RealDigits[ N[ 2 - Pi^2/6, 105]] == RealDigits[ 2 - Pi^2/6, 10, 105]
True    

While you can find the sum of the series symbolically with Sum which is assumed to yield exact expressions there is no reason to work numerically with NSum especially when very accurate results are needed. Having said that, one encounters this issue : Why do I get different results with Sum and NSum ?

The answer to this question takes into account playing with several options of numerical functions. Taking a look at the default settings of NSum :

Options[ NSum]
{ AccuracyGoal -> Infinity, Compiled -> Automatic, EvaluationMonitor -> None,
  Method -> Automatic, NSumTerms -> 15, PrecisionGoal -> Automatic,
  VerifyConvergence -> True, WorkingPrecision -> MachinePrecision }

we conclude that it works with a certain number of explicit terms (15 by default) and then it estimates the contribution of the remaining ones to the final result. One way of improving the accuracy of the result is to increase NSumTerms and setting appropriately WorkingPrecission etc. For various series appropriate settings may be different and one should play around a bit to find the optimal settings, however if we need e.g. 100 exact digits of the final result we should work with similar accuracy. To find 105 identical digits we had to set WorkingPrecision -> 210, AccuracyGoal -> 105 and increase NSumTerms -> 15000 :

RealDigits[ NSum[ 1/(k^2 - k) - 1/k^2, {k, 2, Infinity}, WorkingPrecision -> 210, 
                                          AccuracyGoal -> 105, NSumTerms -> 15000], 
            10, 105] ==
RealDigits[ 2 - Pi^2/6, 10, 105]
True

To sum up we should rely on Sum as far as we need exact results, since it is a very powerful function and it works well in a symbolic regime, nevertheless its range is more restricted than that of NSum, compare e.g. :

NSum[ 1/(k^3 + k^5 + k^7 + k^11), {k, Infinity}]  
Sum[ 1/(k^3 + k^5 + k^7 + k^11), {k, Infinity}]  

Even though one can get the exact sum, it takes much more time to evaluate and there are still many more series which cannot be summed up with Sum, while they are well estimated with NSum e.g.

NSum[ Sqrt[k]/k!, {k, 0, Infinity}]
Sum[ Sqrt[k]/k!, {k, 0, Infinity}]
 2.10176

enter image description here

$\endgroup$
6
  • $\begingroup$ +1, because I replaced the constant one with a sum that converges to one, this might be a pathelogical example. The pronic numbers may converge to one at a different rate than zeta[2] converges. $\endgroup$ Commented Dec 28, 2012 at 18:40
  • $\begingroup$ @FredKline In these both cases NSum cannot very accurately estimate the results. You should better use Sum wherever it would be possible. Which one does converge to Zeta[2] ? $\endgroup$
    – Artes
    Commented Dec 28, 2012 at 18:51
  • $\begingroup$ The second one---1/k^2 (but starting with k=1). $\endgroup$ Commented Dec 28, 2012 at 18:59
  • $\begingroup$ I misunderstood. Change the $-$ between the two terms to a $+$ to get zeta[2]. $\endgroup$ Commented Dec 28, 2012 at 19:34
  • $\begingroup$ @FredKline Just evaluate this Sum[1/k^2, {k, Infinity}] - Zeta[2] to understand what I mean. $\endgroup$
    – Artes
    Commented Dec 28, 2012 at 19:43
4
$\begingroup$

You can check the sum :

partialSum = Sum[(1/(k^2 - k) - 1/k^2), {k, 2, n}]
(* (-6 - 6 n + 12 n^2 - n^2 \[Pi]^2 + 6 n^2 PolyGamma[1, n])/(6 n^2) *)

and

Limit[partialSum, n -> Infinity]
(* 2 - \[Pi]^2/6 *)

What you find checks :

a = Sum[(1/(k^2 - k) - 1/k^2), {k, 2, Infinity}];
b = NSum[(1/(k^2 - k) - 1/k^2), {k, 2, Infinity}, WorkingPrecision -> 500,       
     AccuracyGoal -> Infinity, PrecisionGoal -> 500];

a-b
(* 1.2... x 10^-27 *)

Copy/paste from the link provided ;

oeis = {{3, 5, 5, 0, 6, 5, 9, 3, 3, 1, 5, 1, 7, 7, 3, 5, 6, 3, 5, 2, 
7, 5, 8, 4, 8, 3, 3, 3, 5, 3, 9, 7, 4, 8, 1, 0, 7, 8, 1, 0, 5, 0, 
0, 9, 8, 7, 9, 3, 2, 0, 1, 5, 6, 2, 2, 6, 4, 4, 4, 1, 7, 7, 0, 6, 
2, 9, 9, 9, 2, 5, 2, 9, 5, 9, 6, 7, 9, 9, 1, 2, 6, 1, 6, 6, 3, 7, 
1, 0, 9, 9, 3, 8, 0, 2, 4, 1, 2, 9, 4, 6, 9, 5, 9, 9, 5}, 0};

a - FromDigits[oeis] // N
(* 2.22045*10^-16 *)

b - FromDigits[oeis] // N
(* -1.20039*10^-27 *)
$\endgroup$
6
  • $\begingroup$ +1, Does this mean that the limit is the correct value and if I want to compare the digits I should use the symbolic value? $\endgroup$ Commented Dec 28, 2012 at 11:17
  • $\begingroup$ That's my conclusion so far but let's wait for the experts. $\endgroup$ Commented Dec 28, 2012 at 11:18
  • $\begingroup$ o.O Odd discrepancy with such high options for NSum $\endgroup$
    – ssch
    Commented Dec 28, 2012 at 11:25
  • 1
    $\begingroup$ With NSumTerms -> 50000 the error is about 10^-125 but it prints a NIntegrate::ncvb error message $\endgroup$
    – ssch
    Commented Dec 28, 2012 at 11:34
  • 1
    $\begingroup$ And if you use NSum with additional options Method -> "EulerMaclaurin" and Method -> "EulerMaclaurin", NSumTerms -> 50 the result seems to confirm the one from Sum. $\endgroup$ Commented Dec 28, 2012 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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