示例#1
0
    def quick_pattern_test(self, candidate, test):
        if test == 'System`NumberQ':
            return isinstance(candidate, Number)
        elif test == 'System`Negative':
            if isinstance(candidate, (Integer, Rational, Real)):
                return candidate.value < 0
            return False
            # pass
        elif test == 'System`NegativePowerQ':
            return (candidate.has_form('Power', 2)
                    and isinstance(candidate.leaves[1],
                                   (Integer, Rational, Real))
                    and candidate.leaves[1].value < 0)
        elif test == 'System`NotNegativePowerQ':
            return not (candidate.has_form('Power', 2) and isinstance(
                candidate.leaves[1],
                (Integer, Rational, Real)) and candidate.leaves[1].value < 0)
        else:
            from mathics.builtin import builtins
            from mathics.builtin.base import Test

            builtin = builtins.get(test)
            if builtin is not None and isinstance(builtin, Test):
                return builtin.test(candidate)
        return None
示例#2
0
    def quick_pattern_test(self, candidate, test):
        if test == 'System`NumberQ':
            return isinstance(candidate, Number)
        elif test == 'System`Negative':
            if isinstance(candidate, (Integer, Rational, Real)):
                return candidate.value < 0
            return False
            # pass
        elif test == 'System`NegativePowerQ':
            return (
                candidate.has_form('Power', 2) and
                isinstance(candidate.leaves[1], (Integer, Rational, Real)) and
                candidate.leaves[1].value < 0)
        elif test == 'System`NotNegativePowerQ':
            return not (
                candidate.has_form('Power', 2) and
                isinstance(candidate.leaves[1], (Integer, Rational, Real)) and
                candidate.leaves[1].value < 0)
        else:
            from mathics.builtin import builtins
            from mathics.builtin.base import Test

            builtin = builtins.get(test)
            if builtin is not None and isinstance(builtin, Test):
                return builtin.test(candidate)
        return None
示例#3
0
    def apply(self, expr, evaluation):
        'Precedence[expr_]'

        from mathics.builtin import builtins

        name = expr.get_name()
        precedence = 1000
        if name:
            builtin = builtins.get(name)
            if builtin is not None and isinstance(builtin, Operator):
                precedence = builtin.precedence
            else:
                precedence = 670
        return Real(precedence)
示例#4
0
    def apply(self, expr, evaluation):
        'Precedence[expr_]'

        from mathics.builtin import builtins

        name = expr.get_name()
        precedence = 1000
        if name:
            builtin = builtins.get(name)
            if builtin is not None and isinstance(builtin, Operator):
                precedence = builtin.precedence
            else:
                precedence = 670
        return Real(precedence)