Section 18 Permutations

There is an additional package you can add to work with permutations in R. The first time you use it, you will likely have to retrieve it. Got to the Packages tab in the lower right corner. Choose Install and search for permutations in the Packages window.

require(permutations)
## Loading required package: permutations
## 
## Attaching package: 'permutations'
## The following object is masked from 'package:pracma':
## 
##     size
## The following object is masked from 'package:stats':
## 
##     cycle

You can define permutations via their 1-line notation. Thus,

f <- as.word(c(9,2,6,3,5,4,1,7,8))

And then give its disjoint cycle type as

as.cycle(f)
## [1] (1987)(364)
inverse(f)
## [1] (1789)(346)

We can also input a permutation in cycle notation

g <- as.cycle(c(1,4,2))

R multiplies permutations in the opposite order that we do in class. That is, it applies them from left to right. This is something that one needs to be used to in working with permutations. So in this package (f*g)(1) means g(f(1)) as upi cam see here.

f
## [1] (1987)(364)
g
## [1] (142)
f * g
## [1] (19874362)
g * f
## [1] (13642987)

You can tell if a permutation is even or odd

is.even(f)
## [1] FALSE
is.even(g)
## [1] TRUE
S4 <- allperms(4)
S4
##  [1] ()       (34)     (23)     (234)    (243)    (24)    
##  [7] (12)     (12)(34) (123)    (1234)   (1243)   (124)   
## [13] (132)    (1342)   (13)     (134)    (13)(24) (1324)  
## [19] (1432)   (142)    (143)    (14)     (1423)   (14)(23)
is.even(S4)
##  [1]  TRUE FALSE FALSE  TRUE  TRUE FALSE FALSE  TRUE  TRUE
## [10] FALSE FALSE  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE
## [19] FALSE  TRUE  TRUE FALSE FALSE  TRUE
A4 <- S4[is.even(S4)]
A4
##  [1] ()       (234)    (243)    (12)(34) (123)    (124)   
##  [7] (132)    (134)    (13)(24) (142)    (143)    (14)(23)
cayley(A4)
##          ()       (234)    (243)    (12)(34) (123)    (124)   
## ()       ()       (234)    (243)    (12)(34) (123)    (124)   
## (234)    (234)    (243)    ()       (124)    (12)(34) (123)   
## (243)    (243)    ()       (234)    (123)    (124)    (12)(34)
## (12)(34) (12)(34) (132)    (142)    ()       (134)    (143)   
## (123)    (123)    (13)(24) (143)    (243)    (132)    (14)(23)
## (124)    (124)    (134)    (14)(23) (234)    (13)(24) (142)   
## (132)    (132)    (142)    (12)(34) (143)    ()       (134)   
## (134)    (134)    (14)(23) (124)    (142)    (234)    (13)(24)
## (13)(24) (13)(24) (143)    (123)    (14)(23) (243)    (132)   
## (142)    (142)    (12)(34) (132)    (134)    (143)    ()      
## (143)    (143)    (123)    (13)(24) (132)    (14)(23) (243)   
## (14)(23) (14)(23) (124)    (134)    (13)(24) (142)    (234)   
##          (132)    (134)    (13)(24) (142)    (143)    (14)(23)
## ()       (132)    (134)    (13)(24) (142)    (143)    (14)(23)
## (234)    (134)    (13)(24) (132)    (14)(23) (142)    (143)   
## (243)    (13)(24) (132)    (134)    (143)    (14)(23) (142)   
## (12)(34) (234)    (123)    (14)(23) (243)    (124)    (13)(24)
## (123)    ()       (124)    (142)    (234)    (12)(34) (134)   
## (124)    (243)    (12)(34) (143)    ()       (123)    (132)   
## (132)    (123)    (14)(23) (234)    (13)(24) (243)    (124)   
## (134)    (12)(34) (143)    (243)    (132)    ()       (123)   
## (13)(24) (124)    (142)    ()       (134)    (234)    (12)(34)
## (142)    (14)(23) (234)    (123)    (124)    (13)(24) (243)   
## (143)    (142)    ()       (124)    (12)(34) (134)    (234)   
## (14)(23) (143)    (243)    (12)(34) (123)    (132)    ()