![]() |
(C1) |
kn rn-1 + ... +k2 r+ k1 | (C2) |
On entry to our algorithm we have an integer , and
on exit we wish to have the number nsol of all solutions
of Eq. (31) and the solutions themselves. For a set Si we
introduce an abstract variable S
to describe the array k(1:n) of n integer elements
ordered as ``quasi-decimal digits''.
So, in an abstract form the algorithm looks like:
-- Statement QS: -- all S <= S(CURRENT) -- are out if and only if -- k(1)+2*k(2)+...+n*k(n)=n <*initiate: make QS true for S=S(INITIAL) *>; _while <*condition: S ^= S(FINAL) *> _do <*nextset: find next S keeping QS invariant *> _od; -- Here S=S(FINAL) and QS=.TRUE., i.e. -- all needed solutions are foundIt is easy to initiate QS:
k(1)=n; mold=1; -- keeps largest m -- for non-zero k(m) _do m=2,n; k(m)=0 _od; nsol=1;The integer mold keeps track of the progress of the algorithm and allows us to establish the condition for the continuation of the main loop,
![]() |
-- advance S(CURRENT), i.e. consider adding -- n-( 2*k(2) +3*k(3) + ...+mold*k(mold) ) -- to k(1) trying to add 1 to the lowest of -- k(2),...,k(mold) possible. -- If adding 1 to the lowest k(m) -- makes the sum > n then -- put this k(m)=0 and try k(m+1) -- m=1; sumcur=n; -- integer sum of current set S _repeat sumcur=sumcur-k(m)*m+m+1; k(m)=0; k(m+1)=k(m+1)+1; m=m+1; _until sumcur <= n _or m>mold; _if m>mold _then mold=m _fi; k(1)=n-sumcur; nsol=nsol+1;
Here the node nextset ends, and the whole algorithm is finished. We have written it here in a pseudocode which can be translated mechanically into any machine language. We actually use a special preprocessor Trefor which automatically transforms the text above to standard Fortran (see Weinstein & Blinnikov 1984, and Bartunov et al. 1997).
For reference, we present the first 8 sets of solutions found by this algorithm. In practice it is easier not to use the Table C1 even for low n, but generate all coefficients in the code.
Copyright The European Southern Observatory (ESO)