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 with a product such that
- the product is associative: ;
- there is an identity with for every ;
- every element has an inverse with .
The product need not be commutative. When it is ( always) the group is abelian. The number of elements is the order , and the order of an element is the least with .
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
| Call | Group | Order | Elements are |
|---|---|---|---|
| cyclic(n) | , the turns of a regular n-gon | exponents k, printed | |
| dihedral(n) | , all symmetries of a regular n-gon | pairs [k, f] printed | |
| symmetric(n), alternating(n) | and the even permutations | , | permutations, printed in cycle notation |
| quaternion() | 8 | printed 1, i, −1, … | |
| dicyclic(n) | : , , | pairs [k, f] printed | |
| kleinFour() | 4 | pairs | |
| GL(n, p), SL(n, p) | invertible matrices over , and those of determinant 1 | matrices of whole numbers mod p | |
| PSL(n, p) | modulo its centre | e.g. 60, 168 | cosets |
| heisenberg(p) | upper unitriangular 3×3 matrices over | matrices |
The dihedral group is written with the number of sides, so , the symmetries of a square, has 8 elements. (Some books call it .) Here turns the polygon by of a revolution and reflects it, so .
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 , then , 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 -cycle is transpositions, , so the sign of a permutation of points with cycles (fixed points counted) is . The same parity is the parity of the number of inversions, pairs put out of order. The sign is a homomorphism onto 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 is the set of pairs multiplied entry by entry. The semidirect product twists this: each acts on by an automorphism , and
With and , where the generator of acts by , this is metacyclic(m, k, r); it needs . The dihedral group is with , 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 has exactly one solution . 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.
@ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.