Skip to content

Conversation

alijosephine
Copy link
Contributor

@alijosephine alijosephine commented Aug 31, 2021

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

  • solvers
    • nonlinsolve properly handles instances of Eq in systems of equations

…_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.
@sympy-bot
Copy link

sympy-bot commented Aug 31, 2021

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.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
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

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* solvers
  * nonlinsolve properly handles instances of Eq in systems of equations
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@github-actions
Copy link

github-actions bot commented Aug 31, 2021

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

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
(click on checks at the top of the PR).

Made changes suggested in review comments for unit tests. These tests are to verify the bugfix related to issue sympy#19144.
@smichr smichr enabled auto-merge September 2, 2021 15:59
denominators.update(_simple_dens(eq, symbols))
# Convert equality to expression
if isinstance(eq, Equality):
eq = eq.rewrite(Add)
Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Member

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

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

Successfully merging this pull request may close these issues.

4 participants