Documentation

Mathlib.NumberTheory.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$ then

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

This result is formalised in Lean: riemannZeta_two_mul_nat.

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 โˆˆ Finset.range n, (n.choose k : โ„š) * bernoulli k = if n = 1 then 1 else 0

Definitions #

@[irreducible]
def bernoulli' (n : โ„•) :
โ„š

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}$$

Instances For
    theorem bernoulli'_def' (n : โ„•) :
    bernoulli' n = 1 - โˆ‘ k : Fin n, โ†‘(n.choose โ†‘k) / (โ†‘n - โ†‘โ†‘k + 1) * bernoulli' โ†‘k
    theorem bernoulli'_def (n : โ„•) :
    bernoulli' n = 1 - โˆ‘ k โˆˆ Finset.range n, โ†‘(n.choose k) / (โ†‘n - โ†‘k + 1) * bernoulli' k
    theorem bernoulli'_spec (n : โ„•) :
    โˆ‘ k โˆˆ Finset.range n.succ, โ†‘(n.choose (n - k)) / (โ†‘n - โ†‘k + 1) * bernoulli' k = 1
    theorem bernoulli'_spec' (n : โ„•) :
    โˆ‘ k โˆˆ Finset.antidiagonal n, โ†‘((k.1 + k.2).choose k.2) / (โ†‘k.2 + 1) * bernoulli' k.1 = 1

    Examples #

    @[simp]
    theorem sum_bernoulli' (n : โ„•) :
    โˆ‘ k โˆˆ Finset.range n, โ†‘(n.choose k) * bernoulli' k = โ†‘n
    def bernoulli'PowerSeries (A : Type u_1) [CommRing A] [Algebra โ„š A] :

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

    Instances For
      theorem bernoulli'_eq_zero_of_odd {n : โ„•} (h_odd : Odd n) (hlt : 1 < n) :

      Odd Bernoulli numbers (greater than 1) are zero.

      @[deprecated bernoulli'_eq_zero_of_odd (since := "2025-12-09")]
      theorem bernoulli'_odd_eq_zero {n : โ„•} (h_odd : Odd n) (hlt : 1 < n) :

      Alias of bernoulli'_eq_zero_of_odd.


      Odd Bernoulli numbers (greater than 1) are zero.

      def bernoulli (n : โ„•) :
      โ„š

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

      Instances For
        theorem bernoulli'_eq_bernoulli (n : โ„•) :
        bernoulli' n = (-1) ^ n * bernoulli n
        @[simp]
        theorem bernoulli_one :
        bernoulli 1 = -1 / 2
        @[simp]
        theorem bernoulli_eq_zero_of_odd {n : โ„•} (h_odd : Odd n) (hlt : 1 < n) :
        bernoulli n = 0
        theorem bernoulli_eq_bernoulli'_of_ne_one {n : โ„•} (hn : n โ‰  1) :
        @[simp]
        theorem sum_bernoulli (n : โ„•) :
        โˆ‘ k โˆˆ Finset.range n, โ†‘(n.choose k) * bernoulli k = if n = 1 then 1 else 0
        theorem bernoulli_spec' (n : โ„•) :
        โˆ‘ k โˆˆ Finset.antidiagonal n, โ†‘((k.1 + k.2).choose k.2) / (โ†‘k.2 + 1) * bernoulli k.1 = if n = 0 then 1 else 0
        def bernoulliPowerSeries (A : Type u_1) [CommRing A] [Algebra โ„š A] :

        The exponential generating function for the Bernoulli numbers bernoulli n.

        Instances For
          theorem sum_range_pow (n p : โ„•) :
          โˆ‘ k โˆˆ Finset.range n, โ†‘k ^ p = โˆ‘ i โˆˆ Finset.range (p + 1), bernoulli i * โ†‘((p + 1).choose i) * โ†‘n ^ (p + 1 - i) / (โ†‘p + 1)

          Faulhaber's theorem relating the sum 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 [orosi2018faulhaber] for the proof provided here.

          theorem sum_Ico_pow (n p : โ„•) :
          โˆ‘ k โˆˆ Finset.Ico 1 (n + 1), โ†‘k ^ p = โˆ‘ i โˆˆ 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.