2
$\begingroup$

I quite often need to estimate $\log_2(x)$ for positive integer values of $x$. I find it frustrating that I have to rely on a calculator/computer to do this. By way of contrast, I can happily compute as many decimal places as I like of $\frac{x}{y}$ in my head as long as $x$ and $y$ aren't too large using simple schoolbook long division.

What is a good way to estimate $\log_2(x)$ in your head?

To make the question more concrete, take $\log_2(10)$ or $\log_2(10^{20})$.

$\endgroup$
  • 1
    $\begingroup$ 10 is between 8 and 16, so $log_2(10)$ will be between 3 and 4. Since 10 is somewhat closer to 8 than to 16, even on an exponential scale, the fraction will be about .3 or .4. Multiply by 20 to get $log_2(10^{20})$. This yields 67, answer is 66.4385618977. Close enough? Even if there is some estimating $\endgroup$ – Pieter21 Nov 18 '15 at 7:14
  • $\begingroup$ @Pieter21 Thanks. I was really looking for a method that will allow me to compute an arbitrary number of decimal places if I had enough patience, in the same way as I can for division. $\endgroup$ – user66307 Nov 18 '15 at 7:18
  • $\begingroup$ If you are only interested to know $\log_2(10^n)$ then I would propose to remember $\log_2(10)$ (to a sufficient accuracy). $\endgroup$ – Fabian Nov 18 '15 at 7:20
  • $\begingroup$ How much can you memorize? I know that $\log_{10} 2 = 0.30103$ approximately, so $\lg 10 \doteq 1/0.30103 \doteq 3.322$. $\endgroup$ – Brian Tung Nov 18 '15 at 7:27
  • 2
    $\begingroup$ Something like this? math.stackexchange.com/questions/135368/… $\endgroup$ – zahbaz Nov 18 '15 at 7:44
2
$\begingroup$

You can use the rough approximation of $10^3 \approx 2^{10}$ for 1sf computations.

$\log_2(10) = \frac{1}{3} \log_2(1000) \approx \frac{1}{3} \log_2(1024) = \frac{10}{3}$.

If you want more precision, remember that $\ln(1+x) \approx x - \frac{1}{2} x^2$ as $x \to 0$, so taking just the first-order term we get $\log_2(1.024) = \frac{\ln(1.024)}{\ln(2)} \approx \frac{0.024}{\ln(2)}$. Now you can either use $\ln(2) \approx .693$ for 3sf precision, or you can use a rational approximation $\ln(2) \approx \frac{9}{13}$, which gives $\log_2(1.024) \approx \frac{104}{3000}$, and hence $\log_2(10) \approx \frac{10}{3} - \frac{104}{9000}$, which is good to 4 significant figures!

And from that we get $\log_2(10^{20}) \approx \frac{200}{3} - \frac{208}{900}$.

$\endgroup$
  • $\begingroup$ If you allow the use of a basic calculator with a square-root button, there is an extremely fast way to get the answer to about 8sf, which I describe at math.stackexchange.com/a/96104/21820 (it's in the first half). $\endgroup$ – user21820 Nov 18 '15 at 7:28
1
$\begingroup$

As user21820 says, your best friend is the identity $1024 = 2^{10} \approx 1000 = 10^3$, which gives $\log_2 10 \approx 3.3$ and $\log_2 10^{20} \approx 66$. Using this approximation, you now know how $\log_2 n$ behaves upon either multiplying or dividing $n$ by either $2$ or $5$ (approximately in this case), since you now know $\log_2 5 \approx 2.3$, and so you can estimate $\log_2 n$ by approximately writing $n$ as a product of powers of $2$ or $5$. If you memorize more logarithms of small integers and/or memorize $\log_2 5$ to more precision you can do even better.

For example, suppose you want to estimate $\log_2 75$. This is $\log_2 3 + \log_2 25 \approx \log_2 3 + 4.6$, so you're reduced to estimating $\log_2 3$. Well,

$$\log_2 3 = \log_2 15 - \log_2 5 \approx \log_2 16 - 2.3 = 1.7$$

and hence $\log_2 75 \approx 1.7 + 4.6 \approx 6.3$ (in fact it is $6.23 \dots$).

Or suppose you want to estimate $\log_2 21$ (I generated this example randomly). This is approximately $\log_2 20 = 2 + \log_2 5 \approx 4.3$ (in fact it is $4.39 \dots$).

You can always sanity check these calculations by checking that they have the right integer part: $\lfloor \log_2 n \rfloor$ is the largest $k$ such that $2^k \le n$.

$\endgroup$
0
$\begingroup$

Let $n$ denote the number of digits in the decimal representation of $x$.

Let $d$ denote the most significant digit in the decimal representation of $x$.

Then $\log_2x\approx3(n-1)\cdot(\log_2d+1)$, where:

  • $d=1\implies\log_2d+1=1$
  • $d=2\implies\log_2d+1=2$
  • $d=3\implies\log_2d+1\approx2.5$
  • $d=4\implies\log_2d+1=3$
  • $d=5\implies\log_2d+1\approx3$
  • $d=6\implies\log_2d+1\approx3.5$
  • $d=7\implies\log_2d+1\approx4$
  • $d=8\implies\log_2d+1=4$
  • $d=9\implies\log_2d+1\approx4$

So for the example of $x=10^{20}$:

  • $n=21$
  • $d=1$
  • $\log_2x\approx3\cdot20\cdot1=60$

If you wish to achieve slightly better accuracy, then use $3.3$ ($\approx\log_210$) instead of $3$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy