TransWikia.com

Difference between the infinite rewriting behavior of evaluation and ReplaceRepeated

Mathematica Asked by asd1dsa on April 11, 2021

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:
    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?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP