Avinash's Blog

BasicsByHand: Logarithms

Premise

While reading a book on the history of ee and why it appears everywhere, the author focuses a little on how Napier first developed logarithms. While the book clarifies that Napierian logarithms are different from the definitions we use today, and demonstrates how they were calculated, it occured to me that I had no idea how to derive their values by hand.

Searching online had limited results, and it took me quite some time to find a version that described a simple method that didn’t rely on calculus (something that wasn’t developed fully when logarithms were first calculated).

I write this down almost entirely from that source, primarily as a means to make one more source available on the internet, and for my own curiosity.

Prerequisites

You need to know very little to read this article.

However, if you truly wish to do it quite literally by hand, you will also need to know how to calculate square roots by hand. I went down this (small) rabbit hole myself while doing this research, and have written down how (again, no calculus involved).

Logarithms and key properties

My “first principles” knowledge on Logarithms was a little rusty. I hope this helps you the same way it did me. However, if you remember your logarithms well, you should skip this section.

What is a logarithm?

The logarithm of a number yy is defined for a base bb as the value xx that satisfies the equation:

y=bxy=b^x

It is more popularly written as:

logby=x\log_b y=x

By definition, therefore,

logbbx=x\log_b b^x = x

and conversely

blogbx=xb^{\log_bx}=x

The converse is tricky, but becomes easier if you say logbx=t\log_b x=t, which implies that bt=xb^t=x, which is exactly what blogbxb^{\log_b x} becomes.

Restrictions on bb and yy

It is important to note here that logby\log_b y is defined only for y>0y>0 and b>0b>0 and b1b \ne 1. These restrictions are necessary for the reasons laid out below:

  1. If b<0b < 0, then bxb^x is not always defined (for example, (2)0.5(-2)^{0.5} is not real)
  2. If b=0b = 0, 0x0^x is 0 for positive xx and undefined for x0x \leq 0. It’s not invertible.
  3. If b=1b = 1, 1x=11^x = 1 for all xx, which doesn’t give a useful log\log function.
  4. If y<0y<0 for valid bb, then no real xx can satisfy bx>0b^x>0.
  5. If y=0y=0 for valid bb, then no real xx can satisfy bx=0b^x=0.

Properties of logarithms

Sum of logs to the same base

A very basic property of exponents is that:

bubv=bbb(u times)bbb(v times)=bu+v \begin{aligned} b^u\cdots b^v &= \underbrace{b\cdots b\ldots\cdots b}_\text{(u times)}\cdots \underbrace{b\cdots b\ldots\cdots b}_\text{(v times)}\\ &=b^{u+v} \end{aligned}

To extend this to logarithms, define u=logbxu=\log_b x and v=logbyv=\log_b y:

bu+v=bubvblogbx+logby=blogbxblogbyblogbx+logby=xyblogbx+logby=blogb(xy)logbx+logby=logb(xy) \begin{aligned} b^{u+v} &= b^u\cdots b^v\\ b^{\log_b x+\log_b y}&=b^{\log_b x}\cdots b^{\log_b y}\\ b^{\log_b x+\log_b y}&=xy\\ b^{\log_b x+\log_b y}&=b^{\log_b{(xy)}}\\ \log_bx+\log_by&=\log_b(xy) \end{aligned}

It is important that all logs are to the same base bb.

Logs raised to an arbitrary exponent

This follows directly from sum of logs:

logbxa=logb(xxxa cdots)=logbx+logbx+logbxa times=alogbx \begin{aligned} \log_bx^a&=\log_b(\underbrace{x\cdots x\cdots\ldots\cdots x}_{\text{a cdots}})\\ &=\underbrace{\log_bx+\log_b x+\ldots\log_bx}_{\text{a times}}\\ &=a\log_bx \end{aligned}

Or, when aa isn’t positive or a whole number, we use the fact that:

(bx)a=bxa=bax (b^x)^a=b^{xa}=b^{ax}

which can be written as:

blogb(ya)=ya=(y)a=(blogby)a=balogbylogb(ya)=alogby \begin{aligned} b^{\log_b(y^a)}&=y^a=(y)^a\\ &=(b^{\log_b y})^a\\ &=b^{a\log_b y}\\ \Rightarrow\log_b(y^a)&=a\log_b y \end{aligned}

Difference of logs

Following the first two properties:

logbxlogby=logbx+(1)logby=logbx+logby1=logbx+logb1y=logbxy \begin{aligned} \log_bx-\log_by&=\log_bx+(-1)\log_by\\ &=\log_bx+\log_by^{-1}\\ &=\log_bx+\log_b\frac{1}{y}\\ &=\log_b\frac{x}{y} \end{aligned}

Changing of base

This is an important one. We need to write:

logxy \log_xy

in the form of just logs to a common base bb. We can write:

xlogbylogbx=(blogbx)logbylogbx=blogbxlogbylogbx=blogby=y=xlogxylogbylogbx=logxy \begin{aligned} x^\frac{\log_by}{\log_bx}&=(b^{\log_bx})^\frac{\log_by}{\log_bx}\\ &=b^{\frac{\log_bx\cdots\log_by}{\log_bx}}\\ &=b^{\log_by}\\ &=y\\ &=x^{\log_xy}\\ \Rightarrow \dfrac{\log_by}{\log_bx}&=\log_xy \end{aligned}

The Euler Method

Let’s say that we want to calculate log7155\log_7 155. Euler’s method involved first changing the base:

log7155=log10155log107 \log_7 155=\dfrac{\log_{10} 155}{\log_{10} 7}

and then using the identity:

log(xy)=log(xy)2=logx+logy2 \log(\sqrt{x\cdot y})=\dfrac{\log(xy)}{2}=\dfrac{\log x+\log y}{2}

Let’s see how. From herewith, if only log\log is used, assume that it means log10\log_{10}. This will simplify a lot of the visual noise.

Simplifying log calculations

We can first start by writing:

log155=log(1001.55)=2+log1.55 \log155=\log(100\cdot1.55)=2+\log1.55

Calculating log1.55\log1.55

Iteration 1

We know that from the identity above:

log(110)=log1+log102=12=0.5 \log(\sqrt{1\cdot10}) = \dfrac{\log1 +\log10}{2}=\dfrac{1}{2}=0.5

In other words,

log10=0.5 \log{\sqrt{10}} = 0.5

We know (or can calculate by hand) that 103.16228\sqrt{10}\approx3.16228. You can hopefully now see where this is going.

Iteration 2

Where does 1.551.55 lie? Between 11 and 10\sqrt{10}, or between 11 and 3.162283.16228. Let’s now calculate:

log13.16228=log1+log3.162282=0+0.52=0.25 \log{\sqrt{1\cdot3.16228}}=\dfrac{\log1+\log3.16228}{2}=\dfrac{0+0.5}{2}=0.25

Thus, 13.16228\sqrt{1\cdot3.16228} is 3.16228=1.77828\sqrt{3.16228}=1.77828.

Iteration 3

Once again, we make more progress by finding the square root of 1.778281.77828, because 1.551.55 lies between 11 and 1.778281.77828. Therefore,

log11.77828=log1+log1.778282=0.125 \log{\sqrt{1\cdot1.77828}}=\dfrac{\log1+\log{1.77828}}{2}=0.125

1.778281.33521\sqrt{1.77828}\approx1.33521. We’re getting rather close.

Iteration 4

We have a small change here. 1.551.55 now lies between 1.335211.33521 and 1.778281.77828. This means that the new value we need to find is:

log1.335211.77828=log1.33521+log1.778282=0.125+0.252=0.1875 \begin{aligned} \log{\sqrt{1.33521\cdot1.77828}}&=\dfrac{\log{1.33521}+\log{1.77828}}{2}\\ &=\dfrac{0.125+0.25}{2}\\ &=0.1875 \end{aligned}

Also, 1.335211.77828=1.54090\sqrt{1.33521\cdot1.77828}=1.54090

Further iterations

The next step would be to determine if 1.540901.54090 is sufficiently close to 1.551.55 for us to approximate that log1.54090log1.55\log 1.54090\approx\log 1.55, or we need to proceed further.

Of course, we can continue to refine the values until we’re sufficiently satisfied of our accuracy. What does a calculator tell us about log1.55\log 1.55?

1>>> from math import log
2>>> log(1.55, 10)
30.1903316981702915

So we were off by around… 0.00280.0028, which isn’t bad at all, considering we did only around 4 iterations (and many more iterations for calculating the square root).

Back to the Euler method

We find that log10155=2+0.1875\log_{10}155=2+0.1875. We calculate log107\log_{10}7 the same way, which should come to 0.8450.845 (according to my calculator), so

log71552.18750.845=2.5 \log_7 155\approx\dfrac{2.1875}{0.845}=2.5

and calculators give us:

1>>> from math import log
2>>> log(155, 7)
32.591

Clearly, while this is close to the 2.52.5 we got, it’s not quite correct - we’re off by 0.0910.091, an order of magnitude more. If we’d used the true value, 0.19030.1903, then we would have got:

log71552.19030.8452.592 \log_7 155\approx\dfrac{2.1903}{0.845}\approx2.592

Which is much closer to the true value. We find that approximating the true value of the log to a much larger number of decimal points is crucial to get the correct value.

Takeaway

A key takeaway for a programmer would be that Euler managed to implement binary search to efficiently (especially in terms of human effort) find the logarithm of a number

References

The primary reference for the material in this article is Bureau42. While the link works, it looks like the material that this used to point to doesn’t anymore. Some searching led me to a backup hosted on GitHub and another Hackernews linked source.

#mathematics #logarithms #history #by-hand #euler