Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

PatternMatcher

Guides

  • A Virtual Machine for the Pattern Matcher

Symbols

  • CompilePatternToBytecode
  • CreatePatternMatcherVirtualMachine
  • PatternBytecodeDisassemble
  • PatternBytecodeInformation
  • PatternBytecode
  • PatternBytecodeQ
  • PatternMatcherEnableTrace
  • PatternMatcherExecute
  • PatternMatcherMatch
  • PatternMatcherMatchQ
  • PatternMatcherReplace
  • PatternMatcherStep
  • PatternMatcherTraceEnabled
  • PatternMatcherTraceEnabledQ
  • PatternMatcherVirtualMachine
  • PatternToMatchFunction
DanielS`PatternMatcher`
CompilePatternToBytecode
​
CompilePatternToBytecode
[patt]
converts a pattern expression into bytecode to be run in a virtual machine.
​
Details and Options
Examples  
(6)
Basic Examples  
(1)
Compile a pattern with a repeated variable:
In[1]:=
bytecode=
CompilePatternToBytecode
[f[x_,x_]]
Out[1]=
PatternBytecode
Pattern:
f[x_,x_]
Expr registers count: 5
Bool registers count: 2
Instruction count: 30

Inspect the generated bytecode in a human-readable form:
In[2]:=
PatternBytecodeDisassemble
[bytecode]
Out[2]=
L0:​
0 BEGIN_BLOCK Label[0]​
​L3:​
1 BEGIN_BLOCK Label[3]​
2 MATCH_LENGTH %e0​, 2, Label[4]​
3 MATCH_HEAD %e0​, Expr[List]​, Label[4]​
4 MOVE %e1​, %e0​
5 GET_PART %e2​, %e0​, 1
6 MOVE %e0​, %e2​
7 MATCH_HEAD %e0​, Expr[Integer]​, Label[5]​
8 MOVE %e3​, %e0​
9 BIND_VAR Symbol[Global`x]​, %e3​
10 JUMP Label[6] → L6
​L5:​
11 JUMP Label[4] → L4
​L6:​
12 MOVE %e0​, %e1​
13 GET_PART %e4​, %e0​, 2
14 MOVE %e0​, %e4​
15 MATCH_HEAD %e0​, Expr[Real]​, Label[7]​
16 MOVE %e5​, %e0​
17 BIND_VAR Symbol[Global`y]​, %e5​
18 JUMP Label[8] → L8
​L7:​
19 JUMP Label[4] → L4
​L8:​
20 MOVE %e0​, %e1​
21 END_BLOCK Label[3]​
22 JUMP Label[2] → L2
​L4:​
23 JUMP Label[1] → L1
​L9:​
24 END_BLOCK Label[0]​
​L1:​
25 LOAD_IMM %b0​, 0
26 HALT
​L2:​
27 EXPORT_BINDINGS
28 LOAD_IMM %b0​, 1
29 HALT
​
​========================================​
​Statistics:​
Instructions: 30
Labels: 10
Expr registers: 6
Bool registers: 1
Blocks: 2 (max depth: 2)​
Jumps: 6
Backtrack points: 0
​
​Lexical bindings:​
Global`x → %e3​
Global`y → %e5​
Test whether expressions match the compiled pattern:
In[3]:=
PatternMatcherMatchQ
[bytecode][f[5,5]]
Out[3]=
True
In[4]:=
PatternMatcherMatchQ
[bytecode][f[5,6]]
Out[4]=
False
Get detailed execution results including variable bindings:
In[5]:=
PatternMatcherExecute
[bytecode,f[5,5]]
Out[5]=
ResultTrue,CyclesExecuted22,BindingsGlobal`x5
In[6]:=
PatternMatcherExecute
[bytecode,f[5,6]]
Out[6]=
ResultFalse,CyclesExecuted19,Bindings
Scope  
(1)

Properties & Relations  
(4)

SeeAlso
PatternBytecode
 
▪
PatternMatcherVirtualMachine
 
▪
PatternMatcherExecute
 
▪
PatternMatcherMatchQ
 
▪
PatternMatcherReplace
 
▪
PatternBytecodeDisassemble
 
▪
PatternBytecodeInformation
RelatedGuides
▪
A Virtual Machine for the Pattern Matcher
""

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com