Post Reply 
Estimate logarithm quickly
04-27-2022, 10:02 PM
Post: #17
RE: Estimate logarithm quickly
(10-22-2021 02:15 PM)Albert Chan Wrote:  ln(n) ≈ g - g/(2.7 + 24/g^2)       , where g = (n-1)/√n

Another way to derive above ln(n) approximation, via asinh
see Arc SOHCAHTOA method, for hyperbolics

log(n)
= 2*atanh((n-1) / (n+1))                // assumed n ≥ 1, for atanhq
= 2*atanhq((n-1)² / (n+1)²)           // TOA, O=(n-1)², A = (n+1)²
= 2*asinhq((n-1)² / (4n))               // SOH, H = A-O = 4n
= 2*asinh(g/2)                              // remove n ≥ 1 assumption.

= g * (1 - g²/24 * (1 - 9/80*g² * (1 - 25/168*g² * ( ...
≈ g * (1 - g²/24 / (1 + 9/80*g²))
= g - g/(2.7 + 24/g²)

Or, we could simply use pade command.

CAS> p := pade(2*asinh(g/2),g,5,4)      → (17*g^3+240*g)/(27*g^2+240)
CAS> partfrac(g/(g-p))                          → 27/10+24/g^2

With 3 asinh taylor terms to estimate log(n), formula always over-estimate, in absolute value.

lua> function fastlog(x) x=(x-1)/sqrt(x); return x - x/(2.7+24/(x*x)) end
lua> function ratio(x) return fastlog(x) / log(x) end
lua> ratio(sqrt(2.0))
1.0000002929130414
lua> ratio(sqrt(0.5))
1.0000002929130412

lua> x = 0.1
lua> fastlog((1+x)/(1-x))/2 -- atanh(x) upper-bound estimate
0.10033534884362541
lua> atanh(x)
0.10033534773107558
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Estimate logarithm quickly - Albert Chan - 08-21-2021, 03:39 PM
RE: Estimate logarithm quickly - trojdor - 08-21-2021, 06:31 PM
RE: Estimate logarithm quickly - EdS2 - 08-23-2021, 06:44 AM
RE: Estimate logarithm quickly - Albert Chan - 04-27-2022 10:02 PM
RE: Estimate logarithm quickly - klesl - 04-26-2022, 05:52 PM
RE: Estimate logarithm quickly - vaklaff - 04-28-2022, 04:33 PM
RE: Estimate logarithm quickly - klesl - 04-28-2022, 05:02 PM



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