MultiSet Iteration - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : MultiSet : MultiSet/Iteration

MultiSet Iteration

Iterating over the elements of a MultiSet

 Calling Sequence for e in M do ... end do

Parameters

 M - MultiSet; a (non-generalized) MultiSet

Description

 • To iterate over the elements of a MultiSet, M, use the for x in M do ... end do construct.  Note that this will loop over all the elements of the MultiSet, repeated according to multiplicity.  Note also that the order in which the elements of the MultiSet are visited is not predetermined, although identical elements will be visited consecutively.
 • This iteration functionality is only available for standard (non-generalized) MultiSets (where the multiplicities can only be positive integers).

Examples

 > $M≔\mathrm{MultiSet}\left(a,b,c,b,a\right)$
 ${M}{≔}\left\{\left[{a}{,}{2}\right]{,}\left[{b}{,}{2}\right]{,}\left[{c}{,}{1}\right]\right\}$ (1)

Note that the traversal order is not specified, but the a's will appear together, as will the b's

 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}x\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}M\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{print}\left(x\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 ${a}$
 ${a}$
 ${b}$
 ${b}$
 ${c}$ (2)