Iterator - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Discrete Mathematics : Combinatorics : Iterator : Iterator/Product

Iterator

  

Product

  

create the product of iterators

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

Product(objects, opts)

Parameters

objects

-

sequence of iterators

opts

-

(optional) equation(s) of the form option = value; specify options for the Product 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. The starting rank reverts to one when the iterator is reset, reused, or copied.

Methods

The 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.

Description

• 

The Product command returns an iterator that is the direct product of a sequence of iterators. The output of the created iterator is a one-dimensional Array that concatenates the output of each component iterator. Each component iterator advances when the preceding iterator resets. The first iterator advances with each iteration.

Examples

withIterator:

Create an iterator that combines the permutations of the integers from 1 to 3 with three bit binary Gray code.

PProductPermute3,BinaryGrayCode3:

Print the first 10 iterations, along with the rank.

rnk0:

forpinPwhilernk<10doprintf%d: %{}d\n&comma;rnk&comma;p;rnkrnk+1enddo&colon;

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

Compute the number of iterations.

NumberP

48

(1)

Compute the output with rank equal to 8.

UnrankP&comma;8

132100

(2)

Compatibility

• 

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

• 

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