Skip to content

SolveEquation returns a root that is not a root when a coefficient nearly cancels #2448

Open

Description

@Rafael-SOWNet

Measured on master 5ec47aec5. P and Q are Pell numbers, with (1 + sqrt(2))^n = P_n + Q_n sqrt(2), so P_n - Q_n sqrt(2) = (1 - sqrt(2))^n is tiny.

equation, SolveEquation("x") answer why it is wrong
x^2 + (P_70 + Q_70 sqrt(2)) x - 3 { -622727397928480968026608326 }, that is { -2 P_70 } the residual at -2 P_70 is exactly -2; the roots are about -6.2e26 and 4.8e-27, and the small one is missing
x^2 + (P_70 - Q_70 sqrt(2)) x - 3 { sqrt(3), -sqrt(3) } the residual is ±sqrt(3)(1 - sqrt(2))^70, which is not zero; the coefficient of x was dropped
x^2 + (P_20 - Q_20 sqrt(2)) x - 3 the roots written with 2 sqrt(3) the discriminant b^2 + 12 was read as 12

Cause, measured on the branch for #2446:

  • EquationSolver.Solve runs under PrecisionErrorZeroRange.Set(1e-12m), which widens the downcasting tolerance from 1e-50 to 1e-12.
  • With that override removed, n = 20 to 60 come out right. The filters Algebra|Regression|Corpus|Solv, 2566 tests, pass with and without it.
  • n = 70 stays wrong without the override, because the default 1e-50 reads b^2 + 12 as 12. That is downcasting itself, which Pending breakages: changes agreed or arguable that cannot ship before a major version #1019 removes in v3.
  • The roots are verified inside the same 1e-12 scope, so the check cannot see the residuals.

Fix direction. Remove the override in its own PR, measured across the harnesses. Then a root whose residual provably excludes zero should make the solve decline, not shrink the set: dropping the bad root here would give {} for an equation that has roots.

The system half is #2446, where the same rounding returns a row that is not a solution. The fix there declines such a system.

🤖 Generated with Claude Code

Activity

  1. added this to the 2.8 milestone on Nov 15, 2026
  2. Rafael-SOWNet commented on Nov 15, 2026

    @Rafael-SOWNet
    MemberAuthor

    #2456 is merged. The 1e-12 override is gone, and a root shown not to be one now leaves the equation unsolved rather than shrinking the set. Through SolveEquation: n = 20..60 are answered correctly, n = 70..120 with + are answered correctly, and the − rows from 70 up are declined. The system y^2 - 2, x^2 + (P - Q y) x - 3 now has its 4 rows at n = 20..60.

    One row is still wrong: n = 160 with −. Its residual is about 1e-123, past the 100 digits the evaluation works to, so the check can't see it. That is downcasting, which v3 removes (#1019). I'm keeping this open for it, and moving it to 3.0 with #1019.

  3. modified the milestones: 2.8, 3.0 on Nov 15, 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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions