import numberdb.sage as numberdb
from sage.arith.misc import binomial
from sage.rings.rational_field import QQ
def bdf_coefficients(s, normalisation='alpha-s-one'):
harmonic = sum(QQ(1) / QQ(k) for k in range(1, s + 1))
alpha = {
j: QQ((-1) ** (s - j)) * QQ(binomial(s, j)) / QQ(s - j)
for j in range(s)
}
alpha[s] = harmonic
beta = QQ(1)
if normalisation == 'alpha-s-one':
alpha = {j: value / harmonic for j, value in alpha.items()}
beta = QQ(1) / harmonic
elif normalisation != 'nabla':
raise ValueError("unknown normalisation")
out = {'beta': beta}
out.update({'alpha_%d' % j: alpha[j] for j in range(s + 1)})
return out
bdf_coefficients(3)The generator builds the order conditions over $\mathbb{Q}$ and solves them exactly in the normalisation $\beta_s=1$. Each stored method is checked against the defining moments, the Lagrange-basis derivative formula, the closed backward-difference formula in the Formulas section, and the six displayed BDF formulas in [1].