Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Rewrite an expression, replacing repeatedly by strings
ResourceFunction["RecursiveRewrite"][expr] rewrites expr, replacing repeatedly by strings. |
Choose an expression:
In[1]:= |
![]() |
Get a list of replacements to rewrite the expression:
In[2]:= |
![]() |
Out[2]= |
![]() |
In[3]:= |
![]() |
Out[3]= |
![]() |
Recover the original expression, applying replacements only six times, starting with the final string:
In[4]:= |
![]() |
Out[4]= |
![]() |
To see the values of subexpressions, you can use the function FromRecursiveRewrite instead:
In[5]:= |
![]() |
Out[5]= |
![]() |
RecursiveRewrite prevents evaluation as it rewrites:
In[6]:= |
![]() |
Out[6]= |
![]() |
In[7]:= |
![]() |
Out[7]= |
![]() |
Start with an expression:
In[8]:= |
![]() |
Rewrite a subexpression using the symbol "R":
In[9]:= |
![]() |
Out[9]= |
![]() |
Recover the subexpression:
In[10]:= |
![]() |
Out[10]= |
![]() |
Rewrite the expression inside the square root for only six steps and write the strings as subscripts:
In[11]:= |
![]() |
Out[11]= |
![]() |
Avoid using strings identical to rewrite symbols:
In[12]:= |
![]() |
Out[12]= |
![]() |
In[13]:= |
![]() |
Out[13]= |
![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License