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.is_negative #14815
Comments
I think it is appropriate ( |
@asmeurer I would like to work on this issue. |
If something has a nonzero imaginary component, SymPy gives False:
So I think it's fair to say that sqrt(x) will never be negative: it will either be nonnegative or have an imaginary component. |
Is it better to have this instead of |
Not to be coy, but...it depends what your assumptions are:
With the following diff, diff --git a/sympy/core/power.py b/sympy/core/power.py
index f0e69a3..1172635 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -451,23 +451,10 @@ def _eval_is_positive(self):
return log(self.base).is_imaginary
def _eval_is_negative(self):
- if self.base.is_negative:
- if self.exp.is_odd:
- return True
- if self.exp.is_even:
- return False
- elif self.base.is_positive:
- if self.exp.is_real:
- return False
- elif self.base.is_nonnegative:
- if self.exp.is_nonnegative:
- return False
- elif self.base.is_nonpositive:
- if self.exp.is_even:
- return False
- elif self.base.is_real:
- if self.exp.is_even:
- return False
+ # it is either nonnegative or has an
+ # imaginary component (which is not negative)
+ # since I.is_negative -> False
+ return False >>> sqrt(var('x')).is_negative
False |
Is this issue still open, if yes what needs to be done here, can anyone specify, I'd like to take up the issue. |
The problem is that in sympy we don't have a clean way to distinguish when something is an ordinary number or not. We often think that
I don't know what kind of object possibly could have a negative sqrt (given that sympy uses the principal root) but I think we should make explicit our assumptions when writing this kind of code so e.g.:
If that means that it doesn't evaluate for a plain symbol then that's unfortunate and unintuitive but... Until sympy can clean itself up so it knows when something (including a symbol) actually is a plain number we will always have situations like this. |
sqrt(x).is_negative
currently gives None. But if sqrt represents the principal square root, shouldn't it be False?This came up from this StackOverflow question
The text was updated successfully, but these errors were encountered: