[last updated: 2021-08-01]
go to: ...
-----
- The Karatsuba algorithm is used to multiply very large integers. It is generally faster when the operands are larger than 500 digits (very approximate)
- given two large numbers, x & y
set n = number of digits of the larger one
set m = (n // 2) + 1
- Then:
x = x1 x 10m + x0
y = y1 x 10m + y0
- Calculate interim quantities:
z0 = x0 y0
z1 = x1 y0 + x0 y1
z2 = x1 y1
- Then:
x y = z2 * 102m + z1 * 10m + z0
-------------------------------------------------------------------------
- For example:
- In the python program I wrote to implement this algorithm, it performed 20x slower than standard multiplication for operands up to about 30-digits.
.
.
.
eof