structures - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

# Online Help

###### All Products    Maple    MapleSim

Predefined Structures in the combstruct Package

 Calling Sequence combstruct[function](struct(args), size=n)

Parameters

 struct - one of a predefined list of available structures args - argument list that corresponds to the structure struct n - (optional) non-negative integer specifying the size of the object or the string 'allsizes'

Description

 • Some special combinatorial classes are predefined in the combstruct package. They are Combination or Subset, Permutation, Partition, and Composition.
 Combination or Subset:
 Combinations (or subsets) of elements
 The argument is a set, list, or non-negative integer.  In the case of a non-negative integer n, it is treated as the set $\left\{1,2,...,n\right\}$.  The default size is $'\mathrm{allsizes}'$.
 Use the string 'allsizes' when the object is selected from all possible sizes. If the size is not specified, each structure has default behavior.
 Permutation:
 Permutations of elements
 The argument is a set, list, or non-negative integer.  In the case of a non-negative integer n, it is treated as the list $[1,2,...,n]$.  The default size is the number of elements in the set/list.
 Partition:
 Partitions of positive integers into sums of positive integers without regards to order.
 The argument is a positive integer.  The default size is 'allsizes'.
 Use the string 'allsizes' when the object is selected from all possible sizes. If the size is not specified, each structure has default behavior.
 Composition:
 Composition of a positive integer n into a positive integer k parts of size at least 1, where the order of summands is meaningful.
 The argument is a positive integer.  The default size is $'\mathrm{allsizes}'$.
 Use the string 'allsizes' when the object is selected from all possible sizes. If the size is not specified, each structure has default behavior.
 • Combination and Subset are different names for the same structure.
 • You can define your own structure that is understood by the functions in the combstruct package. To create the structure Foo, create the procedures combstruct/count/Foo, combstruct/draw/Foo, combstruct/allstructs/Foo, and combstruct/iterstructs/Foo.
 Each of these functions must take size as their first argument, a non-negative integer, the string $'\mathrm{allsizes}'$ or the string $'\mathrm{default}'$, with the arguments that your structure needs. Thus, $\mathrm{draw}\left(\mathrm{Foo}\left(x,y,z\right),\mathrm{size}=n\right)$ invokes combstruct/draw/Foo(n, x, y, z).

Examples

 > $\mathrm{with}\left(\mathrm{combstruct}\right):$

Count all possible subsets of $\left\{1,2,3\right\}$.

 > $\mathrm{count}\left(\mathrm{Subset}\left(\left\{1,2,3\right\}\right)\right)$
 ${8}$ (1)

Draw a combination of $\left[1,2,3,4,5\right]$ that has 4 elements.

 > $\mathrm{draw}\left(\mathrm{Combination}\left(5\right),\mathrm{size}=4\right)$
 $\left\{{1}{,}{2}{,}{3}{,}{4}\right\}$ (2)

Count the permutations of $\left[a,a,b\right]$, using all three elements.

 > $\mathrm{count}\left(\mathrm{Permutation}\left(\left[a,a,b\right]\right)\right)$
 ${3}$ (3)

Create an iterator over all the permutations of $\left[a,a,b\right]$ that consist of only two elements.

 > $\mathrm{it}≔\mathrm{iterstructs}\left(\mathrm{Permutation}\left(\left[a,a,b\right]\right),\mathrm{size}=2\right):$

Draw any partition of 9.

 > $\mathrm{draw}\left(\mathrm{Partition}\left(9\right)\right)$
 $\left[{2}{,}{2}{,}{5}\right]$ (4)

List all the compositions of 3 in 2 parts.

 > $\mathrm{allstructs}\left(\mathrm{Composition}\left(3\right),\mathrm{size}=2\right)$
 $\left[\left[{1}{,}{2}\right]{,}\left[{2}{,}{1}\right]\right]$ (5)

 See Also