Repository navigation
Polynomial solver should also be improved #272
Description
Activity
what about Rational root theorem? For many simple cases we can go through all factors of the free term of polynomial to find exact roots
- added a commit that references this issue
on Aug 5, 2026 Investigated and fixed in #742.
The cause is narrow: the solver read a polynomial equation only by its degree — gather monomials, apply Cardano at three, Ferrari at four, nothing above four. It never looked for a factorization, and expanded away one handed to it. So an equation whose factors are written on its face went through the general formula anyway:
solve (x - 1) * (x^2 - 3) = 0 → { 1, -(-1 + (26 + 18i)^(1/3) + 10/(26 + 18i)^(1/3))/3, … } solve x^2 - 3 = 0 → { sqrt(3), -sqrt(3) }Your suggestion here — "check if some constants could be those roots" — is what the fix does, in the form of dividing out the rational roots and letting the existing formulas answer what is left.
One thing the report understates. Sweeping 572 polynomials with known roots turned up ten that were not merely ugly but incomplete:
x^5 - 2x^3 - x^2 + 2 = 0 = (x - 1)(x^2 - 2)(x^2 + x + 1) was { 1, sqrt(2), -sqrt(2) } <- the pair (-1 ± i*sqrt(3))/2 missing now all fiveAbove degree four the whole equation went to the numeric solver, which searches the real axis, so a complex conjugate pair could go missing with nothing to indicate it. After the fix none of the 572 is short of a root, and none gains a value that is not one.
Also faster, since a formula is no longer evaluated and then simplified away: 160 ms → 9 ms on the cubic above, 160 ms → 1 ms on
x^3 - 6x^2 + 11x - 6 = 0.Two-term polynomials
a*x^n + bare deliberately left to the existing inversion ofx^n = -b/a, which gives nicer roots than splitting would (x^3 - 8as(-1/2 ± i*sqrt(3)/2)*2rather than(-2 ∓ sqrt(-12))/2). The remaining rough edge there —x^6 - 1answering a root as1/2 + i*sin(5/3*pi)— is filed as #743.- added a commit that references this issue
on Aug 5, 2026
Now it returns awful responses for 3+ degree polynomials where WA sometimes can return a neat set. We should somehow check if some constants could be those roots (say, check a few integer, a few rational, a few variables, etc.)