![]() |
![]() |
|
![]() |
![]() |
Encyclopedia :
S :
SH :
SHI :
Shifting nth-root algorithm |
|
|
Shifting nth-root algorithmThe shifting nth-root algorithm is an algorithm for extracting the nth root of a positive real number which proceeds iteratively by shifting in n digits of the radicand, starting with the most significant, and produces one digit of the root on each iteration, in a manner similar to long division.AlgorithmNotation Let B be the base of the number system you are using, and be n the degree of the root to be extracted. Let x be the radicand processed thus far, y be the root extracted thus far, and r be the remainder. Let α be the next n digits of the radicand, and β be the next digit of the root. Let x' be the new value of x for the next iteration, y' be the new value of y for the next iteration, and r' be the new value of r for the next iteration. These are all integers. Invariants At each iteration, the invariant will hold. The invariant will hold. Thus y is the largest integer less than the nth root of x, and r is the remainder. Initialization The initial values of x, y, and r should be 0. The value of α for the first iteration should be the most significant aligned block of n digits of the radicand. An aligned block of n digits means a block of digits aligned so that the decimal point falls between blocks. For example, in 123.4 the most significant aligned block of 2 digits is 01, the next most significant is 23, and the third most significant is 40. Main LoopOn each iteration we shift in n digits of the radicand, so we have and we produce 1 digit of the root, so we have . We want to choose β and r' so that the invariants described above hold. It turns out that there is always exactly one such choice, as will be proved below. The first invariant says that:
Now consider the second invariant. It says:
To summarize, on each iteration: Now, note that , so the condition
The final algorithm is: Paper and pencil nth rootsAs noted above, this algorithm is similar to long division, and it lends itself to the same notation: 1. 4 4 2 2 4
----------------------
3/ 3.000 000 000 000 000
/\\/ 1 = 300*(0^2)*1+30*0*(1^2)+1^3
-
2 000
1 744 = 300*(1^2)*4+30*1*(4^2)+4^3
-----
256 000
241 984 = 300*(14^2)*4+30*14*(4^2)+4^3
-------
14 016 000
12 458 888 = 300*(144^2)*2+30*144*(2^2)+2^3
----------
1 557 112 000
1 247 791 448 = 300*(1442^2)*2+30*1442*(2^2)+2^3
-------------
309 320 552 000
249 599 823 424 = 300*(14422^2)*4+30*14422*(4^2)+4^3
---------------
59 720 728 576
Note that after the first iteration or two the leading term dominates the Performance On each iteration, the most time consuming task is to select β. We know that there are B possible values, so we can find β using comparisons. Each comparison will require evaluating . In the kth iteration, y has k digits, and the polynomial can be evaluated with multiplications of up to digits and additions of up to digits, once we know the powers of y and β up through for y and n for β. β has a restricted range, so we can get the powers of β in constant time. We can get the powers of y with multiplications of up to digits. Assuming n-digit multiplication takes time and addition takes time , we take time The only internal storage needed is r, which is digits on the kth iteration. That this algorithm doesn't have bounded memory usage puts an upper bound on the number of digits which can be computed mentally, unlike the more elementary algorithms of arithmetic. Unfortunately, any bounded memory state machine with periodic inputs can only produce periodic outputs, so there are no such algorithms which can compute irrational numbers from rational ones, and thus no bounded memory root extraction algorithms. Note that increasing the base increases the time needed to pick β by a factor of , but decreases the number of digits needed to achieve a given precision by the same factor, and since the algorithm is cubic time in the number of digits, increasing the base gives an overall speedup of . When the base is larger than the radicand, the algorithm degenerates to binary search, so it follows that this algorithm is ExamplesSquare root of 2 in binary
1. 0 1 1 0 1 |
|
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License. |
|
| © 2008 Chamas Enterprises Inc. |