Minimal and Canonical Images

We describe a family of new algorithms for finding the canonical image of a set of points under the action of a permutation group. This family of algorithms makes use of the orbit structure of the group, and a chain of subgroups of the group, to efficiently reduce the amount of search which must be performed to find a canonical image. We present both a formal proof of correctness of our algorithms and experiments on different permutation groups, which compare our algorithms with the previous state of the art.


Background
Many combinatorial and group theory problems [14,4,2] are equivalent to finding, given a group G which acts on a finite set Ω and a subset X Ď Ω, a partition of X into subsets which are in the same orbit of G.
We can solve such problems by taking two elements of X, and searching for an element of G which maps one to the other. However, this requires a possible Op|X| 2 q checks, if all elements of X are in different orbits.
Given a group G acting on a set Ω, a canonical function maps each element of Ω to a distinguished element of its orbit under G. Using a canonical function we can check if two members of Ω are in the same orbit by applying the canonical function to both and checking if the results are equal. More importantly, we can solve the problem of partitioning X into orbitequivalent subsets by performing Op|X|q canonical image calculations, and then comparing the resulting canonical images.
The canonical image problem has a long history. Jeffrey Leon [9] discusses three types of problems on permutation groups -subgroup-type problems (finding the intersection of several groups), coset-type problems (deciding whether or not the intersection of a series of cosets is empty, and if not, finding their intersection) and canonical-representative-type problems. He claims to have an algorithm to efficiently solve the canonical-representative problem, but does not discuss it further. His comments have inspired mathematicians and computer scientists to work on questions related to minimal images and canonical images.
One of the most well-studied canonical-image problems is the canonical graph problem. Current practical systems derive from the partition refinement techniques, which were first practically used for graph automorphisms by McKay [11] in the Nauty system. There have been a series of improvements to this technique, including Saucy [1], Bliss [8] and Traces [12].
We cannot, however, directly apply the existing work for graph isomorphism to finding canonical images in arbitrary groups. This is because McKay's Graph Isomorphism algorithm only considers finding the canonical image of a graph under the action of the full symmetric group on the set of vertices. Many applications require finding canonical images under the action of subgroups of the full symmetric group.
One example of a canonicalizing function is, given a total ordering on X, to map each value of X to the smallest element in its orbit under G. This Minimal image problem has been treated by Linton in [10]. Pech and Reichard [13] apply techniques similar to Linton's to enumerate orbit representatives of subsets of Ω under the action of a permutation group on Ω. Linton gives a practical algorithm for finding the smallest image of a set under the action of a given permutation group. Our new algorithm, inspired by Linton's work, is designed to find canonical images: we extend and generalise Linton's technique using a new orbit-based counting technique. In this paper we first introduce some notation and explain the concepts that go into the algorithm, then we prove the necessary results and finish with experiments that demonstrate how this new algorithm is superior to the previously published techniques.

Minimal and Canonical Images
Throughout this paper, Ω will be a finite set, G a subgroup of SympΩq, and Ω will be ordered by some (not necessarily total) order ď.
If α P Ω, then we denote the orbit of α under G by α G .
Definition 2.1. A canonical function C for the action of G on Ω is a function C : Ω Ñ Ω such that, for all ω P Ω, it is true that • Cpωq P ω G , and • Cpω g q " Cpωq for all g P G.
In this situation we call Cpωq the canonical image of ω P Ω (with respect to G in this particular action).
For all ω P Ω we say that g ω P G is a canonicalizing element if and only if ω gω " Cpωq.
One way to view canonical images is to pick a well-defined representative from each orbit of G on Ω.
In practice we want to be able to find canonical images effectively and efficiently. In some situations we are interested in computing a canonicalizing element, which might not be uniquely determined. Our algorithms will always produce a canonicalizing element as a byproduct of search, and it is trivial to extract. We choose to make this explicit here to make the exposition clearer.
Minimal images are a special type of canonical image.
Remark 2.2. Suppose that ď is a partial order on Ω such that any two elements in the same orbit can be compared by ď.
Then the function Min ď , which for all ω P Ω maps ω to the smallest element in its orbit, is a canonical function.
In practical applications we are interested in more structure, namely in structures that G can act on naturally via the action on a given set Ω. These structures include subsets of Ω, graphs with vertex set Ω, sets of maps with domain or range Ω, and so on.
In this paper, our main application will be finding canonical images when acting on a set of subsets of Ω. Definition 2.3. Suppose that ď is a total order of Ω. Then we introduce a total order ď on PpΩq as follows: We say that A is less than B if and only if A contains an element a such that a R B and a ď b for all b P BzA.
Example 2.4. Let Ω :" t1, 2, 3, 4, 5, 6, 7u with the natural order and let A :" t1, 3, 4u, B :" t3, 5, 7u and C :" t3, 6, 7u. Now A is less than B, because 1 P A, 1 R B and 1 is smaller than all the elements in B, in particular those not in A. Moreover A is less than C for the same reason. Furthermore, B is less than C, because 5 P B, 5 R C, and if we look at CzB, then this only contains the element 6 and 5 is smaller.
If G is a subgroup of S Ω , and ω P Ω then we denote by G ω the point stabilizer of ω in G. For distinct elements x, y P Ω, we denote by G xÞ Ñy the set of all elements of G that map x to y. This set may be empty.
We remark that the above information is readily available from a stabilizer chain for the group G, which can be calculated efficiently. For further details we refer the reader to [5]. We now introduce some notation and then prove a basic result about cosets. Definition 2.5. Let G be a permutation group acting on a totally ordered set pΩ, ďq, and let ď denote the induced ordering as explained in Definition 2.3. Let H be a subgroup of G and S Ď Ω. Then we define the minimal image of S under H to be the smallest element in the set tS h |h P Hu with respect to ď.
In order to simplify notation, we will from now on write ď for the induced order and then we write MinpH, S, ďq for the minimal image of S under H. Lemma 2.6. Let G be a permutation group acting on a totally ordered set pΩ, ďq, and let H be a subgroup of G and S Ď Ω. Then the following hold for all x, y P Ω: (i) For all σ P H xÞ Ñy it is true that σ¨H y " H xÞ Ñy " H x¨σ .
Proof. If σ P H xÞ Ñy , then multiplication by σ from the right or left is a bijection on H, respectively. For all α P H x we have that α¨σ maps x to y and for all β P H y we see that σ¨β also maps x to y. This implies the first statement. For (ii) we just look at the definition: Minpσ¨H, S, ďq denotes the smallest element in the set tS σ¨h | h P Hu and MinpH, S σ , ďq denotes the smallest element in the set tpS σ q h | h P Hu, which is the same set.

Worked Example
We will find minimal, and later canonical, images using similar techniques to Linton in [10]. This algorithm splits the problem into small sub-problems, by splitting a group into the cosets of a point stabilizer. We will begin by demonstrating this general technique with a worked example.
We split our problem into pieces by looking at cosets of G 1 " xp3, 4, 5qy. The minimal image of S under G will be realized by an element contained in (at least) one of the cosets of G 1 , so if we find the minimal image of S under elements in each coset, and then take the minimum of these, we will find the global minimum. Lemma 2.6 gives that for all g P G it holds that Minpg¨G 1 , S, ďq " MinpG 1 , S g , ďq, and so we can change our problem from looking for the minimal image of S with respect to cosets of G 1 to looking at images of S g under elements of G 1 where g runs over a set of coset representatives of G 1 in G.
For each i P t1, ..., 6u we need an element g i P G iÞ Ñ1 (where any exist), so that we can then consider S g i .
As we are looking at the images of these sets under G 1 , we know that all images of a set containing 1 will contain 1, and all images of a set not containing 1 will not contain 1. From Definition 2.3, all subsets of t1, . . . , 6u containing 1 are smaller than all subsets not containing 1. This means that we can filter our list down to t1, 3, 5u, t3, 1, 2u and t3, 6, 1u.
Furthermore, G 1 fixes 2, so by the same argument we can filter our list of sets not containing 2, leaving only t3, 1, 2u. The minimal image of this under G 1 is clearly t3, 1, 2u (in this particular case we could of course also have stopped as soon as we saw t3, 1, 2u, as this is the smallest possible set of size 3). Now, let us consider what would happen if the ordering of the integers was reversed, so we are looking for MinpG, S, ěq, again with the induced ordering.
For the same reasons as above, we begin by calculating G 6 " xp3, 5, 4qy and by finding images of S for some element from each coset of G 6 in G.
As 5 is not fixed by G 6 , we can not reason about the presence or absence of 5 in our sets. There is an image of every set which contains 5, and there are even two distinct images of t6, 5, 3u which contain 5. Therefore we must continue our search by considering G 6,5 .
In this example, different orderings of t1, 2, 3, 4, 5, 6u produced different sized searches, with different numbers of levels of search required.

Minimal Images Under Alternative Ω orderings
As was demonstrated in Example 2.7, the choice of ordering of the set our group acts on influences the size of the search for a minimal image. In this section we will show how to create orderings of Ω which, on average, reduce the size of search for a minimal image.
We begin by showing how large a difference different orderings can make. We do this by proving that, for any choice ď of ordering of Ω, group G and any input set S, we can construct a minimal image problem that is as hard as finding MinpG, S, ďq, but where reversing the ordering on Ω makes the problem trivial.
Given n P N, a permutation group G on t1, ..., nu with some ordering ď and a subset S Ď t1, ..., nu, we construct a group H and a set T such that MinpG, S, ďq " MinpH, T, ďqXt1..nu, which shows that finding MinpH, T, ďq is at least as hard as finding MinpG, S, ďq. On the other hand, we will show that MinpH, T, ěq " T , and therefore no search is required at all. This is done in Lemma 3.5. An example along the way will illustrate the construction.
Definition 3.1. We fix n P N and we let k P N. For all j P N we define qpjq P N and rpjq P t1, ..., nu such that j " qpjq¨n`rpjq.
Let ext : G Ñ S k¨n be the following map: For all g P G and all j P t1, ..., k¨nu, the element extpgq maps j to qpjq¨n`rpjq g . Example 3.2. Let n " 4 and G " S 4 . Then we extend the action of G to the set t1, ..., 12u using the map ext.
For example g " p134q maps 4 to 1. We write 12 " 2¨4`4 and then it follows that extpgq maps 12 to 2¨4`4 g " 8`1 " 9. In fact g acts simultaneously on the three tuples p1, 2, 3, 4q, p5, 6, 7, 8q and p9, 10, 11, 12q as it does on p1, 2, 3, 4q. Definition 3.3. Fixing n, k P N and a subgroup G of S n , and using the map ext defined above, we say that H is the extension of G on t1, ..., k¨nu if and only if H " textpgq | g P Gu is the image of G under the map ext.
The extension H of G on a set t1, ..., k¨nu is a subset of S k¨n . We show now that even more is true: Lemma 3.4. Let n, k P N and G ď S n . Then the extension of G onto t1, ..., k¨nu is a subgroup of S k¨n that is isomorphic to G.
Proof. Let H :" extpGq be the image of G under the map ext and let a, b P G be distinct. Then let j P t1, ..., nu be such that j a ‰ j b . By definition extpaq and extpbq map j in the same way that a and b do, so we see that extpaq ‰ extpbq. Hence the map ext is injective. Therefore ext : G Ñ H is bijective.
Next we let a, b P G be arbitrary and we let j P t1, ..., k¨nu. Then the composition ab is mapped to extpabq which maps j to qpjq¨n`rpjq ab . Now rpjq ab " prpjq a q b and therefore the composition extpaq extpbq P S k¨n maps j to pqpjq¨n`rpjq a q extpbq " qpjq¨n`prpjq a q b . This is because rpjq a P t1, ..., nu.
Hence extpabq " extpaq extpbq, which means that ext is a group homomorphism and hence that G and its image are isomorphic.
Lemma 3.5. Let n P N and G ď S n . Let H denote the extension of G on t1, ..., pn`1q¨nu and let S Ď t1, ..., nu. Let T :" S Y tl¨n`l | l P t1..nuu, ď denote the natural ordering of the integers, and ě its reverse. For simplicity we use the same symbols for the ordering induced on PpΩq, respectively. Then Proof. Let h P H. Then by construction h stabilizes the partition r1, ..., n|n1 , ..., 2n|...|n¨n, ..., pn`1q¨ns. Moreover, for all i P t1, ..., nu and g P G we have that i g " i extpgq and so Lemma 3.4 implies that This proves the first statement.
For the second statement we notice that pn`1q¨n is now the smallest element of T , and it cannot be mapped to anything smaller, because it also is the smallest element available. So if we let h P H be such that T h " MinpH, T, ěq, then h fixes the point npn`1q. By definition of the extension, it follows that h also fixes k¨n for all k P t1 . . . nu. The next point of T under the ordering is n 2´1 . It cannot be mapped by h to n 2 , because n 2 is already fixed, hence h has to fix n 2´1 , too.
Arguing as above it follows that all points are fixed by h, thus in particular MinpH, T, ěq " T , as stated.

Comparing Minimal Images Cheaply
We describe some important aspects of Linton's algorithm for computing the minimal image of a subset of Ω. Definition 3.6. Suppose that pΩ, ďq is a totally ordered set and that G ď SympΩq. Then OrbpGq denotes the list of orbits of G on Ω, ordered by the size of the smallest element in each orbit with respect to ď.
A G-orbit will be called a unit if and only if it has size 1.
If S Ď Ω, then we say that a G-orbit is empty in S if and only if it is disjoint from S as a set, and we say that it is full in S if and only if it is completely contained in S.
Then OrbpGq " rt1, 4u, t2, 7, 8u, t3u, t5, 6us because this list contains all the G-orbits and they are ordered by the smallest element in each orbit, namely 1 in the first, 2 in the second, 3 in the third, which is a unit, and 5 in the last (because 4 is already in an earlier orbit).
The orbits t3u and t5, 6u are full in S, the orbit t2, 7, 8u is empty in S and t1, 4u is neither.
Lemma 3.8. Suppose that pΩ, ďq is a totally ordered finite set and that G ď SympΩq. If MinpG, S, ďq " MinpG, T, ďq and ω P Ω, then ω G is empty in S if and only if it is empty in T , and ω G is full in S if and only if it is full in T .
Proof. Let ω P Ω and suppose that ω G is empty in S. As ω G is closed under the action of G, and S 0 :" MinpG, S, ďq is an image of S under the action of G, we see that ω G is empty in S 0 and hence in T 0 :" MinpG, T, ďq. Thus ω G is empty in T , which is an image of T under the action of G. The same arguments work vice versa.
Next we suppose that ω G is full in S. Then it is full in S 0 " T 0 and hence in T , and the same way we see the converse.
We can now prove Theorem 3.9, which is the main technique used to reduce search. This allows us to prove the minimal image of some set S will be smaller than or equal to the minimal image of a set T , without explicitly calculating the minimal image of either S or T . Theorem 3.9. Suppose that G is a permutation group on a totally ordered finite set pΩ, ďq with list of orbits O :" OrbpGq, and that S and T are two subsets of Ω where |S| " |T |.
Suppose further that o P O is the first orbit in the list OrbpGq that is neither full in both S and T nor empty in both S and T . If o is empty in T , but not in S, then MinpG, S, ďq is strictly smaller than MinpG, T, ďq.
Proof. Suppose that o is empty in T , but not in S. Then o is empty in T 0 :" MinpG, T, ďq, but not in S 0 :" MinpG, S, ďq, and in particular T 0 and S 0 are distinct, as we have seen in Lemma 3.8. If ω P Ω, then the orbit ω G is closed under the action of G. Thus, if A Ď Ω and ω G is full in A, then for Let α :" min ď poq and let ω P Ω. If ω ň α, then ω R o, which means that the orbit ω G appears in the list O before o does. Then the choice of o implies that one of the following two cases holds: (i) ω G is full in both S and T . In particular, for all g P G we have that ω P S g X T g . (ii) ω G is empty in of both S and T . In particular, for all g P G we have that ω G X S g " ∅ and ω G X T g " ∅.
Since S 0 and T 0 are distinct, they must differ amongst the elements at least as large as α and, since they have the same cardinality, the smallest such element determines which one of S 0 and T 0 is smaller.
We recall that o " α G is empty in T and non-empty in S, so there exists some g P G such that α P S g . Then S g " S 0 and α R T 0 , so S 0 is strictly smaller that T 0 .
Here is an example how to use Theorem 3.9.
Going through the orbits as listed, we see that the first one is empty in S and T , the second one is full in S and T , and the third one gives a difference for the first time. It is empty in T , but not in S, so Theorem 3.9 yields that the minimal image of S is strictly smaller than that of T .

Static Orderings of Ω
In this section we look at which total ordering of Ω should be used to minimise the amount of time taken to find minimal images of subsets of Ω.
Given a group G we will choose an ordering on Ω such that orbits with few elements appear as early as possible. In particular, unit orbits should appear first. This is justified by the fact that unit orbits are always either full or empty. Also, we would expect smaller orbits to be more likely to be empty or full than larger orbits. This means that small orbits placed early in the ordering of Ω are more likely to lead to Theorem 3.9 being applicable, leading to a reduction in search.
Algorithm 1 heuristically chooses a new ordering for an ordered set Ω, only depending on the group G, under the assumption that the algorithm that computes minimal images will pick a point from a smallest non-unit orbit to branch on. This will not always be true -in practice Linton's algorithm branches on the first orbit which contains some point contained in one of the current candidates for minimal image.
However, we will show that in Section 5 that Algorithm 1 produces substantially smaller, and therefore faster, searches in practice.
It is not necessary in Line 8 of Algorithm 1 to choose the smallest element of P oints, choosing an arbitrary element will, on average, perform just as well. By fixing which point is chosen, we ensure that independent implementations will produce the same ordering and therefore the same canonical image.
If our intuition about Theorem 3.9 is correct, then MaxOrbit should almost always produce a larger search than MinOrbit, or a random ordering of Ω.

Implementing alternative orderings of Ω
Having calculated an alternative Order using FixedMinOrbit or Fixed-MaxOrbit, we could create a version of MinimalImage which accepted an explicit ordering. However, rather than editing the algorithm, we can instead perform a pre-processing step, using Lemma 3.11. Lemma 3.11. Consider a group G that acts on Ω " t1, . . . , nu and a permutation σ P Sym Ω . We define an ordering ď σ on t1, . . . , nu, where for all x, y P Ω we have that x ď σ y if and only if x σ ď y σ .
For the induced orderings ď and ď σ on subsets of Ω as in Definition 2.3 it holds that X ď σ Y ô X σ ď Y p for all subsets X and Y of Ω, and hence (simplifying notation) MinpG, S, ď σ q " MinpG σ , S σ , ďq σ´1 .
Proof. Following Definition 2.3, X ď σ Y if and only if there is an x P X such that x R Y and for all y P Y zX it holds that x ď σ y. By definition of ď σ , this is the case whenever x σ ď y σ , and since x σ P X σ and for all y σ in Y σ zX σ it holds that x σ ď y σ , it follows that X σ ď Y σ .
Consider the map ϕ σ : S G Ñ pS σ q G σ , which maps sets X P S G to X σ P pS σ q G σ . This map is bijective, and by the above it respects the order, so the second claim follows. Lemma 3.11 gives an efficient method to calculate minimal images under different orderings without having to alter the underlying algorithm. The most expensive part of this algorithm is calculating G σ , but this is still very efficiently implemented in systems such as GAP, and also can be cached so it only has to be calculated once for a given G and σ.

Dynamic Ordering of Ω
In Section 3.2, we looked at methods for choosing an ordering for Ω which allows a minimal image algorithm to search more quickly. There is a major limitation to this technique -it does not make use of the sets whose canonical image we wish to find.
In this section, instead of producing an ordering ahead of time, we will incrementally define the ordering of Ω as the algorithm progresses. At each stage we will consider exactly which extension of our partially constructed ordering will lead to the smallest increase in the number of sets we must consider.
We are not free to choose our ordering arbitrarily as we must still map two sets in the same orbit of G to the same canonical image. However, we can use different orderings for sets which are in different orbits of G.
Firstly, we will explain how we build the orderings which our algorithm uses.

Orderings
When building canonical images, we build orderings as the algorithm progresses. We represent these partially built orderings as ordered partitions.
Definition 4.1. Given k P N and P " rX 1 , ..., X k s, an ordered partition of PpΩq, then given two subsets S and T of Ω, we define S ă P T if and only if the cell which contains S occurs before the cell which contains T in P .
We say that P is G-invariant if and only if for all i P t1, ..., ku and g P G it holds that S P X k if and only if S g P X k .
A refinement of an ordered partition rX 1 , ..., X k s is an ordered partition rY 1,1 , Y 1,2 , ..., Y k,l s where l P N and such that, for all i P t1, ..., ku and j P t1, ..., lu, we have that Y i,j Ď X i .
A completion of an ordered partition X " rX 1 , ..., X k s is a refinement where every cell is of size one. Given an ordering for Ω, the standard completion of an ordered partition X orders the members of each cell of X using the ordering on sets from Definition 2.3.
In our algorithm we need a completion of an ordered partition, but the exact completion is unimportant -it is only important that given an ordered partition X, we always return the same completion. For this reason we define the standard completion of an ordered partition.
The orbits of G on Ω are t1, 2u and t3u. In particular all elements of G stabilize the partition P .
To see this, we let g :" p12q P G. We have that t1, 3u is in the first cell of Q, but t1, 3u g " t2, 3u, which is not in the first cell.
In Example 4.2 we only considered a very small group, as the size of PpΩq " 2 |Ω| . In practice we will not explictly create ordered partitions of PpΩq, but instead store a compact description of them, from which we can deduce the cell that any particular set is in.
In this paper, we will consider two methods of building and refining ordered partitions. We first define the orbit count of a set, which we will use when building refiners. Definition 4.3. Let G be a group acting on an ordered set Ω, and S Ď Ω. Define the orbit count of S in G, denoted OrbcountpG, Sq as follows: Given the list OrbpGq of orbits of G on Ω sorted by the their smallest member, the list OrbcountpG, Sq contains the size of the intersection |o X S| in place of o P OrbpGq.
We will see the practical use of Orbcount in Lemma 5.1.
Lemma 4.4. Suppose that pΩ, ďq is a totally ordered finite set and that G ď SympΩq. Then given two sets S, T Ď Ω such that there is g P G such that S g " T , then OrbcountpG, Sq " OrbcountpG, T q.
Proof. Let o P OrbpGq and g P G with S g " T . Then o g " o and α P po X Sq if and only if α g P po X Sq g , if and only if α g P po g X S g q " po X T q.
Definition 4.5. Let P be an ordered partition of PpΩq.
• If α P Ω, then the point refinement of P by α is the ordered partition Q, where each cell X i of P is split into two cells, namely tS | S P X i , α P Su, and tS | S P X i , α R Su. If one of these sets is empty, X i is not split.
• If G ď SympΩq and C " OrbcountpG, T q for some set T Ď Ω, the orbit refinement of P by C is the ordered partition Q, where each cell X i of P is split into two cells, namely tS | S P X i , OrbcountpG, Sq " Cu, and tS | S P X i , OrbcountpG, Sq ‰ Cu. If one of these sets is empty, X i is not split.

Algorithm
We will now present our algorithm. First, we give a technical definition which will be used in proving our algorithm correct. Definition 4.6. For all n P N we define L n to be the set of lists of length n whose entries are non-empty subsets of Ω. If X P L n , then as a convention we write X 1 , ..., X n for the entries of the list X.
If X P L n and H ď G ď S n is such that |G : H| " k P N and Q " tq 1 , ..., q k u is a set of coset representatives of H in G, then we define X Q to be the list whose first k entries are X q 1 1 , ..., X q k 1 , followed by X q 1 2 , ..., X q k 2 until the last k entries are X q 1 n , ..., X q k n . We note that X Q P L n¨k . Let X, Y P L n . We say that X and Y are G-equivalent if and only if there exist a permutation σ of t1, ..., nu and group elements g 1 , ..., g n P G such that, for all i P t1, ..., nu it holds that Y i " X g i i σ .
We now prove a series of three lemmas about coset representatives, which form the basis for the correctness proof of our algorithm. They are used to perform the recursive step, moving from a group to a subgroup. Lemma 4.7. Suppose that G is a permutation group on a set Ω, that H is a subgroup of G of index k P N and that T is a set of left coset representatives of H in G.
Then the following is true: (ii) If T " tt 1 , ..., t k u and g P G and if, for all i P t1, ..., ku we define q i :" gt i , then Q :" tq 1 , ..., q k u is also a set of coset representatives of H in G. In particular there is a bijection from Q to any set of left coset representatives of H in G.
Proof. By definition the index of H in G is the number of (left or right) cosets of H in G.
For the second statement we let i, j P t1, ..., ku be such that q i H " q j H, hence gt i H " gt j H. Then t´1 j t i " t´1 j g´1gt i P H and hence t i H " t j H. Hence i " j because t i and t j are from a set of coset representatives.
Lemma 4.8. Suppose that G is a permutation group on a set Ω and that S, T Ď Ω are such that the lists rSs and rT s are G-equivalent.
Let H be a subgroup of G of index k P N and let P " tp 1 , ..., p k u and Q :" tq 1 , ..., q k u be sets of left coset representatives of H in G.
Then rSs P and rT s Q are H-equivalent.
Proof. As rSs and rT s are G-equivalent, we know that there exists a group element g P G such that S g " T .
We fix g, for all i P t1, ..., ku we let t i :" gq i and we consider the set T :" tt i |i P t1, . . . , kuu. Then T is also a set of left coset representatives of H in G, by Lemma 4.7. As P is also a set of left coset representatives, we know that T and P have the same size, so there is a bijection from P to T . This can be expressed in the following way: There is a permutation σ P S k such that, for all i P t1, .., ku, it is true that p i σ H " t i H, which means that there is a unique h i P H such that p i σ h i " t i .
Let now S i :" S p i and T i :" T q i for i P t1, ..., ku, then hence rSs P and rT s Q are H-equivalent.
Lemma 4.9. Suppose that G is a permutation group on a set Ω, that n P N and that X, Y P L n are G-equivalent. Let H be a subgroup of G of index k P N and let P " tp 1 , ..., p k u and Q :" tq 1 , ..., q k u be sets of left coset representatives of H in G. Then X P and Y Q are H-equivalent.
Proof. As X and Y are G-equivalent, we know that there exist a permutation σ P S n and g 1 , ..., g n P G such that, for all i P t1, ..., nu: Y i " X g i i σ . We fix this permutation σ.
If i P t1, . . . , nu, then rX i σ s and rY i s satisfy the hypothesis of Lemma 4.8, so it follows that rX i σ s P and rY i s Q are H-equivalent.
So there exist a permutation α i P S k and group elements h i1 , ..., h ik P H such that pX i for all j P t1, ..., ku. Using σ and α 1 , ..., α k we define a permutation γ on 1, ..., n¨k: We express l P t1, ..., n¨ku uniquely as l " c l¨k`rl where c l P t0, ..., n´1u and r l P t1, ..., ku and we define l γ :" pc l`1 q σ¨k`r α c l`1 l . This is well-defined because of the ranges of c l and r l and it is a permutation because of the uniqueness of the expression and because σ and α 1 , ..., α n are permutations.
For each l P t1, ..., n¨ku, expressed as l " c l¨k`rl as we did above, we set h :" h c l`1 ,r l , X 1 l :" X pr l c l`1 and Y 1 l :" Y qr l c l`1 . Then X P " rX 1 1 , ..., X 1 n¨k s and Y Q " rY 1 1 , ..., Y 1 n¨k s. If we set p :" p r a c l`1 l and q :" q r l , then we have, for all l " c l¨k`rl , that X 1h l γ " pX p pc l`1 q σ q h " ppX σ c l`1 q p q h " Y q c l`1 " Y 1 l . This is H-equivalence.
We can now describe the algorithm we use to compute canonical images, and prove that it works correctly. Definition 4.10. Suppose that Ω is a finite set, that G is a permutation group on Ω, that L P L k and that P is an ordered partition on PpΩq.
• An Ω-selector is a function S such that -SpΩ, G, L, P q " ω P Ω, where |ω G | ą 1; -SpΩ, G, L, P q " SpΩ, G, M, P q whenever L and M from L k are G-equivalent.
• An Ordering refiner is a function O such that for all G-invariant partitions P of PpΩq -OpΩ, G, L, P q " P 1 , where P 1 is a G-invariant refinement of P ; -OpΩ, G, L, P q " OpΩ, G, M, P q whenever L and M from L k are G-equivalent.
An ordering refiner cannot return a total ordering, unless G acts trivially, as the partial ordering cannot distinguish between values contained in orbits of G.
Our method for finding canonical images is outlined in Algorithm 2. It recursively searches for the minimal image of a collection of lists, refining the ordering that is used as search progresses.
Proof. In every step of Algorithm 2 the list of considered sets is a list of elements of X G .
Let Ω be a finite set and G a permutation group on Ω. Let X, Y P L k be G-equivalent, and let P be a G-invariant ordered partition of PpΩq. Then CanImagepΩ, G, X, P q " CanImagepΩ, G, Y, P q.
Proof. We proceed by induction on the size of G. The base case is |G| " 1. As X and Y are G-equivalent, X and Y contain the same sets, possibly in a different order. For a given P and Ω, there is only one standard completion of P which gives a complete ordering on PpΩq, and so X and Y have the same smallest element under the standard completion of P and so the claim follows.
Consider now any non-trivial group G, and assume that the claim holds for all groups H where |H| ă |G|.
Definition 4.10 and the fact that S is an Ω-selector imply that Moreover, H is a proper subgroup of G. We take two sets Q 1 and Q 2 of coset representatives of H in G, which are not necessarily equal.
Since O is an ordering refiner, it holds that P 1 " OpΩ, H, X, P q " OpΩ, H, Y, P q By Lemma 4.9, X Q 1 and Y Q 2 are H-equivalent, and by definition P 1 is Ginvariant. If we identify the cell P 1 i of P 1 which contains the smallest element of X Q 1 , then L 1 X contains those elements of X Q 1 which are in P 1 i . Each of these elements is H-equivalent to an element of Y Q 2 , and therefore L 1 X is H-equivalent to L 1 Y . Then the induction assumption yields that CanImagepΩ, H, X 1 , P q " CanImagepΩ, G, Y 1 , P q, so the claim follows by induction.
We see from Theorem 4.11 and 4.12 that CanImagepΩ, G, X, P q " CanImagepΩ, G, Y, P q if and only if Y P X G .
We note that Algorithm 2 can easily be adapted to return an element g of G such that X g " CanImagepΩ, G, X, P q, by attaching to each set, when it is created, the permutation which maps it to the original input S. We omit this addition for readability.

Experiments
In this section, we will compare how well our new algorithms perform in comparison with the MinimalImage function of Linton's.
All of our experiments are performed in GAP [3] using code available in the Images package [7]. Where our algorithm requires it, we use the implementation of partition backtracking provided in the Ferret package [6].
We consider a selection of different canonical image algorithms and we analyze how they perform compared to each other, and compared to the traditional minimal image algorithm of Linton's, which we will refer to as MinImage.
The first three algorithms that we consider come from Section 3. They produce, given a group G on a set Ω, an ordering of Ω. This ordering is then used in MinImage.
(i) FixedMinOrbit uses results from Section 3 to calculate an alternative ordering of Ω, choosing small orbits first. (ii) FixedMaxOrbit works similarly to FixedMinOrbit, choosing large orbits first.
We also consider algorithms which dynamically choose which value to branch on as search progresses. We will use the following lemma for the proof of correctness for all our orderings.
Lemma 5.1. Let Ω be a finite set, G a permutation group on Ω, and P an ordered partition of PpΩq. Let L P L n , and Count " rOrbcountpG, Sq|S P Ls.
• Any function which accepts pΩ, G, L, P q and returns some ω P Ω with |ω G | ą 1, which is invariant under reordering the elements of Count, is an Ω-selector.
• Any function which accepts pΩ, G, L, P q and returns either P or the point refinement of P by some ω G for ω P Ω, and is invariant under permutation of the elements of Count, is an ordering refiner.
• Any function which accepts pΩ, G, L, P q and returns either P or the orbit refiner of P by some member of Count and is invariant under permutation of the elements of Count, is an ordering refiner.
Proof. The only thing we have to show is that, if L and M are G-equivalent, then any of the functions above yield the same result for inputs pΩ, G, L, P q and pΩ, G, M, P q. By Lemma 4.4, any G-equivalent lists L and M will produce the same list Count, up to reordering of elements, and hence the claim follows.
Firstly we define a list of orderings. Each of these orderings chooses an orbit, or list of orbits, to branch on -we will then make an Ω-selector by choosing the smallest element in any of the orbits selected, to break ties (we could choose any point, as long as we picked it consistently). Each of these algorithms operates on a list L P L k . In each case we look for an orbit, ignoring orbits of size one (as fixing a point which was already fixed leads to the same group).
Firstly we will consider two algorithms which only consider the group, and not L: (i) MinOrbit Choose a point from a shortest non-trivial orbit which has a non-empty intersection with at least one element of L. (ii) MaxOrbit Choose a point from a longest non-trivial orbit which has a non-empty intersection with at least one element of L.
We also consider four algorithms which consider both the group, and L. In the following, for an orbit o The motivation for RareOrbit is that this is the branch which will lead to the smallest size of the next level of search -this exactly estimates the size of the next level if our ordering refiner only fixed a point in orbit o. We therefore expect, conversely, CommonOrbit to perform badly and to produce very large searches.
One limitation of RareOrbit is that it will favour smaller orbits -in general we want to minimize the size of the whole search. The idea here is that if we have two levels of search where we split on an orbit of size two, and each time create 10 times more sets is equivalent to splitting once on an orbit of size four, and creating 100 times more sets. RareRatioOrbit compensates for this. We expect that CommonRatioOrbit is the inverse of this, so we also expect it to perform badly.
For each of these orderings, we use the ordering refiner which takes each fixed point of G in their order in Ω, and performs a point refinement by each recursively in turn. By repeated application of Lemma 4.4, this is a G-invariant ordering refiner.
We also have a set of orderings which make use of orbit counting. To keep the number of experiments under control, in each case we used the RareOrbit strategy to choose which point to branch on next, but then also build an orbit refiner.
Given an unordered list of orbit counts, (i) RareOrbitPlusMin chooses the lexicographically smallest one.
(ii) RareOrbitPlusRare chooses the least frequently occurring orbit count list (using the lexicographically smallest to break ties). (iii) RareOrbitPlusCommon chooses the most frequently occurring orbit count list (using the lexicographically smallest to break ties).

Experiments
In this section we perform a practical comparison of our algorithms, and the Minimum algorithm of Linton, for three different families of problems: grid groups, m-sets, and primitive groups.

Experimental Design
We will consider three sets of benchmarks in our testing. In each experiment, given a group G of permutations of t1, . . . , nu, we will run an experiment with each of our orderings to find the canonical image of a set of size X n 2 \ , X n 4 \ and X n 8 \ . We run our algorithms on a randomly chosen conjugate of each primitive group, to randomise the initial ordering of the integers the group is defined over. The same conjugate is used of each group in all experiments, and when choosing a random subset of size x from a set S, we always choose the same random subset. We use a timeout of five minutes for each experiment. We force GAP to build a stabilizer chain for each of our groups, before we begin our algorithm, as this can in some cases take a long time.
For each size of set, and each ordering, we measure three things. The total number of problems solved, the total time taken to solve all problems, counting timeouts as 5 minutes, and the number of moved points of the largest group solved. Our experiments were all performed on an Intel(R) Xeon(R) CPU E5-2640 v4 running at 2.40GHz, with twenty cores. Each copy of GAP was allowed a maximum of 6GB of RAM.

Grid Groups
In this experiment, we look for canonical images of sets in Grid groups (defined below).
We note that, while the construction of the grid group is done by starting with an n by n grid of points and permuting rows or columns independently of each other, we actually represent this group as a subgroup of S n¨n , and we do not assume prior knowledge of the grid structure of the action.
We ran experiments on the grid groups for grids of size 5ˆ5 to 100ˆ100, as described in section 5.2. The results of this experiment are given in Table  5.2.3.
The basic algorithm, Minimum, is only able to solve 22 problems within the timeout. FixedMinOrbit solves 43 problems, while being implemented as a simple pre-processing step to Minimum. The dynamic MinOrbit is able to solve 55 problems, and the best orbit-based strategy, SingleMax-Orbit, solves 70 problems. However the advanced techniques, which filter by orbit lists, perform much better. Even ordering by the most common orbit list leads to solving over 185 problems, and the best strategy, RareOrbit-PlusRare, solves 235 out of the total 288 problems.
Furthermore, for these large groups, the algorithms are still performing very small searches: For example FixedMinOrbit, on its largest solved problem with size X n 2 \ sets and a grid of size(12ˆ12), generates 793, 124 search nodes, while RareOrbitPlusMin produces only 183, 579 search nodes on its largest solved problem with X n 2 \ sets (65ˆ65).

M-Sets
Linton [10] considers, given integers n, m and k, taking the action of S n on the set of all m-sets, and then finding the minimal image of a random set of k points.
We ran experiments for n P t10, 15, . . . , 100u and m " 2, for n P t10, 15, . . . , 35u and m " 4, for n P t10, 15, 20u and m " 6 and also in the case where n " 10, m " 8 as described in Section 5.2. We choose these 30 experiments as these were the problems on which any of our techniques were able to solve in under 5 minutes. The results of our experiments are shown in Table 5 Similarly to our experiments on grid groups, we find that the standard Minimum algorithm is only able to solve a very small set of benchmarks. Some of the better algorithms, including FixedMinOrbit, are able to solve 9 problems. In particular, once again MinOrbit is not significantly better than FixedMinOrbit, although it is slightly faster on average over all problems.
However, the orbit-based strategies do much better, solving all the problems which we set. In the case of sets of size X n 8 \ , the best technique is able to solve all problems any technique can solve, in under 5 minutes. The largest solved problem, which was instance n " 35, m " 4 for a set of size X n 8 \ , is solved in only 6, 594 search nodes by RareOrbitPlusMin, while the largest solved problem of Minimum, n " 15, m " 4 takes 631, 144 search nodes.

Primitive Groups
In this experiment we look for canonical images of sets under the action of a primitive group which moves between 2 and 1, 000 points. We remove the   natural alternating and symmetric groups, as finding minimal and canonical images in these groups is trivial and can be easily special-cased. So we look at a total number of 5, 845 groups, each of which was successfully treated by at least one algorithm. We perform the experiment as described in section 5.2. The results are given in Table 6.
All algorithms are able to solve a large number of problems. This is unsurprising as many primitive groups are quite small (for example the cyclic groups), so any technique is able to brute-force search many problems. However, we can still see that, for the hardest problems X n 8 \ , many algorithms outperform Minimum, and the techniques which use extra orbit-counting filtering solve 300 more problems, and they run much faster.
For the easiest set of problems, X n 8 \ , we see that the algorithm RareOr-bitPlusMin, which usually performs best, solves slightly fewer problems. This is because there are a small number of groups where the extra filtering provides no search reduction, but still requires a small overhead in time. However, the total time taken is still much smaller, and the algorithm only fails to solve five problems. These five problems involve groups that are isomorphic to the affine general linear groups AGLp8, 2q, AGLp6, 3q and AGLp9, 2q, and the projective linear group PSLp9, 2q. This suggests that the linear groups may be a source of hard problems for canonical image algorithms in the future.

Experimental Conclusions
Our experiments show that using FixedMinOrbit is almost always superior to Minimum. As implementing FixedMinOrbit requires a fairly small amount of code and time over Minimum, this suggests any implementations of Linton's algorithm should have FixedMinOrbit added, as this provides a substantial performance boost, for relatively little extra coding.
Algorithms which dynamically order the underlying set, such as MinOrbit and RareOrbit provide only a small benefit over FixedMinOrbit. Algorithms which add orbit counting provide a much bigger gain, often allowing solving problems on groups many orders of magnitude larger than before, thereby greatly advancing the state of the art.

Conclusions
We present a general framework and new set of algorithms which find the canonical image of a set under the action of a permutation group. Our experiments show that our new algorithms outperform the previous state of the art, often by orders of magnitude.
Out basic framework runs on the concept of refiners and selectors and is not limited to finding only canonical images of subsets of Ω. In future work we will investigate families of refiners and selectors which allow finding canonical images for many other combinatorial objects.