Iterator/WeightedComposition - Maple Help

Home : Support : Online Help : Iterator/WeightedComposition

Iterator

 WeightedComposition
 generate weighted compositions that sum to a constant

 Calling Sequence WeightedComposition(W, T, opts)

Parameters

 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

Options

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

Description

 • 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, $\left({r}_{1},\dots ,{r}_{n}\right)$, such that $T=\sum _{k=1}^{n}{W}_{k}{r}_{k}$ with $n=\mathrm{numelems}\left(W\right)$. Unlike regular compositions, but like bounded compositions, a weighted composition is understood to be ordered: ${r}_{k}$ corresponds to ${W}_{k}$.

Examples

 > $\mathrm{with}\left(\mathrm{Iterator}\right):$
 > $B≔\mathrm{WeightedComposition}\left(\left[1,2,4\right],8\right):$
 > $\mathrm{Print}\left(B,'\mathrm{showrank}'\right):$
 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

Compatibility

 • The Iterator[WeightedComposition] command was introduced in Maple 2021.
 • For more information on Maple 2021 changes, see Updates in Maple 2021.