Skip to content

Search for a rational root whatever the scale of the coefficients - #2520

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
parts-scale
Nov 19, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
parts-scale

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

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^k has coefficients 10^(j k) times the other's, which puts them past that bound:

Input 2.8.0 Now
x^3 + 1/10^12*x^2 + 5/(9*10^24)*x + 1/(9*10^36) = 0 three roots by Cardano's formula { -1/3000000000000, (-1/1500000000000 ± sqrt(-1/1125000000000000000000000)) / 2 }
1 + 2(10^12 x) + 3(10^12 x)^2 - 2 Im(10^12 x) = 0 unsolved its two roots

The 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/q in lowest terms has q dividing 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) = 0 run past 20 s, where master declines it in about 1.1 s. This version declines it in about 1.5 s.

Generated equations with x written as 10^6 x and 10^12 x (e387/scalecheck): every family now differs by 0. Master, with #2516, had 4 cxcheck answers declined at 10^12. Unscaled cross-checks are unchanged row for row.

Checks:

  • Unit tests: 21238 passed.
  • MCP, Terminal, Interactive and F# tests pass. AOT is OK.
  • Harnesses: BoundCheck, RootCheck (596/596), CasBench (0 wrong), PropCheck, SimpSweep, RuleCheck, CanonCheck, Confluence and ModenovCorpus are all clean or match their baselines.

Found while solving generated equations with x written as 10^12 x. No issue was filed.

🤖 Generated with Claude Code

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

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.88%. Comparing base (a42c9c5) to head (da97a99).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...nctions/Algebra/Polynomials/PolynomialFactoring.cs 90.47% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           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     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.40% <90.47%> (+<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 Δ
...nctions/Algebra/Polynomials/PolynomialFactoring.cs 97.44% <90.47%> (-0.87%) ⬇️

... and 9 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 94d6f2c into master Nov 19, 2026
35 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the parts-scale branch November 19, 2026 15:12
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 19, 2026
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