All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Eleven Square Roots in a Logarithm (Posted on 2006-09-05)
Presto the Mathematical Magician says, quite correctly, that ln(x), the natural logarithm (to the base e=2.718...) of x, is magically well-approximated by 2047(x1/2048 - 1). Hence logarithms can be calculated with fair accuracy using a primitive calculator that only does square roots along with basic arithmetic.

What is behind Presto's magic?

By the same token, log(x), the common (base 10) logarithm of x, may be approximated by the similar formula K(x1/2048 - 1) for a suitable value of K. For values of x between 1 and 10, explore the accuracy of this approximation, and that of similar formulas of the type K(x1/N-1) where N=2n, under the assumption that a 10-digit calculator is being used to compute the repeated square roots. What values for K and n would you recommend when a 10-digit calculator is being used?

 See The Solution Submitted by Richard Rating: 3.3333 (3 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 For the second part. | Comment 2 of 6 |

The following program simulates what would happen in a 10-digit calculator using various values of n to compute the natural log of, in this case, 2:

`   10   P=11:D=2048   15   X=2   20   while P<60   30   P=P+1:D=D*2   40   L=X   50   for I=1 to P   60      L=int(sqrt(L)*10000000000+0.5)/10000000000   70   next   80   L=(L-1)*(D-1):DPlace=int(log(L)/log(10)+0.5)   90   if DPlace>10 then   91     :L=int(L/10^(DPlace-10)+0.5)*10^(DPlace-10)   92     :else if DPlace=10 then   93        :L=int(L+0.5)   94        :else   95            :L=int(L*10^(10-DPlace)+0.5)/10^(10-DPlace)  100   print P,D,L,log(X)  110   wend`
`sqrts      n               approx          accurate       12      4096            0.6930365715    0.6931471805599453093 13      8192            0.6930921133    0.6931471805599453093 14      16384           0.6931204959    0.6931471805599453093 15      32768           0.6931334578    0.6931471805599453093 16      65536           0.693137481     0.6931471805599453093 17      131072          0.6931427693    0.6931471805599453093 18      262144          0.6931323063    0.6931471805599453093 19      524288          0.693107414     0.6931471805599453093 20      1048576         0.693108075     0.6931471805599453093 21      2097152         0.6931084055    0.6931471805599453093 22      4194304         0.6928988556    0.6931471805599453093 23      8388608         0.6928989382    0.6931471805599453093 24      16777216        0.6928989795    0.6931471805599453093 25      33554432        0.6912212786    0.6931471805599453093 26      67108864        0.6912212889    0.6931471805599453093 27      134217728       0.6845104077    0.6931471805599453093 28      268435456       0.6710886375    0.6931471805599453093 29      536870912       0.6442450932    0.6931471805599453093 30      1073741824      0.6442450938    0.6931471805599453093 31      2147483648      0.6442450941    0.6931471805599453093 32      4294967296      0.4294967294    0.6931471805599453093Illegal parameter in 80`

The best result is for n = 2^17, giving the closest match between the result determined by algorithm and the actual natural log of 2.  When other numbers than 2 are used, the result similarly favors n=2^17.

Offhand we would expect the best value of k to be (n-1)/ln(10), so as to convert natural logs to common logs.  However, we might worry that the approximation is consistently high or low, and therefore might benefit from a fudge factor.  The following program uses n=2^17=131072 and tests the common logs as calculated on a 10-digit calculator against more accurate common logs:

`   10   P=17:D=131072:Conv=1/log(10):Conv2=int(Conv*10000000000+0.5)/10000000000   15   X=1.25   20   while X<10   30   X=X+0.25   40   L=X   50   for I=1 to P   60      L=int(sqrt(L)*10000000000+0.5)/10000000000   70   next   80   L=(L-1)*(D-1)*Conv2:DPlace=int(log(L)/log(10)+0.5)   90   if DPlace>10 then   91     :L=int(L/10^(DPlace-10)+0.5)*10^(DPlace-10)   92     :else if DPlace=10 then   93        :L=int(L+0.5)   94        :else   95            :L=int(L*10^(10-DPlace)+0.5)/10^(10-DPlace)  100   print X,L,log(X)*Conv,L/(log(X)*Conv)  110   wend`

it results in

` x      approx log(x)     accurate log(x)         ratio1.5     0.1760868828    0.1760912590556812419   0.99997514779720066531.75    0.24303450769   0.24303804868629444     0.9999854302800998432.0     0.30102807988   0.3010299956639811951   0.99999363590336913232.25    0.3521794579    0.352182518111362484    0.99999131072326106642.5     0.3979401889    0.3979400086720376093   1.0000004529023432252.75    0.4393292018    0.4393326938302626501   0.9999920515128701093.0     0.477120655     0.4771212547196624371   0.99999874304559584223.25    0.5118837827    0.5118833609788743785   1.0000008238617579113.5     0.5440682799    0.5440680443502756352   1.00000043294166384273.75    0.5740270717    0.5740312677277188513   0.99999269024536683994.0     0.6020561598    0.6020599913279623903   0.99999363596980769434.25    0.6283889302    0.6283889300503115379   1.00000000023820989644.5     0.6532075378    0.6532125137753436792   0.99999238230248388854.75    0.6766941376    0.6766936096248665709   1.00000078022775140675.0     0.6989682687    0.6989700043360188046   0.99999751686623454835.25    0.720160855     0.7201593034059568774   1.00000215451502991685.5     0.740362974     0.7403626894942438453   1.00000038427889491425.75    0.759665703     0.7596678446896304882   0.99999718075518733676.0     0.7781544272    0.7781512503836436323   1.0000040825178328786.25    0.7958803777    0.7958800173440752189   1.00000045277669614516.5     0.8129118626    0.8129133566428555737   0.99999816211304271856.75    0.8293001129    0.8293037728310249212   0.99999558674258477417.0     0.8450963598    0.8450980400142568304   0.99999801181143811177.25    0.8603347572    0.8603380065709936966   0.9999962231460555287.5     0.8750608439    0.8750612633917000465   0.99999952061447855587.75    0.8893030816    0.8893017025063102889   1.0000015507602041298.0     0.903089932     0.9030899869919435856   0.999999939106905878.25    0.9164555491    0.9164539485499250875   1.0000017464599038998.5     0.9294227024    0.9294189257142927332   1.00000406349128770338.75    0.9420084688    0.9420080530223132449   1.00000044137381354759.0     0.9542470024    0.9542425094393248745   1.00000470840549512439.25    0.9661439955    0.9661417327390326062   1.00000234205902790139.5     0.9777279098    0.9777236052888477662   1.00000440258487055969.75    0.9890044378    0.9890046156985368159   0.999999820123653628810.0    1.000002041     0.9999999999999999998   1.000002041`

On a 10-digit calculator, the results seem accurate to only 5 significant digits. The ratios of the approximate log to the accurate log vary above and below 1.  So it would seem no fudge factor should be applied, and the value of k should be 131071/ln(10) or 56923.41204, when rounded to 10 significant figures.

Edited on September 5, 2006, 3:56 pm
 Posted by Charlie on 2006-09-05 15:55:38

 Search: Search body:
Forums (0)