Is there a practical algorithm that gives "multiplication chains"
To clarify, the goal is to produce a multiplication change of an arbitrary and exact length
Multiplication chains of length 1 are trivial.
A "multiplication chain" would be defined as 2 numbers, {start} and {multiplier}, used in code:
Given a pointer to array of size [{count}] // count is a parameter
a = start;
do
{
a = a * multiplier; // Really: a = (a * multiplier) MOD (power of 2
*(pointer++) = a;
}
while (a != {constant} )
// Postcondition: all {count} entries are filled.
I'd like to find a routine that takes three parameters
1. Power of 2
2. Stopping {constant}
3. {count} - Number of times the loop will iterate
The routine would return {start} and {multiplier}.
Ideally, a {Constant} value of 0 should be valid.
Trivial example:
power of 2 = 256
stopping constant = 7
number of times for the loop = 1
returns {7,1}
Nontrivial example:
power of 2 = 256
stopping constant = 1
number of times for the loop = 49
returns {25, 19}
The maximum {count} for a given power of 2 can be fairly small.
For example, 2^4 (16) seems to be limited to a count of 4