Repository navigation
Answer { } where tan, cotan, sec, cosec or a power is set to a value it never takes - #2771
Open
Rafael-SOWNet wants to merge 3 commits into
Open
Rafael-SOWNet wants to merge 3 commits into
Rafael-SOWNet wants to merge 3 commits into
Conversation
…it never takes
tan(arcsin(x)) = i was answered with two points of size 10^8. tan(w) = i
is e^(2 i w) = 0, so it holds for no w, and the substitution t = arcsin(x)
found that; but the substitution loop goes on to the next spelling, and
x / cos(arcsin(x)) = i went to Newton's method on x - i cos(arcsin(x)),
which is 1 / (2x) far out: under the search's absolute tolerance, and 0
outright in double.
Two changes:
- OmittedValueSolver, asked before any spelling: an equation in x only
through one node F(u), polynomial in it with numeric coefficients, every
root of which is a value F omits -- tan and cotan omit +-i, sec and
cosec omit 0, a power of a nonzero number omits 0 -- has no roots.
- Newton's method keeps a point only where the first refinement step from
it is shorter than a thousandth of max(1, |root|); a step of 0, which can
be the value read as 0 below the downcasting floor at 40 digits, is taken
again at the full refinement digits. A root found in double has a first
step of about 1e-16 of its size, a root of order m about the m-th root
of that over m.
Sweep of 1408 equations outer(inner(x)) = c, outer in tan, cotan, tanh,
coth, sec, csc, sech, csch, exp, sin, cos, inner in 16 functions, c in
i, -i, 1, -1, 0, 2, 2i, 1/2: 90 rows change, all to { }, every one a value
the outer function never takes. On master 29 of them were numbers that are
not roots, 59 declined, 2 timed out. A sweep of 300 equations that reach
Newton's method changes one row, x - i cos(arcsin(x)) = 0, from two
non-roots to unsolved. Timing of 25 Newton equations, min of 5 in process,
is unchanged (3044-3452 ms master, 3092-3152 ms branch).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2771 +/- ##
==========================================
- Coverage 86.70% 86.69% -0.02%
==========================================
Files 347 348 +1
Lines 77376 77429 +53
Branches 22783 22810 +27
==========================================
+ Hits 67089 67126 +37
- Misses 5546 5552 +6
- Partials 4741 4751 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…erse-equal-i # Conflicts: # BREAKING-CHANGES.md
… omitted value, go before any work OmittedValueSolver is asked before the spellings on every equation, and on SolveHard it substituted, checked and solved as a polynomial each spelling in e^(i x) only to find a root that is not omitted: +1.2 MB of allocation per solve, +19.3% on the Kernel gate. It now returns at once where the equation has a variable besides x, which it could never answer (a tan(x^2) = i a holds everywhere at a = 0), counts the occurrences of x only on reaching a candidate node, and lets a polynomial go when it vanishes at none of the omitted values, before looking for its roots. Allocation, base 8b4f507 and this branch interleaved, two runs each (B/op): SolveHard 6,208,576 / 6,211,968 base, 6,206,848 / 6,211,224 branch; SolveEasy 421,291 / 421,260 base, 421,673 / 421,631 branch; Derivate 24,564 both; SimplifyHard unchanged within 0.02%. The 1408-row sweep answers identically before and after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #2763
Cause.
tan(arcsin(x)) = i: the substitutiont = arcsin(x)givestan(t) = i, which is correctly{ }(tan(w) = iise^(2 i w) = 0). But the substitution loop only acts on an empty replacement at its end, and the next spelling,x / cos(arcsin(x)) = i, went to Newton's method onx - i cos(arcsin(x)). That is1 / (2x)far out — under the search's absolute residual tolerance of 1e-6, and exactly 0 in double — so points of size 10^8 passed every check. The verification exists (Satisfies,WithoutSpuriousRoots), but it is a residual check, and a function that only tends to 0 passes any residual check.Changes.
OmittedValueSolver, asked before the spellings: an equation inxonly through one nodeF(u), polynomial in it with numeric coefficients, all of whose roots are valuesFnever takes, is{ }.tan/cotanomit±i,sec/cosecomit 0, a power of a nonzero number omits 0. Polynomial only (a quotient bytcould add or cancel roots), and no other variable (a tan(x^2) = i aholds everywhere ata = 0).1e-3 * max(1, |root|). A first step of exactly 0 — the value read as 0 below the downcasting floor at 40 digits — is retaken at the full refinement digits. At a root found in double the step is about 1e-16 of its size; at a root of order m about the m-th root of that over m.With #2761. Independent and compatible: the patch applies cleanly on
fix-2711-inverse-trig-range. #2761 makes an empty replacement mean "no roots" at the end of the spelling loop; that alone does not fix this issue, because a later spelling returns Newton's points before the loop ends (measured on #2761's build: same junk). Here the omitted-value case is answered before the loop, and the Newton points are rejected wherever they arise..Solve("x")tan(arcsin(x)) = i{ -24258808.638504 + 87745223.784967i, 24258808.638504 + 87745223.784967i }(1.9 s){ }cotan(arccos(x)) = i{ }tan(x^2 + 1) = i{ }tan(arcsec(x)) = i{ }tanh(cosh(x)) = -1-8 - 10i…{ }e^(artanh(x)) = 0{ -1 }(artanh has no value there){ }x - i cos(arcsin(x)) = 0(tan(x) - i)(tan(x) - 1) = 0union({ pi / 4 + pi * n }, n in ZZ)Sweep 1 (1408 rows: outer ∈ tan, cotan, tanh, coth, sec, csc, sech, csch, exp, sin, cos; inner ∈ arcsin, arccos, arctan, arccotan, arcsec, arccosec, sinh, cosh, arsinh, arcosh, artanh, ln, sqrt, x^2+1, 2x−1, e^x; rhs ∈ i, −i, 1, −1, 0, 2, 2i, 1/2), master a3f3b9e vs branch: 90 rows change, all to
{ }, each an outer function at a value it never takes (tan/cotan = ±i, tanh/coth = −1, sec/csc = 0, e^u = 0). On master those 90 were: 29 numeric answers, none a root (24 rejected by mpmath outright; 5 are points converging to where the inner function is undefined), 59 declined (8 of them unions of logarithms of Newton decimals), 2 timeouts. mpmath found no root for them (its only "roots" are those limit points, wherearccot,arcsec,arccscorartanhhas no value). No row got worse. The 1318 other rows are identical. Sweep time 335 s → 110 s.Sweep 2 (300 equations that reach Newton's method —
a x + b sin x = c,x^3 − a cos x = b,x^2 + a e^(x/b) = c,tan x = a x + c, …): one row changes,x - i cos(arcsin(x)) = 0, from two non-roots to unsolved. No genuine root lost.Timing. 25 Newton equations, min of 5 in process, two rounds each: master 3452 / 3044 ms, branch 3092 / 3152 ms (an earlier version that took the check at full digits always was +35%, hence the retake only on a zero step).
Suite and harnesses (merged with master 8b4f507, head c7e5185). Unit suite 22551 passed, 0 failed. CasBench 120/121 (0 wrong), RootCheck 596/596 clean; PropCheck 1355 checks 0 failures and SimpSweep 10463/10463 on the first head.
Kernel performance gate. The first push (ff12741) failed it:
SolveHard+19.3% allocation. All of it wasOmittedValueSolver(measured by switching it off: 7,442,660 → 6,240,194 B/op; the Newton check contributed nothing): asked on every equation, it substituted, checked and solved as a polynomial each spelling ine^(i x)only to find a root that is not omitted. It now returns at once where the equation has a variable besidesx(which it could never answer anyway), counts occurrences only on reaching a candidate node, and lets a polynomial go when it vanishes at none of the omitted values before looking for its roots.DotnetBenchmark CommonFunctionsInterVersion+PerformanceGate, base 8b4f507 and branch interleaved, two runs each (B/op):The gate passes on all four runs. The 1408-row sweep answers identically before and after this change.
BREAKING-CHANGES.mdentry added.🤖 Generated with Claude Code