|
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.
|
|
True means compile the iterator. The default is true.
|
|
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
|
|
>
|
|
| (1) |
Compute the number of iterations.
Return the element with rank equal to 4.
Copy the iterator, but start with rank equal to 4.
>
|
|
| (4) |
Create a new iterator and use the append_change option to include the index that changed.
>
|
|
>
|
|
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:
|
| (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.
|
•
|
The radices parameter was updated in Maple 2022.
|
|
|
|