BasicsByHand: Logarithms
Premise
While reading a book on the history of 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 is defined for a base as the value that satisfies the equation:
It is more popularly written as:
By definition, therefore,
and conversely
The converse is tricky, but becomes easier if you say , which implies that , which is exactly what becomes.
Restrictions on and
It is important to note here that is defined only for and and . These restrictions are necessary for the reasons laid out below:
- If , then is not always defined (for example, is not real)
- If , is 0 for positive and undefined for . It’s not invertible.
- If , for all , which doesn’t give a useful function.
- If for valid , then no real can satisfy .
- If for valid , then no real can satisfy .
Properties of logarithms
Sum of logs to the same base
A very basic property of exponents is that:
To extend this to logarithms, define and :
It is important that all logs are to the same base .
Logs raised to an arbitrary exponent
This follows directly from sum of logs:
Or, when isn’t positive or a whole number, we use the fact that:
which can be written as:
Difference of logs
Following the first two properties:
Changing of base
This is an important one. We need to write:
in the form of just logs to a common base . We can write:
The Euler Method
Let’s say that we want to calculate . Euler’s method involved first changing the base:
and then using the identity:
Let’s see how. From herewith, if only is used, assume that it means . This will simplify a lot of the visual noise.
Simplifying log calculations
We can first start by writing:
Calculating
Iteration 1
We know that from the identity above:
In other words,
We know (or can calculate by hand) that . You can hopefully now see where this is going.
Iteration 2
Where does lie? Between and , or between and . Let’s now calculate:
Thus, is .
Iteration 3
Once again, we make more progress by finding the square root of , because lies between and . Therefore,
. We’re getting rather close.
Iteration 4
We have a small change here. now lies between and . This means that the new value we need to find is:
Also,
Further iterations
The next step would be to determine if is sufficiently close to for us to approximate that , 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 ?
1>>> from math import log
2>>> log(1.55, 10)
30.1903316981702915So we were off by around… , 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 . We calculate the same way, which should come to (according to my calculator), so
and calculators give us:
1>>> from math import log
2>>> log(155, 7)
32.591Clearly, while this is close to the we got, it’s not quite correct - we’re off by , an order of magnitude more. If we’d used the true value, , then we would have got:
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.