Generalized Derangements
Derangement problems are quite easy to do when there are no restrictions. Suppose we want to extend the problem with restrictions, e.g.:
There are bins numbered 1,2,3,4,1,2,3,4,1,2 , and there are balls numbered 1,2,3,4,5,1,2,3,4,5 (distinguishable, say, two sets with different colors), and each bin is to contain a single ball such that the number of the bin and the ball should not match. In how many ways can that be done? (or what is the probability of that happening?)
This can be solved by using Rook polynomials.
The rook polynomial for a \(m\times n\) rectangle is:
For this problem:
\(m=\) number of bins numbered 's'
\(n=\) number of balls numbered 's'
and the rook polynomial we require to solve our problem is:
Now, with this rook polynomial, the number of ways of derangements can be found in two ways:
where \(n\) is the number of bins.
Another way is to expand \(R(x)\) and replace each \(x^i\) with \(i\cdot (n-i)!\)
The answer divided by \(n!\) gives the probability.
Both ways are described in the following Sage code:
283/2520 = 283/2520 ~ 0.112301587301587 407520
which agrees with a simulation:
lst=.10$1 2 3 4 a=.2#1+i.5 sim=: 3 : '0=+/((10?10){a)=lst' (+/%#)(sim"0)1000000#0 |
which is about \(0.112101\)
If we now turn our attention to the classic derangement problem, e.g. 10 bins and balls, each numbered 1 to 10, we change the variables accordingly:
balls = range(1,11) bins = balls |
We see that the summ is indeed \(1334961\), which is the number of derangements, \(D(10)\).
References: