Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discriminant for quadratic equation incorrectly computed #2038

Open
goualard-f opened this issue Mar 21, 2023 · 2 comments
Open

Discriminant for quadratic equation incorrectly computed #2038

goualard-f opened this issue Mar 21, 2023 · 2 comments

Comments

@goualard-f
Copy link

Describe the bug

It seems that the computation of the discriminant for quadratic equations uses the textbook formula $\Delta=b^2-4ac$ (source), which is flawed for some inputs. As a consequence, some equations are not solved correctly. Case in point:

$x^2 + (1+2^{-52})x + (0.25+2^{-53}) = 0$

All parameters are representable with double precision floating-point numbers. The solutions are also perfectly representable: $x_1=-\frac{1}{2}$ and $x_2=-\frac{1+2^{-51}}{2}$.

However, Numworks gets both the number of solutions and the solution wrong as it claims that there is only one solution equal to $\frac{4503599627370497}{9007199254740992}=-\frac{1+2^{-52}}{2}$.

Screenshots

screenshot(1)

screenshot

To Reproduce

Steps to reproduce the behavior:

  1. Go to the 'Equations' app
  2. Type the equation above
  3. Solve

Expected behavior

The quadratic solver should use a better algorithm to compute the discriminant so as to avoid returning the wrong number of solutions whenever possible. The state of the art is nicely summarized, albeit without references, in the blog post by Panchekha about the implementation of quadratic-solutions in the racket programming language.

Environment

  • Epsilon version (Settings > About > Software version): 20.4.0
  • The platform(s) on which the problem happens: online simulator, actual device, etc...
    Simulator. Should be the same problem on the actual device.
@artaxxx
Copy link
Collaborator

artaxxx commented Mar 30, 2023

Thank you @goualard-f !

@goualard-f
Copy link
Author

Also, this is not a matter of discriminant computation only. Try $x^2+2^{27}x+\frac{3}{4}=0$. It should have the solutions -134217728 and -5.587935447692871e-9. There is a catastrophic cancellation in computing the second solution with the naive formula, and the Numworks calculator computes the value $\approx$-7.45e-9. The algorithm should use the modified Fagnano's formulas to compute the solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants