Repository navigation
Decline a root the working digits cannot certify, past the caller's decimals and large terms (#2448) - #2679
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2679 +/- ##
==========================================
- Coverage 86.65% 86.65% -0.01%
==========================================
Files 346 346
Lines 76191 76300 +109
Branches 22335 22380 +45
==========================================
+ Hits 66023 66115 +92
- Misses 5499 5505 +6
- Partials 4669 4680 +11
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…ecimals and large terms (#2448) With (1 + sqrt(2))^n = P + Q sqrt(2), x^2 + (P - Q sqrt(2)) x - 3 was answered at n = 130 to 210 and 250 to 300 with roots that are none: the discriminant b^2 + 12 read as 12, or past the hundred working digits the coefficient read as 2499. (P - Q sqrt(2)) x - 1 was { }, x + c was { 0 }, x^3 + c x - 1 was { } from n = 60, and the same for (1 - sqrt(2))^n, (sqrt(3) - sqrt(2))^n and (L_n - F_n sqrt(5))/2. Three holes in the root check in StatementSolver: - a root was enclosed only where the equation had no decimal in it, and an integer of more than half the working digits is parsed as one (#2615); the caller's own decimals now count as exact numbers; - the enclosure took the largest number's digits once more, where a residual such as b^2/4 needs about four times them; the digits now double up to eight times the size of the numbers in the tree, numbers raised to whole powers included, and only where that size passes ten; - an empty answer was never checked: a polynomial as written with a coefficient at a positive power shown not zero is now left unsolved. And Solved simplified a declined statement, which with these numbers rounded it into another ({ x : 241546412250001 x - 1 = 0 }) or into { }; a decline with large numbers or decimals is kept as written. Measured against mpmath at 1600 digits, 674 answers (the issue's quadratic at n = 20..300 by tens, both signs; four coefficient families in eight linear, quadratic and cubic equations), SolveEquation and Solve: 2.10.0 got 165 wrong, master 4674e66 203, this branch none; every answer either got right is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#2448) The merge chain's scale check found right answers lost and two new timeouts with x written 10^k x: - -3 - x + 3x^2 - 3 sgn(-x) - 3 Im(x) = 0 was declined at 10^6, 10^12, 10^20 and 10^30, and -2 + (3 - i)x + (2 + i) sgn(3x^2 + 3x - 1) - 2 Im(x) = 0, which has no root, at 10^12, 10^20 and 10^30. Both are solved through a Groebner basis, whose univariate equations have the decimal roots of the others put in. Those decimals were taken for the caller's, a root of such an equation was enclosed exactly, and each left what the rounding did, so the univariate solve declined and the equation with it. Only an integer as parsed, digit for digit with no exponent, now counts as exact beside rationals; a worked-out decimal leaves the check as it was. - -1 - i + i x + (-1 + (2 + i)x) sgn(3x - 2) = 0 and (1 + 3x - x^2)/abs(x^2 - 3x - 3) + 2x = 0 at 10^-30 took 8 and 7 times as long: every exact root of a Groebner univariate, and the top-level roots of the sgn equation, were enclosed to thousands of digits. The univariate solves now run without the rising digits, as their roots are put back into the system; the digits rise only for an equation that is a polynomial as written; and they rise to twice the orders the numbers span, the larger side counted twice, instead of eight times the largest number's digits. - A declined statement is kept as written only where simplifying would evaluate one of its constants to another number, not wherever its numbers are large: { x : ... 10 ^ 12 * x ... } is simplified again. Timed on one machine, master 00a9048 -> this commit, Solve twice per equation: the sgn equation at 10^-30 11.3 s -> 11.1 s, the abs one 14.5 s -> 13.9 s; the first two equations are answered as on master. The 674-row sweep against mpmath still has no wrong answer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rafael-SOWNet
force-pushed
the
fix-2448-certify-root-residuals
branch
from
December 2, 2026 08:54
3b7c4df to
defac98
Compare
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 #2448
What was wrong
With
(1 + sqrt(2))^n = P + Q sqrt(2),x^2 + (P - Q sqrt(2)) x - 3was still answered with roots that are not roots, and not only at n = 160: re-measured on master 4674e66,SolveEquationandSolvewere wrong at n = 130 to 210 and 250 to 300 ((-b +- 2 sqrt(3)) / 2, the discriminantb^2 + 12read as 12, residuals 1e-54 to 1e-147), and from 270 on the coefficient itself was read as2499and the like (residuals up to 6e29). The same class was wrong elsewhere:(P - Q sqrt(2)) x - 1was{ }at n = 200,x + (P - Q sqrt(2))was{ 0 },x^3 + (P - Q sqrt(2)) x - 1was{ }from n = 60 (exact integers),(1 - sqrt(2))^160 x - 1was{ 17543233911800695450907164956888413406276808032081050028214274 }, andSolveturned declines into other equations,{ x : 241546412250001 * x - 1 = 0 }or{ x : x = 0 }.Cause
StatementSolverinSources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs(line numbers on master):IsAboveTheIntervalFloorreturns false for any inexact number in the residual, so the interval check at :238 never ran on an equation with a decimal in it, and an integer literal of more than about 50 digits is parsed as a decimal (An exact integer times an irrational past 10^100 simplifies to a rounded integer, and past 10^1000 to +oo #2615). From n = 130PandQare such literals.ExcludesZerorefines the enclosure once, by the digits of its first width. A residual likeb^2 / 4against terms nearb^-2needs about four times the digits of the numbers; at n = 160 it needs 246 digits and the enclosure stopped at 224. With exact inputs ((1 - sqrt(2))^160, orIntegers) the floor check at :238 also stops it.{ }.Solvedsimplifies the declined statement, and simplifying evaluatesP - Q sqrt(2)the same way, which turns the decline into a different equation or into{ }.The fix
In
SolveStatement.cs, plus one scope opened inGroebnerSystemSolver.cs; nothing in numeric evaluation:IsShownNotZeroAsTheDigitsRiseapplies to a polynomial equation as written whose numbers span more than 10 decimal orders, counting a number raised to a whole power beyond 10. It retries the enclosure at doubling digits, up to twice the orders above one plus twice the larger of the orders below and above, and never more than 4000 extra digits. An enclosure that leaves out zero declines the equation (ShownNotARoot, as Solve one equation at the default zero tolerance, and decline where an exact root is shown not to be one #2456 already does). A true root's enclosure holds zero at every step, so it is kept. Equations with small numbers never get here. A Groebner basis's univariate solves run without it, since their roots are put back into the system.xas written (no conditions, nox^0), with a coefficient at a positive power that is not zero, by value or by the same rising enclosure, is left unsolved.Solvedkeeps a declined statement as written only where simplifying would evaluate one of its constants to another number. The test is a sum with no symbol in it whose high-digit enclosure excludes zero and is not near its working value.A decline remains a decline; nothing here produces a new answer. Every right answer of 2.10.0 and of master in the sweep below is unchanged.
Sweep, against mpmath at 1600 digits
Every root is put back into the equation in mpmath and matched to the true roots (
polyroots, 1600 digits). An exact root counts as right only if its residual is below 1e-1400 relative. A decline counts as one only if its statement, evaluated at two complex points, is the equation. 674 answers: the issue's quadratic for n = 20 to 300 by tens, both signs; andcin {P - Q sqrt(2),(1 - sqrt(2))^nas written,U - V sqrt(6) = (sqrt(3) - sqrt(2))^n,(L - F sqrt(5))/2 = phi'^n} at n = 20, 40, 60, 80, 100, 120, 160, 200, 300 inc x - 1(L1),x + c(L2),x^2 + c x - 3(Q1),x^2 - c(Q2),c x^2 + x - 1(Q3),x^3 + c x - 1(C1),x^3 - c(C2),x^3 + c x^2 - 2x - 1(C3), each bySolveEquationandSolve.The issue's quadratic:
SolveEquation:Solve:The class, per family and equation (18 answers each: 9 values of n, 2 entry points):
P + Q sqrt(2)at 130 is right on master and declined on 2.10.0. That change is master's, not this PR's.The scale cross-check (second commit)
The merge chain's cxcheck, with x written 10^k x, found right answers that the first commit lost, and two new timeouts:
-3 - x + 3x^2 - 3 sgn(-x) - 3 Im(x) = 0was declined at 10^6, 10^12, 10^20 and 10^30.-2 + (3 - i)x + (2 + i) sgn(3x^2 + 3x - 1) - 2 Im(x) = 0was declined at 10^12, 10^20 and 10^30. Its answer{ }is right: with sgn(z) = z/|z|, x is linear in s = sgn(w), and over the unit circle arg(w) never meets arg(s) (the closest is 2.05 rad, scanned in mpmath); s = 0 gives x = 3/4 + i/4, where w is not 0.Both are solved through a Groebner basis, and its univariate equations have the decimal roots of the other unknowns put in. The first commit took any decimal for one the caller wrote, so it enclosed those roots exactly, and each one left the rounding residue. The univariate solve then declined, and the equation with it. Now only an integer as parsed counts as exact beside rationals: held digit for digit, with no exponent.
-1 - i + i x + (-1 + (2 + i)x) sgn(3x - 2) = 0and(1 + 3x - x^2)/abs(x^2 - 3x - 3) + 2x = 0at 10^-30 took 8 and 7 times as long. Every exact root of the Groebner univariates, and the sgn equation's own roots, were enclosed to thousands of digits. Three changes fix it:Timed on one machine, Solve twice per equation:
{ }equation at 10^12{ }{ }scalecheck/branchrun.shon this branch: run1121, runvar1121, run30 and runnew list the same differences as master's-sglogs. The cross-checks (logcheck, radcheck ×3, cxcheck, trigcheck ×3) give the same results. The runner csprojs point back at the main tree afterwards. The second test,Issue2448_AnEquationInTheComplexPartsOfXIsSolvedAtEveryScaleOfX, pins the first two equations at 10^6, 10^12 and 10^30.Measurements
dotnet test Sources/Tests/UnitTests: 22084 passed, 0 failed, 13 skipped.dotnet test Sources/Tests/FSharpWrapperUnitTests: 135 passed.ln(x) + ln(y) - ln(x * y), as on master), 0 wrong, 0 error, 0 timeout.Issue2448_ARootOfANearlyCancellingCoefficientIsARootOrTheEquationIsLeftUnsolved, 25 cases, inSolverRegressionTest.cs. All 25 fail on master. Each answer must be either every root, each enclosed within 1e-1000 of zero at 2000 digits, or a decline whose statement contains only the equation's own numbers.BREAKING-CHANGES.md: a new entry, measured on 2.10.0.Every changed answer in the sweep was wrong before and is a decline now. The declines come from downcasting, which v3 removes (#1019).
🤖 Generated with Claude Code