Bernoulli numbers Bn form a sequence of rational numbers closely related to number theory. The first few Bernoulli numbers are as follows:
B0=1,B1=−21,B2=61,B3=0,B4=−301,…
Sums of like powers
Bernoulli numbers are named after Jacob Bernoulli, who discovered a remarkable relationship while studying formulas for sums of m-th powers. Let
Sm(n)=k=0∑n−1km=0m+1m+⋯+(n−1)m
Bernoulli observed the following sequence of formulas and sketched a pattern:
S0(n)S1(n)S2(n)S3(n)S4(n)=n=21n2−21n=31n3−21n2+61n=41n4−21n3+41n2=51n5−21n4+31n3−301n
In Sm(n), the coefficient of nm+1 is always m+11, the coefficient of nm is always −21, the coefficient of nm−1 is always 12m, the coefficient of nm−3 is −720m(m−1)(m−2), and the coefficient of nm−4 is always zero, among others.
The coefficient of nm−k is always a constant multiplied by mk, where mk denotes the falling factorial, namely (m−k)!m!.
Recurrence formula
Sm(n)=m+11(B0nm+1+(1m+1)B1nm+⋯+(mm+1)Bmn)=m+11k=0∑m(km+1)Bknm+1−k
Bernoulli numbers are defined by the implicit recurrence:
j=0∑m(jm+1)BjB0=0,(m>0)=1
For example, (02)B0+(12)B1=0, and the first few values are clearly
| n | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | … |
|---|
| Bn | 1 | −21 | 61 | 0 | −301 | 0 | 421 | 0 | −301 | … |
Proof
Proof by induction
This proof is adapted from Concrete Mathematics, 6.5, BERNOULLI NUMBER.
Use an identity for binomial coefficients together with induction:
Sm+1(n)+nm+1=k=0∑n−1(k+1)m+1=k=0∑n−1j=0∑m+1(jm+1)kj=j=0∑m+1(jm+1)Sj(n)
Let S^m(n)=m+11∑k=0m(km+1)Bknm+1−k. We want to prove Sm(n)=S^m(n), assuming that for j∈[0,m), Sj(n)=S^j(n).
Subtracting Sm+1(n) from both sides of the original equation gives:
Sm+1(n)+nm+1nm+1=j=0∑m+1(jm+1)Sj(n)=j=0∑m(jm+1)Sj(n)=j=0∑m−1(jm+1)S^j(n)+(mm+1)Sm(n)
Adding and subtracting (mm+1)S^m(n)−(mm+1)S^m(n) on the right and simplifying gives:
nm+1=j=0∑m(jm+1)S^j(n)+(m+1)(Sm(n)−S^m(n))
Let Δ=Sm(n)−S^m(n) and expand S^j(n):
nm+1=j=0∑m(jm+1)S^j(n)+(m+1)Δ=j=0∑m(jm+1)j+11k=0∑j(kj+1)Bknj+1−k+(m+1)Δ
Reverse the order of summation in the second ∑ and apply identities for binomial coefficients:
nm+1=j=0∑m(jm+1)j+11k=0∑j(j−kj+1)Bj−knk+1+(m+1)Δ=j=0∑m(jm+1)j+11k=0∑j(k+1j+1)Bj−knk+1+(m+1)Δ=j=0∑m(jm+1)j+11k=0∑jk+1j+1(kj)Bj−knk+1+(m+1)Δ=j=0∑m(jm+1)k=0∑j(kj)k+1Bj−knk+1+(m+1)Δ
Interchanging the two summation signs gives:
nm+1=k=0∑mk+1nk+1j=k∑m(jm+1)(kj)Bj−k+(m+1)Δ
Use the identity (jm+1)(kj)
(jm+1)(kj)=(km+1)(j−km−k+1)
to obtain:
nm+1=k=0∑mk+1nk+1j=k∑m(km+1)(j−km−k+1)Bj−k+(m+1)Δ=k=0∑mk+1nk+1(km+1)j=k∑m(j−km−k+1)Bj−k+(m+1)Δ
Replace every j−k by j:
nm+1=k=0∑mk+1nk+1(km+1)j=0∑m−k(jm−k+1)Bj+(m+1)Δ
Recall the recurrence mentioned above:
j=0∑m(jm+1)BjB0j=0∑m(jm+1)Bj=0,(m>0)=1=[m=0]
Substitution yields:
nm+1=k=0∑mk+1nk+1(km+1)[m−k=0]+(m+1)Δ=m+1nm+1(mm+1)+(m+1)Δ=nm+1+(m+1)Δ
Thus Δ=0, and Sm(n)=S^m(n).
Proof using exponential generating functions
For the recurrence ∑j=0m(jm+1)Bj=[m=0].
Add Bm+1 to both sides:
j=0∑m+1(jm+1)Bjj=0∑m(jm)Bjj=0∑mj!Bj⋅(m−j)!1=[m=0]+Bm+1=[m=1]+Bm=[m=1]+m!Bm
Let B(z)=i≥0∑i!Bizi. The left side is a convolution, so:
B(z)ezB(z)=z+B(z)=ez−1z
Let Fn(z)=∑m≥0m!Sm(n)zm:
Fn(z)=m≥0∑m!Sm(n)zm=m≥0∑i=0∑n−1m!imzm
Interchange the order of summation:
Fn(z)=i=0∑n−1m≥0∑m!imzm=i=0∑n−1eiz=ez−1enz−1=ez−1z⋅zenz−1
Substitute B(z)=ez−1z:
Fn(z)=B(z)⋅zenz−1=(i≥0∑i!Bi)(i≥1∑i!nizi−1)=(i≥0∑i!Bi)(i≥0∑(i+1)!ni+1zi)
Since Fn(z)=∑m≥0m!Sm(n)zm, we have Sm(n)=m![zm]Fn(z):
S×m(n)=m![zm]Fn(z)=m!i=0∑mi!B×i⋅(m−i+1)!nm−i+1=m+11i=0∑m(im+1)Binm−i+1
This completes the proof.
Reference implementation
using ll = long long;
constexpr int MAXN = 10000;
constexpr int mod = 1e9 + 7;
ll B[MAXN];
ll C[MAXN][MAXN];
ll inv[MAXN];
void init() {
for (int i = 0; i < MAXN; i++) {
C[i][0] = C[i][i] = 1;
for (int k = 1; k < i; k++) {
C[i][k] = (C[i - 1][k] % mod + C[i - 1][k - 1] % mod) % mod;
}
}
inv[1] = 1;
for (int i = 2; i < MAXN; i++) {
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
}
B[0] = 1;
for (int i = 1; i < MAXN; i++) {
ll ans = 0;
if (i == MAXN - 1) break;
for (int k = 0; k < i; k++) {
ans += C[i + 1][k] * B[k];
ans %= mod;
}
ans = (ans * (-inv[i + 1]) % mod + mod) % mod;
B[i] = ans;
}
}