Combination - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.
Our website is currently undergoing maintenance, which may result in occasional errors while browsing. We apologize for any inconvenience this may cause and are working swiftly to restore full functionality. Thank you for your patience.

Online Help

All Products    Maple    MapleSim


Iterator

  

Combination

  

generate t-combinations of a set

 

Calling Sequence

Parameters

Options

Description

Examples

References

Compatibility

Calling Sequence

Combination(n, t, opts)

Parameters

n

-

nonnegint; size of set

t

-

nonnegint; size of combinations

opts

-

(optional) equation(s) of the form option = value; specify options for the Combination command

Options

• 

compile = truefalse

  

True means compile the iterator. The default is true.

• 

rank = nonnegint

  

Specify the starting rank of the iterator. The default is one. Passing a value greater than one causes the iterator to skip the lower ranks; this can be useful when parallelizing iterators. The starting rank reverts to one when the iterator is reset, reused, or copied.

Description

• 

The Combination command returns an iterator that generates all t-combinations of the integers 0..n1.

• 

The combinations, when read from right to left, appear in lexicographic order.

• 

The n parameter is the size of the set.

• 

The t parameter is the number of elements in each combination.

• 

If n<t, the iterator generates nothing.

• 

If n&equals;t&equals;0, the iterator generates a single empty Array.

Methods

In addition to the common iterator methods, this iterator object has the following methods. The self parameter is the iterator object.

• 

Number(self): return the number of iterations required to step through the iterator, assuming it started at rank one.

• 

Rank(self,L): return the rank of the current iteration. Optionally pass L, a list or one-dimensional rtable, and return its rank.

• 

Unrank(self,rnk): return a one-dimensional Array corresponding to the iterator output with rank rnk.

Examples

withIterator&colon;

Construct an iterator that returns all 3-combinations of the integers from 0 to 4.

n,t5,3&colon;

MCombinationn&comma;t&colon;

PrintM&comma;showrank&colon;

 1: 0 1 2
 2: 0 1 3
 3: 0 2 3
 4: 1 2 3
 5: 0 1 4
 6: 0 2 4
 7: 1 2 4
 8: 0 3 4
 9: 1 3 4
10: 2 3 4

Compute the number of iterations.

NumberM

10

(1)

Return the element with rank equal to 4.

UnrankM&comma;4

123

(2)

Copy the iterator, but start with rank equal to 4.

NObjectM&comma;rank=4&colon;

seqv&comma;v=N

123,014,024,124,034,134,234

(3)

References

  

Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 3; generating all combinations and partitions, sec. 7.2.1.3, algorithm T (Lexicographic combinations), p. 5.

Compatibility

• 

The Iterator[Combination] command was introduced in Maple 2016.

• 

For more information on Maple 2016 changes, see Updates in Maple 2016.

• 

The Iterator[Combination] command was updated in Maple 2022.

• 

The n and t parameters were updated in Maple 2022.

See Also

combinat[choose]

Iterator

Iterator[Chase]

Iterator[RevolvingDoorCombination]