|
Calling Sequence
|
|
Composition(n, opts)
|
|
Parameters
|
|
n
|
-
|
posint; integer to compose, must be greater than one
|
opts
|
-
|
(optional) equation(s) of the form option = value; specify options for the Composition command
|
|
|
|
|
Options
|
|
|
True means compile the iterator. The default is true.
|
|
Specifies the maximum number of integers in each composition. The default is n.
|
|
Specifies the number of integers in each composition. The default, 0, is ignored.
|
|
|
Description
|
|
•
|
The Composition command returns an iterator that generates all compositions of the integer n.
|
•
|
A composition of integer n is a sequence of positive integers that sum to n.
|
•
|
The n parameter is the integer to decompose.
|
•
|
The output of the iterator is an array of fixed length n. The composition is in the indices 1 to , 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.
|
|
|
|
Examples
|
|
Iterate through the compositions of 5.
>
|
|
1: 5
2: 4 1
3: 3 1 1
4: 3 2
5: 2 1 2
6: 2 1 1 1
7: 2 2 1
8: 2 3
9: 1 1 3
10: 1 1 2 1
11: 1 1 1 1 1
12: 1 1 1 2
13: 1 2 2
14: 1 2 1 1
15: 1 3 1
16: 1 4
| |
Compute the number of iterations.
Add the parts of each composition to verify they sum to n.
>
|
|
| (2) |
|
|
References
|
|
|
Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 2; generating all tuples and permutations, sec. 7.2.1.1, generating all n-tuples, algorithm A, p. 77, answer 12.
|
|
|
Compatibility
|
|
•
|
The Iterator[Composition] command was introduced in Maple 2021.
|
•
|
The Iterator[Composition] command was updated in Maple 2022.
|
•
|
The n parameter was updated in Maple 2022.
|
•
|
The maxparts and parts options were updated in Maple 2022.
|
|
|
|