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

Conversation

Smit-create
Copy link
Member

@Smit-create Smit-create commented Feb 7, 2020

Fixes sqrt(x).is_negative to return False instead of None

References to other Issues or PRs

Fixes #14815

Brief description of what is fixed or changed

Before fixing:

>>> from sympy import Symbol, sqrt
>>> x = Symbol('x')
>>> sqrt(x).is_negative
>>>

After fixing:

>>> from sympy import Symbol, sqrt
>>> x = Symbol('x')
>>> sqrt(x).is_negative
False

Other comments

Release Notes

  • core
    • sqrt(x).is_negative is False when x is real

@sympy-bot
Copy link

sympy-bot commented Feb 7, 2020

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.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->
Fixes `sqrt(x).is_negative` to return `False` instead of `None`
#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #14815

#### Brief description of what is fixed or changed
Before fixing:
```
>>> from sympy import Symbol, sqrt
>>> x = Symbol('x')
>>> sqrt(x).is_negative
>>>
```
After fixing:
```
>>> from sympy import Symbol, sqrt
>>> x = Symbol('x')
>>> sqrt(x).is_negative
False
```

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* core
   * `sqrt(x).is_negative` is False when `x` is real
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@oscarbenjamin
Copy link
Contributor

This should be applied to extended_negative rather than is_negative.

@Smit-create
Copy link
Member Author

Okay, will change that

sympy/core/power.py Outdated Show resolved Hide resolved
@oscarbenjamin
Copy link
Contributor

If we return None for nan/zoo than we have to also return None for a plain Symbol('x').

@Smit-create
Copy link
Member Author

If we return None for nan/zoo than we have to also return None for a plain Symbol('x').

But from #14815(comment) i.e in orginal issue was to return False for Symbol('x').

@oscarbenjamin
Copy link
Contributor

It would be good to have a test for a symbol with complex=True and another with extended_real=True.

@smichr smichr merged commit b17ef6e into sympy:master Feb 9, 2020
@@ -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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sqrt.is_negative
5 participants