# Nezuji's Stuff

## The Mathematics Behind the Motion Picture "Cube"

(First Draft)

SPOILER WARNING: THIS ARTICLE CONTAINS SPOILERS ABOUT THE MOVIE "CUBE"! I RECOMMEND NOT READING ANY FURTHER UNTIL YOU HAVE SEEN THE ENTIRE FILM.

Introduction

"Cube" is a feature-length film about six people who wake up one day to find themselves trapped in a bizarre maze constructed from cube-shaped rooms, each with a hatch on every side (including floor and ceiling) which leads to another room. All the rooms are identical with the exception of the colours of the walls, which may be white, blue, green, red or amber.

Before I get any further, I should say that "Cube" is a fantastic film, and that its mathematical consistency (or lack thereof) really has no impact one way or the other on the excellent drama. I've seen people trying to discuss the maths behind "Cube" on film websites get shot down for missing the point of the film, so let me be clear: Yes, I understand that the film ISN'T about maths, as long as you understand that this article IS.

Furthermore, I didn't even start looking at the numbers seriously until I watched the movie with the commentary (I had the first version of the commentary, which included David Hewlett). On the commentary, the guys mention more than once that they took their ideas to a university mathematics professor (David W. Pravica, billed in the film's credits as "Math Consultant") who checked everything out and even helped them with the numbers in the movie, which tempted me to analyse it more substantially.

Learning about the numbers within The Cube

To begin the mathematical discussion, I said earlier that the rooms were identical, aside from a few colour variations. That's not strictly true. Fairly early on, Leaven notices that the crawlspace between each pair of rooms has two plates riveted inside, one for each room. The plates show a sequence of three numbers, each number having three digits, for a total of nine digits.

(Side note: There is some argument about Leaven's background. It is never explicitly stated in the film whether she is a high school or university student, only that she, "goes to school." It is not uncommon for university students to say that they go to "school", although because she never gives a degree title -- her "major" -- and she doesn't argue with Quentin's rhetorical question, "What do you do in school? Math," it seems fair to assume that she is, indeed, a high school student.)

Leaven's first thought on the significance of the numbers is that sequences in which one of the three-digit numbers is prime mark a room with a booby trap in it. This theory holds for quite some time, until Quentin jumps into an apparently safe room, only to be warned by Leaven and the others that he is about to be shredded by dozens of superfine wires. He manages to roll out of the way just in time to escape with only a gash on his leg.

Once Worth reveals that he knows the dimensions of the outer shell that contains The Cube (the structure formed by all the cube-shaped rooms), Leaven quickly does a rough measurement of the room's internal dimensions, figures out how many rooms there might be within The Cube, and theorises that the numbers represent three-dimensional Cartesian co-ordinates. The co-ordinates are oddly "encoded", although Leaven demonstrates that one reads them simply by summing the three digits in each number. For example, the marker sequence "666 897 466" is read as x = 18, y = 24 and z = 16. Although natural, Leaven's naming of the dimensions as x, y and z in that order is purely arbitrary, but as long as she keeps the ordering constant (which appears to happen in the film), it's also irrelevant. Her happy cry of, "It works!" presumably stems from a quick check that her theoretical range of co-ordinates from 1 to 26 in each of x, y and z can be written in this format. The available range of this format (assuming that we stick to decimal) is actually from 0 to 27, which turns out to be necessary later in the film.

(Side note: Given the outer shell's stated dimensions of 434 feet on a side, the knowledge that there is probably a one-room space between The Cube and the outer shell, and Leaven's internal measurement of the room at 14 feet on a side, some people have pointed out that she must have silently figured in the room's walls at 3/4 feet thick to arrive at her answer of a 26-room-wide Cube. Unfortunately, the walls are 1 1/2 feet thick, as we see in the film and hear on the commentary track that the hatchways are three feet long.)

Armed with this new information, the group decide to work their way toward the nearest "edge" (more properly, "side") of the cube to see what they can see. Along the way, Leaven discovers an anomalous marker that, once decoded, reads as (14, 27, 14). Although none of the characters realises this yet, this marks the Bridge Room, or BR for short. Regardless, most mathematicians would see this and freeze in their tracks. Reading this marker sequence on a room blows a diesel-train-sized hole in her current theory that The Cube is 26 rooms in each dimension, however Leaven merely quips that it's odd, and moves on. To compound the error, it's basically impossible for ANYONE to pass through a room with such a marker -- especially while trying to move along anything close to a straight path -- without noticing something odd about it, which I will explain later. Finally, there's one more problem with this plot point: Leaven labelled the first number on the marker sequences as x, and at this point in the film they are attempting to travel from x = 19 toward x = 26 ("X equals 19... we're seven rooms from the edge"). If she reads a marker that says they're at x = 14, Leaven should believe (not yet realising that the rooms move) that she's been taking them in the opposite direction. Oops.

The Revelation Room

After a very tense encounter with a sound-activated booby trap, the group manages to reach a hatchway that opens onto an apparently empty void. They construct a crude rope from their clothes, and Holloway is lowered out to try and swing/jump toward the outer shell in the hopes of finding a door within it, or at least of proving its existence to themselves. Holloway is killed, Quentin gets weird with Leaven, Worth confronts Quentin, and for his trouble is thrown down into the room below, where he discovers the body of Rennes, which was left behind long ago. The group collapses in confusion until Worth points out that judging by the position of the body, the room that killed Rennes has been replaced by the void outside The Cube, and theorises (correctly) that the rooms have been moving.

Leaven agrees, decides (probably correctly, since she finds the exit in the end) that the co-ordinates she's been reading so far are only the starting positions of the rooms, and tries to figure out how the marker numbers can be decoded to reveal their movement patterns. We hear her solution as she mutters to herself over her mathematical scratchings: "To find the original co-ordinates the numbers are... added together. To find the permutations... they're subtracted from one another." (You might need to turn up the volume to catch this line)

Now, this scene is the most interesting in the film from a mathematical perspective, because not only are we told a big part of how to calculate the rooms' movement patterns, we are also given the raw "permutations" for this room, the marker sequences of three neighbouring rooms, and the number of moves remaining before The Cube (or at least, this room) returns to its starting configuration. Furthermore, we know that the three surrounding rooms are all on one level, as neither Worth nor Quentin check the floor or ceiling hatches while reading the marker sequences. In addition, we are given a set of co-ordinates, but while it's implied that they indicate the current position of the room, it's never explicitly stated. The clincher is that, according to the commentary track, this scene was, "pretty much written by," David Pravica, the Math Consultant.

For ease of reference, I'll refer to the room the characters occupy in this scene as the Revelation Room, or RR for short.

Trying to figure out the details of the permutation encoding system

Leaven reveals that RR moves through 0, 1 and -1 on the x-axis, 2, 5 and -7 on the y-axis, and 1, -1, and 0 on the z-axis. There are two important details that we can deduce from these numbers.

The first is that these are almost certainly the differences between sequential pairs selected from three numbers, because they add together to equal zero. For example, let's assume that we have three numbers, a, b, and c. As long as a, b and c are Real numbers, then both
( (a - b) + (b - c) + (c - a) ) = 0
and
( (b - a) + (c - b) + (a - c) ) = 0
will be true. These formulas may also hold true for Imaginary numbers, but I'm just covering my bases; we're only interested in non-negative integers anyway. Since Leaven draws a parallel between the addition of the digits in a single number for resolving starting co-ordinates and the subtraction process which resolves the permutations -- and she also successfully leads the group to the exit, so we can assume that she's correct -- it seems safe to assume that the numbers involved in this subtraction process are the three single digits of one marker number. Certainly, there is no other logical possibility which allows us to know with as much certainty at the outset which dimension of x, y or z any "permutation" that we might calculate should apply to.

The second detail we can deduce is that these "permutations" should be relative to RR's starting co-ordinates. Assuming that we are correct in believing that the "permutations" are calculated by subtracting one digit of a single marker number from another, then the range of possible "permutations" is from -9 to 9. Leaven's model of The Cube locates the rooms on an axis from 1 to 26 in each dimension. Even if we adjust our "permutations" upward by 9, this still doesn't cover the necessary range. Also, from a logistical standpoint, it makes more sense that rooms shouldn't move terribly far (relatively speaking) from their starting positions, which would explain why whenever we see the three digits within a single marker number, they're often similar.

With these points established, it certainly seems possible that such a marker system could work for rooms within The Cube. The problem is that with these assumptions and the information given, the numbers given in relation to RR don't seem to work out.

Where it falls down

Let's jump back for a moment. Do you remember earlier when I said that anyone entering the room marked as (14, 27, 14) would notice something strange? There is only one way to write 27 in this three-digit encoding system: 999. No matter exactly what the "permutations" for this number represent, with the assumptions about their derivation given above they will be 0, 0, and 0. If the assumption that they somehow represent movements relative to the room's starting position is true, this means that BR always has at least one door flush to the external shell; it never enters into "the middle of The Cube" where our protagonists purportedly come across it for the first time. The other unusual point is that if we take all the shots from outside the rooms as accurate, BR is the only room that rests in a position outside the range 1-26. We would enter BR through one door to find a bare wall behind the opposite door, and nothing but thin air behind the other four doors. Therefore, it should be impossible to "pass through" BR unless it is in its starting position.

** MORE (HIGHLY DETAILED) STUFF TO COME HERE TRYING TO FIGURE OUT HOW THE "PERMUTATIONS" WORK AND SHOWING THAT THEY CAN'T (OR AT LEAST THEY DON'T SEEM TO, THAT'S WHY I NEED TO DO MORE WORK ON THEM) **

Prime numbers and trap identification

After all of this exposition on how The Cube works, Leaven reveals that she also has a new theory on how to identify the trapped rooms. It's not only prime numbers that indicate a trap, but also numbers that are the power of a prime. The first time I heard this, my reaction was the same as many others': Leaven's original prime number theory held for such a long time that it must have something to it, but if a number is a power of anything, it can't be prime!

After a little further thought I realised that this is not true. If you take a number to the power of 1, you get the number itself. Therefore every prime number is also the power of a prime - itself to the power of 1.

I've also seen it written that working this out in your head is not as "astronomical" a proposition as Leaven claims in the film, with only a handful of numbers that indicate trapped rooms. While Leaven perhaps slightly overstates the case, it is far from simple. Here's a list of powers-of-primes from 1 to 31 that took me five minutes to work out with a pen and paper (apologies if there are errors, I haven't double-checked them yet):
1
2, 4, 8, 16, 32, 64, 128, 256, 512
3, 9, 27, 81, 243, 729
5, 25, 125, 625
7, 49, 343
11, 121
13, 169
17, 289
19, 361
23, 529
29, 841
31, 961

Add to that all the rest of the prime numbers between 32 and 999:
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997

... plus that fact that Leaven doesn't have a pen and paper to carry with her to each room, and you begin to see how, with the unknown (and as it turns out, small) amount time remaining until the rooms move back into their starting positions, the problem is not as trivial as it seems at first glance.

(Side note: While Kazan is revealed to have a felicitous gift for factorisation, what he is giving is -- theoretically, and for the most part actually -- the number of terms in a prime factorisation of each marker number. This is a little confusing for anyone in the audience who knows much about mathematics as Leaven never says "prime factors" or "prime factorisation" anywhere in the film, instead asking just for "factors", which is a very different proposition. It's unusual that Kazan, as an autistic person, is able to guess from context that she wants the prime factorisation.)

Conclusion

Finally, with the machinations of The Cube finally explained (at least within the mind of Leaven), the survivors travel toward the Bridge Room in the hopes that they will make it in time, and that nothing else untoward will befall them on the way...

"Cube" is a wonderful movie. And the small bits of explanation about The Cube's mathematical workings that we can glean from the dialogue do form a good basis for a plausible room-numbering system. I have no doubt that the creators of "Cube" took their ideas to be verified and expanded upon by a mathematician who knew what he was talking about (in fact, the commentary track alludes to a working 5x5x5 room computer model constructed by David Pravica; I'd love to see that!). Unfortunately, there are an incredible number of errors and inconsistencies in the factual evidence we are presented with, so the exact details of the system's operation must remain a mystery.

Hosted by www.Geocities.ws