-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
raise value error for Eq(RootOf(), Symbol) #15923
Changes from 1 commit
018e005
f392871
b33e6da
905ac79
51b7865
54c8ec3
2568b6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -970,8 +970,10 @@ def _eval_Eq(self, other): | |
# is_real value of the CRootOf instance. | ||
if type(self) == type(other): | ||
return sympify(self == other) | ||
if other.has(Symbol): | ||
return | ||
if other.is_number and other.has(AppliedUndef) or not other.is_number: | ||
# it's a number that can't be evaluated or it's not a number in its current form | ||
# though simplification might identify it as such (but that is the user's choice) | ||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually sorry I see that this might work okay. Have you tested it on your computer? Is it better than the other suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tested it on your computer? Is it better than the other suggestions? I have tested it and I think it is a better suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those were not really yes/no questions. Can you explain what the difference is? Why is this version better? What examples are handled differently? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am happy with this as it is. It would be interesting to see if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also happy with this as it is. The current version makes sense to me even if further optimisations might be possible. |
||
if not (other.is_number and not other.has(AppliedUndef)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are mutually exclusive so if it is a number it doesn't have AppliedUndef so this simplifies to It might make more sense to do if not other.is_number:
# it might be a number after simplification but it isn't right now
# but if it is known that it is not constant, then it can't be a
# RootOf value (hence False)
return other.is_constant But I would tend to just return the None and let the user decide if they want to attempt simplification; I know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't change this online because you might want to test it locally before making this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand this. Surely we don't want to return True just because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right: |
||
return S.false | ||
if not other.is_finite: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
from sympy import ( | ||
S, sqrt, I, Rational, Float, Lambda, log, exp, tan, Function, Eq, | ||
solve, legendre_poly | ||
solve, legendre_poly, Symbol, Integral | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these extra imports needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes and No. They are both used in test 15920, but x is already imported at the top from abc so needs not to be recreated. |
||
) | ||
|
||
from sympy.utilities.pytest import raises | ||
|
@@ -142,8 +142,7 @@ def test_CRootOf___eval_Eq__(): | |
assert Eq(r, 0) is S.false | ||
assert Eq(r, S.Infinity) is S.false | ||
assert Eq(r, I) is S.false | ||
assert Eq(r, f(0)) is S.false | ||
assert Eq(r, f(0)) is S.false | ||
assert Eq(r, f(0)).lhs is r and Eq(r, f(0)).rhs is f(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it guaranteed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the type of test that I wrote this function for; it would be used like: unchanged(Eq, r, f(0)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be useful but wasn't include... Maybe this test for now should just be: eq = Eq(r, f(0))
assert isinstance(eq, Eq) and eq.args == (r, f(0)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smichr this only works because of caching otherwise $ cat t.py
from sympy import *
f = Function('f')
print(f(0) is f(0))
$ python t.py
True
$ SYMPY_USE_CACHE=no python t.py
False |
||
sol = solve(eq) | ||
for s in sol: | ||
if s.is_real: | ||
|
@@ -566,3 +565,9 @@ def test_eval_approx_relative(): | |
assert [str(i) for i in a] == [ | ||
'-0.10', '0.05 - 3.2*I', '0.05 + 3.2*I'] | ||
assert all(abs(((a[i] - t[i])/t[i]).n()) < 1e-2 for i in range(len(a))) | ||
|
||
def test_issue_15920(): | ||
x = Symbol("x") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed please put space around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I patched it up. This should be ready to go. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks |
||
r = rootof(x**5-x+1,0) | ||
p = Integral(x, (x, 1, y)) | ||
assert Eq(r, p).lhs is r and Eq(r, p).rhs is p |
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.
other
will never have AppliedUndef ifother.is_number
is True:So I think this should be