|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Другие алгоритмы. Математика: Быстрое вычисление функций и констант.Точное вычисление обратного числа, квадратного корняПростейший классический алгоритм вычисления квадратного корня представлен здесь. Более серьезно вопрос рассмотрен в довольно простой и конкретной статье: High precision inverse and square rootsСтатья любезно предоставлена: Inverting a number of size n can be done in time O(n2) with the classical school division. This time cost can be reduced to O(nlog(n)) when using a fast multiplication, thanks to a Newton process. The same type of techniques apply to the n-th root computation of a number. For those operations we also describe some very efficient algorithms with high order of convergence (that is quartic, quintic, sextic, ... algorithms).
1 High precision inversionIn this section we want to compute the inverse 1/A of the number A to a great accuracy.
1.1 Newton's iterationStarting from an approximation x0 of 1/A, we apply Newton iteration [1] to the function f(x) = 1/x-A, which gives the approximating sequence
The iteration (*) have a nice feature : the only needed operations are the product by 2, the difference and the product of high precision numbers. The Newton convergence being quadratic, the precision needed to compute iteration (*) is not the full final precision but only with the precision wanted at step n. As an example, we compute the inverse of p, starting from the approximation x0 = 0.31831 (5 digits). The first three iterations become
The first 38 digits of x3 agree with those of 1/p. The cost of this process is of the order of the multiplication cost : since each iteration involves two multiplications on high precision numbers, to find 1/A we need to compute 2 multiplications of size n (last step), 2 multiplications of size n/2 (previous step), 2 multiplications of size n/4 , etc. Using for example an FFT multiplication, with cost O(nlogn), the final cost is of order
Note : a better iteration is obtained by writing (*) in the form
A division B/A is performed by multiplying B by the inverse of A.
1.2 A cubic iterationFrom the general Householder's iteration [2]
applied on f(x) = 1/x-A, we find
Starting with a good initial point x0, the convergence is cubical, that is, the number of good digits is multiplied by 3 at each step of the process. (The second form of this iteration is given in [3]). Since hn tends to zero, the new term hn2 can be computed at a low cost. As an example, we compute again, the inverse of p, starting from the approximation x0 = 0.31831 (5 digits). The two first iterations are
and x3has 174 good digits...
1.3 High order iterations
It's possible to find a quartic iteration, just apply twice Newton's iteration on f(x) = 1/x-A, we find
If we take a look at our example (inverse of p), starting as usual with x0 = 0.31831, we find that x1 has 26 good digits, x2 is 103 digits exact, x3 has 413 good digits ... The sequence of correct digits is then for this example
A quintic iteration founded by the application of a general quintic modified iteration (here, we omit the details of the demonstration which is deduced from the essay on Newton's methods) is given by
the rate of convergence is impressive, again on the previous example, x1 has 32 correct digits and x2 has 161 good digits, x3 has 806 good digits ...
The inverse of a number can be computed with an iteration at any desired order, it's possible to show that the general algorithm of order r is given by
where Pm(u) is a polynomial of degree m, given by
For example, for m = 3,m = 4 and m = 5 (respectively quartic, quintic, sextic iterations)
In practical cases the number hn tends to zero, therefore the evaluation of the powers hnk is more and more efficient when k increases. A careful implementation of those high order iterations is very efficient.
2 Square rootsIn this section we apply the same technique to compute square roots.
2.1 Newton's iterationUsing the function f(x) = x2-A, Newton iteration gives
This iteration has one disadvantage : one should compute the division A/xn. When one wants to compute 1/ЦA, a better iteration is obtained from the function f(x) = 1/x2-A, yielding the iteration
Note : as for the inverse, the best way to compute the iteration (**) is to write it in the form
2.2 A cubic iterationAgain, from the Householder's iteration, applied on the function f(x) = 1/x2-A, we find after some easy manipulations
This process converges cubically to the inverse of the square root of the number A (This form of the iteration is also given in [3]). Just like for the quadratic iteration, a more efficient way is to write it
2.3 High order iterationsJust like for the inverse, it's possible to find a quartic iteration, just apply twice Newton's iteration on f(x) = 1/x2-A :
This algorithm converges quartically to 1/ЦA. It is interesting to compare this result to the direct application of the general quartic modified iteration to our function (see the essay on Newton's methods)
This easier relation suggests that it may be more efficient to use the quartic iteration than twice the Newton iteration. The best form of this quartic algorithm is
As an application of the modified iterations, we provide the general expression of some high order iterations to compute square roots. The general pattern of a high order process is given by
with P(u) being a polynomial with rational coefficients.
The coefficient of the polynomials P(u) are in fact given by the series expansion of
this allow to define easily an algorithm at any order to compute square roots.
3 m-th rootsThe same techniques may be used in order to compute the m-th root (m being an integer) of the number A. Therefore, to find with a great accuracy the number A-1/m, use Newton's method on the function f(x) = 1/xm-A and this will produce the process
Householder's iteration also becomes
which converges cubically to A-1/m.
3.1 High order iterationThe general pattern for any order iteration is given by
and to find P(u) you need to compute the following series expansion
The truncated series at order k will provide an algorithm of order k+1. Observe that for the value m = 1, we retrieve the polynomials used to compute the inverse of a number and for m = 2, it gives back the algorithms to find square roots.
3.1.1 ExampleFor m = 4 the following algorithm converges quartically to A-1/4
and A1/4 is given by at the end of the process by
References
|