Working with logarithms base 10, 2 and e…

A couple of weeks ago I was talking about logarithms and their use. They may seem to be a bit esoteric and they can cause a bit of head-scratching: a logarithm (base a) of a number b is denoted by log_a b and can be better understood in terms of an exponential function since the result is the power to which the base has to be raised to produce the number, i.e. log_a b=x \leftrightarrow a^x=b.

Nonetheless, using the base e for logarithms is far more natural and as a form of abbreviation, it is denoted by \ln. In spite of this, a lot of us still learn about this function with the base 10 (or simply \log). Furthermore, the importance of the binary system makes it very useful to know about \log_2. With that in mind, I ended up mentioning an approximation in which all three logarithms appear:

\log_2 (x)\simeq \ln (x) + \log (x)

This can be very handy as you can approximate the value of the logarithm base 2 with a pedestrian calculator… of course you can still do this using the functions that some calculators offer you, but that is not the point of this post…

Anyway, note that it is an approximation and as such we could ask what is the relative error obtained when using it. Well, let us have a look: if the above expression holds, we can divide both sides by \log_2 (x) to obtain:

1\simeq \frac{\ln (x) + \log (x)}{\log_2 (x)}.

So the relative error can be expressed as:

\epsilon_r = 1 - \frac{\ln (x) + \log (x)}{\log_2 (x)}.

That is all fine and good, but what is the value of that error? Well, let us use some of the properties of logarithms. We know that log_a b=x \leftrightarrow a^x=b. Also, it is true that a^x=e^{x \ln(a)}, and thus we can say that e^{x \ln(a)}=b.  From this it follows that \ln(b) = x \ln(a). Nonetheless, we know that x=\log_a b. Rearranging the terms we end up with the fact that:

\log_a b = \frac{\ln b}{\ln a}.

Using that expression we can re-write the relative error as follows:

\epsilon_r = 1 - \frac{\ln (x) + \frac{\ln(x)}{\ln(10)}}{\frac{\ln (x)}{\ln (2)}}=1-(\ln 2)\left(1+\frac{1}{\ln 10} \right)\simeq 0.00582282...

Not too big an error! Let us have a look, \log_2 (10)=\ln 10 +1\simeq 3.30259..., whereas the actual value is closer to \log_2 (10)=3.32193...

Interesting, don’t you think…

Advertisements