Sequences
A sequence is a formula in a whole number n, or a rule that makes each term from the one before. sequence and recursive give terms exactly, limits with a proof, and statements such as "decreasing from n = 3 on" that hold for every later term and not only the ones looked at.
const a = sequence("(1 + 1/n)^n");
a.terms(3); // [2, 9/4, 64/27] exact
a.limit(); // an interval of width 10^-20 around e
a.bounds(); // { lower, upper, bounded: true }: every term lies between them
const b = sequence("n/(n^2 + 10)");
b.monotone(); // { direction: "decreasing", from: 3, proven: "for every n ≥ 3" }
sequence("n^2/(n + 1)").limit(); // Infinity
sequence("2^n/n!").limit(); // 0, by the ratio of successive terms
Factorials are written n! or (2n)!. The index is n unless you pass { variable }, and starts at 1 unless you pass { from }.
What a limit means here
A sequence has limit when for every there is an with for all . Computing many terms can suggest a limit and cannot prove one: the definition is about all the terms that were not computed.
The library proves limits from the formula. On a ray it writes the term as
with exact exponents and an interval for . The limit, or the fact that the sequence grows without bound, is read off the exponents, and the bound on holds for every at once. This is the same machinery as limits at infinity. Where it finds no such form, as for , limit refuses.
Monotone and bounded
A sequence that is monotone and bounded converges; that theorem is how many limits are shown to exist before they are found. monotone() proves the direction by showing that the derivative of the formula has one sign on a ray , then compares the terms before one by one and moves back as far as they agree. bounds() combines a bound valid on a ray with the finitely many terms before it.
If no proof is found the call refuses. For example the derivative of is a difference of two terms that nearly cancel, and its sign is not settled by this method, although its limit and bounds are.
Two further routes cover cases where the derivative does not settle it. If the derivative tends to 0 and its derivative has one sign on a ray, then has the opposite sign there (a function that decreases to 0 is positive); this is applied up to four levels deep. And for a positive term such as the logarithm is differentiated instead, which turns the power into a product. monotone() reports the route in reason.
Powers with a moving exponent, and the ratio test
A term is rewritten as , and for a ratio of polynomials tending to 1 is handled through the exact difference , so that nothing cancels in floating point. That proves and limits such as , where the ratio of successive terms tends to .
Oscillation: lim sup and lim inf
A factor such as , or repeats with a whole period . Along it is a known constant, so each of the subsequences is an ordinary formula in with a limit. Those limits are the only accumulation points; the largest is and the smallest , and the sequence converges exactly when they agree.
const c = sequence("(-1)^n*(1 + 1/n)");
c.accumulation(); // { period: 2, subsequences: [{ along: "n = 2m", limit: 1 }, { along: "n = 2m + 1", limit: -1 }], … }
c.limsup(); // 1
c.liminf(); // -1
c.limit(); // refuses: "no limit: the terms oscillate, with lim sup 1 and lim inf -1 …"
c.supremum(); // { value: 3/2, attained: true, at: 2, reason }
sequence("n/(n + 1)").supremum(); // { value: 1, attained: false, … }: approached, never reached
supremum() and infimum() use the proven direction of each subsequence: a tail that rises has its limit as supremum, not attained; a tail that falls has its first term. The finitely many terms before the tail are compared one by one. For , which does not repeat on the whole numbers, all of these refuse and say so.
For the that goes with an , see ε, N and δ.
Recursive sequences
const heron = recursive("x/2 + 1/x", { start: 2 }); // x₀ = 2, x_{k+1} = x_k/2 + 1/x_k
heron.terms(5); // [2, 3/2, 17/12, 577/408, 665857/470832]
heron.fixedPoints([1, 2]); // [{ point: [1.41421…], multiplier: [≈ 0], kind: "attracting", unique: true }]
heron.limit([1, 2]); // { limit: [1.41421…], enters: 1, rate: 0.696…, basin: [0.914…, 1.914…] }
If converges and is continuous, the limit is a fixed point, . The multiplier says what happens nearby: errors are multiplied by about each step, so the fixed point attracts when and repels when .
limit turns that into a proof by the contraction principle. It finds an interval around a fixed point such that and on ; then has exactly one fixed point in and every sequence that enters converges to it, with . It then follows the sequence with interval arithmetic until a term is proven to lie in . The answer reports the step at which that happened and the rate .
Terms are exact fractions while they stay short (Heron's iteration doubles the number of digits each step) and certified intervals after that.
| call | returns |
|---|---|
| sequence(term, { variable = "n", from = 1, params }) | Sequence |
| a.term(n), a.terms(count) | Rational where the formula is rational at n, else RationalInterval |
| a.limit({ digits = 20 }) | RationalInterval, or ±Infinity; refuses with no-limit or undecided |
| a.monotone() | { direction, from, proven, reason } |
| a.accumulation() | { period, subsequences: [{ along, term, limit }], limsup, liminf, converges } |
| a.limsup(), a.liminf() | RationalInterval or ±Infinity |
| a.supremum(), a.infimum() | { value, attained, at, reason } |
| a.nFor(ε) | { N, least, reason, certificate }: see ε, N and δ |
| a.bounds() | { lower, upper, bounded }; null for a bound that does not exist |
| a.series() | the series Σ a(n) |
| recursive(next, { start, variable = "x" }) | RecursiveSequence |
| r.terms(count, { maxDigits = 300 }) | Rationals, then RationalIntervals |
| r.fixedPoints([a, b]) | records { point, multiplier, kind, unique } |
| r.limit([a, b], { maxSteps = 400 }) | { limit, enters, rate, basin }; refuses when no contraction is proven |
@ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.