Mathematics - Logarithm Function (log)
About
<math>log_b(n)</math> is the number (#) of times you divide n by b until you get down to 1.
If you see log, you must think trees
Articles Related
Example
With the base 2 where <math>log_2 n</math> is the # of times you divide n by 2 until you get down to 1.
You keep repeating dividing by two and you count how many times you divide by two until you get a number that drops below one
<MATH> \begin{array}{rrl} log_2 (42) = 5.39 &&&\\ 1- & 42/2 & = & 21 \\ 2- & 21/2 & = & 10.5 \\ 3- & 10.5 / 2 & = & 5.25 \\ 4- & 5.25/2 & = & 2.625 \\ 5- & 2.625/2 & = & 1.3125 \\ 6- & 1.3125/2 & = & 0.65625 \\ \end{array} </MATH>
Property
The logarithm is much, much smaller than the input. log is running much, much, much slower than the identity function. <MATH> \begin{array}{rrl} log_2 (10) & \approx & 3 \\ log_2 (100) & \approx & 7 \\ log_2 (1000) & \approx & 10 \\ \end{array} </MATH>
Formula
- With the exponentiation
<MATH> b^n = a </MATH>
- The log is defined as:
<MATH> n = log_b(a) </MATH>
log x without an explicit base may also refer to the natural logarithm.
Law
From multiplication to addition
Logarithms permit to replace multiplication by addition.
<MATH> log_b(x \times y) = log_b(x) + log_b(y) </MATH>
It was more comfortable to carry at a time the calculator does not exist.
Base modification
<MATH> log_b(a) = \frac{log_2(a)}{log_2(b)} = \frac{log_e(a)}{log_e(b)} = \dots = \frac{log_x(a)}{log_x(b)} </MATH>
Log base 2 approximation
<MATH> log_2(x) \approx log_e(x) + log_{10}(x) </MATH> where:
- log_e (or ln) is the natural logarithm
Computer Language
In most of the computer language:
- the log function returns the natural logaritm
- there is also precomputed value in order to help to change base thanks to the division law.
For instance, in javascript, Math.log(x) returns the natural logarithm and to get the log on base 10, you would use the LN10 constant (ie ln(10))
function log10(val) {
return Math.log(val) / Math.LN10;
}