Learn R Programming

PerMallows (version 1.13)

count.perms: Count permutations at a distance

Description

Given a distance (kendall, cayley, hamming or ulam), the number of items in the permutations perm.length and distance value d, how many permutations are there at distance d from any permutation? It can be used to count the number of derangements and the permutations with k cycles (Stirling numbers of the first kind)

Usage

count.perms(perm.length, dist.value, dist.name = "kendall", disk = FALSE)

Arguments

perm.length
number of items in the permutations
dist.value
the distance
dist.name
optional. One of: kendall (default), cayley, hamming, ulam
disk
optional can only be true if counting the permutations at each Ulam distance. Insted of generating the whole set of SYT and count of permutations per distance, it loads the info from a file in the disk

Value

The number of permutations at the given distance

Examples

Run this code
count.perms(4,2,"kendall")
count.perms(4,2,"ulam")
count.perms(4,2,"hamming")
count.perms(4,2,"cayley")
# The number of derangements of length 6 is computed as follows
len <- 6
count.perms(perm.length = len, dist.value = len, dist.name = "h") 
# The number of permutations with one cycle is computed as follows
num.cycles <- 1 
count.perms(perm.length = len, dist.value = len - num.cycles, dist.name = "c") 

Run the code above in your browser using DataLab