First of its kind, this fully coded symbolic computing notebook computes certain Petri categories as asynchronous sequencer/evaluator for Peano Axioms, in specific the Peano Axioms’ asynchronous String Rewriting system. A monoidal structure resides within the Petri category[8] which is used to form multiple multi-stage asynchronous clocks and as monoidal controller/sequencer to evaluate the Peano axioms given any valid input string expression; Peano’s axioms use the common arithmetic operators namely the addition +, multiplication * and parentheses () as grouping operators, and module symbol S as the Successor function-mimic. The monoidal structure of the Petri category provides programmable asynchronicity, indeed this categorical realisation of the asynchronicity is merely a commutative monoid [8]. Additional helper scripts are provided for symbolic computing of the Path categories for both the Peano Rewriting system and the Peri categories. All asynchronous symbolic computations are simulated and then animated with an interactive animator with optional video export. Main result: the asynchronous clocks always dilate and inexorably does their corresponding formal system. The code released in this computational notebook can fuel the instructors’ commitment to serve their students in a modern software learning habitat and fresh imaginative ideas to better render these difficult and detailed subject matters at even younger ages and accessible by all abilities; again the code is also useful for the students who need far more intricate details and would like to gain life-long skills by experimenting with scripts. The code here is also for those who need to design and simulate Petri Nets and animate the results, the monoidal input for configuring the Petri Net makes it far easier to design with than the UI based alternatives. Finally, those who are able to generate a textual output that configures a Petri Net could easily retarget their text generator for this monoidal Petri Net.
*,⊕,⊗,()
In[]:=
DateObject[]
Out[]=
In case of bugs in the code or mistakes in the theory please make contact to fix ASAP.
100% Fat Free Mathematics
computing the Petri category: programmable retarget-able symbolic computing prefix monoid for all Petri Nets residing in a Petri category, objects are the Petri graphs with monoid homomorphisms for graph morphisms.
monoid homomorphisms: programmable symbolic computing which constructs abstract and retarget-able prefix monoids in its code capable of linear mapping to itself or other monoids.
formal system dilation: as an example Peano axioms with additional reflexive arrows that allow idling or redundant substitutions or reversing substitutions.
monoid homomorphisms: programmable symbolic computing which constructs abstract and retarget-able prefix monoids in its code capable of linear mapping to itself or other monoids.
formal system dilation: as an example Peano axioms with additional reflexive arrows that allow idling or redundant substitutions or reversing substitutions.
Software
Release: β1.0 for Peano Test Rewriting system, α7.0 for Petri category monoid.
Scripts: Symbolic computations performed in Wolfram Mathematica 14.3 .Notebook: https://www.wolframcloud.com/obj/ccn2/Published/petri_categories_peano_text_rewriting.nbSupport: Contact the author for additional code, bugs, correction in maths and algebraic/mathematical mistakes or invalid inferences.Nomenclature: Most functions and most identifiers start with lower case letters, all native vendor identifiers start with upper case. No Packaging: There is no software engineering applied to the code here nor elsewhere in the author’s technical notes to reduce the difficulties and version mismatches in future. The eager readers can simply copy paste the code or download and run the notebook. TODO: 1. Parallelize the peanoRW[ ] between multiple physical cpus.2. Automate the adding and removing Terminals namely τ1, τ2, τ3 ... 3. clear is not initialized in the cloud, it has to be initialized only at the application level.This terrifying herculean notion is extremely valuable since it permits generalizing universal algebra over the category of sets to universal algebra over arbitrary categories, for which more subtle kinds of algebraic structures, not expressible in classical terms, may exist.[8]2. Probabilistic Petri categories via the Simplex Monads3. Petri Net products4. Category enhanced Rewriting systems e.g. Category of Derivations by David Benson. 5. Matrix representations of ,6. Matrix representation of the monoid homomorphisms Known Issues:1. Peano axiomatic inferred/constructed arbitrary expressions not implemented and left failing during the evaluation since the Peano axioms do not cover rules for simplifications
4. Make a matrix
⊕
for large graphs with corresponding GPU code for realtime monoidal evaluations. This will be useful for dynamical situations with
millions of moveable parts.
5. Update the Free Form Language Programming Petri Net monoid already released s and in circulation. 6. Add monoidal operators for sequential vs. parallel evaluations.7. φcomposition[ ] exclusively works for the Path categories. Not sure if a general purpose one is possible but we need a better retarget-able version. One way to solve this is a cloud registry for different categories morphism definitions and when a new morphism is coded the proper registrations are required for it to be identifiable. This is not the same as assigning a type to the morphism. 8. φcomposition[ ] add an infix operator version.9. We need a far more compact definition of the Petri category, both Ref[8] and my definition are all over the place. A few authors proposed compact definitions of the Petri category at the expense of dropping all the key important details! 10. Expand the animator code to show the progress for the Peano Tape as well as the Petri Net state. TOLEARN:1. Monads ∂
0
∂
1
© 2012-Present CCN StudiosCreative Commons Attribution-NonCommercial-ShareAlike 4.0
Initialization
Initialization
In[]:=
Notation`AutoLoadNotationPalette=True;Needs["Notation`"];ClearNotations[];(*1stGETshouldbethePetriNet*)CloudGet["https://wolfr.am/1z88b1Snz"];PetriMonoid[];(*2ndGETshouldbethePeanoStringRewritingSystem*)CloudGet["https://wolfr.am/1z88Lc63z"];PeanoSys[];
version: α7.0
version: β1.0
Conspectus
Conspectus
I need to be pedantic and deconstruct all technical concepts and reintegrate them back together in order to converse and code properly about the involved Graphs and Categories in this notebook. The modern literature is quite sloppy and confusing, so I rely as best I can on the original older literature. And again I need to regiment the economy of words to avoid writing a math paper, and focus on the writing mostly computing part namely writing code. To obfuscate math is easy, to make a piece of math code properly in a symbolic computing environment is quite detailed and difficult.
C
1
C
2
φ:G⟶H,edge(x,y)inGthen(φ(x),φ(y))isalsoanedgeinH
This is called SimpGph category or something similar.
C
3
φ:G⟶H
Note that the SimpGph category is between graphs, each graph is an object. On the other hand we can turn one single graph into a category, in and of itself, by means of graph paths:
C
4
C
5
C
6
C
7
C
8
1 Peano String Rewriting System
1 Peano String Rewriting System
Term rewriting systems can be employed to compute arithmetic operations on natural numbers. To this end, each such number has to be encoded as a term. The simplest encoding is the one used in the Peano axioms, based on the constant 0 (zero) and the successor function S. For example, the numbers 0, 1, 2, and 3 are represented by the terms 0, S(0), S(S(0)), and S(S(S(0))), respectively. The following term rewriting system can then be used to compute sum and product of given natural numbers [1] :
1.1 String Substitution Rules
1.1 String Substitution Rules
In[]:=
ules={"A+0"->"A","A+S(B)"->"S(A+B)","A*0"->"0","A*S(B)"->"A+(A*B)"};
Remark : rule added internally to the rewriting since that rule qualifies as a simplifier and not a part of the Peano axioms.
TODO: In the above minimalistic Peano axioms as a Text Rewriting System, the commutativity and expression simplifications and reductions are not included.
1.2 peanoRW[ ]
1.2 peanoRW[ ]
For now, I programmed only a procedural function called peanoRW[ ] that does the String Rewriting for the Peano ules above.
1.3 Module S
1.3 Module S
S is a parametric symbol or called a module, unlike what mathematicians conjure up, S is not a function in our Peano String Rewriting System, since there are no functions in text strings. S is a symbol, atomic and indivisible and yet allows for its parametrization by another token called B.
Therefore S(B) is merely the following parametrization to extend and augment S:
Therefore S(B) is merely the following parametrization to extend and augment S:
1.4 +
1.4 +
1.5 *
1.5 *
countS[ ]: counts the number of tokens S in a string
machParans[ ] : matches the parentheses in case of mismatch. This () mismatch anomaly has not happened since two versions ago!
machParans[ ] : matches the parentheses in case of mismatch. This () mismatch anomaly has not happened since two versions ago!
1.6 String Rewriting as a Graph
1.6 String Rewriting as a Graph
● Any circumstance where A points at B, warrants a vectorial or arrow notion A ⟶ B and once a few more of these arrows are formed we get a Graph.
● Once we have a Graph then we can construct a Path category based upon its arrows.
● If the arrows source and destinations are endowed with lingual structures, then we might be able to augment the graph with a Rewriting system.
● When we have in place this Graph and the Rewriting augmentation, again Path Category is built. However, these morphic paths in this category could be algebraic evaluation steps e.g. simplification or cancelation or expressions as you experiment below with the Peano axioms.
● The edges variable below contain two way arrows as extensions to the Peano axioms. You might agree or not, but fact remains, these arrows make sense arithmetically on pencil and paper.
● All these arrows indicate is this simple Natural numbers fact: given two numbers n and m, one can reduce one to the other with finite applications of + or * and groupings operators () and the Successor function.
● Identity function or morphism or a looped arrow with the same source and target, have a meaning in our graphs and later the Petri categories, namely that of idling! Idling as in leaving an engine running by idle by itself maintaining a fixed location.
● to a mathematician x , whatever it might be, is always there as an eternal entity! Write x on a piece of paper as a variable for some algebra or the variable referring to a point on your paper, whatever the entity x might be you are psychologically conditioned by your math teachers to believe that x is always there. This is the brainchild of Pythagoras[1] who viewed mathematics as a religion with absolute attributes and last in perpetuity and eternal.
● Categories do not need the construction details of the said loop or even the object A, all they need is morphic relations between the objects; the network connectivity graph components are the essence.
1.2 Peano Axioms ⟶ Path Categories
1.2 Peano Axioms ⟶ Path Categories
1.2.1 Graph’s simple paths
1.2.1 Graph’s simple paths
1.2.2 Digression: Test for general graphs
1.2.2 Digression: Test for general graphs
1.2.3 Include Id in the paths
1.2.3 Include Id in the paths
Run the script again and the path indeed starts at source and ends at target but it arbitrarily/randomly loops around the vertices with uniform probability.
1.3.1 Construct the Path-morphisms
1.3.1 Construct the Path-morphisms
index2 reverses the Association for index:
1.3.2 φpaths[ ] : Path Category computation and formatting
1.3.2 φpaths[ ] : Path Category computation and formatting
φ1 is the format from the math books:
{object, arrow, object, arrow, object ...}
{object, arrow, object, arrow, object ...}
φ2
1.3.3 φcomposition[ ]: Morphism Composition
1.3.3 φcomposition[ ]: Morphism Composition
φcomposition[ ] composes the two morphisms and again returns a morphism in the format of the math books. And it is nothing other than concatenating the paths, end of the first one to the head of the second one and so on.
φcomposition2[ ] composes the two morphisms and returns a new graph. Much easier to use for later computing:
2 Petri Category
2 Petri Category
In order for this software to work and in order for all the mathematics to remain correct we will define Petri Nets and their category in a monoidal fashion which requires a bit of monoid/semigroup knowledge.
2.1 Petri Net
2.1 Petri Net
● The software symbols: places, transitions, graph connectivity between Places and Transitions, arcs for monoidal congruence Relation, describe a Petri Net.
● or arcs defines the congruence relation above which in Petri terminology it means if there are 2 balls at c and 5 balls at d the fire a transition and add 3 balls to a and 3 balls to z and 5 balls to b and decrement balls by 1 at c and d. And also the second term denotes if there is 1 ball in z, add a ball to τ1 and decrement z’s balls.
Configure your Petri Net and its monoidal congruence relation :
● the list of transitions.
● Petri Net’s graph connectivity.
● labels for ease of reading String labels are provided for both Places and transitions.
● clear is a list of Places where upon arrival of a ball resets the non-Clock Places to no balls or 0, while leaving the clocks intact.
Compute the Petri graph graph by calling network[] :
Use graph to plot an uninitialized Petri Net meaning no balls.
Adjacency matrix
Laplacian matrix
● Code below runs the Petri Net above 2 times thanks to the operator syntax 20 ⊗ ...
● : graph[2] returns the first initialized Petri Net, : graph[1] is the original graph
● : graph returns the last Petri Net update
Finally get the ball counts history:
2.1 Monoid
2.1 Monoid
We use monoids and modules and semigroups interchangeably to match the literature, however in our case semigroup results hold well for the monoids and R-Module homomorphisms are actually group homomorphisms which commute with scalar multiplications [14]. In Ref [8], the source of the monoidal formal system for Petri Nets, the monoid is used and actually it should have been -Module, which is a mere technicality. Therefore, there might be some confusion.
From here on we make general definitions and quote properties though the verbiage is customized per Ref[8] and often with the prefix Petri.
From here on we make general definitions and quote properties though the verbiage is customized per Ref[8] and often with the prefix Petri.
● Symbol defines a monoidal congruence Relation on .
Standard property for these quotient structure:
4.Single 5-Clock: Petri Category as Sequencer for Peano Axioms Rewriting system
4.Single 5-Clock: Petri Category as Sequencer for Peano Axioms Rewriting system
4.1 graph again
4.1 graph again
● PetriMonoid[ ] is a general purpose Petri Monoidal evaluator and part simulator for Petri Nets. However inside its code it detects if another formal system is active e.g. Peano axioms, if they are then special conditional scripts are also made active.
● Call PetriMonoid[ ] and then network[ ] to construct the graph corresponding to the Peano axioms Petri Net.
● The circular arrow structure is the 5-clock, normally we place 1 ball at α1 to get the clock tik-tok and the clock in turn deposits 1 ball in start and start fires off transition comb to dispatch 1 ball to Peano’s expressions for the String Rewriting.
● clear = {α5} resets the non-clock balls to 0 and these are the set theoretic Complement of clocks set. This resetting is ignored if clear = { } .
4.2 word and wordout : input output strings from Peano axioms
4.2 word and wordout : input output strings from Peano axioms
● word=”S(S(S(0)))+S(S(0))” inputs the tape string for the Peano Text Rewriting System. This word is equivalent to 3+2 in decimal.
● wordout outs the tape string for the Peano Text Rewriting System.
● wordout after 500 rewritings ended up with string S(S(S(S(S(0))))) which is 5 in decimal.
wordout=S(S(S(S(S(0))))) and that is correct since 3+2 = 5.
4.3 Animate
4.3 Animate
Run the below expression cell first, the DynamicModule[]
4.3.1 Video Export
4.3.1 Video Export
This might take a few minutes:
4.4 clear at work
4.4 clear at work
4.5 Paths Morphisms
4.5 Paths Morphisms
4.6 Composition: Path Category for graph of the Petri category for Peano axioms
4.6 Composition: Path Category for graph of the Petri category for Peano axioms
4.8 Digression: LayeredEmbedding for different layout
4.8 Digression: LayeredEmbedding for different layout
4.9 Petri parameters
4.9 Petri parameters
5.Two 5-Clocks: Petri Category as Sequencer for Peano Axioms Rewriting system
5.Two 5-Clocks: Petri Category as Sequencer for Peano Axioms Rewriting system
5.1 graph again
5.1 graph again
5.2 Run the Petri Net 1500 times
5.2 Run the Petri Net 1500 times
wordout is the output and it is correct 4*3=4+4+4 = 12.
Q: Why are there three numeral four added to each other vs. 12 nested S?
A: Peano Axioms we chose lack simplifiers, therefore more rules are required and that was not the point of this treatise.
Q: Why are there three numeral four added to each other vs. 12 nested S?
A: Peano Axioms we chose lack simplifiers, therefore more rules are required and that was not the point of this treatise.
5.3 Animate
5.3 Animate
Run the below expression cell first, the DynamicModule[]
5.3.1 Video Export
5.3.1 Video Export
This might take a few minutes:
5.4 clear at work
5.4 clear at work
Checkout the clear={α5, β5}, which cleared non-clock Places in this example while leaving the state of the α-clock intact and transitioned to β1 and start.
References
References
1. Peano Axiom Rewriting: https://en.wikipedia.org/wiki/Rewriting#Arithmetic
2. Example 15.26.2-2. Value Of Left-Hand Side Of Compound Assignment Is Saved Before Evaluation Of Right-Hand Side:
https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#d5e30252
3. Alfred North-Whitehead Process and Reality
4. Constructive Proof
https://en.wikipedia.org/wiki/Constructive_proof
5. John von Neumann’s quotes
https://en.wikiquote.org/wiki/John_von_Neumann
6. Difference between “Langue” & “Language”
https://awesomefrench.tumblr.com/post/55078404181/difference-between-langue-langage
7. Francis Borceux, Handbook of Categorical Algebra 1.
8. Jose Meseguer, Ugo Montarari, Petri Nets are Monoids. Information and Computation 88, 1990
9. Acharya S, Shukla S. Mirror neurons: Enigma of the metaphysical modular brain. J Nat Sci Biol Med. 2012 Jul;3(2):118-24. doi: 10.4103/0976-9668.101878. PMID: 23225972; PMCID: PMC3510904.
https://pmc.ncbi.nlm.nih.gov/articles/PMC3510904/
10. Mirror Neurons
https://www.sciencedirect.com/topics/neuroscience/mirror-neuron
11. Free category or path category
https://en.wikipedia.org/wiki/Free_category
12. Monoidal Category
https://en.wikipedia.org/wiki/Monoidal_category
13: Category of simple graphs
https://ncatlab.org/nlab/show/category+of+simple+graphs
14: Module homomorphism
https://en.wikipedia.org/wiki/Module_homomorphism
15. Presentation of a monoid
https://en.wikipedia.org/wiki/Presentation_of_a_monoid
16. Module
https://en.wikipedia.org/wiki/Module_(mathematics)
17. Pythagoreanism
https://en.wikipedia.org/wiki/Pythagoreanism
2. Example 15.26.2-2. Value Of Left-Hand Side Of Compound Assignment Is Saved Before Evaluation Of Right-Hand Side:
https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#d5e30252
3. Alfred North-Whitehead Process and Reality
4. Constructive Proof
https://en.wikipedia.org/wiki/Constructive_proof
5. John von Neumann’s quotes
https://en.wikiquote.org/wiki/John_von_Neumann
6. Difference between “Langue” & “Language”
https://awesomefrench.tumblr.com/post/55078404181/difference-between-langue-langage
7. Francis Borceux, Handbook of Categorical Algebra 1.
8. Jose Meseguer, Ugo Montarari, Petri Nets are Monoids. Information and Computation 88, 1990
9. Acharya S, Shukla S. Mirror neurons: Enigma of the metaphysical modular brain. J Nat Sci Biol Med. 2012 Jul;3(2):118-24. doi: 10.4103/0976-9668.101878. PMID: 23225972; PMCID: PMC3510904.
https://pmc.ncbi.nlm.nih.gov/articles/PMC3510904/
10. Mirror Neurons
https://www.sciencedirect.com/topics/neuroscience/mirror-neuron
11. Free category or path category
https://en.wikipedia.org/wiki/Free_category
12. Monoidal Category
https://en.wikipedia.org/wiki/Monoidal_category
13: Category of simple graphs
https://ncatlab.org/nlab/show/category+of+simple+graphs
14: Module homomorphism
https://en.wikipedia.org/wiki/Module_homomorphism
15. Presentation of a monoid
https://en.wikipedia.org/wiki/Presentation_of_a_monoid
16. Module
https://en.wikipedia.org/wiki/Module_(mathematics)
17. Pythagoreanism
https://en.wikipedia.org/wiki/Pythagoreanism
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Petri category sequencer for Peano axioms' rewriting system (fully coded): part 1
by Dara O Shayda
Wolfram Community, STAFF PICKS, October 16, 2025
https://community.wolfram.com/groups/-/m/t/3561206
by Dara O Shayda
Wolfram Community, STAFF PICKS, October 16, 2025
https://community.wolfram.com/groups/-/m/t/3561206