Learn R Programming

permutations (version 1.1-5)

permutation: Functions to create and coerce word objects and cycle objects

Description

Functions to create permutation objects. permutation is a virtual class.

Usage

word(M)
permutation(x)
is.permutation(x)
cycle(x)
is.word(x)
is.cycle(x)
as.word(x,n=NULL)
as.cycle(x)
cycle2word(x,n=NULL)
char2cycle(char)
cyc_len(n)
shift_cycle(n)
# S3 method for word
as.matrix(x,...)

Value

Returns a cycle object or a word object

Arguments

M

In function word(), a matrix with rows corresponding to permutations in word form

x

See details

n

In functions as.word() and cycle2word(), the size of the word to return; in function cyc_len(), the length of the cycles to return

char

In function char2cycle() a character vector which is coerced to a cycle object

...

Further arguments passed to as.matrix()

Author

Robin K. S. Hankin

Details

Functions word() and cycle() are rather formal functions which make no attempt to coerce their arguments into sensible forms. The user should use permutation(), which detects the form of the input and dispatches to as.word() or as.cycle(), which are much more user-friendly and try quite hard to Do The Right Thing (tm).

Functions word() and cycle() are the only functions in the package which assign class word or cycle to an object.

Function word() takes a matrix and returns a word object; silently coerces to integer.

Function cycle() takes a “cyclist”, that is, a list whose elements are lists whose elements are vectors (which are disjoint cycles); and returns an object of class “cycle”. It nicifies its input with nicify_cyclist() before returning it.

A word is a matrix whose rows correspond to permutations in word format.

A cycle is a list whose elements correspond to permutations in cycle form. A cycle object comprises elements which are informally dubbed ‘cyclists’. A cyclist is a list of integer vectors corresponding to the cycles of the permutation.

Function cycle2word() converts cycle objects to word objects.

Function shift_cycle() is a convenience wrapper for as.cycle(seq_len(n)); cyc_len() is a synonym.

It is a very common error (at least, it is for me) to use cycle() when you meant as.cycle().

The print method is sensitive to the value of option ‘print_word_as_cycle’, documented at print.Rd.

Function as.matrix.word() coerces a vector of permutations in word form to a matrix, each row of which is a word. To get a permutation matrix (that is, a square matrix of ones and zeros with exactly one entry of 1 in each row and each column), use perm_matrix().

In function as.word(), argument n cannot act to reduce the size of the word, only increase it. If you want to reduce the size, use trim() or tidy(). This function does not call word() except directly (e.g. it does not call size<-.word(), as this would give a recursion).

See Also

cyclist

Examples

Run this code

word(matrix(1:8,7,8)) # default print method coerces to cycle form

cycle(list(list(c(1,8,2),c(3,6)),list(1:2, 4:8)))

char2cycle(c("(1,4)(6,7)","(3,4,2)(8,19)", "(56)","(12345)(78)","(78)"))

jj <- c(4,2,3,1)

as.word(jj)
as.cycle(jj)

as.cycle(1:2)*as.cycle(1:8) == as.cycle(1:8)*as.cycle(1:2)  # FALSE!

x <- rperm(10,7)
y <- rperm(10,7)
as.cycle(commutator(x,y))

cyc_len(1:9)


Run the code above in your browser using DataLab