Iterator
Partition
generate all partitions of an integer
Calling Sequence
Parameters
Options
Description
Examples
References
Compatibility
Partition(n, m, opts)
n
-
posint; integer to partition
m
(optional) posint; maximum integer in a partition
opts
(optional) equation(s) of the form option = value; specify options for the Partition command
compile = truefalse
True means compile the iterator. The default is true.
The Partition command returns an iterator that generates all partitions of the integer n, in reverse lexicographic order.
A partition of integer n is a sequence of integers a1,…,ak such that n=∑j=1kaj and 0<aj≤n for j∈1,…,k.
The n parameter is the integer to partition.
The optional m parameter is the maximum integer that can appear in any partition. The default is n.
The output of the iterator is an array of fixed length n. The partition is in the indices 1 to length⁡P, where P is the assigned iterator.
Methods
In addition to the common iterator methods, this 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.
with⁡Iterator:
Iterate through the partitions of 8.
P≔Partition⁡8:
Print⁡P,showrank:
1: 8 2: 7 1 3: 6 2 4: 6 1 1 5: 5 3 6: 5 2 1 7: 5 1 1 1 8: 4 4 9: 4 3 1 10: 4 2 2 11: 4 2 1 1 12: 4 1 1 1 1 13: 3 3 2 14: 3 3 1 1 15: 3 2 2 1 16: 3 2 1 1 1 17: 3 1 1 1 1 1 18: 2 2 2 2 19: 2 2 2 1 1 20: 2 2 1 1 1 1 21: 2 1 1 1 1 1 1 22: 1 1 1 1 1 1 1 1
Iterate through the partitions of 8, with maximum integer 5.
P≔Partition⁡8,5:
1: 5 3 2: 5 2 1 3: 5 1 1 1 4: 4 4 5: 4 3 1 6: 4 2 2 7: 4 2 1 1 8: 4 1 1 1 1 9: 3 3 2 10: 3 3 1 1 11: 3 2 2 1 12: 3 2 1 1 1 13: 3 1 1 1 1 1 14: 2 2 2 2 15: 2 2 2 1 1 16: 2 2 1 1 1 1 17: 2 1 1 1 1 1 1 18: 1 1 1 1 1 1 1 1
Compute the number of iterations.
Number⁡P
18
Add the elements of each partition to verify they sum to 8.
seq⁡add⁡pk,k=1..length⁡P,p=P
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
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 P, partitions in reverse lexicographic order. The algorithm was corrected; Knuth_errata, p. 38.
The Iterator[Partition] command was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
The Iterator[Partition] command was updated in Maple 2022.
The n and m parameters were updated in Maple 2022.
See Also
combinat[numbpart]
combinat[partition]
Iterator[MultiPartition]
Iterator[PartitionFixedSize]
Iterator[SetPartitions]
Download Help Document