Skip to content

NSum ​

A numeric series -- a finite range summed directly, or a in b = Infinity accelerated to a tight, checked tolerance.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageNSum!
NSum(f, {n, a, b})the finite sum of f(n) for n from a to b (both integers).
NSum(f, {n, a, Infinity})the numeric value of the infinite series, accelerated and error-checked against a strict ~1e-12 relative tolerance (tightened internally to 1e-14 -- see details); declines rather than guess when the check doesn't clear it.
Typed signatures
TypePackageApplies
(expression, tuple<symbol, integer, infinity | integer>) -> numberanalyticalways

Domain: Calculus

Details
  • Two acceleration methods, chosen by how the terms behave (a term that doesn't shrink at all declines immediately, before either gets a chance): a term whose sign strictly alternates goes through Wynn's epsilon algorithm (a generalization of Aitken's Delta-squared process) on the partial sums -- exact to full double precision for the alternating harmonic series. Otherwise, a term asymptotic to a smooth power law C*n^-p (p estimated locally from two term ratios) goes through Euler-Maclaurin, truncated at its smallest correction term, cross-checked at three truncation depths (200/500/1000 direct terms) -- exact to full double precision for zeta(2) and zeta(3), and accurate to ~14 digits for the much more slowly convergent zeta(1.1).
  • The internal cross-check tolerance is 1e-14, two orders of magnitude tighter than the ~1e-12 this head promises: checked against mpmath and the true zeta values, the cross-check's OWN error estimate can be optimistic by 1-3 orders of magnitude on a series whose local power-law estimate is contaminated by a secondary term (e.g. n / (n^3 + 1)) or whose exponent sits very close to 1 (zeta(1.01)) -- the tighter internal bar is what keeps those correctly declining instead of reporting a false ~12 digits.
  • A term that's non-finite anywhere in the first 60 probed values (a domain edge, a pole) declines, as does any term sequence whose Solve-independent divergence check fails (the tail isn't actually shrinking).
  • Always numeric -- never returns an exact closed form; that is Sum's job, when a series has one.

Examples

Basic #

Sum 1/n^2 = pi^2/6, to full double precision

live ↗
InNSum(1n2,[n,1,∞])\mathrm{NSum}(\frac{1}{n^2}, \bigl\lbrack n, 1, ∞\bigr\rbrack)Out1.644 934 066 848 228 21.644\,934\,066\,848\,228\,2

Sum (-1)^(n+1)/n = ln 2, via Wynn's epsilon algorithm

live ↗
InNSum((−1)n+1n,[n,1,∞])\mathrm{NSum}(\frac{(-1)^{n+1}}{n}, \bigl\lbrack n, 1, ∞\bigr\rbrack)Out0.693 147 180 559 945 40.693\,147\,180\,559\,945\,4

Sum 1/n! from n=1 = e - 1, already stable before any acceleration is needed

live ↗
InNSum(1n!,[n,1,∞])\mathrm{NSum}(\frac{1}{n!}, \bigl\lbrack n, 1, ∞\bigr\rbrack)Out1.718 281 828 459 045 51.718\,281\,828\,459\,045\,5

A finite range needs no acceleration at all

live ↗
InNSum(n,[n,1,5])\mathrm{NSum}(n, \bigl\lbrack n, 1, 5\bigr\rbrack)Out1515
Scope #

Sum 1/n^1.1 = zeta(1.1) -- far slower than zeta(2), but Euler-Maclaurin still clears the bar

live ↗
InNSum(n−1.1,[n,1,∞])\mathrm{NSum}(n^{-1.1}, \bigl\lbrack n, 1, ∞\bigr\rbrack)Out10.584 448 464 950 80310.584\,448\,464\,950\,803
Possible issues #

Declines -- the harmonic series diverges

live ↗
InNSum(1n,[n,1,∞])\mathrm{NSum}(\frac{1}{n}, \bigl\lbrack n, 1, ∞\bigr\rbrack)OutNSum(1n,[n,1,∞])\mathrm{NSum}(\frac{1}{n}, \bigl\lbrack n, 1, ∞\bigr\rbrack)

Declines -- Sum n diverges (the terms don't shrink at all)

live ↗
InNSum(n,[n,1,∞])\mathrm{NSum}(n, \bigl\lbrack n, 1, ∞\bigr\rbrack)OutNSum(n,[n,1,∞])\mathrm{NSum}(n, \bigl\lbrack n, 1, ∞\bigr\rbrack)
About
Examples7
Checked againstWolfram Language 5 agree2 differ
CrosswalkWolfram Language

See also: Sum, NMinimize