Skip to content

Decline a root the working digits cannot certify, past the caller's decimals and large terms (#2448) - #2679

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
fix-2448-certify-root-residuals
Dec 2, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
fix-2448-certify-root-residuals

Conversation

@Rafael-SOWNet

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

Copy link
Copy Markdown
Member

Fixes #2448

What was wrong

With (1 + sqrt(2))^n = P + Q sqrt(2), x^2 + (P - Q sqrt(2)) x - 3 was still answered with roots that are not roots, and not only at n = 160: re-measured on master 4674e66, SolveEquation and Solve were wrong at n = 130 to 210 and 250 to 300 ((-b +- 2 sqrt(3)) / 2, the discriminant b^2 + 12 read as 12, residuals 1e-54 to 1e-147), and from 270 on the coefficient itself was read as 2499 and the like (residuals up to 6e29). The same class was wrong elsewhere: (P - Q sqrt(2)) x - 1 was { } at n = 200, x + (P - Q sqrt(2)) was { 0 }, x^3 + (P - Q sqrt(2)) x - 1 was { } from n = 60 (exact integers), (1 - sqrt(2))^160 x - 1 was { 17543233911800695450907164956888413406276808032081050028214274 }, and Solve turned declines into other equations, { x : 241546412250001 * x - 1 = 0 } or { x : x = 0 }.

Cause

StatementSolver in Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs (line numbers on master):

  1. :364 IsAboveTheIntervalFloor returns 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 = 130 P and Q are such literals.
  2. :317 ExcludesZero refines the enclosure once, by the digits of its first width. A residual like b^2 / 4 against terms near b^-2 needs 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, or Integers) the floor check at :238 also stops it.
  3. :70 an empty answer is returned unchecked: a polynomial whose coefficient downcasting read as 0 is answered { }.
  4. :945 Solved simplifies the declined statement, and simplifying evaluates P - 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 in GroebnerSystemSolver.cs; nothing in numeric evaluation:

  • An integer parsed as a decimal, held digit for digit with no exponent, counts as exact, so a residual with one in it is enclosed. A decimal the solver worked out does not count, and its root is left to the existing checks.
  • IsShownNotZeroAsTheDigitsRise applies 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.
  • An empty answer for an equation that is polynomial arithmetic in x as written (no conditions, no x^0), with a coefficient at a positive power that is not zero, by value or by the same rising enclosure, is left unsolved.
  • Solved keeps 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; and c in {P - Q sqrt(2), (1 - sqrt(2))^n as 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 in c 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 by SolveEquation and Solve.

right declined wrong
2.10.0 364 193 117
master 4674e66 368 106 200
this branch 368 306 0

The issue's quadratic:

SolveEquation:

n + : 2.10.0 + : master + : branch − : 2.10.0 − : master − : branch
20 right right right right right right
30 right right right right right right
40 right right right right right right
50 right right right right right right
60 right right right right right right
70 right right right declined declined declined
80 right right right declined declined declined
90 right right right declined declined declined
100 right right right declined declined declined
110 right right right declined declined declined
120 right right right declined declined declined
130 declined right right wrong, residual 7.52e-101 wrong, residual 7.52e-101 declined
140 declined declined declined declined wrong, residual 4.47e-54 declined
150 declined declined declined declined wrong, residual 6.64e-58 declined
160 declined declined declined wrong, residual 8.12e-124 wrong, residual 8.12e-124 declined
170 declined declined declined wrong, residual 1.8e-131 wrong, residual 1.8e-131 declined
180 declined declined declined wrong, residual 3.97e-139 wrong, residual 3.97e-139 declined
190 declined declined declined wrong, residual 8.77e-147 wrong, residual 8.77e-147 declined
200 declined declined declined declined wrong, residual 4.82e-77 declined
210 declined declined declined declined wrong, residual 7.17e-81 declined
220 declined declined declined right right right
230 declined declined declined right right right
240 declined declined declined right right right
250 declined declined declined wrong, residual 3.5e-96 wrong, residual 3.5e-96 declined
260 declined declined declined wrong, residual 5.21e-100 wrong, residual 5.21e-100 declined
270 declined declined declined declined wrong, residual 6.25e+6 declined
280 declined declined declined declined wrong, residual 2.87e+14 declined
290 declined declined declined declined wrong, residual 1.01e+22 declined
300 declined declined declined declined wrong, residual 5.75e+29 declined

Solve:

n + : 2.10.0 + : master + : branch − : 2.10.0 − : master − : branch
20 right right right right right right
30 right right right right right right
40 right right right right right right
50 right right right right right right
60 right right right right right right
70 right right right declined declined declined
80 right right right declined declined declined
90 right right right declined declined declined
100 right right right declined declined declined
110 right right right declined declined declined
120 right right right declined declined declined
130 declined right right wrong, residual 7.52e-101 wrong, residual 7.52e-101 declined
140 declined declined declined declined wrong, residual 4.47e-54 declined
150 declined declined declined declined wrong, residual 6.64e-58 declined
160 declined declined declined wrong, residual 8.12e-124 wrong, residual 8.12e-124 declined
170 declined declined declined wrong, residual 1.8e-131 wrong, residual 1.8e-131 declined
180 declined declined declined wrong, residual 3.97e-139 wrong, residual 3.97e-139 declined
190 declined declined declined wrong, residual 8.77e-147 wrong, residual 8.77e-147 declined
200 declined declined declined declined wrong, residual 4.82e-77 declined
210 declined declined declined declined wrong, residual 7.17e-81 declined
220 declined declined declined right right right
230 declined declined declined right right right
240 declined declined declined wrong (decline names another equation) wrong, residual 1.73e-8 declined
250 declined declined declined wrong, residual 3.5e-96 wrong, residual 3.5e-96 declined
260 declined declined declined wrong, residual 5.21e-100 wrong, residual 5.21e-100 declined
270 declined declined declined wrong (decline names another equation) wrong, residual 6.25e+6 declined
280 declined declined declined wrong (decline names another equation) wrong, residual 2.87e+14 declined
290 declined declined declined wrong (decline names another equation) wrong, residual 1.01e+22 declined
300 declined declined declined wrong (decline names another equation) wrong, residual 5.75e+29 declined

The class, per family and equation (18 answers each: 9 values of n, 2 entry points):

family equation wrong 2.10.0 wrong master wrong branch right (all three) declined on branch
Pm L1 3 6 0 12 6
Pm L2 1 4 0 14 4
Pm Q2 1 4 0 14 4
Pm Q3 1 4 0 14 4
Pm C1 11 14 0 4 14
Pm C2 1 4 0 14 4
Pm C3 3 6 0 6 12
Raw L1 4 4 0 6 10
Raw L2 0 0 0 18 0
Raw Q1 6 6 0 6 12
Raw Q2 0 0 0 18 0
Raw Q3 0 0 0 12 6
Raw C1 14 14 0 4 14
Raw C2 0 0 0 18 0
Raw C3 2 2 0 6 12
S6 L1 7 8 0 8 10
S6 L2 3 8 0 10 8
S6 Q1 5 10 0 4 14
S6 Q2 3 8 0 10 8
S6 Q3 3 8 0 8 10
S6 C1 11 16 0 2 16
S6 C2 3 8 0 10 8
S6 C3 5 10 0 4 14
Phi L1 2 2 0 14 4
Phi L2 0 2 0 16 2
Phi Q1 0 2 0 10 8
Phi Q2 0 2 0 16 2
Phi Q3 0 2 0 16 2
Phi C1 9 11 0 7 11
Phi C2 0 2 0 16 2
Phi C3 0 2 0 10 8

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) = 0 was 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) = 0 was 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) = 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 the Groebner univariates, and the sgn equation's own roots, were enclosed to thousands of digits. Three changes fix it:
    • the univariate solves run without the rising digits, since their roots are put back into the system;
    • the digits rise only for an equation that is a polynomial as written;
    • they rise to twice the orders the numbers span, counting the larger side twice, instead of eight times the largest number's digits.

Timed on one machine, Solve twice per equation:

master 00a9048 first commit this branch
sgn equation at 10^-30 11.3 s, its roots 86.5 s, its roots 11.1 s, its roots
abs equation at 10^-30 14.5 s, declined 97.3 s, declined 13.9 s, declined
sgn/Im equation at 10^12 its roots declined its roots
{ } equation at 10^12 { } declined { }

scalecheck/branchrun.sh on this branch: run1121, runvar1121, run30 and runnew list the same differences as master's -sg logs. 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.
  • RootCheck: 596/596 clean; 0 incomplete, 0 unsound, 0 unanswered.
  • CasBench: 120/121 solved, 1 unsolved (ln(x) + ln(y) - ln(x * y), as on master), 0 wrong, 0 error, 0 timeout.
  • New regression test Issue2448_ARootOfANearlyCancellingCoefficientIsARootOrTheEquationIsLeftUnsolved, 25 cases, in SolverRegressionTest.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.
  • Rebased on master 00a9048. It merges cleanly with e89bc39 (Do not ask a solve's question again inside itself (#2680) #2682).

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

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.48649% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.65%. Comparing base (00a9048) to head (defac98).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ontinuous/Solvers/EquationSolver/SolveStatement.cs 86.11% 4 Missing and 11 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.14% <86.48%> (-0.01%) ⬇️
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 Δ
...Functions/Algebra/Groebner/GroebnerSystemSolver.cs 63.85% <100.00%> (+0.44%) ⬆️
...ontinuous/Solvers/EquationSolver/SolveStatement.cs 84.43% <86.11%> (+0.41%) ⬆️

... and 4 files with indirect coverage changes

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

Rafael-SOWNet and others added 2 commits December 2, 2026 01:49
…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
Rafael-SOWNet force-pushed the fix-2448-certify-root-residuals branch from 3b7c4df to defac98 Compare December 2, 2026 08:54
@Rafael-SOWNet
Rafael-SOWNet merged commit d6e3ed5 into master Dec 2, 2026
37 of 38 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Dec 2, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fix-2448-certify-root-residuals branch December 2, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

SolveEquation returns a root that is not a root when a coefficient nearly cancels

1 participant