Skip to content

Solve one equation at the default zero tolerance, and decline where an exact root is shown not to be one - #2456

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
fix/solve-equation-zero-tolerance
Nov 15, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
fix/solve-equation-zero-tolerance

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

With (1 + sqrt(2))^n = P + Q sqrt(2), x^2 + (P_70 + Q_70 sqrt(2)) x - 3 was
solved as { -2 P_70 }, which leaves -2; x^2 + (P_70 - Q_70 sqrt(2)) x - 3
as { sqrt(3), -sqrt(3) }, the coefficient dropped; and at n = 20 the
discriminant b^2 + 12 was read as 12.

EquationSolver.Solve ran under PrecisionErrorZeroRange = 1e-12, which
widens the downcasting tolerance from 1e-50, and checked its roots inside
the same scope. The override is gone: SolveEquation now solves as Solve on
the equation already did, and n = 20..60 come out right.

Where the default 1e-50 still rounds, WithoutSpuriousRoots, shared by both
entry points, now weighs an exact root against an interval:

  • a root with only exact numbers in it, in an equation with only exact
    numbers, whose residual's PreciseEvaluation enclosure leaves out zero,
    declines the equation (a ConditionalSet), rather than being dropped,
    which would answer an incomplete set;
  • a root the decimal evidence took for spurious is kept where the residual
    is exact and algebraic and its enclosure holds zero: the small root
    -b/2 + sqrt(b^2 + 12)/2 keeps 46 digits at a hundred and left 5.9e-48
    against terms of 3, which dropped it from 70 to 120.
    The enclosure is taken only where the residual, evaluated without
    downcasting at the working digits plus those of the largest number in the
    tree, is above 1e-95: an interval for every exact root doubled the
    allocation of solving x^2 + x + 1.

A system whose elimination leaves an equation unsolved at a leaf is
declined too, where the rows of the other branches were returned as all
of them; RowsThatHold uses the same enclosure-aware evidence.

Measured, roots checked against the true ones at 400 digits, 2.7.0/master
-> branch, SolveEquation:
n = 5, 10 right -> right
n = 20..60 wrong (+ at 40..60 unsolved) -> right
n = 70..120 + wrong { -2P } -> right
n = 70..120 - wrong { (-b +- 2 sqrt(3))/2 } or { +-sqrt(3) } -> declined
n = 140, 200 wrong -> declined
n = 160 + wrong -> declined; - wrong -> still wrong (residual
near 1e-123, past a hundred digits)
Solve on the equation: right to 60 before and after; 70..120 + missed the
small root -> both roots; the rest as above.
System y^2 - 2, x^2 + (P - Q y) x - 3: n = 20..60 declined -> four rows;
70..200 declined -> declined. With the override removed alone, n = 80 and
120 came back with 3 and 2 of the 4 rows; the leaf decline is what stops
that.

Measured

Roots checked against the true roots at 400 digits; 2.7.0 and master give the same answers. P, Q are Pell numbers, the equation x^2 + (P ± Q sqrt(2)) x - 3.

n SolveEquation, master branch Solve, master branch
5, 10 right right right right
20..60, + wrong (unsolved at 40..60) right right right
20..60, − wrong right right right
70..120, + wrong {-2P} right one root missing right
70..120, − wrong declined wrong declined
140, 200; 160 + wrong declined wrong declined
160 − wrong still wrong wrong still wrong

The system y^2 - 2, x^2 + (P - Q y) x - 3: 4 rows at n = 10 before and after; n = 20..60 declined → 4 rows; n = 70..200 declined → declined.

n = 160 with − is still wrong: the residual is about 1e-123, past the 100 digits the evaluation works to. That is downcasting, which v3 removes (#1019), so this is part of #2448 rather than all of it.

Removing the override alone made the system above answer 3 of 4 rows at n = 80 and 2 of 4 at n = 120, where master declined; the InSolveSystem change (an unsolved last equation of a branch declines the system rather than counting as no rows) is what stops that.

Solver cross-checks (cxcheck 300, radcheck 400 + 300, logcheck 400) run through SolveEquation: identical on master, the override removed alone, and this branch, 0 wrong or missed. Full check on this commit before the rebase onto 840075a, which was clean: 19,871 unit tests, 0 failed; MCP 431, Terminal 69, F# 134, Interactive 19; AOT OK; BoundCheck 0 disagreements, RootCheck 596/596, CasBench 120/121 with 0 wrong, PropCheck 1355/0, SimpSweep 10463/10463, RuleCheck clean, CanonCheck and Confluence at their baselines.

Allocation per call falls (SolveHard 9.51M → 8.49M bytes), which the kernel performance gate will flag; the baseline follows from this PR's own benchmark run.

Part of #2448.

🤖 Generated with Claude Code

…n exact root is shown not to be one (#2448)

With (1 + sqrt(2))^n = P + Q sqrt(2), x^2 + (P_70 + Q_70 sqrt(2)) x - 3 was
solved as { -2 P_70 }, which leaves -2; x^2 + (P_70 - Q_70 sqrt(2)) x - 3
as { sqrt(3), -sqrt(3) }, the coefficient dropped; and at n = 20 the
discriminant b^2 + 12 was read as 12.

EquationSolver.Solve ran under PrecisionErrorZeroRange = 1e-12, which
widens the downcasting tolerance from 1e-50, and checked its roots inside
the same scope. The override is gone: SolveEquation now solves as Solve on
the equation already did, and n = 20..60 come out right.

Where the default 1e-50 still rounds, WithoutSpuriousRoots, shared by both
entry points, now weighs an exact root against an interval:
- a root with only exact numbers in it, in an equation with only exact
  numbers, whose residual's PreciseEvaluation enclosure leaves out zero,
  declines the equation (a ConditionalSet), rather than being dropped,
  which would answer an incomplete set;
- a root the decimal evidence took for spurious is kept where the residual
  is exact and algebraic and its enclosure holds zero: the small root
  -b/2 + sqrt(b^2 + 12)/2 keeps 46 digits at a hundred and left 5.9e-48
  against terms of 3, which dropped it from 70 to 120.
The enclosure is taken only where the residual, evaluated without
downcasting at the working digits plus those of the largest number in the
tree, is above 1e-95: an interval for every exact root doubled the
allocation of solving x^2 + x + 1.

A system whose elimination leaves an equation unsolved at a leaf is
declined too, where the rows of the other branches were returned as all
of them; RowsThatHold uses the same enclosure-aware evidence.

Measured, roots checked against the true ones at 400 digits, 2.7.0/master
-> branch, SolveEquation:
  n = 5, 10        right -> right
  n = 20..60       wrong (+ at 40..60 unsolved) -> right
  n = 70..120  +   wrong { -2P } -> right
  n = 70..120  -   wrong { (-b +- 2 sqrt(3))/2 } or { +-sqrt(3) } -> declined
  n = 140, 200     wrong -> declined
  n = 160      +   wrong -> declined;  -  wrong -> still wrong (residual
                   near 1e-123, past a hundred digits)
Solve on the equation: right to 60 before and after; 70..120 + missed the
small root -> both roots; the rest as above.
System y^2 - 2, x^2 + (P - Q y) x - 3: n = 20..60 declined -> four rows;
70..200 declined -> declined. With the override removed alone, n = 80 and
120 came back with 3 and 2 of the 4 rows; the leaf decline is what stops
that.

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

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.84211% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.97%. Comparing base (840075a) to head (542031f).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ontinuous/Solvers/EquationSolver/SolveStatement.cs 86.36% 3 Missing and 6 partials ⚠️
...ath/Functions/Continuous/Solvers/EquationSolver.cs 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2456   +/-   ##
=======================================
  Coverage   86.96%   86.97%           
=======================================
  Files         319      319           
  Lines       71013    71063   +50     
  Branches    20716    20734   +18     
=======================================
+ Hits        61759    61807   +48     
- Misses       4966     4970    +4     
+ Partials     4288     4286    -2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.50% <86.84%> (+<0.01%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 39.81% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ath/Functions/Continuous/Solvers/EquationSolver.cs 86.85% <90.00%> (+1.21%) ⬆️
...ontinuous/Solvers/EquationSolver/SolveStatement.cs 85.31% <86.36%> (+1.45%) ⬆️

... and 6 files with indirect coverage changes

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

The kernel performance gate on this PR's first run reported SolveHard at
8,514,589 B/op, 10.6% below the 9,526,556 recorded at 190a6c8, and every
other gated benchmark within its band. The file is that run's own measurement
(benchmark-results artifact of run 43747235590), copied over the baseline as
the gate asks.

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

Copy link
Copy Markdown
Member Author

The kernel performance gate failed as expected, on SolveHard alone: 8,514,589 B/op against the baseline's 9,526,556, 10.6% lower; every other gated benchmark stayed within its band. The baseline is updated in this PR from that run's own measurement (run 43747235590).

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.

1 participant