35

I understand the whole concept of Rencontres numbers but I can't understand how to prove this equation

$$D_{n,0}=\left[\frac{n!}{e}\right]$$

where $[\cdot]$ denotes the rounding function (i.e., $[x]$ is the integer nearest to $x$). This equation that I wrote comes from solving the following recursion, but I don't understand how exactly the author calculated this recursion.

$$\begin {align*} D_{n+2,0} & =(n+1)(D_{n+1,0}+D_{n,0}) \\ D_{0,0} & = 1 \\ D_{1,0} & = 0 \end {align*} $$

Piehead
  • 453

3 Answers3

66

Derangements:

A Derangement is a permutation, $P$, in which no element is mapped to itself; that is, $P(k)\ne k$, for $1\le k\le n$. Let $\mathcal{D}(n)$ be the number of derangements of $n$ items.

Here are a few methods of computing $\mathcal{D}(n)$.

Method 1 (build from smaller derangements):

Let us count the number of derangements of $n$ items so that $P(P(n))=n$. There are $n-1$ choices for $P(n)$, and for each of those choices, $\mathcal{D}(n-2)$ ways to arrange the other $n-2$ items. Thus, there are $(n-1)\mathcal{D}(n-2)$ derangements of $n$ items so that $P(P(n))=n$.

Let us count the number of derangements of $n$ items so that $P(P(n))\not=n$. There are $n-1$ choices for $P(n)$, and for each choice, there is a derangement of $n-1$ items identical to $P$ except that they map $P^{-1}(n)\to P(n)$. Thus, there are $(n-1)\mathcal{D}(n-1)$ derangements of $n$ items so that $P(P(n))\not=n$.

Therefore, $$ \mathcal{D}(n)=(n-1)(\mathcal{D}(n-1)+\mathcal{D}(n-2))\tag{1} $$ Method 2 (count permutations):

Count the number of permutations of $n$ items by counting how many fix exactly $k$ items.

There are $\binom{n}{k}$ ways to choose the $k$ items to fix, then $\mathcal{D}(n-k)$ ways to arrange the $n-k$ items that are not fixed. Since there are $n!$ permutations of $n$ items, we get $$ n!=\sum_{k=0}^n\binom{n}{k}\mathcal{D}(n-k)\tag{2} $$ and therefore, rearranging $(2)$ yields $$ \mathcal{D}(n)=n!-\sum_{k=1}^n\binom{n}{k}\mathcal{D}(n-k)\tag{3} $$ Method 3 (inclusion-exclusion):

Let $S_i$ be the set of permutations of $n$ items which fix item $i$. Then the number of permutations in $k$ of the $S_i$ would be the number of permutations that fix $k$ items. There are $\binom{n}{k}$ ways to choose the $k$ items to fix, and $(n-k)!$ ways to arrange the other $n-k$ items. Thus, the number of permutations that fix at least $1$ item would be $$ \sum_{k=1}^n(-1)^{k-1}\binom{n}{k}(n-k)!=\sum_{k=1}^n(-1)^{k-1}\frac{n!}{k!}\tag{4} $$ Since there are $n!$ permutations in total, the number of permutations that don't fix any items is $$ \begin{align} \mathcal{D}(n) &=n!-\sum_{k=1}^n(-1)^{k-1}\frac{n!}{k!}\\ &=\sum_{k=0}^n(-1)^k\frac{n!}{k!}\tag{5}\\ &\approx \frac{n!}{e} \end{align} $$ In fact, the difference $$ \begin{align} \left|\frac{n!}{e}-\mathcal{D}(n)\right| &=\left|\sum_{k=n+1}^\infty(-1)^k\frac{n!}{k!}\right|\\ &=\left|\frac{1}{n+1}-\frac{1}{(n+1)(n+2)}+\frac{1}{(n+1)(n+2)(n+3)}-\dots\right|\\ &<\frac{1}{n+1}\tag{6} \end{align} $$ This method yields directly that $\mathcal{D}(n)$ is the closest integer to $\frac{n!}{e}$ for $n>0$.

Derivation of the Closed Form from the Recursion:

Given $\mathcal{D}(0)=1$ and $\mathcal{D}(1)=0$, and the recursion $(1)$, let's derive $(5)$. Subtracting $n\mathcal{D}(n-1)$ from both sides of $(1)$ yields $$ \mathcal{D}(n)-n\mathcal{D}(n-1)=-(\mathcal{D}(n-1)-(n-1)\mathcal{D}(n-2))\tag{7} $$ Using the initial conditions, $(7)$ implies $$ \mathcal{D}(n)-n\mathcal{D}(n-1)=(-1)^n\tag{8} $$ Dividing both sides of $(8)$ by $n!$ yields $$ \frac{\mathcal{D}(n)}{n!}-\frac{\mathcal{D}(n-1)}{(n-1)!}=\frac{(-1)^n}{n!}\tag{9} $$ Equation $(9)$ is very simple to solve for $\frac{\mathcal{D}(n)}{n!}$: $$ \frac{\mathcal{D}(n)}{n!}=\sum_{k=0}^n\frac{(-1)^k}{k!}+C\tag{10} $$ Plugging $n=0$ into equation $(10)$ yields that $C=0$. Therefore, $$ \mathcal{D}(n)=n!\sum_{k=0}^n\frac{(-1)^k}{k!}\tag{11} $$


Incomplete Gamma Function: $$ \begin{align} \mathcal{D}(n) &=n!\sum_{k=0}^n\frac{(-1)^k}{k!}\tag{12a}\\ &=\sum_{k=0}^n(-1)^k\frac{n!}{k!}\tag{12b}\\ &=\sum_{k=0}^n(-1)^k\binom{n}{k}(n-k)!\tag{12c}\\ &=\sum_{k=0}^n(-1)^k\binom{n}{k}\int_0^\infty x^{n-k}e^{-x}\,\mathrm{d}x\tag{12d}\\ &=\int_0^\infty\sum_{k=0}^n\binom{n}{k}(-1)^kx^{n-k}e^{-x}\,\mathrm{d}x\tag{12e}\\ &=\int_0^\infty(x-1)^ne^{-x}\,\mathrm{d}x\tag{12f}\\ &=\frac1e\int_{-1}^\infty x^ne^{-x}\,\mathrm{d}x\tag{12g}\\ &=\frac1e\Gamma(n+1,-1)\tag{12h} \end{align} $$ Explanation:
$\text{(12a):}$ $(11)$
$\text{(12b):}$ bring the factor of $n!$ inside the sum
$\text{(12c):}$ $\frac{n!}{k!}=\binom{n}{k}(n-k)!$
$\text{(12d):}$ $n!=\int_0^\infty x^ne^{-x}\,\mathrm{d}x$
$\text{(12e):}$ swap the finite sum and the integral
$\text{(12f):}$ apply the Binomial Theorem
$\text{(12g):}$ substitute $x\mapsto x+1$
$\text{(12h):}$ $\Gamma(n,s)=\int_s^\infty x^{n-1}e^{-x}\,\mathrm{d}x$ is the Incomplete Gamma Function

Negative Integer Arguments:$\newcommand{\Ei}{\operatorname{Ei}}\newcommand{\PV}{\operatorname{PV}}$ $$ \begin{align} \mathcal{D}(-1) &=\frac1e\int_{-1}^\infty\frac{e^{-x}}x\,\mathrm{d}x\tag{13a}\\ &=-\frac{\Ei(1)+\pi i}e\tag{13b} \end{align} $$ Explanation:
$\text{(13a):}$ apply $\text{(12g)}$
$\text{(13b):}$ $\Ei(z)=-\PV\int_{-z}^\infty\frac{e^{-t}}{t}\,\mathrm{d}t$
$\phantom{\text{(13b):}}$ the infinitesimal clockwise semicircle
$\phantom{\text{(13b):}}$ around the singularity at $0$ gives $-\pi i$

For $n\ge2$, $$ \begin{align} \mathcal{D}(-n) &=\frac1e\int_{-1}^\infty x^{-n}e^{-x}\,\mathrm{d}x\tag{14a}\\ &=-\frac1{n-1}\frac1e\int_{-1}^\infty e^{-x}\,\mathrm{d}x^{1-n}\tag{14b}\\ &=-\frac1{n-1}\frac1e\left((-1)^ne+\int_{-1}^\infty x^{1-n}e^{-x}\mathrm{d}x\right)\tag{14c}\\ &=\frac{(-1)^{n-1}}{n-1}-\frac1{n-1}\frac1e\int_{-1}^\infty x^{1-n}e^{-x}\mathrm{d}x\tag{14d}\\ &=\frac{(-1)^{n-1}}{n-1}-\frac1{n-1}\mathcal{D}(1-n)\tag{14e} \end{align} $$ Explanation:
$\text{(14a):}$ apply $\text{(12g)}$
$\text{(14b):}$ prepare to integrate by parts
$\text{(14c):}$ integrate by parts
$\text{(14d):}$ distribute
$\text{(14e):}$ apply $\text{(12g)}$

Multiply $(14)$ by $(-1)^{n-1}(n-1)!$ and apply induction: $$ \begin{align} (-1)^{n-1}(n-1)!\mathcal{D}(-n) &=(n-2)!+(-1)^{n-2}(n-2)!\mathcal{D}(1-n)\tag{15a}\\ &=\sum_{k=0}^{n-2}k!+\mathcal{D}(-1)\tag{15b} \end{align} $$

Combine $(13)$ and $(15)$ and divide by $(-1)^{n-1}(n-1)!$: $$ \mathcal{D}(-n)=\frac{(-1)^{n-1}}{(n-1)!}\left(\sum_{k=0}^{n-2}k!-\frac{\Ei(1)+\pi i}e\right)\tag{16} $$

robjohn
  • 345,667
  • 8
    +1 for the nice survey on derangements. Two comments: 1) Your Method 1 is equivalent to my answer. 2) You might be interested in this paper of mine generalizing the derangement numbers. – Mike Spivey Nov 18 '11 at 22:07
  • 1
    @Mike: I didn't mean to step on any toes. However, I wanted to include $(1)$ because I was planning on using it to derive the closed form (I've just added said derivation). – robjohn Nov 18 '11 at 23:07
  • 3
    I just wanted to point it out. My toes didn't feel stepped on. :) – Mike Spivey Nov 18 '11 at 23:12
  • Nice. See also this question on finding the generating function for the derangements, which has some nice methods. – ShreevatsaR Feb 27 '14 at 05:16
  • Nice.... but you should define and clarify what you mean by $P( )$ and how it differs from ${\cal D}( )$ in the first method. – David G. Stork May 03 '16 at 20:01
  • @DavidG.Stork: I have made explicit mention of $P$ in the first paragraph. Does that help? – robjohn May 03 '16 at 20:27
  • Yes it does! Thanks. – David G. Stork May 03 '16 at 21:32
  • @robjohn - In your third method which uses PIE, what do you mean when you say " number of permutations in $k$ of the $S_i$ would be the permutations that fix $k$ items." If " number of permutations in $k$ of the $S_i$" means "permutations that fix $k$ items." so shouldn't there be $S_k$ instead of $S_i$. Also, in the second method, is $P$ mapped from the set having the elements to be deranged to that same set? – user350331 Dec 17 '16 at 06:20
  • @user350331: I have corrected the grammar; that phrase now reads, "the number of permutations in $k$ of the $S_i$ would be the number of permutations that fix $k$ items". The set of permutations $S_k$ are the set of permutations that fix element $k$, not that fix $k$ of the elements. – robjohn Dec 17 '16 at 09:12
  • @user350331: There is no $P$ in the second method. In the first method, $P$ is a permutation on a set of $n$ items. That means it maps that set back to itself, but does not fix any item. If you're confused by the fact that I've shortened $P(u_n)$ to $P(n)$ think of the set of items as the set of integers $1\le k\le n$. That is, $u_k=k$. – robjohn Dec 17 '16 at 09:20
  • @robjohn - Though your edit in the third method made it somewhat clear to me that you are referring to the no of ways of fixing the $k$ items of the $n$ items and not the $k^\text{th}$ item but, I still do not get what you mean when you say "Then the number of permutations in $k$ of the $S_i$ would be".... The main part that I don't get is what do you mean by " in $k$ of the $S_i$ ". The second method is clear now. – user350331 Dec 17 '16 at 09:29
  • 1
    @user350331: Inclusion-Exclusion says that the number of items in the union is $$\sum_{k=1}^n(-1)^{k-1}N(k)$$ where $N(k)$ is the sum of the number of items in all of the intersections of $k$ of the $S_i$. To count these, we multiply the number of intersections of $k$ of the $S_i$, $\binom{n}{k}$, by the size of each intersection of $k$ of the $S_i$, $(n-k)!$. – robjohn Dec 17 '16 at 09:59
  • @robjohn - it would be rather funny to say that to understand your last reply to the doubt that I presented was proving difficult for me to understand, hence I ended up trying to understand the phrase that I quoted before, which finally helped me understand your last reply. – user350331 Dec 17 '16 at 12:02
  • @MikeSpivey In your paper, $S_{n,k}$ is "number of ways to complete the exam & miss first $k$ questions ". I came across problem: $n$ men throw their hat at party & randomly select them, then number of ways none of them selects their own hat is derangements $D_n$, which you, in paper, say equals $S_{n,0}$. So I feel "$n-k$ men did not select their own hat equals $S_{n,k}$", right? However, I doubt how "first" in the first sentence in this comment fits in this equality, i.e. how "missing first $k$ questions out of $n$" equals "any $n-k$ men not selecting their own hat"? – RajS Aug 05 '17 at 20:25
  • I'm stucked at the moment where you say that $D_{n}$ is closest integer to n!/e, becouse difference is less than $1/(n+1)$. How do i know that? – Miokloń Nov 28 '17 at 00:24
  • 1
    @Miokloń: It's proven in $(6)$, which is mainly an application of the Alternating Series Test. – robjohn Nov 28 '17 at 02:05
  • @robjon: The test itself is also not enough because it states non-strict inequality for the bounds. For making it strict we should apply the facts that e is irrational, while D is integer and 1/(n+1) is rational. Then the possibility of strict equality to 1/2 (which might break the rounding to "wrong" side) will be eliminated. P.S. I also was stumbled onto this unobvious last inequality in (6) stated without any references to explanation. – Van Jone Aug 06 '19 at 02:13
  • 1
    @VanJone: Maybe I'm missing your point, but looking at $(6)$, the inequality is strict. Even if it were not, for $n\ge2$, $\frac1{n+1}\le\frac13\lt\frac12$ (strict), so it is the closest integer. – robjohn Aug 06 '19 at 03:11
  • Can we get explicit form of $\mathcal{D}(n)$ from $ \mathcal{D}(n)=n!-\sum_{k=1}^n\binom{n}{k}\mathcal{D}(n-k) $? Thank you. – Andrews Oct 06 '19 at 06:57
  • 1
    @Andrews: we might if we recall the identity $\sum\limits_{k=m}^n(-1)^{k-m}\binom{n}{k}\binom{k}{m}=[n=m]$, which is proven several different ways in this answer. Recall that $[\dots]$ are Iverson Brackets. – robjohn Oct 06 '19 at 08:01
21

(This argument is adapted from page 195 of Concrete Mathematics, Second Edition)

We start with the more conventional representation for the Rencontres number (subfactorial):

$$D_{n,0}=!n=n!\sum_{k=0}^n \frac{(-1)^k}{k!}$$

We also know that

$$\frac{n!}{e}=n!\sum_{k=0}^\infty \frac{(-1)^k}{k!}$$

The difference is

$$\begin{align*}\frac{n!}{e}-!n&=n!\sum_{k=n+1}^\infty \frac{(-1)^k}{k!}\\&=\frac{(-1)^{n+1}}{n+1}\left(1-\frac1{n+2}+\frac1{(n+2)(n+3)}-\cdots\right)\end{align*}$$

and since

$$\frac1{n+2} \leq \left|\frac{n!}{e}-!n\right| \leq \frac1{n+1}$$

along with knowing that $!n$ is an integer, rounding $n!/e$ to the nearest integer gives the subfactorial.


We have

$\small \begin{align}(n+2)!\sum_{k=0}^{n+2} \frac{(-1)^k}{k!}&=(n+1)\left[(n+1)!\sum_{k=0}^{n+1} \frac{(-1)^k}{k!}+n!\sum_{k=0}^n \frac{(-1)^k}{k!}\right]\\(n+2)(n+1)\sum_{k=0}^{n+2} \frac{(-1)^k}{k!}&=(n+1)\left[(n+1)\sum_{k=0}^{n+1} \frac{(-1)^k}{k!}+\sum_{k=0}^n \frac{(-1)^k}{k!}\right]\\(n+2)\sum_{k=0}^{n+2} \frac{(-1)^k}{k!}&=(n+1)\sum_{k=0}^{n+1} \frac{(-1)^k}{k!}+\sum_{k=0}^n \frac{(-1)^k}{k!}\\(n+2)\left(\frac{(-1)^{n+2}}{(n+2)!}+\frac{(-1)^{n+1}}{(n+1)!}+\sum_{k=0}^n \frac{(-1)^k}{k!}\right)&=\frac{(-1)^{n+1}}{n!}+(n+1)\sum_{k=0}^n \frac{(-1)^k}{k!}+\sum_{k=0}^n \frac{(-1)^k}{k!}\\(n+2)\left(\frac{(-1)^n}{(n+2)!}+\frac{(-1)^{n+1}}{(n+1)!}\right)+(n+2)\sum_{k=0}^n \frac{(-1)^k}{k!}&=\frac{(-1)^{n+1}}{n!}+(n+1)\sum_{k=0}^n \frac{(-1)^k}{k!}+\sum_{k=0}^n \frac{(-1)^k}{k!}\\(n+2)\left(\frac{(-1)^n}{(n+2)!}+\frac{(-1)^{n+1}}{(n+1)!}\right)&=\frac{(-1)^{n+1}}{n!}\\(-1)^n+(-1)^{n+1}(n+2)&=(-1)^{n+1}(n+1)\\1-(n+2)&=-(n+1)\end{align}$

and the last bit is easily established, thus proving the recursion relation for the Rencontres numbers.

14

Here's a different derivation. A derangement $D_n$ ($= D_{n,0}$) is a permutation of $n$ elements with no fixed points. We will prove an integral representation for $D_n$ that produces quick derivations of $D_n \approx n!/e$ and $D_n = n! \sum_{k=0}^n (-1)^k/k!.$

A combinatorial proof of the recurrence for $D_n$:

Here's a combinatorial proof of $D_n = (n-1)(D_{n-1} + D_{n-2})$ for $n \geq 2$ due to Euler.

For any derangement $(j_1, j_2, \ldots, j_n)$, we have $j_n \neq n$. Let $j_n = k$, where $k \in \{1, 2, \ldots, n-1\}$. We now break the derangements on $n$ elements into two cases.

Case 1: $j_k = n$ (so $k$ and $n$ map to each other). By removing elements $k$ and $n$ from the permutation we have a derangement on $n-2$ elements, and so, for fixed $k$, there are $D_{n-2}$ derangements in this case.

Case 2: $j_k \neq n$. Swap the values of $j_k$ and $j_n$, so that we have a new permutation with $j_k = k$ and $j_n \neq n$. By removing element $k$ we have a derangement on $n-1$ elements, and so, for fixed $k$, there are $D_{n-1}$ derangements in this case.

Thus, with $n-1$ choices for $k$, we have, for $n \geq 2$, $$D_n = (n-1)(D_{n-1} + D_{n-2}). \tag{1}$$

An integral representation for $D_n$:

It turns out that $$D_n = \int_0^{\infty} (t-1)^n e^{-t} dt. \tag{2}$$

(The similarity of $(2)$ with the integral representation for the factorial as a gamma function is perhaps another reason it makes sense to call the derangements the "subfactorials.")

We will prove $(2)$ by showing that the integral satisfies $(1)$. Let $R_n = \int_0^{\infty} (t-1)^n e^{-t} dt$.

Applying integration by parts yields $$R_n = (-1)^n + n R_{n-1} , \tag{3}$$ which is the recurrence $(8)$ in robjohn's answer. Applying the recurrence $(3)$ again with $R_{n-1}$ yields $$ \begin{align} R_n &= (-1)^n + (n-1)R_{n-1} + R_{n-1} \\ &= (-1)^n + (n-1)R_{n-1} + (-1)^{n-1} + (n-1)R_{n-2} \\ & = (n-1)(R_{n-1} + R_{n-2}). \end{align} $$ Since $R_0 = 1 = D_0$ and $R_1 = 0 = D_1$, Equation $(2)$ is established.

Equation $(2)$ is actually a special case of a more general result that says that the number of permutations with a specified set of fixed points can be represented by $\int_0^{\infty} R_{\tilde{G}}(t) e^{-t} dt$, where $\tilde{G}$ is the complement of $G$ in the complete bipartite graph on $n$ elements, and $R_G(t)$ is the associated rook polynomial for $G$. (See, for example, P. Mark Kayll, "Integrals Don't Have Anything to Do with Discrete Math, Do They?", Mathematics Magazine 84(2): 2011, 108-119.)

The approximation for $D_n$:

From $(2)$ we have $$ \begin{align} D_n &= \int_0^{\infty} (t-1)^n e^{-t} dt \\ &= \int_1^{\infty} (t-1)^n e^{-t} dt + \int_0^1 (t-1)^n e^{-t} dt \\ &= e^{-1} \int_0^{\infty} x^n e^{-x} dx + E_n \\ &= e^{-1} \Gamma(n+1) + E_n \\ &= \frac{n!}{e} + E_n. \end{align} $$ The quantity $E_n$ is small, too: $$|E_n| < \left|\int_0^1 (t-1)^n dt \right| = \frac{1}{n+1},$$ so that $$D_n \approx \frac{n!}{e}.$$

The explicit formula for $D_n$:

Again from $(2)$ we have $$ \begin{align} D_n &= \int_0^{\infty} (t-1)^n e^{-t} dt \\ &= \int_0^{\infty} \sum_{k=0}^n \binom{n}{k} (-1)^k t^{n-k} e^{-t} dt \\ &= \sum_{k=0}^n \binom{n}{k} (-1)^k \int_0^{\infty} t^{n-k} e^{-t} dt \\ &= n! \sum_{k=0}^n \frac{(-1)^k}{k! (n-k)!} \Gamma(n-k+1) \\ &= n! \sum_{k=0}^n \frac{(-1)^k}{k!}. \end{align} $$

(I learned these arguments from the Kayll paper referenced above.)

robjohn
  • 345,667
Mike Spivey
  • 55,550
  • 5
    A yearish late, but in the second step of the approximation of D_n, shouldn't the latter integral run from 0 to 1 instead of 0 to \infty? – Ian Eccles Aug 28 '12 at 15:12
  • @Ian: and in the estimate for $E_n$ that follows. Good eye! – robjohn Aug 28 '12 at 15:41
  • For the recursion solution, when j[k] != n, we are swapping j[k] and j[n] and then reducing the recursion to D(n-1) . But where is the proof that swapping doesn't change the number of derangements. Can we swap any number to any place and count derangements ? – Neer Patel Feb 16 '23 at 08:27