Last time I came close to describing the ‘black box functor’, which takes an electrical circuit made of resistors

and sends it to its behavior as viewed from outside. From outside, all you can see is the relation between currents and potentials at the ‘terminals’—the little bits of wire that poke out of the black box:

I came close to defining the black box functor, but I didn’t quite make it! This time let’s finish the job.

### The categories in question

The black box functor

goes from the category where morphisms are circuits made of resistors, to the category where morphisms are linear relations. Let me remind you how these categories work, and introduce a bit of new notation.

Here is the category

• an object is a finite set;

• a morphism from to is an isomorphism class of cospans

in the category of graphs with edges labelled by **resistances**: numbers in Here we think of the finite sets and as graphs with no edges. We call the set of **inputs** and the set of **outputs**.

• we compose morphisms in by composing isomorphism classes of cospans.

And here is the category

• an object is a finite-dimensional real vector space;

• a morphism from to is a **linear relation** meaning a linear subspace

• we compose a linear relation and a linear relation in the usual way we compose relations, getting:

In case you’re wondering: I’ve just introduced the wiggly arrow notation

for a linear relation from to because it suggests that a relation is a bit like a function but more general. Indeed, a function is a special case of a relation, and composing functions is a special case of composing relations.

### The black box functor

Now, how do we define the black box functor?

Defining it on objects is easy. An object of is a finite set and we define

The idea is that could be a set of inputs or outputs, and then

is a list of numbers: the potentials and currents at those inputs or outputs.

So, the interesting part is defining the black box functor on morphisms!

For this we start with a morphism in :

The labelled graph consists of:

• a set of **nodes**,

• a set of **edges**,

• maps sending each edge to its **source** and **target**,

• a map sending each edge to its **resistance**.

The cospan gives maps

These say how the inputs and outputs are interpreted as nodes in the circuit. We’ll call the nodes that come from inputs or outputs ‘terminals’. So, mathematically,

is the set of **terminals**: the union of the images of and

In the simplest case, the maps and are one-to-one, with disjoint ranges. Then each terminal either comes from a *single* input, or a *single* output, but *not both!* This is a good picture to keep in mind. But some subtleties arise when we leave this simplest case and consider other cases.

Now, the black box functor is supposed to send our circuit to a linear relation. I’ll call the circuit for short, though it’s really the whole cospan

So, our black box functor is supposed to send this circuit to a linear relation

This is a relation between the potentials and currents at the input terminals and the potentials and currents at the output terminals! How is it defined?

I’ll start by outlining how this works.

First, our circuit picks out a subspace

This is the subspace of allowed potentials and currents on the terminals. I’ll explain this and why it’s called a bit later. Briefly, it comes from the principle of minimum power, described last time.

Then, the map

gives a linear relation

This says how the potentials and currents at the inputs are related to those at the terminals. Similarly, the map

gives a linear relation

This says how the potentials and currents at the *outputs* are related to those at the terminals.

Next, we can ‘turn around’ any linear relation

to get a relation

defined by

Here we are just switching the input and output potentials, but when we switch the currents we also throw in a minus sign. The reason is that we care about the current flowing *in* to an input, but *out* of an output.

Finally, one more trick: given a linear subspace

of a vector space we get a linear relation

called **the identity restricted to** , defined like this:

If is all of this relation is actually the identity function on Otherwise it’s a partially defined function that’s defined only on and is the identity there. (A partially defined function is an example of a relation.) My notation is probably bad, but I don’t know a better one, so bear with me.

Let’s use all these ideas to define

To do this, we compose three linear relations:

1) We start with

2) We compose this with

3) Then we compose this with

Note that:

1) says how the potentials and currents at the inputs are related to those at the terminals,

2) picks out which potentials and currents at the terminals are actually allowed, and

3) says how the potentials and currents at the terminals are related to those at the outputs.

So, I hope all makes sense, at least in some rough way. In brief, here’s the formula:

Now I just need to fill in some details. First, how do we define and They work exactly the same way, by ‘copying potentials and adding currents’, so I’ll just talk about one. Second, how do we define the subspace This uses the principle of minimum power.

### Duplicating potentials and adding currents

Any function between finite sets

gives a linear map

Mathematicians call this linear map the **pullback along** and for any it’s defined by

In our application, we think of as a list of potentials at terminals. The function could map a bunch of inputs to the same terminal, and the above formula says the potential at this terminal gives the potential at all those inputs. So, we are *copying potentials*.

We also get a linear map going the other way:

Mathematicians call this the **pushforward along** and for any it’s defined by

In our application, we think of as a list of currents entering at some inputs. The function could map a bunch of inputs to the same terminal, and the above formula says the current at this terminal is the sum of the currents at all those inputs. So, we are *adding currents*.

Putting these together, our map

gives a linear relation

where the pair is related to the pair iff

and

So, here’s the rule of thumb when attaching the points of to the input terminals of our circuit: *copy potentials, but add up currents*. More formally:

### The principle of minimum power

Finally, how does our circuit define a subspace

of allowed potential-current pairs at the terminals? The trick is to use the ideas we discussed last time. If we know the potential at all nodes of our circuit, say , we know the power used by the circuit:

We saw last time that if we fix the potentials at the terminals, the circuit will choose potentials at the other nodes to minimize this power. We can describe the potential at the terminals by

So, the power for a given potential at the terminals is

Actually this is half the power: I stuck in a factor of 1/2 for some reason we’ll soon see. This is a quadratic function

so its derivative is linear. And, our work last time showed something interesting: to compute the current flowing into a terminal we just differentiate with respect to the potential at that terminal:

This is the reason for the 1/2: when we take the derivative of we bring down a 2 from differentiating all those squares, and to make that go away we need a 1/2.

The space of allowed potential-current pairs at the terminals is thus the linear subspace

And this completes our precise description of the black box functor!

The hard part is this:

**Theorem.** is a functor.

In other words, we have to prove that it preserves composition:

For that, read our paper:

• John Baez and Brendan Fong, A compositional framework for passive linear networks.

Whoops! I screwed up the second step of how to get a linear relation from a circuit made of resistors. I wrote:

In the second step I used the power function

to get a linear relation

But Brendan pointed out that this relation is not the right one. Quite concretely, we have

What we really want is another relation which I’ll call This is

In his writeup, Brendan arrives at this in a nice conceptual way. I was trying to take a shortcut, and I went the wrong way!

Let’s see how this stuff works in an example.

First let’s do a very simple circuit: a circuit with one input and one output, where the graph has one node and no edges. This is a degenerate case, so it may be sort of confusing, but it’s fundamental. This circuit is an identity morphism in the category Remember, a morphism in here is a cospan

In our example now, and are identity morphisms, and is a graph with one node and no edges—which is another way to think about a set with one point. This one-point set is also the set of terminals, It takes one number to describe the potential at this point and one number to describe the current flowing into this point from the input.

Since and are identity morphisms, it’s easy to check that steps 1) and 3) of my three-step procedure give identity morphisms. The only problem is step 2), so let’s look at that.

Since has no edges, no power is consumed by this circuit:

So, my recipe gives

This is not what we want! It correctly says that the potential at the input equals the potential at the output (since they’re the same point). But it incorrectly says the current at input and output are zero.

If we work out we get

and this is indeed the identity linear relation on