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

Online Help

All Products    Maple    MapleSim


Iterator

  

MixedRadixGrayCode

  

generate a mixed-radix Gray code

 

Calling Sequence

Parameters

Options

Description

Examples

References

Compatibility

Calling Sequence

MixedRadixGrayCode(radices, opts)

Parameters

radices

-

list(nonnegint)

opts

-

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

Options

• 

append_change = truefalse

  

True means append an integer indicating the change to the output Array. The magnitude of the integer is the index that changed, the sign is the direction of the change. The default is false.

• 

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 MixedRadixGrayCode command returns an iterator that generates a mixed-radix Gray code.

• 

The radices parameter is a list of positive integers that specify the radices of the number. The k-th integer is the radix at the k-th index.

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:

MMixedRadixGrayCode2,4,3:

seqm,m=M

000,100,110,010,020,120,130,030,031,131,121,021,011,111,101,001,002,102,112,012,022,122,132,032

(1)

Compute the number of iterations.

NumberM

24

(2)

Return the element with rank equal to 4.

UnrankM,4

010

(3)

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

NObjectM,rank=4:

seqv,v=N

010,020,120,130,030,031,131,121,021,011,111,101,001,002,102,112,012,022,122,132,032

(4)

Create a new iterator and use the append_change option to include the index that changed.

NMixedRadixGrayCode3,4,append_change:

forVinNdoprintf%d : %d\n,V1..2,V3enddo:

0 0 : 0
1 0 : 1
2 0 : 1
2 1 : 2
1 1 : -1
0 1 : -1
0 2 : 2
1 2 : 1
2 2 : 1
2 3 : 2
1 3 : -1
0 3 : -1

Generate all factors of an integer, such that the ratio of adjacent factors is a prime or the inverse of a prime.

facts := proc(n :: posint)
local F,T,m,iter,p;
uses Iterator;
    # Factor n into the form [[p1,e1],...,[pm,em]],
    # where n = p1^e1*...*pm^em.
    F := op(2,ifactors(n));
    m := numelems(F);

    # Assign a procedure that converts a Vector (of exponents)
    # to an integer, using F.
    T := proc(V)
    local i;
        mul(F[i,1]^V[i],i=1..m);
    end proc;

    # Iterate through all factors.
    seq(T(p), p=MixedRadixGrayCode([seq(f[2]+1,f=F)]));
end proc:

facts72

1,2,4,8,24,12,6,3,9,18,36,72

(5)

References

  

Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 2; generating all tuples and permutations, sec. 7.2.1.1, Generating all n-tuples, algorithm  H, loopless reflected mixed-radix Gray generation, p. 20.

Compatibility

• 

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

• 

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

• 

The radices parameter was updated in Maple 2022.

See Also

Iterator

Iterator[BinaryGrayCode]

Iterator[MixedRadixTuples]