Learn R Programming

partitions (version 1.1-2)

parts: Enumerate the partitions of an integer

Description

Given an integer, return a matrix whose columns enumerate its partitions.

Function parts() returns the unrestricted partions; function diffparts() returns the unequal partitions; function restrictedparts() returns the restricted partitions.

Usage

parts(n)
diffparts(n)
restrictedparts(n, m, include.zero=TRUE, decreasing=TRUE)

Arguments

n
Integer to be partitioned
m
In restrictedparts(), the order of the partition
include.zero
In restrictedparts(), Boolean with default FALSE meaning to include only partitions of $n$ into exactly $m$ parts; and TRUE meaning to include partitions of $n$ into at most $m$ parts
decreasing
In restrictedparts(), Boolean with default TRUE meaning to return partitions whose parts are in decreasing order and FALSE meaning to return partitions in lexicographical order, as appearing in Hindenburg

Details

Function parts() uses the algorithm in Andrews. Function diffparts() uses a very similar algorithm that I have not seen elsewhere.

Function restrictedparts() uses the algorithm in Andrews, originally due to Hindenburg. For partitions into at most $m$ parts, the same Hindenburg's algorithm is used but with a start vector of c(rep(0,m-1),n).

References

G. E. Andrews. The Theory of Partitions, Cambridge University Press, 1998

Examples

Run this code
parts(5)
diffparts(10)
restrictedparts(9,4)
restrictedparts(9,4,FALSE)
restrictedparts(9,4,decreasing=TRUE)

Run the code above in your browser using DataLab