"""Failure mode: floating point instead of exact rationals. An answer to "write a Python function for Bernoulli numbers" can easily be float-based, because most Python numerical code is. The output looks entirely convincing at every index: ``-0.0333...`` really is close to ``-1/30``. It is still inexact from ``B2`` on. The digits stay good to about fourteen significant figures; what grows is the size of the error, about 1.2e-6 at ``B30`` (``8615841276005/14322``, roughly 601580873.9). A test that only checked ``B0`` to ``B12`` with an absolute tolerance would have passed this file, and a fixed tolerance of 1e-9 first fails it at ``B24``. Expected checker diagnosis: ``not-fraction``, a first divergence at ``n=2``, and ``odd-terms``: the checker compares each float as the exact rational it stores, so ``B3 = -1.1102230246251565e-16`` is not zero. """ def bernoulli(n: int) -> float: """Return B_n as a float (this is the bug).""" if n < 0: raise ValueError("n must be >= 0") values = [0.0] * (n + 1) for m in range(n + 1): values[m] = 1.0 for k in range(m): binomial = 1.0 for i in range(k): binomial = binomial * (m - i) / (i + 1) values[m] -= binomial * values[k] / (m - k + 1) if n == 1: return -values[n] return values[n]