Post Reply 
Natural logarithm of 2 [HP-15C/HP-42S/Free42 & others]
11-12-2019, 08:30 PM
Post: #18
RE: Natural logarithm of 2 [HP-15C/HP-42S/Free42 & others]
(11-11-2019 06:14 PM)Gerson W. Barbosa Wrote:  Only 20 iterations here compared to 481 there, but AGM requires the evaluation of one square root per iteration.

We can lower loop count by 2, and extrapolate for the AGM.
(it probably make no difference to the timings though ...)

Loop 19 arithmetic mean: c = (a+b)/2
Loop 19 geometric mean: d = √(ab) = √(c^2 - ε^2), where ε = (a-b)/2

Taylor series for √(1+x) = 1 + x/2 - x^2/8 + x^3/16 - 5x^4/128 + ...

→ d = c * √(1 - (ε/c)^2) ≈ c - ε^2 / (2c)

Loop 20 aritmetic mean:

AGM ≈ ½(c + d) = c - ε^2 / (4c) = c - (a-b)^2 / (16*c)

Code:
FOR i = 1 TO 18
   LET c = a
   LET a = (a + b)/2
   LET b = SQR(b*c)
NEXT i
LET c = (a + b)/2
LET a = c - (a - b)^2 / (16*c)
LET g = d/(a*n)
...
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] - Albert Chan - 11-12-2019 08:30 PM



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