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

Inequalities: return BooleanAtoms instead of bools. #2984

Merged
merged 1 commit into from Mar 15, 2014
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
2 changes: 1 addition & 1 deletion sympy/assumptions/ask.py
Expand Up @@ -135,7 +135,7 @@ def ask(proposition, assumptions=True, context=global_assumptions):
# direct resolution method, no logic
res = key(expr)._eval_ask(assumptions)
if res is not None:
return res
return bool(res)

if assumptions == True:
return
Expand Down
6 changes: 3 additions & 3 deletions sympy/assumptions/handlers/calculus.py
Expand Up @@ -254,11 +254,11 @@ def Pow(expr, assumptions):
return False
if base_bounded and exp_bounded:
return True
if (abs(expr.base) <= 1) is True and ask(Q.positive(expr.exp), assumptions):
if (abs(expr.base) <= 1) == True and ask(Q.positive(expr.exp), assumptions):
return True
if (abs(expr.base) >= 1) is True and ask(Q.negative(expr.exp), assumptions):
if (abs(expr.base) >= 1) == True and ask(Q.negative(expr.exp), assumptions):
return True
if (abs(expr.base) >= 1) is True and exp_bounded is False:
if (abs(expr.base) >= 1) == True and exp_bounded is False:
return False
return None

Expand Down
4 changes: 2 additions & 2 deletions sympy/concrete/delta.py
Expand Up @@ -166,7 +166,7 @@ def deltaproduct(f, limit):
"""
from sympy.concrete.products import product

if ((limit[2] - limit[1]) < 0) is True:
if ((limit[2] - limit[1]) < 0) == True:
return S.One

if not f.has(KroneckerDelta):
Expand Down Expand Up @@ -284,7 +284,7 @@ def deltasummation(f, limit, no_piecewise=False):
from sympy.concrete.summations import summation
from sympy.solvers import solve

if ((limit[2] - limit[1]) < 0) is True:
if ((limit[2] - limit[1]) < 0) == True:
return S.Zero

if not f.has(KroneckerDelta):
Expand Down
15 changes: 7 additions & 8 deletions sympy/concrete/summations.py
Expand Up @@ -194,7 +194,7 @@ def doit(self, **hints):
for n, limit in enumerate(self.limits):
i, a, b = limit
dif = b - a
if dif.is_integer and (dif < 0) is True:
if dif.is_integer and (dif < 0) == True:
a, b = b + 1, a - 1
f = -f

Expand Down Expand Up @@ -308,7 +308,7 @@ def euler_maclaurin(self, m=0, n=0, eps=0, eval_integral=True):
if len(self.limits) != 1:
raise ValueError("More than 1 limit")
i, a, b = self.limits[0]
if (a > b) is True:
if (a > b) == True:
if a - b == 1:
return S.Zero,S.Zero
a, b = b + 1, a - 1
Expand All @@ -324,10 +324,9 @@ def euler_maclaurin(self, m=0, n=0, eps=0, eval_integral=True):
term = f.subs(i, a)
if term:
test = abs(term.evalf(3)) < eps
if isinstance(test, bool):
if test is True:
return s, abs(term)
else:
if test == True:
return s, abs(term)
elif not (test == False):
# a symbolic Relational class, can't go further
return term, S.Zero
s += term
Expand Down Expand Up @@ -758,7 +757,7 @@ def eval_sum_hyper(f, i_a_b):
return None
(res1, cond1), (res2, cond2) = res1, res2
cond = And(cond1, cond2)
if cond is False:
if cond == False:
return None
return Piecewise((res1 - res2, cond), (old_sum, True))

Expand All @@ -770,7 +769,7 @@ def eval_sum_hyper(f, i_a_b):
res1, cond1 = res1
res2, cond2 = res2
cond = And(cond1, cond2)
if cond is False:
if cond == False:
return None
return Piecewise((res1 + res2, cond), (old_sum, True))

Expand Down
6 changes: 3 additions & 3 deletions sympy/core/containers.py
Expand Up @@ -94,10 +94,10 @@ def _to_mpmath(self, prec):
return tuple([a._to_mpmath(prec) for a in self.args])

def __lt__(self, other):
return self.args < other.args
return sympify(self.args < other.args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be Boolean(self.args < other.args) instead (more specific)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Boolean (and BooleanAtom) don't have this functionality. Neither specifies a __new__ or __init__ method, so there's no conversion to the singleton objects.

Copy link
Member

Choose a reason for hiding this comment

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

I saw elsewhere someone using _sympify -- that might be a better option.

Copy link
Member

Choose a reason for hiding this comment

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

nevermind -- _sympify won't work with None


def __le__(self, other):
return self.args <= other.args
return sympify(self.args <= other.args)

# XXX: Basic defines count() as something different, so we can't
# redefine it here. Originally this lead to cse() test failure.
Expand Down Expand Up @@ -247,7 +247,7 @@ def __contains__(self, key):
return sympify(key) in self._dict

def __lt__(self, other):
return self.args < other.args
return sympify(self.args < other.args)

@property
def _sorted_args(self):
Expand Down
10 changes: 5 additions & 5 deletions sympy/core/expr.py
Expand Up @@ -218,7 +218,7 @@ def __ge__(self, other):
raise TypeError("Invalid comparison of complex %s" % dif)
if dif.is_nonnegative is not None and \
dif.is_nonnegative is not dif.is_negative:
return dif.is_nonnegative
return sympify(dif.is_nonnegative)
return C.GreaterThan(self, other)

@_sympifyit('other', False) # sympy > other
Expand All @@ -228,7 +228,7 @@ def __le__(self, other):
raise TypeError("Invalid comparison of complex %s" % dif)
if dif.is_nonpositive is not None and \
dif.is_nonpositive is not dif.is_positive:
return dif.is_nonpositive
return sympify(dif.is_nonpositive)
return C.LessThan(self, other)

@_sympifyit('other', False) # sympy > other
Expand All @@ -238,7 +238,7 @@ def __gt__(self, other):
raise TypeError("Invalid comparison of complex %s" % dif)
if dif.is_positive is not None and \
dif.is_positive is not dif.is_nonpositive:
return dif.is_positive
return sympify(dif.is_positive)
return C.StrictGreaterThan(self, other)

@_sympifyit('other', False) # sympy > other
Expand All @@ -248,7 +248,7 @@ def __lt__(self, other):
raise TypeError("Invalid comparison of complex %s" % dif)
if dif.is_negative is not None and \
dif.is_negative is not dif.is_nonnegative:
return dif.is_negative
return sympify(dif.is_negative)
return C.StrictLessThan(self, other)

@staticmethod
Expand Down Expand Up @@ -2019,7 +2019,7 @@ def could_extract_minus_sign(self):
return len(negative_args) % 2 == 1

# As a last resort, we choose the one with greater value of .sort_key()
return self.sort_key() < negative_self.sort_key()
return bool(self.sort_key() < negative_self.sort_key())

def extract_branch_factor(self, allow_half=False):
"""
Expand Down
4 changes: 2 additions & 2 deletions sympy/core/exprtools.py
Expand Up @@ -534,9 +534,9 @@ def gcd(self, other): # Factors
for factor, exp in self.factors.items():
if factor in other.factors:
lt = (exp < other.factors[factor])
if lt is True:
if lt == True:
factors[factor] = exp
elif lt is False:
elif lt == False:
factors[factor] = other.factors[factor]

return Factors(factors)
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/mod.py
Expand Up @@ -50,7 +50,7 @@ def doit(p, q):
else:
if type(d) is int:
rv = p - d*q
if (rv*q < 0) is True:
if (rv*q < 0) == True:
rv += q
return rv

Expand Down