Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Replace all occurrences of an algebraic subexpression with a new symbol
ResourceFunction["AlgebraicReplace"][expr,reps,repvars] rewrites expr, replacing each occurrence of an element of reps with the corresponding element of repvars. | |
ResourceFunction["AlgebraicReplace"][expr,reps,repvars,vars] rewrites expr, burrowing inside any subexpression that is not a polynomial in vars. |
Algebraically replace xy by a new variable z in a bivariate polynomial:
| In[1]:= |
| Out[1]= |
AlgebraicReplace works with non-polynomial expressions:
| In[2]:= | ![]() |
| Out[2]= |
Use several replacements at once:
| In[3]:= | ![]() |
| Out[3]= |
ReplaceAll only replaces literal matches:
| In[4]:= |
| Out[4]= |
AlgebraicReplace rewrites all monomials containing powers of xy to have powers of z:
| In[5]:= |
| Out[5]= |
AlgebraicReplace with a set of reducing polynomials polys and replacement variables vars has behavior similar to PolynomialReduce with polys-vars:
| In[6]:= | ![]() |
| Out[7]= |
This is not canonical insofar as the reduction is not done with a Gröbner basis, so results can depend on ordering of inputs:
| In[8]:= | ![]() |
| Out[8]= |
If we compute a Gröbner basis then the result is canonical for the given variable ordering:
| In[9]:= |
| Out[9]= |
Reversing the reduction polynomials does not change the result of PolynomialReduce when a Gröbner basis is used:
| In[10]:= |
| Out[10]= |
If the underlying variables are omitted, AlgebraicReplace might not recognize the correct ones:
| In[11]:= |
| Out[11]= |
Specify x and y as variables to get the desired replacement:
| In[12]:= |
| Out[12]= |
AlgebraicReplace will generally figure out the variables if they appear inside numeric functions:
| In[13]:= |
| Out[13]= |
If a function has the NumericFunction attribute then AlgebraicReplace can usually determine the variables to use:
| In[14]:= |
| Out[15]= |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License