Main Loop
On 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:
or
So, pick the largest integer β such that
and let
Such a β always exists, since if then the condition is, but, so this is always true. Also, β must be less than B, since if then we would have
but the second invariant implies that
and since and are both multiples of the difference between them must be at least, and then we have
but by definition of α, so this can't be true, and is a monotonically increasing function of β, so it can't be true for larger β either, so we conclude that there exists an integer γ with such that an integer r' with exists such that the first invariant holds if and only if .
Now consider the second invariant. It says:
or
Now, if β is not the largest admissible β for the first invariant as described above, then is also admissible, and we have
This violates the second invariant, so to satisfy both invariants we must pick the largest β allowed by the first invariant. Thus we have proven the existence and uniqueness of β and r'.
To summarize, on each iteration:
- Let α be the next aligned block of digits from the radicand
- Let
- Let β be the largest β such that
- Let
- Let
Now, note that, so the condition
is equivalent to
and
is equivalent to
Thus, we don't actually need, and since and, or, or, so by using instead of we save time and space by a factor of 1/n. Also, the we subtract in the new test cancels the one in, so now the highest power of y we have to evaluate is rather than .
Read more about this topic: Shifting nth Root Algorithm, Algorithm
Famous quotes containing the word main:
“Mans main task in life is to give birth to himself, to become what he potentially is. The most important product of his effort is his own personality.”
—Erich Fromm (19001980)