Post Reply 
Natural logarithm of 2 [HP-15C/HP-42S/Free42 & others]
11-09-2019, 05:27 PM
Post: #16
RE: Natural logarithm of 2 [HP-15C/HP-42S/Free42 & others]
(11-08-2019 03:18 PM)Albert Chan Wrote:  Using Pi and AGM to get log(2): see http://rnc7.loria.fr/brent_invited.pdf, page 32

\(\large log(2^n) = \frac{\pi/2}{AGM(1, \frac{4}{2^n})} \left(1 + O(\frac{1}{2^{2n}}) \right)\)

Big enough n so that error term may be ignored. Assume O(1/4^n) = 1/4^n :

1/4^n < 1e-12
n ≥ 12 / log10(4) ≥ 19.93

Casio FX-115MS, with n = 20:

A=1
B=2^-18
C=A+B : B=√AB : A=C/2 : A-B

====     → 0.4980487824
====     → 0.2197274566
====     → 0.0525527223
====     → 0.0030466068
====     → 0.0000102395
====     → 0.0000000001

Convergence close to quadratic. With final A,B, we have

log(2) ≈ pi/(n(A+B)) = 0.693147180558, under-estimated 2e-12

Update: More precise calculations shows that n=20 over-estimated log(2) by 2e-12
Below suggested relative error term O(1/4^n) ≈ 1/4^(n-1)

python> from gmpy2 import *
python> f = lambda n: const_pi() / (2 * n * agm(1, 4/2**n))
python> for n in range(20, 25): print n, "%.15g" % f(n)
...
20 0.693147180562285
21 0.693147180560532
22 0.693147180560093
23 0.693147180559982
24 0.693147180559955


Interesting, even though it requires \(\pi\).

Because I’m lazy I’ll take the wp34s for this one:


001 LBL A
002 # π
003 RCL Y
004 # 002
005 -
006 # 1/2
007 STO+ X
008 DSE Y
009 BACK 002
010 STO* Z
011 STO+ X
012 INC Y
013 AGM
014 RCL* T
015 /
016 END

20 A -> 0.6931471805622850
2 LN - -> 2.33975581274e-12

40 A 2 LN - -> 2.210713576e-24

62 A 2 LN - -> 0



2^x would’ve saved a few steps, but I want to avoid the use of logarithms in the program.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Natural logarithm of 2 [HP-15C/HP-42S/Free42 & others] - Gerson W. Barbosa - 11-09-2019 05:27 PM



User(s) browsing this thread: 1 Guest(s)