Futurama theorem



The Futurama theorem is a real-life mathematical theorem invented by Futurama writer Ken Keeler, who holds a PhD in applied mathematics, purely for use in the Season 6 episode "The Prisoner of Benda".

It is the first known theorem to be created for the sole purpose of entertainment in a TV show, and, according to Keeler, was included to popularize math among young people.

The theorem proves that regardless of how many mind switches between two bodies have been made, they can still all be restored to their original bodies using only two extra people, provided these two people have not had any mind switches prior.

Background


In the episode "The Prisoner of Benda", Professor Farnsworth and Amy create a mind-switching machine, only to afterwards realise that when two people have switched minds, they can never switch back with each other. Throughout the episode, the Professor and the Globetrotters try to find a way to solve the problem using two or more additional bodies, and, in the end, the solution is shown both in action and on the board.

Inversion
Keeler uses the method outlined in the proof to restore all minds to their respective bodies. Here are his transpositions. He uses thirteen switches total:


 * Sweet Clyde's body (receiving Dr Zoidberg's mind) ↔ Fry's body (receiving Sweet Clyde's mind)
 * Bubblegum Tate's body (receiving Fry's mind) ↔ Dr Zoidberg's body (receiving Bubblegum Tate's mind)
 * Sweet Clyde's body (receiving Bubblegum Tate's mind) ↔ Dr Zoidberg's body (receiving Dr Zoidberg's mind)
 * Bubblegum Tate's body (receiving Sweet Clyde's mind) ↔ Fry's body (receiving Fry's mind)
 * Sweet Clyde's body (receiving Leela's mind) ↔ Professor Farnsworth's body (receiving Bubblegum Tate's mind)
 * Bubblegum Tate's body (receiving Emperor Nikolai's mind) ↔ Washbucket's body (receiving Sweet Clyde's mind)
 * Sweet Clyde's body (receiving Hermes's mind) ↔ Leela's body (receiving Leela's mind)
 * Bubblegum Tate's body (receiving Bender's mind) ↔ Emperor Nikolai's body (receiving Emperor Nikolai's mind)
 * Sweet Clyde's body (receiving Amy's mind) ↔ Hermes's body (receiving Hermes's mind)
 * Bubblegum Tate's body (receiving Professor Farnsworth's mind) ↔ Bender's body (receiving Bender's mind)
 * Sweet Clyde's body (receiving Washbucket's mind) ↔ Amy's body (receiving Amy's mind)
 * Bubblegum Tate's body (receiving Bubblegum Tate's mind) ↔ Professor Farnsworth's body (receiving Professor Farnsworth's mind)
 * Sweet Clyde's body (receiving Sweet Clyde's mind) ↔ Washbucket's body (receiving Washbucket's mind)

However, this is not the fewest number of switches possible in this scenario. Because Fry and Zoidberg only switched with each other and no one else, and there is an odd number (1) of other switched groups of bodies, they could have been used as the two spare bodies, completing the restoration in only nine switches:


 * Fry's body (receiving Leela's mind) ↔ Professor Farnsworth's body (receiving Zoidberg's mind)
 * Zoidberg's body (receiving Emperor Nikolai's mind) ↔ Washbucket's body (receiving Fry's mind)
 * Fry's body (receiving Hermes's mind) ↔ Leela's body (receiving Leela's mind)
 * Zoidberg's body (receiving Bender's mind) ↔ Emperor Nikolai's body (receiving Emperor Nikolai's mind)
 * Fry's body (receiving Amy's mind) ↔ Hermes's body (receiving Hermes's mind)
 * Zoidberg's body (receiving Professor Farnsworth's mind) ↔ Bender's body (receiving Bender's mind)
 * Fry's body (receiving Washbucket's mind) ↔ Amy's body (receiving Amy's mind)
 * Zoidberg's body (receiving Zoidberg's mind) ↔ Professor Farnsworth's body (receiving Professor Farnsworth's mind)
 * Fry's body (receiving Fry's mind) ↔ Washbucket's body (receiving Washbucket's mind)

Had there been an even number of distinct switched groups, Fry's mind and Zoidberg's mind would have ended up back in the opposite bodies, and having already switched, they could not be switched back without two spare bodies. The solution given in the theorem works for all scenarios.

It is also not necessary for Clyde and Bubblegum (or Fry and Zoidberg) to take turns so often in the machine; it is only convenient for the presentation.

Proof


First let π be some k-cycle on [n] = {1 ... n} WLOG [without loss of generality] write: π = 1 2  ...  k  k+1  ... n    2  3  ...  1  k+1  ... n

Let  represent the transposition that switches the contents of a and b. By hypothesis π is generated by DISTINCT switches on [n]. Introduce two "new bodies" {x,y} and write π* = 1 2  ...  k  k+1  ... n x  y      2  3  ...  1  k+1  ... n x  y

For any i=1 ... k let σ be the (l-to-r) series of switches σ = (  ... ) (  ... ) () ()

Note each switch exchanges an element of [n] with one of {x,y} so they are all distinct from the switches within [n] that generated π and also from . By routine verification π* σ = 1 2  ... n x  y        1  2  ... n y  x

i. e. σ reverts the k-cycle and leaves x and y switched (without performing ).

NOW let π be an ARBITRARY permutation on [n]. It consists of disjoint (nontrivial) cycles and each can be inverted as above in sequence after which x and y can be switched if necessary via , as was desired.

Solution algorithm in plain English
Step 1: Have everybody who's messed up arrange themselves in circles, each facing the body their mind should land in (e.g., if Fry's mind is in Zoidberg's body, then the Zoidberg body should face the Fry body).

Step 2: Go get two "fresh" (as of yet never mind-swapped) people. Let's call them Helper A and Helper B.

Step 3: Fix the circles one by one as follows:

3.0) Start each time with Helper A and Helper B's minds in either their own or each other's bodies

3.1) Pick any circle of messed-up people you like and unwrap it into a line with whoever you like at the front

3.2) Swap the mind at the front of the line into Helper A's body

3.3) From back to front, have everybody in the line swap minds with Helper B's body in turn. (This moves each mind in the line, apart from the front one, forward into the right body)

3.4) Swap the mind in Helper A's body back where it belongs, into the body at the back of the line. Now the circle/line has been completely fixed. The one side effect is that for each time a circle is fixed, the Helpers' minds will switch places, but that's OK, see below

Step 4: At the very end, after all the circles have been fixed, mind-swap the two Helpers if necessary (i.e., in case there was originally an odd number of messed-up circles)

Note: This is not the exact algorithm used in the show. This algorithm sets i = 1 in the proof provided by the show, whereas you could actually set i to be any number from 1 to k. This algorithm also reverses the order of the final two switches in the provided proof. Explained simply, the provided proof's exact method for fixing any circle is this: Helper A could switch in turn back-to-front starting and stopping at any points in the circle, then Helper B would switch back-to-front through the remainder of the circle, Helper A would then switch with the first member of Helper B's arc, and Helper B would then switch with the first member of Helper A's arc.