# Precision differences

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.

-
@NasserM.Abbasi, thanks for that effort. I think I have a bug. I'm in v.8 –  Fred Kline Dec 28 '12 at 11:43

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


-
+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. –  Fred Kline Dec 28 '12 at 18:40
@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] ? –  Artes Dec 28 '12 at 18:51
The second one---1/k^2 (but starting with k=1). –  Fred Kline Dec 28 '12 at 18:59
I misunderstood. Change the $-$ between the two terms to a $+$ to get zeta[2]. –  Fred Kline Dec 28 '12 at 19:34
@FredKline Just evaluate this Sum[1/k^2, {k, Infinity}] - Zeta[2] to understand what I mean. –  Artes Dec 28 '12 at 19:43

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 *)

-
+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? –  Fred Kline Dec 28 '12 at 11:17
That's my conclusion so far but let's wait for the experts. –  b.gatessucks Dec 28 '12 at 11:18
o.O Odd discrepancy with such high options for NSum –  ssch Dec 28 '12 at 11:25
With NSumTerms -> 50000 the error is about 10^-125 but it prints a NIntegrate::ncvb error message –  ssch Dec 28 '12 at 11:34
And if you use NSum with additional options Method -> "EulerMaclaurin" and Method -> "EulerMaclaurin", NSumTerms -> 50 the result seems to confirm the one from Sum. –  b.gatessucks Dec 28 '12 at 13:27