Repository navigation
Keep only the angles in an inverse trigonometric function's range when solving through it - #2761
Open
Rafael-SOWNet wants to merge 2 commits into
Open
Rafael-SOWNet wants to merge 2 commits into
Rafael-SOWNet wants to merge 2 commits into
Conversation
…n solving through it
f(g(x)) = c with g one of arcsin, arccos, arctan, arccotan, arcsec and
arccosec is g(x) = w for each w of the family f brings, and only a w that g
takes gives a root. The inverse nodes checked the value against their range
only where it evaluated to a number, so a family a n + b passed whole:
tan(arcsin(x)) = 1 was sin(pi/4 + pi n), whose odd members are -sqrt(2)/2,
where the tangent is -1; sin(arctan(x)) = 1 was tan(pi/2 + 2 pi n). The
solver judges a family by its member at n = 0, which is why the families
escaped it, and why one whose member at 0 is outside the range was dropped
whole: tan(arccos(x)) = -1 was { } though 3 pi/4 gives -sqrt(2)/2.
The family is now cut to its members in the range, measured with the
library's eval: arcsin and arccosec [-pi/2; pi/2], arccos and arcsec
[0; pi], arctan (-pi/2; pi/2), arccotan (-pi/2; pi/2]; arccotan and
arccosec are never 0 and arcsec never pi/2. A real member is decided
exactly where it is a rational multiple of pi; a complex one is ruled out
only where its real part is outside the strip, as before. Only a parameter
the equation being solved minted is cut, so a system row that shares an
earlier row's parameter keeps it (SolutionParameters tracks which those are
per Bound). The value is read as a line through sums, differences and
products and quotients by numbers, so sin(2 arccos(x)) = -1/2 is cut too.
With the families cut, a substitution can now come back empty where it came
back with a family the root check later emptied: cos(arcsin(2x - 1)) = -1/2
became unsolved. A root x gives its subtree as a root of the substituted
equation, so an empty substitution means no roots over the complex numbers
as it already did over the reals; the replacement loop now says so.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2761 +/- ##
==========================================
- Coverage 86.69% 86.67% -0.02%
==========================================
Files 346 346
Lines 77061 77139 +78
Branches 22679 22706 +27
==========================================
+ Hits 66808 66863 +55
- Misses 5533 5542 +9
- Partials 4720 4734 +14
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Solving
f(g(x)) = cwithgan inverse trigonometric function kept the whole family the outer function brings,g(x) = a n + b. The inverse node checked the value against its range only when it evaluated to a number, and a family doesn't. The solver judges a family by its member atn = 0, so a family passed that check whole when that member was in the range, and was dropped whole when it wasn't, losing the members that were. Over the reals,tan(arccos(x)) = -1has the root-sqrt(2)/2, atarccos(x) = 3pi/4, and was answered{ }.What changed:
The family is cut to its members in the range of
g: arcsin, arccos, arctan, arccotan, arcsec and arccosec. The ranges were measured with the library's own eval:[-pi/2; pi/2][0; pi](-pi/2; pi/2)(-pi/2; pi/2]pi/2.A real member is decided exactly where it is a rational multiple of pi. A complex member is ruled out only where its real part is outside the strip, so it is never treated more strictly than before.
Only a parameter that the equation being solved minted itself is cut. A system row that shares an earlier row's parameter is left as it was.
SolutionParametersnow records, perBound, which parameters are the equation's own.The value is read as a line in
nthrough sums, differences, and products and quotients by numbers. This is what letssin(2 arccos(x)) = -1/2be cut.An empty substitution now means no roots over the complex numbers too, not only over the reals. Once the families are cut, solving the substitution
tofcos(arcsin(2x - 1)) = -1/2comes back empty, and the replacement loop treated that as no information, so the equation became unsolved. A rootxwould giveta root of the substituted equation, so the empty set is the answer.Hyperbolic inverses are rewritten as logarithms before solving, so they never reach these nodes.
Before and after
Checked with mpmath (50 digits): soundness at members
n = -3..5, and completeness by a real root scan on[-12, 12]..Solve("x")tan(arcsin(x)) = 1union({ sin(pi / 4 + pi * n) }, n in ZZ)(odd n: tangent -1){ 1/2 * sqrt(2) }tan(arccos(x)) = 1union({ cos(pi / 4 + pi * n) }, n in ZZ){ 1/2 * sqrt(2) }tan(arcsin(x)) = 1/2union({ sin(arctan(1/2) + pi * n) }, n in ZZ){ sin(arctan(1/2)) }tan(arcsec(x)) = 1union({ sec(pi / 4 + pi * n) }, n in ZZ){ 1 / (1/2 * sqrt(2)) }tan(arccos(x)) = -1{ }(misses-sqrt(2)/2){ -1/2 * sqrt(2) }sin(2 arccos(x)) = -1/2{ }(misses two roots){ -1/4 * (sqrt(6) + sqrt(2)), cos((-5/6 * pi + 2 * pi) / 2) }sin(arctan(x)) = 1union({ tan(pi / 2 + 2 * pi * n) }, n in ZZ){ }cos(arctan(x)) = 0union({ tan(pi / 2 + 2 * pi * n), tan(-pi / 2 + 2 * pi * n) }, n in ZZ){ }sin(arccotan(x)) = 0union({ cotan(pi + 2 * pi * n) }, n in ZZ){ }tan(arccotan(x)) = i{ }arcsin(x) - y,tan(y) - 1[[sin(pi / 4 + pi * n_1), arcsin(sin(pi / 4 + pi * n_1))]][[1/2 * sqrt(2), pi / 4]]The class
The class is every outer function in {sin, cos, tan, cotan, sec, cosec} with every inner one in {arcsin, arccos, arctan, arccotan, arcsec, arccosec}, at the values c in {0, ±1, ±1/2, ±2, ±sqrt(3), 1/3, 3, i}, plus
sin(2 g(x)),tan(g(x)/2)andcos(g(2x - 1)). That is 486 equations.Of the 10:
tan/cotanofarcsin/arccosequal toi. These are Newton-method garbage, the same as on master;tan(w)is neveri.acos(-sqrt(2)) = pi - 0.88iagainst the library'spi + 0.88i.x -> 0-that the checker takes for a root.The class took 14.8 s in total on the branch against 19.2 s on master, with the slowest single row at 2.8 s against 5.9 s.
Suite and harnesses
The new test is
AnInverseTrigonometricFunctionKeepsItsRangeTest, andBREAKING-CHANGES.mdhas an entry.Fixes #2711
🤖 Generated with Claude Code