Sums in closed form
sum finds in closed form by the methods of the course: sums of powers, geometric sums, telescoping. Each answer comes from an antidifference that is proven before it is used.
Using it
import { sum } from "@ratmath/symbolic";
String(sum("k", "k", 1, "n").value); // n*(n + 1)/2
String(sum("k^3", "k", 1, "n").value); // n^2*(n + 1)^2/4
String(sum("k*2^k", "k", 0, "n").value); // 2*(n*2^n - 2^n + 1)
String(sum("r^k", "k", 0, "n - 1").value); // (r^n - 1)/(r - 1), provided r != 1
String(sum("1/(k*(k+1))", "k", 1, "n").value); // n/(n + 1)
String(sum("1/(k*(k+2))", "k", 1, "inf").value); // 3/4
String(sum("k/2^k", "k", 1, "inf").value); // 2
String(sum("1/k^2", "k", 1, "inf")); // = pi^2/6 (known value (Basel problem (Euler)); checked)
sum("1/k", "k", 1, "inf").diverges; // true
const s = sum("k^2", "k", 1, "n");
String(s.antidifference); // k^3/3 - k^2/2 + k/6 — proven: F(k + 1) − F(k) = k^2
s.verified; // "proven"
The arguments are the term, the index, and the two ends; an end may be an expression in other letters or "inf". The result has value (an Expr, "inf", "-inf" or null), antidifference, method, verified, diverges, conditions and steps.
Antidifferences
Summing is to differences what integrating is to derivatives. If , the sum telescopes:
So the work is finding , and the check is easy: the normal form of must be 0. Every closed form returned has passed that check (verified: "proven"). When the ends are whole numbers, the terms are also added up one by one and compared with the closed form.
The methods
Sums of powers. For each power there is a polynomial with and . Expanding by the binomial theorem gives them one after another (Faulhaber's formulas):
A polynomial term, with numbers or letters as coefficients, is a combination of these.
A polynomial times a power. For with , look for with a polynomial of the same degree. The condition is
a triangular system for the coefficients of , solved from the top. Powers can be written as , or ; the ratio may be a letter, and then is returned as a condition.
Telescoping. A rational function of is split into partial fractions. Two terms and whose poles are a whole number apart nearly cancel in the sum, because
When the coefficients of each such group add up to zero, the group has a rational antidifference. When they do not, as for , the partial sums are not a rational function of the end (they are the harmonic numbers), and the library says so.
Infinite sums
is the limit of . A polynomial times tends to 0 when , and a telescoping remainder tends to 0; otherwise limit is asked. Divergence is proven when the terms do not tend to 0, or, for a rational term of size about , by comparison with the harmonic series.
A few famous sums have no antidifference at all. They are in a short table: , , , , , and , and their multiples and shifts. A value from the table is not proven here; it is checked: the exact partial sum to 400 terms must lie within a proven bound on the tail (for , the tail after is less than ; for an alternating series, less than the first term left out).
A factor that does not contain the index comes outside the sum first, , so and works with a letter . The step record names the factor.
@ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.