4

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 recursive relationship is $!n = (n-1) \cdot \left( !(n-1) + !(n-2) \right)$ for $n\ge 2$, with $!0 = 1$ and $!1=0$, (also we have $!2 = 1$, $!3 = 2$, $!4 = 9$, $!5 = 44$ etc). There's an explicit formula for derangement, that is $!n = n! \sum_{i=0}^n \frac{(-1)^i}{i!}$.

Each derangement can be seen as, with numbers $1$, $2$, ..., $n$ put on a circle, draw $n$ arrows among them, each number has one arrow going out and one going in.

Now if we ignore the direction of the arrows, that is, change the arrows to non-directional lines, how many patterns will it be, to line up $1$, $2$, ..., $n$ numbers on a circle, with each number has two lines?

Call it as $f(n)$, we have $f(1)=0$, $f(2)=1$, $f(3)=1$, $f(4)=6$. For example, for 3 numbers on a circle there’s only one pattern: $(1-2-3)$; for 4 numbers there are 6 patterns, namely $(1-2, 3-4)$, $(1-3, 2-4)$, $(1-4, 2-3)$, $(1-2-3-4)$, $(1-2-4-3)$, and $(1-3-2-4)$.

So is there an explicit formula for $f(n)$?

RobPratt
  • 50,938
athos
  • 5,573
  • In other words, this is "the number of labeled $2$-regular multigraphs on $n$ vertices", right? This is related to the same problem for simple graphs, since any example has a simple part and a nonsimple part (corresponding to the transpositions). The simple version has been discussed on MO eg here and here and appears in the OEIS – Izaak van Dongen Apr 30 '24 at 22:22
  • @Karl sorry my original guess on the recurrent relationship $f(n)=(n-1)\cdot \left(f(n-1)+f(n-2)\right)$ was wrong... – athos Apr 30 '24 at 22:56
  • Yeah, I thought about it more carefully and the error was related to the double-counting part when 1 is in a small cycle. – Karl Apr 30 '24 at 22:59

2 Answers2

5

Following the work done at MSE 4118524 we can construct a recurrence (memoized) for these numbers. Using combinatorial classes we have the following class $\mathcal{Q}$ of sets of undirected cycles of length at least two:

$$\def\textsc#1{\dosc#1\csod} \def\dosc#1#2\csod{{\rm #1{\small #2}}} \mathcal{Q} = \textsc{SET}( \textsc{DHD}_{=2}(\mathcal{Z}) + \textsc{DHD}_{=3}(\mathcal{Z}) + \textsc{DHD}_{=4}(\mathcal{Z}) + \textsc{DHD}_{=5}(\mathcal{Z}) + \cdots).$$

This gives the EGF (the dihedral group $D_n$ has order $2n$ except on two nodes where it has order $2$)

$$Q(z) = \sum_{n\ge 0} Q_n \frac{z^n}{n!} = \exp\left( + \frac{z^2}{2} + \frac{1}{2} \frac{z^3}{3} + \frac{1}{2} \frac{z^4}{4} + \frac{1}{2} \frac{z^5}{5} + \cdots\right) \\ = \exp\left(- \frac{z}{2} + \frac{z^2}{4} + \frac{1}{2} \log\frac{1}{1-z}\right) = \frac{\exp(-z/2+z^2/4)}{\sqrt{1-z}}.$$

Differentiating we find

$$Q'(z) = - \frac{1}{2} (1-z) \frac{\exp(-z/2+z^2/4)}{\sqrt{1-z}} + \frac{1}{2} \frac{1}{1-z} \frac{\exp(-z/2+z^2/4)}{\sqrt{1-z}}.$$

Extracting the coefficient on $[z^{n-1}]$ for $n\ge 2$ on both sides yields

$$\frac{Q_n}{(n-1)!} = - \frac{1}{2} \frac{Q_{n-1}}{(n-1)!} + \frac{1}{2} \frac{Q_{n-2}}{(n-2)!} + \frac{1}{2} \sum_{m=0}^{n-1} [z^m] \frac{\exp(-z/2+z^2/4)}{\sqrt{1-z}} \\ = - \frac{1}{2} \frac{Q_{n-1}}{(n-1)!} + \frac{1}{2} \frac{Q_{n-2}}{(n-2)!} + \frac{1}{2} \sum_{m=0}^{n-1} \frac{Q_m}{m!} = \frac{Q_{n-2}}{(n-2)!} + \frac{1}{2} \sum_{m=0}^{n-3} \frac{Q_m}{m!}.$$

This gives the recurrence

$$\bbox[5px,border:2px solid #00A000]{ Q_n = (n-1) Q_{n-2} + \frac{(n-1)!}{2} \sum_{m=0}^{n-3} \frac{Q_m}{m!}.}$$

with base cases $Q_0=1, Q_1=0$ and $Q_2=1.$ To simplify this further we introduce for $n\ge 3$

$$Q_{n-1} = (n-2) Q_{n-3} + \frac{(n-2)!}{2} \sum_{m=0}^{n-4} \frac{Q_m}{m!}$$

and get

$$Q_n = (n-1) Q_{n-1} + (n-1) Q_{n-2} - (n-1) (n-2) Q_{n-3 } + \frac{1}{2} (n-1) (n-2) Q_{n-3}$$

which yields

$$\bbox[5px,border:2px solid #00A000]{ Q_n = (n-1) Q_{n-1} + (n-1) Q_{n-2} - \frac{1}{2} (n-1) (n-2) Q_{n-3}.}$$

for $n\ge 3$ with base cases $Q_0=1, Q_1=0$ and $Q_2=1.$ This will produce the sequence

$$1, 0, 1, 1, 6, 22, 130, 822, 6202, 52552, 499194, 5238370, \ldots$$

which points us to OEIS A002137 where we find the EGF and the recurrence, so the above is sound.

Addendum. If we insist on a closed form we get e.g.

$$\begin{align*} & n! [z^n] \frac{\exp(-z/2(1-z/2))}{\sqrt{1-z}} = n! [z^n] \sum_{k=0}^n \frac{1}{k!} \frac{(-1)^{k}}{2^{k}} z^{k} (1-z/2)^{k} \frac{1}{\sqrt{1-z}} \\ & = n! \sum_{k=0}^n \frac{1}{k!} \frac{(-1)^k}{2^k} [z^{n-k}] (1-z/2)^k \frac{1}{\sqrt{1-z}} \\ & = n! \sum_{k=0}^n \frac{1}{k!} \frac{(-1)^k}{2^k} \sum_{j=0}^{n-k} {k\choose n-k-j} (-1)^{n-k-j} 2^{j+k-n} \frac{1}{4^j} {2j\choose j}. \end{align*}$$

We obtain

$$\bbox[5px,border:2px solid #00A000]{(-1)^n \frac{n!}{2^n} \sum_{k=0}^n \frac{1}{k!} \sum_{j=0}^{n-k} {k\choose n-k-j} (-1)^j \frac{1}{2^j} {2j\choose j}.}$$

This is one of several possibilities.

Remark. Wilf in generatingfunctionology page 180 gives a proof for the asymptotic

$$Q(n) \sim n! \exp(-1/4) {n-1/2\choose n} = \exp(-1/4) (n-1/2)^{\underline{n}}.$$

This can be further simplified to

$$Q(n) \sim \frac{n! \exp(-1/4)}{\sqrt{\pi n}}.$$

Marko Riedel
  • 64,728
  • 1
    thank you! i'll update my post as my initial guess on the recurrent relationship $f(n) = (n-1) \cdot \left( f(n-1) + f(n-2) \right)$ is wrong. sorry – athos Apr 30 '24 at 22:41
  • May I ask, in the first formula, what does $DHD_{=2}$ etc mean? – athos Apr 30 '24 at 22:46
  • 1
    These combinatorial classes are from Analytic Combinatorics. We usually have $n$ slots and a permutation group acting on them, like the cyclic group or the symmetric group. Here we refer to the dihedral group. There is a combinatorial base class for every such group. – Marko Riedel Apr 30 '24 at 22:50
2

Marko Riedel's answer gives an excellent demonstration that the correct recurrence is $$ f(n)=(n-1)[f(n-1)+f(n-2)] - \frac{(n-1)(n-2)}{2}\cdot f(n-3). $$ I will give a bijective explanation of this formula, while at the same time explaining why the recurrence you had was incorrect.

You mentioned that that there are two cases for the number $1$. Either $1$ is linked to another number via a pair of edges, or $1$ is linked to two different numbers. There are $(n-1)\cdot f(n-2)$ ways two have $1$ paired up with a single other element. However, it is not always true that there are $(n-1)\cdot f(n-2)$ ways to insert $1$ into a collection of loops on the set $\{2,3,\dots,n\}$.

For the derangements case, there were $n-1$ ways to insert $1$ into any given derangement on the set $\{2,3,\dots,n\}$, such that it ends up in a cycle of length at least $3$. However, this is no longer true for the current problem of non-oriented loops. The problem is when inserting $1$ into the two-loop $\{a,b\}$, the derangement method counts both "inserting $1$ after $a$" and "inserting $1$ after $b$" as distinct, while the loop variant considers these to be the same. To correct for this double-counting, we just need to subtract the number of double-counted cases. This is exactly equal to $\binom{n-1}2\cdot f(n-3)$, since there are $\binom{n-1}{2}$ ways to choose $\{a,b\}$, and then $f(n-3)$ ways to choose a loop arrangement on the rest of everything except $\{1,a,b\}$. This is exactly the subtracted term in the first formula.

Mike Earnest
  • 84,902