Repository navigation
Search for a rational root whatever the scale of the coefficients - #2520
Merged
Merged
Conversation
The rational root search tried the divisors of the first and last coefficients only where both were below a million, to keep factoring them cheap. A polynomial whose roots are those of another times 10^k has coefficients 10^(j k) times the other's, past that bound. So 9x^3 + 9x^2 + 5x + 1 had its root -1/3 found and the same cubic in 10^12 x had -1/(3 10^12) written by Cardano's formula, which the Groebner back-substitution then could not tell made a coefficient 0: the system for the parts of x in 1 + 2x + 3x^2 - 2 Im(x) = 0 with x written as 10^9 x or more was declined. Past the bound, each real root found numerically gives one candidate: a rational root p/q in lowest terms has q dividing the leading coefficient, so the root times it is a whole number, and the root to the working precision, times it and rounded, is that number. Each is checked exactly as before. A first version listed the divisors of coefficients that large instead, tens of thousands of candidates, and a solve with a signum in 10^6 x ran past twenty seconds where master declines in one; this one takes 1.5 s there, against 1.1 s. Within the bound the search is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2520 +/- ##
=======================================
Coverage 86.88% 86.88%
=======================================
Files 340 340
Lines 73969 73988 +19
Branches 21547 21554 +7
=======================================
+ Hits 64268 64287 +19
+ Misses 5221 5219 -2
- Partials 4480 4482 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This was referenced Nov 19, 2026
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.
The rational root search tries divisors of the first and last coefficients, but only where both are below a million, so that factoring them stays cheap. A polynomial whose roots are another's times
10^khas coefficients10^(j k)times the other's, which puts them past that bound:x^3 + 1/10^12*x^2 + 5/(9*10^24)*x + 1/(9*10^36) = 0{ -1/3000000000000, (-1/1500000000000 ± sqrt(-1/1125000000000000000000000)) / 2 }1 + 2(10^12 x) + 3(10^12 x)^2 - 2 Im(10^12 x) = 0The second row is a consequence of the first. Gröbner back-substitution got the cubic's rational root as a Cardano expression, so it could not tell that the root makes a coefficient 0, and it declined the system.
The fix. Past the bound, each real root found numerically gives one candidate. A rational root
p/qin lowest terms hasqdividing the leading coefficient, so the root times that coefficient is a whole number. The numerical root, times the coefficient and rounded, is therefore that number. Each candidate is still checked exactly. Within the bound the search is unchanged.A first version listed the divisors instead. Divisors of smooth coefficients that large can be tens of thousands of candidates. That version made
2 + 3(10^6 x) + (-3 - 10^6 x)(10^6 x) sgn(1 - 10^6 x) = 0run past 20 s, where master declines it in about 1.1 s. This version declines it in about 1.5 s.Generated equations with
xwritten as10^6 xand10^12 x(e387/scalecheck): every family now differs by 0. Master, with #2516, had 4 cxcheck answers declined at10^12. Unscaled cross-checks are unchanged row for row.Checks:
Found while solving generated equations with
xwritten as10^12 x. No issue was filed.🤖 Generated with Claude Code