My previous post about logarithms has generated far more discussion than I expected. One valuable comment cites Donald Knuth’s TAOCP. While looking up the reference, I stumbled on this curiosity:

lg *x* ≈ ln *x* + log_{10} *x*.

In words, log base 2 is approximately natural log plus log base 10. It’s a pleasant coincidence that there’s a simple relationship between the three most commonly used logarithms.

Knuth credits the approximation to R. W. Hamming and notes that the relative error is less than 1%. In fact, it’s easy to show that the relative error is exactly equal to

1 – (1 + 1/ln 10) ln 2 ≈ 0.0058

for all *x*.

**Related post**: The most interesting logs in the world

Maybe a mistake that causes confusion!?:

“lg” is the short form for “log base 1o” and not “base 2″.

But afaik “log base 2″ has the short form “ld x” or “lb x”!?

I’m quoting the formula as I found it in Knuth’s book. He uses lg for log base 2, which is fairly common in computer science, at least in the US.

More explicitly, log

_{2}x ≈ log_{e}x + log_{10}x.Oki, I didn’t know that with the exception in computer science – learned something new again.

Thanks so far and best regards from Germany

PS.: Great site with a lot of amazing math stuff. Please keep it up!

You can of course turn this around to approximate natural log, which is much harder to compute with the two logs every computer scientist already knows how to do in their head.

ln x ~ lg x – log x

e.g.

ln 1024 ~ lg 1024 – log 1024 ~10 – 3 ~ 7 — is close to the actual 6.931471805599453

(I seem to be having trouble posting this reply; I suspect my attempts to type inequalities are being misconstrued as really bad HTML…)

Even more cool (to me) is the fact that there are no other approximations of this kind — since 2 is the only integer for which ln(2) is less than 1, it’s the only one that can generate a difference of ~ 1 between 1/ln(r) and 1/ln(k) for integers r and k.

OK, I shouldn’t say “no other approximations of this kind” — you could also do (e.g.)

ln(x) ~ 10 * [log15(x) – log41(x)], which is only off by a factor of 0.000131 …

But that’s not nearly as cool.

Dave, does that integers come from a fractional approximation of e?

Kim, I’m using the fact that logA(x) – logB(x) = ln(x)[ 1/ln(A) – 1/ln(B)]. If you want to approximate ln(x) using a difference of logs of other bases, you want to find integers A, B, and N such that N*[1/ln(A) – 1/ln(B)] is as close to 1 as possible. In the example above, 1/ln(15) – 1/ln(41) is very close to 0.1. Those values of A and B were found empirically.