Wolfram Language Paclet Repository
Community-contributed installable additions to the Wolfram Language
A virtual machine for the Wolfram Language pattern matcher
Contributed by: Daniel Sanchez
A register-based virtual machine that compiles Wolfram Language patterns into bytecode for efficient execution. Instead of interpreting patterns each time, this system compiles them once and executes the bytecode repeatedly, enabling performance optimization and detailed execution analysis. The VM maintains complete semantic equivalence with native MatchQ while providing comprehensive metrics, instruction-level debugging, and observable backtracking behavior for research and optimization.
To install this paclet in your Wolfram Language environment,
evaluate this code:
PacletInstall["DanielS/PatternMatcher"]
To load the code after installation, evaluate this code:
Needs["DanielS`PatternMatcher`"]
Convert a pattern into bytecode object:
| In[1]:= |
| Out[1]= | ![]() |
Get a textual representation of the generated bycode:
| In[2]:= |
| Out[2]= | ![]() |
Create a virtual machine loaded with the compiled pattern:
| In[3]:= |
| Out[3]= | ![]() |
Enable the tracing of pattern matcher execution:
| In[4]:= |
| Out[4]= |
Use the virtual machine to test whether an expression matches the pattern):
| In[5]:= |
| Out[5]= |
Get the resulting pattern matching bindings:
| In[6]:= |
| Out[6]= |
Reset the virtual machine to use it again:
| In[7]:= |
| Out[7]= | ![]() |
Alternatively, a pattern can be used directly to match an expression:
| In[8]:= |
| Out[8]= |
Convert a pattern into a function:
| In[9]:= |
| Out[9]= | ![]() |
The function can be used to match expressions:
| In[10]:= |
| Out[10]= |
The function behaves the same as a call to MatchQ:
| In[11]:= |
| Out[11]= |
Wolfram Language Version 14.4