-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix a bug with diophantine() when cornacchia() is not called properly #26780
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
Conversation
Occasionally diophantine() and diop_quadratic() results in a DN form $X^2 - DY^2 = N$ which cannot be handled by the current cornacchia() properly. For example, previously >>> eq1 = x**2 - 15*x + y**2 - 8*y # also mentioned in sympy#18628 >>> diophantine(eq1) {(0, 0), (15, 0), (15, 8), (0, 8)} >>> eq1.subs({x: 16, y: 4}) 0 >>> eq2 = 2*x**2 - 9*x + 4*y**2 - 8*y + 14 >>> diophantine(eq2) set() >>> eq2.subs({x: 2, y: 1}) 0 Both the examples leads to a function call cornacchia(1, X, 1) with X > 1, which turns out to have no solution for cornacchia(). The solver can only be applied when $a+b<=m$, ref: http://www.numbertheory.org/php/cornacchia.html An additional check has been added before the algorithm based on the fact that $ax^2 + by*2 = m$ admits a solution for $a + b > m$ only if $x = 0$ or $y = 0$. A test function includes both the two examples has been appended as well.
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.14. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) Full benchmark results can be found as artifacts in GitHub Actions |
Co-authored-by: haru-44 <36563693+haru-44@users.noreply.github.com>
Co-authored-by: haru-44 <36563693+haru-44@users.noreply.github.com>
Co-authored-by: haru-44 <36563693+haru-44@users.noreply.github.com>
thanks! looks good. |
Thanks |
Occasionally diophantine() and diop_quadratic() result in a DN form$X^2 - DY^2 = N$ which cannot be handled by the current cornacchia() properly. For example, previously the diophantine solver will miss some solutions:
Both the two examples lead to a function call of cornacchia(1, X, 1) with X > 1, which incorrrectly turns out to have no solution by using cornacchia(). The solver can only be applied when$a+b\le m$ . See reference from docs:$ax^2 + by^2 = m$ admits a solution for $a + b > m$ only if $x = 0$ or $y = 0$ . A test function including both the two examples has been appended as well.
http://www.numbertheory.org/php/cornacchia.html
An additional check has been added before the algorithm based on the fact that
References to other Issues or PRs
Fixes #18628
Brief description of what is fixed or changed
An additional check has been added before the cornacchia algorithm body based on the fact that$ax^2 + by^2 = m$ admits a solution for $a + b > m$ only if $x = 0$ or $y = 0$ .
Other comments
Release Notes