Iterator - Maple Programming Help

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

Iterator

 SetPartitionFixedSize
 generate fixed partitions of a set

 Calling Sequence SetPartitionFixedSize(s, opts)

Parameters

 s - list(posint); size of each subset opts - (optional) equation(s) of the form option = value; specify options for the SetPartitionFixedSize command

Options

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

Description

 • The SetPartitionFixedSize command returns an iterator that generates fixed-size partitions of the set of integers starting at one. A partition of a set is a division of the set into disjoint subsets whose union is the set. A fixed-size partition fixes the sizes and number of the partitions.
 • The s parameter is a list of positive integers that specify the size of each subset of a partition.
 • The iterator output is a permutation of the integers from one to n, where n is the sum of the sizes of the subsets. Let ${S}_{k}=1+\left(\sum _{j=1}^{k-1}{s}_{j}\right)$, then the k-th subset corresponds to the indices ${S}_{k}..{S}_{k+1}-1$.

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):$

Partition the set of integers $\left\{1,2,3,4,5\right\}$ into subsets of sizes 2, 1, and 2.

 > $F≔\mathrm{SetPartitionFixedSize}\left(\left[2,1,2\right]\right):$

Print the vectors corresponding to the partitions. Indices 1 and 2 contain the first subset, index 3 the second, and indices 4 and 5 the third.

 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}f\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}F\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("%\left\{\right\}d\n",f\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}:$
 1 2 3 4 5 1 2 4 3 5 1 2 5 3 4 1 3 4 2 5 1 3 5 2 4 1 4 5 2 3 1 3 2 4 5 1 4 2 3 5 1 5 2 3 4 1 4 3 2 5 1 5 3 2 4 1 5 4 2 3 2 3 1 4 5 2 4 1 3 5 2 5 1 3 4

Compute the number of iterations.

 > $\mathrm{Number}\left(F\right)$
 ${15}$ (1)

References

 Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 3; generating all combinations and partitions, sec. 7.2.1.5, generating all set partitions, fixed sizes, exercise 6, pp. 78 and 125.

Compatibility

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