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

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

And in tutorial/EvaluationOfExpressions:

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:
    Block[{$IterationLimit = 20},
    (* 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]} *)

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

  • 1
    $\begingroup$ 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? $\endgroup$
    – thorimur
    Commented Nov 13, 2020 at 2:21
  • 1
    $\begingroup$ 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! $\endgroup$
    – thorimur
    Commented Nov 13, 2020 at 2:28
  • 1
    $\begingroup$ @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. $\endgroup$
    – asd1dsa
    Commented Nov 13, 2020 at 8:42
  • 1
    $\begingroup$ This question is interesting. Please reformulate to make some people happy. $\endgroup$ Commented Nov 13, 2020 at 9:54
  • 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.