# Guide to Game Development/Theory/Mathematics/Logarithms

A logarithm is the answer to the question: "What number do I need to raise this known number to to get this other known number?"

Example of the problem:

${\displaystyle 2^{x}=32}$

Rewritten as a logarithm:

${\displaystyle \log _{2}(32)=x}$

You'd pronounce this as, "log base 2 of 32."

As you can see from the graph, you can't have a negative logarithm. If you think about it, this makes sense because it's a reflection of an exponential graph. When you have a positive number and you raise it to any number, the result will always be positive, and never 0; because of this the domain of a logarithm is as follows: ${\displaystyle \log _{a}(x),x>0}$.

## Combining logarithms

There are 3 rules that you should know when combining logarithms:

${\displaystyle \log _{k}a+\log _{k}b=\log _{k}ab}$

${\displaystyle \log _{k}a-\log _{k}b=\log _{k}{\frac {a}{b}}}$

${\displaystyle a\log _{k}(b)=\log _{k}(b^{a})}$

### Expanding logarithms

When expanding logarithms, you can just do the inverse of what you did to combine them.

Example 1:

${\displaystyle \log _{4}{\bigg (}{\frac {x^{2}}{5^{3}y}}{\bigg )}=\log _{4}(x^{2})-\log _{4}(5^{3}y)=\log _{4}(x^{2})-\log _{4}(5^{3})+\log _{4}(y)=2\log _{4}(x)-3\log _{4}(5)+\log _{4}(y)}$

Example 2 (knowledge of exponentials needed):

${\displaystyle \log _{9}{\bigg (}{\frac {1}{\sqrt[{3}]{5}}}{\bigg )}=\log _{9}{\bigg (}{\frac {1}{5^{\frac {1}{3}}}}{\bigg )}=\log _{9}(5^{-{\frac {1}{3}}})=-{\frac {1}{3}}\log _{9}5}$

## Cancelling logarithms with exponentials and vice versa

There are a few more rules you need to know:

${\displaystyle \log _{a}a^{x}=x}$

${\displaystyle a^{\log _{a}x}=x}$

${\displaystyle \log _{a}b={\frac {\log _{n}a}{\log _{n}b}}}$ where ${\displaystyle n}$ can be any number.

${\displaystyle \log _{a}1=0}$

Note: If you're doing a complex algorithm with a computer, try to give your answer in terms of a base 2 logarithm, because whatever base you input, the computer will convert it to base 2. Doing this for the computer so that it doesn't need to convert it each time will make the algorithm run faster.

### Balancing questions with these rules

So when you have a normal equation, you can do rules like "multiply both sides by 2" or "add 3 to both sides". With logarithms and exponentials, you can do something similar.

You can now:

• "Raise both sides as an exponential of a number"
• Example use:
${\displaystyle log_{3}x=5\rightarrow 3^{log_{3}x}=3^{5}\rightarrow x=3^{5}}$
• "Log both sides (with a common base)"
• Example use:
${\displaystyle 4^{x}=7\rightarrow \log _{4}(4^{x})=log_{4}7\rightarrow x=log_{4}7}$

## Notation

The mathematical constant ${\displaystyle e}$ is often used with logarithms as it's known as the natural base for a logarithm.

${\displaystyle e=2.71828182845904523536028747135266249775724709369995\dots }$

Certain short-hand notation has been developed for logarithms as follows:

${\displaystyle \log _{e}(x)=\ln(x)}$

${\displaystyle \log _{2}(x)=}$ lb ${\displaystyle (x)}$

${\displaystyle \log _{10}(x)=\log(x)}$

### Scale of magnitude

For this scale of magnitude, we'll be using 10 as we work in base as humans.

${\displaystyle \log _{10}1=0}$

${\displaystyle \log _{10}10=1}$

${\displaystyle \log _{10}100=2}$

${\displaystyle \log _{10}1000=3}$

${\displaystyle \log _{10}10000=4}$

Note: remember it's a logarithmic scale, this means that half way between 10 and 100 (55) doesn't produce a half way value (${\displaystyle \log _{10}55\neq 1.5,\log _{10}55\approx 1.74}$).