Random permutations
rperm.Rd
Function rperm()
creates a word object of random permutations.
Function rcyc()
creates random permutations comprising a single
(group-theoretic) cycle of a specified length. Functions
r1cyc()
and rgs1()
are low-level helper functions.
Usage
rperm(n=10,r=7,moved=NA)
rcyc(n,len,r=len)
r1cyc(len,vec)
rgs1(s)
rgivenshape(n,s,size=sum(s))
Arguments
- n
Number of permutations to create
- r
Size of permutations
- len
Length of cycles in
rcyc()
andr1cyc()
- moved
In function
rperm()
, integer specifying how many elements can move (that is, how many elements do not map to themselves), with defaultNA
meaning to choose a permutation at random. This is useful if you want a permutation that has a compact cycle representation- vec
Vector of integers to generate a cycle from
- s,size
Shape and size of permutations to create
Note
Argument moved
specifies a maximum number of elements
that do not map to themselves; the actual number of non-fixed elements
might be lower (as some elements might map to themselves). You can
control the number of non-fixed elements precisely with argument
len
of function rcyc()
, although this will give only
permutations with a single (group-theoretic) cycle.
Argument s
of function rgivensize()
can include 1s
(ones). Although length-one cycles are dropped from the resulting
permutation, it is sometimes useful to include them to increase the
size of the result, see examples.
In function rgivenshape()
, if primary argument n
is a
vector of length greater than 1, it is interpreted as the shape of the
permutation, and a single random permutation is returned.
Examples
rperm()
#> [1] (1547) (164572) (12)(45)(67) (1437256) (13)(24)(67)
#> [6] (1352)(67) (26475) (12765)(34) (17526)(34) (13746)(25)
#> [coerced from word form]
as.cycle(rperm(30,9))
#> [1] (17462)(3589) (1532)(6897) (18)(23)(45967) (1245387)
#> [5] (19324)(58) (12396874) (27659)(38) (145639)(27)
#> [9] (146258)(397) (17)(2589)(46) (18)(2375) (289753)
#> [13] (134926)(58) (17298)(45) (178394)(26) (192756)(34)
#> [17] (1796)(345) (37)(69) (16)(2384957) (15893)(247)
#> [21] (1867)(2395) (19)(2358)(67) (126589743) (13)(2689)(475)
#> [25] (17825)(394) (17453286) (18624)(3957) (1745269)(38)
#> [29] (1649)(2873) (1736954)
rperm(10,9,2)
#> [1] () (29) () (14) () () (68) () (28) ()
#> [coerced from word form]
rcyc(20,5)
#> [1] (12435) (13452) (13245) (15243) (12453) (13254) (12435) (14325) (14352)
#> [10] (12543) (14532) (15324) (13425) (12543) (14235) (14523) (12345) (12435)
#> [19] (15423) (12354)
rcyc(20,5,9)
#> [1] (16238) (23485) (19483) (14729) (16539) (36857) (16247) (36587) (19358)
#> [10] (24568) (12859) (39567) (34769) (24769) (29546) (17856) (46758) (39865)
#> [19] (16243) (16253)
rgivenshape(10,c(2,3)) # size 5
#> [1] (143)(25) (143)(25) (125)(34) (154)(23) (134)(25) (134)(25) (13)(245)
#> [8] (13)(245) (15)(243) (135)(24)
rgivenshape(10,c(2,3,1,1)) # size 7
#> [1] (14)(235) (12)(456) (23)(465) (246)(35) (145)(23) (153)(47) (175)(46)
#> [8] (176)(24) (125)(36) (12)(347)
rgivenshape(1:9)
#> [1] (1,26,25,28,18,35,36)(2,23,29,13)(3,42,19,21,17,43)(4,24,45,15,30,34,27,11,8)(5,44,12,33,38,37,10,16)(6,32,41,14,20)(7,9)(22,40,31)
allpermslike(rgivenshape(c(1,1,3,4)))
#> [1] (158)(2739) (185)(2739) (158)(2793) (185)(2793) (158)(2397) (185)(2397)
#> [7] (158)(2379) (185)(2379) (158)(2973) (185)(2973) (158)(2937) (185)(2937)