A generating function is a formal power series where the sequence of coefficients is the object of interest. Usually the point of using them is that operations on the power series (like addition, multiplication, and differentiation) correspond to meaningful operations on your sequence of coefficients.
I’ve known about the gist of generating functions for a while, and I’d always thought that the fact that differentiation was meaningful was just a magical coincidence (for some reason, addition and multiplication being meaningful didn’t seem as surprising to me).
But recently, Nathan Linger pointed out to me that over in the functional programming community, they have what I think is a very satisfying answer to this question (he said he got it from sigfpe’s blog, but I’m not sure what post, maybe this one?).
Combinatorial Species
I actually find the general concept of generating functions surprisingly slippery. André Joyal’s notion of a combinatorial species makes things more concrete for me. A combinatorial species is simply a functor from
to itself, where
is the category of finite sets and bijections. The idea is that, for a finite set
,
should be considered as the set of all structures of a certain kind on
.
For example: is the functor taking a set
to the set of all linear orders of elements of
, so
. Another example is
which takes
to the set of all trees on elements of
.
Each species has an associated generating function
where
(you could use any set of cardinality
instead of
.
It is now possible to make precise the fact that meaningful operations on species correspond to meaningful operations on generating functions. For example, if you define addition on species by letting be the disjoint union of
and
, then the generating function of the sum of two species is the sum of the generating functions. Similarly, multiplication on species is defined by letting
be a pair of an element of
and an element of
for some partition
, and it corresponds to multiplication of generating functions.
As mentioned before, there’s also an operation on species which corresponds to differentiation of the generating function. It corresponds to an addition of a “hole” in the structure. That is, , and
takes bijections on
to the output of
on the same bijection but fixing
.
This is a very powerful fact. For example, a linear order with a hole is the same thing as the product of two linear orders (the one to the left of the hole and the one to the right of the hole). If is the generating function of
, this gives us the equation
. Since we also know that
should be 1, this gives us
. Thus, if we didn’t know it already, we can deduce that there are
linear orders on
elements.
Furthermore, there is a notion of composition of species corresponding to composition of generating functions, where intuitively is a partition of
together with a
-structure on each element of the partition, and a
-structure on the partition as a whole.
So why is differentiation meaningful?
What is the connection between differentiation of species and ordinary differentiation? Two main ways of approaching ordinary differentiation are through limits or through infinitesimals. There don’t seem to be any limits around, so let’s focus on infinitesimals.
Although you can make infinitesimals precise in various ways, most people who think about calculus using infinitesimals do so in a non-rigorous way. Here’s one common non-rigorous principle:
Let
be such that
. Then for any (smooth, real-valued)
and real
,
.
Of course, there is no such in the standard definition of the real numbers.
Although this is non-rigorous, if we can translate the same non-rigorous principle over to species, that would give a good account of why differentiation shows up in generating functions. The main insight is what the meaning of should be. The condition that
for species simply means that there should be at least one
-structure on some set. The condition that
is subtler: it means that you can’t put a
-structure on two sets at the same time. As in the case with real numbers, this is impossible, but the reasoning works anyway so we’ll go with it.
Now let’s think about what means. An
-structure on a set is either an
-structure or a
-structure. By the definition of composition of species, an
-structure on a set
is a partition of
together with an
-structure on each element of the partition and an
-structure on the partition as a whole. This means that each element of the partition is given either an
-structure or a
-structure.
But, by the infinitesimal nature of , at most one element of the partition can be given a
structure. That means there are two cases: 0 elements of the partition have a
-structure or 1 does. If 0 elements do, every element of the partition has an
-structure, and the species is
. On the other hand, if one does, we can describe the species by saying which one does (with a hole in the
-structure) and what the
-structure was. That’s
. Therefore
!
Note that if we didn’t know what the formula for a species with a hole was, we could go through the preceding informal reasoning and deduce that it should correspond to the derivative! I don’t know if others are convinced, but I find this quite satisfying. To be totally clear, as mentioned before, this argument came from sigfpe’s blog and I don’t know if it has history before that.