Guide
Sums and recurrences
Finite sums and products in closed form, sums of series, and linear recurrences, each with a theorem.
What I usually want from a sum is a formula, not a number. With a symbolic upper bound you get a closed form, and SymLean proves it for every by induction. With a fixed upper bound the sum is evaluated exactly. A finite product in closed form also comes with a theorem for every upper bound. The sum of a series comes with a HasSum theorem, which also says that the series converges, and a linear recurrence with constant coefficients gets its general solution, or the only sequence with the given initial values.
Sums and products
Recurrences
rsolveThe general solution of a linear recurrence with constant coefficients, or the sequence with given initial values, with a theorem.
The Basel problem, with Mathlib’s HasSum. The theorem says that the series converges and that its sum is . The sum starts at , so the theorem writes the shift out as :
#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)
Binet’s formula for the Fibonacci numbers. The theorem is an equivalence about every sequence a : ℕ → ℝ: it has the recurrence and these initial values exactly when it is the closed form, so no other sequence has them:
#cas [rsolve a n, a 0 = 0, a 1 = 1] (a (n + 2) = a (n + 1) + a n)
the sequence with these initial values
a n = (((1 + sqrt(5))/2)^n - ((1 - sqrt(5))/2)^n)/sqrt(5)- Domain
a : ℕ → ℝ- Input (recurrence with initial values)
a (n + 2) = a (n + 1) + a n, a 0 = 0, a 1 = 1
Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form
∀ (a : ℕ → ℝ), (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ∧ a 0 = 0 ∧ a 1 = 1 ↔ ∀ (n : ℕ), a n = (((1 + √5) / 2) ^ n - ((1 - √5) / 2) ^ n) / √5
The certificate: 1 checked step
A sequence has the recurrence and the initial values exactly when it is the closed form
∀ (a : ℕ → ℝ), (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ∧ a 0 = 0 ∧ a 1 = 1 ↔ ∀ (n : ℕ), a n = (((1 + √5) / 2) ^ n - ((1 - √5) / 2) ^ n) / √5
The closed forms of sums cover terms , which include polynomials, geometric terms and their products, and hypergeometric terms through Gosper’s algorithm. The harmonic numbers have no closed form in hypergeometric terms, so is refused, and so is a summand with a parameter. A fixed upper bound sums at most 200 terms. A series takes terms with , or through the values of the zeta function, so odd zeta values such as are refused. A product takes a constant times powers of linear factors with integer shifts. Write those factors out. In a proof, cas proves the closed forms of finite sums and products. It doesn’t prove the statements about series or those of rsolve, but the closed form of a recurrence follows from the recurrence by induction.
