-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fixes discrepancy between solutions for Eq and Expr in nonlinsolve (converts Eq to Expr in _separate_poly_nonpoly) #21989
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
Fixes discrepancy between solutions for Eq and Expr in nonlinsolve (converts Eq to Expr in _separate_poly_nonpoly) #21989
Conversation
…_poly_nonpoly() Previously, Expr and Eq representations of same equations would give different solutions in nonlinsolve() because Expr and Eq were treated differently by _separate_poly_nonpoly(). In this commit, added Eq to Expr conversion based on 'LHS - RHS = 0' in _separate_poly_nonpoly().
Converted Equality to Expr before processing eq in _separate_poly_nonpoly() as part of commit a3a6b2b. In this commit, test cases added to test_solveset.py for the same.
✅ Hi, I am the SymPy bot (v161). 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.9. 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) before after ratio
[ed9a550f] [ea6fce31]
<sympy-1.8^0>
- 961±20ms 131±2ms 0.14 dsolve.TimeDsolve01.time_dsolve
- 8.02±0.03s 4.30±0.06s 0.54 integrate.TimeIntegrationRisch02.time_doit(100)
- 7.99±0.03s 4.22±0.03s 0.53 integrate.TimeIntegrationRisch02.time_doit_risch(100)
- 67.6±0.5μs 26.2±0.1μs 0.39 matrices.TimeDiagonalEigenvals.time_eigenvals
- 82.9±0.7μs 51.9±0.5μs 0.63 matrices.TimeMatrixGetItem.time_ImmutableDenseMatrix_getitem
- 82.3±0.8μs 51.4±0.5μs 0.62 matrices.TimeMatrixGetItem.time_ImmutableSparseMatrix_getitem
- 79.4±1μs 50.2±0.3μs 0.63 matrices.TimeMatrixGetItem.time_MutableDenseMatrix_getitem
- 82.6±0.9μs 50.7±1μs 0.61 matrices.TimeMatrixGetItem.time_MutableSparseMatrix_getitem
+ 80.7±0.4μs 124±0.3μs 1.53 solve.TimeMatrixArithmetic.time_dense_add(10, 5)
+ 10.8±0.04μs 17.1±0.2μs 1.59 solve.TimeMatrixArithmetic.time_dense_add(3, 0)
+ 12.6±0.08μs 27.4±0.2μs 2.17 solve.TimeMatrixArithmetic.time_dense_add(3, 5)
+ 18.5±0.04μs 35.4±0.2μs 1.91 solve.TimeMatrixArithmetic.time_dense_add(4, 5)
+ 33.9±0.2μs 58.7±0.6μs 1.73 solve.TimeMatrixArithmetic.time_dense_add(6, 5)
- 1.12±0.01ms 232±2μs 0.21 solve.TimeMatrixArithmetic.time_dense_multiply(10, 0)
- 42.7±0.2μs 22.9±0.3μs 0.54 solve.TimeMatrixArithmetic.time_dense_multiply(3, 0)
+ 66.3±0.4μs 119±2μs 1.79 solve.TimeMatrixArithmetic.time_dense_multiply(3, 5)
- 90.8±1μs 30.2±0.1μs 0.33 solve.TimeMatrixArithmetic.time_dense_multiply(4, 0)
- 270±2μs 64.5±0.2μs 0.24 solve.TimeMatrixArithmetic.time_dense_multiply(6, 0)
- 85.2±1μs 38.5±0.2μs 0.45 solve.TimeMatrixOperations.time_det(3, 0)
- 154±1μs 92.7±0.8μs 0.60 solve.TimeMatrixOperations.time_det(3, 2)
- 147±3μs 84.0±4μs 0.57 solve.TimeMatrixOperations.time_det(3, 5)
- 83.7±0.8μs 38.0±0.4μs 0.45 solve.TimeMatrixOperations.time_det_bareiss(3, 0)
- 154±2μs 92.0±0.2μs 0.60 solve.TimeMatrixOperations.time_det_bareiss(3, 2)
- 143±1μs 83.5±0.8μs 0.59 solve.TimeMatrixOperations.time_det_bareiss(3, 5)
- 84.0±0.7μs 38.3±0.09μs 0.46 solve.TimeMatrixOperations.time_det_berkowitz(3, 0)
- 155±0.6μs 92.5±0.7μs 0.60 solve.TimeMatrixOperations.time_det_berkowitz(3, 2)
- 145±0.9μs 82.6±0.2μs 0.57 solve.TimeMatrixOperations.time_det_berkowitz(3, 5)
+ 687±10μs 1.11±0ms 1.61 solve.TimeMatrixOperations.time_det_berkowitz(4, 0)
+ 842±20μs 1.59±0.01ms 1.89 solve.TimeMatrixOperations.time_det_berkowitz(4, 2)
+ 906±20μs 1.69±0.02ms 1.86 solve.TimeMatrixOperations.time_det_berkowitz(4, 5)
+ 256±2μs 423±4μs 1.66 solve.TimeMatrixOperations.time_rank(3, 0)
+ 403±10μs 635±4μs 1.58 solve.TimeMatrixOperations.time_rank(4, 0)
+ 115±2μs 175±1μs 1.52 solve.TimeMatrixOperations.time_rref(3, 0)
- 4.74±0.07ms 2.79±0.01ms 0.59 solve.TimeRationalSystem.time_linsolve(10)
Full benchmark results can be found as artifacts in GitHub Actions |
Made changes suggested in review comments for unit tests. These tests are to verify the bugfix related to issue sympy#19144.
denominators.update(_simple_dens(eq, symbols)) | ||
# Convert equality to expression | ||
if isinstance(eq, Equality): | ||
eq = eq.rewrite(Add) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this in a few places in the codebase. Why is rewrite(Add)
preferred over lhs - rhs
?
To me rewriting an equation as an expression is not even really a "rewrite" since usually rewrite in sympy returns a symbolic object that is equivalent to the original.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a guaranteed way to know you have done the right thing: eq.rewrite(Add)
vs eq.rhs - eq.rhs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Historically, the option to write eq.as_expr()
was frowned upon so the more specific rewrite as an Add
was added.)
References to other Issues or PRs
Related to issue #19144
Fixes remaining bug from #19144
Brief description of what is fixed or changed
Previously, Expr and Eq representations of same equations would give different solutions in nonlinsolve() because Expr and Eq were treated differently by _separate_poly_nonpoly(). In this commit, added Eq to Expr conversion based on 'LHS - RHS = 0' in _separate_poly_nonpoly(). Test cases have been added to test_solveset.py
Other comments
Release Notes