Iterator
WeightedComposition
generate weighted compositions that sum to a constant
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
WeightedComposition(W, T, opts)
W
-
{list,Vector,1-dimensional Array}(posint); weights of components of each composition, in nondecreasing order
T
nonnegint; weighted sum of each composition
opts
(optional) equation(s) of the form option = value; specify options for the WeightedComposition command
compile = truefalse
True means compile the iterator. The default is true.
The WeightedComposition command returns an iterator that generates all weighted compositions of T with weights W. The order in which the weighted compositions are generated is co-lexicographic. (That is, lexicographic in the reverse of the weighted compositions.)
A weighted composition is a sequence of nonnegative integers, r1,…,rn, such that T=∑k=1nWk⁢rk with n=numelems⁡W. Unlike regular compositions, but like bounded compositions, a weighted composition is understood to be ordered: rk corresponds to Wk.
with⁡Iterator:
B≔WeightedComposition⁡1,2,4,8:
Print⁡B,showrank:
1: 8 0 0 2: 6 1 0 3: 4 2 0 4: 2 3 0 5: 0 4 0 6: 4 0 1 7: 2 1 1 8: 0 2 1 9: 0 0 2
The Iterator[WeightedComposition] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
Iterator[BoundedComposition]
Iterator[Composition]
Download Help Document