Permutations of Multisets in Cool-Lex Order
Overview
A set of tools to permute multisets without loops or hash tables and to generate integer partitions. The permutation functions are based on C code from Aaron Williams. Cool-lex order is similar to colexicographical order. The algorithm is described in Williams, A. Loopless Generation of Multiset Permutations by Prefix Shifts. SODA 2009, Symposium on Discrete Algorithms, New York, United States. The permutation code is distributed without restrictions. Multinomial coefficients, Stirling numbers of the second kind and Bell numbers are computed exactly using the 'gmp' package. The package also generates the integer partitions of a positive, non-zero integer n. The C++ code for this is based on Python code from Jerome Kelleher, and the algorithm is described in Kelleher and O'Sullivan (2009) doi:10.48550/arXiv.0909.2331. The C++ code and Python code are distributed without conditions.
New features
allPerm()has a new argumentnThreadsto generate large results (at least 100,000 permutations) with several threads. It is about 1.4 to 1.9 times faster with 2 to 4 threads, and close to the speed at which the result can be written to memory. Character and factor multisets always use one thread. The defaultnThreads = 1works as before.nextPerm()has a new argumentnto return the nextnpermutations as the rows of a matrix (fewer at the end, thenFALSE). This makes iterating through permutations much faster, while only holdingnof them in memory. For example,nextPerm(m, 1000)costs about 0.016 microseconds per permutation, the same asallPerm(). The defaultn = 1works as before.multinom(),Stirling2()/S2()andBell()/B()are now computed exactly using the 'gmp' package, and have a new argumentexact. By default they still return doubles, now correct to double precision rather than silently overflowing. Withexact = TRUEthey return exact big integers of classbigz. TheuseDoubleargument ofmultinom()is kept for backwards compatibility but no longer has any effect.
Show all changes in 1.0.2Hide the rest of the changes in 1.0.2
Changes in behaviour
initMC()now gives an error, rather than a warning, for input with fewer than two elements, and an error for input containing missing values.initMC()keeps the type of its input, so logical multisets are permuted as logicals rather than as the strings"TRUE"and"FALSE".
Bug fixes
initMC()with non-whole numbers (e.g.c(1.5, 1.5, 2.5)) permuted the counts of each value rather than the values themselves.Stirling2()andBell()overflowed for moderate arguments, and much sooner on Windows (e.g.Stirling2(20, 5)andBell(16)were wrong).multinom()overflowed silently for large coefficients.genComp()crashed R whennwas zero or negative, and returnedNULLwhenlenwas greater thann.- Calling
allPerm()no longer resets the position ofnextPerm(). - Fixed a memory leak in the permutation object.
Improvements
genComp()is much faster for largern. The time taken previously grew quadratically with the number of partitions (about 100 seconds forn = 50).allPerm()is 10 to 30 times faster and uses much less memory. It writes the elements straight into the result matrix in C++. In the permutation benchmarks from <https://stackoverflow.com/questions/22569176>, it now takes 1.4 to 1.9 times as long as single-threaded 'RcppAlgos' (before, 15 to 54 times as long), and 1.0 to 1.5 times as long as 'arrangements'.initMC()keeps integer input as integer, soallPerm()returns an integer matrix for integer input.nextPerm()is about 9 times faster per call (about 0.9 rather than 8.4 microseconds), because the permutation object is now reached through an external pointer rather than an Rcpp Module.nextPerm()checks that its argument is anmcobject.- Using an
mcobject after it has been saved and reloaded gives a clear error asking you to callinitMC()again. - Native routines are now registered, and documentation and
NAMESPACEare generated with roxygen2.
Acknowledgements
- Earlier versions of this package used C++ code by Dave Barber (<http://tamivox.org/dave/multinomial/code.html>) to compute multinomial coefficients. It has been replaced by exact computation with the 'gmp' package, but we thank Dave for the code that the package relied on for many years.
From NEWS.md in the release
Install
Health
NOTECRAN incoming feasibilityr-devel-linux-x86_64-debian-clang
Maintainer: ‘James Curran <j.curran@auckland.ac.nz>’
No Authors@R field in DESCRIPTION.
Please add one, modifying
Authors@R: c(person(given = "James",
family = "Curran",
role = c("aut", "cre"),
email = "j.curran@auckland.ac.nz"),
person(given = "Aaron",
family = "Williams",
role = "aut"),
person(given = "Jerome",
family = "Kelleher",
role = "aut"),
person(given = "Dave",
family = "Barber",
role = "aut"))
as necessary.- NOTE12 OK, 1 NOTENow
- NOTE12 OK, 2 NOTE2026-04-22
- ERROR11 OK, 2 NOTE, 1 ERROR2026-04-18
- NOTE12 OK, 2 NOTE2026-03-10
Documentation
- Help pages
- 8 (1 internal)includes a package overview page
- Examples that run
- 100%7 run in a plain check
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 38%
Downloads
Repository
- PRs merged (all time)
- 100%
- Median days to close, 50 most recently updated closed issues
- not measured
- Median days to close, 50 most recently updated closed PRs
- 2
Stars over time
Forks over time
Releases over time
Issues over time
PRs over time
Commits over time
3 development-tooling and community-health practices detected across 3 families in the upstream repository
Checks run against github.com/jmcurran/multicool on 2026-10-21.
This repository shows signs of AI coding tools.
- Claude Codefirst seen 2026-10-19Seen in the repository: CLAUDE.mdNamed in .Rbuildignore: CLAUDE.mdCommits: at least 9 crediting it in the message
- Claude Opus 5.59 commits · Oct 2026
Dependencies
Installing multicool adds 2 packages (2 with compiled code, 2.0 MB of source tarballs). Heaviest: Rcpp 1.8 MB, gmp 163 KB.
Code & Tests
People & History
Maintainer since 0.1-1 (2011)
Pick two releases to compare their code metrics.
- 1.0.2Latest2026-10-21 · current release · diff ↗ ·
14 hours in CRAN's queue
Listed in CRAN's incoming queue from 2026-10-20 21:03 to 2026-10-21 10:55 UTC, in 4 readings. - RR 4.6.0 released · 2026-04-24
- RR 4.5.0 released · 2025-04-11
- RR 4.4.0 released · 2024-04-24
- 1.0.12024-02-05 · diff ↗
- 1.0.02023-12-02 · diff ↗
- RR 4.3.0 released · 2023-04-21
- RR 4.2.0 released · 2022-04-22
- 0.1-122021-06-29 · diff ↗
- RR 4.1.0 released · 2021-05-18
- RR 4.0.0 released · 2020-04-24
- 0.1-112019-12-05 · diff ↗
- RR 3.6.0 released · 2019-04-26
- RR 3.5.0 released · 2018-04-23
- RR 3.4.0 released · 2017-04-21
- 0.1-102016-11-25 · diff ↗
Show 13 earlier eventsHide 13 earlier events
- RR 3.3.0 released · 2016-05-03
- 0.1-92015-10-28 · diff ↗
- 0.1-82015-10-22 · diff ↗
- 0.1-72015-08-17 · diff ↗
- 0.1-62015-04-28 · diff ↗
- RR 3.2.0 released · 2015-04-16
- 0.1-5
- RR 3.1.0 released · 2014-04-10
- 0.1-2
- RR 3.0.0 released · 2013-04-03
- RR 2.15.0 released · 2012-03-30
- 0.1-12011-11-15
- RR 2.14.0 released · 2011-10-31
Package metadata
- First published
- 2011-11-15
- Total releases
- 13 / 15 yrs
- License
- GPL-2 OSI
- Download size
- 20 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("multicool")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-23, which the citation names so these numbers can be found later. More on citing and the projects behind them.