From 912ceb28f5a56b7c006326532c519021aa084116 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Fri, 25 Jul 2008 22:03:07 +0400 Subject: [PATCH] [14/24] Mul: teach ._eval_is_negative about all-terms-are-positive expressions (e.g. 2*positive) in such cases negative is known to be False for sure. Signed-off-by: Kirill Smelkov Signed-off-by: Ondrej Certik Signed-off-by: Mateusz Paprocki --- sympy/core/mul.py | 7 ++++++- sympy/core/tests/test_arit.py | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sympy/core/mul.py b/sympy/core/mul.py index 4859344..7d22564 100644 --- a/sympy/core/mul.py +++ b/sympy/core/mul.py @@ -567,7 +567,12 @@ class Mul(AssocOp, RelMeths, ArithMeths): def _eval_is_negative(self): terms = [t for t in self.args if not t.is_positive] if not terms: - return None + # all terms are either positive -- 2*Symbol('n', positive=T) + # or unknown -- 2*Symbol('x') + if self.is_positive: + return False + else: + return None c = terms[0] if len(terms)==1: return c.is_negative diff --git a/sympy/core/tests/test_arit.py b/sympy/core/tests/test_arit.py index cabae2b..6945f09 100644 --- a/sympy/core/tests/test_arit.py +++ b/sympy/core/tests/test_arit.py @@ -374,6 +374,9 @@ def test_Mul_is_negative_positive(): assert (-k).is_negative == False assert (2*k).is_negative == True + assert (2*n)._eval_is_negative() == False + assert (2*n).is_negative == False + assert n.is_negative == False assert (-n).is_negative == True assert (2*n).is_negative == False -- 2.11.4.GIT