### Logarithm

#### What is Logarithm

The logarithm is the inverse operation to exponentiation.
The logarithm of a number is the exponent to which another fixed number, the base, must be raised to produce that number.
For example, the fourth power of 2 $(2^4)$ = 2 * 2 * 2 * 2 = 16 means that logarithm of 16 with respect to base 2 is 4

$2^4$ = 16 or $log_2 16$ = 4
When we say $log_2 16$, what we are actually saying is that what power 2 needs to be raised to to get 16

Let us try with some other bases.
When we say $log_3 81$, what we are saying is that what power 3 needs to be raised to to get 81?
Let us try it our manually.
$3 * 3 * 3 * 3 = 81$ shows us that $3^4$ = 81
$∴ log_3 81 = 4$

Now try to solve this yourself. $log_6 1296$ = ?

Interestingly, $log_{10} 1 = 0$
For that matter, for any base b, $log_b 1 = 0$. Can you figure out why?
This is so because $log_b 1 = 0$ can also be written as $b^0 = 1$ and we all know that any number b raised to 0 is always 1 !!!

The logarithm, in general, is denoted as $log_b x$ (pronounced as "the logarithm of x to base b").

The logarithm to base 10 (where b = 10) is called the common logarithm.
The logarithm to base $e$ (where b = e) is called the natural logarithm where e = 2.71828
The logarithm to base 2 (where b = 2) is called the binary logarithm.

#### Common Logarithm

The common logarithm is the logarithm to base 10.
$log_{10} 1000 = 3$
$log_{10} 100 = 2$
$log_{10} 10 = 1$
$log_{10} 1 = 0$
As one can guess, the common logarithm of numbers between 10 to 100 would lie between 1 and 2.
If a log has no base written, you can generally assume that the base is 10.

Can logarithm be negative?
Yes, logarithm of a positive number less than 1 is negative. e.g.
$log_{10} 0.1 = -1$
$log_{10} 0.01 = -2$
$log_{10} 0.001 = -3$
Why? This is because $10^{-1} = 0.1$, $10^{-2} = 0.01$, $10^{-3} = 0.001$ and so on.

What is log of a negative number?
Log of a negative number is not a real number.
To understand this better, let us take a logarithmic function $y = log_b x$
This can also be represented as $x = b^y$
Since $b$ and $y$ are both positive numbers, $x$ must also be positive.
Hence $log_b x$ for $x$ ≤ 0 is undefined
For example, $log_{10} 0$ is undefined. $log_b ({-4})$ is undefined.

The real logarithmic function $log_b (x)$ is defined only for x>0. However, we can imagine it in the form of complex numbers. We will disucss about it in subsequent topics.

#### Natural Logarithm

The logarithm to base $e$ is called the natural logarithm where e = 2.71828
The natural logarithm is inverse of $e^x$ and is the power to which $e$ should be raised to obtain the given number.
It is generally written as $ln(x)$.
The natural log of $e, ln(e) = 1$, because $e^1 = e$.
The natural logarithm of $1, ln 1 = 0$, since $e^0 = 1$.

An interesting use of natural logarithm is in case of continous compounding. If you know about compound interest, the frequency of compounding is generally yearly, semiannually, quarterly or monthly. However, if one compounds interest over an infinite number of periods i.e. almost on a continous basis, it is called continous compounding.

The future value (FV) of investment with compounding of interest is given as $FV = PV (1 + i/n))^{n * t}$
where PV is the Present Value
i is the Rate of Interest
n is the number of compounding periods and
t is the time in years

In continous compounding, n approaches infinity. Hence taking the limit of this formula as n approaches $∞$, we get
$FV = PV * e ^ {(i * t)}$

As can be seen, the number $e$ represents the continous growth. For a given rate of interest, it lets us find out the time which would give us the required growth.
$e^2$ is 7.389. After 2 units of time (e.g. years), we will have 7.389 times the growth in the amount invested.
In other words, ln (7.389) = 2 represents that to achieve growth of 7.389, we would need for 2 units of time. Some quick inferences - ln (1) = 0 indicates that to achieve growth of 1, we need to wait for 0 units of time. Very logical !!! You already have the required 1 times the amount.

What is natural log of a negative number?
As in case of common logarithm, natural log of a negative number is also not defined.

#### Binary Logarithm

The logarithm to base $2$ is called the binary logarithm.

The binary logarithm of a number n is often written as $log_2 (n)$ and is the power to which the number 2 must be raised to obtain the value n.
$log_2 16 = 4$
$log_2 8 = 3$
$log_2 4 = 2$
$log_2 2 = 1$
$log_2 1 = 0$

Binary logarithm has many applications in Information theory. It is used in Binary Search, in determining rate of growth or decays etc.

#### Logarithm Rules

$log_b (x) + log_b (y) = log_b (xy)$

$log_b (x) - log_b (y) = log_b (x/y)$

$y log_b (x) = log_b (x^y)$

Logarithms and Exponentials with the same base cancel each other. This is because Logarithms are inverse of Exponentials.
$b^{ log_b x} = x$
$log_b (b^x) = x$

There are many more general logarithm rules which are currently not included in this tutorial.