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] eFinset.Icc a b.#cas [sum k a ∞] eHasSum 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 , SymLean finds the closed form and proves it for every 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 cover polynomials, geometric terms and their products, and Gosper’s algorithm covers hypergeometric terms, such as the telescoping . The series form takes the terms with , and through the values of the zeta function.
Examples (20)#
Basic Examples (3)
The sum of the first squares, with the theorem for every :
#cas [sum k 1 n] (k^2)
closed form
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
Closed form for every upper bound
∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k ^ 2 = ↑n * (↑n + 1) * (2 * ↑n + 1) / 6
A telescoping sum, by Gosper’s algorithm:
#cas [sum k 1 n] (1 / (k * (k + 1)))
closed form (Gosper)
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
Closed form for every upper bound, from Gosper's algorithm
∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, 1 / (↑k * (↑k + 1)) = ↑n / (↑n + 1)
A geometric series:
#cas [sum k 0 ∞] ((1/2)^k)
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
Sum of the series
HasSum (fun k ↦ (1 / 2) ^ k) 2
Scope (7)
A finite geometric sum, and a polynomial times a geometric term:
#cas [sum k 0 n] (2^k)
closed form
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
Closed form for every upper bound
∀ (n : ℕ), ∑ k ∈ Finset.Icc 0 n, 2 ^ k = 2 * 2 ^ n - 1
#cas [sum k 1 n] (k * 2^k)
closed form
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
Closed form for every upper bound
∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k * 2 ^ k = 2 * (↑n - 1) * 2 ^ n + 2
A sum from 3. The theorem holds for , and at the sum is empty:
#cas [sum k 3 n] (2*k + 1)
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
Closed form for every upper bound
∀ (n : ℕ), 2 ≤ n → ∑ k ∈ Finset.Icc 3 n, (2 * ↑k + 1) = (↑n - 2) * (↑n + 4)
A numeral upper bound gives the exact value:
#cas [sum k 1 10] (k^2)
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
Value of the sum
∑ k ∈ Finset.Icc 1 10, ↑k ^ 2 = 385
Gosper’s algorithm on a sum that starts at 2, where the summand is defined:
#cas [sum k 2 n] (1 / (k ^ 2 - 1))
closed form (Gosper)
(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
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)))
Series of polynomials times geometric terms, with a positive and with a negative ratio:
#cas [sum k 1 ∞] (k / 2^k)
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
Sum of the series
HasSum (fun k ↦ (↑k + 1) / 2 ^ (k + 1)) 2
#cas [sum k 0 ∞] ((k + 1) * (-1/2)^k)
sum of the series
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
Sum of the series
HasSum (fun k ↦ (↑k + 1) * (-1 / 2) ^ k) (4 / 9)
The Basel problem, with a HasSum statement:
#cas [sum k 1 ∞] (1/k^2)
sum of the series (ζ value)
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
Sum of the series by hasSum_zeta_nat
HasSum (fun k ↦ 1 / ↑(k + 1) ^ 2) (Real.pi ^ 2 / 6)
A zeta value with the first terms left out:
#cas [sum k 3 ∞] (6/k^2)
sum of the series (ζ value)
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
Sum of the series by hasSum_zeta_nat
HasSum (fun k ↦ 6 / ↑(k + 3) ^ 2) (Real.pi ^ 2 - 15 / 2)
Applications (1)
A closed form in a proof. cas proves it by induction, and only the three standard axioms are used:
theorem sum_squares : ∀ n : ℕ, ∑ k ∈ Finset.Icc 1 n, (k : ℝ) ^ 2 = n * (n + 1) * (2 * n + 1) / 6 := by cas #print axioms sum_squares
sum_squares depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (1)
The partial sums of the geometric series tend to its sum 2:
#cas [sum k 0 n] ((1/2)^k)
closed form
-(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
Closed form for every upper bound
∀ (n : ℕ), ∑ k ∈ Finset.Icc 0 n, (1 / 2) ^ k = -(1 / 2) ^ n + 2
Possible Issues (6)
The harmonic numbers have no closed form in hypergeometric terms. The command reports this and states no theorem about it:
#cas [sum k 1 n] (1 / k)
Error
sum: Gosper's algorithm finds no closed form in hypergeometric terms for this summand
A numeral upper bound gives the exact value:
#cas [sum k 1 10] (1/k)
exact value
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
Value of the sum
∑ k ∈ Finset.Icc 1 10, 1 / ↑k = 7381 / 2520
The closed forms cover polynomial, geometric and hypergeometric terms:
#cas [sum k 1 n] (sin k)
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:
#cas [sum k 1 n] (a / (k * (k + 1)))
Error
sum: the summand may contain only the summation variable k; sums with parameters, here a, are not supported
A series with ratio diverges, and the message says why it matters in Mathlib:
#cas [sum k 0 ∞] (2^k)
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 , are refused:
#cas [sum k 1 ∞] (1/k^3)
Error
sum: unsupported formula for the odd exponent 3 (ζ(3))
The summand must be defined in the whole range. Start the sum at 1:
#cas [sum k 0 ∞] (1/k^2)
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 cubes is the square of the sum of the first integers:
#cas [sum k 1 n] (k^3)
closed form
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
Closed form for every upper bound
∀ (n : ℕ), ∑ k ∈ Finset.Icc 1 n, ↑k ^ 3 = ↑n ^ 2 * (↑n + 1) ^ 2 / 4
The value :
#cas [sum k 1 ∞] (1/k^4)
sum of the series (ζ value)
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
Sum of the series by hasSum_zeta_nat
HasSum (fun k ↦ 1 / ↑(k + 1) ^ 4) (Real.pi ^ 4 / 90)
