7

Motivation: Every Christmas, my family does a secret Santa gift exchange (a derangement of n people), and over the years, the family has gotten bigger and people have gotten married. So we’ve added a rule that spouses can’t get one another in the drawing. We always have the same person give the first gift. Then whoever gets it gives the next gift and so on until everyone gives/gets one, or we start a new cycle if a cycle is completed. I’m interested in the probability of everyone being in 1 cycle.

Define

-Let n=s+2m (single people and married couples)

-“Pairwise restrictions”: For each married couple, (a,b), the derangement cannot have a->b or b->a.

Simpler case, without married couples (m=0, n=s):

-#possible length-n cycles: (n-1)!

-#possible derangements: integer(n!/e)

-Probability of 1 cycle: ≈e/n (assume n>3)

Reasoning for #possible cycles: Assume a valid drawing, then the first person could have gotten n-1 people. The next person can’t get themselves or the previous person (this would end the cycle early), so n-2 possibilities, and so on giving (n-1)!

But when we add in the pairwise restrictions, I’m having trouble coming up with a nice expression for “#possible length-n cycles” and I don’t have a clue how to adjust the formula for “# possible derangements”. Maybe there’s a better approach? I could always do a Monte Carlo simulation or something, but I was hoping for an expression of the probability in terms of n and m.

Anecdotally, it used to take more than 1 cycle most years, but lately there’s been more spouses added and it’s been mostly 1 cycle (very small sample size).

RobPratt
  • 50,938
Knight98
  • 458
  • 1
    +1, nice question. You don’t mention how you enforce these restrictions. I take it that you’re sampling uniformly from all permutations that fulfil the restrictions? (BTW I don’t immediately see a way to implement that distribution that’s more efficient than just drawing as usual and starting over when a restriction is violated.) – joriki Dec 27 '24 at 17:11
  • By the way, here's a tutorial and reference for typesetting math on this site. – joriki Dec 27 '24 at 17:12

1 Answers1

4

The number of derangements with the pairwise restrictions can be calculated with rook polynomial theory.

board with example m=2, s=3

There are $m$ 2x2-blocks and $s$ 1x1-blocks so the rook polynomial is

$$ r(x) = (2x^2+4x+1)^m (x+1)^s =_{\text{expanded}} \sum_{j=0}^n c_jx^j $$

Then the number of permutations avoiding these (i.e the good permutations we want) is by inclusion-exclusion

$$ w_1 = \sum_{j=0}^n c_j(-1)^j (n-j)! $$

There's also a funny way to write that as integral:

$$ w_1 = \int_0^\infty e^{-x} x^n p(-x^{-1}) dx $$

Here's a Desmos for testing that calculation.

And approximating that integral could yield an approximation formula like the one in the case of $m=0$ we have $w_1 \approx n! e^{-1}$. The number $(4m + s)$ (the linear coefficient in the rook polynomial) somehow makes a (like some fractional) power of $e$, I once did a thing like that but can't now remember how it goes. The case $s=0$ becomes $e^{-2}$. This was in fact in an older question of mine. It had multipermutations (i.e. we consider the persons in couples to be identical), but anyhow in the calculation we're considering them to be distinct.


For the count of cycles, inclusion-exclusion will work too. There are $2^j (n-j-1)!$ cycles where some particular $j$ married couples are next to each other and $\binom{m}{j}$ ways to choose those $j$ couples. Thus the number we want is

$$ \sum_{j=0}^m (-1)^j \binom{m}{j} 2^j (n-j-1)! $$

ploosu2
  • 12,367