# How to calculate non-exact Log problems like: Base 2 Log 10 = 3.32192809489?

Update, trying to explain this in a better way:

I mean how to find the result without a calculator.

Base 2 Log 16 = 4: simple to figure out: 2 . 2 . 2 . 2

Base 2 Log 18 = ??

• Manually calculating it will be rather difficult unless you have a log table handy. – user296602 May 23 '18 at 17:23
• Concerning the $\log_{10}(x)$ evaluation see here (and note that $\log_a(x)=\dfrac {\log_{10}(x)}{\log_{10}(a)}$). Concerning the use of tables or by hand see here. Other neat and powerful methods are proposed in this thread. – Raymond Manzoni Jul 27 '18 at 19:02
• What do you mean by "Base 2 Log 18 = ??" The base 2 logarithm of any positive integer is a non-negative real real number. What result did you expect? In this case, since you already know Base 2 Log 16 = 4, then the result is greater than 4 and less than 5. How much more precision do you want? – Somos Jul 28 '18 at 17:48

First, you extract out the integer part of the answer; that is, for $\log_2 10$, we have $$\log_2 10 = 3+\log_2 \frac{10}8 = 3+\log_2 \left(1+\frac14\right)$$ Now, we need a good approximation for the remaining logarithm. A straight-forward method to calculate this is to use the Taylor expansion of $\log(1+x)$, but we can do somewhat better using a "Pade Approximant". A neat approximant that's fairly accurate is $$\log(1+x) \approx \frac{x(6+x)}{6+4x}$$ We still have to adjust for base, because the logarithm I've just approximated is the natural logarithm, base $e$... so we end up with $$\log_2(1+x)\approx\frac{x(6+x)}{(6+4x)\log(2)}$$ where $\log(2)\approx 0.693$ So we work out that \begin{align} \log_2 10 &\approx 3+\frac{\frac14(6+\frac14)}{(6+4\frac14)\times 0.693}\\ &=3+\frac{\frac{25}{16}}{7\times 0.693}\\ &=3+\frac{25}{77.616}\\ &\approx 3+0.322098536 \approx 3.3221 \end{align} As you can see, it's quite close to the right answer.

Let’s calculate by hand $L = \log_2(18)$.

Be $L_0 = c_0 \in \mathbb{N}$ the biggest integer that won’t exceed $L$ our first guess. It is obvious that: $$c_0 = \lfloor \log_2(18) \rfloor = 4$$

Let $L_1 = L_0 + 2^{-1}c_{-1}$ where $c_{-1} \in \mathbb{N}$ our second guess: we’re splitting the interval of interest $[L_0, L_0 + 2^0)$ in half and trying to guess where the answer lies (we know for sure that it must be between $4$ and $5$). The previous relation implies that: $$c_{-1} = 2(L_1 - L_0)$$ Recalling that any $c_{i}$ should be an integer we should not expect that letting $L_1 = L$ will be enough. If we are lucky then $c_{-1}$ resolves to an integer, and we’re done. If not so then we want to maximize $c_{-1}$ assigning to it the closest integer to the actual real value of that computation, which is: $$c_{-1} = \lfloor 2(\log_2(18) - c_0) \rfloor = \left\lfloor 2\log_2\left(\frac{18}{16}\right) \right\rfloor = \left\lfloor \log_2\left(\frac{81}{64} \right) \right\rfloor$$ Since $1 < 81\,/\,64 < 2$ then $0 < \log_2\left(81\,/\,64\right) < 1$ giving $c_{-1} = 0$ and $L_{1} = L_0 = 4$.

Be $L_2 = L_1 + 2^{-2}c_{-2}$, then: $$c_{-2} = 4(L_2 - L_1)$$

Going on as before: $$c_{-2}= \lfloor 4(\log_2(18) - 4) \rfloor = \left\lfloor 4\log_2\left(\frac{18}{16}\right) \right\rfloor = \left\lfloor \log_2\left(\frac{6561}{4096} \right) \right\rfloor = 0$$

Evaluate $c_{-3}$ as: $$c_{-3}= \lfloor 8(\log_2(18) - 4) \rfloor = \left\lfloor 8\log_2\left(\frac{9}{8}\right) \right\rfloor = \left\lfloor \log_2\left(\frac{9^8}{8^8}\right) \right\rfloor$$

If $9^8 > 2\cdot 8^8$ then $c_{-3}$ won’t be $0$. Now: $$9^8={9^2}^4={81^2}^2 = \cdots = 43046721$$ $$2\cdot 8^8=2 \cdot {8^2}^4=2 \cdot {64^2}^2 = \cdots = 33554432$$ We were right, $9^8 > 2\cdot 8^8$ is true; it is also true that $9^8 < 4\cdot 8^8$ just looking at the numbers. This means: $$c_{-3} = 1$$

Finally $L_3$ is: $$L_3 = c_0 + 2^{-1}c_{-1} + 2^{-2}c_{-2} + 2^{-3}c_{-3} = 4 + 0.125 = 4.125$$

This approach guarantees that $L_3 < L < L_3 + 2^{-3}$ giving an absolute error of $2^{-4} = 0.0625$ and a percent error of $1.47\,\%$ (in the worst case).

Our best guess $L^\star$ is $$L_3 + 2^{-4} = 4.15625$$ while the actual value $L$ was $\simeq 4.16992$.

The actual percent error is: $$\frac{L - L^\star}{L} \simeq 0.33\,\%$$

• omg, you are a machine – RollRoll Aug 1 '18 at 18:27

Here is one way for your specific problem. As you noted, $5^2=25$ and now keep squaring, instead of just multiplying by $5$. There is also a known trick to quickly square numbers ending in $5$, i.e. if $x = a5$ (where $a$ is any positive integer) then $x^2 = (a*(a+1))25$, for example if $5^2=25$ then $a=2$ and $a(a+1)=2\cdot 3=6$ so $$5^4=25^2 = 625$$ and $62\cdot 63 = 3906$ so $$5^8 = 625^2 = 390625,$$ so the answer will be between $8$ and $9$.

Your mistake was that $5^3=125 \ne 75$...

• Thanks. Why "one way". Isn't there a official way that everybody uses? – RollRoll Jul 27 '18 at 17:56
• @RollRoll not really... – gt6989b Jul 27 '18 at 18:09
• @gt6989b, you may not have noticed, but the OP has edited the question in a way that makes your answer look out of place. – Barry Cipra Jul 27 '18 at 18:25
• I'm sorry for that, I should have edited without removing previous question even though they are different words/examples for the same problem – RollRoll Jul 27 '18 at 20:03

Generally people don't calculate logs "by hand." People use a computer or a calculator or a table or (gasp) a slide rule.

If you are programming the computers or calculator there are infinite series that converge to these functions.

If you want a reasonable approximation, you play some games.

$10^3 = 1000\\ 2^{10} = 1024\\ \frac {\log 10}{\log 2} \approx \frac {10}3$

$\log_2 18 = 2\log_2 3 + 1\\ 3^4 = 81 \\ 4 \log_2 3 \approx 3+\log 10\\ 2 \log_2 3 + 1 = 4 \frac 16$

Which compares to $4.17$ from my calculator.

One way you can get a good approximation is to use the Taylor series expansion of the $\log$ function: $$\log(1+x)=\sum\limits_{n=1}^\infty(-1)^{n+1}\frac{x^n}{n}$$ You can use the fact that $|a_n-s_n|<|s_{n+1}|$ to get an idea of how accurate your answer is.

You might want to memorize the following logarithms, which can then allow you to approximate most others quite well:

(In base $10$)

$\log2=0.30$

$\log3=0.48$

$\log5=0.70$

$\log7=0.85$

Now, just remember the following logarithm properties: $\log{ab}=\log{a}+\log{b},$ $\log{\frac{a}{b}}=\log{a}-\log{b}$, and $\log_ab=\frac{\log_{10}{a}}{\log_{10}{b}}$. Using these identities, you can approximate, relatively, precisely, most logarithms.

Example 1: $\log_2{36}=\log_2{3}+\log_2{3}+\log_2{2}+\log_2{2}=\frac{\log3}{\log2}+\frac{\log3}{\log2}+1+1=\frac{0.48}{0.30}+\frac{0.48}{0.30}+1+1=1.60+1.60+1+1=5.20$

The actual answer is around $5.17$, but this is just an approximation.

Example 2: $\log_5{100}=\log_5{5}+\log_5{5}+\log_2{5}+\log_2{5}=1+1+\frac{\log2}{\log5}+\frac{\log2}{\log5}=1+1+\frac{0.30}{0.70}+\frac{0.30}{0.70}=1+1+0.43+0.43=2.86$

The actual answer is, when rounded to $2$ decimal places, $2.86.$

Hopefully you can see, because of logarithm properties, why $\log_{10}4,\log_{10}6,\log_{10}8, and \log_{10}9$ do not need to be memorized.