Analysis

The constant that counts what does not happen

Nothing grows in a shuffled pack of cards, and nothing grows in a factorial. Yet e sits in the middle of both — as the chance that a shuffle leaves nothing in place, and as the base that makes n! nearly a power.

Worth reading first: The curve that is its own slope · Nobody gets their own hat.

Everything about ee so far in this ladder has been about change. It is the base whose curve is its own slope, the point where an area reaches one, the solution of an equation about rates, the thing a matrix does over time. Growth, in four costumes.

This rung is about the places it turns up where nothing grows at all. There is no rate of change in a shuffled pack of cards and none in the number 12!, and ee is in the middle of both.

The share of arrangements that fix nothing, up to 8 objects. A bar per number of objects, giving the proportion of its arrangements that leave nothing in place, against the horizontal line at 1/e.
Fig. 1 For each number of objects, the proportion of arrangements that leave nothing in its own place. The bars settle onto the line at 1/e=0.36791/e = 0.3679, alternating above and below it, and are within a thousandth by seven objects. Every count is an exhaustive enumeration of all n!n! arrangements.

A shuffle that misses everything

Hand back nn hats to nn people at random. The chance that nobody gets their own is, for nn of any size at all, about 0.3679 — and it barely moves as nn grows. Four people and four hundred give nearly the same answer.

That constancy is the first surprise. Intuition suggests either that the chance should fall, because there are more ways to go wrong with more people, or rise, because each individual is less likely to meet their own hat. It does neither.

The count itself is settled by inclusion–exclusion: subtract the arrangements fixing at least one item, add back those fixing at least two, and so on. What comes out is

Dnn!=111!+12!13!+±1n!,\frac{D_n}{n!} = 1 - \frac{1}{1!} + \frac{1}{2!} - \frac{1}{3!} + \cdots \pm \frac{1}{n!},

and there is the whole answer. That alternating sum of reciprocal factorials is the series for exe^x evaluated at x=1x = -1, cut off after nn terms.

So the proportion is not approximately 1/e1/e in some vague asymptotic sense. It is the first n+1n+1 terms of the series for 1/e1/e, exactly, which is why the convergence is so fast — the error is the next term, at most 1/(n+1)!1/(n+1)!, and by seven objects that is under a two-hundred-thousandth.

The alternating sum for 5 objects. One bar per term: all 120 arrangements, less those fixing one object, plus those fixing two, and so on down to 44.
Fig. 2 The inclusion–exclusion count for five objects, drawn as the alternating sum it is. Each column is the number of arrangements fixing at least that many items, and the signs alternate because every arrangement fixing kk things is counted once for each subset of those kk. What is left at the end is 44, and 44/120 is 0.3667.

Why the exponential is there at all

It is worth asking what a series about growth is doing in a counting problem, and the answer is short: it is not a series about growth. The series is a fact about the numbers 1/k!1/k!, and the reciprocal factorials appear here because kk items can be chosen and permuted in (nk)(nk)!\binom{n}{k}(n-k)! ways, and that ratio to n!n! is 1/k!1/k!.

The exponential’s series is, in this reading, the generating function that counts labelled structures: dividing by k!k! is exactly what is done when the order of a chosen set is irrelevant, and every counting problem in which pieces are chosen and then ignored produces reciprocal factorials. So ee turns up in counting for the same structural reason it turns up in growth — both are about 1/k!1/k! — and the two subjects meet in the series rather than in any shared idea about rates.

There is a matching probabilistic reading, which is the one worth carrying. Each person has probability 1/n1/n of receiving their own hat, and the events are nearly independent. If they were exactly independent, the chance of all nn missing would be (11/n)n(1 - 1/n)^n, which is the compound-interest limit and tends to 1/e1/e. The events are not independent — the hats are handed out without replacement — and the remarkable thing is that the dependence cancels to a far higher order than it has any right to.

Compounding toward e. Interest compounded 1, 2, 4, 12 and 365 times a year, each staircase ending a little higher than the last, and the last of them within 0.0037 of e.
Fig. 3 The limit that the independent-events argument would give: (11/n)n(1 - 1/n)^n is the mirror of this staircase, climbing toward 1/e1/e as the year is split more finely. The true derangement proportion is not this quantity, and agrees with it to a very great many decimal places.

The distribution behind the constant

There is a way of seeing the whole thing at once, and it explains the alternation as well as the limit.

Count how many people get their own hat. The expected number is exactly 1, whatever nn is: each person contributes 1/n1/n and there are nn of them, and expectation adds up whether or not the events are independent. The variance is also exactly 1. And as nn grows, the whole distribution of that count settles onto the Poisson distribution with mean 1, whose probability of zero is e1e^{-1}.

So the derangement proportion is one entry of a limiting distribution, and the other entries are just as tidy: the chance that exactly one person gets their own hat also tends to 1/e1/e, the chance that exactly two do tends to 1/(2e)1/(2e), and in general exactly kk tends to 1/(k!e)1/(k!\,e). Those are the Poisson probabilities, and they sum to 1 because the series for ee does.

That reframing turns the constant from a curiosity into an instance. The Poisson distribution is what a large number of rare, nearly-independent chances produces, and eλe^{-\lambda} is in every one of its probabilities. Derangements are the case λ=1\lambda = 1, and the reason λ=1\lambda = 1 is that the expected number of fixed points is exactly one for every nn — a coincidence of the problem that makes the answer a clean 1/e1/e rather than a clean eλe^{-\lambda} for some less memorable λ\lambda.

The other place, where a factorial is nearly a power

The second appearance is inside the factorial itself.

n!n! grows faster than any exponential and is awkward to work with for exactly that reason: it has no closed form, and estimating it matters constantly, since it is the denominator of every probability in every counting problem. The estimate is

n!(ne)n2πn,n! \approx \left(\frac{n}{e}\right)^n\sqrt{2\pi n},

which is Stirling’s approximation, and it contains both ee and π\pi in a statement about multiplying whole numbers together.

The factorial, and the formula with e inside it. A table of n, n factorial, the value of (n/e)ⁿ√(2πn), their ratio and n times the excess, for n up to 12; the ratio falls from 1.0844 to 1.006967.
Fig. 4 Every factorial up to 12, multiplied out, beside the value of (n/e)n2πn(n/e)^n\sqrt{2\pi n}. The ratio starts at 1.0844 and falls to 1.006967, and the last column — nn times the excess — sits at 0.0836 all the way down, which is one twelfth. That constancy is the next term of the expansion showing itself.

The ee has a clean origin and it is worth extracting, because the derivation explains the shape of the answer.

Take logarithms: lnn!=ln1+ln2++lnn\ln n! = \ln 1 + \ln 2 + \cdots + \ln n, a sum which is approximated by the area under lnx\ln x from 1 to nn — and that area is nlnnn+1n\ln n - n + 1. Exponentiating,

n!enlnnn=nnen=(ne)n.n! \approx e^{n\ln n - n} = \frac{n^n}{e^n} = \left(\frac{n}{e}\right)^n.

The ene^{-n} is the n-n in the integral of the logarithm, nothing more. It comes from the fact that lnxdx=xlnxx\int \ln x\,dx = x\ln x - x, and the x-x is there because differentiating xlnxx\ln x produces an unwanted +1+1 that has to be cancelled. That is the whole of why ee appears in Stirling’s formula, and the area under a curve is again the mechanism.

The 2πn\sqrt{2\pi n} is a different and harder story, which is where the bell curve comes in: it is the width of the peak of the integrand in an integral representation of the factorial, and the 2π\sqrt{2\pi} is the normalising constant of the normal distribution. Two constants, two mechanisms, one formula.

All 24 arrangements of 4 objects, and the 9 that move every one. Every permutation of 4 objects drawn as a grid of cells, with the diagonal — where an object stays where it began — shaded, and the arrangements that avoid it entirely marked.
Fig. 5 Every one of the twenty-four arrangements of four objects, with the nine that leave nothing in place picked out. Nine over twenty-four is 0.375, which is already within seven thousandths of 1/e1/e — at four objects, by exhaustion, with no series involved.

The smallest cases are worth having in front of the eye because they make the speed of the convergence concrete. One object: no derangements, proportion 0. Two: one out of two, proportion 0.5. Three: two out of six, 0.3333. Four: nine out of twenty-four, 0.375. Five: forty-four out of a hundred and twenty, 0.3667. The sequence is already oscillating tightly about 0.3679 by the time it can still be counted by hand, which is what an alternating series with factorial denominators does.

How good, and in what sense

The word “approximation” is doing something specific here and it is easy to get backwards. The difference n!(n/e)n2πnn! - (n/e)^n\sqrt{2\pi n} grows without bound — at n=12n = 12 it is over three million. What shrinks is the ratio, which is what the table measures, and it shrinks like 1+1/(12n)1 + 1/(12n).

That distinction is not pedantry. Stirling’s formula is used to estimate ratios of factorials — binomial coefficients, probabilities, entropies — and in a ratio the errors partly cancel. Used to estimate a factorial itself to within a fixed number, it is useless for any nn worth using it for.

The last column of the table above is the check that the error really behaves as claimed. nn times the relative excess sits at about 0.0836 for every row, and 1/12=0.08331/12 = 0.0833. The figure asserts that agreement rather than displaying it, which is what turns a table into evidence: a formula predicting 1/(12n)1/(12n) makes a claim about that column being flat, and a flat column is something a reader can see and a check can fail on.

The factorial, and the formula with e inside it. A table of n, n factorial, the value of (n/e)ⁿ√(2πn), their ratio and n times the excess, for n up to 18; the ratio falls from 1.0844 to 1.004640.
Fig. 6 The same table taken further. The ratio has fallen to 1.004640 by eighteen and the last column has not moved: still 0.08352, still one twelfth. A correction term is confirmed by a column that stays where it is, which is a more convincing display than a curve approaching a line.

A number nobody would guess

It is worth dwelling on how unhelpful intuition is here, because the failure is instructive.

Asked for the chance that a random shuffle of a large pack leaves no card in its own place, most people offer either a number near zero or a number near one, on the reasoning that with fifty-two chances something is bound to match, or that each individual match is unlikely. Both reasonings are sound and both point at the boundary; the answer sits at 0.37, near neither.

The resolution is that the expected number of matches is exactly 1 — not large, not small — and a count with mean 1 is neither reliably zero nor reliably positive. The whole of the surprise is that the expected number does not depend on nn: more people means more chances and each chance correspondingly rarer, and the two effects cancel exactly rather than approximately.

That exact cancellation is the fact worth carrying away, and it is the reason the answer is a constant rather than a function of nn. Whenever a count’s mean is pinned at a fixed value by two effects trading off, a Poisson limit and a power of ee are what to expect.

What the two have in common

Two appearances of ee in problems about counting, and it is fair to ask whether they have anything to do with each other beyond the letter.

They do, and the common object is the series. Both derivations pass through the same place: the derangement count is the truncated series for e1e^{-1}, and Stirling’s derivation goes through ee because the integral of a logarithm produces a linear term that exponentiates. Underneath both is the fact that exe^x is the function whose nn-th derivative is itself, so its series has 1/n!1/n! in it — and 1/n!1/n! is what appears whenever an ordering is imposed and then discarded.

That is a genuine explanation rather than a coincidence, and it also predicts where else to look. Any counting problem in which kk things are selected and then their order forgotten will produce reciprocal factorials, and any such sum evaluated at ±1\pm 1 will produce a power of ee. The number of permutations with no cycle shorter than kk; the distribution of the number of fixed points, which is Poisson with mean one; the probability that a random function has no small cycle — all of them are the same series read at different points.

The share of arrangements that fix nothing, up to 10 objects. A bar per number of objects, giving the proportion of its arrangements that leave nothing in place, against the horizontal line at 1/e.
Fig. 7 The same proportions taken to ten objects. The alternation about 1/e1/e continues and the bars become indistinguishable from the line, which is the visible form of an error bounded by the next term of a factorial series.

Where else it turns up in counting

Once the mechanism is named — reciprocal factorials, from choosing and then forgetting the order — the same constant becomes predictable in places that look unconnected.

The secretary problem. Interviewing candidates one at a time and hiring the first that beats everything seen so far, the best strategy is to reject the first fraction 1/e1/e of them and then take the next record. The chance of getting the best candidate is also 1/e1/e. The ee arrives from an integral of 1/x1/x, which is the area from the second rung of this ladder, and the essay on when to stop looking works it out.

Records in a random sequence. The expected number of times a running maximum is beaten in nn draws is 1+1/2++1/n1 + 1/2 + \cdots + 1/n, which grows like lnn\ln n — the same logarithm, in a problem with no growth in it either.

Random permutations generally. The chance that a random permutation of nn things has no cycle of length one is 1/e1/e; the chance it has no cycle of length two tends to e1/2e^{-1/2}; and in general the number of kk-cycles is Poisson with mean 1/k1/k. The whole cycle structure of a random permutation is governed by a family of these constants, and the harmonic sum turns up again as the expected number of cycles.

Three problems about arrangements, three appearances of the same constant, and in none of them is anything increasing.

What the picture cannot show

The bars in the hero figure are exact counts, taken by enumerating every arrangement, and they stop at eight because 9!9! arrangements are more than a figure can enumerate honestly on a page and 12!12! is a wall. The claim being made is about all nn, and the picture shows the first eight — which is exactly the situation the site’s standing warning about small cases is about. What rescues it here is that the closed form is exact and elementary, so the pattern is proved rather than extrapolated.

Stirling’s table has a subtler limit. It shows the ratio approaching 1 and cannot show that the sequence of corrections1/(12n)1/(12n), then 1/(288n2)1/(288n^2), and so on — is a series that diverges. Adding more correction terms improves the estimate up to a point and then makes it worse without bound, which is characteristic of asymptotic expansions and is invisible in any table of the first few. A picture of a good approximation getting better says nothing about what happens if the improvement is pursued.

The ladder from here

Rungs above: the Poisson distribution, of which the derangement count is one instance, and where eλe^{-\lambda} appears for the same reason. Asymptotic series, and why an expansion can be divergent and still be the right tool. Stirling’s formula proved by Laplace’s method, where the 2π\sqrt{2\pi} is earned. The Gaussian integral, which is where the π\sqrt{\pi} comes from in the first place. And the exponential generating functions of which this essay’s series is the simplest example.

The lesson worth keeping

The instinct on meeting ee in a problem about shuffling is to look for something growing, and there is nothing growing. That instinct comes from meeting the constant first as a rate of growth, which is a historical accident of how the subject is taught rather than a fact about the number.

What ee actually is, underneath every one of its appearances, is the sum of the reciprocal factorials. Growth is one consequence of that; counting is another; and neither is more fundamental. A constant met in one setting will keep turning up in others, and the reliable way to see why is to find the arithmetic identity that all its appearances pass through, rather than to look for the first setting hiding inside the later ones.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A dashed tag is an object no other essay names yet.

ApproximationCounting argumentDerangemente, the numberFactorialInclusion exclusionLimitPower seriesProbabilityStirling approximation