Groups

Groups and how to build them

A group is a set with a way of combining two elements that can always be undone. The symmetries of a square, the shuffles of a deck, the invertible matrices mod 3: each is a group, and this page shows how to make them and look inside.

What a group is

A group is a set GG with a product abab such that

  • the product is associative: (ab)c=a(bc)(ab)c = a(bc);
  • there is an identity ee with ea=ae=aea = ae = a for every aa;
  • every element has an inverse a−1a^{-1} with aa−1=a−1a=eaa^{-1} = a^{-1}a = e.

The product need not be commutative. When it is (ab=baab = ba always) the group is abelian. The number of elements is the order ∣G∣|G|, and the order of an element aa is the least k≥1k \ge 1 with ak=ea^k = e.

The library holds a finite group by listing all of its elements, so it suits groups of up to a few thousand elements: every group a course meets, and many more. Elements can be anything (numbers, permutations, matrices, pairs) as long as the group knows how to multiply them and how to tell two of them apart.

The named families

CallGroupOrderElements are
cyclic(n)CnC_n, the turns of a regular n-gonnnexponents k, printed aka^k
dihedral(n)DnD_n, all symmetries of a regular n-gon2n2npairs [k, f] printed rksfr^k s^f
symmetric(n), alternating(n)SnS_n and the even permutations AnA_nn!n!, n!/2n!/2permutations, printed in cycle notation
quaternion()Q8={±1,±i,±j,±k}Q_8 = \{\pm1, \pm i, \pm j, \pm k\}8printed 1, i, −1, …
dicyclic(n)Dicn\mathrm{Dic}_n: a2n=1a^{2n} = 1, x2=anx^2 = a^n, xax−1=a−1xax^{-1} = a^{-1}4n4npairs [k, f] printed akxfa^k x^f
kleinFour()V4=C2×C2V_4 = C_2 \times C_24pairs
GL(n, p), SL(n, p)invertible matrices over Fp\mathbb F_p, and those of determinant 1∏i<n(pn−pi)\prod_{i<n}(p^n - p^i)matrices of whole numbers mod p
PSL(n, p)SL(n,p)SL(n,p) modulo its centree.g. 60, 168cosets
heisenberg(p)upper unitriangular 3×3 matrices over Fp\mathbb F_pp3p^3matrices

The dihedral group is written DnD_n with nn the number of sides, so D4D_4, the symmetries of a square, has 8 elements. (Some books call it D8D_8.) Here rr turns the polygon by 1/n1/n of a revolution and ss reflects it, so sr=r−1ssr = r^{-1}s.

import { dihedral, symmetric, quaternion, GL } from "@ratmath/structures";

const D = dihedral(4);
D.elements.map((x) => D.format(x));   // ["e", "r", "s", "r²", "rs", "r³s", "r³", "r²s"]
D.format(D.mul("r", "s"));            // "rs"
D.format(D.mul("s", "r"));            // "r³s": the product depends on the order
D.elementOrder("rs");                 // 2: every reflection has order 2

const S = symmetric(3);
S.format(S.mul("(1 2)", "(2 3)"));    // "(1 2 3)": first (2 3), then (1 2)

const Q = quaternion();
Q.format(Q.mul("i", "j"));            // "k"
Q.format(Q.mul("j", "i"));            // "−k"

const G = GL(2, 3);
G.order;                              // 48
G.centre().elements.map((x) => G.format(x));   // ["[1 0; 0 1]", "[2 0; 0 2]"]

Elements can be named by the way they print: "r²s" or "r^2 s", "(1 2 3)", "-i". Products of permutations follow the rule for composing functions: mul(a, b) means first bb, then aa, the same convention as algebraic's PermGroup.

Even and odd permutations

Every permutation is a product of transpositions, and the number of them is always even or always odd. A kk-cycle is k−1k - 1 transpositions, (1 2 3 4)=(1 4)(1 3)(1 2)(1\,2\,3\,4) = (1\,4)(1\,3)(1\,2), so the sign of a permutation of nn points with cc cycles (fixed points counted) is (−1)n−c(-1)^{n-c}. The same parity is the parity of the number of inversions, pairs i<ji < j put out of order. The sign is a homomorphism onto {±1}\{\pm1\} and its kernel is the alternating group.

import { sign, isEven, inversions } from "@ratmath/structures";

sign("(1 2 3 4)", 4);       // −1: odd
isEven("(1 2)(3 4)", 4);    // true
inversions([2, 0, 1]);      // 2, so (1 3 2) is even

New groups from old

The direct product G×HG \times H is the set of pairs (g,h)(g, h) multiplied entry by entry. The semidirect product N⋊HN \rtimes H twists this: each hh acts on NN by an automorphism φh\varphi_h, and

(n1,h1)(n2,h2)=(n1 φh1(n2),  h1h2). (n_1, h_1)(n_2, h_2) = (n_1\,\varphi_{h_1}(n_2),\; h_1h_2).

With N=CmN = C_m and H=CkH = C_k, where the generator of HH acts by x↦xrx \mapsto x^r, this is metacyclic(m, k, r); it needs rk≡1(modm)r^k \equiv 1 \pmod m. The dihedral group is Cn⋊C2C_n \rtimes C_2 with r=−1r = -1, and metacyclic(7, 3, 2) is the smallest nonabelian group of odd order, of order 21. The library checks that the twisting really is an action by automorphisms, and refuses it otherwise.

import { directProduct, semidirectProduct, metacyclic, cyclic, kleinFour, isIsomorphic } from "@ratmath/structures";

const P = directProduct(cyclic(2), cyclic(3));
String(P);                            // "C2 × C3"
P.isCyclic;                           // true: C2 × C3 is C6

const F21 = metacyclic(7, 3, 2);      // C7 ⋊ C3
F21.order;                            // 21
F21.isAbelian;                        // false

// C4 ⋊ C2 with the generator inverting C4 is the dihedral group of the square
const D = semidirectProduct(cyclic(4), cyclic(2), (h) => (x) => (h ? (4 - x) % 4 : x));
D.order;                              // 8

Groups from a table, or from any multiplication

A finite group is completely described by its Cayley table, the grid of all products. Every row and every column of the table lists each element exactly once (a Latin square), because ax=bax = b has exactly one solution x=a−1bx = a^{-1}b. The converse fails: a Latin square with an identity need not be associative, so Group.fromTable checks associativity too.

import { Group, cyclic, kleinFour, isIsomorphic } from "@ratmath/structures";

String(cyclic(4).cayleyTable());
// ·  │ e  a  a² a³
// ───┼────────────
// e  │ e  a  a² a³
// a  │ a  a² a³ e
// a² │ a² a³ e  a
// a³ │ a³ e  a  a²

const V = Group.fromTable([[0, 1, 2, 3], [1, 0, 3, 2], [2, 3, 0, 1], [3, 2, 1, 0]], { labels: ["e", "a", "b", "c"] });
V.isCyclic;                           // false: every element has order 1 or 2
isIsomorphic(V, kleinFour());         // true

// the nonzero numbers mod 11 under multiplication, generated by 2
const U = Group.generate({ generators: [2n], identity: 1n, mul: (a, b) => (a * b) % 11n });
U.order;                              // 10
U.isCyclic;                           // true: 2 is a primitive root mod 11

The explorer takes any of these names, and products of them such as S3 × C2; the table of small groups names every group of order at most 20.

Try itEdit the code and run it with @ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs