For the optimized left-to-right exponentiation by squaring algorithm, let be the length of the binary expansion of a positive integer , and let be its Hamming weight, the number of digits equal to one. There are exactly digits after the leading one, and exactly remaining ones. Therefore the count is
Here counts squarings and counts further multiplications by the base; every squaring counts as one multiplication in . Assignment, digit reading, and any inversion are outside this count. The formula includes , which requires zero multiplications; define separately.
For a fixed length , the bounds are . A power of two reaches the lower bound because its Hamming weight is one; reaches the upper bound because all digits are one. For , and , giving . Thus the arithmetic operation count is in Big O notation, but inputs of similar magnitude can have different counts.
Figure 1.
Exact multiplication counts for optimized exponentiation by squaring depend on binary length and Hamming weight
. For positive exponents through , dots show , including each squaring. The dashed curves bound all counts at each binary length. Successive multiplication needs operations. The second panel compares squarings and further multiplications for exponents . These are exact counts, not timing measurements. Details.
This is a count for the specified algorithm, not a claim that it always minimizes multiplications among all methods. For instance, at the count is six, but the powers with exponents can be built in five multiplications: square, multiply by , square, square, then multiply by the already stored . Saving operations this way uses a different schedule and stored intermediate powers.

Articles by others on the same topic (NaN)

There are currently no matching articles.