generate partitions of a multiset
list(nonnegint); multiplicities of elements
(optional) equation(s) of the form option = value; specify options for the MultiPartition command
compile = truefalse
True means compile the iterator. The default is true.
The MultiPartition command returns an iterator that generates all partitions of a multiset. A multiset is a generalization of a set; members are allowed to appear more than once.
The N parameter specifies the multiset to partition. It is a list of nonnegative integers, m1,…,mn, specifying the multiplicity of the distinct elements in the multiset.
The iterator returns an Array, W, with Wi,j being the multiplicity of the i-th element in the j-th part of a partition. The number of nonzero columns, starting from the first, is given by the length method.
This iterator object has the common iterator methods.
Create all partitions of a multiset containing two elements, one occurs twice, the other three times.
Construct the iterator.
M ≔ MultiPartition⁡2,3:
Print the first five partitions.
2: 2 0
3: 2 0
4: 2 0 0
1 1 1
5: 2 0
Generating all factorizations of an integer, given its prime factorization, is equivalent to generating all partitions of the multiset of prime factors. Here we assign a procedure that returns an iterator that generates each factorization.
Factorizations := proc(n :: posint)
# Factor n into a multiset format.
L := op(2, ifactors(n));
F := map2(op,1,L); # prime factors
N := map2(op,2,L); # exponents
num := numelems(L); # number of prime factors
# Assign a procedure that converts the Array output
# to a list of factors
T := proc(m)
# Construct the iterator, then iterate through it.
M := Iterator:-MultiPartition(N);
[seq(T(m), m = M)];
Generate all factorizations of 144.
Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 3; generating all combinations and partitions, sec. 126.96.36.199, generating all set partitions, algorithm M, multipartitions in decreasing lexicographic order, pp. 75-76. The algorithm was corrected; Knuth_errata, p. 75.
The Iterator[MultiPartition] command was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
The Iterator[MultiPartition] command was updated in Maple 2022.
The N parameter was updated in Maple 2022.
Download Help Document