# Source code for sympy.assumptions.handlers.ntheory

"""
Handlers for keys related to number theory: prime, even, odd, etc.
"""
from sympy.assumptions.handlers import CommonHandler
from sympy.ntheory import isprime

"""
Handler for key 'prime'
Test that an expression represents a prime number. When the
expression is a number the result, when True, is subject to
the limitations of isprime() which is used to return the result.
"""

@staticmethod
def _number(expr, assumptions):
# helper method
try:
i = int(expr.round())
if not (expr - i).equals(0):
raise TypeError
except TypeError:
return False
return isprime(i)

@staticmethod
def Basic(expr, assumptions):
# Just use int(expr) once
# is solved
if expr.is_number:

@staticmethod
def Mul(expr, assumptions):
if expr.is_number:
for arg in expr.args:
pass
else: break
else:
# a product of integers can't be a prime
return False

@staticmethod
[docs]    def Pow(expr, assumptions):
"""
Integer**Integer     -> !Prime
"""
if expr.is_number:
return False

@staticmethod
def Integer(expr, assumptions):
return isprime(expr)

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

@staticmethod
def Float(expr, assumptions):

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

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

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

@staticmethod
def NumberSymbol(expr, assumptions):

@staticmethod
def Basic(expr, assumptions):
if _positive:
if _integer:
if _prime is None: return
return not _prime
else: return _integer
else: return _positive

@staticmethod
def _number(expr, assumptions):
# helper method
try:
i = int(expr.round())
if not (expr - i).equals(0):
raise TypeError
except TypeError:
return False
return i % 2 == 0

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

@staticmethod
def Mul(expr, assumptions):
"""
Even * Integer -> Even
Even * Odd     -> Even
Integer * Odd  -> ?
Odd * Odd      -> Odd
"""
if expr.is_number:
even, odd, irrational = False, 0, False
for arg in expr.args:
# check for all integers and at least one even
even = True
odd += 1
# one irrational makes the result False
# two makes it undefined
if irrational:
break
irrational = True
else: break
else:
if irrational: return False
if even: return True
if odd == len(expr.args): return False

@staticmethod
"""
Even + Odd  -> Odd
Even + Even -> Even
Odd  + Odd  -> Even

"""
if expr.is_number:
_result = True
for arg in expr.args:
pass
_result = not _result
else: break
else:
return _result

@staticmethod
def Integer(expr, assumptions):
return not bool(expr.p & 1)

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

@staticmethod
def Float(expr, assumptions):
return expr % 2 == 0

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

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

@staticmethod
def NumberSymbol(expr, assumptions):

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

@staticmethod
def Abs(expr, assumptions):

@staticmethod
def re(expr, assumptions):

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

"""
Handler for key 'odd'
Test that an expression represents an odd number
"""

@staticmethod
def Basic(expr, assumptions):