Skip to content

Fix tanh′ interval enclosures in saturated tails - #192

Merged
MoritzMaibaum merged 1 commit into
better-intfrom
codex/tanh-prime-stable
Sep 28, 2026
Merged

MoritzMaibaum merged 1 commit into
better-intfrom
codex/tanh-prime-stable

Conversation

@MoritzMaibaum

Copy link
Copy Markdown
Collaborator

The interval tanh′ routine evaluates 1 - tanh(x)**2, which can round to zero and exclude the real derivative. On [20,21], the old enclosure is approximately [-1.4e-45, 1.4e-45], while the real range is approximately [2.2998e-18, 1.6993e-17].

Use the stable 4*q/(1+q)**2 formula with q=exp(-2*abs(x)), directed Decimal arithmetic, and extremum selection by distance to zero. The new public tanh_prime_bounds preserves [1,1] at zero, keeps bounds within [0,1], and handles subnormal values and underflow conservatively. The ordinary interval Jacobian/Hessian path retains float32 padding within [0,1]. Deep hybrid derivative interval factors use the same helper, with outward rounding after tensor conversion.

Includes the rounding argument and high-precision cosh-based reference tests. Also corrects the optional PyTorch import guard so the scalar activation API can be imported without PyTorch.

Validation: full suite passed (333 tests), including saturated-tail Jacobian regression, extreme numerical cases, float32/float64 deep-factor conversion, and no-PyTorch import. The committed tree exactly matches the tested checkout.

Use the outward-rounded stable 4*q/(1+q)^2 endpoint formula with q=exp(-2*abs(x)). Select extrema by distance to zero, preserve exact zero-domain value 1, clip bounds to [0,1], and handle underflow conservatively. Apply the scalar helper to the interval Jacobian/Hessian path and deep hybrid derivative interval factors, rounding again after tensor conversion.

Expose tanh_prime_bounds, document the rounding argument, and fix the optional PyTorch import guard so scalar activation bounds work without PyTorch.

Validation: all 333 tests passed, including high-precision references, saturated-tail regressions, subnormal inputs/outputs, tensor dtype conversion, and import without PyTorch.
@MoritzMaibaum
MoritzMaibaum merged commit 2ed8991 into better-int Sep 28, 2026
1 check passed
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.

1 participant