Preface
Petri nets were invented in 1962. They predate Unix, the internet, and object-oriented programming. For most of their history, they lived in academic papers — a formalism known to theorists but invisible to working programmers.
This book argues they deserve wider use, and it makes one claim about why. A system built from parts has to be written down in some notation for composition, and several are in use: cospans of sets, string diagrams, ZX-style spiders, operad wiring diagrams, incidence matrices. Each was designed for its own community, and each has its own rules for what “plug these two together” means. The open Petri net — places, transitions, arcs, and a boundary of places left open for gluing — has a presentation in every one of them, and the claim is that each presentation is faithful and that gluing two open nets along a shared place gives the same net in all of them. What is checked by machine is narrower than the claim, and the next paragraph says exactly what it is. We call that claim being a canonical carrier for compositional systems: one structure, many faithful presentations, and one meaning of composition across all of them.
The evidence is public, in pflow-native’s composition views. They draw two compositions ten ways — as a cospan, as spiders, as an operad wiring diagram, as a string diagram, as the flat net, as a net with boundaries, as lenses, as incidence matrices, as runs (processes) and as composition laws — and the two are a model bundle, orders, which links a queue, a resource pool and a payment saga, and a search plan, connect4, which assembles a Connect-4 solver from pieces. A reference tool checks each part. go-pflow checks the bundle: its verdicts on all 5,576 possible links between the ports of six subnets, on eleven flatten cases (one refused, four glued along shared places) and on four scenario runs are recorded in a receipt, and pflow-native, which composes with pflow-rs, matches every one. pflow-rs checks the plans: its verdicts on 289 plans are a second receipt, made before pflow-rs changed some of them on purpose, so the test names each difference and asserts its count: of the 289 plans, 197 get the same verdict and 92 differ, 89 because pflow-rs changed on purpose (seven kinds of change, each counted) and 3 only in the wording of a refusal of a malformed plan, which comes from how pflow-native builds pflow-rs. The receipt holds parse, check and solver-construction verdicts; the solver’s printed values and node counts are not compared, and this is pflow-rs against its own earlier verdicts, not a second implementation. Chyp checks what follows from the composition laws — event links as synchronising spiders, and how plan pieces chain, meet and wrap: given the laws as rules, it checks each rewrite, while the laws themselves are stated, not checked against go-pflow or pflow-rs. Upstream Chyp computed its verdicts on four theories, 33 rewrites, of which the 30 meant to hold are valid and the three negative controls are rejected; pflow-native draws them and does not re-check them. Each view records what it draws as a scene manifest, and the goldens hold 100 of them, ten views of two compositions in five states: pflow-native’s test redraws each one headless and requires it to equal its golden, pflow.xyz’s browser views are held to the same file, and screenshots show all ten views of both compositions (the Boundaries view has nothing to draw for the search plan). What none of this checks is that each notation, composing by its own rules, reaches the same net. Every view but Laws, which draws Chyp’s precomputed exports, draws the one composite pflow-native computes (the flat net, or the plan’s net), so the views agree by construction, and the cross-check is between two implementations of the gluing, go-pflow’s and pflow-rs’s. Faithfulness, that a presentation loses nothing, is not tested here either. The views’ Chyp theories are also not the ones in chyp-rs (below). chyp-rs states its own laws on the same four subjects, and upstream Chyp agrees with it on every step of those, but it has not been run on the views’ theories: their source files are not published, only Chyp’s exports of them, and three of the four use typed wires, which chyp-rs leaves out. Chapter 20 applies the same discipline to runtimes.
A model written this way is also a value, not a program. It is a document: it can be hashed, diffed, composed with another model by sharing a place, and checked by a machine that has never seen any of our code. That is what lets one document be a state machine that handles concurrency, a workflow engine with formal guarantees, a simulation model that converts to differential equations, and a specification from which a running application, a kernel-checked theorem and a zero-knowledge proof are derived rather than written.
We call the practice built on it Metamodel. The plain definition is the literal one: a model for making models. Its vocabulary is place, transition, arc and guard, with local rules for how two models fit together, and it is not a model of any particular thing — not a coffee shop, not a token. The pflow ecosystem is where it is tested. You draw a net in a browser editor, simulate it and generate an application, all from the same JSON-LD model, and pflow-polyglot holds twenty implementations of one model in four languages to one golden trace (Chapter 20). The domains the same vocabulary has already been tiled across — a coffee shop, a token standard, a poker game, a drum machine, and the infrastructure that serves this book — are the evidence that it travels.
What This Book Claims, and What It Does Not
The title says universal, and the word needs fencing before Chapter 1 uses the formalism for anything. The claim is about composition: among notations for systems built from parts, the open Petri net is one structure that all of them can carry without loss. It is not a claim about computation, and not a claim about every kind of system.
The scope is systems built from parts — components with state, events that change it, and resources or conditions that two components can share. A queue, a protocol, a recipe, a game, a ledger and a chemical reaction network all fit. A system whose meaning sits in a continuous field, in a learned weight matrix or in unstructured text does not become a Petri net by being drawn as one, and the book makes no claim about those.
Several limits are worth naming now, because later chapters lean on them.
Ordinary place/transition nets are not Turing-complete. Their reachability problem is decidable (Mayr 1981; Kosaraju 1982), which is a real strength: “can this workflow finish?” has an algorithm. The algorithm is impractical in the worst case, though. Reachability is Ackermann-complete (upper bound Leroux and Schmitz 2019; lower bound Czerwiński and Orlikowski 2021, and independently Leroux 2021), and even coverability is EXPSPACE-complete (Lipton 1976; Rackoff 1978). The tools in this book explore bounded nets of modest size and stop at a configurable state limit (Chapter 1), which is an engineering bound, not a decision procedure for every net.
Extensions buy expressiveness and spend the guarantees. An inhibitor arc tests a place for zero, and inhibitor arcs on just two places are enough to simulate a two-counter machine (Minsky 1967), so nets with inhibitor arcs are Turing-complete and their reachability is undecidable (Chapter 4). A guard over typed data, such as balances[from] >= amount, is a predicate the incidence matrix cannot see. Both kinds of contextual test also leave the free symmetric monoidal category that makes composition well behaved (Appendix E). The canonical-carrier claim covers place, transition and arc. The guard is the fourth term of the token language and the one that steps outside the claim; a model that uses one is checked by exploring states, not read off the structure.
Faithful means faithful to a pair of matrices, not to their difference. The incidence matrix of Chapter 2 records net change, so a self-loop cancels to zero and two different nets can share a . The presentation that carries a net without loss is the pair of input and output matrices together with the boundary. Gluing along a shared place is the composition the presentations are meant to agree on. Fusing two transitions into a rendezvous, Chapter 4’s EventLink, is a second kind of composition, and it has a string-diagram presentation of its own: the link is a synchronising spider on the transitions’ event ports, a special commutative Frobenius algebra. chyp-rs, a Rust port of Chyp’s checker, takes the Frobenius, commutativity and speciality rules as given and checks that the laws which make that presentation well behaved follow from them — two connected sync points fuse into one, their legs are unordered, and fusing three transitions gives the same sync point whichever pair is fused first (laws/sync_spiders.chyp). A rendezvous still refines rather than extends, so the safety-not-liveness caveat below applies to it as well.
Composition preserves safety and not liveness, and safety only for one kind of composition. Fusing transitions can only restrict what each component can do, so a property of the form “no reachable marking looks like this” survives; go-pflow checks this on one bundle, which is a test, not a proof for every bundle. Gluing along a shared place is weaker, because the other side can add tokens to that place or take them away: a component’s conservation law survives when the other side has an invariant that agrees with it on the shared places — the case the Lean theorem invariant_lift proves (proofs/PflowProofs/InvariantLift.lean) — and not otherwise. “This transition can always fire again” survives neither: Appendix E glues one netting transition onto a settlement cycle whose every transition is live, and the composite reaches a dead marking in four firings.
None of this is new mathematics. The free-category theorem is Meseguer and Montanari’s and Sassone’s, open nets as cospans are Baez and Master’s, and the decidability results are decades old; Appendix E lists the references. What this book adds is a working ecosystem in which the same document passes through each of these readings, and the implementations are made to agree by machine.
Who This Book Is For
You know how to program but haven’t encountered Petri nets before — or you’ve seen the formalism and wondered what it’s good for in practice.
The examples are in Go and JavaScript. The mathematics uses standard notation — vectors, matrices, differential equations. Where a result comes from code, the chapter links the code or model that produces it, so you can run it yourself.
How to Read This Book
There are two paths through the material:
- Theory track: Read Parts I and III for the mathematical foundations and advanced topics — formal definitions, incidence matrices, ODE solvers, invariants, and the categorical reasons composition works.
- Hands-on track: Skim Part I for vocabulary, then go to Part II’s worked examples (coffee shops, games, biochemistry) and Part IV’s tooling guides.
Part I: Foundations
Chapters 1-4 introduce the formalism. Places, transitions, arcs — structure — and tokens, the state that moves through it. Then firing rules, incidence matrices, and conservation laws. Then the conversion of discrete nets to continuous ODE systems via mass-action kinetics. Finally, the token language DSL, which adds the fourth primitive — the guard — and typed composition.
Part II: Applications
Chapters 5-10 apply the formalism to six domains: resource management (coffee shop), game mechanics (tic-tac-toe), constraint satisfaction (sudoku), combinatorial optimization (knapsack), biochemistry (enzyme kinetics), and complex state machines (Texas Hold’em). Each chapter builds a complete model from scratch, simulates it, and analyzes the results.
Part III: Advanced Topics
Chapters 11-16 push the formalism further. Process mining discovers nets from event logs. A net’s topology is enough to generate its proof circuit and, once moves and goals are labelled, its ODE rates. Exponential weights encode scoring systems. JSON-LD makes nets self-describing and content-addressable. Zero-knowledge proofs appear here as that generated circuit: a derived artifact, not a destination.
Part IV: Building with pflow
Chapters 17-20 cover the ecosystem tools. The visual editor for designing nets interactively. The hosted service that runs a stored model as seeded what-ifs and checks it. The Go library’s API and package structure. And the parity tests that hold implementations to one golden output — two at first, twenty by the end. The Epilogue names the claim the whole book has been making.
The pflow Ecosystem
The projects referenced throughout this book form a unified ecosystem:
| Project | Purpose | URL |
|---|---|---|
| go-pflow | Core library — ODE simulation, reachability, process mining | github.com/pflow-xyz/go-pflow |
| pflow.xyz | Visual browser-based editor for designing nets | pflow.xyz |
| pflow-polyglot | One model, five forms, ten languages, one golden trace | github.com/pflow-xyz/pflow-polyglot |
| sim.pflow.xyz | Hosted what-if simulation and verification of stored models, with an MCP server | sim.pflow.xyz |
The editor and the library share the same JSON-LD model format, and go-pflow converts it into the model format sim.pflow.xyz stores and runs (parser.ModelFromJSON). A net designed in the editor can be simulated by the library without format conversion. The model is the source of truth.
Conventions
- Code examples appear inline for short snippets and in separate files for longer programs
- Mathematical notation uses standard linear algebra: bold lowercase for vectors (), uppercase for matrices ()
- Cross-references link between chapters: “the coffee shop model (Chapter 5)” or “mass-action kinetics (Chapter 3)”
- Go code uses the
go-pflowlibrary API; JavaScript uses the pflow.xyz browser modules - JSON-LD models use
@context: "https://pflow.xyz/schema"; the few snippets in other vocabularies (schema.org, in Chapter 16) name their own context
Acknowledgments
This book grew from blog posts, documentation, and working code written over two years. The pflow ecosystem is open source, and the ideas draw on sixty years of Petri net theory — from Carl Adam Petri’s 1962 dissertation through the process mining work of Wil van der Aalst and the categorical semantics of Meseguer, Montanari and Sassone.
The best way to learn is to build. Open pflow.xyz in a browser, draw a net, and press play. The mathematics follows.
License
To the extent possible under law, the author has dedicated this book to the public domain under the CC0 1.0 Universal dedication. You may copy, modify, translate, redistribute and build on it for any purpose, with no permission and no attribution required. The Go code that builds the book and the site is separate and is released under the MIT license; see the repository.