The Caley distance measures the distance between two permutations (see this question for a definition https://math.stackexchange.com/questions/1932991/catalan-number-and-cayley-distance-inequality-in-permutation-group). Mathematica has lots of nice commands for permutations but the Caley distance is not a built-in function. I'm looking for Mathematica code that implements it.
Asked
Active
Viewed 1,245 times
2 Answers
5
If I understand correctly the Cayley distance, then
patt = RandomInteger[{0, 9}, 10]
dis = RandomSample @ patt
{3, 5, 5, 0, 1, 7, 7, 0, 7, 2}
{7, 7, 5, 1, 0, 0, 3, 2, 5, 7}
The distance should be the sum of the lengths of the cycles each diminished by one, or in other words the sum of the lengths diminished by the number of cycles; equal to 8 in this case because
perm = FindPermutation[patt, dis]
Cycles[{{1, 7, 2, 3, 9, 10, 8, 6}, {4, 5}}]
The distance is equal to the order of the permutation:
PermutationOrder @ perm
8
As a function:
CayleyDistance[patt_, dis_] :=
PermutationOrder @ FindPermutation[patt, dis]
corey979
- 23,947
- 7
- 58
- 101
0
If we want to measure the Caley distance using as inputs two permutations given in Cycle notation:
f[x_, y_] := Module[{z},
z = PermutationProduct[InversePermutation[Cycles[x]],Cycles[y]][[1]];
Length[Flatten[z]] - Length[z]]
Sergio Parreiras
- 409
- 2
- 11
Permute. – corey979 Oct 27 '16 at 00:02