-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Fix bugs in ComplexRegion._contains() #18308
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
Fix bugs in ComplexRegion._contains() #18308
Conversation
|
✅ Hi, I am the SymPy bot (v149). 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.6. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
|
I see you have a test failure for this I've seen this precise example come up in many PRs including my own. It seems to be very flakey. |
It's flaky indeed. It's the one I meant here and that got me to investigate. I noticed that sympy/sympy/solvers/solveset.py Lines 2759 to 2771 in 8a7dc8e
The above code block is called with both intersection_true and complement_true True, so that the second block overrides the first one...
The commit I pushed just now handles almost all the other test failures. But there's another remaining test failure that pointed me to a very unfortunate fact: Many tests in sympy/sympy/solvers/tests/test_solveset.py Lines 47 to 55 in 8a7dc8e
|
Blame shows that it dates back to the creation of the solveset module. |
|
Strange: With the latest commit the number of Travis test failures in What's bothering me is that when testing locally I only have a single failure ( |
Never mind. I think I figured it out. I had a closer look at the Travis logs and it seems what is actually tested is not the PR branch but a "fictitious" merged branch. That's sensible I guess. |
|
Yes, Travis tests the PR after merging it into master (that's why the tests don't run when there's a merge conflict). That should mean that conflicting PRs can't lead to test failures on master but there is a loop-hole: if the tests have passed then other PRs can be merged to master and the tests won't re-run but the PR remains mergeable. |
The following are fixed in _contains(): - sympy#18280: The method had no provisions for undecidable membership; instead of `None` it would return `False`. - sympy#18280: The method checked `arg(other)` for membership in the respective theta intervals but those are normalized to [0, 2*pi) and not (-pi, pi]. - For PolarComplexRegions the method incorrectly set theta = 0 if `other` was 0. So it returned a somewhat arbitrary truth value in this case. Now it will exclusively check complex modulus if other==0. Tests are added.
Having "spurious" intersections with S.Complexes leads to a number of test failures. (Actual conditions should be handled in other places, not by simply wrapping end results in an intersection.)
This commit fixes a number of bugs: - _extract_main_soln() used sym as key in complements, but sym is not correctly defined at this stage. But the code doesn't raise because an unrelated sym variable has been introduced at the very beginning of substitution(). - _solve_using_known_values() called _add_intersection_complement() with both Intersection=True and Complement=True, but passes only the intersection dictionary. - _add_intersection_complement() could not actually handle intersections and complements concurrently.
8b7ca68 to
2cef166
Compare
| assert len(sol) == 20 | ||
| assert len(sol) >= 4 and len(sol) <= 20 | ||
| # nonlinsolve has been giving a varying number of solutions | ||
| # (originally 18, then 20, now 19) due to various internal changes. |
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 can remember being annoyed by this test. I made sure to leave a comment so that others wouldn't worry too much about it.
Codecov Report
@@ Coverage Diff @@
## master #18308 +/- ##
=============================================
+ Coverage 75.307% 75.308% +0.001%
=============================================
Files 639 639
Lines 167125 167124 -1
Branches 39418 39420 +2
=============================================
+ Hits 125857 125859 +2
+ Misses 35731 35720 -11
- Partials 5537 5545 +8 |
|
Looks good! |
References to other Issues or PRs
Fixes #18280
Brief description of what is fixed or changed
The following are fixed in ComplexRegion._contains():
instead of
Noneit would returnFalse.arg(other)for membership in therespective theta intervals but those are normalized to [0, 2*pi)
and not (-pi, pi].
otherwas 0. So it returned a somewhat arbitrary truth value inthis case. Now it will exclusively check complex modulus if other==0.
Tests are added.
Making the tests pass required fixing a number of issues in
nonlinsolve'ssubstitutionsolver. From the commit message:_extract_main_soln()usedsymas key in complements, butsymis notcorrectly defined at this stage. But the code doesn't raise because an
unrelated
symvariable has been introduced at the very beginning ofsubstitution()._solve_using_known_values()called_add_intersection_complement()withboth
Intersection=TrueandComplement=True, but passes only theintersection dictionary.
_add_intersection_complement()could not actually handle intersectionsand complements concurrently.
Other comments
Release Notes
ComplexRegion.contains()that could lead to incorrect results when membership is in fact undecidable or at least unknown.nonlinsolve's handling of intersections and complements in the final result.