Skip to content

Commit

Permalink
replace repeated fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Apr 12, 2021
1 parent a6c862b commit 39bf7d2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions mathics/builtin/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]]"
Expand All @@ -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()
Expand All @@ -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):
Expand Down

0 comments on commit 39bf7d2

Please sign in to comment.