 Iterator - Maple Programming Help

Home : Support : Online Help : Mathematics : Discrete Mathematics : Combinatorics : Iterator : Iterator/PartitionPartCount

Iterator

 PartitionPartCount
 generate partitions of an integer in part-count form

 Calling Sequence PartitionPartCount(n, opts)

Parameters

 n - posint; integer to partition opts - (optional) equation(s) of the form option = value; specify options for the PartitionPartCount command

Options

 • compile = truefalse
 True means compile the iterator. The default is true.

Description

 • The PartitionPartCount command returns an iterator that generates all partitions of the integer n in part-count form, in reverse lexicographic order.
 • A partition of integer n in part-count form is a sequence of integers $\left({c}_{1},\dots ,{c}_{n}\right)$ such that $n=\sum _{k=1}^{n}k{c}_{k}$ and $0\le {c}_{k}\le n$ for $k\in \left\{1,\dots ,n\right\}$.
 • The n parameter is the integer to partition.
 • The output of the iterator is an array of fixed length n.

Methods

The iterator object has the following methods. The self parameter is the iterator object.

 • Number(self): return the number of iterations required to step through the iterator, assuming it started at rank one.

Examples

 > $\mathrm{with}\left(\mathrm{Iterator}\right):$

Iterate through the partitions of 8.

 > $n≔8:$
 > $P≔\mathrm{PartitionPartCount}\left(n\right):$
 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}p\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}P\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{printf}\left("%d\n",p\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 8 0 0 0 0 0 0 0 6 1 0 0 0 0 0 0 4 2 0 0 0 0 0 0 2 3 0 0 0 0 0 0 0 4 0 0 0 0 0 0 5 0 1 0 0 0 0 0 3 1 1 0 0 0 0 0 1 2 1 0 0 0 0 0 2 0 2 0 0 0 0 0 0 1 2 0 0 0 0 0 4 0 0 1 0 0 0 0 2 1 0 1 0 0 0 0 0 2 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 2 0 0 0 0 3 0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 2 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1

Compute the number of iterations.

 > $\mathrm{Number}\left(P\right)$
 ${22}$ (1)

Add the elements of each partition to verify they sum to n.

 > $\mathrm{seq}\left(\mathrm{add}\left(kp\left[k\right],k=1..n\right),p=P\right)$
 ${8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}{,}{8}$ (2)

References

 Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 3; generating all combinations and partitions, sec. 7.2.1.4, generating all partitions, algorithm C, p. 110, ex. 5.

Compatibility

 • The Iterator[PartitionPartCount] command was introduced in Maple 2016.