# Source code for sympy.assumptions.handlers.order

"""
AskHandlers related to order relations: positive, negative, etc.
"""
from __future__ import print_function, division

from sympy.assumptions.handlers import CommonHandler
from sympy.core.logic import fuzzy_not, fuzzy_and, fuzzy_or

"""
This is called by ask() when key='negative'

Test that an expression is less (strict) than zero.

Examples:

>>> from sympy import ask, Q, pi
False
False

"""

@staticmethod
def _number(expr, assumptions):
if not expr.as_real_imag()[1]:
return expr.evalf() < 0
else:
return False

@staticmethod
def Basic(expr, assumptions):
if expr.is_number:

@staticmethod
"""
Positive + Positive -> Positive,
Negative + Negative -> Negative
"""
if expr.is_number:
nonpos = 0
for arg in expr.args:
if ask(Q.negative(arg), assumptions) is not True:
nonpos += 1
else:
break
else:
if nonpos < len(expr.args):
return True

@staticmethod
def Mul(expr, assumptions):
if expr.is_number:
result = None
for arg in expr.args:
if result is None:
result = False
result = not result
pass
else:
return
return result

@staticmethod
[docs]    def Pow(expr, assumptions):
"""
Real ** Even -> NonNegative
Real ** Odd  -> same_as_base
NonNegative ** Positive -> NonNegative
"""
if expr.is_number:
return False
return False

ImaginaryUnit, Abs = [staticmethod(CommonHandler.AlwaysFalse)]*2

@staticmethod
def exp(expr, assumptions):
return False

@staticmethod
def Basic(expr, assumptions):
if expr.is_number:
if notnegative:
else:
return notnegative

"""
Handler for key 'zero'
Test that an expression is not identically zero
"""

@staticmethod
def Basic(expr, assumptions):
if expr.is_number:
# if there are no symbols just evalf
return expr.evalf() != 0

@staticmethod
if all(ask(Q.positive(x), assumptions) for x in expr.args) \
or all(ask(Q.negative(x), assumptions) for x in expr.args):
return True

@staticmethod
def Mul(expr, assumptions):
for arg in expr.args:
if result:
continue
return result
return True

@staticmethod
def Pow(expr, assumptions):

NaN = staticmethod(CommonHandler.AlwaysTrue)

@staticmethod
def Abs(expr, assumptions):

@staticmethod
def Basic(expr, assumptions):

@staticmethod
def Mul(expr, assumptions):
# TODO: This should be deducible from the nonzero handler
return fuzzy_or(ask(Q.zero(arg), assumptions) for arg in expr.args)

@staticmethod
def Basic(expr, assumptions):
if expr.is_number:
if notpositive:
else:
return notpositive

"""
Handler for key 'positive'
Test that an expression is greater (strict) than zero
"""

@staticmethod
def _number(expr, assumptions):
if not expr.as_real_imag()[1]:
return expr.evalf() > 0
else:
return False

@staticmethod
def Basic(expr, assumptions):
if expr.is_number:

@staticmethod
def Mul(expr, assumptions):
if expr.is_number:
result = True
for arg in expr.args:
continue
result = result ^ True
else:
return
return result

@staticmethod
if expr.is_number:
nonneg = 0
for arg in expr.args:
if ask(Q.positive(arg), assumptions) is not True:
nonneg += 1
else:
break
else:
if nonneg < len(expr.args):
return True

@staticmethod
def Pow(expr, assumptions):
if expr.is_number:
return expr.evalf() > 0
return True
return True
return False

@staticmethod
def exp(expr, assumptions):
return True

@staticmethod
def factorial(expr, assumptions):
x = expr.args[0]
return True

ImaginaryUnit = staticmethod(CommonHandler.AlwaysFalse)

@staticmethod
def Abs(expr, assumptions):

@staticmethod
def Trace(expr, assumptions):