# n-cubes 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. # how to build an n-cube 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. # n-cube vertex finding and drawing conventions for this section: * "n" are the number of dimensions. * vertices represented as unit bitvectors represented as integers interpreted as binary # cell vertices 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}) ``` ## enumerating all vertices ``` vertices = [] for v in 0 ... 2 ** n - 1 vertices.push vertex(v) ``` time complexity Θ(2 ** n). ## extracting sub-cell vertices for every k-face (1 ≤ k ≤ n - 1): * choose a k-element subset `s ⊂ {0 … n - 1}` * fix the bits at indices `¬s` (the complementary (n - k) positions) * this selects one of `2 ** (n - k)` parallel k-faces * iterate all `2 ** k` bit patterns on `s` * combine the fixed and varying bits to obtain the `2 ** k` vertices of that k-face pseudocode: ``` 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. ## illustration 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 * 1 vary, 2 fix - edges * 2 vary, 1 fix - squares * 3 vary, 0 fix - cubes 4-cube * 1 vary, 3 fix - edges * 2 vary, 2 fix - squares * 3 vary, 1 fix - cubes # algorithms * gospers hack for combinations # notes * since the edges of the faces of a cube overlap, it is not possible to draw a cube square by square without visiting some edges multiple times * volume: "side_length ** dimensions" * the facets (also called hyperfaces) of a n-polytope are the (n - 1)-faces (faces of dimension one less than the polytope itself) # what is the lowest dimensional shape that encapsulates the logic shared by all n-cubes? the line segment is the generative unit: * an n-cube is the n-fold cartesian product of the 1-cube. * its vertex set is all n-bit binary strings: {0,1}^n. 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: * symmetry of coordinate flipping emerges, * one can clearly see subfaces (edges) arranged around a cell, * and binary labels form a grid (e.g. "00", "01", "10", "11"). # counts cell counts * 4-cube * 0-cells: 16 vertices * 1-cells: 32 edges * 2-cells: 24 square faces * 3-cells: 8 cube volumes * 4-cell: 1 * 3-cube * 0-cells: 8 vertices * 1-cells: 12 edges * 2-cells: 6 square faces * 3-cell: 1 * 2-cube * 0-cells: 4 vertices * 1-cells: 4 edges * 2-cell: 1 adjacent cell counts * 3-cube * each vertex has 3 edges * each edge has 2 faces * 4-cube * each vertex has 4 edges * each edge has 3 faces # analogies * square to cube: extrude (sweep) the square along an axis perpendicular to its plane * circle to cylinder: extrude the circle along an axis perpendicular to its plane * circle to sphere: rotate the circle around one of its diameters * square to cylindrical surface: rotate the square around one of its edges (yields a curved surface with square cross-section)