| caydist | R Documentation |
Cayley distance and associated metrics for permutations
nmoved(a)
nfixed(a)
ncyc(a, discard1 = TRUE)
caydist(a, b = id)
a, b |
Permutations, coerced to cycle form |
discard1 |
Boolean, with default |
These functions support caydist().
Given a permutation a, nfixed(a) returns the number of
elements mapped to themselves and nmoved(a) returns the number
of elements moved [that is, elements not mapped to themselves];
ncyc(a) returns the number of cycles, and caydist()
returns the minimum number of transpositions needed to convert
a to b.
Generally return non-negative integers
Function ncyc(a, TRUE) returns the number of nontrivial cycles.
Thus, if a is (12)(567), then ncyc(a, TRUE) returns
2. If argument discard1 is FALSE, then length-1 cycles
are not discarded and ncyc(a, FALSE) returns 4 [because a
is equivalent to (12)(3)(4)(567), which has 4 cycles].
The Cayley distance between two permutations a and b is
defined a the least number of swaps to go from a to b.
Operationally:
d_\mathrm{Cayley}(a,b) = n-c(a^{-1}b)
where c(x) is ncyc(a, FALSE). Actually it uses
d_\mathrm{Cayley}(a,b) = n-c(ab^{-1}) internally, for
efficiency reasons. This does not matter, for the shape of ab is
the same as the shape of ba: for any permutations x,y we
have \operatorname{shape}(x) =
\operatorname{shape}(x^{-1}) and
\operatorname{shape}(x)=\operatorname{shape}(y^{-1}xy).
Then
\operatorname{shape}(ab) = \operatorname{shape}(b^{-1}a^{-1}) =
\operatorname{shape}(bb^{-1}a^{-1}b^{-1}) =
\operatorname{shape}(a^{-1}b^{-1}) = \operatorname{shape}(ba).
Robin K. S. Hankin
tidy
x <- rperm()
x
nmoved(x)
nfixed(x)
ncyc(x, discard1 = TRUE)
ncyc(x, discard1 = FALSE)
y <- rperm()
caydist(x,y)
all(caydist(x, y) == caydist(y, x))
z <- rperm()
all(caydist(x, z) <= caydist(x, y) + caydist(y, z))
mean(caydist(rperm(100,100))) # compare 100 - log(100) - gamma ~= 94.82
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.