Skip to content

Keep the digits of arsinh and arcsch of a small argument - #2688

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
fix-2686-small-arsinh-digits
Dec 3, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
fix-2686-small-arsinh-digits

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2686

Cause

arsinh(a) is ln(a + sqrt(a^2 + 1)). For a small a the square root is 1 + a^2/2 - ..., and the downcasting
takes a value within 10^(-precision/2) of an integer for that integer. At a hundred digits,
sqrt(10^(-50) + 1) - 1 evaluates to 0 while sqrt(10^(-40) + 1) - 1 is 5E-41. So from a below about
10^(-25) the antilogarithm was 1 + a and the logarithm was ln(1 + a), short of a^2/2.

The irregular exponents come from NearOneWithMoreDigits (#2681). Where the modulus of the antilogarithm is within
10^(-25) of 1, it evaluates the argument again with precision + k + 10 digits, rounded up to a multiple of 16. At
those digits the tolerance is 10^(-digits/2):

a near-1 path? digits tolerance a^2/2 result
10^-25 no: distance 2e-25 is not below 1e-25 100 1e-50 5e-51 lost, 25 digits right
10^-30 yes 144 1e-72 5e-61 kept, right
10^-35 yes 160 1e-80 5e-71 kept, right
10^-40 yes 160 1e-80 5e-81 lost, 40 digits right
10^-60 yes 176 1e-88 5e-121 lost, 60 digits right

Above 10^(-25) there was a second, smaller loss. The sum near 1 is rounded at the working digits, so the logarithm,
about a, is short of as many digits as a is below 1. For example, arsinh(10^(-16)) was right to 84 digits.
arcsch(y) is the same logarithm with a = 1/y.

Fix

Logf now recognises an antilogarithm s a + sqrt(a^2 + 1) (or 1/y with 1/y^2, as arcsch writes it) when a
is below about 10^(-2). It takes the logarithm as ln(1 + u), with u = s a + a^2/(sqrt(a^2 + 1) + 1):

  • u is the same number, and computing it cancels nothing.
  • The excess sqrt(a^2 + 1) - 1 is refined once from itself, so a root that the downcasting rounded to 1 is still
    accurate enough.
  • ln(1 + u) is taken with as many extra digits as u is below 1, or as u - u^2/2 past half the digits.
  • For an imaginary a, 1 + u is on the unit circle and the real part is exactly 0.

Every other logarithm drops out of the check on its shape alone, without allocating.

Measurements

Master 0b1b7d7 against this branch, at 100 digits. Errors are relative to mpmath at 400 digits.

master branch
arsinh(10^-16) 5.0e-84 9.5e-102
arsinh(10^-20) 3.3e-101 3.3e-101
arsinh(10^-25) 5.0e-26 4.1e-101
arsinh(10^-30) / (10^-35) 3.3e-101 3.3e-101
arsinh(10^-40) 5.0e-41 3.3e-101
arsinh(10^-60) 5.0e-61 1.7e-121
arsinh(10^-81) 5.0e-82 1.7e-163
arsinh(10^-99) 5.0e-100 1.7e-199
arcsch(10^40) 5.0e-41 3.3e-101
arcsch(10^60) 5.0e-61 1.7e-121
arsinh(10^-46 * i) 5.0e-93 3.3e-100

Sweep: 1720 rows. The sweep covers:

  • arsinh at ±10^-k, ±10^-k ± 10^-(k+3)/3 and ±10^-k i
  • arcsch at ±10^k and ±10^k i
  • artanh, arcoth, ln(1 + x), arsech and arcosh at the same sizes
  • for k = 1..60, then every third k up to 120
  • arsinh and arcsch at moderate and large arguments (37/100, ±1, ±2, 2i, ±10^30 ± 1/3, ±10^200,
    ±10^200 i, ±10^60 i, 3 + 4i)

Results:

  • arsinh and arcsch: of 1000 values, master had 391 wrong past 1e-95. The branch has none, and the largest
    error is 5.4e-98.
  • Non-finite values: none.
  • Regressions: no row that was right on master is wrong on the branch.
  • Changed values: 563, all arsinh or arcsch with a below 10^-2.
  • The other functions: artanh, arcoth, arsech and arcosh return identical values on both builds. Their
    existing losses near 0 or 1 are not touched here. For example, artanh(10^-20) is right to 80 digits, and
    arcosh(1 + 10^-120) is wrong.

Tests:

  • UnitTests: 22139 passed, 0 failed, 13 skipped.
  • FSharpWrapperUnitTests: 135 passed.
  • New: Issue2686_TheAreaSineOfASmallArgumentKeepsItsDigits, eleven rows held to 1e-95 of mpmath.

Allocation: GC.GetAllocatedBytesForCurrentThread over 3000 Substitute(...).Evaled calls after a warm-up, two
alternating runs per build. The two runs agree to within 50 B.

master B/op branch B/op
ln(1 + x^2)*arctan(x) at 0.37000000000001234 (EvalTranscendentalFresh) 34680 34680
arsinh(x) at 0.37 153532-153590 153546-153559
arcsch(x) at 0.37 133193 133256 (+0.05%)
arsinh(x) at 10^-25 158263 227304 (+44%; master returned 25 digits on this row)
arcsch(x) at 10^-25 194506-194511 194509 (large argument, outside the new path)

Harnesses: each run alternately on master and the branch, twice, under the chain lock. Their reports are
byte-identical.

master branch
limitcheck 27.9 s, 28.1 s 28.7 s, 28.2 s
symlimitcheck 25.0 s, 24.9 s 25.0 s, 25.2 s

🤖 Generated with Claude Code

arsinh(a) is ln(a + sqrt(a^2 + 1)), and the square root, within a^2/2 of 1,
is taken for 1 by the downcasting below half the working digits, so the
logarithm was ln(1 + a): arsinh(10^-25) kept 25 digits and arsinh(10^-60) 60.
The logarithm near 1, evaluated again with more digits, kept a^2/2 only where
those digits put the tolerance below it, which is why 10^-30 and 10^-35 were
right. Above 10^-25 the sum near 1 kept the digits of 1, not of a.

The logarithm of s a + sqrt(a^2 + 1), which arcsch reaches with a = 1/y, is
now taken for a below about 10^-2 as ln(1 + u), u = s a + a^2/(sqrt(a^2 + 1) + 1),
which cancels nothing, with as many digits more as u is below 1.

Fixes #2686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.63%. Comparing base (0b1b7d7) to head (06c277b).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 81.81% 4 Missing and 6 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2688      +/-   ##
==========================================
- Coverage   86.64%   86.63%   -0.01%     
==========================================
  Files         346      346              
  Lines       76464    76558      +94     
  Branches    22452    22483      +31     
==========================================
+ Hits        66253    66328      +75     
- Misses       5513     5522       +9     
- Partials     4698     4708      +10     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.12% <81.81%> (-0.01%) ⬇️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 87.51% <81.81%> (-0.27%) ⬇️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 3ccf893 into master Dec 3, 2026
47 of 53 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Dec 3, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fix-2686-small-arsinh-digits branch December 3, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

arsinh and arcsch of a small argument keep only some of their digits

1 participant