Skip to content

Decide a rational residual exactly, and decline a row a small part off (#2634, #2635) - #2637

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
rounded-rows-2634
Nov 29, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
rounded-rows-2634

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

I swept the system solver over scaled families whose complete answers are known, and found two ways that rounding inside an exact solve became a wrong answer.

#2634, false rows (introduced by #2612, unreleased). y^2 - 3 = 0, x^2 + (P ∓ Q y) x - c = 0 at (2 + sqrt(3))^190 gave rows like x = -668385287/2, with y a rational within 1e-217 of sqrt(3); the Pell powers 150 and 200 for sqrt(2) failed the same way. The residual of y^2 - 3 is a nonzero rational that reads as 0 to every digit evaluated or enclosed. A residual made only of rationals is now decided exactly.

#2635, a missing row (in 2.10.0 too). For x y = 1, x + y = 10^45 + 7, downcasting rounded one row's y to 10^45 exactly. That row then left -7 against terms near 10^45 and was dropped as no solution. An exact residual that is nonzero but at most 1e-12 of its largest term now reads as rounding having reached the row (ResidualWeight.CannotTell), and the system declines. A root added by a rewrite leaves a residual the size of its terms, so it is still dropped.

Sweep (master a3b3d25df → this PR). Each case had to return all rows, matched against the complete solution set computed independently at 400 digits, or decline:

family cases master wrong here wrong answered (both)
Pell shape, d = 2, 3, powers 10–200, c = 1, 2, 3, 5, both signs 320 12 0 72
x y = c, x + y = 10^e + 7, e up to 60, plain and scaled 48 7 0 29
products of lines, coefficients up to 1e60, a third near-parallel 148 0 0 148
two circles, radius up to 3e60, far apart and nearly tangent 12 0 0 12
Fibonacci linear 2×2, entries up to 1e58 18 0 0 18
determinant, rank and inverse of near-singular integer and rational matrices, entries 1e20–1e60, against fraction arithmetic 270 checks 0 0 —

Tests: ARoundedRowIsDeclinedNotAnsweredTest has 9 cases. On master, 6 fail: the 4 Pell cases and two sum-and-product cases. Two moderate-size controls stay answered. The full UnitTests suite (net10.0) passes: 21805 passed, 0 failed, 13 skipped. The library builds with 0 errors for every target framework. There is a BREAKING-CHANGES.md entry for #2635; #2634 was never released.

Closes #2634.
Closes #2635.

🤖 Generated with Claude Code

#2634, #2635)

Two ways rounding that reached an exact system solve became a wrong answer.

y^2 - 3 = 0, x^2 + (P - Q y) x - 1 = 0 at the 190th power of 2 + sqrt(3)
was answered with false rows, x = -668385287/2 among them and y a rational
within 1e-217 of sqrt(3). The quartic that #2612's second candidate leads
to has coefficients near 1e217, and its roots came out rational. For any
modest x, y = (x^2 + P x - 1)/(Q x) is within 1/Q^2 of sqrt(3). So the
residual of y^2 - 3 is a nonzero rational near 1e-217, which reads as zero
to the evaluation's digits and inside the enclosure's. A residual of
rationals alone is now worked out exactly.

x y = 1, x + y = 10^45 + 7 was answered with one of its two rows; 2.10.0
did the same. In the other row, y came out of the back-substitution as
10^45 exactly: downcasting put a value spoiled by a cancellation of 90
digits onto a nearby rational. The row left -7 against terms near 10^45,
outside what IsEvidenceAgainst lets rounding leave, and was dropped as no
solution. An exact residual that is not zero but is no more than a part
in 10^12 of the largest term is now read as rounding having reached the
row. A row a rewrite added leaves a residual of the terms' own size.

Each case now gives all its rows or declines, through ResidualWeight
.CannotTell. A sweep of 320 Pell-shape systems (d = 2, 3; powers 10 to
200; c = 1, 2, 3, 5; both signs), 48 sum-and-product, 148
product-of-lines, 12 circle and 18 Fibonacci-linear systems found 19
wrong answers on master and none here. The answered counts are unchanged
and the 19 now decline. 270 checks of the determinant, rank and inverse
of integer and rational matrices with entries near 1e30 to 1e60 agree
exactly with fraction arithmetic, on master and here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.72%. Comparing base (a3b3d25) to head (527f303).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2637      +/-   ##
==========================================
+ Coverage   86.70%   86.72%   +0.01%     
==========================================
  Files         345      345              
  Lines       75428    75558     +130     
  Branches    22034    22083      +49     
==========================================
+ Hits        65397    65524     +127     
+ Misses       5418     5412       -6     
- Partials     4613     4622       +9     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.21% <100.00%> (+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 Δ
...ontinuous/Solvers/EquationSolver/SolveStatement.cs 87.16% <100.00%> (+1.04%) ⬆️

... and 15 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
Rafael-SOWNet merged commit 842b8c0 into master Nov 29, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 29, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the rounded-rows-2634 branch November 29, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

1 participant