thumb|305px|Number of possible permutations and derangements of elements. ( [[factorial) is the number of -permutations; is the number of derangements – -permutations where all of the elements change their initial places.]]
In combinatorial mathematics, a derangement is a permutation of the elements of a set in which no element appears in its original position. In other words, a derangement is a permutation that has no fixed points.
The number of derangements of a set of size is known as the derangement number or the subfactorial of or de Montmort number (after Pierre Remond de Montmort). Notations for subfactorials in common use include , , , or .
For , the subfactorial equals the nearest integer to , where denotes the factorial of and is Euler's number. in 1708; he solved it in 1713, as did Nicholas Bernoulli at about the same time.
Example
thumb|right|The 9 derangements (from 24 permutations) are highlighted.
Suppose that a professor gave a test to 4 students – A, B, C, and D – and wants to let them grade each other's tests. How many ways could the professor hand the tests back to the students for grading, such that no student receives their own test back? Out of 24 possible permutations (4!) for handing back the tests,
:{| style="font:125% monospace;line-height:1;border-collapse:collapse;"
|<span style="color:red;font-weight:bold;">ABCD</span>,
|<span style="color:red;font-weight:bold;">AB</span>DC,
|<span style="color:red;font-weight:bold;">A</span>CB<span style="color:red;font-weight:bold;">D</span>,
|<span style="color:red;font-weight:bold;">A</span>CDB,
|<span style="color:red;font-weight:bold;">A</span>DBC,
|<span style="color:red;font-weight:bold;">A</span>D<span style="color:red;font-weight:bold;">C</span>B,
|-
|BA<span style="color:red;font-weight:bold;">CD</span>,
|<span style="color:deepskyblue;font-style:italic;">BADC</span>,
|BCA<span style="color:red;font-weight:bold;">D</span>,
|<span style="color:deepskyblue;font-style:italic;">BCDA</span>,
|<span style="color:deepskyblue;font-style:italic;">BDAC</span>,
|BD<span style="color:red;font-weight:bold;">C</span>A,
|-
|CAB<span style="color:red;font-weight:bold;">D</span>,
|<span style="color:deepskyblue;font-style:italic;">CADB</span>,
|C<span style="color:red;font-weight:bold;">B</span>A<span style="color:red;font-weight:bold;">D</span>,
|C<span style="color:red;font-weight:bold;">B</span>DA,
|<span style="color:deepskyblue;font-style:italic;">CDAB</span>,
|<span style="color:deepskyblue;font-style:italic;">CDBA</span>,
|-
|<span style="color:deepskyblue;font-style:italic;">DABC</span>,
|DA<span style="color:red;font-weight:bold;">C</span>B,
|D<span style="color:red;font-weight:bold;">B</span>AC,
|D<span style="color:red;font-weight:bold;">BC</span>A,
|<span style="color:deepskyblue;font-style:italic;">DCAB</span>,
|<span style="color:deepskyblue;font-style:italic;">DCBA</span>.
|}
there are only 9 derangements (shown in blue italics above). In every other permutation of this 4-member set, at least one student gets their own test back (shown in bold red).
Another version of the problem arises when we ask for the number of ways n letters, each addressed to a different person, can be placed in n pre-addressed envelopes so that no letter appears in the correctly addressed envelope.
Counting derangements
Counting derangements of a set amounts to the hat-check problem, in which one considers the number of ways in which n hats (call them h<sub>1</sub> through h<sub>n</sub>) can be returned to n people (P<sub>1</sub> through P<sub>n</sub>) such that no hat makes it back to its owner.
Each person may receive any of the n − 1 hats that is not their own. Call the hat which the person P<sub>1</sub> receives h<sub>i</sub> and consider h<sub>i</sub>s owner: P<sub>i</sub> receives either P<sub>1</sub>'s hat, h<sub>1</sub>, or some other. Accordingly, the problem splits into two possible cases:
- P<sub>i</sub> receives a hat other than h<sub>1</sub>. This case is equivalent to solving the problem with n − 1 people and n − 1 hats because for each of the n − 1 people besides P<sub>1</sub> there is exactly one hat from among the remaining n − 1 hats that they may not receive (for any P<sub>j</sub> besides P<sub>i</sub>, the unreceivable hat is h<sub>j</sub>, while for P<sub>i</sub> it is h<sub>1</sub>). Another way to see this is to rename h<sub>1</sub> to h<sub>i</sub>, where the derangement is more explicit: for any j from 2 to n, P<sub>j</sub> cannot receive h<sub>j</sub>.
- P<sub>i</sub> receives h<sub>1</sub>. In this case the problem reduces to n − 2 people and n − 2 hats, because P<sub>1</sub> received h<sub>i</sub>s hat and P<sub>i</sub> received h<sub>1</sub>'s hat, effectively putting both out of further consideration.
For each of the n − 1 hats that P<sub>1</sub> may receive, the number of ways that P<sub>2</sub>, ..., P<sub>n</sub> may all receive hats is the sum of the counts for the two cases.
This gives us the solution to the hat-check problem: Stated algebraically, the number <math>D_n</math> of derangements of an n-element set is
<math display="block">D_n = \left( n - 1 \right) \bigl({!\left( n - 1 \right)} + {!\left( n - 2 \right)}\bigr)</math> for <math> n \geq 2</math>,
where <math>!0 = 1</math> and <math>!1 = 0.</math>
The number of derangements of small lengths is given in the table below.
{| class="wikitable"
|+ The number of derangements of an n-element set for small n
|- style="text-align: center;"
! n
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13
|-
! <math>D_n</math>
| 1 || 0 || 1 || 2 || 9 || 44 || 265 || 1,854 || 14,833 || 133,496 || 1,334,961 || 14,684,570 || 176,214,841 || 2,290,792,932
|}
There are various other expressions for <math>D_n</math>, equivalent to the formula given above. These include
<math display="block">D_n = n! \sum_{i=0}^n \frac{(-1)^i}{i!}</math> for <math> n \geq 0</math>
and
:<math>D_n = \left[ \frac{n!}{e} \right] = \left\lfloor\frac{n!}{e}+\frac{1}{2}\right\rfloor</math> for <math>n \geq 1,</math>
where <math>\left[ x\right]</math> is the nearest integer function and <math>\left\lfloor x \right\rfloor</math> is the floor function.
<math display="block">D_n = \left\lfloor \frac{n!+1}{e} \right\rfloor,\quad\ n \ge 1,</math>
<math display="block">D_n = \left\lfloor \left(e + e^{-1}\right)n!\right\rfloor - \lfloor en!\rfloor,\quad n \geq 2,</math>
and
<math display="block">D_n = n! - \sum_{i=1}^n {n \choose i} \cdot {!(n - i)},\quad\ n \ge 1.</math>
The following recurrence also holds:
Growth of number of derangements as n approaches ∞
From
<math display="block">D_n = n! \sum_{i=0}^n \frac{(-1)^i}{i!}</math>
and
<math display="block">e^x = \sum_{i=0}^\infty {x^i \over i!}</math>
by substituting <math display="inline"> x = -1</math> one immediately obtains that
<math display="block"> \lim_{n\to\infty} {D_n \over n!} = \lim_{n\to\infty} \sum_{i=0}^n \frac{(-1)^i}{i!} = e^{-1} \approx 0.367879\ldots.</math>
This is the limit of the probability that a randomly selected permutation of a large number of objects is a derangement. The probability converges to this limit extremely quickly as increases, which is why <math>D_n</math> is the nearest integer to The above semi-log graph shows that the derangement graph lags the permutation graph by an almost constant value.
More information about this calculation and the above limit may be found in the article on the
statistics of random permutations.
Asymptotic expansion in terms of Bell numbers
An asymptotic expansion for the number of derangements in terms of Bell numbers is as follows:
<math display="block">D_n = \frac{n!}{e} + \sum_{k=1}^m \left(-1\right)^{n+k-1}\frac{B_k}{n^k} + O\left(\frac{1}{n^{m+1\right),</math>
where <math>m</math> is any fixed positive integer, and <math>B_k</math> denotes the <math>k</math>-th Bell number. Moreover, the constant implied by the big O-term does not exceed <math>B_{m+1}</math>.
Generalizations
The problème des rencontres asks how many permutations of a size-n set have exactly k fixed points.
Derangements are an example of the wider field of constrained permutations. For example, the ménage problem asks if n opposite-sex couples are seated man-woman-man-woman-... around a table, how many ways can they be seated so that nobody is seated next to his or her partner?
More formally, given sets A and S, and some sets U and V of surjections A → S, we often wish to know the number of pairs of functions (f, g) such that f is in U and g is in V, and for all a in A, f(a) ≠ g(a); in other words, where for each f and g, there exists a derangement φ of S such that f(a) = φ(g(a)).
Another generalization is the following problem:
:How many anagrams with no fixed letters of a given word are there?
For instance, for a word made of only two different letters, say n letters A and m letters B, the answer is, of course, 1 or 0 according to whether n = m or not, for the only way to form an anagram without fixed letters is to exchange all the A with B, which is possible if and only if n = m. In the general case, for a word with n<sub>1</sub> letters X<sub>1</sub>, n<sub>2</sub> letters X<sub>2</sub>, ..., n<sub>r</sub> letters X<sub>r</sub>, it turns out (after a proper use of the inclusion-exclusion formula) that the answer has the form
<math display="block"> \int_0^\infty P_{n_1}(x) P_{n_2}(x) \cdots P_{n_r}(x)\ e^{-x} dx,</math>
for a certain sequence of polynomials P<sub>n</sub>, where P<sub>n</sub> has degree n. But the above answer for the case r = 2 gives an orthogonality relation, whence the P<sub>n</sub><nowiki>'</nowiki>s are the Laguerre polynomials (up to a sign that is easily decided).
thumb|<math>\ \int_0^\infty(t-1)^ze^{-t}dt\ </math> in the complex plane
In particular, for the classical derangements, one has that
<math display="block"> D_n = \frac{ \Gamma(n+1,-1) }{ e } = \int_0^\infty(x - 1)^n e^{-x} dx </math>
where <math>\Gamma(s,x)</math> is the upper incomplete gamma function.
Computational complexity
It is NP-complete to determine whether a given permutation group (described by a given set of permutations that generate it) contains any derangements.
: {| class="wikitable collapsible collapsed" style="margin:0; width:100%"
|+ Table of factorial and derangement values<span id="derangements_and_factorials_0_30" class="anchor"></span>
|-
! scope="col" | <math>n</math>
! scope="col" class="nowrap" | Permutations, <math>n!</math>
! scope="col" class="nowrap" | Derangements, <math>D_n</math>
! scope="col" | <math>\frac{D_n}{n!}</math>
|-
| style="text-align: center" | 0
| 1
<span style="font-size:80%; float:right;">=1×10<sup>0</sup></span>
| 1
<span style="font-size:80%; float:right;">=1×10<sup>0</sup></span>
| = 1
|-
| style="text-align: center" | 1
| 1
<span style="font-size:80%; float:right;">=1×10<sup>0</sup></span>
| 0
| = 0
|-
| style="text-align: center" | 2
| 2
<span style="font-size:80%; float:right;">=2×10<sup>0</sup></span>
| 1
<span style="font-size:80%; float:right;">=1×10<sup>0</sup></span>
| = 0.5
|-
| style="text-align: center" | 3
| 6
<span style="font-size:80%; float:right;">=6×10<sup>0</sup></span>
| 2
<span style="font-size:80%; float:right;">=2×10<sup>0</sup></span>
|align="right"| ≈0.33333 33333
|-
| style="text-align: center" | 4
| 24
<span style="font-size:80%; float:right;">=2.4×10<sup>1</sup></span>
| 9
<span style="font-size:80%; float:right;">=9×10<sup>0</sup></span>
| = 0.375
|-style="border-top:2px solid #aaaaaa;"
| style="text-align: center" | 5
| 120
<span style="font-size:80%; float:right;">=1.20×10<sup>2</sup></span>
| 44
<span style="font-size:80%; float:right;">=4.4×10<sup>1</sup></span>
|align="right"| ≈0.36666 66667
|-
| style="text-align: center" | 6
| 720
<span style="font-size:80%; float:right;">=7.20×10<sup>2</sup></span>
| 265
<span style="font-size:80%; float:right;">=2.65×10<sup>2</sup></span>
|align="right"| ≈0.36805 55556
|-
| style="text-align: center" | 7
| 5,040
<span style="font-size:80%; float:right;">=5.04×10<sup>3</sup></span>
| 1,854
<span style="font-size:80%; float:right;">≈1.85×10<sup>3</sup></span>
|align="right"| ≈0.36785,71429
|-
| style="text-align: center" | 8
| 40,320
<span style="font-size:80%; float:right;">≈4.03×10<sup>4</sup></span>
| 14,833
<span style="font-size:80%; float:right;">≈1.48×10<sup>4</sup></span>
|align="right"| ≈0.36788 19444
|-
| style="text-align: center" | 9
| 362,880
<span style="font-size:80%; float:right;">≈3.63×10<sup>5</sup></span>
| 133,496
<span style="font-size:80%; float:right;">≈1.33×10<sup>5</sup></span>
|align="right"| ≈0.36787 91887
|-style="border-top:2px solid #aaaaaa;"
| style="text-align: center" | 10
| 3,628,800
<span style="font-size:80%; float:right;">≈3.63×10<sup>6</sup></span>
| 1,334,961
<span style="font-size:80%; float:right;">≈1.33×10<sup>6</sup></span>
|align="right"| ≈0.36787 94643
|-
| style="text-align: center" | 11
| 39,916,800
<span style="font-size:80%; float:right;">≈3.99×10<sup>7</sup></span>
| 14,684,570
<span style="font-size:80%; float:right;">≈1.47×10<sup>7</sup></span>
|align="right"| ≈0.36787 94392
|-
| style="text-align: center" | 12
| 479,001,600
<span style="font-size:80%; float:right;">≈4.79×10<sup>8</sup></span>
| 176,214,841
<span style="font-size:80%; float:right;">≈1.76×10<sup>8</sup></span>
|align="right"| ≈0.36787 94413
|-
| style="text-align: center" | 13
| 6,227,020,800
<span style="font-size:80%; float:right;">≈6.23×10<sup>9</sup></span>
| 2,290,792,932
<span style="font-size:80%; float:right;">≈2.29×10<sup>9</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 14
| 87,178,291,200
<span style="font-size:80%; float:right;">≈8.72×10<sup>10</sup></span>
| 32,071,101,049
<span style="font-size:80%; float:right;">≈3.21×10<sup>10</sup></span>
|align="right"| ≈0.36787 94412
|-style="border-top:2px solid #aaaaaa;"
| style="text-align: center" | 15
|style="font-size:80%;"| 1,307,674,368,000
<span style="float:right;">≈1.31×10<sup>12</sup></span>
|style="font-size:80%;"| 481,066,515,734
<span style="float:right;">≈4.81×10<sup>11</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 16
|style="font-size:80%;"| 20,922,789,888,000
<span style="float:right;">≈2.09×10<sup>13</sup></span>
|style="font-size:80%;"| 7,697,064,251,745
<span style="float:right;">≈7.70×10<sup>12</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 17
|style="font-size:80%;"| 355,687,428,096,000
<span style="float:right;">≈3.56×10<sup>14</sup></span>
|style="font-size:80%;"| 130,850,092,279,664
<span style="float:right;">≈1.31×10<sup>14</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 18
|style="font-size:80%;"| 6,402,373,705,728,000
<span style="float:right;">≈6.40×10<sup>15</sup></span>
|style="font-size:80%;"| 2,355,301,661,033,953
<span style="float:right;">≈2.36×10<sup>15</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 19
|style="font-size:80%;"| 121,645,100,408,832,000
<span style="float:right;">≈1.22×10<sup>17</sup></span>
|style="font-size:80%;"| 44,750,731,559,645,106
<span style="float:right;">≈4.48×10<sup>16</sup></span>
|align="right"| ≈0.36787 94412
|-style="border-top:2px solid #aaaaaa;"
| style="text-align: center" | 20
|style="font-size:80%;"| 2,432,902,008,176,640,000
<span style="float:right;">≈2.43×10<sup>18</sup></span>
|style="font-size:80%;"| 895,014,631,192,902,121
<span style="float:right;">≈8.95×10<sup>17</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 21
|style="font-size:80%;"| 51,090,942,171,709,440,000
<span style="float:right;">≈5.11×10<sup>19</sup></span>
|style="font-size:80%;"| 18,795,307,255,050,944,540
<span style="float:right;">≈1.88×10<sup>19</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 22
|style="font-size:80%;"| 1,124,000,727,777,607,680,000
<span style="float:right;">≈1.12×10<sup>21</sup></span>
|style="font-size:80%;"| 413,496,759,611,120,779,881
<span style="float:right;">≈4.13×10<sup>20</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 23
|style="font-size:80%;"| 25,852,016,738,884,976,640,000
<span style="float:right;">≈2.59×10<sup>22</sup></span>
|style="font-size:80%;"| 9,510,425,471,055,777,937,262
<span style="float:right;">≈9.51×10<sup>21</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 24
|style="font-size:80%;"| 620,448,401,733,239,439,360,000
<span style="float:right;">≈6.20×10<sup>23</sup></span>
|style="font-size:80%;"| 228,250,211,305,338,670,494,289
<span style="float:right;">≈2.28×10<sup>23</sup></span>
|align="right"| ≈0.36787 94412
|-style="border-top:2px solid #aaaaaa;"
| style="text-align: center" | 25
|style="font-size:80%;"| 15,511,210,043,330,985,984,000,000
<span style="float:right;">≈1.55×10<sup>25</sup></span>
|style="font-size:80%;"| 5,706,255,282,633,466,762,357,224
<span style="float:right;">≈5.71×10<sup>24</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 26
|style="font-size:80%;"| 403,291,461,126,605,635,584,000,000
<span style="float:right;">≈4.03×10<sup>26</sup></span>
|style="font-size:80%;"| 148,362,637,348,470,135,821,287,825
<span style="float:right;">≈1.48×10<sup>26</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 27
|style="font-size:80%;"| 10,888,869,450,418,352,160,768,000,000
<span style="float:right;">≈1.09×10<sup>28</sup></span>
|style="font-size:80%;"| 4,005,791,208,408,693,667,174,771,274
<span style="float:right;">≈4.01×10<sup>27</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 28
|style="font-size:80%;"| 304,888,344,611,713,860,501,504,000,000
<span style="float:right;">≈3.05×10<sup>29</sup></span>
|style="font-size:80%;"| 112,162,153,835,443,422,680,893,595,673
<span style="float:right;">≈1.12×10<sup>29</sup></span>
|align="right"| ≈0.36787 94412
|-
| style="text-align: center" | 29
|style="font-size:80%;"| 8,841,761,993,739,701,954,543,616,000,000
<span style="float:right;">≈8.84×10<sup>30</sup></span>
|style="font-size:80%;"| 3,252,702,461,227,859,257,745,914,274,516
<span style="float:right;">≈3.25×10<sup>30</sup></span>
|align="right"| ≈0.36787 94412
|-style="border-top:2px solid #aaaaaa;"
| style="text-align: center" | 30
|style="font-size:80%;"| 265,252,859,812,191,058,636,308,480,000,000
<span style="float:right;">≈2.65×10<sup>32</sup></span>
|style="font-size:80%;"| 97,581,073,836,835,777,732,377,428,235,481
<span style="float:right;">≈9.76×10<sup>31</sup></span>
|align="right"| ≈0.36787 94412
|}
Footnotes
References
External links
es:Subfactorial
