doubling and halving algorithm for integer multiplication
Because multiplying and dividing by 2 is often easier for humans than multiplying and dividing by other numbers there is an algorithm for multiplication of any two integers that takes advantage of multiplication and division by 2.
Call the algorithm with two integers.
Use one of the integers to start a column on the left and the other to start a column on the right. (Either number can be put in either column, there are very minor optimizations that are unlikely to make a difference in performance, such as not choosing for the left column numbers that end long Cunningham chains).
Repeat Step 2 until the yield on the left column is 1.
For every even number on the left column, cross out the right column’s number of the same row.
Add up the the numbers on the right column that haven’t been crossed out.
For example, to multiply 108 by 255:
This works in any base (as long as one doesn’t get confused about parity in odd bases). For example, 18 times 24 in base 5:
Naturally one might wonder if this can be applied to binary and used by computers. After all, halving and ignoring the fractional part is even easier: it’s just a matter of shifting the bits to the right, and it doesn’t matter what the computer does with the discarded bit (as long as it doesn’t put it back into the original byte or word in the most significant bit or the sign bit). Doubling is also easy, just a shift left, with the only concern being overflow.
Of course this algorithm is not suitable for large integer multiplication as is required in the search for large prime numbers.
- 1 Paul Erdős & János Surányi Topics in the theory of numbers New York: Springer (2003): 5
- 2 Ogilvy & Anderson, Excursions in Number Theory. Oxford: Oxford University Press (1966). Reprinted New York: Dover (1988): 6 - 8
|Title||doubling and halving algorithm for integer multiplication|
|Date of creation||2013-03-22 17:01:20|
|Last modified on||2013-03-22 17:01:20|
|Last modified by||CompositeFan (12809)|