Esempio n. 1
0
    def apply_check(self, x, y, evaluation):
        'Power[x_, y_]'

        # Power uses _MPMathFunction but does some error checking first
        if isinstance(x, Number) and x.is_zero:
            if isinstance(y, Number):
                y_err = y
            else:
                y_err = Expression('N', y).evaluate(evaluation)
            if isinstance(y_err, Number):
                py_y = y_err.round_to_float(permit_complex=True).real
                if py_y > 0:
                    return x
                elif py_y == 0.0:
                    evaluation.message('Power', 'indet',
                                       Expression('Power', x, y_err))
                    return Symbol('Indeterminate')
                elif py_y < 0:
                    evaluation.message('Power', 'infy',
                                       Expression('Power', x, y_err))
                    return Symbol('ComplexInfinity')

        result = self.apply(Expression('Sequence', x, y), evaluation)
        if result is None or result != Symbol('Null'):
            return result
Esempio n. 2
0
    def apply_check(self, x, y, evaluation):
        "Power[x_, y_]"

        # Power uses _MPMathFunction but does some error checking first
        if isinstance(x, Number) and x.is_zero:
            if isinstance(y, Number):
                y_err = y
            else:
                y_err = Expression(SymbolN, y).evaluate(evaluation)
            if isinstance(y_err, Number):
                py_y = y_err.round_to_float(permit_complex=True).real
                if py_y > 0:
                    return x
                elif py_y == 0.0:
                    evaluation.message("Power", "indet",
                                       Expression("Power", x, y_err))
                    return Symbol("Indeterminate")
                elif py_y < 0:
                    evaluation.message("Power", "infy",
                                       Expression("Power", x, y_err))
                    return Symbol("ComplexInfinity")
        if isinstance(x, Complex) and x.real.is_zero:
            yhalf = Expression("Times", y, Rational(1, 2))
            factor = self.apply(Expression("Sequence", x.imag, y), evaluation)
            return Expression("Times", factor,
                              Expression("Power", Integer(-1), yhalf))

        result = self.apply(Expression(SymbolSequence, x, y), evaluation)
        if result is None or result != SymbolNull:
            return result
Esempio n. 3
0
    def apply_check(self, x, y, evaluation):
        'Power[x_, y_]'

        # Power uses _MPMathFunction but does some error checking first
        if isinstance(x, Number) and x.is_zero:
            if isinstance(y, Number):
                y_err = y
            else:
                y_err = Expression('N', y).evaluate(evaluation)
            if isinstance(y_err, Number):
                py_y = y_err.round_to_float(permit_complex=True).real
                if py_y > 0:
                    return x
                elif py_y == 0.0:
                    evaluation.message('Power', 'indet', Expression('Power', x, y_err))
                    return Symbol('Indeterminate')
                elif py_y < 0:
                    evaluation.message('Power', 'infy', Expression('Power', x, y_err))
                    return Symbol('ComplexInfinity')

        result = self.apply(Expression('Sequence', x, y), evaluation)
        if result is None or result != Symbol('Null'):
            return result