
Petri Nets Are Monoids (1990) [pdf] - boshomi
https://core.ac.uk/download/pdf/82342688.pdf
======
ampdepolymerase
For those who are interested, Petri nets have a lot of applications in CS, for
example, spiking neural networks.

------
yingw787
For those who don’t know what a monoid is, like me three months ago, I believe
a monoid is something that implements monoidal operations, which are binary
associative operations with an identity. Integers have monoidal operations
like addition and multiplication. You have two arguments, which don’t matter
in ordering, and where an identity like the additive or multiplicative
identity exists.

~~~
RangerScience
ELI5? I appreciate the attempted explanation, but I'm not finding the the new
one any more helpful.

~~~
kmill
A monoid is a set of objects each having a port on the left and on the right,
and given two such objects you can join the left port of one object to the
right port of the other, constructing a new object. There is also an "empty"
object that, when joined to any given object, results in that object
unchanged.

For example, stacks of paper can be thought of as a monoid. Given two stacks,
you can stack one on top of the other (the top and bottom of the stack
standing in for the ports). The vacuous concept of a stack of zero sheets of
paper is the "empty" object.

Another example is the set of PNG files. There are a number of monoids you
could define, like horizontal concatenation of images, or the vertical
concatenation of images. A non-example is blending two images with 50% opacity
each, since depending on the order you blend the images, like (AB)C versus
A(BC), image A might contribute 25% or 50% to the final image.

For some monoids, the left/right port distinction doesn't matter. Consider
buckets of marbles. The way you join two buckets of marbles is to dump them
into a single bucket. The empty bucket is the empty object. It doesn't matter
in which order you dump the marbles into a bucket --- you'll get the same
number of marbles in the end.

~~~
RangerScience
This was very helpful. So an important aspect of a set of monodial operations
is that the order doesn't effect the outcome...?

This mostly makes sense, although... not for arrays where order matters...?

~~~
uryga
it's not exactly order independence, it's associativity:

    
    
      (a • b) • c  ==  a • (b • c)
    

i.e. "no matter where you put the parentheses, it'll give the same result".
this DOESN'T mean that

    
    
      a • b == b • a 
    

though it may be true for some monoids like addition/multiplication over
numbers¹.

you'll notice that associativity indeed holds for strings (or arrays of some
T), where concatenation is the monoidal operation:

    
    
      ("he" ++ "ll") ++ "o!" ==
      "he ++ ("ll" ++ "o!") ==
       "hello!" 
    
    
    

though at first blush associativity may not seem very useful, it is! it means
folding/"summing" a sequence of monoidal values is trivially parallelizable.
i.e. if you've got a sequence

    
    
      as = [a0, a1, a2, ..., an-1, an]
    

and you want to "sum"/fold it using a's monoidal operation "•":

    
    
      r = (a0 • a1 • a2 • ... • an)
    

you can split it into chunks across multiple workers and then "sum" the
results of summing each chunk:

    
    
       r0 = (a0•a1•a2)  // worker 0
       r1 = (a3•a4•a5)  // worker 1
       ...
       rm = (an-2,an-1,an) // worker m
    
       r = r0•r1•...•rm // sum up what the workers produced
     

the nice thing is, as long as we don't reorder the elements, we'll always get
the same result no matter how we chunk up `as`! and this will hold for any
monoid `(a, •)`.

btw, an example of a less trivial monoid is `sorted lists of T `:

\- `•`, the monoidal operation, is `merge(a, b)`, which combines two sorted
lists into a new sorted list: `merge([1,2,3,5], [2,4]) == [1,2,2,3,4,5]`

\- `e`, the "neutral element", is just the empty list `[]`

this is a (commutative) monoid, and you could say that mergesort _relies_ on
its monoidal properties to work!

\---

¹ if you can swap values around and still get the same result, you've got a
"commutative monoid".

~~~
uryga
whoops, that last code block was supposed to have

    
    
       rm = (an-2•an-1•an)
    

instead of the commas.

------
adamnemecek
They can also be reasoned about in terms of linear logic.

[https://www.researchgate.net/publication/318253097_Petri_Net...](https://www.researchgate.net/publication/318253097_Petri_Nets_as_Models_of_Linear_Logic)

------
hobbio
Paged through the article for pictures, but the only example with tensors was
trivial. Could anyone who read the thing tell if there's an intuitive
explanation of the binary operation on full nets?

------
stebann
They can be used for modelling actions and states, including the tricky cases
where an automaton would become too complex.

~~~
kitd
Indeed. Finite state machines are a subset of Petri nets, having deterministic
state transitions. Petri nets are useful where concurrent state transitions
needs to be modelled, and are thus useful when modelling the physical world.

~~~
stebann
Thanks. I forgot to appoint that.

