Repository navigation
Keep the digits of arsinh and arcsch of a small argument - #2688
Merged
Merged
Conversation
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 Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2686
Cause
arsinh(a)isln(a + sqrt(a^2 + 1)). For a smallathe square root is1 + a^2/2 - ..., and the downcastingtakes a value within
10^(-precision/2)of an integer for that integer. At a hundred digits,sqrt(10^(-50) + 1) - 1evaluates to0whilesqrt(10^(-40) + 1) - 1is5E-41. So fromabelow about10^(-25)the antilogarithm was1 + aand the logarithm wasln(1 + a), short ofa^2/2.The irregular exponents come from
NearOneWithMoreDigits(#2681). Where the modulus of the antilogarithm is within10^(-25)of 1, it evaluates the argument again withprecision + k + 10digits, rounded up to a multiple of 16. Atthose digits the tolerance is
10^(-digits/2):aa^2/210^-252e-25is not below1e-251e-505e-5110^-301e-725e-6110^-351e-805e-7110^-401e-805e-8110^-601e-885e-121Above
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 asais below 1. For example,arsinh(10^(-16))was right to 84 digits.arcsch(y)is the same logarithm witha = 1/y.Fix
Logfnow recognises an antilogarithms a + sqrt(a^2 + 1)(or1/ywith1/y^2, asarcschwrites it) whenais below about
10^(-2). It takes the logarithm asln(1 + u), withu = s a + a^2/(sqrt(a^2 + 1) + 1):uis the same number, and computing it cancels nothing.sqrt(a^2 + 1) - 1is refined once from itself, so a root that the downcasting rounded to 1 is stillaccurate enough.
ln(1 + u)is taken with as many extra digits asuis below 1, or asu - u^2/2past half the digits.a,1 + uis 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.
arsinh(10^-16)arsinh(10^-20)arsinh(10^-25)arsinh(10^-30)/(10^-35)arsinh(10^-40)arsinh(10^-60)arsinh(10^-81)arsinh(10^-99)arcsch(10^40)arcsch(10^60)arsinh(10^-46 * i)Sweep: 1720 rows. The sweep covers:
arsinhat±10^-k,±10^-k ± 10^-(k+3)/3and±10^-k iarcschat±10^kand±10^k iartanh,arcoth,ln(1 + x),arsechandarcoshat the same sizesk= 1..60, then every thirdkup to 120arsinhandarcschat moderate and large arguments (37/100,±1,±2,2i,±10^30 ± 1/3,±10^200,±10^200 i,±10^60 i,3 + 4i)Results:
arsinhandarcsch: of 1000 values, master had 391 wrong past 1e-95. The branch has none, and the largesterror is 5.4e-98.
arsinhorarcschwithabelow10^-2.artanh,arcoth,arsechandarcoshreturn identical values on both builds. Theirexisting losses near 0 or 1 are not touched here. For example,
artanh(10^-20)is right to 80 digits, andarcosh(1 + 10^-120)is wrong.Tests:
Issue2686_TheAreaSineOfASmallArgumentKeepsItsDigits, eleven rows held to 1e-95 of mpmath.Allocation:
GC.GetAllocatedBytesForCurrentThreadover 3000Substitute(...).Evaledcalls after a warm-up, twoalternating runs per build. The two runs agree to within 50 B.
ln(1 + x^2)*arctan(x)at 0.37000000000001234 (EvalTranscendentalFresh)arsinh(x)at 0.37arcsch(x)at 0.37arsinh(x)at 10^-25arcsch(x)at 10^-25Harnesses: each run alternately on master and the branch, twice, under the chain lock. Their reports are
byte-identical.
🤖 Generated with Claude Code