9

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.

Artes
  • 57,212
  • 12
  • 157
  • 245
Fred Daniel Kline
  • 2,360
  • 2
  • 20
  • 41

2 Answers2

8

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

Artes
  • 57,212
  • 12
  • 157
  • 245
4

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 *)
Artes
  • 57,212
  • 12
  • 157
  • 245
b.gates.you.know.what
  • 20,103
  • 2
  • 43
  • 84