Toom–Cook, sometimes known as Toom-3, named after Andrei Toom, who introduced the new algorithm with its low complexity, and Stephen Cook, who cleaned the description of it, is a multiplication algorithm for large integers.
Given two large integers, a and b, Toom–Cook splits up a and b into k smaller parts each of length l, and performs operations on the parts. As k grows, one may combine many of the multiplication sub-operations, thus reducing the overall computational complexity of the algorithm. The multiplication sub-operations can then be computed recursively using Toom–Cook multiplication again, and so on. Although the terms "Toom-3" and "Toom–Cook" are sometimes incorrectly used interchangeably, Toom-3 is only a single instance of the Toom–Cook algorithm, where k = 3.
Toom-3 reduces nine multiplications to five, and runs in Θ(nlog(5)/log(3)) ≈ Θ(n1.46). In general, Toom-k runs in Θ(c(k) ne), where e = log(2k − 1) / log(k), ne is the time spent on sub-multiplications, and c is the time spent on additions and multiplication by small constants.[1] The Karatsuba algorithm is equivalent to Toom-2, where the number is split into two smaller ones. It reduces four multiplications to three and so operates at Θ(nlog(3)/log(2)) ≈ Θ(n1.58).
Although the exponent e can be set arbitrarily close to 1 by increasing k, the constant term in the function grows very rapidly.[1][2] The growth rate for mixed-level Toom–Cook schemes was still an open research problem in 2005.[3] An implementation described by Donald Knuth achieves the time complexity Θ(n 2√2 log n log n).[4]
Due to its overhead, Toom–Cook is slower than long multiplication with small numbers, and it is therefore typically used for intermediate-size multiplications, before the asymptotically faster Schönhage–Strassen algorithm (with complexity Θ(n log n log log n)) becomes practical.
Toom first described this algorithm in 1963, and Cook published an improved (asymptotically equivalent) algorithm in his PhD thesis in 1966.[5]
Details
This section discusses exactly how to perform Toom-k for any given value of k, and is a simplification of a description of Toom–Cook polynomial multiplication described by Marco Bodrato.[6] The algorithm has five main steps:
In a typical large integer implementation, each integer is represented as a sequence of digits in positional notation, with the base or radix set to some (typically large) value b; for this example we use b = 10000, so that each digit corresponds to a group of four decimal digits (in a computer implementation, b would typically be a power of 2 instead). Say the two integers being multiplied are:
m
=
12
3456
7890
1234
5678
9012
n
=
9
8765
4321
9876
5432
1098.
These are much smaller than would normally be processed with Toom–Cook (grade-school multiplication would be faster) but they will serve to illustrate the algorithm.
Splitting
In Toom-k, we want to split the factors into k parts.
The first step is to select the base B = bi, such that the number of digits of both m and n in base B is at most k (e.g., 3 in Toom-3). A typical choice for i is given by:
In our example we'll be doing Toom-3, so we choose B = b2 = 108. We then separate m and n into their base B digits mi, ni:
We then use these digits as coefficients in degree-(k − 1) polynomials p and q, with the property that p(B) = m and q(B) = n:
The purpose of defining these polynomials is that if we can compute their product r(x) = p(x)q(x), our answer will be r(B) = m × n.
In the case where the numbers being multiplied are of different sizes, it's useful to use different values of k for m and n, which we'll call km and kn. For example, the algorithm "Toom-2.5" refers to Toom–Cook with km = 3 and kn = 2. In this case the i in B = bi is typically chosen by:
Evaluation
The Toom–Cook approach to computing the polynomial product p(x)q(x) is a commonly used one. Note that a polynomial of degree d is uniquely determined by d + 1 points (for example, a line - polynomial of degree one is specified by two points). The idea is to evaluate p(·) and q(·) at various points. Then multiply their values at these points to get points on the product polynomial. Finally interpolate to find its coefficients.
Since deg(pq) = deg(p) + deg(q), we will need deg(p) + deg(q) + 1 = km + kn − 1 points to determine the final result. Call this d. In the case of Toom-3, d = 5. The algorithm will work no matter what points are chosen (with a few small exceptions, see matrix invertibility requirement in Interpolation), but in the interest of simplifying the algorithm it's better to choose small integer values like 0, 1, −1, and −2.
One unusual point value that is frequently used is infinity, written ∞ or 1/0. To "evaluate" a polynomial p at infinity actually means to take the limit of p(x)/xdeg p as x goes to infinity. Consequently, p(∞) is always the value of its highest-degree coefficient (in the example above coefficient m2).
In our Toom-3 example, we will use the points 0, 1, −1, −2, and ∞. These choices simplify evaluation, producing the formulas:
and analogously for q. In our example, the values we get are:
p(0)
=
m0
=
56789012
=
56789012
p(1)
=
m0 + m1 + m2
=
56789012 + 78901234 + 123456
=
135813702
p(−1)
=
m0 − m1 + m2
=
56789012 − 78901234 + 123456
=
−21988766
p(−2)
=
m0 − 2m1 + 4m2
=
56789012 − 2 × 78901234 + 4 × 123456
=
−100519632
p(∞)
=
m2
=
123456
=
123456
q(0)
=
n0
=
54321098
=
54321098
q(1)
=
n0 + n1 + n2
=
54321098 + 43219876 + 98765
=
97639739
q(−1)
=
n0 − n1 + n2
=
54321098 − 43219876 + 98765
=
11199987
q(−2)
=
n0 − 2n1 + 4n2
=
54321098 − 2 × 43219876 + 4 × 98765
=
−31723594
q(∞)
=
n2
=
98765
=
98765.
As shown, these values may be negative.
For the purpose of later explanation, it will be useful to view this evaluation process as a matrix-vector multiplication, where each row of the matrix contains powers of one of the evaluation points, and the vector contains the coefficients of the polynomial:
The dimensions of the matrix are d by km for p and d by kn for q. The row for infinity is always all zero except for a 1 in the last column.
Faster evaluation
Multipoint evaluation can be obtained faster than with the above formulas. The number of elementary operations (addition/subtraction) can be reduced. The sequence given by Bodrato[6] for Toom-3, executed here over the first operand (polynomial p) of the running example is the following:
p0
←
m0 + m2
=
56789012 + 123456
=
56912468
p(0)
=
m0
=
56789012
=
56789012
p(1)
=
p0 + m1
=
56912468 + 78901234
=
135813702
p(−1)
=
p0 − m1
=
56912468 − 78901234
=
−21988766
p(−2)
=
(p(−1) + m2) × 2 − m0
=
(− 21988766 + 123456 ) × 2 − 56789012
=
− 100519632
p(∞)
=
m2
=
123456
=
123456.
This sequence requires five addition/subtraction operations, one less than the straightforward evaluation. Moreover the multiplication by 4 in the calculation of p(−2) was saved.
Pointwise multiplication
Unlike multiplying the polynomials p(·) and q(·), multiplying the evaluated values p(a) and q(a) just involves multiplying integers — a smaller instance of the original problem. We recursively invoke our multiplication procedure to multiply each pair of evaluated points. In practical implementations, as the operands become smaller, the algorithm will switch to schoolbook long multiplication. Letting r be the product polynomial, in our example we have:
r(0)
=
p(0)q(0)
=
56789012 × 54321098
=
3084841486175176
r(1)
=
p(1)q(1)
=
135813702 × 97639739
=
13260814415903778
r(−1)
=
p(−1)q(−1)
=
−21988766 × 11199987
=
−246273893346042
r(−2)
=
p(−2)q(−2)
=
−100519632 × −31723594
=
3188843994597408
r(∞)
=
p(∞)q(∞)
=
123456 × 98765
=
12193131840.
As shown, these can also be negative. For large enough numbers, this is the most expensive step, the only step that is not linear in the sizes of m and n.
Interpolation
This is the most complex step, the reverse of the evaluation step: given our d points on the product polynomial r(·), we need to determine its coefficients. In other words, we want to solve this matrix equation for the vector on the right-hand side:
This matrix is constructed the same way as the one in the evaluation step, except that it's d × d. We could solve this equation with a technique like Gaussian elimination, but this is too expensive. Instead, we use the fact that, provided the evaluation points were chosen suitably, this matrix is invertible (see also Vandermonde matrix), and so:
All that remains is to compute this matrix-vector product. Although the matrix contains fractions, the resulting coefficients will be integers — so this can all be done with integer arithmetic, just additions, subtractions, and multiplication/division by small constants. A difficult design challenge in Toom–Cook is to find an efficient sequence of operations to compute this product; one sequence given by Bodrato[6] for Toom-3 is the following, executed here over the running example:
If we were using different km, kn, or evaluation points, the matrix and so our interpolation strategy would change; but it does not depend on the inputs and so can be hard-coded for any given set of parameters.
Recomposition
Finally, we evaluate r(B) to obtain our final answer. This is straightforward since B is a power of b and so the multiplications by powers of B are all shifts by a whole number of digits in base b. In the running example b = 104 and B = b2 = 108.
3084
8414
8617
5176
6740
4157
2123
7444
3422
4165
8197
1852
13
1284
3338
7466
+
121
9313
1840
121
9326
3124
6761
1632
4937
6009
5208
5858
8617
5176
And this is in fact the product of 1234567890123456789012 and 987654321987654321098.
Interpolation matrices for various k
Here we give common interpolation matrices for a few different common small values of km and kn.
Toom-1
Applying formally the definition, we may consider Toom-1 (km = kn = 1). This does not yield a multiplication algorithm, but a recursive algorithm that never halts, as it trivially reduces each input instance to a recursive call with the same instance. The algorithm requires 1 evaluation point, whose value is irrelevant, as it is used only to "evaluate" constant polynomials. Thus, the interpolation matrix is the identity matrix:
Toom-1.5
Toom-1.5 (km = 2, kn = 1) is still degenerate: it recursively reduces one input by halving its size, but leaves the other input unchanged, hence we can make it into a multiplication algorithm only if we supply a 1 × n multiplication algorithm as a base case (whereas the true Toom–Cook algorithm reduces to constant-size base cases). It requires 2 evaluation points, here chosen to be 0 and ∞. Its interpolation matrix is then the identity matrix:
The algorithm is essentially equivalent to a form of long multiplication: both coefficients of one factor are multipled by the sole coefficient of the other factor.
Toom-2
Toom-2 (km = 2, kn = 2) requires 3 evaluation points, here chosen to be 0, 1, and ∞. It is the same as Karatsuba multiplication, with an interpolation matrix of:
Toom-2.5
Toom-2.5 (km = 3, kn = 2) requires 4 evaluation points, here chosen to be 0, 1, −1, and ∞. It then has an interpolation matrix of:
^Positive Results, chapter III of Stephen A. Cook: On the Minimum Computation Time of Functions.
^ abcMarco Bodrato. Towards Optimal Toom–Cook Multiplication for Univariate and Multivariate Polynomials in Characteristic 2 and 0. In WAIFI'07 proceedings, volume 4547 of LNCS, pages 116–133. June 21–22, 2007. author website
References
D. Knuth. The Art of Computer Programming, Volume 2. Third Edition, Addison-Wesley, 1997. Section 4.3.3.A: Digital methods, pg.294.
R. Crandall & C. Pomerance. Prime Numbers – A Computational Perspective. Second Edition, Springer, 2005. Section 9.5.1: Karatsuba and Toom–Cook methods, pg.473.
Perjalanan respons imun Respons imun adalah reaksi sistem imun suatu organisme terhadap keberadaan benda asing yang masuk ke dalam tubuh. Objek yang dianggap sebagai benda asing dapat berupa mikroorganisme seperti virus, bakteri, parasit, dan fungi, yang dapat menyebabkan masalah serius bagi kesehatan organisme inang jika tidak dibersihkan atau dieliminasi dari tubuh.[1] Ada dua aspek berbeda dari respons imun, yaitu sistem imun bawaan dan sistem imun adaptif, yang keduanya bekerja sa...
Keeshond Nama lain Dutch Barge DogSmiling DutchmanChien LoupGerman SpitzDeutscher WolfsspitzWolfsspitz Nama panggilan Kees Negara asal Belanda, Jerman Ciri-ciri Klasifikasi & standar FCI Grup 5 Seksi 4 #97 standar AKC Non-sporting standar ANKC Group 7 (Non-sporting) standar CKC Group 6 (Non-sporting) standar KC (UK) Utility standar NZKC Non-sporting standar UKC Northern Breeds standar Keeshond adalah ras anjing berukuran sedang dan termasuk golongan yang memiliki bulu panjang dan lebat, ...
نادي برشلونة لكرة اليد الاسم الكامل نادي برشلونة لكرة اليد الاسم القصير برشلونة لاسا التأسيس 29 نوفمبر 1942 (العمر 81 سنة) الملعب بالاو بلوغرانا السعة 7,500 الرئيس خوان لابورتا المدرب كارلوس انطونيو اورتيغا الدوري الدوري الإسباني لكرة اليد 2019–20 الأول الطقم الأساسي الطقم الإحت�...
Nama ini menggunakan cara penamaan Spanyol: nama keluarga pertama atau paternalnya adalah Alba dan nama keluarga kedua atau maternalnya adalah Ramos. Jordi alba Informasi pribadiNama lengkap Jordi Alba RamosTanggal lahir 21 Maret 1989 (umur 35)Tempat lahir L'Hospitalet de Llobregat, SpanyolTinggi 1,70 m[1]Posisi bermain BekInformasi klubKlub saat ini Inter MiamiNomor 18Karier junior1998–2005 Barcelona2005–2007 CornellàKarier senior*Tahun Tim Tampil (Gol)2007 Cornellà 2...
Untuk kegunaan lain, lihat Qatadah. Qatadah bin an-Nu'man (Arab: قتدة بن النعمان) adalah Sahabat Nabi Muhammad. Qatadah yang bernama asli Abdul Khatib merupakan penduduk Madinah, sehingga disebut golongan Anshar. Dalam Pertempuran Uhud, mata dia terluka hingga lepas dari rongga mata, kemudian Nabi Muhammad dengan didahului dengan doa mengembalikan bola mata Abu Qatadah seperti sediakala. Ia dijuluki sebagai Ksatria rasulallah (فارس رسول الله Faaris rasulullah).[1&...
Editora GloboIndustriPenerbitanGenreBerbagaiDidirikan1883PendiriL. P. de Barcellos & S. A. PintoKantorpusatPorto AlegreCabangBrasilWilayah operasi BrasilProdukBukuIndukGrupo GloboSitus webeditoraglobo.globo.com Editora Globo (Editor Globo) adalah sebuah penerbit Brasil dihormati, properti yang dimiliki oleh Fundação Roberto Marinho. Ini dimulai sebagai sebuah toko buku yang disebut Livraria do Globo, didirikan di Porto Alegre, pada bulan Desember 1883, oleh Laudelino Pinheiro de Ba...
Election 1890 Massachusetts gubernatorial election ← 1889 November 4, 1890 1891 → Nominee William Russell John Q. A. Brackett Party Democratic Republican Popular vote 140,507 131,454 Percentage 49.21% 46.04% County resultsRussell: 40–50% 50–60%Brackett: 40–50% 50–60% 60–70% Governor before election Joh...
Palestinian legislator, activist, and scholar (born 1946) Hanan AshrawiAshrawi at the Duisburg Audimax Campus, 29 November 2007BornHanan Daoud Mikhael Ashrawi (1946-10-08) 8 October 1946 (age 77)Nablus, Mandatory PalestineEducationAmerican University of Beirut (BA, MA)University of Virginia (Ph.D.)OccupationPoliticianSpouseEmile AshrawiChildrenAmalZeinaParent(s)Daoud Mikhail, Wadi'a Ass'ad Hanan Daoud Mikhael Ashrawi (Arabic: حنان داوود مخايل عشراوي; born 8 October 19...
Ini adalah nama Maluku, (Ambon), marganya adalah Sahertian Grace SahertianLahirGrace Carolline Sahertian18 Oktober 1986 (umur 37)Bandung, IndonesiaNama lainGrace SahertianAlmamaterInstitut Teknologi BandungPekerjaanpenyanyipenulis lagudosenKarier musikGenreJazzR&BsoulInstrumenVokalTahun aktif2006 – sekarangLabelDemajors Grace Carolline Sahertian atau yang dikenal dengan Grace Sahertian (lahir 18 Oktober 1986) merupakan seorang penyanyi dan dosen berkebangsaan Indonesia. Karier...
يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (مايو 2023) غوستا ساندبرغ معلومات شخصية الميلاد 6 أغسطس 1932 الوفاة 27 أبريل 2006 (73 سنة) مركز اللعب مهاجم الجنسية ...
كأس ألمانيا 1967–68 تفاصيل الموسم كأس ألمانيا النسخة 25 البلد ألمانيا المنظم الاتحاد الألماني لكرة القدم البطل نادي كولن مباريات ملعوبة 33 [1] عدد المشاركين 32 أهداف مسجلة 113 [1] كأس ألمانيا 1966–67 كأس ألمانيا 1968–69 تعديل مصدري - تعديل ك�...
Type of animal group activity This article is about predatory animals. For other uses, see Feeding frenzy (disambiguation). Common carp (Cyprinus carpio) competing for food at the pond of the Royal Palace Agdal of Marrakech in Morocco Herring gulls (Larus argentatus) and great black-backed gulls (Larus marinus) in Vestfjord, Norway eating fish remnants after fishers cleaned their catch. In ecology, a feeding frenzy is a type of animal group activity that occurs when predators are overwhelmed ...
American college football season 1901 Illinois Fighting Illini footballConferenceWestern ConferenceRecord8–2 (4–2 Western)Head coachEdgar Holt (1st season)CaptainJusta LindgrenHome stadiumIllinois FieldSeasons← 19001902 → 1901 Western Conference football standings vte Conf Overall Team W L T W L T Michigan + 4 – 0 – 0 11 – 0 – 0 Wisconsin + 2 – 0 – 0 9 – 0 – 0 Minnesota 3 – 1 ...
Optimization algorithm This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article possibly contains original research. Please improve it by verifying the claims made and adding inline citations. Statements consisting only of original research should be removed. (August 2018) (Learn how and when to remove this message) This article includes a list of general references, but it lacks suff...
Football program North Carolina A&T Aggies football2024 North Carolina A&T Aggies football team First season1901; 123 years ago (1901)Athletic directorEarl HiltonHead coachVincent Brown 1st season, 0–0 (–)StadiumTruist Stadium(capacity: 21,500)Field surfaceNatural grassLocationGreensboro, North CarolinaConferenceCAA FootballAll-time record466–423–46 (.523)Bowl record7–4 (.636)Claimed national titles7 (black college):1968, 1990, 1999, 2...
New York PalaceNew York-palotaDétail de la façade du Palais New York surmontée de l'emblème historique de la New York Life Insurance CompanyPrésentationNom complet Anantara New York Palace Budapest HotelDestination initiale Siège d'assuranceDestination actuelle HôtelStyle ÉclectismeArchitecte Alajos Hauszmann, Flóris Korb et Kálmán GierglConstruction 1894Ouverture 05.05.2006Reconstruction 2001-2006Rénovation 2001-2006Occupants New York Life (depuis le 23 octobre 1894), The Dedica ...
Sekolah TinggiMeteorologi, Klimatologi, dan Geofisika(STMKG) InformasiNama sebelumnyaAkademi Meteorologi dan Geofisika (AMG) (1955-1978), Balai Pendidikan dan Latihan Meteorologi dan Geofisika (BPLMG) (1978-2000), Akademi Meteorologi dan Geofisika (AMG) (2000-2014)JenisPerguruan Tinggi KedinasanDidirikan1955Lembaga indukBadan Meteorologi Klimatologi dan GeofisikaAfiliasi akademikInstitut Teknologi Bandung (1955-1960)DirekturDr. Suko Prayitno Adi, M.SiAlamatJalan Perhubungan I No. 5, Ke...