Beispiel #1
0
 def compare(e1, e2):
     result = Expression(p, e1, e2).evaluate(evaluation)
     if result.is_true():
         result = Expression(p, e2, e1).evaluate(evaluation)
         if result.is_true():
             return 0
         else:
             return -1
     else:
         return 1
Beispiel #2
0
 def compare(e1, e2):
     result = Expression(p, e1, e2).evaluate(evaluation)
     if result.is_true():
         result = Expression(p, e2, e1).evaluate(evaluation)
         if result.is_true():
             return 0
         else:
             return -1
     else:
         return 1
Beispiel #3
0
 def apply_generic(self, expr, cond, evaluation):
     "ConditionalExpression[expr_, cond_]"
     # What we need here is a way to evaluate
     # cond as a predicate, using assumptions.
     # Let's delegate this to the And (and Or) symbols...
     if not cond.is_atom() and cond._head == SymbolList:
         cond = Expression("System`And", *(cond._leaves))
     else:
         cond = Expression("System`And", cond)
     if cond is None:
         return
     if cond.is_true():
         return expr
     if cond == SymbolFalse:
         return SymbolUndefined
     return
Beispiel #4
0
    def apply(self, f, expr, n, evaluation, options):
        "FixedPoint[f_, expr_, n_:DirectedInfinity[1], OptionsPattern[FixedPoint]]"
        if n == Expression("DirectedInfinity", 1):
            count = None
        else:
            count = n.get_int_value()
            if count is None or count < 0:
                evaluation.message("FixedPoint", "intnn")
                return

        if count is None:
            count = self.get_option(options, "MaxIterations", evaluation)
            if count.is_numeric():
                count = count.get_int_value()
            else:
                count = None

        result = expr
        index = 0
        sametest = self.get_option(options, "SameTest", evaluation)
        if sametest == Symbol("Automatic"):
            sametest = None

        while count is None or index < count:
            evaluation.check_stopped()
            new_result = Expression(f, result).evaluate(evaluation)
            if sametest:
                same = Expression(sametest, result,
                                  new_result).evaluate(evaluation)
                same = same.is_true()
                if same:
                    break
            else:
                if new_result == result:
                    result = new_result
                    break
            result = new_result
            index += 1

        return result