inverse | R Documentation |
Calculates the inverse of a permutation in either word or cycle form
inverse(x)
## S3 method for class 'word'
inverse(x)
## S3 method for class 'cycle'
inverse(x)
inverse_word_single(W)
inverse_cyclist_single(cyc)
x |
Object of class |
W |
In function |
cyc |
In function |
The package provides methods to invert objects of class word
(the R idiom is W[W] <- seq_along(W)
) and also objects of class
cycle
(the idiom is
lapply(cyc,function(o){c(o[1],rev(o[-1]))})
).
The user should use inverse()
directly, which dispatches to
either inverse.word()
or inverse.cycle()
as appropriate.
Sometimes, using idiom such as x^-1
or id/x
gives neater
code, although these may require coercion between word form and cycle
form.
Function inverse()
returns an object of the same class as its argument.
Inversion of words is ultimately performed by function
inverse_word_single()
:
inverse_word_single <- function(W){ W[W] <- seq_along(W) return(W) }
which can be replaced by order()
although this is considerably
less efficient, especially for small sizes of permutations. One of my
longer-term plans is to implement this in C, although it is
not clear that this will be any faster.
Robin K. S. Hankin
cycle_power
x <- rperm(10,6)
x
inverse(x)
all(is.id(x*inverse(x))) # should be TRUE
inverse(as.cycle(matrix(1:8,9,8)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.