Iterator
MixedRadixGrayCode
generate a mixed-radix Gray code
Calling Sequence
Parameters
Options
Description
Examples
References
Compatibility
MixedRadixGrayCode(radices, opts)
radices
-
list(nonnegint)
opts
(optional) equation(s) of the form option = value; specify options for the MixedRadixGrayCode command
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.
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.
with⁡Iterator:
M≔MixedRadixGrayCode⁡2,4,3:
seq⁡m,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
Compute the number of iterations.
Number⁡M
24
Return the element with rank equal to 4.
Unrank⁡M,4
010
Copy the iterator, but start with rank equal to 4.
N≔Object⁡M,rank=4:
seq⁡v,v=N
010,020,120,130,030,031,131,121,021,011,111,101,001,002,102,112,012,022,122,132,032
Create a new iterator and use the append_change option to include the index that changed.
N≔MixedRadixGrayCode⁡3,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:
facts⁡72
1,2,4,8,24,12,6,3,9,18,36,72
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.
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[BinaryGrayCode]
Iterator[MixedRadixTuples]
Download Help Document