Pólya counting
How many different necklaces of six beads in two colours are there, when turning or flipping a necklace gives the same one? Burnside's lemma counts orbits by averaging fixed points, and Pólya's cycle index makes that a polynomial you can substitute into.
Burnside's lemma
A group acting on a finite set has
orbits. For colourings of positions with colours, a permutation with cycles fixes colourings, since each cycle must be one colour.
import { symmetry, countColourings, cycleIndex, patternInventory } from "@ratmath/discrete";
countColourings(symmetry.cyclic(6), 2); // 14n necklaces
countColourings(symmetry.dihedral(6), 2); // 13n bracelets
countColourings(symmetry.cubeFaces(), 3); // 57n ways to colour a cube's faces
The cycle index
cycleIndex(symmetry.dihedral(4)).toString();
// "(1/4) s4 + (1/4) s1^2 s2 + (3/8) s2^2 + (1/8) s1^4"
patternInventory(symmetry.dihedral(4), ["r", "b"]).toString();
// "r^4 + r^3b + 2r^2b^2 + rb^3 + b^4"
The cycle index records the cycle type of every group element: , where is the number of -cycles. Substituting gives the count above. Substituting gives the pattern inventory, which counts orbits by how many of each colour they use: the square has two different colourings with two red and two blue corners, adjacent or opposite.
Groups
symmetry provides the cyclic, dihedral and symmetric groups and the 24 rotations of a cube acting on its faces. Any group works when given as { degree, generators } with 0-based permutations, or as a PermGroup from @ratmath/algebraic, such as the automorphism group of a graph from Isomorphism and spectra.
@ratmath/discrete and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.