parts: Enumerate the partitions of an integer

Description Usage Arguments Details Note Author(s) References See Also Examples

Description

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

Function parts() returns the unrestricted partitions; function diffparts() returns the unequal partitions; function restrictedparts() returns the restricted partitions; function blockparts() returns the partitions subject to specified maxima; and function compositions() returns all compositions of the argument.

Usage

1
2
3
4
5
parts(n)
diffparts(n)
restrictedparts(n, m, include.zero=TRUE, decreasing=TRUE)
blockparts(f, n=NULL, include.fewer=FALSE)
compositions(n, m=NULL, include.zero=TRUE)

Arguments

n

Integer to be partitioned. In function blockparts(), the default of NULL means to return all partitions of any size

m

In functions restrictedparts() and compositions(), the order of the partition

include.zero

In functions restrictedparts() and compositions(), 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 (because zero parts are included)

include.fewer

In function blockparts(), Boolean with default FALSE meaning to return vectors whose sum is exactly n and TRUE meaning to return partitions whose sum is at most n

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's algorithm. Note that setting to decreasing to FALSE has the effect of making conjugate() return garbage

f

In function blockparts(), a vector of strictly positive integers that gives the maximal number of blocks; see details

Details

Note

These vectorized functions return a matrix whose columns are the partitions. If this matrix is too large, consider enumerating the partitions individually using the functionality documented in nextpart.Rd.

One commonly encountered idiom is blockparts(rep(n,n),n), which is equivalent to compositions(n,n) [Sloane's A001700].

Author(s)

Robin K. S. Hankin

References

See Also

nextpart

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
parts(5)
diffparts(10)
restrictedparts(9,4)
restrictedparts(9,4,FALSE)
restrictedparts(9,4,decreasing=TRUE)

blockparts(1:4)
blockparts(1:4,3)
blockparts(1:4,3,include.fewer=TRUE)

blockparts(c(4,3,3,2),5)  # Knuth's example, Fascicle 3a, p16

compositions(4)           # not the same as parts(4)
compositions(4,4) 

# With 10 blocks, enumerate all partitions with maxima of 1:5 and minima
# of c(0,1,1,2,1):

a <- c(0,1,1,2,1)
sweep(blockparts(1:5-a,10-sum(a)),1,a,"+")

partitions documentation built on July 7, 2017, 9:03 a.m.