3 ms·
I can't really follow the algorithm Euler used... I've come up with one that is likely equivalent, and easy to do with a 4 function calculator. For log10....
by mikewarot 3y ago
I can't really follow the algorithm Euler used... I've come up with one that is likely equivalent, and easy to do with a 4 function calculator.
For log10....
Scale X to be between 1 and 10
For each time you divide by 10, add 1.0 to the log
each time you have to multiply by 10, subtract 1.0 from the log
Add the decimal point to the log
Loop:
Take X' (the scaled value) to the 10th power
square it (store to memory, if you have it, this is x'^2)
square that (which is x'^4)
square that (now x'^8)
multiply that by x'^2
you now have X'^10
the number now has to be divided N times to be between 1.0 and 10, and N to the log
if you need more digits, goto Loop
Here it is, taking log10(3)
3 0.
59,049 0.4
51,537,752.07320113 0.47
13,220,708.19480807 0.477
16.31350185342626 0.4771
133.4971414230401 0.47712
17.97710116675744 0.477121
352.530441082974 0.4771212
296,460.0951963823 0.47712125
52,439.97032955288 0.477121254
15,726,220.94397862 0.4771212547
- nickcw 3y agoVery nice algorithm - no square roots and 1 digit per iteration guaranteed. I converted this into python to understand it better def log10(x): """ Find 10 decimal places of log10(x) using calculator functions only """ assert x > 0, "can't log <= 0" log = 0 while x >= 10: log += 1 x /= 10 while x < 1: log -= 1 x *= 10 # x is now [1, 10) decimal = 0.1 for i in range(10): x10 = x**10 # or calculate as above so as not to use power function while x10 >= 10: log += decimal x10 /= 10 x = x10 decimal /= 10 print(f"log10(x) = {log:.10f}, x = {x:.10f}") log10(3) Which gives log10(x) = 0.4000000000, x = 5.9049000000 log10(x) = 0.4700000000, x = 5.1537752073 log10(x) = 0.4770000000, x = 1.3220708195 log10(x) = 0.4771000000, x = 1.6313501853 log10(x) = 0.4771200000, x = 1.3349714142 log10(x) = 0.4771210000, x = 1.7977101167 log10(x) = 0.4771212000, x = 3.5253044107 log10(x) = 0.4771212500, x = 2.9646009506 log10(x) = 0.4771212540, x = 5.2439970092 log10(x) = 0.4771212547, x = 1.5726220230
- physPop 3y agoyour print should be x', not x!
- foldr 3y agoI think this is quite similar to Clay S Turner's algorithm for calculating binary logarithms: http://www.claysturner.com/dsp/BinaryLogarithm.pdf http://www.claysturner.com/dsp/BinaryLogarithm.pdf
- mikewarot 3y agoI didn't follow the proof, but yes it is the same algorithm. It'll work for any integer base >= 2.
- foldr 3y agoYeah I remember that some of the notation in the proof confused me a bit too. I proved it to my satisfaction using a slightly different approach, but I don't remember it well enough to write it out. (I'm sure it's trivial for anyone with math chops, but I don't got them.)
- Someone 3y agoI’m not sure that’s efficient. The number of digits in that tenth power grows very rapidly (59049^¹⁰ already has 47 digits; (59049¹⁰)¹⁰ around 477) and there’s the risk that rounding introduces errors (did you really do that with “a 4 function calculator”?) On the other hand, (hand-waving) it takes many generated digits before the “far away” get shifted left of the decimal point, so numerical analysis probably can show you don’t need them all to reach a target number of digits.
- nickcw 3y agoThe intermediate numbers never get bigger than 10^10 - if you look at the python program I posted you might find that easier to see.
- Someone 3y agoThat’s true, but the number of digits to the right of the decimal point grows rapidly.
- mikewarot 3y ago>did you really do that with “a 4 function calculator”? I have in the past, this time I used the 4 function calculator mode of Windows 10's calculator. x^2, MS, x^2, x^2 * MR = on the loops, then divide by 1+n zeros, repeat. I used NotePad++ to record the data as I went. Doing it for a binary logarithm would be a lot easer, because then it's square and optionally divide by 2.
- Someone 3y ago> this time I used the 4 function calculator mode of Windows 10's calculator AFAIK, that calculator has “Infinite precision for basic arithmetic operations (addition, subtraction, multiplication, division) so that calculations never lose precision” (https://github.com/microsoft/calculator https://github.com/microsoft/calculator)