The Azimuth Project
Blog - cospans, wiring diagrams, and the behavioural approach

Joint post by John Baez and Brendan Fong.


Last time we heard about understanding types of networks as categories of decorated cospans.

• Decorated cospans post.

Earlier, David Spivak also told us about understanding networks as algebras over an operad.

A Networked World (Part 3)

Both these frameworks work at capturing notions of modularity and interconnection. Are they then related? How? In this post we want to discuss some similarities between decorated cospan categories constructed from functors with domain (Set,+) (\mathrm{Set},+), and algebras for Spivak’s operad of wiring diagrams. The main idea is that the two approaches are ‘essentially’ equivalent, but that compared to decorated cospans, Spivak’s operad formalism puts greater emphasis on the distinction between the Frobenius morphisms and other morphisms in our category. The precise details are still to be worked out – jump in and help us!

Operads

We begin with a bit about operads in general. Recall that an operad is similar to a category, except that instead of a set hom(x,y)\mathrm{hom}(x,y) of morphisms from any object xx to any object yy, you have a set hom(x 1,...,x n;y)\mathrm{hom}(x_1,...,x_n;y) of operations from any finite list of objects x 1,...,x nx_1,...,x_n to any object yy. If we have an operation fhom(x 1,...,x n;y)f \in \mathrm{hom}(x_1,...,x_n;y), we can call x 1,,x nx_1, \dots, x_n the inputs of ff and call yy the output of ff.

We can compose operations in an operad. To understand how, it’s easiest to use pictures. We draw an operation in hom(x 1,...,x n;y)\mathrm{hom}(x_1,...,x_n;y) as a little black box with nn wires coming in and one wire coming out:

The input wires should be labelled with the objects x 1,,x nx_1, \dots, x_n and the output wire with the object yy, but I haven’t done this.

We are allowed to compose these operations as follows:

as long as the outputs of the operations g 1,,g ng_1,\dots,g_n match the inputs of the operation ff. The result is a new operation which we call f(g 1,,g n)f \circ (g_1,\dots,g_n).

We demand that there be unary operations 1 xhom(x,x)1_x \in hom(x,x) serving as identities for composition, and we impose an associative law that makes a composite of composites like this well-defined:

So far this is the definition of a planar operad. In a full-fledged permutative operad, often called just an operad, we can also permute the inputs of an operation ff and get a new operation:

which we call fσf \sigma if σ\sigma is the the permutation of the inputs. We demand that (fσ)σ=f(σσ)(f \sigma) \sigma' = f (\sigma \sigma'). And finally, we demand that permutations act in a way that is compatible with composition. For example:

Here we see that (fσ)(g 1,,g n)(f \sigma) \circ (g_1, \dots, g_n) is equal to some obvious other thing. There is also a law saying f(g 1σ 1,,g nσ n)f \circ (g_1 \sigma_1, \dots, g_n \sigma_n) is equal to some other expression.

Operads are similar to symmetric monoidal categories. The idea is that in a symmetric monoidal category you can just form the tensor product x 1x n x_1 \otimes \dots \otimes x_n and talk about the set of morphisms x 1x ny x_1 \otimes \dots \otimes x_n \to y. Indeed any symmetric monoidal category gives an operad in this way: just define hom(x 1,...,x n;y)\mathrm{hom}(x_1,...,x_n;y) to be hom(x 1x n,y)\mathrm{hom}(x_1 \otimes \cdots \otimes x_n, y). If we do this with Set, which is a symmetric monoidal category using the usual cartesian product of sets, we get an operad called Sets\mathrm{Sets}.

An algebra for an operad OO is an operad homomorphism OSetsO \to \mathrm{Sets}. I know I haven’t said what an operad homomorphism is, but you can probably figure it out yourself. The point is this: an algebra for OO turns the abstract operations in OO into actual operations on sets!

The operad of wiring diagrams

Spivak’s favorite operad is the operad of wiring diagrams. The operad of wiring diagrams WDWD is an operad version of Cospan(FinSet) \mathrm{Cospan}(\mathrm{FinSet}), constructed in the vein suggested above: the objects are finite sets, and the morphisms from a set of sets {X 1,...,X n} \{X_1,...,X_n\} to a set YY are cospans X 1+...+X nY X_1+...+X_n \to Y. Spivak draws these things as a big circle with nn small circles cut out from the interior. The outside of the big circle has YY terminals marked on it, and the small circles each have X iX_i terminals marked respectively. Then in the interior of this shape there are wires connecting these terminals. These are the so-called wiring diagrams.

You compose these wiring diagrams by pasting other wiring diagrams into each of the small circles.

The relationship with our Frobenius algebra diagrams is pretty simple: we draw our ‘wiring diagrams’ XY X \to Y in a square, with the XX terminals on the left and YY terminals on the right. To get a Spivak-approved wiring diagram, glue the top and bottom edges of this square together, then flatten the cylinder you get down into an annulus, with the XX-side on the inside and YY-side on the outside. If X=X 1+X 2 X = X_1+X_2 you can imagine gluing opposite edges of the inside circle together to divide it into two small circles accordingly, and so on.

So loosely, we could think of the operad of wiring diagrams as like the PROP for special commutative Frobenius monoids.

Relational algebras of type A

Algebras for wiring diagrams tell you what components you have available to wire together with your diagrams. An algebra for the operad of wiring diagrams is a functor WDSetsWD \to Sets. What does this look like? Just like a functor for categories, it assigns to each natural number a set, and each wiring diagram a function.

In work related to decorated cospans (such as our draft paper on circuits or John and Jason Erbele’s work on signal flow diagrams), our semantics usually is constructed from a field of values: like assigning a velocity, or potential, or current to a variable. This gives us vector spaces and bimonoids and a bunch of nice structure. Spivak works more generally: he’s interested in the structure when you just have a set of values. While this means we can’t do some of the nice things we could do with a field, it also means this framework can do things like talk about logic gates, where the variables are boolean ones, or number theoretic questions, where you’re interested in the natural numbers.

So to discuss semantics we pick a set A of values, such as the real numbers or natural numbers or booleans or colours. We imagine then associating elements of this set to each wire in a wiring diagram. More technically, the algebra RelA:WDSets\mathrm{Rel}A: WD \to \mathrm{Sets} then maps each finite set XX to the power set 𝒫(A X)\mathcal{P}(A^X) of the set A XA^X of functions XAX \to A.

On the morphisms (the wiring diagrams themselves), this functor behaves like our copying/comparing Frobenius algebra (the white one in the signal flow calculus). Note that a function (XAX \to A) can be thought of as an ‘X-vector’ (a 1,...,a x)(a_1,...,a_x) of ‘AA-coordinates’. A wiring diagram XYX \to Y is just a cospan XNYX \to N \leftarrow Y in SetSet, so it can be thought of as some compares (XNX \to N) followed by some copies (NYN \to Y). Thus, given a wiring diagram XYX \to Y, we can consider a partial function that maps an XX-vector to the YY-vector by doing these compares, and if it passes them does the copies and returns the resulting Y-vector, but if not returns ‘undefined’. We can then define a map 𝒫(A X)𝒫(A Y)\mathcal{P}(A^X) \to \mathcal{P}(A^Y) which takes a set of XX-vectors to its image under this partial function.

This semantics is called the relational WDWD-algebra of type AA. We can think of it as like the white fragment of the signal flow calculus.

Note that we can’t do the black signal flow calculus, because we only have a set AA of values, not a field AA, and the black signal flow calculus requires addition.

Operads and the behavioural approach

In formulating Frobenius monoids this way, Spivak achieves something that we’ve been working hard to find ways to acheive: a separation of the behavioural structure from the interconnection structure.

What do I mean by this? In his ‘behavioural approach’, Willems makes the point that for all their elaborate and elegant formulation, in the end physical laws just come down to dividing the set of what might a priori be possible (the ‘universum’) into the set of things that actually are possible (the ‘behaviour’), and the set of things that aren’t). Here the universum is the set A XA^X: a priori, on each of the wires in XX, we might associate any value of AA. For example, to the two wires at the ends of a resistor, we might a priori associate any pair of currents. But physical law, here Kirchhoff’s current law, says otherwise: the currents must be equal and opposite. So the ‘behaviour’ is the subset (i,i)(i,-i) of the universum 2\mathbb{R}^2.

So you can say that to each object XX in the operad of wiring diagrams the relational algebra of type AA associates the set 𝒫(A X)\mathcal{P}(A^X) of possible behaviours – the universum is A XA^X. (𝒫(A X)\mathcal{P}(A^X) forms some sort of meta-universum, where you can discuss physical laws about physical laws, commonly called ‘principles’.)

The second key aspect of the behavioural approach is that the behaviours of larger systems can be constructed from the behaviours of its subsystems, if we understand the so-called ‘interconnection structure’ well enough. This is a key principle in engineering: we build big, complicated systems from a much smaller set of components, whether it be electronics from resistors and inductors, or mechanical devices from wheels and rods and ropes, or houses from Lego bricks. The various interconnection structures here are the wiring diagrams, and our relational algebras say they act by what Willems calls ‘variable sharing’.

This division between behaviour and interconnection motivates the decorated cospans construction (the decorations are the ‘components’, the cospans the ‘interconnection’) and multigraph categories (morphisms = ‘components’, Frobenius monoids = ‘interconnection’).

So it’s good to have this additional way of thinking about things in our repertoire: Operads describe ‘interconnection’, their algebras ‘behaviours’.

The separation Spivak achieves, however, seems to me to come at the cost of neat ways to talk about individual components, and perhaps this can be seen as the essential difference between the two approaches. By including our components as morphisms, we can talk more carefully about them and additional structure individual components have. On the other hand, by lumping all the components into the objects, Spivak can talk more carefully about how the interconnection structure acts on all behaviours at once.

Other operads of wiring diagrams

One advantage of the operad approach is that you can easily tweak your operad to talk about different sorts of network structure. Sometimes you can make similar adjustments with decorated cospans too, such as working over the category of typed finite sets, rather than just finite sets, to discuss networks in which wires have types, and only wires of the same types can be connected together. A physical example is a model of a hydroelectric power plant, where you don’t want to connect a water pipe with an electrical cable! This is also a common technique in computer science, where you don’t want to try to multiply two strings of text, or try to interpret a telephone number as a truth value.

But some modifications are harder to do with decorated cospans. In some other papers, Spivak employs a more restricted operad of wiring diagrams, in which joining wires and terminating wires is not allowed, among other things. He uses this to formalise graphical languages for certain types of discrete-time processes, open dynamical systems, including mode-dependent ones.

More detail:

B. Fong - Decorated cospans. http://arxiv.org/abs/1502.00872.

D. Spivak - The operad of wiring diagrams: formalizing a graphical language for databases, recursion, and plug-and-play circuits. http://arxiv.org/abs/1305.0297.