diff --git a/mathics/builtin/patterns.py b/mathics/builtin/patterns.py index 0adf129be7..c299cb0ac0 100644 --- a/mathics/builtin/patterns.py +++ b/mathics/builtin/patterns.py @@ -305,6 +305,11 @@ class ReplaceRepeated(BinaryOperator): >> a+b+c //. c->d = a + b + d + >> f = ReplaceRepeated[c->d]; + >> f[a+b+c] + = a + b + d + >> Clear[f]; + Simplification of logarithms: >> logrules = {Log[x_ * y_] :> Log[x] + Log[y], Log[x_ ^ y_] :> y * Log[x]}; >> Log[a * (b * c) ^ d ^ e * f] //. logrules @@ -324,7 +329,13 @@ class ReplaceRepeated(BinaryOperator): "rmix": "Elements of `1` are a mixture of lists and nonlists.", } - options = {"MaxIterations": "Infinity", "Heads": "False"} + options = { + "MaxIterations": "65535", + } + + rules = { + "ReplaceRepeated[rules_][expr_]" : "ReplaceRepeated[expr, rules]", + } def apply_list(self, expr, rules, evaluation, options): "ReplaceRepeated[expr_, rules_, OptionsPattern[ReplaceRepeated]]" @@ -337,7 +348,6 @@ def apply_list(self, expr, rules, evaluation, options): if ret: return rules - heads = self.get_option(options, "Heads", evaluation).is_true() maxit = self.get_option(options, "MaxIterations", evaluation) if maxit.is_numeric(): maxit = maxit.get_int_value() @@ -349,9 +359,7 @@ def apply_list(self, expr, rules, evaluation, options): if maxit == 0: break maxit -= 1 - result, applied = expr.apply_rules( - rules, evaluation, options={"levelspec": (0, None), "heads": heads,} - ) + result, applied = expr.apply_rules(rules, evaluation) if applied: result = result.evaluate(evaluation) if applied and not result.sameQ(expr):