Random permutation statistics
The statistics of random permutations, such as the cycle structure of a random permutation are of fundamental importance in the analysis of algorithms, especially of sorting algorithms, which operate on random permutations. Suppose, for example, that we are using quickselect (a cousin of quicksort) to select a random element of a random permutation. Quickselect will perform a partial sort on the array, as it partitions the array according to the pivot. Hence a permutation will be less disordered after quickselect has been performed. The amount of disorder that remains may be analysed with generating functions. These generating functions depend in a fundamental way on the generating functions of random permutation statistics. Hence it is of vital importance to compute these generating functions.
The article on random permutations contains an introduction to random permutations.
The fundamental relation
Permutations are sets of labelled cycles. Using the labelled case of the Flajolet–Sedgewick fundamental theorem and writing [math]\displaystyle{ \scriptstyle\mathcal{P} }[/math] for the set of permutations and [math]\displaystyle{ \scriptstyle\mathcal{Z} }[/math] for the singleton set, we have
- [math]\displaystyle{ \operatorname{SET}(\operatorname{CYC}(\mathcal{Z})) = \mathcal{P}. }[/math]
Translating into exponential generating functions (EGFs), we have
- [math]\displaystyle{ \exp \left(\log \frac{1}{1-z}\right) = \frac{1}{1-z} }[/math]
where we have used the fact that the EGF of the combinatorial species of permutations (there are n! permutations of n elements) is
- [math]\displaystyle{ \sum_{n\ge 0} \frac{n!}{n!} z^n = \frac{1}{1-z}. }[/math]
This one equation allows one to derive a large number of permutation statistics. Firstly, by dropping terms from [math]\displaystyle{ \scriptstyle\operatorname{SET} }[/math], i.e. exp, we may constrain the number of cycles that a permutation contains, e.g. by restricting the EGF to [math]\displaystyle{ \scriptstyle\operatorname{SET}_2 }[/math] we obtain permutations containing two cycles. Secondly, note that the EGF of labelled cycles, i.e. of [math]\displaystyle{ \scriptstyle\operatorname{CYC}(\mathcal{Z}) }[/math], is [math]\displaystyle{ \sum_{k\ge 1} \frac{(k-1)!z^k}{k!} = \sum_{k\ge 1} \frac{z^k}{k} = \log \frac{1}{1-z} }[/math] because there are k! / k labelled cycles. This means that by dropping terms from this generating function, we may constrain the size of the cycles that occur in a permutation and obtain an EGF of the permutations containing only cycles of a given size.
Instead of removing and selecting cycles, one can also put different weights on different size cycles. If [math]\displaystyle{ b: \mathbb{N} \rightarrow \mathbb{R} }[/math] is a weight function that depends only on the size k of the cycle and for brevity we write
- [math]\displaystyle{ b(\sigma) = \sum_{c\in\sigma} b(c), }[/math]
defining the value of b for a permutation [math]\displaystyle{ \sigma }[/math] to be the sum of its values on the cycles, then we may mark cycles of length k with ub(k) and obtain a two-variable generating function
- [math]\displaystyle{ g(z, u) = 1 + \sum_{n\ge 1} \left( \sum_{\sigma\in S_n } u^{b(\sigma)} \right) \frac{z^n}{n!} = \exp \sum_{k\ge 1} u^{b(k)} \frac{z^k}{k} }[/math]
This is a "mixed" generating function: it is an exponential generating function in z and an ordinary generating function in the secondary parameter u. Differentiating and evaluating at u = 1, we have
- [math]\displaystyle{ \frac{\partial}{\partial u} g(z, u) \Bigg|_{u=1} = \frac{1}{1-z} \sum_{k\ge 1} b(k) \frac{z^k}{k} = \sum_{n\ge 1} \left( \sum_{\sigma\in S_n} b(\sigma) \right) \frac{z^n}{n!} }[/math]
This is the probability generating function of the expectation of b. In other words, the coefficient of [math]\displaystyle{ z^n }[/math] in this power series is the expected value of b on permutations in [math]\displaystyle{ S_n }[/math], given that each permutation is chosen with the same probability [math]\displaystyle{ 1/n! }[/math].
This article uses the coefficient extraction operator [zn], documented on the page for formal power series.
Number of permutations that are involutions
An involution is a permutation σ so that σ2 = 1 under permutation composition. It follows that σ may only contain cycles of length one or two, i.e. the exponential generating function g(z) of these permutations is[1]
- [math]\displaystyle{ g(z) = \exp\left(z + \frac{1}{2} z^2\right). }[/math]
This gives the explicit formula for the total number [math]\displaystyle{ I(n) }[/math] of involutions among the permutations σ ∈ Sn:[1]
- [math]\displaystyle{ I(n) = n! [z^n] g(z) = n! \sum_{a+2b=n} \frac{1}{a! \; 2^b \; b!} = n! \sum_{b=0}^{\lfloor n/2 \rfloor} \frac{1}{(n-2b)! \; 2^b \; b!}. }[/math]
Dividing by n! yields the probability that a random permutation is an involution. These numbers are known as telephone numbers.
Number of permutations that are mth roots of unity
This generalizes the concept of an involution. An mth root of unity is a permutation σ so that σm = 1 under permutation composition. Now every time we apply σ we move one step in parallel along all of its cycles. A cycle of length d applied d times produces the identity permutation on d elements (d fixed points) and d is the smallest value to do so. Hence m must be a multiple of all cycle sizes d, i.e. the only possible cycles are those whose length d is a divisor of m. It follows that the EGF g(x) of these permutations is
- [math]\displaystyle{ g(z) = \exp\left(\sum_{d\mid m} \frac{z^d}{d}\right). }[/math]
When m = p, where p is prime, this simplifies to
- [math]\displaystyle{ n! [z^n] g(z) = n! \sum_{a+pb=n} \frac{1}{a! \; p^b \; b!} = n! \sum_{b=0}^{\lfloor n/p \rfloor} \frac{1}{(n-pb)! \; p^b \; b!}. }[/math]
Number of permutations of order exactly k
This one can be done by Möbius inversion. Working with the same concept as in the previous entry we note that the combinatorial species [math]\displaystyle{ \mathcal{Q} }[/math] of permutations whose order divides k is given by
- [math]\displaystyle{ \mathcal{Q} = \operatorname{SET}\left(\sum_{d\mid k} \operatorname{CYC}_{=d}(\mathcal{Z})\right). }[/math]
Translation to exponential generating functions we obtain the EGF of permutations whose order divides k, which is
- [math]\displaystyle{ Q_k(z) = \exp\left(\sum_{d\mid k} \frac{z^d}{d}\right). }[/math]
Now we can use this generating function to count permutations of order exactly k. Let [math]\displaystyle{ p_{n,d} }[/math] be the number of permutations on n whose order is exactly d and [math]\displaystyle{ q_{n,k} }[/math] the number of permutations on n the permutation count whose order divides k. Then we have
- [math]\displaystyle{ \sum_{d|k} p_{n,d} = q_{n,k}. }[/math]
It follows by Möbius inversion that
- [math]\displaystyle{ \sum_{d|k} q_{n, d}\times \mu(k/d) = p_{n, k}. }[/math]
Therefore, we have the EGF
- [math]\displaystyle{ Q(z) = \sum_{d\mid k} \mu(k/d) \times Q_d(z) = \sum_{d\mid k} \mu(k/d) \exp\left(\sum_{m\mid d} \frac{z^m}{m}\right). }[/math]
The desired count is then given by
- [math]\displaystyle{ n! [z^n] Q(z). }[/math]
This formula produces e.g. for k = 6 the EGF
- [math]\displaystyle{ Q(z) = {\rm e}^z - {\rm e}^{z+1/2\,z^2} - {\rm e}^{z+1/3\,z^3} + {\rm e}^{z+1/2\, z^2+1/3\,z^3+1/6\,z^6} }[/math]
with the sequence of values starting at n = 5
- [math]\displaystyle{ 20, 240, 1470, 10640, 83160, 584640, 4496030, 42658440, 371762820, 3594871280,\ldots }[/math] (sequence A061121 in the OEIS)
For k = 8 we get the EGF
- [math]\displaystyle{ Q(z) = -{\rm e}^{z+1/2\,z^2+1/4\,z^4}+ {\rm e}^{z+1/2\,z^2+1/4\,z^4+1/8\,z ^8} }[/math]
with the sequence of values starting at n = 8
- [math]\displaystyle{ 5040, 45360, 453600, 3326400, 39916800, 363242880, 3874590720, 34767532800,\ldots }[/math] (sequence A061122 in the OEIS)
Finally for k = 12 we get the EGF
- [math]\displaystyle{ Q(z) = {\rm e}^{z+1/2\,z^2}-{\rm e}^{z+1/2\,z^2+1/4\,z^4}-{\rm e}^{z+1/2\,z ^2+1/3\,{z}^{3}+1/6\,z^6} + {\rm e}^{z+1/2\,z^2+1/3\,z^3+1/4\,z^4+1 /6\,z^6+1/12\,z^{12}} }[/math]
with the sequence of values starting at n = 7
- [math]\displaystyle{ 420, 3360, 30240, 403200, 4019400, 80166240, 965284320, 12173441280, 162850287600,\ldots }[/math] (sequence A061125 in the OEIS)
Number of permutations that are derangements
Suppose there are n people at a party, each of whom brought an umbrella. At the end of the party everyone picks an umbrella out of the stack of umbrellas and leaves. What is the probability that no one left with his/her own umbrella? This problem is equivalent to counting permutations with no fixed points (called derangements), and hence the EGF, where we subtract out fixed points (cycles of length 1) by removing the term z from the fundamental relation is
- [math]\displaystyle{ \exp \left( -z + \sum_{k\ge 1} \frac{z^k} k \right) = \frac{e^{-z}}{1-z}. }[/math]
Multiplication by [math]\displaystyle{ 1/(1-z) }[/math] sums the coefficients of [math]\displaystyle{ e^{-z} }[/math], so [math]\displaystyle{ D(n) }[/math], the total number of derangements, is given by:
- [math]\displaystyle{ D(n) = n! \sum_{k=0}^n \frac{(-1)^k}{k!} \; \approx \; \frac{n!}{e}. }[/math]
Hence there are about [math]\displaystyle{ n!/e }[/math] derangements and the probability that a random permutation is a derangement is [math]\displaystyle{ 1/e. }[/math]
This result may also be proved by inclusion–exclusion. Using the sets [math]\displaystyle{ A_p }[/math] where [math]\displaystyle{ \begin{matrix}1\le p\le n\end{matrix} }[/math] to denote the set of permutations that fix p, we have
- [math]\displaystyle{ \left| \bigcup_p A_p \right| = \sum_p \left| A_p \right| \; - \; \sum_{p\lt q} \left| A_p \cap A_q \right| \; + \; \sum_{p\lt q\lt r} \left| A_p \cap A_q \cap A_r \right| \; - \; \cdots \; \pm \; \left| A_p \cap \; \cdots \; \cap A_s \right|. }[/math]
This formula counts the number of permutations that have at least one fixed point. The cardinalities are as follows:
- [math]\displaystyle{ \left| A_p \right| = (n-1)!\; , \; \; \left| A_p \cap A_q \right| = (n-2)!\; , \; \; \left| A_p \cap A_q \cap A_r \right| = (n-3)!\; , \; \ldots }[/math]
Hence the number of permutations with no fixed point is
- [math]\displaystyle{ n! \; \; - \; \; {n \choose 1} (n-1)! \; \; + \; \; {n \choose 2} (n-2)! \; \; - \; \; {n \choose 3} (n-3)! \; \; + \; \; \cdots \; \; \pm \; \; {n \choose n} (n-n)! }[/math]
or
- [math]\displaystyle{ n! \left( 1 - \frac{1}{1!} + \frac{1}{2!} - \frac{1}{3!} + \cdots \pm \frac{1}{n!} \right) = n! \sum_{k=0}^n \frac{(-1)^k}{k!} }[/math]
and we have the claim.
There is a generalization of these numbers, which is known as rencontres numbers, i.e. the number [math]\displaystyle{ D(n, m) }[/math] of permutations of [math]\displaystyle{ [n] }[/math] containing m fixed points. The corresponding EGF is obtained by marking cycles of size one with the variable u, i.e. choosing b(k) equal to one for [math]\displaystyle{ k=1 }[/math] and zero otherwise, which yields the generating function [math]\displaystyle{ g(z, u) }[/math] of the set of permutations by the number of fixed points:
- [math]\displaystyle{ g(z, u) = \exp \left( -z + uz + \sum_{k\ge 1} \frac{z^k}{k} \right) = \frac{e^{-z}}{1-z} e^{uz}. }[/math]
It follows that
- [math]\displaystyle{ [u^m] g(z, u) = \frac{e^{-z}}{1-z} \frac{z^m}{m!} }[/math]
and hence
- [math]\displaystyle{ D(n, m) = n! [z^n] [u^m] g(z, u) = \frac{n!}{m!} [z^{n-m}] \frac{e^{-z}}{1-z} = \frac{n!}{m!} \sum_{k=0}^{n-m} \frac{(-1)^k}{k!}. }[/math]
This immediately implies that
- [math]\displaystyle{ D(n, m) = {n \choose m} D(n-m, 0) \; \; \text{ and } \; \; \frac{D(n, m)}{n!} \approx \frac{e^{-1}}{m!} }[/math]
for n large, m fixed.
Order of a random permutation
If P is a permutation, the order of P is the smallest positive integer n for which [math]\displaystyle{ P^n }[/math] is the identity permutation. This is the least common multiple of the lengths of the cycles of P.
A theorem of Goh and Schmutz[2] states that if [math]\displaystyle{ \mu_n }[/math] is the expected order of a random permutation of size n, then
- [math]\displaystyle{ \log\mu_n \sim c\sqrt{\frac{n}{\log n}} }[/math]
where the constant c is
- [math]\displaystyle{ 2\sqrt{2\int_0^\infty \log\log\left(\frac{e}{1-e^{-t}}\right)dt}\approx 1.1178641511899 }[/math]
Derangements containing an even and an odd number of cycles
We can use the same construction as in the previous section to compute the number of derangements [math]\displaystyle{ D_0(n) }[/math] containing an even number of cycles and the number [math]\displaystyle{ D_1(n) }[/math] containing an odd number of cycles. To do this we need to mark all cycles and subtract fixed points, giving
- [math]\displaystyle{ g(z, u) = \exp\left( - u z + u \log \frac{1}{1-z} \right) = \exp(-uz) \left( \frac{1}{1-z} \right)^u. }[/math]
Now some very basic reasoning shows that the EGF [math]\displaystyle{ q(z) }[/math] of [math]\displaystyle{ D_0(n) }[/math] is given by
- [math]\displaystyle{ q(z) = \frac{1}{2} \times g(z, -1) + \frac{1}{2} \times g(z, 1) = \frac{1}{2} \exp(-z) \frac{1}{1-z} +\frac{1}{2} \exp(z) (1-z). }[/math]
We thus have
- [math]\displaystyle{ D_0(n) = n! [z^n] q(z) = \frac{1}{2} n! \sum_{k=0}^n \frac{(-1)^k}{k!} + \frac{1}{2} n! \frac{1}{n!} - \frac{1}{2} n! \frac{1}{(n-1)!} }[/math]
which is
- [math]\displaystyle{ \frac{1}{2} n! \sum_{k=0}^n \frac{(-1)^k}{k!} + \frac{1}{2} (1-n) \sim \frac{1}{2e} n! + \frac{1}{2} (1-n). }[/math]
Subtracting [math]\displaystyle{ D_0(n) }[/math] from [math]\displaystyle{ D(n) }[/math], we find
- [math]\displaystyle{ D_1(n) = \frac{1}{2} n! \sum_{k=0}^n \frac{(-1)^k}{k!} - \frac{1}{2} (1-n). }[/math]
The difference of these two ([math]\displaystyle{ D_0(n) }[/math] and [math]\displaystyle{ D_1(n) }[/math]) is [math]\displaystyle{ n-1. }[/math]
One hundred prisoners
A prison warden wants to make room in his prison and is considering liberating one hundred prisoners, thereby freeing one hundred cells. He therefore assembles one hundred prisoners and asks them to play the following game: he lines up one hundred urns in a row, each containing the name of one prisoner, where every prisoner's name occurs exactly once. The game is played as follows: every prisoner is allowed to look inside fifty urns. If he or she does not find his or her name in one of the fifty urns, all prisoners will immediately be executed, otherwise the game continues. The prisoners have a few moments to decide on a strategy, knowing that once the game has begun, they will not be able to communicate with each other, mark the urns in any way or move the urns or the names inside them. Choosing urns at random, their chances of survival are almost zero, but there is a strategy giving them a 30% chance of survival, assuming that the names are assigned to urns randomly – what is it?
First of all, the survival probability using random choices is
- [math]\displaystyle{ \left( \frac{{99 \choose 49}}{{100 \choose 50}} \right)^{100} = \frac{1}{2^{100}}, }[/math]
so this is definitely not a practical strategy.
The 30% survival strategy is to consider the contents of the urns to be a permutation of the prisoners, and traverse cycles. To keep the notation simple, assign a number to each prisoner, for example by sorting their names alphabetically. The urns may thereafter be considered to contain numbers rather than names. Now clearly the contents of the urns define a permutation. The first prisoner opens the first urn. If he finds his name, he has finished and survives. Otherwise he opens the urn with the number he found in the first urn. The process repeats: the prisoner opens an urn and survives if he finds his name, otherwise he opens the urn with the number just retrieved, up to a limit of fifty urns. The second prisoner starts with urn number two, the third with urn number three, and so on. This strategy is precisely equivalent to a traversal of the cycles of the permutation represented by the urns. Every prisoner starts with the urn bearing his number and keeps on traversing his cycle up to a limit of fifty urns. The number of the urn that contains his number is the pre-image of that number under the permutation. Hence the prisoners survive if all cycles of the permutation contain at most fifty elements. We have to show that this probability is at least 30%.
Note that this assumes that the warden chooses the permutation randomly; if the warden anticipates this strategy, he can simply choose a permutation with a cycle of length 51. To overcome this, the prisoners may agree in advance on a random permutation of their names.
We consider the general case of [math]\displaystyle{ 2n }[/math] prisoners and [math]\displaystyle{ n }[/math] urns being opened. We first calculate the complementary probability, i.e. that there is a cycle of more than [math]\displaystyle{ n }[/math] elements. With this in mind, we introduce
- [math]\displaystyle{ g(z, u) = \exp \left( z + \frac{z^2}{2} + \frac{z^3}{3} + \cdots + u \frac{z^{n+1}}{n+1} + u \frac{z^{n+2}}{n+2} + \cdots \right) }[/math]
or
- [math]\displaystyle{ \frac{1}{1-z} \exp \left( (u-1) \left( \frac{z^{n+1}}{n+1} + \frac{z^{n+2}}{n+2} + \cdots \right) \right), }[/math]
so that the desired probability is
- [math]\displaystyle{ [z^{2n}][u] g(z, u), }[/math]
because the cycle of more than [math]\displaystyle{ n }[/math] elements will necessarily be unique. Using the fact that [math]\displaystyle{ 2(n+1)\gt 2n }[/math], we find that
- [math]\displaystyle{ [z^{2n}][u] g(z, u) = [z^{2n}][u] \frac{1}{1-z} \left( 1 + (u-1) \left( \frac{z^{n+1}}{n+1} + \frac{z^{n+2}}{n+2} + \cdots \right) \right), }[/math]
which yields
- [math]\displaystyle{ [z^{2n}][u] g(z, u) = [z^{2n}] \frac{1}{1-z} \left( \frac{z^{n+1}}{n+1} + \frac{z^{n+2}}{n+2} + \cdots \right) = \sum_{k=n+1}^{2n} \frac{1}{k} = H_{2n} - H_n. }[/math]
Finally, using an integral estimate such as Euler–Maclaurin summation, or the asymptotic expansion of the nth harmonic number, we obtain
- [math]\displaystyle{ H_{2n} - H_n \sim \log 2 - \frac{1}{4n} + \frac{1}{16n^2} - \frac{1}{128n^4} + \frac{1}{256n^6} - \frac{17}{4096n^8} + \cdots, }[/math]
so that
- [math]\displaystyle{ [z^{2n}][u] g(z, u) \lt \log 2 \quad \mbox{and} \quad 1 - [z^{2n}][u] g(z, u) \gt 1 - \log 2 = 0.30685281, }[/math]
or at least 30%, as claimed.
A related result is that asymptotically, the expected length of the longest cycle is λn, where λ is the Golomb–Dickman constant, approximately 0.62.
This example is due to Anna Gál and Peter Bro Miltersen; consult the paper by Peter Winkler for more information, and see the discussion on Les-Mathematiques.net. Consult the references on 100 prisoners for links to these references.
The above computation may be performed in a more simple and direct way, as follows: first note that a permutation of [math]\displaystyle{ 2n }[/math] elements contains at most one cycle of length strictly greater than [math]\displaystyle{ n }[/math] . Thus, if we denote
- [math]\displaystyle{ p_k=\Pr[\mbox{there is a cycle of length }k], }[/math]
then
- [math]\displaystyle{ \Pr[\mbox{there is a cycle of length}\gt n] = \sum_{k=n+1}^{2n} p_k. }[/math]
For [math]\displaystyle{ k\gt n }[/math], the number of permutations that contain a cycle of length exactly [math]\displaystyle{ k }[/math] is
- [math]\displaystyle{ {{2n}\choose k} \cdot \frac{k!}{k} \cdot (2n-k)!. }[/math]
Explanation: [math]\displaystyle{ {{2n}\choose k} }[/math] is the number of ways of choosing the [math]\displaystyle{ k }[/math] elements that comprise the cycle; [math]\displaystyle{ \frac{k!}{k} }[/math] is the number of ways of arranging [math]\displaystyle{ k }[/math] items in a cycle; and [math]\displaystyle{ (2n-k)! }[/math] is the number of ways to permute the remaining elements. There is no double counting here because there is at most one cycle of length [math]\displaystyle{ k }[/math] when [math]\displaystyle{ k \gt n }[/math]. Thus,
- [math]\displaystyle{ p_k = \frac{{{2n}\choose k} \cdot \frac{k!}{k} \cdot (2n-k)!}{(2n)!} = \frac1k. }[/math]
We conclude that
- [math]\displaystyle{ \Pr[\mbox{there is a cycle of length}\gt n] = \sum_{k=n+1}^{2n} \frac1k = H_{2n}-H_n. }[/math]
A variation on the 100 prisoners problem (keys and boxes)
There is a closely related problem that fits the method presented here quite nicely. Say you have n ordered boxes. Every box contains a key to some other box or possibly itself giving a permutation of the keys. You are allowed to select k of these n boxes all at once and break them open simultaneously, gaining access to k keys. What is the probability that using these keys you can open all n boxes, where you use a found key to open the box it belongs to and repeat.
The mathematical statement of this problem is as follows: pick a random permutation on n elements and k values from the range 1 to n, also at random, call these marks. What is the probability that there is at least one mark on every cycle of the permutation? The claim is this probability is k/n.
The species [math]\displaystyle{ \mathcal{Q} }[/math] of permutations by cycles with some non-empty subset of every cycle being marked has the specification
- [math]\displaystyle{ \mathcal{Q} = \operatorname{SET} \left(\sum_{q\ge 1}\operatorname{CYC}_{=q}(\mathcal{Z}) \times \sum_{p=1}^q {q\choose p} \mathcal{U}^p \right). }[/math]
The index in the inner sum starts at one because we must have at least one mark on every cycle.
Translating the specification to generating functions we obtain the bivariate generating function
- [math]\displaystyle{ G(z, u) = \exp\left(\sum_{q\ge 1} \frac{z^q}{q} \sum_{p=1}^q {q\choose p} u^p\right). }[/math]
This simplifies to
- [math]\displaystyle{ \exp\left(\sum_{q\ge 1} \frac{z^q}{q} (u+1)^q - \sum_{q\ge 1} \frac{z^q}{q} \right) }[/math]
or
- [math]\displaystyle{ \exp\left(\log\frac{1}{1-(u+1)z} - \log\frac{1}{1-z}\right) = \frac{1-z}{1-(u+1)z}. }[/math]
In order to extract coefficients from this re-write like so
- [math]\displaystyle{ (1-z)\sum_{q\ge 0} (u+1)^q z^q. }[/math]
It now follows that
- [math]\displaystyle{ [z^n] G(z, u) = (u+1)^n - (u+1)^{n-1} }[/math]
and hence
- [math]\displaystyle{ [u^k] [z^n] G(z, u) = {n\choose k} - {n-1\choose k}. }[/math]
Divide by [math]\displaystyle{ {n\choose k} }[/math] to obtain
- [math]\displaystyle{ 1 - \frac{(n-1)!}{k! (n-1-k)!} \frac{k! (n-k)!}{n!} = 1 - \frac{n-k}{n} = \frac{k}{n}. }[/math]
We do not need to divide by n! because [math]\displaystyle{ G(z, u) }[/math] is exponential in z.
Number of permutations containing m cycles
Applying the Flajolet–Sedgewick fundamental theorem, i.e. the labelled enumeration theorem with [math]\displaystyle{ G = S_m }[/math], to the set
- [math]\displaystyle{ \operatorname{SET}_{=m}(\operatorname{CYC}(\mathcal{Z})) }[/math]
we obtain the generating function
- [math]\displaystyle{ g_m(z) = \frac{1}{|S_m|} \left( \log \frac{1}{1-z} \right)^m = \frac{1}{m!} \left( \log \frac{1}{1-z} \right)^m. }[/math]
The term
- [math]\displaystyle{ (-1)^{n+m} n! \; [z^n] g_m(z) = s(n,m) }[/math]
yields the signed Stirling numbers of the first kind, and [math]\displaystyle{ g_m(z) }[/math] is the EGF of the unsigned Stirling numbers of the first kind, i.e.
- [math]\displaystyle{ n! [z^n] g_m(z) = \left[\begin{matrix} n \\ m \end{matrix}\right]. }[/math]
We can compute the OGF of the signed Stirling numbers for n fixed, i.e.
- [math]\displaystyle{ s_n(w) = \sum_{m=0}^n s(n,m) w^m. }[/math]
Start with
- [math]\displaystyle{ g_m(z) = \sum_{n\ge m} \frac{(-1)^{n+m}}{n!} s(n,m) z^n }[/math]
which yields
- [math]\displaystyle{ (-1)^m g_m(z) w^m = \sum_{n\ge m} \frac{(-1)^n}{n!} s(n,m) w^m z^n. }[/math]
Summing this, we obtain
- [math]\displaystyle{ \sum_{m\ge 0} (-1)^m g_m(z) w^m = \sum_{m\ge 0} \sum_{n\ge m} \frac{(-1)^n}{n!} s(n,m) w^m z^n = \sum_{n\ge 0}\frac{(-1)^n}{n!} z^n \sum_{m=0}^n s(n,m) w^m. }[/math]
Using the formula involving the logarithm for [math]\displaystyle{ g_m(z) }[/math] on the left, the definition of [math]\displaystyle{ s_n(w) }[/math] on the right, and the binomial theorem, we obtain
- [math]\displaystyle{ (1-z)^w = \sum_{n\ge 0} {w \choose n} (-1)^n z^n = \sum_{n\ge 0}\frac{(-1)^n}{n!} s_n(w) z^n. }[/math]
Comparing the coefficients of [math]\displaystyle{ z^n }[/math], and using the definition of the binomial coefficient, we finally have
- [math]\displaystyle{ s_n(w) = w \; (w-1) \; (w-2) \; \cdots \; (w-(n-1)) = (w)_n, }[/math]
a falling factorial. The computation of the OGF of the unsigned Stirling numbers of the first kind works in a similar way.
Expected number of cycles of a given size m
In this problem we use a bivariate generating function g(z, u) as described in the introduction. The value of b for a cycle not of size m is zero, and one for a cycle of size m. We have
- [math]\displaystyle{ \frac{\partial}{\partial u} g(z, u) \Bigg|_{u=1} = \frac{1}{1-z} \sum_{k\ge 1} b(k) \frac{z^k}{k} = \frac{1}{1-z} \frac{z^m}{m} }[/math]
or
- [math]\displaystyle{ \frac{1}{m} z^m \; + \; \frac{1}{m} z^{m+1} \; + \; \frac{1}{m} z^{m+2} \; + \; \cdots }[/math]
This means that the expected number of cycles of size m in a permutation of length n less than m is zero (obviously). A random permutation of length at least m contains on average 1/m cycles of length m. In particular, a random permutation contains about one fixed point.
The OGF of the expected number of cycles of length less than or equal to m is therefore
- [math]\displaystyle{ \frac{1}{1-z} \sum_{k=1}^m \frac{z^k}{k} \mbox{ and } [z^n] \frac{1}{1-z} \sum_{k=1}^m \frac{z^k}{k} = H_m \mbox{ for } n \ge m }[/math]
where Hm is the mth harmonic number. Hence the expected number of cycles of length at most m in a random permutation is about ln m.
Moments of fixed points
The mixed GF [math]\displaystyle{ g(z, u) }[/math] of the set of permutations by the number of fixed points is
- [math]\displaystyle{ g(z, u) = \exp\left( -z + uz + \log \frac{1}{1-z}\right) = \frac{1}{1-z} \exp ( -z + uz ). }[/math]
Let the random variable X be the number of fixed points of a random permutation. Using Stirling numbers of the second kind, we have the following formula for the mth moment of X:
- [math]\displaystyle{ E(X^m) = E\left( \sum_{k=0}^m \left\{ \begin{matrix} m \\ k \end{matrix} \right\} (X)_k \right) = \sum_{k=0}^m \left\{ \begin{matrix} m \\ k \end{matrix} \right\} E((X)_k), }[/math]
where [math]\displaystyle{ (X)_k }[/math] is a falling factorial. Using [math]\displaystyle{ g(z, u) }[/math], we have
- [math]\displaystyle{ E((X)_k) = [z^n] \left(\frac{d}{du}\right)^k g(z, u) \Bigg|_{u=1} = [z^n] \frac{z^k}{1-z} \exp ( -z + uz ) \Bigg|_{u=1} = [z^n] \frac{z^k}{1-z}, }[/math]
which is zero when [math]\displaystyle{ k\gt n }[/math], and one otherwise. Hence only terms with [math]\displaystyle{ k\lt =n }[/math] contribute to the sum. This yields
- [math]\displaystyle{ E(X^m) = \sum_{k=0}^n \left\{ \begin{matrix} m \\ k \end{matrix} \right\}. }[/math]
Expected number of fixed points in random permutation raised to some power k
Suppose you pick a random permutation [math]\displaystyle{ \sigma }[/math] and raise it to some power [math]\displaystyle{ k }[/math], with [math]\displaystyle{ k }[/math] a positive integer and ask about the expected number of fixed points in the result. Denote this value by [math]\displaystyle{ E[F_k] }[/math].
For every divisor [math]\displaystyle{ d }[/math] of [math]\displaystyle{ k }[/math] a cycle of length [math]\displaystyle{ d }[/math] splits into [math]\displaystyle{ d }[/math] fixed points when raised to the power [math]\displaystyle{ k. }[/math] Hence we need to mark these cycles with [math]\displaystyle{ u^d. }[/math] To illustrate this consider [math]\displaystyle{ E[F_6]. }[/math]
We get
- [math]\displaystyle{ g(z, u) = \exp\left(uz - z + u^2 \frac{z^2}{2} - \frac{z^2}{2} + u^3 \frac{z^3}{3} - \frac{z^3}{3} + u^6 \frac{z^6}{6} - \frac{z^6}{6} + \log \frac{1}{1-z}\right) }[/math]
which is
- [math]\displaystyle{ \frac{1}{1-z} \exp\left(uz - z + u^2 \frac{z^2}{2} - \frac{z^2}{2} + u^3 \frac{z^3}{3} - \frac{z^3}{3} + u^6 \frac{z^6}{6} - \frac{z^6}{6}\right). }[/math]
Once more continuing as described in the introduction, we find
- [math]\displaystyle{ \left.\frac{\partial}{\partial u} g(z, u)\right|_{u=1} = \left. \frac{z+z^2+z^3+z^6}{1-z} \exp\left(uz - z + u^2 \frac{z^2}{2} - \frac{z^2}{2} + u^3 \frac{z^3}{3} - \frac{z^3}{3} + u^6 \frac{z^6}{6} - \frac{z^6}{6}\right) \right|_{u=1} }[/math]
which is
- [math]\displaystyle{ \frac{z+z^2+z^3+z^6}{1-z}. }[/math]
The conclusion is that [math]\displaystyle{ E[F_6] = 4 }[/math] for [math]\displaystyle{ n\ge 6 }[/math] and there are four fixed points on average.
The general procedure is
- [math]\displaystyle{ g(z, u) = \exp\left(\sum_{d\mid k} \left(u^d \frac{z^d}{d} - \frac{z^d}{d}\right) + \log \frac{1}{1-z} \right)= \frac{1}{1-z} \exp\left(\sum_{d\mid k} \left(u^d \frac{z^d}{d} - \frac{z^d}{d}\right)\right). }[/math]
Once more continuing as before, we find
- [math]\displaystyle{ \left.\frac{\partial}{\partial u} g(z, u)\right|_{u=1} = \left. \frac{\sum_{d\mid k} z^d}{1-z} \exp\left(\sum_{d\mid k} \left(u^d \frac{z^d}{d} - \frac{z^d}{d}\right)\right) \right|_{u=1} = \frac{\sum_{d\mid k} z^d}{1-z}. }[/math]
We have shown that the value of [math]\displaystyle{ E[F_k] }[/math] is equal to [math]\displaystyle{ \tau(k) }[/math] (the number of divisors of [math]\displaystyle{ k }[/math]) as soon as [math]\displaystyle{ n\ge k. }[/math] It starts out at [math]\displaystyle{ 1 }[/math] for [math]\displaystyle{ n=1 }[/math] and increases by one every time [math]\displaystyle{ n }[/math] hits a divisor of [math]\displaystyle{ k }[/math] up to and including [math]\displaystyle{ k }[/math] itself.
Expected number of cycles of any length of a random permutation
We construct the bivariate generating function [math]\displaystyle{ g(z, u) }[/math] using [math]\displaystyle{ b(k) }[/math], where [math]\displaystyle{ b(k) }[/math] is one for all cycles (every cycle contributes one to the total number of cycles).
Note that [math]\displaystyle{ g(z, u) }[/math] has the closed form
- [math]\displaystyle{ g(z, u) = \left(\frac{1}{1-z}\right)^u }[/math]
and generates the unsigned Stirling numbers of the first kind.
We have
- [math]\displaystyle{ \frac{\partial}{\partial u} g(z, u) \Bigg|_{u=1} = \frac{1}{1-z} \sum_{k\ge 1} b(k) \frac{z^k}{k} = \frac{1}{1-z} \sum_{k\ge 1} \frac{z^k}{k} = \frac{1}{1-z} \log \frac{1}{1-z}. }[/math]
Hence the expected number of cycles is the harmonic number [math]\displaystyle{ H_n }[/math], or about [math]\displaystyle{ \log n }[/math].
Number of permutations with a cycle of length larger than n/2
(Note that Section One hundred prisoners contains exactly the same problem with a very similar calculation, plus also a simpler elementary proof.)
Once more, start with the exponential generating function [math]\displaystyle{ g(z, u) }[/math], this time of the class [math]\displaystyle{ \mathcal{P} }[/math] of permutations according to size where cycles of length more than [math]\displaystyle{ n/2 }[/math] are marked with the variable [math]\displaystyle{ u }[/math]:
- [math]\displaystyle{ g(z, u) = \exp\left(u \sum_{k\gt \lfloor\frac{n}{2}\rfloor}^\infty \frac{z^k}{k} + \sum_{k=1}^{\lfloor\frac{n}{2}\rfloor} \frac{z^k}{k} \right). }[/math]
There can only be one cycle of length more than [math]\displaystyle{ \frac{n}{2} }[/math], hence the answer to the question is given by
- [math]\displaystyle{ n! [u z^n] g(z, u) = n! [z^n] \exp\left(\sum_{k=1}^{\lfloor\frac{n}{2}\rfloor} \frac{z^k}{k}\right) \sum_{k\gt \lfloor\frac{n}{2}\rfloor}^\infty \frac{z^k}{k} }[/math]
or
- [math]\displaystyle{ n! [z^n] \exp\left(\log \frac{1}{1-z} - \sum_{k\gt \lfloor\frac{n}{2}\rfloor}^\infty\frac{z^k}{k}\right) \sum_{k\gt \lfloor\frac{n}{2}\rfloor}^\infty \frac{z^k}{k} }[/math]
which is
- [math]\displaystyle{ n! [z^n] \frac{1}{1-z} \exp\left( - \sum_{k\gt \lfloor\frac{n}{2}\rfloor}^\infty\frac{z^k}{k}\right) \sum_{k\gt \lfloor\frac{n}{2}\rfloor}^\infty \frac{z^k}{k} = n! [z^n] \frac{1}{1-z} \sum_{m=0}^\infty \frac{(-1)^m}{m!} \left( \sum_{k\gt \lfloor\frac{n}{2}\rfloor}^\infty\frac{z^k}{k}\right)^{m+1} }[/math]
The exponent of [math]\displaystyle{ z }[/math] in the term being raised to the power [math]\displaystyle{ m+1 }[/math] is larger than [math]\displaystyle{ \lfloor\frac{n}{2} \rfloor }[/math] and hence no value for [math]\displaystyle{ m\gt 0 }[/math] can possibly contribute to [math]\displaystyle{ [z^n]. }[/math]
It follows that the answer is
- [math]\displaystyle{ n![z^n] \frac{1}{1-z}\sum_{k\gt \lfloor\frac{n}{2}\rfloor}^\infty\frac{z^k}{k} = n! \sum_{k=\lfloor\frac{n}{2}\rfloor +1}^n \frac{1}{k}. }[/math]
The sum has an alternate representation that one encounters e.g. in the OEIS OEIS: A024167.
- [math]\displaystyle{ \sum_{k=1}^n \frac{1}{k} - \sum_{k=1}^{\lfloor\frac{n}{2}\rfloor} \frac{1}{k} = \sum_{k=1}^n \frac{1}{k} - 2\sum_{k=1}^{\lfloor\frac{n}{2}\rfloor} \frac{1}{2k} = \sum_{k=1\atop k\; \text{even}}^n (1-2) \frac{1}{k} + \sum_{k=1\atop k \;\text{odd}}^n \frac{1}{k} }[/math]
finally giving
- [math]\displaystyle{ n!\sum_{k=1}^n \frac{(-1)^{k+1}}{k} \sim n! \log 2. }[/math]
Expected number of transpositions of a random permutation
We can use the disjoint cycle decomposition of a permutation to factorize it as a product of transpositions by replacing a cycle of length k by k − 1 transpositions. E.g. the cycle [math]\displaystyle{ (1 \; 2 \; 3 4) }[/math] factors as [math]\displaystyle{ (1 \; 2) \; (2 \; 3) \; (3 \; 4) }[/math]. The function [math]\displaystyle{ b(k) }[/math] for cycles is equal to [math]\displaystyle{ k-1 }[/math] and we obtain
- [math]\displaystyle{ g(z, u) = \left( \frac{1}{1-uz} \right)^{1/u} }[/math]
and
- [math]\displaystyle{ \frac{\partial}{\partial u} g(z, u) \Bigg|_{u=1} = \frac{1}{1-z} \sum_{k\ge 1} (k-1) \frac{z^k}{k} = \frac{z}{(1-z)^2} - \frac{1}{1-z} \log \frac{1}{1-z}. }[/math]
Hence the expected number of transpositions [math]\displaystyle{ T(n) }[/math] is
- [math]\displaystyle{ T(n) = n - H_n }[/math]
where [math]\displaystyle{ H_n }[/math] is the [math]\displaystyle{ n^{th} }[/math] Harmonic number. We could also have obtained this formula by noting that the number of transpositions is obtained by adding the lengths of all cycles (which gives n) and subtracting one for every cycle (which gives [math]\displaystyle{ \log n }[/math] by the previous section).
Note that [math]\displaystyle{ g(z, u) }[/math] again generates the unsigned Stirling numbers of the first kind, but in reverse order. More precisely, we have
- [math]\displaystyle{ (-1)^m n! \; [z^n] [u^m] g(z, u) = \left[\begin{matrix} n \\ n-m \end{matrix}\right] }[/math]
To see this, note that the above is equivalent to
- [math]\displaystyle{ (-1)^{n+m} n! \; [z^n] [u^m] g(z, u)|_{u=1/u} |_{z=uz} = \left[\begin{matrix} n \\ m \end{matrix}\right] }[/math]
and that
- [math]\displaystyle{ [u^m] g(z, u)|_{u=1/u} |_{z=uz} = [u^m] \left( \frac{1}{1-z} \right)^u = \frac{1}{m!} \left( \log \frac{1}{1-z} \right)^m, }[/math]
which we saw to be the EGF of the unsigned Stirling numbers of the first kind in the section on permutations consisting of precisely m cycles.
Expected cycle size of a random element
We select a random element q of a random permutation [math]\displaystyle{ \sigma }[/math] and ask about the expected size of the cycle that contains q. Here the function [math]\displaystyle{ b(k) }[/math] is equal to [math]\displaystyle{ k^2 }[/math], because a cycle of length k contributes k elements that are on cycles of length k. Note that unlike the previous computations, we need to average out this parameter after we extract it from the generating function (divide by n). We have
- [math]\displaystyle{ \frac{\partial}{\partial u} g(z, u) \Bigg|_{u=1} = \frac{1}{1-z} \sum_{k\ge 1} k^2 \frac{z^k}{k} = \frac{1}{1-z} \frac{z}{(1-z)^2} = \frac{z}{(1-z)^3}. }[/math]
Hence the expected length of the cycle that contains q is
- [math]\displaystyle{ \frac{1}{n} [z^n] \frac{z}{(1-z)^3} = \frac{1}{n} \frac{1}{2} n (n+1) = \frac{1}{2} (n+1). }[/math]
Probability that a random element lies on a cycle of size m
This average parameter represents the probability that if we again select a random element of [math]\displaystyle{ [n] }[/math] of a random permutation, the element lies on a cycle of size m. The function [math]\displaystyle{ b(k) }[/math] is equal to [math]\displaystyle{ m }[/math] for [math]\displaystyle{ m=k }[/math] and zero otherwise, because only cycles of length m contribute, namely m elements that lie on a cycle of length m. We have
- [math]\displaystyle{ \frac{\partial}{\partial u} g(z, u) \Bigg|_{u=1} = \frac{1}{1-z} \sum_{k\ge 1} b(k) \frac{z^k}{k} = \frac{1}{1-z} \; m \; \frac{z^m}{m} = \frac{z^m}{1-z}. }[/math]
It follows that the probability that a random element lies on a cycle of length m is
- [math]\displaystyle{ \frac{1}{n} [z^n] \frac{z^m}{1-z} = \begin{cases} \frac{1}{n}, & \mbox{if }n\ge m \\ 0, & \mbox{otherwise.} \end{cases} }[/math]
Probability that a random subset of [n] lies on the same cycle
Select a random subset Q of [n] containing m elements and a random permutation, and ask about the probability that all elements of Q lie on the same cycle. This is another average parameter. The function b(k) is equal to [math]\displaystyle{ \begin{matrix}{k \choose m}\end{matrix} }[/math], because a cycle of length k contributes [math]\displaystyle{ \begin{matrix}{k \choose m}\end{matrix} }[/math] subsets of size m, where [math]\displaystyle{ \begin{matrix}{k \choose m} = 0\end{matrix} }[/math] for k < m. This yields
- [math]\displaystyle{ \frac{\partial}{\partial u} g(z, u) \Bigg|_{u=1} = \frac{1}{1-z} \sum_{k\ge m} {k \choose m} \frac{z^k}{k} = \frac{1}{1-z} \frac{1}{m} \frac{z^m}{(1-z)^m} = \frac{1}{m} \frac{z^m}{(1-z)^{m+1}}. }[/math]
Averaging out we obtain that the probability of the elements of Q being on the same cycle is
- [math]\displaystyle{ {n \choose m}^{-1} [z^n] \frac{1}{m} \frac{z^m}{(1-z)^{m+1}} = {n \choose m}^{-1} \frac{1}{m} [z^{n-m}] \frac{1}{(1-z)^{m+1}} }[/math]
or
- [math]\displaystyle{ \frac{1}{m} {n \choose m}^{-1} {(n-m) \; + \; m \choose m} = \frac{1}{m}. }[/math]
In particular, the probability that two elements p < q are on the same cycle is 1/2.
Number of permutations containing an even number of even cycles
We may use the Flajolet–Sedgewick fundamental theorem directly and compute more advanced permutation statistics. (Check that page for an explanation of how the operators we will use are computed.) For example, the set of permutations containing an even number of even cycles is given by
- [math]\displaystyle{ \operatorname{SET}(\operatorname{CYC}_{\operatorname{odd}}(\mathcal{Z})) \operatorname{SET}_{\operatorname{even}}(\operatorname{CYC}_{\operatorname{even}}(\mathcal{Z})). }[/math]
Translating to exponential generating functions (EGFs), we obtain
- [math]\displaystyle{ \exp \left( \frac{1}{2} \log \frac{1+z}{1-z} \right) \cosh \left( \frac{1}{2} \log \frac{1}{1-z^2} \right) }[/math]
or
- [math]\displaystyle{ \frac{1}{2} \exp \left( \frac{1}{2} \left( \log \frac{1+z}{1-z} + \log \frac{1}{1-z^2} \right) \right) + \frac{1}{2} \exp \left( \frac{1}{2} \left( \log \frac{1+z}{1-z} - \log \frac{1}{1-z^2} \right) \right). }[/math]
This simplifies to
- [math]\displaystyle{ \frac{1}{2} \exp \left( \frac{1}{2} \log \frac{1}{(1-z)^2} \right) + \frac{1}{2} \exp \left( \frac{1}{2} \log (1+z)^2 \right) }[/math]
or
- [math]\displaystyle{ \frac{1}{2} \frac{1}{1-z} + \frac{1}{2} (1+z) = 1 + z + \frac{1}{2} \frac{z^2}{1-z}. }[/math]
This says that there is one permutation of size zero containing an even number of even cycles (the empty permutation, which contains zero cycles of even length), one such permutation of size one (the fixed point, which also contains zero cycles of even length), and that for [math]\displaystyle{ n\ge 2 }[/math], there are [math]\displaystyle{ n!/2 }[/math] such permutations.
Permutations that are squares
Consider what happens when we square a permutation. Fixed points are mapped to fixed points. Odd cycles are mapped to odd cycles in a one-to-one correspondence, e.g. [math]\displaystyle{ (1 \; 8 \; 9 \; 11 \; 13) }[/math] turns into [math]\displaystyle{ (1 \; 9 \; 13 \; 8 \; 11) }[/math]. Even cycles split in two and produce a pair of cycles of half the size of the original cycle, e.g. [math]\displaystyle{ (5 \; 13 \; 6 \; 9) }[/math] turns into [math]\displaystyle{ (5 \; 6) \; (9 \; 13) }[/math]. Hence permutations that are squares may contain any number of odd cycles, and an even number of cycles of size two, an even number of cycles of size four etc., and are given by
- [math]\displaystyle{ \operatorname{SET}(\operatorname{CYC}_\operatorname{odd}(\mathcal{Z})) \operatorname{SET}_\operatorname{even}(\operatorname{CYC}_{=2}(\mathcal{Z})) \operatorname{SET}_\operatorname{even}(\operatorname{CYC}_{=4}(\mathcal{Z})) \operatorname{SET}_\operatorname{even}(\operatorname{CYC}_{=6}(\mathcal{Z})) \cdots }[/math]
which yields the EGF
- [math]\displaystyle{ \exp \left( \frac{1}{2} \log \frac{1+z}{1-z} \right) \prod_{m\ge 1} \cosh \frac{z^{2m}}{2m} = \sqrt{\frac{1+z}{1-z}} \prod_{m\ge 1} \cosh \frac{z^{2m}}{2m}. }[/math]
Odd cycle invariants
The types of permutations presented in the preceding two sections, i.e. permutations containing an even number of even cycles and permutations that are squares, are examples of so-called odd cycle invariants, studied by Sung and Zhang (see external links). The term odd cycle invariant simply means that membership in the respective combinatorial class is independent of the size and number of odd cycles occurring in the permutation. In fact we can prove that all odd cycle invariants obey a simple recurrence, which we will derive. First, here are some more examples of odd cycle invariants.
Permutations where the sum of the lengths of the even cycles is six
This class has the specification
- [math]\displaystyle{ \operatorname{SET}(\operatorname{CYC}_\operatorname{odd}(\mathcal{Z})) \left( \operatorname{SET}_{=3}(\operatorname{CYC}_{=2}(\mathcal{Z})) + \operatorname{CYC}_{=2}(\mathcal{Z})\operatorname{CYC}_{=4}(\mathcal{Z}) + \operatorname{CYC}_{=6}(\mathcal{Z}) \right) }[/math]
and the generating function
- [math]\displaystyle{ \sqrt{\frac{1+z}{1-z}} \left( \frac{1}{6} \left( \frac{z^2}{2} \right)^3 + \frac{z^2}{2} \frac{z^4}{4} + \frac{z^6}{6} \right) = \frac{5}{16} z^6 \sqrt{\frac{1+z}{1-z}}. }[/math]
The first few values are
- [math]\displaystyle{ 0, 0, 0, 0, 0, 225, 1575, 6300, 56700, 425250, 4677750, 46777500, 608107500, \ldots }[/math]
Permutations where all even cycles have the same length
This class has the specification
- [math]\displaystyle{ \operatorname{SET}(\operatorname{CYC}_\operatorname{odd}(\mathcal{Z})) \left( \operatorname{SET}_{\ge 1}(\operatorname{CYC}_{=2}(\mathcal{Z})) + \operatorname{SET}_{\ge 1}(\operatorname{CYC}_{=4}(\mathcal{Z})) + \operatorname{SET}_{\ge 1}(\operatorname{CYC}_{=6}(\mathcal{Z})) + \cdots \right) }[/math]
and the generating function
- [math]\displaystyle{ \sqrt{\frac{1+z}{1-z}} \left( \exp\left(\frac{z^2}{2}\right)-1 \, + \, \exp\left(\frac{z^4}{4}\right)-1 \, + \, \exp\left(\frac{z^6}{6}\right)-1 \, + \, \cdots \right). }[/math]
There is a semantic nuance here. We could consider permutations containing no even cycles as belonging to this class, since zero is even. The first few values are
- [math]\displaystyle{ 0, 1, 3, 15, 75, 405, 2835, 22155, 199395, 1828575, \ldots }[/math]
Permutations where the maximum length of an even cycle is four
This class has the specification
- [math]\displaystyle{ \operatorname{SET}(\operatorname{CYC}_\operatorname{odd}(\mathcal{Z})) \operatorname{SET}(\operatorname{CYC}_{=2}(\mathcal{Z}) + \operatorname{CYC}_{=4}(\mathcal{Z})) }[/math]
and the generating function
- [math]\displaystyle{ \sqrt{\frac{1+z}{1-z}} \exp \left( \frac{z^2}{2} + \frac{z^4}{4} \right). }[/math]
The first few values are
- [math]\displaystyle{ 1, 2, 6, 24, 120, 600, 4200, 28560, 257040, 2207520, 24282720, 258128640, \ldots }[/math]
The recurrence
Observe carefully how the specifications of the even cycle component are constructed. It is best to think of them in terms of parse trees. These trees have three levels. The nodes at the lowest level represent sums of products of even-length cycles of the singleton [math]\displaystyle{ \mathcal{Z} }[/math]. The nodes at the middle level represent restrictions of the set operator. Finally the node at the top level sums products of contributions from the middle level. Note that restrictions of the set operator, when applied to a generating function that is even, will preserve this feature, i.e. produce another even generating function. But all the inputs to the set operators are even since they arise from even-length cycles. The result is that all generating functions involved have the form
- [math]\displaystyle{ g(z) = h(z) \sqrt{\frac{1+z}{1-z}}, }[/math]
where [math]\displaystyle{ h(z) }[/math] is an even function. This means that
- [math]\displaystyle{ \frac{1}{1+z} \; g(z) = h(z) \; \frac{1}{\sqrt{1-z^2}} }[/math]
is even, too, and hence
- [math]\displaystyle{ \frac{1}{1+z} \; g(z) = \frac{1}{1-z} \; g(-z) \quad \mbox{ or } \quad (1-z) \; g(z) = (1+z) \; g(-z). }[/math]
Letting [math]\displaystyle{ g_n = n! [z^n] g(z) }[/math] and extracting coefficients, we find that
- [math]\displaystyle{ \frac{g_{2m+1}}{(2m+1)!} - \frac{g_{2m}}{(2m)!} = - \frac{g_{2m+1}}{(2m+1)!} + \frac{g_{2m}}{(2m)!} \quad \mbox{ or } \quad 2 \frac{g_{2m+1}}{(2m+1)!} = 2 \frac{g_{2m}}{(2m)!} }[/math]
which yields the recurrence
- [math]\displaystyle{ g_{2m+1} = (2m+1) g_{2m}\,. }[/math]
A problem from the 2005 Putnam competition
A link to the Putnam competition website appears in the section External links. The problem asks for a proof that
- [math]\displaystyle{ \sum_{\pi\in S_n} \frac{\sigma(\pi)}{\nu(\pi)+1} = (-1)^{n+1} \frac{n}{n+1}, }[/math]
where the sum is over all [math]\displaystyle{ n! }[/math] permutations of [math]\displaystyle{ [n] }[/math], [math]\displaystyle{ \sigma(\pi) }[/math] is the sign of [math]\displaystyle{ \pi }[/math], i.e. [math]\displaystyle{ \sigma(\pi)= 1 }[/math] if [math]\displaystyle{ \pi }[/math] is even and [math]\displaystyle{ \sigma(\pi)=-1 }[/math] if [math]\displaystyle{ \pi }[/math] is odd, and [math]\displaystyle{ \nu(\pi) }[/math] is the number of fixed points of [math]\displaystyle{ \pi }[/math].
Now the sign of [math]\displaystyle{ \pi }[/math] is given by
- [math]\displaystyle{ \sigma(\pi) = \prod_{c\in\pi} (-1)^{|c|-1}, }[/math]
where the product is over all cycles c of [math]\displaystyle{ \pi }[/math], as explained e.g. on the page on even and odd permutations.
Hence we consider the combinatorial class
- [math]\displaystyle{ \operatorname{SET}( - \mathcal{Z} + \mathcal{V} \mathcal{Z} + \operatorname{CYC}_{=1}(\mathcal{Z}) + \mathcal{U}\operatorname{CYC}_{=2}(\mathcal{Z}) + \mathcal{U}^2\operatorname{CYC}_{=3}(\mathcal{Z}) + \mathcal{U}^3\operatorname{CYC}_{=4}(\mathcal{Z}) + \cdots) }[/math]
where [math]\displaystyle{ \mathcal{U} }[/math] marks one minus the length of a contributing cycle, and [math]\displaystyle{ \mathcal{V} }[/math] marks fixed points. Translating to generating functions, we obtain
- [math]\displaystyle{ g(z, u, v) = \exp\left( -z + vz + \sum_{k\ge 1} u^{k-1} \frac{z^k}{k} \right) }[/math]
or
- [math]\displaystyle{ \exp\left( -z + vz + \frac{1}{u} \log\frac{1}{1-uz} \right) = \exp(-z + vz) \left(\frac{1}{1-uz} \right)^{1/u}. }[/math]
Now we have
- [math]\displaystyle{ n! [z^n] g(z, -1, v) = n! [z^n] \exp(-z + vz) (1 + z) = \sum_{\pi\in S_n} \sigma(\pi) v^{\nu(\pi)} }[/math]
and hence the desired quantity is given by
- [math]\displaystyle{ n! [z^n] \int_0^1 g(z, -1, v) dv = \sum_{\pi\in S_n} \frac{\sigma(\pi)}{\nu(\pi)+1}. }[/math]
Doing the computation, we obtain
- [math]\displaystyle{ \int_0^1 g(z, -1, v) dv = \exp(-z)(1+z) \left(\frac{1}{z}\exp(z) - \frac{1}{z}\right) }[/math]
or
- [math]\displaystyle{ \left(\frac{1}{z} + 1\right) \left(1 - \exp(-z)\right) = \frac{1}{z} + 1 - \exp(-z) - \frac{1}{z} \exp(-z). }[/math]
Extracting coefficients, we find that the coefficient of [math]\displaystyle{ 1/z }[/math] is zero. The constant is one, which does not agree with the formula (should be zero). For [math]\displaystyle{ n }[/math] positive, however, we obtain
- [math]\displaystyle{ n! [z^n] \left( - \exp(-z) - \frac{1}{z} \exp(-z) \right) = n! \left( - (-1)^n \frac{1}{n!} - (-1)^{n+1} \frac{1}{(n+1)!} \right) }[/math]
or
- [math]\displaystyle{ (-1)^{n+1} \left( 1 - \frac{1}{n+1} \right) = (-1)^{n+1} \frac{n}{n+1}, }[/math]
which is the desired result.
As an interesting aside, we observe that [math]\displaystyle{ g(z, u, v) }[/math] may be used to evaluate the following determinant of an [math]\displaystyle{ n\times n }[/math] matrix:
- [math]\displaystyle{ d(n) = \det(A_n) = \begin{vmatrix} a && b && b && \cdots && b \\ b && a && b && \cdots && b \\ b && b && a && \cdots && b \\ \vdots && \vdots && \vdots && \ddots && \vdots \\ b && b && b && \cdots && a \end{vmatrix}. }[/math]
where [math]\displaystyle{ a, b \ne 0 }[/math]. Recall the formula for the determinant:
- [math]\displaystyle{ \det(A) = \sum_{\pi \in S_n} \sigma(\pi) \prod_{i=1}^n A_{i, \pi(i)}. }[/math]
Now the value of the product on the right for a permutation [math]\displaystyle{ \pi }[/math] is [math]\displaystyle{ a^f b^{n-f} }[/math], where f is the number of fixed points of [math]\displaystyle{ \pi }[/math]. Hence
- [math]\displaystyle{ d(n) = b^n n! [z^n] g\left(z, -1, \frac{a}{b}\right)= b^n n! [z^n] \exp \left(\frac{a-b}{b} z\right) (1+z) }[/math]
which yields
- [math]\displaystyle{ b^n \left(\frac{a-b}{b}\right)^n + b^n n \left(\frac{a-b}{b}\right)^{n-1} = (a-b)^n + n b (a-b)^{n-1} }[/math]
and finally
- [math]\displaystyle{ d(n) = (a + (n-1)b) (a-b)^{n-1}\,. }[/math]
The difference between the number of cycles in even and odd permutations
Here we seek to show that this difference is given by
- [math]\displaystyle{ (-1)^n (n-2)! }[/math]
Recall that the sign [math]\displaystyle{ \sigma(\pi) }[/math] of a permutation [math]\displaystyle{ \pi }[/math] is given by
- [math]\displaystyle{ \sigma(\pi) = \prod_{c\in\pi} (-1)^{|c|-1} }[/math]
where the product ranges over the cycles c from the disjoint cycle composition of [math]\displaystyle{ \pi }[/math].
It follows that the combinatorial species [math]\displaystyle{ \mathcal{Q} }[/math] that reflects the signs and the cycle count of the set of permutations is given by
- [math]\displaystyle{ \mathcal{Q} = \operatorname{SET}(\mathcal{V}\operatorname{CYC}_1(\mathcal{Z}) +\mathcal{U}\mathcal{V}\operatorname{CYC}_{=2}(\mathcal{Z})) +\mathcal{U}^2\mathcal{V}\operatorname{CYC}_{=3}(\mathcal{Z}) +\mathcal{U}^3\mathcal{V}\operatorname{CYC}_{=4}(\mathcal{Z}) +\mathcal{U}^4\mathcal{V}\operatorname{CYC}_{=5}(\mathcal{Z}) +\cdots) }[/math]
where we have used [math]\displaystyle{ \mathcal{U} }[/math] to mark signs and [math]\displaystyle{ \mathcal{V} }[/math] for the cycle count.
Translating to generating functions we have
- [math]\displaystyle{ Q(z, u, v) = \exp\left(v\frac{z}{1} + vu\frac{z^2}{2} + vu^2\frac{z^3}{3} + vu^3\frac{z^4}{4} + vu^4\frac{z^5}{5} +\cdots\right). }[/math]
This simplifies to
- [math]\displaystyle{ Q(z,u,v) = \exp\left(\frac{v}{u} \left( \frac{zu}{1} + \frac{z^2 u^2}{2} + \frac{z^3 u^3}{3} + \frac{z^4 u^4}{4} + \frac{z^5 u^5}{5} + \cdots \right)\right) }[/math]
which is
- [math]\displaystyle{ \exp\left(\frac{v}{u} \log \frac{1}{1-uz}\right) = \left(\frac{1}{1-uz}\right)^{\frac{v}{u}}. }[/math]
Now the two generating functions [math]\displaystyle{ Q_1(z, v) }[/math] and [math]\displaystyle{ Q_2(z, v) }[/math] of even and odd permutations by cycle count are given by
- [math]\displaystyle{ Q_1(z,v) = \frac{1}{2} Q(z,+1,v) + \frac{1}{2} Q(z,-1,v) = \frac{1}{2}\left(\frac{1}{1-z}\right)^v +\frac{1}{2}\left(\frac{1}{1+z}\right)^{-v} }[/math]
and
- [math]\displaystyle{ Q_2(z,v) = \frac{1}{2} Q(z,+1,v) - \frac{1}{2} Q(z,-1,v) = \frac{1}{2}\left(\frac{1}{1-z}\right)^v -\frac{1}{2}\left(\frac{1}{1+z}\right)^{-v}. }[/math]
We require the quantity
- [math]\displaystyle{ G(z, v) = \left.\frac{d}{dv} (Q_1(z,v)-Q_2(z,v))\right|_{v=1} }[/math]
which is
- [math]\displaystyle{ \left.\frac{d}{dv} \left(\frac{1}{1+z}\right)^{-v}\right|_{v=1} = - \left.\log \frac{1}{1+z} \left(\frac{1}{1+z}\right)^{-v}\right|_{v=1} = -(1+z)\log \frac{1}{1+z}. }[/math]
Finally, extracting coefficients from this generating function, we obtain
- [math]\displaystyle{ - n! [z^n] (1+z)\log \frac{1}{1+z} = - n! \left(\frac{(-1)^n}{n} + \frac{(-1)^{n-1}}{n-1}\right) }[/math]
which is
- [math]\displaystyle{ - n! (-1)^{n-1} \left(-\frac{1}{n} + \frac{1}{n-1}\right) = n! (-1)^n \frac{n-(n-1)}{n(n-1)} }[/math]
which is in turn
- [math]\displaystyle{ n! (-1)^n \frac{1}{n(n-1)} = (-1)^n (n-2)! }[/math]
This concludes the proof.
Generalizations
Similar statistics are available for random endomorphisms on a finite set.[3][4]
See also
References
- ↑ 1.0 1.1 "On recursions connected with symmetric groups. I", Canadian Journal of Mathematics 3: 328–334, 1951, doi:10.4153/CJM-1951-038-3
- ↑ Goh, William M.Y.; Schmutz, Eric (1991). "The Expected order of a Random Permutation". Bulletin of the London Mathematical Society 23 (1): 34–42. doi:10.1112/blms/23.1.34. https://academic.oup.com/blms/article-abstract/23/1/34/288444. Alt URL
- ↑ Bernard Harris (1960). "Probability Distributions Related to Random Mappings". Ann. Math. Statist. 31 (4): 1045–1062. doi:10.1214/aoms/1177705677.
- ↑ Philippe Flajolet, Andrew M. Odlyzko (1989). Random mapping statistics (Research Report RR-1114). INRIA. inria-00075445. https://hal.inria.fr/inria-00075445.
External links
- Sung, Philip; Zhang, Yan (2003). "Recurring Recurrences in Counting Permutations". CiteSeerX 10.1.1.91.1088.
- Marko Riedel et al., The difference of number of cycles of even and odd permutations
- Marko Riedel et al., Keys inside closed boxes, a question on probability
100 prisoners
- Various authors, Permutations with a cycle > n/2
- Various authors, A property of derangements
- Various authors, Expected number of fixed points
- Peter Winkler, Seven puzzles you think you must not have heard correctly
- Various authors, Les-Mathematiques.net. Cent prisonniers (in French)
Original source: https://en.wikipedia.org/wiki/Random permutation statistics.
Read more |