Skip to content

Commit

Permalink
fixing levelspec
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Apr 12, 2021
1 parent ca87528 commit a6c862b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions mathics/builtin/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,20 +524,21 @@ class FixedPoint(Builtin):
= 0.739085
"""

options = {'MaxIterations': 'Infinity',
"SameTest": "Automatic",
}
options = {
"MaxIterations": "Infinity",
"SameTest": "Automatic",
}

def apply(self, f, expr, n, evaluation, options):
"FixedPoint[f_, expr_, n_:DirectedInfinity[1], OptionsPattern[FixedPoint]]"
"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():
Expand All @@ -550,7 +551,7 @@ def apply(self, f, expr, n, evaluation, options):
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)
Expand Down
11 changes: 6 additions & 5 deletions mathics/builtin/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,8 @@ class ReplaceRepeated(BinaryOperator):
"rmix": "Elements of `1` are a mixture of lists and nonlists.",
}

options = {'MaxIterations': 'Infinity',
"Heads": "False"}

options = {"MaxIterations": "Infinity", "Heads": "False"}

def apply_list(self, expr, rules, evaluation, options):
"ReplaceRepeated[expr_, rules_, OptionsPattern[ReplaceRepeated]]"
try:
Expand All @@ -344,13 +343,15 @@ def apply_list(self, expr, rules, evaluation, options):
maxit = maxit.get_int_value()
else:
maxit = -1

while True:
evaluation.check_stopped()
if maxit == 0:
break
maxit -= 1
result, applied = expr.apply_rules(rules, evaluation, options={"heads": heads,})
result, applied = expr.apply_rules(
rules, evaluation, options={"levelspec": (0, None), "heads": heads,}
)
if applied:
result = result.evaluate(evaluation)
if applied and not result.sameQ(expr):
Expand Down

0 comments on commit a6c862b

Please sign in to comment.