2

Cycle of position means: {a, b, a, a} and {a, a, b, a} is the same.

Cycle of element means: {a, b, a, a} and {b, a, b, b} is the same.


Related: How to represent a list as a cycle

There's a solution of position cycle.

enter image description here

Notice that $(2)$ and $(3)$ is the same.

$$\rm{BBWBWW} \to \rm{WWBWBB} \to \rm{BBWWBW} = \rm{BBWWBW}$$

So how to delete the duplicates in this case?

Aster
  • 3,836
  • 1
  • 18
  • 44

1 Answers1

4
ClearAll[labelings, labelingFreeCanonize]

labelings[a_] := Module[{u = Union @ a}, a /. Map[Thread[u -> #] &] @ Permutations[u]]

labelingFreeCanonize = First @ Sort[canonize /@ labelings[#]] &;

Union[labelingFreeCanonize /@ t]

enter image description here

FWIW: Alternative ways to canonize:

1. Permute input list under the elements of CyclicGroup:

ClearAll[canonizeCG]
canonizeCG = First @ Sort @ Permute[#, CyclicGroup[Length @ #]] &;

2. Use Ordering @* Ordering to get the ranks of list elements instead of Position in @Mr.Wizard's canonize:

ClearAll[ranks, canonize2, canonize3]

ranks = Ordering @* Ordering;

canonize2[a_] := ranks[a] // Map[RotateLeft[a, # - 1] &] // Sort // First

or

canonize3[a_] := ranks[a] // Map[RotateLeft[a, #1 - 1] &] // #[[First@Ordering[#, 1]]] &

All three methods give the same result as canonize:

canonize /@ t == canonizeCG /@ t == canonize2 /@ t == canonize3 /@ t

True

kglr
  • 394,356
  • 18
  • 477
  • 896