Topic

Series and convergence tests

sum(term) is the series ∑an\sum a_n. Each convergence test of a calculus course is a method that returns its verdict together with the quantity that decided it, and sum() encloses the value of a convergent series: finitely many terms, plus an interval proven to hold all the rest.

const s = sum("1/n^2");
s.convergence();   // { convergence: "absolutely convergent", by: "comparison", reason: "|a(n)| behaves like 1·n^-2, …" }
s.partial(3);      // 49/36   exact
s.sum();           // { enclosure: [1.6449340656…, 1.6449340674…], terms: 512, tail: […], by: "integral bounds for a convex term: …", met: true }

sum("n/2^n").ratioTest();      // { test: "ratio", verdict: "convergent", limit: 1/2, reason: … }
sum("(-1)^n/n").convergence(); // conditionally convergent, by the alternating series test
sum("1/n").sum();              // refuses: the series diverges (comparison test: …)

The tests

Every test returns { test, verdict, reason, … } with verdict "convergent", "divergent" or "inconclusive". Inconclusive is a real answer: the ratio test says nothing about ∑1/n2\sum 1/n^2, and the method says so.

methodstatementalso returns
divergenceTest()If an↛0a_n \not\to 0 the series diverges. If an→0a_n \to 0, nothing follows.limit
ratioTest()L=lim⁡∣an+1/an∣L = \lim |a_{n+1}/a_n|: converges absolutely if L<1L < 1, diverges if L>1L > 1.limit
rootTest()L=lim⁡∣an∣1/nL = \lim |a_n|^{1/n}, with the same conclusions.limit
comparisonTest()Limit comparison with np(log⁡n)mn^p(\log n)^m, which is summable exactly when p<−1p < -1, or p=−1p = -1 and m<−1m < -1.like, exponent, log, coefficient
integralTest()For a positive decreasing term, ∑an\sum a_n and ∫a(x) dx\int a(x)\,dx converge or diverge together.from, integral
alternatingTest()If the signs alternate and ∣an∣|a_n| decreases to 0, the series converges.from

tests() runs all six, and convergence() picks the conclusion: absolutely convergent, conditionally convergent (the alternating test passes and the series of sizes is proven to diverge), divergent or undecided.

The limits in these tests are proven, not estimated. The term is first read as an=(±1)n qn⋅(factorials)⋅r(n)a_n = (\pm1)^n\, q^n \cdot (\text{factorials}) \cdot r(n). In the ratio an+1/ana_{n+1}/a_n the power leaves the constant qq and each factorial leaves a polynomial, exactly as when the ratio is simplified by hand, and what is left is handled by the asymptotic form of rr.

The sum, with a proven tail

Write S=SN+RNS = S_N + R_N with SNS_N the sum of the terms up to NN and RNR_N the tail. SNS_N is computed exactly or enclosed. For RNR_N one of these bounds is proven, and the result names it in by:

  • Ratio. If ∣an+1∣≤ρ ∣an∣|a_{n+1}| \le \rho\,|a_n| for all n≥Nn \ge N with ρ<1\rho < 1, then ∣RN∣≤∣aN+1∣/(1−ρ)|R_N| \le |a_{N+1}|/(1-\rho). The bound on the ratio is proven on the whole ray [N,∞)[N, \infty).
  • Integral. For a positive decreasing term, ∫N+1∞a≤RN≤∫N∞a\int_{N+1}^\infty a \le R_N \le \int_N^\infty a. If the term is also convex, comparing the curve with trapezoids and with midpoint rectangles gives the much tighter ∫N∞a dx−aN2  ≤  RN  ≤  ∫N+12∞a dx. \int_N^\infty a\,dx - \frac{a_N}{2} \;\le\; R_N \;\le\; \int_{N+\frac12}^\infty a\,dx . The improper integrals are the certified ones from Limits and improper integrals.
  • Alternating. The tail lies between 0 and its first term. If the sizes are convex as well, it lies between aN+1/2a_{N+1}/2 and −aN/2-a_N/2, which gains several digits for slowly convergent series such as ∑(−1)n/n\sum (-1)^n/n.
  • Comparison. If only a bound ∣an∣≤C np(log⁡n)m|a_n| \le C\,n^p(\log n)^m is known (as for sin⁡n/n2\sin n / n^2), the tail is at most the integral of the bound.

How many terms for a given error

For an alternating series whose term sizes decrease to 0, the error after the term n=Nn = N is at most the next term, ∣S−SN∣≤∣aN+1∣|S - S_N| \le |a_{N+1}|. s.termsForError(ε) runs the alternating test to find the index n0n_0 from which the sizes are proven to decrease, then finds the first NN with N+1≥n0N + 1 \ge n_0 and ∣aN+1∣≤ε|a_{N+1}| \le ε by doubling and bisection, deciding each comparison from certified enclosures of the term. For ∑(−1)n+1/n2\sum (-1)^{n+1}/n^2 and ε=1/1000ε = 1/1000 that is 31 terms, since 1/322=1/10241/32^2 = 1/1024.

NN is doubled until the enclosure is as narrow as digits asks (default 8) or maxTerms is reached; met says which. Whatever the width, the enclosure contains the sum.

callreturns
sum(term, { variable = "n", from = 1 })Series
s.term(n), s.partial(N)Rational when exact, else RationalInterval
s.divergenceTest(), s.ratioTest(), s.rootTest(), s.comparisonTest(), s.integralTest(), s.alternatingTest(){ test, verdict, reason, … }
s.tests()all six
s.termsForError(ε){ terms, last, bound, from, reason }: the error after the term last is at most bound = |a(last + 1)| ≤ ε; alternating series only
s.convergence(){ convergence, by, reason, test }
s.sum({ digits = 8, maxTerms = 8192 }){ enclosure, terms, upTo, partial, tail, by, met }; refuses for a divergent or undecided series
Try itEdit the code and run it with @ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs