Another Method for Extracting Cube Roots Brian

Another Method for Extracting Cube Roots
Brian J. Shelburne
Dept of Math and Computer Science
Wittenberg University
Probably the easiest way (?) to compute the cube root of a is to use the iteration formula
2 x3 + a
xn +1 = n 2 . However, while checking out an article in the December 1958 issue of the
3 xn
Communications of the ACM I ran across a paper that demonstrated another method for
extracting cube roots. The method was useful (?) since it was done using fixed point arithmetic,
it required no division and could be modified so only minimal multiplication was needed (both
“expensive” operations for computers in the 1950’s). It’s similar to the method of extracting a
square root by hand.
The Theory
Let X be the number whose cube root we want
Represent
3
X by the sum
∞
i =1
d i 10n −i where d i is a digit between 0 and 9 and n is the number of
digits above the decimal point. Letting ai = d i10n −i we can write X = (a1 + a2 + ... + an + ...)3 .
For positive integer k, (a1 + a2 + ... + ak )3 approximates X and so (a1 + a2 + ... + ak ) approximates
3
X.
We will show how to compute each term ak or more exactly each digit d k in an iterative fashion
such that at each stage the error X − (a1 + a2 + ... + ak −1 + ak )3 decreases.
This is done by expanding (a1 + a2 + ... + ak −1 + ak )3 in terms of (a1 + a2 + ... + ak −1 ) and ak ; that is
(a1 + a2 + ... + ak −1 + ak )3 = (a1 + a2 + ... + ak −1 )3 + 3 ⋅ (a1 + a2 + ... + ak −1 ) 2 ⋅ ak + 3 ⋅ (a1 + a2 + ... + ak −1 ) ⋅ ak2 + ak3
Then if X k −1 = X − (a1 + a2 + ...ak −1 )3 is the error at the k-1st stage we choose the largest ak so that
X − (a1 + a2 + ... + ak −1 )3 − ( 3 ⋅ (a1 + a2 + ... + ak −1 ) 2 ⋅ ak + 3 ⋅ (a1 + a2 + ... + ak −1 ) ⋅ ak2 + ak3 ) is non-negative or
equivalently X k = X k −1 − ( 3 ⋅ (a1 + a2 + ...ak −1 )2 ⋅ ak + 3 ⋅ (a1 + a2 + ...ak −1 ) ⋅ ak2 + ak3 ) is non-negative.
An Example - Find
Stage 1:
3
79201
Begin by finding the largest value of a1 such that a13 is less than or equal to X, or
equivalently finding the largest value of a1 such that the error X 1 = X − a13 is non-negative.
We partition the digits into groups of three (i.e. 79 201.000) and start with the left-most group. In
this case the largest integer (digit) whose cube is less than or equal to 79 is 4.
43
4
+----------| 79 201 000
-64
--15 201 = X1
We then bring down the next group of three digits. This has the effect of scaling the answer by
10.
Given the value of a1 = 4 ×10 (because of scaling) find the largest value of a2
Stage 2
such that the error X 2 = X 1 − 3 ⋅ a12 a2 + 3 ⋅ a1a22 + a23 is non-negative. Note
that X 2 = X − (a1 + a2 )3
Find the largest digit d 2 such that 3 ⋅1600 ⋅ d 2 + 3 ⋅ 40 ⋅ d 22 + d 23 = 4800d 2 + 120 ⋅ d 22 + d 23 is less than
or equal to 15210
43
3×1600× d 2 + 3×40× d 22 + d 23
4800× d 2 + 120× d 22 + d 23
(4800
+
4
d2
+----------| 79 201 000
-64
------15 201
120× d 2 + d 22 ) d 2
d 2 = 3 is too big (15507) so we use d 2 = 2
43
3×1600× d 2 + 3×40× d 22 + d 23
120×22+ 23
4800×2+
4
2.
+----------| 79 201.000
-64
--15 201
-10 088
---------5 113 000
Stage 3 -
In general given (a 1 + a2 + ... + ak −1 ) find the largest value of ak such that the error
X k = X k −1 − 3 ⋅ (a1 + a2 + ... + ak −1 ) 2 ak + 3 ⋅ (a1 + a2 + ... + ak −1 )ak2 + ak3 is non-negative. Note that
X k = X − (a1 + a2 + ... + ak )3
Find the largest digit d3 such that 3 ⋅176400 ⋅ d3 + 3 ⋅ 420 ⋅ d 32 + d33 = 529200 ⋅ d 3 + 1260 ⋅ d32 + d 33 is
less than or equal to 5113000. Because of scaling (a1 + a2 ) = 420
43
3×1600×2+ 3×40×22 + 23
4800×2+ 120×22 + 23
3×176400× d3 +3×420× d 32 + d 33
4
2 d3
+----------| 79 201 000
-64
--15 201
-10 088
---------5 113 000
= 529200× d3 + 1260× d 32 + d 33
We estimate d3 to be 9 which works
43
3×1600×2+ 3×40×22 + 23
4800×2+ 120×22 + 23
3×176400× d3 +3×420× d 32 + d 33
= 529200×9+ 1260×92 +93
4
2. 9
+----------| 79 201.000
-64
--15 201
-10 088
---------5 113 000
-4 865 589
----------247 411 000
Reducing Computational Complexity - I
We can simplify the squaring of (a 1 + a2 + ... + ak −1 ) 2 at the kth step by using previously computed
values. Let uk be the value of (a1 + a2 + ... + ak −1 ) and vk = uk2 be the value of
(a 1 + a2 + ... + ak −1 ) 2 at the kth step. It’s not difficult to derive a pair of interlocking formulas to
compute uk and vk .
u k=
0 if k = 0
(uk −1 + d k −1 ) ⋅10 if k > 0
and
vk =
0 if k = 0
(vk −1 + 2 ⋅ u k −1⋅d k −1 + d k2−1 ) ⋅100 if k > 0
Given uk −1 and vk −1 the computational cost of computing vk = (a 1 + a2 + ... + ak −1 )2 is reduced to an
addition followed by a multiplication by 10 to obtain uk plus two additions and three simple
multiplications (by 2, by the digit d k and by 100) to obtain vk (assuming a simple table lookup
to find the square of the digit d k ).
43
3×1600×2+ 3×40×22 + 23
4800×2+ 120×22 + 23
3×176400× d3 +3×420× d 32 + d 33
= 529200×9+ 1260×92 +93
4
2. 9
+----------| 79 201.000
-64
--15 201
-10 088
---------5 113 000
-4 865 589
----------247 411 000
For example (1600 + 2×40×2 + 22) × 100 = 176400
Stage 4
43
3×1600×2+ 3×40×22 + 23
4800×2+ 120×22 + 23
3×176400× d3 +3×420× d 32 + d 33
= 529200×9+ 1260×92 +93
3×18404100× d 4 +3×4290× d 42 + d 43
55212300× d 4 +12870× d 42 + d 43
4
2. 9
4
+--------------| 79 201.000 000
-64
--15 201
-10 088
---------5 113 000
-4 865 589
----------247 411 000
-221 055 184
----------26 355 816
u4 = (u3+d3)×10 = 4290
v4 = (v3 + 2×u3×d3 + d32)×100 = 18 404 100
Reducing Computational Complexity - II
The difference between adjacent terms of the form 3 ⋅ vk ⋅ m + 3 ⋅ uk ⋅ m 2 + m3 for m = 1, 2, etc can
be written as
3 ⋅ vk ⋅ m + 3 ⋅ uk ⋅ m 2 + m3 − ( 3 ⋅ vk ⋅ (m − 1) + 3 ⋅ uk ⋅ (m − 1)2 + (m − 1)3 ) = 3 ⋅ vk + 3 ⋅ uk ⋅ (2m − 1) + ∆m3
Let ∆m3 = m3 − (m − 1)3 denote the difference between adjacent cubes
The computational cost of estimating the largest d k so that X k −1 − 3 ⋅ vk ⋅ d k + 3 ⋅ uk ⋅ d k2 + d k3 is nonnegative can be simplified by subtracting 3 ⋅ vk + 3 ⋅ uk ⋅1 + 1 from X k −1 and continuing to subtract
expressions of the form 3 ⋅ vk + 3 ⋅ uk ⋅ (2m − 1) + ∆m3 until a negative value is obtained (then
restoring the previous value). The difference between adjacent cubes (i.e. 1, 7, 19, 37, 61, 91,
127, 169, 217, 271) is easily found by table look up.
For example, the calculation for k = 4 above (where 3 ⋅ v4 = 55, 212,300 and
3 ⋅ u4 = 12,870 ) can be redone using the following table.
d4
1
2
3
4
5
6
55212300+12870×(2k-1)+ d43
55212300+12870×1+1
55212300+12870×3+7
55212300+12870×5+19
55212300+12870×7+37
55212300+12870×9+61
55212399+12870×11+127
X3×1000 = 247411000
192185829
136934912
816582434
26355816
-28972375
…
Computationally for each row you need only one multiplication (by an odd integer), two
additions and one table look up for the first difference of the cube.
References
Sugai, Iwao; “Extraction of Roots by Repeated Subtractions for Digital Computers”; Comm. of
A.C.M.; Vol 1 No 12; December 1958; pp 6 – 8.
Asimov, Isaac; "The Feeling of Power"; The Mathematical Magpie, Clifton Fadiman, ed.; Simon
and Schuster; New York; 1962.
My Home Page: http://www4.wittenberg.edu/academics/mathcomp/shelburn.shtml