Skip to content

Take the side approached at an inverse trigonometric cut in limits - #2742

Open
Rafael-SOWNet wants to merge 1 commit into
masterfrom
fix-2709-arcsin-arccos-cut-side
Open

Rafael-SOWNet wants to merge 1 commit into
masterfrom
fix-2709-arcsin-arccos-cut-side

Conversation

@Rafael-SOWNet

@Rafael-SOWNet Rafael-SOWNet commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

What was wrong. A limit reaching the cut of arcsin, arccos, arcsec, arccsc or arccot from the side the function does not take its value from was answered with that value. arcsin(2 + i/x) at +oo gave arcsin(2) = pi/2 - 1.317i, where it tends to pi/2 + 1.317i. And along the negative half of the real cut, readings through derivatives took the other side from eval. 1 / sqrt(1 - t^2) takes the principal root of a negative number, which is the side from below past 1 and from above past -1, while the library takes both halves from below. So arccos(-x) / ln(x) at +oo was -i, where eval(arccos(-1e30) / ln(1e30)) is 0.045 + 1.010i.

The library's convention, measured with eval: arcsin(2) = pi/2 - 1.317i, arcsin(-2) = -pi/2 - 1.317i, arccos(2) = 1.317i, arccos(-2) = pi + 1.317i. That is the limit from below on both halves. So arccos(-2 + i x) at 0+, which comes from above, was also wrong on master (arccos(-2); the true value is pi - 1.317i). arcsec/arccsc take their cut (-1, 1) from above. arccot(i/2) is the limit from the left and arccot(-i/2) the limit from the right.

The fix.

  • Off the real line: the descent reads the side from the sign of the argument's imaginary part (the real part for arccot). The argument is split structurally into parts that are real on the approach. From the value's side the answer is the value. From the other side it is the value across the jump: the conjugate, or arccot ± pi. Where the side cannot be read (2 + i sin(x)/x, or anything the split does not handle), the limit is declined, as ln(-1 + i/x) already is. Substitution and Gruntz decline the same arguments unless they come from the value's side.
  • Along the negative half: an argument real on the approach and below -1 (between -1 and 0 for arcsec/arccsc) is rewritten through the negated argument: arcsin(t) = arcsin(-t) - pi, arccos(t) = pi + arccos(-t). These are the library's own values, and on the positive half every reading agrees with them.
  • Substitution writes arcsin/arccos of an infinity as the angle they evaluate to.

artanh, arcoth, arcosh, arsinh, arsech and arcsch are rewritten to logarithms and already declined these limits. arctan already declined them too.

Measured against mpmath, using the library's convention on the cut:

master this branch
286 generated variants (both cut classes, all five functions, finite points and infinities, one- and two-sided) 58 wrong, 130 slow-converging 0 wrong, 269 right, 17 declined
1041 sweep rows holding these functions 199 wrong 184 wrong (the rest are the separate infinity-direction class)

Before → after for the issue's rows: arcsin(2 + i/x) arcsin(2) → pi - arcsin(2). arccos(2 + i/x) arccos(2) → -arccos(2). arccos(-x)/ln(x) -i → i. (1/x)/arccos(1/x) at 0- -ooi → +ooi. All twelve G2 sweep rows and six of the seven G rows are now right. arcsin(arctan(ln(ln(x)))) at -oo is declined.

Known costs:

  • (arccos(1/x)) / e^(1/x) at 0- was declined and is now +oo. That is wrong: the true direction is +ooi. The rewrite exposes the existing reading of oo + ooi as +oo in SolveBySubstitution. Master already gives that wrong +oo for the same limit written as (pi + arccos(x)) e^x at +oo, which is the sweep's infinity-direction class. Fixing that reading turned 168 currently-right x + arcsin(x)-style rows into oo + ooi, so it is left to that class.
  • arcsin(gamma(exp(-x))) at 1- and arcsin(x gamma(x sin(x))) at pi/2+ were right and are now declined: the factorial is not recognized as real on the approach.
  • x arcsin(Ei(x)) at 0 is NaN both before and after, but takes 7 s where it took 0.5 s (paired minimum of 3). x * (arcsin(-Ei(x)) - pi) is slow on master as well. Every other row timed within noise in paired runs. The variant set took 13.6 s against master's 16.2 s.

Full unit suite: 0 failed, 22353 passed.

Fixes #2709

🤖 Generated with Claude Code

A limit whose argument reached the cut of arcsin, arccos, arcsec, arccsc or
arccot off the real line was answered with the value on the cut, which is the
limit from one side only: arcsin(2 + i/x) at +oo gave arcsin(2) = pi/2 - 1.317i
where it tends to pi/2 + 1.317i. The descent now reads the side from the sign
of the argument's imaginary part (the real part for arccot), split structurally
into parts real on the approach, and answers the value across the jump from the
other side, or declines where the side cannot be read; substitution and Gruntz
decline the same arguments unless they come from the value's side.

Along the negative half of the cut the library's value is the limit from below,
but 1 / sqrt(1 - t^2) and the logarithmic form take the other side there, so
every reading through derivatives or series disagreed with eval: arccos(-x) /
ln(x) at +oo was -i where it is i. Arguments real on the approach and below -1
(between -1 and 0 for arcsec and arccsc) are rewritten through the negated
argument, arcsin(t) = arcsin(-t) - pi and arccos(t) = pi + arccos(-t), which are
the library's own values and on whose half every reading agrees. Substitution
now writes arcsin and arccos of an infinity as the angle they evaluate to.

Checked against mpmath on 286 generated variants (0 wrong, was 58) and on the
1041 sweep rows holding these functions.

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

codecov Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.89209% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.69%. Comparing base (409d688) to head (25a47f7).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ath/Functions/Continuous/Limits/Transformations.cs 80.73% 4 Missing and 17 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2742      +/-   ##
==========================================
+ Coverage   86.65%   86.69%   +0.03%     
==========================================
  Files         346      346              
  Lines       76959    77098     +139     
  Branches    22644    22699      +55     
==========================================
+ Hits        66692    66840     +148     
+ Misses       5534     5523      -11     
- Partials     4733     4735       +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.18% <84.89%> (+0.03%) ⬆️
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 Δ
...nctions/Continuous/Limits/Solvers/Limit.Classes.cs 81.37% <100.00%> (+0.89%) ⬆️
...nctions/Continuous/Limits/Solvers/Limit.Solvers.cs 90.15% <100.00%> (+0.15%) ⬆️
...ns/Continuous/Limits/Solvers/Solvers.Definition.cs 89.62% <100.00%> (+0.84%) ⬆️
...ath/Functions/Continuous/Limits/Transformations.cs 89.03% <80.73%> (-1.09%) ⬇️

... and 10 files with indirect coverage changes

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

A limit reaching the arcsin or arccos cut takes the principal side, not the side approached: arcsin(2 + i/x) at +oo

1 participant