# Difference between the infinite rewriting behavior of evaluation and ReplaceRepeated

In the documentation tutorial/Evaluation it's said that:

Every time the expression changes, the Wolfram Language effectively starts the evaluation sequence over again.

The general principle that the Wolfram Language follows in evaluating expressions is to go on applying transformation rules until the expressions no longer change.

A similar statement appears for ReplaceRepeated, too:

expr//.rules repeatedly performs replacements until expr no longer changes.

But there're differences:

1. For ReplaceRepeated, it's replaced just once:
ReplaceRepeated[h[], h@x___ -> (Print@1;h@x)]
(* h[] *)

2. For rewriting involving a Blank pattern, infinite evaluation occurs:
g[x_]:=g[x]
Block[{$IterationLimit = 20}, g[y] ] (* Message[$IterationLimit::itlim, 20] *)
(* Hold[g[y]] *)

3. For transformation rules without generic patterns such as Blank and Repeated, it's rewrited only once.
f[x]:=f[x]
Trace@f[x]
(* {f[x], f[x]} *)


What is the exact description of the condition for the termination of infinite rewriting?

• I think this got downvoted because it's a bit confusingly worded and people didn't understand. But you're asking (and I'm not necessarily going to word it better, lol) what the difference is between how ReplaceRepeated decides evaluation is finished and how Mathematica's evaluation procedure decides that evaluation is finished (when rewriting expressions via := definitions), right? Commented Nov 13, 2020 at 2:21
• Also, I think it might be more clear to separate your examples so that it's clear what you're contrasting with what, e.g. ReplaceRepeated, then a blank line, then the f example, then a blank line, then the g example. I think this is an interesting question and I hope people understand it! Commented Nov 13, 2020 at 2:28
• @thorimur Thank you for your advice and your understanding is right. I'd thought this statement is clear after evaluate the example given in the question. Maybe the non-canonical terminology "re-evaluation" is confusing. However, currently I'm not able to fetch reference.wolfram.com to cite the original description for improving this question further. Commented Nov 13, 2020 at 8:42
• This question is interesting. Please reformulate to make some people happy. Commented Nov 13, 2020 at 9:54
• Commented Nov 13, 2020 at 18:56