RobinHankin / permutations

https://robinhankin.github.io/permutations/
5 stars 3 forks source link

Permutations lack their underlying permutation group #19

Open magviana opened 4 years ago

magviana commented 4 years ago

one should be able to pass the symmetric group in which, say, (23) belongs to

as to enable its evaluation within the group of interest (in the example below, S_4):

cpmat(as.cycle(allperms(4)[3]))
as.cycle(allperms(4)[3]) fp<-as.function(as.cycle(allperms(4)[3]))
fp(1) ## 1 fp(2) ## 3 fp(3) ## 2 fp(4) ## error

RobinHankin commented 4 years ago

Here is an excerpt of the email I sent in reply to magviana before I realised that there was new issue on github:

Your diagnosis of the problem is quite right, and the error is caused by the coercion to cycle form. This issue was a major major headache when I was developing the package (exceeded only by the problem of the identity element):

 > as.function(allperms(4)[3])
function (a) 

x[, a]

<environment: 0x7fe299d741f8>

> f <- as.function(allperms(4)[3])

> f(4)

[1] 4

In general, word form is better for dealing with permutation matrices. In your case we are thinking about the cycle (23) and we can use the second argument of as.word():

> as.function(as.word(as.cycle(2:3),n=9))(8)

[1] 8

Note also that most of the package is vectorized:

> as.function(allperms(4))(4)

 [1] 4 3 4 2 3 2 4 3 4 1 3 1 4 2 4 1 2 1 3 2 3 1 2 1