Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReplaceRepeated and FixedPoint have no MaxIterations option #1260

Closed
vsht opened this issue Apr 11, 2021 · 0 comments · Fixed by #1269
Closed

ReplaceRepeated and FixedPoint have no MaxIterations option #1260

vsht opened this issue Apr 11, 2021 · 0 comments · Fixed by #1269

Comments

@vsht
Copy link

vsht commented Apr 11, 2021

MaxIterations allows to limit the number of applications of a rule/pattern to the given expression.
This helps to prevent unwanted infinite recursions, e.g.

In[1]:= ReplaceRepeated[f[x], f[x_] :> f[f[x]], MaxIterations -> 4]                                                                                         

ReplaceRepeated::rrlim: Exiting after f[x_] scanned 4 times.

Out[1]= f[f[f[f[f[x]]]]]

In FixedPoint the number of maximal iterations is not an option but an optional parameter

In[3]:= FixedPoint[(# /. f[x_] :> f[f[x]]) &, f[x], 4]                                                                                                       

Out[3]= f[f[f[f[f[x]]]]]

Both currently don't work with mathics

In[1]:= ReplaceRepeated[f[x], f[x_] :> f[f[x]], MaxIterations -> 4] 
Out[1]= ReplaceRepeated[f[x], f[x_] :> f[f[x]], MaxIterations -> 4]

In[2]:= FixedPoint[(# /. f[x_] :> f[f[x]]) &, f[x], 4]
Syntax::sntxf: "FixedPoint[(" cannot be followed by " /. f[x_] :> f[f[x]]) &, f[x], 4]" (line 1 of "<stdin>").
In[2]:= 

This is relevant for #1174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant