# Coloring the faces of a hypercube

I will restate the 3-D version of the problem. In how many ways can you color a regular cube with 2 colors up to a rotational isometry. The answer is of course a special case of Burnsides Lemma which can be used to show that the number of distinct face permutations is $\frac{1}{24}(N^6 + 3N^4 + 12N^3 + 8N^2)$ where $N$ is the number of colors used, $2$ in this case, which gives us an answer of $10$ distinct permutations.

My question is how can you expand this to a tesseract, and then more generally, to any hypercube. The rotational isometries of a cube are somewhat simple to comprehend, but the rotational isometries o hypercube are difficult to grasp (even after an hour of playing with the 4d rubiks cube app)

My initial thought was to consider the expansion of a tesseract as 8 interconnected cubelets. For the two color case each one of these cubelets has 10 distinct states. Which gives us $10^8$ non-distinct permutations of the hypercube. Or more generally, this reduces to how many distinct ways one can color a 8 faced 3-dimensional figure using 10 colors. So the complicated question of 4-dimensional isometries reduces to 3 dimensional rotational isometries of a octahedron.

But I'm a physicist so what the hell do I know :D

-
For d-dimensional polytopes the faces of dimension d-1 are usually referred to as facets of the polytope. For a 4-polytope there are two-dimensional faces (2-faces) and the 3-faces or facets. –  Joseph Malkevitch Sep 29 '10 at 18:05

Once someone else has done the hard work and come up with the answer, as Qiaochu has done, then it's easy to prove it on an ad hoc basis as this interloper (me) will do.

Consider an $n$-cube with faces coloured red and blue. Consider a set of $n$ balls. Colour the $j$-th ball red, blue or green according to the colours of the $j$-th pair of faces in the cube, that is if they both have the same colour give the ball that colour, else if they have different colours colour the ball green. Now a symmetry operation on the cube will shuffle the balls so the number of each colour of balls will be the same. Conversely given the $n$ coloured balls there will be various coloured cubes giving rise to the colour distribution of the balls, but these will all be equivalent under the full symmetry group of the cube. However for $n\ge 2$ each $2$-coloured cube has a non-rotational symmetry, so any two coloured cubes giving rise to the same colour distribution of balls are related by a rotation. Hence the number of $2$-coloured $n$-cubes up rotation is the same as the number of triples $(r,b,g)$ of nonnegative integers adding to $n$ and there are ${n+2\choose 2}$ of these.

One can repeat this with $k$-colours for the cube. This time one needs ${k+1\choose 2}$ colours for the balls, and the argument ensuring that rotations and the full symmetry group give the same answer requires $n>{k\choose 2}$ (why?).

Added (30/9/2010) One can get the general result using these considerations. For $n>{k\choose 2}$ one gets $${n+(k^2+k)/2-1\choose (k^2+k)/2-1}$$ colourings up to rotations. For $n\le {k\choose 2}$ there are $k$-colourings having no improper (determinant $-1$) symmetries. But any such colouring has no nontrivial symmetries at all. If two opposite faces have the same colour, one can reflect through a hyperplane parallel to them. So assume that no colour is opposite itself. Then if two pairs of opposite faces have the same two colours between them, one can reflect in a plane $x_i=x_j$or $x_i=-x_j$. Hence in these "special" colourings each pair of opposite faces has a distinct pair of distinct colours. Up to symmetry there are $${(k^2-k)/2\choose n}$$ of these special colourings. So for $n\le{k\choose 2}$ there are $${(k^2-k)/2\choose n}+{n+(k^2+k)/2-1\choose (k^2+k)/2-1}$$ up to rotational symmetries.

-
I am sure this works, but could you explain more carefully the step "However for n≥2 each 2-coloured cube has a non-rotational symmetry, so any two coloured cubes giving rise to the same colour distribution of balls are related by a rotation"? –  Qiaochu Yuan Sep 30 '10 at 8:38

First let's state the special case of Burnside's lemma that is relevant here.

Lemma: Let $G$ be a finite group acting on a finite set $X$. The number of ways to color the elements of $X$ with $z$ different colors, up to the action of $G$, is

$$\frac{1}{|G|} \sum_{g \in G} z^{c(g)}$$

where $c(g)$ is the number of cycles in the cycle decomposition of $g$ acting on $X$. (Proof.)

Here $X$ is the set of faces of a hypercube. In $n$ dimensions there are $2n$ such faces. $G$ is the subgroup of index $2$ in the hyperoctahedral group with determinant $1$, also known as the Coxeter group $D_n$. So our job now is to count, for each $k$, the number of elements of $D_n$ with $k$ cycles in the action on $X$.

Now, note that to analyze the action of $D_n$ on the faces it suffices to analyze the action of $D_n$ on the midpoints of the faces. But these are precisely the $2n$ points $(0, 0, ... \pm 1, ..., 0, 0)$, so writing the elements of $D_n$ as signed permutation matrices is very well-suited to analyzing their action on these points; in particular, it suffices to figure out the answer for a single signed cycle. But this turns out to be very simple: there are either one or two cycles depending on whether the product of the signs is $-1$ or $+1$.

(It might be helpful here to play with a specific example. Consider $\left[ \begin{array}{cc} 0 & 1 & 0 \\ 0 & 0 & -1 \\ -1 & 0 & 0 \end{array} \right]$ acting on the six points $(\pm 1, 0, 0), (0, \pm 1, 0), (0, 0, \pm 1)$ to get a feel for what's going on in the general case.)

From here I think it's easiest to work with generating functions because the combinatorics get a little messy. Begin with the identity

$$\sum_{m \ge 0} Z(S_n) t^n = \exp \left( z_1 t + \frac{z_2 t^2}{2} + \frac{z_3 t^3}{3} + ... \right)$$

where $Z(S_n)$ is the cycle index polynomial for the action of $S_n$ on $\{ 1, 2, ... n \}$. Each $z_i$ is the term that controls cycles of length $i$. We want to modify this generating function so that it tells us how the cycles in $D_n$ work. There are $2^i$ signed cycles of length $i$ which come in two flavors: half of them have positive sign product (two unsigned cycles) and half of them have negative sign product (one unsigned cycle), so to keep track of the total number of unsigned cycles we should replace $z_i$ with $2^{i-1} z^2 + 2^{i-1} z$. We also have to keep in mind that the determinant of a signed cycle is its sign product multiplied by $(-1)^{i+1}$, and we only want permutations with determinant $1$. So the generating function we want is

$$\sum_{n \ge 0} f_n(z) \frac{t^n}{n!} = \frac{1}{2} \left( \exp \left( \sum_{i \ge 1} \frac{2^{i-1} z^2 + 2^{i-1} z) t^i}{i} \right) + \exp \left( \sum_{i \ge 1} (-1)^{i+1} \frac{2^{i-1} z^2 - 2^{i-1} z) t^i}{i} \right) \right)$$

where $f_n(z) = \sum_{g \in D_n} z^{c(g)}$. After some simplification the above becomes

$$\sum_{n \ge 0} \frac{1}{|D_n|} f_n(z) t^n = \frac{1}{(1 - t)^{(z^2+z)/2}} + (1+t)^{(z^2-z)/2}.$$

Substituting $z = 2$ gives, at last, the answer

$$\sum_{n \ge 0} \frac{1}{|D_n|} f_n(2) t^n = \frac{1}{(1 - t)^3} + 1 + t.$$

In other words, for $n \ge 2$ we simply have $\frac{1}{|D_n|} f_n(2) = {n+2 \choose 2}$. This is such a simple answer that there should be a direct proof of it. I'll keep working on it. (There is a rather straightforward proof of the corresponding result with "hypercube" replaced by "simplex," so my guess is something along those lines is possible here.)

-
I am having trouble describing the direct proof. It goes something like this: for the analogous problem for a simplex we basically sort the colors according to some order by permutation. Here we instead sort opposite pairs of colors, but there is a low-dimensional restriction on how we can do this because of the determinant thing. –  Qiaochu Yuan Sep 29 '10 at 20:16

I presume you want to colour the faces of the cube? If so there are $2^6$ colourings as there are six faces. But do you want two colourings which are equivalent under rotations (or rotations and reflections) to count as as the same? If so then this is a classic application of Burnside's lemma.

Added If you want to do the same in higher dimensions then you need a good handle on the symmetries of an $n$-cube. Its convenient to centre the cube at the origin and take its vertices to be all points $(\pm1,\ldots,\pm1)$. Then all symmetries of the cube fix the origin and their matrices are "signed" permutation matrices: each row and column is all zero save for one entry which is $\pm1$. The rotations correspond to signed permutation matrices of determinant 1. The faces are the sets defined by $x_i=1$ and $x_i=-1$. Again use Burnside's lemma but the book-keeping gets fiddlier.

-
The question was really about extending Burnside's lemma to a higher dimensional figure. How would one answer the same question, but about a hypercube. –  crasic Sep 29 '10 at 9:19

Here is a contribution that treats the full symmetry group of the hypercube, not just rigid motions. This group can be obtained by labelling the vertices of the cube with the $2^n$ bit strings of length $n$ where adjacency is equivalent to having one bit different between two vertices. Then we obtain the full vertex permutation group of the hypercube by combining bit flips with bit position permutations e.g. combine a particular bit flip with a particular permutation of the bits and the result is an automorphism. Once we have these permutations we can use them to compute the induced permutation group on the two-faces.

This gives the following cycle indices for the face permutation groups containing rotations and reflections: for $n=2,$ $$a_{{1}},$$ for $n=3$, $$1/48\,{a_{{1}}}^{6}+3/16\,{a_{{2}}}^{2}{a_{{1}}}^{2}+1/6\,{a_{{3}}}^{2}+1/16\,{a_{{1 }}}^{4}a_{{2}}+{\frac {7}{48}}\,{a_{{2}}}^{3}+1/8\,{a_{{1}}}^{2}a_{{4}}+1/6\,a_{{6}} +1/8\,a_{{4}}a_{{2}},$$ for $n=4$, $${\frac {1}{384}}\,{a_{{1}}}^{24}+1/32\,{a_{{1}}}^{6}{a_{{2}}}^{9}+1/12\,{a_{{3}}}^{8 }+{\frac {3}{64}}\,{a_{{1}}}^{4}{a_{{2}}}^{10}+{\frac {7}{32}}\,{a_{{4}}}^{5}{a_{{2} }}^{2}+{\frac {1}{96}}\,{a_{{1}}}^{12}{a_{{2}}}^{6}+{\frac {3}{32}}\,{a_{{1}}}^{2}{a _{{2}}}^{11}+1/12\,{a_{{3}}}^{4}{a_{{6}}}^{2}+1/32\,{a_{{1}}}^{4}{a_{{4}}}^{5}+1/16 \,{a_{{1}}}^{2}a_{{2}}{a_{{4}}}^{5}+1/6\,{a_{{6}}}^{4}+1/8\,{a_{{8}}}^{3}+1/32\,{a_{ {4}}}^{6}+{\frac {5}{384}}\,{a_{{2}}}^{12},$$ and for $n=5$, $${\frac {1}{3840}}\,{a_{{1}}}^{80}+{\frac {1}{192}}\,{a_{{1}}}^{20}{a_{{2}}}^{30}+1/ 48\,{a_{{1}}}^{2}{a_{{3}}}^{26}+{\frac {13}{384}}\,{a_{{2}}}^{36}{a_{{1}}}^{8}+{ \frac {37}{192}}\,{a_{{4}}}^{18}{a_{{2}}}^{4}+1/24\,{a_{{1}}}^{2}{a_{{3}}}^{6}{a_{{6 }}}^{10}+1/10\,{a_{{5}}}^{16}+{\frac {1}{768}}\,{a_{{1}}}^{32}{a_{{2}}}^{24}+1/24\,{ a_{{1}}}^{2}{a_{{3}}}^{10}{a_{{6}}}^{8}+1/40\,{a_{{2}}}^{40}+{\frac {1}{192}}\,{a_{{ 1}}}^{8}{a_{{4}}}^{18}+1/32\,{a_{{1}}}^{4}{a_{{2}}}^{2}{a_{{4}}}^{18}+1/24\,{a_{{1}} }^{2}{a_{{3}}}^{2}{a_{{12}}}^{6}+1/8\,{a_{{6}}}^{13}a_{{2}}+1/8\,{a_{{8}}}^{10}+1/10 \,{a_{{10}}}^{8}+{\frac {1}{64}}\,{a_{{1}}}^{4}{a_{{2}}}^{38}+1/48\,{a_{{1}}}^{2}{a_ {{3}}}^{2}{a_{{6}}}^{12}\\+1/32\,{a_{{4}}}^{20}+1/24\,{a_{{12}}}^{6}a_{{6}}a_{{2}} .$$

These directly produce the following formulas for the number of colorings with at most $N$ colors. For $n=2$, we get $$N.$$ For $n=3$ we get $$1/48\,{N}^{6}+1/16\,{N}^{5}+3/16\,{N}^{4}+{\frac {13}{48}}\,{N}^{3}+{\frac {7}{24}} \,{N}^{2}+1/6\,N,$$ for $n=4$ we get $${\frac {1}{384}}\,{N}^{24}+{\frac {1}{96}}\,{N}^{18}+1/32\,{N}^{15}+{\frac {3}{64}} \,{N}^{14}+{\frac {3}{32}}\,{N}^{13}+{\frac {5}{384}}\,{N}^{12}+1/32\,{N}^{9}+{ \frac {7}{48}}\,{N}^{8}\\+{\frac {7}{32}}\,{N}^{7}+{\frac {11}{96}}\,{N}^{6}+1/6\,{N}^ {4}+1/8\,{N}^{3},$$ and for $n=5$ we have $${\frac {1}{3840}}\,{N}^{80}+{\frac {1}{768}}\,{N}^{56}+{\frac {1}{192}}\,{N}^{50}+{ \frac {13}{384}}\,{N}^{44}+{\frac {1}{64}}\,{N}^{42}+1/40\,{N}^{40}+1/48\,{N}^{28}+{ \frac {1}{192}}\,{N}^{26}+1/32\,{N}^{24}+{\frac {37}{192}}\,{N}^{22}+{\frac {7}{96}} \,{N}^{20}+1/24\,{N}^{18}+{\frac {29}{240}}\,{N}^{16}+1/8\,{N}^{14}+1/6\,{N}^{10}+{ \frac {17}{120}}\,{N}^{8} .$$ Note that the case for $n=3$ is OEIS A198833.

These cycle indices were computed with the following Maple program.

with(combinat, permute);
with(combinat, choose);

pet_autom2cycles :=
proc(src, aut)
local numa, numsubs;
local marks, pos, cycs, cpos, clen;

numsubs := [seq(src[k]=k, k=1..nops(src))];
numa := subs(numsubs, aut);

marks := [seq(true, pos=1..nops(aut))];

cycs := []; pos := 1;

while pos <= nops(aut) do
if marks[pos] then
clen := 0; cpos := pos;

while marks[cpos] do
marks[cpos] := false;
cpos := numa[cpos];
clen := clen+1;
od;

cycs := [op(cycs), clen];
fi;

pos := pos+1;
od;

return mul(a[cycs[k]], k=1..nops(cycs));
end;

hypercube_face_cind :=
proc(dim)
option remember;

local verts, v1, v2, faces, f, ff, fv, k, m, b,
d2, pos, fpos, perm, fperm, act, s;

if dim=1 then return FAIL fi;

verts := [];
for k from 2^dim to 2^(dim+1)-1 do
b := convert(k, base, 2);

verts := [op(verts), [seq(b[m], m=1..dim)]];
od;

faces := [];

for d2 in choose(dim, 2) do
for k from 2^(dim-2) to 2^(dim-1)-1 do
b := convert(k, base, 2);

f := [];
for ff in [[0,0], [0,1], [1,0], [1,1]] do
fv := [seq(-1, pos=1..dim)];
fv[d2[1]] := ff[1];
fv[d2[2]] := ff[2];

fpos := 1;
for pos to dim do
if fv[pos] = -1 then
fv[pos] := b[fpos];
fpos := fpos+1;
fi;
od;

f := [op(f), fv];
od;

faces := [op(faces), convert(f, set)];
od;
od;

s := 0;
for k from 2^dim to 2^(dim+1)-1 do
b := convert(k, base, 2);

for perm in permute(dim) do
act :=
proc(v)
local w, m;
w := [seq(v[m], m=1..dim)];
for m to dim do
if b[m]=1 then
w[m] := 1-w[m];
fi;
od;
w := [seq(w[perm[m]], m=1..dim)];
end;

fperm := map(x -> map(act, x), faces);
s := s + pet_autom2cycles(faces, fperm);
od;
od;

s/2^dim/dim!;
end;

bs_Ninto_cind :=
proc(vN, ind)
local subs1, indvars, v, pot, res;

res := ind;

indvars := indets(ind);
subs1 := [seq(indvars[k]=vN, k=1..nops(indvars))];

subs(subs1, res);
end;

v :=
proc(dim)
option remember;

bs_Ninto_cind(dim, hypercube_face_cind(dim));
end;



This MSE link computes another cube-related cycle index.

-