Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Unify expressions containing pattern variables
ResourceFunction["MostGeneralUnifier"][t1,t2,…] returns an association representing a most general unifier of terms t1,t2,…. |
Find the most general unifier for terms:
In[1]:= | ![]() |
Out[1]= | ![]() |
In[2]:= | ![]() |
Out[2]= | ![]() |
Unifying already equal terms returns an empty unifier:
In[3]:= | ![]() |
Out[3]= | ![]() |
Trying to unify non-unifiable terms returns a Failure:
In[4]:= | ![]() |
Out[4]= | ![]() |
Only a single unifier is found, but in general it's not unique (e.g. <|y_⧴x_|>is also valid here):
In[5]:= | ![]() |
Out[5]= | ![]() |
MostGeneralUnifier holds its arguments:
In[6]:= | ![]() |
Out[6]= | ![]() |
Unify heads:
In[7]:= | ![]() |
Out[7]= | ![]() |
Given multiple expressions, unifier makes them equal by substitution using ReplaceAll:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
Different pattern variables with the same name are still considered distinct:
In[10]:= | ![]() |
Out[10]= | ![]() |
In[11]:= | ![]() |
Out[11]= | ![]() |
PatternTest and Condition are treated verbatim:
In[12]:= | ![]() |
Out[12]= | ![]() |
In[13]:= | ![]() |
Out[13]= | ![]() |
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License