0

I'm trying to find the result of $\log{x}$ (base 10) close to exact value in two digits with these methods:

The methods below are doing by hand. I appreciate you all who already give answers for computer method.

As suggested by Praktik Deoghare's answer

If number N (base 10) is n-digit then $$n-1 \leq \log_{10}(N) < n$$ Then logarithm can be approximated using $$\log_{10}(N) \approx n-1 + \frac{N}{10^{n} - 10^{n-1}}$$ Logarithm maps numbers from 10 to 100 in the range 1 to 2 so log of numbers near 50 is about 1.5. But this is only a linear approximation, good for mental calculation and toy projects but not that good for serious research.

This method is cool for me, but it's nearly close to exact value. $\log_{10}(53)$ is 1.7 and with that method results 1.58.

As suggested by Pedro Tamaroff's answer

One can get very good approximations by using $$\frac 1 2 \log \left|\frac{1+x}{1-x}\right| =x+\frac {x^3} 3+ \frac {x^5}5+\cdots$$ Say you want to get $\log{3}$. Then take $x=1/2$. Then you get $$\log 3 \approx 2\left( \frac 1 2 +\frac 1 {24} + \frac 1 {140} \right)=1.0976190\dots$$ The real value is $\log 3 \approx 1.098065476\dots$

This one is also cool for me, but it's to find natural logarithm, not base-10 logarithm.

As suggested by Kaleb's answer

This can be done by recourse to Taylor series. For $ln(x)$ centered at 1, i.e. where $0 < x \leq 2$: $$\ln(x)= \sum_{n=1}^\infty \frac{(x-1)^n}{n}= (x-1) - \frac{1}{2}(x-1)^2 + \frac{1}{3}(x-1)^3 + \frac{1}{4}(x-1)^4 + \cdots$$

The method is for calculating $ln(x)$, not $\log{x}$. I don't know the Taylor series for calculate $\log{x}$, especially when to find log result close to exact value in two digits (with similar method).

As suggested by Glenn's answer

The Wikipedia article "Generalized continued fraction" has a Khovanskiĭ-based algorithm that differs only in substituting x/y for z, and showing an intermediate step: $$\log \left( 1+\frac{x}{y} \right) = \cfrac{x} {y+\cfrac{1x} {2+\cfrac{1x} {3y+\cfrac{2x} {2+\cfrac{2x} {5y+\cfrac{3x} {2+\ddots}}}}}} $$

This method is very slow for me. When I stop at $3y$, the result (log calculation) is still far from the exact value.

Anyone who can improve all of the above methods so I can precisely get log result close to exact value in two digits?

làntèrn
  • 307
  • 1
    What is the range you want to approximate? – Gappy Hilmore Jun 07 '15 at 07:24
  • The formula for $\frac12\log \big|\frac{1+x}{1-x} \big|$ is also for the natural logarithm, not the base-10 logarithm. – Greg Martin Jun 07 '15 at 07:26
  • @grdgfgr For $x$ of $\log{x}$ is 1 until 100, especially prime numbers. – làntèrn Jun 07 '15 at 07:26
  • @GregMartin Ah ... why ... – làntèrn Jun 07 '15 at 07:29
  • 1
    Could you explain exactly what your requirements are? If you're doing this by computer, why can't you just use the built-in logarithm function? And if you're doing it by hand, I would only ask why you are doing it by hand!? – Christopher A. Wong Jun 07 '15 at 07:58
  • @grdgfgr and Christopher A, I apologize to you all. What requirement I need is doing the methods by hand. I don't know if there's also different method used by computer. – làntèrn Jun 07 '15 at 08:04
  • @ChristopherA.Wong I will edit my requirement for by hand. – làntèrn Jun 07 '15 at 08:06
  • 1
    Why. Got nothing better to do? – Gappy Hilmore Jun 07 '15 at 08:11
  • @grdgfgr I asking this because I've tried those methods by hand, so what I hope is someone will improve the equations in the methods given. I'm not a native English, so if you can't get what I mean, you can edit the question. – làntèrn Jun 07 '15 at 08:21
  • I think the question is ok. But if this is for mental arithmetic or paper and pencil work, you should really describe an interesting range of $x$. To get two significant digits to the Briggs logarithm requires rather different level of accuracy from the approximations, if $x$ is in the range $10^3<x<10^6$ as opposed to it being in the range $1<x<10$. – Jyrki Lahtonen Jun 07 '15 at 09:25

4 Answers4

4

Listing a few tricks that work for mental arithmetic. Mostly to get the OP to comment, whether this is at all what they expect. I write $\log$ for $\log_{10}$ to save a few keystrokes.

You need to memorize a few logarithms and play with those. We all have seen $\log 2\approx 0.30103$ enough many times to have memorized it. Consequently by mental arithmetic we get for example the following $$ \begin{aligned} \log4&=2\log2&\approx 0.602,\\ \log5&=\log(10/2)&\approx 0.699,\\ \log1.6&=\log(2^4/10)&\approx 0.204,\\ \log1.024&=\log(2^{10})-3&\approx 0.0103.\\ \end{aligned} $$ Using these is based on spotting numerical near matches.

You should also be aware of the first order Taylor series approximation $$ \log(1+x)\approx\frac{x}{\ln 10}\approx\frac{x}{2.3}\approx0.434 x, $$ which implies (plug in $x=0.01$) that if you change the value of $x$ by 1 per cent, then its logarithm changes by approximately $0.0043$.

As an example let's do $\log 53$ and $\log7$. Here $x=53$ is $6\%$ larger than $50$, so a first order approximation would be $$ \log53\approx\log 50+6\cdot 0.0043=\log(10^2/2)+6\cdot0.00434\approx 2-0.30103+0.0258\approx1.725. $$ With $7$ we can spot that $7^2=49$ is $2\%$ less than $50$, so $$\log 7=\frac12\,\log49\approx\frac12(2-0.301-2\cdot0.0043)\approx\frac{1.690}2=0.845. $$ Here the third decimal of $\log53$ is off by one, but $\log7$ has three correct digits - both well within your desired accuracy.

Jyrki Lahtonen
  • 133,153
  • Thank you so much! You can understand my question exactly :-). How do you make the %? – làntèrn Jun 07 '15 at 09:59
  • Sorry, I mean how do you know that is 6% larger and 2% less? – làntèrn Jun 07 '15 at 10:02
  • $1$ is $2%$ of $50$. This method really is better suited for mental arithmetic than any serious work. Something you can impress students with (or chicks you meet at a bar, if you think showing off with logarithms helps your cause). – Jyrki Lahtonen Jun 07 '15 at 10:05
  • Wow this method is very awesome for me! Is the change by 0.0043 always work for any number of log? Or is there a small method to get the 0.0043? – làntèrn Jun 07 '15 at 10:10
  • It comes from that Taylor series expansion: $0.0043\approx 0.434\cdot \dfrac1{100}$. That $1/100$ is, of course, $1$ percent. Caveat: if the percentage difference is larger the formula will quickly begin to lose accuracy. You always need a nearby reference point. – Jyrki Lahtonen Jun 07 '15 at 10:17
  • That's make sense! Thank you for helping me! – làntèrn Jun 07 '15 at 10:20
1

Is this good enough? It is within your specifications in 1 to 100

enter image description here

$$\frac{\frac{(x-10)^5 (137+30 \log (10))}{756000000}+\frac{(x-10)^4 (77+30 \log (10))}{2520000}+\frac{(x-10)^3 (47+30 \log (10))}{36000}+\frac{1}{450} (x-10)^2 (9+10 \log (10))+\frac{1}{20} (x-10) (2+5 \log (10))+\log (10)}{\frac{(x-10)^5}{25200000}+\frac{(x-10)^4}{84000}+\frac{(x-10)^3}{1200}+\frac{1}{45} (x-10)^2+\frac{x-10}{4}+1}$$

in plain text:

(Log[10]+1/20 (-10+x) (2+5 Log[10])+1/450 (-10+x)^2 (9+10 Log[10])+((-10+x)^3 (47+30 Log[10]))/36000+((-10+x)^4 (77+30 Log[10]))/2520000+((-10+x)^5 (137+30 Log[10]))/756000000)/(1+1/4 (-10+x)+1/45 (-10+x)^2+(-10+x)^3/1200+(-10+x)^4/84000+(-10+x)^5/25200000)

You can generate these yourself :

http://www.wolframalpha.com/input/?i=PadeApproximant%5BLog%5Bx%5D%2C+%7Bx%2C+10%2C+%7B5%2C+5%7D%7D%5D

Click the A button

enter image description here

If you want base 10, you would want to use Log10[x]

http://www.wolframalpha.com/input/?i=PadeApproximant%5BLog10%5Bx%5D%2C+%7Bx%2C+10%2C+%7B5%2C+5%7D%7D%5D

You are going to use this syntax to tune it yourself:

https://reference.wolfram.com/language/ref/PadeApproximant.html

Of course you have to you use a computer to actually evaluate this rational function. But if you already have a computer, why not just evaluate logx ?

1

There is a well-known trick based on the linearization of the logarithm that can be employed in a shockingly simple manner. However, the linearization is only "nice" for computing $\log_2(x)$, which on a computer is the only relevant logarithm anyways since all numbers are represented in base 2.

The algorithm is as follows: Let $x = 2^b (1 + m)$, where $b$ is a non-negative integer and $m \in [0,1)$. Let the floating point bit representation of $x$ be given by the concatenation of the binary strings $b$ and $m$. Then you can trivially approximate $\log_2(x)$ by the binary number $b.m$, which is merely just moving the position of the "dot" in the floating point bit representation. This is really just the statement that $\log_2(1 + m) \approx m$.

If you are willing to store a single precomputed value $\log_{2}(10)$, then from here you can trivially convert to a base 10 logarithm.

Example: Chose $x = 53_{10}$ (as represented as a decimal). Then in binary $x = 110101_{2}$, and hence $b = 101_{2}$ and $m = 10101_{2}$. Then in binary $\log_2(x)$ can be approximated by $b.m = 101.10101_{2} = 5.65625_{10}$, and then $\log_{10}(x) \approx 5.65625 / \log_2(10) = 1.7027$.

Summary: Let $x = 2^b (1 + m)$. Then $\log_{10}(x) \approx 0.30103_{10} \times (b.m)_{2}$.

For the slightly better version, see this Wikipedia description.

Christopher A. Wong
  • 22,445
  • 3
  • 51
  • 82
1

Consider any real number $x$, $1 \le x < b$ (if $x$ is outside this range, it can be normalized by repeated divisions/multiplications by $b$). $\log_b(x)$ can be computed digit-by-digit iteratively; the obtained digits being accurate within the calculation errors. The base of the log and the radix of these digits can be anything. Below is outline of the "digit-by-digit" algorithm when both are 2.

(Its generic form for a class of functions was published by D.R. Morrison in 1956).

Say,

$\log_2(x) = 0.b_1b_2b_3...$ {$b_i$ are bits} (1)

Then,

$2\log_2(x) = b_1.b_2b_3...$

$\Leftrightarrow \log_2(x^2) = b_1. b_2 b_3...$

So, $b_1$ can be found based on whether $x^2 \ge 2$ or not. Now, having found bit $b_1$, we subtract it from both sides, giving:

$\log_2(x^2/2^{b_1}) = 0. b_2 b_3...$ {$b_1$ is 0 or 1}

This equation now looks similar to equation (1) (with another $x$). So we can find $b_2$ in the similar manner, and likewise any number of bits we want.

This method can be adjusted to work with base-10 log and base-10 output digits. Instead of multiplying the equation (1) by 2, we will do it by 10. Also, instead of subtracting by $b_1$, we will subtract by the digit found in base-10.