Skip to content

Add a dev-only nanobind Python layer and the beta distribution's entropy - #1563

Merged
NAThompson merged 1 commit into
developfrom
python-dev-layer
Oct 12, 2026
Merged

NAThompson merged 1 commit into
developfrom
python-dev-layer

Conversation

@NAThompson

@NAThompson NAThompson commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

nanobind/ bindings (not built by CI); entropy(beta_distribution) via Stirling and zeta series; libeta, ligamma and lbeta return an exact -inf instead of raising; x87 tolerance in test_lanczos_smoothing.

Closes #1508

entropy(beta_distribution)

The textbook form log B(α, β) − (α−1)ψ(α) − (β−1)ψ(β) + (α+β−2)ψ(α+β) cancels catastrophically. For large α or β the terms grow like α log α while H only grows like log α, and near α = β = 1 the terms are first order while H is second order.

  • α or β ≥ 10 (scaled with precision): Stirling remainder series cancel the large parts exactly, giving H = ½ log(2πe αβ/s³) − 1/(2α) − 1/(2β) + 1/s + r(α) + r(β) − r(s) + ν(s), with s = α + β.
  • Both small: H = g(α) + g(β) + k(s), where g(x) = lgamma(x) − (x−1)ψ(x) and k(s) = (s−2)ψ(s) − lgamma(s) vanish to second order at 1 and 2. Near those points they come from zeta series.

Against mpmath at 40 digits on a 500 × 500 log grid, double precision, the median error is 0.63 ulps and the maximum 110. The maximum is at 1 ≲ α, β ≲ 10, where neither series applies. The textbook form reaches 5.3·10⁶ ulps.

entropy ulps

textbook formula ulps

cpp_bin_float_50 gives 0.03 to 21 eps at the test points.

🤖 Generated with Claude Code

@NAThompson NAThompson changed the title Add a dev-only nanobind Python layer [ci skip] Add a dev-only nanobind Python layer Oct 12, 2026
nanobind/ bindings (not built by CI); entropy(beta_distribution) via Stirling and zeta series; libeta, ligamma and lbeta return an exact -inf instead of raising; x87 tolerance in test_lanczos_smoothing.
Closes #1508

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NAThompson NAThompson changed the title Add a dev-only nanobind Python layer Add a dev-only nanobind Python layer and the beta distribution's entropy Oct 12, 2026
@NAThompson
NAThompson merged commit a4f2d48 into develop Oct 12, 2026
48 of 50 checks passed
@NAThompson
NAThompson deleted the python-dev-layer branch October 12, 2026 05:00
@steppi steppi mentioned this pull request Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nanobind layer

1 participant