 cartprod - Maple Help

combinat

 cartprod
 iterate over a list of lists or sets Calling Sequence cartprod(LL) Parameters

 LL - list of sets or lists of anything Description

 • The command cartprod is special iterating function. It allows one to iterate over the Cartesian product of a list of lists or sets of values, as illustrated in the example below. It returns a table with two entries finished and nextvalue.
 • The nextvalue entry is a function.  When called repeatedly, it iterates through the values in the cartesian product of the list of lists or sets LL.
 • The finished entry is either true or false and indicates whether the iteration is complete.  If the finished flag is true, the nextvalue function can be called to get the next value in the cartesian product.  If false, the sequence is finished.
 • The command with(combinat,cartprod) allows the use of the abbreviated form of this command. Examples

 > $\mathrm{with}\left(\mathrm{combinat},\mathrm{cartprod}\right)$
 $\left[{\mathrm{cartprod}}\right]$ (1)
 > $T≔\mathrm{cartprod}\left(\left[\left[1,2,3\right],\left\{a,b\right\}\right]\right):$
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{not}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}T\left[\mathrm{finished}\right]\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}}T\left[\mathrm{nextvalue}\right]\left(\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 $\left[{1}{,}{a}\right]$
 $\left[{1}{,}{b}\right]$
 $\left[{2}{,}{a}\right]$
 $\left[{2}{,}{b}\right]$
 $\left[{3}{,}{a}\right]$
 $\left[{3}{,}{b}\right]$ (2)
 >