notes and information about n-cubes that i could not find summarized in other places.
an n-cube (hypercube) is a geometric figure in n-dimensional space, defined by the 2^n points whose coordinates lie in [0,1]^n. all edges are equal in length and mutually orthogonal, with each spanning one of the n independent directions. every k-face is itself a k-cube, and the entire structure requires full n-dimensional euclidean space to preserve orthogonality without distortion. its symmetry group, the hyperoctahedral group, includes all permutations and sign flips of coordinate axes.
begin with a point. draw a line. at each endpoint, draw a new line at a right angle to all previous directions. repeat this process: at each vertex, extend a line in a new direction orthogonal to all existing axes. continue until you have introduced n orthogonal directions.
conventions for this section:
the n-cube has 2 ** n
distinct vertices.
index each vertex by an integer v ∈ 0 … (2 ** n) - 1
; the binary representation of v
supplies the cartesian coordinates:
coord_d = if (v >> d & 1) == 0 then -1 else 1 # 0 → -1, 1 → +1
hence
vertex(v) = (coord_0, coord_1, …, coord_{n - 1})
vertices = [] for v in 0 ... 2 ** n - 1 vertices.push vertex(v)
time complexity Θ(2 ** n).
for every k-face (1 ≤ k ≤ n - 1):
s ⊂ {0 … n - 1}
fix the bits at indices ¬s
(the complementary (n - k) positions)
2 ** (n - k)
parallel k-faces2 ** k
bit patterns on s
2 ** k
vertices of that k-facepseudocode:
for k in 1 ... n - 1 for mask in combinations(n, k) # k-bit mask of moving coordinates fixed_positions = ¬mask # n - k fixed coordinates for fixed_bits in 0 ... 2 ** (n - k) - 1 face = [] for varying_bits in 0 ... 2 ** k - 1 v = merge_bits(fixed_bits, varying_bits, fixed_positions, mask) face.push vertex(v)
merge_bits
places fixed_bits
into fixed_positions
and varying_bits
into mask
.
this procedure filters vertices instead of regenerating them, preserving Θ(2 ** n) total work.
the following templates are the basis for the 2-cube faces of a 4-cube. components at "f" are fixed for each face and all variations of "v" (either 0 or 1) create its vertices.
ffvv fvfv fvvf vffv vfvf vvff
the four vertices of one square face of a 4-cube with the pattern vfvf and fixed values v0v1:
0001 0011 1001 1011
3-cube
4-cube
the line segment is the generative unit:
the square (2-cube) is the first shape where the recursive, combinatorial structure becomes visually evident: vertices, edges, and enclosed area. it's also the lowest dimension where:
cell counts
4-cube
3-cube
2-cube
0-cells: 4 vertices
1-cells: 4 edges
2-cell: 1
adjacent cell counts
3-cube
4-cube
each vertex has 4 edges
each edge has 3 faces