There are EXACTLY 1493804444499093354916284290188948031229880469556

Ways to Derange a Standard Deck of Cards (ignoring suits) [and many other such useful facts]

Shalosh B. EKHAD, Christoph KOUTSCHAN, and Doron ZEILBERGER

In fond memory of Joe Gillis (3 Aug. 1911- 18 Nov. 1993), who taught us that Special

Functions Count

The famous problème des rencontres, due to Montmort, can be formulated (see [R], p. 58) in terms of counting the number of ways of rearranging a deck of n distinct cards, such that no card landed in the previous location. Calling this number D_{n}, there are quite a few good answers. Perhaps the best is as the solution of the (inhomogeneous) first-order linear recurrence

D_{n+1} − (n + 1)D_{n} = (−1)^{n+1} , D_{1} = 0 ,

that enables you, very fast, to find the first, say, 10000 terms. It follows, in particular, that the number of ways of completely deranging a standard deck of cards, where all the 52 cards are considered distinct is

29672484407795138298279444403649511427278111361911893663894333196201 .

This raises the natural question, of counting derangements of a standard deck of cards with 13 different denominations {1, …, 13} (where 1 =Ace, 11 =Jack, 12 =Queen, 13 =King), but ignoring suits. To our great surprise, this number was not (Jan. 22, 2021) in Neil Sloane’s monumental [OEIS]. The exact value is the one in the title, namely

1493804444499093354916284290188948031229880469556 .

This is a special case of the problem of finding the number of derangements of a multiset.

You have a_{1} copies of 1, a_{2} copies of 2, …, a_{n} copies of n, in other words, you have the multiset 1^{a_{1}} … n^{a_{n}}, and you are interested in the number, let’s call it M(a_{1}, …, a_{n}), of derangements. In other words, out of the total number of arrangements, given by the multinomial coefficient (a_{1} +…+a_{n})!/(a_{1}! ⋯ a_{n}!), how many are there where each location is different than the original. Here is why such questions are useful.^{1}

Suppose that in a certain army there are n different ranks, and each officer must wear a jacket indicating his or her rank. In a certain party, there were a_{1} officers of rank 1, a_{2} officers of rank 2, …, a_{n} officers of rank n. Before the party started, they hung their jackets in the coat-room. When the party was over, they were all very drunk, so they each grabbed a jacket (uniformly) at random.

1 This answers a question of Persi Diaconis , who asked ‘Why is it useful?’, at the end of DZ’s talk about this problem,

at the special session of the Joint Mathematics Meeting in memory of Richard Askey, Jan. 2021. We thank him for raising this important question, that also inspired the word ‘useful’ in the title.

What is the probability that every one shows the wrong rank?

Knowing the exact (rather than the approximate) probability is (potentially) very useful in deciding what odds to bet on such an event. Recall that probability theory started out with such important (and useful!) questions about gambling!

For example, M(2, 2, 2) = 10, since there are ten of them. Here they are:

( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 2 & 2 & 3 & 3 & 1 & 1 \end{matrix} ) , ( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 2 & 3 & 1 & 3 & 1 & 2 \end{matrix} ) , ( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 2 & 3 & 1 & 3 & 2 & 1 \end{matrix} ) , ( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 2 & 3 & 3 & 1 & 1 & 2 \end{matrix} ) ,

( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 2 & 3 & 3 & 1 & 2 & 1 \end{matrix} ) , ( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 3 & 2 & 1 & 3 & 1 & 2 \end{matrix} ) , ( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 3 & 2 & 1 & 3 & 2 & 1 \end{matrix} ) , ( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 3 & 2 & 3 & 1 & 1 & 2 \end{matrix} ) ,

( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 3 & 2 & 3 & 1 & 2 & 1 \end{matrix} ) , ( \begin{matrix}1 & 1 & 2 & 2 & 3 & 3 \\ 3 & 3 & 1 & 1 & 2 & 2 \end{matrix} ) .

The million dollar question is: How to efficiently compute these numbers M(a_{1}, a_{2}, …, a_{n})? (for example, the number of the title is M(4, 4, …, 4) where the 4 is repeated 13 times.)

For a fixed n, the great Percy Alexander MacMahon gave a nice generating function that he deemed important enough to include in the entry Combinatory Analysis that he contributed, in 1910, to the eleventh edition of Encyclopedia Britannica ([M], p. 755, col. 1)

∑_{0≤a_{1},...,a_{n}<∞} M(a_{1}, …, a_{n}) x_{1}^{a_{1}} ⋯ x_{n}^{a_{n}} = \frac{1}{1 − e_{2} − 2e_{3} − … − (n − 1)e_{n}} ,

where e_{i} = e_{i}(x_{1}, …, x_{n}) is the elementary symmetric function of degree i.

But this is not very efficient if one wants to find, say, M(5, …, 5), where 5 is repeated 100 times. One would have to find the Taylor series of a rational function with 100 variables, and extract the coefficient of x_{1}^{5} ⋯ x_{100}^{5}. Even for the number in the title, one would have to extract the coefficient of x_{1}^{4} ⋯ x_{13}^{4} in a rational function with 13 variables.

A much more efficient formula was given in the seminal paper [EG], by Shimon Even and Joe Gillis. It is the following amazing formula, made more widely known by Richard Askey in his classic monograph ([A], p. 43).

Theorem (Even-Gillis [EG]) The number of ways of deranging the multiset 1^{a_{1}} … n^{a_{n}} is

(−1)^{a_{1}+...+a_{n}} ∫_{0}^{∞} e^{−x}L_{a_{1}}(x) ⋯ L_{a_{n}}(x) dx ,

where L_{a}(x) is the (simple) Laguerre polynomial of degree a, so useful in classical potential theory, Quantum Mechanics, and elsewhere, and thanks to Gillis and Even, even in combinatorics!

L_{a}(x) := ∑_{α=0}^{a} (−1)^{α}\binom{a}{α}\frac{x^{α}}{α!} .

In particular the number of ways of deranging a standard deck of cards (given in the title) is

∫_{0}^{∞} e^{−x}L_{4}(x)^{13} dx ,

and it took Maple 0.123 seconds to find it! Using MacMahon’s formula would take much longer!

From now on, we are interested in fast efficient computations of the numbers [k repeated n times below].

F [n](k) = M(k, k, …, k) = (−1)^{kn} ∫_{0}^{∞} e^{−x}L_{k}(x)^{n} dx .

Suppose that we have 1000 different denominations (rather than 13) and still 4 suits, then we would need the number F [1000](4). Now Maple has to integrate e^{−x} times a polynomial of degree 4000 and it takes much longer!, in fact, SBE took 295 seconds to compute it.

It so happens that thanks to the Holonomic Systems Approach to Special Functions [Z], initiated in 1990 by one of us (DZ), and later extended and efficiently implemented [K] by another one of us (CK), the Even-Gillis formula can be used to compute very fast F [n](k) for small (and not so small) k, and very large n, and also for small n (we went as far as n = 9) and very large k, for which doing it directly would take a very long time.

Recall that a function f(n, x) is holonomic in (n, x) if (roughly) it satisfies a linear differential equation (with respect to x) with coefficients that are polynomials in (n, x) and a linear difference equation (also called recurrence equation), with respect to n, also with coefficients that are polynomials in (n, x). This is obviously true for the Laguerre polynomials L_{n}(x).

It is easy to see that the integrand e^{−x}L_{k}(x)^{n} is holonomic in (n, x) for each specific (numeric) k. In fact, this is true for any function of (n, x) that has the form e^{−x}P (x)^{n}, for an arbitrary polynomial P (x).

It is also easy, since, as observed in [Z], the class of holonomic functions is an algebra, that the integrand e^{−x}L_{k}(x)^{n} is holonomic in (k, x) for each specific (numeric) n.

For the former case, things are simpler, since the integrand is more than ‘just holonomic’, is it hyper-exponential, i.e. the two relevant equations (differential and difference) are first order. For this special case the Almkvist-Zeilberger algorithm [AlZ] implemented in the Maple package

https://sites.math.rutgers.edu/~zeilberg/tokhniot/EKHAD.txt

(procedure AZdI), and also included in this article’s Maple package

https://sites.math.rutgers.edu/~zeilberg/tokhniot/MultiDer.txt ,

finds such a recurrence very fast.

The output file https://sites.math.rutgers.edu/~zeilberg/tokhniot/oMultiDer1.txt con-

tains such recurrences for 1 ≤ k ≤ 19.

The [OEIS] (viewed Jan. 21, 2021) only has the sequences for 1 ≤ k ≤ 5.

The case k = 1 is the classical derangement sequence A000166. The case k = 2 is A000459, where a recurrence is given. The case k = 3 is A059073, that only has the entries up to n = 12, and there is no recurrence. The case k = 4 is A059074, where also only the entries up to n = 12 are given, and there is no recurrence. So the number of the title of this paper ‘almost’ made it to the OEIS, since it is the n = 13 entry of that sequence. The sequence corresponding to k = 5 is A123297, there is no recurrence and it only goes as far as n = 11. The sequences for k ≥ 6 were not present. The above output file has many terms, and recurrences for all these sequences through k = 19.

What about the sequences {F [n](k)}_{k=0}^{∞} for a fixed, numeric n? Now things are much more complicated (and slower), and the Almkvist-Zeilberger algorithm is not applicable. While we know, a priori that such a recurrence exists, for every n, once n gets larger, it becomes computationally challenging. The Mathematica package [K], written by one of us (CK), can handle it very well, and we found linear recurrences for n ≤ 9.

The output file https://sites.math.rutgers.edu/~zeilberg/tokhniot/oMultiDer2.txt con-

tains such recurrences for 2 ≤ n ≤ 9.

Note that the case n = 2 is the identically 1 sequence (after all, the Laguerre polynomials are orthonormal, and there exists exactly one multi-set derangement of 1^{n}2^{n}). The case n = 3 gives the Franel sequence ∑_{k=0}^{n} \binom{n}{k}^{3}, as noted by Richard Askey (mentioned at the end of [EG], and in [As], p.43). Surprisingly the sequences for n ≥ 4 were not in the OEIS.

Conclusion

People have been playing cards for centuries, and luminaries such as Persi Diaconis analyzed their random shuffling. It is surprising that such a natural number, the number of ways of deranging a standard deck, ignoring suits, could not be found anywhere in the OEIS, or for that matter in the internet. In fact, an internet search for the number of the title did give one hit, but unless you know the number beforehand, it is useless.

But the main message of this article, in addition to filling this much needed gap, is to illustrate the great utility of the Even-Gillis formula that, interfaced with symbolic-computation (the holonomic systems approach [AZ][Z][K]) can easily find , almost immediately, the number of ways of, say, deranging the multisets 1^{19} … 2000^{19} and the number of ways of deranging the multiset 1^{2000} … 9^{2000}, both of which are contained in the above-mentioned output files.

References

[AlZ] Gert Almkvist and Doron Zeilberger, The method of differentiating under the integral sign, J. Symbolic Computation 10, 571-591 (1990).

https://sites.math.rutgers.edu/~zeilberg/mamarim/mamarimhtml/duis.html .

[As] Richard Askey, Orthogonal Polynomials and Special Functions, SIAM, 1975.

[EG] S. Even and J. Gillis, Derangements and Laguerre polynomials, Math. Proc. Camb. Phil. Soc. 79 (1976), 135-143.

[K] Christoph Koutschan, Advanced applications of the holonomic systems approach, PhD thesis, Research Institute for Symbolic Computation (RISC), Johannes Kepler University, Linz, Austria, 2009.

http://www.koutschan.de/publ/Koutschan09/thesisKoutschan.pdf,
http://www.risc.jku.at/research/combinat/software/HolonomicFunctions/ .

[M] Percy Alexander MacMahon, Combinatory Analysis, in: Encyclopedia Britannica, eleventh edition, 1910. Volume VI, pp. 752-758.

[OEIS] The On-Line Encyclopedia of Integer Sequences, https://oeis.org .

[R] John Riordan, ‘Introduction to Combinatorial Analysis’, Dover, originally published by John Wiley, 1958.

[Z] Doron Zeilberger, A Holonomic systems approach to special functions identities, J. of Computational and Applied Math. 32, 321-368 (1990).

https://sites.math.rutgers.edu/~zeilberg/mamarim/mamarimhtml/holonomic.html .

Shalosh B. Ekhad, Department of Mathematics, Rutgers University (New Brunswick), Hill Center-Busch Campus, 110 Frelinghuysen Rd., Piscataway, NJ 08854-8019, USA.

Email: ShaloshBEkhad at gmail dot com .

Christoph Koutschan, Johann Radon Institute of Computational and Applied Mathematics (RI-CAM), Austrian Academy of Sciences, Altenberger Strasse 69, A-4040 Linz, Austria

Email: christoph.koutschan at ricam dot oeaw dot ac dot at .

Doron Zeilberger, Department of Mathematics, Rutgers University (New Brunswick), Hill Center-Busch Campus, 110 Frelinghuysen Rd., Piscataway, NJ 08854-8019, USA.

Email: DoronZeil at gmail dot com .

Jan. 25, 2021