value ln

advertisement
Ln(x)
it
X MP  b IX 1  b j 1 IX ( j  1)
j 1
Error
The error in xMP is
b
 xMP  b X 11b  t  2
2
Expand
log x  log xMP 1   xMP / xMP 
 log xMP   xMP / xMP
In the case that x is close to 1, this is the dominant error.
Write log xMP as
t 1
log xMP  b LogX 11  b i LogX  i 
i2
The ratio of the first term left our of the series to the first is
 Rat  b it  2 b / 2
In the case that x is not close to 1, this is the dominant error, for x very close to 1 the
error in (1-x) dominates. The calculation speeds up as (1-x) 0, so it costs little to
calculate to the relative accuracy, but users need to bear in mind that if (1-x) < b--it-1, that
there is no accuracy in the stated log. The lack of accuracy is also true for double
precision logarithms. The problem can be avoided by always passing 1-x in the
argument. mpkroot2.for mplog2.for.
2k’th root of (x-1)+1
This starts by finding
1  c 
  x  1  1 (1)
Note that for k=0, c = x-1 and the expansion in (4) gives the answer.
log x  2k log 1  c  (2)
2
k
The left side of 1 is
(1+c)2  1 + 2c
(1+2c)21+22c
…
(1+2k-1c)  1+2kc
So that c  (x-1)/2k (3)
This is found much more accurately in KthRoot2.doc - mpln.for.

 c 
i 1
i
log 1  c   
i
(4)
Estimation of M and k
If the sum in (4) is truncated at i=M, the error is
 Series 

 c 
i  M 1
i

i

 c 
M 1
M 1

  c 
i
 c 
 M  1 1   c  
M 1

i 0
(5)
For c << 1, the c in the denominator can be dropped so that, the value of log(x) is
Ln  x   2
M
k

 c 
i 1
i
 c 
 M  1
M 1
i
2
k
(6)
For small c, the natural log is approximately 2kc with relative truncation error
 c 
 M  1
M
 rel ,T 
(7)
The absolute error in the multi precision value of the natural log is - MPDetail.doc
1
  b IC 1it
(8)
2
IC(1)=log(c)/14-1
The first term in this expansion is approximately c so the relative error is ||/c, so that
equating this to the truncation error gives
M 1
c
1 ln( c ) / 14*ln(2) it
b

2
 M  1
(9)
Or
 log 2   log(c) / 14*log(2)   it  log b   M  1 log c  log  M  1
Note that for our b = 16384 = 214, this becomes
 log 2   log(c) / 14*log(2)   it  log b   M  1 log c  log  M  1
log c(1  M  1)  it log b   log  2 /  M  1 
(10)
(11)
M   it log b  log 2  log( M  1)  / log c
To a reasonable approximation, the last two terms on the last line of (11) can be dropped
and 2k c = x, so that
M  it log b /  k log 2  log x 
For x such that k log2 >> log x, this becomes
M  14it / k
The number of multiplications required to find log(x) are approximately1 7 k + M or
ops  M  98it / M
This is a minimum with
M  10 it
(12)
k  1.4 it
The total number of multilications is  20 (it)1/2
The 7 is approximately the number of iterations required to solve (1+c) M = 1+x where M=2k by Newton’s
method.
1
M and k are found semi-iteratively. Assume that M is given by the first line in
(12). Then use the approximation in (3), c=(x-1)/2k, to find k from the last line of (11)
M   it log b  log 2  log( M  1)  / log   x  1 / 2 k 
log   x  1 / 2k    it log b  log 2  log( M  1)  / M
 k log 2  log( x  1)   it log b  log 2  log( M  1)  / M
k   it log b / log 2  1  log( M  1) / log 2  / M  log  x  1 / log 2
k  14it / M  1/ log 2  log( M  1) / log 2  log( x  1) / log 2
Ignoring the value of x, it is shown below (12) that the log series should contain
M = 10 it terms. This implies that
c M  Mb  it 1
  x  1 2 
 k M 1
 Mb
 M  1 log( x  1)  k log 2   log M  log b
Then
Download