Skip to content

ReplaceRepeated

expr //. rule replaces all occurences of the LHS of rule with the RHS of rule in expr repeatedly until the expression stabilizes.

expr //. {r1, r2, ...} performes the same operation as expr //. rule, but evaluating each r_n in sequence.

Attributes[ReplaceRepeated] := {Protected}

Simple examples

ReplaceRepeated can be used to implement logarithm expansion:

In[1]:= logRules := {Log[x_*y_] :> (Log[x] + Log[y]), Log[x_^k_] :> (k*Log[x])}
Out[1]= Null
In[2]:= (Log[a^b*b^(c^d)]) //. (logRules)
Out[2]= b*Log[a] + c^d*Log[b]