# mathlibdocumentation

number_theory.bernoulli

# Bernoulli numbers #

The Bernoulli numbers are a sequence of rational numbers that frequently show up in number theory.

## Mathematical overview #

The Bernoulli numbers $(B_0, B_1, B_2, \ldots)=(1, -1/2, 1/6, 0, -1/30, \ldots)$ are a sequence of rational numbers. They show up in the formula for the sums of $k$th powers. They are related to the Taylor series expansions of $x/\tan(x)$ and of $\coth(x)$, and also show up in the values that the Riemann Zeta function takes both at both negative and positive integers (and hence in the theory of modular forms). For example, if $1 \leq n$ is even then

$$\zeta(2n)=\sum_{t\geq1}t^{-2n}=(-1)^{n+1}\frac{(2\pi)^{2n}B_{2n}}{2(2n)!}.$$

Note however that this result is not yet formalised in Lean.

The Bernoulli numbers can be formally defined using the power series

$$\sum B_n\frac{t^n}{n!}=\frac{t}{1-e^{-t}}$$

although that happens to not be the definition in mathlib (this is an implementation detail and need not concern the mathematician).

Note that $B_1=-1/2$, meaning that we are using the $B_n^-$ of from Wikipedia.

## Implementation detail #

The Bernoulli numbers are defined using well-founded induction, by the formula $$B_n=1-\sum_{k\lt n}\frac{\binom{n}{k}}{n-k+1}B_k.$$ This formula is true for all $n$ and in particular $B_0=1$. Note that this is the definition for positive Bernoulli numbers, which we call bernoulli'. The negative Bernoulli numbers are then defined as bernoulli := (-1)^n * bernoulli'.

## Main theorems #

sum_bernoulli : ∑ k in finset.range n, (n.choose k : ℚ) * bernoulli k = 0

### Definitions #

def bernoulli'  :

The Bernoulli numbers: the $n$-th Bernoulli number $B_n$ is defined recursively via $$B_n = 1 - \sum_{k < n} \binom{n}{k}\frac{B_k}{n+1-k}$$

Equations
theorem bernoulli'_def' (n : ) :
= 1 - ∑ (k : fin n), ((n.choose k) / (n - k + 1)) *
theorem bernoulli'_def (n : ) :
= 1 - ∑ (k : ) in , ((n.choose k) / (n - k + 1)) *
theorem bernoulli'_spec (n : ) :
∑ (k : ) in , ((n.choose (n - k)) / (n - k + 1)) * = 1
theorem bernoulli'_spec' (n : ) :
∑ (k : × ) in , (((k.fst + k.snd).choose k.snd) / ((k.snd) + 1)) * = 1

### Examples #

@[simp]
theorem bernoulli'_zero  :
= 1
@[simp]
theorem bernoulli'_one  :
= 1 / 2
@[simp]
theorem bernoulli'_two  :
= 1 / 6
@[simp]
theorem bernoulli'_three  :
= 0
@[simp]
theorem bernoulli'_four  :
= (-1) / 30
@[simp]
theorem sum_bernoulli' (n : ) :
∑ (k : ) in , ((n.choose k)) * = n
def bernoulli'_power_series (A : Type u_1) [comm_ring A] [ A] :

The exponential generating function for the Bernoulli numbers bernoulli' n.

Equations
theorem bernoulli'_power_series_mul_exp_sub_one (A : Type u_1) [comm_ring A] [ A] :
theorem bernoulli'_odd_eq_zero {n : } (h_odd : odd n) (hlt : 1 < n) :
= 0

Odd Bernoulli numbers (greater than 1) are zero.

def bernoulli (n : ) :

The Bernoulli numbers are defined to be bernoulli' with a parity sign.

Equations
• = ((-1) ^ n) *
theorem bernoulli'_eq_bernoulli (n : ) :
= ((-1) ^ n) *
@[simp]
theorem bernoulli_zero  :
= 1
@[simp]
theorem bernoulli_one  :
= (-1) / 2
theorem bernoulli_eq_bernoulli'_of_ne_one {n : } (hn : n 1) :
@[simp]
theorem sum_bernoulli (n : ) :
∑ (k : ) in , ((n.choose k)) * = ite (n = 1) 1 0
theorem bernoulli_spec' (n : ) :
∑ (k : × ) in , (((k.fst + k.snd).choose k.snd) / ((k.snd) + 1)) * = ite (n = 0) 1 0
def bernoulli_power_series (A : Type u_1) [comm_ring A] [ A] :

The exponential generating function for the Bernoulli numbers bernoulli n.

Equations
theorem bernoulli_power_series_mul_exp_sub_one (A : Type u_1) [comm_ring A] [ A] :
theorem sum_range_pow (n p : ) :
∑ (k : ) in , k ^ p = ∑ (i : ) in finset.range (p + 1), ((bernoulli i) * ((p + 1).choose i)) * n ^ (p + 1 - i) / (p + 1)

Faulhaber's theorem relating the sum of of p-th powers to the Bernoulli numbers: $$\sum_{k=0}^{n-1} k^p = \sum_{i=0}^p B_i\binom{p+1}{i}\frac{n^{p+1-i}}{p+1}.$$ See https://proofwiki.org/wiki/Faulhaber%27s_Formula and [Oro18] for the proof provided here.

theorem sum_Ico_pow (n p : ) :
∑ (k : ) in (n + 1), k ^ p = ∑ (i : ) in finset.range (p + 1), ((bernoulli' i) * ((p + 1).choose i)) * n ^ (p + 1 - i) / (p + 1)

Alternate form of Faulhaber's theorem, relating the sum of p-th powers to the Bernoulli numbers: $$\sum_{k=1}^{n} k^p = \sum_{i=0}^p (-1)^iB_i\binom{p+1}{i}\frac{n^{p+1-i}}{p+1}.$$ Deduced from sum_range_pow.