Skip to main content

Module bernoulli

Module bernoulli 

Source
Expand description

The Bernoulli sequence as vectors: $B_0, B_1, B_2, B_3, \ldots$, splatted.

This is the public face of the Bernoulli tables. The raw per-format tables live in tables::bernoulli and hold only the even-index numbers from $B_2$ up, because those are the ones that need a table; BernoulliSequence puts the head and the zeros back so the whole sequence can be iterated.

use thermite::prelude::*;
use thermite_special::bernoulli::BernoulliMath;

type V = Vector<f64>;

let b: Vec<f64> = V::bernoulli_numbers(-0.5)   // B_1 = -1/2, the caller's choice
    .take(7)
    .map(|v| v.extract::<0>())
    .collect();

assert_eq!(b, [1.0, -0.5, 1.0 / 6.0, 0.0, -1.0 / 30.0, 0.0, 1.0 / 42.0]);

§$B_1$ is yours to pick

It is the one Bernoulli number the two conventions disagree on ($-1/2$ from the generating function $x/(e^x - 1)$, $+1/2$ from $x/(1 - e^{-x})$), so the table does not carry it and this iterator takes it as an argument instead. Pass whichever your formula assumes. Nothing else in the sequence changes with the choice.

§Where it stops

After the last $B_{2n}$ representable in the element type: $B_{258}$ for f64 (259 items) and $B_{64}$ for f32 (65 items). $|B_{2n}|$ grows factorially, so there is nothing beyond it to yield. See the table docs for the boundary in full.

The iterator is ExactSizeIterator, so len() gives that count up front.

Structs§

BernoulliSequence
The Bernoulli sequence $B_0, B_1, B_2, \ldots$ as splatted vectors, including the zero-valued odd terms.

Traits§

BernoulliMath
Bernoulli numbers for real primal vectors.
BernoulliNumbers
Static Bernoulli number tables for a float format.

Functions§

bernoulli_b2n
$B_{2n}$, or None when it is not tabulated: either $n = 0$, or $B_{2n}$ overflows E.
Last built: 2026-09-08 21:35:55 UTC