Skip to content
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

sqrt(x).is_negative returns False instead of None #18597

Merged
merged 6 commits into from Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions sympy/core/power.py
Expand Up @@ -530,6 +530,9 @@ def _eval_is_extended_positive(self):
return log(self.base).is_imaginary

def _eval_is_extended_negative(self):
if self.exp is S(1)/2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is works here because 1/2 is singletonized, but it's generally better to be explicit about that and use S.Half if you are using is (otherwise use ==).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to generalize this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I would change that and keep it correct next time. Should I commit this to same branch?

if self.base.is_complex or self.base.is_extended_real:
return False
Smit-create marked this conversation as resolved.
Show resolved Hide resolved
if self.base.is_extended_negative:
if self.exp.is_odd and self.base.is_finite:
return True
Expand Down
13 changes: 13 additions & 0 deletions sympy/core/tests/test_power.py
Expand Up @@ -510,6 +510,19 @@ def test_issue_18190():
assert sqrt(1 / tan(1 + I)) == 1 / sqrt(tan(1 + I))


def test_issue_14815():
x = Symbol('x', real=True)
assert sqrt(x).is_extended_negative is False
x = Symbol('x', real=False)
assert sqrt(x).is_extended_negative is None
x = Symbol('x', complex=True)
assert sqrt(x).is_extended_negative is False
x = Symbol('x', extended_real=True)
assert sqrt(x).is_extended_negative is False
assert sqrt(zoo, evaluate=False).is_extended_negative is None
assert sqrt(nan, evaluate=False).is_extended_negative is None


def test_issue_18509():
assert unchanged(Mul, oo, 1/pi**oo)
assert (1/pi**oo).is_extended_positive == False