HOME

TheInfoList



OR:

A multiplication algorithm is an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
(or method) to
multiply Multiplication is one of the four elementary mathematical operations of arithmetic, with the other ones being addition, subtraction, and division. The result of a multiplication operation is called a '' product''. Multiplication is often de ...
two numbers. Depending on the size of the numbers, different algorithms are more efficient than others. Numerous algorithms are known and there has been much research into the topic. The oldest and simplest method, known since antiquity as long multiplication or grade-school multiplication, consists of multiplying every digit in the first number by every digit in the second and adding the results. This has a
time complexity In theoretical computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations ...
of O(n^2), where ''n'' is the number of digits. When done by hand, this may also be reframed as grid method multiplication or
lattice multiplication Lattice multiplication, also known as the Italian method, Chinese method, Chinese lattice, gelosia multiplication, sieve multiplication, shabakh, diagonally or Venetian squares, is a method of multiplication that uses a Lattice (group), lattice to ...
. In software, this may be called "shift and add" due to bitshifts and addition being the only two operations needed. In 1960,
Anatoly Karatsuba Anatoly Alexeyevich Karatsuba (his first name often spelled Anatolii) (; Grozny, Soviet Union, 31 January 1937 – Moscow, Russia, 28 September 2008) was a Russian people, Russian mathematician working in the field of analytic number theory, p-ad ...
discovered Karatsuba multiplication, unleashing a flood of research into fast multiplication algorithms. This method uses three multiplications rather than four to multiply two two-digit numbers. (A variant of this can also be used to multiply
complex numbers In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the form a ...
quickly.) Done recursively, this has a time complexity of O(n^). Splitting numbers into more than two parts results in Toom-Cook multiplication; for example, using three parts results in the Toom-3 algorithm. Using many parts can set the exponent arbitrarily close to 1, but the constant factor also grows, making it impractical. In 1968, the Schönhage-Strassen algorithm, which makes use of a
Fourier transform In mathematics, the Fourier transform (FT) is an integral transform that takes a function as input then outputs another function that describes the extent to which various frequencies are present in the original function. The output of the tr ...
over a modulus, was discovered. It has a time complexity of O(n\log n\log\log n). In 2007, Martin Fürer proposed an algorithm with complexity O(n\log n 2^). In 2014, Harvey, Joris van der Hoeven, and Lecerf proposed one with complexity O(n\log n 2^), thus making the implicit constant explicit; this was improved to O(n\log n 2^) in 2018. Lastly, in 2019, Harvey and van der Hoeven came up with a galactic algorithm with complexity O(n\log n). This matches a guess by Schönhage and Strassen that this would be the optimal bound, although this remains a
conjecture In mathematics, a conjecture is a conclusion or a proposition that is proffered on a tentative basis without proof. Some conjectures, such as the Riemann hypothesis or Fermat's conjecture (now a theorem, proven in 1995 by Andrew Wiles), ha ...
today. Integer multiplication algorithms can also be used to multiply polynomials by means of the method of Kronecker substitution.


Long multiplication

If a
positional numeral system Positional notation, also known as place-value notation, positional numeral system, or simply place value, usually denotes the extension to any base of the Hindu–Arabic numeral system (or decimal system). More generally, a positional system ...
is used, a natural way of multiplying numbers is taught in schools as long multiplication, sometimes called grade-school multiplication, sometimes called the Standard Algorithm: multiply the multiplicand by each digit of the multiplier and then add up all the properly shifted results. It requires memorization of the
multiplication table In mathematics, a multiplication table (sometimes, less formally, a times table) is a mathematical table used to define a multiplication binary operation, operation for an algebraic system. The decimal multiplication table was traditionally tau ...
for single digits. This is the usual algorithm for multiplying larger numbers by hand in base 10. A person doing long multiplication on paper will write down all the products and then add them together; an
abacus An abacus ( abaci or abacuses), also called a counting frame, is a hand-operated calculating tool which was used from ancient times in the ancient Near East, Europe, China, and Russia, until the adoption of the Hindu–Arabic numeral system. A ...
-user will sum the products as soon as each one is computed.


Example

This example uses ''long multiplication'' to multiply 23,958,233 (multiplicand) by 5,830 (multiplier) and arrives at 139,676,498,390 for the result (product). 23958233 × 5830 ——————————————— 00000000 ( = 23,958,233 × 0) 71874699 ( = 23,958,233 × 30) 191665864 ( = 23,958,233 × 800) + 119791165 ( = 23,958,233 × 5,000) ——————————————— 139676498390 ( = 139,676,498,390)


Other notations

In some countries such as
Germany Germany, officially the Federal Republic of Germany, is a country in Central Europe. It lies between the Baltic Sea and the North Sea to the north and the Alps to the south. Its sixteen States of Germany, constituent states have a total popu ...
, the above multiplication is depicted similarly but with the original product kept horizontal and computation starting with the first digit of the multiplier: 23958233 · 5830 ——————————————— 119791165 191665864 71874699 00000000 ——————————————— 139676498390 Below pseudocode describes the process of above multiplication. It keeps only one row to maintain the sum which finally becomes the result. Note that the '+=' operator is used to denote sum to existing value and store operation (akin to languages such as Java and C) for compactness. multiply(a ..p b ..q base) // Operands containing rightmost digits at index 1 product = ..p+q // Allocate space for result for b_i = 1 to q // for all digits in b carry = 0 for a_i = 1 to p // for all digits in a product _i + b_i - 1+= carry + a _i* b _i carry = product _i + b_i - 1/ base product _i + b_i - 1= product _i + b_i - 1mod base product _i + p= carry // last digit comes from final carry return product


Usage in computers

Some
chips ''CHiPs'' is an American crime drama television series created by Rick Rosner and originally aired on NBC from September 15, 1977, to May 1, 1983. After the final first-run telecast on NBC in May 1983, the series went into reruns on Sundays fr ...
implement long multiplication, in hardware or in
microcode In processor design, microcode serves as an intermediary layer situated between the central processing unit (CPU) hardware and the programmer-visible instruction set architecture of a computer. It consists of a set of hardware-level instructions ...
, for various integer and floating-point word sizes. In
arbitrary-precision arithmetic In computer science, arbitrary-precision arithmetic, also called bignum arithmetic, multiple-precision arithmetic, or sometimes infinite-precision arithmetic, indicates that calculations are performed on numbers whose digits of precision are po ...
, it is common to use long multiplication with the base set to 2''w'', where ''w'' is the number of bits in a word, for multiplying relatively small numbers. To multiply two numbers with ''n'' digits using this method, one needs about ''n''2 operations. More formally, multiplying two ''n''-digit numbers using long multiplication requires Θ(''n''2) single-digit operations (additions and multiplications). When implemented in software, long multiplication algorithms must deal with overflow during additions, which can be expensive. A typical solution is to represent the number in a small base, ''b'', such that, for example, 8''b'' is a representable machine integer. Several additions can then be performed before an overflow occurs. When the number becomes too large, we add part of it to the result, or we carry and map the remaining part back to a number that is less than ''b''. This process is called ''normalization''. Richard Brent used this approach in his Fortran package, MP. Computers initially used a very similar algorithm to long multiplication in base 2, but modern processors have optimized circuitry for fast multiplications using more efficient algorithms, at the price of a more complex hardware realization. In base two, long multiplication is sometimes called "shift and add", because the algorithm simplifies and just consists of shifting left (multiplying by powers of two) and adding. Most currently available microprocessors implement this or other similar algorithms (such as Booth encoding) for various integer and floating-point sizes in
hardware multiplier A binary multiplier is an electronic circuit used in digital electronics, such as a computer, to multiply two binary numbers. A variety of computer arithmetic techniques can be used to implement a digital multiplier. Most techniques involve com ...
s or in
microcode In processor design, microcode serves as an intermediary layer situated between the central processing unit (CPU) hardware and the programmer-visible instruction set architecture of a computer. It consists of a set of hardware-level instructions ...
. On currently available processors, a bit-wise shift instruction is usually (but not always) faster than a multiply instruction and can be used to multiply (shift left) and divide (shift right) by powers of two. Multiplication by a constant and division by a constant can be implemented using a sequence of shifts and adds or subtracts. For example, there are several ways to multiply by 10 using only bit-shift and addition. ((x << 2) + x) << 1 # Here 10*x is computed as (x*2^2 + x)*2 (x << 3) + (x << 1) # Here 10*x is computed as x*2^3 + x*2 In some cases such sequences of shifts and adds or subtracts will outperform hardware multipliers and especially dividers. A division by a number of the form 2^n or 2^n \pm 1 often can be converted to such a short sequence.


Algorithms for multiplying by hand

In addition to the standard long multiplication, there are several other methods used to perform multiplication by hand. Such algorithms may be devised for speed, ease of calculation, or educational value, particularly when computers or
multiplication table In mathematics, a multiplication table (sometimes, less formally, a times table) is a mathematical table used to define a multiplication binary operation, operation for an algebraic system. The decimal multiplication table was traditionally tau ...
s are unavailable.


Grid method

The grid method (or box method) is an introductory method for multiple-digit multiplication that is often taught to pupils at
primary school A primary school (in Ireland, India, the United Kingdom, Australia, New Zealand, Trinidad and Tobago, Jamaica, South Africa, and Singapore), elementary school, or grade school (in North America and the Philippines) is a school for primary ...
or
elementary school A primary school (in Ireland, India, the United Kingdom, Australia, New Zealand, Trinidad and Tobago, Jamaica, South Africa, and Singapore), elementary school, or grade school (in North America and the Philippines) is a school for primary ...
. It has been a standard part of the national primary school mathematics curriculum in England and Wales since the late 1990s. Both factors are broken up ("partitioned") into their hundreds, tens and units parts, and the products of the parts are then calculated explicitly in a relatively simple multiplication-only stage, before these contributions are then totalled to give the final answer in a separate addition stage. The calculation 34 × 13, for example, could be computed using the grid:
  300
   40
   90
 + 12
 ————
  442
followed by addition to obtain 442, either in a single sum (see right), or through forming the row-by-row totals : (300 + 40) + (90 + 12) = 340 + 102 = 442. This calculation approach (though not necessarily with the explicit grid arrangement) is also known as the partial products algorithm. Its essence is the calculation of the simple multiplications separately, with all addition being left to the final gathering-up stage. The grid method can in principle be applied to factors of any size, although the number of sub-products becomes cumbersome as the number of digits increases. Nevertheless, it is seen as a usefully explicit method to introduce the idea of multiple-digit multiplications; and, in an age when most multiplication calculations are done using a calculator or a spreadsheet, it may in practice be the only multiplication algorithm that some students will ever need.


Lattice multiplication

Lattice, or sieve, multiplication is algorithmically equivalent to long multiplication. It requires the preparation of a lattice (a grid drawn on paper) which guides the calculation and separates all the multiplications from the
addition Addition (usually signified by the Plus and minus signs#Plus sign, plus symbol, +) is one of the four basic Operation (mathematics), operations of arithmetic, the other three being subtraction, multiplication, and Division (mathematics), divis ...
s. It was introduced to Europe in 1202 in
Fibonacci Leonardo Bonacci ( – ), commonly known as Fibonacci, was an Italians, Italian mathematician from the Republic of Pisa, considered to be "the most talented Western mathematician of the Middle Ages". The name he is commonly called, ''Fibonacci ...
's
Liber Abaci The or (Latin for "The Book of Calculation") was a 1202 Latin work on arithmetic by Leonardo of Pisa, posthumously known as Fibonacci. It is primarily famous for introducing both base-10 positional notation and the symbols known as Arabic n ...
. Fibonacci described the operation as mental, using his right and left hands to carry the intermediate calculations. Matrakçı Nasuh presented 6 different variants of this method in this 16th-century book, Umdet-ul Hisab. It was widely used in Enderun schools across the Ottoman Empire.
Napier's bones Napier's bones is a manually operated calculating device created by John Napier of Merchiston, Scotland for the calculation of products and quotients of numbers. The method was based on lattice multiplication, and also called ''rabdology'', a w ...
, or Napier's rods also used this method, as published by Napier in 1617, the year of his death. As shown in the example, the multiplicand and multiplier are written above and to the right of a lattice, or a sieve. It is found in
Muhammad ibn Musa al-Khwarizmi Muhammad ibn Musa al-Khwarizmi , or simply al-Khwarizmi, was a mathematician active during the Islamic Golden Age, who produced Arabic-language works in mathematics, astronomy, and geography. Around 820, he worked at the House of Wisdom in B ...
's "Arithmetic", one of Leonardo's sources mentioned by Sigler, author of "Fibonacci's Liber Abaci", 2002. *During the multiplication phase, the lattice is filled in with two-digit products of the corresponding digits labeling each row and column: the tens digit goes in the top-left corner. *During the addition phase, the lattice is summed on the diagonals. * Finally, if a carry phase is necessary, the answer as shown along the left and bottom sides of the lattice is converted to normal form by carrying ten's digits as in long addition or multiplication.


Example

The pictures on the right show how to calculate 345 × 12 using lattice multiplication. As a more complicated example, consider the picture below displaying the computation of 23,958,233 multiplied by 5,830 (multiplier); the result is 139,676,498,390. Notice 23,958,233 is along the top of the lattice and 5,830 is along the right side. The products fill the lattice and the sum of those products (on the diagonal) are along the left and bottom sides. Then those sums are totaled as shown.


Russian peasant multiplication

The binary method is also known as peasant multiplication, because it has been widely used by people who are classified as peasants and thus have not memorized the
multiplication table In mathematics, a multiplication table (sometimes, less formally, a times table) is a mathematical table used to define a multiplication binary operation, operation for an algebraic system. The decimal multiplication table was traditionally tau ...
s required for long multiplication. The algorithm was in use in ancient Egypt. Its main advantages are that it can be taught quickly, requires no memorization, and can be performed using tokens, such as
poker chips Casino chips (also known as poker chips, gaming tokens, or checks/cheques) are small discs used as currency in casinos. Larger, rectangular gaming plaques may be used for high-stakes games. Poker chips are also widely used as play money in ca ...
, if paper and pencil aren't available. The disadvantage is that it takes more steps than long multiplication, so it can be unwieldy for large numbers.


Description

On paper, write down in one column the numbers you get when you repeatedly halve the multiplier, ignoring the remainder; in a column beside it repeatedly double the multiplicand. Cross out each row in which the last digit of the first number is even, and add the remaining numbers in the second column to obtain the product.


Examples

This example uses peasant multiplication to multiply 11 by 3 to arrive at a result of 33. Decimal: Binary: 11 3 1011 11 5 6 101 110 2 12 10 1100 1 24 1 11000 —— —————— 33 100001 Describing the steps explicitly: * 11 and 3 are written at the top * 11 is halved (5.5) and 3 is doubled (6). The fractional portion is discarded (5.5 becomes 5). * 5 is halved (2.5) and 6 is doubled (12). The fractional portion is discarded (2.5 becomes 2). The figure in the left column (2) is even, so the figure in the right column (12) is discarded. * 2 is halved (1) and 12 is doubled (24). * All not-scratched-out values are summed: 3 + 6 + 24 = 33. The method works because multiplication is distributive, so: : \begin 3 \times 11 & = 3 \times (1\times 2^0 + 1\times 2^1 + 0\times 2^2 + 1\times 2^3) \\ & = 3 \times (1 + 2 + 8) \\ & = 3 + 6 + 24 \\ & = 33. \end A more complicated example, using the figures from the earlier examples (23,958,233 and 5,830): Decimal: Binary: 5830 23958233 1011011000110 1011011011001001011011001 2915 47916466 101101100011 10110110110010010110110010 1457 95832932 10110110001 101101101100100101101100100 728 191665864 1011011000 1011011011001001011011001000 364 383331728 101101100 10110110110010010110110010000 182 766663456 10110110 101101101100100101101100100000 91 1533326912 1011011 1011011011001001011011001000000 45 3066653824 101101 10110110110010010110110010000000 22 6133307648 10110 101101101100100101101100100000000 11 12266615296 1011 1011011011001001011011001000000000 5 24533230592 101 10110110110010010110110010000000000 2 49066461184 10 101101101100100101101100100000000000 1 98132922368 1 1011011011001001011011001000000000000 ———————————— 1022143253354344244353353243222210110 (before carry) 139676498390 10000010000101010111100011100111010110


Quarter square multiplication

This formula can in some cases be used, to make multiplication tasks easier to complete: : \frac - \frac = \frac\left(\left(x^2+2xy+y^2\right) - \left(x^2-2xy+y^2\right)\right) = \frac\left(4xy\right) = xy. In the case where x and y are integers, we have that : (x+y)^2 \equiv (x-y)^2 \bmod 4 because x+y and x-y are either both even or both odd. This means that :\begin xy &= \frac14(x+y)^2 - \frac14(x-y)^2 \\ &= \left((x+y)^2 \text 4\right)- \left((x-y)^2 \text 4\right) \end and it's sufficient to (pre-)compute the integral part of squares divided by 4 like in the following example.


Examples

Below is a lookup table of quarter squares with the remainder discarded for the digits 0 through 18; this allows for the multiplication of numbers up to . If, for example, you wanted to multiply 9 by 3, you observe that the sum and difference are 12 and 6 respectively. Looking both those values up on the table yields 36 and 9, the difference of which is 27, which is the product of 9 and 3.


History of quarter square multiplication

In prehistoric time, quarter square multiplication involved
floor function In mathematics, the floor function is the function that takes as input a real number , and gives as output the greatest integer less than or equal to , denoted or . Similarly, the ceiling function maps to the least integer greater than or eq ...
; that some sources attribute to
Babylonian mathematics Babylonian mathematics (also known as Assyro-Babylonian mathematics) is the mathematics developed or practiced by the people of Mesopotamia, as attested by sources mainly surviving from the Old Babylonian period (1830–1531 BC) to the Seleucid ...
(2000–1600 BC). Antoine Voisin published a table of quarter squares from 1 to 1000 in 1817 as an aid in multiplication. A larger table of quarter squares from 1 to 100000 was published by Samuel Laundy in 1856, and a table from 1 to 200000 by Joseph Blater in 1888. Quarter square multipliers were used in
analog computer An analog computer or analogue computer is a type of computation machine (computer) that uses physical phenomena such as Electrical network, electrical, Mechanics, mechanical, or Hydraulics, hydraulic quantities behaving according to the math ...
s to form an
analog signal An analog signal (American English) or analogue signal (British and Commonwealth English) is any continuous-time signal representing some other quantity, i.e., ''analogous'' to another quantity. For example, in an analog audio signal, the ins ...
that was the product of two analog input signals. In this application, the sum and difference of two input
voltage Voltage, also known as (electrical) potential difference, electric pressure, or electric tension, is the difference in electric potential between two points. In a Electrostatics, static electric field, it corresponds to the Work (electrical), ...
s are formed using
operational amplifier An operational amplifier (often op amp or opamp) is a direct coupling, DC-coupled Electronic component, electronic voltage amplifier with a differential input, a (usually) Single-ended signaling, single-ended output, and an extremely high gain ( ...
s. The square of each of these is approximated using piecewise linear circuits. Finally the difference of the two squares is formed and scaled by a factor of one fourth using yet another operational amplifier. In 1980, Everett L. Johnson proposed using the quarter square method in a
digital Digital usually refers to something using discrete digits, often binary digits. Businesses *Digital bank, a form of financial institution *Digital Equipment Corporation (DEC) or Digital, a computer company *Digital Research (DR or DRI), a software ...
multiplier. To form the product of two 8-bit integers, for example, the digital device forms the sum and difference, looks both quantities up in a table of squares, takes the difference of the results, and divides by four by shifting two bits to the right. For 8-bit integers the table of quarter squares will have 29−1=511 entries (one entry for the full range 0..510 of possible sums, the differences using only the first 256 entries in range 0..255) or 29−1=511 entries (using for negative differences the technique of 2-complements and 9-bit masking, which avoids testing the sign of differences), each entry being 16-bit wide (the entry values are from (0²/4)=0 to (510²/4)=65025). The quarter square multiplier technique has benefited 8-bit systems that do not have any support for a hardware multiplier. Charles Putney implemented this for the
6502 The MOS Technology 6502 (typically pronounced "sixty-five-oh-two" or "six-five-oh-two") William Mensch and the moderator both pronounce the 6502 microprocessor as ''"sixty-five-oh-two"''. is an 8-bit microprocessor that was designed by a small ...
.


Computational complexity of multiplication

A line of research in
theoretical computer science Theoretical computer science is a subfield of computer science and mathematics that focuses on the Abstraction, abstract and mathematical foundations of computation. It is difficult to circumscribe the theoretical areas precisely. The Associati ...
is about the number of single-bit arithmetic operations necessary to multiply two n-bit integers. This is known as the
computational complexity In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations ...
of multiplication. Usual algorithms done by hand have asymptotic complexity of O(n^2), but in 1960
Anatoly Karatsuba Anatoly Alexeyevich Karatsuba (his first name often spelled Anatolii) (; Grozny, Soviet Union, 31 January 1937 – Moscow, Russia, 28 September 2008) was a Russian people, Russian mathematician working in the field of analytic number theory, p-ad ...
discovered that better complexity was possible (with the
Karatsuba algorithm The Karatsuba algorithm is a fast multiplication algorithm for integers. It was discovered by Anatoly Karatsuba in 1960 and published in 1962. Knuth D.E. (1969) '' The Art of Computer Programming. v.2.'' Addison-Wesley Publ.Co., 724 pp ...
). Currently, the algorithm with the best computational complexity is a 2019 algorithm of David Harvey and Joris van der Hoeven, which uses the strategies of using
number-theoretic transform In mathematics, the discrete Fourier transform over a ring generalizes the discrete Fourier transform (DFT), of a function whose values are commonly complex numbers, over an arbitrary ring. Definition Let be any ring, let n\geq 1 be an integer, ...
s introduced with the Schönhage–Strassen algorithm to multiply integers using only O(n\log n) operations. This is conjectured to be the best possible algorithm, but lower bounds of \Omega(n\log n) are not known.


Karatsuba multiplication

Karatsuba multiplication is an O(''n''log23) ≈ O(''n''1.585) divide and conquer algorithm, that uses recursion to merge together sub calculations. By rewriting the formula, one makes it possible to do sub calculations / recursion. By doing recursion, one can solve this in a fast manner. Let x and y be represented as n-digit strings in some base B. For any positive integer m less than n, one can write the two given numbers as :x = x_1 B^m + x_0, :y = y_1 B^m + y_0, where x_0 and y_0 are less than B^m. The product is then \begin xy &= (x_1 B^m + x_0)(y_1 B^m + y_0) \\ &= x_1 y_1 B^ + (x_1 y_0 + x_0 y_1) B^m + x_0 y_0 \\ &= z_2 B^ + z_1 B^m + z_0, \\ \end where :z_2 = x_1 y_1, :z_1 = x_1 y_0 + x_0 y_1, :z_0 = x_0 y_0. These formulae require four multiplications and were known to
Charles Babbage Charles Babbage (; 26 December 1791 â€“ 18 October 1871) was an English polymath. A mathematician, philosopher, inventor and mechanical engineer, Babbage originated the concept of a digital programmable computer. Babbage is considered ...
. Karatsuba observed that xy can be computed in only three multiplications, at the cost of a few extra additions. With z_0 and z_2 as before one can observe that : \begin z_1 &= x_1 y_0 + x_0 y_1 \\ &= x_1 y_0 + x_0 y_1 + x_1 y_1 - x_1 y_1 + x_0 y_0 - x_0 y_0 \\ &= x_1 y_0 + x_0 y_0 + x_0 y_1 + x_1 y_1 - x_1 y_1 - x_0 y_0 \\ &= (x_1 + x_0) y_0 + (x_0 + x_1) y_1 - x_1 y_1 - x_0 y_0 \\ &= (x_1 + x_0) (y_0 + y_1) - x_1 y_1 - x_0 y_0 \\ &= (x_1 + x_0) (y_1 + y_0) - z_2 - z_0. \\ \end Because of the overhead of recursion, Karatsuba's multiplication is slower than long multiplication for small values of ''n''; typical implementations therefore switch to long multiplication for small values of ''n''.


General case with multiplication of N numbers

By exploring patterns after expansion, one see following: \begin (x_1 B^ + x_0) (y_1 B^ + y_0) (z_1 B^ + z_0) (a_1 B^ + a_0) &= a_1 x_1 y_1 z_1 B^ &+ a_1 x_1 y_1 z_0 B^ &+ a_1 x_1 y_0 z_1 B^ &+ a_1 x_0 y_1 z_1 B^ \\ &+ a_0 x_1 y_1 z_1 B^ &+ a_1 x_1 y_0 z_0 B^ &+ a_1 x_0 y_1 z_0 B^ &+ a_0 x_1 y_1 z_0 B^\\ &+ a_1 x_0 y_0 z_1 B^ &+ a_0 x_1 y_0 z_1 B^ &+ a_0 x_0 y_1 z_1 B^ &+ a_1 x_0 y_0 z_0 B^\\ &+ a_0 x_1 y_0 z_0 B^ &+ a_0 x_0 y_1 z_0 B^ &+ a_0 x_0 y_0 z_1 B^ &+ a_0 x_0 y_0 z_0 \phantom \end Each summand is associated to a unique binary number from 0 to 2^-1 , for example a_1 x_1 y_1 z_1 \longleftrightarrow 1111,\ a_1 x_0 y_1 z_0 \longleftrightarrow 1010 etc. Furthermore; B is powered to number of 1, in this binary string, multiplied with m. If we express this in fewer terms, we get: \prod_^N (x_ B^ + x_) = \sum_^\prod_^N x_B^ = \sum_^z_jB^ , where c(i,j) means digit in number i at position j. Notice that c(i,j) \in \ \begin z_ &= \prod_^N x_ \\ z_ &= \prod_^N x_ \\ z_ &= \prod_^N (x_ + x_) - \sum_^ z_i \end


History

Karatsuba's algorithm was the first known algorithm for multiplication that is asymptotically faster than long multiplication, and can thus be viewed as the starting point for the theory of fast multiplications.


Toom–Cook

Another method of multiplication is called Toom–Cook or Toom-3. The Toom–Cook method splits each number to be multiplied into multiple parts. The Toom–Cook method is one of the generalizations of the Karatsuba method. A three-way Toom–Cook can do a size-''3N'' multiplication for the cost of five size-''N'' multiplications. This accelerates the operation by a factor of 9/5, while the Karatsuba method accelerates it by 4/3. Although using more and more parts can reduce the time spent on recursive multiplications further, the overhead from additions and digit management also grows. For this reason, the method of Fourier transforms is typically faster for numbers with several thousand digits, and asymptotically faster for even larger numbers.


Schönhage–Strassen

Every number in base B, can be written as a polynomial: X = \sum_^N Furthermore, multiplication of two numbers could be thought of as a product of two polynomials: XY = (\sum_^N )(\sum_^N ) Because,for B^k : c_k =\sum_ = \sum_^k , we have a convolution. By using fft (fast fourier transformation) with convolution rule, we can get \hat(a * b) = \hat(\sum_^k ) = \hat(a) \bullet \hat(b) . That is; C_k = a_k \bullet b_k , where C_k is the corresponding coefficient in fourier space. This can also be written as: \mathrm(a * b) = \mathrm(a) \bullet \mathrm(b). We have the same coefficient due to linearity under fourier transformation, and because these polynomials only consist of one unique term per coefficient: \hat(x^n) = \left(\frac\right)^n \delta^ and \hat(a\, X(\xi) + b\, Y(\xi)) = a\, \hat(\xi) + b\, \hat(\xi) * Convolution rule: \hat(X * Y) = \ \hat(X) \bullet \hat(Y) We have reduced our convolution problem to product problem, through fft. By finding ifft (polynomial interpolation), for each c_k , one get the desired coefficients. Algorithm uses divide and conquer strategy, to divide problem to subproblems. It has a time complexity of O(''n'' log(''n'') log(log(''n''))).


History

The algorithm was invented by Strassen (1968). It was made practical and theoretical guarantees were provided in 1971 by Schönhage and Strassen resulting in the Schönhage–Strassen algorithm.


Further improvements

In 2007 the
asymptotic complexity In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations ...
of integer multiplication was improved by the Swiss mathematician Martin Fürer of Pennsylvania State University to O(n \log n \cdot ^) using Fourier transforms over
complex number In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the for ...
s, where log* denotes the iterated logarithm. Anindya De, Chandan Saha, Piyush Kurur and Ramprasad Saptharishi gave a similar algorithm using
modular arithmetic In mathematics, modular arithmetic is a system of arithmetic operations for integers, other than the usual ones from elementary arithmetic, where numbers "wrap around" when reaching a certain value, called the modulus. The modern approach to mo ...
in 2008 achieving the same running time. In context of the above material, what these latter authors have achieved is to find ''N'' much less than 23''k'' + 1, so that ''Z''/''NZ'' has a (2''m'')th root of unity. This speeds up computation and reduces the time complexity. However, these latter algorithms are only faster than Schönhage–Strassen for impractically large inputs. In 2014, Harvey, Joris van der Hoeven and Lecerf gave a new algorithm that achieves a running time of O(n\log n \cdot 2^), making explicit the implied constant in the O(\log^* n) exponent. They also proposed a variant of their algorithm which achieves O(n\log n \cdot 2^) but whose validity relies on standard conjectures about the distribution of
Mersenne prime In mathematics, a Mersenne prime is a prime number that is one less than a power of two. That is, it is a prime number of the form for some integer . They are named after Marin Mersenne, a French Minim friar, who studied them in the early 1 ...
s. In 2016, Covanov and Thomé proposed an integer multiplication algorithm based on a generalization of Fermat primes that conjecturally achieves a complexity bound of O(n\log n \cdot 2^). This matches the 2015 conditional result of Harvey, van der Hoeven, and Lecerf but uses a different algorithm and relies on a different conjecture. In 2018, Harvey and van der Hoeven used an approach based on the existence of short lattice vectors guaranteed by Minkowski's theorem to prove an unconditional complexity bound of O(n\log n \cdot 2^). In March 2019, David Harvey and Joris van der Hoeven announced their discovery of an multiplication algorithm. It was published in the ''
Annals of Mathematics The ''Annals of Mathematics'' is a mathematical journal published every two months by Princeton University and the Institute for Advanced Study. History The journal was established as ''The Analyst'' in 1874 and with Joel E. Hendricks as t ...
'' in 2021. Because Schönhage and Strassen predicted that ''n'' log(''n'') is the "best possible" result, Harvey said: "...our work is expected to be the end of the road for this problem, although we don't know yet how to prove this rigorously."


Lower bounds

There is a trivial lower bound of Ω(''n'') for multiplying two ''n''-bit numbers on a single processor; no matching algorithm (on conventional machines, that is on Turing equivalent machines) nor any sharper lower bound is known. Multiplication lies outside of AC0 'p''for any prime ''p'', meaning there is no family of constant-depth, polynomial (or even subexponential) size circuits using AND, OR, NOT, and MOD''p'' gates that can compute a product. This follows from a constant-depth reduction of MOD''q'' to multiplication. Lower bounds for multiplication are also known for some classes of branching programs.


Complex number multiplication

Complex multiplication normally involves four multiplications and two additions. :(a+bi) (c+di) = (ac-bd) + (bc+ad)i. Or : \begin \times & a & bi \\ \hline c & ac & bci \\ \hline di & adi & -bd \end As observed by Peter Ungar in 1963, one can reduce the number of multiplications to three, using essentially the same computation as Karatsuba's algorithm. The product (''a'' + ''bi'') · (''c'' + ''di'') can be calculated in the following way. :''k''1 = ''c'' · (''a'' + ''b'') :''k''2 = ''a'' · (''d'' − ''c'') :''k''3 = ''b'' · (''c'' + ''d'') :Real part = ''k''1 − ''k''3 :Imaginary part = ''k''1 + ''k''2. This algorithm uses only three multiplications, rather than four, and five additions or subtractions rather than two. If a multiply is more expensive than three adds or subtracts, as when calculating by hand, then there is a gain in speed. On modern computers a multiply and an add can take about the same time so there may be no speed gain. There is a trade-off in that there may be some loss of precision when using floating point. For
fast Fourier transform A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IDFT). A Fourier transform converts a signal from its original domain (often time or space) to a representation in ...
s (FFTs) (or any
linear transformation In mathematics, and more specifically in linear algebra, a linear map (also called a linear mapping, linear transformation, vector space homomorphism, or in some contexts linear function) is a mapping V \to W between two vector spaces that pr ...
) the complex multiplies are by constant coefficients ''c'' + ''di'' (called
twiddle factor A twiddle factor, in fast Fourier transform (FFT) algorithms, is any of the trigonometric constant coefficients that are multiplied by the data in the course of the algorithm. This term was apparently coined by Gentleman & Sande in 1966, and has ...
s in FFTs), in which case two of the additions (''d''−''c'' and ''c''+''d'') can be precomputed. Hence, only three multiplies and three adds are required. However, trading off a multiplication for an addition in this way may no longer be beneficial with modern
floating-point unit A floating-point unit (FPU), numeric processing unit (NPU), colloquially math coprocessor, is a part of a computer system specially designed to carry out operations on floating-point numbers. Typical operations are addition, subtraction, multip ...
s.


Polynomial multiplication

All the above multiplication algorithms can also be expanded to multiply
polynomial In mathematics, a polynomial is a Expression (mathematics), mathematical expression consisting of indeterminate (variable), indeterminates (also called variable (mathematics), variables) and coefficients, that involves only the operations of addit ...
s. Alternatively the Kronecker substitution technique may be used to convert the problem of multiplying polynomials into a single binary multiplication. Long multiplication methods can be generalised to allow the multiplication of algebraic formulae: 14ac - 3ab + 2 multiplied by ac - ab + 1 14ac -3ab 2 ac -ab 1 ———————————————————— 14a2c2 -3a2bc 2ac -14a2bc 3 a2b2 -2ab 14ac -3ab 2 ——————————————————————————————————————— 14a2c2 -17a2bc 16ac 3a2b2 -5ab +2

As a further example of column based multiplication, consider multiplying 23 long tons (t), 12 hundredweight (cwt) and 2 quarters (qtr) by 47. This example uses
avoirdupois Avoirdupois (; abbreviated avdp.) is a measurement system of weights that uses pounds and ounces as units. It was first commonly used in the 13th century AD and was updated in 1959. In 1959, by international agreement, the definitions of the p ...
measures: 1 t = 20 cwt, 1 cwt = 4 qtr. t cwt qtr 23 12 2 47 x ———————————————— 141 94 94 940 470 29 23 ———————————————— 1110 587 94 ———————————————— 1110 7 2

=
Answer: 1110 ton 7 cwt 2 qtr First multiply the quarters by 47, the result 94 is written into the first workspace. Next, multiply cwt 12*47 = (2 + 10)*47 but don't add up the partial results (94, 470) yet. Likewise multiply 23 by 47 yielding (141, 940). The quarters column is totaled and the result placed in the second workspace (a trivial move in this case). 94 quarters is 23 cwt and 2 qtr, so place the 2 in the answer and put the 23 in the next column left. Now add up the three entries in the cwt column giving 587. This is 29 t 7 cwt, so write the 7 into the answer and the 29 in the column to the left. Now add up the tons column. There is no adjustment to make, so the result is just copied down. The same layout and methods can be used for any traditional measurements and non-decimal currencies such as the old British
£sd file:Guildhall Museum Collection- Drusilla Dunford Money Table Sampler 3304.JPG, A Sampler (needlework), sampler in the Rochester Guildhall, Guildhall Museum of Rochester, Medway, Rochester illustrates the conversion between pence and shillings ...
system.


See also

*
Binary multiplier A binary multiplier is an electronic circuit used in digital electronics, such as a computer, to multiply two binary numbers. A variety of computer arithmetic techniques can be used to implement a digital multiplier. Most techniques involve com ...
* Dadda multiplier *
Division algorithm A division algorithm is an algorithm which, given two integers ''N'' and ''D'' (respectively the numerator and the denominator), computes their quotient and/or remainder, the result of Euclidean division. Some are applied by hand, while others ar ...
* Horner scheme for evaluating of a polynomial *
Logarithm In mathematics, the logarithm of a number is the exponent by which another fixed value, the base, must be raised to produce that number. For example, the logarithm of to base is , because is to the rd power: . More generally, if , the ...
*
Matrix multiplication algorithm Because matrix multiplication is such a central operation in many numerical algorithms, much work has been invested in making matrix multiplication algorithms efficient. Applications of matrix multiplication in computational problems are found in m ...
*
Mental calculation Mental calculation (also known as mental computation) consists of arithmetical calculations made by the mind, within the brain, with no help from any supplies (such as pencil and paper) or devices such as a calculator. People may use menta ...
*
Number-theoretic transform In mathematics, the discrete Fourier transform over a ring generalizes the discrete Fourier transform (DFT), of a function whose values are commonly complex numbers, over an arbitrary ring. Definition Let be any ring, let n\geq 1 be an integer, ...
* Prosthaphaeresis *
Slide rule A slide rule is a hand-operated mechanical calculator consisting of slidable rulers for conducting mathematical operations such as multiplication, division, exponents, roots, logarithms, and trigonometry. It is one of the simplest analog ...
* Trachtenberg system * for another fast multiplication algorithm, specially efficient when many operations are done in sequence, such as in linear algebra * Wallace tree


References


Further reading

* * * (x+268 pages)


External links


Basic arithmetic


The Many Ways of Arithmetic in UCSMP Everyday Mathematics

A Powerpoint presentation about ancient mathematics



Advanced algorithms



{{DEFAULTSORT:Multiplication Algorithm * Multiplication Articles with example pseudocode