Mode of #cas

sum

A finite sum in closed form or by its exact value, or the sum of a series, with a theorem.

#cas [sum k a b] e
sums e for k from the natural number a to b, in closed form when b is a variable and by its exact value when b is a numeral, with a theorem about the sum over Finset.Icc a b.
#cas [sum k a ∞] e
sums the series of e from a, for polynomials times geometric terms and for even zeta values, with a HasSum theorem, which states that the series converges and has that sum.

sum gives a finite sum in closed form, including sums with a symbolic upper bound, and the sums of some series. With a variable upper bound n, SymLean finds the closed form and proves it for every n by induction. With a numeral upper bound, it adds the terms one by one and gives the exact rational value. And with ∞ as the upper bound, it finds the sum of the series and proves that the series converges to it.

The closed forms come from two places. Sums of terms ckjrk cover polynomials, geometric terms and their products, and Gosper’s algorithm covers hypergeometric terms, such as the telescoping 1/(k(k+1)). The series form takes the terms ckjrk with |r|<1, and c/k2m through the values of the zeta function.

Details and Options

  • For a variable upper bound n and the printed closed form F, the theorem is ∀ n : ℕ, ∑ k ∈ Finset.Icc a n, e = F, and ∀ n : ℕ, a - 1 ≤ n → ∑ k ∈ Finset.Icc a n, e = F when a≥2. For a numeral b it is ∑ k ∈ Finset.Icc a b, e = v with the exact rational v.
  • A polynomial divided by a geometric term, such as k ^ 11 / 2 ^ k, is summed as the polynomial times a geometric term.
  • Gosper’s algorithm takes hypergeometric terms c ^ k * R k with a rational function R and a rational c>0, and the label of the answer then says “(Gosper)”. Its work is bounded where it grows. It needs the shifts between the factors of the ratio of consecutive terms: they are tested one by one up to a bound on the distance of their roots, as for 1 / k ^ 6 - 1 / (k + 1) ^ 6, when that bound is small, and otherwise found as the integer roots of a resultant of degree at most 100. The polynomials of the closed form have degree at most 100: 1 / (k * (k + 101)) is the last of its family that the command proves, and 1 / (k * (k + 1000)), which needs degree 999, is refused with that degree. The kernel check grows with the degree, and 1 / (k * (k + 96)) takes about 40 seconds. A summand outside these bounds is refused with what the command would need. The search checks maxHeartbeats at each step, except while it finds the integer roots of a resultant: for 1 / ((k ^ 10 + 10 ^ 40) * ((k + 1) ^ 10 + 10 ^ 40)) that step takes about two minutes.
  • The summand contains the summation variable and nothing else. A summand with a parameter, such as a / (k * (k + 1)), is refused.
  • A summand that is undefined in the range is refused. A numeral upper bound sums at most 200 terms, and each term must be an exact rational number.
  • For a series the theorem is HasSum (fun k : ℕ ↦ e (k + a)) S, with the shift written out: the series converges and its sum is S. A term with |r|≥1 is refused before any proof: its series diverges. For c/k2m the lower bound is between 1 and 50, and 2m≤60.
  • There are no options. In a proof, cas proves the closed forms of finite sums, but not the statements about series.
  • With CASOracle.Sum imported, #cas [sum k a n, oracle := sympy] e asks an external system for the closed form F. sage and giac work the same way. Lean proves ∀ n : ℕ, a ≤ n → ∑ k ∈ Finset.Icc a n, e = F by induction, or refuses. See oracle.

Examples (20)#

Basic Examples (3)

The sum of the first n squares, with the theorem for every n:

In[1]:=
#cas [sum k 1 n] (k^2)
Out[1]=

closed form

n(n+1)(2n+1)6
n*(n + 1)*(2*n + 1)/6
Domain
k ∈ [1, n]
Input (summand)
(k^2)

Checked by Lean’s kernel: Closed form for every upper bound

∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k ^ 2 = ↑n * (↑n + 1) * (2 * ↑n + 1) / 6
The certificate: 1 checked step
  1. Closed form for every upper bound

    ∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k ^ 2 = ↑n * (↑n + 1) * (2 * ↑n + 1) / 6

    Checked by Lean’s kernel


A telescoping sum, by Gosper’s algorithm:

In[2]:=
#cas [sum k 1 n] (1 / (k * (k + 1)))
Out[2]=

closed form (Gosper)

nn+1
n/(n + 1)
Domain
k ∈ [1, n]
Input (hypergeometric summand)
(1 / (k * (k + 1)))

Checked by Lean’s kernel: Closed form for every upper bound, from Gosper's algorithm

∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, 1 / (↑k * (↑k + 1)) = ↑n / (↑n + 1)
The certificate: 1 checked step
  1. Closed form for every upper bound, from Gosper's algorithm

    ∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, 1 / (↑k * (↑k + 1)) = ↑n / (↑n + 1)

    Checked by Lean’s kernel


A geometric series:

In[3]:=
#cas [sum k 0 ∞] ((1/2)^k)
Out[3]=

sum of the series

2
Domain
k ∈ ℕ, k ≥ 0
Input (summand)
((1/2)^k)

Checked by Lean’s kernel: Sum of the series

HasSum (fun k ↦ (1 / 2) ^ k) 2
The certificate: 1 checked step
  1. Sum of the series

    HasSum (fun k ↦ (1 / 2) ^ k) 2

    Checked by Lean’s kernel

Scope (7)

A finite geometric sum, and a polynomial times a geometric term:

In[4]:=
#cas [sum k 0 n] (2^k)
Out[4]=

closed form

2·2n−1
2*2^n - 1
Domain
k ∈ [0, n]
Input (summand)
(2^k)

Checked by Lean’s kernel: Closed form for every upper bound

∀ (n : ℕ), ∑ k ∈ Finset.Icc 0 n, 2 ^ k = 2 * 2 ^ n - 1
The certificate: 1 checked step
  1. Closed form for every upper bound

    ∀ (n : ℕ), ∑ k ∈ Finset.Icc 0 n, 2 ^ k = 2 * 2 ^ n - 1

    Checked by Lean’s kernel

In[5]:=
#cas [sum k 1 n] (k * 2^k)
Out[5]=

closed form

2(n−1)·2n+2
2*(n - 1)*2^n + 2
Domain
k ∈ [1, n]
Input (summand)
(k * 2^k)

Checked by Lean’s kernel: Closed form for every upper bound

∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k * 2 ^ k = 2 * (↑n - 1) * 2 ^ n + 2
The certificate: 1 checked step
  1. Closed form for every upper bound

    ∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k * 2 ^ k = 2 * (↑n - 1) * 2 ^ n + 2

    Checked by Lean’s kernel


A sum from 3. The theorem holds for n≥2, and at n=2 the sum is empty:

In[6]:=
#cas [sum k 3 n] (2*k + 1)
Out[6]=

closed form

(n - 2)*(n + 4)
Domain
k ∈ [3, n]
Input (summand)
(2*k + 1)

Checked by Lean’s kernel: Closed form for every upper bound

∀ (n : ℕ), 2 ≤ n → ∑ k ∈ Finset.Icc 3 n, (2 * ↑k + 1) = (↑n - 2) * (↑n + 4)
The certificate: 1 checked step
  1. Closed form for every upper bound

    ∀ (n : ℕ), 2 ≤ n → ∑ k ∈ Finset.Icc 3 n, (2 * ↑k + 1) = (↑n - 2) * (↑n + 4)

    Checked by Lean’s kernel


A numeral upper bound gives the exact value:

In[7]:=
#cas [sum k 1 10] (k^2)
Out[7]=

exact value

385
Domain
k ∈ [1, 10]
Input (summand)
(k^2)

Checked by Lean’s kernel: Value of the sum

∑ k ∈ Finset.Icc 1 10, ↑k ^ 2 = 385
The certificate: 1 checked step
  1. Value of the sum

    ∑ k ∈ Finset.Icc 1 10, ↑k ^ 2 = 385

    Checked by Lean’s kernel


Gosper’s algorithm on a sum that starts at 2, where the summand is defined:

In[8]:=
#cas [sum k 2 n] (1 / (k ^ 2 - 1))
Out[8]=

closed form (Gosper)

(n−1)(3n+2)4n(n+1)
(n - 1)*(3*n + 2)/(4*n*(n + 1))
Domain
k ∈ [2, n]
Input (hypergeometric summand)
(1 / (k ^ 2 - 1))

Checked by Lean’s kernel: Closed form for every upper bound, from Gosper's algorithm

∀ (n : ℕ),
  1 ≤ n → ∑ k ∈ Finset.Icc 2 n, 1 / (↑k ^ 2 - 1) = (↑n - 1) * (3 * ↑n + 2) / (4 * (↑n * (↑n + 1)))
The certificate: 1 checked step
  1. Closed form for every upper bound, from Gosper's algorithm

    ∀ (n : ℕ),
      1 ≤ n → ∑ k ∈ Finset.Icc 2 n, 1 / (↑k ^ 2 - 1) = (↑n - 1) * (3 * ↑n + 2) / (4 * (↑n * (↑n + 1)))

    Checked by Lean’s kernel


Series of polynomials times geometric terms, with a positive and with a negative ratio:

In[9]:=
#cas [sum k 1 ∞] (k / 2^k)
Out[9]=

sum of the series

2
Domain
k ∈ ℕ, k ≥ 1
Input (summand)
(k / 2^k)

Checked by Lean’s kernel: Sum of the series

HasSum (fun k ↦ (↑k + 1) / 2 ^ (k + 1)) 2
The certificate: 1 checked step
  1. Sum of the series

    HasSum (fun k ↦ (↑k + 1) / 2 ^ (k + 1)) 2

    Checked by Lean’s kernel

In[10]:=
#cas [sum k 0 ∞] ((k + 1) * (-1/2)^k)
Out[10]=

sum of the series

49
4/9
Domain
k ∈ ℕ, k ≥ 0
Input (summand)
((k + 1) * (-1/2)^k)

Checked by Lean’s kernel: Sum of the series

HasSum (fun k ↦ (↑k + 1) * (-1 / 2) ^ k) (4 / 9)
The certificate: 1 checked step
  1. Sum of the series

    HasSum (fun k ↦ (↑k + 1) * (-1 / 2) ^ k) (4 / 9)

    Checked by Lean’s kernel


The Basel problem, with a HasSum statement:

In[11]:=
#cas [sum k 1 ∞] (1/k^2)
Out[11]=

sum of the series (ζ value)

π26
pi^2/6
Domain
k ∈ ℕ, k ≥ 1
Input (summand)
1/k^2

Checked by Lean’s kernel: Sum of the series by hasSum_zeta_nat

HasSum (fun k ↦ 1 / ↑(k + 1) ^ 2) (Real.pi ^ 2 / 6)
The certificate: 1 checked step
  1. Sum of the series by hasSum_zeta_nat

    HasSum (fun k ↦ 1 / ↑(k + 1) ^ 2) (Real.pi ^ 2 / 6)

    Checked by Lean’s kernel


A zeta value with the first terms left out:

In[12]:=
#cas [sum k 3 ∞] (6/k^2)
Out[12]=

sum of the series (ζ value)

π2−152
pi^2 - 15/2
Domain
k ∈ ℕ, k ≥ 3
Input (summand)
6/k^2

Checked by Lean’s kernel: Sum of the series by hasSum_zeta_nat

HasSum (fun k ↦ 6 / ↑(k + 3) ^ 2) (Real.pi ^ 2 - 15 / 2)
The certificate: 1 checked step
  1. Sum of the series by hasSum_zeta_nat

    HasSum (fun k ↦ 6 / ↑(k + 3) ^ 2) (Real.pi ^ 2 - 15 / 2)

    Checked by Lean’s kernel

Applications (1)

A closed form in a proof. cas proves it by induction, and only the three standard axioms are used:

In[13]:=
theorem sum_squares :
    ∀ n : ℕ, ∑ k ∈ Finset.Icc 1 n, (k : ℝ) ^ 2 = n * (n + 1) * (2 * n + 1) / 6 := by
  cas

#print axioms sum_squares
Out[13]=

sum_squares depends on the axioms propext, Classical.choice, Quot.sound.

Properties and Relations (1)

The partial sums 2−(1/2)n of the geometric series tend to its sum 2:

In[14]:=
#cas [sum k 0 n] ((1/2)^k)
Out[14]=

closed form

−(12)n+2
-(1/2)^n + 2
Domain
k ∈ [0, n]
Input (summand)
((1/2)^k)

Checked by Lean’s kernel: Closed form for every upper bound

∀ (n : ℕ), ∑ k ∈ Finset.Icc 0 n, (1 / 2) ^ k = -(1 / 2) ^ n + 2
The certificate: 1 checked step
  1. Closed form for every upper bound

    ∀ (n : ℕ), ∑ k ∈ Finset.Icc 0 n, (1 / 2) ^ k = -(1 / 2) ^ n + 2

    Checked by Lean’s kernel

Possible Issues (6)

The harmonic numbers have no closed form in hypergeometric terms. The command reports this and states no theorem about it:

In[15]:=
#cas [sum k 1 n] (1 / k)
Out[15]=

Error

sum: Gosper's algorithm finds no closed form in hypergeometric terms for this summand

A numeral upper bound gives the exact value:

In[16]:=
#cas [sum k 1 10] (1/k)
Out[16]=

exact value

73812520
7381/2520
Domain
k ∈ [1, 10]
Input (summand)
(1/k)

Checked by Lean’s kernel: Value of the sum

∑ k ∈ Finset.Icc 1 10, 1 / ↑k = 7381 / 2520
The certificate: 1 checked step
  1. Value of the sum

    ∑ k ∈ Finset.Icc 1 10, 1 / ↑k = 7381 / 2520

    Checked by Lean’s kernel


The closed forms cover polynomial, geometric and hypergeometric terms:

In[17]:=
#cas [sum k 1 n] (sin k)
Out[17]=

Error

sum: the summand is not a sum of terms c k ^ j r ^ k with rational c and r

The summand may contain the summation variable only. A parameter is refused:

In[18]:=
#cas [sum k 1 n] (a / (k * (k + 1)))
Out[18]=

Error

sum: the summand may contain only the summation variable k; sums with parameters, here a, are not supported

A series with ratio |r|≥1 diverges, and the message says why it matters in Mathlib:

In[19]:=
#cas [sum k 0 ∞] (2^k)
Out[19]=

Error

sum: the term with ratio 2 has |2| ≥ 1, so the series diverges (Mathlib's tsum of a non-summable series is 0)

Odd zeta values, such as ζ(3), are refused:

In[20]:=
#cas [sum k 1 ∞] (1/k^3)
Out[20]=

Error

sum: unsupported formula for the odd exponent 3 (ζ(3))

The summand must be defined in the whole range. Start the sum at 1:

In[21]:=
#cas [sum k 0 ∞] (1/k^2)
Out[21]=

Error

sum: the summand 1/k^2 is undefined at k = 0; start the sum at 1

Neat Examples (2)

The sum of the first n cubes is the square of the sum of the first n integers:

In[22]:=
#cas [sum k 1 n] (k^3)
Out[22]=

closed form

n2(n+1)24
n^2*(n + 1)^2/4
Domain
k ∈ [1, n]
Input (summand)
(k^3)

Checked by Lean’s kernel: Closed form for every upper bound

∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k ^ 3 = ↑n ^ 2 * (↑n + 1) ^ 2 / 4
The certificate: 1 checked step
  1. Closed form for every upper bound

    ∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k ^ 3 = ↑n ^ 2 * (↑n + 1) ^ 2 / 4

    Checked by Lean’s kernel


The value ζ(4)=π4/90:

In[23]:=
#cas [sum k 1 ∞] (1/k^4)
Out[23]=

sum of the series (ζ value)

π490
pi^4/90
Domain
k ∈ ℕ, k ≥ 1
Input (summand)
1/k^4

Checked by Lean’s kernel: Sum of the series by hasSum_zeta_nat

HasSum (fun k ↦ 1 / ↑(k + 1) ^ 4) (Real.pi ^ 4 / 90)
The certificate: 1 checked step
  1. Sum of the series by hasSum_zeta_nat

    HasSum (fun k ↦ 1 / ↑(k + 1) ^ 4) (Real.pi ^ 4 / 90)

    Checked by Lean’s kernel

See Also

product · rsolve · zeta · series · cas