You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an expression is only known to be extended_real and infinite its sign is unknown so is_extended_positive should give None but
In [1]: x =Symbol('x', infinite=True, extended_real=True)
In [2]:print(x.is_extended_positive)
None
In [3]:print((-x).is_extended_positive)
True
The obvious fix is
diff --git a/sympy/core/mul.py b/sympy/core/mul.py
index da2a8b18e7..ea0df52dfc 100644
--- a/sympy/core/mul.py+++ b/sympy/core/mul.py@@ -1401,12 +1401,12 @@ def _eval_pos_neg(self, sign):
saw_NON = True
elif t.is_extended_nonnegative:
saw_NON = True
- elif t.is_positive is False:+ elif t.is_extended_positive is False:
sign = -sign
if saw_NOT:
return
saw_NOT = True
- elif t.is_negative is False:+ elif t.is_extended_negative is False:
if saw_NOT:
return
saw_NOT = True
Which gives
In [3]:print((-x).is_extended_positive)
None
However it also leads to test failures in other places where positive=False is used:
$ pytest sympy/core/ -n4...============================================================ FAILURES ============================================================_________________________________________________ test_symbol_falsepositive_mul __________________________________________________[gw1] darwin -- Python 3.5.7 /Users/enojb/current/sympy/35venv/bin/python3.5 def test_symbol_falsepositive_mul(): # To test pull request 9379 # Explicit handling of arg.is_positive=False was added to Mul._eval_is_positive x = 2*Symbol('x', positive=False)
> assert x.is_positive is False # This was None beforeE assert None is FalseE + where None = 2*x.is_positivesympy/core/tests/test_assumptions.py:460: AssertionError_________________________________________________ test_neg_symbol_falsepositive __________________________________________________[gw1] darwin -- Python 3.5.7 /Users/enojb/current/sympy/35venv/bin/python3.5 def test_neg_symbol_falsepositive(): x = -Symbol('x', positive=False) assert x.is_positive is None assert x.is_nonpositive is None
> assert x.is_negative is FalseE assert None is FalseE + where None = -x.is_negativesympy/core/tests/test_assumptions.py:472: AssertionError_________________________________________________ test_neg_symbol_falsenegative __________________________________________________[gw1] darwin -- Python 3.5.7 /Users/enojb/current/sympy/35venv/bin/python3.5 def test_neg_symbol_falsenegative(): # To test pull request 9379 # Explicit handling of arg.is_negative=False was added to Mul._eval_is_positive x = -Symbol('x', negative=False)
> assert x.is_positive is False # This was None beforeE assert None is FalseE + where None = -x.is_positivesympy/core/tests/test_assumptions.py:482: AssertionError DO *NOT* COMMIT! ================================= 3 failed, 1696 passed, 65 skipped, 41 xfailed in 60.70 seconds =================================
The fix for that is probably to add Mul._eval_is_positive (and Mul._eval_is_negative) as well as Mul._eval_is_extended_positive. However this should be done intelligently to avoid duplicating the _eval_pos_neg routine. Maybe just:
def _eval_is_positive(self):
if self._eval_is_finite() is False:
return False
return self._eval_pos_neg(1)
It should be checked that this doesn't lead to any slowdown though.
The text was updated successfully, but these errors were encountered:
When an expression is only known to be extended_real and infinite its sign is unknown so
is_extended_positive
should give None butThe obvious fix is
Which gives
However it also leads to test failures in other places where positive=False is used:
The fix for that is probably to add
Mul._eval_is_positive
(andMul._eval_is_negative
) as well asMul._eval_is_extended_positive
. However this should be done intelligently to avoid duplicating the_eval_pos_neg
routine. Maybe just:It should be checked that this doesn't lead to any slowdown though.
The text was updated successfully, but these errors were encountered: