def apply(self, z, evaluation): "%(name)s[z__]" args = z.get_sequence() if len(args) != self.nargs: return # if no arguments are inexact attempt to use sympy if len([True for x in args if Expression("InexactNumberQ", x).evaluate(evaluation).is_true()]) == 0: expr = Expression(self.get_name(), *args).to_sympy() result = from_sympy(expr) # evaluate leaves to convert e.g. Plus[2, I] -> Complex[2, 1] result = result.evaluate_leaves(evaluation) else: prec = min_prec(*args) with mpmath.workprec(prec): mpmath_args = [sympy2mpmath(x.to_sympy()) for x in args] if None in mpmath_args: return try: result = self.eval(*mpmath_args) result = from_sympy(mpmath2sympy(result, prec)) except ValueError, exc: text = str(exc) if text == "gamma function pole": return Symbol("ComplexInfinity") else: raise except ZeroDivisionError: return except SpecialValueError, exc: return Symbol(exc.name)
def apply(self, z, evaluation): '%(name)s[z__]' args = z.get_sequence() if len(args) != self.nargs: return # if no arguments are inexact attempt to use sympy if all(not x.is_inexact() for x in args): result = Expression(self.get_name(), *args).to_sympy() result = self.prepare_mathics(result) result = from_sympy(result) # evaluate leaves to convert e.g. Plus[2, I] -> Complex[2, 1] result = result.evaluate_leaves(evaluation) else: prec = min_prec(*args) with mpmath.workprec(prec): mpmath_args = [sympy2mpmath(x.to_sympy()) for x in args] if None in mpmath_args: return try: result = self.eval(*mpmath_args) result = from_sympy(mpmath2sympy(result, prec)) except ValueError, exc: text = str(exc) if text == 'gamma function pole': return Symbol('ComplexInfinity') else: raise except ZeroDivisionError: return except SpecialValueError, exc: return Symbol(exc.name)
def apply_N(self, k, precision, evaluation): 'N[AiryBiZero[k_Integer], precision_]' prec = get_precision(precision, evaluation) k_int = k.get_int_value() with mpmath.workprec(prec): result = mpmath2sympy(mpmath.airybizero(k_int), prec) return from_sympy(result)
def apply_inexact(self, z, evaluation): '%(name)s[z_Real|z_Complex?InexactNumberQ]' prec = z.get_precision() with mpmath.workprec(prec): z = sympy2mpmath(z.to_sympy()) if z is None: return try: result = self.eval(z) result = mpmath2sympy(result, prec) except ValueError, exc: text = str(exc) if text == 'gamma function pole': return Symbol('ComplexInfinity') else: raise except ZeroDivisionError: return