Introduction

advertisement
Introduction
For large enough M, the Mth root of any x is 1, but 1 to any power is not x. This is
similar to the digit loss discussed in ExpLn.doc. The extra digits in the root are kept by
solving directly for the part that adds to 1. The fact that x itself may be very close to 1 is
accounted for by solving for x + 1. The equation is
1  c 
M DP
 1  x 
M DP ln 1  c   ln 1  x 
1  c  exp  ln 1  x  / M DP 
(1)
c1  exp  ln 1  x  / M DP   1
An equation for the M=2k root of 1+x is


k
2 2
M
f  c    1  c    x  1  1  c   x  1


The first derivative with respect to c is
M 1
f '  c   M 1  c 
So that
f  ci 
1  ci  f  ci 
ci 1  ci 
 ci 
M 1
M
M 1  ci 
M 1  ci 
(2)
(3)
(4)
1
1
ci  1  ci  1  x  f  ci 
M
If c is approximately correct on the first step, the f will be down by a large factor. This
means that the evaluation of f is the only part that requires multiple precision in the
second term. Then the addition of ci and its correction requires multiple precision. This
gains 16 digits per step for a cost of k multiplications per step. If the term added were
multiple precsion the error would square on each step, but there would be two extra
multiplications per step plus an inversion requiring approximately 25 multiplications. At
it = 31, the method requires 2 extra steps of k multiplications. For k = 20 this is 40 extra
multiplications while saving 5 multiplications per step + ~ 25 to invert 1+x.
The 1 dominates the c in (4), but the small value of f(c) will still enable the
Newton’s method to work.
Squaring
2
1  c   1  2c  c 2
At each step
c  2c  c  c
mpkroot2.for
A method without the 1’s is in KthRoot.doc
mpkroot.for tmpkroot.wpj
To a fair approximation x=c * 2**k or
log x / c  k log 2
k  log x / c / log(2)
Approximate size of c
1  c 
2k
 1 x
log(1  c)  c
2 k c  log(1  x)
If we want c = 0.1, this yields
k log 2  log c  log(log(1  x))
k  log(10 log(1  x)) / log 2
2k c  x
Or
c  x / 2k
In taking a logarithm we need to have c > 0 and
cn
I
 cb t
n
So that
 x2 
k
n 1
 nb
 It
Or
 n  1 log x  k log 2   log n  I t log b
k   n  1 log 2    n  1 log x  log n  I t log b
k
I log b
log x
log n

 t
log 2  n  1 log 2 n  1 log 2
k  14 I t / n
The number of operations is n+(1/16)(4.2It)k or approximately
4I 2
4.2 *14 2
ops(n)  n 
It / n  n  t
16
n
Minimizing with respect to n yields
0  1  4 It 2 / n2
n  2It
k 7
For It = 31, n is about 62 and k about 7. The total number of operations are 8 * 7 + 62 =
120
Log limit

 c 
i 1
i
log 1  c   
i
If this sum is truncated at i=M, the error is
i
M 1
M 1

 c   c  
 c 
i
Err  

  c    M  1 1   c   (5)
i
M  1 i 0
i  M 1
As a practical matter for small c, the denominator is 1. Thus the relative error is
cM
R 
 b it 1
(6)
M 1
M  log | c |   it  1 log b  log( M  1)
M1=-(it+1)logb/log|c|
M2=M1+log(M1+1)/log|c|
This is coded into mpln.for
c is very approximately given by x/2k so that
x/ 2 

k M
R
 b it 1
(7)
M 1
M log x  Mk log 2    it  1 log b  log( M  1)
Taking the dominant part of (7)
 it  1 log b / log 2
(8)
M
k
The number of multiplications are approximately 5k + M
Minimizing with respect to k yields
5  14  it  1 / k 2  0
k  14  it  1 / 5
For an it of 31, this is ~5. There is an advantage to 7 and in fact, I like 14. - Note that
214 is well within the range of the integers. In this case M is
 it  114  32 so that the total number of multiplications for a log is ~ 102. With a
M
14
k of 7, this drops to ~ 35+32*14/7 = 35 + 64 = 99.
mplog2.wpj
With x = 1e15 5 * 14 + 51
1e208 6 * 14 + 87
1e-208 saturated at 100 and 101 – problem with error. Answer seemed correct.
1
5*14 + 33
Download