Series and convergence tests
sum(term) is the series . 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 , and the method says so.
| method | statement | also returns |
|---|---|---|
| divergenceTest() | If the series diverges. If , nothing follows. | limit |
| ratioTest() | : converges absolutely if , diverges if . | limit |
| rootTest() | , with the same conclusions. | limit |
| comparisonTest() | Limit comparison with , which is summable exactly when , or and . | like, exponent, log, coefficient |
| integralTest() | For a positive decreasing term, and converge or diverge together. | from, integral |
| alternatingTest() | If the signs alternate and 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 . In the ratio the power leaves the constant 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 .
The sum, with a proven tail
Write with the sum of the terms up to and the tail. is computed exactly or enclosed. For one of these bounds is proven, and the result names it in by:
- Ratio. If for all with , then . The bound on the ratio is proven on the whole ray .
- Integral. For a positive decreasing term, . If the term is also convex, comparing the curve with trapezoids and with midpoint rectangles gives the much tighter 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 and , which gains several digits for slowly convergent series such as .
- Comparison. If only a bound is known (as for ), 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 is at most the next term, . s.termsForError(ε) runs the alternating test to find the index from which the sizes are proven to decrease, then finds the first with and by doubling and bisection, deciding each comparison from certified enclosures of the term. For and that is 31 terms, since .
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.
| call | returns |
|---|---|
| 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 |
@ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.