How to | Use a Rule with an Expression More Than Once

You may find it useful to use one or more rules with an expression several times. The Wolfram Language provides functions that let you iterate when using rules with expressions. In cases where a rule can be used in several ways with an expression, the Wolfram Language also allows you to view all possible results.

While (the short form for ReplaceAll) applies rules to an expression only once, you may find it useful to repeatedly apply rules to an expression until it no longer changes. You can do this by using (the short form for ReplaceRepeated).

Use to apply a rule or list of rules to each part of an expression only once:

In[1]:=
Click for copyable input
Out[1]=

Use to apply the rules repeatedly until the expression no longer changes:

In[2]:=
Click for copyable input
Out[2]=

Similarly:

In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=

You should use caution when using with a circular set of rules. Use the MaxIterations option to set the maximum number of iterations for :

In[5]:=
Click for copyable input
Out[5]=

You can use ReplaceList to transform an entire expression by applying a rule or list of rules in all possible ways. Use Column to display the results for easier viewing:

In[6]:=
Click for copyable input
Out[6]=