Wolfram Language Paclet Repository
Community-contributed installable additions to the Wolfram Language
Utilities for testing code equivalence
Contributed By: Richard Hennigan
CodeEquivalenceUtilities is a collection of Wolfram Language functions that can be used to test if different pieces of code are equivalent without the need for evaluation.
This allows comparison of unevaluated expressions that may have non-deterministic outputs (e.g. random values, dates, etc).
This Paclet represents the underlying technology that powers several automated code grading systems, such as the online exercises for EIWL and Wolfram Challenges.
To install this paclet in your Wolfram Language environment,
evaluate this code:
PacletInstall["Wolfram/CodeEquivalenceUtilities"]
Check if two expressions are equivalent:
In[1]:= |
Out[1]= |
View the canonical representations of expressions:
In[2]:= |
Out[2]= |
In[3]:= |
Out[3]= |
These are directly comparable:
In[4]:= |
Out[4]= |
Get additional information about the equivalence test:
In[5]:= |
Out[5]= |
View the sequence of transformations used to convert an expression to its canonical form:
In[6]:= |
Out[6]= |
Convert a canonical representation to a normal expression:
In[7]:= |
Out[7]= |
In[8]:= |
Out[8]= |
Evaluate:
In[9]:= |
Out[9]= |
Here is a list of expressions, some of which are equivalent to others:
In[10]:= |
Find the sequence of transformations for each expression:
In[11]:= |
Out[11]= |
Generate a graph for each sequence:
In[12]:= |
Out[12]= |
Combine the graphs:
In[13]:= |
Equivalent expressions converge to the same connected component:
In[14]:= |
Out[14]= |
Group the expressions into their corresponding equivalence class:
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |