Sums

Sums in closed form

sum finds ∑k=abf(k)\sum_{k=a}^{b} f(k) 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 F(k+1)−F(k)=f(k)F(k+1) - F(k) = f(k), the sum telescopes:

∑k=abf(k)=∑k=ab(F(k+1)−F(k))=F(b+1)−F(a). \sum_{k=a}^{b} f(k) = \sum_{k=a}^{b} \bigl(F(k+1) - F(k)\bigr) = F(b+1) - F(a).

So the work is finding FF, and the check is easy: the normal form of F(k+1)−F(k)−f(k)F(k+1) - F(k) - f(k) 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 FjF_j with Fj(k+1)−Fj(k)=kjF_j(k+1) - F_j(k) = k^j and Fj(0)=0F_j(0) = 0. Expanding (k+1)j+1−kj+1(k+1)^{j+1} - k^{j+1} by the binomial theorem gives them one after another (Faulhaber's formulas):

Fj(k)=1j+1(kj+1−∑i<j(j+1i)Fi(k)). F_j(k) = \frac{1}{j+1}\Bigl(k^{j+1} - \sum_{i<j} \binom{j+1}{i} F_i(k)\Bigr).

A polynomial term, with numbers or letters as coefficients, is a combination of these.

A polynomial times a power. For p(k) rkp(k)\,r^k with r≠1r \ne 1, look for F=q(k) rkF = q(k)\,r^k with qq a polynomial of the same degree. The condition F(k+1)−F(k)=p(k)rkF(k+1) - F(k) = p(k)r^k is

r q(k+1)−q(k)=p(k), r\,q(k+1) - q(k) = p(k),

a triangular system for the coefficients of qq, solved from the top. Powers can be written as 2k+12^{k+1}, (1/3)k(1/3)^k or e2ke^{2k}; the ratio rr may be a letter, and then r≠1r \ne 1 is returned as a condition.

Telescoping. A rational function of kk is split into partial fractions. Two terms c/(k+b)c/(k+b) and c′/(k+b+j)c'/(k+b+j) whose poles are a whole number jj apart nearly cancel in the sum, because

1k+b+j=1k+b−Δ(−∑i=0j−11k+b+i). \frac{1}{k+b+j} = \frac{1}{k+b} - \Delta\Bigl(-\sum_{i=0}^{j-1} \frac{1}{k+b+i}\Bigr).

When the coefficients of each such group add up to zero, the group has a rational antidifference. When they do not, as for ∑1/k\sum 1/k, the partial sums are not a rational function of the end (they are the harmonic numbers), and the library says so.

Infinite sums

∑k=a∞f(k)\sum_{k=a}^{\infty} f(k) is the limit of F(n+1)−F(a)F(n+1) - F(a). A polynomial times rnr^n tends to 0 when ∣r∣<1|r| < 1, and a telescoping remainder ∑c/(n+b+i)\sum c/(n+b+i) 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 1/k1/k, by comparison with the harmonic series.

A few famous sums have no antidifference at all. They are in a short table: ∑1/k2=π2/6\sum 1/k^2 = \pi^2/6, ∑1/k4=π4/90\sum 1/k^4 = \pi^4/90, ∑1/k6=π6/945\sum 1/k^6 = \pi^6/945, ∑(−1)k+1/k=log⁡2\sum (-1)^{k+1}/k = \log 2, ∑(−1)k/(2k+1)=π/4\sum (-1)^k/(2k+1) = \pi/4, ∑(−1)k+1/k2=π2/12\sum (-1)^{k+1}/k^2 = \pi^2/12 and ∑1/(2k−1)2=π2/8\sum 1/(2k-1)^2 = \pi^2/8, 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 ∑1/k2\sum 1/k^2, the tail after NN is less than 1/N1/N; for an alternating series, less than the first term left out).

A factor that does not contain the index comes outside the sum first, ∑c f(k)=c∑f(k)\sum c\,f(k) = c\sum f(k), so ∑4/(n2π2)=4π2⋅π26=23\sum 4/(n^2\pi^2) = \tfrac{4}{\pi^2}\cdot\tfrac{\pi^2}{6} = \tfrac23 and ∑a k\sum a\,k works with a letter aa. The step record names the factor.

Try itEdit the code and run it with @ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs