Skip to content

Polynomial solver should also be improved #272

Description

@WhiteBlackGoose

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.)

Activity

  1. MomoDeve commented on Nov 1, 2020

    @MomoDeve
    Member

    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

  2. added this to the 1.2.2 milestone on Nov 12, 2020
  3. Rafael-SOWNet commented on Aug 5, 2026

    @Rafael-SOWNet
    Member

    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 five
    

    Above 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 + b are deliberately left to the existing inversion of x^n = -b/a, which gives nicer roots than splitting would (x^3 - 8 as (-1/2 ± i*sqrt(3)/2)*2 rather than (-2 ∓ sqrt(-12))/2). The remaining rough edge there — x^6 - 1 answering a root as 1/2 + i*sin(5/3*pi) — is filed as #743.

  4. added theissue type on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions