Rather than defining a permutation group from scratch every time, Magma provides a library of standard constructions — cyclic, dihedral, symmetric, alternating groups, and combinations of groups via direct and wreath products. It also provides a full set of arithmetic and predicate operations on individual permutations once you have them.
Standard Permutation Groups
A handful of intrinsics build well-known groups directly as permutation groups, acting on a standard set of generators.
CyclicGroup(n) constructs the cyclic group of order n with generator (1,2,...,n). DihedralGroup(n) constructs the dihedral group of degree n and order 2*n. SymmetricGroup(n) (or Sym(n)) builds the symmetric group of degree n, and AlternatingGroup(n) (or Alt(n)) builds the alternating group of degree n. AbelianGroup(GrpPerm, Q) builds the direct product of cyclic groups whose orders are given by the sequence Q.
> A := AbelianGroup(GrpPerm, [2, 2, 4]);
> A;
Permutation group A acting on a set of cardinality 8
Order = 16 = 2^4
(1, 2)
(3, 4)
(5, 6, 7, 8)
> D12 := DihedralGroup(GrpPerm, 12);
> D12;
Permutation group D12 acting on a set of cardinality 12
Order = 24 = 2^3 * 3
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
(1, 12)(2, 11)(3, 10)(4, 9)(5, 8)(6, 7)
Note that DihedralGroup(n) returns the dihedral group of degree n, which has order 2*n — so DihedralGroup(12) gives a group of order 24, not 12.
There is also YoungSubgroup(L), which given a sequence L of positive integers builds the direct product of symmetric groups on L[i] points each — the Young subgroup parameterized by L.
Direct and Wreath Products
Given two (or more) permutation groups, Magma can combine them into a larger group in several standard ways.
DirectProduct(G, H) builds the direct product of G and H as an intransitive group of degree equal to the sum of the two degrees, and also returns sequences of inclusion and projection homomorphisms relating the factors to the product.
WreathProduct(G, H) builds the wreath product G wr H with imprimitive action, while PrimitiveWreathProduct(G, H) builds G wr H with product action instead — the same abstract group, but represented on a different, larger permutation domain.
> G := SymmetricGroup(GrpPerm, 4);
> H := DihedralGroup(GrpPerm, 3);
> D := DirectProduct(G, H);
> D;
Permutation group D acting on a set of cardinality 7
Order = 144 = 2^4 * 3^2
(1, 2, 3, 4)
(1, 2)
(5, 6, 7)
(5, 6)
> W := WreathProduct(G, H);
> W;
Permutation group W acting on a set of cardinality 12
Order = 82944 = 2^10 * 3^4
(1, 5, 9)(2, 6, 10)(3, 7, 11)(4, 8, 12)
(1, 5)(2, 6)(3, 7)(4, 8)
(1, 2, 3, 4)
(1, 2)
Here the imprimitive wreath product W acts on only 12 points (4 blocks of size 3), whereas PrimitiveWreathProduct(G, H) on the same two groups acts on 64 points (3^4), since it represents the product action on tuples instead of blocks.
Arithmetic with Permutations
Once you have permutations, Magma supports the usual group arithmetic: g * h for the product, g^n for a power, g / h for g * h^-1, and g^h for the conjugate h^-1 * g * h. Commutators are written (g, h) for g^-1 * h^-1 * g * h, and left-normed commutators (g1, ..., gr) extend this to several elements evaluated left to right.
> G := Sym(9);
> x := G ! (1,2,4)(5,6,8)(3,9,7);
> y := G ! (4,5,6)(7,9,8);
> x*y;
(1, 2, 5, 4)(3, 8, 6, 7)
> x^-1;
(1, 4, 2)(3, 7, 9)(5, 8, 6)
> x^y;
(1, 2, 5)(3, 8, 9)(4, 7, 6)
> (x, y);
(1, 7, 3, 6)(4, 5, 9, 8)
Alongside arithmetic, several intrinsics report properties of a single permutation. Degree(g) returns the number of points moved by g. CycleStructure(g) returns the partition of the degree given by the cycle lengths of g, as a sequence of <length, count> pairs. Order(g) returns the order of g, and Sign(g)/IsEven(g) report whether g is an even or odd permutation.
> CycleStructure(x^2*y);
[ <6, 1>, <2, 1>, <1, 1> ]
> Order(x^2*y);
6
Equality of permutations is tested with eq/ne, and IsIdentity(g) (or IsId(g)) tests whether g is the identity.
Set Operations and Random Elements
Once a base and strong generating set (BSGS) is known for a group G, Magma can number its elements. NumberingMap(G) returns a bijection from G onto {1, ..., #G} based on the chosen BSGS, which is handy for building multiplication tables on small groups.
> G := DihedralGroup(GrpPerm, 6);
> f := NumberingMap(G);
> [ f(G.1 * G.2) ];
For larger groups, generating uniformly random elements directly can be expensive; RandomProcess(G) creates a product-replacement process, and repeated calls to Random(P) on that process produce random elements much faster than repeated calls to Random(G).
> G := WreathProduct(Sym(4), CyclicGroup(GrpPerm, 6));
> Order(G);
1146617856
> Random(G);
(1, 17, 12, 4, 18, 10, 3, 20, 9, 2, 19, 11)(5, 22, 13, 6, 21, 15)
(7, 24, 16)(8, 23, 14)
ElementSet(G, H) returns the elements of a subgroup H of G as an explicit set (only practical for small groups), and Representative(G) (or Rep(G)) returns some single element of G without any randomness guarantee.