omnibias.core.verified.coeffs
Coefficient recurrences, activation contracts, jet algebra, and verified arithmetic shared by the numerical backends.
import omnibias.core.verified.coeffsModule contract & mathematical conventions
Exact-integer derivative-tower polynomial coefficients + interval Horner.
omnibias.core.polynomials returns the activation derivative-tower
coefficients as float tuples; they are mathematically *integers* (Eulerian /
Legendre / Hermite recurrences) but lose exactness once n is large enough
that n!-scale values exceed 2**53. For a computer-assisted proof the
coefficients must stay exact, so this module reproduces the identical
recurrences in Python int arithmetic.
These are bit-for-bit the same sequences as the float versions wherever the
float versions are still exact -- tests asserts that overlap -- so the
verified tower composes with the float fast-paths without any drift.
Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.
bernoulli_number_exact
omnibias.core.verified.bernoulli_number_exactSource ↗bernoulli_number_exact(n: int) -> FractionThe n-th Bernoulli number B_n as an exact ~fractions.Fraction.
Read off the closed-form tanh tower: the odd derivative tanh^(2m-1)(0)
is the signed tangent number tanh_poly_coeffs_exact(2m-1)[0], and the Taylor
series tanh(x) = sum_m 2^{2m}(2^{2m}-1) B_{2m}/(2m)! x^{2m-1} gives
B_{2m} = \tanh^{(2m-1)}(0)\;\frac{2m}{2^{2m}\,(2^{2m}-1)}.
Convention B_0 = 1, B_1 = -1/2 (matches mpmath.bernoulli), and
B_{2m+1} = 0 for m >= 1. This is the shared source of truth for the
Bernoulli numbers used by omnibias.core.verified.euler_maclaurin and
re-exported by omnibias.difference.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
FractionExplicit validation & failure cases
- When
n < 0, raisesValueError(f'n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · bernoulli enclosure contains exact
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_bernoulli_enclosure_contains_exact(n: int) -> None:
assert _encloses(bernoulli_enclosure(n), bernoulli_number(n))python -m pytest "packages/omnibias-difference/tests/test_generating.py::test_bernoulli_enclosure_contains_exact[110]" -qRegression example · value at zero is bernoulli number
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_value_at_zero_is_bernoulli_number(self, n: int) -> None:
assert bernoulli_polynomial_exact(n, 0) == bernoulli_number_exact(n)python -m pytest packages/omnibias-core/tests/verified/test_bernoulli_polynomials.py -k test_value_at_zero_is_bernoulli_number -qRead the implementation
def bernoulli_number_exact(n: int) -> Fraction:
r"""The ``n``-th Bernoulli number ``B_n`` as an exact :class:`~fractions.Fraction`.
Read off the closed-form ``tanh`` tower: the odd derivative ``tanh^(2m-1)(0)``
is the signed tangent number ``tanh_poly_coeffs_exact(2m-1)[0]``, and the Taylor
series ``tanh(x) = sum_m 2^{2m}(2^{2m}-1) B_{2m}/(2m)! x^{2m-1}`` gives
.. math::
B_{2m} = \tanh^{(2m-1)}(0)\;\frac{2m}{2^{2m}\,(2^{2m}-1)}.
Convention ``B_0 = 1``, ``B_1 = -1/2`` (matches ``mpmath.bernoulli``), and
``B_{2m+1} = 0`` for ``m >= 1``. This is the shared source of truth for the
Bernoulli numbers used by :mod:`omnibias.core.verified.euler_maclaurin` and
re-exported by :mod:`omnibias.difference`.
"""
if n < 0:
raise ValueError(f"n must be >= 0, got {n}")
if n == 0:
return Fraction(1)
if n == 1:
return Fraction(-1, 2)
if n % 2 == 1:
return Fraction(0)
m = n // 2
tangent = tanh_poly_coeffs_exact(2 * m - 1)[0] # tanh^(2m-1)(0), an exact integer
return Fraction(tangent) * Fraction(2 * m) / Fraction(2 ** (2 * m) * (2 ** (2 * m) - 1))Other public import paths
omnibias.core.verified.bernoulli_number_exactomnibias.core.verified.coeffs.bernoulli_number_exact
bernoulli_polynomial_exact
omnibias.core.verified.bernoulli_polynomial_exactSource ↗bernoulli_polynomial_exact(n: int, x: Fraction | int) -> FractionThe Bernoulli polynomial B_n(x) at a rational x as an exact Fraction.
with the B_1 = -1/2 convention (matches mpmath.bernpoly). Hence
B_n(0) = B_n, B_1(x) = x - 1/2, B_2(x) = x^2 - x + 1/6. This is the
shared source for the Hurwitz-zeta negative-integer special values
zeta(-n, a) = -B_{n+1}(a)/(n+1) and the generalized Bernoulli numbers below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
xpositional-or-keyword | Fraction | intRequired | See the operation contract and implementation below. |
FractionExplicit validation & failure cases
- When
n < 0, raisesValueError(f'n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · value at zero is bernoulli number
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_value_at_zero_is_bernoulli_number(self, n: int) -> None:
assert bernoulli_polynomial_exact(n, 0) == bernoulli_number_exact(n)python -m pytest "packages/omnibias-core/tests/verified/test_bernoulli_polynomials.py::TestBernoulliPolynomials::test_value_at_zero_is_bernoulli_number[0]" -qRegression example · reflection B n of one
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_reflection_B_n_of_one(self) -> None:
# B_n(1) = (-1)^n B_n.
for n in range(0, 12):
assert bernoulli_polynomial_exact(n, 1) == (-1) ** n * bernoulli_number_exact(n)python -m pytest packages/omnibias-core/tests/verified/test_bernoulli_polynomials.py -k test_reflection_B_n_of_one -qRead the implementation
def bernoulli_polynomial_exact(n: int, x: Fraction | int) -> Fraction:
r"""The Bernoulli polynomial ``B_n(x)`` at a rational ``x`` as an exact Fraction.
.. math:: B_n(x) = \sum_{k=0}^{n} \binom{n}{k} B_k\, x^{n-k},
with the ``B_1 = -1/2`` convention (matches ``mpmath.bernpoly``). Hence
``B_n(0) = B_n``, ``B_1(x) = x - 1/2``, ``B_2(x) = x^2 - x + 1/6``. This is the
shared source for the Hurwitz-zeta negative-integer special values
``zeta(-n, a) = -B_{n+1}(a)/(n+1)`` and the generalized Bernoulli numbers below.
"""
if n < 0:
raise ValueError(f"n must be >= 0, got {n}")
xf = Fraction(x)
total = Fraction(0)
for k in range(n + 1):
total += comb(n, k) * bernoulli_number_exact(k) * xf ** (n - k)
return totalOther public import paths
omnibias.core.verified.bernoulli_polynomial_exactomnibias.core.verified.coeffs.bernoulli_polynomial_exact
euler_number_exact
omnibias.core.verified.euler_number_exactSource ↗euler_number_exact(n: int) -> intThe n-th Euler (secant) number E_n as an exact integer.
Read off the closed-form sech tower: sech^(n)(0) = Q_n(0) sech(0) =
Q_n(0), so E_n is the constant term
sech_poly_coeffs_exact\ (n)[0]. Convention E_0 = 1,
E_{2m+1} = 0, E_2 = -1, E_4 = 5, E_6 = -61 (matches
mpmath.eulernum). This is the shared source of truth for the Euler numbers
used by the Dirichlet beta special values and re-exported by
omnibias.difference.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
intExplicit validation & failure cases
- When
n < 0, raisesValueError(f'n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · euler recurrence is zero
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_euler_recurrence_is_zero(self, m: int) -> None:
cert = euler_recurrence_identity(m)
assert _lhs_sum(cert) == 0
assert sum(comb(2 * m, 2 * k) * euler_number_exact(2 * k) for k in range(m + 1)) == 0python -m pytest "packages/omnibias-difference/tests/test_identities.py::TestIdentitiesHoldExactly::test_euler_recurrence_is_zero[1]" -qRegression example · q euler matches core exact
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_q_euler_matches_core_exact() -> None:
from omnibias.core.verified.coeffs import euler_number_exact
for n in range(0, 9, 2):
assert q_euler(n, 1) == euler_number_exact(n)python -m pytest packages/omnibias-qcalculus/tests/test_qspecial.py -k test_q_euler_matches_core_exact -qRead the implementation
def euler_number_exact(n: int) -> int:
r"""The ``n``-th Euler (secant) number ``E_n`` as an exact integer.
Read off the closed-form ``sech`` tower: ``sech^(n)(0) = Q_n(0) sech(0) =
Q_n(0)``, so ``E_n`` is the constant term
:func:`sech_poly_coeffs_exact`\ ``(n)[0]``. Convention ``E_0 = 1``,
``E_{2m+1} = 0``, ``E_2 = -1``, ``E_4 = 5``, ``E_6 = -61`` (matches
``mpmath.eulernum``). This is the shared source of truth for the Euler numbers
used by the Dirichlet ``beta`` special values and re-exported by
:mod:`omnibias.difference`.
"""
if n < 0:
raise ValueError(f"n must be >= 0, got {n}")
return int(sech_poly_coeffs_exact(n)[0])Other public import paths
omnibias.core.verified.euler_number_exactomnibias.core.verified.coeffs.euler_number_exact
generalized_bernoulli_exact
omnibias.core.verified.generalized_bernoulli_exactSource ↗generalized_bernoulli_exact(n: int, chi: Sequence[int | Fraction]) -> FractionGeneralized Bernoulli number B_{n,chi} for a *real* Dirichlet character.
chi is the periodic value table of a real character modulo f = len(chi):
chi[a] is chi(a) for a = 0..f-1 (chi[0] = chi(0), typically 0
for a non-principal character). Then
an exact ~fractions.Fraction (real characters give rational values).
The Dirichlet L special values read this off as L(1-n, chi) = -B_{n,chi}/n
(n >= 1). chi = (0, 1) (trivial character mod 1 shifted) recovers
B_{n,chi} = B_n.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
chipositional-or-keyword | Sequence[int | Fraction]Required | See the operation contract and implementation below. |
FractionExplicit validation & failure cases
- When
f < 1, raisesValueError('character table must be non-empty'). - When
n < 0, raisesValueError(f'n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · input guards
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_input_guards(self) -> None:
with pytest.raises(ValueError):
generalized_bernoulli_exact(1, ())
with pytest.raises(ValueError):
generalized_bernoulli_exact(-1, (1,))
with pytest.raises(ValueError):
bernoulli_polynomial_exact(-1, 0)python -m pytest "packages/omnibias-core/tests/verified/test_bernoulli_polynomials.py::TestGeneralizedBernoulli::test_input_guards" -qRegression example · trivial character recovers bernoulli
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_trivial_character_recovers_bernoulli(self) -> None:
# Principal character mod 1: B_{n,chi} = B_n except n=1 (B_1(1) = +1/2).
assert generalized_bernoulli_exact(0, (1,)) == bernoulli_number_exact(0)
assert generalized_bernoulli_exact(1, (1,)) == Fraction(1, 2)
for n in range(2, 6):
assert generalized_bernoulli_exact(n, (1,)) == bernoulli_number_exact(n)python -m pytest packages/omnibias-core/tests/verified/test_bernoulli_polynomials.py -k test_trivial_character_recovers_bernoulli -qRead the implementation
def generalized_bernoulli_exact(n: int, chi: Sequence[int | Fraction]) -> Fraction:
r"""Generalized Bernoulli number ``B_{n,chi}`` for a *real* Dirichlet character.
``chi`` is the periodic value table of a real character modulo ``f = len(chi)``:
``chi[a]`` is ``chi(a)`` for ``a = 0..f-1`` (``chi[0] = chi(0)``, typically ``0``
for a non-principal character). Then
.. math:: B_{n,\chi} = f^{\,n-1} \sum_{a=1}^{f} \chi(a)\, B_n(a/f),
an exact :class:`~fractions.Fraction` (real characters give rational values).
The Dirichlet ``L`` special values read this off as ``L(1-n, chi) = -B_{n,chi}/n``
(``n >= 1``). ``chi = (0, 1)`` (trivial character mod 1 shifted) recovers
``B_{n,chi} = B_n``.
"""
f = len(chi)
if f < 1:
raise ValueError("character table must be non-empty")
if n < 0:
raise ValueError(f"n must be >= 0, got {n}")
total = Fraction(0)
for a in range(1, f + 1):
chi_a = Fraction(chi[a % f])
if chi_a == 0:
continue
total += chi_a * bernoulli_polynomial_exact(n, Fraction(a, f))
return Fraction(f) ** (n - 1) * totalOther public import paths
omnibias.core.verified.generalized_bernoulli_exactomnibias.core.verified.coeffs.generalized_bernoulli_exact
hermite_coeffs_exact
omnibias.core.verified.hermite_coeffs_exactSource ↗hermite_coeffs_exact(n: int) -> tuple[int, ...]Exact integer coefficients of the probabilist's Hermite polynomial He_n.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
tuple[int, ...]Explicit validation & failure cases
- When
n < 0, raisesValueError(f'order n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · residual contains zero and is tight
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_residual_contains_zero_and_is_tight(name: str, a: float, b: float, k: int) -> None:
residual = certified_ftc_residual(name, a, b, k=k, order=8)
assert residual.contains(0.0) # a sound tower forces the true residual to 0
assert residual.width < 1e-3 # rigorous + tight over a modest cellpython -m pytest "packages/omnibias-core/tests/verified/test_ftc.py::test_residual_contains_zero_and_is_tight[gaussian--0.3-0.2-1]" -qRegression example · hermite exact coeffs small
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_exact_coeffs_small() -> None:
assert hermite_coeffs_exact(2) == (-1, 0, 1) # He_2 = z^2 - 1
assert hermite_coeffs_exact(3) == (0, -3, 0, 1) # He_3 = z^3 - 3zpython -m pytest packages/omnibias-core/tests/verified/test_sigma_and_jet.py -k test_hermite_exact_coeffs_small -qRead the implementation
def hermite_coeffs_exact(n: int) -> tuple[int, ...]:
"""Exact integer coefficients of the probabilist's Hermite polynomial ``He_n``."""
if n < 0:
raise ValueError(f"order n must be >= 0, got {n}")
if n == 0:
return (1,)
# Iterative, so a tall tower costs memory but never a RecursionError.
prev2: tuple[int, ...] = (1,)
prev1: tuple[int, ...] = (0, 1)
for m in range(2, n + 1):
out = [0] * (m + 1)
for k, c in enumerate(prev1):
out[k + 1] += c
for k, c in enumerate(prev2):
out[k] -= (m - 1) * c
prev2, prev1 = prev1, tuple(out)
return prev1Other public import paths
omnibias.core.verified.hermite_coeffs_exactomnibias.core.verified.coeffs.hermite_coeffs_exact
horner_interval
omnibias.core.verified.horner_intervalSource ↗horner_interval(coeffs: Sequence[int], x: Interval) -> IntervalRigorously evaluate sum_k coeffs[k] * x**k by interval Horner.
Parameters
| Name | Type & default | Contract |
|---|---|---|
coeffspositional-or-keyword | Sequence[int]Required | See the operation contract and implementation below. |
xpositional-or-keyword | IntervalRequired | See the operation contract and implementation below. |
IntervalExecuted regression · g2 non vacuous
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_g2_non_vacuous() -> None:
ex = worked_example()
assert float(ex["remainder_width"]) < 0.1
assert ex["vacuous"] is False
assert float(ex["width"]) < 0.1python -m pytest "packages/omnibias-core/tests/verified/test_tm_neuron.py::test_g2_non_vacuous" -qRead the implementation
def horner_interval(coeffs: Sequence[int], x: Interval) -> Interval:
"""Rigorously evaluate ``sum_k coeffs[k] * x**k`` by interval Horner."""
if not coeffs:
return Interval.point(0.0)
acc = Interval.from_rational(int(coeffs[-1]))
for c in reversed(coeffs[:-1]):
acc = acc * x + Interval.from_rational(int(c))
return accOther public import paths
omnibias.core.verified.horner_intervalomnibias.core.verified.coeffs.horner_interval
sech_poly_coeffs_exact
omnibias.core.verified.sech_poly_coeffs_exactSource ↗sech_poly_coeffs_exact(n: int) -> tuple[int, ...]Exact integer coefficients of Q_n(t) with sech^(n)(z) = Q_n(t) sech(z).
Same tanh/sech Riccati recurrence as
omnibias.core.polynomials.sech_polynomial_coeffs in exact int
arithmetic: Q_0 = 1, Q_{n+1}(t) = (1 - t^2) Q_n'(t) - t Q_n(t). The
constant term Q_n(0) is the exact n-th Euler (secant) number E_n.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
tuple[int, ...]Explicit validation & failure cases
- When
n < 0, raisesValueError(f'order n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · euler enclosure contains exact
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_euler_enclosure_contains_exact(n: int) -> None:
assert _encloses(euler_enclosure(n), euler_number(n))python -m pytest "packages/omnibias-difference/tests/test_generating.py::test_euler_enclosure_contains_exact[110]" -qRegression example · tanh exact coeffs match float
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_tanh_exact_coeffs_match_float(n: int) -> None:
exact = tanh_poly_coeffs_exact(n)
flt = tanh_polynomial_coeffs(n)
assert len(exact) == len(flt)
for ce, cf in zip(exact, flt, strict=True):
assert float(ce) == cf # still exact as double at these orderspython -m pytest packages/omnibias-core/tests/verified/test_sigma_and_jet.py -k test_tanh_exact_coeffs_match_float -qRead the implementation
def sech_poly_coeffs_exact(n: int) -> tuple[int, ...]:
r"""Exact integer coefficients of ``Q_n(t)`` with ``sech^(n)(z) = Q_n(t) sech(z)``.
Same tanh/sech Riccati recurrence as
:func:`omnibias.core.polynomials.sech_polynomial_coeffs` in exact ``int``
arithmetic: ``Q_0 = 1``, ``Q_{n+1}(t) = (1 - t^2) Q_n'(t) - t Q_n(t)``. The
constant term ``Q_n(0)`` is the exact ``n``-th Euler (secant) number ``E_n``.
"""
if n < 0:
raise ValueError(f"order n must be >= 0, got {n}")
# Iterative, so a tall tower costs memory but never a RecursionError.
coeffs: tuple[int, ...] = (1,)
for _ in range(n):
deriv = [k * coeffs[k] for k in range(1, len(coeffs))]
out = [0] * (len(coeffs) + 1)
for i, c in enumerate(deriv):
out[i] += c
out[i + 2] -= c
for i, c in enumerate(coeffs):
out[i + 1] -= c
coeffs = tuple(out)
return coeffsOther public import paths
omnibias.core.verified.sech_poly_coeffs_exactomnibias.core.verified.coeffs.sech_poly_coeffs_exact
sigmoid_poly_coeffs_exact
omnibias.core.verified.sigmoid_poly_coeffs_exactSource ↗sigmoid_poly_coeffs_exact(n: int) -> tuple[int, ...]Exact integer coefficients of P_n(s) = sigma^(n)(z), s=sigmoid(z).
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
tuple[int, ...]Explicit validation & failure cases
- When
n < 0, raisesValueError(f'order n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · residual contains zero and is tight
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_residual_contains_zero_and_is_tight(name: str, a: float, b: float, k: int) -> None:
residual = certified_ftc_residual(name, a, b, k=k, order=8)
assert residual.contains(0.0) # a sound tower forces the true residual to 0
assert residual.width < 1e-3 # rigorous + tight over a modest cellpython -m pytest "packages/omnibias-core/tests/verified/test_ftc.py::test_residual_contains_zero_and_is_tight[sigmoid--0.2-0.3-1]" -qRegression example · sigmoid exact coeffs small
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_sigmoid_exact_coeffs_small() -> None:
# P_1(s) = s - s^2 ; P_2(s) = s - 3 s^2 + 2 s^3.
assert sigmoid_poly_coeffs_exact(1) == (0, 1, -1)
assert sigmoid_poly_coeffs_exact(2) == (0, 1, -3, 2)python -m pytest packages/omnibias-core/tests/verified/test_sigma_and_jet.py -k test_sigmoid_exact_coeffs_small -qRead the implementation
def sigmoid_poly_coeffs_exact(n: int) -> tuple[int, ...]:
"""Exact integer coefficients of ``P_n(s) = sigma^(n)(z)``, ``s=sigmoid(z)``."""
if n < 0:
raise ValueError(f"order n must be >= 0, got {n}")
# Iterative, so a tall tower costs memory but never a RecursionError.
coeffs = [0, 1]
for _ in range(n):
deriv = [k * coeffs[k] for k in range(1, len(coeffs))]
out = [0] * (len(deriv) + 2)
for i, c in enumerate(deriv):
out[i + 1] += c
out[i + 2] -= c
coeffs = out
return tuple(coeffs)Other public import paths
omnibias.core.verified.sigmoid_poly_coeffs_exactomnibias.core.verified.coeffs.sigmoid_poly_coeffs_exact
tanh_poly_coeffs_exact
omnibias.core.verified.tanh_poly_coeffs_exactSource ↗tanh_poly_coeffs_exact(n: int) -> tuple[int, ...]Exact integer coefficients of T_n(t) = tanh^(n)(z), t=tanh(z).
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
tuple[int, ...]Explicit validation & failure cases
- When
n < 0, raisesValueError(f'order n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · bernoulli enclosure contains exact
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_bernoulli_enclosure_contains_exact(n: int) -> None:
assert _encloses(bernoulli_enclosure(n), bernoulli_number(n))python -m pytest "packages/omnibias-difference/tests/test_generating.py::test_bernoulli_enclosure_contains_exact[110]" -qRegression example · tanh exact coeffs match float
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_tanh_exact_coeffs_match_float(n: int) -> None:
exact = tanh_poly_coeffs_exact(n)
flt = tanh_polynomial_coeffs(n)
assert len(exact) == len(flt)
for ce, cf in zip(exact, flt, strict=True):
assert float(ce) == cf # still exact as double at these orderspython -m pytest packages/omnibias-core/tests/verified/test_sigma_and_jet.py -k test_tanh_exact_coeffs_match_float -qRead the implementation
def tanh_poly_coeffs_exact(n: int) -> tuple[int, ...]:
"""Exact integer coefficients of ``T_n(t) = tanh^(n)(z)``, ``t=tanh(z)``."""
if n < 0:
raise ValueError(f"order n must be >= 0, got {n}")
# Iterative, so a tall tower costs memory but never a RecursionError.
coeffs = [0, 1]
for _ in range(n):
deriv = [k * coeffs[k] for k in range(1, len(coeffs))]
out = [0] * (len(deriv) + 2)
for i, c in enumerate(deriv):
out[i] += c
out[i + 2] -= c
coeffs = out
return tuple(coeffs)Other public import paths
omnibias.core.verified.tanh_poly_coeffs_exactomnibias.core.verified.coeffs.tanh_poly_coeffs_exact