PlanetMath (more info)
 Math for the people, by the people. Sponsor PlanetMath
Encyclopedia | Requests | Forums | Docs | Wiki | Random | RSS  
Login
create new user
name:
pass:
forget your password?
Main Menu
Owner confidence rating: High Entry average rating: No information on entry rating
[parent] doubling and halving algorithm for integer multiplication (Algorithm)

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.

  1. 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).
  2. Divide the previous integer on the left column by 2 and write the yield below it, ignoring any fractional part there may be. Multiply the previous integer on the right column by 2 and write the product below.
  3. Repeat Step 2 until the yield on the left column is 1.
  4. For every even number on the left column, cross out the right column's number of the same row.
  5. Add up the the numbers on the right column that haven't been crossed out.

For example, to multiply 108 by 255:

108 $\not{255}$
54 $\not{510}$
27 1020
13 2040
6 $\not{4080}$
3 8160
1 16320
  27540

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:

33 $\not{44}$
14 143
4 $\not{341}$
2 $\not{1232}$
1 3014
  3212

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.

1010 $\not{111}$
101 1110
10 $\not{11100}$
1 111000
  1000110

Of course this algorithm is not suitable for large integer multiplication as is required in the search for large prime numbers.

Bibliography

1
Paul Erdos & 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




"doubling and halving algorithm for integer multiplication" is owned by CompositeFan.
(view preamble | get metadata)

View style:


This object's parent.
Log in to rate this entry.
(view current ratings)

Cross-references: prime numbers, even, computers, binary, bases, odd, parity, base, row, even number, product, fractional part, divide, Cunningham chains, difference, minor, right, column, division, integers, multiplication, algorithm, numbers

This is version 2 of doubling and halving algorithm for integer multiplication, born on 2007-05-01, modified 2007-09-17.
Object id is 9307, canonical name is DoublingAndHalvingAlgorithmForIntegerMultiplication.
Accessed 1570 times total.

Classification:
AMS MSC11B25 (Number theory :: Sequences and sets :: Arithmetic progressions)
 00A05 (General :: General and miscellaneous specific topics :: General mathematics)
 00A06 (General :: General and miscellaneous specific topics :: Mathematics for nonmathematicians )

Pending Errata and Addenda
None.
Discussion
Style: Expand: Order:
forum policy
Strikeout by Mravinci on 2007-05-01 18:06:27
There's got to be a better way to cross out numbers (or any text) in TeX. Even lowly HMTL can do it.
[ reply | up ]

Interact
post | correct | update request | add example | add (any)