Skip to content

ReplaceRepeated and FixedPoint have no MaxIterations option #1260

Description

@vsht

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions