-
-
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
Fix is_real for trigonometric and hyperbolic functions #13678
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,7 +228,16 @@ def _eval_as_leading_term(self, x): | |
return self.func(arg) | ||
|
||
def _eval_is_real(self): | ||
return self.args[0].is_real | ||
if self.args[0].is_real: | ||
return True | ||
|
||
def _eval_is_positive(self): | ||
if self.args[0].is_real: | ||
return self.args[0].is_positive | ||
|
||
def _eval_is_negative(self): | ||
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. similarly for this I guess. |
||
if self.args[0].is_real: | ||
return self.args[0].is_negative | ||
|
||
def _eval_is_finite(self): | ||
arg = self.args[0] | ||
|
@@ -379,8 +388,9 @@ def _eval_as_leading_term(self, x): | |
else: | ||
return self.func(arg) | ||
|
||
def _eval_is_real(self): | ||
return self.args[0].is_real | ||
def _eval_is_positive(self): | ||
if self.args[0].is_real: | ||
return True | ||
|
||
def _eval_is_finite(self): | ||
arg = self.args[0] | ||
|
@@ -526,7 +536,16 @@ def _eval_as_leading_term(self, x): | |
return self.func(arg) | ||
|
||
def _eval_is_real(self): | ||
return self.args[0].is_real | ||
if self.args[0].is_real: | ||
return True | ||
|
||
def _eval_is_positive(self): | ||
if self.args[0].is_real: | ||
return self.args[0].is_positive | ||
|
||
def _eval_is_negative(self): | ||
if self.args[0].is_real: | ||
return self.args[0].is_negative | ||
|
||
def _eval_is_finite(self): | ||
arg = self.args[0] | ||
|
@@ -657,6 +676,14 @@ def _eval_rewrite_as_cosh(self, arg): | |
def _eval_rewrite_as_tanh(self, arg): | ||
return 1/tanh(arg) | ||
|
||
def _eval_is_positive(self): | ||
if self.args[0].is_real: | ||
return self.args[0].is_positive | ||
|
||
def _eval_is_negative(self): | ||
if self.args[0].is_real: | ||
return self.args[0].is_negative | ||
|
||
def _eval_as_leading_term(self, x): | ||
from sympy import Order | ||
arg = self.args[0].as_leading_term(x) | ||
|
@@ -784,6 +811,14 @@ def taylor_term(n, x, *previous_terms): | |
def _eval_rewrite_as_cosh(self, arg): | ||
return S.ImaginaryUnit / cosh(arg + S.ImaginaryUnit * S.Pi / 2) | ||
|
||
def _eval_is_positive(self): | ||
if self.args[0].is_real: | ||
return self.args[0].is_positive | ||
|
||
def _eval_is_negative(self): | ||
if self.args[0].is_real: | ||
return self.args[0].is_negative | ||
|
||
def _sage_(self): | ||
import sage.all as sage | ||
return sage.csch(self.args[0]._sage_()) | ||
|
@@ -823,6 +858,10 @@ def taylor_term(n, x, *previous_terms): | |
def _eval_rewrite_as_sinh(self, arg): | ||
return S.ImaginaryUnit / sinh(arg + S.ImaginaryUnit * S.Pi /2) | ||
|
||
def _eval_is_positive(self): | ||
if self.args[0].is_real: | ||
return True | ||
|
||
def _sage_(self): | ||
import sage.all as sage | ||
return sage.sech(self.args[0]._sage_()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In your branch:
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.
You probably want
sinh(1 + I).is_real
to be False instead of None (makingis_positive
False too), but I'm not sure it's worth it.It would be easy to call
self.as_real_imag()
and then.is_zero
, but even if we passdeep=False
nested evaluation will lead to runtime exponential in the depth of the expression: 8 seconds for building(sinh^9)(1 + I)
(^
in the sense of nested application) and 24 seconds for.is_real
, instead of 3 milliseconds total with the current PR.Slowing down to return True instead of None could have been worthwhile because proving something is real often leads to simplifications, but is it worth the slowdown to return False instead of None?
Food for thought: in the current implementation,
(a+b).is_real
only returns True when both a and b are real.