I was reminded recently about something that took me an embarrassingly long time to realise: that the binomial expansion and the binomial distribution were intrinsically linked.

I mean, sure, obviously they both have an nCr in them, but what of it? It’s just Pascal’s triangle.

And then someone mentioned generating functions in a way that made sudden sense to me, and I hope I can do the same for you.

Let’s start with a concrete example

Suppose we roll four standard six-sided dice and want to know how likely we are to throw any given number of sixes. That’s simple enough:

Sixes Calculation Probability
0 4C0(16)0(56)4 0.482
1 4C1(16)1(56)3 0.386
2 4C2(16)2(56)2 0.116
3 4C3(16)3(56)1 0.015
4 4C4(16)4(56)0 0.001

Now, if we look at the binomial expansion of ((56)+(16)x)4, we get:

  • 4C0(16)0(56)4x0+
  • 4C1(16)1(56)3x1+
  • 4C2(16)2(56)2x2+
  • 4C3(16)3(56)1x3+
  • 4C4(16)4(56)0x4

… say look! Those calculations are identical. The coefficient of the xk term is the probability of rolling k sixes!

And this works in general – if you’ve got n trials, each with a probability of p, you want the coefficients of (q+px)n. If the probabilities are different but independent, you can work out (q1+p1x)(q2+p2x) in just the same way.

Other distributions

It turns out, you can do just the same thing for the geometric distribution: given XGeo(p), P(X=k)=pqk1.

What would our GF look like? gp(x)=px+pqx2+pq2x3+.

That looks a lot like, well, a geometric sequence. The first term is px and the common ratio is qx, so the sum of the series is gp(x)=px1qx. How lovely!

And the Poisson? Well, if YPo(λ), then P(Y=k)=eλλkk!.

If we write out the corresponding function, we get eλ(1+λx1+λ2x22!+), and that bracket is just eλx. The GF is pλ(x)=eλ(x1).

Sanity checks and means

A quick sanity check for GFs is to see whether the probabilities sum to one – and that’s easy: just put in x=1 and check the result is 1. (It is for all of these).

There’s also a quick way to figure out means: if you differentiate the generating function and put in x=1, the dark magic of GFs gives you the mean. Can you figure out why?