How to label a cube I can't come up with a clever way to label a cube's faces, such that if I turned it in one of four directions, "Up", "Down", "Left", "Right", I'd know the resulting face by applying a function to the current face number, e.g., right(f) = f + 1, left(f) = f - 1. Any ideas?
Please excuse my terrible ASCII cube. I needn't label them 1 - 6.
Cube:
     ____
    / 5 /|   3 (back)
   /___/_|
4  | 1 |2|
   |___|/

     6 (underside)

 A: This is a PDF of my attempt to express rotations of the cube in terms of permutations of the faces. Trying to reproduce it here would cost us both some time.
A: Here's something that works, but it takes a little time to explain why it works. Label the top and bottom faces $\infty$ and $0$, respectively, and label the others $1, i, -1, -i$ in counterclockwise order looking down on the cube (where $i$ is the imaginary unit). If $z$ is the label of the current face at a particular location, then


*

*Right rotation is given by $z \mapsto -iz$,

*Left rotation is given by $z \mapsto iz$,

*Up rotation is given by $z \mapsto \frac{z + 1}{z - 1}$,

*Down rotation is given by $z \mapsto - \frac{z - 1}{z + 1}$.


If you know how to compute with complex numbers you should be able to verify all of this, although to really understand how this works you'll have to learn about the Riemann sphere, stereographic projection, and fractional linear transformations.
You can also explicitly write down the quaternions that represent the rotations you want. But really, none of this seems particularly useful for programming applications (in this special case; the quaternions are very useful for more general rotations). 
More generally, you are asking a kind of group-theoretic question, asking whether there are elegant ways to describe the group action of the symmetry group of the cube on the faces (equivalently, on the centers of the faces). There are several ways to do this; one can use permutations, which is the standard way to describe group actions, but since our symmetries act by rotations we can also look at ways to represent the special orthogonal group $\text{SO}(3)$ of rotations. Above I make use of two such representations: one identifies it with the projective unitary group $\text{PU}(2)$, whereas another identifies it with the projective symplectic group $\text{PSp}(1)$ of unit quaternions modulo $-1$. 
But again, I don't think any of this is particularly useful for a programming application.
A: A general function is simply a mapping, and the suggestion in your drawing can do that almost verbatim in any language:
$$
\begin{eqnarray}
R(1) &=& 2;\\
R(2) &=& 3;\\
R(3) &=& 4;\\
R(4) &=& 1;\\
R(5) &=& 2;\\
R(6) &=& 4;\\
\end{eqnarray}
$$
That is, (in C style)
R(x) = (x==1) ? 2 : (x==2) ? 3 : (x==3) ? 4 : (x==4) ? 1 : (x==5) ? 2 : 4; 

You could create a function for L, U, D, too (and presumably O for opposite), and this would work for any labeling. Note though that you should have a preferred orientation for each face/label (so that you can't rotate the cube keeping the same face forward). This you already knew.
What you are seeking is a labeling such that you can have a simpler function and corresponding labeling that fits, one that does not involve laboriously listing out the assigned values for each function and face. For some reason a case-by-case version is just not as elegant as a pre-calculus function. For example, to mimic the above function for $R$ and your labeling, you might use:
$$
\begin{eqnarray}
R(x) &=& (x \bmod 4) + 1\\
L(x) &=& (x-2 \bmod 4) + 1\\
U(x) &=& 5\\
D(x) &=& 6\\
\end{eqnarray}
$$
(note that the range of mod is from 0 to 3). 
These functions work very well for $x=1,2,3,4$ but not at all when $x=5,6$.
The difficulty as you've probably already noticed is how to assign labels and some other functions so that $U$ and $D$ are likewise easy to compute so that it will work for $x=5$ and $x=6$ too.
Again, one could use an arbitrary labeling and for each function come up with a polynomial that fits all 6 values. Suppose $R(5) = 2$ and $R(6) = 4$. 
Lagrange Interpolation is a one possible technique that already does this. For $n$ $x,y$ points you fit an $n-1$ degree polynomial to get 
$$
\begin{eqnarray}
R(x) &=& 2\cdot\frac{(x-2)(x-3)(x-4)(x-5)(x-6)}{(1-2)(1-3)(1-4)(1-5)(1-6)}\\
     &+& 3\cdot\frac{(x-1)(x-3)(x-4)(x-5)(x-6)}{(2-1)(2-3)(2-4)(2-5)(2-6)}\\
     &+& 4\cdot\frac{(x-1)(x-2)(x-4)(x-5)(x-6)}{(3-1)(3-2)(3-4)(3-5)(3-6)}\\
     &+& 1\cdot\frac{(x-1)(x-2)(x-3)(x-5)(x-6)}{(4-1)(4-2)(4-3)(4-5)(4-6)}\\
     &+& 2\cdot\frac{(x-1)(x-2)(x-3)(x-4)(x-6)}{(5-1)(5-2)(5-3)(5-4)(5-6)}\\
     &+& 4\cdot\frac{(x-1)(x-2)(x-3)(x-4)(x-5)}{(6-1)(6-2)(6-3)(6-4)(6-5)}\\
\end{eqnarray}
$$
(notice the cancellation of all terms to either 0 or 1) and after a lot of tedious calculation and simplification (or rather after Mathematica does it), you get:
$$R(x) = \frac{1}{120} (4800 - 10062 x - 7755 x^2 - 2635 x^3 - 405 x^4 - 23 x^5)$$
Using Zhen Lin's suggestion in the comment, one can take this mod 7 to get more manageable coefficients:
$$R(x) = (5 + 4 x + 6 x^2 + 4 x^3 + 6 x^4 + 5 x^5) \bmod 7$$
So two things to note...not only was that calculation tedious (just checking it is intractable by hand (more than it's worth)), but the resulting function is not particularly nice, and looks even more complex than just the plain old list.
At this point, maybe we could find a simpler function for a particular idiosyncratic labeling like Qiaochu's, using mod or some other simple functions, and it might even be simpler to do the finding, but I have no flash of insight right yet that it would allow it to work for all faces.
So I think the moral of the story is that, really, the easiest thing to code (and also quickest to execute, and easiest to understand later) will be the 'list-of-values' function.
The desire for a non-case based function is a natural one, like capturing a recurrence relation with a generating function, or fitting a function to a set of points. But in this case the result is as or more complex than the simple list.
