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
Use assumption system instead of structural equality check in __bool__ method of Expression domain element #20428
Use assumption system instead of structural equality check in __bool__ method of Expression domain element #20428
Conversation
✅ 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.8. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Codecov Report
@@ Coverage Diff @@
## master #20428 +/- ##
=============================================
- Coverage 75.752% 75.747% -0.006%
=============================================
Files 673 673
Lines 174119 174120 +1
Branches 41109 41108 -1
=============================================
- Hits 131900 131892 -8
- Misses 36505 36507 +2
- Partials 5714 5721 +7 |
It seems that sympy/sympy/polys/densebasic.py Lines 265 to 276 in 026221a
The __bool__ method of EX sympy/sympy/polys/domains/expressiondomain.py Lines 122 to 123 in 026221a
return not f.ex.is_zero .
|
…oly (better fixed by expression domain fix in sympy#20428)
That's a better fix that also removes the need for the conversion to expression in |
sympy/polys/tests/test_polytools.py
Outdated
@@ -1458,6 +1458,15 @@ def test_Poly_rat_clear_denoms(): | |||
assert f.rat_clear_denoms(g) == (f, g) | |||
|
|||
|
|||
def test_issue_20427(): | |||
f = Poly(-117968192370600*18**(S(1)/3)/(217603955769048*(24201 + 253*sqrt(9165))**(S(1)/3) + 2273005839412*sqrt(9165)*(24201 + 253*sqrt(9165))**(S(1)/3)) - 15720318185*2**(S(2)/3)*3**(S(1)/3)*(24201 + 253*sqrt(9165))**(S(2)/3)/(217603955769048*(24201 + 253*sqrt(9165))**(S(1)/3) + 2273005839412*sqrt(9165)*(24201 + 253*sqrt(9165))**(S(1)/3)) + 15720318185*12**(S(1)/3)*(24201 + 253*sqrt(9165))**(S(2)/3)/(217603955769048*(24201 + 253*sqrt(9165))**(S(1)/3) + 2273005839412*sqrt(9165)*(24201 + 253*sqrt(9165))**(S(1)/3)) + 117968192370600*2**(S(1)/3)*3**(S(2)/3)/(217603955769048*(24201 + 253*sqrt(9165))**(S(1)/3) + 2273005839412*sqrt(9165)*(24201 + 253*sqrt(9165))**(S(1)/3)), x) |
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.
Can you split this long line? It looks like ca. 10 lines would be needed. Backslashes are not necessary.
sympy/polys/tests/test_polytools.py
Outdated
@@ -1458,6 +1458,15 @@ def test_Poly_rat_clear_denoms(): | |||
assert f.rat_clear_denoms(g) == (f, g) | |||
|
|||
|
|||
def test_issue_20427(): | |||
f = Poly(-117968192370600*18**(S(1)/3)/(217603955769048*(24201 + 253*sqrt(9165))**(S(1)/3) + 2273005839412*sqrt(9165)*(24201 + 253*sqrt(9165))**(S(1)/3)) - 15720318185*2**(S(2)/3)*3**(S(1)/3)*(24201 + 253*sqrt(9165))**(S(2)/3)/(217603955769048*(24201 + 253*sqrt(9165))**(S(1)/3) + 2273005839412*sqrt(9165)*(24201 + 253*sqrt(9165))**(S(1)/3)) + 15720318185*12**(S(1)/3)*(24201 + 253*sqrt(9165))**(S(2)/3)/(217603955769048*(24201 + 253*sqrt(9165))**(S(1)/3) + 2273005839412*sqrt(9165)*(24201 + 253*sqrt(9165))**(S(1)/3)) + 117968192370600*2**(S(1)/3)*3**(S(2)/3)/(217603955769048*(24201 + 253*sqrt(9165))**(S(1)/3) + 2273005839412*sqrt(9165)*(24201 + 253*sqrt(9165))**(S(1)/3)), x) | |||
coeff, poly = f.clear_denoms() |
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.
Maybe a single test would suffice: assert f == Poly(0, x, domain='EX')
.
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.
Done. That also clears up some confusion in my previous commit: Poly(...).is_zero is indeed 2 valued; Poly(y, x).is_zero is False
(is not the zero poly) doesn't imply y.is_zero is False
(there also shouldn't be a problem with how Poly(...).is_zero is used currently in rsolve).
This looks good. Can you squash the commits? |
7344f27
to
e35d42b
Compare
…_ method of ExpressionDomain Expression Avoids unstripped 0 bug
e35d42b
to
22c48bd
Compare
squashed and reworded commit message. |
Thanks! Merging. |
Thanks for the fix suggestion and review! |
References to other Issues or PRs
Brief description of what is fixed or changed
Fixes #20427
Other comments
fixes an unstripped zero in result from clear_denoms that would create a Poly that prints like the zero Poly but behaves inconsistently
Release Notes
__bool__
method ofExpression
domain element (fixing cases wherePoly(...).is_zero
would incorrectly returnFalse
)