# Bernoulli Numbers

 Function Library Home Bernoulli Numbers

### Description

There are several different definitions of the Bernoulli numbers, Bn. The definition programmed here arises from using the generating function
x / (ex-1) = Σn=0Bn xn / n!.
This definition yields B0 = 1,  B1 = -1/2,  B2 = 1/6,  B3 = 0,  B4 = -1/30 etc.
Multiply both sides of the generating function for the Bernoulli numbers by (e x - 1) / x
1 = (ex-1) / x Σn=0Bn xn / n!.
and expand (e x - 1) / x in a Taylor series expansion
1 = Σk=0 xk / (k+1)! Σn=0Bn xn / n! = Σk=0 Σn=0Bn xn+k / [n! (k+1)!] .
Rearrange the terms
1 = Σj=0 x j Σ jn=0 Bn / [n! (j-n+1)!] .
Then equate like powers of x on both sides of the equation
1 = B0
and
0 = Σ jn=0 Bn / [n! (j-n+1)!] , for j ≥ 1.
Solve for Bj for j ≥ 1,
Bj = - j! Σ j-1n=0 Bn / [n! (j-n+1)!] .
The even-indexed Bernoulli numbers can be expressed in terms of the Riemann zeta function as:
B2n = (-1)n [ 2 (2n)! / (2 π)2n ] ζ(2n)
.

#### Function List

• double Bernoulli_Number( int n )

This function returns Bn for n ≥ 0. If Bn ≤ -DBL_MAX, then -DBL_MAX is returned and if Bn ≥ DBL_MAX, then DBL_MAX is returned.

• void Bernoulli_Number_Sequence( double *b, int start, int length )

This function returns Bn in the array b for n = start, start + 1, ... , start + length - 1 where start ≥ 0 and length ≥ 1. I.e. b[n] = Bstart + n. If Bn ≤ -DBL_MAX, then -DBL_MAX is returned and if Bn ≥ DBL_MAX, then DBL_MAX is returned.

• void Bernoulli_Even_Index_Sequence( double *b, int start, int length )

This function returns Bn in the array b for n = start, start + 2, ... , start + 2*length - 1 where start ≥ 0 and length ≥ 1. I.e. b[n] = Bstart + 2n. If Bn ≤ -DBL_MAX, then -DBL_MAX is returned and if Bn ≥ DBL_MAX, then DBL_MAX is returned.

• int Max_Bernoulli_Even_Number_Index( void )

This function returns the maximum even number index of the largest Bernoulli representable as a type double. Note the Bernoulli numbers with odd index vanish save B1 which equals - 1 / 2.

• long double xBernoulli_Number( int n )

This function returns Bn for n ≥ 0. If Bn ≤ -LDBL_MAX, then -LDBL_MAX is returned and if Bn ≥ LDBL_MAX, then LDBL_MAX is returned.

• void xBernoulli_Number_Sequence( long double *b, int start, int length )

This function returns Bn in the array b for n = start, start + 1, ... , start + length - 1 where start ≥ 0 and length ≥ 1. I.e. b[n] = Bstart + n. If Bn ≤ -LDBL_MAX, then -LDBL_MAX is returned and if Bn ≥ LDBL_MAX, then LDBL_MAX is returned.

• void xBernoulli_Even_Index_Sequence( long double *b, int start, int length )

This function returns Bn in the array b for n = start, start + 2, ... , start + 2*length - 1 where start ≥ 0 and length ≥ 1. I.e. b[n] = Bstart + 2n. If Bn ≤ -LDBL_MAX, then -LDBL_MAX is returned and if Bn ≥ LDBL_MAX, then LDBL_MAX is returned.

• int xMax_Bernoulli_Even_Number_Index( void )

This function returns the maximum even number index of the largest Bernoulli representable as a type long double. Note the Bernoulli numbers with odd index vanish save B1 which equals - 1 / 2.

#### Source Code

C source code is available for these routines:
• The file, bernoulli_numbers.c, contains the functions Bernoulli_Number( ), Bernoulli_Number_Sequence( ), Bernoulli_Even_Index_Sequence( ), Max_Bernoulli_Even_Number_Index, xBernoulli_Number( ), xBernoulli_Number_Sequence( ), xBernoulli_Even_Index_Sequence( ), and xMax_Bernoulli_Even_Number_Index( ).

Dependencies: No external dependencies.