hudebnik: (Default)
hudebnik ([personal profile] hudebnik) wrote2021-02-08 07:35 am
Entry tags:

group theory and pop culture

So last night we were both in a mood to watch something not-particularly-challenging, and on a whim Turned On the Cable Box (which happens every few months in our house) and started flipping through the hundreds of channels to see if anything looked appealing. We landed on a series of back-to-back episodes of "Futurama", which we usually see only when we're staying in a motel, which hasn't happened in almost a year because covid.

One episode stands out in my mind because the resolution to the plot problems rests on a theorem of permutation theory. The professor has built a mind-swapping device, and two characters swap minds, then have second thoughts and want to swap back, but the way the device works, once a pair of minds have been swapped, that exact pair can never be swapped again. But all is not lost: they can swap through a third party: (a,b) = (a,c)(c,b)(a,c). No, wait: that repeats the (a,c) pair; maybe a fourth party? Before they can explore that possibility, the third party runs off in mid-sequence, and various other swaps happen for other motivations... eventually (IIRC) eight different characters are all in the wrong bodies, and would all like to get back home. Is this even possible?

In the penultimate scene, two black NBA players (why? because it's Futurama, of course) show up, do a bunch of figuring on a blackboard (which they still have in Futurama), and announce that no matter how screwed-up the permutation of minds and bodies, it's possible to get back to the original state with at most two "extra players". Which they do, in a dizzying montage of swaps that leaves everybody in the right body, and they all live happily ever after.

OK, so the theorem is "for any sequence of swaps on a set of n objects, there's an additional sequence of swaps (on the original set plus at most two additional objects) that inverts the original sequence, without the same swap ever appearing more than once in the combined sequence." Why is this true, and why two additional objects -- one would have expected either one or infinitely many? And how does the number of swaps grow? I guess it can't grow more than quadratically in n because there are only C(n+2,2) = (n+2)(n+1)/2 possible swaps on n+2 objects without repeating.

The n=2 case from above: (a,b) can be inverted by (a,c)(b,d)(a,d)(b,c) without violating the no-repeats rule. And it really can't be done with only one additional "player", as one can see by exhaustive search: there are only 3 possible swaps on {a,b,c}, and neither (a,c), (b,c), (a,c)(b,c), nor (b,c)(a,c) is equivalent to (a,b). (Side question: how big is this "exhaustive search"? There are only C(n+1,2) = n(n+1)/2 possible swaps, but then you have to look at all permutations of at most this many swaps... how many permutations are there of at most m objects, where m=C(n+1,2)? Let F(m) = 1 + m + m(m-1) + m(m-1)(m-2) + ... + m!; then F(0)=1, F(1)=2, F(2)=5, F(3)=16, F(4)=65, F(5)=306.... nothing obvious except that it grows at least as fast as m!. I should know this, or be able to solve it; I've taken combinatorics, thirty years ago. I'll get back to this.)

It'll be difficult to do the underlying theorem by induction because the no-repeats rule imposes a global constraint that doesn't lend itself to self-reduction. But maybe it's simpler than that: just grab the last swap in the sequence that needs to be reversed, label it (a,b), label the "extra players" c and d, do (a,c)(b,d)(a,d)(b,c) as above, and iterate. We know that nothing involving c or d was in the original sequence, so that doesn't violate the no-repeats rule, but it's not obvious that nothing involving a or b has already been used in the "undoing" sequence. We know that (a,b) doesn't appear twice in the original sequence, and if that's the only occurrence of either a or b in the original sequence, the above works, but it's likely that (a,*) and (b,*) each appears more than once in the original sequence, which could use up our allotted (a,c), (a,d), (b,c), and (b,d) swaps. I'll get back to this.
hlinspjalda: Rolakan 5 (Default)

[personal profile] hlinspjalda 2021-02-08 09:44 pm (UTC)(link)
Mr. Fixer howls at "Futurama" like this too. <3 We have a house rule that if somebody gets really far into a critique of this nature we have to install the MST3K silhouette at the bottom of the screen so everybody knows it's open season.
cellio: (Default)

[personal profile] cellio 2021-02-09 04:11 am (UTC)(link)

This sounds entertaining... but I'm not going to try to solve it; I'd rather watch you. :-)