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

DiagrammaticComputation

Guides

  • DiagramConversion
  • DiagramDrawing
  • DiagramGrid
  • DiagramRewriting
  • Diagrams
  • DiagramSurgery
  • FeynmanDiagrams
  • Ports

Tech Notes

  • Diagram Examples
  • Introduction to Diagrammatic Computation
  • Rewriting Diagrams

Symbols

  • AnnihilationRule
  • CapDiagram
  • ColumnDiagram
  • CommutationRule
  • CopyDiagram
  • CupDiagram
  • DiagramArrange
  • DiagramAssignPorts
  • DiagramCases
  • DiagramComposition
  • DiagramCopySplit
  • DiagramDecompose
  • DiagramDelete
  • DiagramDraw
  • DiagramDual
  • DiagramExpressionReplace
  • DiagramExtract
  • DiagramFlip
  • DiagramFunction
  • DiagramGraphics
  • DiagramGraphSimplify
  • DiagramGridHeight
  • DiagramGrid
  • DiagramGridTree
  • DiagramGridWidthHeight
  • DiagramGridWidth
  • DiagramHypergraph
  • DiagramHypergraphRule
  • DiagramInsert
  • DiagramMapAt
  • DiagramMap
  • DiagramMatchPorts
  • Diagram
  • DiagramNestReplace
  • DiagramNetwork
  • DiagramPattern
  • DiagramPermute
  • DiagramPosition
  • DiagramPositions
  • DiagramProduct
  • DiagramQ
  • DiagramReplaceList
  • DiagramReplace
  • DiagramReplacePart
  • DiagramReverse
  • DiagramRightComposition
  • DiagramRule
  • DiagramsFreePorts
  • DiagramsGraph
  • DiagramsNetGraph
  • DiagramSplit
  • DiagramsPortGraph
  • DiagramSubdiagrams
  • DiagramSum
  • DiagramTensor
  • DuplicateAnnihilationRule
  • DuplicateEraserRule
  • EmptyDiagram
  • EmptyDiagramQ
  • EmptyPortQ
  • EraserAnnihilationRule
  • EraserDiagram
  • EraserRule
  • FeynArtsTopologyGraphics
  • FeynmanDiagram
  • GridInputPorts
  • GridOutputPorts
  • IdentityDiagram
  • MergeDiagram
  • PermutationDiagram
  • PortDual
  • PortMinus
  • Port
  • PortNeutral
  • PortPower
  • PortProduct
  • PortQ
  • PortSum
  • PropagationRule
  • RemoveDiagramRule
  • RowDiagram
  • SimplifyDiagram
  • SingletonDiagram
  • SpiderDiagram
  • TagPort
  • TensorDiagram
  • ToDiagram
  • ToDiagramNetwork
  • TopologyGraphics
  • TopologyGraph
  • TopologyGraphs
  • UntagPort
  • WigglyArcFunction
  • ZeroDiagram
  • ZeroPortQ
Rewriting Diagrams
Diagram rewriting replaces a piece of a diagram matching a pattern with another piece, reconnecting the wires. Matching happens on the diagram's hypergraph structure, so rules are insensitive to layout and port naming — formal pattern symbols in port positions bind to whatever wiring the match finds. This tech note builds rewrite rules for algebraic laws and applies them with
DiagramReplaceList
and
DiagramReplace
.
In[1]:=
<<Wolfram`DiagrammaticComputation`
Structural Rules
A rewrite rule is a
Rule
between two diagrams whose ports carry patterns. Associativity of a binary operation
f
rewires the parenthesisation of a double application:
In[2]:=
associativity=
DiagramComposition

Diagram
[f_,{p_,p3_},p4_],
Diagram
[f_,{p1_,p2_},p_]​​
DiagramComposition

Diagram
[f,{p1,p},p4],
Diagram
[f,{p2,p3},p]
Out[2]=

Coassociativity is the mirror law for a binary cooperation:
In[3]:=
coassociativity=
DiagramComposition

Diagram
[f_,p_,{p2_,p3_}],
Diagram
[f_,p1_,{p_,p4_}]​​
DiagramComposition

Diagram
[f,p,{p3,p4}],
Diagram
[f,p1,{p2,p}]
Out[3]=

Applying Rules
A tree of binary operations
A
and cooperations
B
to rewrite:
In[4]:=
diag=
Diagram

DiagramRightComposition
​​
DiagramProduct

Diagram
[C,p],
DiagramComposition

Diagram
[B,p,{p,p}],
Diagram
[B,p,{p,p}],​​
DiagramComposition

Diagram
[A,{p,p},p],
DiagramProduct

Diagram
[A,{p,p},p],
IdentityDiagram
[p],​​
Diagram
[D,p,p]
Out[4]=
DiagramReplaceList
enumerates every possible single application of the rule:
In[5]:=
DiagramReplaceList
[diag,associativity]
Out[5]=


Several rules can be tried at once:
In[6]:=
DiagramReplaceList
[diag,{associativity,coassociativity}]
Out[6]=

,

DiagramReplace
applies the first match only:
In[7]:=
DiagramReplace
[diag,associativity]
Out[7]=
And
DiagramNestReplace
iterates rules a given number of times:
In[8]:=
DiagramNestReplace
[diag,{associativity,coassociativity},2]
Out[8]=
Interaction-Net Rules
The paclet provides constructors for the standard interaction-net rule schemas. Two facing copy nodes annihilate into parallel wires:
A node commutes past a copy node, duplicating itself:
An eraser propagates through a process, erasing it port by port:
Erasing one branch of a copy leaves a plain wire:
These rules drive lambda-calculus evaluation as interaction nets: beta reduction is an annihilation between a lambda node and an application node, and copy/erase rules implement sharing and garbage collection.
Inspecting the Matcher

© 2026 Wolfram. All rights reserved.

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